新增
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\common\command;
|
||||
|
||||
use app\adminapi\logic\order\OrderLogic;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\input\Argument;
|
||||
use think\console\input\Option;
|
||||
use think\console\Output;
|
||||
use think\facade\Log;
|
||||
|
||||
/**
|
||||
* 同步企业微信对外收款到订单
|
||||
* 按天拉取,避免接口时间范围限制
|
||||
*/
|
||||
class SyncWechatWorkBills extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('sync_wechat_work_bills')
|
||||
->setDescription('同步企业微信对外收款到订单(按天拉取)')
|
||||
->addOption('date', 'd', Option::VALUE_OPTIONAL, '指定日期 Y-m-d,默认今天', '')
|
||||
->addOption('days', null, Option::VALUE_OPTIONAL, '拉取最近N天,每天单独请求', '1');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$dateStr = $input->getOption('date');
|
||||
$days = (int)$input->getOption('days');
|
||||
$days = $days > 0 ? min($days, 31) : 1;
|
||||
|
||||
$totalCreated = 0;
|
||||
$totalUpdated = 0;
|
||||
$totalSkipped = 0;
|
||||
$errors = [];
|
||||
|
||||
if ($dateStr) {
|
||||
$dates = [$dateStr];
|
||||
} else {
|
||||
$dates = [];
|
||||
for ($i = 0; $i < $days; $i++) {
|
||||
$dates[] = date('Y-m-d', strtotime("-{$i} days"));
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($dates as $d) {
|
||||
$beginTime = strtotime($d . ' 00:00:00');
|
||||
$endTime = strtotime($d . ' 23:59:59');
|
||||
$output->writeln("同步 {$d} ...");
|
||||
$result = OrderLogic::syncFromWechatWorkBills($beginTime, $endTime);
|
||||
$totalCreated += $result['created'];
|
||||
$totalUpdated += $result['updated'];
|
||||
$totalSkipped += $result['skipped'];
|
||||
if (!empty($result['errors'])) {
|
||||
$errors = array_merge($errors, $result['errors']);
|
||||
}
|
||||
$output->writeln(" -> 新增 {$result['created']} 更新 {$result['updated']} 跳过 {$result['skipped']}");
|
||||
}
|
||||
|
||||
$output->writeln("完成: 共新增 {$totalCreated} 更新 {$totalUpdated} 跳过 {$totalSkipped}");
|
||||
if (!empty($errors)) {
|
||||
foreach ($errors as $e) {
|
||||
$output->writeln("<error>{$e}</error>");
|
||||
Log::error('sync_wechat_work_bills: ' . $e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user