Ver código fonte

修改期业绩表活跃状态

root 3 anos atrás
pai
commit
b1525e61a1

+ 3 - 12
common/helpers/bonus/CalcServeBonusCalc.php

@@ -46,6 +46,7 @@ use common\models\QtrCalcUser;
 use common\models\QtrCalcWeight;
 use common\models\ServeProcess;
 use common\models\StarCrownLevel;
+use common\models\User;
 use Exception;
 use Yii;
 use yii\base\BaseObject;
@@ -693,7 +694,7 @@ class CalcServeBonusCalc extends BaseObject {
                 $starCrown = StarCrownLevel::getStarCrown($payLeg);
 
                 // 是否活跃
-                $isActive = $this->_isPerfActive($userId);
+                $isActive = User::isPerfActive($userId, $this->_periodNum, $this->_calcYearMonth);
                 $oriBonus = $isActive ? $teamBonus : 0;
                 $lastCrownLv = $isActive ? $starCrown['ID'] : StarCrownLevel::getDefaultLevelId();
                 
@@ -1150,7 +1151,7 @@ class CalcServeBonusCalc extends BaseObject {
         if ($allData) {
             foreach ($allData as $user) {
                 // 是否活跃会员
-                $isActive = $this->_isPerfActive($user['USER_ID']);
+                $isActive = User::isPerfActive($user['USER_ID'], $this->_periodNum, $this->_calcYearMonth);
                 $oriBonus = $isActive ? $user['ORI_BONUS'] : 0;
                 $lastEmpLv = $isActive ? $user['LEVEL_ID'] : EmployLevel::getDefaultLevelId();
                 if ($oriBonus > 0) {
@@ -1489,16 +1490,6 @@ 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'];
-    }
-
     // 获取用户当期最新聘级
     // 非结算月,直接获取传过来的用户级别.如果是结算月,bs流水表无数据则是无级别.有数据,则直接取缓存中数据.因为第一步计算bs奖已更新缓存数据
     public function _nowLastEmpLv($userId) {

+ 34 - 0
common/helpers/bonus/CalcServePerfCalc.php

@@ -12,6 +12,7 @@ use common\models\PerfPeriod;
 use common\models\Period;
 use common\models\PerfMonth;
 use common\models\ServeProcess;
+use common\models\User;
 use common\models\UserNetwork;
 use yii\base\Exception;
 use yii\base\StaticInstanceTrait;
@@ -168,7 +169,13 @@ class CalcServePerfCalc {
                 ServeProcess::recordProcess($t7, $t8, $this->_periodNum, '本月业绩入库完成');
             }
             $this->_updatePercent(100);
+            
+
+            //十二、期业绩表,增加是否活跃字段
+            $this->loopUpdatePeriodActive();
             $t9 = microtime(true);
+            echo(date('Y-m-d H:i:s',time()).'期业绩表活跃状态更新完成,耗时:' . round($t9 - $t8, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
+
             ServeProcess::recordProcess($t6, $t7, $this->_periodNum, '计算业绩业绩结算全部完成');
             echo(date('Y-m-d H:i:s',time()).'计算业绩业绩结算全部完成,共耗时:' . round($t9 - $t1, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
         } catch (\Exception $e) {
@@ -642,4 +649,31 @@ class CalcServePerfCalc {
         // 把数据写入数据库中
         Period::updateAll(['PERF_PERCENT' => $percent], 'PERIOD_NUM=:PERIOD_NUM', [':PERIOD_NUM' => $this->_periodNum]);
     }
+
+    // 期业绩表,增加是否活跃字段判断,就用isPerfActive 方法进行判断。
+    public function loopUpdatePeriodActive($offset = 0) {
+        echo sprintf("时间:[%s]更新期业绩表活跃状态字段,当前offset为:【%s】" . PHP_EOL, date('Y-m-d H:i:s', time()) , $offset);
+        $allData = PerfPeriod::findUseDbCalc()
+        ->where('PERIOD_NUM=:PERIOD_NUM', [':PERIOD_NUM' => $this->_periodNum])
+        ->offset($offset)
+        ->limit($this->_limit)
+        ->asArray()
+        ->all();
+        if ($allData) {
+            foreach ($allData as $data) {
+                $isActive = User::isPerfActive($data['USER_ID'], $this->_periodNum, $this->_calcYearMonth);
+                // 期结算结果
+                PerfPeriod::updateAll(['IS_ACTIVE' => $isActive], 'USER_ID=:USER_ID AND PERIOD_NUM=:PERIOD_NUM', 
+                    [
+                        ':USER_ID' => $data['USER_ID'],
+                        ':PERIOD_NUM' => $this->_periodNum
+                    ]
+                );
+            }
+            unset($allData);
+            return $this->loopUpdatePeriodActive($offset + $this->_limit);
+        }
+        unset($allData);
+        return true;
+    }
 }

+ 14 - 58
common/models/User.php

@@ -267,64 +267,6 @@ class User extends \common\components\ActiveRecord
         Yii::$app->redis->hdel(Cache::USER_INFO_KEY, $userId);
     }
 
-    /**
-     *  判断用户是否是观察期
-     *  观望期:自加入算起2个月
-     *  例子:2022年5月14日加入, 观望期至2022年7月31日。
-     *  true为是观察期用户  false为不是观察期用户
-     * @param $addAt 用户的加入时间
-     * @param $month 观察期月份限制 系统初始化为2个月
-     */
-    public static function checkIsObserve($addAt, $month) {
-        if (empty($month)) {
-            // 如果0 代表全站全额升级
-            return false;
-        }
-        $appendMonth = date("Y-m", strtotime("first day of +$month month", $addAt)); // 指定月份
-        $lastDay = date("t", strtotime($appendMonth));  // 获取指定月的最后一天
-        $eTime = strtotime($appendMonth.'-'.$lastDay);
-
-        return time() < $eTime ? true : false;
-    }
-
-    // 获取用户报单PV总和
-    public static function sumDevPvByUserId($userId) {
-        $decOrderPv = DecOrder::find()
-        ->select('SUM(DEC_PV) AS PV_SUM')
-        ->where('TO_USER_ID=:TO_USER_ID  AND IS_DEL=0', 
-            ['TO_USER_ID'=>$userId]
-        )
-        ->asArray()
-        ->one();
-        $decOrderPv = isset($decOrderPv['PV_SUM']) ? $decOrderPv['PV_SUM'] : 0;
-        $orderDecPv = OrderDec::find()
-        ->select('SUM(PAY_PV) AS PV_SUM')
-        ->where('USER_ID=:USER_ID  AND IS_DELETE=0', 
-            [
-                'USER_ID'=>$userId, 
-                
-            ]
-        )
-        ->asArray()
-        ->one();
-        $orderDecPv = isset($orderDecPv['PV_SUM']) ? $orderDecPv['PV_SUM'] : 0;
-        // 还得加上用户在老系统中的所有报单PV之和
-        $originPv = OriginDecPv::find()
-        ->select('SUM(DEC_PV) AS PV_SUM')
-        ->where('USER_ID=:USER_ID', 
-            [
-                'USER_ID'=>$userId, 
-                
-            ]
-        )
-        ->asArray()
-        ->one();
-        $originPv = isset($originPv['PV_SUM']) ? $originPv['PV_SUM'] : 0;
-        $total = $orderDecPv + $decOrderPv + $originPv;
-
-        return $total;
-    }
-
     /**
      * 获取会员的部分信息并对敏感信息加密
      * @param $userId
@@ -514,4 +456,18 @@ class User extends \common\components\ActiveRecord
         ];
     }
 
+    /**
+     * 判断此期用户是否活跃
+     * @param varchar $userId 用户ID
+     * @param int $periodNum 业绩期
+     * @param varchar $calcYearMonth 结算年月
+     */
+    public static function isPerfActive($userId, $periodNum, $calcYearMonth): bool {
+        $sysConfig = Cache::getSystemConfig();
+        $pv = PerfPeriod::find()->where('USER_ID=:USER_ID AND CALC_MONTH=:CALC_MONTH AND PERIOD_NUM<=:PERIOD_NUM',
+        ['USER_ID'=>$userId, 'CALC_MONTH'=>$calcYearMonth, 'PERIOD_NUM'=>$periodNum])
+        ->SUM('PV_PCS');
+
+        return $pv >= $sysConfig['monthPcsPvFxCondition']['VALUE'];
+    }
 }