UserProc.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. <?php
  2. namespace loyalsoft;
  3. require_once __DIR__ . '/../service_call/pay/official/pay_op.php';
  4. /**
  5. * Description of UserProc
  6. * 玩家数据处理流程
  7. *
  8. */
  9. class UserProc {
  10. const role_Table = 'tab_rolename';
  11. /**
  12. * 逻辑分发
  13. * 所有的Proc中必须有这样一个方法
  14. * @param Req $req
  15. */
  16. public static function procMain($req) {
  17. switch ($req->cmd) {
  18. case CmdCode::cmd_user_getzonelist: # 6000 分区列表
  19. return UserProc::GetZoneList();
  20. case CmdCode::cmd_user_loginuserinfo: # 6001 登录/新玩家直接注册并登录
  21. return UserProc::loginUserInfo();
  22. case CmdCode::cmd_user_gameconstinfo: # 6002 下载游戏配置
  23. return UserProc::downloadConstInfo();
  24. case CmdCode::cmd_user_setAnimation: # 6004 片头播放记录
  25. return UserProc::setAnimation();
  26. case CmdCode::cmd_user_replaceHeadImg: # 6005 替换头像
  27. return UserProc::replaceHeadImg();
  28. case CmdCode::cmd_user_delUserUid: # 6006 删除账号
  29. return UserProc::delUserUid();
  30. default:
  31. Err(ErrCode::cmd_err);
  32. }
  33. }
  34. /**
  35. * 6006 删除账号
  36. * @return type
  37. */
  38. public static function delUserUid() {
  39. $mem = gMem();
  40. $list = self::GetUserDataKeys(req()->uid, req()->zoneid); # 玩家数据key
  41. foreach ($list as $key) {
  42. if ($mem->exists($key)) {
  43. $mem->delete($key);
  44. }
  45. }
  46. // <editor-fold defaultstate="collapsed" desc="清理mongodb中的数据">
  47. self::deleteUserMapData(req()->uid, req()->zoneid);
  48. // </editor-fold>
  49. FightProc::DeleteRankInvalidUser(req()->uid);
  50. self::delRegRole(req()->zoneid, req()->uid, ctx()->baseInfo->name);
  51. //UserProc::updateUserInfo();
  52. $ret = array();
  53. return Resp::ok($ret);
  54. }
  55. private static function GetUserDataKeys($uid, $zoneid) {
  56. $list = array();
  57. $zoneKey = MemKey_User::Union_PlayedZoneInfo_normal($uid); # 分区信息
  58. $list[] = $zoneKey;
  59. $publicKey = MemKey_User::Union_PublicState_hash($uid); # 公共信息
  60. $list[] = $publicKey;
  61. $gameInfoKey = MemKey_User::Info_hash($zoneid, $uid); # 游戏数据主体
  62. $list[] = $gameInfoKey;
  63. $CurIdKey = MemKey_User::Mail_CurId_int($zoneid, $uid); # 当前邮件编号
  64. $list[] = $CurIdKey;
  65. $SysRecordKey = MemKey_User::Mail_SysRecord_set($zoneid, $uid); # 当前已经领取过的系统邮件记录
  66. $list[] = $SysRecordKey;
  67. $QueueKey = MemKey_User::Mail_Queue_hash($zoneid, $uid); # 邮件列表
  68. $list[] = $QueueKey;
  69. return $list;
  70. }
  71. /**
  72. * 删除账号-区别内外网
  73. * @param type $uid
  74. * @param type $type
  75. */
  76. static public function deleteUserMapData($uid, $zoneid) {
  77. gMongo()->delete("playerMapInfo", array('Uid' => $uid, 'ZoneId' => intval($zoneid))); # 地图
  78. gMongo()->delete("PlayerInfo", array('Uid' => $uid, 'ZoneId' => intval($zoneid)));
  79. gMongo()->delete("userInfoBack", array('key' => MemKey_User::Info_hash($zoneid, $uid)));
  80. }
  81. /**
  82. * 6005 替换头像
  83. * @return type
  84. */
  85. public static function replaceHeadImg() {
  86. list($img) = req()->paras;
  87. ctx()->baseInfo->headImg = $img;
  88. FightProc::UpdateRankUserHeadImg(req()->uid, $img);
  89. UserProc::updateUserInfo();
  90. $ret = array();
  91. return Resp::ok($ret);
  92. }
  93. /**
  94. * 6004 设置片头播放记录
  95. * @return type
  96. */
  97. public static function setAnimation() {
  98. list($tag) = req()->paras;
  99. if (ctx()->baseInfo->animation == 0 && $tag > 0) {
  100. ctx()->baseInfo->animation = 1;
  101. }
  102. UserProc::updateUserInfo();
  103. $ret = array();
  104. return Resp::ok($ret);
  105. }
  106. /**
  107. * 检测遗漏订单
  108. */
  109. static function checkMissOrder() {
  110. $tableName = "tpl_order_tab";
  111. if (daoInst()->tableExist($tableName)) {
  112. $arr = daoInst()->select("*")->from($tableName)
  113. ->where('uid')->eq(req()->uid)
  114. ->andWhere('zoneid')->eq(req()->zoneid)
  115. ->andWhere('status')->eq(1)
  116. ->andWhere('drawed_ts')->eq(0)
  117. ->fetchAll();
  118. if (count($arr) != null) {
  119. foreach ($arr as $item) {
  120. $result = pay_op::CheckAndDrawOrder(req()->uid, $item->cpOrderId, array(new PayProc, 'distributePayGoods'));
  121. }
  122. }
  123. }
  124. }
  125. /**
  126. * 6016 拉取其他玩家的信息.
  127. */
  128. public static function UserOtherPlayerInfo() {
  129. $zoneId = req()->zoneid;
  130. list($other_uid) = req()->paras;
  131. $g = UserProc::getUserGame($zoneId, $other_uid);
  132. my_Assert(null != $g, ErrCode::user_no_err); # 找不到指定的玩家数据
  133. return Resp::ok($g);
  134. }
  135. /**
  136. * 6000 【移动端】 获取分区列表
  137. */
  138. public static function GetZoneList() {
  139. $defaultZone = new Ins_ZoneInfo(1, 0, ""); # 新用户默认分区
  140. $bGetRecommended = false;
  141. if (count(req()->paras) > 0) { # 是否只拉取推荐分区
  142. $bGetRecommended = req()->paras[0];
  143. }
  144. $zoneList = array();
  145. $ts = now();
  146. // foreach (GameConfig::zonelist() as $zoneid => $zone) {
  147. // isEditor() and $zone = new \sm_zonelist();
  148. // if ($zone->publicTs > $ts) {
  149. // continue;
  150. // }
  151. // $zone->zoneid = $zoneid; # 把zoneid塞进zone数据结构中
  152. // if ($bGetRecommended) {
  153. // if ($zone->isRecommended > 0 && $zone->status == 1) {
  154. // $zoneList[] = $zone;
  155. // } else {
  156. //
  157. // }
  158. // } else {
  159. // $zoneList[] = $zone;
  160. // }
  161. // unset($zone->isRecommended);
  162. // }
  163. // UserProc::_AddTesterZonelist($zoneList); # 添加测试分区
  164. #
  165. // <editor-fold defaultstate="collapsed" desc=" 取玩家分区记录 ">
  166. $userZoneInfo = self::getUserZoneInfo(); # 玩家分区记录
  167. $isNewUser = false;
  168. if ($userZoneInfo == null) { // 这里使用推荐分区的数据,推荐分区信息,在后台编辑,编辑器可用
  169. $userZoneInfo = new Data_UserZoneInfo();
  170. $userZoneInfo->lastZone = $defaultZone; # 新用户导向默认分区
  171. $isNewUser = true;
  172. } else { # 转换一下格式,去掉key,只保留value的集合
  173. // $userZoneInfo->playedZones = ArrayInit();
  174. // array_merge($userZoneInfo->playedZones, array_values((array) $userZoneInfo->playedZones));
  175. }
  176. // </editor-fold>
  177. $ret = array(
  178. 'isNewUser' => $isNewUser,
  179. 'zonelist' => json_decode(json_encode($zoneList)),
  180. 'userZoneInfo' => $userZoneInfo
  181. );
  182. return Resp::ok($ret); # 返回值
  183. }
  184. private static function _AddTesterZonelist(&$zoneList) {
  185. if (config::Inst()->isTester(req()->uid)) { # 添加测试分区
  186. $zoneList[] = array('zoneid' => 999, 'name' => '内测专区', 'status' => 2, 'publicTs' => 0);
  187. }
  188. }
  189. /**
  190. * 6002 客户端下载常量配置信息
  191. * @return type
  192. */
  193. public static function downloadConstInfo() {
  194. list($clientDataVer) = req()->paras; # 客户端数据版本号,程序版本号
  195. $serverVer = GameConfig::ver(); # 最新数据版本号
  196. my_Assert($serverVer, ErrCode::err_const_no); # 找不到常量数据
  197. $url = config::CDN_host() . "/cfg/" . req()->CV . "/Client.bytes?" . $serverVer;
  198. $ret = array(
  199. 'version' => $serverVer,
  200. 'url' => $clientDataVer == $serverVer ? "" : $url, # # 如果版本一致,url传空,只传回版本号
  201. 'data' => null);
  202. return Resp::ok($ret);
  203. // $md5 = md5(json_encode($constInfo)); # 计算MD5值,多余计算md5
  204. // $constInfo = GameConfig::client(); # 取出来的已经是base64过的压缩数据
  205. // my_Assert($constInfo, ErrCode::err_const_no); # 找不到配置数据
  206. }
  207. /**
  208. * 6001 客户端登录并返还玩家信息
  209. * @return Resp
  210. */
  211. public static function loginUserInfo() {
  212. $game = UserProc::getUserGame(req()->zoneid, req()->uid);
  213. if ($game == null) { # 新用户, -> 6006创建账号
  214. $userID = req()->uid;
  215. list($nickName) = req()->paras;
  216. $id = gMem()->increment(MemKey_GameRun::Stat_UserCountByZone_int(req()->zoneid)); # 增加玩家数量计数
  217. $rolename = "No." . sprintf("%03d", req()->zoneid) . sprintf("%07d", $id); # 生成编号
  218. $rolename = $nickName; # 采用客户端传过来的值创建账号, 2024.6.24
  219. if (self::checkRoleNameNotExist($rolename)) { # 记录玩家
  220. $game = self::createUser($rolename);
  221. if (1 == self::regRole(req()->zoneid, $userID, $rolename, "", "", "")) {
  222. $resp = Resp::ok($game);
  223. self::updtateUserZoneInfo();
  224. } else {
  225. $resp = Resp::err(ErrCode::err_db);
  226. }
  227. } else { # 昵称已存在
  228. $resp = Resp::ok(array('ret' => '用户已存在.'));
  229. }
  230. $game->RegenNewToken();
  231. UserProc::updateUserInfo(); # 这一步回存操作只有在 userInfo正常存在的情况下才进行
  232. TaskProc::OnLogin_Daily();
  233. TaskProc::OnLogin_day7();
  234. FightProc::Ranking_FightPower();
  235. return $resp;
  236. } else { # 2.如果玩家已存在,则处理普通登录流程
  237. req()->game = $game; # 给Req挂载玩家数据
  238. $game->base()->Reset_tilits(); # 修正体力ts
  239. UserProc::checkContidays(); # 连续登录,状态检查
  240. //PayProc::m_refreshChargeOrders(); # 刷新订单, 多平台版本
  241. //PayProc::checkDeltest(); # 检查内侧充值记录(函数内部会只检查一次)
  242. //self::checkMissOrder(); #校验是否有漏单
  243. $game->RegenNewToken();
  244. UserProc::updateUserInfo(); # 这一步回存操作只有在 userInfo正常存在的情况下才进行
  245. FightProc::Ranking_FightPower();
  246. TaskProc::OnLogin_Daily();
  247. TaskProc::OnLogin_day7();
  248. $resp = Resp::ok($game); # 设置返回值
  249. self::updtateUserZoneInfo(); # 1. 更新玩家分区记录
  250. }
  251. return $resp;
  252. }
  253. //
  254. // <editor-fold defaultstate="collapsed" desc=" 辅助方法 ">
  255. /**
  256. * 检查昵称是否已经存在
  257. * @param string $roleName
  258. * @return boolean
  259. */
  260. static function checkRoleNameNotExist($roleName) {
  261. return true; # 不再检查昵称重复
  262. static $sqlFormat = "SELECT count(*) as rows FROM `tab_rolename` WHERE roleName='%s';";
  263. $sql = sprintf($sqlFormat, $roleName);
  264. $n = daoInst()->query($sql)->fetch();
  265. return $n->rows <= 0;
  266. }
  267. /**
  268. * 插入玩家新角色
  269. *
  270. * @param string $zoneid
  271. * @param string $userID
  272. * @param string $nickname
  273. * @param string $gender
  274. * @param string $profile_img
  275. * @param string $plat
  276. */
  277. static function regRole($zoneid, $userID, $nickname, $gender, $profile_img, $plat) {
  278. return daoInst()->insert('tab_rolename')
  279. ->data(array(
  280. 'zoneid' => $zoneid,
  281. 'userID' => $userID,
  282. 'roleName' => $nickname,
  283. 'gender' => $gender,
  284. 'profile' => $profile_img,
  285. 'plat' => $plat
  286. ))->exec();
  287. }
  288. /**
  289. *
  290. * @param type $zoneid
  291. * @param type $userID
  292. * @param type $nickname
  293. * @param type $gender
  294. * @param type $profile_img
  295. * @param type $plat
  296. * @return type
  297. */
  298. static function delRegRole($zoneid, $userID, $nickname) {
  299. return daoInst()->del('tab_rolename')
  300. ->data(array(
  301. 'zoneid' => $zoneid,
  302. 'userID' => $userID,
  303. 'roleName' => $nickname,
  304. ))->exec();
  305. }
  306. /**
  307. * 检测连续登录状态,重置必要字段[时间戳自动记录]
  308. */
  309. static function checkContidays($isnew = 0) {
  310. $ret = TimeUtil::totalDays() - TimeUtil::totalDays(ctx()->baseInfo->lastLogin); // 对比登录日期
  311. if ($ret > 0 || $isnew) { # 当天第一次登录
  312. self::OnNewDay($isnew);
  313. } else { # 更新下登录次数记录(任务计数器)
  314. }
  315. if ($ret == 1) { # 连续登录
  316. } else if ($ret >= 2) { # 隔天登录
  317. }
  318. ctx()->baseInfo->lastLogin = now(); # 更新下访问时间
  319. //TapDBUtil::SOnUserLogin(); # 向tapdb上报玩家登录 2023.5.10
  320. return $ret;
  321. }
  322. /**
  323. * 处理当天第一次登录
  324. * @param bool $isnew Description
  325. */
  326. static function OnNewDay($isnew) {
  327. ShopProc::DailyShopItemRand();
  328. ShopProc::ShopDailyClear();
  329. //self::clear();
  330. FightProc::FightDailyClear();
  331. //TaskProc::initAchieveData();
  332. TaskProc::ResetTask();
  333. }
  334. // static function clear() {
  335. // $dic = GameConfig::announcement();
  336. // foreach ($dic as $mo) {
  337. // if(now() > $mo->endTs && in_array($mo->id,ctx()->privateState->announcement)){
  338. // StlUtil::arrayRemove(ctx()->privateState->announcement, $mo->id);
  339. // }
  340. // }
  341. //
  342. // }
  343. // <editor-fold defaultstate="collapsed" desc="创建新用户">
  344. /**
  345. * 创建用户
  346. * @return Data_UserGame
  347. */
  348. static function createUser($rolename) {
  349. $game = new Data_UserGame();
  350. req()->game = $game; # 更新Req挂载的玩家数据,
  351. $game->initialize(); # 初始化玩家数据
  352. $game->baseInfo->name = $rolename;
  353. //$game->baseInfo->headImg = "";
  354. $game->baseInfo->firstLogin = now();
  355. #Ps 6006是没有获得到Userinfo到Req中的
  356. UserProc::checkContidays(1); # 每日状态检查
  357. // UserProc::fetchFromInteract($mem, $req); # 从interact拉取数据,Ps.初始化的过程应该还拉取不到什么有效数据
  358. UserProc::updateUserInfo(); # 回存用户数据
  359. return $game;
  360. }
  361. /**
  362. * 整理平台玩家记录集
  363. * @param int $isnew
  364. */
  365. private static function updatePlatUserRecord($isnew = 0) {
  366. $zoneid = req()->zoneid;
  367. $uid = req()->uid;
  368. $user = ctx()->baseInfo;
  369. $day = totalDays();
  370. $level = $user->level;
  371. $platUser = ObjectInit();
  372. $platUser->uid = $uid; #
  373. $platUser->name = $user->name; #
  374. $platUser->level = $level;
  375. $platUser->img = $user->headImg; # 头像字段
  376. $platUser->cash = $user->cash;
  377. $platUser->gold = $user->gold;
  378. $platUser->tili = $user->tili;
  379. $platUser->ts = now();
  380. $platUser->isnew = $isnew;
  381. gMem()->delete(MemKey_GameRun::DailyLoginUser_byUID_hash($zoneid, $day - 108));
  382. gMem()->hset(MemKey_GameRun::DailyLoginUser_byUID_hash($zoneid), $uid, $platUser);
  383. gMem()->delete(MemKey_GameRun::DailyLoginUser_byLevel_hash($zoneid, $level, $day - 108));
  384. gMem()->hset(MemKey_GameRun::DailyLoginUser_byLevel_hash($zoneid, $level), $uid, $platUser);
  385. }
  386. // </editor-fold>
  387. //
  388. // <editor-fold defaultstate="collapsed" desc="读写玩家数据">
  389. /**
  390. * 取玩家数据
  391. * @param type $zoneid
  392. * @param type $uid
  393. * @return Data_UserGame
  394. */
  395. public static function getUserGame($zoneid, $uid) {
  396. $key = MemKey_User::Info_hash($zoneid, $uid);
  397. // $pf = req()->getPlatStr();
  398. // if ($pf == "tap") { # taptap平台
  399. // $oldkey = MemKey_User::Info_hash($zoneid, req()->getPlatOid());
  400. // if (gMem()->exists($oldkey)) {
  401. // gMem()->rename($oldkey, $key); # 做下数据迁移
  402. // }
  403. // }
  404. $a = new Data_UserGame();
  405. if (null == $a->readDataFromMem($key)) { # ps.下面这一段代码和经常删号会有冲突,因此关闭了 --gwang 2022.2.28
  406. $collection = "userInfoBack";
  407. $cursor = gMongo()->find($collection, ['key' => $key], ['sort' => array('ts' => -1), 'limit' => 1]); # 提取备份数据
  408. $cursor->rewind();
  409. if ($cursor->valid()) {
  410. $v = $cursor->current();
  411. $a->LoadFrom($v->value); # 加载
  412. $a->updateDataFull($key); # 反向写回redis
  413. } else {
  414. return null;
  415. }
  416. }
  417. return new Data_UserGame($a);
  418. }
  419. /**
  420. * 更新用户数据(设置标志位,最后统一更新-gwang 2017.07.18)
  421. */
  422. public static function updateUserInfo() {
  423. my_Assert(req(), "req()为空");
  424. my_Assert(req()->game, "[" . req()->cmd . "] 玩家数据正在被清空!" . req()->uid);
  425. req()->userInfoChanged = TRUE; # 设置回写标志位
  426. }
  427. /**
  428. * 回写玩家数据
  429. * @param Data_UserGame $game
  430. */
  431. public static function setUserInfo($game) {
  432. $OK = false;
  433. if ($game) {
  434. $zoneid = req()->zoneid;
  435. $uid = req()->uid;
  436. $game->baseInfo->lastSaveTs = now();
  437. $key = MemKey_User::Info_hash($zoneid, $uid);
  438. $OK = $game->updateDataFull($key); # 向Redis回写玩家数据
  439. if ($OK) {
  440. // CLog::info($msg);
  441. self::backupUserInfoMongo(); # 向MongoDB备份数据
  442. gMem()->expire($key, 3600); # 设置过期时间1小时
  443. } else {
  444. // redo Logic
  445. CLog::err("写入数据时版本已过期!!!");
  446. }
  447. }
  448. return $OK;
  449. }
  450. // </editor-fold>
  451. //
  452. // <editor-fold defaultstate="collapsed" desc="玩家分区记录">
  453. /**
  454. * 读取玩家的分区记录
  455. * @return Data_UserZoneInfo Description
  456. */
  457. public static function getUserZoneInfo() {
  458. $ret = gMem()->get(MemKey_User::Union_PlayedZoneInfo_normal(req()->uid));
  459. return $ret;
  460. }
  461. /**
  462. * 更新玩家分区记录
  463. */
  464. public static function updtateUserZoneInfo() {
  465. $req = req();
  466. $userZoneInfo = self::getUserZoneInfo(); # 取玩家分区记录
  467. if (!$userZoneInfo) {
  468. $userZoneInfo = new Data_UserZoneInfo;
  469. }
  470. $level = 0;
  471. $zoneid = $req->zoneid;
  472. $playerName = "";
  473. $headImg = "";
  474. if (null != ctx()) { # 防御确保玩家数据不为空
  475. $level = ctx()->baseInfo->level;
  476. $playerName = ctx()->baseInfo->name;
  477. $headImg = ctx()->baseInfo->headImg;
  478. } else {
  479. Err('玩家数据为空!' . __CLASS__ . '.' . __FUNCTION__);
  480. }
  481. if (is_null($level)) {
  482. $level = 0;
  483. }
  484. $userZoneInfo->lastZone = new Ins_ZoneInfo($zoneid, $level, $playerName, $headImg); # 更新玩家分区记录
  485. $userZoneInfo->playedZones->$zoneid = $userZoneInfo->lastZone; # 玩过的分区集合
  486. gMem()->set(MemKey_User::Union_PlayedZoneInfo_normal($req->uid), $userZoneInfo); # 回写数据
  487. }
  488. // </editor-fold>
  489. // <editor-fold defaultstate="collapsed" desc=" 用户数据备份 ">
  490. /**
  491. * 备份玩家数据,(玩家数据落地),一天一份,当天记为最后一次登录时的状态而非最后一次操作的状态
  492. * @history
  493. * version 3.0.13 mysql版备份玩家数据, (性能优化后表现还不错)
  494. * 除非用脚本在redis中实现备份,否则直接写入mysql.
  495. * 主要是mysql版本利用存储过程之后性能已经和redis版相差不多.
  496. * version 2.0.0 Redis storage 从MySQL转到Redis中存储. 这个备份数据没有大规模导出硬盘的需求
  497. * 因为mysql版本实在是负载太大了, 上百毫秒. 所以改在redis中了.
  498. * version 1.0.0 Mysql storagef 1. 分表不做了, 2. 存储过程不用了 3. 先能用再说
  499. */
  500. public static function backupUserInfo() {
  501. $tsday = TimeUtil::totalDays(); # 精确到天,保留10个最近记录.
  502. $value = base64_encode(gzdeflate(JsonUtil::encode(ctx()))); # blob数据,序列化下
  503. $sql = sprintf("call insertUserInfo('%s', %d, %d, '%s');", # # 所以直接将序列化后的结果存进去吧,
  504. req()->uid, req()->zoneid, $tsday, $value); # zoneid, uid, tsday
  505. daoInst()->exec($sql); # 也可以用exec($sql)
  506. }
  507. /**
  508. * 备份玩家数据,(玩家数据落地),一天一份,当天记为最后一次登录时的状态而非最后一次操作的状态
  509. * @history
  510. * version 4.0.0 切换到MongoDB存储
  511. * version 3.0.13 mysql版备份玩家数据, (性能优化后表现还不错)
  512. * 除非用脚本在redis中实现备份,否则直接写入mysql.
  513. * 主要是mysql版本利用存储过程之后性能已经和redis版相差不多.
  514. * version 2.0.0 Redis storage 从MySQL转到Redis中存储. 这个备份数据没有大规模导出硬盘的需求
  515. * 因为mysql版本实在是负载太大了, 上百毫秒. 所以改在redis中了.
  516. * version 1.0.0 Mysql storagef 1. 分表不做了, 2. 存储过程不用了 3. 先能用再说
  517. */
  518. public static function backupUserInfoMongo() {
  519. $collectionName = "userInfoBack"; # 表名
  520. $key = MemKey_User::Info_hash(req()->zoneid, req()->uid);
  521. $doc = array('key' => $key, # # 最新文档
  522. 'ts' => TimeUtil::dtCurrent(), # # 更新时间
  523. 'stVer' => ctx()->stVer, # # 增加版本号
  524. 'value' => ctx()); # 玩家数据
  525. $bok = gMongo()->insert($collectionName, $doc); # 插入备份
  526. // CLog::err($collectionName . "备份玩家数据" . req()->uid . ($bok ? "成功" : "失败"));
  527. if (ctx()->stVer % 100 == 1) { # 每100条记录清理一次(delete耗时比较长-gwang.2023年3月10日)
  528. $delFilter = array('key' => $key, 'stVer' => ['$lt' => ctx()->stVer - 100]); # 保留最后一百次变更记录
  529. gMongo()->delete($collectionName, $delFilter);
  530. }
  531. // $filter = array('key' => $key); # 指定条件
  532. // gMongo()->update($collectionName, $filter, $doc, true); # 更新
  533. }
  534. // </editor-fold>
  535. //</editor-fold>
  536. //
  537. }