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/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/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(); } } 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