|
|
|
@ -4,6 +4,7 @@ namespace App\Http\Controllers\Api; |
|
|
|
use App\Common\PayType; |
|
|
|
use App\Models\Agent; |
|
|
|
use App\Models\AgentProduct; |
|
|
|
use App\Models\AgentSetting; |
|
|
|
use App\Models\Order; |
|
|
|
use App\Models\Product; |
|
|
|
use App\Models\UserMoneyLog; |
|
|
|
@ -62,6 +63,14 @@ class WxpayController |
|
|
|
if ($message['result_code'] === 'SUCCESS') { |
|
|
|
DB::beginTransaction(); |
|
|
|
try { |
|
|
|
//增加销量,库存在拍下时已经减了
|
|
|
|
$agent_product = AgentProduct::find($order->agent_product_id); |
|
|
|
$agent_product->increment('sale', $order->num); |
|
|
|
|
|
|
|
Product::query() |
|
|
|
->where('id', $order->product_id) |
|
|
|
->increment('sale', $order->num); |
|
|
|
|
|
|
|
$status = $order->status; |
|
|
|
$pay_type = $order->pay_type; |
|
|
|
$money = $message['total_fee'] / 100; |
|
|
|
@ -73,24 +82,29 @@ class WxpayController |
|
|
|
$order->status = OrderStatus::PAID_RETAINAGE; |
|
|
|
$order->verify_code = uniqid(); //生成核销码
|
|
|
|
} |
|
|
|
} else if ($pay_type == 0) { |
|
|
|
} else if ($pay_type == PayType::ONLINE) { |
|
|
|
$order->status = OrderStatus::PAID; |
|
|
|
$order->verify_code = uniqid(); //生成核销码
|
|
|
|
} |
|
|
|
|
|
|
|
$order->paid_at = now(); |
|
|
|
$order->paid_money = DB::raw('`paid_money` + ' . $money); |
|
|
|
$order->timeout = null; //清除超时时间
|
|
|
|
//如果是已付定金,重新设置超时时间,否则清除超时时间
|
|
|
|
if ($order->status == OrderStatus::PAY_EARNEST) { |
|
|
|
if ($pay_type == PayType::DEPOSIT_PAY) { //订金超时
|
|
|
|
$time = $agent_product->deposit_timeout * 60; |
|
|
|
} else if ($pay_type == PayType::EARNEST_PAY) { //定金超时
|
|
|
|
$time = $agent_product->earnest_timeout * 60; |
|
|
|
} |
|
|
|
if (empty($time)) { //默认订单超时
|
|
|
|
$time = (AgentSetting::val($agent_id, 'order_timeout') ?? 60) * 60; |
|
|
|
} |
|
|
|
$order->timeout = date('Y-m-d H:i:s', time() + $time); |
|
|
|
} else { |
|
|
|
$order->timeout = null; |
|
|
|
} |
|
|
|
$order->save(); |
|
|
|
|
|
|
|
//增加销量,库存在拍下时已经减了
|
|
|
|
AgentProduct::query() |
|
|
|
->where('id', $order->agent_product_id) |
|
|
|
->increment('sale', $order->num); |
|
|
|
Product::query() |
|
|
|
->where('id', $order->product_id) |
|
|
|
->increment('sale', $order->num); |
|
|
|
|
|
|
|
//资金流水
|
|
|
|
UserMoneyLog::query()->create([ |
|
|
|
'user_id' => $order->user_id, |
|
|
|
|