feat(fsgx): 完善报单佣金与积分奖励落库链路
放宽报单/人人分销场景下的推广员校验,确保订单返现佣金可落库;并将直推/伞下积分奖励补充写入 user_bill 明细,支持后台页面可见与审计追踪,同时更新对应 PRD 和问题记录。 Made-with: Cursor
This commit is contained in:
@@ -7,6 +7,7 @@ use app\dao\hjf\PointsReleaseLogDao;
|
||||
use app\dao\user\UserDao;
|
||||
use app\services\agent\AgentLevelServices;
|
||||
use app\services\BaseServices;
|
||||
use app\services\user\UserBillServices;
|
||||
use think\annotation\Inject;
|
||||
use think\facade\Db;
|
||||
use think\facade\Log;
|
||||
@@ -33,17 +34,22 @@ class PointsRewardServices extends BaseServices
|
||||
#[Inject]
|
||||
protected AgentLevelServices $agentLevelServices;
|
||||
|
||||
#[Inject]
|
||||
protected UserBillServices $userBillServices;
|
||||
|
||||
/**
|
||||
* 对一笔报单订单发放积分奖励
|
||||
*
|
||||
* @param int $orderDbId 订单表主键 id,用于 user_bill.link_id 关联后台订单
|
||||
*/
|
||||
public function reward(int $orderUid, string $orderId): void
|
||||
public function reward(int $orderUid, string $orderId, int $orderDbId = 0): void
|
||||
{
|
||||
try {
|
||||
$buyer = $this->userDao->get($orderUid);
|
||||
if (!$buyer || !$buyer['spread_uid']) {
|
||||
return;
|
||||
}
|
||||
$this->propagateReward($buyer['spread_uid'], $orderUid, $orderId, 0);
|
||||
$this->propagateReward($buyer['spread_uid'], $orderUid, $orderId, 0, 0, $orderDbId);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error("[PointsReward] 积分奖励失败 orderUid={$orderUid} orderId={$orderId}: " . $e->getMessage());
|
||||
}
|
||||
@@ -63,7 +69,8 @@ class PointsRewardServices extends BaseServices
|
||||
int $fromUid,
|
||||
string $orderId,
|
||||
int $lowerReward,
|
||||
int $depth = 0
|
||||
int $depth = 0,
|
||||
int $orderDbId = 0
|
||||
): void {
|
||||
if ($depth >= 10 || $uid <= 0) {
|
||||
return;
|
||||
@@ -79,7 +86,7 @@ class PointsRewardServices extends BaseServices
|
||||
|
||||
if ($grade === 0) {
|
||||
if ($user['spread_uid']) {
|
||||
$this->propagateReward((int)$user['spread_uid'], $uid, $orderId, 0, $depth + 1);
|
||||
$this->propagateReward((int)$user['spread_uid'], $uid, $orderId, 0, $depth + 1, $orderDbId);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -97,7 +104,8 @@ class PointsRewardServices extends BaseServices
|
||||
$actual,
|
||||
$orderId,
|
||||
$isDirect ? 'reward_direct' : 'reward_umbrella',
|
||||
($isDirect ? '直推奖励' : '伞下奖励(级差)') . " - 来源订单 {$orderId}"
|
||||
($isDirect ? '直推奖励' : '伞下奖励(级差)') . " - 来源订单 {$orderId}",
|
||||
$orderDbId
|
||||
);
|
||||
}
|
||||
|
||||
@@ -107,7 +115,8 @@ class PointsRewardServices extends BaseServices
|
||||
$uid,
|
||||
$orderId,
|
||||
$reward,
|
||||
$depth + 1
|
||||
$depth + 1,
|
||||
$orderDbId
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -115,9 +124,15 @@ class PointsRewardServices extends BaseServices
|
||||
/**
|
||||
* 写入待释放积分(frozen_points)并记录明细
|
||||
*/
|
||||
private function grantFrozenPoints(int $uid, int $points, string $orderId, string $type, string $mark): void
|
||||
{
|
||||
Db::transaction(function () use ($uid, $points, $orderId, $type, $mark) {
|
||||
private function grantFrozenPoints(
|
||||
int $uid,
|
||||
int $points,
|
||||
string $orderId,
|
||||
string $type,
|
||||
string $mark,
|
||||
int $orderDbId = 0
|
||||
): void {
|
||||
Db::transaction(function () use ($uid, $points, $orderId, $type, $mark, $orderDbId) {
|
||||
$this->userDao->bcInc($uid, 'frozen_points', $points, 'uid');
|
||||
|
||||
$this->logDao->save([
|
||||
@@ -130,6 +145,11 @@ class PointsRewardServices extends BaseServices
|
||||
'status' => 'frozen',
|
||||
'order_id' => $orderId,
|
||||
]);
|
||||
|
||||
// PRD §3.3:营销后台积分日志读 eb_user_bill,双写待释放积分明细(不增加可消费 integral)
|
||||
$integralBalance = (int)($this->userDao->value(['uid' => $uid], 'integral') ?: 0);
|
||||
$billType = ($type === 'reward_direct') ? 'hjf_reward_direct_integral' : 'hjf_reward_umbrella_integral';
|
||||
$this->userBillServices->income($billType, $uid, $points, $integralBalance, $orderDbId, 0, $mark);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user