|
|
@@ -26,6 +26,7 @@ use common\models\CalcBonusHB;
|
|
|
use common\models\CalcBonusLS;
|
|
|
use common\models\CalcBonusLX;
|
|
|
use common\models\CalcBonusQY;
|
|
|
+use common\models\CalcBonusST;
|
|
|
use common\models\CalcBonusStandard;
|
|
|
use common\models\CalcBonusTG;
|
|
|
use common\models\CalcBonusVIP;
|
|
|
@@ -253,13 +254,25 @@ class BonusCalc extends BaseObject {
|
|
|
// $t14 = microtime(true);
|
|
|
// echo('计算复消管理奖'.($this->_sysConfig['fxOpenGL']['VALUE']?'完成':'关闭').',耗时:' . round($t14 - $t13, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
|
|
|
// $this->_updatePercent(70);
|
|
|
-
|
|
|
- if($this->_sysConfig['openYC']['VALUE']) {
|
|
|
- $this->calcBonusYCStepOne();
|
|
|
- $this->calcBonusYCStepTwo();
|
|
|
+
|
|
|
+
|
|
|
+ // if($this->_sysConfig['openYC']['VALUE']) {
|
|
|
+ // $this->calcBonusYCStepOne();
|
|
|
+ // $this->calcBonusYCStepTwo();
|
|
|
+ // }
|
|
|
+
|
|
|
+ // 计算店服务奖 月奖
|
|
|
+ if($this->_sysConfig['openStore']['VALUE']) {
|
|
|
+ if ($this->_sysConfig['openStoreReduce']['VALUE']) {
|
|
|
+ // 开启了紧缩方式,计算店服务
|
|
|
+ $this->calcStoreBonusReduce();
|
|
|
+ } else {
|
|
|
+ // 未开启紧缩方式,计算店服务
|
|
|
+ $this->calcStoreBonus();
|
|
|
+ }
|
|
|
}
|
|
|
$t16 = microtime(true);
|
|
|
- echo('计算荣衔奖'.($this->_sysConfig['openYC']['VALUE']?'完成':'关闭').',耗时:' . round($t16 - $t13, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
|
|
|
+ echo('计算店服务奖金'.($this->_sysConfig['openStore']['VALUE']?'完成':'关闭').',耗时:' . round($t16 - $t13, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
|
|
|
$this->_updatePercent(55);
|
|
|
|
|
|
if($this->_sysConfig['openVIP']['VALUE']) {
|
|
|
@@ -421,6 +434,7 @@ class BonusCalc extends BaseObject {
|
|
|
CalcBonusGL::pageDeleteAll('PERIOD_NUM='.$this->_periodNum);
|
|
|
// 月结时要清空的数据
|
|
|
if ($this->_isCalcMonth) {
|
|
|
+ CalcBonusST::pageDeleteAll('PERIOD_NUM='.$this->_periodNum);
|
|
|
CalcBonusYC::pageDeleteAll('PERIOD_NUM='.$this->_periodNum);
|
|
|
CalcBonusVIP::pageDeleteAll('PERIOD_NUM='.$this->_periodNum);
|
|
|
CalcBonusStandard::pageDeleteAll('PERIOD_NUM='.$this->_periodNum);
|
|
|
@@ -921,6 +935,164 @@ class BonusCalc extends BaseObject {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ // 紧缩计算店服务奖,不活跃,则给一个活跃的店铺
|
|
|
+ public function calcStoreBonusReduce(int $offset = 0) {
|
|
|
+ if( !$this->_isCalcMonth ) {
|
|
|
+ // 不是结算月,则不进行计算
|
|
|
+ echo sprintf("时间:[%s]店服务奖金非月节点,不进行计算,当前offset为:【%s】" . PHP_EOL, date('Y-m-d H:i:s', time()) , $offset);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ echo sprintf("时间:[%s]店服务奖金计算--紧缩方式,当前offset为:【%s】" . PHP_EOL, date('Y-m-d H:i:s', time()) , $offset);
|
|
|
+ $allData = CalcCache::getHasPerfUsers($this->_periodNum, $offset, $this->_limit);
|
|
|
+ if ($allData) {
|
|
|
+ $insertBonusData = [];
|
|
|
+ foreach ($allData as $userId) {
|
|
|
+ $storeBonus = $this->verifyStorePerf($userId);
|
|
|
+ if (empty($storeBonus)) continue;
|
|
|
+ // 判断此店铺是否是活跃用户,如果不活跃,则往上找一个活跃的店铺获得此奖
|
|
|
+ $isActive = $this->_isMonthPerfLimit($userId);
|
|
|
+ $bonusUserId = '';
|
|
|
+ // 如果用户不活跃,且上面没有活跃的,则不累计了,是不是
|
|
|
+ if (!$isActive) {
|
|
|
+ // 如果此店铺不活跃,则找最近的一个店铺获得此奖
|
|
|
+ $this->loopRelationParentDo($userId, function ($parent) use (&$bonusUserId) {
|
|
|
+ if ($this->_isMonthPerfLimit($parent['PARENT_UID'])) {
|
|
|
+ // 判断是否是店铺
|
|
|
+ $parentUser = CalcCache::getUserInfo($parent['PARENT_UID'], $this->_periodNum);
|
|
|
+ if ($parentUser['IS_STUDIO'] == 1) {
|
|
|
+ $bonusUserId = $parent['PARENT_UID'];
|
|
|
+
|
|
|
+ return self::LOOP_FINISH;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ unset($parent);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (!$isActive && !$bonusUserId) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ $realBonusUserId = $bonusUserId ? $bonusUserId : $userId;
|
|
|
+ //扣除相应的复消积分和管理费
|
|
|
+ $deductData = $this->deduct($realBonusUserId, $storeBonus);
|
|
|
+ // 把对碰后的奖金存入缓存中
|
|
|
+ CalcCache::bonus($realBonusUserId, $this->_periodNum, 'BONUS_STORE', $storeBonus, $deductData);
|
|
|
+ $surplus = $deductData['surplus'];
|
|
|
+ $manageTax = $deductData['manageTax'];
|
|
|
+ $reConsumePoints = $deductData['reConsumePoints'];
|
|
|
+
|
|
|
+ //店服务奖流水
|
|
|
+ $insertBonusData[] = [
|
|
|
+ 'ID' => SnowFake::instance()->generateId(),
|
|
|
+ 'USER_ID' => $realBonusUserId,
|
|
|
+ 'FROM_USER_ID' => $bonusUserId ? $userId : '', // 分享店铺的ID.只有紧缩且未活跃,才有此值
|
|
|
+ 'AMOUNT' => $surplus,
|
|
|
+ 'ORI_BONUS' => $storeBonus,
|
|
|
+ 'RECONSUME_POINTS' => $reConsumePoints,
|
|
|
+ 'MANAGE_TAX' => $manageTax,
|
|
|
+ '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()
|
|
|
+ ];
|
|
|
+
|
|
|
+ unset($bonusUserId, $userId, $deductData);
|
|
|
+ }
|
|
|
+ CalcBonusST::batchInsert($insertBonusData);
|
|
|
+ unset($allData, $insertBonusData);
|
|
|
+ return $this->calcStoreBonusReduce($offset + $this->_limit);
|
|
|
+ }
|
|
|
+
|
|
|
+ unset($allData);
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 未开启紧缩方式计算店服务奖,不活跃即不给奖金
|
|
|
+ public function calcStoreBonus(int $offset = 0) {
|
|
|
+ if( !$this->_isCalcMonth ) {
|
|
|
+ // 不是结算月,则不进行计算
|
|
|
+ echo sprintf("时间:[%s]店服务奖金非月节点,不进行计算,当前offset为:【%s】" . PHP_EOL, date('Y-m-d H:i:s', time()) , $offset);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ echo sprintf("时间:[%s]店服务奖金计算--非紧缩方式,当前offset为:【%s】" . PHP_EOL, date('Y-m-d H:i:s', time()) , $offset);
|
|
|
+ $allData = CalcCache::getHasPerfUsers($this->_periodNum, $offset, $this->_limit);
|
|
|
+ if ($allData) {
|
|
|
+ $insertBonusData = [];
|
|
|
+ foreach ($allData as $userId) {
|
|
|
+ $storeBonus = $this->verifyStorePerf($userId);
|
|
|
+ if (empty($storeBonus)) continue;
|
|
|
+ // 未开启紧缩,不活跃,则不发放了
|
|
|
+ $isActive = $this->_isMonthPerfLimit($userId);
|
|
|
+ if (!$isActive) continue;
|
|
|
+ $surplus = $storeBonus;
|
|
|
+ //扣除相应的复消积分和管理费
|
|
|
+ $deductData = $this->deduct($userId, $storeBonus);
|
|
|
+ CalcCache::bonus($userId, $this->_periodNum, 'BONUS_STORE', $storeBonus, $deductData);
|
|
|
+ $surplus = $deductData['surplus'];
|
|
|
+ $manageTax = $deductData['manageTax'];
|
|
|
+ $reConsumePoints = $deductData['reConsumePoints'];
|
|
|
+
|
|
|
+ //店服务奖流水
|
|
|
+ $insertBonusData[] = [
|
|
|
+ 'ID' => SnowFake::instance()->generateId(),
|
|
|
+ 'USER_ID' => $userId,
|
|
|
+ 'AMOUNT' => $surplus,
|
|
|
+ 'ORI_BONUS' => $storeBonus,
|
|
|
+ 'RECONSUME_POINTS' => $reConsumePoints,
|
|
|
+ 'MANAGE_TAX' => $manageTax,
|
|
|
+ '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()
|
|
|
+ ];
|
|
|
+
|
|
|
+ unset($userId, $deductData);
|
|
|
+ }
|
|
|
+ CalcBonusST::batchInsert($insertBonusData);
|
|
|
+ unset($allData, $insertBonusData);
|
|
|
+ return $this->calcStoreBonus($offset + $this->_limit);
|
|
|
+ }
|
|
|
+
|
|
|
+ unset($allData);
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过用户id,校验店服务奖,此用户是否有原奖金
|
|
|
+ */
|
|
|
+ public function verifyStorePerf($userId) {
|
|
|
+ // 从缓存中获取会员的业绩信息
|
|
|
+ $perfData = CalcCache::nowPeriodPerf($userId, $this->_periodNum);
|
|
|
+ if( !$perfData ) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ // 获取小组+自己的业绩
|
|
|
+ $perfPv = $perfData['STORE_PV_GRAND'] ?? 0;
|
|
|
+ if( $perfPv <= 0 ) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ // 业绩乘以比例为奖金
|
|
|
+ $storeBonus = Tool::formatPrice($perfPv * $this->_sysConfig['storePercent']['VALUE'] / 100);
|
|
|
+ if ($storeBonus <= 0) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ // 获取会员的报单级别
|
|
|
+ $userBaseInfo = CalcCache::getUserInfo($userId, $this->_periodNum);
|
|
|
+ $storeBonus = $this->bonusTotalLimit($storeBonus, $userId, $userBaseInfo['REC_NUM'], $userBaseInfo['ZC_AMOUNT']);
|
|
|
+ if( $storeBonus <= 0 ) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ unset($perfData, $perfPv, $userBaseInfo, $userId);
|
|
|
+
|
|
|
+ return $storeBonus;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 报单业绩奖
|
|
|
* @param int $offset
|
|
|
@@ -3436,7 +3608,7 @@ class BonusCalc extends BaseObject {
|
|
|
$bonus['MANAGE_TAX'] = $bonus['MANAGE_TAX'] + $monthGxManageTax;
|
|
|
$realBonusGl += $bonusGlSum + $bonus['BONUS_GL'];
|
|
|
$realBonusBs = $blueStartAmount;
|
|
|
- $bonusReal += $realBonusGx + $realBonusBs + $realBonusGl;
|
|
|
+ $bonusReal += $realBonusGx + $realBonusBs + $realBonusGl + $bonus['BONUS_STORE']; // 再加上店服务奖的实发
|
|
|
$exchangePoints = isset($userBS['PRODUCT_POINT']) && !empty($userBS['PRODUCT_POINT']) ? $userBS['PRODUCT_POINT'] : 0; // 兑换积分
|
|
|
unset($monthSumData, $bonusGxSum, $bonusGlSum);
|
|
|
$oriBonusBs = isset($bonus['ORI_BONUS_BS']) && $bonus['ORI_BONUS_BS'] > 0 ? $bonus['ORI_BONUS_BS'] : 0;
|
|
|
@@ -3515,6 +3687,8 @@ class BonusCalc extends BaseObject {
|
|
|
'ORI_BONUS_YC' => $bonus['ORI_BONUS_YC'] + $bonus['ORI_BONUS_YC_EXTRA'],
|
|
|
'ORI_BONUS_VIP' => $bonus['ORI_BONUS_VIP'],
|
|
|
'ORI_BONUS_STANDARD' => $standardBonus,
|
|
|
+ 'BONUS_ST' => $bonus['BONUS_STORE'], // 店服务奖实发
|
|
|
+ 'ORI_BONUS_ST' => $bonus['ORI_BONUS_STORE'], // 店服务奖原奖金
|
|
|
|
|
|
|
|
|
|