|
|
@@ -297,12 +297,12 @@ class BonusCalc extends BaseObject {
|
|
|
echo('计算蓝星奖'.($this->_sysConfig['openGL']['VALUE']?'完成':'关闭').',耗时:' . round($t20 - $t19, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
|
|
|
$this->_updatePercent(67);
|
|
|
|
|
|
- $this->calcBonusTourism($this->_sysConfig['openTourism']);
|
|
|
+// $this->calcBonusTourism($this->_sysConfig['openTourism']);
|
|
|
$t21 = microtime(true);
|
|
|
- echo('计算旅游奖' . ($this->_sysConfig['openTourism']['VALUE'] ? '完成' : '关闭') . ',耗时:' . round($t21 - $t20, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
|
|
|
- $this->_updatePercent(68);
|
|
|
+// echo('计算旅游奖' . ($this->_sysConfig['openTourism']['VALUE'] ? '完成' : '关闭') . ',耗时:' . round($t21 - $t20, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
|
|
|
+// $this->_updatePercent(68);
|
|
|
|
|
|
- $this->calcBonusGarage($this->_sysConfig['openGarage']);
|
|
|
+ $this->calcBonusGarage();
|
|
|
$t22 = microtime(true);
|
|
|
echo('计算车房奖' . ($this->_sysConfig['openGarage']['VALUE'] ? '完成' : '关闭').',耗时:' . round($t22 - $t21, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL . PHP_EOL);
|
|
|
$this->_updatePercent(69);
|
|
|
@@ -1644,12 +1644,13 @@ class BonusCalc extends BaseObject {
|
|
|
}
|
|
|
|
|
|
// 执行旅游奖的计算
|
|
|
- public function calcBonusTourism(array $bonusConfig) {
|
|
|
+ public function calcBonusTourism() {
|
|
|
// 月结,如果不是月结点,则直接退出
|
|
|
if (!$this->_isCalcMonth) {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ $bonusConfig = $this->_sysConfig['openTourism'];
|
|
|
// 达标条件:聘级、级别、奖项比例
|
|
|
$config = json_decode($bonusConfig['OPTIONS'], true);
|
|
|
// 奖金总比例
|
|
|
@@ -1665,44 +1666,60 @@ class BonusCalc extends BaseObject {
|
|
|
->where('CALC_MONTH=:CALC_MONTH', [':CALC_MONTH' => $this->_calcYearMonth])
|
|
|
->sum('PV_PCS');
|
|
|
|
|
|
- if ($monthTotalPV <= 0) {
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- // 基于蓝星奖结果计算符合获奖条件的会员
|
|
|
- $userBonusData = CalcBonusBS::find()
|
|
|
+ // 基于蓝星奖结果计算符合获奖条件的会员StarDirector
|
|
|
+ $userStarDirector = CalcBonusBS::find()
|
|
|
->yearMonth($this->_calcYearMonth)
|
|
|
->where('CALC_MONTH=:CALC_MONTH', [':CALC_MONTH' => $this->_calcYearMonth])
|
|
|
->select('USER_ID,LEVEL_ID,LAST_DEC_LV,LAST_EMP_LV,LAST_STATUS')
|
|
|
->groupBy('USER_ID')
|
|
|
->asArray()
|
|
|
->all();
|
|
|
+ $userStarDirectorObj = array_column($userStarDirector, NULL, 'USER_ID');
|
|
|
+
|
|
|
+ // 基于团队奖/绩效奖结果计算会员的StarCrown
|
|
|
+ $userStarCrown = CalcBonusQY::find()
|
|
|
+ ->yearMonth($this->_calcYearMonth)
|
|
|
+ ->where('CALC_MONTH=:CALC_MONTH', [':CALC_MONTH' => $this->_calcYearMonth])
|
|
|
+ ->select('USER_ID,LAST_STAR_LV')
|
|
|
+ ->groupBy('USER_ID')
|
|
|
+ ->asArray()
|
|
|
+ ->all();
|
|
|
+ $userStarCrownObj = array_column($userStarCrown, NULL, 'USER_ID');
|
|
|
+
|
|
|
+ // 合并用户ID,去重
|
|
|
+ $bonusUsers = array_unique(array_merge(array_keys($userStarDirectorObj), array_keys($userStarCrownObj)));
|
|
|
|
|
|
$insertBonusData = [];
|
|
|
- foreach($userBonusData as $userBonus) {
|
|
|
- // TODO:基于绩效奖,获取会员starCrown级别,计算奖金
|
|
|
- $startCrownPoint = (mt_rand(10, 75) / 10) / 100;
|
|
|
- $amount = Tool::formatPrice(($monthTotalPV * $mate) * $startCrownPoint);
|
|
|
+ foreach($bonusUsers as $userId) {
|
|
|
+ // 计算奖金:取starDirectorPoint和startCrownPoint的大个值
|
|
|
+ $starDirectorPoint = $this->_empLevelConfig[$userStarDirectorObj[$userId]['LEVEL_ID']]['TOURISM_PERCENT'] ?? 0;
|
|
|
+ $startCrownPoint = $this->_starCrownLevelConfig[$userStarCrownObj[$userId]['LAST_STAR_LV']]['TOURISM_PERCENT'] ?? 0;
|
|
|
+ // 奖金比例:
|
|
|
+ $bonusPoint = max($starDirectorPoint, $startCrownPoint);
|
|
|
+ // 计算奖金
|
|
|
+ $amount = Tool::formatPrice(($monthTotalPV * $mate * $bonusPoint) / 100);
|
|
|
if ($amount <= 0) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
// 会员级别+聘级都达到要求才会发放奖金
|
|
|
- if (in_array($userBonus['LAST_DEC_LV'], $minDecLevel) && in_array($userBonus['LEVEL_ID'], $minEmpLevel)) {
|
|
|
+ if (in_array($userStarDirectorObj[$userId]['LAST_DEC_LV'], $minDecLevel) && in_array($userStarDirectorObj[$userId]['LEVEL_ID'], $minEmpLevel)) {
|
|
|
// 放入缓存
|
|
|
- CalcCache::tourismBonus($userBonus['USER_ID'], $this->_periodNum, $amount);
|
|
|
+ CalcCache::tourismBonus($userId, $this->_periodNum, $amount);
|
|
|
// 加入月奖的会员
|
|
|
- CalcCache::addHasMonthBonusUsers($userBonus['USER_ID'], $this->_periodNum);
|
|
|
+ CalcCache::addHasMonthBonusUsers($userId, $this->_periodNum);
|
|
|
}
|
|
|
|
|
|
$insertBonusData[] = [
|
|
|
'ID' => SnowFake::instance()->generateId(),
|
|
|
- 'USER_ID' => $userBonus['USER_ID'],
|
|
|
- 'LEVEL_ID' => $userBonus['LEVEL_ID'],
|
|
|
- 'LAST_DEC_LV' => $userBonus['LAST_DEC_LV'],
|
|
|
- 'LAST_EMP_LV' => $userBonus['LAST_EMP_LV'],
|
|
|
- 'LAST_STATUS' => $userBonus['LAST_STATUS'],
|
|
|
- 'AMOUNT' => $amount,
|
|
|
+ 'USER_ID' => $userId,
|
|
|
+ 'LEVEL_ID' => $userStarDirectorObj[$userId]['LEVEL_ID'],
|
|
|
+ 'LAST_DEC_LV' => $userStarDirectorObj[$userId]['LAST_DEC_LV'],
|
|
|
+ 'LAST_EMP_LV' => $userStarDirectorObj[$userId]['LAST_EMP_LV'],
|
|
|
+ 'LAST_STATUS' => $userStarDirectorObj[$userId]['LAST_STATUS'],
|
|
|
+ 'LAST_STAR_LV' => $userStarCrownObj[$userId]['LAST_STAR_LV'],
|
|
|
+ 'AMOUNT_STANDARD' => $amount,
|
|
|
+ 'POINT' => $bonusPoint,
|
|
|
'PERIOD_NUM' => $this->_periodNum,
|
|
|
'CALC_YEAR' => $this->_calcYear,
|
|
|
'CALC_MONTH' => $this->_calcYearMonth,
|
|
|
@@ -1720,12 +1737,13 @@ class BonusCalc extends BaseObject {
|
|
|
}
|
|
|
|
|
|
// 执行车房奖的计算
|
|
|
- public function calcBonusGarage($bonusConfig) {
|
|
|
+ public function calcBonusGarage() {
|
|
|
// 月结,如果不是月结点,则直接退出
|
|
|
if (!$this->_isCalcMonth) {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ $bonusConfig = $this->_sysConfig['openGarage'];
|
|
|
// 达标条件:聘级、级别、奖项比例
|
|
|
$config = json_decode($bonusConfig['OPTIONS'], true);
|
|
|
// 奖金总比例
|
|
|
@@ -1743,47 +1761,62 @@ class BonusCalc extends BaseObject {
|
|
|
->where('CALC_MONTH=:CALC_MONTH', [':CALC_MONTH' => $this->_calcYearMonth])
|
|
|
->sum('PV_PCS');
|
|
|
|
|
|
- if ($monthTotalPV <= 0) {
|
|
|
- return true;
|
|
|
- }
|
|
|
+ // 基于蓝星奖结果计算符合获奖条件的会员StarDirector
|
|
|
+ $userStarDirector = CalcBonusBS::find()
|
|
|
+ ->yearMonth($this->_calcYearMonth)
|
|
|
+ ->where('CALC_MONTH = :CALC_MONTH', [':CALC_MONTH' => $this->_calcYearMonth])
|
|
|
+ ->select('USER_ID,LEVEL_ID,LAST_DEC_LV,LAST_EMP_LV,LAST_STATUS')
|
|
|
+ ->groupBy('USER_ID')
|
|
|
+ ->asArray()
|
|
|
+ ->all();
|
|
|
+ $userStarDirectorObj = array_column($userStarDirector, NULL, 'USER_ID');
|
|
|
|
|
|
- // 基于蓝星奖结果计算符合获奖条件的会员
|
|
|
- $userBonusData = CalcBonusBS::find()
|
|
|
+ // 基于团队奖/绩效奖结果计算会员的StarCrown
|
|
|
+ $userStarCrown = CalcBonusQY::find()
|
|
|
->yearMonth($this->_calcYearMonth)
|
|
|
- ->where('CALC_MONTH=:CALC_MONTH', [':CALC_MONTH' => $this->_calcYearMonth])
|
|
|
- ->select('USER_ID,LEVEL_ID,LAST_DEC_LV,LAST_EMP_LV,LAST_STATUS,RECONSUME_POINTS')
|
|
|
+ ->where('CALC_MONTH = :CALC_MONTH AND PERIOD_NUM = :PERIOD_NUM', [':CALC_MONTH' => $this->_calcYearMonth, ':PERIOD_NUM' => $this->_periodNum])
|
|
|
+ ->select('USER_ID,LAST_DEC_LV,LAST_EMP_LV,LAST_STAR_LV,LAST_STATUS')
|
|
|
->groupBy('USER_ID')
|
|
|
->asArray()
|
|
|
->all();
|
|
|
+ $userStarCrownObj = array_column($userStarCrown, NULL, 'USER_ID');
|
|
|
+
|
|
|
+ // 合并用户ID,去重
|
|
|
+ $bonusUsers = array_unique(array_merge(array_keys($userStarDirectorObj), array_keys($userStarCrownObj)));
|
|
|
|
|
|
$insertBonusData = [];
|
|
|
- foreach($userBonusData as $userBonus) {
|
|
|
- // TODO:基于绩效奖,获取会员starCrown级别,计算奖金
|
|
|
- $startCrownPoint = mt_rand(1, 10) / 100;
|
|
|
- $amount = Tool::formatPrice(($monthTotalPV * $mate) * $startCrownPoint);
|
|
|
+ foreach($bonusUsers as $userId) {
|
|
|
+ // 计算奖金:取starDirectorPoint和startCrownPoint的大个值
|
|
|
+ $starDirectorPoint = !isset($userStarDirectorObj[$userId]['LEVEL_ID']) ? 0 : ($this->_empLevelConfig[$userStarDirectorObj[$userId]['LEVEL_ID']]['GARAGE_PERCENT'] ?? 0);
|
|
|
+ $startCrownPoint = !isset($userStarCrownObj[$userId]['LAST_STAR_LV']) ? 0: ($this->_starCrownLevelConfig[$userStarCrownObj[$userId]['LAST_STAR_LV']]['GARAGE_PERCENT'] ?? 0);
|
|
|
+ // 奖金比例:
|
|
|
+ $bonusPoint = max($starDirectorPoint, $startCrownPoint);
|
|
|
+ // 计算奖金
|
|
|
+ $amount = Tool::formatPrice(($monthTotalPV * $mate * $bonusPoint) / 100);
|
|
|
if ($amount <= 0) {
|
|
|
continue;
|
|
|
}
|
|
|
-
|
|
|
// 奖金数不能大于封顶值
|
|
|
$amount = ($amount > $capBonus) ? $capBonus : $amount;
|
|
|
|
|
|
// 会员级别+聘级都达到要求才会发放奖金
|
|
|
- if (in_array($userBonus['LAST_DEC_LV'], $minDecLevel) && in_array($userBonus['LEVEL_ID'], $minEmpLevel)) {
|
|
|
+ if (in_array($userStarDirectorObj[$userId]['LAST_DEC_LV'], $minDecLevel) && in_array($userStarDirectorObj[$userId]['LEVEL_ID'], $minEmpLevel)) {
|
|
|
// 放入缓存
|
|
|
- CalcCache::garageBonus($userBonus['USER_ID'], $this->_periodNum, $amount);
|
|
|
+ CalcCache::garageBonus($userId, $this->_periodNum, $amount);
|
|
|
// 加入月奖的会员
|
|
|
- CalcCache::addHasMonthBonusUsers($userBonus['USER_ID'], $this->_periodNum);
|
|
|
+ CalcCache::addHasMonthBonusUsers($userId, $this->_periodNum);
|
|
|
}
|
|
|
|
|
|
$insertBonusData[] = [
|
|
|
'ID' => SnowFake::instance()->generateId(),
|
|
|
- 'USER_ID' => $userBonus['USER_ID'],
|
|
|
- 'LEVEL_ID' => $userBonus['LEVEL_ID'],
|
|
|
- 'LAST_DEC_LV' => $userBonus['LAST_DEC_LV'],
|
|
|
- 'LAST_EMP_LV' => $userBonus['LAST_EMP_LV'],
|
|
|
- 'LAST_STATUS' => $userBonus['LAST_STATUS'],
|
|
|
+ 'USER_ID' => $userId,
|
|
|
+ 'LEVEL_ID' => $userStarDirectorObj[$userId]['LEVEL_ID'] ?? '',
|
|
|
+ 'LAST_DEC_LV' => $userStarDirectorObj[$userId]['LAST_DEC_LV'] ?? ($userStarCrownObj[$userId]['LAST_DEC_LV'] ?? ''),
|
|
|
+ 'LAST_EMP_LV' => $userStarDirectorObj[$userId]['LAST_EMP_LV'] ?? ($userStarCrownObj[$userId]['LAST_EMP_LV'] ?? ''),
|
|
|
+ 'LAST_STATUS' => $userStarDirectorObj[$userId]['LAST_STATUS'] ?? ($userStarCrownObj[$userId]['LAST_STATUS'] ?? 1),
|
|
|
+ 'LAST_STAR_LV' => $userStarCrownObj[$userId]['LAST_STAR_LV'] ?? '',
|
|
|
'AMOUNT' => $amount,
|
|
|
+ 'POINT' => $bonusPoint,
|
|
|
'PERIOD_NUM' => $this->_periodNum,
|
|
|
'CALC_YEAR' => $this->_calcYear,
|
|
|
'CALC_MONTH' => $this->_calcYearMonth,
|
|
|
@@ -1832,12 +1865,12 @@ class BonusCalc extends BaseObject {
|
|
|
$point = $deductData['reConsumePoints'] + $user['RECONSUME_POINTS'];// 复消积分
|
|
|
|
|
|
// 管理奖钻卡发放
|
|
|
- if (in_array($user['LAST_DEC_LV'], $minDecLevel)) {
|
|
|
+// if (in_array($user['LAST_DEC_LV'], $minDecLevel)) {
|
|
|
// 把对碰后的奖金存入缓存中
|
|
|
CalcCache::bonus($user['USER_ID'], $this->_periodNum, 'BONUS_BS_MNT', $user['ORI_BONUS_MNT'], $deductData);
|
|
|
// 加入月奖的会员
|
|
|
CalcCache::addHasMonthBonusUsers($user['USER_ID'], $this->_periodNum);
|
|
|
- }
|
|
|
+// }
|
|
|
|
|
|
// 更新蓝星奖金存储过程的实发金额数据
|
|
|
CalcBonusBS::updateAll([
|
|
|
@@ -1885,12 +1918,12 @@ class BonusCalc extends BaseObject {
|
|
|
$point = $deductData['reConsumePoints'] + $user['RECONSUME_POINTS'];// 复消积分
|
|
|
|
|
|
// 业绩奖金卡、钻卡发放
|
|
|
- if (in_array($user['LAST_DEC_LV'], $minDecLevel)) {
|
|
|
+// if (in_array($user['LAST_DEC_LV'], $minDecLevel)) {
|
|
|
// 把对碰后的奖金存入缓存中
|
|
|
CalcCache::bonus($user['USER_ID'], $this->_periodNum, 'BONUS_BS_ABBR', $user['ORI_BONUS_ABBR'], $deductData);
|
|
|
// 加入月奖的会员
|
|
|
CalcCache::addHasMonthBonusUsers($user['USER_ID'], $this->_periodNum);
|
|
|
- }
|
|
|
+// }
|
|
|
|
|
|
// 更新蓝星业绩奖金存储过程的实发金额数据
|
|
|
CalcBonusBS::updateAll([
|