feat(ProductLogic): 修改统计逻辑使用数据库连接

This commit is contained in:
mkm 2024-07-19 11:32:20 +08:00
parent 4fde559f4d
commit 5cd73f3f40

View File

@ -6,24 +6,25 @@ use app\common\logic\BaseLogic;
use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_product\StoreProduct; use app\common\model\store_product\StoreProduct;
use app\common\model\system_store\SystemStore; use app\common\model\system_store\SystemStore;
use think\facade\Db;
class ProductLogic extends BaseLogic class ProductLogic extends BaseLogic
{ {
public static function Count($where, $time) public static function Count($where, $time)
{ {
if (isset($where['store_id']) && $where['store_id'] > 0) { if (isset($where['store_id']) && $where['store_id'] > 0) {
$todayProductCount = StoreBranchProduct::where($where)->whereDay('create_time', $time)->count(); $todayProductCount = Db::connect('demo')->name('store_branch_product')->where($where)->whereDay('create_time', $time)->count();
$yestertodayProductCount = StoreBranchProduct::where($where)->where('create_time', '<', strtotime($time) - 1)->count(); $yestertodayProductCount = Db::connect('demo')->name('store_branch_product')->where($where)->where('create_time', '<', strtotime($time) - 1)->count();
$todayNewProductCount = StoreBranchProduct::where($where)->whereDay('create_time', $time)->count(); $todayNewProductCount = Db::connect('demo')->name('store_branch_product')->where($where)->whereDay('create_time', $time)->count();
$yestertodayNewProductCount = StoreBranchProduct::where($where)->whereDay('create_time', date('Y-m-d', strtotime($time) - 1))->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']; $where['id']=$where['store_id'];
unset($where['store_id']); unset($where['store_id']);
} else { } else {
$todayProductCount = StoreProduct::whereDay('create_time', $time)->count(); $todayProductCount = Db::connect('demo')->name('store_product')->whereDay('create_time', $time)->count();
$yestertodayProductCount = StoreProduct::count(); $yestertodayProductCount = Db::connect('demo')->name('store_product')->count();
$todayNewProductCount = StoreProduct::whereDay('create_time', $time)->count(); $todayNewProductCount = Db::connect('demo')->name('store_product')->whereDay('create_time', $time)->count();
$yestertodayNewProductCount = StoreProduct::whereDay('create_time', date('Y-m-d', strtotime($time) - 1))->count(); $yestertodayNewProductCount = Db::connect('demo')->name('store_product')->whereDay('create_time', date('Y-m-d', strtotime($time) - 1))->count();
} }
if ($yestertodayProductCount == 0 || $todayProductCount == 0) { if ($yestertodayProductCount == 0 || $todayProductCount == 0) {
@ -63,7 +64,7 @@ class ProductLogic extends BaseLogic
public static function sales($where) public static function sales($where)
{ {
$select = StoreBranchProduct::where($where)->limit(10)->order('sales desc')->field('id,store_name,image,sales')->select(); $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(); return $select?->toArray();
} }
} }