|
|
|
<?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_9')->first();
|
|
|
|
|
|
|
|
$balance = $userService->getBalance($user->member_id);
|
|
|
|
|
|
|
|
echo 'before balance: ' . $balance . PHP_EOL;
|
|
|
|
|
|
|
|
if ($balance == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$bankCard = BankCard::where('user_id', $user->user_id)->first();
|
|
|
|
|
|
|
|
$requestLog = $this->createRequestLog([
|
|
|
|
'userId' => $user->user_id,
|
|
|
|
'withdrawType' => 'entrust',
|
|
|
|
'agreementNo' => $bankCard->agreement_no,
|
|
|
|
'outWithdrawNo' => StringHelper::generateOrderNo(StringHelper::ORDER_NO_TYPE_ACCOUNT_WITHDRAW),
|
|
|
|
'amount' => $balance,
|
|
|
|
'notifyUrl' => 'http://124.223.222.61:9701/notify/test-notify'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$url = $paymentService->withdraw($requestLog->getData(), $requestLog->app, $requestLog->request_token);
|
|
|
|
|
|
|
|
echo 'result: ' . $url . PHP_EOL;
|
|
|
|
|
|
|
|
$balance = $userService->getBalance($user->member_id);
|
|
|
|
echo 'after balance: ' . $balance . PHP_EOL;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|