From a3e73c3e37e38d95ca136723348c727dbe5ce364 Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Wed, 5 Jun 2024 15:20:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AE=A2=E5=8D=95=E5=88=97?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lists/store_order/StoreOrderLists.php | 18 +++++- app/common/logic/SystemStoreStaffLogic.php | 15 +++++ .../logic/store_order/StoreOrderLogic.php | 8 ++- app/common/model/store_order/StoreOrder.php | 6 ++ .../store_order/StoreOrderController.php | 59 +++++++++++++++---- 5 files changed, 89 insertions(+), 17 deletions(-) create mode 100644 app/common/logic/SystemStoreStaffLogic.php diff --git a/app/admin/lists/store_order/StoreOrderLists.php b/app/admin/lists/store_order/StoreOrderLists.php index 737a07a0a..b3c0923f2 100644 --- a/app/admin/lists/store_order/StoreOrderLists.php +++ b/app/admin/lists/store_order/StoreOrderLists.php @@ -28,7 +28,7 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface public function setSearch(): array { return [ - '=' => ['order_id', 'pay_type'], + '=' => ['order_id', 'pay_type', 'status'], ]; } @@ -44,13 +44,19 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface */ public function lists(): array { - return StoreOrder::with(['user', 'product' => function ($query) { + return StoreOrder::with(['user', 'staff', 'product' => function ($query) { $query->field(['id', 'oid', 'product_id', 'cart_info']); }])->where($this->searchWhere) + ->when(!empty($this->params['start_time']), function ($query) { + $query->whereTime('create_time', '>=', $this->params['start_time']); + }) + ->when(!empty($this->params['end_time']), function ($query) { + $query->whereTime('create_time', '<=', $this->params['end_time']); + }) ->when(!empty($this->request->adminInfo['store_id']), function ($query) { $query->where('store_id', '=', $this->request->adminInfo['store_id']); }) - ->field(['id', 'order_id', 'pay_price', 'pay_time', 'pay_type', 'status', 'uid']) + ->field(['id', 'store_id', 'staff_id', 'order_id', 'pay_price', 'pay_time', 'pay_type', 'status', 'uid']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select()->each(function($item){ @@ -76,6 +82,12 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface ->when(!empty($this->request->adminInfo['store_id']), function ($query) { $query->where('store_id', '=', $this->request->adminInfo['store_id']); }) + ->when(!empty($this->params['start_time']), function ($query) { + $query->whereTime('create_time', '>=', $this->params['start_time']); + }) + ->when(!empty($this->params['end_time']), function ($query) { + $query->whereTime('create_time', '<=', $this->params['end_time']); + }) ->count(); } diff --git a/app/common/logic/SystemStoreStaffLogic.php b/app/common/logic/SystemStoreStaffLogic.php new file mode 100644 index 000000000..ddce0e347 --- /dev/null +++ b/app/common/logic/SystemStoreStaffLogic.php @@ -0,0 +1,15 @@ +field($field)->select()->toArray(); + } + +} diff --git a/app/common/logic/store_order/StoreOrderLogic.php b/app/common/logic/store_order/StoreOrderLogic.php index adab39e3f..e8a05d258 100644 --- a/app/common/logic/store_order/StoreOrderLogic.php +++ b/app/common/logic/store_order/StoreOrderLogic.php @@ -107,4 +107,10 @@ class StoreOrderLogic extends BaseLogic return false; } } -} \ No newline at end of file + + public function storeOrderCount($storeId, $status) + { + return StoreOrder::where(['store_id' => $storeId, 'status' => $status, 'paid' => 1])->count(); + } + +} diff --git a/app/common/model/store_order/StoreOrder.php b/app/common/model/store_order/StoreOrder.php index f0af91c60..f7931d5a4 100644 --- a/app/common/model/store_order/StoreOrder.php +++ b/app/common/model/store_order/StoreOrder.php @@ -7,6 +7,7 @@ use app\common\enum\PayEnum; use app\common\model\BaseModel; use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\system_store\SystemStore; +use app\common\model\system_store\SystemStoreStaff; use app\common\model\user\User; use think\model\concern\SoftDelete; @@ -50,4 +51,9 @@ class StoreOrder extends BaseModel return $this->hasMany(StoreOrderCartInfo::class, 'oid', 'id'); } + public function staff() + { + return $this->hasOne(SystemStoreStaff::class, 'id', 'staff_id')->bind(['staff_name']); + } + } diff --git a/app/store/controller/store_order/StoreOrderController.php b/app/store/controller/store_order/StoreOrderController.php index 037f7e913..266d344f0 100644 --- a/app/store/controller/store_order/StoreOrderController.php +++ b/app/store/controller/store_order/StoreOrderController.php @@ -5,8 +5,10 @@ namespace app\store\controller\store_order; use app\admin\lists\store_order\StoreOrderLists; use app\common\controller\Definitions; +use app\common\enum\PayEnum; +use app\common\logic\SystemStoreStaffLogic; use app\store\controller\BaseAdminController; -use app\store\logic\store_order\StoreOrderLogic; +use app\common\logic\store_order\StoreOrderLogic; use app\store\validate\store_order\StoreOrderValidate; use hg\apidoc\annotation as ApiDoc; @@ -26,22 +28,31 @@ class StoreOrderController extends BaseAdminController ApiDoc\Method('GET'), ApiDoc\NotHeaders(), ApiDoc\Author('中国队长'), - ApiDoc\Query(name: 'order_id', type: 'int', require: false, desc: '分类id'), - ApiDoc\Query(name: 'pay_type', type: 'string', require: false, desc: '商品名称'), - ApiDoc\Query(name: 'status', type: 'int', require: false, desc: '状态:1上架,2下架,3售罄,4库存告警'), + ApiDoc\Query(name: 'order_id', type: 'string', require: false, desc: '订单编号'), + ApiDoc\Query(name: 'pay_type', type: 'int', require: false, desc: '支付方式'), + ApiDoc\Query(name: 'start_time', type: 'string', require: false, desc: '开始时间'), + ApiDoc\Query(name: 'end_time', type: 'string', require: false, desc: '结束时间'), + ApiDoc\Query(name: 'status', type: 'int', require: false, desc: '状态:0待发货,1待收货,2已完成'), ApiDoc\Header(ref: [Definitions::class, "token"]), ApiDoc\Query(ref: [Definitions::class, "page"]), ApiDoc\ResponseSuccess("data", type: "array", children: [ ['name' => 'id', 'desc' => 'ID', 'type' => 'int'], - ['name' => 'image', 'desc' => '图片', 'type' => 'string'], - ['name' => 'store_name', 'desc' => '商品名称', 'type' => 'string'], - ['name' => 'price', 'desc' => '零售价', 'type' => 'float'], - ['name' => 'cost', 'desc' => '成本价', 'type' => 'float'], - ['name' => 'sales', 'desc' => '销量', 'type' => 'int'], - ['name' => 'stock', 'desc' => '库存', 'type' => 'int'], - ['name' => 'unit_name', 'desc' => '单位', 'type' => 'string'], - ['name' => 'cate_name', 'desc' => '分类', 'type' => 'string'], - ['name' => 'status', 'desc' => '状态:1上架,0下架', 'type' => 'string'], + ['name' => 'order_id', 'desc' => '订单编号', 'type' => 'string'], + ['name' => 'pay_price', 'desc' => '支付金额', 'type' => 'string'], + ['name' => 'pay_time', 'desc' => '支付时间', 'type' => 'float'], + ['name' => 'pay_type_name', 'desc' => '支付方式', 'type' => 'float'], + ['name' => 'status_name', 'desc' => '状态', 'type' => 'int'], + ['name' => 'staff_name', 'desc' => '店员', 'type' => 'int'], + ['name' => 'nickname', 'desc' => '用户昵称', 'type' => 'string'], + ['name' => 'avatar', 'desc' => '用户头像', 'type' => 'string'], + ['name' => 'product', 'desc' => '商品信息', 'type' => 'array', 'children' => [ + ['name' => 'cart_info', 'desc' => '商品信息', 'type' => 'array', 'children' => [ + ['name' => 'name', 'desc' => '商品名称', 'type' => 'int'], + ['name' => 'image', 'desc' => '图片', 'type' => 'string'], + ['name' => 'cart_num', 'desc' => '购买数量', 'type' => 'string'], + ['name' => 'price', 'desc' => '单价', 'type' => 'string'], + ]], + ]], ]), ] public function lists() @@ -49,6 +60,28 @@ class StoreOrderController extends BaseAdminController return $this->dataLists(new StoreOrderLists()); } + #[ + ApiDoc\Title('订单统计'), + ApiDoc\url('/store/store_order/storeOrder/title'), + ApiDoc\Method('GET'), + ApiDoc\NotHeaders(), + ApiDoc\Author('中国队长'), + ApiDoc\Header(ref: [Definitions::class, "token"]), + ApiDoc\ResponseSuccess("data", type: "array"), + ] + public function title(SystemStoreStaffLogic $staffLogic, StoreOrderLogic $orderLogic) + { + return $this->data([ + 'staff' => $staffLogic->listByWhere(['store_id' => $this->request->adminInfo['store_id'], 'status' => 1], 'id,staff_name'), + 'pay_type' => PayEnum::getPaySceneDesc(), + 'order_status' => [ + 'wait_send' => $orderLogic->storeOrderCount($this->request->adminInfo['store_id'], 0), + 'wait_receive' => $orderLogic->storeOrderCount($this->request->adminInfo['store_id'], 1), + 'finish' => $orderLogic->storeOrderCount($this->request->adminInfo['store_id'], 2), + ], + ]); + } + #[ ApiDoc\Title('添加订单'), ApiDoc\url('/store/store_order/storeOrder/add'),