root 3 лет назад
Родитель
Сommit
2e252fb306

+ 30 - 18
common/helpers/bonus/CalcServeBonusCalc.php

@@ -44,7 +44,7 @@ use common\models\QtrCalcRecord;
 use common\models\QtrCalcScore;
 use common\models\QtrCalcUser;
 use common\models\QtrCalcWeight;
-use common\models\ServeProcess;
+use common\models\ServeLog;
 use common\models\StarCrownLevel;
 use common\models\User;
 use Exception;
@@ -148,18 +148,18 @@ class CalcServeBonusCalc extends BaseObject {
                 // 更新状态为,奖金计算中
                 Period::updateCalcProcess(4, $this->_periodNum);
             }
-            $t2 = microtime(true);
-            ServeProcess::recordProcess($t1, $t2, $this->_periodNum, '奖金计算初始化配置', 'bonus');
+            // 日志----记录开始
+            ServeLog::noParamsLog($this->_periodNum, $this->_calcYearMonth, '开始奖金计算');
             // 设置结算状态
             $this->setCalcStatus('start');
             // 清空所有本期结算用到的缓存
             CalcCache::clearCalcBonusCache($this->_periodNum);
-            $t3 = microtime(true);
-            ServeProcess::recordProcess($t2, $t3, $this->_periodNum, '设置结算状态,清空缓存', 'bonus');
+            
+            // 日志----记录清除的流水表数据
+            ServeLog::clearTableBonus($this->_periodNum, $this->_calcYearMonth, $this->_isCalcMonth);
             // 清空相关表数据
             $this->clearCalcTableData();
             $t4 = microtime(true);
