Merge pull request 'dev' (#96) from dev into rose

Reviewed-on: #96
This commit is contained in:
mkm 2024-08-03 21:18:07 +08:00
commit 188904a63b
4 changed files with 208 additions and 1 deletions

View File

@ -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

View File

@ -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,22 @@ 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');
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('请选择商品');
}
$res=(new StoreOrderCartInfoLogic())->curve($product_id,$start_time,$end_time);
return $this->data($res);
}
}

View File

@ -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;
}
}

View File

@ -0,0 +1,60 @@
<?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;
$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;
}
}