文件
xionggeshop/addons/shopro_huifu/command/CompensateQuery.php

92 行
1.6 KiB
PHP

<?php
namespace addons\shopro_huifu\command;
use addons\shopro_huifu\library\HuifuQueryService;
use think\console\Command;
use think\console\Input;
use think\console\input\Option;
use think\console\Output;
class CompensateQuery extends Command
{
protected function configure()
{
$this->setName('shopro_huifu:compensate')
->addOption('order_sn', null, Option::VALUE_OPTIONAL, '补偿单笔订单(商户订单号/req_seq_id)')
->setDescription('Compensate pending Huifu payment orders via official query API');
}
protected function execute(Input $input, Output $output)
{
if (!class_exists('\\addons\\shopro_huifu\\library\\Bridge') || !\addons\shopro_huifu\library\Bridge::isEnabled()) {
$output->writeln('Huifu plugin disabled.');
return;
}
$service = new HuifuQueryService();
$orderSn = trim((string) $input->getOption('order_sn'));
if ($orderSn !== '') {
try {
$result = $service->compensateByOrderSn($orderSn);
$output->writeln(($result['ok'] ? '[OK] ' : '[FAIL] ') . $result['message']);
if (!empty($result['req_seq_id'])) {
$output->writeln('req_seq_id=' . $result['req_seq_id']);
}
} catch (\Throwable $e) {
$output->writeln('[FAIL] ' . $e->getMessage());
}
return;
}
$results = $service->compensatePending();
$output->writeln('Huifu compensate finished. ok=' . $results['ok'] . ' fail=' . $results['fail']);
}
}