UserProc.php 34 KB

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