Chat.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace app\supplier\model\chat;
  3. use app\common\model\plus\chat\Chat as ChatModel;
  4. /**
  5. * 客服消息模型类
  6. */
  7. class Chat extends ChatModel
  8. {
  9. /**
  10. * 隐藏字段
  11. */
  12. protected $hidden = [
  13. 'app_id',
  14. 'status',
  15. 'update_time'
  16. ];
  17. //消息列表
  18. public function getList($user, $data)
  19. {
  20. $model = new ChatRelation();
  21. if ($data['nickName']) {
  22. $model = $model->where('ju.nickName', 'like', '%' . $data['nickName'] . '%');
  23. }
  24. $list = $model->with(['user', 'supplier.logo'])
  25. ->where(['supplier_user_id' => $user['supplier_user_id']])
  26. ->order('update_time desc')
  27. ->paginate($data);
  28. foreach ($list as $key => &$value) {
  29. $value['newMessage'] = $this->where('user_id', '=', $value['user_id'])
  30. ->where('supplier_user_id', '=', $value['supplier_user_id'])
  31. ->order('chat_id desc')
  32. ->find();
  33. }
  34. return $list;
  35. }
  36. //获取聊天信息
  37. public function getMessage($data, $user)
  38. {
  39. $list = $this->with(['user', 'supplier.logo'])
  40. ->where('supplier_user_id', '=', $user['supplier_user_id'])
  41. ->where('user_id', '=', $data['user_id'])
  42. ->order('chat_id desc')
  43. ->paginate($data);
  44. return $list;
  45. }
  46. //获取消息条数
  47. public function mCount($user)
  48. {
  49. $num = 0;
  50. if ($user) {
  51. $where[] = ['user_id', '=', $user['user_id']];
  52. $where[] = ['status', '=', 0];
  53. $where[] = ['msg_type', '=', 1];
  54. $num = $this->where($where)->count();
  55. }
  56. return $num;
  57. }
  58. }