ChatUserLists.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop100%开源免费商用商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | 商业版本务必购买商业授权,以免引起法律纠纷
  8. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  9. // | gitee下载:https://gitee.com/likeshop_gitee
  10. // | github下载:https://github.com/likeshop-github
  11. // | 访问官网:https://www.likeshop.cn
  12. // | 访问社区:https://home.likeshop.cn
  13. // | 访问手册:http://doc.likeshop.cn
  14. // | 微信公众号:likeshop技术社区
  15. // | likeshop团队 版权所有 拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshopTeam
  18. // +----------------------------------------------------------------------
  19. namespace app\kefuapi\lists;
  20. use app\common\lists\ListsSearchInterface;
  21. use app\common\logic\ChatLogic;
  22. use app\common\model\ChatRelation;
  23. /**
  24. * 用户列表-(客服聊天页-用户列表)
  25. * Class ChatUserLists
  26. * @package app\kefuapi\lists
  27. */
  28. class ChatUserLists extends BaseKefuDataLists implements ListsSearchInterface
  29. {
  30. /**
  31. * @notes 设置搜索条件
  32. * @return array
  33. * @author 段誉
  34. * @date 2022/3/14 14:52
  35. */
  36. public function setSearch(): array
  37. {
  38. $this->searchWhere[] = ['kefu_id', '=', $this->kefuId];
  39. if (isset($this->params['nickname']) && $this->params['nickname']) {
  40. $this->searchWhere[] = ['nickname', 'like', '%' . $this->params['nickname'] . '%'];
  41. }
  42. return $this->searchWhere;
  43. }
  44. /**
  45. * @notes 获取排序
  46. * @param $onlineUser
  47. * @return string
  48. * @author 段誉
  49. * @date 2022/3/14 14:52
  50. */
  51. public function getOrderRaw($onlineUser)
  52. {
  53. $exp = 'update_time desc';
  54. if (!empty($onlineUser)) {
  55. $user_id = implode(",", $onlineUser);
  56. $exp = "field(user_id," . $user_id . ") desc, update_time desc";
  57. }
  58. return $exp;
  59. }
  60. /**
  61. * @notes 获取用户列表
  62. * @return array
  63. * @author 段誉
  64. * @date 2022/3/14 14:52
  65. */
  66. public function lists(): array
  67. {
  68. $this->setSearch();
  69. $onlineUser = ChatLogic::getOnlineUser();
  70. $lists = ChatRelation::where($this->searchWhere)
  71. ->limit($this->limitOffset, $this->limitLength)
  72. ->orderRaw($this->getOrderRaw($onlineUser))
  73. ->select()->toArray();
  74. foreach ($lists as &$item) {
  75. $item['online'] = 0;
  76. if (in_array($item['user_id'], $onlineUser)) {
  77. $item['online'] = 1;
  78. }
  79. if (empty($item['msg'])) {
  80. $item['update_time'] = '';
  81. }
  82. }
  83. return $lists;
  84. }
  85. /**
  86. * @notes 列表数量
  87. * @return int
  88. * @author 段誉
  89. * @date 2022/3/14 14:53
  90. */
  91. public function count(): int
  92. {
  93. return ChatRelation::where($this->searchWhere)->count();
  94. }
  95. }