| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547 |
- <?php
- /**
- * Created by PhpStorm.
- * User: leo
- * Date: 2018/8/2
- * Time: 上午10:32
- */
- namespace common\helpers\bonus;
- use common\helpers\Cache;
- use common\helpers\Date;
- use common\helpers\snowflake\SnowFake;
- use common\helpers\Tool;
- use common\models\CalcBonus;
- use common\models\CalcBonusBD;
- use common\models\CalcBonusBS;
- use common\models\CalcBonusQuarter;
- use common\models\CalcBonusGarage;
- use common\models\CalcBonusQY;
- use common\models\CalcBonusTG;
- use common\models\CalcBonusTourism;
- use common\models\CalcBonusVilla;
- use common\models\PerfMonth;
- use common\models\PerfPeriod;
- use common\models\Period;
- use common\models\StarCrownLevel;
- use yii\base\BaseObject;
- use yii\base\StaticInstanceTrait;
- use yii\db\Query;
- class CalcServeBonusCalc extends BaseObject {
- use StaticInstanceTrait;
- private $_limit = 3000;
- private $_handleUserId;
- private $_sysConfig = [];
- private $_decLevelConfig = [];
- private $_empLevelConfig = [];
- private $_starCrownLevelConfig = [];
- private $_decRoleConfig = [];
- private $_errors = [];
- private $_periodNum = 0;
- private $_periodId;
- private $_isCalcMonth = 0;
- private $_calcYear;
- private $_calcMonth;
- private $_calcYearMonth;
- private $_calcMonthPeriodNumCount = 0;
- //pv
- private $_pvRatio;
- private $_calcZone = ['openTravel', 'openCar', 'openHouse'];
- const LOOP_FINISH = 1;
- const LOOP_CONTINUE = 2;
- const ORDER_TYPE_TO_FW_COEFFICIENT = [
- 'ZC' => 'fwCoefficientFromZc',
- 'FX_CASH' => 'fwCoefficientFromFxCash',
- 'FX_POINT' => 'fwCoefficientFromFxPoint',
- ];
- //最小报单pv
- const MIN_BD_PV = 980;
- public function init() {
- parent::init();
- }
- /**
- * 设置期数
- * @param int $periodNum
- * @return int
- */
- public function setPeriodNum(int $periodNum) {
- return $this->_periodNum = $periodNum;
- }
- /**
- * 获取期数
- * @return int
- */
- public function getPeriodNum() {
- return $this->_periodNum;
- }
- /**
- * 加入错误错误
- * @param $attr
- * @param $error
- */
- public function addError($attr, $error) {
- $this->_errors[$attr][] = $error;
- }
- /**
- * 获取错误信息
- * @return array
- */
- public function getErrors() {
- return $this->_errors;
- }
- /**
- * 开始执行结算步骤
- * @param $periodNum
- * @param null $handleUserId
- * @return bool
- */
- public function calcStep($periodNum, $handleUserId = null) {
- try {
- $this->_errors = [];
- $this->setPeriodNum($periodNum);
- $this->_handleUserId = $handleUserId;
- $t1 = microtime(true);
- // 初始化结算任务
- $this->initCalcTask();
- $t2 = microtime(true);
- // 设置结算状态
- $this->setCalcStatus('start');
- // 清空所有本期结算用到的缓存
- CalcCache::clearCalcBonusCache($this->_periodNum);
- $t3 = microtime(true);
- // 清空相关表数据
- $this->clearCalcTableData();
- $t4 = microtime(true);
- echo('初始化、清空缓存及相关数据表完成,耗时:' . round($t4 - $t1, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
- $this->_updatePercent(10);
- // 蓝星奖放到最前面 奖金计算开始
- if($this->_sysConfig['openGL']['VALUE']) {
- echo('计算蓝星奖开始,' . date('Y-m-d H:i:s', $t4) . PHP_EOL);
- // 调用存储过程,计算蓝星管理奖金
- $this->calcBsProcedure();
- // 将有蓝星管理奖金的用户加入到有奖金缓存用户中
- $this->calcBonusBsGL();
- // 将有【蓝星业绩奖金】的用户加入到有奖金缓存用户中
- // $this->calcBonusBsYJ();
- // // 将有【蓝星管理奖金】的用户加入到有奖金缓存用户中
- // $this->calcBonusBsGL();
- }
- $t5 = microtime(true);
- echo('计算蓝星奖'.($this->_sysConfig['openGL']['VALUE']?'完成':'关闭').',耗时:' . round($t5 - $t4, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
- if($this->_sysConfig['openFW']['VALUE']) {
- $this->calcBonusBDStepOne();
- $this->calcBonusBDStepTwo();
- }
- $t6 = microtime(true);
- echo('计算服务奖'.($this->_sysConfig['openFW']['VALUE']?'完成':'关闭').',耗时:' . round($t6 - $t5, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
- $this->_updatePercent(15);
- // 销售奖/推广奖
- if($this->_sysConfig['openTG']['VALUE']) {
- $this->calcBonusTG();
- }
- $t7 = microtime(true);
- echo('计算推广奖'.($this->_sysConfig['openTG']['VALUE']?'完成':'关闭').',耗时:' . round($t7 - $t6, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
- $this->_updatePercent(20);
- // 绩效奖/团队奖
- if($this->_sysConfig['openQY']['VALUE']) {
- $this->calcBonusQY();
- }
- $t8 = microtime(true);
- echo('计算团队奖'.($this->_sysConfig['openQY']['VALUE']?'完成':'关闭').',耗时:' . round($t8 - $t7, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
- $this->_updatePercent(35);
- // $this->calcBonusTourism($this->_sysConfig['openTourism']);
- // $t21 = microtime(true);
- // echo('计算旅游奖' . ($this->_sysConfig['openTourism']['VALUE'] ? '完成' : '关闭') . ',耗时:' . round($t21 - $t20, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
- // $this->_updatePercent(68);
- $this->calcBonusVilla();
- $t22 = microtime(true);
- echo('计算房奖' . ($this->_sysConfig['openVilla']['VALUE'] ? '完成' : '关闭').',耗时:' . round($t22 - $t8, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL . PHP_EOL);
- $this->_updatePercent(45);
- $this->calcBonusGarage();
- $t23 = microtime(true);
- echo('计算车奖' . ($this->_sysConfig['openGarage']['VALUE'] ? '完成' : '关闭').',耗时:' . round($t23 - $t22, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL . PHP_EOL);
- $this->_updatePercent(55);
- // 计算季度奖
- $this->calcQuarter();
- $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->calcQuarterUser();
- $this->_updatePercent(65);
- $t25 = microtime(true);
- echo('计算季度奖' . ($this->_sysConfig['openQuarter']['VALUE'] ? '完成' : '关闭').',耗时:' . round($t25 - $t24, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL . PHP_EOL);
- // 奖金写库
- $this->loopBonusUsers();
- $this->_updatePercent(75);
- $t30 = microtime(true);
- echo('奖金写库操作完成,耗时:' . round($t30 - $t25, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
- Period::updateCalcProcess(3, $this->_periodNum);
- $this->_updatePercent(100);
- $t35 = microtime(true);
- echo('结算全部完成,共耗时:' . round($t35 - $t1, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL . PHP_EOL);
- } catch (\Exception $e) {
- $this->errorCalcTask();
- $this->addError('calc', sprintf('File【%s】, Line【%s】, Msg【%s】', $e->getFile(), $e->getLine(), $e->getMessage()));
- return false;
- }
- return true;
- }
- /**
- * 结算完成
- */
- public function endCalcTask() {
- // 更新结算状态
- $this->setCalcStatus('end');
- }
- /**
- * 结算错误
- */
- public function errorCalcTask() {
- // 清空所有本期结算用到的缓存
- CalcCache::clearCalcBonusCache($this->_periodNum);
- // 更新结算状态
- $this->setCalcStatus('fail');
- }
- /**
- * 初始化结算任务
- * @throws \yii\db\Exception
- */
- public function initCalcTask() {
- $periodObj = Period::instance();
- $periodDataArr = $periodObj->setPeriodNum($this->_periodNum);
- if (empty($this->_periodNum)) {
- $this->_periodNum = $periodDataArr['PERIOD_NUM'];
- }
- $this->_sysConfig = Cache::getSystemConfig();
- $this->_decLevelConfig = Cache::getDecLevelConfig();
- $this->_empLevelConfig = Cache::getEmpLevelConfig();
- $this->_starCrownLevelConfig = Cache::getStarCrownLevelConfig();
- $this->_decRoleConfig = CalcCache::getDecRoleConfig($this->_periodNum);
- $periodNum = $this->_periodNum;
- $this->_periodId = $periodDataArr['ID'];
- $this->_isCalcMonth = $periodObj->isCalcMonth($periodNum);
- $this->_calcYear = $periodObj->getYear($periodNum);
- $this->_calcMonth = $periodObj->getMonth($periodNum);
- $this->_calcYearMonth = $periodObj->getYearMonth($periodNum);
- }
- /**
- * 设置结算状态
- * @param $type
- * start|end|fail
- */
- public function setCalcStatus($type) {
- if ($type == 'start') {
- Period::updateAll(['IS_CALCING' => 1, 'IS_CALCULATED' => Period::CALCULATE_NONE, 'CALCULATE_STARTED_AT' => Date::nowTime()], 'PERIOD_NUM=:PERIOD_NUM', [':PERIOD_NUM' => $this->_periodNum]);
- } elseif ($type == 'end') {
- Period::updateAll(['IS_CALCING' => 0, 'IS_CALCULATED' => Period::CALCULATE_FINISH, 'CALCULATED_AT' => Date::nowTime()], 'PERIOD_NUM=:PERIOD_NUM', [':PERIOD_NUM' => $this->_periodNum]);
- } elseif ($type == 'fail') {
- Period::updateAll(['IS_CALCING' => 0, 'IS_CALCULATED' => Period::CALCULATE_FAIL, 'CALCULATED_AT' => 0], 'PERIOD_NUM=:PERIOD_NUM', [':PERIOD_NUM' => $this->_periodNum]);
- }
- }
- /**
- * 清空相关表数据
- */
- public function clearCalcTableData() {
- // 奖金表
- CalcBonus::pageDeleteAll('PERIOD_NUM='.$this->_periodNum);
- CalcBonusQY::pageDeleteAll('PERIOD_NUM='.$this->_periodNum);
- CalcBonusBD::pageDeleteAll('PERIOD_NUM='.$this->_periodNum); // 实际上是服务奖流水表
- CalcBonusTG::pageDeleteAll('PERIOD_NUM='.$this->_periodNum);
- // 月结时要清空的数据
- if ($this->_isCalcMonth) {
- CalcBonusTourism::pageDeleteAll('PERIOD_NUM='.$this->_periodNum);
- CalcBonusGarage::pageDeleteAll('PERIOD_NUM='.$this->_periodNum);
- CalcBonusVilla::pageDeleteAll('PERIOD_NUM='.$this->_periodNum);
- }
- }
- /**
- * 推广奖
- * @param int $offset
- * @return bool
- * @throws \yii\db\Exception
- */
- public function calcBonusTG(int $offset = 0) {
- $periodNum = $this->_periodNum;
- // 从缓存获取分页有业绩的会员信息
- $allData = CalcCache::getHasPerfUsers($this->_periodNum, $offset, $this->_limit);
- if ($allData) {
- $insertBonusData = [];
- foreach ($allData as $userId) {
- // 从缓存中获取会员的业绩信息
- $perfData = CalcCache::nowPeriodPerf($userId, $periodNum);
- if( !$perfData ) continue;
- //个人业绩都算推荐奖,包括报单和复消、二次购物
- $perfPv = $perfData['PV_PCS_ZC'] ?? 0;
- if( $perfPv <= 0 ) continue;
- //推广奖使用个人PCS
- $recBonus = Tool::formatPrice($perfPv * $this->_sysConfig['recPercent']['VALUE'] / 100);
- if ($recBonus <= 0) continue;
- // 把对碰后的奖金存入缓存中
- $perfUserInfo = CalcCache::getUserInfo($userId, $periodNum);
- $bonusUserId = $perfUserInfo['REC_UID'] ?? '';
- if( !$bonusUserId ) continue;
- // 获取会员的报单级别
- $userBaseInfo = CalcCache::getUserInfo($bonusUserId, $this->_periodNum);
- //扣除相应的复消积分和管理费
- $deductData = $this->deduct($bonusUserId, $recBonus);
- CalcCache::bonus($bonusUserId, $periodNum, 'BONUS_TG', $recBonus, $deductData);
- //来源会员信息
- $fromUserInfo = CalcCache::getUserInfo($userId, $this->_periodNum);
- //推广奖流水
- $insertBonusData[] = [
- 'ID' => SnowFake::instance()->generateId(),
- 'USER_ID' => $bonusUserId,
- 'LAST_DEC_LV' => $userBaseInfo['DEC_LV'],
- 'LAST_EMP_LV' => $userBaseInfo['LAST_EMP_LV'],,
- 'LAST_STATUS' => $userBaseInfo['STATUS'],
- 'FROM_USER_ID' => $userId,
- 'LAST_FROM_DEC_LV' => $fromUserInfo['DEC_LV'],
- 'LAST_FROM_EMP_LV' => $fromUserInfo['EMP_LV'],
- 'LAST_FROM_STATUS' => $fromUserInfo['STATUS'],
- 'AMOUNT' => $deductData['surplus'],
- 'ORI_BONUS' => $recBonus,
- 'RECONSUME_POINTS' => $deductData['reConsumePoints'],
- 'MANAGE_TAX' => $deductData['manageTax'],
- 'PERIOD_NUM' => $this->_periodNum,
- 'CALC_YEAR' => $this->_calcYear,
- 'CALC_MONTH' => $this->_calcYearMonth,
- 'CREATED_AT' => Date::nowTime(),
- 'LOGS' => json_encode([
- 'perfPv' => $perfPv,
- 'recPercentConfig' => $this->_sysConfig['recPercent']['VALUE'],
- 'recNum' => $userBaseInfo['REC_NUM'],
- 'decAmount' => $userBaseInfo['ZC_AMOUNT'],
- 'decLevel' => $userBaseInfo['DEC_LV'],
- 'bonusTotalLimit' => [
- $this->_sysConfig['bonusTotalZeroLimit']['VALUE'],
- $this->_sysConfig['bonusTotalOneLimit']['VALUE'],
- $this->_sysConfig['bonusTotalTwoLimit']['VALUE'],
- ],
- ]),
- ];
- unset($perfData, $perfPv, $perfUserInfo, $recBonus, $bonusUserId, $userBaseInfo, $userId, $deductData, $fromUserInfo);
- }
- CalcBonusTG::batchInsert($insertBonusData);
- unset($allData, $insertBonusData);
- return $this->calcBonusTG($offset + $this->_limit);
- }
- unset($allData);
- return true;
- }
- /**
- * 服务奖第一步
- * @param int $offset
- * @return bool
- * @throws \yii\db\Exception
- */
- public function calcBonusBDStepOne(int $offset = 0) {
- echo sprintf("时间:[%s]服务奖第【1】步,当前offset为:【%s】" . PHP_EOL, date('Y-m-d H:i:s', time()) , $offset);
- $periodNum = $this->_periodNum;
- // 从缓存获取分页有业绩的会员信息
- $allData = CalcCache::getHasPerfUsers($this->_periodNum, $offset, $this->_limit);
- if ($allData) {
- $insertBonusData = [];
- foreach ($allData as $userId) {
- // 从缓存中获取会员的业绩信息
- $perfData = CalcCache::nowPeriodPerf($userId, $periodNum);
- if( !$perfData ) continue;
- $decRoleBonusFrom = explode(',', $this->_sysConfig['decRoleBonusFrom']['VALUE']);
- $validPvPcs = 0;
- foreach ($decRoleBonusFrom as $orderType) {
- $orderTypeName = sprintf('PV_PCS_%s', $orderType);
- $orderTypeValue = $perfData[$orderTypeName] ?? 0;
- $coefficientName = self::ORDER_TYPE_TO_FW_COEFFICIENT[$orderType];
- $coefficient = $this->_sysConfig[$coefficientName]['VALUE'] ?? 1;
- $validPvPcs += $orderTypeValue * $coefficient;
- unset($orderType, $orderTypeName, $orderTypeValue, $coefficientName, $coefficient);
- }
- unset($perfData, $decRoleBonusFrom);
- if ( $validPvPcs <= 0 ) continue;
- $this->loopRelationParentDo($userId, function ($parent) use($userId, $validPvPcs){
- //判断parent的报单中心级别 和 服务奖比例
- $bonusUserId = $parent['PARENT_UID'];
- //计算级别之后更新过userInfo的缓存,缓存中级别发生了变化
- $bonusUserInfo = CalcCache::getUserInfo($bonusUserId, $this->_periodNum);
- $isDec = $bonusUserInfo['IS_DEC'];
- if($isDec == 0) return self::LOOP_CONTINUE;
- $decRoleId = $bonusUserInfo['DEC_ROLE_ID'];
- if( !$decRoleId ) return self::LOOP_CONTINUE;
- if( !isset($this->_decRoleConfig[$decRoleId]) ) return self::LOOP_CONTINUE;
- $parentDecRoleLevel = $this->_decRoleConfig[$decRoleId];
- $parentFwBonusPercent = $parentDecRoleLevel['FW_BONUS_PERCENT'] ?? 0;
- $cacheMaxPercent = CalcCache::fwMaxBonusPercent($userId, $this->_periodNum);
- $diffPercent = $parentFwBonusPercent - $cacheMaxPercent;
- if( $diffPercent <= 0 ) return self::LOOP_CONTINUE;
- $fwBonus = $validPvPcs * $diffPercent / 100;
- if( $fwBonus <= 0 ) return self::LOOP_CONTINUE;
- //给本人添加服务奖比例
- CalcCache::fwMaxBonusPercent($userId, $this->_periodNum, $parentFwBonusPercent);
- //记录奖金和奖金来源到缓存 并实现在缓存中奖金累加
- CalcCache::saveFwBonusList($bonusUserId, $this->_periodNum, $fwBonus, ['fromUid'=>$userId, 'fromPvPcs'=>$validPvPcs]);
- CalcCache::addHasFwBonusUsers($bonusUserId, $this->_periodNum);
- unset($bonusUserId, $bonusUserInfo, $isDec, $decRoleId, $parentDecRoleLevel, $parentFwBonusPercent, $cacheMaxPercent, $diffPercent, $fwBonus);
- });
- unset($userId, $validPvPcs);
- }
- unset($allData, $insertBonusData);
- return $this->calcBonusBDStepOne($offset + $this->_limit);
- }
- unset($allData);
- return true;
- }
- /**
- * 服务奖第二步
- * @param int $offset
- * @return bool
- * @throws \yii\db\Exception
- */
- public function calcBonusBDStepTwo(int $offset = 0) {
- echo sprintf("时间:[%s]服务奖第【2】步,当前offset为:【%s】" . PHP_EOL, date('Y-m-d H:i:s', time()) , $offset);
- $allData = CalcCache::getHasFwBonusUsers($this->_periodNum, $offset, $this->_limit);
- if ($allData) {
- $insertBonusData = [];
- foreach ($allData as $userId) {
- $fwBonusData = CalcCache::getFwBonusList($userId, $this->_periodNum);
- if( !$fwBonusData ) continue;
- $fwBonus = $fwBonusData['fwBonus'] ?? 0;
- if( $fwBonus <=0 ) continue;
- //总金额限制
- $userBaseInfo = CalcCache::getUserInfo($userId, $this->_periodNum);
- CalcCache::bonus($userId, $this->_periodNum, 'BONUS_BD', $fwBonus);
- $decRoleId = $userBaseInfo['DEC_ROLE_ID'];
- $insertBonusData[] = [
- 'ID' => SnowFake::instance()->generateId(),
- 'USER_ID' => $userId,
- 'LAST_DEC_LV' => $userBaseInfo['DEC_LV'],
- 'LAST_EMP_LV' => $userBaseInfo['LAST_EMP_LV'],
- 'LAST_STATUS' => $userBaseInfo['STATUS'],
- 'FROM_USER_ID' => $userId,
- 'LAST_FROM_DEC_LV' => $userBaseInfo['DEC_LV'],
- 'LAST_FROM_EMP_LV' => $userBaseInfo['EMP_LV'],
- 'LAST_FROM_STATUS' => $userBaseInfo['STATUS'],
- 'AMOUNT' => $fwBonus,
- 'ORI_BONUS' => $fwBonus,
- 'RECONSUME_POINTS' => 0,
- 'MANAGE_TAX' => 0,
- 'PERIOD_NUM' => $this->_periodNum,
- 'CALC_YEAR' => $this->_calcYear,
- 'CALC_MONTH' => $this->_calcYearMonth,
- 'CREATED_AT' => Date::nowTime(),
- 'LOGS' => json_encode([
- 'decRoleId' => $decRoleId,
- ])
- ];
- unset($userId, $fwBonusData, $userBaseInfo, $decRoleId, $fwBonus);
- }
- CalcBonusBD::batchInsert($insertBonusData);
- unset($insertBonusData, $allData);
- $this->calcBonusBDStepTwo($offset + $this->_limit);
- }
- unset($allData);
- return true;
- }
- /**
- * 团队奖
- * @param int $offset
- * @return bool
- * @throws \yii\db\Exception
- */
- public function calcBonusQY(int $offset = 0) {
- echo sprintf("时间:[%s]团队奖,当前offset为:【%s】" . PHP_EOL, date('Y-m-d H:i:s', time()) , $offset);
- $periodNum = $this->_periodNum;
- // 从缓存获取分页有业绩的会员信息
- $allData = CalcCache::getHasPerfUsers($this->_periodNum, $offset, $this->_limit);
- if ($allData) {
- $insertBonusData = [];
- foreach ($allData as $userId) {
- // 从缓存中获取会员的业绩信息
- $perfData = CalcCache::nowPeriodPerf($userId, $periodNum);
- // 从缓存中获取会员的上期结余业绩信息
- $pervSurplusPerf = CalcCache::surplusPerf($userId, $periodNum);
- // 本期 + 上期结余
- $perfArr = [
- 'SURPLUS_1L' => $perfData['PV_1L_TOUCH'] + $pervSurplusPerf['SURPLUS_1L'],
- 'SURPLUS_2L' => $perfData['PV_2L_TOUCH'] + $pervSurplusPerf['SURPLUS_2L'],
- 'SURPLUS_3L' => $perfData['PV_3L_TOUCH'] + $pervSurplusPerf['SURPLUS_3L'],
- 'SURPLUS_4L' => $perfData['PV_4L_TOUCH'] + $pervSurplusPerf['SURPLUS_4L'],
- 'SURPLUS_5L' => $perfData['PV_5L_TOUCH'] + $pervSurplusPerf['SURPLUS_5L'],
- ];
- $oriPerfArr = [
- 'perfArr' => $perfArr,
- 'touchBonus' => 0,
- ];
- // 获取会员的报单级别
- $userBaseInfo = CalcCache::getUserInfo($userId, $this->_periodNum);
- $decLevelConfig = $this->_decLevelConfig;
- $nowDecLevelConfig = $decLevelConfig[$userBaseInfo['DEC_LV']];
- // 对碰
- $touchBonusArr = $this->touchPerf($oriPerfArr, $perfArr, $nowDecLevelConfig['QY_PERCENT']/100);
- $touchPerfArr = [];
- foreach ($touchBonusArr['perfArr'] as $keyR => $perfR) {
- $touchPerfArr[$keyR] = $perfR;
- }
- // 对碰完成后把结余的业绩存入本期业绩缓存中
- CalcCache::nowPeriodPerf($userId, $periodNum, $touchPerfArr);
- //更新数据库
- PerfPeriod::updateAll($touchPerfArr, 'USER_ID=:USER_ID AND PERIOD_NUM=:PERIOD_NUM', [
- 'USER_ID' => $userId,
- 'PERIOD_NUM' => $periodNum,
- ]);
- if ($touchBonusArr['touchBonus'] <= 0) continue;
- $teamBonus = $touchBonusArr['touchBonus'];
- $capBonusQy = $teamBonus; // 封顶前的奖金
- //判断级别上限,个人奖金封顶限制
- $teamBonus = $this->declarationLevelCap($teamBonus, $userId, $userBaseInfo['DEC_LV']);
- if( $teamBonus <= 0 ) continue;
- // 将封顶前的金额加入用户奖金缓存中,此金额不能发放(总奖金,总实际奖金)
- CalcCache::bonus($userId, $periodNum, 'CAPPED_BONUS_QY', $capBonusQy);
- //扣除相应的复消积分和管理费
- $deductData = $this->deduct($userId, $teamBonus);
- // 把对碰后的奖金存入缓存中
- CalcCache::bonus($userId, $periodNum, 'BONUS_QY', $teamBonus, $deductData);
- // TODO:取小腿值
- $payLeg = min([$perfArr['SURPLUS_1L'], $perfArr['SURPLUS_2L']]);
- // 计算荣衔星级
- $starCrown = StarCrownLevel::getStarCrown($payLeg);
- // 星级放入缓存
- CalcCache::addUserStarCrown($userId, $periodNum, $starCrown['ID']);
- //团队奖流水
- $insertBonusData[] = [
- 'ID' => SnowFake::instance()->generateId(),
- 'USER_ID' => $userId,
- 'ORI_CAPPED_BONUS_QY' => $capBonusQy,
- 'LAST_DEC_LV' => $userBaseInfo['DEC_LV'],
- 'LAST_EMP_LV' => $userBaseInfo['LAST_EMP_LV'],
- 'LAST_CROWN_LV' => $starCrown['ID'],
- 'LAST_STATUS' => $userBaseInfo['STATUS'],
- 'AMOUNT' => $deductData['surplus'],
- 'ORI_BONUS' => $teamBonus,
- 'RECONSUME_POINTS' => $deductData['reConsumePoints'],
- 'MANAGE_TAX' => $deductData['manageTax'],
- 'PERIOD_NUM' => $this->_periodNum,
- 'CALC_YEAR' => $this->_calcYear,
- 'CALC_MONTH' => $this->_calcYearMonth,
- 'CREATED_AT' => Date::nowTime(),
- 'LOGS' => json_encode([
- 'perfArr' => $perfArr,
- 'touchPerfArrOri' => $touchBonusArr['perfArr'],
- 'touchPerfArr' => $touchPerfArr,
- 'nowDecLevelConfig' => $nowDecLevelConfig,
- 'decLevel' => $userBaseInfo['DEC_LV'],
- ]),
- ];
- unset($perfData, $pervSurplusPerf, $perfArr, $oriPerfArr, $touchPerfArr, $userBaseInfo, $decLevelConfig, $touchBonusArr, $userId, $nowDecLevelConfig, $teamBonus, $deductData);
- }
- CalcBonusQY::batchInsert($insertBonusData);
- unset($allData, $insertBonusData);
- return $this->calcBonusQY($offset + $this->_limit);
- }
- unset($allData);
- return true;
- }
- /**
- * 季度奖计算
- *
- */
- public function calcQuarter() {
- if( !$this->_isCalcMonth || !in_array($this->_calcMonth, [3,6,9,12])) {
- // echo('不是季结点,进这里,不计算季度奖'. PHP_EOL);
- return false;
- }
- $result = \Yii::$app->db->createCommand("CALL QtrCalc(:periodNum)")
- ->bindValue(':periodNum' , $this->_periodNum )
- ->execute();
- return $result;
- }
- // 执行蓝星管理奖金的存储过程
- public function calcBsProcedure() {
- if( !$this->_isCalcMonth ) {
- // 不是结算月,则不进行计算
- return false;
- }
- $result = \Yii::$app->db->createCommand("CALL CalcBlue(:periodNum)")
- ->bindValue(':periodNum' , $this->_periodNum )
- ->execute();
-
- return $result;
- }
- // 执行旅游奖的计算
- public function calcBonusTourism() {
- // 月结,如果不是月结点,则直接退出
- if (!$this->_isCalcMonth) {
- return true;
- }
- $bonusConfig = $this->_sysConfig['openTourism'];
- // 达标条件:聘级、级别、奖项比例
- $config = json_decode($bonusConfig['OPTIONS'], true);
- // 奖金总比例
- $mate = $bonusConfig['VALUE'] / 100;
- // 会员级别
- $minDecLevel = $config['OPTIONS']['declarationLevel'] ?? [];
- // 月度公司总PV
- $monthTotalPV = PerfMonth::find()
- ->yearMonth($this->_calcYearMonth)
- ->where('CALC_MONTH=:CALC_MONTH', [':CALC_MONTH' => $this->_calcYearMonth])
- ->sum('PV_PCS');
- // 用于分发的奖金总数
- $transferAmount = $monthTotalPV * $mate;
- // 基于蓝星奖结果计算符合获奖条件的会员StarDirector
- $userStarDirector = CalcBonusBS::find()
- ->yearMonth($this->_calcYearMonth)
- ->where('CALC_MONTH=:CALC_MONTH', [':CALC_MONTH' => $this->_calcYearMonth])
- ->select('USER_ID,LEVEL_ID,LAST_DEC_LV,LAST_EMP_LV,LAST_STATUS')
- ->groupBy('USER_ID')
- ->asArray()
- ->all();
- $userStarDirectorObj = array_column($userStarDirector, NULL, 'USER_ID');
- // 基于团队奖/绩效奖结果计算会员的StarCrown
- $userStarCrown = CalcBonusQY::find()
- ->yearMonth($this->_calcYearMonth)
- ->where('CALC_MONTH=:CALC_MONTH', [':CALC_MONTH' => $this->_calcYearMonth])
- ->select('USER_ID,LAST_CROWN_LV')
- ->groupBy('USER_ID')
- ->asArray()
- ->all();
- $userStarCrownObj = array_column($userStarCrown, NULL, 'USER_ID');
- // 合并用户ID,去重
- $bonusUsers = array_unique(array_merge(array_keys($userStarDirectorObj), array_keys($userStarCrownObj)));
- // 奖金点数综合
- $bonusPointComplex = 0;
- $insertBonusData = [];
- foreach($bonusUsers as $userId) {
- // 计算奖金:取starDirectorPoint和starCrownPoint的大个值
- $starDirectorPoint = $this->_empLevelConfig[$userStarDirectorObj[$userId]['LEVEL_ID']]['TOURISM_PERCENT'] ?? 0;
- $starCrownPoint = $this->_starCrownLevelConfig[$userStarCrownObj[$userId]['LAST_CROWN_LV']]['TOURISM_PERCENT'] ?? 0;
- // 奖金比例:
- $bonusPoint = max($starDirectorPoint, $starCrownPoint);
- if ($bonusPoint <= 0) {
- continue;
- }
-
- $insertBonusData[] = [
- 'ID' => SnowFake::instance()->generateId(),
- 'USER_ID' => $userId,
- 'LAST_DEC_LV' => $userStarDirectorObj[$userId]['LAST_DEC_LV'],
- 'LAST_EMP_LV' => $userStarDirectorObj[$userId]['LAST_EMP_LV'],
- 'LAST_STATUS' => $userStarDirectorObj[$userId]['LAST_STATUS'],
- 'LAST_CROWN_LV' => $userStarCrownObj[$userId]['LAST_CROWN_LV'],
- 'AMOUNT_STANDARD' => 0,
- 'POINT' => $bonusPoint,
- '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(),
- 'PERF' => $monthTotalPV,
- 'TRANSFER_RATE' => $mate,
- 'TRANSFER_AMOUNT' => Tool::formatPrice($transferAmount),
- 'CAP_AMOUNT' => 0,
- 'POINT_COMPLEX' => 0,
- ];
- $bonusPointComplex += $bonusPoint;
- }
- // 数据写入总表
- if ($insertBonusData) {
- foreach ($insertBonusData as &$bonusData) {
- // 计算奖金
- $amount = Tool::formatPrice($transferAmount * ($bonusData['POINT'] / $bonusPointComplex));
- if ($amount <= 0) {
- continue;
- }
- // 会员级别达到要求才会发放奖金
- if ($bonusData['LAST_DEC_LV'] == $minDecLevel) {
- // 放入缓存
- CalcCache::tourismBonus($bonusData['USER_ID'], $this->_periodNum, $amount);
- // 加入月奖的会员
- CalcCache::addHasMonthBonusUsers($bonusData['USER_ID'], $this->_periodNum);
- }
- $bonusData['AMOUNT'] = $amount;
- $bonusData['POINT_COMPLEX'] = $bonusPointComplex;
- }
- CalcBonusTourism::batchInsert($insertBonusData);
- }
- return true;
- }
- // 执行房奖的计算
- public function calcBonusVilla() {
- // 月结,如果不是月结点,则直接退出
- if (!$this->_isCalcMonth) {
- return true;
- }
- $bonusConfig = $this->_sysConfig['openVilla'];
- // 达标条件:聘级、级别、奖项比例
- $config = json_decode($bonusConfig['OPTIONS'], true);
- // 奖金总比例
- $mate = $bonusConfig['VALUE'] / 100;
- // 个人奖金封顶
- $capBonus = intval($this->_sysConfig['openVillaCap']['VALUE'] ?? 0);
- // 会员级别
- $minDecLevel = $config['declarationLevel'] ?? [];
- // 月度公司总PV
- $monthTotalPV = PerfMonth::find()
- ->yearMonth($this->_calcYearMonth)
- ->where('CALC_MONTH=:CALC_MONTH', [':CALC_MONTH' => $this->_calcYearMonth])
- ->sum('PV_PCS');
- // 用于分发的奖金总数
- $transferAmount = $monthTotalPV * $mate;
- // 基于团队奖/绩效奖结果计算会员的StarCrown.StarCrown基于周期计算,一个月会产生多次,取月周期中的最高星级
- $subQuery = CalcBonusQY::find()
- ->yearMonth($this->_calcYearMonth)
- ->where('CALC_MONTH = :CALC_MONTH AND LAST_CROWN_LV <> :NO_CROWN_LV', [':CALC_MONTH' => $this->_calcYearMonth, ':NO_CROWN_LV' => StarCrownLevel::NO_LEVEL_ID])
- ->select('USER_ID,LAST_DEC_LV,LAST_CROWN_LV,LAST_STATUS,LEVEL_NAME,SORT')
- ->joinWith(['starCrown' => function($query) {
- $query->select(['LEVEL_NAME', 'SORT']);
- }])
- ->having(1)
- ->orderBy('USER_ID ASC, SORT DESC');
- $userStarCrownObj = (new Query())->from(['u' => $subQuery])->select('USER_ID,LAST_DEC_LV,LAST_CROWN_LV,LAST_STATUS,LEVEL_NAME,SORT')->groupBy('USER_ID')->indexBy('USER_ID')->all();
- // 奖金点数综合
- $bonusPointComplex = 0;
- $insertBonusData = [];
- foreach($userStarCrownObj as $item) {
- // 奖金比例
- $bonusPoint = $this->_starCrownLevelConfig[$item['LAST_CROWN_LV']]['VILLA_PERCENT'] ?? 0;
- if (!$bonusPoint) {
- continue;
- }
- // 会员级别达到要求才会发放奖金
- if ($item['LAST_DEC_LV'] != $minDecLevel) {
- continue;
- }
- $userBaseInfo = CalcCache::getUserInfo($item['USER_ID'], $this->_periodNum);
- $insertBonusData[] = [
- 'ID' => SnowFake::instance()->generateId(),
- 'USER_ID' => $item['USER_ID'],
- 'LAST_DEC_LV' => $item['LAST_DEC_LV'] ?? '',
- 'LAST_EMP_LV' => $userBaseInfo['LAST_EMP_LV'],
- 'LAST_STATUS' => $item['LAST_STATUS'] ?? 0,
- 'LAST_CROWN_LV' => $item['LAST_CROWN_LV'] ?? '',
- 'AMOUNT' => 0,
- 'POINT' => $bonusPoint,
- 'PERIOD_NUM' => $this->_periodNum,
- 'CALC_YEAR' => $this->_calcYear,
- 'CALC_MONTH' => $this->_calcYearMonth,
- 'CREATED_AT' => Date::nowTime(),
- 'PERF' => $monthTotalPV,
- 'TRANSFER_RATE' => $mate,
- 'TRANSFER_AMOUNT' => Tool::formatPrice($transferAmount),
- 'CAP_AMOUNT' => 0,
- 'POINT_COMPLEX' => 0,
- ];
- $bonusPointComplex += $bonusPoint;
- }
- // 数据写入总表
- if ($insertBonusData) {
- // 计算个人奖金
- foreach ($insertBonusData as &$bonusData) {
- // 计算奖金
- $amount = Tool::formatPrice($transferAmount * ($bonusData['POINT'] / $bonusPointComplex));
- if ($amount <= 0) {
- continue;
- }
- // 封顶前奖金数
- $capAmount = $amount;
- // 奖金数不能大于封顶值
- $amount = ($amount > $capBonus) ? $capBonus : $amount;
- $bonusData['AMOUNT'] = $amount;
- $bonusData['CAP_AMOUNT'] = $capAmount;
- $bonusData['POINT_COMPLEX'] = $bonusPointComplex;
- // 放入缓存
- CalcCache::villaBonus($bonusData['USER_ID'], $this->_periodNum, $amount);
- // 加入月奖的会员
- CalcCache::addHasMonthBonusUsers($bonusData['USER_ID'], $this->_periodNum);
- }
- CalcBonusVilla::batchInsert($insertBonusData);
- }
- return true;
- }
- // 执行车奖的计算
- public function calcBonusGarage() {
- // 月结,如果不是月结点,则直接退出
- if (!$this->_isCalcMonth) {
- return true;
- }
- $bonusConfig = $this->_sysConfig['openGarage'];
- // 达标条件:聘级、级别、奖项比例
- $config = json_decode($bonusConfig['OPTIONS'], true);
- // 奖金总比例
- $mate = $bonusConfig['VALUE'] / 100;
- // 会员级别
- $minDecLevel = $config['declarationLevel'] ?? [];
- // 个人奖金封顶
- $capBonus = intval($this->_sysConfig['openGarageCap']['VALUE'] ?? 0);
- // 月度公司总PV
- $monthTotalPV = PerfMonth::find()
- ->yearMonth($this->_calcYearMonth)
- ->where('CALC_MONTH=:CALC_MONTH', [':CALC_MONTH' => $this->_calcYearMonth])
- ->sum('PV_PCS');
- // 用于分发的奖金总数
- $transferAmount = $monthTotalPV * $mate;
- // 基于蓝星奖结果计算符合获奖条件的会员StarDirector
- $userStarDirector = CalcBonusBS::find()
- ->yearMonth($this->_calcYearMonth)
- ->where('CALC_MONTH = :CALC_MONTH', [':CALC_MONTH' => $this->_calcYearMonth])
- ->select('USER_ID,LEVEL_ID,LAST_DEC_LV,LAST_STATUS')
- ->groupBy('USER_ID')
- ->asArray()
- ->all();
- $userStarDirectorObj = array_column($userStarDirector, NULL, 'USER_ID');
- // 基于团队奖/绩效奖结果计算会员的StarCrown.StarCrown基于周期计算,一个月会产生多次,取月周期中的最高星级
- $subQuery = CalcBonusQY::find()
- ->yearMonth($this->_calcYearMonth)
- ->where('CALC_MONTH = :CALC_MONTH AND LAST_CROWN_LV <> :NO_CROWN_LV', [':CALC_MONTH' => $this->_calcYearMonth, ':NO_CROWN_LV' => StarCrownLevel::NO_LEVEL_ID])
- ->select('USER_ID,LAST_DEC_LV,LAST_CROWN_LV,LAST_STATUS,LEVEL_NAME,SORT')
- ->joinWith(['starCrown' => function($query) {
- $query->select(['LEVEL_NAME', 'SORT']);
- }])
- ->having(1)
- ->orderBy('USER_ID ASC, SORT DESC');
- $userStarCrownObj = (new Query())->from(['u' => $subQuery])->select('USER_ID,LAST_DEC_LV,LAST_CROWN_LV,LAST_STATUS,LEVEL_NAME,SORT')->groupBy('USER_ID')->indexBy('USER_ID')->all();
-
- // 合并用户ID,去重
- $bonusUsers = array_unique(array_merge(array_keys($userStarDirectorObj), array_keys($userStarCrownObj)));
- sort($bonusUsers);
- // 奖金点数综合
- $bonusPointComplex = 0;
- $insertBonusData = [];
- foreach($bonusUsers as $userId) {
- // 计算奖金:取starDirectorPoint和starCrownPoint的大个值
- $starDirectorPoint = !isset($userStarDirectorObj[$userId]['LEVEL_ID']) ? 0 : ($this->_empLevelConfig[$userStarDirectorObj[$userId]['LEVEL_ID']]['GARAGE_PERCENT'] ?? 0);
- $starCrownPoint = !isset($userStarCrownObj[$userId]['LAST_CROWN_LV']) ? 0: ($this->_starCrownLevelConfig[$userStarCrownObj[$userId]['LAST_CROWN_LV']]['GARAGE_PERCENT'] ?? 0);
- // 奖金比例:
- $bonusPoint = max($starDirectorPoint, $starCrownPoint);
- if ($bonusPoint <= 0) {
- continue;
- }
- // 会员级别达到要求才会发放奖金
- $lastDecLv = $userStarDirectorObj[$userId]['LAST_DEC_LV'] ?? ($userStarCrownObj[$userId]['LAST_DEC_LV'] ?? '');
- if ($lastDecLv != $minDecLevel) {
- continue;
- }
- $insertBonusData[] = [
- 'ID' => SnowFake::instance()->generateId(),
- 'USER_ID' => $userId,
- 'LAST_DEC_LV' => $userStarDirectorObj[$userId]['LAST_DEC_LV'] ?? ($userStarCrownObj[$userId]['LAST_DEC_LV'] ?? ''),
- 'LAST_EMP_LV' => $userStarDirectorObj[$userId]['LEVEL_ID'] ?? '',
- 'LAST_STATUS' => $userStarDirectorObj[$userId]['LAST_STATUS'] ?? ($userStarCrownObj[$userId]['LAST_STATUS'] ?? 1),
- 'LAST_CROWN_LV' => $userStarCrownObj[$userId]['LAST_CROWN_LV'] ?? '',
- 'AMOUNT' => 0,
- 'POINT' => $bonusPoint,
- 'PERIOD_NUM' => $this->_periodNum,
- 'CALC_YEAR' => $this->_calcYear,
- 'CALC_MONTH' => $this->_calcYearMonth,
- 'CREATED_AT' => Date::nowTime(),
- 'PERF' => $monthTotalPV,
- 'TRANSFER_RATE' => $mate,
- 'TRANSFER_AMOUNT' => Tool::formatPrice($transferAmount),
- 'CAP_AMOUNT' => 0,
- 'POINT_COMPLEX' => 0,
- ];
- $bonusPointComplex += $bonusPoint;
- }
- // 数据写入总表
- if ($insertBonusData) {
- foreach ($insertBonusData as &$bonusData) {
- // 计算奖金
- $amount = Tool::formatPrice($transferAmount * ($bonusData['POINT'] / $bonusPointComplex));
- if ($amount <= 0) {
- continue;
- }
- // 封顶前奖金数
- $capAmount = $amount;
- // 奖金数不能大于封顶值
- $amount = ($amount > $capBonus) ? $capBonus : $amount;
- $bonusData['AMOUNT'] = $amount;
- $bonusData['CAP_AMOUNT'] = $capAmount;
- $bonusData['POINT_COMPLEX'] = $bonusPointComplex;
- // 放入缓存
- CalcCache::garageBonus($bonusData['USER_ID'], $this->_periodNum, $amount);
- // 加入月奖的会员
- CalcCache::addHasMonthBonusUsers($bonusData['USER_ID'], $this->_periodNum);
- }
- CalcBonusGarage::batchInsert($insertBonusData);
- }
- 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['openQuarter']['OPTIONS'], true);
- $minDecLevel = $config['declarationLevel'] ?? [];
- 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 ($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
- * @return bool
- * @throws \yii\db\Exception
- */
- public function calcBonusBsGL(int $offset = 0) {
- if( !$this->_isCalcMonth ) {
- // 不是结算月,则不进行计算
- return false;
- }
- // 从缓存获取分页有收入的会员信息
- $allData = CalcBonusBS::findUseDbCalc()
- ->where('PERIOD_NUM=:PERIOD_NUM', [':PERIOD_NUM' => $this->_periodNum])
- ->groupBy('USER_ID')
- ->offset($offset)
- ->limit($this->_limit)
- ->asArray()
- ->all();
- if ($allData) {
- foreach ($allData as $user) {
- // 添加到有奖励信息的数据中
- CalcCache::addHasBonusUsers($user['USER_ID'], $this->_periodNum);
- $fxStatus = $this->_isMonthPerfLimit($user['USER_ID']);
- if ($fxStatus) {
- // //扣除相应的复消积分和管理费
- // $deductData = $this->deduct($user['USER_ID'], $user['ORI_BONUS']);
- // // 把对碰后的奖金存入缓存中
- // CalcCache::bonus($user['USER_ID'], $this->_periodNum, 'BONUS_BS', $user['ORI_BONUS'], $deductData);
- CalcCache::bonus($user['USER_ID'], $this->_periodNum, 'BONUS_BS', $user['ORI_BONUS']);
- // $realBonusBs = $user['ORI_BONUS']; // 扣除管理费和复消积分后的实发蓝星奖金
- // $manageTax = $deductData['manageTax']; // 管理费
- // $point = $deductData['reConsumePoints'];// 复消积分
- // // 更新蓝星奖金存储过程的实发金额数据
- // CalcBonusBS::updateAll(['AMOUNT' => $realBonusBs, 'MANAGE_TAX' => $manageTax, 'RECONSUME_POINTS' => $point],
- // 'USER_ID=:USER_ID AND PERIOD_NUM=:PERIOD_NUM',
- // [':USER_ID' => $user['USER_ID'], ':PERIOD_NUM' => $this->_periodNum]);
- }
- }
- return $this->calcBonusBsGL($offset + $this->_limit);
- }
- unset($allData);
- return true;
- }
- // /**
- // * 蓝星管理奖金
- // * @param int $offset
- // * @return bool
- // * @throws \yii\db\Exception
- // */
- // public function calcBonusBsGL(int $offset = 0) {
- // if( !$this->_isCalcMonth ) {
- // // 不是结算月,则不进行计算
- // return false;
- // }
- // // 从缓存获取分页有收入的会员信息
- // $allData = CalcBonusBS::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_MNT']);
- // $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_BS_MNT', $user['ORI_BONUS_MNT'], $deductData);
- // // 加入月奖的会员
- // CalcCache::addHasMonthBonusUsers($user['USER_ID'], $this->_periodNum);
- // // }
- // // 更新蓝星奖金存储过程的实发金额数据
- // CalcBonusBS::updateAll([
- // 'RECONSUME_POINTS' => $point,
- // 'AMOUNT_MNT' => $realBonusBs,
- // 'MANAGE_TAX_MNT' => $manageTax],
- // 'USER_ID=:USER_ID AND PERIOD_NUM=:PERIOD_NUM',
- // [':USER_ID' => $user['USER_ID'], ':PERIOD_NUM' => $this->_periodNum]);
- // }
- // return $this->calcBonusBsGL($offset + $this->_limit);
- // }
- // unset($allData);
- // return true;
- // }
- // /**
- // * 蓝星业绩奖金
- // * @param int $offset
- // * @return bool
- // * @throws \yii\db\Exception
- // */
- // public function calcBonusBsYJ(int $offset = 0) {
- // if( !$this->_isCalcMonth ) {
- // // 不是结算月,则不进行计算
- // return false;
- // }
- // // 从缓存获取分页有收入的会员信息
- // $allData = CalcBonusBS::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['abbrDec'] ?? [];
- // foreach ($allData as $user) {
- // //扣除相应的复消积分和管理费
- // $deductData = $this->deduct($user['USER_ID'], $user['ORI_BONUS_ABBR']);
- // $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_BS_ABBR', $user['ORI_BONUS_ABBR'], $deductData);
- // // 加入月奖的会员
- // CalcCache::addHasMonthBonusUsers($user['USER_ID'], $this->_periodNum);
- // // }
- // // 更新蓝星业绩奖金存储过程的实发金额数据
- // CalcBonusBS::updateAll([
- // 'AMOUNT_ABBR' => $realBonusBs,
- // 'MANAGE_TAX_ABBR' => $manageTax,
- // 'RECONSUME_POINTS' => $point],
- // 'USER_ID=:USER_ID AND PERIOD_NUM=:PERIOD_NUM',
- // [':USER_ID' => $user['USER_ID'], ':PERIOD_NUM' => $this->_periodNum]);
- // }
- // return $this->calcBonusBsYJ($offset + $this->_limit);
- // }
- // unset($allData);
- // return true;
- // }
- /**
- * 对碰
- * @param array $oriPerfArr
- * @param array $perfArr
- * @param $percent
- * @param $loopTimes
- * @return array
- */
- public function touchPerf(array $oriPerfArr, array $perfArr, $percent, $loopTimes=1) {
- $resultArr = $oriPerfArr;
- foreach ($perfArr as $keyT => $perfT) {
- if ($perfT <= 0) {
- unset($perfArr[$keyT]);
- }
- }
- if (count($perfArr) >= 2 && $loopTimes < 6) {
- arsort($perfArr, SORT_NUMERIC);
- $onePerf = null;
- $oneKey = null;
- // $touchSurplusAmount = 0;
- $touchAmount = 0;
- // 前两个进行对碰
- foreach ($perfArr as $key => $perf) {
- if ($onePerf === null) {
- $oneKey = $key;
- $onePerf = $perf;
- } else {
- $touchSurplusAmount = $perf - $onePerf;
- if ($touchSurplusAmount > 0) {
- unset($perfArr[$oneKey]);
- $resultArr['perfArr'][$oneKey] = 0;
- $perfArr[$key] = $touchSurplusAmount;
- $touchAmount = $onePerf;
- } elseif ($touchSurplusAmount < 0) {
- unset($perfArr[$key]);
- $resultArr['perfArr'][$key] = 0;
- $perfArr[$oneKey] = abs($touchSurplusAmount);
- $touchAmount = $perf;
- } else {
- unset($perfArr[$oneKey], $perfArr[$key]);
- $resultArr['perfArr'][$oneKey] = 0;
- $resultArr['perfArr'][$key] = 0;
- $touchAmount = $perf;
- }
- break;
- }
- }
- $touchBonus = Tool::formatPrice($touchAmount * $percent);
- $resultArr['touchBonus'] += $touchBonus;
- foreach ($perfArr as $keyR => $perfR) {
- $resultArr['perfArr'][$keyR] = $perfR;
- }
- return $this->touchPerf($resultArr, $perfArr, $percent, $loopTimes+1);
- }
- return $resultArr;
- }
- /**
- * 循环父级并执行回调函数
- * @param $userId
- * @param callable $callbackFunc
- * @param int $offset
- * @return bool
- */
- public function loopNetworkParentDo($userId, callable $callbackFunc, int $offset = 0) {
- $allParents = Cache::getAllNetworkParents($userId);
- $allData = array_slice($allParents, $offset, $this->_limit);
- unset($allParents);
- if ($allData) {
- foreach ($allData as $data) {
- $funcResult = $callbackFunc($data);
- if ($funcResult === self::LOOP_FINISH) {
- return true;
- } elseif ($funcResult === self::LOOP_CONTINUE) {
- continue;
- }
- unset($data, $funcResult);
- }
- unset($allData);
- return $this->loopNetworkParentDo($userId, $callbackFunc, $offset + $this->_limit);
- }
- return true;
- }
- /**
- * 循环推荐网络的父级
- * @param $userId
- * @param callable $callbackFunc
- * @param int $offset
- * @return bool
- */
- public function loopRelationParentDo($userId, callable $callbackFunc, int $offset = 0) {
- $allParents = Cache::getAllRelationParents($userId);
- $allData = array_slice($allParents, $offset, $this->_limit);
- unset($allParents);
- if ($allData) {
- foreach ($allData as $data) {
- $funcResult = $callbackFunc($data);
- if ($funcResult === self::LOOP_FINISH) {
- return true;
- } elseif ($funcResult === self::LOOP_CONTINUE) {
- continue;
- }
- unset($data, $funcResult);
- }
- unset($allData);
- return $this->loopRelationParentDo($userId, $callbackFunc, $offset + $this->_limit);
- }
- return true;
- }
- /**
- * 按级别的收入上限
- * 新的需求调整: 改成不按月进行限制,并且去掉vip奖
- * @param $bonus
- * @param $userId
- * @param $declarationLevel
- * @return float
- */
- public function declarationLevelCap($bonus, $userId, $declarationLevel) {
- $decLevelConfig = $this->_decLevelConfig;
- $nowDecLevelConfig = $decLevelConfig[$declarationLevel];
- unset($decLevelConfig);
- $maxGetBonus = $nowDecLevelConfig['INCOME_CAP'];
- if( $bonus <= $maxGetBonus) {
- return $bonus;
- }else {
- return $maxGetBonus;
- }
- }
- /**
- * 扣除复消积分和管理费
- * @param $userId
- * @param $bonus
- * @return array
- * @throws \yii\db\Exception
- */
- public function deduct($userId, $bonus) {
- //判断是否达到了本月扣除复消的上限
- $cacheData = CalcCache::monthLastPeriodReconsumePoints($userId, $this->_periodNum, $this->_calcYearMonth);
- $bonusCache = CalcCache::bonus($userId, $this->_periodNum);
- $reConsumePointsTotal = $bonusCache['RECONSUME_POINTS'] + $cacheData['RECONSUME_POINTS_SUM'];
- $reConsumePointsCap = $this->_sysConfig['reConsumePointsMonthCap']['VALUE'];
- unset($cacheData, $bonusCache);
- $reConsumePoints = 0;
- if( $reConsumePointsTotal < $reConsumePointsCap ) {
- $reConsumePoints = $bonus * $this->_sysConfig['reConsumePointsPercent']['VALUE'] / 100;
- $reConsumePoints = min($reConsumePoints, $reConsumePointsCap-$reConsumePointsTotal);
- }
- unset($reConsumePointsTotal, $reConsumePointsCap);
- $manageTax = $bonus * $this->_sysConfig['manageTaxPercent']['VALUE'] / 100;
- $surplus = $bonus - $reConsumePoints - $manageTax;
- return [
- 'reConsumePoints' => Tool::formatPrice($reConsumePoints),//复效积分
- 'manageTax' => Tool::formatPrice($manageTax),//管理费
- 'surplus' => Tool::formatPrice($surplus),//真实奖金
- ];
- }
- /**
- * 更新百分比并发送
- * @param $percent
- */
- private function _updatePercent($percent) {
- // 把数据写入数据库中
- Period::updateAll(['CALC_PERCENT' => $percent], 'PERIOD_NUM=:PERIOD_NUM', [':PERIOD_NUM' => $this->_periodNum]);
- \Yii::$app->swooleAsyncTimer->pushAsyncPercentToAdmin($percent, ['MODEL' => 'PERIOD', 'ID' => $this->_periodId, 'FIELD' => 'CALC_PERCENT']);
- }
- /**
- * 循环奖服务奖金会员,并入库
- * @param int $offset
- * @return bool
- * @throws \yii\db\Exception
- */
- public function loopBonusUsers($offset = 0) {
- echo sprintf("时间:[%s]缓存奖金数据入库,当前offset为:【%s】" . PHP_EOL, date('Y-m-d H:i:s', time()) , $offset);
- // 从缓存列表里面从底层往上倒序获取会员
- $allData = CalcCache::getHasBonusUsers($this->_periodNum, $offset, $this->_limit);
- if($allData){
- $insertDataBonus = [];
- foreach($allData as $userId){
- $tempBonusData = $this->bonusData($userId);
- if(!empty($tempBonusData['result'])){
- $insertDataBonus[] = $tempBonusData['result'];
- }
- unset($userId, $tempBonusData);
- }
- CalcBonus::batchInsert($insertDataBonus);
- unset($insertDataBonus, $allData);
- return $this->loopBonusUsers($offset + $this->_limit);
- }
- return true;
- }
- /**
- * 奖金
- * @param $userId
- * @return array
- * @throws \yii\db\Exception
- */
- public function bonusData($userId) {
- // 从缓存中获取用户的奖金
- $bonus = CalcCache::bonus($userId, $this->_periodNum);
- $baseInfo = CalcCache::getUserInfo($userId, $this->_periodNum);
- $perfData = CalcCache::nowPeriodPerf($userId, $this->_periodNum);
- $tourismBonus = CalcCache::tourismBonus($userId, $this->_periodNum);
- $garageBonus = CalcCache::garageBonus($userId, $this->_periodNum);
- $villaBonus = CalcCache::villaBonus($userId, $this->_periodNum);
- $pervSurplusPerf = CalcCache::surplusPerf($userId, $this->_periodNum);
- // 星级
- $starCrownLv = CalcCache::getUserStarCrown($userId, $this->_periodNum);
- //没有共享和管理奖
- $bonusReal = $bonus['BONUS_BD'] + $bonus['BONUS_TG'] + $bonus['BONUS_XF'] + $bonus['BONUS_YJ'] +
- $bonus['BONUS_QY'] + $bonus['BONUS_YC'] + $bonus['BONUS_YC_EXTRA'] + $bonus['BONUS_VIP'] +
- $bonus['BONUS_BS_MNT'] + $bonus['BONUS_BS_ABBR'] + $bonus['BONUS_QUARTER'];
- $realBonusGx = 0;
- $realBonusGl = 0;
- $realBonusBs = 0; // 蓝星管理奖. BlueStar
- $blueStartOriBonus = 0;
- $blueStartManageTax = 0;
- $exchangePoints = 0; // 蓝星奖管理奖. 产生的兑换积分
- $realBonusBsMnt = 0; // 蓝星管理奖——实发奖金
- $blueStartOriBonusMnt = 0; // 蓝星管理奖——原奖金
- $blueStartManageTaxMnt = 0; // 蓝星管理奖——管理费
- $realBonusBsAbbr = 0; // 蓝星业绩奖——实发奖金
- $blueStartOriBonusAbbr = 0; // 蓝星业绩奖——原奖金
- $blueStartManageTaxAbbr = 0; // 蓝星业绩奖——管理费
- if( $this->_isCalcMonth ) {
- // 个人月消费PV大于配置值,才会计算发放蓝星奖
- $fxPvStatus = $this->_isMonthPerfLimit($userId);
- // BONUS_REAL 字段是发到用户的真实奖金
- if ( $fxPvStatus ) {
- $userBS = CalcBonusBS::find()
- ->where(
- 'PERIOD_NUM=:PERIOD_NUM AND USER_ID=:USER_ID',
- [
- ':PERIOD_NUM' => $this->_periodNum,
- ':USER_ID' => $userId
- ]
- )
- ->select('AMOUNT,ORI_BONUS,MANAGE_TAX,LEVEL_ID,PRODUCT_POINT,AMOUNT_MNT,ORI_BONUS_MNT,MANAGE_TAX_MNT,AMOUNT_ABBR,ORI_BONUS_ABBR,MANAGE_TAX_ABBR')
- ->limit(1)
- ->orderBy('CREATED_AT DESC')
- ->asArray()
- ->all();
- $userBS = is_array($userBS) ? reset($userBS) : [];
- $blueStartAmount = isset($userBS['AMOUNT']) && !empty($userBS['AMOUNT']) ? $userBS['AMOUNT'] : 0; // 奖金
- $blueStartOriBonus = isset($userBS['ORI_BONUS']) && !empty($userBS['ORI_BONUS']) ? $userBS['ORI_BONUS'] : 0; // 原奖金
- $blueStartManageTax = isset($userBS['MANAGE_TAX']) && !empty($userBS['MANAGE_TAX']) ? $userBS['MANAGE_TAX'] : 0; // 管理费
- $realBonusBsMnt = $userBS['AMOUNT_MNT'] ?? 0; // 蓝星管理奖. 实发奖金
- $blueStartOriBonusMnt = $userBS['ORI_BONUS_MNT'] ?? 0; // 蓝星管理奖. 原奖金
- $blueStartManageTaxMnt = $userBS['MANAGE_TAX_MNT'] ?? 0; // 蓝星管理奖. 管理费
- $realBonusBsAbbr = $userBS['AMOUNT_ABBR'] ?? 0; // 蓝星业绩奖. 奖金
- $blueStartOriBonusAbbr = $userBS['ORI_BONUS_ABBR'] ?? 0; // 蓝星业绩奖. 原奖金
- $blueStartManageTaxAbbr = $userBS['MANAGE_TAX_ABBR'] ?? 0; // 蓝星业绩奖. 管理费
- $blueStartManageTax += $blueStartManageTaxMnt + $blueStartManageTaxAbbr; // 管理费
- $realBonusBs = $blueStartAmount; // 蓝星奖直接取数据库中算好的值PRODUCT_POINT
- $exchangePoints = isset($userBS['PRODUCT_POINT']) && !empty($userBS['PRODUCT_POINT']) ? $userBS['PRODUCT_POINT'] : 0; // 兑换积分
- }
- }
- if( $this->_isCalcMonth ) { //季度奖
- if(in_array($this->_calcMonth, [3,6,9,12])){ // 季度奖
- }
- }
- $result = [
- 'USER_ID' => $userId,
- 'LAST_USER_NAME' => $baseInfo['USER_NAME'],
- 'LAST_REAL_NAME' => $baseInfo['REAL_NAME'],
- 'LAST_DEC_LV' => $baseInfo['DEC_LV'],
- 'LAST_EMP_LV' => $baseInfo['LAST_EMP_LV'],
- 'LAST_CROWN_LV' => $starCrownLv ?? StarCrownLevel::getDefaultLevelId(),
- 'LAST_STATUS' => $baseInfo['STATUS'],
- 'LAST_REC_USER_NAME' => $baseInfo['REC_USER_NAME'],
- 'LAST_REC_REAL_NAME' => $baseInfo['REC_REAL_NAME'],
- 'LAST_CON_USER_NAME' => $baseInfo['CON_USER_NAME'],
- 'LAST_CON_REAL_NAME' => $baseInfo['CON_REAL_NAME'],
- 'EXCHANGE_POINTS' => $exchangePoints, // 兑换积分
- // 'LAST_LOCATION' => $baseInfo['LOCATION'] ? $baseInfo['LOCATION'] : 1,
- //@todo
- 'LAST_LOCATION' => 1,
- 'BONUS_BD' => $bonus['BONUS_BD'],
- 'BONUS_TG' => $bonus['BONUS_TG'],
- 'BONUS_QY' => $bonus['BONUS_QY'],
- 'RECONSUME_POINTS' => $bonus['RECONSUME_POINTS'],
- 'MANAGE_TAX' => $blueStartManageTax, // 管理费
- 'BONUS_INCOME'=>$bonus['INCOME_TOTAL'],
- 'BONUS_REAL'=> $bonusReal,
- 'BONUS_TOTAL'=>$bonus['BONUS_TOTAL'],
- 'ORI_BONUS_BD' => $bonus['ORI_BONUS_BD'],
- 'ORI_BONUS_TG' => $bonus['ORI_BONUS_TG'],
- 'BONUS_BS' => $realBonusBs, // 新的管理奖金,即蓝星管理奖
- 'ORI_BONUS_BS' => $blueStartOriBonus, // 蓝星管理奖金原奖金,即包含管理费
- 'REAL_BONUS_BS' => $realBonusBs, // 实发蓝星管理奖金
- 'BONUS_BS_MNT' => $realBonusBsMnt, // 蓝星管理奖
- 'ORI_BONUS_BS_MNT' => $blueStartOriBonusMnt, // 蓝星管理奖金原奖金,即包含管理费
- 'REAL_BONUS_BS_MNT' => $realBonusBsMnt, // 实发蓝星管理奖金
- 'MANAGE_TAX_MNT' => $blueStartManageTaxMnt, // 实发蓝星管理——管理费
- 'BONUS_BS_ABBR' => $realBonusBsAbbr, // 蓝星业绩奖
- 'ORI_BONUS_BS_ABBR' => $blueStartOriBonusAbbr, // 蓝星业绩奖金原奖金,即包含管理费
- 'REAL_BONUS_BS_ABBR' => $realBonusBsAbbr, // 实发蓝星业绩奖金
- 'MANAGE_TAX_ABBR' => $blueStartManageTaxAbbr, // 实发蓝星业绩奖——管理费
- 'ORI_BONUS_QY' => $bonus['ORI_BONUS_QY'],
- '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, // 房奖
- 'BONUS_GARAGE' => $garageBonus, // 车奖
- //以下没有用
- 'PV_1L' => $perfData['PV_1L_TOUCH'],//TOUCH为碰业绩
- 'QY_1L' => $perfData['PV_1L_TOUCH'] + $pervSurplusPerf['SURPLUS_1L'],
- 'SURPLUS_1L' => $perfData['SURPLUS_1L'],
- 'PV_2L' => $perfData['PV_2L_TOUCH'],
- 'QY_2L' => $perfData['PV_2L_TOUCH'] + $pervSurplusPerf['SURPLUS_2L'],
- 'SURPLUS_2L' => $perfData['SURPLUS_2L'],
- 'PV_3L' => $perfData['PV_3L_TOUCH'],
- 'QY_3L' => $perfData['PV_3L_TOUCH'] + $pervSurplusPerf['SURPLUS_3L'],
- 'SURPLUS_3L' => $perfData['SURPLUS_3L'],
- 'PV_4L' => $perfData['PV_4L_TOUCH'],
- 'QY_4L' => $perfData['PV_4L_TOUCH'] + $pervSurplusPerf['SURPLUS_4L'],
- 'SURPLUS_4L' => $perfData['SURPLUS_4L'],
- 'PV_5L' => $perfData['PV_5L_TOUCH'],
- 'QY_5L' => $perfData['PV_5L_TOUCH'] + $pervSurplusPerf['SURPLUS_5L'],
- 'SURPLUS_5L' => $perfData['SURPLUS_5L'],
- 'PV_PCS' => $perfData['PV_PCS'],
- 'PV_TOUCH' => Tool::formatPrice($perfData['PV_1L_TOUCH'] + $perfData['PV_2L_TOUCH'] + $perfData['PV_3L_TOUCH'] + $perfData['PV_4L_TOUCH'] + $perfData['PV_5L_TOUCH'] + $perfData['PV_LS_TOUCH']),
- 'PERIOD_NUM' => $this->_periodNum,
- 'CALC_YEAR' => $this->_calcYear,
- 'CALC_MONTH' => $this->_calcYearMonth,
- 'CREATED_AT' => Date::nowTime(),
- ];
- $resend = [];
- unset($bonus, $realBonusGx, $realBonusGl, $bonusReal);
- return ['result'=>$result,'resend'=>$resend];
- }
- // 判断是否满足月最低消费
- public function _isMonthPerfLimit($userId) {
- $userMonthTotal = PerfMonth::find()->where(
- 'USER_ID=:USER_ID AND CALC_MONTH=:CALC_MONTH',
- ['USER_ID'=>$userId, 'CALC_MONTH'=>$this->_calcYearMonth]
- )
- ->asArray()
- ->one();
- $fxPvStatus = false;
- if (isset($userMonthTotal['PV_PCS']) && $userMonthTotal['PV_PCS'] >= $this->_sysConfig['monthPcsPvFxCondition']['VALUE']) {
- $fxPvStatus = true;
- }
-
- return $fxPvStatus;
- }
- }
|