From 65ce4808c93d10d07ad1e1fc0ba72c74b6b0505c Mon Sep 17 00:00:00 2001 From: "DESKTOP-GMUNQ1B\\Administrator" <604446095@qq.com> Date: Wed, 18 Dec 2024 17:44:44 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=B0=83=E6=95=B4=E9=87=87=E8=B4=AD?= =?UTF-8?q?=E5=8D=95=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PurchaseProductOfferLists.php | 16 ++++++ .../PurchaseProductOfferLogic.php | 53 +++++++++++++------ .../PurchaseProductOffer.php | 2 + 3 files changed, 56 insertions(+), 15 deletions(-) diff --git a/app/admin/lists/purchase_product_offer/PurchaseProductOfferLists.php b/app/admin/lists/purchase_product_offer/PurchaseProductOfferLists.php index 5d72a652f..05e5f5d9e 100644 --- a/app/admin/lists/purchase_product_offer/PurchaseProductOfferLists.php +++ b/app/admin/lists/purchase_product_offer/PurchaseProductOfferLists.php @@ -49,6 +49,14 @@ class PurchaseProductOfferLists extends BaseAdminDataLists implements ListsSearc */ public function lists(): array { + $procurementOrderId = PurchaseProductOffer::where('source_order_id', $this->params['order_id'])->value('source_order_id'); + if ($procurementOrderId) { + foreach ($this->searchWhere as $k => &$v) { + if ($v[0] == 'order_id') { + $v[2] = $procurementOrderId; + } + } + } $store_name=$this->request->get('store_name'); if($store_name){ $ids=StoreProduct::where('store_name','like','%'.$store_name.'%')->column('id'); @@ -125,6 +133,14 @@ class PurchaseProductOfferLists extends BaseAdminDataLists implements ListsSearc if($this->is_ids==1){ return 0; } + $procurementOrderId = PurchaseProductOffer::where('source_order_id', $this->params['order_id'])->value('source_order_id'); + if ($procurementOrderId) { + foreach ($this->searchWhere as $k => &$v) { + if ($v[0] == 'order_id') { + $v[2] = $procurementOrderId; + } + } + } return PurchaseProductOffer::where($this->searchWhere)->count(); } diff --git a/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php b/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php index 7ca280fb6..c00169aa0 100644 --- a/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php +++ b/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php @@ -56,21 +56,44 @@ class PurchaseProductOfferLogic extends BaseLogic $mark = BeforehandOrderCartInfo::where('bhoid', $params['order_id'])->where('product_id', $params['product_id'])->value('mark'); } $find=StoreProduct::where('id',$params['product_id'])->find(); - PurchaseProductOffer::create([ - 'order_id' => $procurementOrder['id'], - 'product_id' => $params['product_id'], - 'unit' => $params['unit'], - 'is_buyer' => $params['is_buyer'], - 'need_num' => $params['need_num'], - 'mark' => $mark, - 'buyer_id' => $params['buyer_id'], - 'package' => $find['package'], - 'store_info' => $find['store_info'], - 'marques' => $find['marques'], - 'after_sales' => $find['after_sales'], - 'status' => 0, - - ]); + $purchaseProductOffer = PurchaseProductOffer::where(['order_id' => $procurementOrder['id'], 'product_id' => $params['product_id']])->find(); + if ($purchaseProductOffer) { + $purchaseProductOffer->need_num = $purchaseProductOffer['need_num'] + $params['need_num']; + if (!empty($purchaseProductOffer['source_order_info'])) { + $sourceOrderInfo = $purchaseProductOffer['source_order_info']; + $sourceOrderInfo[] = [ + 'source_order_id' => $params['order_id'], + 'product_id' => $params['product_id'], + 'need_num' => $params['need_num'], + 'mark' => $mark, + ]; + $purchaseProductOffer->source_order_info = $sourceOrderInfo; + } + $purchaseProductOffer->save(); + } else { + PurchaseProductOffer::create([ + 'order_id' => $procurementOrder['id'], + 'product_id' => $params['product_id'], + 'unit' => $params['unit'], + 'is_buyer' => $params['is_buyer'], + 'need_num' => $params['need_num'], + 'mark' => $mark, + 'buyer_id' => $params['buyer_id'], + 'package' => $find['package'], + 'store_info' => $find['store_info'], + 'marques' => $find['marques'], + 'after_sales' => $find['after_sales'], + 'status' => 0, + 'source_order_info' => [ + [ + 'source_order_id' => $params['order_id'], + 'product_id' => $params['product_id'], + 'need_num' => $params['need_num'], + 'mark' => $mark, + ] + ] + ]); + } BeforehandOrderCartInfo::where(['bhoid' => $params['order_id'], 'product_id' => $params['product_id']])->update(['is_buyer' => 1]); Db::commit(); return true; diff --git a/app/common/model/purchase_product_offer/PurchaseProductOffer.php b/app/common/model/purchase_product_offer/PurchaseProductOffer.php index 4f76f0f99..1c6efb332 100644 --- a/app/common/model/purchase_product_offer/PurchaseProductOffer.php +++ b/app/common/model/purchase_product_offer/PurchaseProductOffer.php @@ -18,5 +18,7 @@ class PurchaseProductOffer extends BaseModel protected $name = 'purchase_product_offer'; protected $deleteTime = 'delete_time'; + protected $json = ['source_order_info']; + protected $jsonAssoc = true; } \ No newline at end of file From 2c6e3ccb819519928bf8aa3df73fb2f87e6efc71 Mon Sep 17 00:00:00 2001 From: "DESKTOP-GMUNQ1B\\Administrator" <604446095@qq.com> Date: Thu, 19 Dec 2024 16:34:17 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=B0=83=E6=95=B4=E9=87=87=E8=B4=AD?= =?UTF-8?q?=E5=8D=95=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BeforehandOrderCartInfoController.php | 27 ++++++++++++++++++- .../PurchaseProductOfferLists.php | 16 ----------- .../beforehand_order/BeforehandOrderLogic.php | 2 +- .../PurchaseProductOfferLogic.php | 7 ++++- 4 files changed, 33 insertions(+), 19 deletions(-) diff --git a/app/admin/controller/beforehand_order_cart_info/BeforehandOrderCartInfoController.php b/app/admin/controller/beforehand_order_cart_info/BeforehandOrderCartInfoController.php index 35226807d..9736a5ec2 100644 --- a/app/admin/controller/beforehand_order_cart_info/BeforehandOrderCartInfoController.php +++ b/app/admin/controller/beforehand_order_cart_info/BeforehandOrderCartInfoController.php @@ -6,8 +6,10 @@ namespace app\admin\controller\beforehand_order_cart_info; use app\admin\controller\BaseAdminController; use app\admin\lists\beforehand_order_cart_info\BeforehandOrderCartInfoLists; use app\admin\logic\beforehand_order_cart_info\BeforehandOrderCartInfoLogic; +use app\common\model\beforehand_order\BeforehandOrder; use app\common\model\beforehand_order_cart_info\BeforehandOrderCartInfo; use app\common\model\purchase_product_offer\PurchaseProductOffer; +use app\common\model\store_product\StoreProduct; /** * 预订单购物详情表控制器 @@ -65,11 +67,34 @@ class BeforehandOrderCartInfoController extends BaseAdminController $res=BeforehandOrderCartInfo::where('id',$id)->find(); $find=PurchaseProductOffer::where(['product_id'=>$res['product_id'],'order_id'=>$res['bhoid']])->find(); + if (empty($find)) { + $rawSql = "JSON_CONTAINS(source_order_info, '{\"source_order_id\": {$res['bhoid']}}')"; + $find = PurchaseProductOffer::where(['product_id' => $res['product_id']])->whereRaw($rawSql)->find(); + } if($find){ if($find['buyer_confirm']==1){ return $this->fail('该商品已采购完成,无法更改状态'); }else{ - PurchaseProductOffer::where('id',$find['id'])->update(['delete_time'=>time()]); + if (!empty($find['source_order_info'])) { + $json = $find['source_order_info']; + foreach ($json as $key => $value) { + if ($value['source_order_id'] == $res['bhoid']) { + $find->need_num = $find->need_num - $value['need_num']; + unset($json[$key]); + break; + } + } + $find->source_order_info = array_values($json); + $productPrice = StoreProduct::where('id',$res['product_id'])->value('price'); + $procurementOrder = BeforehandOrder::where('id', $find['order_id'])->find(); + $procurementOrder->total_price = bcsub($procurementOrder->total_price, bcmul($productPrice, $res['cart_num'], 2), 2); + $procurementOrder->pay_price = $procurementOrder->total_price; + $procurementOrder->save(); + } + if ($find->need_num <= 0) { + $find->delete_time = time(); + } + $find->save(); } } $res->save(['is_buyer'=>-1]); diff --git a/app/admin/lists/purchase_product_offer/PurchaseProductOfferLists.php b/app/admin/lists/purchase_product_offer/PurchaseProductOfferLists.php index 05e5f5d9e..5d72a652f 100644 --- a/app/admin/lists/purchase_product_offer/PurchaseProductOfferLists.php +++ b/app/admin/lists/purchase_product_offer/PurchaseProductOfferLists.php @@ -49,14 +49,6 @@ class PurchaseProductOfferLists extends BaseAdminDataLists implements ListsSearc */ public function lists(): array { - $procurementOrderId = PurchaseProductOffer::where('source_order_id', $this->params['order_id'])->value('source_order_id'); - if ($procurementOrderId) { - foreach ($this->searchWhere as $k => &$v) { - if ($v[0] == 'order_id') { - $v[2] = $procurementOrderId; - } - } - } $store_name=$this->request->get('store_name'); if($store_name){ $ids=StoreProduct::where('store_name','like','%'.$store_name.'%')->column('id'); @@ -133,14 +125,6 @@ class PurchaseProductOfferLists extends BaseAdminDataLists implements ListsSearc if($this->is_ids==1){ return 0; } - $procurementOrderId = PurchaseProductOffer::where('source_order_id', $this->params['order_id'])->value('source_order_id'); - if ($procurementOrderId) { - foreach ($this->searchWhere as $k => &$v) { - if ($v[0] == 'order_id') { - $v[2] = $procurementOrderId; - } - } - } return PurchaseProductOffer::where($this->searchWhere)->count(); } diff --git a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php index 8699bdc60..4b3d43892 100644 --- a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php +++ b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php @@ -678,7 +678,7 @@ class BeforehandOrderLogic extends BaseLogic { $order_info = new OrderInfo(); $order = BeforehandOrder::where('id', $params['id'])->find(); - if ($order['order_type'] == 7 && $params['print'] == 1) { + if ($order['order_type'] == 7 && isset($params['print']) && $params['print'] == 1) { $order->is_buying = 1; $order->save(); } diff --git a/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php b/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php index c00169aa0..a3445587c 100644 --- a/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php +++ b/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php @@ -41,7 +41,7 @@ class PurchaseProductOfferLogic extends BaseLogic { Db::startTrans(); try { - $procurementOrder = BeforehandOrder::where('order_type', 7)->where('is_buying', 0)->find(); + $procurementOrder = BeforehandOrder::where('order_type', 7)->where('is_buying', 0)->where('create_time', '>=', strtotime('-3 days'))->find(); if (empty($procurementOrder)) { $beforeOrder = BeforehandOrder::where('id', $params['order_id'])->findOrEmpty()->toArray(); unset($beforeOrder['id'], $beforeOrder['create_time'], $beforeOrder['update_time']); @@ -49,6 +49,8 @@ class PurchaseProductOfferLogic extends BaseLogic $procurementOrder->setAttrs($beforeOrder); $procurementOrder->order_id = getNewOrderId('CG'); $procurementOrder->order_type = 7; + $procurementOrder->total_price = 0; + $procurementOrder->pay_price = 0; $procurementOrder->save(); } $mark = $params['mark'] ?? ''; @@ -57,6 +59,9 @@ class PurchaseProductOfferLogic extends BaseLogic } $find=StoreProduct::where('id',$params['product_id'])->find(); $purchaseProductOffer = PurchaseProductOffer::where(['order_id' => $procurementOrder['id'], 'product_id' => $params['product_id']])->find(); + $procurementOrder->total_price = bcadd($procurementOrder->total_price, bcmul($find['price'], $params['need_num'], 2), 2); + $procurementOrder->pay_price = $procurementOrder->total_price; + $procurementOrder->save(); if ($purchaseProductOffer) { $purchaseProductOffer->need_num = $purchaseProductOffer['need_num'] + $params['need_num']; if (!empty($purchaseProductOffer['source_order_info'])) {