| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739 |
- <?php
- /**
- * Created by PhpStorm.
- * User: leo
- * Date: 2018/8/2
- * Time: 上午10:38
- */
- namespace common\helpers\bonus;
- use common\components\Redis;
- use common\helpers\Cache;
- use common\helpers\Date;
- use common\helpers\user\Info;
- use common\models\CalcBonus;
- use common\models\PerfMonth;
- use common\models\PerfPeriod;
- use common\models\Period;
- use common\models\DeclarationLevel;
- use common\models\DecRole;
- use common\models\EmployLevel;
- use common\models\StarCrownLevel;
- use common\models\User;
- use common\models\UserBonus;
- use common\models\UserNetwork;
- use common\models\UserPerf;
- use common\models\UserRelation;
- use Yii;
- use common\models\UserInfo;
- use yii\helpers\Json;
- class CalcCache {
- const LIMIT = 1000;
- const REDIS_KEY_PREFIX_USER = 'calc:user_';
- const REDIS_KEY_PREFIX_USER_ACTIVE = 'calc:userActive_';
- const REDIS_KEY_PREFIX_USER_INFO = 'calc:userInfo_';
- const REDIS_KEY_PREFIX_USER_BONUS = 'calc:userBonus_';
- const REDIS_KEY_PREFIX_PERIOD_MONTH_CALC_BONUS = 'calc:periodMonthCalcBonus_';
- const REDIS_KEY_PREFIX_USER_PERF = 'calc:userPerf_';
- const REDIS_KEY_PREFIX_SURPLUS_PERF = 'calc:spPerf_';
- const REDIS_KEY_PREFIX_NOW_PERIOD_PERF = 'calc:nowPeriodPerf_';
- const REDIS_KEY_PREFIX_NOW_STANDARD_MONTH_PERF = 'calc:nowStandardMonthPerf_';
- const REDIS_KEY_PREFIX_LAST_MONTH_PERF = 'calc:lastMonthPerf_';
- const REDIS_KEY_PREFIX_NOW_MONTH_PERF = 'calc:nowMonthPerf_';
- const REDIS_KEY_PREFIX_NOW_MONTH_SCORE = 'calc:nowMonthScore_';
- const REDIS_KEY_PREFIX_NOW_MONTH_LAST_PERIOD_RECONSUME_POINTS = 'calc:nowMonthLastPeriodReconsumePoints_';
- const REDIS_KEY_PREFIX_EMP_NUM_PERF = 'calc:empLevelNum_';
- const REDIS_KEY_PREFIX_BONUS = 'calc:bonus_';
- const REDIS_KEY_PREFIX_STANDARD_BONUS = 'calc:standard:bonus_';
- const REDIS_KEY_PREFIX_YC_BONUS = 'calc:yc:bonus_';
- const REDIS_KEY_PREFIX_FW_BONUS = 'calc:fw:bonus_';
- const REDIS_KEY_PREFIX_TOURISM_BONUS = 'calc:tourism:bonus_';
- const REDIS_KEY_PREFIX_VILLA_BONUS = 'calc:villa:bonus_';
- const REDIS_KEY_PREFIX_GARAGE_BONUS = 'calc:garage:bonus_';
- const REDIS_KEY_PREFIX_HAS_PERF_USER = 'calc:hasPerfUser_';
- const REDIS_KEY_PREFIX_HAS_MONTH_PERF_USER = 'calc:hasMonthPerfUser_';
- const REDIS_KEY_PREFIX_HAS_STANDARD_MONTH_PERF_USER = 'calc:hasStandardMonthPerfUser_';
- const REDIS_KEY_PREFIX_HAS_BD_USER = 'calc:hasBDUser_';
- const REDIS_KEY_PREFIX_HAS_INCOME_USER = 'calc:hasIncomeUser_';
- const REDIS_KEY_PREFIX_HAS_BONUS_USER = 'calc:hasBonusUser_';
- const REDIS_KEY_PREFIX_HAS_YC_BONUS_USER = 'calc:hasYcBonusUser_';
- const REDIS_KEY_PREFIX_HAS_FW_BONUS_USER = 'calc:hasFwBonusUser_';
- const REDIS_KEY_PREFIX_HAS_MONTH_BONUS_USER = 'calc:hasMonthBonusUser_';
- const REDIS_KEY_PREFIX_HAS_PERF_USER_POOL = 'calc:hasPerfUserPool_';
- const REDIS_KEY_PREFIX_HAS_MONTH_PERF_USER_POOL = 'calc:hasMonthPerfUserPool_';
- const REDIS_KEY_PREFIX_HAS_STANDARD_MONTH_PERF_USER_POOL = 'calc:hasStandardMonthPerfUserPool_';
- const REDIS_KEY_PREFIX_HAS_BD_USER_POOL = 'calc:hasBDUserPool_';
- const REDIS_KEY_PREFIX_HAS_INCOME_USER_POOL = 'calc:hasIncomeUserPool_';
- const REDIS_KEY_PREFIX_HAS_BONUS_USER_POOL = 'calc:hasBonusUserPool_';
- const REDIS_KEY_PREFIX_HAS_YC_BONUS_USER_POOL = 'calc:hasYcBonusUserPool_';
- const REDIS_KEY_PREFIX_HAS_FW_BONUS_USER_POOL = 'calc:hasFwBonusUserPool_';
- const REDIS_KEY_PREFIX_HAS_MONTH_BONUS_USER_POOL = 'calc:hasMonthBonusUserPool_';
- const REDIS_KEY_PREFIX_HAS_SCORE_USER = 'calc:hasScoreUser_';
- const REDIS_KEY_PREFIX_HAS_SCORE_USER_POOL = 'calc:hasScoreUserPool_';
- const REDIS_KEY_PREFIX_HAS_LS_PCS_USER = 'calc:hasLSPCSUser_';
- const REDIS_KEY_PREFIX_HAS_LS_PCS_USER_POOL = 'calc:hasLSPCSUserPool_';
- const REDIS_KEY_PREFIX_HAS_CF_PERCENT_USER = 'calc:hasCFPercentPCSUser_';
- const REDIS_KEY_PREFIX_HAS_CF_PERCENT_USER_POOL = 'calc:hasCFPercentPCSUserPool_';
- const REDIS_KEY_PREFIX_HAS_LX_PERCENT_USER = 'calc:hasLXPercentPCSUser_';
- const REDIS_KEY_PREFIX_HAS_LX_PERCENT_USER_POOL = 'calc:hasLXPercentPCSUserPool_';
- const REDIS_KEY_PREFIX_DEC_ROLE_CONFIG = 'calc:decRoleConfig_';
- const REDIS_KEY_PREFIX_CF_TOTAL_PERCENT = 'calc:cfTotalPercent_';
- const REDIS_KEY_PREFIX_LX_TOTAL_PERCENT = 'calc:lxTotalPercent_';
- const REDIS_KEY_PREFIX_USER_INFO_CHILD_ONE_DEEP = 'calc:userInfo:ChildOneDeep_';
- const REDIS_KEY_PREFIX_GX_BONUS_DEEP_ONE_LIST_DATA = 'calc:gxBonusDeepOneListData_';
- const REDIS_KEY_PREFIX_GX_BONUS_DEEP_TWO_LIST_DATA = 'calc:gxBonusDeepTwoListData_';
- const REDIS_KEY_PREFIX_YC_BONUS_LIST_DATA = 'calc:ycBonusListData_';
- const REDIS_KEY_PREFIX_FW_BONUS_LIST_DATA = 'calc:fwBonusListData_';
- const REDIS_KEY_PREFIX_BONUS_STAR_CROWN_LIST_DATA = 'calc:bonusStarCrownListData_';
- //@todo
- const REDIS_KEY_PREFIX_REPAIR_SURPLUS_PERF = 'calc:repairSurplusPerf_';
- const REDIS_KEY_PREFIX_HAS_REPAIR_PERF_USER = 'calc:hasRepairPerfUser_';
- const REDIS_KEY_PREFIX_HAS_REPAIR_PERF_USER_POOL = 'calc:hasRepairPerfPool_';
- //收入的奖金类型
- // const INCOME_TG_BONUS = 'BONUS_TG';
- // const INCOME_XF_BONUS = 'BONUS_XF';
- // const INCOME_YJ_BONUS = 'BONUS_YJ';
- // const INCOME_QY_BONUS = 'BONUS_QY';
- const INCOME_QY_BONUS_BD = 'BONUS_QY_BD';
- const INCOME_QY_BONUS_FX = 'BONUS_QY_FX';
- const INCOME_BONUS_TRAVEL = 'BONUS_TRAVEL';
- const INCOME_BONUS_CAR = 'BONUS_CAR';
- const INCOME_BONUS_HOUSE = 'BONUS_HOUSE';
- const CAPPED_BONUS_QY = 'CAPPED_BONUS_QY'; // 团队奖封顶前的金额
- const INCOME_BONUS_LIST = [
- // self::INCOME_TG_BONUS,
- // self::INCOME_XF_BONUS,
- // self::INCOME_YJ_BONUS,
- // self::INCOME_QY_BONUS,
- self::INCOME_QY_BONUS_BD,
- // self::INCOME_QY_BONUS_FX,
- ];
- const NOT_SEND_BONUS_LIST = [
- self::INCOME_QY_BONUS_BD,
- self::INCOME_QY_BONUS_FX,
- self::INCOME_BONUS_TRAVEL,
- self::INCOME_BONUS_CAR,
- self::INCOME_BONUS_HOUSE,
- self::CAPPED_BONUS_QY,
- ];
- const FROM_MEANS_BD = 'BD';
- const FROM_MEANS_FX = 'FX';
- /**
- * 结算奖金时要清空的缓存
- * @param $periodNum
- */
- public static function clearCalcBonusCache($periodNum) {
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_BONUS . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_HAS_BONUS_USER . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_HAS_BONUS_USER_POOL . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_STANDARD_BONUS . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_YC_BONUS . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_HAS_YC_BONUS_USER . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_HAS_YC_BONUS_USER_POOL . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_GX_BONUS_DEEP_ONE_LIST_DATA . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_GX_BONUS_DEEP_TWO_LIST_DATA . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_YC_BONUS_LIST_DATA . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_FW_BONUS . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_HAS_FW_BONUS_USER . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_HAS_FW_BONUS_USER_POOL . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_HAS_MONTH_BONUS_USER . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_HAS_MONTH_BONUS_USER_POOL . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_FW_BONUS_LIST_DATA . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_BONUS_STAR_CROWN_LIST_DATA . $periodNum);
- }
- /**
- * 清网络缓存
- */
- public static function clearNetCache(){
- \Yii::$app->redis->del(Cache::USER_NETWORK_PARENTS);
- \Yii::$app->redis->del(Cache::USER_RELATION_PARENTS);
- }
- /**
- * 清空所有临时计算用到的缓存
- * @param $periodNum
- */
- public static function clearAll($periodNum) {
- //Yii::$app->redis->del(Yii::$app->redis->keys('calc*'));
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_USER . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_USER_ACTIVE . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_USER_INFO . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_USER_BONUS . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_PERIOD_MONTH_CALC_BONUS . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_SURPLUS_PERF . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_USER_PERF . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_NOW_PERIOD_PERF . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_NOW_STANDARD_MONTH_PERF . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_LAST_MONTH_PERF . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_NOW_MONTH_PERF . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_NOW_MONTH_SCORE . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_NOW_MONTH_LAST_PERIOD_RECONSUME_POINTS . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_EMP_NUM_PERF . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_BONUS . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_STANDARD_BONUS . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_YC_BONUS . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_FW_BONUS . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_HAS_PERF_USER . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_HAS_PERF_USER_POOL . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_HAS_MONTH_PERF_USER . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_HAS_MONTH_PERF_USER_POOL . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_HAS_STANDARD_MONTH_PERF_USER . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_HAS_STANDARD_MONTH_PERF_USER_POOL . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_HAS_BD_USER . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_HAS_BD_USER_POOL . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_HAS_INCOME_USER . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_HAS_INCOME_USER_POOL . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_HAS_BONUS_USER . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_HAS_BONUS_USER_POOL . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_HAS_YC_BONUS_USER . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_HAS_YC_BONUS_USER_POOL . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_HAS_FW_BONUS_USER . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_HAS_FW_BONUS_USER_POOL . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_HAS_MONTH_BONUS_USER . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_HAS_MONTH_BONUS_USER_POOL . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_HAS_SCORE_USER . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_HAS_SCORE_USER_POOL . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_HAS_LS_PCS_USER . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_HAS_LS_PCS_USER_POOL . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_HAS_CF_PERCENT_USER . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_HAS_CF_PERCENT_USER_POOL . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_HAS_LX_PERCENT_USER . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_HAS_LX_PERCENT_USER_POOL . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_DEC_ROLE_CONFIG . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_USER_INFO_CHILD_ONE_DEEP . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_GX_BONUS_DEEP_ONE_LIST_DATA . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_GX_BONUS_DEEP_TWO_LIST_DATA . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_YC_BONUS_LIST_DATA . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_FW_BONUS_LIST_DATA . $periodNum);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_BONUS_STAR_CROWN_LIST_DATA . $periodNum);
- }
- /**
- * 会员信息加入缓存
- * @param $periodNum
- * @param int $offset
- * @param int $limit
- * @return bool
- */
- public static function addUsers($periodNum, $offset = 0, $limit = self::LIMIT) {
- // echo sprintf("时间:[%s]缓存用户,当前offset为:【%s】" . PHP_EOL, date('Y-m-d H:i:s', time()) , $offset);
- // 修复USER_INFO表里面已经没有PERIOD_NUM了
- $allData = UserInfo::findUseDbCalc()->from(UserInfo::tableName(). 'AS UI')->select('UI.USER_ID,U.STATUS')->leftJoin(User::tableName() . 'AS U', 'U.ID=UI.USER_ID')->where('1=1')->orderBy('UI.RELATION_DEEP DESC,UI.ID DESC')->offset($offset)->limit($limit)->asArray()->all();
- //$allData = User::findUseDbShopCalc()->select('ID AS USER_ID')->where('PERIOD_AT<=:PERIOD_AT AND IS_UNION=0 AND DELETED=0', [':PERIOD_AT' => $periodNum])->offset($offset)->limit($limit)->asArray()->all();
- if ($allData) {
- foreach ($allData as $data) {
- // if(User::find()->where('ID=:ID',[':ID'=>$data['USER_ID']])->exists()) continue;
- // 会员ID加入缓存
- $cacheKey = self::REDIS_KEY_PREFIX_USER . $periodNum;
- $value = $data['USER_ID'];
- Yii::$app->redis->rpush($cacheKey, $value);
- if( $data['STATUS'] == 1 ) {
- $activeCacheKey = self::REDIS_KEY_PREFIX_USER_ACTIVE . $periodNum;
- Yii::$app->redis->rpush($activeCacheKey, $value);
- unset($activeCacheKey);
- }
- unset($data, $cacheKey, $value);
- }
- unset($allData);
- return self::addUsers($periodNum, $offset + $limit, $limit);
- }
- unset($allData);
- return true;
- }
- /**
- * 获取会员从缓存中
- * @param $periodNum
- * @param int $offset
- * @param int $limit
- * @return mixed
- */
- public static function getUsers($periodNum, $offset = 0, $limit = self::LIMIT) {
- return Yii::$app->redis->lrange(self::REDIS_KEY_PREFIX_USER . $periodNum, $offset, ($offset + $limit - 1));
- }
- /**
- * 获取激活会员从缓存中
- * @param $periodNum
- * @param int $offset
- * @param int $limit
- * @return mixed
- */
- public static function getActiveUsers($periodNum, $offset = 0, $limit = self::LIMIT) {
- return Yii::$app->redis->lrange(self::REDIS_KEY_PREFIX_USER_ACTIVE . $periodNum, $offset, ($offset + $limit - 1));
- }
- /**
- * 加入有业绩的会员
- * @param $userId
- * @param $periodNum
- */
- public static function addHasPerfUsers($userId, $periodNum) {
- // 先从已存在的会员池里面获取
- $isset = Yii::$app->redis->hget(self::REDIS_KEY_PREFIX_HAS_PERF_USER_POOL . $periodNum, $userId);
- if (!$isset) {
- Yii::$app->redis->hset(self::REDIS_KEY_PREFIX_HAS_PERF_USER_POOL . $periodNum, $userId, 1);
- Yii::$app->redis->rpush(self::REDIS_KEY_PREFIX_HAS_PERF_USER . $periodNum, $userId);
- }
- unset($userId, $periodNum, $isset);
- }
- /**
- * 获取有业绩的会员
- * @param $periodNum
- * @param int $offset
- * @param int $limit
- * @return mixed
- */
- public static function getHasPerfUsers($periodNum, $offset = 0, $limit = self::LIMIT) {
- return Yii::$app->redis->lrange(self::REDIS_KEY_PREFIX_HAS_PERF_USER . $periodNum, $offset, ($offset + $limit - 1));
- }
- /**
- * 加入有月业绩的会员
- * @param $userId
- * @param $periodNum
- */
- public static function addHasMonthPerfUsers($userId, $periodNum) {
- // 先从已存在的会员池里面获取
- $isset = Yii::$app->redis->hget(self::REDIS_KEY_PREFIX_HAS_MONTH_PERF_USER_POOL . $periodNum, $userId);
- if (!$isset) {
- Yii::$app->redis->hset(self::REDIS_KEY_PREFIX_HAS_MONTH_PERF_USER_POOL . $periodNum, $userId, 1);
- Yii::$app->redis->rpush(self::REDIS_KEY_PREFIX_HAS_MONTH_PERF_USER . $periodNum, $userId);
- }
- unset($userId, $periodNum, $isset);
- }
- /**
- * 获取有业绩的会员
- * @param $periodNum
- * @param int $offset
- * @param int $limit
- * @return mixed
- */
- public static function getHasMonthPerfUsers($periodNum, $offset = 0, $limit = self::LIMIT) {
- return Yii::$app->redis->lrange(self::REDIS_KEY_PREFIX_HAS_MONTH_PERF_USER . $periodNum, $offset, ($offset + $limit - 1));
- }
- /**
- * 加入有达标业绩的会员
- * @param $userId
- * @param $periodNum
- */
- public static function addHasStandardMonthPerfUsers($userId, $periodNum) {
- // 先从已存在的会员池里面获取
- $isset = Yii::$app->redis->hget(self::REDIS_KEY_PREFIX_HAS_STANDARD_MONTH_PERF_USER_POOL . $periodNum, $userId);
- if (!$isset) {
- Yii::$app->redis->hset(self::REDIS_KEY_PREFIX_HAS_STANDARD_MONTH_PERF_USER_POOL . $periodNum, $userId, 1);
- Yii::$app->redis->rpush(self::REDIS_KEY_PREFIX_HAS_STANDARD_MONTH_PERF_USER . $periodNum, $userId);
- }
- unset($userId, $periodNum, $isset);
- }
- /**
- * 获取有达标业绩的会员
- * @param $periodNum
- * @param int $offset
- * @param int $limit
- * @return mixed
- */
- public static function getHasStandardMonthPerfUsers($periodNum, $offset = 0, $limit = self::LIMIT) {
- return Yii::$app->redis->lrange(self::REDIS_KEY_PREFIX_HAS_STANDARD_MONTH_PERF_USER . $periodNum, $offset, ($offset + $limit - 1));
- }
- /**
- * 加入被报单的会员
- * @param $userId
- * @param $periodNum
- * @param $saveData
- */
- public static function addHasBDUsers($userId, $periodNum, $saveData) {
- // 先从已存在的会员池里面获取
- $data = Yii::$app->redis->hget(self::REDIS_KEY_PREFIX_HAS_BD_USER_POOL . $periodNum, $userId);
- if (!$data) {
- Yii::$app->redis->hset(self::REDIS_KEY_PREFIX_HAS_BD_USER_POOL . $periodNum, $userId, Json::encode($saveData));
- Yii::$app->redis->rpush(self::REDIS_KEY_PREFIX_HAS_BD_USER . $periodNum, $userId);
- }
- unset($userId, $periodNum, $saveData, $isset);
- }
- /**
- * 获取被报单的会员信息
- * @param $userId
- * @param $periodNum
- * @return array
- */
- public static function getBDUsersInfo($userId, $periodNum) {
- $data = Yii::$app->redis->hget(self::REDIS_KEY_PREFIX_HAS_BD_USER_POOL . $periodNum, $userId);
- if( !$data ) return [];
- return Json::decode($data, true);
- }
- /**
- * 获取被报单的会员
- * @param $periodNum
- * @param int $offset
- * @param int $limit
- * @return mixed
- */
- public static function getHasBDUsers($periodNum, $offset = 0, $limit = self::LIMIT) {
- return Yii::$app->redis->lrange(self::REDIS_KEY_PREFIX_HAS_BD_USER . $periodNum, $offset, ($offset + $limit - 1));
- }
- /**
- * 加入有收入的会员
- * @param $userId
- * @param $periodNum
- */
- public static function addHasIncomeUsers($userId, $periodNum) {
- // 先从已存在的会员池里面获取
- $isset = Yii::$app->redis->hget(self::REDIS_KEY_PREFIX_HAS_INCOME_USER_POOL . $periodNum, $userId);
- if (!$isset) {
- Yii::$app->redis->hset(self::REDIS_KEY_PREFIX_HAS_INCOME_USER_POOL . $periodNum, $userId, 1);
- Yii::$app->redis->rpush(self::REDIS_KEY_PREFIX_HAS_INCOME_USER . $periodNum, $userId);
- }
- unset($userId, $periodNum, $isset);
- }
- /**
- * 获取有收入的会员
- * @param $periodNum
- * @param int $offset
- * @param int $limit
- * @return mixed
- */
- public static function getHasIncomeUsers($periodNum, $offset = 0, $limit = self::LIMIT) {
- return Yii::$app->redis->lrange(self::REDIS_KEY_PREFIX_HAS_INCOME_USER . $periodNum, $offset, ($offset + $limit - 1));
- }
- /**
- * 加入有奖金的会员
- * @param $userId
- * @param $periodNum
- */
- public static function addHasBonusUsers($userId, $periodNum) {
- // 先从已存在的会员池里面获取
- $isset = Yii::$app->redis->hget(self::REDIS_KEY_PREFIX_HAS_BONUS_USER_POOL . $periodNum, $userId);
- if (!$isset) {
- Yii::$app->redis->hset(self::REDIS_KEY_PREFIX_HAS_BONUS_USER_POOL . $periodNum, $userId, 1);
- Yii::$app->redis->rpush(self::REDIS_KEY_PREFIX_HAS_BONUS_USER . $periodNum, $userId);
- }
- unset($userId, $periodNum, $isset);
- }
- /**
- * 获取有奖金的会员
- * @param $periodNum
- * @param int $offset
- * @param int $limit
- * @return mixed
- */
- public static function getHasBonusUsers($periodNum, $offset = 0, $limit = self::LIMIT) {
- return Yii::$app->redis->lrange(self::REDIS_KEY_PREFIX_HAS_BONUS_USER . $periodNum, $offset, ($offset + $limit - 1));
- }
- /**
- * 加入荣衔奖的会员
- * @param $userId
- * @param $periodNum
- */
- public static function addHasYcBonusUsers($userId, $periodNum) {
- // 先从已存在的会员池里面获取
- $isset = Yii::$app->redis->hget(self::REDIS_KEY_PREFIX_HAS_YC_BONUS_USER_POOL . $periodNum, $userId);
- if (!$isset) {
- Yii::$app->redis->hset(self::REDIS_KEY_PREFIX_HAS_YC_BONUS_USER_POOL . $periodNum, $userId, 1);
- Yii::$app->redis->rpush(self::REDIS_KEY_PREFIX_HAS_YC_BONUS_USER . $periodNum, $userId);
- }
- unset($userId, $periodNum, $isset);
- }
- /**
- * 保存荣衔奖奖金
- * @param $userId
- * @param $periodNum
- * @param $empBonus
- * @param array $fromData
- */
- public static function saveYCBonusList($userId, $periodNum, $empBonus, $fromData=[]) {
- $userYcBonusData = Yii::$app->redis->hget(self::REDIS_KEY_PREFIX_YC_BONUS_LIST_DATA . $periodNum, $userId);
- if( $userYcBonusData ) {
- $ycBonusData = Json::decode($userYcBonusData, true);
- $ycBonusData['empBonus'] += $empBonus;
- // $ycBonusData['fromData'][] = $fromData;
- }else {
- $ycBonusData = [
- 'empBonus' => $empBonus,
- // 'fromData' => [
- // $fromData
- // ]
- ];
- }
- unset($userYcBonusData);
- Yii::$app->redis->hset(self::REDIS_KEY_PREFIX_YC_BONUS_LIST_DATA . $periodNum, $userId, Json::encode($ycBonusData));
- unset($ycBonusData, $userId, $periodNum, $empBonus, $fromData);
- }
- /**
- * 返回荣衔奖信息
- * @param $userId
- * @param $periodNum
- * @return array
- */
- public static function getYCBonusList($userId, $periodNum) {
- $userYcBonusData = Yii::$app->redis->hget(self::REDIS_KEY_PREFIX_YC_BONUS_LIST_DATA . $periodNum, $userId);
- return $userYcBonusData ? Json::decode($userYcBonusData, true) : [];
- }
- /**
- * 获取有荣衔奖的会员
- * @param $periodNum
- * @param int $offset
- * @param int $limit
- * @return mixed
- */
- public static function getHasYcBonusUsers($periodNum, $offset = 0, $limit = self::LIMIT) {
- return Yii::$app->redis->lrange(self::REDIS_KEY_PREFIX_HAS_YC_BONUS_USER . $periodNum, $offset, ($offset + $limit - 1));
- }
- /**
- * 获取有服务奖的会员
- * @param $periodNum
- * @param int $offset
- * @param int $limit
- * @return mixed
- */
- public static function getHasFwBonusUsers($periodNum, $offset = 0, $limit = self::LIMIT) {
- return Yii::$app->redis->lrange(self::REDIS_KEY_PREFIX_HAS_FW_BONUS_USER . $periodNum, $offset, ($offset + $limit - 1));
- }
- /**
- * 加入服务奖的会员
- * @param $userId
- * @param $periodNum
- */
- public static function addHasFwBonusUsers($userId, $periodNum) {
- // 先从已存在的会员池里面获取
- $isset = Yii::$app->redis->hget(self::REDIS_KEY_PREFIX_HAS_FW_BONUS_USER_POOL . $periodNum, $userId);
- if (!$isset) {
- Yii::$app->redis->hset(self::REDIS_KEY_PREFIX_HAS_FW_BONUS_USER_POOL . $periodNum, $userId, 1);
- Yii::$app->redis->rpush(self::REDIS_KEY_PREFIX_HAS_FW_BONUS_USER . $periodNum, $userId);
- }
- unset($userId, $periodNum, $isset);
- }
- /**
- * 获取有月奖的会员
- * @param $periodNum
- * @param int $offset
- * @param int $limit
- * @return mixed
- */
- public static function getHasMonthBonusUsers($periodNum, $offset = 0, $limit = self::LIMIT) {
- return Yii::$app->redis->lrange(self::REDIS_KEY_PREFIX_HAS_MONTH_BONUS_USER . $periodNum, $offset, ($offset + $limit - 1));
- }
- /**
- * 加入月奖的会员
- * @param $userId
- * @param $periodNum
- */
- public static function addHasMonthBonusUsers($userId, $periodNum) {
- // 先从已存在的会员池里面获取
- $isset = Yii::$app->redis->hget(self::REDIS_KEY_PREFIX_HAS_MONTH_BONUS_USER_POOL . $periodNum, $userId);
- if (!$isset) {
- Yii::$app->redis->hset(self::REDIS_KEY_PREFIX_HAS_MONTH_BONUS_USER_POOL . $periodNum, $userId, 1);
- Yii::$app->redis->rpush(self::REDIS_KEY_PREFIX_HAS_MONTH_BONUS_USER . $periodNum, $userId);
- }
- unset($userId, $periodNum, $isset);
- }
- /**
- * 保存荣衔奖奖金
- * @param $userId
- * @param $periodNum
- * @param $fwBonus
- * @param array $fromData
- */
- public static function saveFwBonusList($userId, $periodNum, $fwBonus, $fromData=[]) {
- $userFwBonusData = Yii::$app->redis->hget(self::REDIS_KEY_PREFIX_FW_BONUS_LIST_DATA . $periodNum, $userId);
- if( $userFwBonusData ) {
- $fwBonusData = Json::decode($userFwBonusData, true);
- $fwBonusData['fwBonus'] += $fwBonus;
- // $ycBonusData['fromData'][] = $fromData;
- }else {
- $fwBonusData = [
- 'fwBonus' => $fwBonus,
- // 'fromData' => [
- // $fromData
- // ]
- ];
- }
- unset($userFwBonusData);
- Yii::$app->redis->hset(self::REDIS_KEY_PREFIX_FW_BONUS_LIST_DATA . $periodNum, $userId, Json::encode($fwBonusData));
- unset($fwBonusData, $userId, $periodNum, $empBonus, $fromData);
- }
- /**
- * 返回服务奖信息
- * @param $userId
- * @param $periodNum
- * @return array
- */
- public static function getFwBonusList($userId, $periodNum) {
- $userYcBonusData = Yii::$app->redis->hget(self::REDIS_KEY_PREFIX_FW_BONUS_LIST_DATA . $periodNum, $userId);
- return $userYcBonusData ? Json::decode($userYcBonusData, true) : [];
- }
- /**
- * 会员星级加入缓存
- * @param $userId
- * @param $periodNum
- * @param $starCrown
- */
- public static function addUserStartCrown($userId, $periodNum, $starCrown) {
- // 先从已存在的会员池里面获取
- $data = Yii::$app->redis->hget(self::REDIS_KEY_PREFIX_BONUS_STAR_CROWN_LIST_DATA . $periodNum, $userId);
- if (!$data) {
- Yii::$app->redis->hset(self::REDIS_KEY_PREFIX_BONUS_STAR_CROWN_LIST_DATA . $periodNum, $userId, $starCrown);
- }
- unset($userId, $periodNum, $saveData, $isset);
- }
- /**
- * 获取会员星级信息
- * @param $userId
- * @param $periodNum
- * @return array
- */
- public static function getUserStartCrown($userId, $periodNum) {
- return Yii::$app->redis->hget(self::REDIS_KEY_PREFIX_BONUS_STAR_CROWN_LIST_DATA . $periodNum, $userId);
- }
- /**
- * 加入有复销业绩的会员列表
- * @param $userId
- * @param $periodNum
- */
- public static function addHasScoreUsers($userId, $periodNum) {
- $isset = Yii::$app->redis->hget(self::REDIS_KEY_PREFIX_HAS_SCORE_USER_POOL . $periodNum, $userId);
- if (!$isset) {
- Yii::$app->redis->hset(self::REDIS_KEY_PREFIX_HAS_SCORE_USER_POOL . $periodNum, $userId, 1);
- $key = self::REDIS_KEY_PREFIX_HAS_SCORE_USER . $periodNum;
- Yii::$app->redis->rpush($key, $userId);
- }
- }
- /**
- * 获取有复销业绩的会员列表
- * @param $periodNum
- * @param int $offset
- * @param int $limit
- * @return mixed
- */
- public static function getHasScoreUsers($periodNum, $offset = 0, $limit = self::LIMIT) {
- return Yii::$app->redis->lrange(self::REDIS_KEY_PREFIX_HAS_SCORE_USER . $periodNum, $offset, ($offset + $limit - 1));
- }
- /**
- * 加入有零售个人消费的会员列表
- * @param $userId
- * @param $periodNum
- */
- public static function addHasLSPCSUsers($userId, $periodNum) {
- $isset = Yii::$app->redis->hget(self::REDIS_KEY_PREFIX_HAS_LS_PCS_USER_POOL . $periodNum, $userId);
- if (!$isset) {
- Yii::$app->redis->hset(self::REDIS_KEY_PREFIX_HAS_LS_PCS_USER_POOL . $periodNum, $userId, 1);
- $key = self::REDIS_KEY_PREFIX_HAS_LS_PCS_USER . $periodNum;
- $value = $userId;
- Yii::$app->redis->rpush($key, $value);
- }
- }
- /**
- * 加入有零售消费的会员列表
- * @param $periodNum
- * @param int $offset
- * @param int $limit
- * @return mixed
- */
- public static function getHasLSPCSUsers($periodNum, $offset = 0, $limit = self::LIMIT) {
- return Yii::$app->redis->lrange(self::REDIS_KEY_PREFIX_HAS_LS_PCS_USER . $periodNum, $offset, ($offset + $limit - 1));
- }
- /**
- * 有车房补贴比例的人
- * @param $userId
- * @param $periodNum
- */
- public static function addHasCFPercentUsers($userId, $periodNum) {
- $isset = Yii::$app->redis->hget(self::REDIS_KEY_PREFIX_HAS_CF_PERCENT_USER_POOL . $periodNum, $userId);
- if (!$isset) {
- Yii::$app->redis->hset(self::REDIS_KEY_PREFIX_HAS_CF_PERCENT_USER_POOL . $periodNum, $userId, 1);
- $key = self::REDIS_KEY_PREFIX_HAS_CF_PERCENT_USER . $periodNum;
- $value = $userId;
- Yii::$app->redis->rpush($key, $value);
- }
- }
- /**
- * 获取有车房补贴的人
- * @param $periodNum
- * @param int $offset
- * @param int $limit
- * @return mixed
- */
- public static function getHasCFPercentUsers($periodNum, $offset = 0, $limit = self::LIMIT) {
- return Yii::$app->redis->lrange(self::REDIS_KEY_PREFIX_HAS_CF_PERCENT_USER . $periodNum, $offset, ($offset + $limit - 1));
- }
- /**
- * 有领袖分红的人
- * @param $userId
- * @param $periodNum
- */
- public static function addHasLXPercentUsers($userId, $periodNum) {
- $isset = Yii::$app->redis->hget(self::REDIS_KEY_PREFIX_HAS_LX_PERCENT_USER_POOL . $periodNum, $userId);
- if (!$isset) {
- Yii::$app->redis->hset(self::REDIS_KEY_PREFIX_HAS_LX_PERCENT_USER_POOL . $periodNum, $userId, 1);
- $key = self::REDIS_KEY_PREFIX_HAS_LX_PERCENT_USER . $periodNum;
- $value = $userId;
- Yii::$app->redis->rpush($key, $value);
- }
- }
- /**
- * 获取有领袖分红的人
- * @param $periodNum
- * @param int $offset
- * @param int $limit
- * @return mixed
- */
- public static function getHasLXPercentUsers($periodNum, $offset = 0, $limit = self::LIMIT) {
- return Yii::$app->redis->lrange(self::REDIS_KEY_PREFIX_HAS_LX_PERCENT_USER . $periodNum, $offset, ($offset + $limit - 1));
- }
- /**
- * 通过创建时间获取指定长度的用户列表
- * @param $userId
- * @param $limit
- * @return array|\yii\db\ActiveRecord[]
- */
- public static function getUserListByCreatedAtFromDb($userId, $limit)
- {
- //查找这个人的CREATED_AT
- $user = User::findUseDbCalc()->select('ID,CREATED_AT')->where('ID=:ID', ['ID'=>$userId])->asArray()->one();
- if( !$user ) return [];
- return User::findUseDbCalc()->select('ID,CREATED_AT')->where('ID<:ID AND CREATED_AT<=:CREATED_AT', [
- 'ID'=>$userId,
- 'CREATED_AT' => $user['CREATED_AT']
- ])->orderBy('CREATED_AT DESC,ID DESC')->limit($limit)->asArray()->all();
- }
- /**
- * 通过创建时间获取指定长度的用户列表
- * @param $userId
- * @param $limit
- * @return array|\yii\db\ActiveRecord[]
- */
- public static function getAfterUserListByCreatedAtFromDb($userId, $limit)
- {
- $cacheKey = Cache::USER_CREATED_AT_LIST . $limit;
- $value = Yii::$app->redis->hGet($cacheKey, $userId);
- if( $value ) {
- unset($cacheKey);
- return json_decode($value, true);
- }
- unset($value);
- $list = UserInfo::findUseDbCalc()->select('USER_ID')->where('USER_ID>:USER_ID', [
- 'USER_ID'=>$userId,
- ])->orderBy('USER_ID ASC')->limit($limit)->asArray()->all();
- if ( $limit == count($list) ) {
- Yii::$app->redis->hSet($cacheKey, $userId, json_encode($list));
- }
- unset($cacheKey);
- return $list;
- }
- /**
- * 获取会员信息从缓存
- * @param $userId
- * @param $periodNum
- * @return array
- * @throws \Exception
- */
- public static function getUserInfo($userId, $periodNum) {
- $key = self::REDIS_KEY_PREFIX_USER_INFO . $periodNum;
- $data = Yii::$app->redis->hget($key, $userId);
- if (!$data) {
- $userInfo = UserInfo::findUseDbCalc()->select('USER_ID,USER_NAME,ZC_AMOUNT,ZC_PV,CON_UID,REC_UID,CON_NUM,REC_NUM,NETWORK_DEEP,RELATION_DEEP,STORE_TYPE,UPDATED_AT,SYSTEM_ID')->where('USER_ID=:USER_ID', [':USER_ID' => $userId])->asArray()->one();
- if( !$userInfo ) {
- throw new \Exception('用户信息表数据不存在,userId:'.$userId);
- }
- // 在获取商城库的会员的级别信息和是否报单中心的会员
- $userShopInfo = User::find()->select('REAL_NAME,LAST_DEC_LV,DEC_LV,EMP_LV,STAR_LV,IS_DEC,DEC_ID,DEC_ROLE_ID,STATUS,PERIOD_AT,MOBILE,CREATED_AT,SUB_COM_ID,PROVINCE,CITY,COUNTY,DEC_PROVINCE,DEC_CITY,DEC_COUNTY,IS_DIRECT_SELLER,SUB_COM_LEADER')->where('ID=:ID', [':ID' => $userId])->asArray()->one();
- if ( !$userShopInfo ) {
- throw new \Exception('用户表数据不存在,userId:'.$userId);
- }
- $userInfo['REAL_NAME'] = $userShopInfo['REAL_NAME'];
- // $userInfo['DEC_LV'] = $userShopInfo['DEC_LV'];
- //先用last_dec_lv
- $userInfo['DEC_LV'] = $userShopInfo['LAST_DEC_LV'];
- $userInfo['EMP_LV'] = $userShopInfo['EMP_LV'];
- $userInfo['STAR_LV'] = $userShopInfo['STAR_LV'];
- $userInfo['IS_DEC'] = $userShopInfo['IS_DEC'];
- $userInfo['DEC_ID'] = $userShopInfo['DEC_ID'];
- $userInfo['DEC_ROLE_ID'] = $userShopInfo['DEC_ROLE_ID'];
- $userInfo['DEC_PROVINCE'] = $userShopInfo['DEC_PROVINCE'];
- $userInfo['DEC_CITY'] = $userShopInfo['DEC_CITY'];
- $userInfo['DEC_COUNTY'] = $userShopInfo['DEC_COUNTY'];
- $userInfo['STATUS'] = $userShopInfo['STATUS'];
- $userInfo['PERIOD_NUM'] = $userShopInfo['PERIOD_AT'];
- $userInfo['MOBILE'] = $userShopInfo['MOBILE'];
- $userInfo['CREATED_AT'] = $userShopInfo['CREATED_AT'];
- $userInfo['SUB_COM_ID'] = $userShopInfo['SUB_COM_ID'];
- $userInfo['PROVINCE'] = $userShopInfo['PROVINCE'];
- $userInfo['CITY'] = $userShopInfo['CITY'];
- $userInfo['COUNTY'] = $userShopInfo['COUNTY'];
- $userInfo['IS_DIRECT_SELLER'] = $userShopInfo['IS_DIRECT_SELLER'];
- $userInfo['SUB_COM_LEADER'] = $userShopInfo['SUB_COM_LEADER'];
- $userInfo['REC_USER_NAME'] = isset($userInfo['REC_UID']) && $userInfo['REC_UID'] ? Info::getUserNameByUserId($userInfo['REC_UID']) : '';
- $userInfo['REC_REAL_NAME'] = isset($userInfo['REC_UID']) && $userInfo['REC_UID'] ? Info::getUserRealNameByUserId($userInfo['REC_UID']) : '';
- $userInfo['CON_USER_NAME'] = isset($userInfo['CON_UID']) && $userInfo['CON_UID'] ? Info::getUserNameByUserId($userInfo['CON_UID']) : '';
- $userInfo['CON_REAL_NAME'] = isset($userInfo['CON_UID']) && $userInfo['CON_UID'] ? Info::getUserRealNameByUserId($userInfo['CON_UID']) : '';
- // $userInfo['REC_USER_NAME'] = '';
- // $userInfo['REC_REAL_NAME'] = '';
- // $userInfo['CON_USER_NAME'] = '';
- // $userInfo['CON_REAL_NAME'] = '';
- // $userInfo['LOCATION'] = 1;
- unset($userShopInfo);
- // if( isset($userInfo['CON_UID']) && $userInfo['CON_UID'] ) {
- // if ($networkParent = UserNetwork::findOneAsArray('USER_ID=:USER_ID', [':USER_ID' => $userId])) {
- // $userInfo['LOCATION'] = $networkParent['RELATIVE_LOCATION'];
- // }
- // }
- if (!$userInfo['DEC_LV']) {
- $userInfo['DEC_LV'] = DeclarationLevel::getDefaultLevelId();
- }
- if (!$userInfo['EMP_LV']) {
- $userInfo['EMP_LV'] = EmployLevel::getDefaultLevelId();
- }
- if (!$userInfo['STAR_LV']) {
- $userInfo['STAR_LV'] = StarCrownLevel::getDefaultLevelId();
- }
- $data = Json::encode($userInfo);
- Yii::$app->redis->hset($key, $userId, $data);
- unset($userInfo, $key, $userId, $periodNum);
- }
- return $data ? Json::decode($data, true) : [];
- }
- public static function setUserInfo($userId, $periodNum, $userInfo) {
- $key = self::REDIS_KEY_PREFIX_USER_INFO . $periodNum;
- $data = Json::encode($userInfo);
- Yii::$app->redis->hset($key, $userId, $data);
- unset($userId, $key, $data, $userInfo, $periodNum);
- return true;
- }
- /**
- * 用户奖金信息
- * @param $userId
- * @param $periodNum
- * @return array|mixed|null|\yii\db\ActiveRecord
- */
- public static function LastUserBonus($userId, $periodNum) {
- $cacheKey = self::REDIS_KEY_PREFIX_USER_BONUS . $periodNum;
- $field = $userId;
- $cacheValue = \Yii::$app->redis->hget($cacheKey, $field);
- if ($cacheValue) {
- $value = Json::decode($cacheValue, true);
- } else {
- $value = UserBonus::findUseDbCalc()->select('USER_ID,BONUS_TOTAL')->where('USER_ID=:USER_ID', [
- 'USER_ID'=>$userId
- ])->asArray()->one();
- \Yii::$app->redis->hset($cacheKey, $field, Json::encode($value));
- }
- return $value;
- }
- /**
- * 用户奖金信息
- * @param $userId
- * @param $periodNum
- * @param $yearMonth
- * @return array|mixed|null|\yii\db\ActiveRecord
- */
- public static function lastPeriodMonthCalcBonus($userId, $periodNum, $yearMonth) {
- $cacheKey = self::REDIS_KEY_PREFIX_PERIOD_MONTH_CALC_BONUS . $periodNum;
- $field = $userId;
- $cacheValue = \Yii::$app->redis->hget($cacheKey, $field);
- if ($cacheValue) {
- $value = Json::decode($cacheValue, true);
- } else {
- $value = CalcBonus::findUseDbCalc()->select('SUM(ORI_BONUS_QY) AS ORI_BONUS_QY_SUM,SUM(ORI_BONUS_VIP) AS ORI_BONUS_VIP_SUM')->where('USER_ID=:USER_ID AND CALC_MONTH=:CALC_MONTH', [
- 'USER_ID'=>$userId,
- 'CALC_MONTH'=>$yearMonth
- ])->asArray()->one();
- \Yii::$app->redis->hset($cacheKey, $field, Json::encode($value));
- }
- return $value;
- }
- /**
- * 本月往期的复消积分的数据
- * @param $userId
- * @param $periodNum
- * @param $calcYearMonth
- * @return array|mixed|null|\yii\db\ActiveRecord
- * @throws \yii\db\Exception
- */
- public static function monthLastPeriodReconsumePoints($userId, $periodNum, $calcYearMonth) {
- $cacheKey = self::REDIS_KEY_PREFIX_NOW_MONTH_LAST_PERIOD_RECONSUME_POINTS . $periodNum;
- $cacheValue = \Yii::$app->redis->hget($cacheKey, $userId);
- if ($cacheValue) {
- $value = Json::decode($cacheValue, true);
- } else {
- $value = CalcBonus::findUseDbCalc()->select(["SUM(RECONSUME_POINTS) as RECONSUME_POINTS_SUM"])->where('USER_ID=:USER_ID AND CALC_MONTH=:CALC_MONTH', [':USER_ID' => $userId, ':CALC_MONTH'=>$calcYearMonth])->asArray()->one();
- \Yii::$app->redis->hset($cacheKey, $userId, Json::encode($value));
- }
- return $value;
- }
- /**
- * 获取结算时这一期的报单中心级别的配置
- * @param $periodNum
- * @return array|\yii\db\ActiveRecord[]
- */
- public static function getDecRoleConfig($periodNum) {
- $key = self::REDIS_KEY_PREFIX_DEC_ROLE_CONFIG . $periodNum;
- Yii::$app->redis->del($key);
- $data = Yii::$app->redis->get($key);
- if (!$data) {
- $data = DecRole::find()->where('1=1')->indexBy('ID')->asArray()->all();
- $data = Json::encode($data);
- Yii::$app->redis->set($key, $data);
- }
- return $data ? Json::decode($data) : [];
- }
- /**
- * 上一期结余业绩
- * @param $userId
- * @param $periodNum
- * @return array|mixed|\yii\db\ActiveRecord|null
- * @throws \yii\db\Exception
- */
- public static function surplusPerf($userId, $periodNum) {
- // $cacheKey = self::REDIS_KEY_PREFIX_SURPLUS_PERF . $periodNum;
- // $field = $userId;
- // $cacheValue = \Yii::$app->redis->hget($cacheKey, $field);
- // if ($cacheValue) {
- // $value = Json::decode($cacheValue);
- // } else {
- // $value = UserPerf::getPeriodSurplusPerf($userId);
- // \Yii::$app->redis->hset($cacheKey, $field, Json::encode($value));
- // }
- // return $value;
- $userPerf = self::userPerf($userId, $periodNum);
- return [
- 'SURPLUS_1L' => $userPerf['SURPLUS_1L'],
- 'SURPLUS_2L' => $userPerf['SURPLUS_2L'],
- 'SURPLUS_3L' => $userPerf['SURPLUS_3L'],
- 'SURPLUS_4L' => $userPerf['SURPLUS_4L'],
- 'SURPLUS_5L' => $userPerf['SURPLUS_5L'],
- 'SURPLUS_1L_ZC' => $userPerf['SURPLUS_1L_ZC'],
- 'SURPLUS_2L_ZC' => $userPerf['SURPLUS_2L_ZC'],
- 'SURPLUS_3L_ZC' => $userPerf['SURPLUS_3L_ZC'],
- 'SURPLUS_4L_ZC' => $userPerf['SURPLUS_4L_ZC'],
- 'SURPLUS_5L_ZC' => $userPerf['SURPLUS_5L_ZC'],
- 'SURPLUS_1L_FX' => $userPerf['SURPLUS_1L_FX'],
- 'SURPLUS_2L_FX' => $userPerf['SURPLUS_2L_FX'],
- 'SURPLUS_3L_FX' => $userPerf['SURPLUS_3L_FX'],
- 'SURPLUS_4L_FX' => $userPerf['SURPLUS_4L_FX'],
- 'SURPLUS_5L_FX' => $userPerf['SURPLUS_5L_FX'],
- 'VIP_SURPLUS_1L_ZC' => $userPerf['VIP_SURPLUS_1L_ZC'],
- 'VIP_SURPLUS_2L_ZC' => $userPerf['VIP_SURPLUS_2L_ZC'],
- 'VIP_SURPLUS_3L_ZC' => $userPerf['VIP_SURPLUS_3L_ZC'],
- 'VIP_SURPLUS_4L_ZC' => $userPerf['VIP_SURPLUS_4L_ZC'],
- 'VIP_SURPLUS_5L_ZC' => $userPerf['VIP_SURPLUS_5L_ZC'],
- 'SURPLUS_LS' => 0,
- ];
- }
- /**
- * 获取repairSurplusPerf
- * @param $userId
- * @return int[]|mixed|null
- */
- public static function getRepairSurplusPerf($userId) {
- $cacheKey = self::REDIS_KEY_PREFIX_REPAIR_SURPLUS_PERF;
- $cacheValue = \Yii::$app->redis->hget($cacheKey, $userId);
- if ($cacheValue) {
- $value = Json::decode($cacheValue);
- }else {
- $value = [
- 'SURPLUS_1L' => 0,
- 'SURPLUS_2L' => 0,
- 'SURPLUS_3L' => 0,
- 'SURPLUS_4L' => 0,
- 'SURPLUS_5L' => 0,
- ];
- }
- return $value;
- }
- /**
- * 累加repairSurplusPerf
- * @param $userId
- * @param $surplusPerf
- * @return int[]|mixed|null
- */
- public static function setRepairSurplusPerf($userId, $surplusPerf) {
- $surplusPerfList = self::getRepairSurplusPerf($userId);
- foreach ($surplusPerfList as $key => $perf) {
- $thisPerf = $surplusPerf[$key] ?? 0;
- $surplusPerfList[$key] = $perf + $thisPerf;
- unset($key, $perf, $thisPerf);
- }
- $cacheKey = self::REDIS_KEY_PREFIX_REPAIR_SURPLUS_PERF;
- \Yii::$app->redis->hset($cacheKey, $userId, Json::encode($surplusPerfList));
- self::addHasRepairPerfUsers($userId);
- unset($userId, $cacheKey, $surplusPerf);
- return $surplusPerfList;
- }
- /**
- * 加入有往期结余业绩的会员
- * @param $userId
- */
- public static function addHasRepairPerfUsers($userId) {
- // 先从已存在的会员池里面获取
- $isset = Yii::$app->redis->hget(self::REDIS_KEY_PREFIX_HAS_REPAIR_PERF_USER_POOL, $userId);
- if (!$isset) {
- Yii::$app->redis->hset(self::REDIS_KEY_PREFIX_HAS_REPAIR_PERF_USER_POOL, $userId, 1);
- Yii::$app->redis->rpush(self::REDIS_KEY_PREFIX_HAS_REPAIR_PERF_USER, $userId);
- }
- unset($userId, $isset);
- }
- /**
- * 获取有往期结余业绩的会员
- * @param int $offset
- * @param int $limit
- * @return mixed
- */
- public static function getHasRepairPerfUsers($offset = 0, $limit = self::LIMIT) {
- return Yii::$app->redis->lrange(self::REDIS_KEY_PREFIX_HAS_REPAIR_PERF_USER, $offset, ($offset + $limit - 1));
- }
- /**
- * 修正业绩缓存清空
- */
- public static function clearRepairAllCache() {
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_REPAIR_SURPLUS_PERF);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_HAS_REPAIR_PERF_USER);
- Yii::$app->redis->del(self::REDIS_KEY_PREFIX_HAS_REPAIR_PERF_USER_POOL);
- }
- /**
- * 上一期结余业绩
- * @param $userId
- * @param $periodNum
- * @return array|mixed|\yii\db\ActiveRecord|null
- * @throws \yii\db\Exception
- */
- public static function userPerf($userId, $periodNum) {
- $cacheKey = self::REDIS_KEY_PREFIX_USER_PERF . $periodNum;
- $field = $userId;
- $cacheValue = \Yii::$app->redis->hget($cacheKey, $field);
- if ($cacheValue) {
- $value = Json::decode($cacheValue);
- } else {
- $value = UserPerf::getOneUserPerf($userId);
- \Yii::$app->redis->hset($cacheKey, $field, Json::encode($value));
- }
- return $value;
- }
- /**
- * 当前期数的的业绩
- * @param $userId
- * @param $periodNum
- * @param null $perf
- * @return array|mixed
- */
- public static function nowPeriodPerf($userId, $periodNum, $perf = null) {
- $cacheKey = self::REDIS_KEY_PREFIX_NOW_PERIOD_PERF . $periodNum;
- $field = $userId;
- $cacheValue = \Yii::$app->redis->hget($cacheKey, $field);
- if ($cacheValue) {
- $value = Json::decode($cacheValue);
- } else {
- $value = [
- 'FX_AMOUNT_CASH' => 0,
- 'PV_PCS' => 0,
- 'PV_PSS' => 0,//本期的团队业绩
- 'PV_PCS_ZC' => 0,//注册
- 'PV_PCS_YH' => 0,
- 'PV_PCS_ZG' => 0,//增购
- 'PV_PCS_LS' => 0,
- 'PV_PCS_FX' => 0,
- 'PV_PCS_FX_CASH' => 0,//现金复消
- 'PV_PCS_FX_POINT' => 0,//积分复消
- 'PV_1L' => 0,
- 'PV_1L_TOUCH' => 0,
- 'PV_1L_ZC' => 0,
- 'PV_1L_YH' => 0,
- 'PV_1L_ZG' => 0,
- 'PV_1L_LS' => 0,
- 'PV_1L_FX' => 0,
- 'PV_2L' => 0,
- 'PV_2L_TOUCH' => 0,
- 'PV_2L_ZC' => 0,
- 'PV_2L_YH' => 0,
- 'PV_2L_ZG' => 0,
- 'PV_2L_LS' => 0,
- 'PV_2L_FX' => 0,
- 'PV_3L' => 0,
- 'PV_3L_TOUCH' => 0,
- 'PV_3L_ZC' => 0,
- 'PV_3L_YH' => 0,
- 'PV_3L_ZG' => 0,
- 'PV_3L_LS' => 0,
- 'PV_3L_FX' => 0,
- 'PV_4L' => 0,
- 'PV_4L_TOUCH' => 0,
- 'PV_4L_ZC' => 0,
- 'PV_4L_YH' => 0,
- 'PV_4L_ZG' => 0,
- 'PV_4L_LS' => 0,
- 'PV_4L_FX' => 0,
- 'PV_5L' => 0,
- 'PV_5L_TOUCH' => 0,
- 'PV_5L_ZC' => 0,
- 'PV_5L_YH' => 0,
- 'PV_5L_ZG' => 0,
- 'PV_5L_LS' => 0,
- 'PV_5L_FX' => 0,
- 'PV_LS_TOUCH' => 0,
- 'SURPLUS_1L' => 0,
- 'SURPLUS_2L' => 0,
- 'SURPLUS_3L' => 0,
- 'SURPLUS_4L' => 0,
- 'SURPLUS_5L' => 0,
- 'SURPLUS_1L_ZC' => 0,
- 'SURPLUS_2L_ZC' => 0,
- 'SURPLUS_3L_ZC' => 0,
- 'SURPLUS_4L_ZC' => 0,
- 'SURPLUS_5L_ZC' => 0,
- 'SURPLUS_1L_FX' => 0,
- 'SURPLUS_2L_FX' => 0,
- 'SURPLUS_3L_FX' => 0,
- 'SURPLUS_4L_FX' => 0,
- 'SURPLUS_5L_FX' => 0,
- 'SURPLUS_LS' => 0,
- ];
- }
- if ($perf !== null) {
- foreach ($perf as $key => $pv) {
- if (strpos($key, 'SURPLUS') !== false) {
- $value[$key] = $pv;
- } else {
- $value[$key] = $pv + $value[$key];
- }
- }
- Yii::$app->redis->hset($cacheKey, $field, Json::encode($value));
- }
- return $value;
- }
- /**
- * 上个月的业绩
- * @param $userId
- * @param $periodNum
- * @return array|mixed|null|\yii\db\ActiveRecord
- */
- public static function lastMonthPerf($userId, $periodNum) {
- $period = Period::instance();
- $last = $period->getLastMonth($periodNum);
- $lastYearMonth = $last['yearMonth'];
- $cacheKey = self::REDIS_KEY_PREFIX_LAST_MONTH_PERF . $periodNum;
- $field = $userId;
- $cacheValue = \Yii::$app->redis->hget($cacheKey, $field);
- if ($cacheValue) {
- $value = Json::decode($cacheValue);
- } else {
- $value = PerfMonth::getMonthPerf($lastYearMonth, $userId);
- \Yii::$app->redis->hset($cacheKey, $field, Json::encode($value));
- }
- return $value;
- }
- /**
- * 当前月的业绩
- * @param $userId
- * @param $periodNum
- * @param $perf
- * @return array|mixed
- */
- public static function nowMonthPerf($userId, $periodNum, $perf = null) {
- $cacheKey = self::REDIS_KEY_PREFIX_NOW_MONTH_PERF . $periodNum;
- $field = $userId;
- $cacheValue = \Yii::$app->redis->hget($cacheKey, $field);
- if ($cacheValue) {
- $value = Json::decode($cacheValue);
- } else {
- $baseInfo = self::getUserInfo($userId, $periodNum);
- $value = [
- 'USER_ID' => $userId,
- 'FX_AMOUNT_CASH' => 0,
- 'PV_PCS' => 0,
- 'PV_PCS_FX' => 0,
- 'PV_PSS' => 0,
- 'PV_1L' => 0,
- 'PV_2L' => 0,
- 'PV_3L' => 0,
- 'PV_4L' => 0,
- 'PV_5L' => 0,
- 'VIP_PV_1L_ZC' => 0,
- 'VIP_PV_2L_ZC' => 0,
- 'VIP_PV_3L_ZC' => 0,
- 'VIP_PV_4L_ZC' => 0,
- 'VIP_PV_5L_ZC' => 0,
- 'PV_1L_TOTAL' => 0,
- 'PV_2L_TOTAL' => 0,
- 'PV_3L_TOTAL' => 0,
- 'PV_4L_TOTAL' => 0,
- 'PV_5L_TOTAL' => 0,
- 'PV_PSS_TOTAL' => 0,
- 'DEC_LEVEL' => $baseInfo['DEC_LV'],
- 'EMP_LEVEL' => EmployLevel::getDefaultLevelId(),
- 'CF_PERCENT' => 0,
- 'LX_PERCENT' => 0,
- 'FX_STATUS' => PerfMonth::NEXT_MONTH_FX_FALSE,
- ];
- }
- if ($perf !== null) {
- foreach ($perf as $key => $item) {
- $value[$key] = $item;
- }
- }
- Yii::$app->redis->hset($cacheKey, $field, Json::encode($value));
- return $value;
- }
- /**
- * 当前期数的的业绩
- * @param $userId
- * @param $periodNum
- * @param null $perf
- * @return array|mixed
- */
- public static function nowStandardMonthPerf($userId, $periodNum, $perf = null) {
- $cacheKey = self::REDIS_KEY_PREFIX_NOW_STANDARD_MONTH_PERF . $periodNum;
- $field = $userId;
- $cacheValue = \Yii::$app->redis->hget($cacheKey, $field);
- if ($cacheValue) {
- $value = Json::decode($cacheValue);
- } else {
- $value = [
- 'AMOUNT_PCS' => 0,
- 'AMOUNT_PSS' => 0
- ];
- }
- if ($perf !== null) {
- foreach ($perf as $key => $pv) {
- $value[$key] = $pv + $value[$key];
- }
- Yii::$app->redis->hset($cacheKey, $field, Json::encode($value));
- }
- return $value;
- }
- /**
- * 当前月的积分
- * @param $userId
- * @param $periodNum
- * @param $perf
- * @return array|mixed
- */
- public static function nowMonthScore($userId, $periodNum, $perf = null) {
- $cacheKey = self::REDIS_KEY_PREFIX_NOW_MONTH_SCORE . $periodNum;
- $cacheValue = \Yii::$app->redis->hget($cacheKey, $userId);
- if ($cacheValue) {
- $value = Json::decode($cacheValue);
- } else {
- $value = [
- 'USER_ID' => $userId,
- 'BASE_SCORE' => 0,
- 'LEVEL_SCORE' => 0,
- 'UPGRADE_SCORE' => 0,
- // 'TOTAL_SCORE' => 0,
- ];
- }
- unset($cacheValue);
- if ($perf !== null) {
- foreach ($perf as $key => $item) {
- $value[$key] = $item;
- // $value['TOTAL_SCORE'] += $item;
- unset($key, $item);
- }
- Yii::$app->redis->hset($cacheKey, $userId, Json::encode($value));
- }
- unset($userId, $periodNum, $perf, $cacheKey);
- return $value;
- }
- /**
- * 获取直推的所有子会员
- * @param $userId
- * @param $periodNum
- * @return array
- */
- public static function getChildrenOneDeepFromRedis($userId, $periodNum){
- $key = self::REDIS_KEY_PREFIX_USER_INFO_CHILD_ONE_DEEP . $periodNum;
- $data = Yii::$app->redis->hget($key, $userId);
- if(!$data){
- $list = UserInfo::findUseDbCalc()->select('USER_ID')->where('REC_UID=:REC_UID', [
- 'REC_UID' => $userId
- ])->asArray()->all();
- $data = Json::encode($list);
- unset($list);
- Yii::$app->redis->hset($key, $userId, $data);
- }
- unset($key, $userId, $periodNum);
- return $data ? Json::decode($data, true) : [];
- }
- /**
- * 每个区有多少个什么级别的数量
- * @param $userId
- * @param $periodNum
- * @param null $levelNumArr
- * @return array|mixed
- */
- public static function hasEmpLevelNum($userId, $periodNum, $levelNumArr = null) {
- $key = self::REDIS_KEY_PREFIX_EMP_NUM_PERF . $periodNum;
- $field = $userId;
- $cacheValue = Yii::$app->redis->hget($key, $field);
- if ($cacheValue) {
- $value = Json::decode($cacheValue);
- } else {
- $allEmpLevel = EmployLevel::getFromCache();
- $value = [];
- $relationList = self::getChildrenOneDeepFromRedis($userId, $periodNum);
- foreach ($relationList as $relationData) {
- foreach ($allEmpLevel as $level) {
- // 从月度业绩表中找到所有下级的各个部门的数量
- $value[$relationData['USER_ID']][$level['ID']] = 0;
- }
- }
- }
- if ($levelNumArr != null) {
- foreach ($levelNumArr as $departUserId => $item) {
- foreach ($item as $levelID => $num) {
- if( isset($value[$departUserId][$levelID]) ) {
- $value[$departUserId][$levelID] += $num;
- }else {
- $value[$departUserId][$levelID] = $num;
- }
- }
- }
- }
- Yii::$app->redis->hset($key, $field, Json::encode($value));
- if ($levelNumArr == null) return $value;
- }
- /**
- * 会员是否本月注册
- * @param $userId
- * @param $periodNum
- * @return bool
- * @throws \yii\db\Exception
- */
- public static function isMonthJoinFromRedis($userId, $periodNum) {
- $period = Period::instance();
- $calcYearMonth = $period->getYearMonth($periodNum);
- $userInfo = self::getUserInfo($userId, $periodNum);
- $addYearMonth = $period->getYearMonth($userInfo['PERIOD_NUM']);
- //当月注册
- if ($addYearMonth == $calcYearMonth) return true;
- //上月注册
- $calcLastYearMonth = $period->getLastMonth($periodNum);
- if ($addYearMonth == $calcLastYearMonth['yearMonth']) return true;
- // 未来注册
- if ($addYearMonth > $calcYearMonth) return true;
- return false;
- }
- /**
- * 荣衔奖最大比例
- * @param $userId
- * @param $periodNum
- * @param int $percent
- * @return float|int
- */
- public static function ycMaxBonusPercent($userId, $periodNum, $percent=0) {
- $cacheKey = self::REDIS_KEY_PREFIX_YC_BONUS . $periodNum;
- $value = Yii::$app->redis->hget($cacheKey, $userId);
- $maxPercent = floatval($value)>0 ? floatval($value) : 0;
- if ( $percent > 0 && $percent > $maxPercent ) {
- $maxPercent = $percent;
- unset($periodNum, $percent);
- Yii::$app->redis->hset($cacheKey, $userId, $maxPercent);
- return $maxPercent;
- }
- unset($userId, $periodNum, $oriBonus, $cacheKey, $value);
- return $maxPercent;
- }
- /**
- * 服务奖最大比例
- * @param $userId
- * @param $periodNum
- * @param int $percent
- * @return float|int
- */
- public static function fwMaxBonusPercent($userId, $periodNum, $percent=0) {
- $cacheKey = self::REDIS_KEY_PREFIX_FW_BONUS . $periodNum;
- $value = Yii::$app->redis->hget($cacheKey, $userId);
- $maxPercent = floatval($value)>0 ? floatval($value) : 0;
- if ( $percent > 0 && $percent > $maxPercent ) {
- $maxPercent = $percent;
- unset($periodNum, $percent);
- Yii::$app->redis->hset($cacheKey, $userId, $maxPercent);
- return $maxPercent;
- }
- unset($userId, $periodNum, $oriBonus, $cacheKey, $value);
- return $maxPercent;
- }
- /**
- * 奖金缓存
- * @param $userId
- * @param $periodNum
- * @param string $bonusType
- * @param float $oriBonus
- * @param array $deductData
- * @return array|mixed
- */
- public static function bonus($userId, $periodNum, $bonusType = null, $oriBonus = 0.00, $deductData=[], $fromMeans='') {
- $cacheKey = self::REDIS_KEY_PREFIX_BONUS . $periodNum;
- $value = [
- 'BONUS_BD' => 0,
- 'BONUS_TG' => 0,
- 'BONUS_XF' => 0,
- 'BONUS_YJ' => 0,
- 'BONUS_GX' => 0,
- 'BONUS_GL' => 0,
- 'BONUS_QY' => 0,
- 'BONUS_YC' => 0,
- 'BONUS_VIP' => 0,
- 'BONUS_BS' => 0,
- 'BONUS_QUARTER' => 0,
- 'BONUS_YC_EXTRA' => 0,
- 'ORI_BONUS_BD' => 0,
- 'ORI_BONUS_BS' => 0,
- 'BONUS_BS_MNT' => 0,
- 'BONUS_BS_ABBR' => 0,
- 'ORI_BONUS_BS_MNT' => 0,
- 'ORI_BONUS_BS_ABBR' => 0,
- 'ORI_BONUS_QUARTER' => 0,
- 'ORI_BONUS_TG' => 0,
- 'ORI_BONUS_XF' => 0,
- 'ORI_BONUS_YJ' => 0,
- 'ORI_BONUS_YJ_BD' => 0,
- 'ORI_BONUS_YJ_FX' => 0,
- 'ORI_BONUS_GX' => 0,
- 'ORI_BONUS_GL' => 0,
- 'ORI_BONUS_GL_BD' => 0,
- 'ORI_BONUS_GL_FX' => 0,
- 'ORI_BONUS_QY' => 0,
- 'ORI_BONUS_QY_BD' => 0,
- 'ORI_BONUS_QY_FX' => 0,
- 'ORI_BONUS_YC' => 0,
- 'ORI_BONUS_VIP' => 0,
- 'ORI_BONUS_YC_EXTRA' => 0,
- // 'INCOME_TG_TOTAL' => 0,
- // 'INCOME_YJ_TOTAL' => 0,
- // 'INCOME_QY_TOTAL' => 0,
- 'INCOME_TOTAL' => 0,
- 'BONUS_TOTAL' => 0,
- 'RECONSUME_POINTS' => 0,
- 'MANAGE_TAX' => 0,
- 'ORI_CAPPED_BONUS_QY' => 0,// 团队奖,封顶前金额
- //没有用到的
- 'BONUS_FX' => 0,
- 'BONUS_LS' => 0,
- 'BONUS_CF' => 0,
- 'BONUS_LX' => 0,
- 'BONUS_HB' => 0,
- 'BONUS_BT' => 0,
- 'BONUS_BT_PROD' => 0,
- 'BONUS_BT_TOOL' => 0,
- 'DEDUCT_ZR' => 0,
- 'BONUS_FL' => 0,
- ];
- // 从 redis 中获取当前的结果
- $cacheValue = \Yii::$app->redis->hget($cacheKey, $userId);
- if ($cacheValue) {
- $cacheValue = Json::decode($cacheValue);
- $value = $cacheValue;
- }
- unset($cacheValue);
- if ($oriBonus > 0) {
- $oriBonusType = sprintf('ORI_%s', $bonusType);
- $value[$oriBonusType] += $oriBonus;
- if( $fromMeans !== '' ) {
- $oriBonusMeansType = sprintf('ORI_%s_%s', $bonusType, $fromMeans);
- $value[$oriBonusMeansType] += $oriBonus;
- }
- if( !in_array($bonusType, self::NOT_SEND_BONUS_LIST) ) {
- if( $deductData ) {
- $value[$bonusType] += $deductData['surplus'];
- $value['RECONSUME_POINTS'] += $deductData['reConsumePoints'];
- $value['MANAGE_TAX'] += $deductData['manageTax'];
- }else {
- $value[$bonusType] += $oriBonus;
- }
- $value['BONUS_TOTAL'] += $oriBonus;
- }
- if( in_array($bonusType, self::INCOME_BONUS_LIST) ) {
- self::addHasIncomeUsers($userId, $periodNum);
- // if( !in_array($bonusType, self::NOT_SEND_BONUS_LIST) ) {
- // $value['INCOME_TOTAL'] += $oriBonus;
- // }
- }
- Yii::$app->redis->hset($cacheKey, $userId, Json::encode($value));
- unset($oriBonusType);
- self::addHasBonusUsers($userId, $periodNum);
- }
- unset($userId, $periodNum, $bonusType, $oriBonus, $deductData, $cacheKey);
- return $value;
- }
- public static function standardBonus($userId, $periodNum, $bonus=0.00) {
- $cacheKey = self::REDIS_KEY_PREFIX_STANDARD_BONUS . $periodNum;
- $value = 0.00;
- if( $bonus > 0 ) {
- Yii::$app->redis->hset($cacheKey, $userId, $bonus);
- $value = $bonus;
- //加入有奖金的会员中
- self::addHasBonusUsers($userId, $periodNum);
- }else {
- $cacheValue = \Yii::$app->redis->hget($cacheKey, $userId);
- if ($cacheValue) {
- $value = $cacheValue;
- }
- unset($cacheValue);
- }
- unset($cacheKey, $userId, $periodNum, $bonus);
- return $value;
- }
- public static function tourismBonus($userId, $periodNum, $bonus = 0.00) {
- $cacheKey = self::REDIS_KEY_PREFIX_TOURISM_BONUS . $periodNum;
- $value = 0.00;
- if( $bonus > 0 ) {
- Yii::$app->redis->hset($cacheKey, $userId, $bonus);
- $value = $bonus;
- //加入有奖金的会员中
- self::addHasBonusUsers($userId, $periodNum);
- }else {
- $cacheValue = \Yii::$app->redis->hget($cacheKey, $userId);
- if ($cacheValue) {
- $value = $cacheValue;
- }
- unset($cacheValue);
- }
- unset($cacheKey, $userId, $periodNum, $bonus);
- return $value;
- }
- public static function villaBonus($userId, $periodNum, $bonus = 0.00) {
- $cacheKey = self::REDIS_KEY_PREFIX_VILLA_BONUS . $periodNum;
- $value = 0.00;
- if( $bonus > 0 ) {
- Yii::$app->redis->hset($cacheKey, $userId, $bonus);
- $value = $bonus;
- //加入有奖金的会员中
- self::addHasBonusUsers($userId, $periodNum);
- }else {
- $cacheValue = \Yii::$app->redis->hget($cacheKey, $userId);
- if ($cacheValue) {
- $value = $cacheValue;
- }
- unset($cacheValue);
- }
- unset($cacheKey, $userId, $periodNum, $bonus);
- return $value;
- }
- public static function garageBonus($userId, $periodNum, $bonus = 0.00) {
- $cacheKey = self::REDIS_KEY_PREFIX_GARAGE_BONUS . $periodNum;
- $value = 0.00;
- if( $bonus > 0 ) {
- Yii::$app->redis->hset($cacheKey, $userId, $bonus);
- $value = $bonus;
- //加入有奖金的会员中
- self::addHasBonusUsers($userId, $periodNum);
- }else {
- $cacheValue = \Yii::$app->redis->hget($cacheKey, $userId);
- if ($cacheValue) {
- $value = $cacheValue;
- }
- unset($cacheValue);
- }
- unset($cacheKey, $userId, $periodNum, $bonus);
- return $value;
- }
- /**
- * 设置车房总系数
- * @param $periodNum
- * @param $value
- */
- public static function setCFTotalPercent($periodNum, $value) {
- Yii::$app->redis->set(self::REDIS_KEY_PREFIX_CF_TOTAL_PERCENT . $periodNum, $value);
- }
- /**
- * 获得车房总系数
- * @param $periodNum
- * @return mixed
- */
- public static function getCFTotalPercent($periodNum) {
- return Yii::$app->redis->get(self::REDIS_KEY_PREFIX_CF_TOTAL_PERCENT . $periodNum);
- }
- /**
- * 设置领袖总系数
- * @param $periodNum
- * @param $value
- */
- public static function setLXTotalPercent($periodNum, $value) {
- Yii::$app->redis->set(self::REDIS_KEY_PREFIX_LX_TOTAL_PERCENT . $periodNum, $value);
- }
- /**
- * 获得领袖总系数
- * @param $periodNum
- * @return mixed
- */
- public static function getLXTotalPercent($periodNum) {
- return Yii::$app->redis->get(self::REDIS_KEY_PREFIX_LX_TOTAL_PERCENT . $periodNum);
- }
- /**
- * 添加上2代共享奖关系
- * @param $bonusUserId
- * @param $fromUserId
- * @param $periodNum
- * @param $validDeep
- * @return boolean
- */
- public static function addShareBonusOneRelation($bonusUserId, $fromUserId, $periodNum, $validDeep) {
- if ($validDeep == 1) {
- $cacheKey = self::REDIS_KEY_PREFIX_GX_BONUS_DEEP_ONE_LIST_DATA . $periodNum;
- }else {
- $cacheKey = self::REDIS_KEY_PREFIX_GX_BONUS_DEEP_TWO_LIST_DATA . $periodNum;
- }
- $fromUserDataJson = Yii::$app->redis->hget($cacheKey, $fromUserId);
- $fromUserData = [];
- if( $fromUserDataJson ) {
- $fromUserData = Json::decode($fromUserDataJson, true);
- }
- unset($fromUserDataJson);
- $fromUserData[] = $bonusUserId;
- Yii::$app->redis->hset($cacheKey, $fromUserId, Json::encode($fromUserData));
- unset($fromUserData, $bonusUserId, $fromUserId, $periodNum);
- return true;
- }
- /**
- * 获取上2代共享奖关系
- * @param $fromUserId
- * @param $periodNum
- * @param $validDeep
- * @return array
- */
- public static function getShareBonusOneRelation($fromUserId, $periodNum, $validDeep) {
- if ($validDeep == 1) {
- $cacheKey = self::REDIS_KEY_PREFIX_GX_BONUS_DEEP_ONE_LIST_DATA . $periodNum;
- }else {
- $cacheKey = self::REDIS_KEY_PREFIX_GX_BONUS_DEEP_TWO_LIST_DATA . $periodNum;
- }
- $fromUserDataJson = Yii::$app->redis->hget($cacheKey, $fromUserId);
- $bonusUserData = [];
- if( $fromUserDataJson ) {
- $bonusUserData = Json::decode($fromUserDataJson, true);
- }
- unset($fromUserDataJson);
- return $bonusUserData;
- }
- }
|