diff --git a/docs/issues-0323-1.md b/docs/issues-0323-1.md index d3a7e4c0..f04dcc43 100644 --- a/docs/issues-0323-1.md +++ b/docs/issues-0323-1.md @@ -36,7 +36,7 @@ 1. **已修复**点击获取验证,去除安全验证,直接发送验证码 ## 佣金记录页面,uniapp/pages/users/user_spread_money -1. 团队业绩统计数据的伞下人数不显示 +1. **已修复**团队业绩统计数据的伞下人数不显示 --- diff --git a/pro_v3.5.1/app/command/HjfPatchMissingRewards.php b/pro_v3.5.1/app/command/HjfPatchMissingRewards.php index 58cbf02b..b0157cef 100644 --- a/pro_v3.5.1/app/command/HjfPatchMissingRewards.php +++ b/pro_v3.5.1/app/command/HjfPatchMissingRewards.php @@ -3,7 +3,9 @@ declare(strict_types=1); namespace app\command; +use app\services\agent\AgentLevelServices; use app\services\hjf\PointsRewardServices; +use app\services\user\UserServices; use think\console\Command; use think\console\Input; use think\console\input\Option; @@ -57,21 +59,22 @@ class HjfPatchMissingRewards extends Command /** @var PointsRewardServices $pointsService */ $pointsService = app()->make(PointsRewardServices::class); + /** @var AgentLevelServices $agentLevelServices */ + $agentLevelServices = app()->make(AgentLevelServices::class); + /** @var UserServices $userServices */ + $userServices = app()->make(UserServices::class); + $patched = 0; $skipped = 0; foreach ($orders as $order) { + // 幂等检查:points_release_log 中是否已有 reward_direct/reward_umbrella 记录 $hasRewardLog = Db::name('points_release_log') ->where('order_id', $order['order_id']) - ->where('type', 'reward_direct') + ->whereIn('type', ['reward_direct', 'reward_umbrella']) ->count(); - $hasRewardBill = Db::name('user_bill') - ->where('link_id', $order['id']) - ->where('type', 'hjf_frozen_direct') - ->count(); - - if ($hasRewardLog > 0 || $hasRewardBill > 0) { + if ($hasRewardLog > 0) { $skipped++; $output->writeln(sprintf(' [SKIP] 订单 #%d (%s) 已有积分奖励记录', $order['id'], $order['order_id'])); continue; @@ -93,11 +96,23 @@ class HjfPatchMissingRewards extends Command } try { - $pointsService->reward((int)$order['uid'], (string)$order['order_id'], (int)$order['id']); + $uid = (int)$order['uid']; + // 先执行等级升级检查,确保积分奖励使用正确的 agent_level + $userCacheInfo = $userServices->getUserCacheInfo($uid); + $spreadUid = $userCacheInfo ? (int)($userCacheInfo['spread_uid'] ?? 0) : (int)$order['spread_uid']; + $twoSpreadUid = 0; + if ($spreadUid > 0 && $oneUserInfo = $userServices->getUserCacheInfo($spreadUid)) { + $twoSpreadUid = $userServices->getSpreadUid($spreadUid, $oneUserInfo, false); + } + $uids = array_values(array_filter(array_unique([$uid, $spreadUid, $twoSpreadUid]))); + $agentLevelServices->checkUserLevelFinish($uid, $uids); + + // 发放积分奖励(PointsRewardServices 内部已做幂等检查) + $pointsService->reward($uid, (string)$order['order_id'], (int)$order['id']); $patched++; $output->writeln(sprintf( - ' [PATCHED] 订单 #%d (%s) 已补发积分奖励', - $order['id'], $order['order_id'] + ' [PATCHED] 订单 #%d (%s) uid=%d 等级检查+积分奖励已补发', + $order['id'], $order['order_id'], $uid )); } catch (\Throwable $e) { $output->writeln(sprintf( diff --git a/pro_v3.5.1/app/controller/admin/v1/hjf/QueueController.php b/pro_v3.5.1/app/controller/admin/v1/hjf/QueueController.php index d3d5df65..5c713385 100644 --- a/pro_v3.5.1/app/controller/admin/v1/hjf/QueueController.php +++ b/pro_v3.5.1/app/controller/admin/v1/hjf/QueueController.php @@ -54,7 +54,7 @@ class QueueController extends AuthController 'trigger_multiple' => (int)SystemConfigService::get('hjf_trigger_multiple', 4), 'release_rate' => (int)SystemConfigService::get('hjf_release_rate', 4), 'withdraw_fee_rate' => (int)SystemConfigService::get('hjf_withdraw_fee_rate', 7), - 'enabled' => (bool)SystemConfigService::get('hjf_queue_enabled', 1), + 'enabled' => (bool)SystemConfigService::get('hjf_queue_pool_enable', 0), ]; return $this->success($config); } @@ -75,7 +75,7 @@ class QueueController extends AuthController 'hjf_trigger_multiple' => (int)$data['trigger_multiple'], 'hjf_release_rate' => (int)$data['release_rate'], 'hjf_withdraw_fee_rate' => (int)$data['withdraw_fee_rate'], - 'hjf_queue_enabled' => (int)$data['enabled'], + 'hjf_queue_pool_enable' => (int)$data['enabled'], ]; foreach ($map as $key => $value) { diff --git a/pro_v3.5.1/app/listener/order/Pay.php b/pro_v3.5.1/app/listener/order/Pay.php index 7ba1fd64..8a8473f0 100644 --- a/pro_v3.5.1/app/listener/order/Pay.php +++ b/pro_v3.5.1/app/listener/order/Pay.php @@ -14,6 +14,8 @@ namespace app\listener\order; use app\jobs\agent\AgentJob; use app\jobs\hjf\HjfOrderPayJob; +use app\services\agent\AgentLevelServices; +use app\services\hjf\PointsRewardServices; use app\jobs\order\OrderCreateAfterJob; use app\jobs\order\OrderDeliveryJob; use app\jobs\order\OrderJob; @@ -149,13 +151,43 @@ class Pay implements ListenerInterface //对外接口推送事件 event('out.outPush', ['order_pay_push', ['order_id' => (int)$orderInfo['id']]]); - // 公排入队 + 积分奖励 + 等级升级(仅报单商品订单) + // 报单商品订单:等级检查 + 积分奖励 + 公排入队(受 hjf_queue_pool_enable 控制) if (!empty($orderInfo['is_queue_goods'])) { - HjfOrderPayJob::dispatch([ - (int)$orderInfo['uid'], - (string)$orderInfo['order_id'], - (float)($orderInfo['pay_price'] ?? 3600.00), - ]); + $queuePoolEnable = (int)sys_config('hjf_queue_pool_enable', 0); + if ($queuePoolEnable) { + // 公排模式(开启):异步派发,含公排入队 + 等级检查 + 积分奖励 + HjfOrderPayJob::dispatch([ + (int)$orderInfo['uid'], + (string)$orderInfo['order_id'], + (float)($orderInfo['pay_price'] ?? 3600.00), + ]); + } else { + // 非公排模式(默认关闭):同步执行等级检查 + 积分奖励,不入公排池,不依赖队列 + try { + $uid = (int)$orderInfo['uid']; + /** @var UserServices $userServices */ + $userServices = app()->make(UserServices::class); + $userCacheInfo = $userServices->getUserCacheInfo($uid); + $spreadUid = $userCacheInfo ? (int)($userCacheInfo['spread_uid'] ?? 0) : 0; + $twoSpreadUid = 0; + if ($spreadUid > 0 && $oneUserInfo = $userServices->getUserCacheInfo($spreadUid)) { + $twoSpreadUid = $userServices->getSpreadUid($spreadUid, $oneUserInfo, false); + } + $uids = array_filter(array_unique([$uid, $spreadUid, $twoSpreadUid])); + + /** @var AgentLevelServices $agentLevelServices */ + $agentLevelServices = app()->make(AgentLevelServices::class); + $agentLevelServices->checkUserLevelFinish($uid, array_values($uids)); + + /** @var PointsRewardServices $pointsService */ + $pointsService = app()->make(PointsRewardServices::class); + $pointsService->reward($uid, (string)$orderInfo['order_id'], (int)$orderInfo['id']); + + Log::info('[Pay] 同步积分奖励发放完成 uid=' . $uid . ' order_id=' . $orderInfo['id']); + } catch (\Throwable $e) { + Log::error('[Pay] 同步积分奖励失败 order_id=' . $orderInfo['id'] . ': ' . $e->getMessage()); + } + } } //自动打标签 event('user.auto.label', [$orderInfo['uid'], '', [], []]); diff --git a/pro_v3.5.1/app/services/hjf/PointsRewardServices.php b/pro_v3.5.1/app/services/hjf/PointsRewardServices.php index 6c01d370..9adb221f 100644 --- a/pro_v3.5.1/app/services/hjf/PointsRewardServices.php +++ b/pro_v3.5.1/app/services/hjf/PointsRewardServices.php @@ -143,7 +143,7 @@ class PointsRewardServices extends BaseServices int $orderDbId = 0 ): void { Db::transaction(function () use ($uid, $points, $orderId, $type, $mark, $orderDbId) { - $this->userDao->bcInc($uid, 'frozen_points', $points, 'uid'); + $this->userDao->bcInc($uid, 'frozen_points', (string)$points, 'uid'); $this->logDao->save([ 'uid' => $uid, diff --git a/pro_v3.5.1/database/hjf_migration.sql b/pro_v3.5.1/database/hjf_migration.sql index 76676965..3a28b8a7 100644 --- a/pro_v3.5.1/database/hjf_migration.sql +++ b/pro_v3.5.1/database/hjf_migration.sql @@ -341,7 +341,11 @@ VALUES (0, 'hjf_fee_rate', 'text', 'input', 0, '', 0, '', 100, 0, - '7', '提现手续费率(%)', '申请提现时收取的手续费比例,默认7%', 30, 1); + '7', '提现手续费率(%)', '申请提现时收取的手续费比例,默认7%', 30, 1), + +(0, 'hjf_queue_pool_enable', 'text', 'input', 0, + '', 0, '', 100, 0, + '0', '公排入队开关', '0=关闭(积分同步发放) 1=开启(通过队列异步处理)', 5, 1); -- ============================================================ diff --git a/pro_v3.5.1/view/uniapp/vue.config.js b/pro_v3.5.1/view/uniapp/vue.config.js index aa4b9518..8c73798b 100644 --- a/pro_v3.5.1/view/uniapp/vue.config.js +++ b/pro_v3.5.1/view/uniapp/vue.config.js @@ -4,15 +4,15 @@ module.exports = { port: 8080, proxy: { '/api': { - target: 'http://127.0.0.1', + target: 'http://127.0.0.1:20199', changeOrigin: true }, '/uploads': { - target: 'http://127.0.0.1', + target: 'http://127.0.0.1:20199', changeOrigin: true }, '/statics': { - target: 'http://127.0.0.1', + target: 'http://127.0.0.1:20199', changeOrigin: true } }