feat(ProductStatisticLogic): 修改商品统计逻辑并优化查询性能

This commit is contained in:
mkm 2024-06-21 18:05:28 +08:00
parent 3c0848a4e4
commit 2bec4ba97c

View File

@ -32,7 +32,7 @@ class ProductStatisticLogic extends BaseLogic
'SUM(collect_num) as collect',
'ROUND((COUNT(distinct(pay_uid))-1)/COUNT(distinct(uid)),2) as changes',
'COUNT(distinct(pay_uid))-1 as repeats'
])->group('product_id')->order('pay' , ' desc')->limit(20)->select()->toArray();
])->group('product_id')->order('pay'.' desc')->limit(20)->select()->toArray();
foreach ($list as $key => &$item) {
$find=StoreProduct::where('id',$item['product_id'])->field('store_name,image')->find();
$item['store_name']=$find['store_name'];
@ -45,6 +45,6 @@ class ProductStatisticLogic extends BaseLogic
$item['repeats'] = bcdiv(count(StoreProductLog::where($where)->where('type', 'pay')->where('product_id', $item['product_id'])->field('count(pay_uid) as p')->group('pay_uid')->having('p>1')->select()), $item['repeats'], 2);
}
}
return array_merge($list);
return $list;
}
}