Projectconfig.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace app\admin\controller\service\info;
  3. use app\common\controller\Backend;
  4. use think\Db;
  5. /**
  6. * 项目配置管理
  7. *
  8. * @icon fa fa-circle-o
  9. */
  10. class Projectconfig extends Backend
  11. {
  12. /**
  13. * Projectconfig模型对象
  14. * @var \app\admin\model\service\info\Projectconfig
  15. */
  16. protected $model = null;
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->model = new \app\admin\model\service\info\Projectconfig;
  21. }
  22. /**
  23. * 编辑
  24. *
  25. * @param $ids
  26. * @return string
  27. * @throws DbException
  28. * @throws \think\Exception
  29. */
  30. public function edit($ids = 1)
  31. {
  32. $row = $this->model->get($ids);
  33. if (!$row) {
  34. \app\admin\model\service\info\Projectconfig::create(['service_mobile'=>'18200000000','cooperate_mobile'=>'18200000000','user_notice'=>'切换到北京、上海、广州、成都、郑州体验效果更好','skill_notice'=>'这是一个服务端小广播','shop_notice'=>'这是一个商户端小广播','refund_notice'=>'1、这是一个退款注意事项.','state'=>1,'cancel_minute'=>10,'comment_day'=>7]);
  35. $row = $this->model->get($ids);
  36. }
  37. $adminIds = $this->getDataLimitAdminIds();
  38. if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
  39. $this->error(__('You have no permission'));
  40. }
  41. if (false === $this->request->isPost()) {
  42. $this->view->assign('row', $row);
  43. return $this->view->fetch();
  44. }
  45. $params = $this->request->post('row/a');
  46. if (empty($params)) {
  47. $this->error(__('Parameter %s can not be empty', ''));
  48. }
  49. $params = $this->preExcludeFields($params);
  50. $result = false;
  51. Db::startTrans();
  52. try {
  53. //是否采用模型验证
  54. if ($this->modelValidate) {
  55. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  56. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  57. $row->validateFailException()->validate($validate);
  58. }
  59. $result = $row->allowField(true)->save($params);
  60. Db::commit();
  61. } catch (ValidateException|PDOException|Exception $e) {
  62. Db::rollback();
  63. $this->error($e->getMessage());
  64. }
  65. if (false === $result) {
  66. $this->error(__('No rows were updated'));
  67. }
  68. $this->success();
  69. }
  70. public function new()
  71. {
  72. $row = $this->model->get(1);
  73. if (!$row) {
  74. \app\admin\model\service\info\Projectconfig::create(['service_mobile'=>'18200000000','cooperate_mobile'=>'18200000000','user_notice'=>'切换到北京、上海、广州、成都、郑州体验效果更好','skill_notice'=>'这是一个服务端小广播','shop_notice'=>'这是一个商户端小广播','refund_notice'=>'1、这是一个退款注意事项.','state'=>1,'cancel_minute'=>10,'comment_day'=>7]);
  75. $row = $this->model->get(1);
  76. }
  77. $adminIds = $this->getDataLimitAdminIds();
  78. if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
  79. $this->error(__('You have no permission'));
  80. }
  81. if (false === $this->request->isPost()) {
  82. $this->view->assign('row', $row);
  83. return $this->view->fetch();
  84. }
  85. $params = $this->request->post('row/a');
  86. if (empty($params)) {
  87. $this->error(__('Parameter %s can not be empty', ''));
  88. }
  89. $params = $this->preExcludeFields($params);
  90. $result = false;
  91. Db::startTrans();
  92. try {
  93. //是否采用模型验证
  94. if ($this->modelValidate) {
  95. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  96. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  97. $row->validateFailException()->validate($validate);
  98. }
  99. $result = $row->allowField(true)->save($params);
  100. Db::commit();
  101. } catch (ValidateException|PDOException|Exception $e) {
  102. Db::rollback();
  103. $this->error($e->getMessage());
  104. }
  105. if (false === $result) {
  106. $this->error(__('No rows were updated'));
  107. }
  108. $this->success();
  109. }
  110. }