root 3 лет назад
Родитель
Сommit
143a1e0934
2 измененных файлов с 48 добавлено и 29 удалено
  1. 27 0
      common/helpers/bonus/CalcCache.php
  2. 21 29
      common/helpers/bonus/CalcServeBonusCalc.php

+ 27 - 0
common/helpers/bonus/CalcCache.php

@@ -9,6 +9,7 @@ namespace common\helpers\bonus;
 
 use common\helpers\Cache;
 use common\models\CalcBonus;
+use common\models\CalcBonusBS;
 use common\models\PerfMonth;
 use common\models\Period;
 use common\models\DeclarationLevel;
@@ -579,9 +580,35 @@ class CalcCache {
             if ( !$userShopInfo ) {
                 throw new \Exception('用户表数据不存在,userId:'.$userId);
             }
+            // 先判断此期是否是月节点
+            $nowPeriod = Period::find()
+                ->where('PERIOD_NUM=:PERIOD_NUM', [':PERIOD_NUM'=>$periodNum])
+                ->asArray()
+                ->one();
+            if ($nowPeriod['IS_MONTH'] == 1) {
+                $bsMonthPeriod = $nowPeriod['PERIOD_NUM'];
+            } else {
+                $forwardMonthPeriod = Period::find()
+                ->where('IS_MONTH=1 AND PERIOD_NUM<:PERIOD_NUM', [':PERIOD_NUM'=>$periodNum])
+                ->orderBy('PERIOD_NUM DESC')
+                ->asArray()
+                ->one();
+                $bsMonthPeriod = $forwardMonthPeriod['PERIOD_NUM'];
+            }
+            $blueBsInfo = CalcBonusBS::findOneAsArray(
+                'PERIOD_NUM=:PERIOD_NUM  AND USER_ID=:USER_ID', 
+                [':PERIOD_NUM'=>$bsMonthPeriod, ':USER_ID'=>$userId]
+            );
+            if (!empty($blueBsInfo)) {
+                $bsEmpLv = $blueBsInfo['LEVEL_ID']; // 当前蓝星奖计算(即管理奖) 的等级
+            } else {
+                $bsEmpLv = EmployLevel::NO_LEVEL_ID;
+            }
+            // 获取用户的最新级别数据,根据蓝星最近一期月结数据进行查询
             $userInfo['REAL_NAME'] = $userShopInfo['REAL_NAME'];
             $userInfo['DEC_LV'] = $userShopInfo['LAST_DEC_LV'];
             $userInfo['EMP_LV'] = $userShopInfo['EMP_LV'];
+            $userInfo['LAST_EMP_LV'] = $bsEmpLv; // 最新的聘级
             $userInfo['CROWN_LV'] = $userShopInfo['CROWN_LV'];
             $userInfo['IS_DEC'] = $userShopInfo['IS_DEC'];
             $userInfo['STATUS'] = $userShopInfo['STATUS'];

+ 21 - 29
common/helpers/bonus/CalcServeBonusCalc.php

@@ -34,11 +34,8 @@ use yii\db\Query;
 class CalcServeBonusCalc extends BaseObject {
     use StaticInstanceTrait;
 
-    private $_limit = 10000;
+    private $_limit = 3000;
     private $_handleUserId;
-    private $_companyMonthPerf = 0;
-    private $_cfTotalPercent = 0;
-    private $_lxTotalPercent = 0;
     private $_sysConfig = [];
     private $_decLevelConfig = [];
     private $_empLevelConfig = [];
@@ -128,14 +125,26 @@ class CalcServeBonusCalc extends BaseObject {
             $this->clearCalcTableData();
             $t2 = microtime(true);
             echo('初始化、清空缓存及相关数据表完成,耗时:' . round($t2 - $t1, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
-            $t3 = microtime(true);
             $this->_updatePercent(10);
+            $t3 = microtime(true);
+            // @todo 蓝星奖放到最前面
+            if($this->_sysConfig['openGL']['VALUE']) {
+                echo('计算蓝星奖开始,' . date('Y-m-d H:i:s', $t3) . PHP_EOL);
+                // 调用存储过程,计算蓝星管理奖金
+                $this->calcBsProcedure();
+                // 将有【蓝星业绩奖金】的用户加入到有奖金缓存用户中
+                $this->calcBonusBsYJ();
+                // 将有【蓝星管理奖金】的用户加入到有奖金缓存用户中
+                $this->calcBonusBsGL();
+            }
+            $t4 = microtime(true);
+            echo('计算蓝星奖'.($this->_sysConfig['openGL']['VALUE']?'完成':'关闭').',耗时:' . round($t4 - $t3, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
+
             // 奖金部分
             if($this->_sysConfig['openFW']['VALUE']) {
                 $this->calcBonusBDStepOne();
                 $this->calcBonusBDStepTwo();
             }
-            $t4 = microtime(true);
             echo('计算服务奖'.($this->_sysConfig['openFW']['VALUE']?'完成':'关闭').',耗时:' . round($t4 - $t3, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
             $this->_updatePercent(15);
 
@@ -156,20 +165,6 @@ class CalcServeBonusCalc extends BaseObject {
             echo('计算团队奖'.($this->_sysConfig['openQY']['VALUE']?'完成':'关闭').',耗时:' . round($t9 - $t6, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
             $this->_updatePercent(65);
 
-            $t10 = microtime(true);
-            if($this->_sysConfig['openGL']['VALUE']) {
-                echo('计算蓝星奖开始,' . date('Y-m-d H:i:s', $t10) . PHP_EOL);
-                // 调用存储过程,计算蓝星管理奖金
-                $this->calcBsProcedure();
-                // 将有【蓝星业绩奖金】的用户加入到有奖金缓存用户中
-                $this->calcBonusBsYJ();
-                // 将有【蓝星管理奖金】的用户加入到有奖金缓存用户中
-                $this->calcBonusBsGL();
-            }
-            $t20 = microtime(true);
-            echo('计算蓝星奖'.($this->_sysConfig['openGL']['VALUE']?'完成':'关闭').',耗时:' . round($t20 - $t10, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
-            $this->_updatePercent(67);
-
 //            $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);
@@ -200,8 +195,6 @@ class CalcServeBonusCalc extends BaseObject {
 
             // 奖金写库
             $this->loopBonusUsers();
-            // 入库完成,将各个奖金计算流水会员聘级,更新成蓝星奖当时计算的聘级
-            $this->loopCalcBlueEmpLv(); // @todo 调整,将蓝星奖放到第一个进行计算
             $this->_updatePercent(75);
             unset($calcWrite);
             $t31 = microtime(true);
@@ -337,7 +330,7 @@ class CalcServeBonusCalc extends BaseObject {
                     'ID' => SnowFake::instance()->generateId(),
                     'USER_ID' => $bonusUserId,
                     'LAST_DEC_LV' => $userBaseInfo['DEC_LV'],
-                    'LAST_EMP_LV' => $userBaseInfo['EMP_LV'],
+                    'LAST_EMP_LV' => $userBaseInfo['LAST_EMP_LV'],,
                     'LAST_STATUS' => $userBaseInfo['STATUS'],
                     'FROM_USER_ID' => $userId,
                     'LAST_FROM_DEC_LV' => $fromUserInfo['DEC_LV'],
@@ -477,7 +470,7 @@ class CalcServeBonusCalc extends BaseObject {
                     'ID' => SnowFake::instance()->generateId(),
                     'USER_ID' => $userId,
                     'LAST_DEC_LV' => $userBaseInfo['DEC_LV'],
-                    'LAST_EMP_LV' => $userBaseInfo['EMP_LV'],
+                    'LAST_EMP_LV' => $userBaseInfo['LAST_EMP_LV'],
                     'LAST_STATUS' => $userBaseInfo['STATUS'],
                     'FROM_USER_ID' => $userId,
                     'LAST_FROM_DEC_LV' => $userBaseInfo['DEC_LV'],
@@ -587,7 +580,7 @@ class CalcServeBonusCalc extends BaseObject {
                     'USER_ID' => $userId,
                     'ORI_CAPPED_BONUS_QY' => $capBonusQy,
                     'LAST_DEC_LV' => $userBaseInfo['DEC_LV'],
-                    'LAST_EMP_LV' => $userBaseInfo['EMP_LV'],
+                    'LAST_EMP_LV' => $userBaseInfo['LAST_EMP_LV'],
                     'LAST_CROWN_LV' => $starCrown['ID'],
                     'LAST_STATUS' => $userBaseInfo['STATUS'],
                     'AMOUNT' => $deductData['surplus'],
@@ -807,12 +800,12 @@ class CalcServeBonusCalc extends BaseObject {
             if ($item['LAST_DEC_LV'] != $minDecLevel) {
                 continue;
             }
-
+            $userBaseInfo = CalcCache::getUserInfo($item['USER_ID'], $this->_periodNum);
             $insertBonusData[] = [
                 'ID' => SnowFake::instance()->generateId(),
                 'USER_ID' => $item['USER_ID'],
                 'LAST_DEC_LV' => $item['LAST_DEC_LV'] ?? '',
-                'LAST_EMP_LV' => $item['LAST_EMP_LV'] ?? '',
+                'LAST_EMP_LV' => $userBaseInfo['LAST_EMP_LV'],
                 'LAST_STATUS' => $item['LAST_STATUS'] ?? 0,
                 'LAST_CROWN_LV' => $item['LAST_CROWN_LV'] ?? '',
                 'AMOUNT' => 0,
@@ -1491,7 +1484,6 @@ class CalcServeBonusCalc extends BaseObject {
         $tourismBonus = CalcCache::tourismBonus($userId, $this->_periodNum);
         $garageBonus = CalcCache::garageBonus($userId, $this->_periodNum);
         $villaBonus = CalcCache::villaBonus($userId, $this->_periodNum);
-        $empLv = $baseInfo['EMP_LV'];
         $pervSurplusPerf = CalcCache::surplusPerf($userId, $this->_periodNum);
         // 星级
         $starCrownLv = CalcCache::getUserStarCrown($userId, $this->_periodNum);
@@ -1575,7 +1567,7 @@ class CalcServeBonusCalc extends BaseObject {
             'LAST_USER_NAME' => $baseInfo['USER_NAME'],
             'LAST_REAL_NAME' => $baseInfo['REAL_NAME'],
             'LAST_DEC_LV' => $baseInfo['DEC_LV'],
-            'LAST_EMP_LV' => $empLv,
+            'LAST_EMP_LV' => $baseInfo['LAST_EMP_LV'],
             'LAST_CROWN_LV' => $starCrownLv ?? StarCrownLevel::getDefaultLevelId(),
             'LAST_STATUS' => $baseInfo['STATUS'],
             'LAST_MOBILE' => $baseInfo['MOBILE'],