This commit is contained in:
Your Name
2026-04-07 18:13:03 +08:00
parent a780356908
commit fdf714f833
397 changed files with 15086 additions and 1043 deletions
@@ -5,9 +5,10 @@ declare(strict_types=1);
namespace app\common\command;
use app\adminapi\logic\order\OrderLogic;
use app\common\model\auth\Admin;
use app\common\model\Order;
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;
@@ -23,11 +24,24 @@ class SyncWechatWorkBills extends Command
$this->setName('sync_wechat_work_bills')
->setDescription('同步企业微信对外收款到订单(按天拉取)')
->addOption('date', 'd', Option::VALUE_OPTIONAL, '指定日期 Y-m-d,默认今天', '')
->addOption('days', null, Option::VALUE_OPTIONAL, '拉取最近N天,每天单独请求', '1');
->addOption('days', null, Option::VALUE_OPTIONAL, '拉取最近N天,每天单独请求', '1')
->addOption(
'fill-order-creators-only',
null,
Option::VALUE_NONE,
'仅补全订单创建人:creator_id 为空时用 payee_userid 匹配 admin.work_wechat_userid(可单独做定时任务)'
);
}
protected function execute(Input $input, Output $output)
{
if ($input->getOption('fill-order-creators-only')) {
$fixed = $this->fillOrderCreatorsFromPayee();
$output->writeln("补全创建人完成,共更新 {$fixed} 条订单");
return;
}
$dateStr = $input->getOption('date');
$days = (int)$input->getOption('days');
$days = $days > 0 ? min($days, 31) : 1;
@@ -68,4 +82,32 @@ class SyncWechatWorkBills extends Command
}
}
}
/**
* creator_id 为空的订单,用 payee_userid 匹配管理员 work_wechat_userid 写入 creator_id
*/
protected function fillOrderCreatorsFromPayee(): int
{
$fixed = 0;
Order::whereRaw('(creator_id IS NULL OR creator_id = 0)')
->whereNotNull('payee_userid')
->where('payee_userid', '<>', '')
->chunk(200, function ($orders) use (&$fixed) {
foreach ($orders as $order) {
$payee = trim((string) $order->getAttr('payee_userid'));
if ($payee === '') {
continue;
}
$admin = Admin::where('work_wechat_userid', $payee)->whereNull('delete_time')->find();
if (!$admin) {
continue;
}
$order->creator_id = (int) $admin->getAttr('id');
$order->save();
$fixed++;
}
});
return $fixed;
}
}