|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
namespace app\jobs\integral;
|
|
|
|
|
|
+use app\services\user\level\UserLevelServices;
|
|
|
use app\services\user\UserAwardIntegralServices;
|
|
|
use app\services\user\UserServices;
|
|
|
use crmeb\basic\BaseJobs;
|
|
@@ -23,10 +24,12 @@ class IntegralJob extends BaseJobs
|
|
|
$awardIntegralService = app()->make(UserAwardIntegralServices::class);
|
|
|
/** @var UserServices $userService */
|
|
|
$userService = app()->make(UserServices::class);
|
|
|
+ /** @var UserLevelServices $levelServices */
|
|
|
+ $levelServices = app()->make(UserLevelServices::class);
|
|
|
$user = $userService->getUserInfo($order['uid']);
|
|
|
$integral_price = $awardIntegralService->getPrice($order['id']);
|
|
|
$total_price = $order['total_price'];
|
|
|
- return $awardIntegralService->transaction(function () use ($awardIntegralService, $userService, $user, $integral_price, $total_price, $order) {
|
|
|
+ return $awardIntegralService->transaction(function () use ($levelServices, $awardIntegralService, $userService, $user, $integral_price, $total_price, $order) {
|
|
|
try {
|
|
|
//添加静态积分
|
|
|
$static_integral_ratio = sys_config('static_integral_ratio', 0);
|
|
@@ -46,19 +49,38 @@ class IntegralJob extends BaseJobs
|
|
|
}
|
|
|
//TODO 加动态积分
|
|
|
//推荐奖
|
|
|
+ $rate = sys_config('action_integral_rate', 3);
|
|
|
$spread = $userService->getUserInfo($user['spread_uid']);
|
|
|
if ($spread) {
|
|
|
if ($awardIntegralService->getPaySum($spread['uid']) >= 1000 || $awardIntegralService->getHourExtractPaySum($spread['uid'], 24) >= 1000) {
|
|
|
$award_ratio = sys_config('recommend_integral', 0);
|
|
|
$give_action_integral = bcdiv(bcmul($total_price, $award_ratio), 100, 2);
|
|
|
if ($give_action_integral > 0) {
|
|
|
- $rate = sys_config('action_integral_rate', 3);
|
|
|
$extract_sum = bcmul($give_action_integral, $rate, 2);
|
|
|
$mark = '推荐用户' . $user['nickname'] . "({$user['uid']})" . '购买商品,获得推荐积分';
|
|
|
$awardIntegralService->incIntegral($spread['uid'], $integral_price, $give_action_integral, $total_price, 1, $extract_sum, $order['id'], $mark);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ $levelServices->detection((int)$user['uid']);
|
|
|
+ $pass = [$user['uid']];
|
|
|
+ $send = 0;
|
|
|
+ while ($spread && !in_array($spread['uid'], $pass)) {
|
|
|
+ //先发奖,再结算等级
|
|
|
+ $level = $levelServices->getUserLevel($spread['uid']);
|
|
|
+ $ratio = $level['levelInfo']['group_award'] ?? 0;
|
|
|
+ $give_action_integral = bcdiv(bcmul($total_price, $ratio), 100, 2);
|
|
|
+ if ($give_action_integral > $send) {
|
|
|
+ $real_send = bcsub($give_action_integral, $send, 2);
|
|
|
+ $extract_sum = bcmul($real_send, $rate, 2);
|
|
|
+ $mark = '团队用户' . $user['nickname'] . "({$user['uid']})" . '购买商品,获得团队级差积分';
|
|
|
+ $awardIntegralService->incIntegral($spread['uid'], $integral_price, $real_send, $total_price, 1, $extract_sum, $order['id'], $mark);
|
|
|
+ $send = $give_action_integral;
|
|
|
+ }
|
|
|
+ $levelServices->detection((int)$spread['uid']);
|
|
|
+ $pass[] = $spread['uid'];
|
|
|
+ $spread = $userService->getUserInfo($spread['spread_uid']);
|
|
|
+ }
|
|
|
return true;
|
|
|
} catch (\Throwable $e) {
|
|
|
Log::error('处理积分奖池失败,失败原因:' . $e->getMessage());
|
|
@@ -67,7 +89,6 @@ class IntegralJob extends BaseJobs
|
|
|
});
|
|
|
|
|
|
}
|
|
|
-
|
|
|
/**
|
|
|
* 减积分
|
|
|
* @param int $uid 用户
|