Browse Source

price接口处理

master
李可松 4 years ago
parent
commit
70107eda84
  1. 4
      app/Http/Controllers/Api/AgentProductController.php
  2. 30
      app/Http/Controllers/Api/OrderController.php

4
app/Http/Controllers/Api/AgentProductController.php

@ -68,7 +68,9 @@ class AgentProductController extends Controller
'coupon:tag,agent_product_id',
'product:id,type,extends',
'spec' => function($query) {
return $query->has('productSpec')->with('productSpec:id,name,date');
return $query->has('productSpec')->with('productSpec', function ($query) {
$query->select(['id', 'name', 'date'])->orderBy('date', 'asc');
});
}
])
->whereDoesntHave('agentProductItem', function ($query) {

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

@ -402,10 +402,11 @@ class OrderController extends Controller
'id' => 'required|integer',
'num' => 'required|integer',
'pay_type' => 'required|integer',
'spec_id' => 'required|integer',
'spec_id' => 'required|array',
], [
'*.required' => '参数缺失',
'*.integer' => '参数类型错误',
'spec_id.array' => '产品规格必须是数组',
]);
if (!$formData['num'] || $formData['num'] < 1) {
@ -425,19 +426,26 @@ class OrderController extends Controller
//如果是线下支付,显示的价格跟在线全款支付价格一样
//订金支付
if ($formData['pay_type'] == PayType::DEPOSIT_PAY) {
$ap->final_price = $ap->deposit * $formData['num'];
$spec = AgentProductSpec::where('agent_product_id', $formData['id'])
->whereIn('id', $formData['spec_id'])
->get();
if ($spec->isEmpty()) {
return $this->error('你选择的产品规格不存在');
}
//定金支付
else if($formData['pay_type'] == PayType::EARNEST_PAY) {
$ap->final_price = $ap->earnest * $formData['num'];
$spec = $spec->toArray();
if ($formData['pay_type'] == PayType::DEPOSIT_PAY) { //订金支付
$single_price = $ap->deposit;
}
else if($formData['pay_type'] == PayType::EARNEST_PAY) { //定金支付
$single_price = $ap->earnes;
} else {
$spec = AgentProductSpec::where('agent_product_id', $formData['id'])->find($formData['spec_id']);
if (!$spec) {
return $this->error('你选择的产品规格不存在');
$single_price = $ap->price;
}
$ap->final_price = $spec->price * $formData['num'];
$ap->final_price = 0;
foreach ($spec as $v) {
$ap->final_price += $single_price * $formData['num'];
}
$ap->num = $formData['num'];

Loading…
Cancel
Save