瀏覽代碼

问答订单的聊天记录,其他聊天记录要屏蔽问答订单的,问答聊天记录不能删除,

lizhen_gitee 4 周之前
父節點
當前提交
41e64f5018

+ 83 - 1
app/Http/Controllers/Api/ChatController.php

@@ -262,6 +262,7 @@ class ChatController extends BaseController
         $refer_id = $request->input('refer_id', 0);
         $refer_id = $request->input('refer_id', 0);
         $shop_good_id = $request->input('shop_good_id', 0);
         $shop_good_id = $request->input('shop_good_id', 0);
         $voter_id = _abs(_empty_default_($request->voter_id, 0));
         $voter_id = _abs(_empty_default_($request->voter_id, 0));
+        $ask_order_id = _abs(_empty_default_($request->ask_order_id, 0));
 
 
         if(_empty_($uid) || _empty_($oid)){
         if(_empty_($uid) || _empty_($oid)){
             return $this->fail(200001);
             return $this->fail(200001);
@@ -299,7 +300,7 @@ class ChatController extends BaseController
             return $this->fail(200000, [], '抱歉,您没有聊天权限');
             return $this->fail(200000, [], '抱歉,您没有聊天权限');
         }
         }
 
 
-        $model = WxContRepositories::add($uid, $oid, $chat_content, $chat_image, $chat_audio_url, $chat_audio_length, $refer_id, 0, 0, $shop_good_id, null, 0, $voter_id);
+        $model = WxContRepositories::add($uid, $oid, $chat_content, $chat_image, $chat_audio_url, $chat_audio_length, $refer_id, 0, 0, $shop_good_id, null, 0, $voter_id,$ask_order_id); //通用聊天
 
 
         if($model){
         if($model){
             $websocket_id = GatewayUtils::uid2client_id($oid);
             $websocket_id = GatewayUtils::uid2client_id($oid);
@@ -370,6 +371,7 @@ class ChatController extends BaseController
                 $query->where('user_id', $oid)
                 $query->where('user_id', $oid)
                     ->where('object_id', $uid);
                     ->where('object_id', $uid);
             })
             })
+            ->where('expand_type','!=',9)  //排除问答聊天,因为要独立
             ->orderByRaw('id DESC')
             ->orderByRaw('id DESC')
             ->simplePaginate($limit);
             ->simplePaginate($limit);
 
 
@@ -420,6 +422,10 @@ class ChatController extends BaseController
                     }else if($v->expand_type == 8){
                     }else if($v->expand_type == 8){
                         $v->mode = 'voter';
                         $v->mode = 'voter';
                         $v->voter_id = $v->expand_id;
                         $v->voter_id = $v->expand_id;
+                    }else if($v->expand_type == 9){
+                        //仅占用
+                        $v->mode = 'ask_order';
+                        $v->ask_order_id = $v->expand_id;
                     }else if(in_array($v->expand_type, [101, 102, 103, 104, 105, 106, 107, 108, 109, 110])){
                     }else if(in_array($v->expand_type, [101, 102, 103, 104, 105, 106, 107, 108, 109, 110])){
                         $v->mode = 'review';
                         $v->mode = 'review';
                     }else{
                     }else{
@@ -692,6 +698,10 @@ class ChatController extends BaseController
                 }
                 }
             }
             }
 
 
