landing.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. <?php
  2. defined('IN_WEB') or die( 'Include Error!');
  3. /**
  4. * 数据落地
  5. * Class ModelLanding
  6. * Created by: Owen
  7. * Created on: 2020/3/26 15:06
  8. */
  9. class ModelLanding {
  10. public $expire;
  11. public $cardKeyJson = [];
  12. public function __construct(){
  13. $this->expire = time() - 24*60*60;
  14. $this->cardKeyJson = ['ciid', 'send_card','sended_card', 'csid', 'cgreward', 'cpreward'];
  15. }
  16. /**
  17. * 统一落地
  18. * @param bool $uid
  19. * Created by: Owen
  20. * Created on: 2020/3/26 19:29
  21. */
  22. public function unionLanding($uid = false){
  23. self::card($uid);
  24. // self::achieve($uid);
  25. self::userStatistics();
  26. // self::mining($uid);
  27. self::props($uid);
  28. self::building($uid);
  29. self::dynamics();
  30. self::pet($uid);
  31. // self::coindozer($uid);
  32. self::userFriend();
  33. }
  34. /**
  35. * 卡片落地
  36. * @param bool $uid
  37. * @param bool $recursive 递归
  38. * @return bool
  39. * Created by: Owen
  40. * Created on: 2020/3/26 19:34
  41. */
  42. public function card($uid = false,$recursive = false){
  43. if($uid != false){
  44. if(!$recursive){
  45. if(!oo::commonOprRedis('common')->zScore(okeys::Landing("CARD", $uid),$uid)){
  46. return false;
  47. }
  48. }
  49. $userCardInfo = oo::commonOprModel('card')->getUserCardInfo($uid);
  50. $tb = otable::usercard_config($uid);
  51. $sql= "UPDATE {$tb} SET ";
  52. foreach ($userCardInfo as $key=>$row){
  53. if($key == "id" || $key == "uid"){
  54. continue;
  55. }
  56. if(in_array($key,$this->cardKeyJson)){
  57. $temp = json_encode($row);
  58. $sql .= "`$key`='$temp',";
  59. }else{
  60. $sql .= "`$key`='$row',";
  61. }
  62. }
  63. $sql = trim($sql,',');
  64. $sql.= " WHERE uid={$uid} LIMIT 1";
  65. $ret = oo::commonOprDb('common')->query($sql);
  66. if($ret){
  67. oo::commonOprRedis('common')->zDelete(okeys::Landing("CARD", $uid),$uid);
  68. oo::commonOprRedis('common')->setex(okeys::UserCardInfo($uid),json_encode($userCardInfo),oo::redisRandomExpire(7*24*60*60));
  69. }
  70. }else{
  71. $keys = okeys::LandingKeys("CARD");
  72. foreach($keys as $okey){
  73. $ret = oo::commonOprRedis('common')->zRangeByScore($okey,0,$this->expire,['withscores'=>true]);
  74. foreach ($ret as $key=>$row){
  75. if(!$key){
  76. oo::commonOprRedis('Usercache')->zDelete($okey,$key);
  77. continue;
  78. }
  79. self::card($key,true);
  80. }
  81. }
  82. }
  83. }
  84. /**
  85. * 成就落地
  86. * @param bool $uid
  87. * @param bool $recursive
  88. * @return bool
  89. * Created by: Owen
  90. * Created on: 2020/4/7 19:15
  91. */
  92. public function achieve($uid = false,$recursive = false){
  93. if($uid != false){
  94. if(!$recursive){
  95. if(!oo::commonOprRedis('common')->zScore(okeys::Landing("ACHIEVE", $uid),$uid)){
  96. return false;
  97. }
  98. }
  99. $userAchieve = oo::commonOprModel('achievement')->getUserAchieve($uid);
  100. $tb = otable::achievement($uid);
  101. $achieveSize = count($userAchieve);
  102. $noLandingSize = 0;
  103. foreach ($userAchieve as $achieve){
  104. if(isset($achieve['isLanding']) && $achieve['isLanding'] == 1){
  105. $sql= "UPDATE {$tb} SET ";
  106. foreach ($achieve as $key=>$row){
  107. if($key == "aid" || $key == "uid" || $key == "isLanding"){
  108. continue;
  109. }
  110. $sql .= "`$key`='$row',";
  111. }
  112. $sql = trim($sql,',');
  113. $sql.= " WHERE uid={$uid} AND aid={$achieve['aid']} LIMIT 1";
  114. $ret = oo::commonOprDb('common')->query($sql);
  115. }else{
  116. $noLandingSize++;
  117. }
  118. }
  119. if($ret || $achieveSize == $noLandingSize){
  120. oo::commonOprRedis('common')->zDelete(okeys::Landing("ACHIEVE", $uid),$uid);
  121. oo::commonOprRedis('common')->expire(okeys::UserAchieve($uid),oo::redisRandomExpire(3*24*60*60));
  122. }
  123. }else{
  124. $keys = okeys::LandingKeys("ACHIEVE");
  125. foreach($keys as $okey){
  126. $ret = oo::commonOprRedis('common')->zRangeByScore($okey,0,$this->expire,['withscores'=>true]);
  127. foreach ($ret as $key=>$row){
  128. if(!$key){
  129. oo::commonOprRedis('Usercache')->zDelete($okey,$key);
  130. continue;
  131. }
  132. self::achieve($key,true);
  133. }
  134. }
  135. }
  136. }
  137. /**
  138. * 个人统计
  139. * @param bool $uid
  140. * @param bool $recursive
  141. * @return bool
  142. * Created by: Owen
  143. * Created on: 2020/4/10 16:16
  144. */
  145. // public function statistics($uid = false,$recursive = false){
  146. // if($uid != false){
  147. // if(!$recursive){
  148. // if(!oo::commonOprRedis('Usercache')->zScore(okeys::Landing("STATISTICS", $uid),$uid)){
  149. // return false;
  150. // }
  151. // }
  152. // $userStatistics = oo::commonOprModel('member')->getUserBasicsStatistics($uid);
  153. // $inData= [];
  154. // $tb = otable::statistics($uid);
  155. // $sql= "UPDATE {$tb} SET ";
  156. // foreach ($userStatistics as $key=>$row){
  157. // if($key == "id" || $key == "uid"){
  158. // continue;
  159. // }
  160. // $inData[$key]=$row;
  161. // $sql .= "`$key`='$row',";
  162. // }
  163. // $sql = trim($sql,',');
  164. // $sql.= " WHERE uid={$uid} LIMIT 1";
  165. // $ret = oo::commonOprDb('common')->query($sql);
  166. // if(!$ret){
  167. // $inData['uid'] = $uid;
  168. // $sql2 = funs::db_insertSQL($tb,$inData);
  169. // $ret =oo::commonOprDb('common')->query($sql2);
  170. // }
  171. // if($ret){
  172. // oo::commonOprRedis('Usercache')->zDelete(okeys::Landing("STATISTICS", $uid),$uid);
  173. // oo::commonOprRedis('userinfo')->expire(okeys::UserStatistics($uid),86400*7);
  174. // }
  175. // }else{
  176. // $keys = okeys::LandingKeys("STATISTICS");
  177. // foreach($keys as $okey){
  178. // $ret = oo::commonOprRedis('Usercache')->zRangeByScore($okey,0,$this->expire,['withscores'=>true]);
  179. // foreach ($ret as $key=>$row){
  180. // if(!$key){
  181. // oo::commonOprRedis('Usercache')->zDelete($okey,$key);
  182. // continue;
  183. // }
  184. // self::statistics($key,true);
  185. // }
  186. // }
  187. // }
  188. // }
  189. /**
  190. * 矿工落地
  191. * @param bool $uid
  192. * @param bool $recursive
  193. * @return bool
  194. * Created by: Owen
  195. * Created on: 2020/4/10 16:16
  196. */
  197. public function mining($uid = false,$recursive = false){
  198. if($uid != false){
  199. if(!$recursive){
  200. if(!oo::commonOprRedis('common')->zScore(okeys::Landing("MINING", $uid),$uid)){
  201. return false;
  202. }
  203. }
  204. $userMiningInfo = oo::commonOprModel('mining')->getUserMiningInfo($uid);
  205. $tb = otable::miningInfo();
  206. $islandLevel = addslashes(json_encode($userMiningInfo['islandLevel']));
  207. $ret = oo::commonOprDb('common')->query("UPDATE {$tb} SET `islandLevel`='{$islandLevel}' WHERE uid={$uid} LIMIT 1");
  208. if($ret){
  209. oo::commonOprRedis('common')->zDelete(okeys::Landing("MINING", $uid),$uid);
  210. oo::commonOprRedis('common')->setex(okeys::UserMining($uid),json_encode($userMiningInfo),oo::redisRandomExpire(7*24*60*60));
  211. }
  212. }else{
  213. $keys = okeys::LandingKeys("MINING");
  214. foreach($keys as $okey){
  215. $ret = oo::commonOprRedis('common')->zRangeByScore($okey,0,$this->expire,['withscores'=>true]);
  216. foreach ($ret as $key=>$row){
  217. if(!$key){
  218. oo::commonOprRedis('Usercache')->zDelete($okey,$key);
  219. continue;
  220. }
  221. self::mining($key,true);
  222. }
  223. }
  224. }
  225. }
  226. /**
  227. * 道具落地
  228. * @param bool $uid
  229. * @param bool $recursive
  230. * @return bool
  231. * Created by: Owen
  232. * Created on: 2020/5/7 20:31
  233. */
  234. public function props($uid = false,$recursive = false){
  235. if($uid != false){
  236. if(!$recursive){
  237. if(!oo::commonOprRedis('common')->zScore(okeys::Landing("PROPS", $uid),$uid)){
  238. return false;
  239. }
  240. }
  241. $propsInfo = oo::commonOprModel('props')->getUserPropsData($uid);
  242. $tb = otable::userprops($uid);
  243. $cacheKey = okeys::UserProps($uid);
  244. foreach ($propsInfo as $row){
  245. if(isset($row['isLanding']) && $row['isLanding'] == 1){
  246. if($row['count'] <= 0){
  247. $ret = oo::commonOprDb('common')->query("DELETE FROM {$tb} WHERE uid = {$uid} AND id = {$row['id']} LIMIT 1");
  248. oo::commonOprRedis('common')->hDel($cacheKey,$row['id']);
  249. }else{
  250. $ret = oo::commonOprDb('common')->query("UPDATE {$tb} SET `count`='{$row['count']}' WHERE uid = {$uid} AND id = {$row['id']} LIMIT 1");
  251. $temp = $row;
  252. unset($temp['isLanding']);
  253. oo::commonOprRedis('common')->hSet($cacheKey,$row['id'],json_encode($temp));
  254. }
  255. }
  256. }
  257. if($ret){
  258. oo::commonOprRedis('common')->zDelete(okeys::Landing("PROPS", $uid),$uid);
  259. oo::commonOprRedis('common')->expire($cacheKey,oo::redisRandomExpire(7*24*60*60));
  260. }
  261. }else{
  262. $keys = okeys::LandingKeys("PROPS");
  263. foreach($keys as $okey){
  264. $ret = oo::commonOprRedis('common')->zRangeByScore($okey,0,$this->expire,['withscores'=>true]);
  265. foreach ($ret as $key=>$row){
  266. if(!$key){
  267. oo::commonOprRedis('Usercache')->zDelete($okey,$key);
  268. continue;
  269. }
  270. self::props($key,true);
  271. }
  272. }
  273. }
  274. }
  275. /**
  276. * 建筑落地
  277. * @param bool $uid
  278. * @param bool $recursive
  279. * @return bool
  280. * Created by: Owen
  281. * Created on: 2020/5/7 20:31
  282. */
  283. public function building($uid = false,$recursive = false){
  284. if($uid != false){
  285. if(!$recursive){
  286. if(!oo::commonOprRedis('common')->zScore(okeys::Landing("BUILDING", $uid),$uid)){
  287. return false;
  288. }
  289. }
  290. $userBuildInfo = oo::commonOprModel('member')->getUserLevel($uid);
  291. if(isset($userBuildInfo['isLanding']) && $userBuildInfo['isLanding'] == 1){
  292. $tb = otable::userlevel($uid);
  293. $level = $userBuildInfo['levelId'];
  294. $element = addslashes(json_encode($userBuildInfo['element']));
  295. $is_reward = intval($userBuildInfo['is_reward']);
  296. $ret = oo::commonOprDb('common')->getOne("SELECT max(levelId) as levelId FROM {$tb} WHERE uid={$uid} LIMIT 1",MYSQLI_ASSOC);
  297. if(empty($ret) || $ret['levelId'] == 0){
  298. $d_str_level = '[{\"id\":1,\"level\":0,\"maxLevel\":0,\"status\":0},{\"id\":2,\"level\":0,\"maxLevel\":0,\"status\":0},{\"id\":3,\"level\":0,\"maxLevel\":0,\"status\":0},{\"id\":4,\"level\":0,\"maxLevel\":0,\"status\":0},{\"id\":5,\"level\":0,\"maxLevel\":0,\"status\":0}]';
  299. if($level<1){
  300. $level =1;
  301. }
  302. if($element){
  303. $str_level = $element;
  304. }else{
  305. $str_level = $d_str_level;
  306. }
  307. $time = time();
  308. $res = oo::commonOprDb('common')->query("INSERT INTO {$tb} (`uid`,`levelId`,`element`,`createTime`) VALUES ({$uid},$level, '$str_level','{$time}')");
  309. $ret['levelId'] = $level;
  310. oo::logs()->commlog(["uid"=>$uid,"userBuildInfo"=>$userBuildInfo,"res"=>$res],"landing_creatUserLevel.log");
  311. }
  312. $ret = oo::commonOprDb('common')->query("UPDATE {$tb} SET `levelId`={$level},`element`='{$element}',is_reward='{$is_reward}' WHERE uid = {$uid} AND levelId={$ret['levelId']} LIMIT 1");
  313. if($ret){
  314. oo::commonOprRedis('common')->zDelete(okeys::Landing("BUILDING", $uid),$uid);
  315. }
  316. }
  317. oo::commonOprRedis('common')->expire(okeys::UserBuildLevel($uid),oo::redisRandomExpire(7*24*60*60));
  318. }else{
  319. $keys = okeys::LandingKeys("BUILDING");
  320. foreach($keys as $okey){
  321. $ret = oo::commonOprRedis('common')->zRangeByScore($okey,0,$this->expire,['withscores'=>true]);
  322. foreach ($ret as $key=>$row){
  323. if(!$key){
  324. oo::commonOprRedis('Usercache')->zDelete($okey,$key);
  325. continue;
  326. }
  327. self::building($key,true);
  328. }
  329. }
  330. }
  331. }
  332. /**
  333. * Notes:用户重要信息落地
  334. * User: wsc
  335. * Time: 2020/6/30 18:43
  336. * @param bool $uid
  337. * @param bool $recursive
  338. * @return bool
  339. */
  340. public function gameinfo($uid=false,$recursive=false){
  341. if($uid != false){
  342. if(!$recursive){
  343. if(!oo::commonOprRedis('Usercache')->zScore(okeys::Landing("GAMEINFO", $uid),$uid)){
  344. return false;
  345. }
  346. }
  347. $userinfo = oo::commonOprModel('member')->getUserAssetsInfo($uid);
  348. $tb = otable::gh_gameserver($uid);
  349. $sql= "UPDATE {$tb} SET ";
  350. foreach ($userinfo as $key=>$row){
  351. if($key == "id" || $key == "uid"){
  352. continue;
  353. }
  354. $sql .= "`$key`='$row',";
  355. }
  356. $sql = trim($sql,',');
  357. $sql.= " WHERE mid={$uid} LIMIT 1";
  358. $ret = oo::commonOprDb('ghgames')->query($sql);
  359. if($ret){
  360. oo::commonOprRedis('Usercache')->zDelete(okeys::Landing("GAMEINFO", $uid),$uid);
  361. oo::commonOprRedis('user')->persist(okeys::userAttr($uid));
  362. // oo::commonOprRedis('user')->expire(okeys::userAttr($uid),oo::redisRandomExpire(86400*7*24));
  363. }
  364. }else{
  365. $t = time() - 60;
  366. $keys = okeys::LandingKeys("GAMEINFO");
  367. foreach($keys as $okey){
  368. $ret = oo::commonOprRedis('Usercache')->zRangeByScore($okey,0,$t,['withscores'=>true]);
  369. foreach ($ret as $key=>$row){
  370. if(!$key){
  371. oo::commonOprRedis('Usercache')->zDelete($okey, $key);
  372. continue;
  373. }
  374. self::gameinfo($key,true);
  375. }
  376. }
  377. }
  378. }
  379. /**
  380. * 用户动态数据
  381. * @param bool $uid
  382. * @param bool $recursive
  383. * @return bool
  384. * Created by: Owen
  385. * Created on: 2020/4/10 16:16
  386. */
  387. public function dynamics(){
  388. $keys = okeys::LandingKeys("DYNAMICS");
  389. foreach($keys as $okey){
  390. $ret = oo::commonOprRedis('Usercache')->zRangeByScore($okey,0,$this->expire,['withscores'=>true]);
  391. if(empty($ret)){
  392. continue;
  393. }
  394. foreach ($ret as $uid=>$row){
  395. if(!$uid){
  396. continue;
  397. }
  398. $uinfoStr=oo::commonOprRedis('common')->get("UserDynamicsData:{$uid}");
  399. $tb = otable::UserDynamicsData();
  400. if($uinfoStr){
  401. $uinfo = json_decode($uinfoStr,true);
  402. if(is_array($uinfo)&&!empty($uinfo)){
  403. $update =[
  404. 'activeDay'=>$uinfo['activeDay'],// 活跃天数
  405. 'pushLock'=>$uinfo['pushLock'],// 推送开关
  406. 'groupId3'=>$uinfo['groupId3'],// 数数分组
  407. ];
  408. $sql = funs::db_updateSQL($tb,$update,"uid={$uid}");
  409. $ret = oo::commonOprDb('common')->query($sql);
  410. if(!$ret){
  411. oo::logs()->commlog(["time"=>time(),"context"=>"dynamics-落地失败","data"=>$sql],"landing.log");
  412. }
  413. }
  414. }
  415. oo::commonOprRedis('Usercache')->zDelete($okey,$uid);
  416. }
  417. }
  418. }
  419. public function dynamics_old($uid = false,$recursive = false){
  420. if($uid != false){
  421. if(!$recursive){
  422. if(!oo::commonOprRedis('Usercache')->zScore(okeys::Landing("DYNAMICS", $uid),$uid)){
  423. return false;
  424. }
  425. }
  426. $userDynamicsData = oo::commonOprModel('member')->getUserDynamicsData($uid);
  427. if(!isset($userDynamicsData['isLanding']) || $userDynamicsData['isLanding'] != 1){
  428. oo::commonOprRedis('Usercache')->zDelete(okeys::Landing("DYNAMICS", $uid),$uid);
  429. return false;
  430. }
  431. // $tb = otable::UserDynamicsData();
  432. // $sql= "UPDATE {$tb} SET ";
  433. // foreach ($userDynamicsData as $key=>$row){
  434. // if($key == "isLanding" || $key == "uid"){
  435. // continue;
  436. // }
  437. // if($key == "userCache"){
  438. // $row = json_encode((array)$row);
  439. // $temp = addslashes($row);
  440. // $sql .= "`$key`='$temp',";
  441. // }else{
  442. // $sql .= "`$key`='$row',";
  443. // }
  444. // }
  445. // $sql = trim($sql,',');
  446. // $sql.= " WHERE uid={$uid} LIMIT 1";
  447. // $ret = oo::commonOprDb('common')->query($sql);
  448. // if($ret){
  449. oo::commonOprRedis('Usercache')->zDelete(okeys::Landing("DYNAMICS", $uid),$uid);
  450. oo::commonOprRedis('userinfo')->expire(okeys::UserDynamicsData($uid),oo::redisRandomExpire(86400*7));
  451. // }
  452. }else{
  453. $keys = okeys::LandingKeys("DYNAMICS");
  454. foreach($keys as $okey){
  455. $ret = oo::commonOprRedis('Usercache')->zRangeByScore($okey,0,$this->expire,['withscores'=>true]);
  456. foreach ($ret as $key=>$row){
  457. if(!$key){
  458. oo::commonOprRedis('Usercache')->zDelete($okey,$key);
  459. continue;
  460. }
  461. self::dynamics_old($key,true);
  462. }
  463. }
  464. }
  465. }
  466. /**
  467. * 用户宠物数据
  468. * @param bool $uid
  469. * @param bool $recursive
  470. * @return bool
  471. * Created by: Owen
  472. * Created on: 2020/4/10 16:16
  473. */
  474. public function pet($uid = false,$recursive = false){
  475. if($uid != false){
  476. if(!$recursive){
  477. if(!oo::commonOprRedis('Usercache')->zScore(okeys::Landing("PET", $uid),$uid)){
  478. return false;
  479. }
  480. }
  481. $userPetArr = oo::commonOprModel('pet')->getUserPet($uid,0,true);
  482. $tb = otable::UserPet($uid);
  483. $deleteFlag = false;
  484. foreach ($userPetArr as $row){
  485. if($row['isLanding'] == 1){
  486. $sql= "UPDATE {$tb} SET ";
  487. foreach ($row as $key=>$value){
  488. if($key == "isLanding" || $key == "uid" || $key == "petId"){
  489. continue;
  490. }
  491. $sql .= "`$key`='$value',";
  492. }
  493. $petId = $row['petId'];
  494. $sql = trim($sql,',');
  495. if(empty($petId)){
  496. $deleteFlag = true;
  497. continue;
  498. }
  499. $sql.= " WHERE uid={$uid} AND petId={$petId} LIMIT 1";
  500. oo::commonOprDb('common')->query($sql);
  501. }
  502. }
  503. if($deleteFlag){
  504. oo::commonOprRedis('User')->delete(okeys::UserPet2($uid));
  505. oo::commonOprModel('pet')->getUserPet($uid);
  506. }
  507. oo::commonOprRedis('Usercache')->zDelete(okeys::Landing("PET", $uid),$uid);
  508. oo::commonOprRedis('userinfo')->expire(okeys::UserPet2($uid),oo::redisRandomExpire(86400*7));
  509. }else{
  510. $keys = okeys::LandingKeys("PET");
  511. foreach($keys as $okey){
  512. $ret = oo::commonOprRedis('Usercache')->zRangeByScore($okey,0,$this->expire,['withscores'=>true]);
  513. foreach ($ret as $key=>$row){
  514. if(!$key){
  515. oo::commonOprRedis('Usercache')->zDelete($okey,$key);
  516. continue;
  517. }
  518. self::pet($key,true);
  519. }
  520. }
  521. }
  522. }
  523. /**
  524. * Notes:推金币用户游戏数据落地
  525. * User: wsc
  526. * Time: 2020/11/26 12:20
  527. * @param bool $uid
  528. * @param bool $recursive
  529. * @return bool
  530. */
  531. public function coindozer($uid = false,$recursive = false){
  532. if($uid != false){
  533. if(!$recursive){
  534. if(!oo::commonOprRedis('common')->zScore(okeys::Landing("COINDOZER_GAMEDATA"),$uid)){
  535. return false;
  536. }
  537. }
  538. $key1 = okeys::userGameInfoCoinDozer($uid);
  539. $userGameInfo = oo::commonOprModel('coindozer')->getUserGameInfo($uid)['info'];
  540. $tb = otable::usercoindozer();
  541. $data = $userGameInfo;
  542. $data['up_ts'] =time();
  543. unset($data['uid'],$data['create_ts']);
  544. $sql = funs::db_updateSQL($tb,$data," uid={$uid}");
  545. $ret = oo::commonOprDb('common')->query($sql);
  546. if($ret){
  547. // oo::commonOprRedis('usercache')->hMset($key1,$userGameInfo);
  548. oo::commonOprRedis('Usercache')->zDelete(okeys::Landing("COINDOZER_GAMEDATA"),$uid);
  549. oo::commonOprRedis('usercache')->expire($key1,oo::redisRandomExpire(86400*7));
  550. }
  551. }else{
  552. $ret = oo::commonOprRedis('Usercache')->zRangeByScore(okeys::Landing("COINDOZER_GAMEDATA"),0,$this->expire,['withscores'=>true]);
  553. foreach ($ret as $key=>$row){
  554. if(!$key){
  555. oo::commonOprRedis('Usercache')->zDelete(okeys::Landing("COINDOZER_GAMEDATA"),$key);
  556. continue;
  557. }
  558. self::coindozer($key,true);
  559. }
  560. }
  561. }
  562. /**
  563. * Notes:用户统计游戏数据落地
  564. * User: wsc
  565. * Time: 2020/11/26 12:20
  566. * @param bool $uid
  567. * @param bool $recursive
  568. * @return bool
  569. */
  570. public function userStatistics()
  571. {
  572. $keys = okeys::LandingKeys("USERSTATISTICS");var_dump($keys);
  573. foreach($keys as $okey){
  574. $ret = oo::commonOprRedis('common')->zRangeByScore($okey, 0, $this->expire, ['withscores' => true]);
  575. if(empty($ret)){
  576. continue;
  577. }
  578. foreach ($ret as $uid => $row) {
  579. if (!$uid) {
  580. oo::commonOprRedis('common')->zDelete($okey, $uid);
  581. continue;
  582. }
  583. $cacheKey = okeys::UserStatistics($uid);
  584. $userStatisticsInfo = oo::commonOprRedis('Statistics')->hGetAll($cacheKey);
  585. if ($userStatisticsInfo) {
  586. $tb = otable::UserStatistics($uid);
  587. unset($userStatisticsInfo['uid']);
  588. oo::commonOprDb('common')->query(funs::db_updateSQL($tb, $userStatisticsInfo, " uid={$uid}"));
  589. oo::commonOprRedis('Statistics')->expire($cacheKey,86400*7);
  590. }
  591. oo::commonOprRedis('common')->zDelete($okey, $uid);
  592. }
  593. }
  594. }
  595. /**
  596. * Notes:好友数据落地
  597. * User: wsc
  598. * Time: 2022/2/25 21:14
  599. * @param bool $uid
  600. * @param bool $recursive
  601. * @return bool
  602. */
  603. public function userFriend($uid =false,$recursive=false){
  604. if($uid != false){
  605. if(!$recursive){
  606. if(!oo::commonOprRedis('Usercache')->zScore(okeys::Landing("USERFRIENDS", $uid),$uid)){
  607. return false;
  608. }
  609. }
  610. if(!is_int($uid)){
  611. oo::commonOprRedis('Usercache')->zDelete(okeys::Landing("USERFRIENDS", $uid),$uid);
  612. return false;
  613. }
  614. $data =[];
  615. $fields = ["poker"=>"fb","nopoker"=>"nopoker","game_list"=>"game"];
  616. foreach ($fields as $k=>$type){
  617. $friendsStr = oo::commonOprRedis('userinfo')->get(okeys::userfriends($uid,$type));
  618. if(!$friendsStr){
  619. continue;
  620. }
  621. $friendsList = json_decode($friendsStr,true);
  622. $data[$k] = is_array($friendsList)?implode(',',$friendsList):'';
  623. }
  624. $data['updatetime']=time();
  625. $w =" uid={$uid}";
  626. $sql = funs::db_updateSQL(otable::userfriends($uid),$data,$w);
  627. $ret = oo::commonOprDb('common')->query($sql);
  628. if($ret){
  629. oo::commonOprRedis('Usercache')->zDelete(okeys::Landing("USERFRIENDS", $uid),$uid);
  630. oo::commonOprRedis('user')->expire(okeys::userfriends($uid,$type),oo::redisRandomExpire(86400*7));
  631. }
  632. }else{
  633. $t = time() - 60;
  634. $keys = okeys::LandingKeys("USERFRIENDS");
  635. foreach($keys as $okey){
  636. $ret = oo::commonOprRedis('Usercache')->zRangeByScore($okey,0,$t,['withscores'=>true]);
  637. foreach ($ret as $key=>$row){
  638. if(!$key){
  639. oo::commonOprRedis('Usercache')->zDelete($okey, $key);
  640. continue;
  641. }
  642. self::userFriend($key,true);
  643. }
  644. }
  645. }
  646. }
  647. }