| xqd
@@ -31,26 +31,31 @@ class ChatController extends Controller
|
|
|
if(!$toUser = User::query()->where(['tencent_im_user_id'=>$request->tencent_im_user_id])->first()){
|
|
|
throw new Exception("对应用户不存在");
|
|
|
}
|
|
|
+ if(!ChatList::query()->where(['user_id'=>$user->id,'to_user_id'=>$toUser->id])->first()){
|
|
|
|
|
|
- $tencent_account =new TencentImAccountService();
|
|
|
- $tencent_friend =new TencentImFriendService();
|
|
|
- //检测是否已经导入IM账号
|
|
|
- $check_result = $tencent_account->accountCheck([$request->tencent_im_user_id]);
|
|
|
- if(!isset($check_result) || (isset($check_result['AccountStatus'])&&$check_result['AccountStatus']=="NotImported")){
|
|
|
- throw new Exception("对方账户错误");
|
|
|
- }
|
|
|
- $res = $tencent_friend->friendAddItem($user->tencent_im_user_id,$request->tencent_im_user_id);
|
|
|
+ $tencent_account =new TencentImAccountService();
|
|
|
+ $tencent_friend =new TencentImFriendService();
|
|
|
+ //检测是否已经导入IM账号
|
|
|
+ $check_result = $tencent_account->accountCheck([$request->tencent_im_user_id]);
|
|
|
+ if(!isset($check_result) || (isset($check_result['AccountStatus'])&&$check_result['AccountStatus']=="NotImported")){
|
|
|
+ throw new Exception("对方账户错误");
|
|
|
+ }
|
|
|
+ $res = $tencent_friend->friendAddItem($user->tencent_im_user_id,$request->tencent_im_user_id);
|
|
|
|
|
|
- ChatList::query()->firstOrCreate([
|
|
|
- 'user_id'=>$user->id,
|
|
|
- 'to_user_id'=>$toUser->id,
|
|
|
- 'atime'=>date('Y-m-d H:i:s'),
|
|
|
- ]);
|
|
|
- ChatList::query()->firstOrCreate([
|
|
|
- 'user_id'=>$toUser->id,
|
|
|
- 'to_user_id'=>$user->id,
|
|
|
- 'atime'=>date('Y-m-d H:i:s'),
|
|
|
- ]);
|
|
|
+ ChatList::query()->firstOrCreate([
|
|
|
+ 'user_id'=>$user->id,
|
|
|
+ 'to_user_id'=>$toUser->id,
|
|
|
+ 'atime'=>date('Y-m-d H:i:s'),
|
|
|
+ ]);
|
|
|
+ ChatList::query()->firstOrCreate([
|
|
|
+ 'user_id'=>$toUser->id,
|
|
|
+ 'to_user_id'=>$user->id,
|
|
|
+ 'atime'=>date('Y-m-d H:i:s'),
|
|
|
+ ]);
|
|
|
+
|
|
|
+ }else{
|
|
|
+ $res = [];
|
|
|
+ }
|
|
|
DB::commit();
|
|
|
}catch (\Exception $exception){
|
|
|
DB::rollBack();
|