Keys.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Think.Admin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2017 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://think.ctolog.com
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | github开源项目:https://github.com/zoujingli/Think.Admin
  12. // +----------------------------------------------------------------------
  13. namespace app\wechat\controller;
  14. use controller\BasicAdmin;
  15. use service\DataService;
  16. use think\Db;
  17. /**
  18. * 微信文章管理
  19. * Class Article
  20. * @package app\wechat\controller
  21. * @author Anyon <zoujingli@qq.com>
  22. * @date 2017/03/27 14:43
  23. */
  24. class Keys extends BasicAdmin {
  25. /**
  26. * 指定当前数据表
  27. * @var string
  28. */
  29. public $table = 'WechatKeys';
  30. /**
  31. * 显示关键字列表
  32. */
  33. public function index() {
  34. $this->assign('title', '微信关键字');
  35. $db = Db::name($this->table)->where('keys', 'not in', ['subscribe', 'default']);
  36. return $this->_list($db);
  37. }
  38. /**
  39. * 列表数据处理
  40. * @param array $data
  41. */
  42. protected function _index_data_filter(&$data) {
  43. $types = ['keys' => '关键字', 'image' => '图片', 'news' => '图文', 'music' => '音乐', 'text' => '文字', 'video' => '视频', 'voice' => '语音'];
  44. foreach ($data as &$vo) {
  45. $vo['type'] = isset($types[$vo['type']]) ? $types[$vo['type']] : $vo['type'];
  46. }
  47. }
  48. /**
  49. * 添加关键字
  50. * @return string
  51. */
  52. public function add() {
  53. $this->title = '添加关键字规则';
  54. return $this->_form($this->table, 'form');
  55. }
  56. /**
  57. * 编辑关键字
  58. * @return string
  59. */
  60. public function edit() {
  61. $this->title = '编辑关键字规则';
  62. return $this->_form($this->table, 'form');
  63. }
  64. /**
  65. * 表单处理
  66. * @param $data
  67. */
  68. protected function _form_filter($data) {
  69. if ($this->request->isPost() && isset($data['keys'])) {
  70. $db = Db::name($this->table)->where('keys', $data['keys']);
  71. !empty($data['id']) && $db->where('id', 'neq', $data['id']);
  72. $db->count() > 0 && $this->error('关键字已经存在,请使用其它关键字!');
  73. }
  74. }
  75. /**
  76. * 删除关键字
  77. */
  78. public function del() {
  79. if (DataService::update($this->table)) {
  80. $this->success("关键字删除成功!", '');
  81. }
  82. $this->error("关键字删除失败,请稍候再试!");
  83. }
  84. /**
  85. * 关键字禁用
  86. */
  87. public function forbid() {
  88. if (DataService::update($this->table)) {
  89. $this->success("关键字禁用成功!", '');
  90. }
  91. $this->error("关键字禁用失败,请稍候再试!");
  92. }
  93. /**
  94. * 关键字禁用
  95. */
  96. public function resume() {
  97. if (DataService::update($this->table)) {
  98. $this->success("关键字启用成功!", '');
  99. }
  100. $this->error("关键字启用失败,请稍候再试!");
  101. }
  102. /**
  103. * 关注默认回复
  104. */
  105. public function subscribe() {
  106. $this->assign('title', '编辑默认回复');
  107. return $this->_form($this->table, 'form');
  108. }
  109. /**
  110. * 关注默认回复表单处理
  111. * @param $data
  112. */
  113. protected function _subscribe_form_filter(&$data) {
  114. if ($this->request->isGet()) {
  115. $data = Db::name($this->table)->where('keys', 'subscribe')->find();
  116. }
  117. $data['keys'] = 'subscribe';
  118. }
  119. /**
  120. * 无配置默认回复
  121. */
  122. public function defaults() {
  123. $this->assign('title', '编辑无配置默认回复');
  124. return $this->_form($this->table, 'form');
  125. }
  126. /**
  127. * 无配置默认回复表单处理
  128. * @param $data
  129. */
  130. protected function _defaults_form_filter(&$data) {
  131. if ($this->request->isGet()) {
  132. $data = Db::name($this->table)->where('keys', 'default')->find();
  133. }
  134. $data['keys'] = 'default';
  135. }
  136. }