chunkById(1, function ($logs) use ($yeePayService) { foreach ($logs as $log) { try { $result = $yeePayService->request('accountpay.behalf.Pay', [ 'payerOutUserId' => config('services.yeepay.partner_id'), 'merchOrderNo' => $log->pay_sn, 'tradeName' => '余额提现', 'payeeUserName' => $log->username, 'bankCardNo' => $log->bank_number, 'bankCode' => Bank::tryFromBankName($log->bank_name)?->name, 'bankCardType' => 'DEBIT_CARD', 'amount' => bcdiv($log->account_amount, 100, 2), 'feeRole' => 'PAYER', 'tradeMemo' => '商城余额提现', 'context' => json_encode(['type' => 'wallet_to_bank']), ]); // 如果交易超时,重新发起支付 if ($result['resultCode'] === 'TIME_OUT') { continue; } if ($result['orderStatus'] === 'SUCCESS') { $log->update([ 'status' => WalletToBankLogStatus::Success, 'pay_at' => now(), 'failed_reason' => null, ]); } elseif ($result['orderStatus'] === 'FAIL') { $log->update([ 'status' => WalletToBankLogStatus::Failed, 'failed_reason' => '交易失败', ]); } else { $log->update([ 'status' => WalletToBankLogStatus::Paying, 'failed_reason' => null, ]); } } catch (YeePayException $e) { $log->update([ 'status' => WalletToBankLogStatus::Failed, 'failed_reason' => $e->getMessage(), ]); } catch (Throwable $e) { throw $e; } } }); sleep(60); } } }