|
|
@@ -3010,11 +3010,12 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
}
|
|
|
// var_dump("sector_types",$all_sector_types);
|
|
|
// var_dump("must_type",$must_type);
|
|
|
- // return $is_must;
|
|
|
+ // return $must_type;
|
|
|
|
|
|
|
|
|
// 非必须通栏的随机处理
|
|
|
$not_must_type = array_diff($all_sector_types,$must_type);
|
|
|
+
|
|
|
$total = count($not_must_type);
|
|
|
$randomCount = mt_rand(0, $total); // 可能为0(无元素)或任意数量,最多等于数组长度
|
|
|
$and_type = $rule->and_type ?? [];
|
|
|
@@ -3059,20 +3060,28 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
// 必需通栏
|
|
|
$must_type = array_intersect($all_sector_types,$must_type);
|
|
|
// return $must_type;
|
|
|
+// 此代码用于从 $sectors 数组中筛选出必需的通栏数据。
|
|
|
+// 1. array_keys($must_type) 获取 $must_type 数组的所有键名
|
|
|
+// 2. array_flip() 将这些键名作为值,生成一个新数组
|
|
|
+// 3. array_intersect_key() 比较 $sectors 和上述新数组的键名,返回键名相同的元素
|
|
|
+// 4. array_values() 重新索引返回的数组,使其键名从 0 开始连续递增
|
|
|
+// 最终得到的 $must_sector 数组包含了 $sectors 中对应 $must_type 键名的所有必需通栏数据
|
|
|
$must_sector = array_values(array_intersect_key($sectors, array_flip(array_keys($must_type))));
|
|
|
$must_count = count($must_sector);
|
|
|
// var_dump("must_sector",$must_sector);
|
|
|
- var_dump("must_count",$must_count);
|
|
|
+ // var_dump("must_count",$must_count);
|
|
|
// return $must_sector;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
// 计算随机之后减去必需的通栏,查询重复通栏可用数量;(目前的这些通栏没有重复的同类别通栏)
|
|
|
$repeat_num = $sector_num-$rand_count-$must_count;
|
|
|
// 组合起来通栏
|
|
|
$sector_zuhe1 = array_merge($must_sector,$random_sector);
|
|
|
-
|
|
|
+ $sector_ids = array_column($sector_zuhe1, 'id');
|
|
|
+ // var_dump("sector_ids",$sector_ids);
|
|
|
+ // return [
|
|
|
+ // 'random_sector'=>$random_sector,
|
|
|
+ // 'must_sector'=>$must_sector,
|
|
|
+ // 'sector_ids'=>$sector_ids,
|
|
|
+ // ];
|
|
|
// 各类型通栏最大数量数量限制 = 规则最大数量-已经存在的通栏数量(目前的通栏不会有重复的,所以只是-1)
|
|
|
$rule_repeat = (array)$rule->type_max;
|
|
|
$sector_zuhe1_type = array_count_values(array_column($sector_zuhe1,'sector_type'));
|
|
|
@@ -3083,8 +3092,10 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
}
|
|
|
}
|
|
|
var_dump("repeat_num",$repeat_num);
|
|
|
- // return $sector_zuhe1;
|
|
|
-
|
|
|
+ // return array_intersect($sector_zuhe1,$must_sector);
|
|
|
+ if(count(array_intersect($sector_zuhe1,$must_sector)) != count($must_sector)){
|
|
|
+ return '此页面缺少必要通栏!';
|
|
|
+ }
|
|
|
// 剩余通栏进行重复处理
|
|
|
// $rule_repeat = (array)$rule->type_max;
|
|
|
// 取到可以重复的通栏类别
|
|
|
@@ -3149,12 +3160,13 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
$repeat_count = count($repeat_sector);
|
|
|
var_dump("repeat_count",$repeat_count);
|
|
|
// var_dump("repeat_sector", $repeat_sector);
|
|
|
- // return $repeat_sector;
|
|
|
-
|
|
|
+ // return ($data['page'] == '2' || $data['page'] == 2);
|
|
|
+
|
|
|
$sector = array_merge($repeat_sector,$sector_zuhe1);
|
|
|
+ // var_dump("sector",$sector);
|
|
|
// 处理头条及轮播图在随机通栏中的特殊位置特殊处理
|
|
|
$sector_specal_sort = array_column($sector,'sector_type');
|
|
|
- if((in_array(6,$sector_specal_sort) || in_array(7,$sector_specal_sort)) ){
|
|
|
+ if(in_array(6,$sector_specal_sort) || in_array(7,$sector_specal_sort) || in_array(5,$sector_specal_sort)){
|
|
|
|
|
|
$toutiao_key = array_search(6,$sector_specal_sort) ?? null;
|
|
|
$pic_key = array_search(7,$sector_specal_sort) ?? null;
|
|
|
@@ -3165,26 +3177,38 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
$sort_1 = $sector[0];
|
|
|
$sort_2 = $sector[1];
|
|
|
$sort_3 = $sector[2];
|
|
|
- if($data['page'] == 1){
|
|
|
- if(!empty($toutiao_key)){
|
|
|
+
|
|
|
+ // return $sector_specal_sort;
|
|
|
+ // return [
|
|
|
+ // 'sector_ids' => array_column($sector_zuhe1,'id'),
|
|
|
+ // // 'repeat_sector' => $repeat_sector,
|
|
|
+ // 'sector_id' => array_column($sector,'id'),
|
|
|
+ // 'array_intersect' => count(array_intersect($sector,$must_sector)),
|
|
|
+ // 'old' => [ $toutiao_key,$pic_key,$cat_key],
|
|
|
+ // 'new' => [ $sort_1,$sort_2,$sort_3]
|
|
|
+ // ];
|
|
|
+ if($data['page'] == 1 || $data['page'] == '1'){
|
|
|
+ if($toutiao_key){
|
|
|
$sector[0] = $toutiao;
|
|
|
$sector[$toutiao_key] = $sort_1;
|
|
|
$sector[1] = $pic;
|
|
|
$sector[$pic_key] = $sort_2;
|
|
|
- }else{
|
|
|
+ }
|
|
|
+ if($cat_key){
|
|
|
$sector[0] = $pic;
|
|
|
$sector[$pic_key] = $sort_1;
|
|
|
}
|
|
|
}
|
|
|
- if($data['page'] == 2){
|
|
|
+ if($data['page'] == '2' || $data['page'] == 2){
|
|
|
$sector[0] = $cat;
|
|
|
$sector[$cat_key] = $sort_1;
|
|
|
- if(!empty($toutiao_key)){
|
|
|
+ if($toutiao_key && $pic_key){
|
|
|
$sector[1] = $toutiao;
|
|
|
$sector[$toutiao_key] = $sort_2;
|
|
|
$sector[2] = $pic;
|
|
|
$sector[$pic_key] = $sort_3;
|
|
|
- }else{
|
|
|
+ }
|
|
|
+ if($pic_key){
|
|
|
$sector[1] = $pic;
|
|
|
$sector[$pic_key] = $sort_2;
|
|
|
}
|
|
|
@@ -3193,6 +3217,10 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
|
|
|
}
|
|
|
$sector_id = array_column($sector,'id');
|
|
|
+
|
|
|
+ // if(count(array_intersect($sector,$must_sector)) != count($must_sector)){
|
|
|
+ // return '此页面缺少必要通栏!';
|
|
|
+ // }
|
|
|
$data['page'] = $page;
|
|
|
$component[] = $this->randomComponent($sector_id,$data,$sector);
|
|
|
var_dump("sector_id",$sector_id);
|