Configure.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace app\admin\controller\service;
  3. use app\common\controller\Backend;
  4. use think\Db;
  5. /**
  6. * 项目配置
  7. *
  8. * @icon fa fa-circle-o
  9. */
  10. class Configure extends Backend
  11. {
  12. /**
  13. * Configure模型对象
  14. * @var \app\admin\model\service\Configure
  15. */
  16. protected $model = null;
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->model = new \app\admin\model\service\Configure;
  21. }
  22. public function edit($ids=1)
  23. {
  24. $row = $this->model->get($ids);
  25. if (!$row) {
  26. \app\admin\model\service\Configure::create(['userappid'=>'wxxxxxxxx1231434','usersecret'=>'wxxxxxxxx1231434','skillappid'=>'wxxxxxxxx1231434','skillsecret'=>'wxxxxxxxx1231434','shopappid'=>'wxxxxxxxx1231434','shopsecret'=>'wxxxxxxxx1231434','gaodekey'=>'ajaxkkloxxxx','state'=>1]);
  27. $row = $this->model->get($ids);
  28. }
  29. $adminIds = $this->getDataLimitAdminIds();
  30. if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
  31. $this->error(__('You have no permission'));
  32. }
  33. if (false === $this->request->isPost()) {
  34. $this->view->assign('row', $row);
  35. return $this->view->fetch();
  36. }
  37. $params = $this->request->post('row/a');
  38. if (empty($params)) {
  39. $this->error(__('Parameter %s can not be empty', ''));
  40. }
  41. $params = $this->preExcludeFields($params);
  42. $result = false;
  43. Db::startTrans();
  44. try {
  45. //是否采用模型验证
  46. if ($this->modelValidate) {
  47. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  48. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  49. $row->validateFailException()->validate($validate);
  50. }
  51. $result = $row->allowField(true)->save($params);
  52. Db::commit();
  53. } catch (ValidateException|PDOException|Exception $e) {
  54. Db::rollback();
  55. $this->error($e->getMessage());
  56. }
  57. if (false === $result) {
  58. $this->error(__('No rows were updated'));
  59. }
  60. $this->success();
  61. }
  62. }