feat(DemoController): 修改产品统计逻辑,优化查询性能

This commit is contained in:
mkm 2024-07-19 11:24:53 +08:00
parent dd5a03ee65
commit 4fde559f4d

View File

@ -48,14 +48,15 @@ class DemoController extends BaseLikeController
public function product_count_sotre_count()
{
$time = $this->request->get('date', date('Y-m-d'));
$data=SystemStore::where('is_show', 1)->field('id,introduction street_name')->select()->each(function ($item) {
$item['product_count'] = StoreBranchProduct::where('store_id', $item['id'])->count();
return $item;
$data=SystemStore::where('is_show', 1)->field('id,introduction street_name')->select()
->each(function (&$item) {
$item['product_count'] = Db::connect('demo')->name('store_branch_product')->where('store_id', $item['id'])->count();
});
//总商品
$townProductCount = StoreProduct::where('create_time','<=',strtotime($time))->count();
// $townProductCount = StoreProduct::where('create_time','<=',strtotime($time))->count();
$townProductCount = Db::connect('demo')->name('store_product')->where('create_time','<=',strtotime($time))->count();
//商品销量
$product_count = StoreBranchProduct::where('create_time','<=',strtotime($time))->group('product_id')->order('total_sales desc')->limit(20)->field('image,product_id,store_name,sum(sales) as total_sales')->select();
$product_count = Db::connect('demo')->name('store_branch_product')->where('create_time','<=',strtotime($time))->group('product_id')->order('total_sales desc')->limit(20)->field('image,product_id,store_name,sum(sales) as total_sales')->select();
//总销量
$productRankingTotal = 0;
foreach ($product_count as $item) {