| | |
| | | */ |
| | | 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 |
| | | ]; |
| | | 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) { |