diff --git a/app/statistics/logic/ProductLogic.php b/app/statistics/logic/ProductLogic.php index ad7d4c54..87d9f3c1 100644 --- a/app/statistics/logic/ProductLogic.php +++ b/app/statistics/logic/ProductLogic.php @@ -6,24 +6,25 @@ 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 = StoreBranchProduct::where($where)->whereDay('create_time', $time)->count(); - $yestertodayProductCount = StoreBranchProduct::where($where)->where('create_time', '<', strtotime($time) - 1)->count(); - $todayNewProductCount = StoreBranchProduct::where($where)->whereDay('create_time', $time)->count(); - $yestertodayNewProductCount = StoreBranchProduct::where($where)->whereDay('create_time', date('Y-m-d', strtotime($time) - 1))->count(); + $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 = StoreProduct::whereDay('create_time', $time)->count(); - $yestertodayProductCount = StoreProduct::count(); + $todayProductCount = Db::connect('demo')->name('store_product')->whereDay('create_time', $time)->count(); + $yestertodayProductCount = Db::connect('demo')->name('store_product')->count(); - $todayNewProductCount = StoreProduct::whereDay('create_time', $time)->count(); - $yestertodayNewProductCount = StoreProduct::whereDay('create_time', date('Y-m-d', strtotime($time) - 1))->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) { @@ -63,7 +64,7 @@ class ProductLogic extends BaseLogic 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(); } }