feat(ProductStatisticLogic): 修改商品统计逻辑并优化查询性能
This commit is contained in:
parent
3c0848a4e4
commit
2bec4ba97c
@ -32,7 +32,7 @@ class ProductStatisticLogic extends BaseLogic
|
|||||||
'SUM(collect_num) as collect',
|
'SUM(collect_num) as collect',
|
||||||
'ROUND((COUNT(distinct(pay_uid))-1)/COUNT(distinct(uid)),2) as changes',
|
'ROUND((COUNT(distinct(pay_uid))-1)/COUNT(distinct(uid)),2) as changes',
|
||||||
'COUNT(distinct(pay_uid))-1 as repeats'
|
'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) {
|
foreach ($list as $key => &$item) {
|
||||||
$find=StoreProduct::where('id',$item['product_id'])->field('store_name,image')->find();
|
$find=StoreProduct::where('id',$item['product_id'])->field('store_name,image')->find();
|
||||||
$item['store_name']=$find['store_name'];
|
$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);
|
$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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user