Auto.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. /**
  20. * 关注自动回复
  21. * Class Auto
  22. * @package app\wechat\controller
  23. */
  24. class Auto extends Controller
  25. {
  26. /**
  27. * 消息类型
  28. * @var array
  29. */
  30. public $types = [
  31. 'text' => '文字', 'news' => '图文',
  32. 'image' => '图片', 'music' => '音乐',
  33. 'video' => '视频', 'voice' => '语音',
  34. ];
  35. /**
  36. * 关注自动回复
  37. * @auth true
  38. * @menu true
  39. * @throws \think\db\exception\DataNotFoundException
  40. * @throws \think\db\exception\DbException
  41. * @throws \think\db\exception\ModelNotFoundException
  42. */
  43. public function index()
  44. {
  45. $this->title = '关注自动回复';
  46. $query = WechatAuto::mQuery()->like('code,type');
  47. $query->equal('status')->dateBetween('create_at')->order('time asc')->page();
  48. }
  49. /**
  50. * 列表数据处理
  51. * @param array $data
  52. */
  53. protected function _index_page_filter(array &$data)
  54. {
  55. foreach ($data as &$vo) {
  56. $vo['type'] = $this->types[$vo['type']] ?? $vo['type'];
  57. }
  58. }
  59. /**
  60. * 添加自动回复
  61. * @auth true
  62. */
  63. public function add()
  64. {
  65. $this->title = '添加自动回复';
  66. WechatAuto::mForm('form');
  67. }
  68. /**
  69. * 编辑自动回复
  70. * @auth true
  71. */
  72. public function edit()
  73. {
  74. $this->title = '编辑自动回复';
  75. WechatAuto::mForm('form');
  76. }
  77. /**
  78. * 添加数据处理
  79. * @param array $data
  80. */
  81. protected function _form_filter(array &$data)
  82. {
  83. if (empty($data['code'])) {
  84. $data['code'] = CodeExtend::uniqidNumber(18, 'AM');
  85. }
  86. if ($this->request->isGet()) {
  87. $public = dirname($this->request->basefile(true));
  88. $this->defaultImage = "{$public}/static/theme/img/image.png";
  89. } else {
  90. $data['content'] = strip_tags($data['content'] ?? '', '<a>');
  91. }
  92. }
  93. /**
  94. * 表单结果处理
  95. * @param boolean $result
  96. */
  97. protected function _form_result(bool $result)
  98. {
  99. if ($result !== false) {
  100. $this->success('恭喜, 关键字保存成功!', 'javascript:history.back()');
  101. } else {
  102. $this->error('关键字保存失败, 请稍候再试!');
  103. }
  104. }
  105. /**
  106. * 修改规则状态
  107. * @auth true
  108. */
  109. public function state()
  110. {
  111. WechatAuto::mSave($this->_vali([
  112. 'status.in:0,1' => '状态值范围异常!',
  113. 'status.require' => '状态值不能为空!',
  114. ]));
  115. }
  116. /**
  117. * 删除自动回复
  118. * @auth true
  119. */
  120. public function remove()
  121. {
  122. WechatAuto::mDelete();
  123. }
  124. }