Преглед изворни кода

1359 旅游奖、名车奖、豪宅奖需求

kevin_zhangl пре 3 година
родитељ
комит
4e66bbb7ef
2 измењених фајлова са 178 додато и 0 уклоњено
  1. 107 0
      common/helpers/bonus/BonusCalc.php
  2. 71 0
      common/models/CalcBonusZone.php

+ 107 - 0
common/helpers/bonus/BonusCalc.php

@@ -32,6 +32,7 @@ use common\models\CalcBonusVIP;
 use common\models\CalcBonusXF;
 use common\models\CalcBonusYC;
 use common\models\CalcBonusYJ;
+use common\models\CalcBonusZone;
 use common\models\CalcMonthBonusUser;
 use common\models\Config;
 use common\models\FlowDeductZR;
@@ -85,6 +86,7 @@ class BonusCalc extends BaseObject {
     private $_lastPeriodYearMonth;
     //pv
     private $_pvRatio;
+    private $_calcZone = ['openTravel', 'openCar', 'openHouse'];
 
     const LOOP_FINISH = 1;
     const LOOP_CONTINUE = 2;
@@ -285,6 +287,22 @@ class BonusCalc extends BaseObject {
             echo('计算蓝星管理奖'.($this->_sysConfig['openGL']['VALUE']?'完成':'关闭').',耗时:' . round($t18temp - $t18, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
             $this->_updatePercent(65);
 
+            $this->calcBonusZoneBS($this->_sysConfig['openTravel']);
+            $t18travel = microtime(true);
+            echo('计算旅游奖' . ($this->_sysConfig['openTravel']['VALUE'] ? '完成' : '关闭') . ',耗时:' . round($t18travel - $t18temp, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
+            $this->_updatePercent(67);
+
+            $this->calcBonusZoneBS($this->_sysConfig['openCar']);
+            $t18car = microtime(true);
+            echo('计算名车奖' . ($this->_sysConfig['openCar']['VALUE'] ? '完成' : '关闭').',耗时:' . round($t18car - $t18travel, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
+            $this->_updatePercent(68);
+
+            $this->calcBonusZoneBS($this->_sysConfig['openHouse']);
+            $t18house = microtime(true);
+            echo('计算豪宅奖' . ($this->_sysConfig['openHouse']['VALUE'] ? '完成' : '关闭').',耗时:' . round($t18house - $t18car, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
+            $this->_updatePercent(69);
+
+
             //把奖金会员写入缓存
             $this->loopMonthBonusUserFromDbToCache();
             $t19 = microtime(true);
@@ -424,6 +442,7 @@ class BonusCalc extends BaseObject {
             CalcBonusVIP::pageDeleteAll('PERIOD_NUM='.$this->_periodNum);
             CalcBonusStandard::pageDeleteAll('PERIOD_NUM='.$this->_periodNum);
             ScoreMonth::pageDeleteAll('PERIOD_NUM='.$this->_periodNum);
+            CalcBonusZone::pageDeleteAll('PERIOD_NUM='.$this->_periodNum);
         }
     }
 
@@ -1611,6 +1630,94 @@ class BonusCalc extends BaseObject {
         return $result;
     }
 
+    // 执行旅游奖、名车奖、豪宅奖的计算
+    public function calcBonusZoneBS(array $bonusConfig) {
+        // 月结,如果不是月结点,则直接退出
+        if (!$this->_isCalcMonth) {
+            return true;
+        }
+        // 限定条件,只计算旅游奖、名车奖、豪宅奖
+        if (!in_array($bonusConfig['CONFIG_NAME'], $this->_calcZone)) {
+            return true;
+        }
+
+        // 达标条件:聘级、级别、奖项比例
+        $config = json_decode($bonusConfig['OPTIONS'], true);
+        $mate = $bonusConfig['VALUE'] / 100;
+        $minEmployLevel = $config['employLevel'];
+        $minDeclarationLevel = $config['declarationLevel'];
+
+        // 月度公司总PV
+        $monthTotalPV = PerfMonth::find()
+            ->yearMonth($this->_calcYearMonth)
+            ->where('CALC_MONTH=:CALC_MONTH', [':CALC_MONTH' => $this->_calcYearMonth])
+            ->sum('PV_PCS');
+
+        if ($monthTotalPV <= 0) {
+            return true;
+        }
+
+        // 奖项获取条件:聘级
+        $minEmpLV = "'" . implode("','", $minEmployLevel) . "'";
+        // 计算奖金条件
+        if ($bonusConfig['CONFIG_NAME'] == 'openTravel') {
+            // 旅游奖:聘级3级
+            $query = "CALC_MONTH=:CALC_MONTH AND LEVEL_ID IN ({$minEmpLV})";
+            $param = [':CALC_MONTH' => $this->_calcYearMonth];
+        } else {
+            // 名车奖:聘级4 && 钻卡    豪宅奖:聘级5 && 钻卡
+            $query = "CALC_MONTH=:CALC_MONTH AND LEVEL_ID IN({$minEmpLV}) AND LAST_DEC_LV=:DEV_LV";
+            $param = [':CALC_MONTH' => $this->_calcYearMonth, ':DEV_LV' => $minDeclarationLevel];
+        }
+
+        // 基于蓝星奖结果计算符合获奖条件的会员
+        $userBonusData = CalcBonusBS::find()
+            ->yearMonth($this->_calcYearMonth)
+            ->where($query, $param)
+            ->select('USER_ID,LEVEL_ID,LAST_DEC_LV,LAST_EMP_LV,LAST_STATUS')
+            ->groupBy('USER_ID')
+            ->asArray()
+            ->all();
+
+        // 获奖会员数
+        $userBonusNumber = count($userBonusData);
+        if (!$userBonusNumber) {
+            return true;
+        }
+
+        // 计算奖金:(公司月总PV * 奖金比) / 得奖人数
+        $amount = Tool::formatPrice(($monthTotalPV  * $mate) / $userBonusNumber);
+        if ($amount <= 0) {
+            return true;
+        }
+
+        $insertBonusData = [];
+        foreach($userBonusData as $userBonus) {
+            $insertBonusData[] = [
+                'ID' => SnowFake::instance()->generateId(),
+                'USER_ID' => $userBonus['USER_ID'],
+                'LEVEL_ID' => $userBonus['LEVEL_ID'],
+                'LAST_DEC_LV' => $userBonus['LAST_DEC_LV'],
+                'LAST_EMP_LV' => $userBonus['LAST_EMP_LV'],
+                'LAST_STATUS' => $userBonus['LAST_STATUS'],
+                'AMOUNT' => $amount,
+                'PERIOD_NUM' => $this->_periodNum,
+                'CALC_YEAR' => $this->_calcYear,
+                'CALC_MONTH' => $this->_calcYearMonth,
+                'P_CALC_MONTH' => Date::ociToDate($this->_calcYearMonth, Date::OCI_TIME_FORMAT_SHORT_MONTH),
+                'CREATED_AT' => Date::nowTime(),
+                'BONUS_TYPE' => $bonusConfig['CONFIG_NAME'],
+            ];
+        }
+
+        // 数据写入总表
+        if ($insertBonusData) {
+            CalcBonusZone::batchInsert($insertBonusData);
+        }
+
+        return true;
+    }
+
     /**
      * 蓝星管理奖金
      * @param int $offset

+ 71 - 0
common/models/CalcBonusZone.php

@@ -0,0 +1,71 @@
+<?php
+
+namespace common\models;
+
+use Yii;
+
+/**
+ * This is the model class for table "{{%CALC_BONUS_ZONE}}".
+ *
+ * @property string $ID
+ * @property string $USER_ID 会员ID
+ * @property string $LAST_DEC_LV 结算时会员级别
+ * @property string $LAST_EMP_LV 结算时会员聘级
+ * @property int $LAST_STATUS 结算时状态
+ * @property string $AMOUNT 奖金金额
+ * @property int $PERIOD_NUM 结算期数
+ * @property int $CALC_YEAR 所在结算年
+ * @property int $CALC_MONTH 所在结算月
+ * @property string $P_CALC_MONTH 表分区的日期索引
+ * @property string $LOGS 日志
+ * @property int $CREATED_AT 创建时间
+ * @property string $BONUS_TYPE 奖金类型
+ */
+class CalcBonusZone extends \common\components\ActiveRecord
+{
+    /**
+     * @inheritdoc
+     */
+    public static function tableName()
+    {
+        return '{{%CALC_BONUS_ZONE}}';
+    }
+
+    /**
+     * @inheritdoc
+     */
+    public function rules()
+    {
+        return [
+            [['USER_ID', 'PERIOD_NUM', 'CALC_YEAR', 'CALC_MONTH', 'P_CALC_MONTH', 'CREATED_AT', 'BONUS_TYPE'], 'required'],
+            [['AMOUNT'], 'number'],
+            [['LAST_STATUS', 'PERIOD_NUM', 'CALC_YEAR', 'CALC_MONTH', 'CREATED_AT'], 'integer'],
+            [['ID', 'USER_ID', 'LAST_DEC_LV', 'BONUS_TYPE'], 'string', 'max' => 32],
+            [['P_CALC_MONTH'], 'safe'],
+            [['LOGS'], 'string', 'max' => 2000],
+            [['ID'], 'unique'],
+        ];
+    }
+
+    /**
+     * @inheritdoc
+     */
+    public function attributeLabels()
+    {
+        return [
+            'ID' => 'ID',
+            'USER_ID' => '会员ID',
+            'LAST_DEC_LV' => '结算时会员级别',
+            'LAST_EMP_LV' => '结算时会员聘级',
+            'LAST_STATUS' => '结算时状态',
+            'AMOUNT' => '奖金金额',
+            'PERIOD_NUM' => '结算期数',
+            'CALC_YEAR' => '所在结算年',
+            'CALC_MONTH' => '所在结算月',
+            'P_CALC_MONTH' => '表分区的日期索引',
+            'CREATED_AT' => '创建时间',
+            'LOGS' => '日志',
+            'BONUS_TYPE' => '奖金类型',
+        ];
+    }
+}