Setting.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace app\admin\controller\setting;
  3. use app\common\controller\Backend;
  4. use think\Db;
  5. use think\exception\PDOException;
  6. use think\exception\ValidateException;
  7. /**
  8. * 平台设置管理
  9. *
  10. * @icon fa fa-circle-o
  11. */
  12. class Setting extends Backend
  13. {
  14. /**
  15. * Setting模型对象
  16. * @var \app\admin\model\setting\Setting
  17. */
  18. protected $model = null;
  19. public function _initialize()
  20. {
  21. parent::_initialize();
  22. $this->model = new \app\admin\model\setting\Setting;
  23. }
  24. /**
  25. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  26. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  27. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  28. */
  29. public function index()
  30. {
  31. $row = $this->model->get(1);
  32. $adminIds = $this->getDataLimitAdminIds();
  33. if (is_array($adminIds)) {
  34. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  35. $this->error(__('You have no permission'));
  36. }
  37. }
  38. if ($this->request->isPost()) {
  39. $params = $this->request->post("row/a");
  40. if ($params) {
  41. $params = $this->preExcludeFields($params);
  42. if (!is_numeric($params['one_rmb_to_coin_num']) || $params['one_rmb_to_coin_num'] < 0) {
  43. $this->error('金币兑换RMB数量有误');
  44. }
  45. if (!is_numeric($params['recovery_discount']) || $params['recovery_discount'] < 0) {
  46. $this->error('商品回收金额占比设置有误');
  47. }
  48. if (!is_numeric($params['retail_1']) || $params['retail_1'] < 0) {
  49. $this->error('一级分销佣金占比设置有误');
  50. }
  51. if (!is_numeric($params['retail_1']) || $params['retail_1'] < 0) {
  52. $this->error('二级分销佣金占比设置有误');
  53. }
  54. if (!is_numeric($params['retail_1']) || $params['retail_1'] < 0) {
  55. $this->error('三级分销佣金占比设置有误');
  56. }
  57. $result = false;
  58. Db::startTrans();
  59. try {
  60. //是否采用模型验证
  61. if ($this->modelValidate) {
  62. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  63. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  64. $row->validateFailException(true)->validate($validate);
  65. }
  66. $result = $row->allowField('logo_image,one_rmb_to_coin_num,hot_box_banner,cheap_box_banner,recovery_discount,service_number,service_qrcode,retail_1,retail_2,retail_3,kou,url,openurl,registerurl,check_switch')->save($params);
  67. Db::commit();
  68. } catch (ValidateException $e) {
  69. Db::rollback();
  70. $this->error($e->getMessage());
  71. } catch (PDOException $e) {
  72. Db::rollback();
  73. $this->error($e->getMessage());
  74. } catch (\Exception $e) {
  75. Db::rollback();
  76. $this->error($e->getMessage());
  77. }
  78. if ($result !== false) {
  79. $this->success();
  80. } else {
  81. $this->error(__('No rows were updated'));
  82. }
  83. }
  84. $this->error(__('Parameter %s can not be empty', ''));
  85. }
  86. $this->view->assign("row", $row);
  87. $this->view->assign("statusList", [1 => __('开启'), 0 => __('关闭')]);
  88. return $this->view->fetch();
  89. }
  90. }