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.
75 lines
2.0 KiB
PHP
75 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Command;
|
|
|
|
use App\Model\Order;
|
|
use App\Service\PaymentService;
|
|
use App\Service\RequestService;
|
|
use Hyperf\Command\Annotation\Command;
|
|
use Hyperf\Command\Command as HyperfCommand;
|
|
use Hyperf\Contract\ContainerInterface;
|
|
|
|
/**
|
|
* @Command
|
|
*/
|
|
class PaymentCommand extends HyperfCommand
|
|
{
|
|
/**
|
|
* @var ContainerInterface
|
|
*/
|
|
protected $container;
|
|
|
|
protected $admin;
|
|
|
|
public function __construct(ContainerInterface $container)
|
|
{
|
|
$this->container = $container;
|
|
|
|
parent::__construct('payment');
|
|
}
|
|
|
|
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);
|
|
$endTime = date('Y-m-d H:i:s', time() - 6*60);
|
|
$beginTime = date('Y-m-d H:i:s', time() - 20*60);
|
|
$orders = Order::where('updated_at', '>=', $beginTime)->where('updated_at', '<=', $endTime)->where('status', 'SUCCESS')->get();
|
|
foreach ($orders as $order) {
|
|
if ($order->user_id != 'ELF1990' && strpos($order->user_id, 'ACT_') !== 0) {
|
|
continue;
|
|
}
|
|
$userId = $order->user_id;
|
|
$requestLog = $this->createRequestLog(['userId' => $userId, 'oldOutOrderNo' => $order->out_order_no, 'amount' => $order->amount]);
|
|
$result = $paymentService->confirmPay($requestLog->getData(), $requestLog->app, $requestLog->request_token);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
} |