This commit is contained in:
mkm 2024-08-03 21:17:38 +08:00
parent 07b1ebc3c8
commit c8c7333ec7
2 changed files with 39 additions and 20 deletions

View File

@ -35,13 +35,16 @@ class StoreOrderCartInfoController extends BaseAdminController
public function curve(){ public function curve(){
$product_id=$this->request->get('product_id'); $product_id=$this->request->get('product_id');
$start_time=$this->request->get('start_time'); $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'); $end_time=$this->request->get('end_time');
if(empty($end_time)){
$end_time=date('Y-m-t 23:59:59');
}
if(empty($product_id)){ if(empty($product_id)){
return $this->fail('请选择商品'); return $this->fail('请选择商品');
} }
if(empty($start_time) || empty($end_time)){
return $this->fail('请选择时间');
}
$res=(new StoreOrderCartInfoLogic())->curve($product_id,$start_time,$end_time); $res=(new StoreOrderCartInfoLogic())->curve($product_id,$start_time,$end_time);
return $this->data($res); return $this->data($res);

View File

@ -13,7 +13,7 @@ use app\common\model\store_order_cart_info\StoreOrderCartInfo;
*/ */
class StoreOrderCartInfoLogic extends BaseLogic 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(); $store_order_cart_info = new StoreOrderCartInfo();
$tradeStatisticLogic = new TradeStatisticLogic(); $tradeStatisticLogic = new TradeStatisticLogic();
@ -23,22 +23,38 @@ class StoreOrderCartInfoLogic extends BaseLogic
$timeKey = $tradeStatisticLogic->TimeConvert(['start_time' => $start_time, 'end_time' => $end_time]); $timeKey = $tradeStatisticLogic->TimeConvert(['start_time' => $start_time, 'end_time' => $end_time]);
$time['timeKey'] = $timeKey; $time['timeKey'] = $timeKey;
$totalCartNum= $store_order_cart_info->getCurveData($where, $time, 'sum(cart_num)'); $totalCartNum1 = $store_order_cart_info->getCurveData($where, $time, 'sum(cart_num)');
$totalCartNum = $tradeStatisticLogic->trendYdata((array)$totalCartNum, $timeKey); $totalCartNum1 = $tradeStatisticLogic->trendYdata((array)$totalCartNum1, $timeKey);
$data=[];
if($totalCartNum){
$data['xAxis']=$totalCartNum['x'];
$data['series']=[
[
'name'=>'销量',
'smooth'=>'true',
'type'=>'line',
'yAxisIndex'=>1,
'data'=>$totalCartNum['y']
]
];
}
return $data;
$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;
} }
} }