Config.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace app\admin\controller\commission;
  3. use app\common\controller\Backend;
  4. use app\common\Service\ShopConfigService;
  5. use think\exception\PDOException;
  6. use think\exception\ValidateException;
  7. /**
  8. * 分销配置管理
  9. *
  10. * @icon fa fa-cogs
  11. */
  12. class Config extends Backend
  13. {
  14. /**
  15. * Config模型对象
  16. *
  17. */
  18. protected $model = null;
  19. public function _initialize()
  20. {
  21. parent::_initialize();
  22. }
  23. /**
  24. * 查看分销配置
  25. */
  26. public function index()
  27. {
  28. // 获取分销配置
  29. $commissionConfig = ShopConfigService::getConfigs('shop.commission');
  30. $this->view->assign('commissionConfig', $commissionConfig ?: []);
  31. return $this->view->fetch();
  32. }
  33. /**
  34. * 编辑配置
  35. */
  36. public function edit($ids = null)
  37. {
  38. if ($this->request->isPost()) {
  39. $this->token();
  40. $params = $this->request->post("row/a", [], 'trim');
  41. if ($params) {
  42. // try {
  43. // 特殊处理某些配置项
  44. if (isset($params['become_agent']) && is_array($params['become_agent'])) {
  45. $params['become_agent'] = json_encode($params['become_agent'], JSON_UNESCAPED_UNICODE);
  46. }
  47. // 更新配置
  48. ShopConfigService::setConfigs('shop.commission', $params);
  49. $this->success('配置保存成功');
  50. // } catch (ValidateException $e) {
  51. // $this->error($e->getMessage());
  52. // } catch (PDOException $e) {
  53. // $this->error($e->getMessage());
  54. // } catch (\Exception $e) {
  55. // $this->error($e->getMessage());
  56. // }
  57. }
  58. $this->error(__('Parameter %s can not be empty', ''));
  59. }
  60. }
  61. }