TestController.php 107 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655
  1. <?php
  2. /**
  3. * 测试专用控制器
  4. * Created by PhpStorm.
  5. * User: leo
  6. * Date: 2018/3/9
  7. * Time: 上午11:56
  8. */
  9. namespace console\controllers;
  10. use common\helpers\bonus\BonusCalc;
  11. use common\helpers\bonus\BonusSend;
  12. use common\helpers\bonus\CalcCache;
  13. use common\helpers\bonus\PerfCalc;
  14. use common\helpers\Cache;
  15. use common\helpers\DataBak;
  16. use common\helpers\Date;
  17. use common\helpers\Form;
  18. use common\helpers\ocr\OcrApi;
  19. use common\helpers\snowflake\SnowFake;
  20. use common\helpers\Tool;
  21. use common\helpers\user\Balance;
  22. use common\helpers\user\Info;
  23. use common\helpers\user\Reconsume;
  24. use common\libs\api\sms\SmsApi;
  25. use common\libs\swoole\RPCApi;
  26. use common\libs\taskQueue\Queue;
  27. use common\libs\taskQueue\TaskFunc;
  28. use common\models\CalcBonus;
  29. use common\models\CalcBonusBD;
  30. use common\models\CalcBonusFX;
  31. use common\models\CalcBonusGL;
  32. use common\models\CalcBonusGX;
  33. use common\models\CalcBonusQY;
  34. use common\models\CalcBonusTG;
  35. use common\models\CalcBonusYC;
  36. use common\models\CalcBonusYJ;
  37. use common\models\CalcMonthBonusUser;
  38. use common\models\DealType;
  39. use common\models\EmployLevel;
  40. use common\models\FlowBonus;
  41. use common\models\FlowReconsumePoints;
  42. use common\models\forms\ClearDataForm;
  43. use common\models\forms\DeclarationForm;
  44. use common\models\forms\DeclarationLoopForm;
  45. use common\models\forms\HistoryBonusForm;
  46. use common\models\forms\UserForm;
  47. use common\models\Order;
  48. use common\models\OrderShop;
  49. use common\models\PerfMonth;
  50. use common\models\PerfOrder;
  51. use common\models\PerfPeriod;
  52. use common\models\Period;
  53. use common\models\ReconsumePool;
  54. use common\models\ReconsumePoolFlow;
  55. use common\models\DecOrder;
  56. use common\models\ScoreMonth;
  57. use common\models\TaskQueue;
  58. use common\models\TmpOldNetwork;
  59. use common\models\User;
  60. use common\models\UserBind;
  61. use common\models\UserBonus;
  62. use common\models\UserInfo;
  63. use common\models\UserMove;
  64. use common\models\UserNetwork;
  65. use common\models\UserPerf;
  66. use common\models\UserRelation;
  67. use yii\base\Exception;
  68. use yii\db\Expression;
  69. use yii\db\Query;
  70. use yii\helpers\Json;
  71. class TestController extends BaseController
  72. {
  73. public function actionPut(){
  74. file_put_contents(\Yii::getAlias('@common/runtime/logs/asyncLog.log'), var_export(['asdasd'=>'中午'], true));
  75. }
  76. /**
  77. * 测试异步任务
  78. * ./yii test/async-task calcBonus
  79. * @param null $routeAndParamsMethod 想要测试的方法名
  80. * @throws \yii\base\Exception
  81. * @throws \yii\base\InvalidConfigException
  82. */
  83. public function actionAsyncTask($routeAndParamsMethod = null){
  84. if($routeAndParamsMethod !== null){
  85. $routeAndParams = call_user_func(self::class.'::_'.$routeAndParamsMethod);
  86. $route = $routeAndParams['route'];
  87. $params = $routeAndParams['params'];
  88. } else {
  89. $moveInfo = UserMove::find()->select('UM.ID,UM.LOCATION,UM.TYPE,MU.USER_NAME AS moveUserName,TU.USER_NAME AS toConUserName,TU.REAL_NAME AS toConRealName')
  90. ->from(UserMove::tableName().' AS UM')
  91. ->leftJoin(User::tableName().' AS MU', 'UM.USER_ID=MU.ID')
  92. ->leftJoin(User::tableName() . ' AS TU', 'UM.TO_UID=TU.ID')
  93. ->where('AUDIT_STATUS=0')->asArray()->all();
  94. foreach($moveInfo as $k=>$moves){
  95. // route换成要测试的路由路径
  96. if($moves['TYPE']=='relation'){
  97. $route = 'user/move-relation';
  98. }else{
  99. $route = 'user/move-network';
  100. }
  101. // params的数组内容替换为要传的值
  102. $params = [
  103. 'moveId' => $moves['ID'],
  104. 'moveUserName' => $moves['moveUserName'],
  105. 'toConUserName' => $moves['toConUserName'],
  106. 'toConRealName' => $moves['toConRealName'],
  107. 'location' => $moves['LOCATION'],
  108. 'type' => $moves['TYPE'],
  109. ];
  110. echo sprintf("任务【%s】开始执行".PHP_EOL, $k);
  111. $params['handleUserId'] = null;
  112. $taskKey = Cache::setAsyncParams($params);
  113. $parts = \Yii::$app->createController($route);
  114. if(is_array($parts)){
  115. $res = \Yii::$app->runAction($route,[$taskKey]);
  116. var_dump($res);
  117. unset($res);
  118. } else {
  119. echo('失败'.PHP_EOL);
  120. }
  121. unset($k,$moves,$route,$params,$taskKey,$parts);
  122. }
  123. }
  124. // $params['handleUserId'] = null;
  125. // $taskKey = Cache::setAsyncParams($params);
  126. // $parts = \Yii::$app->createController($route);
  127. // if(is_array($parts)){
  128. // $res = \Yii::$app->runAction($route,[$taskKey]);
  129. // var_dump($res);
  130. // } else {
  131. // echo('失败'.PHP_EOL);
  132. // }
  133. }
  134. /**
  135. * 异步发奖
  136. * @param string $router
  137. * @param int $periodNum
  138. * @return void
  139. */
  140. public function actionBonusAsyncTask($router='bonus/perf', $periodNum=105) {
  141. // 异步处理添加任务
  142. $taskKey = Cache::setAsyncParams([
  143. 'handleUserId' => null,
  144. 'handleUserName' => null,
  145. 'periodNum' => $periodNum,
  146. ]);
  147. $data = [
  148. 'data' => [
  149. [
  150. 'a' => $router,
  151. 'p' => [$taskKey],
  152. ]
  153. ],
  154. ];
  155. if(\Yii::$app->swooleAsyncTimer->async(Json::encode($data))){
  156. echo 'ok' . PHP_EOL;
  157. } else {
  158. echo 'fail' . PHP_EOL;
  159. }
  160. }
  161. private static function _calcPerf(){
  162. return [
  163. 'route' => 'bonus/perf',
  164. 'params' => [
  165. 'periodNum' => 105,
  166. ],
  167. ];
  168. }
  169. /**
  170. * 测试结算
  171. * @return array
  172. */
  173. private static function _calcBonus(){
  174. return [
  175. 'route' => 'bonus/calc',
  176. 'params' => [
  177. 'periodNum' => 105,
  178. ],
  179. ];
  180. }
  181. /**
  182. * 测试结算
  183. * @return array
  184. */
  185. private static function _sendBonus(){
  186. return [
  187. 'route' => 'bonus/send',
  188. 'params' => [
  189. 'periodNum' => 118,
  190. ],
  191. ];
  192. }
  193. /**
  194. * 测试移网
  195. * @return array
  196. */
  197. private static function _moveRouteAndParams(){
  198. return [
  199. 'route' => 'user/move-network',
  200. 'params' => [
  201. 'moveId' => 'A090B24973524443BE8BA95A40EE2148',
  202. 'moveUserName' => 'b30746926',
  203. 'toConUserName' => 'tester004',
  204. 'toConRealName' => 'hhhjhjj',
  205. 'location' => 1,
  206. 'type' => 'network',
  207. ],
  208. ];
  209. }
  210. /**
  211. * 添加体系
  212. * @return array
  213. */
  214. private static function _addSystem(){
  215. return [
  216. 'route' => 'user/system-add',
  217. 'params' => [
  218. 'systemName' => '测试',
  219. 'leaderUserName' => 'tester001',
  220. 'remark' => '测试',
  221. ],
  222. ];
  223. }
  224. private $_addUserNum = 1;
  225. private $_md5UserId = 2;
  226. private $_userNameNum = 2;
  227. public function actionAddUserTable(){
  228. $notDelUserId = "'670B84FD7C216D4EE055736AECE8644D','B322C18F7E274A9D9FC5DADC3B385E8B','638A5A3B617F46C999C5E4D072EED369','3C313C66D1724D658BF10B08194022BB'";
  229. User::deleteAll("ID NOT IN (".$notDelUserId.")");
  230. DecOrder::deleteAll("TO_USER_ID NOT IN (".$notDelUserId.")");
  231. $offset = 100;
  232. $allCount = UserInfo::find()->where("USER_ID NOT IN (".$notDelUserId.")")->orderBy('NETWORK_DEEP ASC')->asArray()->count("USER_ID");
  233. $pageCount = ceil($allCount/$offset);
  234. for($page=1;$page<=$pageCount;$page++) {
  235. $allUser = UserInfo::find()->where("USER_ID NOT IN (".$notDelUserId.")")->offset(($page-1)*$offset)->limit($offset)->orderBy('NETWORK_DEEP ASC')->asArray()->all();
  236. $insertData = [];
  237. $userInsertData=[];
  238. $decSn = 190310000000;
  239. foreach($allUser as $key=>$user){
  240. $decSn += 1;
  241. $decPv = rand(1, 100) * 1000;
  242. $insertData[] = [
  243. 'DEC_SN' => 'D'.$decSn.'0000',
  244. 'ORDER_SN' => $decSn,
  245. 'USER_ID' => $user['USER_ID'],
  246. 'TYPE' => 'ZC',
  247. 'TO_USER_ID' => $user['USER_ID'],
  248. 'DEC_AMOUNT' => $decPv,
  249. 'DEC_PV' => $decPv,
  250. 'PAID_WALLET' => 'bill',
  251. 'PERIOD_NUM' => 102,
  252. 'IS_DEL' => 0,
  253. 'P_CALC_MONTH' => Date::ociToDate(202001, Date::OCI_TIME_FORMAT_SHORT_MONTH),
  254. 'CREATED_AT' => strtotime('2020-01-20'),
  255. 'DEC_ID' => $user['REC_UID'],
  256. ];
  257. $userInsertData[] = [
  258. 'ID' => $user['USER_ID'],
  259. 'USER_NAME' => $user['USER_NAME'],
  260. 'AVATAR' => 'http://abc.anran.ming/cdn/avatar/1.png',
  261. 'PASSWORD_HASH' => password_hash('111111', PASSWORD_DEFAULT),
  262. 'PAY_PASSWORD' => password_hash('111111', PASSWORD_DEFAULT),
  263. 'NATION' => 1,
  264. 'REAL_NAME' => $user['USER_NAME'],
  265. 'ID_CARD' => '130322111111111113',
  266. 'ID_TYPE' => 0,
  267. 'MOBILE' => '13333333339',
  268. 'ADDRESS' => '广东省 / 广州市荔湾区三号五弄',
  269. 'IS_DEC' => 1,
  270. 'DEC_ID' => '670B84FD7C216D4EE055736AECE8644D',
  271. 'PERIOD_AT' => 102,
  272. 'CREATED_AT' => strtotime('2020-02-12'),
  273. 'LAST_DEC_LV' => '67ABCE0ECE705575E055736AECE8644D',
  274. 'DEC_LV' => '67ABCB8C1F7D5519E055736AECE8644D',
  275. 'EMP_LV' => '67BE1C6C21F81B32E055736AECE8644D'
  276. ];
  277. }
  278. User::batchInsert($userInsertData);
  279. DecOrder::batchInsert($insertData);
  280. echo('第'.$page.'页数据'.PHP_EOL);
  281. }
  282. echo('全部完成'.PHP_EOL);
  283. }
  284. /**
  285. * 模拟添加会员
  286. * @param $num
  287. * @param string $conUid
  288. * @param string $recUid
  289. * @param int $location
  290. * @return bool
  291. * @throws Exception
  292. * @throws \yii\db\Exception
  293. */
  294. public function actionAddUser($num, $conUid = 'B322C18F7E274A9D9FC5DADC3B385E8B', $recUid = 'B322C18F7E274A9D9FC5DADC3B385E8B', $location = 1){
  295. if($num <= $this->_addUserNum) {
  296. echo('模拟加入完成'.PHP_EOL);
  297. return true;
  298. }
  299. $this->_md5UserId += 1;
  300. $this->_userNameNum += 1;
  301. $form = new UserForm();
  302. $form->scenario = 'addWithUid';
  303. $form->userId = md5($this->_md5UserId);
  304. $form->userName = 'simulate'.($this->_userNameNum);
  305. $form->zcPv = 1000;
  306. $form->zcAmount = 1000;
  307. $form->conUid = $conUid;
  308. $form->recUid = $recUid;
  309. $form->location = $location;
  310. if($form->add()){
  311. echo('添加了'.$this->_addUserNum.'名会员'.PHP_EOL);
  312. $this->_addUserNum += 1;
  313. // 获取全网深度最浅还没满的会员ID 作为节点人ID
  314. $conUser = UserInfo::find()->select('USER_ID, CON_NUM')->where('CON_NUM < 3')->orderBy('NETWORK_DEEP ASC')->asArray()->one();
  315. if($conUser['CON_NUM'] == 0){
  316. $newLocation = 1;
  317. } elseif($conUser['CON_NUM'] == 1){
  318. $newLocation = 2;
  319. } elseif($conUser['CON_NUM'] == 2) {
  320. $newLocation = 3;
  321. } else {
  322. throw new Exception('添加失败,原因:加入会员的点位区位错误');
  323. }
  324. return $this->actionAddUser($num, $conUser['USER_ID'], $conUser['USER_ID'], $newLocation);
  325. } else {
  326. throw new Exception('添加失败,原因:'.Form::formatErrorsForApi($form->getErrors()));
  327. }
  328. return true;
  329. }
  330. /**
  331. * 清空已增加的会员
  332. */
  333. public function actionClearAddUser(){
  334. $notDelUserId = "'670B84FD7C216D4EE055736AECE8644D','B322C18F7E274A9D9FC5DADC3B385E8B','638A5A3B617F46C999C5E4D072EED369','3C313C66D1724D658BF10B08194022BB'";
  335. $netChangeUserId = "'B322C18F7E274A9D9FC5DADC3B385E8B','638A5A3B617F46C999C5E4D072EED369','3C313C66D1724D658BF10B08194022BB'";
  336. UserInfo::deleteAll("USER_ID NOT IN (".$notDelUserId.")");
  337. UserNetwork::deleteAll("USER_ID NOT IN (".$notDelUserId.")");
  338. UserRelation::deleteAll("USER_ID NOT IN (".$notDelUserId.")");
  339. UserInfo::updateAll(['CON_NUM' => 0, 'REC_NUM' => 0], "USER_ID IN (".$netChangeUserId.")");
  340. User::deleteAll("ID NOT IN (".$notDelUserId.")");
  341. CalcBonus::deleteAll("USER_ID NOT IN (".$notDelUserId.")");
  342. CalcBonusBD::deleteAll("USER_ID NOT IN (".$notDelUserId.")");
  343. CalcBonusTG::deleteAll("USER_ID NOT IN (".$notDelUserId.")");
  344. CalcBonusYJ::deleteAll("USER_ID NOT IN (".$notDelUserId.")");
  345. CalcBonusGX::deleteAll("USER_ID NOT IN (".$notDelUserId.")");
  346. CalcBonusGL::deleteAll("USER_ID NOT IN (".$notDelUserId.")");
  347. CalcBonusQY::deleteAll("USER_ID NOT IN (".$notDelUserId.")");
  348. CalcBonusYC::deleteAll("USER_ID NOT IN (".$notDelUserId.")");
  349. FlowBonus::deleteAll("USER_ID NOT IN (".$notDelUserId.")");
  350. FlowReconsumePoints::deleteAll("USER_ID NOT IN (".$notDelUserId.")");
  351. PerfPeriod::deleteAll("USER_ID NOT IN (".$notDelUserId.")");
  352. PerfMonth::deleteAll("USER_ID NOT IN (".$notDelUserId.")");
  353. DecOrder::deleteAll("TO_USER_ID NOT IN (".$notDelUserId.")");
  354. UserBonus::deleteAll();
  355. echo '删除完成'.PHP_EOL;
  356. }
  357. /**
  358. * 清空所有会员
  359. */
  360. public function actionClearAllUser(){
  361. UserInfo::deleteAll();
  362. UserNetwork::deleteAll();
  363. UserRelation::deleteAll();
  364. User::deleteAll();
  365. CalcBonus::deleteAll();
  366. CalcBonusBD::deleteAll();
  367. CalcBonusTG::deleteAll();
  368. CalcBonusYJ::deleteAll();
  369. CalcBonusGX::deleteAll();
  370. CalcBonusGL::deleteAll();
  371. CalcBonusQY::deleteAll();
  372. CalcBonusYC::deleteAll();
  373. FlowBonus::deleteAll();
  374. FlowReconsumePoints::deleteAll();
  375. PerfPeriod::deleteAll();
  376. PerfMonth::deleteAll();
  377. DecOrder::deleteAll();
  378. UserBonus::deleteAll();
  379. echo '删除完成'.PHP_EOL;
  380. }
  381. /**
  382. * 清空结算的奖金
  383. */
  384. public function actionClearBonus(){
  385. CalcBonus::deleteAll();
  386. CalcBonusBD::deleteAll();
  387. CalcBonusTG::deleteAll();
  388. CalcBonusYJ::deleteAll();
  389. CalcBonusGX::deleteAll();
  390. CalcBonusGL::deleteAll();
  391. CalcBonusQY::deleteAll();
  392. CalcBonusYC::deleteAll();
  393. FlowBonus::deleteAll();
  394. FlowReconsumePoints::deleteAll();
  395. PerfPeriod::deleteAll();
  396. PerfMonth::deleteAll();
  397. echo '删除完成'.PHP_EOL;
  398. }
  399. /**
  400. * 清空会员的网络
  401. */
  402. public function actionClearNetRedis(){
  403. \Yii::$app->redis->del(Cache::USER_NETWORK_PARENTS);
  404. \Yii::$app->redis->del(Cache::USER_RELATION_PARENTS);
  405. echo '全部完成'.PHP_EOL;
  406. }
  407. public function actionLoopUser($offset = 0){
  408. $query = UserInfo::findUseDbCalc()->select('USER_ID,USER_NAME,ZC_PV,CON_UID,REC_UID,CON_NUM,REC_NUM,NETWORK_DEEP,RELATION_DEEP,STORE_TYPE,PERIOD_NUM,CREATED_AT,UPDATED_AT')->where('1=1')->orderBy('NETWORK_DEEP DESC')->offset($offset)->limit(100)->asArray()->all();
  409. if($query){
  410. foreach($query as $data){
  411. echo($data['USER_NAME'].PHP_EOL);
  412. }
  413. $this->actionLoopUser($offset + 100);
  414. }
  415. exit();
  416. }
  417. public function actionLoopUserTwo(){
  418. // $query = UserInfo::findUseDbCalc()->select('USER_ID,USER_NAME,ZC_PV,CON_UID,REC_UID,CON_NUM,REC_NUM,NETWORK_DEEP,RELATION_DEEP,STORE_TYPE,PERIOD_NUM,CREATED_AT,UPDATED_AT')->where('1=1')->orderBy('NETWORK_DEEP DESC')->asArray();
  419. //
  420. // foreach($query->batch() as $allData){
  421. // foreach($allData as $data){
  422. // echo($data['USER_NAME'].PHP_EOL);
  423. // }
  424. // }
  425. //
  426. // exit();
  427. // $test=(new \yii\db\Query());
  428. // $test->from('AR_USER_INFO');
  429. // $reader=$test->prepare(\Yii::$app->db->queryBuilder)->createCommand()->query();
  430. // while ($row = $reader->read()) {
  431. // print_r($row);
  432. // }
  433. $query = (new Query())->from('{{%USER_INFO}}')->prepare(\Yii::$app->db->queryBuilder)->where('1=1');
  434. // while ($row = $query->read()) {
  435. // print_r($row['USER_NAME'].PHP_EOL);
  436. // }
  437. try {
  438. foreach($query->batch() as $allData){
  439. foreach($allData as $data){
  440. echo($data['USER_NAME'].PHP_EOL);
  441. }
  442. }
  443. } catch (\PDOException $e){
  444. print_r($e->getMessage());
  445. }
  446. }
  447. /**
  448. * 循环加入报单
  449. * @throws \yii\db\Exception
  450. */
  451. public function actionLoopAddDec(){
  452. // 获取最底层的100名会员
  453. $allUser = UserInfo::find()->where('1=1')->limit(100)->orderBy('NETWORK_DEEP DESC')->asArray()->all();
  454. $insertData = [];
  455. $decSn = 190310000000;
  456. foreach($allUser as $key=>$user){
  457. $decSn += 1;
  458. $decPv = rand(1, 100) * 1000;
  459. $insertData[] = [
  460. 'DEC_SN' => 'D'.$decSn.'0000',
  461. 'ORDER_SN' => $decSn,
  462. 'USER_ID' => $user['USER_ID'],
  463. 'TYPE' => 'ZC',
  464. 'TO_USER_ID' => $user['USER_ID'],
  465. 'DEC_AMOUNT' => $decPv,
  466. 'DEC_PV' => $decPv,
  467. 'PAID_WALLET' => 'bill',
  468. 'PERIOD_NUM' => 121,
  469. 'IS_DEL' => 0,
  470. 'P_CALC_MONTH' => Date::ociToDate(202001, Date::OCI_TIME_FORMAT_SHORT_MONTH),
  471. 'CREATED_AT' => strtotime('2020-01-20'),
  472. 'DEC_ID' => $user['REC_UID'],
  473. ];
  474. }
  475. DecOrder::batchInsert($insertData);
  476. echo('全部完成'.PHP_EOL);
  477. }
  478. /**
  479. * 清空报单
  480. */
  481. public function actionClearDec(){
  482. DecOrder::deleteAll('PERIOD_NUM = 100');
  483. echo('删除完成'.PHP_EOL);
  484. }
  485. /**
  486. * 测试rpc接口
  487. * @throws Exception
  488. */
  489. public function actionRpcCli(){
  490. // $data = [
  491. // ['type' => 'ZC', 'userId' => '670B84FD7C216D4EE055736AECE8644D', 'toUserId'=>'dec001', 'decPv' => '5000', 'insertUserName' => 'dec001', 'conUserName' => 'tester005', 'recUserName' => 'tester003', 'location' => 1],
  492. // ['type' => 'ZC', 'userId' => '670B84FD7C216D4EE055736AECE8644D', 'toUserId'=>'dec002', 'decPv' => '5000', 'insertUserName' => 'dec002', 'conUserName' => 'tester003', 'recUserName' => 'tester003', 'location' => 2],
  493. // ['type' => 'ZC', 'userId' => '670B84FD7C216D4EE055736AECE8644D', 'toUserId'=>'dec003', 'decPv' => '5000', 'insertUserName' => 'dec003', 'conUserName' => 'tester003', 'recUserName' => 'tester003', 'location' => 3],
  494. // ['type' => 'ZC', 'userId' => '670B84FD7C216D4EE055736AECE8644D', 'toUserId'=>'dec004', 'decPv' => '5000', 'insertUserName' => 'dec004', 'conUserName' => 'dec001', 'recUserName' => 'tester003', 'location' => 1],
  495. // ['type' => 'ZC', 'userId' => '670B84FD7C216D4EE055736AECE8644D', 'toUserId'=>'dec005', 'decPv' => '5000', 'insertUserName' => 'dec005', 'conUserName' => 'dec001', 'recUserName' => 'tester003', 'location' => 2],
  496. // ['type' => 'ZC', 'userId' => '670B84FD7C216D4EE055736AECE8644D', 'toUserId'=>'dec006', 'decPv' => '5000', 'insertUserName' => 'dec006', 'conUserName' => 'dec001', 'recUserName' => 'tester003', 'location' => 3],
  497. // ];
  498. // $data = array (
  499. // 0 =>
  500. // array (
  501. // 'type' => 'ZC',
  502. // 'userId' => 'B322C18F7E274A9D9FC5DADC3B385E8B',
  503. // 'toUserId' => '6B2869C5958446CAB479CF1A5D9E3763',
  504. // 'decPv' => '705',
  505. // 'insertUserName' => 'b80346267',
  506. // 'insertUserIdCard' => '130302199905051113',
  507. // 'conUserName' => 'b90556236',
  508. // 'recUserName' => 'tester002',
  509. // 'location' => '1',
  510. // ),
  511. // 1 =>
  512. // array (
  513. // 'type' => 'ZC',
  514. // 'userId' => 'B322C18F7E274A9D9FC5DADC3B385E8B',
  515. // 'toUserId' => '940644BC1C2D41F392EA0EDCB4354F55',
  516. // 'decPv' => '875',
  517. // 'insertUserName' => 'b27486502',
  518. // 'insertUserIdCard' => '130302199905051113',
  519. // 'conUserName' => 'b80346267',
  520. // 'recUserName' => 'tester002',
  521. // 'location' => '1',
  522. // ),
  523. // 2 =>
  524. // array (
  525. // 'type' => 'ZC',
  526. // 'userId' => 'B322C18F7E274A9D9FC5DADC3B385E8B',
  527. // 'toUserId' => '854E59FE17494633A853872C878B93D7',
  528. // 'decPv' => '1405',
  529. // 'insertUserName' => 'b76328656',
  530. // 'insertUserIdCard' => '130302199905051113',
  531. // 'conUserName' => 'b80346267',
  532. // 'recUserName' => 'b27486502',
  533. // 'location' => '2',
  534. // ),
  535. // );
  536. $data = [
  537. [
  538. 'type' => 'ZC',
  539. 'userId' => '3C313C66D1724D658BF10B08194022BB',
  540. 'toUserId' => '',
  541. 'decPv' => '3000',
  542. 'insertUserName' => 'b27251926',
  543. 'conUserName' => 'b83825142',
  544. 'recUserName' => 'b92223569',
  545. 'location' => '1',
  546. 'insertUserIdCard' => '110227196504215915',
  547. ],
  548. [
  549. 'type' => 'ZC',
  550. 'userId' => '3C313C66D1724D658BF10B08194022BB',
  551. 'toUserId' => '',
  552. 'decPv' => 12000.0,
  553. 'insertUserName' => 'b86268542',
  554. 'conUserName' => 'b92223569',
  555. 'recUserName' => 'b27251926',
  556. 'location' => '2',
  557. 'insertUserIdCard' => '110227196504215915',
  558. ],
  559. ];
  560. $condition = [
  561. 'namespace' => '\\'.RPCApi::class.'::api',
  562. 'param' => [
  563. 'class'=> '\\'.DeclarationLoopForm::class,
  564. 'fields'=>[
  565. 'scenario' => 'canDec',
  566. 'data' => $data,
  567. ],
  568. 'action'=>'validate',
  569. 'param'=>[],
  570. ],
  571. ];
  572. $rpcApi = new RPCApi();
  573. if($result = $rpcApi->request($condition)){
  574. var_dump($result);
  575. } else {
  576. var_dump($rpcApi->getError());
  577. }
  578. }
  579. /**
  580. * 发票识别
  581. */
  582. public function actionOcr(){
  583. $result = OcrApi::instance()->vatInvoice('/Volumes/HDD/Downloads/vatInvoice.jpg');
  584. print_r($result);
  585. }
  586. /**
  587. * 备份数据库测试
  588. * @throws \yii\db\Exception
  589. */
  590. public function actionBakData(){
  591. DataBak::backup(142);
  592. }
  593. /**
  594. * 测试短信发送(可协程发送)
  595. */
  596. public function actionSendSms(){
  597. $params = [
  598. 'mobiles' => '19933643193',
  599. 'content' => '测试短息,您好',
  600. ];
  601. SmsApi::instance()->clearError();
  602. for($i=0;$i<10;$i++){
  603. SmsApi::instance()->goSend($params);
  604. }
  605. print_r(SmsApi::instance()->getError());
  606. }
  607. /**
  608. * 测试绑定
  609. * @throws \yii\db\Exception
  610. */
  611. public function actionBind(){
  612. UserBind::autoBind('9AC80FF809B04EED96321D34CBA0EAA9','32132419900307929X');
  613. }
  614. /**
  615. * 测试任务队列
  616. */
  617. public function actionTaskQueue(){
  618. if(Queue::instance()->addTask(Queue::TYPE_FUNC, TaskFunc::class.'::testTaskQueue', [], Queue::LOOP_TYPE_DAY, '16:39:00', 2)){
  619. echo('任务添加成功'.PHP_EOL);
  620. } else {
  621. echo('任务添加失败'.PHP_EOL);
  622. }
  623. }
  624. public function actionMsg(){
  625. $r=Reconsume::getUserReconsumePool("8C5E7DEB93767021E053693418ACB2B6");
  626. }
  627. public function actionGenerateId() {
  628. for($i=1;$i<=10;$i++) {
  629. echo SnowFake::instance()->generateId() . PHP_EOL;
  630. }
  631. }
  632. public function actionShow() {
  633. $a4Uid = '76202856516030464';
  634. $data = CalcCache::bonus($a4Uid, 104);
  635. print_r($data);die;
  636. }
  637. public function actionLoopAllUsers($findUid='76193630875947008', $periodNum=105, $offset = 0)
  638. {
  639. // 从缓存列表里面从底层往上倒序获取会员
  640. $allData = CalcCache::getUsers($periodNum, $offset, 100);
  641. if($allData) {
  642. foreach($allData as $userId){
  643. // echo sprintf("userId:%s", $userId) . PHP_EOL;
  644. if( $userId === $findUid ) {
  645. echo "find user" . $findUid . PHP_EOL;
  646. // $data = CalcCache::bonus($findUid, 104);
  647. // var_dump($data);die;
  648. }
  649. unset($userId);
  650. }
  651. unset($allData);
  652. return $this->actionLoopAllUsers($findUid, $periodNum, $offset + 100);
  653. }
  654. return true;
  655. }
  656. public function actionLoopAllPerfUser($offset=0, $periodNum=103, $limit=1000) {
  657. $allData = CalcCache::getHasPerfUsers($periodNum, $offset, $limit);
  658. if ($allData) {
  659. foreach ($allData as $userId) {
  660. $user = User::find()->select(["USER_NAME"])->where('ID=:ID', ['ID'=>$userId])->asArray()->all();
  661. if( !$user ) {
  662. echo $userId . PHP_EOL;
  663. }
  664. }
  665. $this->actionLoopAllPerfUser($offset+$limit, $periodNum, $limit);
  666. }
  667. }
  668. public function actionLoopAllGxUser($offset=0, $periodNum=105, $limit=1000) {
  669. return false;
  670. $allData = CalcBonus::find()->select(["ID", "USER_ID", "ORI_BONUS_GX"])->where("PERIOD_NUM=:PERIOD_NUM", ["PERIOD_NUM"=>$periodNum])->offset($offset)->limit($limit)->asArray()->all();
  671. if ($allData) {
  672. foreach ($allData as $everyData) {
  673. if( $everyData['ORI_BONUS_GX'] <= 0 ) continue;
  674. $list = CalcBonusGX::find()->select(['ID', 'USER_ID', 'ORI_BONUS'])->where('USER_ID=:USER_ID AND PERIOD_NUM=:PERIOD_NUM', [
  675. 'USER_ID' => $everyData['USER_ID'],
  676. 'PERIOD_NUM' => $periodNum,
  677. ])->asArray()->all();
  678. if( count($list) <= 1) {
  679. unset($list);
  680. continue;
  681. }
  682. //删除一条
  683. $firstData = array_shift($list);
  684. if( $firstData['ORI_BONUS'] != $everyData['ORI_BONUS_GX'] ) {
  685. //修改奖金
  686. echo 'ID:' . $everyData['ID'] . '奖金:' . $everyData['ORI_BONUS_GX'] . '修改为:' . $firstData['ORI_BONUS'] . PHP_EOL;
  687. CalcBonus::updateAll(['ORI_BONUS_GX'=>$firstData['ORI_BONUS']], 'ID=:ID', [
  688. 'ID' => $everyData['ID'],
  689. ]);
  690. }
  691. //删除其它记录
  692. foreach ($list as $deleteData) {
  693. echo '删除记录为:' . $deleteData['ID'] . PHP_EOL;
  694. CalcBonusGX::deleteAll('ID=:ID', ['ID'=>$deleteData['ID']]);
  695. unset($deleteData);
  696. }
  697. unset($everyData, $list, $firstData);
  698. }
  699. unset($allData);
  700. $this->actionLoopAllGxUser($offset+$limit, $periodNum, $limit);
  701. }
  702. }
  703. public function actionLoopAllGxUserTwo($offset=0, $periodNum=105, $limit=1000) {
  704. return false;
  705. $allData = CalcBonusGX::find()->select(['ID', 'USER_ID', 'ORI_BONUS', 'AMOUNT', 'RECONSUME_POINTS', 'MANAGE_TAX'])->where('PERIOD_NUM=:PERIOD_NUM', [
  706. 'PERIOD_NUM' => $periodNum,
  707. ])->offset($offset)->limit($limit)->asArray()->all();
  708. if ($allData) {
  709. foreach ($allData as $everyData) {
  710. $oneData = CalcBonus::find()->select(["ID", "USER_ID", "BONUS_GX", "RECONSUME_POINTS", "MANAGE_TAX", "BONUS_TOTAL"])->where('USER_ID=:USER_ID AND PERIOD_NUM=:PERIOD_NUM', [
  711. 'USER_ID' => $everyData['USER_ID'],
  712. 'PERIOD_NUM' => $periodNum,
  713. ])->asArray()->one();
  714. if( $oneData['BONUS_GX'] != $everyData['AMOUNT'] ) {
  715. //修改奖金
  716. echo 'ID:' . $oneData['ID'] . '奖金:' . $oneData['BONUS_GX'] . '修改为:' . $everyData['AMOUNT'] . PHP_EOL;
  717. // echo 'RECONSUME_POINTS:' . ($oneData['RECONSUME_POINTS']-$everyData['RECONSUME_POINTS']) . 'MANAGE_TAX:' . ($oneData['MANAGE_TAX']-$everyData['MANAGE_TAX']) . PHP_EOL;
  718. CalcBonus::updateAll([
  719. 'BONUS_GX'=>$everyData['AMOUNT'],
  720. 'RECONSUME_POINTS'=>$oneData['RECONSUME_POINTS']-$everyData['RECONSUME_POINTS'],
  721. 'MANAGE_TAX'=>$oneData['MANAGE_TAX']-$everyData['MANAGE_TAX'],
  722. 'BONUS_TOTAL'=>$oneData['BONUS_TOTAL']-$everyData['ORI_BONUS'],
  723. ], 'ID=:ID', [
  724. 'ID' => $oneData['ID'],
  725. ]);
  726. }
  727. unset($everyData, $oneData);
  728. }
  729. unset($allData);
  730. $this->actionLoopAllGxUserTwo($offset+$limit, $periodNum, $limit);
  731. }
  732. }
  733. /**
  734. * 导入结余业绩
  735. * @param int $periodNum
  736. */
  737. public function actionAddSurplusData($periodNum=107) {
  738. $allCount = PerfPeriod::find()->where('PERIOD_NUM=:PERIOD_NUM', ['PERIOD_NUM'=>$periodNum])->count('ID');
  739. $pageSize = 1000;
  740. $pageCount = ceil($allCount/$pageSize);
  741. unset($allCount);
  742. for($page=1;$page<=$pageCount;$page++){
  743. echo sprintf('导入【%d】期结余业绩,总页数为【%d】,当前页数为【%d】' . PHP_EOL, $periodNum, $pageCount, $page);
  744. $perfPeriodData = PerfPeriod::find()->select(['USER_ID', 'SURPLUS_1L', 'SURPLUS_2L', 'SURPLUS_3L', 'SURPLUS_4L', 'SURPLUS_5L'])->where('PERIOD_NUM=:PERIOD_NUM', ['PERIOD_NUM'=>$periodNum])->orderBy('ID ASC')->offset(($page-1)*$pageSize)->limit($pageSize)->asArray()->all();
  745. foreach ($perfPeriodData as $data) {
  746. UserPerf::updateAll([
  747. 'SURPLUS_1L' => $data['SURPLUS_1L'],
  748. 'SURPLUS_2L' => $data['SURPLUS_2L'],
  749. 'SURPLUS_3L' => $data['SURPLUS_3L'],
  750. 'SURPLUS_4L' => $data['SURPLUS_4L'],
  751. 'SURPLUS_5L' => $data['SURPLUS_5L'],
  752. ], 'USER_ID=:USER_ID', [':USER_ID' => $data['USER_ID']]);
  753. unset($data);
  754. }
  755. unset($perfPeriodData);
  756. }
  757. }
  758. public function actionAddLastSurplus()
  759. {
  760. $data = [
  761. 'A10505648'=>360,
  762. 'D86714213'=>120,
  763. 'F10401034'=>120,
  764. 'A16768918'=>360,
  765. 'H72700605'=>720,
  766. 'H19166726'=>550,
  767. 'H38585848'=>360,
  768. 'A18950413'=>1560,
  769. 'H87620691'=>120,
  770. 'E10242995'=>426,
  771. 'Eh78786514'=>124,
  772. 'E14356640'=>120,
  773. 'E12757473'=>360,
  774. 'A19273920'=>240,
  775. 'H10164357'=>120,
  776. ];
  777. foreach ($data as $username=>$perf) {
  778. $user = User::find()->select(['ID'])->where('USER_NAME=:USER_NAME', [
  779. 'USER_NAME' => $username
  780. ])->asArray()->one();
  781. UserPerf::updateAll([
  782. 'SURPLUS_2L' => $perf,
  783. ], 'USER_ID=:USER_ID', [':USER_ID' => $user['ID']]);
  784. unset($username, $perf);
  785. }
  786. echo 'OK' . PHP_EOL;
  787. }
  788. public function actionBackup() {
  789. DataBak::backup(105);
  790. }
  791. /**
  792. * 结算最后一步写数据
  793. * @param int $periodNum
  794. * @throws \yii\db\Exception
  795. */
  796. public function actionCalcWriteDb($periodNum=108) {
  797. // 周业绩
  798. // PerfPeriod::pageDeleteAll('PERIOD_NUM='.$periodNum);
  799. // // 奖金表
  800. // CalcBonus::pageDeleteAll('PERIOD_NUM='.$periodNum);
  801. //
  802. // $calcWrite = new CalcWrite();
  803. // $calcWrite->start($periodNum);
  804. Period::updateAll(['IS_CALCING' => 0, 'IS_CALCULATED' => Period::CALCULATE_FINISH, 'CALCULATED_AT' => Date::nowTime(), 'CALC_PERCENT' => 100], 'PERIOD_NUM=:PERIOD_NUM', [':PERIOD_NUM' => $periodNum]);
  805. }
  806. /**
  807. * 计算某一期的聘级
  808. * @param $periodNum
  809. * @return string
  810. * @throws Exception
  811. * @throws \yii\db\Exception
  812. */
  813. public function actionCalcEmpLevel($periodNum) {
  814. $bonusCalc = PerfCalc::instance();
  815. $bonusCalc->setPeriodNum($periodNum);
  816. $bonusCalc->initCalcTask();
  817. $bonusCalc->loopCalcEmpLevel();
  818. return 'ok' . PHP_EOL;
  819. }
  820. /**
  821. * 计算某一期的聘级
  822. * @param $periodNum
  823. * @return string
  824. * @throws Exception
  825. * @throws \yii\db\Exception
  826. */
  827. public function actionCheckVipBonus($periodNum) {
  828. $bonusCalc = BonusCalc::instance();
  829. $bonusCalc->setPeriodNum($periodNum);
  830. $bonusCalc->initCalcTask();
  831. $bonusCalc->calcBonusVIP();
  832. return 'ok' . PHP_EOL;
  833. }
  834. /**
  835. * 检测共享奖
  836. * @param $periodNum
  837. * @return string
  838. * @throws \yii\db\Exception
  839. */
  840. public function actionCheckShareBonus($periodNum) {
  841. $bonusCalc = BonusCalc::instance();
  842. $bonusCalc->setPeriodNum($periodNum);
  843. $bonusCalc->initCalcTask();
  844. $bonusCalc->calcBonusGXBefore();
  845. return 'ok' . PHP_EOL;
  846. }
  847. /**
  848. * 修正导入数据的报单中心ID
  849. * @param int $startPage
  850. * @param int $limit
  851. * @return bool
  852. */
  853. public function actionFixImportDecId($startPage=1, $limit = 1000) {
  854. $numCount = TmpOldNetwork::find()->where("1=1")->orderBy("ID ASC")->count("ID");
  855. $pageCount = ceil($numCount/$limit);
  856. for ($page=$startPage;$page<=$pageCount;$page++) {
  857. $pageList = TmpOldNetwork::find()->where("1=1")->orderBy("ID ASC")->limit($limit)->offset(($page - 1) * $limit)->asArray()->all();
  858. foreach ($pageList as $pageData) {
  859. User::updateAll(['DEC_ID'=>'670B84FD7C216D4EE055736AECE8644D'], 'USER_NAME=:USER_NAME', ['USER_NAME'=>$pageData['USER_NAME']]);
  860. unset($pageData);
  861. }
  862. unset($pageList);
  863. echo sprintf("修改所属报单中心,总页数【%s】,当前页数:【%s】写入成功".PHP_EOL, $pageCount, $page);
  864. }
  865. unset($numCount, $pageCount, $page, $startPage, $limit);
  866. return true;
  867. }
  868. /**
  869. *
  870. * 环循所有会员找到错误的数据
  871. * @param int $periodNum
  872. * @param int $offset
  873. * @return bool
  874. */
  875. public function actionLoopAllUsersForError($periodNum=115, $offset = 0)
  876. {
  877. echo '当前offset:' . $offset . PHP_EOL;
  878. // 从缓存列表里面从底层往上倒序获取会员
  879. $allData = CalcCache::getUsers($periodNum, $offset, 1000);
  880. if($allData) {
  881. foreach($allData as $userId){
  882. // 获取到级别以后,给上级的相应人数中追加数量
  883. $parentRecUserId = $userId;
  884. $this->loopRelationParentDo($userId, function ($parent) use ($periodNum, &$parentRecUserId) {
  885. //判断$parentRecUserId是否为$parent['PARENT_UID']的直推
  886. $parentUid = $parent['PARENT_UID'];
  887. $toInfo = CalcCache::getUserInfo($parentRecUserId, $periodNum);
  888. if( !isset($toInfo['REC_UID']) ) {
  889. echo '错误数据:' . $parentRecUserId . PHP_EOL;
  890. }
  891. if( isset($toInfo['REC_UID']) && $parentUid !== $toInfo['REC_UID'] ) {
  892. $parentUid = $toInfo['REC_UID'];
  893. }
  894. unset($toInfo);
  895. if( !$parentUid ) return 1;
  896. //每次记录上次的USER_ID
  897. $parentRecUserId = $parentUid;
  898. });
  899. unset($userId);
  900. }
  901. unset($allData);
  902. return $this->actionLoopAllUsersForError($periodNum, $offset + 1000);
  903. }
  904. return true;
  905. }
  906. /**
  907. * 循环推荐网络的父级
  908. * @param $userId
  909. * @param callable $callbackFunc
  910. * @param int $offset
  911. * @return bool
  912. */
  913. public function loopRelationParentDo($userId, callable $callbackFunc, int $offset = 0) {
  914. $allParents = Cache::getAllRelationParents($userId);
  915. $allData = array_slice($allParents, $offset, 1000);
  916. unset($allParents);
  917. if ($allData) {
  918. foreach ($allData as $data) {
  919. $funcResult = $callbackFunc($data);
  920. if ($funcResult === 1) {
  921. return true;
  922. } elseif ($funcResult === 2) {
  923. continue;
  924. }
  925. unset($data, $funcResult);
  926. }
  927. unset($allData);
  928. return $this->loopRelationParentDo($userId, $callbackFunc, $offset + 1000);
  929. }
  930. return true;
  931. }
  932. /**
  933. * 循环父级并执行回调函数
  934. * @param $userId
  935. * @param callable $callbackFunc
  936. * @param int $offset
  937. * @return bool
  938. */
  939. public function loopNetworkParentDo($userId, callable $callbackFunc, int $offset = 0) {
  940. $allParents = Cache::getAllNetworkParents($userId);
  941. $allData = array_slice($allParents, $offset, 1000);
  942. unset($allParents);
  943. if ($allData) {
  944. foreach ($allData as $data) {
  945. $funcResult = $callbackFunc($data);
  946. if ($funcResult === 1) {
  947. return true;
  948. } elseif ($funcResult === 2) {
  949. continue;
  950. }
  951. unset($data, $funcResult);
  952. }
  953. unset($allData);
  954. return $this->loopNetworkParentDo($userId, $callbackFunc, $offset + 1000);
  955. }
  956. return true;
  957. }
  958. /**
  959. * 计算某人某一期的聘级
  960. * @param $userId
  961. * @param $periodNum
  962. * @return string
  963. * @throws Exception
  964. * @throws \yii\db\Exception
  965. */
  966. public function actionCheckUserEmpLevel($userId, $periodNum) {
  967. $bonusCalc = PerfCalc::instance();
  968. $bonusCalc->setPeriodNum($periodNum);
  969. $bonusCalc->initCalcTask();
  970. $nowMonthPerf = CalcCache::nowMonthPerf($userId, $periodNum);
  971. var_dump($nowMonthPerf);
  972. $empLevelData = $bonusCalc->isEmpLevel1($userId, $nowMonthPerf);
  973. var_dump($empLevelData);
  974. return 'ok' . PHP_EOL;
  975. }
  976. public function actionCheckYcBonus($userId, $periodNum) {
  977. $empLevelConfig = Cache::getEmpLevelConfig();
  978. $nowMonthPerf = CalcCache::nowMonthPerf($userId, $periodNum);
  979. // $monthPvPss = $nowMonthPerf['PV_PCS'] + $nowMonthPerf['PV_PSS'];
  980. $empLevelId = $nowMonthPerf['EMP_LEVEL'];
  981. $empLevel = $empLevelConfig[$empLevelId];
  982. $rxPercent = $empLevel['RX_PERCENT'] ?? 0;
  983. if( $rxPercent <= 0 ) {
  984. echo 'rxPercent error' . PHP_EOL;
  985. return false;
  986. }
  987. //个人业绩的奖金
  988. $empBonus = $nowMonthPerf['PV_PCS'] * $rxPercent / 100;
  989. //2020-06-05修改荣衔奖的计算方式、不由自己的业绩决定、由直推会员的业绩决定
  990. $childList = CalcCache::getChildrenOneDeepFromRedis($userId, $periodNum);
  991. foreach ($childList as $child) {
  992. $childMaxPercent = CalcCache::ycMaxBonusPercent($child['USER_ID'], $periodNum);
  993. $percentDiff = $rxPercent - $childMaxPercent;
  994. if( $percentDiff <= 0 ) continue;
  995. $childNowMonthPerf = CalcCache::nowMonthPerf($child['USER_ID'], $periodNum);
  996. $childBonus = $childNowMonthPerf['PV_PSS_TOTAL'] * $percentDiff / 100;
  997. $empBonus += $childBonus;
  998. echo sprintf('childUserId:%s,childMaxPercent:%s,childBonus:%s' . PHP_EOL, $child['USER_ID'], $childMaxPercent, $childBonus);
  999. unset($child, $childMaxPercent, $percentDiff, $childNowMonthPerf, $childBonus);
  1000. }
  1001. unset($childList);
  1002. echo sprintf('userId:%s,rxPercent:%s,empBonus:%s' . PHP_EOL, $userId, $rxPercent, $empBonus);
  1003. }
  1004. /**
  1005. * 修正移网业绩错误的问题
  1006. * @return bool
  1007. */
  1008. public function actionFixMoveNetPerf() {
  1009. //获取未结算的月份
  1010. $noSentPeriod = Period::find()->where('IS_SENT=0')->orderBy('PERIOD_NUM ASC')->asArray()->one();
  1011. if( !$noSentPeriod ) return false;
  1012. $thisYearMonth = $noSentPeriod['CALC_YEAR'].Tool::numFix($noSentPeriod['CALC_MONTH'], 2);
  1013. $lastYearMonth = Date::lastMonth($noSentPeriod['CALC_YEAR'].'-'.$noSentPeriod['CALC_MONTH'], 'Ym');
  1014. // $lastYearMonth = '202003';
  1015. echo sprintf("当前期数为:%s,当前结算年月为:%s,上一个结算年月为:%s" . PHP_EOL, $noSentPeriod['PERIOD_NUM'], $thisYearMonth, $lastYearMonth);
  1016. unset($noSentPeriod);
  1017. //找到所有的relation的移网
  1018. $allRelationList = UserMove::find()->where('TYPE=:TYPE', ['TYPE'=>'relation'])->asArray()->all();
  1019. //根据原来的父级、找到所有的原父级
  1020. $lastYearMonthPerf = [
  1021. '86821386802302976'=>960.000,
  1022. '76193537884033024'=>1053.000,
  1023. '76200969452523520'=>1098.000,
  1024. '76193583539032064'=>360.000,
  1025. '76220073806794752'=>4678.400,
  1026. '76218844456292352'=>17825.000,
  1027. '76219777546326016'=>12316.000,
  1028. '76220534563672064'=>6844.000,
  1029. '76220988731297792'=>2680.000,
  1030. '86805887292936192'=>508.000,
  1031. '86803242738126848'=>6688.200,
  1032. '76193502618324992'=>28590.000,
  1033. '86804998209540096'=>0.000,
  1034. '86802876130791424'=>8938.000,
  1035. '76196752000159744'=>436.000,
  1036. '76189559771238400'=>90423.400,
  1037. ];
  1038. foreach ($allRelationList as $moveData) {
  1039. echo sprintf("当前用户ID:%s,原看接点人ID:%s,新接点人ID:%s" . PHP_EOL, $moveData['USER_ID'], $moveData['FROM_UID'], $moveData['TO_UID']);
  1040. if( !isset($lastYearMonthPerf[$moveData['USER_ID']]) || $lastYearMonthPerf[$moveData['USER_ID']] == 0 ) continue;
  1041. //查找移动点位这个人的上个月的累计业绩
  1042. // $lastYearMonthPerf = PerfMonth::find()->where('USER_ID=:USER_ID AND CALC_MONTH=:CALC_MONTH', ['USER_ID'=>$moveData['USER_ID'], 'CALC_MONTH'=>$lastYearMonth])->asArray()->one();
  1043. // echo sprintf("'%s'=>%s," . PHP_EOL, $moveData['USER_ID'], $lastYearMonthPerf['PV_PSS_TOTAL']);
  1044. //本月的已结算业绩
  1045. // $thisPerfPeriodList = PerfPeriod::find()->select(['PV_PCS', 'PERIOD_NUM'])->where('USER_ID=:USER_ID AND CALC_MONTH=:CALC_MONTH', ['USER_ID'=>$moveData['USER_ID'], 'CALC_MONTH'=>$thisYearMonth])->asArray()->all();
  1046. $oldParentList = UserRelation::find()->where('USER_ID=:USER_ID', ['USER_ID'=>$moveData['FROM_UID']])->asArray()->all();
  1047. $oldParentUids = [$moveData['FROM_UID']];
  1048. foreach ($oldParentList as $oldData) {
  1049. $oldParentUids[] = $oldData['PARENT_UID'];
  1050. unset($oldData);
  1051. }
  1052. unset($oldParentList);
  1053. $newParentList = UserRelation::find()->where('USER_ID=:USER_ID', ['USER_ID'=>$moveData['TO_UID']])->asArray()->all();
  1054. $newParentUids = [$moveData['TO_UID']];
  1055. foreach ($newParentList as $newData) {
  1056. $newParentUids[] = $newData['PARENT_UID'];
  1057. unset($newData);
  1058. }
  1059. unset($newParentList);
  1060. //修改上个月的累计业绩
  1061. foreach ($oldParentUids as $oldParentUid) {//减
  1062. PerfMonth::updateAllCounters(['PV_PSS_TOTAL'=>(-1)*$lastYearMonthPerf[$moveData['USER_ID']]], 'USER_ID=:USER_ID AND CALC_MONTH=:CALC_MONTH', ['USER_ID'=>$oldParentUid, 'CALC_MONTH'=>$lastYearMonth]);
  1063. unset($oldParentUid);
  1064. }
  1065. foreach ($newParentUids as $newParentUid) {//加
  1066. PerfMonth::updateAllCounters(['PV_PSS_TOTAL'=>$lastYearMonthPerf[$moveData['USER_ID']]], 'USER_ID=:USER_ID AND CALC_MONTH=:CALC_MONTH', ['USER_ID'=>$newParentUid, 'CALC_MONTH'=>$lastYearMonth]);
  1067. unset($newParentUid);
  1068. }
  1069. //修改本月的已结算业绩
  1070. // foreach ($thisPerfPeriodList as $periodPerf) {
  1071. // if( $periodPerf['PV_PCS'] <= 0 ) continue;
  1072. //
  1073. // foreach ($oldParentUids as $oldParentUid) {//减
  1074. // PerfPeriod::updateAllCounters(['PV_PSS'=>(-1)*$periodPerf['PV_PCS']], 'USER_ID=:USER_ID AND PERIOD_NUM=:PERIOD_NUM', ['USER_ID'=>$oldParentUid, 'PERIOD_NUM'=>$periodPerf['PERIOD_NUM']]);
  1075. // unset($oldParentUid);
  1076. // }
  1077. // foreach ($newParentUids as $newParentUid) {//加
  1078. // PerfPeriod::updateAllCounters(['PV_PSS'=>$periodPerf['PV_PCS']], 'USER_ID=:USER_ID AND PERIOD_NUM=:PERIOD_NUM', ['USER_ID'=>$newParentUid, 'PERIOD_NUM'=>$periodPerf['PERIOD_NUM']]);
  1079. // unset($newParentUid);
  1080. // }
  1081. //
  1082. // unset($periodPerf);
  1083. // }
  1084. unset($moveData);
  1085. }
  1086. unset($allRelationList, $thisYearMonth, $lastYearMonth, $lastYearMonthPerf);
  1087. }
  1088. /**
  1089. * 检测聘级
  1090. * @param $userId
  1091. * @param int $periodNum
  1092. * @throws \yii\db\Exception
  1093. */
  1094. public function actionCheckEmpLevel($userId, $periodNum=115)
  1095. {
  1096. $bonusCalc = PerfCalc::instance();
  1097. $bonusCalc->setPeriodNum($periodNum);
  1098. $bonusCalc->initCalcTask();
  1099. $userInfo = CalcCache::getUserInfo($userId, $periodNum);
  1100. $nowMonthPerf = CalcCache::nowMonthPerf($userId, $periodNum);
  1101. $empLevel = $bonusCalc->checkEmpLevel($userId, $nowMonthPerf, $userInfo['EMP_LV']);
  1102. var_dump($empLevel);
  1103. die;
  1104. }
  1105. /*
  1106. * 清空所有会员的剩余业绩
  1107. */
  1108. public function actionClearSurplusPerf() {
  1109. $allCount = UserPerf::find()->where('1=1')->orderBy('ID ASC')->count('ID');
  1110. $pageSize = 1000;
  1111. $pageCount = ceil($allCount/$pageSize);
  1112. for( $page=1;$page<=$pageCount;$page++ ) {
  1113. echo sprintf('清空所有会员的剩余业绩,总页数为【%d】,当前页数为【%d】' . PHP_EOL, $pageCount, $page);
  1114. $list = UserPerf::find()->where('1=1')->orderBy('ID ASC')->offset(($page-1)*$pageSize)->limit($pageSize)->asArray()->all();
  1115. foreach ($list as $every) {
  1116. UserPerf::updateAll([
  1117. 'SURPLUS_1L' => 0,
  1118. 'SURPLUS_2L' => 0,
  1119. 'SURPLUS_3L' => 0,
  1120. 'SURPLUS_4L' => 0,
  1121. 'SURPLUS_5L' => 0], 'ID=:ID', ['ID'=>$every['ID']]);
  1122. unset($every);
  1123. }
  1124. unset($list);
  1125. }
  1126. }
  1127. /**
  1128. * 手动清空RepairCache
  1129. */
  1130. public function actionClearRepairCache() {
  1131. CalcCache::clearRepairAllCache();
  1132. }
  1133. /**
  1134. * 修正剩余业绩没有记录的错误
  1135. */
  1136. public function actionFixSurplusPerf() {
  1137. $bigPercentPeriod = 116;
  1138. $pageSize = 1000;
  1139. for ($periodNum=111;$periodNum<=118;$periodNum++) {
  1140. $allCount = PerfPeriod::find()->from(PerfPeriod::tableName() . 'AS PP')->select('PP.ID,PP.USER_ID, PP.PV_1L,PP.PV_2L,PP.PV_3L,CBQ.LOGS')->leftJoin(CalcBonusQY::tableName() . ' AS CBQ', 'CBQ.USER_ID=PP.USER_ID AND CBQ.PERIOD_NUM=PP.PERIOD_NUM')->where('PP.PERIOD_NUM=:PERIOD_NUM', [':PERIOD_NUM' => $periodNum])->orderBy('PP.ID ASC')->count();
  1141. $pageCount = ceil($allCount/$pageSize);
  1142. for ($page=1;$page<=$pageCount;$page++) {
  1143. $allData = PerfPeriod::find()->from(PerfPeriod::tableName() . 'AS PP')->select('PP.ID,PP.USER_ID, PP.PV_1L,PP.PV_2L,PP.PV_3L,CBQ.LOGS')->leftJoin(CalcBonusQY::tableName() . ' AS CBQ', 'CBQ.USER_ID=PP.USER_ID AND CBQ.PERIOD_NUM=PP.PERIOD_NUM')->where('PP.PERIOD_NUM=:PERIOD_NUM', [':PERIOD_NUM' => $periodNum])->orderBy('PP.ID ASC')->offset(($page-1)*$pageSize)->limit($pageSize)->asArray()->all();
  1144. if( !$allData ) continue;
  1145. foreach ($allData as $everyData) {
  1146. if( $everyData['LOGS'] ) {
  1147. $logData = json_decode($everyData['LOGS'], true);
  1148. $surplusData = $logData['touchPerfArr'];
  1149. unset($logData);
  1150. }else {
  1151. $surplusData = [
  1152. 'SURPLUS_1L' => $everyData['PV_1L'],
  1153. 'SURPLUS_2L' => $everyData['PV_2L'],
  1154. 'SURPLUS_3L' => $everyData['PV_3L'],
  1155. 'SURPLUS_4L' => 0,
  1156. 'SURPLUS_5L' => 0,
  1157. ];
  1158. }
  1159. //更新当前记录
  1160. PerfPeriod::updateAll($surplusData, 'ID=:ID', ['ID'=>$everyData['ID']]);
  1161. //更新userPerf
  1162. if( $periodNum >= $bigPercentPeriod ) {
  1163. UserPerf::updateAllCounters($surplusData, 'USER_ID=:USER_ID', ['USER_ID'=>$everyData['USER_ID']]);
  1164. }else {
  1165. //@todo 存储到缓存中或新字段里
  1166. CalcCache::setRepairSurplusPerf($everyData['USER_ID'], $surplusData);
  1167. }
  1168. $baseUser = Info::getBaseUserById($everyData['USER_ID']);
  1169. echo sprintf('当前期数:%s,当前用户ID为:%s,用户名为:%s,更新的数为,一区剩余:%s,二区剩余:%s,三区剩余:%s' . PHP_EOL, $periodNum, $everyData['USER_ID'], $baseUser['USER_NAME'], $surplusData['SURPLUS_1L'], $surplusData['SURPLUS_2L'], $surplusData['SURPLUS_3L']);
  1170. unset($everyData, $surplusData, $baseUser);
  1171. }
  1172. unset($allData);
  1173. }
  1174. }
  1175. }
  1176. public function actionTestUpdateEmpLevel()
  1177. {
  1178. $allCount = PerfMonth::find()->where('CALC_MONTH=:CALC_MONTH', ['CALC_MONTH' => '202005'])->count('ID');
  1179. $periodNum = 115;
  1180. $pageSize = 1000;
  1181. $pageCount = ceil($allCount / $pageSize);
  1182. for ($page = 1; $page <= $pageCount; $page++) {
  1183. $list = PerfMonth::find()->where('CALC_MONTH=:CALC_MONTH', ['CALC_MONTH' => '202005'])->offset(($page - 1) * $pageSize)->limit($pageSize)->asArray()->all();
  1184. foreach ($list as $every) {
  1185. $userInfo = CalcCache::getUserInfo($every['USER_ID'], $periodNum);
  1186. //更新月业绩的聘级和用户信息中的聘级
  1187. CalcCache::nowMonthPerf($every['USER_ID'], $periodNum, [
  1188. 'EMP_LEVEL' => $every['LAST_EMP_LV']
  1189. ]);
  1190. if ($userInfo['EMP_LV'] != $every['LAST_EMP_LV']) {
  1191. $userInfo['EMP_LV'] = $every['LAST_EMP_LV'];
  1192. CalcCache::setUserInfo($every['USER_ID'], $periodNum, $userInfo);
  1193. }
  1194. CalcBonus::updateAll(['LAST_EMP_LV' => $every['LAST_EMP_LV']], 'USER_ID=:USER_ID AND PERIOD_NUM=:PERIOD_NUM', ['USER_ID' => $every['USER_ID'], 'PERIOD_NUM' => $periodNum]);
  1195. unset($every, $userInfo);
  1196. }
  1197. unset($list);
  1198. echo sprintf("更新【聘级】数据,总页数【%s】,当前页数:【%s】导入成功" . PHP_EOL, $pageCount, $page);
  1199. }
  1200. }
  1201. /**
  1202. * 修正PSS_TOTAL
  1203. */
  1204. public function actionFixPssTotal() {
  1205. $db = \Yii::$app->db;
  1206. $sql = "SELECT COUNT(ID) as allCount FROM AR_USER_PERF_NEW WHERE 1=1 ORDER BY ID ASC";
  1207. $allCountOne = $db->createCommand($sql)->queryOne();
  1208. $pageSize = 1000;
  1209. $pageCount = ceil($allCountOne['allCount']/$pageSize);
  1210. for($page=1;$page<=$pageCount;$page++) {
  1211. echo sprintf('修正PSS_TOTAL,总页数为【%d】,当前页数为【%d】' . PHP_EOL, $pageCount, $page);
  1212. $offset = ($page-1)*$pageSize;
  1213. $listSql = "SELECT * FROM AR_USER_PERF_NEW WHERE 1=1 ORDER BY ID ASC LIMIT {$pageSize} OFFSET {$offset}";
  1214. $list = $db->createCommand($listSql)->queryAll();
  1215. foreach ($list as $every) {
  1216. //更新pss_total
  1217. UserPerf::updateAll(['PV_PSS'=>$every['PV_PSS_TOTAL'], 'PV_PSS_TOTAL'=>$every['PV_PSS_TOTAL']], 'USER_ID=:USER_ID', ['USER_ID'=>$every['USER_ID']]);
  1218. //更新perf_month
  1219. PerfMonth::updateAll(['PV_PSS_TOTAL'=>$every['PV_PSS_TOTAL']], 'USER_ID=:USER_ID AND CALC_MONTH=:CALC_MONTH', ['USER_ID'=>$every['USER_ID'], 'CALC_MONTH'=>'202006']);
  1220. unset($every);
  1221. }
  1222. }
  1223. }
  1224. public function actionCheckRepairUser($offset, $limit=1000) {
  1225. $allData = CalcCache::getHasRepairPerfUsers($offset, $limit);
  1226. if ($allData) {
  1227. foreach ($allData as $userId) {
  1228. if( $userId === '102239880700104704' ) {
  1229. echo 'OK' . PHP_EOL;
  1230. }
  1231. }
  1232. $this->actionCheckRepairUser($offset+$limit);
  1233. }
  1234. echo 'END' . PHP_EOL;
  1235. }
  1236. /**
  1237. * 在数据库查询注册的前7人
  1238. * @param int $limit
  1239. */
  1240. public function actionCheckGxCreateAt($limit=7)
  1241. {
  1242. $userId = '110188471594913792';
  1243. $list = UserInfo::findUseDbCalc()->select('USER_ID')->where('USER_ID>:USER_ID', [
  1244. 'USER_ID' => $userId,
  1245. ])->orderBy('USER_ID ASC')->limit($limit)->asArray()->all();
  1246. foreach ($list as $every) {
  1247. echo $every['USER_ID'] . PHP_EOL;
  1248. }
  1249. }
  1250. public function actionRelationList($userId) {
  1251. $this->loopRelationParentDo($userId, function ($parent) {
  1252. $parentUid = $parent['PARENT_UID'];
  1253. echo $parentUid . PHP_EOL;
  1254. });
  1255. }
  1256. /**
  1257. * 检测用户服务奖金
  1258. * @param string $userId
  1259. * @param int $periodNum
  1260. * @throws \yii\db\Exception
  1261. */
  1262. public function actionCheckUserBdQyBonus($userId='', $periodNum=125) {
  1263. // 从缓存中获取会员的业绩信息
  1264. $perfData = CalcCache::nowPeriodPerf($userId, $periodNum);
  1265. // 从缓存中获取会员的上期结余业绩信息
  1266. $pervSurplusPerf = CalcCache::surplusPerf($userId, $periodNum);
  1267. // 本期 + 上期结余
  1268. $perfArr = [
  1269. 'SURPLUS_1L_ZC' => $perfData['PV_1L_ZC'] + $pervSurplusPerf['SURPLUS_1L_ZC'],
  1270. 'SURPLUS_2L_ZC' => $perfData['PV_2L_ZC'] + $pervSurplusPerf['SURPLUS_2L_ZC'],
  1271. 'SURPLUS_3L_ZC' => $perfData['PV_3L_ZC'] + $pervSurplusPerf['SURPLUS_3L_ZC'],
  1272. 'SURPLUS_4L_ZC' => $perfData['PV_4L_ZC'] + $pervSurplusPerf['SURPLUS_4L_ZC'],
  1273. 'SURPLUS_5L_ZC' => $perfData['PV_5L_ZC'] + $pervSurplusPerf['SURPLUS_5L_ZC'],
  1274. ];
  1275. $oriPerfArr = [
  1276. 'perfArr' => $perfArr,
  1277. 'touchBonus' => 0,
  1278. ];
  1279. // 获取会员的报单级别
  1280. $userBaseInfo = CalcCache::getUserInfo($userId, $periodNum);
  1281. $decLevelConfig = Cache::getDecLevelConfig();
  1282. // 对碰
  1283. $touchBonusArr = $this->touchPerf($oriPerfArr, $perfArr, $userBaseInfo['DEC_LV'], $decLevelConfig);
  1284. // $nowDecLevelConfig = $decLevelConfig[$userBaseInfo['DEC_LV']];
  1285. $touchPerfArr = [];
  1286. foreach ($touchBonusArr['perfArr'] as $keyR => $perfR) {
  1287. $touchPerfArr[$keyR] = $perfR;
  1288. }
  1289. var_dump($touchBonusArr);die;
  1290. // 对碰完成后把结余的业绩存入本期业绩缓存中
  1291. if ($touchBonusArr['touchBonus'] <= 0) return;
  1292. $teamBonus = $touchBonusArr['touchBonus'];
  1293. // 把对碰后的奖金存入缓存中
  1294. // CalcCache::bonus($userId, $periodNum, 'BONUS_QY_BD', $teamBonus, [
  1295. // 'reConsumePoints' => 0,
  1296. // 'manageTax' => 0,
  1297. // 'surplus' => $teamBonus,
  1298. // ]);
  1299. unset($perfData, $pervSurplusPerf, $perfArr, $oriPerfArr, $touchPerfArr, $userBaseInfo, $decLevelConfig, $touchBonusArr, $userId, $nowDecLevelConfig, $teamBonus, $deductData);
  1300. }
  1301. /**
  1302. * 对碰
  1303. * @param array $oriPerfArr
  1304. * @param array $perfArr
  1305. * @param $decLevel
  1306. * @param $decLevelConfig
  1307. * @param $loopTimes
  1308. * @return array
  1309. */
  1310. public function touchPerf(array $oriPerfArr, array $perfArr, $decLevel, $decLevelConfig, $loopTimes=1) {
  1311. $resultArr = $oriPerfArr;
  1312. foreach ($perfArr as $keyT => $perfT) {
  1313. if ($perfT <= 0) {
  1314. unset($perfArr[$keyT]);
  1315. }
  1316. }
  1317. if (count($perfArr) >= 2 && $loopTimes < 6) {
  1318. $nowDecLevelConfig = $decLevelConfig[$decLevel];
  1319. arsort($perfArr, SORT_NUMERIC);
  1320. $onePerf = null;
  1321. $oneKey = null;
  1322. // $touchSurplusAmount = 0;
  1323. $touchAmount = 0;
  1324. // 前两个进行对碰
  1325. foreach ($perfArr as $key => $perf) {
  1326. if ($onePerf === null) {
  1327. $oneKey = $key;
  1328. $onePerf = $perf;
  1329. } else {
  1330. $touchSurplusAmount = $perf - $onePerf;
  1331. if ($touchSurplusAmount > 0) {
  1332. unset($perfArr[$oneKey]);
  1333. $resultArr['perfArr'][$oneKey] = 0;
  1334. $perfArr[$key] = $touchSurplusAmount;
  1335. $touchAmount = $onePerf;
  1336. } elseif ($touchSurplusAmount < 0) {
  1337. unset($perfArr[$key]);
  1338. $resultArr['perfArr'][$key] = 0;
  1339. $perfArr[$oneKey] = abs($touchSurplusAmount);
  1340. $touchAmount = $perf;
  1341. } else {
  1342. unset($perfArr[$oneKey], $perfArr[$key]);
  1343. $resultArr['perfArr'][$oneKey] = 0;
  1344. $resultArr['perfArr'][$key] = 0;
  1345. $touchAmount = $perf;
  1346. }
  1347. break;
  1348. }
  1349. }
  1350. /*if ($touchAmount > $nowDecLevelConfig['QY_TOUCH_CAP']) {
  1351. $touchAmount = $nowDecLevelConfig['QY_TOUCH_CAP'];
  1352. }*/
  1353. $touchBonus = Tool::formatPrice($touchAmount * $nowDecLevelConfig['QY_PERCENT'] / 100);
  1354. // if ($touchBonus > $nowDecLevelConfig['QY_TOUCH_CAP']) {
  1355. // $resultArr['touchBonus'] += $nowDecLevelConfig['QY_TOUCH_CAP'];
  1356. // } else {
  1357. // $resultArr['touchBonus'] += $touchBonus;
  1358. // }
  1359. $resultArr['touchBonus'] += $touchBonus;
  1360. foreach ($perfArr as $keyR => $perfR) {
  1361. $resultArr['perfArr'][$keyR] = $perfR;
  1362. }
  1363. return $this->touchPerf($resultArr, $perfArr, $decLevel, $decLevelConfig, $loopTimes+1);
  1364. }
  1365. return $resultArr;
  1366. }
  1367. /**
  1368. * 检测用户报单管理奖奖金
  1369. * @param string $userId
  1370. * @param string $parentUid
  1371. * @param int $periodNum
  1372. * @throws \yii\db\Exception
  1373. */
  1374. public function actionCheckUserBdGlBonus($userId='', $parentUid='', $periodNum=125) {
  1375. //会员信息
  1376. $decLevelConfig = Cache::getDecLevelConfig();
  1377. $netWorkParents = Cache::getAllRelationParents($userId);
  1378. $userBaseInfo = CalcCache::getUserInfo($userId, $periodNum);
  1379. $userEmpLevel = $userBaseInfo['EMP_LV'];
  1380. foreach ($netWorkParents as $netWorkParent) {
  1381. echo '父级ID:' . $netWorkParent['PARENT_UID'] . PHP_EOL;
  1382. //自已距顶端的深度减去父级距顶端的深度
  1383. $diffLayer = $netWorkParent['TOP_DEEP'] - $netWorkParent['PARENT_DEEP'];
  1384. if( $diffLayer <= 0) continue;
  1385. //@todo 超过最大代数就跳出本次循环
  1386. //偶数代跳过
  1387. if( $diffLayer % 2 == 0 ) continue;
  1388. // 获取会员的报单级别
  1389. $bonusUserId = $netWorkParent['PARENT_UID'];
  1390. if( !$bonusUserId ) continue;
  1391. if( $bonusUserId != $parentUid ) continue;
  1392. $bonusUserBaseInfo = CalcCache::getUserInfo($bonusUserId, $periodNum);
  1393. $nowDecLevelConfig = $decLevelConfig[$bonusUserBaseInfo['DEC_LV']];
  1394. if( !$nowDecLevelConfig ) continue;
  1395. //推荐人数
  1396. $recNum = $bonusUserBaseInfo['REC_NUM'];
  1397. if( $recNum <= 0 ) continue;
  1398. if( $recNum == 1 ) {
  1399. $maxOddLayer = $nowDecLevelConfig['GL_ODD_DEEP_ONE'];
  1400. }else if( $recNum == 2 ) {
  1401. $maxOddLayer = $nowDecLevelConfig['GL_ODD_DEEP_TWO'];
  1402. }else {
  1403. $maxOddLayer = $nowDecLevelConfig['GL_ODD_DEEP_THREE'];
  1404. }
  1405. //超过代数上限也跳过
  1406. if( $diffLayer >= 2 * $maxOddLayer ) continue;
  1407. $everyLayer = floor(2 * $nowDecLevelConfig['GL_ODD_DEEP_THREE'] / $nowDecLevelConfig['SORT']);
  1408. //多少代
  1409. // $theLayer = $diffLayer % $everyLayer;
  1410. $theLayerLevel = floor($diffLayer/$everyLayer);
  1411. $parentOddPercentName = sprintf('parentOddPercent_%s', $theLayerLevel);
  1412. if( !isset($this->_sysConfig[$parentOddPercentName]) ) continue;
  1413. $bonusPercent = $this->_sysConfig[$parentOddPercentName]['VALUE'];
  1414. // 从缓存中获取会员的收入信息
  1415. $incomeBonus = CalcCache::bonus($userId, $periodNum);
  1416. $parentOddIncomeFromName = sprintf('parentOddIncomeFrom_%s', $theLayerLevel);
  1417. $parentOddIncomeFrom = explode(',', $this->_sysConfig[$parentOddIncomeFromName]['VALUE']);
  1418. $parentOddIncome = 0;
  1419. foreach ($parentOddIncomeFrom as $incomeType) {
  1420. if( $incomeType === 'TG' ) {
  1421. $incomeTypeName = sprintf('ORI_BONUS_%s', $incomeType);
  1422. }else {
  1423. $incomeTypeName = sprintf('ORI_BONUS_%s_BD', $incomeType);
  1424. }
  1425. $incomeTypeValue = $incomeBonus[$incomeTypeName] ?? 0;
  1426. $parentOddIncome += $incomeTypeValue;
  1427. unset($incomeType, $incomeTypeName, $incomeTypeValue);
  1428. }
  1429. unset($parentOddIncomeFrom);
  1430. $manageBonus = Tool::formatPrice($parentOddIncome * $bonusPercent / 100);
  1431. var_dump($manageBonus);die;
  1432. if ($manageBonus <= 0) continue;
  1433. //总金额限制
  1434. // $manageBonus = $this->bonusTotalLimit($manageBonus, $bonusUserId, $recNum, $bonusUserBaseInfo['ZC_AMOUNT']);
  1435. // if( $manageBonus <= 0 ) continue;
  1436. //扣除相应的复消积分和管理费
  1437. // $deductData = $this->deduct($bonusUserId, $manageBonus);
  1438. // CalcCache::bonus($bonusUserId, $periodNum, 'BONUS_GL', $manageBonus, $deductData, CalcCache::FROM_MEANS_BD);
  1439. //管理奖流水
  1440. unset($netWorkParent, $diffLayer, $bonusUserId, $bonusUserBaseInfo, $bonusPercent, $nowDecLevelConfig, $manageBonus, $incomeBonus, $maxOddLayer, $theLayerLevel, $recNum, $parentOddPercentName, $parentOddIncomeFromName, $deductData);
  1441. }
  1442. unset($userId, $userBaseInfo, $userEmpLevel, $netWorkParents, $decLevelConfig);
  1443. }
  1444. /**
  1445. * 修改总业绩
  1446. */
  1447. public function actionModifyPssTotal() {
  1448. $modifyData = [
  1449. 'Q08186744' => 600.01,
  1450. 'Q62088906' => 150,
  1451. 'Q08480433' => 150,
  1452. 'Q43506253' => 48.75,
  1453. 'Q12863038' => 600.01,
  1454. 'Q78680727' => 41.25,
  1455. 'Q94839185' => 308265.61,
  1456. 'A14938155' => 11206.89,
  1457. 'H779051HD' => 162.5,
  1458. 'D75201679' => 150,
  1459. 'H49297159' => 481.25,
  1460. 'H17118288' => 481.25,
  1461. 'A12336641' => -160,
  1462. 'D18233466' => 157.5,
  1463. 'H19657853' => -1320,
  1464. 'H17219628' => -120,
  1465. 'H10821466' => -1320,
  1466. 'H11050788' => -4920,
  1467. 'H15532405' => -1320,
  1468. 'H65057238' => -360,
  1469. 'H49978401' => -720,
  1470. 'H17767474' => -1260,
  1471. 'F17628577' => -4008,
  1472. 'F17072646' => -359.99,
  1473. 'F59854958' => -240,
  1474. 'F10634375' => -1440,
  1475. 'F17425461' => -120,
  1476. 'F18852157' => -593,
  1477. 'F68846358' => -2301.99,
  1478. 'Q14703000' => -120,
  1479. 'D17865446' => -112,
  1480. 'D16104173' => -119.99,
  1481. 'D19426525' => -360,
  1482. 'D13146869' => -420,
  1483. 'D13336250' => -845,
  1484. 'Q16475055' => -120,
  1485. 'E19911439' => -159,
  1486. 'E17429791' => -166,
  1487. 'E14226349' => -240,
  1488. 'E16315856' => -480,
  1489. 'E18363352' => -240,
  1490. 'E18322188' => -120,
  1491. 'A19477210' => -120,
  1492. 'A13628496791' => -240,
  1493. 'A14488417' => -120,
  1494. 'A15836950' => -120,
  1495. 'E69809425' => -480,
  1496. 'D14193606' => -360,
  1497. 'D13663861' => -120,
  1498. 'D10776466' => -240,
  1499. 'D11736447' => -120,
  1500. 'D13128139' => -725,
  1501. 'D15308257' => -360,
  1502. 'D19443335' => -855,
  1503. 'H16408887' => -960,
  1504. 'H15328699' => -120,
  1505. 'H18951571' => -480,
  1506. 'H15167279' => -480,
  1507. 'H15382316' => -360,
  1508. 'H12129027' => -240,
  1509. 'H15359261' => -840,
  1510. 'H16004849' => -120,
  1511. 'H14711148' => -120,
  1512. 'H14276238' => -240,
  1513. 'H69162532' => -240,
  1514. 'H93297042' => -4680,
  1515. 'H88875817' => -120,
  1516. 'H11847679' => -120,
  1517. 'F90795660' => -3768,
  1518. 'F17797628' => -840,
  1519. 'F17546019' => -473,
  1520. 'F15803008' => -2062,
  1521. 'H10394296' => -960,
  1522. 'E17839915' => -166,
  1523. 'E13466446' => -240,
  1524. 'A16594718' => -240,
  1525. 'A19671826' => -120,
  1526. 'A15198548' => -120,
  1527. 'A51726927' => -2635.98,
  1528. 'H11036379' => -240,
  1529. 'H12907432' => -817.99,
  1530. 'H17973140' => -960,
  1531. 'H12666892' => -600,
  1532. 'H11866173' => -2460,
  1533. 'E10658077' => -120,
  1534. 'E17573755' => -480,
  1535. 'E45944014' => -1184,
  1536. 'E15960537' => -240,
  1537. 'E12683263' => -592,
  1538. 'E11002878' => -360,
  1539. 'E10602731' => -120,
  1540. 'A17081891' => -120,
  1541. 'A18717229' => -835.98,
  1542. 'H11097065' => -1200,
  1543. 'H19578891' => -1080,
  1544. 'H12505489' => -120,
  1545. 'H10746043' => -960,
  1546. 'E12569967' => -120,
  1547. 'H11295941' => -1666,
  1548. 'H59287202' => -120,
  1549. 'H18132610' => -120,
  1550. 'H18113300' => -240,
  1551. 'H19096880' => -120,
  1552. 'H12050104' => -480,
  1553. 'H10655472' => -3000,
  1554. 'H12439274' => -720,
  1555. 'F31467862' => -3528,
  1556. 'F29042730' => -360,
  1557. 'F10062708' => -982,
  1558. 'F60226072' => -120,
  1559. 'E13291482' => -120,
  1560. 'D13390146' => -360,
  1561. 'D15369301' => -376,
  1562. 'D10058595' => -240,
  1563. 'H17368844' => -120,
  1564. 'H17673492' => -360,
  1565. 'H40420622' => -120,
  1566. 'H37612456' => -240,
  1567. 'H16239634' => -720,
  1568. 'H19200443' => -2760,
  1569. 'F10693156' => -3407.99,
  1570. 'F15664716' => -360,
  1571. 'F14542850' => -120,
  1572. 'F15821274' => -600,
  1573. 'A14314525' => -120,
  1574. 'A16968827' => -480,
  1575. 'D19551159' => -240,
  1576. 'D17359769' => -120,
  1577. 'D17464140' => -240,
  1578. 'D12103432' => -128,
  1579. 'H11158785' => -578,
  1580. 'H11304078' => -120,
  1581. 'H38384841' => -120,
  1582. 'H15263058' => -120,
  1583. 'H44636655' => -240,
  1584. 'H13540567' => -720,
  1585. 'H11372262' => -2160,
  1586. 'H95402009' => -1260,
  1587. 'H59876727' => -960,
  1588. 'F16723562' => -819.99,
  1589. 'F14010022' => -2468,
  1590. 'F16485738' => -360,
  1591. 'F17398416' => -360,
  1592. 'F11668609' => -120,
  1593. 'E14666737' => -120,
  1594. 'E18812880' => -213,
  1595. 'D13299101' => -240,
  1596. 'D18768019' => -120,
  1597. 'D18898064' => -128,
  1598. 'D16748142' => -240,
  1599. 'H19464479' => -1080,
  1600. 'H11879978' => -240,
  1601. 'H18864434' => -840,
  1602. 'H15868186' => -120,
  1603. 'H68332692' => -720,
  1604. 'H50691564' => -2160,
  1605. 'F17368654' => -2348,
  1606. 'F17121859' => -699.99,
  1607. 'H93093611' => -600,
  1608. 'A17962339' => -120,
  1609. 'A18358406' => -480,
  1610. 'D15539120' => -240,
  1611. 'D19181661' => -240,
  1612. 'H17928312' => -960,
  1613. 'H14358188' => -840,
  1614. 'H10699566' => -1666,
  1615. 'H15912596' => -240,
  1616. 'H31173575' => -480,
  1617. 'H19433676' => -240,
  1618. 'H17288092' => -360,
  1619. 'A17816239' => -120,
  1620. 'A10678307' => -360,
  1621. 'H23275366' => -720,
  1622. 'H12591081' => -240,
  1623. 'H16504568' => -840,
  1624. 'H16531555' => -480,
  1625. 'H38486089' => -600,
  1626. 'H83574838' => -1320,
  1627. 'H18357186' => -120,
  1628. 'H16049391' => -120,
  1629. 'H16379925' => -240,
  1630. 'F13307818' => -120,
  1631. 'F11580708' => -1868,
  1632. 'F11108484' => -120,
  1633. 'H13915722' => -360,
  1634. 'D15805087' => -120,
  1635. 'D15467159' => -240,
  1636. 'H10366600' => -720,
  1637. 'H63372506' => -120,
  1638. 'H14710441' => -840,
  1639. 'H10090408' => -1666,
  1640. 'H33154162' => -360,
  1641. 'H15358396' => -480,
  1642. 'H72700605' => -840,
  1643. 'H12827073' => -480,
  1644. 'F15846968' => -1748,
  1645. 'H16660022' => -360,
  1646. 'D11624328' => -240,
  1647. 'H11552847' => -1666,
  1648. 'H19166726' => -240,
  1649. 'H14364498' => -480,
  1650. 'H17797668' => -600,
  1651. 'H12452235' => -480,
  1652. 'H18592203' => -120,
  1653. 'F14890926' => -1628,
  1654. 'D13778545' => -240,
  1655. 'H11066019' => -600,
  1656. 'H11306623' => -120,
  1657. 'H16157527' => -840,
  1658. 'H13701187' => -240,
  1659. 'H18248205' => -600,
  1660. 'H17907648' => -840,
  1661. 'H13779328' => -1666,
  1662. 'H19450811' => -240,
  1663. 'H17008421' => -480,
  1664. 'H16387500' => -840,
  1665. 'H91950177' => -1666,
  1666. 'H18592565' => -240,
  1667. 'H77879934' => -1666,
  1668. 'H13711477' => -120,
  1669. 'H13833502' => -240,
  1670. 'H12286615' => -240,
  1671. 'F17783334' => -1148,
  1672. 'D11204865' => -240,
  1673. 'H17393209' => -480,
  1674. 'H17832251' => -840,
  1675. 'H10164361' => -240,
  1676. 'H19291917' => -120,
  1677. 'H16253624' => -720,
  1678. 'H15216330' => -120,
  1679. 'F12562440' => -680,
  1680. 'D15177935' => -240,
  1681. 'H17439829' => -840,
  1682. 'H19424150' => -480,
  1683. 'H13125893' => -840,
  1684. 'H24399895' => -840,
  1685. 'H10159130' => -840,
  1686. 'H11682345' => -840,
  1687. 'H17826076' => -840,
  1688. 'H10656939' => -840,
  1689. 'H17396420' => -840,
  1690. 'H10514419' => -840,
  1691. 'H16934767' => -840,
  1692. 'H14181865' => -840,
  1693. 'H16130940' => -840,
  1694. 'H17608191' => -840,
  1695. 'H11569007' => -840,
  1696. 'H14576782' => -840,
  1697. 'H15577686' => -840,
  1698. 'H11753266' => -840,
  1699. 'H12284905' => -720,
  1700. 'H15872474' => -720,
  1701. 'H13200796' => -600,
  1702. 'H15478592' => -480,
  1703. 'H19659132' => -480,
  1704. 'D12199046' => 503.75,
  1705. 'D19795156' => 155,
  1706. 'D15436866' => 155,
  1707. 'H49758932' => -360,
  1708. 'H16852727' => -360,
  1709. 'H15064959' => -360,
  1710. 'H15043547' => -360,
  1711. 'H14896153' => -360,
  1712. 'H12062745' => -360,
  1713. 'H11705904' => -360,
  1714. 'H44310375' => -360,
  1715. 'H17570490' => -360,
  1716. 'H15866731' => -360,
  1717. 'H10082397' => -360,
  1718. 'H17197020' => -360,
  1719. 'H96244925' => -360,
  1720. 'H18278522' => -360,
  1721. 'H16921167' => -360,
  1722. 'H11746826' => -360,
  1723. 'H14231961' => -360,
  1724. 'H17528587' => -360,
  1725. 'H19118260' => -360,
  1726. 'H12448611' => -360,
  1727. 'H16502115' => -360,
  1728. 'H66096080' => -360,
  1729. 'H13333591' => -360,
  1730. 'H12704168' => -360,
  1731. 'H10822555' => -360,
  1732. 'H27825190' => -360,
  1733. 'H62054512' => -360,
  1734. 'H18450323' => -360,
  1735. 'H16863190' => -360,
  1736. 'H11241039' => -360,
  1737. 'H15641979' => -360,
  1738. 'H15453609' => -360,
  1739. 'H88069590' => -360,
  1740. 'H17085313' => -360,
  1741. 'H13018948' => -360,
  1742. 'H12503677' => -360,
  1743. 'H46274824' => -360,
  1744. 'H50970678' => -360,
  1745. 'H15757860' => -360,
  1746. 'H65559852' => -360,
  1747. 'H15888980' => -360,
  1748. 'H18669651' => -240,
  1749. 'H12966470' => -240,
  1750. 'H15605405' => -240,
  1751. 'H13302229' => -240,
  1752. 'H19988098' => -240,
  1753. 'H19139717' => -240,
  1754. 'H17419145' => -240,
  1755. 'H15179291' => -240,
  1756. 'H15024184' => -240,
  1757. 'H13577736' => -240,
  1758. 'D13347854' => 200,
  1759. 'H16105967' => -240,
  1760. 'H10292657' => -240,
  1761. 'H14109018' => -240,
  1762. 'H15892232' => -240,
  1763. 'H10659498' => -240,
  1764. 'H18383896' => -240,
  1765. 'H14304440' => -240,
  1766. 'H97331452' => -240,
  1767. 'H12055085' => -240,
  1768. 'H87950486' => -240,
  1769. 'H13902912' => -240,
  1770. 'H14311006' => -240,
  1771. 'H89043517' => -240,
  1772. 'H20947501' => -240,
  1773. 'H10466894' => -240,
  1774. 'H19591200' => -240,
  1775. 'H19920650' => -240,
  1776. 'H10809534' => -240,
  1777. 'H13081445' => -240,
  1778. 'H19304638' => -240,
  1779. 'H17167739' => -240,
  1780. 'H13575379' => -240,
  1781. 'H19106582' => -240,
  1782. 'H17782450' => -240,
  1783. 'H11446432' => -240,
  1784. 'H15058672' => -240,
  1785. 'H10535417' => -240,
  1786. 'H92052401' => -240,
  1787. 'H11517133' => -240,
  1788. 'H80093994' => -240,
  1789. 'H11956092' => -240,
  1790. 'H17165790' => -240,
  1791. 'H11424567' => -240,
  1792. 'H19560581' => -240,
  1793. 'H19423232' => -240,
  1794. 'H16184781' => -240,
  1795. 'H10780996' => -240,
  1796. 'H12168567' => -240,
  1797. 'H69093228' => -240,
  1798. 'H10849787' => -240,
  1799. 'D18829108' => 200,
  1800. 'D18507164' => 347.5,
  1801. 'Q73338908' => 150,
  1802. 'Q69472907' => 150
  1803. ];
  1804. foreach ($modifyData as $username => $modifyValue) {
  1805. $oneUser = User::find()->select(['ID', 'USER_NAME'])->where('USER_NAME=:USER_NAME', ['USER_NAME'=>$username])->asArray()->one();
  1806. if( !$oneUser ) {
  1807. echo sprintf('用户%s不存在' . PHP_EOL, $username);
  1808. continue;
  1809. }
  1810. $realModifyValue = (-1) * $modifyValue;
  1811. UserPerf::updateAllCounters(['PV_PSS_TOTAL'=>$realModifyValue], 'USER_ID=:USER_ID', ['USER_ID'=>$oneUser['ID']]);
  1812. echo sprintf('用户%s变化业绩为:%s' . PHP_EOL, $username, $realModifyValue);
  1813. unset($username, $modifyValue, $oneUser, $realModifyValue);
  1814. }
  1815. }
  1816. public function actionGetYcData($userId, $periodNum=132) {
  1817. $ycBonusData = CalcCache::getYCBonusList($userId, $periodNum);
  1818. if( $ycBonusData ) {
  1819. if( $ycBonusData['fromData'] ) {
  1820. foreach ($ycBonusData['fromData'] as $every) {
  1821. //fromPvPcs fromUid
  1822. $fromBaseInfo = CalcCache::getUserInfo($every['fromUid'], $periodNum);
  1823. echo sprintf("来源用户名:%s,来源用户pv:%s" . PHP_EOL, $fromBaseInfo['USER_NAME'], $every['fromPvPcs']);
  1824. }
  1825. }
  1826. }
  1827. }
  1828. /**
  1829. * 计算某期复消现金金额
  1830. */
  1831. public function actionCalcPeriodFxCash() {
  1832. $periodNumList = [146];
  1833. foreach ($periodNumList as $periodNum) {
  1834. $this->_calcPeriodFxCash($periodNum);
  1835. }
  1836. }
  1837. private function _calcPeriodFxCash($periodNum) {
  1838. //复消订单
  1839. $pageSize = 1000;
  1840. $allCount = Order::findUseDbCalc()->where("PERIOD_NUM=:PERIOD_NUM AND IS_DELETE=0 AND ORDER_TYPE=:ORDER_TYPE", [':PERIOD_NUM' => $periodNum, ':ORDER_TYPE'=>DeclarationForm::TYPE_FX])->count('ID');
  1841. $pageCount = ceil($allCount/$pageSize);
  1842. for ($page=1;$page<=$pageCount;$page++) {
  1843. echo sprintf('期数:%s,复消订单:当前页数%s,总页数:%s' . PHP_EOL, $periodNum, $page, $pageCount);
  1844. $allData = Order::findUseDbCalc()->select('ID,SN,DEC_SN,USER_ID,ORDER_TYPE,ORDER_AMOUNT,PAY_AMOUNT,PAY_PV,PAY_TYPE,PERIOD_NUM,STATUS,IS_DELETE,P_CALC_MONTH,CREATED_AT')->where("PERIOD_NUM=:PERIOD_NUM AND IS_DELETE=0 AND ORDER_TYPE=:ORDER_TYPE", [':PERIOD_NUM' => $periodNum, ':ORDER_TYPE'=>DeclarationForm::TYPE_FX])->orderBy('CREATED_AT DESC,ID DESC')->offset(($page-1)*$pageSize)->limit($pageSize)->asArray()->all();
  1845. if( $allData ) {
  1846. foreach ($allData as $data) {
  1847. //如果支付方式是现金,那么实际业绩是支付PV的50%
  1848. if ($data['PAY_TYPE'] === 'cash') {
  1849. PerfPeriod::updateAll([
  1850. 'FX_AMOUNT_CASH'=>new Expression('FX_AMOUNT_CASH+' . $data['ORDER_AMOUNT'])
  1851. ], 'USER_ID=:USER_ID AND PERIOD_NUM=:PERIOD_NUM', ['USER_ID'=>$data['USER_ID'], 'PERIOD_NUM'=>$periodNum]);
  1852. }
  1853. unset($data);
  1854. }
  1855. }
  1856. unset($allData);
  1857. }
  1858. unset($allCount, $pageCount, $page);
  1859. //导入的复消订单
  1860. $allCount = OrderShop::findUseDbCalc()->where("PERIOD_NUM=:PERIOD_NUM AND IS_DELETE=0 AND ORDER_TYPE=:ORDER_TYPE", [':PERIOD_NUM' => $periodNum, ':ORDER_TYPE'=>DeclarationForm::TYPE_FX])->count('ID');
  1861. $pageCount = ceil($allCount/$pageSize);
  1862. for ($page=1;$page<=$pageCount;$page++) {
  1863. echo sprintf('期数:%s,导入订单:当前页数%s,总页数:%s' . PHP_EOL, $periodNum, $page, $pageCount);
  1864. $allData = OrderShop::findUseDbCalc()->select('ID,SN,DEC_SN,USER_ID,ORDER_TYPE,ORDER_AMOUNT,PAY_AMOUNT,PAY_PV,PAY_TYPE,PERIOD_NUM,STATUS,IS_DELETE,P_CALC_MONTH,CREATED_AT')->where("PERIOD_NUM=:PERIOD_NUM AND IS_DELETE=0 AND ORDER_TYPE=:ORDER_TYPE", [':PERIOD_NUM' => $periodNum, ':ORDER_TYPE'=>DeclarationForm::TYPE_FX])->orderBy('CREATED_AT DESC,ID DESC')->offset(($page-1)*$pageSize)->limit($pageSize)->asArray()->all();
  1865. if( $allData ) {
  1866. foreach ($allData as $data) {
  1867. //如果支付方式是现金,那么实际业绩是支付PV的50%
  1868. if ($data['PAY_TYPE'] === 'cash') {
  1869. PerfPeriod::updateAll([
  1870. 'FX_AMOUNT_CASH'=>new Expression('FX_AMOUNT_CASH+' . $data['ORDER_AMOUNT'])
  1871. ], 'USER_ID=:USER_ID AND PERIOD_NUM=:PERIOD_NUM', ['USER_ID'=>$data['USER_ID'], 'PERIOD_NUM'=>$periodNum]);
  1872. }
  1873. unset($data);
  1874. }
  1875. }
  1876. unset($allData);
  1877. }
  1878. unset($allCount, $pageCount, $page);
  1879. }
  1880. public function actionCheckGxNextFive() {
  1881. $userId = '76190398896279552';
  1882. $periodNum = 160;
  1883. $bonusUserData = [];
  1884. $sysConfig = Cache::getSystemConfig();
  1885. $bonusPercentTwo = $sysConfig['sharePercent']['VALUE'] / 100;
  1886. // 从缓存中获取会员的收入信息
  1887. $incomeBonus = CalcCache::bonus($userId, $periodNum);
  1888. $lastTwoIncome = $incomeBonus['ORI_BONUS_QY_BD'] ?? 0;
  1889. unset($lastTwoIncome);
  1890. $nextFiveIncome = $incomeBonus['ORI_BONUS_QY_BD'] ?? 0;
  1891. $shareBonusTwo = $nextFiveIncome * $bonusPercentTwo;
  1892. unset($nextFiveIncome);
  1893. //找到下5代(安置网) 紧缩 相对偶数层2、4、6、8、10层
  1894. if( $shareBonusTwo > 0 ) {
  1895. $validDeep = 1;
  1896. $this->loopNetworkParentDo($userId, function ($parent) use ($userId, $shareBonusTwo,$periodNum, &$validDeep, &$bonusUserData) {
  1897. if ( $validDeep % 2 === 0 ) {
  1898. $bonusUserData[] = [
  1899. 'bonusUid' => $parent['PARENT_UID'],
  1900. 'bonus' => $shareBonusTwo
  1901. ];
  1902. }
  1903. //判断$parent是否有首单团队奖
  1904. $parentBonus = CalcCache::bonus($parent['PARENT_UID'], $periodNum);
  1905. if( $parentBonus['ORI_BONUS_QY_BD'] > 0 ) {//有效层
  1906. $validDeep += 1;
  1907. }
  1908. unset($parent, $parentBonus);
  1909. if ( $validDeep >= 11 ) {
  1910. return 1;
  1911. }
  1912. });
  1913. unset($validDeep);
  1914. }
  1915. // if ( !$bonusUserData ) return;
  1916. var_dump($bonusUserData);die;
  1917. }
  1918. public function actionCheckGxLastTwo() {
  1919. $userId = '76189391281852416';
  1920. $periodNum = 160;
  1921. $bonusUserData = [];
  1922. $bonusPercentOne = 5 / 100;
  1923. // 从缓存中获取会员的收入信息
  1924. $incomeBonus = CalcCache::bonus($userId, $periodNum);
  1925. $lastTwoIncome = $incomeBonus['ORI_BONUS_QY_BD'] ?? 0;
  1926. $shareBonusOne = $lastTwoIncome * $bonusPercentOne;
  1927. unset($lastTwoIncome);
  1928. //找到上2代 新增个人+推荐团队业绩 加权平均分配 这个奖
  1929. if( $shareBonusOne > 0) {
  1930. $bonusUserList = CalcCache::getShareBonusOneRelation($userId, $periodNum);
  1931. if( $bonusUserList ) {
  1932. $bonusUserTotalPerf = 0;
  1933. $bonusUserRealList = [];
  1934. foreach ($bonusUserList as $bonusUserId) {
  1935. //查看该用户的个人业绩和团队新增业绩总和
  1936. $nowPeriodData = CalcCache::nowPeriodPerf($bonusUserId, $periodNum);
  1937. //本期新增业绩
  1938. $bonusUserPerf = $nowPeriodData['PV_PCS'] + $nowPeriodData['PV_PSS'];
  1939. if ($bonusUserPerf <= 0) {
  1940. unset($bonusUserId, $nowPeriodData, $bonusUserPerf);
  1941. continue;
  1942. }
  1943. $bonusUserTotalPerf += $bonusUserPerf;
  1944. $bonusUserRealList[] = [
  1945. 'bonusUserId' => $bonusUserId,
  1946. 'bonusUserPerf' => $bonusUserPerf
  1947. ];
  1948. unset($bonusUserId, $nowPeriodData, $bonusUserPerf);
  1949. }
  1950. unset($bonusUserList);
  1951. foreach ($bonusUserRealList as $everyData) {
  1952. $bonusUserData[] = [
  1953. 'bonusUid' => $everyData['bonusUserId'],
  1954. 'bonus' => $shareBonusOne * $everyData['bonusUserPerf'] / $bonusUserTotalPerf
  1955. ];
  1956. unset($everyData);
  1957. }
  1958. unset($bonusUserRealList);
  1959. }
  1960. }
  1961. var_dump($bonusUserData);die;
  1962. }
  1963. public function actionCheckGxMonthData() {
  1964. //查看是否复消300
  1965. $userId = '76189026280935424';
  1966. $periodNum = 162;
  1967. $sysConfig = Cache::getSystemConfig();
  1968. $monthPerfData = CalcCache::nowMonthPerf($userId, $periodNum);
  1969. $fxPvStatus = $monthPerfData['PV_PCS_FX'] >= $sysConfig['monthPcsPvFxCondition']['VALUE'];
  1970. if ( $fxPvStatus ) {//加上本期和往期的共享和管理奖
  1971. $monthSumData = CalcBonus::findUseSlaves()->select('SUM(BONUS_GX) AS BONUS_GX_SUM, SUM(BONUS_GL) AS BONUS_GL_SUM')->where('USER_ID=:USER_ID AND CALC_MONTH=:CALC_MONTH', ['USER_ID'=>$userId, 'CALC_MONTH'=>'202104'])->asArray()->one();
  1972. $bonus = CalcCache::bonus($userId, $periodNum);
  1973. $bonusGxSum = $monthSumData['BONUS_GX_SUM'] ?? 0;
  1974. $bonusGlSum = $monthSumData['BONUS_GL_SUM'] ?? 0;
  1975. $realBonusGx = $bonusGxSum + $bonus['BONUS_GX'];
  1976. $realBonusGl = $bonusGlSum + $bonus['BONUS_GL'];
  1977. var_dump($realBonusGx, $realBonusGl);die;
  1978. }
  1979. echo "..OK" . PHP_EOL;
  1980. }
  1981. /**
  1982. * 根据奖金表中的记录
  1983. */
  1984. public function actionAddMonthBonusUser($calcMonth) {
  1985. // $calcMonth = '202104';
  1986. $pageSize = 1000;
  1987. $allCount = CalcBonus::find()->where('CALC_MONTH=:CALC_MONTH', [
  1988. 'CALC_MONTH' => $calcMonth
  1989. ])->asArray()->count();
  1990. $pageCount = ceil($allCount/$pageSize);
  1991. for($page=1;$page<=$pageCount;$page++) {
  1992. echo sprintf('【%d】月奖金用户,总页数为【%d】,当前页数为【%d】' . PHP_EOL, $calcMonth, $pageCount, $page);
  1993. $insertDataBonusUser = [];
  1994. $offset = ($page-1)*$pageSize;
  1995. $listData = CalcBonus::find()->select('USER_ID,CALC_MONTH,PERIOD_NUM,ORI_BONUS_GX,ORI_BONUS_GL')->where('CALC_MONTH=:CALC_MONTH', [
  1996. 'CALC_MONTH' => $calcMonth
  1997. ])->offset($offset)->limit($pageSize)->asArray()->all();
  1998. foreach ($listData as $everyData) {
  1999. if( $everyData['ORI_BONUS_GX'] == 0 && $everyData['ORI_BONUS_GL'] == 0 ) continue;
  2000. $insertDataBonusUser[] = [
  2001. 'ID' => SnowFake::instance()->generateId(),
  2002. 'USER_ID' => $everyData['USER_ID'],
  2003. 'CALC_MONTH' => $everyData['CALC_MONTH'],
  2004. 'PERIOD_NUM' => $everyData['PERIOD_NUM'],
  2005. 'CREATED_AT' => Date::nowTime()
  2006. ];
  2007. }
  2008. if( $insertDataBonusUser ) CalcMonthBonusUser::batchInsert($insertDataBonusUser);
  2009. unset($listData, $insertDataBonusUser);
  2010. }
  2011. }
  2012. /**
  2013. * 后续计算共享和管理奖
  2014. * @param $tableName
  2015. * @param $toPeriod
  2016. * @throws \yii\db\Exception
  2017. */
  2018. public function actionAfterCalcBonusGxAndGl($tableName, $toPeriod) {
  2019. $db = \Yii::$app->db;
  2020. $fromTableName = sprintf("AR_CALC_BONUS_%s", $tableName);
  2021. $sql = "SELECT COUNT(ID) as allCount FROM {$fromTableName} WHERE PERIOD_NUM={$toPeriod} ORDER BY ID ASC";
  2022. $allCountOne = $db->createCommand($sql)->queryOne();
  2023. $pageSize = 1000;
  2024. $pageCount = ceil($allCountOne['allCount']/$pageSize);
  2025. for($page=1;$page<=$pageCount;$page++) {
  2026. echo sprintf('同步【%d】期的数据,总页数为【%d】,当前页数为【%d】' . PHP_EOL, $toPeriod, $pageCount, $page);
  2027. $offset = ($page-1)*$pageSize;
  2028. $listSql = "SELECT * FROM {$fromTableName} WHERE PERIOD_NUM={$toPeriod} ORDER BY ID ASC LIMIT {$pageSize} OFFSET {$offset}";
  2029. $list = $db->createCommand($listSql)->queryAll();
  2030. foreach ($list as $every) {
  2031. //判断该会员在AR_CALC_BONUS 表中 对应期数是否有相应的数据,有就更新,没有就插入。
  2032. $one = CalcBonus::find()->where('USER_ID=:USER_ID AND PERIOD_NUM=:PERIOD_NUM', ['USER_ID'=>$every['USER_ID'], 'PERIOD_NUM'=>$toPeriod])->asArray()->one();
  2033. if( $one ) {
  2034. CalcBonus::updateAll([
  2035. 'BONUS_GX' => $every['BONUS_GX'],
  2036. 'ORI_BONUS_GX' => $every['ORI_BONUS_GX'],
  2037. 'REAL_BONUS_GX' => $every['REAL_BONUS_GX'],
  2038. 'BONUS_GL' => $every['BONUS_GL'],
  2039. 'ORI_BONUS_GL' => $every['ORI_BONUS_GL'],
  2040. 'REAL_BONUS_GL' => $every['REAL_BONUS_GL'],
  2041. ], 'ID=:ID', ['ID'=>$one['ID']]);
  2042. }else {
  2043. $insertData = $every;
  2044. $insertData['ID'] = SnowFake::instance()->generateId();
  2045. $insertData['IS_SENT'] = 1;
  2046. $insertData['SENT_AT'] = Date::nowTime();
  2047. CalcBonus::insertOne($insertData);
  2048. unset($insertData);
  2049. }
  2050. unset($every, $one);
  2051. }
  2052. }
  2053. }
  2054. /**
  2055. * 补发$fromPeriod 共享和管理实发奖金
  2056. * @param $fromPeriod
  2057. * @throws Exception
  2058. * @throws \yii\db\Exception
  2059. */
  2060. public function actionSendBonusGxAndGl($fromPeriod)
  2061. {
  2062. $allCount = CalcBonus::find()->where('PERIOD_NUM=:PERIOD_NUM', ['PERIOD_NUM'=>$fromPeriod])->asArray()->count(1);
  2063. $pageSize = 1000;
  2064. $pageCount = ceil($allCount/$pageSize);
  2065. for($page=1;$page<=$pageCount;$page++) {
  2066. echo sprintf('补发【%d】期共享奖金和管理奖金,总页数为【%d】,当前页数为【%d】' . PHP_EOL, $fromPeriod, $pageCount, $page);
  2067. $offset = ($page-1)*$pageSize;
  2068. $pageList = CalcBonus::find()->select(['USER_ID', 'REAL_BONUS_GX', 'REAL_BONUS_GL'])->where('PERIOD_NUM=:PERIOD_NUM', ['PERIOD_NUM'=>$fromPeriod])->offset($offset)->limit($pageSize)->asArray()->all();
  2069. foreach ($pageList as $everyData) {
  2070. $sendBonus = $everyData['REAL_BONUS_GX'] + $everyData['REAL_BONUS_GL'];
  2071. if( $sendBonus <= 0 ) {
  2072. unset($everyData, $sendBonus);
  2073. continue;
  2074. }
  2075. Balance::changeUserBonus($everyData['USER_ID'], 'bonus', $sendBonus, [
  2076. 'REMARK' => 'From ' . $fromPeriod . '期补发共享和管理奖',
  2077. 'PERIOD_NUM' => $fromPeriod,
  2078. 'DEAL_TYPE_ID' => DealType::BONUS_SEND,
  2079. ]);
  2080. unset($everyData, $sendBonus);
  2081. }
  2082. }
  2083. }
  2084. public function actionCheckGxMinPv() {
  2085. $userId = '76190155484041216';
  2086. $periodNum = 160;
  2087. $bonusCalc = BonusCalc::instance();
  2088. $bonusCalc->setPeriodNum($periodNum);
  2089. $rt = $bonusCalc->checkSmallMarketPerf($userId);
  2090. var_dump($rt);
  2091. return 'ok' . PHP_EOL;
  2092. }
  2093. /**
  2094. * 同步VIP奖
  2095. * @param $tableName
  2096. * @param $toPeriod
  2097. * @throws \yii\db\Exception
  2098. */
  2099. public function actionAfterCalcBonusVip($tableName, $toPeriod) {
  2100. $db = \Yii::$app->db;
  2101. $fromTableName = sprintf("AR_CALC_BONUS_%s", $tableName);
  2102. $sql = "SELECT COUNT(ID) as allCount FROM {$fromTableName} WHERE PERIOD_NUM={$toPeriod} ORDER BY ID ASC";
  2103. $allCountOne = $db->createCommand($sql)->queryOne();
  2104. $pageSize = 1000;
  2105. $pageCount = ceil($allCountOne['allCount']/$pageSize);
  2106. for($page=1;$page<=$pageCount;$page++) {
  2107. echo sprintf('同步【%d】期的VIP数据,总页数为【%d】,当前页数为【%d】' . PHP_EOL, $toPeriod, $pageCount, $page);
  2108. $offset = ($page-1)*$pageSize;
  2109. $listSql = "SELECT * FROM {$fromTableName} WHERE PERIOD_NUM={$toPeriod} ORDER BY ID ASC LIMIT {$pageSize} OFFSET {$offset}";
  2110. $list = $db->createCommand($listSql)->queryAll();
  2111. foreach ($list as $every) {
  2112. //判断该会员在AR_CALC_BONUS 表中 对应期数是否有相应的数据,有就更新,没有就插入。
  2113. $one = CalcBonus::find()->where('USER_ID=:USER_ID AND PERIOD_NUM=:PERIOD_NUM', ['USER_ID'=>$every['USER_ID'], 'PERIOD_NUM'=>$toPeriod])->asArray()->one();
  2114. if( $one ) {
  2115. CalcBonus::updateAll([
  2116. 'BONUS_VIP' => $every['BONUS_VIP'],
  2117. 'ORI_BONUS_VIP' => $every['ORI_BONUS_VIP'],
  2118. ], 'ID=:ID', ['ID'=>$one['ID']]);
  2119. }else {
  2120. $insertData = $every;
  2121. $insertData['ID'] = SnowFake::instance()->generateId();
  2122. $insertData['IS_SENT'] = 1;
  2123. $insertData['SENT_AT'] = Date::nowTime();
  2124. CalcBonus::insertOne($insertData);
  2125. unset($insertData);
  2126. }
  2127. unset($every, $one);
  2128. }
  2129. }
  2130. }
  2131. /**
  2132. * 补发VIP奖
  2133. * @param $fromPeriod
  2134. * @throws Exception
  2135. * @throws \yii\db\Exception
  2136. */
  2137. public function actionSendBonusVip($fromPeriod)
  2138. {
  2139. $allCount = CalcBonus::find()->where('PERIOD_NUM=:PERIOD_NUM', ['PERIOD_NUM'=>$fromPeriod])->asArray()->count(1);
  2140. $pageSize = 1000;
  2141. $pageCount = ceil($allCount/$pageSize);
  2142. for($page=1;$page<=$pageCount;$page++) {
  2143. echo sprintf('补发【%d】期VIP奖金,总页数为【%d】,当前页数为【%d】' . PHP_EOL, $fromPeriod, $pageCount, $page);
  2144. $offset = ($page-1)*$pageSize;
  2145. $pageList = CalcBonus::find()->select(['USER_ID', 'BONUS_VIP', 'ORI_BONUS_VIP'])->where('PERIOD_NUM=:PERIOD_NUM', ['PERIOD_NUM'=>$fromPeriod])->offset($offset)->limit($pageSize)->asArray()->all();
  2146. foreach ($pageList as $everyData) {
  2147. $sendBonus = $everyData['BONUS_VIP'];
  2148. if( $sendBonus <= 0 ) {
  2149. unset($everyData, $sendBonus);
  2150. continue;
  2151. }
  2152. Balance::changeUserBonus($everyData['USER_ID'], 'bonus', $sendBonus, [
  2153. 'REMARK' => 'From ' . $fromPeriod . '期补发VIP奖',
  2154. 'PERIOD_NUM' => $fromPeriod,
  2155. 'DEAL_TYPE_ID' => DealType::BONUS_SEND,
  2156. ]);
  2157. unset($everyData, $sendBonus);
  2158. }
  2159. }
  2160. }
  2161. /**
  2162. * 补发复消积分对应的奖金
  2163. * @param $calcMonth
  2164. * @throws Exception
  2165. * @throws \yii\db\Exception
  2166. */
  2167. public function actionSendReConsumePoints($calcMonth) {
  2168. $pageSize = 1000;
  2169. $allCount = CalcBonus::find()->where('CALC_MONTH=:CALC_MONTH', [
  2170. 'CALC_MONTH' => $calcMonth
  2171. ])->groupBy('USER_ID')->orderBy('USER_ID DESC')->count();
  2172. $pageCount = ceil($allCount/$pageSize);
  2173. for($page=1;$page<=$pageCount;$page++) {
  2174. echo sprintf('【%d】补发复消积分,总页数为【%d】,当前页数为【%d】' . PHP_EOL, $calcMonth, $pageCount, $page);
  2175. $offset = ($page-1)*$pageSize;
  2176. $list = CalcBonus::find()->select('USER_ID,SUM(ORI_BONUS_GX) AS ORI_BONUS_GX_SUM,SUM(ORI_BONUS_GL) AS ORI_BONUS_GL_SUM,SUM(REAL_BONUS_GX) AS REAL_BONUS_GX_SUM,SUM(REAL_BONUS_GL) AS REAL_BONUS_GL_SUM')->where('CALC_MONTH=:CALC_MONTH', [
  2177. 'CALC_MONTH' => $calcMonth
  2178. ])->groupBy('USER_ID')->orderBy('USER_ID DESC')->offset($offset)->limit($pageSize)->asArray()->all();
  2179. foreach ($list as $everyData) {
  2180. //计算出实发共享奖扣除的积分和管理奖扣除的积分
  2181. $userReconsumePoints = 0;
  2182. if( $everyData['ORI_BONUS_GX_SUM'] > 0 ) {
  2183. $manageGx = $everyData['ORI_BONUS_GX_SUM'] * 5 / 100;
  2184. $gxReconsumePoints = $everyData['ORI_BONUS_GX_SUM'] - $manageGx - $everyData['REAL_BONUS_GX_SUM'];
  2185. if( $gxReconsumePoints > 0 ) $userReconsumePoints += $gxReconsumePoints;
  2186. unset($manageGx, $gxReconsumePoints);
  2187. }
  2188. if( $everyData['ORI_BONUS_GL_SUM'] > 0 ) {
  2189. $manageGL = $everyData['ORI_BONUS_GL_SUM'] * 5 / 100;
  2190. $glReconsumePoints = $everyData['ORI_BONUS_GL_SUM'] - $manageGL - $everyData['REAL_BONUS_GL_SUM'];
  2191. if( $glReconsumePoints > 0 ) $userReconsumePoints += $glReconsumePoints;
  2192. unset($manageGL, $glReconsumePoints);
  2193. }
  2194. if( $userReconsumePoints <= 0 ) continue;
  2195. $all = FlowBonus::find()->where('USER_ID=:USER_ID AND REMARK=:REMARK', ['USER_ID'=>$everyData['USER_ID'], 'REMARK' => 'From162期补发复消积分对应的奖金'])->asArray()->all();
  2196. if( $all ) {
  2197. $countAll = count($all);
  2198. if( $countAll > 1 ) {
  2199. array_pop($all);
  2200. foreach ($all as $one) {
  2201. $oneBonus = (-1) * Tool::formatPrice($one['AMOUNT']);
  2202. Balance::changeUserBonus($one['USER_ID'], 'bonus', $oneBonus, [
  2203. 'REMARK' => 'From162期撤消重复补发复消积分对应的奖金',
  2204. 'PERIOD_NUM' => 162,
  2205. 'DEAL_TYPE_ID' => DealType::BONUS_SEND,
  2206. ]);
  2207. unset($one, $oneBonus);
  2208. }
  2209. }
  2210. }else {
  2211. //发放复消积分金额的奖金
  2212. Balance::changeUserBonus($everyData['USER_ID'], 'bonus', $userReconsumePoints, [
  2213. 'REMARK' => 'From162期补发复消积分对应的奖金',
  2214. 'PERIOD_NUM' => 162,
  2215. 'DEAL_TYPE_ID' => DealType::BONUS_SEND,
  2216. ]);
  2217. }
  2218. unset($everyData, $userReconsumePoints, $all);
  2219. }
  2220. }
  2221. }
  2222. /**
  2223. * 清除某一期结算缓存
  2224. * @param $periodNum
  2225. */
  2226. public function actionClearPeriodCalcCache($periodNum) {
  2227. CalcCache::clearAll($periodNum);
  2228. }
  2229. public function actionDeleteSendPoints() {
  2230. $pageSize = 1000;
  2231. $allCount = FlowBonus::find()->where('PERIOD_NUM=162 AND REMARK=:REMARK', ['REMARK' => 'From162期补发复消积分对应的奖金'])->count(1);
  2232. $pageCount = ceil($allCount/$pageSize);
  2233. for($page=1;$page<=$pageCount;$page++) {
  2234. echo sprintf('【%d】撤消补发复消积分,总页数为【%d】,当前页数为【%d】' . PHP_EOL, 162, $pageCount, $page);
  2235. $offset = ($page-1)*$pageSize;
  2236. $list = FlowBonus::find()->where('PERIOD_NUM=162 AND REMARK=:REMARK', ['REMARK' => 'From162期补发复消积分对应的奖金'])->offset($offset)->limit($pageSize)->asArray()->all();
  2237. foreach ($list as $everyData) {
  2238. //查询金额是否足够
  2239. $bonus = Tool::formatPrice($everyData['AMOUNT']);
  2240. $useBonus = UserBonus::find()->where('USER_ID=:USER_ID', ['USER_ID'=>$everyData['USER_ID']])->asArray()->one();
  2241. if( $useBonus['BONUS'] < $bonus ) {
  2242. echo $everyData['USER_ID'] . PHP_EOL;
  2243. }
  2244. // $bonus = (-1) * $everyData['AMOUNT'];
  2245. // Balance::changeUserBonus($everyData['USER_ID'], 'bonus', $bonus, [
  2246. // 'REMARK' => 'From162期撤消重复补发复消积分对应的奖金',
  2247. // 'PERIOD_NUM' => 162,
  2248. // 'DEAL_TYPE_ID' => DealType::BONUS_SEND,
  2249. // ]);
  2250. unset($bonus);
  2251. }
  2252. }
  2253. }
  2254. /**
  2255. * 补发其它期奖金不正确的脚本
  2256. * @param $tableName
  2257. * @param $toPeriod
  2258. * @throws Exception
  2259. * @throws \yii\db\Exception
  2260. */
  2261. public function actionAddOtherPeriodGXAndGl($tableName, $toPeriod) {
  2262. $db = \Yii::$app->db;
  2263. $fromTableName = sprintf("AR_CALC_BONUS_%s", $tableName);
  2264. $sql = "SELECT COUNT(ID) as allCount FROM {$fromTableName} WHERE PERIOD_NUM={$toPeriod} ORDER BY ID ASC";
  2265. $allCountOne = $db->createCommand($sql)->queryOne();
  2266. $pageSize = 1000;
  2267. $pageCount = ceil($allCountOne['allCount']/$pageSize);
  2268. for($page=1;$page<=$pageCount;$page++) {
  2269. echo sprintf('同步【%d】期的数据,总页数为【%d】,当前页数为【%d】' . PHP_EOL, $toPeriod, $pageCount, $page);
  2270. $offset = ($page-1)*$pageSize;
  2271. $listSql = "SELECT * FROM {$fromTableName} WHERE PERIOD_NUM={$toPeriod} ORDER BY ID ASC LIMIT {$pageSize} OFFSET {$offset}";
  2272. $list = $db->createCommand($listSql)->queryAll();
  2273. foreach ($list as $every) {
  2274. //判断该会员在AR_CALC_BONUS 表中 对应期数是否有相应的数据,有就更新,没有就插入。
  2275. $one = CalcBonus::find()->where('USER_ID=:USER_ID AND PERIOD_NUM=:PERIOD_NUM', ['USER_ID'=>$every['USER_ID'], 'PERIOD_NUM'=>$toPeriod])->asArray()->one();
  2276. if( !$one ) {
  2277. $insertData = $every;
  2278. $insertData['ID'] = SnowFake::instance()->generateId();
  2279. $insertData['IS_SENT'] = 1;
  2280. $insertData['SENT_AT'] = Date::nowTime();
  2281. CalcBonus::insertOne($insertData);
  2282. unset($insertData);
  2283. //发对应的奖金
  2284. $sendBonus = $every['REAL_BONUS_GX'] + $every['REAL_BONUS_GL'];
  2285. if( $sendBonus <= 0 ) {
  2286. unset($sendBonus);
  2287. continue;
  2288. }
  2289. //计算复消积分
  2290. $oldOne = CalcBonus::find()->select('USER_ID,SUM(ORI_BONUS_GX) AS ORI_BONUS_GX_SUM,SUM(ORI_BONUS_GL) AS ORI_BONUS_GL_SUM,SUM(REAL_BONUS_GX) AS REAL_BONUS_GX_SUM,SUM(REAL_BONUS_GL) AS REAL_BONUS_GL_SUM')->where('USER_ID=:USER_ID AND CALC_MONTH=:CALC_MONTH', ['USER_ID'=>$every['USER_ID'], 'CALC_MONTH'=>202104])->asArray()->one();
  2291. //计算出实发共享奖扣除的积分和管理奖扣除的积分
  2292. $userReconsumePoints = 0;
  2293. if( $oldOne['ORI_BONUS_GX_SUM'] > 0 ) {
  2294. $manageGx = $oldOne['ORI_BONUS_GX_SUM'] * 5 / 100;
  2295. $gxReconsumePoints = $oldOne['ORI_BONUS_GX_SUM'] - $manageGx - $oldOne['REAL_BONUS_GX_SUM'];
  2296. if( $gxReconsumePoints > 0 ) $userReconsumePoints += $gxReconsumePoints;
  2297. unset($manageGx, $gxReconsumePoints);
  2298. }
  2299. if( $oldOne['ORI_BONUS_GL_SUM'] > 0 ) {
  2300. $manageGL = $oldOne['ORI_BONUS_GL_SUM'] * 5 / 100;
  2301. $glReconsumePoints = $oldOne['ORI_BONUS_GL_SUM'] - $manageGL - $oldOne['REAL_BONUS_GL_SUM'];
  2302. if( $glReconsumePoints > 0 ) $userReconsumePoints += $glReconsumePoints;
  2303. unset($manageGL, $glReconsumePoints);
  2304. }
  2305. $sendBonus += $userReconsumePoints;
  2306. Balance::changeUserBonus($every['USER_ID'], 'bonus', $sendBonus, [
  2307. 'REMARK' => 'From ' . $toPeriod . '期补发共享和管理奖',
  2308. 'PERIOD_NUM' => $toPeriod,
  2309. 'DEAL_TYPE_ID' => DealType::RESEND,
  2310. ]);
  2311. unset($sendBonus, $oldOne, $userReconsumePoints);
  2312. }
  2313. unset($every, $one);
  2314. }
  2315. }
  2316. }
  2317. /**
  2318. * 修正某一期bonusTotal
  2319. * @param $periodNum
  2320. */
  2321. public function actionFixBonusTotal($periodNum) {
  2322. $allCount = CalcBonus::find()->where('PERIOD_NUM=:PERIOD_NUM', ['PERIOD_NUM'=>$periodNum])->count('ID');
  2323. $pageSize = 1000;
  2324. $pageCount = ceil($allCount/$pageSize);
  2325. for($page=1;$page<=$pageCount;$page++) {
  2326. echo sprintf('修正【%d】期的数据,总页数为【%d】,当前页数为【%d】' . PHP_EOL, $periodNum, $pageCount, $page);
  2327. $offset = ($page-1)*$pageSize;
  2328. $list = CalcBonus::find()->where('PERIOD_NUM=:PERIOD_NUM', ['PERIOD_NUM'=>$periodNum])->offset($offset)->limit($pageSize)->asArray()->all();
  2329. foreach ($list as $everyData) {
  2330. $bonusTotal = $everyData['ORI_BONUS_BD'] + $everyData['ORI_BONUS_TG'] + $everyData['ORI_BONUS_XF'] + $everyData['ORI_BONUS_YJ'] + $everyData['ORI_BONUS_QY'] + $everyData['ORI_BONUS_YC'] + $everyData['ORI_BONUS_VIP'] + $everyData['ORI_BONUS_GX'] + $everyData['ORI_BONUS_GL'] + $everyData['ORI_BONUS_STANDARD'];
  2331. $bonusTotalStr = strval($bonusTotal);
  2332. if( $bonusTotalStr != $everyData['BONUS_TOTAL'] ) {
  2333. echo sprintf('当前期数【%d】BONUS_TOTAL:%s, 计算结果:%s' . PHP_EOL, $periodNum, $everyData['BONUS_TOTAL'], $bonusTotalStr);
  2334. CalcBonus::updateAll([
  2335. 'BONUS_TOTAL' => $bonusTotalStr
  2336. ], 'ID=:ID', ['ID'=>$everyData['ID']]);
  2337. }
  2338. }
  2339. }
  2340. }
  2341. function actionCalcPoints($offset = 0) {
  2342. echo sprintf("时间:[%s]基础积分,当前offset为:【%s】" . PHP_EOL, date('Y-m-d H:i:s', time()) , $offset);
  2343. //查询本月的,每人的累计总收入
  2344. $limit = 1000;
  2345. $empLevelConfig = Cache::getEmpLevelConfig();
  2346. $allData = CalcBonus::findUseDbCalc()->select('USER_ID, SUM(BONUS_TOTAL) AS TOTAL_SUM, SUM(ORI_BONUS_BD) AS BD_TOTAL_SUM')->where('CALC_MONTH=:CALC_MONTH', [':CALC_MONTH' => '202104'])->groupBy('USER_ID')->orderBy('USER_ID DESC')->offset($offset)->limit($limit)->asArray()->all();
  2347. if ($allData) {
  2348. $insertData = [];
  2349. foreach ($allData as $everyData) {
  2350. $validTotalSum = $everyData['TOTAL_SUM'] - $everyData['BD_TOTAL_SUM'];
  2351. if( $validTotalSum <=0 ) continue;
  2352. //达不到 见习主任级别,不产生基础积分
  2353. $userBaseInfo = User::findOneAsArray('ID=:ID', [':ID' => $everyData['USER_ID']]);
  2354. $userEmpLevel = $empLevelConfig[$userBaseInfo['EMP_LV']];
  2355. $userEmpLevelSort = $userEmpLevel['SORT'] ?? EmployLevel::EMP_LEVEL_SORT['NO_LEVEL'];
  2356. unset($userBaseInfo, $userEmpLevel);
  2357. if( $userEmpLevelSort < EmployLevel::EMP_LEVEL_SORT['JX_ZR_LEVEL'] ) {
  2358. unset($userEmpLevelSort);
  2359. continue;
  2360. }
  2361. unset($userEmpLevelSort);
  2362. //根据总收入获取积分
  2363. $baseScore = $this->_getBaseScoreByTotalBonus($validTotalSum);
  2364. //根据用户的级别判断 能否得到级别积分
  2365. if( $baseScore > 0 ) {
  2366. //有记录就更新,没有记录就插入
  2367. $one = ScoreMonth::find()->where("USER_ID=:USER_ID AND CALC_MONTH=:CALC_MONTH", [
  2368. "USER_ID" => $everyData['USER_ID'],
  2369. "CALC_MONTH" => 202104
  2370. ])->asArray()->one();
  2371. if ( $one ) {
  2372. $totalScore = $baseScore + $one["LEVEL_SCORE"] + $one["UPGRADE_SCORE"];
  2373. ScoreMonth::updateAll(["BASE_SCORE"=>$baseScore, "TOTAL_SCORE"=>$totalScore], "ID=:ID", ["ID"=>$one["ID"]]);
  2374. }else {
  2375. $insertData[] = [
  2376. 'ID' => SnowFake::instance()->generateId(),
  2377. 'USER_ID' => $everyData['USER_ID'],
  2378. 'BASE_SCORE' => $baseScore,
  2379. 'TOTAL_SCORE' => $baseScore,
  2380. 'PERIOD_NUM' => 162,
  2381. 'CALC_MONTH' => 202104,
  2382. 'CREATED_AT' => time(),
  2383. ];
  2384. }
  2385. }
  2386. unset($everyData, $validTotalSum, $baseScore);
  2387. }
  2388. if($insertData) ScoreMonth::batchInsert($insertData);
  2389. unset($insertData, $allData);
  2390. return $this->actionCalcPoints($offset + $limit);
  2391. }
  2392. unset($allData);
  2393. return true;
  2394. }
  2395. /**
  2396. * 根据总收入获取相应的基础积分
  2397. * @param $totalBonus
  2398. * @return int|mixed
  2399. */
  2400. private function _getBaseScoreByTotalBonus($totalBonus) {
  2401. $sysConfig = cache::getSystemConfig();
  2402. $baseScoreConfig = Json::decode($sysConfig['baseScore']['VALUE']);
  2403. $baseScore = 0;
  2404. foreach ($baseScoreConfig as $everyScoreData) {
  2405. if( $totalBonus < $everyScoreData['monthTotalPvMin'] ) continue;
  2406. if( $everyScoreData['monthTotalPvMax'] != 0 && $totalBonus >= $everyScoreData['monthTotalPvMax'] ) continue;
  2407. $baseScore = $everyScoreData['score'];
  2408. unset($everyScoreData);
  2409. break;
  2410. }
  2411. unset($baseScoreConfig, $totalBonus);
  2412. return $baseScore;
  2413. }
  2414. }