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
This commit is contained in:
mac
2026-03-24 20:40:46 +08:00
parent a41e0ab0f7
commit 451918bc73
11 changed files with 180 additions and 23 deletions

View File

@@ -0,0 +1,118 @@
<?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;
}
}

View File

@@ -118,8 +118,12 @@ class SystemTimer extends AuthController
if (!$mark) {
return $this->fail('定时任务标识不存在');
}
$this->services->runNow($mark);
return $this->success('任务已触发');
try {
$this->services->runNow($mark);
return $this->success('任务已触发并执行成功');
} catch (\Throwable $e) {
return $this->fail($e->getMessage());
}
}
/**

View File

@@ -201,7 +201,7 @@ class SystemTimer extends Cron implements ListenerInterface
$timerServices = app()->make(SystemTimerServices::class);
$taskName = $timerServices->getTasKName();
response_log_write([
'message' => '定时任务:[' . $taskName[$mark] ?? '未知' . '],失败原因:[' . class_basename($this) . ']',
'message' => '定时任务:[' . ($taskName[$mark] ?? '未知') . '],失败原因:[' . class_basename($this) . ']',
'file' => $e->getFile(),
'line' => $e->getLine(),
'msg' => $e->getMessage()

View File

@@ -39,6 +39,11 @@ class UserPointServices extends BaseServices
'storeIntegral_use' => '积分兑换商品',
'pay_product_integral_back' => '返还下单使用积分',
'sign' => '签到获得积分',
'hjf_frozen_direct' => '直推积分奖励',
'hjf_frozen_umbrella' => '伞下积分奖励',
'frozen_points_brokerage' => '佣金奖励积分(待释放)',
'frozen_points_release' => '每日积分释放',
'holiday_gift_integral' => '节日有礼赠送积分',
];
[$page, $limit] = $this->getPageValue();
$list = $this->dao->getList($where, '*', $page, $limit);
@@ -59,9 +64,9 @@ class UserPointServices extends BaseServices
} elseif ($item['type'] == 'storeIntegral_use') {
$item['relation'] = $integralOrderServices->value(['id' => $item['link_id']], 'order_id');
} else {
$item['relation'] = $status[$item['type']];
$item['relation'] = $status[$item['type']] ?? $item['type'];
}
$item['type_name'] = $status[$item['type']];
$item['type_name'] = $status[$item['type']] ?? $item['type'];
}
$count = $this->dao->count($where);
return compact('list', 'count', 'status');

View File

@@ -6,6 +6,7 @@ namespace app\services\hjf;
use app\dao\hjf\PointsReleaseLogDao;
use app\dao\user\UserDao;
use app\services\BaseServices;
use app\services\user\UserBillServices;
use crmeb\services\SystemConfigService;
use think\annotation\Inject;
use think\facade\Db;
@@ -29,6 +30,9 @@ class PointsReleaseServices extends BaseServices
#[Inject]
protected UserDao $userDao;
#[Inject]
protected UserBillServices $userBillServices;
/**
* 执行今日积分释放(批量)
*
@@ -89,6 +93,18 @@ class PointsReleaseServices extends BaseServices
'status' => 'released',
'release_date' => $releaseDate,
]);
// 同步写入 eb_user_bill使管理后台积分日志页面可见
$integralBalance = (int)($this->userDao->value(['uid' => $user['uid']], 'integral') ?: 0);
$this->userBillServices->income(
'frozen_points_release',
(int)$user['uid'],
(int)$releaseAmount,
$integralBalance,
0,
0,
"积分每日自动解冻,释放日期 {$releaseDate}"
);
});
$totalReleased += $releaseAmount;

View File

@@ -275,6 +275,12 @@ class StoreOrderTakeServices extends BaseServices
}
//订单中取出
$brokeragePrice = $orderInfo['one_brokerage'] ?? 0;
// fsgx: 积分奖励独立于佣金金额,只要是报单订单且推荐人存在就触发
if ($isQueueOrder && $one_spread_uid > 0) {
$this->grantFrozenPointsByBrokerage($one_spread_uid, $brokeragePrice, $orderInfo);
}
// 返佣金额小于等于0 直接返回不返佣金
if ($brokeragePrice <= 0) {
return true;
@@ -299,9 +305,6 @@ class StoreOrderTakeServices extends BaseServices
//给上级发送获得佣金的模板消息
$this->sendBackOrderBrokerage($orderInfo, $one_spread_uid, $brokeragePrice);
// fsgx: 若推荐人有分销等级(创客及以上),在佣金发放时同步发放积分到 frozen_points
$this->grantFrozenPointsByBrokerage($one_spread_uid, $brokeragePrice, $orderInfo);
// 一级返佣成功 跳转二级返佣
$res = $res1 && $res2 && $this->backOrderBrokerageTwo($orderInfo, $userInfo, $isSelfBrokerage, $frozen_time);
return $res;
@@ -309,21 +312,21 @@ class StoreOrderTakeServices extends BaseServices
/**
* fsgx: 佣金发放后,按照 eb_agent_level 配置的「直推/伞下奖励积分」发放 frozen_points
* fsgx: 按照 eb_agent_level 配置的「直推/伞下奖励积分」发放 frozen_points
*
* 积分奖励规则:
* - 直推上级:获得其等级 direct_reward_points 配置的积分
* - 更上级(伞下):按级差规则获得 umbrella_reward_points 积分
* - 具体计算由 PointsRewardServices::reward() 统一实现,同 HjfOrderPayJob 逻辑保持一致
* - 具体计算由 PointsRewardServices::reward() 统一实现
*
* @param int $spreadUid 直推上级uid仅用于前置校验
* @param string|float $brokeragePrice 本次佣金金额(前置校验用
* @param string|float $brokeragePrice 本次佣金金额(仅日志参考,不再作为前置条件
* @param array $orderInfo 订单信息(需含 uid、order_id
*/
protected function grantFrozenPointsByBrokerage(int $spreadUid, $brokeragePrice, array $orderInfo): void
{
try {
if ($spreadUid <= 0 || $brokeragePrice <= 0) return;
if ($spreadUid <= 0) return;
$buyerUid = (int)($orderInfo['uid'] ?? 0);
$orderId = (string)($orderInfo['order_id'] ?? '');
if ($buyerUid <= 0 || $orderId === '') return;

View File

@@ -51,6 +51,7 @@ class SystemTimerServices extends BaseServices
'auto_presale_product' => '预售商品到期处理数据',
'auto_card_code' => '清理到期礼品卡',
'holiday_gift_push_task'=>'节日有礼赠送礼品',
'fsgx_release_frozen_points' => 'fsgx每日积分释放',
];
/**
@@ -240,9 +241,14 @@ class SystemTimerServices extends BaseServices
public function runNow(string $mark): void
{
$this->update(['mark' => $mark], ['last_execution_time' => time()]);
$ref = new \ReflectionClass(SystemTimerListener::class);
$instance = $ref->newInstanceWithoutConstructor();
$instance->implement_timer($mark);
try {
$ref = new \ReflectionClass(SystemTimerListener::class);
$instance = $ref->newInstanceWithoutConstructor();
$instance->implement_timer($mark);
} catch (\Throwable $e) {
$taskName = $this->taskName[$mark] ?? $mark;
throw new \RuntimeException("定时任务[{$taskName}]执行失败: " . $e->getMessage(), 0, $e);
}
}
/**获取下次执行时间

View File

@@ -23,5 +23,7 @@ return [
'clear:cache' => \app\command\ClearCache::class,
'reset:password' => \app\command\ResetAdminPwd::class,
'holiday_gift_push_task' => \app\command\HolidayGiftPushTask::class,
'hjf:release-points' => \app\command\HjfReleasePoints::class,
'hjf:patch-rewards' => \app\command\HjfPatchMissingRewards::class,
],
];

View File

@@ -16,7 +16,7 @@ export function getMemberInfo() {
* 获取团队成员列表(复用 CRMEB 推广用户列表接口)
*/
export function getTeamData(params) {
return request.get('spread/people', params);
return request.post('spread/people', params);
}
/**

View File

@@ -229,12 +229,12 @@
* @returns {void}
*/
loadTeamData() {
getTeamData().then(res => {
getTeamData({ grade: 0 }).then(res => {
const d = (res && res.data) || {};
this.teamData = {
direct_count: d.direct_count || 0,
umbrella_count: d.umbrella_count || 0,
umbrella_orders: d.umbrella_orders || 0,
direct_count: d.total || 0,
umbrella_count: d.totalLevel || 0,
umbrella_orders: d.order_count || 0,
};
}).catch(() => {});