From d1c52d222a339e66d4748ffb85abd074b6c4e10d Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Wed, 5 Jun 2024 15:49:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AE=A2=E5=8D=95=E8=AF=A6?= =?UTF-8?q?=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lists/store_order/StoreOrderLists.php | 9 ++-- .../logic/store_order/StoreOrderLogic.php | 48 +++++++++++++++---- app/common/model/store_order/StoreOrder.php | 2 +- .../store_order/StoreOrderController.php | 25 +++------- 4 files changed, 49 insertions(+), 35 deletions(-) diff --git a/app/admin/lists/store_order/StoreOrderLists.php b/app/admin/lists/store_order/StoreOrderLists.php index b3c0923f..fe210d17 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', 'status'], + '=' => ['order_id', 'pay_type', 'status', 'staff_id'], ]; } @@ -59,10 +59,9 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface ->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){ - $item['pay_type_name']=PayEnum::getPaySceneDesc($item['pay_type']); - $item['pay_time']=$item['pay_time']>0?date('Y-m-d H:i:s',$item['pay_time']):''; - $item['status_name']= OrderEnum::getOrderType($item['status'])??''; + ->select()->each(function ($item) { + $item['pay_time'] = $item['pay_time'] > 0 ? date('Y-m-d H:i:s', $item['pay_time']) : ''; + $item['status_name'] = OrderEnum::getOrderType($item['status']) ?? ''; return $item; }) diff --git a/app/common/logic/store_order/StoreOrderLogic.php b/app/common/logic/store_order/StoreOrderLogic.php index e8a05d25..ac6db621 100644 --- a/app/common/logic/store_order/StoreOrderLogic.php +++ b/app/common/logic/store_order/StoreOrderLogic.php @@ -1,6 +1,8 @@ $v) { $find = StoreProduct::where(['id' => $v['product_id']])->field('store_name,image,unit,price')->find(); - if(!$find){ + if (!$find) { continue; } $cart_select[$k]['total'] = bcmul($v['cart_num'], $find['price'], 2); @@ -44,7 +47,7 @@ class StoreOrderLogic extends BaseLogic $cart_select[$k]['product_id'] = $v['product_id']; $cart_select[$k]['cart_num'] = $v['cart_num']; $cart_select[$k]['unit_name'] = StoreProductUnit::where(['id' => $find['unit']])->value('name'); - self::$total=bcadd(self::$total, $cart_select[$k]['total'], 2); + self::$total = bcadd(self::$total, $cart_select[$k]['total'], 2); } $order = [ 'time' => time(), @@ -52,7 +55,7 @@ class StoreOrderLogic extends BaseLogic 'total' => self::$total, 'pay_type' => $params['pay_type'] ?? 0, 'cart_id' => implode(',', $cartId), - 'delivery_msg'=>' 预计48小时发货 ' + 'delivery_msg' => ' 预计48小时发货 ' ]; } catch (\Exception $e) { self::setError($e->getMessage()); @@ -68,16 +71,16 @@ class StoreOrderLogic extends BaseLogic static public function createOrder($cartId, $addressId, $user = null, $params = []) { $orderInfo = self::cartIdByOrderInfo($cartId, $addressId, $user, $params); - if(!$orderInfo){ + if (!$orderInfo) { return false; } $_order = $orderInfo['order']; $_order['deduction_price'] = 0; $_order['store_id'] = $params['store_id']; $_order['uid'] = request()->userId; - if($addressId>0){ - $address=UserAddress::where(['id'=>$addressId,'uid'=>Request()->userId])->find(); - if($address){ + if ($addressId > 0) { + $address = UserAddress::where(['id' => $addressId, 'uid' => Request()->userId])->find(); + if ($address) { $_order['real_name'] = $address['real_name']; $_order['user_phone'] = $address['phone']; $_order['user_address'] = $address['detail']; @@ -85,8 +88,8 @@ class StoreOrderLogic extends BaseLogic } } - if($params['pay_type']==PayEnum::CASH_PAY){ - $_order['money']=$_order['total']; + if ($params['pay_type'] == PayEnum::CASH_PAY) { + $_order['money'] = $_order['total']; } Db::startTrans(); try { @@ -98,7 +101,7 @@ class StoreOrderLogic extends BaseLogic } (new StoreOrderCartInfo())->saveAll($goods_list); $where = ['is_pay' => 0, 'is_fail' => 0]; - Cart::whereIn('id', $cartId)->where($where)->update(['is_pay'=>1]); + Cart::whereIn('id', $cartId)->where($where)->update(['is_pay' => 1]); Db::commit(); return $order; } catch (\Exception $e) { @@ -108,6 +111,31 @@ class StoreOrderLogic extends BaseLogic } } + /** + * 订单详情 + * @param $params + * @return array + */ + public function detail($params) + { + $order = StoreOrder::with(['user', 'staff', 'product' => function ($query) { + $query->field(['id', 'oid', 'product_id', 'cart_info']); + }])->where($params)->find(); + if (empty($order)) { + throw new \Exception('订单不存在'); + } + $order['pay_time'] = $order['pay_time'] > 0 ? date('Y-m-d H:i:s', $order['pay_time']) : ''; + $order['status_name'] = OrderEnum::getOrderType($order['status']) ?? ''; + return $order->toArray(); + } + + /** + * 订单统计 + * @param $storeId + * @param $status + * @return int|\think\db\Query + * @throws \think\db\exception\DbException + */ 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 f7931d5a..c55eca27 100644 --- a/app/common/model/store_order/StoreOrder.php +++ b/app/common/model/store_order/StoreOrder.php @@ -43,7 +43,7 @@ class StoreOrder extends BaseModel public function user() { - return $this->hasOne(User::class, 'id', 'uid')->bind(['nickname', 'avatar']); + return $this->hasOne(User::class, 'id', 'uid')->bind(['nickname', 'avatar', 'mobile']); } public function product() diff --git a/app/store/controller/store_order/StoreOrderController.php b/app/store/controller/store_order/StoreOrderController.php index 266d344f..e0641a56 100644 --- a/app/store/controller/store_order/StoreOrderController.php +++ b/app/store/controller/store_order/StoreOrderController.php @@ -7,6 +7,7 @@ use app\admin\lists\store_order\StoreOrderLists; use app\common\controller\Definitions; use app\common\enum\PayEnum; use app\common\logic\SystemStoreStaffLogic; +use app\common\model\store_order\StoreOrder; use app\store\controller\BaseAdminController; use app\common\logic\store_order\StoreOrderLogic; use app\store\validate\store_order\StoreOrderValidate; @@ -29,6 +30,7 @@ class StoreOrderController extends BaseAdminController ApiDoc\NotHeaders(), ApiDoc\Author('中国队长'), ApiDoc\Query(name: 'order_id', type: 'string', require: false, desc: '订单编号'), + ApiDoc\Query(name: 'staff_id', type: 'int', require: false, desc: '店员id'), 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: '结束时间'), @@ -40,7 +42,7 @@ class StoreOrderController extends BaseAdminController ['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' => 'pay_type', 'desc' => '支付方式', 'type' => 'float'], ['name' => 'status_name', 'desc' => '状态', 'type' => 'int'], ['name' => 'staff_name', 'desc' => '店员', 'type' => 'int'], ['name' => 'nickname', 'desc' => '用户昵称', 'type' => 'string'], @@ -120,22 +122,6 @@ class StoreOrderController extends BaseAdminController return $this->fail(StoreOrderLogic::getError()); } - #[ - ApiDoc\Title('删除订单'), - ApiDoc\url('/store/store_order/storeOrder/delete'), - ApiDoc\Method('POST'), - ApiDoc\NotHeaders(), - ApiDoc\Author('中国队长'), - ApiDoc\Header(ref: [Definitions::class, "token"]), - ApiDoc\ResponseSuccess("data", type: "array"), - ] - public function delete() - { - $params = (new StoreOrderValidate())->post()->goCheck('delete'); - StoreOrderLogic::delete($params); - return $this->success('删除成功', [], 1, 1); - } - #[ ApiDoc\Title('订单详情'), ApiDoc\url('/store/store_order/storeOrder/detail'), @@ -143,12 +129,13 @@ class StoreOrderController extends BaseAdminController ApiDoc\NotHeaders(), ApiDoc\Author('中国队长'), ApiDoc\Header(ref: [Definitions::class, "token"]), + ApiDoc\Query(name: 'id', type: 'int', require: true, desc: '订单id'), ApiDoc\ResponseSuccess("data", type: "array"), ] - public function detail() + public function detail(StoreOrderLogic $orderLogic) { $params = (new StoreOrderValidate())->goCheck('detail'); - $result = StoreOrderLogic::detail($params); + $result = $orderLogic->detail($params); return $this->data($result); }