Auto.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkAdmin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2022 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: https://thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // | 免费声明 ( https://thinkadmin.top/disclaimer )
  11. // +----------------------------------------------------------------------
  12. // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
  13. // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
  14. // +----------------------------------------------------------------------
  15. namespace app\wechat\controller;
  16. use app\wechat\model\WechatAuto;
  17. use think\admin\Controller;
  18. use think\admin\extend\CodeExtend;
  19. use think\admin\helper\QueryHelper;
  20. /**
  21. * 关注自动回复
  22. * Class Auto
  23. * @package app\wechat\controller
  24. */
  25. class Auto extends Controller
  26. {
  27. /**
  28. * 消息类型
  29. * @var array
  30. */
  31. public $types = [
  32. 'text' => '文字', 'news' => '图文',
  33. 'image' => '图片', 'music' => '音乐',
  34. 'video' => '视频', 'voice' => '语音',
  35. ];
  36. /**
  37. * 关注自动回复
  38. * @auth true
  39. * @menu true
  40. * @throws \think\db\exception\DataNotFoundException
  41. * @throws \think\db\exception\DbException
  42. * @throws \think\db\exception\ModelNotFoundException
  43. */
  44. public function index()
  45. {
  46. $this->type = input('get.type', 'index');
  47. WechatAuto::mQuery()->layTable(function () {
  48. $this->title = '关注自动回复';
  49. }, function (QueryHelper $query) {
  50. $query->like('code,type#mtype')->dateBetween('create_at');
  51. $query->where(['status' => intval($this->type === 'index')]);
  52. });
  53. }
  54. /**
  55. * 列表数据处理
  56. * @param array $data
  57. */
  58. protected function _index_page_filter(array &$data)
  59. {
  60. foreach ($data as &$vo) {
  61. $vo['type'] = $this->types[$vo['type']] ?? $vo['type'];
  62. }
  63. }
  64. /**
  65. * 添加自动回复
  66. * @auth true
  67. */
  68. public function add()
  69. {
  70. $this->title = '添加自动回复';
  71. WechatAuto::mForm('form');
  72. }
  73. /**
  74. * 编辑自动回复
  75. * @auth true
  76. */
  77. public function edit()
  78. {
  79. $this->title = '编辑自动回复';
  80. WechatAuto::mForm('form');
  81. }
  82. /**
  83. * 添加数据处理
  84. * @param array $data
  85. */
  86. protected function _form_filter(array &$data)
  87. {
  88. if (empty($data['code'])) {
  89. $data['code'] = CodeExtend::uniqidNumber(18, 'AM');
  90. }
  91. if ($this->request->isGet()) {
  92. $public = dirname($this->request->basefile(true));
  93. $this->defaultImage = "{$public}/static/theme/img/image.png";
  94. } else {
  95. $data['content'] = strip_tags($data['content'] ?? '', '<a>');
  96. }
  97. }
  98. /**
  99. * 表单结果处理
  100. * @param boolean $result
  101. */
  102. protected function _form_result(bool $result)
  103. {
  104. if ($result !== false) {
  105. $this->success('恭喜, 关键字保存成功!', 'javascript:history.back()');
  106. } else {
  107. $this->error('关键字保存失败, 请稍候再试!');
  108. }
  109. }
  110. /**
  111. * 修改规则状态
  112. * @auth true
  113. */
  114. public function state()
  115. {
  116. WechatAuto::mSave($this->_vali([
  117. 'status.in:0,1' => '状态值范围异常!',
  118. 'status.require' => '状态值不能为空!',
  119. ]));
  120. }
  121. /**
  122. * 删除自动回复
  123. * @auth true
  124. */
  125. public function remove()
  126. {
  127. WechatAuto::mDelete();
  128. }
  129. }