diff --git a/app/statistics/controller/IndexController.php b/app/statistics/controller/IndexController.php index 0e4957275..e6f2ed0f4 100644 --- a/app/statistics/controller/IndexController.php +++ b/app/statistics/controller/IndexController.php @@ -2,6 +2,7 @@ namespace app\statistics\controller; +use app\admin\logic\statistic\TradeStatisticLogic; use app\common\controller\BaseLikeController; use app\statistics\logic\OrderLogic; use app\statistics\logic\ProductLogic; @@ -15,12 +16,13 @@ class IndexController extends BaseLikeController public function index() { + $time=$this->request->get('date',date('Y-m-d')); $store_id = $this->store_id; if($store_id){ $where['store_id'] = $store_id; } $where['paid'] = 1; - $res = OrderLogic::dayPayPrice($where); + $res = OrderLogic::dayPayPrice($where,$time); if (OrderLogic::hasError()) { return $this->fail(OrderLogic::getError()); //获取错误信息并返回错误信息 } @@ -28,7 +30,8 @@ class IndexController extends BaseLikeController } public function user() { - $today = strtotime(date('Y-m-d')); + $time=$this->request->get('date',date('Y-m-d')); + $today = strtotime($time); $dates=[]; // 循环输出前5天的日期 for ($i = 0; $i <= 4; $i++) { @@ -56,12 +59,13 @@ class IndexController extends BaseLikeController */ public function product_count() { + $time=$this->request->get('date',date('Y-m-d')); $store_id = $this->store_id; $where=[]; if($store_id){ $where['store_id'] = $store_id; } - $res = ProductLogic::Count($where); + $res = ProductLogic::Count($where,$time); if (ProductLogic::hasError()) { return $this->fail(ProductLogic::getError()); //获取错误信息并返回错误信息 } @@ -72,12 +76,13 @@ class IndexController extends BaseLikeController */ public function order_user_num_count() { + $time=$this->request->get('date',date('Y-m-d')); $store_id = $this->store_id; $where=[]; if($store_id){ $where['store_id'] = $store_id; } - $res = OrderLogic::Count($where); + $res = OrderLogic::Count($where,$time); if (ProductLogic::hasError()) { return $this->fail(ProductLogic::getError()); //获取错误信息并返回错误信息 } @@ -88,12 +93,13 @@ class IndexController extends BaseLikeController */ public function sales_ranking() { + $time=$this->request->get('date',date('Y-m-d')); $store_id = $this->store_id; $where=[]; if($store_id){ $where['store_id'] = $store_id; } - $res = ProductLogic::sales($where); + $res = OrderLogic::sales($where,$time); if (ProductLogic::hasError()) { return $this->fail(ProductLogic::getError()); //获取错误信息并返回错误信息 } @@ -104,38 +110,31 @@ class IndexController extends BaseLikeController */ public function user_trade_count() { - $dates = []; + $logic=(new TradeStatisticLogic()); + $leftToday = $logic->getTopLeftTrade(['create_time' => 'today']); + $leftyestoday = $logic->getTopLeftTrade(['create_time' => 'yestoday']); + $totalleft = [$leftToday, $leftyestoday]; + foreach ($totalleft as $k => $v) { + $left['name'] = "当日订单金额"; + $left['x'] = $v['curve']['x']; + $left['series'][$k]['money'] = round($v['total_money'], 2); + $left['series'][$k]['value'] = array_values($v['curve']['y']); + } - $today = new DateTime(); - $thirtyDaysAgo = new DateTime($today->format('Y-m-d')); - $thirtyDaysAgo->modify('-30 days'); - for ($i = 0; $i < 31; $i++) { - $date = new DateTime($thirtyDaysAgo->format('Y-m-d')); - $date->modify('+' . $i . ' days'); - $dates[] = $date->format('Y-m-d'); - } - $store_id = $this->store_id; - $where=[]; - if($store_id){ - $where['store_id'] = $store_id; - } - $res = UserLogic::TradeCount($where, $dates); - if (UserLogic::hasError()) { - return $this->fail(UserLogic::getError()); //获取错误信息并返回错误信息 - } - return $this->success('ok', $res); + return $this->data($left); } /** * 当日订单金额 */ public function street_currday_order_count() { + $time=$this->request->get('date',date('Y-m-d')); $store_id = $this->store_id; $where=[]; if($store_id){ $where['store_id'] = $store_id; } - $res = OrderLogic::Currday($where); + $res = OrderLogic::Currday($where,$time); if (ProductLogic::hasError()) { return $this->fail(ProductLogic::getError()); //获取错误信息并返回错误信息 } diff --git a/app/statistics/logic/OrderLogic.php b/app/statistics/logic/OrderLogic.php index 5c32bee1c..3f1617ac7 100644 --- a/app/statistics/logic/OrderLogic.php +++ b/app/statistics/logic/OrderLogic.php @@ -26,9 +26,8 @@ class OrderLogic extends BaseLogic ]; return $data; } - public static function Currday($where) + public static function Currday($where,$date) { - $date = date("Y-m-d"); $startTime = strtotime($date . ' 00:00:00'); // 当天的开始时间戳 $endTime = strtotime($date . ' 23:59:59'); // 当天的结束时间戳 @@ -57,14 +56,19 @@ class OrderLogic extends BaseLogic } return $data; } - public static function dayPayPrice($where) + public static function dayPayPrice($where,$time) { $todayAmount = UserRecharge::where($where) - ->whereDay('create_time') + ->whereDay('create_time',$time) ->sum('price'); $pay_price = StoreOrder::where($where) - ->whereDay('create_time') + ->whereDay('create_time',$time) ->sum('pay_price'); return bcadd($todayAmount, $pay_price, 2); } + + public static function sales($where,$time){ + $select=StoreOrder::where($where)->whereDay('create_time',$time)->limit(10)->order('id desc')->field('id,order_id,pay_price,create_time')->select(); + return $select?->toArray(); + } } diff --git a/app/statistics/logic/ProductLogic.php b/app/statistics/logic/ProductLogic.php index 2abe8ab06..8fad8de91 100644 --- a/app/statistics/logic/ProductLogic.php +++ b/app/statistics/logic/ProductLogic.php @@ -7,18 +7,18 @@ use app\common\model\store_branch_product\StoreBranchProduct; class ProductLogic extends BaseLogic { - public static function Count($where) + public static function Count($where,$time) { - $todayProductCount=StoreBranchProduct::where($where)->count(); - $yestertodayProductCount=StoreBranchProduct::where($where)->where('create_time', '<',strtotime(date('Y-md'))-1)->count(); + $todayProductCount=StoreBranchProduct::where($where)->whereDay($time)->count(); + $yestertodayProductCount=StoreBranchProduct::where($where)->where('create_time', '<',strtotime($time)-1)->count(); if ($yestertodayProductCount == 0 ||$todayProductCount==0) { $weeklyProductTotalGrowthRate = 0; } else { $weeklyProductTotalGrowthRate = ($todayProductCount - $yestertodayProductCount) / $yestertodayProductCount * 100; } - $todayNewProductCount=StoreBranchProduct::where($where)->whereDay('create_time')->count(); - $yestertodayNewProductCount=StoreBranchProduct::where($where)->whereDay('create_time', 'yesterday')->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(); if ($yestertodayProductCount == 0 ||$todayProductCount==0) { $weeklyNewProductTotalGrowthRate = 0; } else {