Support.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 海豚PHP框架 [ DolphinPHP ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2016~2019 广东卓锐软件有限公司 [ http://www.zrthink.com ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://dolphinphp.com
  8. // +----------------------------------------------------------------------
  9. namespace app\cms\admin;
  10. use app\admin\controller\Admin;
  11. use app\common\builder\ZBuilder;
  12. use app\cms\model\Support as SupportModel;
  13. /**
  14. * 客服控制器
  15. * @package app\cms\admin
  16. */
  17. class Support extends Admin
  18. {
  19. public function index()
  20. {
  21. // 查询
  22. $map = $this->getMap();
  23. // 排序
  24. $order = $this->getOrder();
  25. // 数据列表
  26. $data_list = SupportModel::where($map)->order($order)->paginate();
  27. $search = [
  28. 'name' => '客服名称',
  29. 'qq' => 'QQ',
  30. 'msn' => 'MSN',
  31. 'taobao' => '淘宝旺旺',
  32. 'alibaba' => '阿里旺旺',
  33. 'skype' => 'SKYPE'
  34. ];
  35. // 使用ZBuilder快速创建数据表格
  36. return ZBuilder::make('table')
  37. ->setPageTips('添加的QQ需要到【shang.qq.com】登录后在【商家沟通组建—设置】开启QQ的在线状态,否则将显示“未启用”<br>开启和关闭在线客服功能,以及更多设置,请在 <a class="alert-link link-effect" href="'.url('admin/system/index', ['group' => 'cms']).'">系统设置</a> 中操作。')
  38. ->setSearch($search) // 设置搜索框
  39. ->addColumns([ // 批量添加数据列
  40. ['id', 'ID'],
  41. ['name', '客服名称', 'text.edit'],
  42. ['qq', 'QQ'],
  43. ['msn', 'MSN'],
  44. ['taobao', '淘宝旺旺'],
  45. ['alibaba', '阿里旺旺'],
  46. ['skype', 'SKYPE'],
  47. ['create_time', '创建时间', 'datetime'],
  48. ['sort', '排序', 'text.edit'],
  49. ['status', '状态', 'switch'],
  50. ['right_button', '操作', 'btn']
  51. ])
  52. ->addTopButtons('add,enable,disable,delete') // 批量添加顶部按钮
  53. ->addRightButtons(['edit', 'delete' => ['data-tips' => '删除后无法恢复。']]) // 批量添加右侧按钮
  54. ->addOrder('id,name,create_time,update_time')
  55. ->addValidate('Support', 'name')
  56. ->setRowList($data_list) // 设置表格数据
  57. ->fetch(); // 渲染模板
  58. }
  59. /**
  60. * 新增
  61. * @author 蔡伟明 <314013107@qq.com>
  62. * @return mixed
  63. * @throws \think\Exception
  64. */
  65. public function add()
  66. {
  67. // 保存数据
  68. if ($this->request->isPost()) {
  69. // 表单数据
  70. $data = $this->request->post();
  71. // 验证
  72. $result = $this->validate($data, 'Support');
  73. if(true !== $result) $this->error($result);
  74. if ($support = SupportModel::create($data)) {
  75. // 记录行为
  76. action_log('support_add', 'cms_support', $support['id'], UID, $data['name']);
  77. $this->success('新增成功', 'index');
  78. } else {
  79. $this->error('新增失败');
  80. }
  81. }
  82. // 显示添加页面
  83. return ZBuilder::make('form')
  84. ->addFormItems([
  85. ['text', 'name', '客服名称'],
  86. ['text', 'qq', 'QQ号码'],
  87. ['text', 'msn', 'MSN号码'],
  88. ['text', 'taobao', '淘宝旺旺'],
  89. ['text', 'alibaba', '阿里旺旺'],
  90. ['text', 'skype', 'SKYPE'],
  91. ['text', 'sort', '排序', '', 100],
  92. ['radio', 'status', '立即启用', '', ['否', '是'], 1]
  93. ])
  94. ->fetch();
  95. }
  96. /**
  97. * 编辑
  98. * @param null $id 客服id
  99. * @author 蔡伟明 <314013107@qq.com>
  100. * @return mixed
  101. * @throws \think\Exception
  102. */
  103. public function edit($id = null)
  104. {
  105. if ($id === null) $this->error('缺少参数');
  106. // 保存数据
  107. if ($this->request->isPost()) {
  108. // 表单数据
  109. $data = $this->request->post();
  110. // 验证
  111. $result = $this->validate($data, 'Support');
  112. if(true !== $result) $this->error($result);
  113. if (SupportModel::update($data)) {
  114. // 记录行为
  115. action_log('support_edit', 'cms_support', $id, UID, $data['name']);
  116. $this->success('编辑成功', 'index');
  117. } else {
  118. $this->error('编辑失败');
  119. }
  120. }
  121. $info = SupportModel::get($id);
  122. // 显示编辑页面
  123. return ZBuilder::make('form')
  124. ->addFormItems([
  125. ['hidden', 'id'],
  126. ['text', 'name', '客服名称'],
  127. ['text', 'qq', 'QQ号码'],
  128. ['text', 'msn', 'MSN号码'],
  129. ['text', 'taobao', '淘宝旺旺'],
  130. ['text', 'alibaba', '阿里旺旺'],
  131. ['text', 'skype', 'SKYPE'],
  132. ['text', 'sort', '排序'],
  133. ['radio', 'status', '立即启用', '', ['否', '是']]
  134. ])
  135. ->setFormData($info)
  136. ->fetch();
  137. }
  138. /**
  139. * 删除客服
  140. * @param array $record 行为日志
  141. * @author 蔡伟明 <314013107@qq.com>
  142. * @throws \think\Exception
  143. * @throws \think\exception\PDOException
  144. */
  145. public function delete($record = [])
  146. {
  147. return $this->setStatus('delete');
  148. }
  149. /**
  150. * 启用客服
  151. * @param array $record 行为日志
  152. * @author 蔡伟明 <314013107@qq.com>
  153. * @throws \think\Exception
  154. * @throws \think\exception\PDOException
  155. */
  156. public function enable($record = [])
  157. {
  158. return $this->setStatus('enable');
  159. }
  160. /**
  161. * 禁用客服
  162. * @param array $record 行为日志
  163. * @author 蔡伟明 <314013107@qq.com>
  164. * @throws \think\Exception
  165. * @throws \think\exception\PDOException
  166. */
  167. public function disable($record = [])
  168. {
  169. return $this->setStatus('disable');
  170. }
  171. /**
  172. * 设置客服状态:删除、禁用、启用
  173. * @param string $type 类型:delete/enable/disable
  174. * @param array $record
  175. * @author 蔡伟明 <314013107@qq.com>
  176. * @throws \think\Exception
  177. * @throws \think\exception\PDOException
  178. */
  179. public function setStatus($type = '', $record = [])
  180. {
  181. $ids = $this->request->isPost() ? input('post.ids/a') : input('param.ids');
  182. $support_title = SupportModel::where('id', 'in', $ids)->column('name');
  183. return parent::setStatus($type, ['support_'.$type, 'cms_support', 0, UID, implode('、', $support_title)]);
  184. }
  185. /**
  186. * 快速编辑
  187. * @param array $record 行为日志
  188. * @author 蔡伟明 <314013107@qq.com>
  189. * @return mixed
  190. */
  191. public function quickEdit($record = [])
  192. {
  193. $id = input('post.pk', '');
  194. $field = input('post.name', '');
  195. $value = input('post.value', '');
  196. $support = SupportModel::where('id', $id)->value($field);
  197. $details = '字段(' . $field . '),原值(' . $support . '),新值:(' . $value . ')';
  198. return parent::quickEdit(['support_edit', 'cms_support', $id, UID, $details]);
  199. }
  200. }