Files
huangjingfen/pro_v3.5.1/app/command/HjfPatchMissingRewards.php
mac 451918bc73 fix(fsgx): 修复5个未修复Bug — 积分解耦/定时任务/积分日志/团队统计/历史补偿
Bug3: 解耦积分奖励与佣金发放,报单订单只要推荐人存在即触发积分,
不再依赖 brokeragePrice > 0;grantFrozenPointsByBrokerage 移至
佣金判断之前独立执行。

Bug1: 定时任务手动触发返回真实结果 —— 补充 fsgx_release_frozen_points
到 taskName 映射;runNow() try/catch 后抛出异常;控制器捕获并返回
fail;修复 SystemTimer listener catch 块运算符优先级 bug。

Bug5: PointsReleaseServices 每日释放同步写入 eb_user_bill,使管理
后台积分日志页面可见;UserPointServices::pointRecord $status 数组
补充 hjf_frozen_direct/hjf_frozen_umbrella/frozen_points_release 等
fsgx 类型映射,防止未知类型报错。

Bug2: hjfMember.js getTeamData 改为 POST 与路由匹配;loadTeamData
字段映射 total/totalLevel/order_count → 界面展示字段。

Bug4: 新增 HjfPatchMissingRewards 命令(hjf:patch-rewards),支持
扫描全量/指定订单补发缺失积分奖励,支持 --dry-run 预览;注册命令
到 config/console.php。

Made-with: Cursor
2026-03-24 20:40:46 +08:00

119 lines
4.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare(strict_types=1);
namespace app\command;
use app\services\hjf\PointsRewardServices;
use think\console\Command;
use think\console\Input;
use think\console\input\Option;
use think\console\Output;
use think\facade\Db;
use think\facade\Log;
/**
* 补偿历史报单订单缺失的积分奖励
*
* 用法:
* php think hjf:patch-rewards # 扫描全部报单订单
* php think hjf:patch-rewards --order-id=11 # 仅补偿指定订单
* php think hjf:patch-rewards --dry-run # 仅扫描不执行
*/
class HjfPatchMissingRewards extends Command
{
protected function configure(): void
{
$this->setName('hjf:patch-rewards')
->setDescription('补偿历史报单订单缺失的冻结积分奖励')
->addOption('order-id', null, Option::VALUE_OPTIONAL, '指定订单ID不传则扫描全部')
->addOption('dry-run', null, Option::VALUE_NONE, '仅扫描打印,不实际执行');
}
protected function execute(Input $input, Output $output): int
{
$orderId = $input->getOption('order-id');
$dryRun = $input->getOption('dry-run');
$output->writeln('[HjfPatchRewards] 开始扫描缺失积分奖励的报单订单...');
$query = Db::name('store_order')
->where('is_queue_goods', 1)
->where('paid', 1)
->where('is_del', 0)
->where('is_system_del', 0);
if ($orderId) {
$query->where('id', (int)$orderId);
}
$orders = $query->field('id,order_id,uid,spread_uid,one_brokerage')->select()->toArray();
if (empty($orders)) {
$output->writeln('[HjfPatchRewards] 没有找到符合条件的报单订单');
return 0;
}
$output->writeln(sprintf('[HjfPatchRewards] 找到 %d 笔报单订单', count($orders)));
/** @var PointsRewardServices $pointsService */
$pointsService = app()->make(PointsRewardServices::class);
$patched = 0;
$skipped = 0;
foreach ($orders as $order) {
$hasRewardLog = Db::name('points_release_log')
->where('order_id', $order['order_id'])
->where('type', 'reward_direct')
->count();
$hasRewardBill = Db::name('user_bill')
->where('link_id', $order['id'])
->where('type', 'hjf_frozen_direct')
->count();
if ($hasRewardLog > 0 || $hasRewardBill > 0) {
$skipped++;
$output->writeln(sprintf(' [SKIP] 订单 #%d (%s) 已有积分奖励记录', $order['id'], $order['order_id']));
continue;
}
if (!$order['spread_uid'] || $order['spread_uid'] <= 0) {
$skipped++;
$output->writeln(sprintf(' [SKIP] 订单 #%d (%s) 无推荐人', $order['id'], $order['order_id']));
continue;
}
if ($dryRun) {
$output->writeln(sprintf(
' [DRY-RUN] 订单 #%d (%s) uid=%d spread_uid=%d 需要补发积分',
$order['id'], $order['order_id'], $order['uid'], $order['spread_uid']
));
$patched++;
continue;
}
try {
$pointsService->reward((int)$order['uid'], (string)$order['order_id'], (int)$order['id']);
$patched++;
$output->writeln(sprintf(
' [PATCHED] 订单 #%d (%s) 已补发积分奖励',
$order['id'], $order['order_id']
));
} catch (\Throwable $e) {
$output->writeln(sprintf(
' [ERROR] 订单 #%d (%s): %s',
$order['id'], $order['order_id'], $e->getMessage()
));
Log::error("[HjfPatchRewards] 订单 #{$order['id']} 补发失败: " . $e->getMessage());
}
}
$output->writeln(sprintf(
'[HjfPatchRewards] 完成:补发 %d 笔,跳过 %d 笔%s',
$patched, $skipped, $dryRun ? ' (dry-run 模式)' : ''
));
return 0;
}
}