Mini.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. namespace app\admin\controller\send\message;
  3. use app\common\controller\Backend;
  4. use app\main\service\MiniProgramService;
  5. use think\Controller;
  6. use think\Request;
  7. /**
  8. * 高级群发消息图文消息
  9. *
  10. * @icon fa fa-circle-o
  11. */
  12. class Mini extends Backend
  13. {
  14. /**
  15. * SendMessageText模型对象
  16. */
  17. protected $model = null;
  18. protected $noNeedRight = ['add','edit'];
  19. public function _initialize()
  20. {
  21. parent::_initialize();
  22. }
  23. /**
  24. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个方法
  25. * 因此在当前控制器中可不用编写增删改查的代码,如果需要自己控制这部分逻辑
  26. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  27. */
  28. /**
  29. * 添加
  30. */
  31. public function add()
  32. {
  33. if ($this->request->isPost())
  34. {
  35. $params = $this->request->post("row/a");
  36. if ($params)
  37. {
  38. /*
  39. * 已经弃用,如果为了兼容老版可取消注释
  40. foreach ($params as $k => &$v)
  41. {
  42. $v = is_array($v) ? implode(',', $v) : $v;
  43. }
  44. */
  45. if ($this->dataLimit)
  46. {
  47. $params[$this->dataLimitField] = $this->auth->id;
  48. }
  49. try
  50. {
  51. //是否采用模型验证
  52. if ($this->modelValidate)
  53. {
  54. $name = basename(str_replace('\\', '/', get_class($this->model)));
  55. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : true) : $this->modelValidate;
  56. $this->model->validate($validate);
  57. }
  58. $result = $this->model->allowField(true)->save($params);
  59. if ($result !== false)
  60. {
  61. $this->success();
  62. }
  63. else
  64. {
  65. $this->error($this->model->getError());
  66. }
  67. }
  68. catch (\think\exception\PDOException $e)
  69. {
  70. $this->error($e->getMessage());
  71. }
  72. }
  73. $this->error(__('Parameter %s can not be empty', ''));
  74. }
  75. $miniPages = MiniProgramService::instance()->getMiniPage();
  76. $this->assign('miniPages',$miniPages);
  77. $isWrite = MiniProgramService::instance()->miniWrite($this->auth->id,$this->group);
  78. $this->assign('isWrite',$isWrite);
  79. return $this->view->fetch();
  80. }
  81. /**
  82. * 编辑
  83. */
  84. public function edit($ids = NULL)
  85. {
  86. $row = $this->request->get();
  87. if (!$row)
  88. $this->error(__('No Results were found'));
  89. $adminIds = $this->getDataLimitAdminIds();
  90. if (is_array($adminIds))
  91. {
  92. if (!in_array($row[$this->dataLimitField], $adminIds))
  93. {
  94. $this->error(__('You have no permission'));
  95. }
  96. }
  97. if ($this->request->isPost())
  98. {
  99. $params = $this->request->post("row/a");
  100. if ($params)
  101. {
  102. /*
  103. * 已经弃用,如果为了兼容老版可取消注释
  104. foreach ($params as $k => &$v)
  105. {
  106. $v = is_array($v) ? implode(',', $v) : $v;
  107. }
  108. */
  109. try
  110. {
  111. //是否采用模型验证
  112. if ($this->modelValidate)
  113. {
  114. $name = basename(str_replace('\\', '/', get_class($this->model)));
  115. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : true) : $this->modelValidate;
  116. $row->validate($validate);
  117. }
  118. $result = $row->allowField(true)->save($params);
  119. if ($result !== false)
  120. {
  121. $this->success();
  122. }
  123. else
  124. {
  125. $this->error($row->getError());
  126. }
  127. }
  128. catch (\think\exception\PDOException $e)
  129. {
  130. $this->error($e->getMessage());
  131. }
  132. }
  133. $this->error(__('Parameter %s can not be empty', ''));
  134. }
  135. $miniPages = MiniProgramService::instance()->getMiniPage();
  136. $isWrite = MiniProgramService::instance()->miniWrite($this->auth->id,$this->group);
  137. $this->assign('isWrite',$isWrite);
  138. $this->assign('miniPages',$miniPages);
  139. $this->view->assign('row', $row);
  140. return $this->view->fetch();
  141. }
  142. }