Support.php 7.2 KB

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