Browse Source

判断首页接口的es数据是否存在

Cherry 1 year ago
parent
commit
2f0980b55f
1 changed files with 19 additions and 0 deletions
  1. 19 0
      application/api/controller/MobileController.php

+ 19 - 0
application/api/controller/MobileController.php

@@ -491,6 +491,25 @@ class MobileController extends UserApi
                }
            }
        }
+
+        // 判断数据有无
+        $mobile_ids = [];
+        foreach ($esData['data'] as $dv){
+            $mobile_ids[] = $dv['id'];
+        }
+        $mobile_db_ids=Mobile::whereIn('id',$mobile_ids)->column('id');
+        // es 需要删除的id
+        $mobile_ids_es_del = array_diff($mobile_ids,$mobile_db_ids);
+        if($mobile_ids_es_del){
+            EsMobileService::delMobiles($mobile_ids_es_del);
+            user_log("EsMobileService_indexList_delByMobile", $mobile_ids_es_del);
+            //foreach ($esData['data'] as $idk => $idv){
+            //     if(in_array($idv['id'],$mobile_ids_es_del)){
+            //        unset($esData['data'][$idk]);
+            //    }
+            // }
+        }
+
        $this->success('',$esData);
     }
     /**