root пре 3 година
родитељ
комит
d46056ec3a
1 измењених фајлова са 49 додато и 13 уклоњено
  1. 49 13
      common/helpers/bonus/CalcServeBonusCalc.php

+ 49 - 13
common/helpers/bonus/CalcServeBonusCalc.php

@@ -21,6 +21,7 @@ use common\models\CalcBonusQY;
 use common\models\CalcBonusTG;
 use common\models\CalcBonusTourism;
 use common\models\CalcBonusVilla;
+use common\models\EmployLevel;
 use common\models\PerfMonth;
 use common\models\PerfPeriod;
 use common\models\Period;
@@ -180,7 +181,7 @@ class CalcServeBonusCalc extends BaseObject {
                 ServeProcess::recordProcess($t8, time(), $this->_periodNum, '计算房奖', 'bonus');
             }
             $t22 = microtime(true);
-            echo('计算房奖' . ($this->_sysConfig['openVilla']['VALUE'] ? '完成' : '关闭').',耗时:' . round($t22 - $t8, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL . PHP_EOL);
+            echo('计算房奖' . ($this->_sysConfig['openVilla']['VALUE'] ? '完成' : '关闭').',耗时:' . round($t22 - $t8, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
             $this->_updatePercent(45);
 
             if($this->_sysConfig['openGarage']['VALUE']) {
@@ -188,7 +189,7 @@ class CalcServeBonusCalc extends BaseObject {
                 ServeProcess::recordProcess($t22, time(), $this->_periodNum, '计算车奖', 'bonus');
             }
             $t23 = microtime(true);
-            echo('计算车奖' . ($this->_sysConfig['openGarage']['VALUE'] ? '完成' : '关闭').',耗时:' . round($t23 - $t22, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL . PHP_EOL);
+            echo('计算车奖' . ($this->_sysConfig['openGarage']['VALUE'] ? '完成' : '关闭').',耗时:' . round($t23 - $t22, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
             $this->_updatePercent(55);
 
             // 计算季度奖
@@ -197,7 +198,7 @@ class CalcServeBonusCalc extends BaseObject {
                 ServeProcess::recordProcess($t23, time(), $this->_periodNum, '计算季度奖-调用存储过程', 'bonus');
             }
             $t24 = microtime(true);
-            echo('计算季度奖' . ($this->_sysConfig['openQuarter']['VALUE'] ? '开启调用存储过程' : '关闭').',耗时:' . round($t24 - $t23, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL . PHP_EOL);
+            echo('计算季度奖' . ($this->_sysConfig['openQuarter']['VALUE'] ? '开启调用存储过程' : '关闭').',耗时:' . round($t24 - $t23, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
             // 将用户写入缓存
             if($this->_sysConfig['openQuarter']['VALUE']) {
                 $this->calcQuarterUser();
@@ -205,7 +206,7 @@ class CalcServeBonusCalc extends BaseObject {
             }
             $this->_updatePercent(65);
             $t25 = microtime(true);
-            echo('计算季度奖' . ($this->_sysConfig['openQuarter']['VALUE'] ? '完成' : '关闭').',耗时:' . round($t25 - $t24, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL . PHP_EOL);
+            echo('计算季度奖' . ($this->_sysConfig['openQuarter']['VALUE'] ? '完成' : '关闭').',耗时:' . round($t25 - $t24, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
 
             // 奖金写库
             $this->loopBonusUsers();
@@ -218,7 +219,7 @@ class CalcServeBonusCalc extends BaseObject {
             ServeProcess::recordProcess($t30, time(), $this->_periodNum, '标记为计算完成', 'bonus');
             $this->_updatePercent(100);
             $t35 = microtime(true);
-            echo('结算全部完成,共耗时:' . round($t35 - $t1, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL . PHP_EOL);
+            echo('结算全部完成,共耗时:' . round($t35 - $t1, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
         } catch (\Exception $e) {
             $this->errorCalcTask();
             $this->addError('calc', sprintf('File【%s】, Line【%s】, Msg【%s】', $e->getFile(), $e->getLine(), $e->getMessage()));
@@ -551,14 +552,16 @@ class CalcServeBonusCalc extends BaseObject {
                 // 将封顶前的金额加入用户奖金缓存中,此金额不能发放(总奖金,总实际奖金) 
                 CalcCache::bonus($userId, $periodNum, 'CAPPED_BONUS_QY', $capBonusQy); 
 
-                CalcCache::bonus($userId, $periodNum, 'BONUS_QY', $teamBonus);
                 // TODO:取小腿值
                 $payLeg = min([$perfArr['SURPLUS_1L'], $perfArr['SURPLUS_2L']]);
                 // 计算荣衔星级
                 $starCrown = StarCrownLevel::getStarCrown($payLeg);
-                // 星级放入缓存
-                CalcCache::addUserStarCrown($userId, $periodNum, $starCrown['ID']);
 
+                // 是否活跃
+                $isActive = $this->_isPerfActive($userId);
+                $oriBonus = $isActive ? $teamBonus : 0;
+                $lastCrownLv = $isActive ? $starCrown['ID'] : StarCrownLevel::getDefaultLevelId();
+                
                 //团队奖流水
                 $insertBonusData[] = [
                     'ID' => SnowFake::instance()->generateId(),
@@ -566,9 +569,9 @@ class CalcServeBonusCalc extends BaseObject {
                     'ORI_CAPPED_BONUS_QY' => $capBonusQy,
                     'LAST_DEC_LV' => $userBaseInfo['DEC_LV'],
                     'LAST_EMP_LV' => $userBaseInfo['LAST_EMP_LV'],
-                    'LAST_CROWN_LV' => $starCrown['ID'],
+                    'LAST_CROWN_LV' => $lastCrownLv,
                     'LAST_STATUS' => $userBaseInfo['STATUS'],
-                    'ORI_BONUS' => $teamBonus,
+                    'ORI_BONUS' => $oriBonus,
                     'PERIOD_NUM' => $this->_periodNum,
                     'CALC_YEAR' => $this->_calcYear,
                     'CALC_MONTH' => $this->_calcYearMonth,
@@ -580,7 +583,17 @@ class CalcServeBonusCalc extends BaseObject {
                         'nowDecLevelConfig' => $nowDecLevelConfig,
                         'decLevel' => $userBaseInfo['DEC_LV'],
                     ]),
+                    'IS_ACTIVE' => (int)$isActive,
+                    'HOPE_CROWN_LV' => $starCrown['ID'],
+                    'HOPE_BONUS' => $teamBonus,
                 ];
+                // 星级放入缓存
+                CalcCache::addUserStarCrown($userId, $periodNum, $lastCrownLv);
+                if ($oriBonus > 0) {
+                    // 把对碰后的奖金存入缓存中
+                    // CalcCache::bonus($userId, $periodNum, 'BONUS_QY', $oriBonus, $deductData);
+                    CalcCache::bonus($userId, $periodNum, 'BONUS_QY', $teamBonus);
+                }
 
                 unset($perfData, $pervSurplusPerf, $perfArr, $oriPerfArr, $touchPerfArr, $userBaseInfo, $decLevelConfig, $touchBonusArr, $userId, $nowDecLevelConfig, $teamBonus, $deductData);
             }
@@ -997,10 +1010,23 @@ class CalcServeBonusCalc extends BaseObject {
             ->all();
         if ($allData) {
             foreach ($allData as $user) {
-                $fxStatus = $this->_isMonthPerfLimit($user['USER_ID']);
-                if ($fxStatus) {
+                // 是否活跃会员
+                $isActive = $this->_isPerfActive($user['USER_ID']);
+                $oriBonus = $isActive ? $user['ORI_BONUS'] : 0;
+                $lastEmpLv = $isActive ? $user['LEVEL_ID'] : EmployLevel::getDefaultLevelId();
+                if ($oriBonus > 0) {
                     CalcCache::bonus($user['USER_ID'], $this->_periodNum, 'BONUS_BS', $user['ORI_BONUS']);
-                }  
+                }
+                // 如果不活跃,则不发放奖金,积分,级别
+                // 更新蓝星奖金存储过程的实发金额数据
+                CalcBonusBS::updateAll(
+                    [
+                        'IS_ACTIVE' => (int)$isActive,
+                        'HOPE_EMP_LV' => $user['LEVEL_ID'],
+                        'LEVEL_ID' => $lastEmpLv,
+                    ],
+                'USER_ID=:USER_ID AND PERIOD_NUM=:PERIOD_NUM', 
+                [':USER_ID' => $user['USER_ID'], ':PERIOD_NUM' => $this->_periodNum]);
             }
             return $this->calcBonusBsGL($offset + $this->_limit);
         }
@@ -1318,4 +1344,14 @@ class CalcServeBonusCalc extends BaseObject {
         
         return $fxPvStatus;
     }
+
+    // 判断会员是否活跃
+    public function _isPerfActive($userId): bool
+    {
+        $pv = PerfPeriod::find()->where('USER_ID=:USER_ID AND CALC_MONTH=:CALC_MONTH AND PERIOD_NUM<=:PERIOD_NUM',
+            ['USER_ID'=>$userId, 'CALC_MONTH'=>$this->_calcYearMonth, 'PERIOD_NUM'=>$this->_periodNum])
+            ->SUM('PV_PCS');
+
+        return $pv >= $this->_sysConfig['monthPcsPvFxCondition']['VALUE'];
+    }
 }