feat(DemoController): 修改产品统计逻辑,优化查询性能
This commit is contained in:
parent
dd5a03ee65
commit
4fde559f4d
@ -48,14 +48,15 @@ class DemoController extends BaseLikeController
|
|||||||
public function product_count_sotre_count()
|
public function product_count_sotre_count()
|
||||||
{
|
{
|
||||||
$time = $this->request->get('date', date('Y-m-d'));
|
$time = $this->request->get('date', date('Y-m-d'));
|
||||||
$data=SystemStore::where('is_show', 1)->field('id,introduction street_name')->select()->each(function ($item) {
|
$data=SystemStore::where('is_show', 1)->field('id,introduction street_name')->select()
|
||||||
$item['product_count'] = StoreBranchProduct::where('store_id', $item['id'])->count();
|
->each(function (&$item) {
|
||||||
return $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;
|
$productRankingTotal = 0;
|
||||||
foreach ($product_count as $item) {
|
foreach ($product_count as $item) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user