diff --git a/MySQL_change.sql b/MySQL_change.sql index 452567a..6375bcc 100644 --- a/MySQL_change.sql +++ b/MySQL_change.sql @@ -135,4 +135,8 @@ ALTER TABLE `product_specs` ALTER TABLE `agent_product_specs` ADD COLUMN `deleted_at` TIMESTAMP NULL DEFAULT NULL AFTER `price`; +ALTER TABLE `order_product_items` + ADD COLUMN `agent_product_spec_id` BIGINT UNSIGNED NOT NULL DEFAULT 0 COMMENT '代理商产品规格ID' AFTER `price`, + ADD COLUMN `product_type` TINYINT NOT NULL DEFAULT 0 COMMENT '供应商产品的type' AFTER `agent_product_spec_id`, + CHANGE COLUMN `product_spec_id` `product_spec_id` BIGINT NOT NULL DEFAULT 0 COMMENT '供应商产品规格ID' AFTER `product_type`; diff --git a/app/Http/Controllers/Api/OrderController.php b/app/Http/Controllers/Api/OrderController.php index 2e6a29d..9c229d9 100644 --- a/app/Http/Controllers/Api/OrderController.php +++ b/app/Http/Controllers/Api/OrderController.php @@ -156,7 +156,9 @@ class OrderController extends Controller //0:单品销售;1:组合销售 if ($ap->type == 0) { - $spec = AgentProductSpec::where('agent_product_id', $formData['id'])->find($formData['spec_id']); + $spec = AgentProductSpec::with('productSpec') + ->where('agent_product_id', $formData['id']) + ->find($formData['spec_id']); if (!$spec) { return $this->error('你选择的产品规格不存在'); } @@ -314,25 +316,20 @@ class OrderController extends Controller 'info' => $order_info, ]); - //存入订单产品表 - $supplier_product_info = Product::whereIn('id', $product_ids) - ->orderBy('id')->get(['type', 'id AS product_id', 'supplier_id', 'price', 'service_persons'])->toArray(); - - $order_id = $order->id; - $agent_id = $this->agent_id; - $agent_product_id = $ap->id; - - foreach ($supplier_product_info as &$v) { - $v['order_id'] = $order_id; - $v['agent_id'] = $agent_id; - $v['agent_product_id'] = $agent_product_id; - $v['num'] = $formData['num']; - if ($v['type'] == 0) { //TODO 此处未处理组合产品 - $v['product_spec_id'] = $formData['spec_id']; - } - unset($v['type']); - } - OrderProductItem::insert($supplier_product_info); + //存入订单产品表,TODO 此处不考虑组合产品 + OrderProductItem::insert([ + 'order_id' => $order->id, + 'agent_id' => $this->agent_id, + 'agent_product_id' => $ap->id, + 'supplier_id' => $ap->product->supplier_id, + 'product_id' => $ap->product->id, + 'num' => $formData['num'], + 'price' => $ap->product->price, + 'agent_product_spec_id' => $formData['spec_id'], + 'product_type' => $ap->product->type, + 'product_spec_id' => $spec->productSpec->id, + 'service_persons' => $ap->product->service_persons, + ]); DB::commit(); } catch (\Exception $e) { @@ -341,7 +338,7 @@ class OrderController extends Controller } if ($formData['pay_type'] == PayType::OFFLINE) { //线下支付 - return $this->success(['id' => $order_id], '操作成功,请及时联系客服付款'); + return $this->success(['id' => $order->id], '操作成功,请及时联系客服付款'); } else { //在线支付或定金支付 /*$config = $this->payConfig($order, $price); if (!empty($config['paySign'])) { @@ -526,7 +523,7 @@ class OrderController extends Controller $id = (int)request()->input('id'); $fields = ['id', 'agent_id', 'order_no', 'agent_product_id', 'num', 'price', 'name', 'mobile', 'title', 'picture', 'status', - 'pay_type', 'coupon_id', 'paid_money', 'paid_at', 'refund_info', 'verify_code', 'created_at']; + 'pay_type', 'coupon_id', 'paid_money', 'paid_at', 'refund_info', 'verify_code', 'info', 'created_at']; $order = Order::with('agent:id,appid,appsecret') ->where('user_id', $this->user_id) ->find($id, $fields);