Merge pull request 'feat(StoreOrderCartInfoController): 添加了列表二功能及对应搜索条件' (#81) from erp into rose

Reviewed-on: #81
This commit is contained in:
mkm 2024-08-02 19:46:23 +08:00
commit b7ea08c41c
3 changed files with 133 additions and 57 deletions

View File

@ -5,6 +5,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;
/**
* 订单购物详情控制器
@ -25,5 +26,8 @@ class StoreOrderCartInfoController extends BaseAdminController
{
return $this->dataLists(new StoreOrderCartInfoLists());
}
public function listsTwo()
{
return $this->dataLists(new StoreOrderCartInfoTwoLists());
}
}

View File

@ -23,7 +23,6 @@ use app\common\model\system_store\SystemStore;
class StoreOrderCartInfoGroupLists extends BaseAdminDataLists implements ListsSearchInterface,ListsExcelInterface
{
public $order_arr;
/**
* @notes 设置搜索条件
* @return \string[][]
@ -49,54 +48,9 @@ class StoreOrderCartInfoGroupLists extends BaseAdminDataLists implements ListsSe
*/
public function lists(): array
{
if($this->request->get('start_time')){
$arr[]=['paid','=',1];
$arr[]=['refund_status','=',0];
if($this->request->get('store_id')){
$this->searchWhere[]=['store_id','=',$this->request->get('store_id')];
}
$order_arr=StoreOrder::where($this->searchWhere)->where($arr)->column('id');
}elseif($this->request->get('store_id')){
$arr[]=['paid','=',1];
$arr[]=['refund_status','=',0];
$this->searchWhere[]=['store_id','=',$this->request->get('store_id')];
$order_arr=StoreOrder::where($this->searchWhere)->where($arr)->column('id');
}else{
$order_arr=StoreOrder::whereDay('create_time')->where(['paid'=>1,'refund_status'=>0])->column('id');
}
if(!$order_arr){
return [];
}
$this->order_arr=$order_arr;
$this->searchWhere[]=['oid','in',$order_arr];
if($this->request->get('is_all')){
$query= StoreOrderCartInfo::where($this->searchWhere);
if($this->request->get('store_id')){
$query->field('store_id,product_id,price,SUM(total_price) as total_price,SUM(cart_num) as cart_num')->group('product_id');
}else{
$query->field('store_id,product_id,price,total_price,cart_num');
}
return $query->order('store_id 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();
$item['system_store']=SystemStore::where('id',$item['store_id'])->value('name');
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');
$item['cate_name'] = StoreCategory::where('id', $find['cate_id'])->value('name');
}else{
$item['image']='';//商品图片
$item['store_name']='';//商品名称
$item['store_info']='';//商品规格-(数据库叫商品简介)
}
return $item; //返回处理后的数据。
})
->toArray();
if($this->request->get('start_time')==''){
$this->searchWhere[]=['create_time','between',[strtotime(date('Y-m-d 00:00:00')),strtotime(date('Y-m-d 23:59:59'))]];
}
return StoreOrderCartInfo::where($this->searchWhere)
->field('product_id,price,SUM(total_price) as total_price,SUM(cart_num) as cart_num')->group('product_id')
@ -128,11 +82,7 @@ class StoreOrderCartInfoGroupLists extends BaseAdminDataLists implements ListsSe
*/
public function count(): int
{
if($this->order_arr){
return StoreOrderCartInfo::where($this->searchWhere)->group('product_id')->count();
}
return StoreOrderCartInfo::where($this->searchWhere)->count();
return StoreOrderCartInfo::where($this->searchWhere)->group('product_id')->count();
}
/**
@ -164,9 +114,6 @@ class StoreOrderCartInfoGroupLists extends BaseAdminDataLists implements ListsSe
'price' => '单价',
'total_price' => '总价',
];
if($this->order_arr){
$data['system_store'] = '店铺名称';
}
return $data;
}
}

View File

@ -0,0 +1,125 @@
<?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 StoreOrderCartInfoTwoLists
* @package app\admin\store_order_cart_info
*/
class StoreOrderCartInfoTwoLists extends BaseAdminDataLists implements ListsSearchInterface, ListsExcelInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author admin
* @date 2024/05/31 16:02
*/
public function setSearch(): array
{
return [
'=' => ['store_id'],
'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-d 00:00:00')), strtotime(date('Y-m-d 23:59:59'))]];
}
$query = StoreOrderCartInfo::where($this->searchWhere);
if ($this->request->get('is_group') == 1) {
$query->field('store_id,product_id,price,SUM(total_price) as total_price,SUM(cart_num) as cart_num')->group(['store_id', 'product_id']);
} else {
$query->field('store_id,product_id,price,total_price,cart_num');
}
return $query->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');
$item['cate_name'] = StoreCategory::where('id', $find['cate_id'])->value('name');
$item['system_store'] = SystemStore::where('id', $item['store_id'])->value('name');
}
return $item; //返回处理后的数据。
})
->toArray();
}
/**
* @notes 获取订单购物详情数量
* @return int
* @author admin
* @date 2024/05/31 16:02
*/
public function count(): int
{
if ($this->request->get('is_group') == 1) {
return StoreOrderCartInfo::where($this->searchWhere)->group('product_id')->count();
} else {
return StoreOrderCartInfo::where($this->searchWhere)->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 = [
'system_store' => '门店',
'store_name' => '商品名称',
'store_info' => '规格',
'unit_name' => '单位',
'cate_name' => '分类',
'cart_num' => '数量',
'price' => '单价',
'total_price' => '总价',
];
return $data;
}
}