Browse Source

`order_product_items`增加num和price字段

develop
李可松 4 years ago
parent
commit
4a33c2fc0c
  1. 5
      MySQL_change.sql
  2. 8
      app/Http/Controllers/Api/OrderController.php

5
MySQL_change.sql

@ -236,3 +236,8 @@ CREATE TABLE `order_product_items` (
COMMENT='订单对应产品表' COMMENT='订单对应产品表'
COLLATE='utf8_general_ci' COLLATE='utf8_general_ci'
ENGINE=InnoDB; 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`;

8
app/Http/Controllers/Api/OrderController.php

@ -204,18 +204,18 @@ class OrderController extends Controller
//存入订单产品表 //存入订单产品表
$supplier_product_info = Product::whereIn('id', $product_ids) $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; $order_id = $order->id;
$agent_id = $this->agent_id; $agent_id = $this->agent_id;
$agent_product_id = $ap->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['order_id'] = $order_id;
$v['agent_id'] = $agent_id; $v['agent_id'] = $agent_id;
$v['agent_product_id'] = $agent_product_id; $v['agent_product_id'] = $agent_product_id;
return $v;
}, $supplier_product_info);
$v['num'] = $formData['num'];
}
OrderProductItem::insert($supplier_product_info); OrderProductItem::insert($supplier_product_info);
DB::commit(); DB::commit();

Loading…
Cancel
Save