Setting.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. * @var array
  13. */
  14. private $describe = [
  15. 'basic' => '基础设置',
  16. 'condition' => '分销商条件',
  17. 'commission' => '佣金设置',
  18. 'settlement' => '结算',
  19. 'words' => '自定义文字',
  20. 'license' => '申请协议',
  21. 'background' => '页面背景图',
  22. 'template_msg' => '模板消息',
  23. 'qrcode' => '分销海报',
  24. ];
  25. /**
  26. * 更新系统设置
  27. */
  28. public function edit($data)
  29. {
  30. $this->startTrans();
  31. try {
  32. foreach ($data as $key => $values)
  33. $this->saveValues($key, $values);
  34. $this->commit();
  35. // 删除系统设置缓存
  36. Cache::delete('agent_setting_' . self::$app_id);
  37. return true;
  38. } catch (\Exception $e) {
  39. $this->error = $e->getMessage();
  40. $this->rollback();
  41. return false;
  42. }
  43. }
  44. /**
  45. * 保存设置项
  46. */
  47. private function saveValues($key, $values)
  48. {
  49. $where['key'] = $key;
  50. $res = $this->where($where)->select()->count();
  51. $data = [
  52. 'describe' => $this->describe[$key],
  53. 'values' => $values,
  54. 'app_id' => self::$app_id,
  55. ];
  56. if ($res == 1) {
  57. return self::update($data, $where);
  58. }
  59. if ($res == 0) {
  60. $data['key'] = $key;
  61. return self::create($data);
  62. }
  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. }