71 lines
3.4 KiB
PHP
71 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace app\statistics\logic;
|
|
|
|
use app\common\logic\BaseLogic;
|
|
use app\common\model\store_branch_product\StoreBranchProduct;
|
|
use app\common\model\store_product\StoreProduct;
|
|
use app\common\model\system_store\SystemStore;
|
|
use think\facade\Db;
|
|
|
|
class ProductLogic extends BaseLogic
|
|
{
|
|
public static function Count($where, $time)
|
|
{
|
|
if (isset($where['store_id']) && $where['store_id'] > 0) {
|
|
$todayProductCount = Db::connect('demo')->name('store_branch_product')->where($where)->whereDay('create_time', $time)->count();
|
|
$yestertodayProductCount = Db::connect('demo')->name('store_branch_product')->where($where)->where('create_time', '<', strtotime($time) - 1)->count();
|
|
$todayNewProductCount = Db::connect('demo')->name('store_branch_product')->where($where)->whereDay('create_time', $time)->count();
|
|
$yestertodayNewProductCount = Db::connect('demo')->name('store_branch_product')->where($where)->whereDay('create_time', date('Y-m-d', strtotime($time) - 1))->count();
|
|
$where['id']=$where['store_id'];
|
|
unset($where['store_id']);
|
|
} else {
|
|
$todayProductCount = Db::connect('demo')->name('store_product')->whereDay('create_time', $time)->count();
|
|
$yestertodayProductCount = Db::connect('demo')->name('store_product')->count();
|
|
|
|
$todayNewProductCount = Db::connect('demo')->name('store_product')->whereDay('create_time', $time)->count();
|
|
$yestertodayNewProductCount = Db::connect('demo')->name('store_product')->whereDay('create_time', date('Y-m-d', strtotime($time) - 1))->count();
|
|
}
|
|
|
|
if ($yestertodayProductCount == 0 || $todayProductCount == 0) {
|
|
$weeklyProductTotalGrowthRate = 0;
|
|
} else {
|
|
$weeklyProductTotalGrowthRate = bcdiv(($todayProductCount - $yestertodayProductCount), $yestertodayProductCount) * 100;
|
|
}
|
|
|
|
|
|
if ($todayNewProductCount == 0 || $yestertodayNewProductCount == 0) {
|
|
$weeklyNewProductTotalGrowthRate = 0;
|
|
} else {
|
|
$weeklyNewProductTotalGrowthRate = bcdiv(($todayNewProductCount - $yestertodayNewProductCount), $yestertodayNewProductCount) * 100;
|
|
}
|
|
$todayMerchantCount = SystemStore::where($where)->whereDay('create_time', $time)->count();
|
|
$where['is_show'] = 1;
|
|
$yestertodayMerchantCount = SystemStore::where($where)->count();
|
|
$data = [
|
|
"totalProductCounInfo" => [
|
|
"todayProductCount" => $todayProductCount,
|
|
"yestertodayProductCount" => $yestertodayProductCount,
|
|
"weeklyProductTotalGrowthRate" => $weeklyProductTotalGrowthRate
|
|
],
|
|
"newProductCountInfo" => [
|
|
"todayNewProductCount" => 0,
|
|
"yestertodayNewProductCount" => 0,
|
|
"weeklyNewProductTotalGrowthRate" => $weeklyNewProductTotalGrowthRate
|
|
],
|
|
"merchantCountInfo" => [
|
|
"todayMerchantCount" => $todayMerchantCount,
|
|
"yestertodayMerchantCount" => $yestertodayMerchantCount,
|
|
"weeklyMerchantGrowthRate" => 0
|
|
]
|
|
];
|
|
return $data;
|
|
}
|
|
|
|
public static function sales($where)
|
|
{
|
|
$select = Db::connect('demo')->name('store_branch_product')->where($where)->limit(10)->order('sales desc')->field('id,store_name,image,sales')->select();
|
|
return $select?->toArray();
|
|
}
|
|
}
|