防并发
parent
a24bc7ab4c
commit
c144baa60c
|
|
@ -48,7 +48,43 @@ class HandleAgentAlipayResultNotice implements ShouldQueue
|
|||
|
||||
$aliNotice = AliAgentNotice::where('notify_id', $this->data['notify_id'])->first();
|
||||
if ($aliNotice) {
|
||||
Log::error('HandleAgentAlipayResultNotice noticeId exist', $this->data);
|
||||
Log::error('HandleAgentAlipayResultNotice noticeId_exist', $this->data);
|
||||
return;
|
||||
}
|
||||
$rechargeSn = $this->data['out_trade_no'];
|
||||
$rechargeObj = new CustomerRecharge();
|
||||
$recharge = $rechargeObj->where('recharge_sn', $rechargeSn)->first();
|
||||
if (!$recharge) {
|
||||
Log::error('HandleAgentAlipayResultNotice not_found_recharge_sn', [
|
||||
'data' => $this->data,
|
||||
'rechargeSn' => $rechargeSn,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$tradeStatus = Arr::get($this->data, 'trade_status', '');
|
||||
$pay_state = PayState::ERROR;
|
||||
if ($tradeStatus == 'TRADE_SUCCESS') {
|
||||
$pay_state = PayState::SUCCESS;
|
||||
if (!bc_equal(Helps::floatFormat($recharge->pay_money), Helps::floatFormat($this->data['receipt_amount']))) {
|
||||
$pay_state = PayState::UNEQUAL;
|
||||
}
|
||||
}
|
||||
$res = CustomerRecharge::query()->where('id', $recharge->id)
|
||||
->where('recharge_sn', $rechargeSn)
|
||||
->whereNotIn('pay_state', [PayState::ERROR,PayState::SUCCESS,PayState::UNEQUAL])
|
||||
->update([
|
||||
'out_trade_no' => $this->data['trade_no'],
|
||||
'received_money' => $this->data['receipt_amount'],
|
||||
'pay_at' => $this->data['gmt_create'],
|
||||
'pay_state' => $pay_state,
|
||||
]);
|
||||
if (!$res) {
|
||||
Log::error('HandleAgentAlipayResultNotice recharge_update_fail', [
|
||||
'data' => $this->data,
|
||||
'rechargeSn' => $rechargeSn,
|
||||
'res' => $res,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -56,7 +92,7 @@ class HandleAgentAlipayResultNotice implements ShouldQueue
|
|||
$aliNotice->notify_id = Arr::get($this->data, 'notify_id', '');
|
||||
$aliNotice->out_trade_no = Arr::get($this->data, 'out_trade_no', '');
|
||||
$aliNotice->trade_no = Arr::get($this->data, 'trade_no', '');
|
||||
$aliNotice->trade_status = Arr::get($this->data, 'trade_status', '');
|
||||
$aliNotice->trade_status = $tradeStatus;
|
||||
$aliNotice->receipt_amount = Arr::get($this->data, 'receipt_amount', 0);
|
||||
$aliNotice->buyer_pay_amount = Arr::get($this->data, 'buyer_pay_amount', '');
|
||||
$aliNotice->total_amount = Arr::get($this->data, 'total_amount', 0);
|
||||
|
|
@ -68,31 +104,8 @@ class HandleAgentAlipayResultNotice implements ShouldQueue
|
|||
$aliNotice->response = $this->data;
|
||||
$aliNotice->save();
|
||||
|
||||
$rechargeSn = $this->data['out_trade_no'];
|
||||
$rechargeObj = new CustomerRecharge();
|
||||
$recharge = $rechargeObj->where('recharge_sn', $rechargeSn)->first();
|
||||
if (!$recharge) {
|
||||
Log::error('HandleAgentAlipayResultNotice 表中充值单号', [
|
||||
'data' => $this->data,
|
||||
'rechargeSn' => $rechargeSn,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($aliNotice->trade_status == 'TRADE_SUCCESS') {
|
||||
$recharge->pay_state = PayState::SUCCESS;
|
||||
if (!bc_equal(Helps::floatFormat($recharge->pay_money), Helps::floatFormat($this->data['receipt_amount']))) {
|
||||
$recharge->pay_state = PayState::UNEQUAL;
|
||||
}
|
||||
} else {
|
||||
$recharge->pay_state = PayState::ERROR;
|
||||
}
|
||||
$recharge->out_trade_no = $this->data['trade_no'];
|
||||
$recharge->received_money = $this->data['receipt_amount'];
|
||||
$recharge->pay_at = $this->data['gmt_create'];
|
||||
$recharge->save();
|
||||
|
||||
if ($recharge->pay_state == PayState::SUCCESS) {
|
||||
if ($pay_state == PayState::SUCCESS) {
|
||||
$recharge = $rechargeObj->where('recharge_sn', $rechargeSn)->first();
|
||||
CustomerWalletService::recharge($recharge);
|
||||
// 如果有订单,则处理订单支付状态
|
||||
if ($recharge->order_id > 0) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue