User.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace app\admin\controller\shopro\chat;
  3. use think\Db;
  4. use app\admin\controller\shopro\Common;
  5. use app\admin\model\shopro\chat\User as ChatUser;
  6. use app\admin\model\shopro\chat\ServiceLog;
  7. use app\admin\model\shopro\chat\Record;
  8. class User extends Common
  9. {
  10. public function _initialize()
  11. {
  12. parent::_initialize();
  13. $this->model = new ChatUser;
  14. }
  15. /**
  16. * 会话列表
  17. */
  18. public function index()
  19. {
  20. if (!$this->request->isAjax()) {
  21. return $this->view->fetch();
  22. }
  23. $user = $this->model->sheepFilter()->with(['user', 'customer_service'])->where('auth', 'user')->order('id desc')->paginate(request()->param('list_rows', 10));
  24. $this->success('获取成功', null, $user);
  25. }
  26. /**·
  27. * 删除会话
  28. *
  29. * @param $id
  30. * @return \think\Response
  31. */
  32. public function delete($id)
  33. {
  34. if (empty($id)) {
  35. $this->error(__('Parameter %s can not be empty', 'id'));
  36. }
  37. $id = explode(',', $id);
  38. $list = $this->model->where('id', 'in', $id)->select();
  39. Db::transaction(function () use ($list) {
  40. foreach ($list as $user) {
  41. // 删除这个会话的所有服务记录
  42. ServiceLog::where('chat_user_id', $user->id)->delete();
  43. // 删除这个会话的所有聊天记录
  44. Record::where('chat_user_id', $user->id)->delete();
  45. // 删除这个会话
  46. $user->delete();
  47. }
  48. });
  49. $this->success('删除成功');
  50. }
  51. }