multi-store/app/statistics/logic/ProductLogic.php

52 lines
2.2 KiB
PHP

<?php
namespace app\statistics\logic;
use app\common\logic\BaseLogic;
use app\common\model\store_branch_product\StoreBranchProduct;
class ProductLogic extends BaseLogic
{
public static function Count($store_id)
{
$todayProductCount=StoreBranchProduct::where('store_id',$store_id)->count();
$yestertodayProductCount=StoreBranchProduct::where('store_id',$store_id)->where('create_time', '<',strtotime(date('Y-md'))-1)->count();
if ($yestertodayProductCount == 0 ||$todayProductCount==0) {
$weeklyProductTotalGrowthRate = 0;
} else {
$weeklyProductTotalGrowthRate = ($todayProductCount - $yestertodayProductCount) / $yestertodayProductCount * 100;
}
$todayNewProductCount=StoreBranchProduct::where('store_id',$store_id)->whereDay('create_time')->count();
$yestertodayNewProductCount=StoreBranchProduct::where('store_id',$store_id)->whereDay('create_time', 'yesterday')->count();
if ($yestertodayProductCount == 0 ||$todayProductCount==0) {
$weeklyNewProductTotalGrowthRate = 0;
} else {
$weeklyNewProductTotalGrowthRate = ($todayNewProductCount - $yestertodayNewProductCount) / $yestertodayNewProductCount * 100;
}
$data = [
"totalProductCounInfo" => [
"todayProductCount" => $todayProductCount,
"yestertodayProductCount" => $yestertodayProductCount,
"weeklyProductTotalGrowthRate" => $weeklyProductTotalGrowthRate
],
"newProductCountInfo" => [
"todayNewProductCount" => 0,
"yestertodayNewProductCount" => 0,
"weeklyNewProductTotalGrowthRate" => $weeklyNewProductTotalGrowthRate
],
"merchantCountInfo" => [
"todayMerchantCount" => 1,
"yestertodayMerchantCount" => 1,
"weeklyMerchantGrowthRate" => 0
]
];
return $data;
}
public static function sales($store_id){
$select=StoreBranchProduct::where('store_id',$store_id)->limit(10)->order('sales desc')->field('id,store_name,image,sales')->select();
return $select?->toArray();
}
}