Plan.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace app\admin\controller\wechat;
  3. use app\common\controller\Backend;
  4. use app\admin\model\WechatResponse;
  5. /**
  6. * 微信模版列表
  7. *
  8. * @icon fa fa-circle-o
  9. */
  10. class Plan extends Backend
  11. {
  12. protected $model = null;
  13. protected $noNeedRight = ['check_text_unique'];
  14. public function _initialize()
  15. {
  16. parent::_initialize();
  17. $this->model = new \app\admin\model\WechatPlan;
  18. $this->view->assign("hidedataList", $this->model->getHidedataList());
  19. }
  20. /**
  21. * 编辑
  22. */
  23. public function edit($ids = null)
  24. {
  25. $row = $this->model->get(['id' => $ids]);
  26. if (!$row) {
  27. $this->error(__('No Results were found'));
  28. }
  29. if ($this->request->isPost()) {
  30. $params = $this->request->post("row/a");
  31. if ($params) {
  32. $row->save($params);
  33. $this->success();
  34. }
  35. $this->error();
  36. }
  37. $this->view->assign("row", $row);
  38. return $this->view->fetch();
  39. }
  40. /**
  41. * 判断模版编号是否唯一
  42. * @internal
  43. */
  44. public function check_text_unique()
  45. {
  46. $row = $this->request->post("row/a");
  47. $except = $this->request->post("except");
  48. $text = isset($row['plan_id']) ? $row['plan_id'] : '';
  49. if ($this->model->where('plan_id', $text)->where(function ($query) use ($except) {
  50. if ($except) {
  51. $query->where('plan_id', '<>', $except);
  52. }
  53. })->count() == 0) {
  54. $this->success();
  55. } else {
  56. $this->error(__('Text already exists'));
  57. }
  58. }
  59. }