diff --git a/app/admin/controller/WorkbenchController.php b/app/admin/controller/WorkbenchController.php index 027a06cd5..86053d804 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 8683acbc9..ba3e16292 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 000000000..f4398fd62 --- /dev/null +++ b/app/admin/lists/store_order_cart_info/StoreOrderCartInfoGroupMonthLists.php @@ -0,0 +1,122 @@ +<?php + +namespace app\admin\lists\store_order_cart_info; + + +use app\admin\lists\BaseAdminDataLists; +use app\common\enum\PayEnum; +use app\common\lists\ListsExcelInterface; +use app\common\lists\ListsSearchInterface; +use app\common\model\store_branch_product\StoreBranchProduct; +use app\common\model\store_category\StoreCategory; +use app\common\model\store_order\StoreOrder; +use app\common\model\store_order_cart_info\StoreOrderCartInfo; +use app\common\model\store_product\StoreProduct; +use app\common\model\store_product_unit\StoreProductUnit; +use app\common\model\system_store\SystemStore; + +/** + * 订单购物详情列表 + * Class StoreOrderCartInfoGroupMonthLists + * @package app\admin\store_order_cart_info + */ +class StoreOrderCartInfoGroupMonthLists extends BaseAdminDataLists implements ListsSearchInterface,ListsExcelInterface +{ + + /** + * @notes 设置搜索条件 + * @return \string[][] + * @author admin + * @date 2024/05/31 16:02 + */ + public function setSearch(): array + { + return [ + 'between_time' => '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 000000000..9346281d4 --- /dev/null +++ b/app/admin/logic/store_order_cart_info/StoreOrderCartInfoLogic.php @@ -0,0 +1,44 @@ +<?php + +namespace app\admin\logic\store_order_cart_info; + +use app\admin\logic\statistic\TradeStatisticLogic; +use app\common\logic\BaseLogic; +use app\common\model\store_order_cart_info\StoreOrderCartInfo; + +/** + * 订单购物详情表逻辑 + * Class StoreProductLogic + * @package app\admin\logic\store_order_cart_info + */ +class StoreOrderCartInfoLogic extends BaseLogic +{ + public function curve($product_id,$start_time,$end_time) + { + $store_order_cart_info = new StoreOrderCartInfo(); + $tradeStatisticLogic = new TradeStatisticLogic(); + $where[] = ['product_id', '=', $product_id]; + $where[] = ['is_pay', '=', 1]; + $where[] = ['status', '>=', 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; + + } +}