UserProc.php 33 KB

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