From 4a33c2fc0cb6c36af04f799a5aed85c10b1f516c Mon Sep 17 00:00:00 2001 From: liapples Date: Thu, 2 Sep 2021 15:53:38 +0800 Subject: [PATCH] =?UTF-8?q?`order=5Fproduct=5Fitems`=E5=A2=9E=E5=8A=A0num?= =?UTF-8?q?=E5=92=8Cprice=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MySQL_change.sql | 5 +++++ app/Http/Controllers/Api/OrderController.php | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/MySQL_change.sql b/MySQL_change.sql index 0175fdf..5a3a75e 100644 --- a/MySQL_change.sql +++ b/MySQL_change.sql @@ -236,3 +236,8 @@ CREATE TABLE `order_product_items` ( COMMENT='订单对应产品表' COLLATE='utf8_general_ci' ENGINE=InnoDB; + +# 15:44 2021/9/2 +ALTER TABLE `order_product_items` + ADD COLUMN `num` INT(10) NOT NULL COMMENT '购买数量' AFTER `product_id`, + ADD COLUMN `price` DECIMAL(20,2) NOT NULL COMMENT '销售价格' AFTER `num`; diff --git a/app/Http/Controllers/Api/OrderController.php b/app/Http/Controllers/Api/OrderController.php index 1535817..18be8cc 100644 --- a/app/Http/Controllers/Api/OrderController.php +++ b/app/Http/Controllers/Api/OrderController.php @@ -204,18 +204,18 @@ class OrderController extends Controller //存入订单产品表 $supplier_product_info = Product::whereIn('id', $product_ids) - ->orderBy('id')->get(['id AS product_id', 'supplier_id'])->toArray(); + ->orderBy('id')->get(['id AS product_id', 'supplier_id', 'price'])->toArray(); $order_id = $order->id; $agent_id = $this->agent_id; $agent_product_id = $ap->id; - $supplier_product_info = array_map(function ($v) use($order_id, $agent_id, $agent_product_id) { + foreach ($supplier_product_info as &$v) { $v['order_id'] = $order_id; $v['agent_id'] = $agent_id; $v['agent_product_id'] = $agent_product_id; - return $v; - }, $supplier_product_info); + $v['num'] = $formData['num']; + } OrderProductItem::insert($supplier_product_info); DB::commit();