Auto.php 4.0 KB

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