Text.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 Text extends Backend
  13. {
  14. /**
  15. * SendMessageText模型对象
  16. */
  17. protected $model = null;
  18. public function _initialize()
  19. {
  20. parent::_initialize();
  21. }
  22. /**
  23. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个方法
  24. * 因此在当前控制器中可不用编写增删改查的代码,如果需要自己控制这部分逻辑
  25. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  26. */
  27. /**
  28. * 添加
  29. */
  30. public function add()
  31. {
  32. if ($this->request->isPost())
  33. {
  34. $params = $this->request->post("row/a");
  35. if ($params)
  36. {
  37. /*
  38. * 已经弃用,如果为了兼容老版可取消注释
  39. foreach ($params as $k => &$v)
  40. {
  41. $v = is_array($v) ? implode(',', $v) : $v;
  42. }
  43. */
  44. if ($this->dataLimit)
  45. {
  46. $params[$this->dataLimitField] = $this->auth->id;
  47. }
  48. try
  49. {
  50. //是否采用模型验证
  51. if ($this->modelValidate)
  52. {
  53. $name = basename(str_replace('\\', '/', get_class($this->model)));
  54. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : true) : $this->modelValidate;
  55. $this->model->validate($validate);
  56. }
  57. $result = $this->model->allowField(true)->save($params);
  58. if ($result !== false)
  59. {
  60. $this->success();
  61. }
  62. else
  63. {
  64. $this->error($this->model->getError());
  65. }
  66. }
  67. catch (\think\exception\PDOException $e)
  68. {
  69. $this->error($e->getMessage());
  70. }
  71. }
  72. $this->error(__('Parameter %s can not be empty', ''));
  73. }
  74. $miniPages = MiniProgramService::instance()->getMiniPage();
  75. $isWrite = MiniProgramService::instance()->miniWrite($this->auth->id,$this->group);
  76. $this->assign('isWrite',$isWrite);
  77. $this->assign('miniPages',$miniPages);
  78. return $this->view->fetch();
  79. }
  80. }