From 07b1ebc3c89a0ee991a300be2584b28dc320b2d1 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 3 Aug 2024 18:04:52 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E6=9C=88=E9=94=80?= =?UTF-8?q?=E5=94=AE=E5=95=86=E5=93=81=E7=BB=9F=E8=AE=A1=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/WorkbenchController.php | 8 +- .../StoreOrderCartInfoController.php | 16 +++ .../StoreOrderCartInfoGroupMonthLists.php | 122 ++++++++++++++++++ .../StoreOrderCartInfoLogic.php | 44 +++++++ 4 files changed, 189 insertions(+), 1 deletion(-) create mode 100644 app/admin/lists/store_order_cart_info/StoreOrderCartInfoGroupMonthLists.php create mode 100644 app/admin/logic/store_order_cart_info/StoreOrderCartInfoLogic.php diff --git a/app/admin/controller/WorkbenchController.php b/app/admin/controller/WorkbenchController.php index 027a06cd..86053d80 100644 --- a/app/admin/controller/WorkbenchController.php +++ b/app/admin/controller/WorkbenchController.php @@ -15,6 +15,7 @@ namespace app\admin\controller; use app\admin\lists\store_order_cart_info\StoreOrderCartInfoGroupLists; +use app\admin\lists\store_order_cart_info\StoreOrderCartInfoGroupMonthLists; use app\admin\logic\statistic\ProductStatisticLogic; use app\admin\logic\statistic\TradeStatisticLogic; use app\admin\logic\statistic\UserStatisticLogic; @@ -230,9 +231,14 @@ class WorkbenchController extends BaseAdminController */ public function product_order(){ return $this->dataLists(new StoreOrderCartInfoGroupLists()); - } + /** + * 月销售商品统计 + */ + public function product_month_order(){ + return $this->dataLists(new StoreOrderCartInfoGroupMonthLists()); + } /** * 格式化时间 * @param $time diff --git a/app/admin/controller/store_order_cart_info/StoreOrderCartInfoController.php b/app/admin/controller/store_order_cart_info/StoreOrderCartInfoController.php index 8683acbc..ba3e1629 100644 --- a/app/admin/controller/store_order_cart_info/StoreOrderCartInfoController.php +++ b/app/admin/controller/store_order_cart_info/StoreOrderCartInfoController.php @@ -6,6 +6,7 @@ namespace app\admin\controller\store_order_cart_info; use app\admin\controller\BaseAdminController; use app\admin\lists\store_order_cart_info\StoreOrderCartInfoLists; use app\admin\lists\store_order_cart_info\StoreOrderCartInfoTwoLists; +use app\admin\logic\store_order_cart_info\StoreOrderCartInfoLogic; /** * 订单购物详情控制器 @@ -30,4 +31,19 @@ class StoreOrderCartInfoController extends BaseAdminController { return $this->dataLists(new StoreOrderCartInfoTwoLists()); } + + public function curve(){ + $product_id=$this->request->get('product_id'); + $start_time=$this->request->get('start_time'); + $end_time=$this->request->get('end_time'); + 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); + + } } \ No newline at end of file diff --git a/app/admin/lists/store_order_cart_info/StoreOrderCartInfoGroupMonthLists.php b/app/admin/lists/store_order_cart_info/StoreOrderCartInfoGroupMonthLists.php new file mode 100644 index 00000000..f4398fd6 --- /dev/null +++ b/app/admin/lists/store_order_cart_info/StoreOrderCartInfoGroupMonthLists.php @@ -0,0 +1,122 @@ + 'create_time' + ]; + } + + + /** + * @notes 获取订单购物详情列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2024/05/31 16:02 + */ + public function lists(): array + { + + if($this->request->get('start_time')==''){ + $this->searchWhere[]=['create_time','between',[strtotime(date('Y-m-01 00:00:00')),strtotime(date('Y-m-t 23:59:59'))]]; + } + $this->searchWhere[]=['is_pay','=',1]; + $this->searchWhere[]=['status','>=',0]; + return StoreOrderCartInfo::where($this->searchWhere) + ->field('product_id,price,SUM(total_price) as total_price,SUM(cart_num) as cart_num')->group('product_id') + ->order('cart_num desc') + ->limit($this->limitOffset, $this->limitLength) + ->select()->each(function ($item) { + $find=StoreProduct::where('id',$item['product_id'])->field('image,unit,cate_id,store_name,store_info')->find(); + if($find){ + $item['image']=$find['image'];//商品图片 + $item['store_name']=$find['store_name'];//商品名称 + $item['store_info']=$find['store_info'];//商品规格 + $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name')??""; + }else{ + $item['image']='';//商品图片 + $item['store_name']='';//商品名称 + $item['store_info']='';//商品规格-(数据库叫商品简介) + $item['unit_name']='';// + } + return $item; //返回处理后的数据。 + }) + ->toArray(); + } + + + /** + * @notes 获取订单购物详情数量 + * @return int + * @author admin + * @date 2024/05/31 16:02 + */ + public function count(): int + { + return StoreOrderCartInfo::where($this->searchWhere)->group('product_id')->count(); + } + + /** + * @notes 导出文件名 + * @return string + * @author 乔峰 + * @date 2022/11/24 16:17 + */ + public function setFileName(): string + { + return '订单总商品统计'; + } + + + /** + * @notes 导出字段 + * @return string[] + * @author 乔峰 + * @date 2022/11/24 16:17 + */ + public function setExcelFields(): array + { + $data=[ + 'store_name' => '商品名称', + 'store_info' => '规格', + 'unit_name' => '单位', + 'cate_name' => '分类', + 'cart_num' => '数量', + 'price' => '单价', + 'total_price' => '总价', + ]; + return $data; + } +} diff --git a/app/admin/logic/store_order_cart_info/StoreOrderCartInfoLogic.php b/app/admin/logic/store_order_cart_info/StoreOrderCartInfoLogic.php new file mode 100644 index 00000000..9346281d --- /dev/null +++ b/app/admin/logic/store_order_cart_info/StoreOrderCartInfoLogic.php @@ -0,0 +1,44 @@ +=', 0]; + $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; + + } +}