From c8c7333ec748bc0cd897dd168a1d4a0466057ba3 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 3 Aug 2024 21:17:38 +0800 Subject: [PATCH] 1 --- .../StoreOrderCartInfoController.php | 9 ++-- .../StoreOrderCartInfoLogic.php | 50 ++++++++++++------- 2 files changed, 39 insertions(+), 20 deletions(-) diff --git a/app/admin/controller/store_order_cart_info/StoreOrderCartInfoController.php b/app/admin/controller/store_order_cart_info/StoreOrderCartInfoController.php index ba3e1629..60d41c4c 100644 --- a/app/admin/controller/store_order_cart_info/StoreOrderCartInfoController.php +++ b/app/admin/controller/store_order_cart_info/StoreOrderCartInfoController.php @@ -35,13 +35,16 @@ class StoreOrderCartInfoController extends BaseAdminController public function curve(){ $product_id=$this->request->get('product_id'); $start_time=$this->request->get('start_time'); + if(empty($start_time)){ + $start_time=date('Y-m-01 00:00:00'); + } $end_time=$this->request->get('end_time'); + if(empty($end_time)){ + $end_time=date('Y-m-t 23:59:59'); + } if(empty($product_id)){ return $this->fail('请选择商品'); } - if(empty($start_time) || empty($end_time)){ - return $this->fail('请选择时间'); - } $res=(new StoreOrderCartInfoLogic())->curve($product_id,$start_time,$end_time); return $this->data($res); diff --git a/app/admin/logic/store_order_cart_info/StoreOrderCartInfoLogic.php b/app/admin/logic/store_order_cart_info/StoreOrderCartInfoLogic.php index 9346281d..84c9a84f 100644 --- a/app/admin/logic/store_order_cart_info/StoreOrderCartInfoLogic.php +++ b/app/admin/logic/store_order_cart_info/StoreOrderCartInfoLogic.php @@ -13,7 +13,7 @@ use app\common\model\store_order_cart_info\StoreOrderCartInfo; */ class StoreOrderCartInfoLogic extends BaseLogic { - public function curve($product_id,$start_time,$end_time) + public function curve($product_id, $start_time, $end_time) { $store_order_cart_info = new StoreOrderCartInfo(); $tradeStatisticLogic = new TradeStatisticLogic(); @@ -23,22 +23,38 @@ class StoreOrderCartInfoLogic extends BaseLogic $timeKey = $tradeStatisticLogic->TimeConvert(['start_time' => $start_time, 'end_time' => $end_time]); $time['timeKey'] = $timeKey; - $totalCartNum= $store_order_cart_info->getCurveData($where, $time, 'sum(cart_num)'); - $totalCartNum = $tradeStatisticLogic->trendYdata((array)$totalCartNum, $timeKey); - $data=[]; - if($totalCartNum){ - $data['xAxis']=$totalCartNum['x']; - $data['series']=[ - [ - 'name'=>'销量', - 'smooth'=>'true', - 'type'=>'line', - 'yAxisIndex'=>1, - 'data'=>$totalCartNum['y'] - ] - ]; - } - return $data; + $totalCartNum1 = $store_order_cart_info->getCurveData($where, $time, 'sum(cart_num)'); + $totalCartNum1 = $tradeStatisticLogic->trendYdata((array)$totalCartNum1, $timeKey); + $totalCartNum2 = $store_order_cart_info->getCurveData($where, $time, 'sum(total_price)'); + $totalCartNum2 = $tradeStatisticLogic->trendYdata((array)$totalCartNum2, $timeKey); + + $value1=[]; + $value2=[]; + foreach($totalCartNum1['y'] as $k=>$v){ + $value1[]=$v; + } + foreach($totalCartNum2['y'] as $k=>$v){ + $value2[]=$v; + } + $data = []; + $data['xAxis'] = $totalCartNum1['x'] ?? []; + $data['series'] = [ + [ + 'name' => '销量', + 'smooth' => 'true', + 'type' => 'line', + 'yAxisIndex' => 1, + 'value' =>$value1 + ] + ,[ + 'name' => '金额', + 'smooth' => 'true', + 'type' => 'line', + 'yAxisIndex' => 1, + 'value' => $value2 + ] + ]; + return $data; } }