Files
cycle_api/app/Jobs/Wallet/WalletPlatformTransactionQueue.php
2024-03-27 00:11:26 +08:00

59 lines
1.8 KiB
PHP

<?php
namespace App\Jobs\Wallet;
use App\Bean\Queue\Wallet\QueueWalletPlatformTransactionBean;
use App\Models\Wallet\Wallet\WalletAddressTransactionModel;
use App\Service\Wallet\PlatformRechargeService;
use App\Service\Wallet\PlatformWithdrawService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class WalletPlatformTransactionQueue implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*/
public function __construct()
{
//处理平台到账账变
}
/**
* Execute the job.
*/
public function handle(array $params): void
{
$bean = new QueueWalletPlatformTransactionBean($params);
$oWithdrawService = new PlatformWithdrawService();
$oRechargeSService = new PlatformRechargeService();
try {
$type = $bean->getType();
//提现
if ($type == WalletAddressTransactionModel::TYPE_WITHDRAW) {
$oWithdrawService->walletPlatformTransactionConsumer($bean);
}
//充值
if ($type == WalletAddressTransactionModel::TYPE_RECHARGE) {
$oRechargeSService->walletPlatformTransactionConsumer($bean);
}
} catch (\Exception $e) {
}
}
public static function putToQueue(QueueWalletPlatformTransactionBean $bean, $delaySec = null): \Illuminate\Foundation\Bus\PendingDispatch
{
$queue = self::dispatch($bean->toArrayNotNull())->onQueue(QueueWalletPlatformTransactionBean::QUEUE_NAME);
if(!empty($delaySec)){
$queue->delay(now()->addSeconds($delaySec));
}
return $queue;
}
}