-            ServeProcess::recordProcess($t3, $t4, $this->_periodNum, '清空相关表数据', 'bonus');
             echo('初始化、清空缓存及相关数据表完成,耗时:' . round($t4 - $t1, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
             $this->_updatePercent(10);
             // 蓝星奖放到最前面 奖金计算开始
@@ -169,10 +169,9 @@ class CalcServeBonusCalc extends BaseObject {
                 $this->calcBsProcedure();
                 // 将有蓝星管理奖金的用户加入到有奖金缓存用户中
                 $this->calcBonusBsGL();
-                if ($this->_isCalcMonth) {
-                    ServeProcess::recordProcess($t4, time(), $this->_periodNum, '计算蓝星奖', 'bonus');
-                }
             }
+            // 日志----记录管理奖数据
+            ServeLog::bonusBSData($this->_periodNum, $this->_calcYearMonth);
             $t5 = microtime(true);
             echo('计算蓝星奖'.($this->_sysConfig['openGL']['VALUE']?'完成':'关闭').',耗时:' . round($t5 - $t4, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
             
@@ -190,12 +189,15 @@ class CalcServeBonusCalc extends BaseObject {
             if ($this->_isCalcMonth) {
                 $this->loopMonthPerfBsPGS();
             }
+            // 日志----增加小组业绩数据
+            ServeLog::perfMonthPgs($this->_periodNum, $this->_calcYearMonth);
 
             if($this->_sysConfig['openFW']['VALUE']) {
                 $this->calcBonusBDStepOne();
                 $this->calcBonusBDStepTwo();
-                ServeProcess::recordProcess($t5, time(), $this->_periodNum, '计算服务奖', 'bonus');
             }
+            // 日志----服务奖数据
+            ServeLog::bonusBDData($this->_periodNum, $this->_calcYearMonth);
             $t6 = microtime(true);
             echo('计算服务奖'.($this->_sysConfig['openFW']['VALUE']?'完成':'关闭').',耗时:' . round($t6 - $t5, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
             $this->_updatePercent(15);
@@ -203,8 +205,9 @@ class CalcServeBonusCalc extends BaseObject {
             // 销售奖/推广奖
             if($this->_sysConfig['openTG']['VALUE']) {
                 $this->calcBonusTG();
-                ServeProcess::recordProcess($t6, time(), $this->_periodNum, '计算推广奖', 'bonus');
             }
+            // 日志----推广奖数据
+            ServeLog::bonusTGData($this->_periodNum, $this->_calcYearMonth);
             $t7 = microtime(true);
             echo('计算推广奖'.($this->_sysConfig['openTG']['VALUE']?'完成':'关闭').',耗时:' . round($t7 - $t6, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
             $this->_updatePercent(20);
@@ -212,8 +215,11 @@ class CalcServeBonusCalc extends BaseObject {
             // 绩效奖/团队奖
             if($this->_sysConfig['openQY']['VALUE']) {
                 $this->calcBonusQY();
-                ServeProcess::recordProcess($t7, time(), $this->_periodNum, '计算团队奖', 'bonus');
             }
+            // 日志----团队奖数据
+            ServeLog::bonusQYData($this->_periodNum, $this->_calcYearMonth);
+            // 日志----团队奖计算会更新期业绩结余业绩字段
+            ServeLog::noParamsLog($this->_periodNum, $this->_calcYearMonth, '更新期业绩表市场结余业绩完成AR_PERF_PERIOD');
             $t8 = microtime(true);
             echo('计算团队奖'.($this->_sysConfig['openQY']['VALUE']?'完成':'关闭').',耗时:' . round($t8 - $t7, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
             $this->_updatePercent(35);
@@ -224,16 +230,18 @@ class CalcServeBonusCalc extends BaseObject {
 //            $this->_updatePercent(68);
             if($this->_sysConfig['openVilla']['VALUE']) {
                 $this->calcBonusVilla();
-                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);
             $this->_updatePercent(45);
+            // 日志----房奖数据
+            ServeLog::bonusVillaData($this->_periodNum, $this->_calcYearMonth);
 
             if($this->_sysConfig['openGarage']['VALUE']) {
                 $this->calcBonusGarage();
-                ServeProcess::recordProcess($t22, time(), $this->_periodNum, '计算车奖', 'bonus');
             }
+            // 日志----车奖数据
+            ServeLog::bonusGarageData($this->_periodNum, $this->_calcYearMonth);
             $t23 = microtime(true);
             echo('计算车奖' . ($this->_sysConfig['openGarage']['VALUE'] ? '完成' : '关闭').',耗时:' . round($t23 - $t22, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
             $this->_updatePercent(55);
@@ -241,15 +249,15 @@ class CalcServeBonusCalc extends BaseObject {
             // 计算季度奖
             if($this->_sysConfig['openQuarter']['VALUE']) {
                 $this->calcQuarter();
-                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);
             // 将用户写入缓存
             if($this->_sysConfig['openQuarter']['VALUE']) {
                 $this->calcQuarterUser();
-                ServeProcess::recordProcess($t24, time(), $this->_periodNum, '计算季度奖-存入奖金会员', 'bonus');
             }
+            // 日志----季度奖数据
+            ServeLog::bonusQuarterData($this->_periodNum, $this->_calcYearMonth);
             $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);
@@ -258,13 +266,17 @@ class CalcServeBonusCalc extends BaseObject {
             $this->loopBonusUsers();
             $this->_updatePercent(75);
             $t30 = microtime(true);
-            ServeProcess::recordProcess($t25, $t30, $this->_periodNum, '奖金写库', 'bonus');
+            // 日志----奖金写库
+            ServeLog::noParamsLog($this->_periodNum, $this->_calcYearMonth, '写入奖金汇总表并计算管理费和复消积分');
+            // 日志----写库数据统计
+            ServeLog::bonusData($this->_periodNum, $this->_calcYearMonth);
             echo('奖金写库操作完成,耗时:' . round($t30 - $t25, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
 
-            ServeProcess::recordProcess($t30, time(), $this->_periodNum, '标记为计算完成', 'bonus');
             $this->endCalcTask();
             $this->_updatePercent(100);
             $t35 = microtime(true);
+            // 日志----计算完成
+            ServeLog::noParamsLog($this->_periodNum, $this->_calcYearMonth, '奖金计算完成');
             echo('结算全部完成,共耗时:' . round($t35 - $t1, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
         } catch (\Exception $e) {
             $this->errorCalcTask();

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

@@ -12,7 +12,6 @@ use common\models\PerfPeriod;
 use common\models\Period;
 use common\models\PerfMonth;
 use common\models\ServeLog;
-use common\models\ServeProcess;
 use common\models\User;
 use common\models\UserNetwork;
 use yii\base\Exception;

+ 350 - 64
common/models/ServeLog.php

@@ -185,7 +185,7 @@ class ServeLog extends \common\components\ActiveRecord
         ->asArray()
         ->one();
         $num = $data['TOTAL_NUM'];
-        $total_pvpcs = $data['TOTAL_NUM'];
+        $total_pvpcs = $data['TOTAL_PV_PCS'];
         $desc = "期业绩计算完成:AR_PERF_PERIOD-期业绩总条数:$num,期业绩个人消费PV总数:$total_pvpcs";
         $logData[] = [
             'PERIOD_NUM' => $periodNum,
@@ -210,7 +210,7 @@ class ServeLog extends \common\components\ActiveRecord
         ->asArray()
         ->one();
         $num = $data['TOTAL_NUM'];
-        $total_pvpcs = $data['TOTAL_NUM'];
+        $total_pvpcs = $data['TOTAL_PV_PCS'];
         $desc = "月业绩计算完成:AR_PERF_MONTH-月业绩表总条数:$num,月业绩个人消费总数:$total_pvpcs";
         $logData[] = [
             'PERIOD_NUM' => $periodNum,
@@ -247,80 +247,366 @@ class ServeLog extends \common\components\ActiveRecord
         return true;
     }
 
-    
-    
-    
-    
-    
-    
-    
-    
     // =============================奖金相关日志=====================================================================================
-    
-    // ------以下为记录操作流程
-    // 记录请求时间
-    public static function recordRequest($time, $periodNum, $desc = '', $needCheck = false) {
-        // 查询此期是否存在计算中,如果在计算中则不用记录
-        if ($needCheck) {
-            $hasPerpare = Period::findUseSlaves()
-            ->select('ID')
-            ->where('PERIOD_NUM=:PERIOD_NUM AND IS_PREPARE=1', [':PERIOD_NUM'=>$periodNum])
-            ->asArray()
-            ->one();
-            if (empty($hasPerpare)) {
-                return true;
-            }
+    /**
+     * 记录清除的奖金流水表数据
+     * @param int $periodNum
+     * @param int $calcMonth 业绩期
+     * @param int $isCalcMonth 是否月节点
+     */
+    public static function clearTableBonus($periodNum, $calcMonth, $isCalcMonth) {
+        $bonusCount = CalcBonus::find()->where('1=1')->count('ID');
+        $bonusTgCount = CalcBonusTG::find()->where('1=1')->count('ID');
+        $bonusBdCount = CalcBonusBD::find()->where('1=1')->count('ID');
+        $bonusQyCount = CalcBonusQY::find()->where('PERIOD_NUM=:PERIOD_NUM', [':PERIOD_NUM'=>$periodNum])->count('ID');
+        $bonusBsCount = $bonusQuarterCount = $bonusVillaCount = $bonusGarageCount = 0;
+
+        if ($isCalcMonth) {
+            $bonusBsCount = CalcBonusBS::find()->where('1=1')->count('ID');
+            $bonusQuarterCount = CalcBonusQuarter::find()->where('1=1')->count('ID');
+            $bonusVillaCount = CalcBonusVilla::find()->where('1=1')->count('ID');
+            $bonusGarageCount = CalcBonusGarage::find()->where('1=1')->count('ID');
         }
+
+        $desc = "清除奖金流水表数据:AR_CALC_BONUS-清除奖金汇总表总数:$bonusCount;AR_CALC_BONUS_TG-清除推广将流水表总条数:$bonusTgCount;
+        AR_CALC_BONUS_BD-清除服务奖流水表总条数:$bonusBdCount;AR_CALC_BONUS_QY-清除团队奖流水表总条数:$bonusQyCount;
+        AR_CALC_BONUS_BS-清除管理奖流水表总条数:$bonusBsCount;AR_CALC_BONUS_QUARTER-清除季度奖流水表总条数:$bonusQuarterCount;
+        AR_CALC_BONUS_VILLA-清除房奖流水表总条数:$bonusVillaCount;AR_CALC_BONUS_GARAGE-清除车房奖流水表总条数:$bonusGarageCount";
         $logData[] = [
-            'ID' => SnowFake::instance()->generateId(),
-            'PERIOD_NUM' => $periodNum ?: 0,
-            'TASK_TYPE' => 'serve',
-            'TASK_DESCRIBE' => $desc ?: '请求服务开始',
-            'START_AT' => $time
+            'PERIOD_NUM' => $periodNum,
+            'CALC_MONTH' => $calcMonth,
+            'LOG_DESCRIBE' => $desc,
+            'CREATE_AT' => time()
         ];
 
-        ServeProcess::batchInsert($logData);
+        ServeLog::batchInsert($logData);
         return true;
     }
 
-    // 记录计算基础数据
-    public static function recordDataInfo($time, $periodNum) {
-        $userCount = User::find()->where('1=1')->count('ID'); // user表总数
-        $perfSum = PerfOrder::find()->where('1=1')->sum('PV');// 业绩单总业绩
-        $infoCount = UserInfo::find()->where('1=1')->count('ID'); // userinfo表总数
-        $networkConut = UserNetwork::find()->where('1=1')->count('ID'); // UserNetwork总数
-        $relationCount = UserRelation::find()->where('1=1')->count('ID'); // UserRelation
+    /**
+     * 记录管理奖数据
+     * @param int $periodNum
+     * @param int $calcMonth 业绩期
+     */
+    public static function bonusBSData($periodNum, $calcMonth) {
+        $data = CalcBonusBS::findUseSlaves()
+        ->select('SUM(AMOUNT) AS ORI_AMOUNT,SUM(ORI_BONUS) AS REAL_BONUS,COUNT(ID) AS USER_NUM')
+        ->where('PERIOD_NUM=:PERIOD_NUM', ['PERIOD_NUM'=>$periodNum])
+        ->asArray()
+        ->one();
+        $num = $data['USER_NUM'];
+        $oriBonus = $data['ORI_AMOUNT'];
+        $realBonus = $data['REAL_BONUS'];
+        // 查询得将人数
+        $hasBonus = CalcBonusBS::findUseSlaves()
+        ->select('COUNT(ID) AS BONUS_USER_NUM')
+        ->where('PERIOD_NUM=:PERIOD_NUM AND ORI_BONUS > 0', ['PERIOD_NUM'=>$periodNum])
+        ->asArray()
+        ->one();
+        $hasBonusNum = $hasBonus['BONUS_USER_NUM'];
+        $desc = "计算管理奖完成AR_CALC_BONUS_BS:人数:$num,得奖人数:$hasBonusNum,原金额:$oriBonus,实发金额:$realBonus";
         $logData[] = [
-            'ID' => SnowFake::instance()->generateId(),
-            'PERIOD_NUM' => $periodNum ?: 0,
-            'TASK_TYPE' => 'serve',
-            'TASK_DESCRIBE' => '统计业务系统数据信息',
-            'START_AT' => $time,
-            'CALC_USER_TOTAL' => $userCount > 0 ? $userCount : 0,
-            'CALC_PERF_TOTAL' => $perfSum > 0 ? $perfSum : 0,
-            'CALC_USERINFO_TOTAL' => $infoCount > 0 ? $infoCount : 0,
-            'CALC_NETWORK_TOTAL' => $networkConut > 0 ? $networkConut : 0,
-            'CALC_RELATION_TOTAL' => $relationCount > 0 ? $relationCount :0
+            'PERIOD_NUM' => $periodNum,
+            'CALC_MONTH' => $calcMonth,
+            'LOG_DESCRIBE' => $desc,
+            'CREATE_AT' => time()
         ];
 
-        ServeProcess::batchInsert($logData);
+        ServeLog::batchInsert($logData);
+        return true;
     }
 
-    // 记录流程
-    public static function recordProcess($start, $end, $periodNum, $desc, $type='perf') {
-        try {
-            $logData[] = [
-                'ID' => SnowFake::instance()->generateId(),
-                'PERIOD_NUM' => $periodNum ?: 0,
-                'TASK_TYPE' => $type,
-                'START_AT' => $start,
-                'END_AT' => $end,
-                'TASK_DESCRIBE' => $desc,
-            ];
-
-            ServeProcess::batchInsert($logData);
-        } catch (Exception $e) {
-            var_dump($e->getMessage());
-        }
+    /**
+     * 记录月业绩,小组业绩数据
+     * @param int $periodNum
+     * @param int $calcMonth 业绩期
+     */
+    public static function perfMonthPgs($periodNum, $calcMonth) {
+        $data = PerfMonth::findUseSlaves()
+        ->select('SUM(DIRECTOR_BONUS_PGS) AS SUM_PGS,COUNT(ID) AS USER_NUM')
+        ->where('CALC_MONTH=:CALC_MONTH', ['CALC_MONTH'=>$calcMonth])
+        ->asArray()
+        ->one();
+        $userNum = $data['USER_NUM'];
+        $totalPgs = $data['SUM_PGS'];
+        $desc = "月业绩表增加小组业绩完成AR_PERF_MONTH:小组业绩:$totalPgs,条数:$userNum";
+        $logData[] = [
+            'PERIOD_NUM' => $periodNum,
+            'CALC_MONTH' => $calcMonth,
+            'LOG_DESCRIBE' => $desc,
+            'CREATE_AT' => time()
+        ];
+
+        ServeLog::batchInsert($logData);
+        return true;
+    }
+
+    /**
+     * 记录服务奖数据
+     * @param int $periodNum
+     * @param int $calcMonth 业绩期
+     */
+    public static function bonusBDData($periodNum, $calcMonth) {
+        $data = CalcBonusBD::findUseSlaves()
+        ->select('SUM(AMOUNT) AS SUM_AMOUNT,COUNT(ID) AS USER_NUM')
+        ->where('PERIOD_NUM=:PERIOD_NUM AND AMOUNT>0', ['PERIOD_NUM'=>$periodNum])
+        ->asArray()
+        ->one();
+        $userNum = $data['USER_NUM'];
+        $totalAmount = $data['SUM_AMOUNT'];
+        $desc = "计算服务奖完成AR_CALC_BONUS_BD:得奖人数:$userNum,金额:$totalAmount";
+        $logData[] = [
+            'PERIOD_NUM' => $periodNum,
+            'CALC_MONTH' => $calcMonth,
+            'LOG_DESCRIBE' => $desc,
+            'CREATE_AT' => time()
+        ];
+
+        ServeLog::batchInsert($logData);
+        return true;
+    }
+
+    /**
+     * 记录推广奖数据
+     * @param int $periodNum
+     * @param int $calcMonth 业绩期
+     */
+    public static function bonusTGData($periodNum, $calcMonth) {
+        $data = CalcBonusTG::findUseSlaves()
+        ->select('SUM(AMOUNT) AS SUM_AMOUNT,COUNT(ID) AS USER_NUM')
+        ->where('PERIOD_NUM=:PERIOD_NUM AND AMOUNT>0', ['PERIOD_NUM'=>$periodNum])
+        ->asArray()
+        ->one();
+        $userNum = $data['USER_NUM'];
+        $totalAmount = $data['SUM_AMOUNT'];
+        $desc = "计算推广奖完成AR_CALC_BONUS_TG:得奖人数:$userNum,金额:$totalAmount";
+        $logData[] = [
+            'PERIOD_NUM' => $periodNum,
+            'CALC_MONTH' => $calcMonth,
+            'LOG_DESCRIBE' => $desc,
+            'CREATE_AT' => time()
+        ];
+
+        ServeLog::batchInsert($logData);
+        return true;
+    }
+
+    /**
+     * 记录团队奖数据
+     * @param int $periodNum
+     * @param int $calcMonth 业绩期
+     */
+    public static function bonusQYData($periodNum, $calcMonth) {
+        // 获取封顶人数
+        $cappedNumData = CalcBonusQY::findUseSlaves()
+        ->select('ID,USER_ID')
+        ->where('PERIOD_NUM=:PERIOD_NUM AND ORI_CAPPED_BONUS_QY > 0', ['PERIOD_NUM'=>$periodNum])
+        ->groupBy('USER_ID')
+        ->asArray()
+        ->all();
+        $cappedNumData = array_column($cappedNumData, 'USER_ID');
+        $cappedNum = count($cappedNumData);
+        // 封顶金额
+        $cappedBonusData = CalcBonusQY::findUseSlaves()
+        ->select('SUM(ORI_CAPPED_BONUS_QY) AS CAPPED_AMOUNT')
+        ->where('PERIOD_NUM=:PERIOD_NUM AND ORI_CAPPED_BONUS_QY > 0', ['PERIOD_NUM'=>$periodNum])
+        ->asArray()
+        ->one();
+        $cappendBonus = $cappedBonusData['CAPPED_AMOUNT'];
+
+        // 得奖人数
+        $bonusNumData = CalcBonusQY::findUseSlaves()
+        ->select('ID,USER_ID')
+        ->where('PERIOD_NUM=:PERIOD_NUM AND AMOUNT > 0', ['PERIOD_NUM'=>$periodNum])
+        ->groupBy('USER_ID')
+        ->asArray()
+        ->one();
+        $bonusNumData = array_column($bonusNumData, 'USER_ID');
+        $bonusNum = count($bonusNumData);
+        // 实发金额
+        $bonusData = CalcBonusQY::findUseSlaves()
+        ->select('SUM(AMOUNT) AS BONUS_AMOUNT')
+        ->where('PERIOD_NUM=:PERIOD_NUM', ['PERIOD_NUM'=>$periodNum])
+        ->asArray()
+        ->one();
+        $realBonus = $bonusData['BONUS_AMOUNT'];
+
+        // 人数
+        $allNumData = CalcBonusQY::findUseSlaves()
+        ->select('ID,USER_ID')
+        ->where('PERIOD_NUM=:PERIOD_NUM', ['PERIOD_NUM'=>$periodNum])
+        ->groupBy('USER_ID')
+        ->asArray()
+        ->one();
+        $allNumData = array_column($allNumData, 'USER_ID');
+        $allNum = count($allNumData);
+        // 金额
+        $allBonusData = CalcBonusQY::findUseSlaves()
+        ->select('SUM(HOPE_BONUS) AS ALL_BONUS_AMOUNT')
+        ->where('PERIOD_NUM=:PERIOD_NUM', ['PERIOD_NUM'=>$periodNum])
+        ->asArray()
+        ->one();
+        $oriBonus = $allBonusData['ALL_BONUS_AMOUNT'];
+
+        $desc = "计算团队奖完成AR_CALC_BONUS_QY:人数:$allNum,得奖人数:$bonusNum,原金额:$oriBonus,实发金额:$realBonus,封顶人数:$cappedNum,封顶金额:$cappendBonus";
+        $logData[] = [
+            'PERIOD_NUM' => $periodNum,
+            'CALC_MONTH' => $calcMonth,
+            'LOG_DESCRIBE' => $desc,
+            'CREATE_AT' => time()
+        ];
+
+        ServeLog::batchInsert($logData);
+        return true;
+    }
+
+    /**
+     * 记录房奖数据
+     * @param int $periodNum
+     * @param int $calcMonth 业绩期
+     */
+    public static function bonusVillaData($periodNum, $calcMonth) {
+        // 得奖人数和实发金额
+        $hasNumData = CalcBonusVilla::findUseSlaves()
+        ->select('COUNT(ID) AS USER_NUM, SUM(AMOUNT) AS BONUS_AMOUNT')
+        ->where('PERIOD_NUM=:PERIOD_NUM AND AMOUNT > 0', ['PERIOD_NUM'=>$periodNum])
+        ->asArray()
+        ->one();
+        $hasNum = $hasNumData['USER_NUM'];
+        $realBonus = $hasNumData['BONUS_AMOUNT'];
+        
+        // 封顶金额
+        $cappedBonusData = CalcBonusVilla::findUseSlaves()
+        ->select('SUM(CAP_AMOUNT) AS CAPPED_AMOUNT')
+        ->where('PERIOD_NUM=:PERIOD_NUM AND CAP_AMOUNT > 0 AND CAP_AMOUNT > AMOUNT', ['PERIOD_NUM'=>$periodNum])
+        ->asArray()
+        ->one();
+        $cappendBonus = $cappedBonusData['CAPPED_AMOUNT'];
+
+        $desc = "计算房奖完成AR_CALC_BONUS_VILLA:得奖人数:$hasNum,金额:$realBonus,封顶金额:$cappendBonus";
+        $logData[] = [
+            'PERIOD_NUM' => $periodNum,
+            'CALC_MONTH' => $calcMonth,
+            'LOG_DESCRIBE' => $desc,
+            'CREATE_AT' => time()
+        ];
+
+        ServeLog::batchInsert($logData);
+        return true;
+    }
+
+    /**
+     * 记录车奖数据
+     * @param int $periodNum
+     * @param int $calcMonth 业绩期
+     */
+    public static function bonusGarageData($periodNum, $calcMonth) {
+        // 得奖人数和实发金额
+        $hasNumData = CalcBonusGarage::findUseSlaves()
+        ->select('COUNT(ID) AS USER_NUM, SUM(AMOUNT) AS BONUS_AMOUNT')
+        ->where('PERIOD_NUM=:PERIOD_NUM AND AMOUNT > 0', ['PERIOD_NUM'=>$periodNum])
+        ->asArray()
+        ->one();
+        $hasNum = $hasNumData['USER_NUM'];
+        $realBonus = $hasNumData['BONUS_AMOUNT'];
+        
+        // 封顶金额
+        $cappedBonusData = CalcBonusGarage::findUseSlaves()
+        ->select('SUM(CAP_AMOUNT) AS CAPPED_AMOUNT')
+        ->where('PERIOD_NUM=:PERIOD_NUM AND CAP_AMOUNT > 0 AND CAP_AMOUNT>AMOUNT', ['PERIOD_NUM'=>$periodNum])
+        ->asArray()
+        ->one();
+        $cappendBonus = $cappedBonusData['CAPPED_AMOUNT'];
+
+        $desc = "计算车奖完成AR_CALC_BONUS_GARAGE:得奖人数:$hasNum,金额:$realBonus,封顶金额:$cappendBonus";
+        $logData[] = [
+            'PERIOD_NUM' => $periodNum,
+            'CALC_MONTH' => $calcMonth,
+            'LOG_DESCRIBE' => $desc,
+            'CREATE_AT' => time()
+        ];
+
+        ServeLog::batchInsert($logData);
+        return true;
+    }
+
+    /**
+     * 记录季度奖数据----季度奖有问题,记录不到实发金额,因为不符合得奖得人,没有更新流水表中的AMOUNT字段
+     * @param int $periodNum
+     * @param int $calcMonth 业绩期
+     */
+    public static function bonusQuarterData($periodNum, $calcMonth) {
+        // 得奖人数和实发金额
+        // $hasNumData = CalcBonusQuarter::findUseSlaves()
+        // ->select('COUNT(ID) AS USER_NUM, SUM(AMOUNT) AS BONUS_AMOUNT')
+        // ->where('PERIOD_NUM=:PERIOD_NUM AND AMOUNT > 0', ['PERIOD_NUM'=>$periodNum])
+        // ->asArray()
+        // ->one();
+        // $hasNum = $hasNumData['USER_NUM'];
+        // $realBonus = $hasNumData['BONUS_AMOUNT'];
+        
+        // // 封顶金额
+        // $cappedBonusData = CalcBonusGarage::findUseSlaves()
+        // ->select('SUM(CAP_AMOUNT) AS CAPPED_AMOUNT')
+        // ->where('PERIOD_NUM=:PERIOD_NUM AND CAP_AMOUNT > 0 AND CAP_AMOUNT>AMOUNT', ['PERIOD_NUM'=>$periodNum])
+        // ->asArray()
+        // ->one();
+        // $cappendBonus = $cappedBonusData['CAPPED_AMOUNT'];
+
+        // $desc = "计算季度奖完成AR_CALC_BONUS_QUARTER:得奖人数:xx,原金额:xx,实发金额:xx";
+        // $logData[] = [
+        //     'PERIOD_NUM' => $periodNum,
+        //     'CALC_MONTH' => $calcMonth,
+        //     'LOG_DESCRIBE' => $desc,
+        //     'CREATE_AT' => time()
+        // ];
+
+        // ServeLog::batchInsert($logData);
+        return true;
+    }
+
+    /**
+     * 记录奖金汇总表数据
+     * @param int $periodNum
+     * @param int $calcMonth 业绩期
+     */
+    public static function bonusData($periodNum, $calcMonth) {
+        $bonusData = CalcBonus::findUseSlaves()
+        ->select('SUM(BONUS_REAL) AS LOG_BONUS_REAL,SUM(BONUS_TOTAL) AS LOG_BONUS_TOTAL,SUM(ORI_BONUS_BS) AS LOG_BONUS_BS,
+        SUM(ORI_BONUS_QY) AS LOG_BONUS_QY,SUM(ORI_BONUS_BD) AS LOG_BONUS_BD,SUM(ORI_BONUS_TG) AS LOG_BONUS_TG,
+        SUM(ORI_BONUS_QUARTER) AS LOG_BONUS_QUARTER,SUM(ORI_BONUS_GARAGE) AS LOG_BONUS_GARAGE,SUM(ORI_BONUS_VILLA) AS LOG_BONUS_VILLA,
+        SUM(MANAGE_TAX) AS LOG_MANAGE_TAX,SUM(RECONSUME_POINTS) AS LOG_RECONSUME_POINTS')
+        ->where('PERIOD_NUM=:PERIOD_NUM', ['PERIOD_NUM'=>$periodNum])
+        ->asArray()
+        ->one();
+        $totalBonus = $bonusData['LOG_BONUS_TOTAL'];// 总金额
+        $realBonus = $bonusData['LOG_BONUS_REAL'];// 实发总额
+        $bsBonus = $bonusData['LOG_BONUS_BS'];// 管理奖总额
+        $qyBonus = $bonusData['LOG_BONUS_QY'];// 团队奖
+        $bdBonus = $bonusData['LOG_BONUS_BD'];// 服务奖
+        $tgBonus = $bonusData['LOG_BONUS_TG'];// 推广奖
+        $quarterBonus = $bonusData['LOG_BONUS_QUARTER'];// 季度奖
+        $garageBonus = $bonusData['LOG_BONUS_GARAGE'];// 车奖
+        $villaBonus = $bonusData['LOG_BONUS_VILLA'];// 房奖
+        $manageTax = $bonusData['LOG_MANAGE_TAX'];// 管理费
+        $reconsumePoints = $bonusData['LOG_RECONSUME_POINTS'];// 复消积分
+
+        // 得奖人数
+        $hasNum = CalcBonus::find()
+        ->where('PERIOD_NUM=:PERIOD_NUM AND BONUS_REAL>0', [':PERIOD_NUM'=>$periodNum])
+        ->count('ID');
+        
+        $desc = "奖金写入奖金汇总表完成AR_CALC_BONUS:得奖人数:$hasNum,实发金额:$realBonus,原金额:$totalBonus,管理奖金额:$bsBonus,
+        团队奖金额:$qyBonus,服务奖金额:$bdBonus,推广奖金额:$tgBonus,季度奖金额:$quarterBonus,车奖金额:$garageBonus,房奖金额:$villaBonus,
+        管理费:$manageTax,复消积分:$reconsumePoints";
+        $logData[] = [
+            'PERIOD_NUM' => $periodNum,
+            'CALC_MONTH' => $calcMonth,
+            'LOG_DESCRIBE' => $desc,
+            'CREATE_AT' => time()
+        ];
+
+        ServeLog::batchInsert($logData);
+        return true;
     }
 }