Selaa lähdekoodia

Merge branch 'feature/3725-studioBonus' into dev

kevin_zhangl 2 vuotta sitten
vanhempi
commit
294d3548b8
1 muutettua tiedostoa jossa 33 lisäystä ja 22 poistoa
  1. 33 22
      common/helpers/bonus/BonusCalc.php

+ 33 - 22
common/helpers/bonus/BonusCalc.php

@@ -10,6 +10,7 @@ namespace common\helpers\bonus;
 
 
 use common\helpers\Cache;
 use common\helpers\Cache;
 use common\helpers\Date;
 use common\helpers\Date;
+use common\helpers\LoggerTool;
 use common\helpers\snowflake\SnowFake;
 use common\helpers\snowflake\SnowFake;
 use common\helpers\Tool;
 use common\helpers\Tool;
 use common\models\CalcBonus;
 use common\models\CalcBonus;
@@ -223,6 +224,18 @@ class BonusCalc extends BaseObject {
             echo('计算报单管理奖'.($this->_sysConfig['openGL']['VALUE']?'完成':'关闭').',耗时:' . round($t13 - $t11, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
             echo('计算报单管理奖'.($this->_sysConfig['openGL']['VALUE']?'完成':'关闭').',耗时:' . round($t13 - $t11, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
             $this->_updatePercent(50);
             $this->_updatePercent(50);
 
 
+            $t16 = microtime(true);
+            // 蓝星奖入库,实际上是插入有奖金会员数据缓存中.
+            // 调用存储过程,计算蓝星管理奖金
+            $this->calcBsProcedure();
+            // 将有蓝星管理奖金的用户加入到有奖金缓存用户中
+            $this->calcBonusBsGL();
+            $this->calcBonusBsGLCF();
+            $this->calcBonusBsYJCF();
+            $t17 = microtime(true);
+            echo('计算蓝星管理奖'.($this->_sysConfig['openGL']['VALUE']?'完成':'关闭').',耗时:' . round($t17 - $t16, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
+            $this->_updatePercent(65);
+
             // 计算店服务奖 月奖
             // 计算店服务奖 月奖
             if($this->_sysConfig['openStore']['VALUE']) {
             if($this->_sysConfig['openStore']['VALUE']) {
                 if ($this->_sysConfig['openStoreReduce']['VALUE']) {
                 if ($this->_sysConfig['openStoreReduce']['VALUE']) {
@@ -233,21 +246,9 @@ class BonusCalc extends BaseObject {
                     $this->calcStoreBonus();
                     $this->calcStoreBonus();
                 }
                 }
             }
             }
-            $t16 = microtime(true);
-            echo('计算店服务奖金'.($this->_sysConfig['openStore']['VALUE']?'完成':'关闭').',耗时:' . round($t16 - $t13, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
-            $this->_updatePercent(55);
-
-            $t17 = microtime(true);
-            // 蓝星奖入库,实际上是插入有奖金会员数据缓存中.
-            // 调用存储过程,计算蓝星管理奖金
-            $this->calcBsProcedure();
-            // 将有蓝星管理奖金的用户加入到有奖金缓存用户中
-            $this->calcBonusBsGL();
-            $this->calcBonusBsGLCF();
-            $this->calcBonusBsYJCF();
             $t18 = microtime(true);
             $t18 = microtime(true);
-            echo('计算蓝星管理奖'.($this->_sysConfig['openGL']['VALUE']?'完成':'关闭').',耗时:' . round($t18 - $t17, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
-            $this->_updatePercent(65);
+            echo('计算店服务奖金'.($this->_sysConfig['openStore']['VALUE']?'完成':'关闭').',耗时:' . round($t18 - $t17, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
+            $this->_updatePercent(55);
 
 
             //把奖金会员写入缓存
             //把奖金会员写入缓存
             $this->loopMonthBonusUserFromDbToCache();
             $this->loopMonthBonusUserFromDbToCache();
@@ -866,25 +867,35 @@ class BonusCalc extends BaseObject {
                 if (empty($storeBonus)) continue;
                 if (empty($storeBonus)) continue;
                 // 判断此店铺是否是活跃用户,如果不活跃,则往上找一个活跃的店铺获得此奖
                 // 判断此店铺是否是活跃用户,如果不活跃,则往上找一个活跃的店铺获得此奖
                 $isActive = $this->_isMonthPerfLimit($userId);
                 $isActive = $this->_isMonthPerfLimit($userId);
+                // 聘级列表
+                $empLv = EmployLevel::getIdConvertLevelSortCache();
+                // 本期蓝星奖
+                $bonusBs = CalcBonusBS::findUseDbCalc()->where('PERIOD_NUM=:PERIOD_NUM AND USER_ID=:USER_ID', [':PERIOD_NUM' => $this->_periodNum, ':USER_ID' => $parent['PARENT_UID']])->asArray()->one();
+                LoggerTool::debug(['calcStoreBonusReduce-1', $isActive, $bonusBs, $empLv, ($bonusBs ? $empLv[$bonusBs['LEVEL_ID']] : '-1')]);
                 $bonusUserId = '';
                 $bonusUserId = '';
-                // 如果用户不活跃,且上面没有活跃的,则不累计了,是不是
-                if (!$isActive) {
+                // 活跃 + 主任聘级
+                if (!$isActive || !$bonusBs || $empLv[$bonusBs['LEVEL_ID']] < 3) {
                     // 如果此店铺不活跃,则找最近的一个店铺获得此奖
                     // 如果此店铺不活跃,则找最近的一个店铺获得此奖
-                    $this->loopRelationParentDo($userId, function ($parent) use (&$bonusUserId) {
+                    $this->loopRelationParentDo($userId, function ($parent) use (&$bonusUserId, $empLv) {
                         if ($this->_isMonthPerfLimit($parent['PARENT_UID'])) {
                         if ($this->_isMonthPerfLimit($parent['PARENT_UID'])) {
                             // 判断是否是店铺
                             // 判断是否是店铺
                             $parentUser = CalcCache::getUserInfo($parent['PARENT_UID'], $this->_periodNum);
                             $parentUser = CalcCache::getUserInfo($parent['PARENT_UID'], $this->_periodNum);
                             if ($parentUser['IS_STUDIO'] == 1) {
                             if ($parentUser['IS_STUDIO'] == 1) {
-                                $bonusUserId = $parent['PARENT_UID'];
-
-                                return self::LOOP_FINISH;
+                                // 本期蓝星奖
+                                $bonusBs = CalcBonusBS::findUseDbCalc()->where('PERIOD_NUM=:PERIOD_NUM AND USER_ID=:USER_ID', [':PERIOD_NUM' => $this->_periodNum, ':USER_ID' => $parent['PARENT_UID']])->asArray()->one();
+                                LoggerTool::debug(['calcStoreBonusReduce-2', $bonusBs, $empLv, ($bonusBs ? $empLv[$bonusBs['LEVEL_ID']] : '-2')]);
+                                // 蓝星奖星级>=主任
+                                if ($bonusBs && $empLv[$bonusBs['LEVEL_ID']] >= 3) {
+                                    $bonusUserId = $parent['PARENT_UID'];
+                                    return self::LOOP_FINISH;
+                                }
                             }
                             }
-                            
                         }
                         }
-                        unset($parent);
+                        unset($parent, $bonusBs);
                     });
                     });
                 }
                 }
                 if (!$isActive && !$bonusUserId) {
                 if (!$isActive && !$bonusUserId) {
+                    LoggerTool::debug(['calcStoreBonusReduce-3', $isActive, $bonusUserId, '-3']);
                     continue;
                     continue;
                 }
                 }