|
|
@@ -36,6 +36,7 @@ use yii\base\StaticInstanceTrait;
|
|
|
use common\helpers\Cache;
|
|
|
use common\helpers\Date;
|
|
|
use common\models\CalcBonus;
|
|
|
+use common\models\CalcBonusBS;
|
|
|
use common\models\PerfActiveUser;
|
|
|
use common\models\PerfMonth;
|
|
|
use common\models\User;
|
|
|
@@ -379,14 +380,28 @@ class BonusSend extends BaseObject {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 更新会员聘级
|
|
|
+ * 蓝星奖金(即新的管理奖),更新会员聘级
|
|
|
* @param int $offset
|
|
|
* @return bool
|
|
|
* @throws \yii\db\Exception
|
|
|
*/
|
|
|
public function updateEmpLevel(int $offset = 0) {
|
|
|
if ($this->_isCalcMonth) {
|
|
|
- $allData = PerfMonth::findUseDbCalc()->yearMonth($this->_calcYearMonth)->where('CALC_MONTH=:CALC_MONTH', [':CALC_MONTH' => $this->_calcYearMonth])->offset($offset)->limit($this->_limit)->all();
|
|
|
+ $empLv = EmployLevel::getIdConvertLevelSortCache();
|
|
|
+ $allData = CalcBonusBS::findUseDbCalc()
|
|
|
+ ->yearMonth($this->_calcYearMonth)
|
|
|
+ ->where(
|
|
|
+ 'CALC_MONTH=:CALC_MONTH AND PERIOD_NUM=:PERIOD_NUM',
|
|
|
+ [
|
|
|
+ ':CALC_MONTH' => $this->_calcYearMonth,
|
|
|
+ ':PERIOD_NUM' =>$this->_periodNum
|
|
|
+ ]
|
|
|
+ )
|
|
|
+ ->orderBy('CREATED_AT DESC')
|
|
|
+ ->groupBy('USER_ID')
|
|
|
+ ->offset($offset)
|
|
|
+ ->limit($this->_limit)
|
|
|
+ ->all();
|
|
|
//@todo 用户级别不变则不更新
|
|
|
$defaultEmpLv = EmployLevel::getDefaultLevelId();
|
|
|
if ($allData) {
|
|
|
@@ -394,11 +409,20 @@ class BonusSend extends BaseObject {
|
|
|
try {
|
|
|
foreach ($allData as $data) {
|
|
|
//@todo 用户级别不变则不更新
|
|
|
- if( $data['LAST_EMP_LV'] === $defaultEmpLv ) continue;
|
|
|
-
|
|
|
- User::updateAll(['EMP_LV' => $data['LAST_EMP_LV']], 'ID=:USER_ID', [':USER_ID' => $data['USER_ID']]);
|
|
|
- User::deleteBaseInfoFromRedis($data['USER_ID']);
|
|
|
- unset($data);
|
|
|
+ if( $data['LEVEL_ID'] === $defaultEmpLv ) continue;
|
|
|
+ $user = CalcCache::getUserInfo($data['USER_ID'], $this->_periodNum);
|
|
|
+ $userEmpLv = $user['EMP_LV']; // 用户的历史最高聘级
|
|
|
+ $nowBsEmpLv = $data['LEVEL_ID']; // 当前蓝星奖计算(即管理奖) 的等级
|
|
|
+ $userEmpLvSort = $empLv[$userEmpLv]; // 历史最高聘级的 级别值
|
|
|
+ $nowBsEmpLvSort = $empLv[$nowBsEmpLv]; // 当前蓝星计算的聘级 级别值
|
|
|
+ if ($nowBsEmpLvSort > $userEmpLvSort) {
|
|
|
+ // 如果当前期的级别值大于历史最高级别,则更新用户表里的最高聘级
|
|
|
+ User::updateAll(['EMP_LV' => $data['LEVEL_ID']], 'ID=:USER_ID', [':USER_ID' => $data['USER_ID']]);
|
|
|
+ User::deleteBaseInfoFromRedis($data['USER_ID']);
|
|
|
+ unset($data);
|
|
|
+ } else {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
}
|
|
|
$transaction->commit();
|
|
|
} catch (Exception $e) {
|
|
|
@@ -414,6 +438,42 @@ class BonusSend extends BaseObject {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ // /**
|
|
|
+ // * 更新会员聘级
|
|
|
+ // * @param int $offset
|
|
|
+ // * @return bool
|
|
|
+ // * @throws \yii\db\Exception
|
|
|
+ // */
|
|
|
+ // public function updateEmpLevel(int $offset = 0) {
|
|
|
+ // if ($this->_isCalcMonth) {
|
|
|
+ // $allData = PerfMonth::findUseDbCalc()->yearMonth($this->_calcYearMonth)->where('CALC_MONTH=:CALC_MONTH', [':CALC_MONTH' => $this->_calcYearMonth])->offset($offset)->limit($this->_limit)->all();
|
|
|
+ // //@todo 用户级别不变则不更新
|
|
|
+ // $defaultEmpLv = EmployLevel::getDefaultLevelId();
|
|
|
+ // if ($allData) {
|
|
|
+ // $transaction = Yii::$app->db->beginTransaction();
|
|
|
+ // try {
|
|
|
+ // foreach ($allData as $data) {
|
|
|
+ // //@todo 用户级别不变则不更新
|
|
|
+ // if( $data['LAST_EMP_LV'] === $defaultEmpLv ) continue;
|
|
|
+
|
|
|
+ // User::updateAll(['EMP_LV' => $data['LAST_EMP_LV']], 'ID=:USER_ID', [':USER_ID' => $data['USER_ID']]);
|
|
|
+ // User::deleteBaseInfoFromRedis($data['USER_ID']);
|
|
|
+ // unset($data);
|
|
|
+ // }
|
|
|
+ // $transaction->commit();
|
|
|
+ // } catch (Exception $e) {
|
|
|
+ // $transaction->rollBack();
|
|
|
+ // $this->addError('updateEmpLevel', '更新聘级失败,原因:' . $e->getMessage());
|
|
|
+ // return false;
|
|
|
+ // }
|
|
|
+ // unset($transaction, $allData, $defaultEmpLv);
|
|
|
+ // return $this->updateEmpLevel($offset + $this->_limit);
|
|
|
+ // }
|
|
|
+ // unset($allData);
|
|
|
+ // }
|
|
|
+ // return true;
|
|
|
+ // }
|
|
|
+
|
|
|
// 更活跃会员,将is_send改成1
|
|
|
public function updateActiveUser() {
|
|
|
try {
|