From ef47fe01473bd6a619b310a86a51b605afe8db2c Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 10 Oct 2024 15:16:34 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=94=9F=E6=88=90?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E8=AE=A2=E5=8D=95=E5=8A=9F=E8=83=BD=E5=B9=B6?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=AE=A2=E5=8D=95=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 BeforehandOrderController 中新增 generateOrder 方法,用于生成支付订单 - 在 BeforehandOrderLogic 中实现 generateOrder 方法,处理订单生成逻辑 - 优化 StoreOrderLogic 中的退款逻辑,改进数据库更新操作 --- .../BeforehandOrderController.php | 8 +++ .../beforehand_order/BeforehandOrderLogic.php | 51 +++++++++++++++++++ .../logic/store_order/StoreOrderLogic.php | 2 +- 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/app/admin/controller/beforehand_order/BeforehandOrderController.php b/app/admin/controller/beforehand_order/BeforehandOrderController.php index c3c94a5f1..9f509ac42 100644 --- a/app/admin/controller/beforehand_order/BeforehandOrderController.php +++ b/app/admin/controller/beforehand_order/BeforehandOrderController.php @@ -59,6 +59,14 @@ class BeforehandOrderController extends BaseAdminController $result = BeforehandOrderLogic::add($params); return $this->success('添加成功', [], 1, 1); } + /** + * 生成支付订单 + */ + public function generateOrder(){ + $params = $this->request->post(); + $result = BeforehandOrderLogic::generateOrder($params); + return $this->success('生成成功', [], 1, 1); + } /** * 一键出库 */ diff --git a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php index 6c95c4652..455c196da 100644 --- a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php +++ b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php @@ -4,12 +4,16 @@ namespace app\admin\logic\beforehand_order; use app\admin\logic\store_product\StoreProductLogic; use app\admin\logic\warehouse_product\WarehouseProductLogic; +use app\api\logic\order\CartLogic; +use app\api\logic\order\OrderLogic; use app\common\model\beforehand_order\BeforehandOrder; use app\common\logic\BaseLogic; use app\common\model\beforehand_order_cart_info\BeforehandOrderCartInfo; +use app\common\model\store_branch_product\StoreBranchProduct; 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\user\User; use app\common\model\warehouse_order\WarehouseOrder; use app\common\model\warehouse_product\WarehouseProduct; use support\exception\BusinessException; @@ -77,6 +81,53 @@ class BeforehandOrderLogic extends BaseLogic } } + /** + * @notes 生成支付订单 + * @param array $params + * @return bool + * @author admin + * @date 2024/09/30 11:26 + */ + public static function generateOrder(array $params): bool + { + Db::startTrans(); + try { + $order= BeforehandOrder::where('id',$params['id'])->find(); + $cart_info=BeforehandOrderCartInfo::where('bhoid',$params['id'])->select()->toArray(); + $cartId = []; + foreach ($cart_info as $k => $v) { + $v['uid'] = $params['user_id']; + $v['store_id'] = $params['store_id']; + $find=StoreBranchProduct::where('store_id', $params['store_id'])->where('product_id', $v['product_id'])->find(); + if(!$find){ + $product=StoreProduct::where('id', $v['product_id'])->find(); + $find=StoreProductLogic::ordinary($product, $params['store_id'], 0, $product); + } + if(in_array($order['order_type'],[2,3])){ + if(isset($v['purchase']) && $v['purchase'] > 0){ + $purchase = $v['purchase']; + }else{ + $purchase=$v['price']; + } + $find->save(['price' => $v['price'], 'vip_price' => $v['price'], 'cost' => $v['price'], 'purchase' => $purchase]); + } + unset($v['id']); + $cart = CartLogic::add($v); + $cartId[] = $cart['id']; + } + $user = User::where('id', $params['user_id'])->find(); + $params['shipping_type'] = 2; + $params['source'] =2;//后台下单 + $res = OrderLogic::createOrder($cartId, null, $user, $params); + $order->order_sn=$res['order_id']; + $order->save(); + Db::commit(); + return true; + } catch (\Throwable $e) { + Db::rollback(); + throw new BusinessException($e->getMessage()); + } + } /** * @notes 编辑预订单表 diff --git a/app/admin/logic/store_order/StoreOrderLogic.php b/app/admin/logic/store_order/StoreOrderLogic.php index 57a1a28d2..7aa407f15 100644 --- a/app/admin/logic/store_order/StoreOrderLogic.php +++ b/app/admin/logic/store_order/StoreOrderLogic.php @@ -212,6 +212,6 @@ class StoreOrderLogic extends BaseLogic $detail['refund_price']=$refund_price; CommissionnLogic::setStore($detail, $village_uid, $brigade_uid, $transaction_id); - StoreOrder::where('id', $detail['oid'])->update(['refund_price' => $refund_price, 'refund_num' => $refund_num]); + StoreOrder::where('id', $detail['id'])->inc('refund_price',$refund_price)->inc('refund_num',$refund_num)->update(); } } From 00fb209800efd6900ac454342b72dac7615ac027 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 10 Oct 2024 16:19:32 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=AE=A2=E5=8D=95=E7=B1=BB=E5=9E=8B=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E5=8F=8A=E5=90=8D=E7=A7=B0=E6=98=BE=E7=A4=BA=EF=BC=9B?= =?UTF-8?q?=E9=87=87=E8=B4=AD=E4=BA=A7=E5=93=81=E6=8A=A5=E4=BB=B7=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E5=A2=9E=E5=8A=A0=E7=94=A8=E6=88=B7ID=E7=AD=9B?= =?UTF-8?q?=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 BeforehandOrderLists 类的 lists 方法中添加 order_type 字段,并增加对应的订单类型名称显示 - 在 PurchaseProductOfferController 类的 lists 方法中设置 uid 参数为当前用户 ID - 在 PurchaseProductOfferLists 类的 lists 方法中根据 uid 进行搜索条件设置,并在 count 方法中添加对应逻辑 --- .../beforehand_order/BeforehandOrderLists.php | 9 ++++++++- .../PurchaseProductOfferController.php | 1 + .../PurchaseProductOfferLists.php | 14 ++++++++++++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/app/admin/lists/beforehand_order/BeforehandOrderLists.php b/app/admin/lists/beforehand_order/BeforehandOrderLists.php index 0026a05de..9e2e1ea79 100644 --- a/app/admin/lists/beforehand_order/BeforehandOrderLists.php +++ b/app/admin/lists/beforehand_order/BeforehandOrderLists.php @@ -43,7 +43,7 @@ class BeforehandOrderLists extends BaseAdminDataLists implements ListsSearchInte public function lists(): array { return BeforehandOrder::where($this->searchWhere) - ->field(['id','order_id', 'uid','total_num','total_price','admin_id', 'pay_price', 'deduction_price','create_time', 'status', 'mark']) + ->field(['id','order_id', 'uid','order_type','total_num','total_price','admin_id', 'pay_price', 'deduction_price','create_time', 'status', 'mark']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select()->each(function ($item){ @@ -52,6 +52,13 @@ class BeforehandOrderLists extends BaseAdminDataLists implements ListsSearchInte }else{ $item->admin_name=''; } + if($item->order_type==1){ + $item->order_type_name='普通订单'; + }elseif($item->order_type==2){ + $item->order_type_name='商贩订单'; + }elseif($item->order_type==3){ + $item->order_type_name='一条龙订单'; + } }) ->toArray(); } diff --git a/app/api/controller/purchase_product_offer/PurchaseProductOfferController.php b/app/api/controller/purchase_product_offer/PurchaseProductOfferController.php index 658a806f7..ff5b04181 100644 --- a/app/api/controller/purchase_product_offer/PurchaseProductOfferController.php +++ b/app/api/controller/purchase_product_offer/PurchaseProductOfferController.php @@ -26,6 +26,7 @@ class PurchaseProductOfferController extends BaseApiController */ public function lists() { + $this->request->__set('uid',$this->userId); return $this->dataLists(new PurchaseProductOfferLists()); } diff --git a/app/api/lists/purchase_product_offer/PurchaseProductOfferLists.php b/app/api/lists/purchase_product_offer/PurchaseProductOfferLists.php index d80f67758..73ef2ef1d 100644 --- a/app/api/lists/purchase_product_offer/PurchaseProductOfferLists.php +++ b/app/api/lists/purchase_product_offer/PurchaseProductOfferLists.php @@ -18,7 +18,7 @@ use app\api\lists\BaseApiDataLists; class PurchaseProductOfferLists extends BaseApiDataLists implements ListsSearchInterface { - + public $userId; /** * @notes 设置搜索条件 * @return \string[][] @@ -44,6 +44,12 @@ class PurchaseProductOfferLists extends BaseApiDataLists implements ListsSearchI */ public function lists(): array { + $uid=$this->request->__get('uid'); + if($uid){ + $this->searchWhere[]=['buyer_id','=',$uid]; + }else{ + return []; + } return PurchaseProductOffer::where($this->searchWhere) ->field(['id', 'order_id', 'product_id', 'price', 'buyer_nums', 'unit', 'is_buyer', 'buyer_confirm','need_num', 'buyer_id', 'status', ]) ->limit($this->limitOffset, $this->limitLength) @@ -81,7 +87,11 @@ class PurchaseProductOfferLists extends BaseApiDataLists implements ListsSearchI */ public function count(): int { - return PurchaseProductOffer::where($this->searchWhere)->count(); + if($this->userId){ + return 0; + }else{ + return PurchaseProductOffer::where($this->searchWhere)->count(); + } } } \ No newline at end of file