54 行
2.2 KiB
PHP
54 行
2.2 KiB
PHP
<?php
|
||
|
||
namespace addons\shopro\console;
|
||
|
||
use think\console\Input;
|
||
use think\console\Output;
|
||
use think\console\input\Option;
|
||
use think\console\Command;
|
||
use addons\shopro\service\partner\DailySettleService;
|
||
|
||
class PartnerSettle extends Command
|
||
{
|
||
protected function configure()
|
||
{
|
||
$this->setName('shopro:partner:settle')
|
||
->addOption('date', 'd', Option::VALUE_OPTIONAL, '结算日期 Y-m-d,指定日期时执行传统日结')
|
||
->addOption('rerun', 'r', Option::VALUE_NONE, '删除当天日结后重算')
|
||
->addOption('daily', null, Option::VALUE_NONE, '强制执行昨天标准日结')
|
||
->setDescription('收益中心结算(默认1分钟dmepa增量结算与兑换券释放,亦支持指定日期日结)');
|
||
}
|
||
|
||
protected function execute(Input $input, Output $output)
|
||
{
|
||
$date = $input->getOption('date');
|
||
$rerun = (bool) $input->getOption('rerun');
|
||
$isDaily = (bool) $input->getOption('daily');
|
||
|
||
// 指定日期或强制日结模式
|
||
if ($date || $isDaily || $rerun) {
|
||
$settleDate = $date ?: date('Y-m-d', strtotime('-1 day'));
|
||
$output->writeln('partner daily settle start ' . $settleDate . ($rerun ? ' rerun' : ''));
|
||
try {
|
||
$report = (new DailySettleService())->run($date, $rerun);
|
||
$output->writeln('partner daily settle done: ' . json_encode($report ? $report->toArray() : [], JSON_UNESCAPED_UNICODE));
|
||
return 0;
|
||
} catch (\Exception $e) {
|
||
$output->writeln('partner daily settle fail: ' . $e->getMessage());
|
||
return 1;
|
||
}
|
||
}
|
||
|
||
// 默认执行 1 分钟dmepa增量结算与兑换券释放
|
||
$output->writeln('[' . date('Y-m-d H:i:s') . '] partner minute settle start');
|
||
try {
|
||
$result = (new DailySettleService())->runMinute();
|
||
$output->writeln('[' . date('Y-m-d H:i:s') . '] partner minute settle done: ' . json_encode($result, JSON_UNESCAPED_UNICODE));
|
||
return 0;
|
||
} catch (\Exception $e) {
|
||
$output->writeln('[' . date('Y-m-d H:i:s') . '] partner minute settle fail: ' . $e->getMessage());
|
||
return 1;
|
||
}
|
||
}
|
||
}
|