You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
payment/app/Command/WithdrawCommand.php

96 lines
2.4 KiB
PHTML

11 months ago
<?php
declare(strict_types=1);
namespace App\Command;
use App\Helper\StringHelper;
use App\Model\BankCard;
use App\Model\Order;
use App\Model\User;
use App\Service\PaymentService;
use App\Service\RequestService;
use App\Service\UserService;
use Hyperf\Command\Annotation\Command;
use Hyperf\Command\Command as HyperfCommand;
use Hyperf\Contract\ContainerInterface;
/**
* @Command
*/
class WithdrawCommand extends HyperfCommand
{
/**
* @var ContainerInterface
*/
protected $container;
protected $admin;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
parent::__construct('withdraw');
}
public function configure(): void
{
parent::configure();
$this->setDescription('提现');
}
public function handle(): void
{
$this->confirmPay();
}
public function confirmPay()
{
/**
* @var PaymentService $paymentService
*/
$paymentService = $this->container->make(PaymentService::class);
/**
* @var UserService $userService
*/
$userService = $this->container->make(UserService::class);
$user = User::where('user_id', 'ACT_5')->first();
11 months ago
11 months ago
$balance = $userService->getBalance($user->member_id);
11 months ago
echo 'before balance' . $balance . PHP_EOL;
11 months ago
$bankCard = BankCard::where('user_id', $user->user_id)->first();
$requestLog = $this->createRequestLog([
'userId' => $user->user_id,
'withdrawType' => 'entrust',
11 months ago
'agreementNo' => $bankCard->agreement_no,
'outWithdrawNo' => StringHelper::generateOrderNo(StringHelper::ORDER_NO_TYPE_ACCOUNT_WITHDRAW),
11 months ago
'amount' => $balance
]);
11 months ago
11 months ago
$url = $paymentService->withdraw($requestLog->getData(), $requestLog->app, $requestLog->request_token);
11 months ago
echo 'result' . $url . PHP_EOL;
$balance = $userService->getBalance($user->member_id);
echo 'after balance' . $balance . PHP_EOL;
11 months ago
}
private function createRequestLog($data) {
/**
* @var RequestService $requestService
*/
$requestService = $this->container->make(RequestService::class);
$params = [
'app_id' => '202308070000001',
'data' => json_encode($data),
];
return $requestService->createRequestLog('', $params);
}
}