| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686 |
- <?php
- /**
- * Created by PhpStorm.
- * User: leo
- * Date: 2018/8/2
- * Time: 上午10:38
- */
- namespace common\helpers\bonus;
- use common\helpers\Cache;
- use common\helpers\user\Info;
- use common\models\CalcBonus;
- use common\models\PerfMonth;
- use common\models\Period;
- use common\models\DeclarationLevel;
- use common\models\DecRole;
- use common\models\EmployLevel;
- use common\models\User;
- use common\models\UserBonus;
- use common\models\UserPerf;
- use Yii;
- use common\models\UserInfo;
- use yii\helpers\Json;
- class CalcCache {
- const LIMIT = 10000;
- 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_';
- //@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);
- }
- /**
- * 清网络缓存
- */
- 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(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);
- }
- /**
- * 会员信息加入缓存
- * @param $periodNum
- * @param int $offset
- * @param int $limit
- * @return bool
- */
- public static function addUsers($periodNum, $offset = 0, $limit = self::LIMIT) {
- // 修复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();
- if ($allData) {
- foreach ($allData as $data) {
- // 会员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
- */
- 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,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'];
- //先用last_dec_lv
- $userInfo['DEC_LV'] = $userShopInfo['LAST_DEC_LV'];
- $userInfo['EMP_LV'] = $userShopInfo['EMP_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']) : '';
- unset($userShopInfo);
- if (!$userInfo['DEC_LV']) {
- $userInfo['DEC_LV'] = DeclarationLevel::getDefaultLevelId();
- }
- if (!$userInfo['EMP_LV']) {
- $userInfo['EMP_LV'] = EmployLevel::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;
- }
- }
|