93 lines
3.4 KiB
PHP
93 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands\Dealer;
|
|
|
|
use App\Enums\Bank;
|
|
use App\Enums\DealerWalletToBankLogStatus;
|
|
use App\Exceptions\YeePayException;
|
|
use App\Models\DealerWalletToBankLog;
|
|
use App\Services\YeePayService;
|
|
use Illuminate\Console\Command;
|
|
use Throwable;
|
|
|
|
class WalletToBankCommand extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'dealer:wallet-to-bank';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = '批零提现';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return int
|
|
*/
|
|
public function handle()
|
|
{
|
|
$yeePayService = new YeePayService(config('services.yeepay'));
|
|
|
|
while (true) {
|
|
DealerWalletToBankLog::where('status', DealerWalletToBankLogStatus::Passed)->chunkById(1, function ($logs) use ($yeePayService) {
|
|
foreach ($logs as $log) {
|
|
try {
|
|
$result = $yeePayService->request('accountpay.behalf.Pay', [
|
|
'payerOutUserId' => '21102510220227100003' ?: config('services.yeepay.partner_id'),
|
|
'merchOrderNo' => $log->pay_sn,
|
|
'tradeName' => '批零提现',
|
|
'payeeUserName' => data_get($log->pay_info, 'bank.user_name'),
|
|
'bankCardNo' => data_get($log->pay_info, 'bank.bank_number'),
|
|
'bankCode' => Bank::tryFromBankName(data_get($log->pay_info, 'bank.bank_name'))?->name,
|
|
'bankCardType' => 'DEBIT_CARD',
|
|
'amount' => $log->account_amount,
|
|
'feeRole' => 'PAYER',
|
|
'tradeMemo' => '批零提现',
|
|
'context' => json_encode(['type' => 'dealer_wallet_to_bank']),
|
|
]);
|
|
|
|
// 如果交易超时,重新发起支付
|
|
if ($result['resultCode'] === 'TIME_OUT') {
|
|
continue;
|
|
}
|
|
|
|
if ($result['orderStatus'] === 'SUCCESS') {
|
|
$log->update([
|
|
'status' => DealerWalletToBankLogStatus::Success,
|
|
'pay_at' => now(),
|
|
'failed_reason' => null,
|
|
]);
|
|
} elseif ($result['orderStatus'] === 'FAIL') {
|
|
$log->update([
|
|
'status' => DealerWalletToBankLogStatus::Failed,
|
|
'failed_reason' => '交易失败',
|
|
]);
|
|
} else {
|
|
$log->update([
|
|
'status' => DealerWalletToBankLogStatus::Paying,
|
|
'failed_reason' => null,
|
|
]);
|
|
}
|
|
} catch (YeePayException $e) {
|
|
$log->update([
|
|
'status' => DealerWalletToBankLogStatus::Failed,
|
|
'failed_reason' => $e->getMessage(),
|
|
]);
|
|
} catch (Throwable $e) {
|
|
throw $e;
|
|
}
|
|
}
|
|
});
|
|
|
|
sleep(60);
|
|
}
|
|
}
|
|
}
|