|
|
@@ -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
|