15313670163 5 месяцев назад
Родитель
Сommit
1d0004b7d0
1 измененных файлов с 24 добавлено и 8 удалено
  1. 24 8
      app/JsonRpc/PublicRpcService.php

+ 24 - 8
app/JsonRpc/PublicRpcService.php

@@ -2703,16 +2703,32 @@ class PublicRpcService implements PublicRpcServiceInterface
         if(empty($template)){
             return Result::error('此皮肤不存在!');
         }
-        $rule = TemplateRule::first();
-        if(empty($rule)){
-            return Result::error('此规则不存在!');
-        }
-        $template_id = $data['template_id'];
-        $index = $this->randomPage($rule,$template_id);
+        
+        // if(empty($rule)){
+        //     return Result::error('此规则不存在!');
+        // }
+        // $template_id = $data['template_id'];
+
+        $index = $this->randomPage($data);
         return Result::success($index);
     }
-    public function randomPage($template_id,$rule){
-        $sectors = Sector::where('template_id',$template_id)->limit(3)->get();
+    public function randomPage($data){
+        $rule = TemplateRule::first();
+        $index_rule = json_decode($rule['index_rule'],true);
+        // $zeroKeysPerItem = array_map(function ($item) {
+        // $zeroValues = array_filter($item, function ($value) {
+        //     return $value === 0;
+        // });
+        $index_sector_num = $index_rule[0];
+        $index_rule = json_encode($index_rule);
+
+        // 输出结果
+        // print_r($zeroKeysPerItem);
+        // $index_num = array_search(0, array_map($index_rule, $array ?? []));
+        $sectors = Sector::where('template_id',$data['template_id'])
+        ->where('page_type','like','%1%')
+        ->limit($index_sector_num)->get();
+        
         return $sectors;
     }