wesmiler 1 년 전
부모
커밋
d986ee3d84
1개의 변경된 파일11개의 추가작업 그리고 6개의 파일을 삭제
  1. 11 6
      app/Services/Api/VideoService.php

+ 11 - 6
app/Services/Api/VideoService.php

@@ -223,22 +223,27 @@ class VideoService extends BaseService
 
         // 随机优先匹配推送
         $match = false;
-        if($total > 3 && rand(100,999) > rand(100,999)){
+        $list = [];
+        if($total > 3 ){
             // 关联推荐数据
-            $match = true;
             $list = $countModel->selectRaw($field)
                 ->orderByRaw($uids?DB::raw("FIND_IN_SET(user_id,'".implode(',', $uids)."')"):'lev_a.create_time desc')
                 ->orderByRaw($order)
                 ->paginate($pageSize > 0 ? $pageSize : 9999999);
-        }else{
+            $list = $list ? $list->toArray() : [];
+        }
+
+        // 数据不够补充默认匹配数据
+        if($total<$pageSize){
             // 默认推荐数据
-            $list = $model->selectRaw($field)
+            $list1 = $model->selectRaw($field)
                 ->orderByRaw('lev_a.create_time desc')
                 ->orderByRaw($order)
                 ->paginate($pageSize > 0 ? $pageSize : 9999999);
+            $list1 = $list1 ? $list1->toArray() : [];
+            $list = array_merge($list, $list1);
         }
-
-        $list = $list ? $list->toArray() : [];
+        
         if ($list && $list['data']) {
             foreach ($list['data'] as &$item) {
                 $item['time_text'] = isset($item['create_time']) ? dateFormat($item['create_time'], 'Y-m-d H:i') : '';