Просмотр исходного кода

扣除管理费和复消积分

root 3 лет назад
Родитель
Сommit
a861abeb1f
2 измененных файлов с 55 добавлено и 18 удалено
  1. 45 18
      common/helpers/bonus/CalcServeBonusCalc.php
  2. 10 0
      common/models/Config.php

+ 45 - 18
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\Config;
 use common\models\EmployLevel;
 use common\models\PerfMonth;
 use common\models\PerfPeriod;
@@ -1163,6 +1164,32 @@ class CalcServeBonusCalc extends BaseObject {
         }
     }
 
+    /**
+     * 扣除管理费 返回管理费
+     */
+    public function deductManageTax($bonus) {
+        return $bonus * $this->_sysConfig['manageTaxPercent']['VALUE'] / 100;
+    }
+
+    // 扣除复消积分 返回应扣除的复消费积分
+    public function deductReconsumePonits($userId, $bonus) {
+        //判断是否达到了本月扣除复消的上限
+        $cacheData = CalcCache::monthLastPeriodReconsumePoints($userId, $this->_periodNum, $this->_calcYearMonth);
+        $bonusCache = CalcCache::bonus($userId, $this->_periodNum);
+        $reConsumePointsTotal = $bonusCache['RECONSUME_POINTS'] + $cacheData['RECONSUME_POINTS_SUM'];
+        $reConsumePointsCap = $this->_sysConfig['reConsumePointsMonthCap']['VALUE'];
+        unset($cacheData, $bonusCache);
+        $reConsumePoints = 0;
+        if( $reConsumePointsTotal < $reConsumePointsCap ) {
+            $reConsumePoints = $bonus * $this->_sysConfig['reConsumePointsPercent']['VALUE'] / 100;
+
+            $reConsumePoints = min($reConsumePoints, $reConsumePointsCap-$reConsumePointsTotal);
+        }
+        unset($reConsumePointsTotal, $reConsumePointsCap);
+
+        return $reConsumePoints;
+    }
+
     /**
      * 扣除复消积分和管理费
      */
@@ -1240,29 +1267,29 @@ class CalcServeBonusCalc extends BaseObject {
         $villaBonus = CalcCache::villaBonus($userId, $this->_periodNum);
         $pervSurplusPerf = CalcCache::surplusPerf($userId, $this->_periodNum);
         $starCrownLv = CalcCache::getUserStarCrown($userId, $this->_periodNum);// 星级
-
-        $bonusReal = '0.000'; // 总实发
-        $deductConfig = Cache::getSystemConfig()['deductBonusItem']['OPTIONS'];     
-        $deductConfig = json_decode($deductConfig, true);
-        $noDeduct = $deductConfig['noDeduct']; // 不需要扣除的奖金项
-        $deduct = $deductConfig['deduct']; // 需要扣除的奖金项
-        $totalDeductSum = '0.000'; // 需要扣除的奖金项,扣除完之后的实发金额
+        $bonusReal = '0.000'; // 总实发   
+        $deductManageTaxItems = Config::DEDUCT_MANAGE_TAX; // 扣除管理费的列表  
+        $deductReconsumePointsItems = Config::DEDUCT_RECONSUME_POINTS;// 扣除复消积分的列表
+        $totalReconsumePointSum = $totalManageSum = '0.000'; // 需要扣除的奖金项,扣除完之后的实发金额
         $deductManageTax = '0.000'; //  扣除的管理费
         $deductReconsumePoints = '0.000'; //  扣除的复消积分 
-        foreach($noDeduct as $v) {
-            $bonusReal+= $bonus[$v]; // 累加不需要扣除奖的项
+        foreach($deductManageTaxItems as $v) {
+            $totalManageSum+= $bonus[$v]; // 需要扣除管理费的累计之和
         }
-        foreach($deduct as $v) {
-            $totalDeductSum+= $bonus[$v]; // 需要扣除的累计之和
+        foreach($deductReconsumePointsItems as $v) {
+            $totalReconsumePointSum+= $bonus[$v]; // 需要扣除管理费的累计之和
         }
-        if ($totalDeductSum > 0) {
-            // 进行扣除管理费和复消积分
-            $tempDeduct = $this->deduct($userId, $totalDeductSum);
-            $totalDeductSum = $tempDeduct['surplus'];
-            $deductManageTax = $tempDeduct['manageTax'];
-            $deductReconsumePoints = $tempDeduct['reConsumePoints'];
+        // 扣除管理费
+        if ($totalManageSum > 0) {
+            $deductManageTax = $this->deductManageTax($totalManageSum);
+        }
+
+        // 扣除复消积分
+        if ($totalReconsumePointSum > 0) {
+            $deductReconsumePoints = $this->deductReconsumePonits($userId, $totalReconsumePointSum);
         }
-        $bonusReal += $totalDeductSum;
+        // 总实发=总原奖金-扣除的总管理费-总复消积分
+        $bonusReal = $bonus['BONUS_TOTAL'] - $deductManageTax - $deductReconsumePoints;
 
         $result = [
             'USER_ID' => $userId,

+ 10 - 0
common/models/Config.php

@@ -36,6 +36,16 @@ class Config extends \common\components\ActiveRecord
     const INPUT_TYPE_SWITCH = 8;            // 开关切换
     const INPUT_TYPE_TEXTAREA = 9;            // 多行文本
     const INPUT_TYPE_TABLE = 10;            // 表格
+    CONST DEDUCT_MANAGE_TAX = [
+        'BONUS_BS', // 蓝星管理奖
+        'BONUS_QY', // 团队奖
+        'BONUS_QUARTER' // 季度奖
+    ]; // 扣除管理费的奖金项
+    CONST DEDUCT_RECONSUME_POINTS = [
+        'BONUS_BS', // 蓝星管理奖
+        'BONUS_QY', // 团队奖
+        'BONUS_QUARTER' // 季度奖
+    ]; // 扣除复消积分的奖金项
 
     /**
      * @inheritdoc