Plan.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 = model('WechatPlan');
  18. }
  19. /**
  20. * 编辑
  21. */
  22. public function edit($ids = null)
  23. {
  24. $row = $this->model->get(['id' => $ids]);
  25. if (!$row) {
  26. $this->error(__('No Results were found'));
  27. }
  28. if ($this->request->isPost()) {
  29. $params = $this->request->post("row/a");
  30. if ($params) {
  31. $row->save($params);
  32. $this->success();
  33. }
  34. $this->error();
  35. }
  36. $this->view->assign("row", $row);
  37. return $this->view->fetch();
  38. }
  39. /**
  40. * 判断价格是否唯一
  41. * @internal
  42. */
  43. public function check_text_unique()
  44. {
  45. $row = $this->request->post("row/a");
  46. $except = $this->request->post("except");
  47. $text = isset($row['price']) ? $row['price'] : '';
  48. if ($this->model->where('price', $text)->where(function ($query) use ($except) {
  49. if ($except) {
  50. $query->where('price', '<>', $except);
  51. }
  52. })->count() == 0) {
  53. $this->success();
  54. } else {
  55. $this->error(__('Text already exists'));
  56. }
  57. }
  58. }