|
|
@ -14,6 +14,7 @@ use EasyWeChat\Factory; |
|
|
use EasyWeChat\Kernel\Exceptions\InvalidArgumentException; |
|
|
use EasyWeChat\Kernel\Exceptions\InvalidArgumentException; |
|
|
use EasyWeChat\Kernel\Exceptions\InvalidConfigException; |
|
|
use EasyWeChat\Kernel\Exceptions\InvalidConfigException; |
|
|
use GuzzleHttp\Exception\GuzzleException; |
|
|
use GuzzleHttp\Exception\GuzzleException; |
|
|
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
|
use Illuminate\Http\Request; |
|
|
use Illuminate\Http\Request; |
|
|
use Illuminate\Support\Facades\DB; |
|
|
use Illuminate\Support\Facades\DB; |
|
|
use App\Common\OrderStatus as Status; |
|
|
use App\Common\OrderStatus as Status; |
|
|
@ -144,7 +145,7 @@ class OrderController extends Controller |
|
|
|
|
|
|
|
|
DB::beginTransaction(); |
|
|
DB::beginTransaction(); |
|
|
try { |
|
|
try { |
|
|
$price = $this->calc($ap->price, $ap->coupon, $formData['num'], $formData['pay_type']); |
|
|
|
|
|
|
|
|
$price = $this->calc($ap->price, $formData['num'], $formData['pay_type'], $ap); |
|
|
$title = $ap->title; //产品标题
|
|
|
$title = $ap->title; //产品标题
|
|
|
|
|
|
|
|
|
//供应商产品表减库存
|
|
|
//供应商产品表减库存
|
|
|
@ -252,7 +253,7 @@ class OrderController extends Controller |
|
|
$ap = AgentProduct::query() |
|
|
$ap = AgentProduct::query() |
|
|
->has('product') |
|
|
->has('product') |
|
|
->with('coupon:agent_product_id,type,detail,agent_id,tag,start_at,end_at') |
|
|
->with('coupon:agent_product_id,type,detail,agent_id,tag,start_at,end_at') |
|
|
->find($formData['id'], ['id', 'price', 'original_price', 'product_id', 'title', 'pictures']); |
|
|
|
|
|
|
|
|
->find($formData['id'], ['id', 'price', 'original_price', 'product_id', 'title', 'pictures', 'earnest', 'earnest_timeout', 'deposit', 'deposit_timeout']); |
|
|
|
|
|
|
|
|
if (!$ap) { |
|
|
if (!$ap) { |
|
|
return $this->error('产品信息不存在'); |
|
|
return $this->error('产品信息不存在'); |
|
|
@ -266,7 +267,7 @@ class OrderController extends Controller |
|
|
$formData['pay_type'] = PayType::ONLINE; |
|
|
$formData['pay_type'] = PayType::ONLINE; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$ap->final_price = $this->calc($ap->price, $ap->coupon, $formData['num'], $formData['pay_type']); |
|
|
|
|
|
|
|
|
$ap->final_price = $this->calc($ap->price, $formData['num'], $formData['pay_type'], $ap); |
|
|
$ap->num = $formData['num']; |
|
|
$ap->num = $formData['num']; |
|
|
return $this->success($ap); |
|
|
return $this->success($ap); |
|
|
} |
|
|
} |
|
|
@ -286,13 +287,13 @@ class OrderController extends Controller |
|
|
return $this->error('订单不存在或已支付'); |
|
|
return $this->error('订单不存在或已支付'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$coupon = Coupon::whereIn('id', $order['coupon_id'])->get(); |
|
|
|
|
|
|
|
|
$ap = AgentProduct::with('coupon')->find($order->agent_product_id); |
|
|
|
|
|
|
|
|
//如果已经付定金或首付款,则仅支付尾款
|
|
|
//如果已经付定金或首付款,则仅支付尾款
|
|
|
if ($order->status == Status::PAY_EARNEST) { |
|
|
if ($order->status == Status::PAY_EARNEST) { |
|
|
$price = $order->price - $order->paid_money; |
|
|
$price = $order->price - $order->paid_money; |
|
|
} else { |
|
|
} else { |
|
|
$price = $this->calc($order->price, $coupon, $order->num, $order->pay_type); |
|
|
|
|
|
|
|
|
$price = $this->calc($order->price, $order->num, $order->pay_type, $ap); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$config = $this->payConfig($order, $price); |
|
|
$config = $this->payConfig($order, $price); |
|
|
@ -371,21 +372,25 @@ class OrderController extends Controller |
|
|
* 计算最终价格(扣除优惠券之后的价格) |
|
|
* 计算最终价格(扣除优惠券之后的价格) |
|
|
* $price:原价;$coupon:优惠券;$num:产品数量;$pay_type:支付方式 |
|
|
* $price:原价;$coupon:优惠券;$num:产品数量;$pay_type:支付方式 |
|
|
* @param float $price |
|
|
* @param float $price |
|
|
* @param Coupon $coupon |
|
|
|
|
|
* @param int $num |
|
|
* @param int $num |
|
|
* @param int $pay_type |
|
|
* @param int $pay_type |
|
|
|
|
|
* @param Model $agent_product |
|
|
* @return float |
|
|
* @return float |
|
|
*/ |
|
|
*/ |
|
|
private function calc($price, $coupon, $num, $pay_type) |
|
|
|
|
|
|
|
|
private function calc($price, $num, $pay_type, $agent_product) |
|
|
{ |
|
|
{ |
|
|
//根据支付方式计算价格
|
|
|
//根据支付方式计算价格
|
|
|
if (in_array($pay_type, [PayType::DEPOSIT_PAY, PayType::EARNEST_PAY, PayType::DOWN_PAYMENT])) { |
|
|
if (in_array($pay_type, [PayType::DEPOSIT_PAY, PayType::EARNEST_PAY, PayType::DOWN_PAYMENT])) { |
|
|
return $this->earnest; |
|
|
|
|
|
|
|
|
if ($pay_type == PayType::DEPOSIT_PAY && $agent_product->deposit && $agent_product->deposit_timeout) { |
|
|
|
|
|
return $agent_product->deposit; |
|
|
|
|
|
} |
|
|
|
|
|
if ($pay_type == PayType::EARNEST_PAY && $agent_product->earnest && $agent_product->earnest_timeout) { |
|
|
|
|
|
return $agent_product->earnest; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
//TODO 还要计算尾款支付金额
|
|
|
|
|
|
|
|
|
|
|
|
$total_price = $price * $num; |
|
|
$total_price = $price * $num; |
|
|
//没有任何优惠券时直接返回最终价
|
|
|
|
|
|
|
|
|
/*//没有任何优惠券时直接返回最终价 |
|
|
if ($coupon && $coupon->isEmpty()) { |
|
|
if ($coupon && $coupon->isEmpty()) { |
|
|
return $total_price; |
|
|
return $total_price; |
|
|
} |
|
|
} |
|
|
@ -393,14 +398,14 @@ class OrderController extends Controller |
|
|
$coupon = $coupon->toArray(); |
|
|
$coupon = $coupon->toArray(); |
|
|
foreach ($coupon as $v) { |
|
|
foreach ($coupon as $v) { |
|
|
// TODO 未判断优惠券有效期
|
|
|
// TODO 未判断优惠券有效期
|
|
|
/*if ($v['type'] == 1 && !empty($v['detail']['full']) && !empty($v['detail']['reduction'])) { //满减
|
|
|
|
|
|
|
|
|
if ($v['type'] == 1 && !empty($v['detail']['full']) && !empty($v['detail']['reduction'])) { //满减
|
|
|
if ($total_price >= $v['detail']['full']) { |
|
|
if ($total_price >= $v['detail']['full']) { |
|
|
$total_price -= $v['detail']['reduction']; |
|
|
$total_price -= $v['detail']['reduction']; |
|
|
} |
|
|
} |
|
|
} else if ($v['type'] == 2 && !empty($v['detail']['discount'])) { //打折
|
|
|
} else if ($v['type'] == 2 && !empty($v['detail']['discount'])) { //打折
|
|
|
$total_price *= $v['detail']['discount']; |
|
|
$total_price *= $v['detail']['discount']; |
|
|
}*/ |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
}*/ |
|
|
return round($total_price, 2); |
|
|
return round($total_price, 2); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|