| | |
| | | */ |
| | | public function createConversation($businessCardId, $participants = []) |
| | | { |
| | | $appId = self::$app_id; |
| | | // 检查是否已存在相同名片的会话 |
| | | $existing = $this->where('business_card_id', $businessCardId)->find(); |
| | | if ($existing) { |
| | |
| | | |
| | | $data = [ |
| | | 'business_card_id' => $businessCardId, |
| | | 'app_id' => $appId |
| | | 'app_id' => self::$app_id, |
| | | ]; |
| | | try { |
| | | $this->save($data); |
| | | $conversationId = $this->conversation_id; |
| | | // 添加参与者 |
| | | foreach ($participants as $userId) { |
| | | (new Participant())->addParticipant($conversationId, $userId, $appId); |
| | | (new Participant())->addParticipant($conversationId, $userId); |
| | | } |
| | | return $conversationId; |
| | | } catch (\Exception $e) { |
| | |
| | | */ |
| | | public function getUserConversations($param = []) |
| | | { |
| | | return $this->with(['businessCard', 'participants.user', 'messages']) |
| | | return $this->with(['businessCard', 'participants.user']) |
| | | ->order('update_time', 'desc') |
| | | ->paginate($param); |
| | | } |
| | |
| | | ->where('business_card_id', $businessCardId) |
| | | ->find(); |
| | | } |
| | | public function getConversationByBusinessCardUser($businessCardId,$userId) |
| | | { |
| | | $conversation_ids=(new Participant())->where('user_id',$userId)->column('conversation_id'); |
| | | return $this->with(['businessCard', 'participants.user']) |
| | | ->where('business_card_id', $businessCardId) |
| | | ->where('conversation_id', 'in', $conversation_ids) |
| | | ->find(); |
| | | } |
| | | |
| | | /** |
| | | * 更新会话时间 |