searchWhere[] = ['kefu_id', '=', $this->kefuId]; if (isset($this->params['nickname']) && $this->params['nickname']) { $this->searchWhere[] = ['nickname', 'like', '%' . $this->params['nickname'] . '%']; } return $this->searchWhere; } /** * @notes 获取排序 * @param $onlineUser * @return string * @author 段誉 * @date 2022/3/14 14:52 */ public function getOrderRaw($onlineUser) { $exp = 'update_time desc'; if (!empty($onlineUser)) { $user_id = implode(",", $onlineUser); $exp = "field(user_id," . $user_id . ") desc, update_time desc"; } return $exp; } /** * @notes 获取用户列表 * @return array * @author 段誉 * @date 2022/3/14 14:52 */ public function lists(): array { $this->setSearch(); $onlineUser = ChatLogic::getOnlineUser(); $lists = ChatRelation::where($this->searchWhere) ->limit($this->limitOffset, $this->limitLength) ->orderRaw($this->getOrderRaw($onlineUser)) ->select()->toArray(); foreach ($lists as &$item) { $item['online'] = 0; if (in_array($item['user_id'], $onlineUser)) { $item['online'] = 1; } if (empty($item['msg'])) { $item['update_time'] = ''; } } return $lists; } /** * @notes 列表数量 * @return int * @author 段誉 * @date 2022/3/14 14:53 */ public function count(): int { return ChatRelation::where($this->searchWhere)->count(); } }