UserProc.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  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. case CmdCode::cmd_user_removeNewHeadImgTip: # 6007 移除新头像标志
  31. return UserProc::removeNewHeadImgTip();
  32. case CmdCode::cmd_user_readAnnouncement: # 6008 读公告记录
  33. return UserProc::readAnnouncement();
  34. case CmdCode::cmd_user_clearFunUnlockInfo: # 6009 重置功能解锁记录信息
  35. return UserProc::clearFunUnlockInfo();
  36. case CmdCode::user_rename: # 6010 改名
  37. return self::ReName();
  38. case CmdCode::cmd_user_completeNewbieGuide: # 6011 新手引导更新
  39. return self::completeNewbieGuide();
  40. case CmdCode::cmd_user_clearGuideInfo: # 6012 清理引导记录
  41. return self::clearGuideInfo();
  42. default:
  43. Err(ErrCode::cmd_err);
  44. }
  45. }
  46. public static function clearGuideInfo(){
  47. list($id) = req()->paras; # 参数:引导模块
  48. ctx()->privateState->funUnlockRecord_3 = array();
  49. UserProc::updateUserInfo(); # 回写数据
  50. return Resp::ok(array());
  51. }
  52. /**
  53. * 更新新手引导阶段步骤
  54. */
  55. public static function completeNewbieGuide() {
  56. list($guideType,$guide_type_forceSave) = req()->paras; # 参数: 新手引导步骤
  57. ctx()->base(true)->guide_type = $guideType;
  58. $forceSave = guide_type_forceSave == true?1:0;
  59. ctx()->base(true)->guide_type_forceSave = $forceSave;
  60. UserProc::updateUserInfo(); # 回写数据
  61. return Resp::ok(array());
  62. }
  63. /**
  64. * 6010 玩家改名
  65. */
  66. public static function ReName() {
  67. list($newName) = req()->paras;
  68. $historyNames = ctx()->privateData()->HistoryNames;
  69. $n = count($historyNames);
  70. $arr = explode(',', glc()->Rename_Cost); # 花费数组
  71. $cost = ($n >= count($arr) ) ? $arr[count($arr) - 1] : $arr[$n]; # 本次改名花费
  72. my_Assert((ctx()->privateData()->lastRenameTs + glc()->Rename_Cooldown) < now(), "改名功能冷却中");
  73. my_Assert(ctx()->base(true)->Consume_Cash($cost), "元宝不足!");
  74. my_Assert(self::checkRoleNameNotExist($newName), "昵称已存在, 请重新命名.");
  75. if (1 == self::regRole(req()->zoneid, req()->uid, $newName, "", "", "")) {
  76. $historyNames[] = ctx()->base()->name;
  77. ctx()->privateData(true)->HistoryNames = $historyNames;
  78. ctx()->privateState->lastRenameTs = now();
  79. ctx()->base()->name = $newName;
  80. self::updateUserInfo(); # 回存数据
  81. FightProc::UpdateRankUserName(req()->uid, $newName); # 刷新排行榜上的昵称
  82. TaskProc::OnReName();
  83. return Resp::ok(array("task" => ctx()->task));
  84. }
  85. return Resp::err(ErrCode::err_db);
  86. }
  87. /**
  88. * 6009 重置功能解锁记录信息
  89. */
  90. public static function clearFunUnlockInfo() {
  91. list($type, $id) = req()->paras;
  92. if ($type == 1 && in_array($id, ctx()->privateState->funUnlockRecord)) {
  93. StlUtil::arrayRemove(ctx()->privateState->funUnlockRecord, $id);
  94. } elseif ($type == 2) {
  95. $mo = GameConfig::skills_getItem($id);
  96. if (in_array($mo->typeId, ctx()->privateState->skillUnlockRecord)) {
  97. StlUtil::arrayRemove(ctx()->privateState->skillUnlockRecord, $mo->typeId);
  98. }
  99. } elseif ($type == 3) {
  100. ctx()->privateState->oldLevel = 0;
  101. ctx()->privateState->upLevel = 0;
  102. }
  103. UserProc::updateUserInfo();
  104. return Resp::ok(array());
  105. }
  106. /**
  107. * 6008 读公告记录
  108. */
  109. public static function readAnnouncement() {
  110. list($id) = req()->paras;
  111. if (!in_array($id, ctx()->privateState->announcement_drawed)) {
  112. ctx()->privateState->announcement_drawed[] = $id;
  113. }
  114. UserProc::updateUserInfo();
  115. return Resp::ok(array());
  116. }
  117. /**
  118. * 6007 移除新头像标志
  119. */
  120. public static function removeNewHeadImgTip() {
  121. //list($gateId) = req()->paras;
  122. $dic = ctx()->heros->Dic;
  123. foreach ($dic as $heroId => $ins_Hero) {
  124. if ($ins_Hero->isUnlock == 1 && $ins_Hero->isNewHeadImgTip == 1) {
  125. ctx()->heros->Dic->$heroId->isNewHeadImgTip = 0;
  126. }
  127. }
  128. UserProc::updateUserInfo();
  129. return Resp::ok(array());
  130. }
  131. /**
  132. * 6006 删除账号
  133. * @return type
  134. */
  135. public static function delUserUid() {
  136. $mem = gMem();
  137. $list = self::GetUserDataKeys(req()->uid, req()->zoneid); # 玩家数据key
  138. foreach ($list as $key) {
  139. if ($mem->exists($key)) {
  140. $mem->delete($key);
  141. }
  142. }
  143. // <editor-fold defaultstate="collapsed" desc="清理mongodb中的数据">
  144. self::deleteUserMapData(req()->uid, req()->zoneid);
  145. // </editor-fold>
  146. FightProc::DeleteRankInvalidUser(req()->uid);
  147. self::delRegRole(req()->zoneid, req()->uid, ctx()->baseInfo->name);
  148. $ret = array();
  149. return Resp::ok($ret);
  150. }
  151. private static function GetUserDataKeys($uid, $zoneid) {
  152. $list = array();
  153. $zoneKey = MemKey_User::Union_PlayedZoneInfo_normal($uid); # 分区信息
  154. $list[] = $zoneKey;
  155. $publicKey = MemKey_User::Union_PublicState_hash($uid); # 公共信息
  156. $list[] = $publicKey;
  157. $gameInfoKey = MemKey_User::Info_hash($zoneid, $uid); # 游戏数据主体
  158. $list[] = $gameInfoKey;
  159. $CurIdKey = MemKey_User::Mail_CurId_int($zoneid, $uid); # 当前邮件编号
  160. $list[] = $CurIdKey;
  161. $SysRecordKey = MemKey_User::Mail_SysRecord_set($zoneid, $uid); # 当前已经领取过的系统邮件记录
  162. $list[] = $SysRecordKey;
  163. $QueueKey = MemKey_User::Mail_Queue_hash($zoneid, $uid); # 邮件列表
  164. $list[] = $QueueKey;
  165. return $list;
  166. }
  167. /**
  168. * 删除账号-区别内外网
  169. * @param type $uid
  170. * @param type $type
  171. */
  172. static public function deleteUserMapData($uid, $zoneid) {
  173. gMongo()->delete("playerMapInfo", array('Uid' => $uid, 'ZoneId' => intval($zoneid))); # 地图
  174. gMongo()->delete("PlayerInfo", array('Uid' => $uid, 'ZoneId' => intval($zoneid)));
  175. gMongo()->delete("userInfoBack", array('key' => MemKey_User::Info_hash($zoneid, $uid)));
  176. }
  177. /**
  178. * 6005 替换头像
  179. * @return type
  180. */
  181. public static function replaceHeadImg() {
  182. list($img) = req()->paras;
  183. ctx()->baseInfo->headImg = $img;
  184. FightProc::UpdateRankUserHeadImg(req()->uid, $img);
  185. UserProc::updateUserInfo();
  186. $ret = array();
  187. return Resp::ok($ret);
  188. }
  189. /**
  190. * 6004 设置片头播放记录
  191. * @return type
  192. */
  193. public static function setAnimation() {
  194. list($tag) = req()->paras;
  195. if (ctx()->baseInfo->animation == 0 && $tag > 0) {
  196. ctx()->baseInfo->animation = 1;
  197. }
  198. UserProc::updateUserInfo();
  199. $ret = array();
  200. return Resp::ok($ret);
  201. }
  202. /**
  203. * 检测遗漏订单
  204. */
  205. static function checkMissOrder() {
  206. $tableName = "tpl_order_tab";
  207. if (daoInst()->tableExist($tableName)) {
  208. $arr = daoInst()->select("*")->from($tableName)
  209. ->where('uid')->eq(req()->uid)
  210. ->andWhere('zoneid')->eq(req()->zoneid)
  211. ->andWhere('status')->eq(1)
  212. ->andWhere('drawed_ts')->eq(0)
  213. ->fetchAll();
  214. if (count($arr) != null) {
  215. foreach ($arr as $item) {
  216. $result = pay_op::CheckAndDrawOrder(req()->uid, $item->cpOrderId, array(new PayProc, 'distributePayGoods'));
  217. }
  218. }
  219. }
  220. }
  221. /**
  222. * 6016 拉取其他玩家的信息.
  223. */
  224. public static function UserOtherPlayerInfo() {
  225. $zoneId = req()->zoneid;
  226. list($other_uid) = req()->paras;
  227. $g = UserProc::getUserGame($zoneId, $other_uid);
  228. my_Assert(null != $g, ErrCode::user_no_err); # 找不到指定的玩家数据
  229. return Resp::ok($g);
  230. }
  231. /**
  232. * 6000 【移动端】 获取分区列表
  233. */
  234. public static function GetZoneList() {
  235. $defaultZone = new Ins_ZoneInfo(1, 0, ""); # 新用户默认分区
  236. $bGetRecommended = false;
  237. if (count(req()->paras) > 0) { # 是否只拉取推荐分区
  238. $bGetRecommended = req()->paras[0];
  239. }
  240. $zoneList = array();
  241. $ts = now();
  242. // foreach (GameConfig::zonelist() as $zoneid => $zone) {
  243. // isEditor() and $zone = new \sm_zonelist();
  244. // if ($zone->publicTs > $ts) {
  245. // continue;
  246. // }
  247. // $zone->zoneid = $zoneid; # 把zoneid塞进zone数据结构中
  248. // if ($bGetRecommended) {
  249. // if ($zone->isRecommended > 0 && $zone->status == 1) {
  250. // $zoneList[] = $zone;
  251. // } else {
  252. //
  253. // }
  254. // } else {
  255. // $zoneList[] = $zone;
  256. // }
  257. // unset($zone->isRecommended);
  258. // }
  259. // UserProc::_AddTesterZonelist($zoneList); # 添加测试分区
  260. #
  261. // <editor-fold defaultstate="collapsed" desc=" 取玩家分区记录 ">
  262. $userZoneInfo = self::getUserZoneInfo(); # 玩家分区记录
  263. $isNewUser = false;
  264. if ($userZoneInfo == null) { // 这里使用推荐分区的数据,推荐分区信息,在后台编辑,编辑器可用
  265. $userZoneInfo = new Data_UserZoneInfo();
  266. $userZoneInfo->lastZone = $defaultZone; # 新用户导向默认分区
  267. $isNewUser = true;
  268. } else { # 转换一下格式,去掉key,只保留value的集合
  269. // $userZoneInfo->playedZones = ArrayInit();
  270. // array_merge($userZoneInfo->playedZones, array_values((array) $userZoneInfo->playedZones));
  271. }
  272. // </editor-fold>
  273. $ret = array(
  274. 'isNewUser' => $isNewUser,
  275. 'zonelist' => json_decode(json_encode($zoneList)),
  276. 'userZoneInfo' => $userZoneInfo
  277. );
  278. return Resp::ok($ret); # 返回值
  279. }
  280. private static function _AddTesterZonelist(&$zoneList) {
  281. if (config::Inst()->isTester(req()->uid)) { # 添加测试分区
  282. $zoneList[] = array('zoneid' => 999, 'name' => '内测专区', 'status' => 2, 'publicTs' => 0);
  283. }
  284. }
  285. /**
  286. * 6002 客户端下载常量配置信息
  287. * @return type
  288. */
  289. public static function downloadConstInfo() {
  290. list($clientDataVer) = req()->paras; # 客户端数据版本号,程序版本号
  291. $serverVer = GameConfig::ver(); # 最新数据版本号
  292. my_Assert($serverVer, ErrCode::err_const_no); # 找不到常量数据
  293. $url = config::CDN_host() . "/cfg/" . req()->CV . "/Client.bytes?" . $serverVer;
  294. $ret = array(
  295. 'version' => $serverVer,
  296. 'url' => $clientDataVer == $serverVer ? "" : $url, # # 如果版本一致,url传空,只传回版本号
  297. 'data' => null);
  298. return Resp::ok($ret);
  299. // $md5 = md5(json_encode($constInfo)); # 计算MD5值,多余计算md5
  300. // $constInfo = GameConfig::client(); # 取出来的已经是base64过的压缩数据
  301. // my_Assert($constInfo, ErrCode::err_const_no); # 找不到配置数据
  302. }
  303. /**
  304. * 6001 客户端登录并返还玩家信息
  305. * @return Resp
  306. */
  307. public static function loginUserInfo() {
  308. $game = UserProc::getUserGame(req()->zoneid, req()->uid);
  309. if ($game == null) { # 新用户, -> 6006创建账号
  310. $userID = req()->uid;
  311. list($nickName) = req()->paras;
  312. $id = gMem()->increment(MemKey_GameRun::Stat_UserCountByZone_int(req()->zoneid)); # 增加玩家数量计数
  313. $rolename = "No." . sprintf("%03d", req()->zoneid) . sprintf("%07d", $id); # 生成编号
  314. $rolename = $nickName; # 采用客户端传过来的值创建账号, 2024.6.24
  315. if (self::checkRoleNameNotExist($rolename)) { # 记录玩家
  316. $game = self::createUser($rolename);
  317. if (1 == self::regRole(req()->zoneid, $userID, $rolename, "", "", "")) {
  318. $resp = Resp::ok($game);
  319. self::updtateUserZoneInfo();
  320. } else {
  321. $resp = Resp::err(ErrCode::err_db);
  322. }
  323. } else { # 昵称已存在
  324. $resp = Resp::ok(array('ret' => '用户已存在.'));
  325. }
  326. $game->RegenNewToken();
  327. $game->baseInfo->Reset_tilits();
  328. self::OnLogin_DateDeal();
  329. UserProc::updateUserInfo(); # 这一步回存操作只有在 userInfo正常存在的情况下才进行
  330. return $resp;
  331. } else { # 2.如果玩家已存在,则处理普通登录流程
  332. req()->game = $game; # 给Req挂载玩家数据
  333. $game->base(true)->Reset_tilits(); # 修正体力ts
  334. UserProc::checkContidays(); # 连续登录,状态检查
  335. //PayProc::m_refreshChargeOrders(); # 刷新订单, 多平台版本
  336. PayProc::selfhelpCheckOrders();
  337. PayProc::checkDeltest(); # 检查内侧充值记录(函数内部会只检查一次)
  338. //self::checkMissOrder(); #校验是否有漏单
  339. $game->RegenNewToken();
  340. UserProc::updateUserInfo(); # 这一步回存操作只有在 userInfo正常存在的情况下才进行
  341. self::OnLogin_DateDeal();
  342. //ctx()->privateState->firstRechargeUI_OpenTip = 1;
  343. if (ctx()->baseInfo->charge_amt == 0) {
  344. ctx()->privateState->firstRechargeUI_OpenTip = 1;
  345. } else {
  346. $num = ctx()->privateState->firstRecharge_receiveTag;
  347. if (!in_array($num, ctx()->privateState->firstRechargeRewardRecord)) {
  348. ctx()->privateState->firstRechargeUI_OpenTip = 1;
  349. }
  350. }
  351. $resp = Resp::ok($game); # 设置返回值
  352. self::updtateUserZoneInfo(); # 1. 更新玩家分区记录
  353. }
  354. return $resp;
  355. }
  356. //
  357. // <editor-fold defaultstate="collapsed" desc=" 辅助方法 ">
  358. /**
  359. * 检查昵称是否已经存在
  360. * @param string $roleName
  361. * @return boolean
  362. */
  363. static function checkRoleNameNotExist($roleName) {
  364. // return true; # 不再检查昵称重复
  365. static $sqlFormat = "SELECT count(*) as cnt FROM `tab_rolename` WHERE roleName='%s';";
  366. $sql = sprintf($sqlFormat, $roleName);
  367. $n = daoInst()->query($sql)->fetch();
  368. // var_dump($n);
  369. return $n->cnt <= 0;
  370. }
  371. /**
  372. * 插入玩家新角色
  373. *
  374. * @param string $zoneid
  375. * @param string $userID
  376. * @param string $nickname
  377. * @param string $gender
  378. * @param string $profile_img
  379. * @param string $plat
  380. */
  381. static function regRole($zoneid, $userID, $nickname, $gender, $profile_img, $plat) {
  382. return daoInst()->insert('tab_rolename')
  383. ->data(array(
  384. 'zoneid' => $zoneid,
  385. 'userID' => $userID,
  386. 'roleName' => $nickname,
  387. 'gender' => $gender,
  388. 'profile' => $profile_img,
  389. 'plat' => $plat
  390. ))->exec();
  391. }
  392. /**
  393. *
  394. * @param type $zoneid
  395. * @param type $userID
  396. * @param type $nickname
  397. * @param type $gender
  398. * @param type $profile_img
  399. * @param type $plat
  400. * @return type
  401. */
  402. static function delRegRole($zoneid, $userID, $nickname) {
  403. return daoInst()->del('tab_rolename')
  404. ->data(array(
  405. 'zoneid' => $zoneid,
  406. 'userID' => $userID,
  407. 'roleName' => $nickname,
  408. ))->exec();
  409. }
  410. /**
  411. * 检测连续登录状态,重置必要字段[时间戳自动记录]
  412. */
  413. static function checkContidays($isnew = 0) {
  414. $ret = TimeUtil::totalDays() - TimeUtil::totalDays(ctx()->baseInfo->lastLogin); // 对比登录日期
  415. if ($ret > 0 || $isnew) { # 当天第一次登录
  416. self::OnNewDay($isnew);
  417. } else { # 更新下登录次数记录(任务计数器)
  418. }
  419. if ($ret == 1) { # 连续登录
  420. } else if ($ret >= 2) { # 隔天登录
  421. }
  422. ctx()->baseInfo->lastLogin = now(); # 更新下访问时间
  423. //TapDBUtil::SOnUserLogin(); # 向tapdb上报玩家登录 2023.5.10
  424. return $ret;
  425. }
  426. /**
  427. * 处理当天第一次登录
  428. * @param bool $isnew Description
  429. */
  430. static function OnNewDay($isnew) {
  431. ShopProc::DailyShopItemRand();
  432. ShopProc::ShopDailyClear();
  433. //self::clear();
  434. FightProc::FightDailyClear();
  435. //TaskProc::initAchieveData();
  436. TaskProc::ResetTask();
  437. PayProc::setFirstRechargeLoginTag();
  438. self::ActiveRefershTsDeal();
  439. ActiveProc::DailyResetDay7Task();
  440. }
  441. static function ActiveRefershTsDeal() {
  442. //一天一刷
  443. TaskProc::DailyTaskReset();
  444. TaskProc::ClearDay7Task();
  445. //一周一刷
  446. $weekNum = TimeUtil::totalWeeks();
  447. $lastWeekNum = TimeUtil::totalWeeks(ctx()->baseInfo->lastLogin);
  448. if ($weekNum - $lastWeekNum >= 1) {
  449. TaskProc::WeekTaskReset();
  450. }
  451. //两周一刷
  452. if ($weekNum - $lastWeekNum >= 2) {//暂时还没有对应活动
  453. }
  454. //2天一刷
  455. $curDay = TimeUtil::totalDays();
  456. $nextDay = TimeUtil::totalDays(ctx()->privateState->nextDayLogin);
  457. $limitTsSaleMo = GameConfig::subfun_unlock_getItem(Enum_SubFunType::LimitTsSale);
  458. $day = $limitTsSaleMo->ts;
  459. if (ctx()->privateState->nextDayLogin > 0 && $curDay - $nextDay >= $day) {
  460. ActiveProc::ResetLimitTsBuy();
  461. }
  462. $activePoint_BattlePassMo = GameConfig::subfun_unlock_getItem(Enum_SubFunType::ActivePoint_BattlePass);
  463. $activePoint_BattlePass_day = $activePoint_BattlePassMo->ts;
  464. $activePoint_refersh_tsDay = TimeUtil::totalDays(ctx()->privateState->battlePass_activePoint_refersh_ts);
  465. if (ctx()->privateState->battlePass_activePoint_refersh_ts > 0 && $curDay - $activePoint_refersh_tsDay >= $activePoint_BattlePass_day) {
  466. ctx()->privateState->battlePass_activePoint_refersh_ts = TimeUtil::getNextDayTs($activePoint_BattlePassMo->startTs, $activePoint_BattlePass_day);
  467. ctx()->privateData(true)->battlePass_activePoint_cost_ts = 0;
  468. ctx()->privateData(true)->battlePass_taskPoint = 0;
  469. ActiveProc::ResetBattlePassReward(Enum_SubFunType::ActivePoint_BattlePass);
  470. }
  471. $tili_BattleBassMo = GameConfig::subfun_unlock_getItem(Enum_SubFunType::Tili_BattleBass);
  472. $tili_BattleBass_day = $tili_BattleBassMo->ts;
  473. $tili_BattleBass_refershDay = TimeUtil::totalDays(ctx()->privateState->battlePass_tili_refersh_ts);
  474. if (ctx()->privateState->battlePass_tili_refersh_ts > 0 && $curDay - $tili_BattleBass_refershDay >= $tili_BattleBass_day) {
  475. ctx()->privateState->battlePass_tili_refersh_ts = TimeUtil::getNextDayTs($tili_BattleBassMo->startTs, $tili_BattleBass_day);
  476. ctx()->privateData(true)->battlePass_tili_cost_ts = 0;
  477. ctx()->privateData(true)->battlePass_tili = 0;
  478. ActiveProc::ResetBattlePassReward(Enum_SubFunType::Tili_BattleBass);
  479. }
  480. }
  481. static function OnLogin_DateDeal() {
  482. EmailProc::refreshSysMail(req()->zoneid, req()->uid);
  483. EmailProc::IsExistRedTip();
  484. FightProc::isExistNoDrawed_FightPower();
  485. FightProc::isExistNoDrawed_MainGate();
  486. FightProc::Ranking_FightPower();
  487. TaskProc::OnLogin_Daily();
  488. TaskProc::OnLogin_day7();
  489. TaskProc::checkMainTask();
  490. FightProc::SubFunDateInit_Config();
  491. }
  492. // static function clear() {
  493. // $dic = GameConfig::announcement();
  494. // foreach ($dic as $mo) {
  495. // if(now() > $mo->endTs && in_array($mo->id,ctx()->privateState->announcement)){
  496. // StlUtil::arrayRemove(ctx()->privateState->announcement, $mo->id);
  497. // }
  498. // }
  499. //
  500. // }
  501. // <editor-fold defaultstate="collapsed" desc="创建新用户">
  502. /**
  503. * 创建用户
  504. * @return Data_UserGame
  505. */
  506. static function createUser($rolename) {
  507. $game = new Data_UserGame();
  508. req()->game = $game; # 更新Req挂载的玩家数据,
  509. $game->initialize(); # 初始化玩家数据
  510. $game->baseInfo->name = $rolename;
  511. //$game->baseInfo->headImg = "";
  512. $game->baseInfo->firstLogin = now();
  513. #Ps 6006是没有获得到Userinfo到Req中的
  514. UserProc::checkContidays(1); # 每日状态检查
  515. // UserProc::fetchFromInteract($mem, $req); # 从interact拉取数据,Ps.初始化的过程应该还拉取不到什么有效数据
  516. UserProc::updateUserInfo(); # 回存用户数据
  517. return $game;
  518. }
  519. /**
  520. * 整理平台玩家记录集
  521. * @param int $isnew
  522. */
  523. private static function updatePlatUserRecord($isnew = 0) {
  524. $zoneid = req()->zoneid;
  525. $uid = req()->uid;
  526. $user = ctx()->baseInfo;
  527. $day = totalDays();
  528. $level = $user->level;
  529. $platUser = ObjectInit();
  530. $platUser->uid = $uid; #
  531. $platUser->name = $user->name; #
  532. $platUser->level = $level;
  533. $platUser->img = $user->headImg; # 头像字段
  534. $platUser->cash = $user->cash;
  535. $platUser->gold = $user->gold;
  536. $platUser->tili = $user->tili;
  537. $platUser->ts = now();
  538. $platUser->isnew = $isnew;
  539. gMem()->delete(MemKey_GameRun::DailyLoginUser_byUID_hash($zoneid, $day - 108));
  540. gMem()->hset(MemKey_GameRun::DailyLoginUser_byUID_hash($zoneid), $uid, $platUser);
  541. gMem()->delete(MemKey_GameRun::DailyLoginUser_byLevel_hash($zoneid, $level, $day - 108));
  542. gMem()->hset(MemKey_GameRun::DailyLoginUser_byLevel_hash($zoneid, $level), $uid, $platUser);
  543. }
  544. // </editor-fold>
  545. //
  546. // <editor-fold defaultstate="collapsed" desc="读写玩家数据">
  547. /**
  548. * 取玩家数据
  549. * @param type $zoneid
  550. * @param type $uid
  551. * @return Data_UserGame
  552. */
  553. public static function getUserGame($zoneid, $uid) {
  554. $key = MemKey_User::Info_hash($zoneid, $uid);
  555. // $pf = req()->getPlatStr();
  556. // if ($pf == "tap") { # taptap平台
  557. // $oldkey = MemKey_User::Info_hash($zoneid, req()->getPlatOid());
  558. // if (gMem()->exists($oldkey)) {
  559. // gMem()->rename($oldkey, $key); # 做下数据迁移
  560. // }
  561. // }
  562. $a = new Data_UserGame();
  563. if (null == $a->readDataFromMem($key)) { # ps.下面这一段代码和经常删号会有冲突,因此关闭了 --gwang 2022.2.28
  564. $collection = "userInfoBack";
  565. $cursor = gMongo()->find($collection, ['key' => $key], ['sort' => array('ts' => -1), 'limit' => 1]); # 提取备份数据
  566. $cursor->rewind();
  567. if ($cursor->valid()) {
  568. $v = $cursor->current();
  569. $a->LoadFrom($v->value); # 加载
  570. $a->updateDataFull($key); # 反向写回redis
  571. } else {
  572. return null;
  573. }
  574. }
  575. return new Data_UserGame($a);
  576. }
  577. /**
  578. * 更新用户数据(设置标志位,最后统一更新-gwang 2017.07.18)
  579. */
  580. public static function updateUserInfo() {
  581. my_Assert(req(), "req()为空");
  582. my_Assert(req()->game, "[" . req()->cmd . "] 玩家数据正在被清空!" . req()->uid);
  583. req()->userInfoChanged = TRUE; # 设置回写标志位
  584. }
  585. /**
  586. * 回写玩家数据
  587. * @param Data_UserGame $game
  588. */
  589. public static function setUserInfo($game) {
  590. $OK = false;
  591. if ($game) {
  592. $zoneid = req()->zoneid;
  593. $uid = req()->uid;
  594. $game->baseInfo->lastSaveTs = now();
  595. $key = MemKey_User::Info_hash($zoneid, $uid);
  596. // $OK = $game->updateDataByTag($key); # 向Redis回写玩家数据
  597. $OK = $game->updateDataFull($key); # 向Redis回写玩家数据
  598. if ($OK) {
  599. // CLog::info($msg);
  600. self::backupUserInfoMongo(); # 向MongoDB备份数据
  601. gMem()->expire($key, 3600); # 设置过期时间1小时
  602. } else {
  603. // redo Logic
  604. CLog::err("写入数据时版本已过期!!!");
  605. }
  606. }
  607. return $OK;
  608. }
  609. // </editor-fold>
  610. //
  611. // <editor-fold defaultstate="collapsed" desc="玩家分区记录">
  612. /**
  613. * 读取玩家的分区记录
  614. * @return Data_UserZoneInfo Description
  615. */
  616. public static function getUserZoneInfo() {
  617. $ret = gMem()->get(MemKey_User::Union_PlayedZoneInfo_normal(req()->uid));
  618. return $ret;
  619. }
  620. /**
  621. * 更新玩家分区记录
  622. */
  623. public static function updtateUserZoneInfo() {
  624. $req = req();
  625. $userZoneInfo = self::getUserZoneInfo(); # 取玩家分区记录
  626. if (!$userZoneInfo) {
  627. $userZoneInfo = new Data_UserZoneInfo;
  628. }
  629. $level = 0;
  630. $zoneid = $req->zoneid;
  631. $playerName = "";
  632. $headImg = "";
  633. if (null != ctx()) { # 防御确保玩家数据不为空
  634. $level = ctx()->baseInfo->level;
  635. $playerName = ctx()->baseInfo->name;
  636. $headImg = ctx()->baseInfo->headImg;
  637. } else {
  638. Err('玩家数据为空!' . __CLASS__ . '.' . __FUNCTION__);
  639. }
  640. if (is_null($level)) {
  641. $level = 0;
  642. }
  643. $userZoneInfo->lastZone = new Ins_ZoneInfo($zoneid, $level, $playerName, $headImg); # 更新玩家分区记录
  644. $userZoneInfo->playedZones->$zoneid = $userZoneInfo->lastZone; # 玩过的分区集合
  645. gMem()->set(MemKey_User::Union_PlayedZoneInfo_normal($req->uid), $userZoneInfo); # 回写数据
  646. }
  647. // </editor-fold>
  648. // <editor-fold defaultstate="collapsed" desc=" 用户数据备份 ">
  649. /**
  650. * 备份玩家数据,(玩家数据落地),一天一份,当天记为最后一次登录时的状态而非最后一次操作的状态
  651. * @history
  652. * version 3.0.13 mysql版备份玩家数据, (性能优化后表现还不错)
  653. * 除非用脚本在redis中实现备份,否则直接写入mysql.
  654. * 主要是mysql版本利用存储过程之后性能已经和redis版相差不多.
  655. * version 2.0.0 Redis storage 从MySQL转到Redis中存储. 这个备份数据没有大规模导出硬盘的需求
  656. * 因为mysql版本实在是负载太大了, 上百毫秒. 所以改在redis中了.
  657. * version 1.0.0 Mysql storagef 1. 分表不做了, 2. 存储过程不用了 3. 先能用再说
  658. */
  659. public static function backupUserInfo() {
  660. $tsday = TimeUtil::totalDays(); # 精确到天,保留10个最近记录.
  661. $value = base64_encode(gzdeflate(JsonUtil::encode(ctx()))); # blob数据,序列化下
  662. $sql = sprintf("call insertUserInfo('%s', %d, %d, '%s');", # # 所以直接将序列化后的结果存进去吧,
  663. req()->uid, req()->zoneid, $tsday, $value); # zoneid, uid, tsday
  664. daoInst()->exec($sql); # 也可以用exec($sql)
  665. }
  666. /**
  667. * 备份玩家数据,(玩家数据落地),一天一份,当天记为最后一次登录时的状态而非最后一次操作的状态
  668. * @history
  669. * version 4.0.0 切换到MongoDB存储
  670. * version 3.0.13 mysql版备份玩家数据, (性能优化后表现还不错)
  671. * 除非用脚本在redis中实现备份,否则直接写入mysql.
  672. * 主要是mysql版本利用存储过程之后性能已经和redis版相差不多.
  673. * version 2.0.0 Redis storage 从MySQL转到Redis中存储. 这个备份数据没有大规模导出硬盘的需求
  674. * 因为mysql版本实在是负载太大了, 上百毫秒. 所以改在redis中了.
  675. * version 1.0.0 Mysql storagef 1. 分表不做了, 2. 存储过程不用了 3. 先能用再说
  676. */
  677. public static function backupUserInfoMongo() {
  678. $collectionName = "userInfoBack"; # 表名
  679. $key = MemKey_User::Info_hash(req()->zoneid, req()->uid);
  680. $doc = array('key' => $key, # # 最新文档
  681. 'ts' => TimeUtil::dtCurrent(), # # 更新时间
  682. 'stVer' => ctx()->stVer, # # 增加版本号
  683. 'value' => ctx()); # 玩家数据
  684. $bok = gMongo()->insert($collectionName, $doc); # 插入备份
  685. // CLog::err($collectionName . "备份玩家数据" . req()->uid . ($bok ? "成功" : "失败"));
  686. if (ctx()->stVer % 100 == 1) { # 每100条记录清理一次(delete耗时比较长-gwang.2023年3月10日)
  687. $delFilter = array('key' => $key, 'stVer' => ['$lt' => ctx()->stVer - 100]); # 保留最后一百次变更记录
  688. gMongo()->delete($collectionName, $delFilter);
  689. }
  690. // $filter = array('key' => $key); # 指定条件
  691. // gMongo()->update($collectionName, $filter, $doc, true); # 更新
  692. }
  693. // </editor-fold>
  694. //</editor-fold>
  695. //
  696. }