浏览代码

季度分红相关

theo 3 年之前
父节点
当前提交
97742df282
共有 3 个文件被更改,包括 135 次插入3 次删除
  1. 83 3
      common/helpers/bonus/BonusCalc.php
  2. 2 0
      common/helpers/bonus/CalcCache.php
  3. 50 0
      common/models/CalcBonusQuarter.php

+ 83 - 3
common/helpers/bonus/BonusCalc.php

@@ -16,6 +16,7 @@ use common\helpers\Tool;
 use common\models\CalcBonus;
 use common\models\CalcBonusBD;
 use common\models\CalcBonusBS;
+use common\models\CalcBonusQuarter;
 use common\models\CalcBonusBT;
 use common\models\CalcBonusCF;
 use common\models\CalcBonusFL;
@@ -314,6 +315,12 @@ class BonusCalc extends BaseObject {
             echo('计算车奖' . ($this->_sysConfig['openGarage']['VALUE'] ? '完成' : '关闭').',耗时:' . round($t23 - $t22, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL . PHP_EOL);
             $this->_updatePercent(69);
 
+            // 计算季度奖
+            $this->calcQuarter();
+            // 将用户写入缓存
+            $this->calcQuarterUser();
+            $t24 = microtime(true);
+            echo('计算季度奖' . ($this->_sysConfig['openQuarter']['VALUE'] ? '完成' : '关闭').',耗时:' . round($t24 - $t23, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL . PHP_EOL);
 
             //把奖金会员写入缓存
             $this->loopMonthBonusUserFromDbToCache();
@@ -1642,6 +1649,23 @@ class BonusCalc extends BaseObject {
         return true;
     }
 
+    /**
+     * 季度奖计算
+     *
+     */
+    public function calcQuarter() {
+        if( !$this->_isCalcMonth || !in_array($this->_calcMonth, [3,6,9,12])) {
+            // 不是结算月,则不进行计算
+            print_r('不是季结点,进这里,不计算季度奖');
+            return false;
+        }
+        $result = \Yii::$app->db->createCommand("CALL QtrCalc(:periodNum)")
+            ->bindValue(':periodNum' , $this->_periodNum )
+            ->execute();
+
+        return $result;
+    }
+
     // 执行蓝星管理奖金的存储过程
     public function calcBsProcedure() {
         if( !$this->_isCalcMonth ) {
@@ -1982,6 +2006,55 @@ class BonusCalc extends BaseObject {
         return true;
     }
 
+    /**
+     * 季度奖写用户缓存
+     *
+     */
+    public function calcQuarterUser(int $offset = 0) {
+        if( !$this->_isCalcMonth || !in_array($this->_calcMonth, [3,6,9,12])) {
+            // 不是结算月,则不进行计算
+            return false;
+        }
+        $allData = CalcBonusQuarter::finduseDbCalc()
+                ->where('PERIOD_NUM=:PERIOD_NUM', [':PERIOD_NUM' => $this->_periodNum])
+                ->groupBy('USER_ID')
+                ->offset($offset)
+                ->limit($this->_limit)
+                ->asArray()
+                ->all();
+        if ($allData){
+            // 达标条件:会员级别:钻卡
+            $config = json_decode($this->_sysConfig['openGL']['OPTIONS'], true);
+            $minDecLevel = $config['mntDec'] ?? [];
+
+            foreach ($allData as $user) {
+                // 扣除相应的复消积分和管理费
+                $deductData = $this->deduct($user['USER_ID'], $user['ORI_BONUS']);
+                $realBonusBs = $deductData['surplus']; // 扣除管理费和复消积分后的实发蓝星奖金
+                $manageTax = $deductData['manageTax']; // 管理费
+                $point = $deductData['reConsumePoints'] + $user['RECONSUME_POINTS'];// 复消积分
+                // 管理奖钻卡发放
+//                if (in_array($user['LAST_DEC_LV'], $minDecLevel)) {
+                // 把对碰后的奖金存入缓存中
+                CalcCache::bonus($user['USER_ID'], $this->_periodNum, 'BONUS_QUARTER', $user['ORI_BONUS'], $deductData);
+                // 加入月奖的会员
+                CalcCache::addHasMonthBonusUsers($user['USER_ID'], $this->_periodNum);
+//                }
+
+                // 更新蓝星奖金存储过程的实发金额数据
+                CalcBonusQuarter::updateAll([
+                    'RECONSUME_POINTS' => $point,
+                    'AMOUNT' => $realBonusBs,
+                    'MANAGE_TAX' => $manageTax],
+                    'USER_ID=:USER_ID AND PERIOD_NUM=:PERIOD_NUM',
+                    [':USER_ID' => $user['USER_ID'], ':PERIOD_NUM' => $this->_periodNum]);
+            }
+            return $this->calcQuarterUser($offset + $this->_limit);
+        }
+        unset($allData);
+        return true;
+    }
+
     /**
      * 蓝星管理奖金
      * @param int $offset
@@ -3724,10 +3797,10 @@ class BonusCalc extends BaseObject {
 
                 $monthSumData = CalcBonus::findUseSlaves()
                 ->select('SUM(BONUS_GX) AS BONUS_GX_SUM, SUM(BONUS_GL) AS BONUS_GL_SUM')
-                ->where('USER_ID=:USER_ID AND CALC_MONTH=:CALC_MONTH', 
+                ->where('USER_ID=:USER_ID AND CALC_MONTH=:CALC_MONTH',
                     [
-                        'USER_ID'=>$userId, 
-                        'CALC_MONTH'=>$this->_calcYearMonth
+                        'USER_ID' => $userId,
+                        'CALC_MONTH' => $this->_calcYearMonth
                     ]
                 )
                 ->asArray()
@@ -3742,6 +3815,11 @@ class BonusCalc extends BaseObject {
             }
         }
 
+        if( $this->_isCalcMonth ) { //季度奖
+            if(in_array($this->_calcMonth, [3,6,9,12])){ // 季度奖
+            }
+        }
+
         $result = [
             'USER_ID' => $userId,
             'LAST_USER_NAME' => $baseInfo['USER_NAME'],
@@ -3815,6 +3893,8 @@ class BonusCalc extends BaseObject {
             'ORI_BONUS_VIP' => $bonus['ORI_BONUS_VIP'],
             'ORI_BONUS_STANDARD' => $standardBonus,
             'ORI_CAPPED_BONUS_QY' => $bonus['ORI_CAPPED_BONUS_QY'], // 团队奖封顶前的奖金
+            'BONUS_QUARTER' => $bonus['BONUS_QUARTER'],
+            'ORI_BONUS_QUARTER' => $bonus['ORI_BONUS_QUARTER'],
 
             'BONUS_TOURISM' => $tourismBonus, // 旅游奖
             'BONUS_VILLA' => $villaBonus, // 房奖

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

@@ -1475,6 +1475,7 @@ class CalcCache {
             'BONUS_YC' => 0,
             'BONUS_VIP' => 0,
             'BONUS_BS' => 0,
+            'BONUS_QUARTER' => 0,
             'BONUS_YC_EXTRA' => 0,
             'ORI_BONUS_BD' => 0,
             'ORI_BONUS_BS' => 0,
@@ -1482,6 +1483,7 @@ class CalcCache {
             'BONUS_BS_ABBR' => 0,
             'ORI_BONUS_BS_MNT' => 0,
             'ORI_BONUS_BS_ABBR' => 0,
+            'ORI_BONUS_QUARTER' => 0,
             'ORI_BONUS_TG' => 0,
             'ORI_BONUS_XF' => 0,
             'ORI_BONUS_YJ' => 0,

+ 50 - 0
common/models/CalcBonusQuarter.php

@@ -0,0 +1,50 @@
+<?php
+
+namespace common\models;
+
+use Yii;
+
+
+class CalcBonusQuarter extends \common\components\ActiveRecord
+{
+    /**
+     * @inheritdoc
+     */
+    public static function tableName()
+    {
+        return '{{%CALC_BONUS_QUARTER}}';
+    }
+
+    /**
+     * @inheritdoc
+     */
+    public function rules()
+    {
+        return [
+            [['USER_ID', 'PERIOD_NUM', 'CALC_MONTH', 'CREATED_AT'], 'required'],
+            [['AMOUNT', 'ORI_BONUS', 'MANAGE_TAX'], 'number'],
+            [['PERIOD_NUM', 'CALC_MONTH', 'CREATED_AT'], 'integer'],
+            [['ID', 'USER_ID'], 'string', 'max' => 32],
+            [['ID'], 'unique'],
+        ];
+    }
+
+    /**
+     * @inheritdoc
+     */
+    public function attributeLabels()
+    {
+        return [
+            'ID' => 'ID',
+            'USER_ID' => '会员ID',
+            'ORI_BONUS' => '原奖金',
+            'MANAGE_TAX' => '管理费',
+            'RECONSUME_POINTS' => '复消积分',
+            'AMOUNT' => '金额',
+            'CALC_YEAR' => '所在结算年',
+            'CALC_MONTH' => '所在结算月',
+            'PERIOD_NUM' => '结算期数',
+            'CREATED_AT' => '创建时间',
+        ];
+    }
+}