Setting.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace app\shop\model\plus\agent;
  3. use think\facade\Cache;
  4. use app\common\model\plus\agent\Setting as SettingModel;
  5. /**
  6. * 分销商设置模型
  7. */
  8. class Setting extends SettingModel
  9. {
  10. /**
  11. * 设置项描述
  12. */
  13. private $describe = [
  14. 'basic' => '基础设置',
  15. 'condition' => '分销商条件',
  16. 'commission' => '佣金设置',
  17. 'settlement' => '结算',
  18. 'words' => '自定义文字',
  19. 'license' => '申请协议',
  20. 'background' => '页面背景图',
  21. 'template_msg' => '模板消息',
  22. 'qrcode' => '分销海报',
  23. ];
  24. /**
  25. * 更新系统设置
  26. */
  27. public function edit($data)
  28. {
  29. $this->startTrans();
  30. try {
  31. foreach ($data as $key => $values)
  32. $this->saveValues($key, $values);
  33. $this->commit();
  34. // 删除系统设置缓存
  35. Cache::delete('agent_setting_' . self::$app_id);
  36. return true;
  37. } catch (\Exception $e) {
  38. $this->error = $e->getMessage();
  39. $this->rollback();
  40. return false;
  41. }
  42. }
  43. /**
  44. * 保存设置项
  45. */
  46. private function saveValues($key, $values)
  47. {
  48. $where['key'] = $key;
  49. $res = $this->where($where)->select()->count();
  50. $data = [
  51. 'describe' => $this->describe[$key],
  52. 'values' => $values,
  53. 'app_id' => self::$app_id,
  54. ];
  55. if ($res == 1) {
  56. return self::update($data, $where);
  57. }
  58. if ($res == 0) {
  59. $data['key'] = $key;
  60. return self::create($data);
  61. }
  62. return false;
  63. }
  64. /**
  65. * 验证结算方式
  66. */
  67. private function validSettlement($values)
  68. {
  69. if (!isset($values['pay_type']) || empty($values['pay_type'])) {
  70. $this->error = '请设置 结算-提现方式';
  71. return false;
  72. }
  73. return true;
  74. }
  75. }