+            if(!_empty_($v->ask_order_id)){
+                //仅占用
+            }
+
             if(!_empty_($v->shop_good_id)){
             if(!_empty_($v->shop_good_id)){
                 $data = WxShopGoods::where('id', $v->shop_good_id)->first()->toArray();
                 $data = WxShopGoods::where('id', $v->shop_good_id)->first()->toArray();
                 if($data) {
                 if($data) {
@@ -788,6 +798,78 @@ class ChatController extends BaseController
     }
     }
 
 
     /**
     /**
+     * 查询用户问答订单聊天记录
+     * @param Request $request
+     * @return \Illuminate\Http\JsonResponse
+     */
+    public function getUserAskOrderChat(Request $request, $limit = 6)
+    {
+
+        $uid = $request->uid;
+        $oid = $request->oid;
+        $ask_order_id = $request->ask_order_id;
+
+        if(_empty_($uid) || _empty_($oid)){
+            return $this->fail(200001);
+        }
+
+        $data = WxChat::where(function ($query) use ($uid, $oid) {
+            $query->where('user_id', $uid)
+                ->where('object_id', $oid);
+        })
+            ->orWhere(function ($query) use ($uid, $oid) {
+                $query->where('user_id', $oid)
+                    ->where('object_id', $uid);
+            })
+            ->where('expand_type',9)            //只要问答订单的
+            ->where('expand_id',$ask_order_id)  //只要问答订单的
+            ->orderByRaw('id DESC')
+            ->simplePaginate($limit);
+
+        $data->map(function ($v) use ($uid){
+            $v->type = 'user';
+            $imgList = array();
+            array_push($imgList, ['img_url' => $v->chat_image]);
+            $v->imgList = $imgList;
+            $v->user = WxUser::where('id', $v->user_id)->first(FieldUtils::userInfoColums());
+            $v->datetime = format_datetime($v->created_at);
+
+            if($v->chat_audio_url && $v->chat_audio_length){
+                $v->mode = 'audio';
+            }else if($v->chat_image){
+                $v->mode = 'img';
+            }else{
+                $v->mode = 'text';
+            }
+
+            if(!_empty_($v->chat_audio_length)){
+                $min = (int)($v->chat_audio_length / 60);
+                if($min < 10){
+                    $min = '0'.$min;
+                }
+                $sec = $v->chat_audio_length % 60;
+                if($sec < 10){
+                    $sec = '0'.$sec;
+                }
+                $v->chat_audio_length = $min.':'.$sec;
+            }
+
+            $allowable[] = [
+                'text' => '复制',
+                'type' => 'copy',
+                'id' => $v->id,
+                'raw' => strip_tags($v->chat_content),
+                'icon' => 'mini-icon mini-fuzhi'
+            ];
+            $v->allowable = $allowable;
+
+            return $v;
+        });
+
+        return $this->success($data);
+    }
+
+    /**
      * 已读对应用户信息
      * 已读对应用户信息
      * @param Request $request
      * @param Request $request
      * @return \Illuminate\Http\JsonResponse
      * @return \Illuminate\Http\JsonResponse

+ 3 - 1
app/Http/Controllers/Api/MessagesController.php

@@ -180,7 +180,9 @@ class MessagesController extends BaseController
         $uid = $request->uid;
         $uid = $request->uid;
         if($uid && $uid > 0){
         if($uid && $uid > 0){
             $data = WxChat::where([['user_id','=', $uid],['chat_state','=', 0]])
             $data = WxChat::where([['user_id','=', $uid],['chat_state','=', 0]])
-                ->orWhere([['object_id','=', $uid],['chat_state','=', 0]])->orderBy('id', 'desc')->get();
+                ->orWhere([['object_id','=', $uid],['chat_state','=', 0]])
+                ->where('expand_type','!=',9)
+                ->orderBy('id', 'desc')->get();
 
 
             //  二维数组去重
             //  二维数组去重
             $res = array();
             $res = array();

+ 1 - 1
app/Jobs/ChatExpireCleanJob.php

@@ -43,7 +43,7 @@ class ChatExpireCleanJob implements ShouldQueue
 
 
         //
         //
         $after_days = Settings::get('chat_expire_days', 90);
         $after_days = Settings::get('chat_expire_days', 90);
-        $chats = WxChat::where('created_at', '<', Carbon::now()->subDays($after_days))->get();
+        $chats = WxChat::where('created_at', '<', Carbon::now()->subDays($after_days))->where('expand_type','!=',9)->get();
         $clean_chats = 0;
         $clean_chats = 0;
         $clean_images = 0;
         $clean_images = 0;
         if($chats){
         if($chats){

+ 2 - 0
app/Routes/api/v1.php

@@ -142,6 +142,8 @@ Route::group(
     Route::post('/massages/addChat', [ChatController::class, 'addChat'])->middleware('auth.userstate');
     Route::post('/massages/addChat', [ChatController::class, 'addChat'])->middleware('auth.userstate');
     // 查询用户聊天记录
     // 查询用户聊天记录
     Route::get('/massages/getUserChat', [ChatController::class, 'getUserChat']);
     Route::get('/massages/getUserChat', [ChatController::class, 'getUserChat']);
+    // 查询用户聊天记录
+    Route::get('/massages/getUserAskOrderChat', [ChatController::class, 'getUserAskOrderChat']);
     // 已读对应用户信息
     // 已读对应用户信息
     Route::get('/massages/readUserChat', [ChatController::class, 'readUserChat']);
     Route::get('/massages/readUserChat', [ChatController::class, 'readUserChat']);
     // 用户删除聊天记录
     // 用户删除聊天记录