Plan.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. public function index()
  21. {
  22. //设置过滤方法
  23. $this->request->filter(['strip_tags', 'trim']);
  24. if ($this->request->isAjax()) {
  25. //如果发送的来源是Selectpage,则转发到Selectpage
  26. if ($this->request->request('keyField')) {
  27. $data = $this->selectpage()->getData();
  28. return $data;
  29. }
  30. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  31. /**
  32. * 获取企业信息
  33. */
  34. $where1 = is_sys_admin();
  35. $list = $this->model
  36. ->where($where)->where($where1)
  37. ->order($sort, $order)
  38. ->paginate($limit);
  39. foreach ($list as $k => $v) {
  40. }
  41. $result = array("total" => $list->total(), "rows" => $list->items());
  42. return json($result);
  43. }
  44. return $this->view->fetch();
  45. }
  46. /**
  47. * 编辑
  48. */
  49. public function edit($ids = null)
  50. {
  51. $row = $this->model->get(['id' => $ids]);
  52. if (!$row) {
  53. $this->error(__('No Results were found'));
  54. }
  55. if ($this->request->isPost()) {
  56. $params = $this->request->post("row/a");
  57. if ($params) {
  58. $row->save($params);
  59. $this->success();
  60. }
  61. $this->error();
  62. }
  63. $this->view->assign("row", $row);
  64. return $this->view->fetch();
  65. }
  66. /**
  67. * 判断模版编号是否唯一
  68. * @internal
  69. */
  70. public function check_text_unique()
  71. {
  72. $row = $this->request->post("row/a");
  73. $except = $this->request->post("except");
  74. $text = isset($row['plan_id']) ? $row['plan_id'] : '';
  75. if ($this->model->where('plan_id', $text)->where(function ($query) use ($except) {
  76. if ($except) {
  77. $query->where('plan_id', '<>', $except);
  78. }
  79. })->count() == 0) {
  80. $this->success();
  81. } else {
  82. $this->error(__('Text already exists'));
  83. }
  84. }
  85. }