FriendProc.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881
  1. <?php
  2. //
  3. //namespace loyalsoft;
  4. //
  5. ///**
  6. // * 好友模块各种操作类型-枚举值
  7. // */
  8. //class enum_Friend_op extends Enum {
  9. //
  10. // const __default = 0;
  11. // // 删除好友
  12. // const remove = 1;
  13. // // 加好友
  14. // const apply = 2;
  15. // // 接受请求
  16. // const accepted = 3;
  17. // // 示好, 送心...
  18. // const gift = 4;
  19. // // 加好友请求的发送记录
  20. // const applied = 5;
  21. // // 示好,送心的记录
  22. // const giftrecord = 6;
  23. //
  24. //}
  25. //
  26. ///**
  27. // * 好友处理流程
  28. // * @version
  29. // * 1.0.0 Created at 2017-3-6. by --gwang
  30. // * @author gwang (mail@wanggangzero.cn)
  31. // * @copyright ? 2017-3-6, SJZ LoyalSoft Corporation & gwang. All rights reserved.
  32. // */
  33. //class FriendProc {
  34. //
  35. // /**
  36. // * 好友发送消息的最大长度(超过的截断)
  37. // */
  38. // const MaxMessageLength = 80;
  39. //
  40. // /**
  41. // * 逻辑分发
  42. // * 所有的Proc中必须有这样一个方法
  43. // * @param type $req
  44. // */
  45. // static function procMain($req) {
  46. // switch ($req->cmd) {
  47. // case CmdCode::cmd_user_friend_search: # [6110]查找好友
  48. // return FriendProc::SearchFriend($req);
  49. // case CmdCode::cmd_user_friend_suggestList: # [6111]添加好友界面获取一批推荐好友列表
  50. // return FriendProc::GetSuggestList($req);
  51. // case CmdCode::cmd_user_friend_get_list: # [6106]获取好友列表 ok下发好友个人公会信息
  52. // return FriendProc::getAppFriends($req);
  53. // case CmdCode::cmd_user_friend_get_infos: # [6107]获取详细信息
  54. // return FriendProc::getAppFriendInfos($req);
  55. //// ------------------------------------------
  56. //
  57. // case CmdCode::cmd_user_friend_gift_getlist: # [6113]拉取好友赠送礼物的记录
  58. // return FriendProc::getAppFriendGiftList($req);
  59. // case CmdCode::cmd_user_friend_gift_redraw: # [6114]领取好友赠送的礼物[并回赠]
  60. // return FriendProc::getAppFriendGift($req);
  61. // case CmdCode::cmd_user_friend_gift_send: # [6115]向好友发送礼物,示好
  62. // return FriendProc::sendGiftToAppFriend($req);
  63. // case CmdCode::cmd_user_friend_unduckmsg:
  64. // return FriendProc::CheckUnduckMessage($req);
  65. ////--------------------------------------------
  66. // case CmdCode::cmd_user_friend_apply: # [6101]加好友
  67. // return FriendProc::ApplyToAddNewFriend($req);
  68. // case CmdCode::cmd_user_friend_accept: # [6102]接受好友请求
  69. // return FriendProc::Accept($req);
  70. // case CmdCode::cmd_user_friend_deny: # [6103]拒绝好友请求
  71. // return FriendProc::Deny($req);
  72. // case CmdCode::cmd_user_friend_remove: # [6104]删除好友
  73. // return FriendProc::Remove($req);
  74. // case CmdCode::cmd_user_friend_getapplylist: # [6105]好友请求列表
  75. // return FriendProc::GetApplyList($req);
  76. ////-----------------------------------------------
  77. // case CmdCode::cmd_user_friend_leave_message: # [6108]给好友发消息
  78. // return FriendProc::SendMessage($req);
  79. // case CmdCode::cmd_user_friend_get_message: # [6109]刷新消息
  80. // return FriendProc::GetNewMessage($req);
  81. //
  82. ////-----------------------------------------------
  83. // case CmdCode::cmd_user_friend_reload: # [6112]更新好友
  84. // return FriendProc::Reload($req);
  85. // case CmdCode::cmd_user_friend_LookGuildInfo: # [6117]查看好友所在部落信息
  86. // return FriendProc::LookGuildInfo($req);
  87. // case CmdCode::cmd_user_friend_LookFriendInfo: # [6118]查看好友简介
  88. // return FriendProc::LookFriendInfo($req);
  89. // default:
  90. // return Resp::err(ErrCode::cmd_err);
  91. // }
  92. // }
  93. //
  94. // /**
  95. // * 查看好友的部落信息
  96. // * @param type $req
  97. // */
  98. // static function LookGuildInfo($req) {
  99. // $friendId = $req->paras[0];
  100. // $zoneid = $req->zoneid;
  101. // $mem = $req->mem;
  102. //
  103. // $sql = "select * from `tab_rolename` where userID = '$friendId'";
  104. // $rows = daoInst()->query($sql)->fetchAll();
  105. // my_Assert(count($rows) > 0, ErrCode::err_user_no); # 找不到玩家数据
  106. // $friendGuildInfo = GuildProc::getMemUserGuildInfo($mem, $friendId, $zoneid);
  107. // my_Assert($friendGuildInfo != null, "好友公会数据为空");
  108. // my_Assert($friendGuildInfo->guildId > 0, ErrCode::err_guild_userguildinfono);
  109. //
  110. // $guildInfo = GuildProc::getMemGuildInfo($mem, $friendGuildInfo->guildId, $zoneid);
  111. // my_Assert($guildInfo != null, ErrCode::err_guild_guildinfono); # 找不到公会
  112. //
  113. // return Resp::ok($guildInfo);
  114. // }
  115. //
  116. // /**
  117. // * 查看好友简介
  118. // * @param type $req
  119. // */
  120. // static function LookFriendInfo($req) {
  121. // $friendId = $req->paras[0]; //好友id
  122. // $mem = $req->mem;
  123. // $sql = "select * from `tab_rolename` where userID = '$friendId'";
  124. // $rows = daoInst()->query($sql)->fetchAll();
  125. // my_Assert(count($rows) > 0, ErrCode::err_user_no); # 找不到玩家角色记录
  126. // $friendInfo = self::initfriendInfo($mem, $rows[0]['userID'], $rows[0]['zoneid']);
  127. // my_Assert($friendInfo != null, ErrCode::err_user_no); # 好友数据初始化成功
  128. // $friendInfo->fightPower = GuildProc::initFightTeamInfo($mem, $rows[0]['userID'], $rows[0]['zoneid']);
  129. // return Resp::ok(array("friendInfo" => $friendInfo,));
  130. // }
  131. //
  132. // /**
  133. // * 检查玩家的好友信息是否有未处理的
  134. // * @param type $req
  135. // */
  136. // public static function CheckUnduckMessage($req) {
  137. // $mem = $req->mem;
  138. // $zoneid = $req->zoneid;
  139. // $uid = $req->uid;
  140. // $result = -1;
  141. // // 别人的赠送列表
  142. // $fgiftlist = self::getOps($mem, $uid, $zoneid, enum_Friend_op::gift);
  143. // if (count((array) $fgiftlist) <= 0) {
  144. // $result = 0;
  145. // } else {
  146. // foreach ($fgiftlist as $key => $value) {
  147. // if (count((array) $value) <= 0) {
  148. // continue;
  149. // } else {
  150. // $result = 1;
  151. // break;
  152. // }
  153. // }
  154. // }
  155. // //找别人发来的申请加好友的列表
  156. // if ($result == 0) {
  157. // $ret = FriendProc::getOps($req->mem, $req->uid, $req->zoneid, enum_Friend_op::apply);
  158. // $result = (count((array) $ret) > 0) ? 1 : 0;
  159. // }
  160. // return Resp::ok(array('ret' => $result));
  161. // }
  162. //
  163. // /**
  164. // * [6112] 核算好友的离线操作
  165. // * @param Req $req
  166. // */
  167. // public static function Reload($req) {
  168. // $mem = $req->mem;
  169. // $uid = $req->uid;
  170. // $zoneid = $req->zoneid;
  171. //
  172. // // 刷新接受请求列表, 将已接受的好友添加到
  173. // $allOps = self::getOps($mem, $uid, $zoneid);
  174. // $op = new enum_Friend_op(enum_Friend_op::accepted);
  175. // $ops = $allOps->$op;
  176. // if (count($ops) > 0) {
  177. // foreach ($ops as $u => $ts) { # 立即将对方添加到好友列表
  178. // self::_AddFriend($mem, $uid, $zoneid, $u);
  179. // }
  180. // $ops = "{}";
  181. // $allOps->$op = $ops;
  182. // }
  183. //
  184. // // 刷新删除列表, 看谁和我解除了好友关系, 删掉他
  185. // $op = new enum_Friend_op(enum_Friend_op::remove);
  186. // $ops = $allOps->$op;
  187. // if (count($ops) > 0) {
  188. // foreach ($ops as $u => $ts) {
  189. // self::_RemoveFriend($mem, $uid, $zoneid, $u);
  190. // }
  191. // $allOps->$op = "{}";
  192. // }
  193. // $g = glc();
  194. //
  195. // self::filterOutDateRecords($allOps, # # 清理过期的请求记录,
  196. // new enum_Friend_op(enum_Friend_op::applied), $g->User_Friends_Apply_ExpireTs);
  197. //
  198. // self::filterOutDateRecords($allOps, # # 刷新别人发来的好友请求列表, 过期而没有处理的也删掉(莫名其妙的消失,玩家会不会不爽?要不要加上倒计时?).
  199. // new enum_Friend_op(enum_Friend_op::apply), $g->User_Friends_Apply_ExpireTs);
  200. //
  201. // self::saveOps($mem, $uid, $zoneid, $allOps, 0); # 回存数据
  202. // // 清理过期的互动记录, 不清除, 一个好友最多保留3条记录
  203. // // 更新好友数量
  204. // return Resp::ok(array("ret" => "ok"));
  205. // }
  206. //
  207. // private static function filterOutDateRecords($allOps, $op, $outts) {
  208. // $ops = $allOps->$op;
  209. // if (count((array) $ops) > 0) {
  210. // $ops = array_filter((array) $ops, function ($ts)use($outts) {
  211. // return (intval($ts) + $outts) > now();
  212. // });
  213. // $allOps->$op = (is_null($ops) || 0 == count((array) $ops)) ? "{}" : $ops;
  214. // }
  215. // }
  216. //
  217. ////
  218. //// <editor-fold defaultstate="collapsed" desc=" 聊天/留言 ">
  219. // //
  220. //
  221. // /**
  222. // * [6108]发送消息/留言
  223. // * @param Req $req
  224. // */
  225. // public static function SendMessage($req) {
  226. // // todo:检查是否好友
  227. // $mem = $req->mem;
  228. // $uid_from = $req->uid;
  229. // $uid_to = $req->paras[0];
  230. // $msg = $req->paras[1];
  231. // if (strlen($msg) > self::MaxMessageLength) {
  232. // $msg = substr($msg, 0, self::MaxMessageLength) . "...";
  233. // }
  234. // $key = MemKey_User::FriendsMsgQueue_hash($req->zoneid, $uid_to);
  235. // $arr = $mem->hget($key, $uid_from);
  236. // if (null == $arr) {
  237. // $arr = ArrayInit();
  238. // }
  239. // $ts = now();
  240. // array_push($arr, "{$msg}{$ts}");
  241. // if (count($arr) > glc()->User_Friends_MessageCount_Max) {
  242. // array_shift($arr);
  243. // }
  244. // $mem->hset($key, $uid_from, $arr);
  245. ////
  246. // $mts = isset($req->paras[2]) ? $req->paras[2] : 0;
  247. // $newmsg = self::_GetNewMessage($mem, $req->zoneid, $uid_from, $uid_to, $mts);
  248. // return Resp::ok(array("ret" => "ok", 'newmsg' => $newmsg));
  249. // }
  250. //
  251. // /**
  252. // * [6109]拉取最新消息/留言
  253. // *
  254. // * @param Req $req
  255. // */
  256. // public static function GetNewMessage($req) {
  257. // if (count($req->paras) < 2) {
  258. // return Resp::err(ErrCode::parasnotenough_msg);
  259. // }
  260. // $uid_filter = $req->paras[0];
  261. // $ts = $req->paras[1];
  262. // $arr = self::_GetNewMessage($req->mem, $req->zoneid, $req->uid, $uid_filter, $ts);
  263. //
  264. // return Resp::ok($arr);
  265. // }
  266. //
  267. // /**
  268. // * 取留言消息
  269. // * @param CredisUtil $mem
  270. // * @param int $zoneid
  271. // * @param string $uid
  272. // * @param string $f_uid
  273. // * @param ts $ts
  274. // * @return asoc_array
  275. // */
  276. // private static function _GetNewMessage($mem, $zoneid, $uid, $f_uid, $ts) {
  277. // $key = MemKey_User::FriendsMsgQueue_hash($zoneid, $uid);
  278. // $arr = array($f_uid => $mem->hget($key, $f_uid));
  279. // // 依据ts时间戳,剔除客户端不需要的消息,然后传送.
  280. // foreach ($arr as &$msgq) {
  281. // if (null == $msgq) { // 防御
  282. // continue;
  283. // }
  284. // $msgq = array_filter($msgq, function($msg) use($ts) {
  285. // return $ts < substr($msg, -10); // 时间戳10位
  286. // });
  287. // }
  288. // return $arr;
  289. // }
  290. //
  291. // //
  292. // //
  293. //// </editor-fold>
  294. ////
  295. //// <editor-fold defaultstate="collapsed" desc=" 待定 ">
  296. // //
  297. //
  298. // /**
  299. // * 设置默认同意好友请求
  300. // * @param Req $req
  301. // */
  302. // public static function SetAutoAccept($req) {
  303. //
  304. // }
  305. //
  306. //// </editor-fold>
  307. ////
  308. //// <editor-fold defaultstate="collapsed" desc=" 好友操作 ">
  309. ////
  310. //
  311. // /**
  312. // * [6105] 拉取好友请求列表
  313. // * @param Req $req
  314. // */
  315. // public static function GetApplyList($req) {
  316. // $ret = FriendProc::getOps($req->mem, $req->uid, $req->zoneid, enum_Friend_op::apply);
  317. // return Resp::ok(array("ret" => (count((array) $ret) > 0) ? $ret : array()));
  318. // }
  319. //
  320. // /**
  321. // * [6101]添加好友
  322. // * @param Req $req
  323. // */
  324. // public static function ApplyToAddNewFriend($req) { // 取目标玩家的ops列表插入请求
  325. // $mem = $req->mem;
  326. // $uid_to = $req->paras[0];
  327. // $uid_from = $req->uid;
  328. // if ($uid_from == $uid_to) {
  329. // return Resp::err(ErrCode::paras_err, "添加的好友ID非法!");
  330. // }
  331. //
  332. // $err = self::AddOp($mem, $req->zoneid, $uid_to, enum_Friend_op::apply, $uid_from);
  333. // if (ErrCode::ok != $err) {
  334. // return Resp::err($err);
  335. // }
  336. // $err = self::AddOp($mem, $req->zoneid, $req->uid, enum_Friend_op::applied, $uid_to);
  337. // if (ErrCode::ok != $err) {
  338. // return Resp::err($err);
  339. // }
  340. // return Resp::ok(array("ret" => "ok"));
  341. // }
  342. //
  343. // /**
  344. // * [6102]接受好友请求
  345. // * @param Req $req
  346. // */
  347. // public static function Accept($req) { // 将对方立即放到自己的好友列表中, 并给对方发送接受的op, 删除请求记录
  348. // $mem = $req->mem;
  349. // $zoneid = $req->zoneid;
  350. // $uid_my = $req->uid;
  351. // $uid_arr = explode(',', $req->paras[0]);
  352. // foreach ($uid_arr as $uid_to) {
  353. // $myOp = self::getOps($mem, $req->uid, $zoneid, enum_Friend_op::apply); // 自己的请求列表
  354. // unset($myOp->$uid_to); // 删除请求记录
  355. // self::saveOps($mem, $req->uid, $zoneid, $myOp, enum_Friend_op::apply); // 更新自己的请求列表
  356. //
  357. // $err = self::AddOp($mem, $zoneid, $uid_to, enum_Friend_op::accepted, $uid_my); // 向对方的已接受列表中添加记录
  358. // if ($err != ErrCode::ok) { // 出错
  359. // return Resp::err($err);
  360. // }
  361. // self::_AddFriend($mem, $uid_my, $zoneid, $uid_to);
  362. //// $mem->sadd(MemKey_User::FriendsList_set($zoneid, $req->uid), $uid_to); // 立即将对方添加到好友列表
  363. // }
  364. //
  365. // return Resp::ok(array("ret" => "ok"));
  366. // }
  367. //
  368. // /**
  369. // * [6103]拒接好友请求
  370. // * @param Req $req
  371. // */
  372. // public static function Deny($req) { // 直接 删除请求记录, 不通知对方了
  373. // $mem = $req->mem;
  374. // $zoneid = $req->zoneid;
  375. // $uid_my = $req->uid;
  376. // $uid_to = $req->paras[0];
  377. //
  378. // // 从自己的列表中删除就行了,不用通知对方
  379. // $myOp = self::getOps($mem, $uid_my, $zoneid, enum_Friend_op::apply); // 自己的请求列表
  380. // unset($myOp->$uid_to);
  381. // self::saveOps($mem, $uid_my, $zoneid, $myOp, enum_Friend_op::apply); // 更新自己的请求列表
  382. //
  383. // return Resp::ok(array("ret" => "ok"));
  384. // }
  385. //
  386. // /**
  387. // * [6104]删除好友
  388. // * @param Req $req
  389. // */
  390. // public static function Remove($req) {// 将对方立即从自己的好友列表中删除, 并给对方发送remove的op
  391. // $mem = $req->mem;
  392. // $zoneid = $req->zoneid;
  393. // $uid_to = $req->paras[0]; // 删除谁
  394. // $uid_my = $req->uid;
  395. //
  396. // $tOp = self::getOps($mem, $uid_to, $zoneid, enum_Friend_op::remove); // 对方的删除列表
  397. // $ts = now();
  398. // $userInfo_my = UserProc::getUserInfo($mem, $zoneid, $uid_my);
  399. // $name = $userInfo_my->game->name;
  400. // $tOp->$uid_my = $ts . "_" . $name;
  401. // self::saveOps($mem, $uid_to, $zoneid, $tOp, enum_Friend_op::remove); // 更新对方的删除列表
  402. // self::_RemoveFriend($mem, $uid_my, $zoneid, $uid_to);
  403. //
  404. // return Resp::ok(array("ret" => "ok"));
  405. // }
  406. //
  407. ////
  408. //// </editor-fold>
  409. ////
  410. //// <editor-fold defaultstate="collapsed" desc=" 搜索 ">
  411. //
  412. // /**
  413. // * [6110]搜索好友
  414. // * @param Req $req
  415. // */
  416. // static function SearchFriend($req) {
  417. // //客户端参数解析
  418. // if (count($req->paras) <= 1) { // 参数非法
  419. // return Resp::err(ErrCode::parasnotenough_msg);
  420. // }
  421. // $zoneid = $req->zoneid;
  422. // $filter = $req->paras[0];
  423. // $start = 0;
  424. // if (count($req->paras) > 1) {
  425. // $start = $req->paras[1];
  426. // }
  427. // $max = 8; // 每次查询返回的数据条目数量
  428. // $sql = "select * from `tab_rolename` where (`userID`='$filter' OR `roleName` like '%$filter%') and zoneid = $zoneid limit $start, $max ;";
  429. // $paydb = CPayInit();
  430. // $rows = $paydb->fetch_array($sql);
  431. // $ret = ArrayInit();
  432. // foreach ($rows as $row) {
  433. // $uid = $row['userID'];
  434. // $zone_all = $row['zoneid'];
  435. // if ($uid == $req->uid) {
  436. // continue;
  437. // }
  438. // $friendInfo = self::initfriendInfo($req->mem, $uid, $zone_all);
  439. // if ($friendInfo != null) {
  440. // $ret[] = $friendInfo;
  441. // }
  442. // }
  443. // $ops = self::getOps($req->mem, $req->uid, $req->zoneid, enum_Friend_op::applied);
  444. // return Resp::ok(array('fList' => $ret, 'applied' => $ops));
  445. // }
  446. //
  447. // static function initfriendInfo($mem, $uid, $zoneid) {
  448. // $userInfo = UserProc::getUserInfo($mem, $zoneid, $uid);
  449. // if ($userInfo == null) {
  450. // return null;
  451. // }
  452. // $userGuildInfo = GuildProc::getMemUserGuildInfo($mem, $uid, $zoneid);
  453. // if ($userGuildInfo == null) {
  454. // $userGuildInfo = ObjectInit();
  455. // $userGuildInfo->guildName = "";
  456. // $userGuildInfo->guildId = 0;
  457. // }
  458. // $key_cur = MemKey_GameRun::Game_PVPScoreByZone_zset($zoneid);
  459. // $score = $mem->zscore($key_cur, $uid);
  460. // $userGuildInfo->cupScore = $score == null ? 0 : $score;
  461. // $friendObj = new initfriendInfoModel(null, $uid, $userInfo->game->name, $userInfo->game->level, $userInfo->game->img, #
  462. // $userInfo->game->imgBorderId, $userGuildInfo->guildName, $userGuildInfo->guildId, $userGuildInfo->cupScore);
  463. // return $friendObj;
  464. // }
  465. //
  466. // /**
  467. // * [6111]添加好友界面获取一批推荐好友列表
  468. // * @param Req $req
  469. // */
  470. // static function GetSuggestList($req) {
  471. // //客户端参数解析
  472. // if (count($req->paras) < 1) { // 参数非法
  473. // return Resp::err(ErrCode::parasnotenough_msg);
  474. // }
  475. // $zoneid = $req->zoneid;
  476. // $start = $req->paras[0]; // 第几页
  477. // $max = 8; // 每次查询返回的数据条目数量
  478. // $sql = "select * from `tab_rolename` where `zoneid`=$zoneid order by ts desc limit $start, $max ;";
  479. // $paydb = CPayInit();
  480. // $rows = $paydb->fetch_array($sql);
  481. // $arr = ArrayInit();
  482. // foreach ($rows as $row) {
  483. // if ($row['userID'] == $req->uid) {
  484. // continue;
  485. // }
  486. // unset($row["tid"]);
  487. // unset($row["zoneid"]);
  488. //
  489. // $arr[] = $row['userID'];
  490. // }
  491. // $applidops = self::getOps($req->mem, $req->uid, $req->zoneid, enum_Friend_op::applied);
  492. // $ret = array('fList' => array_unique($arr), 'applied' => $applidops);
  493. // return Resp::ok($ret);
  494. // }
  495. //
  496. //// </editor-fold>
  497. ////
  498. //// <editor-fold defaultstate="collapsed" desc=" 好友列表 ">
  499. //
  500. // /**
  501. // * [6106]获取好友ID列表
  502. // * @param Req $req
  503. // * @return int
  504. // */
  505. // static function getAppFriends($req) {
  506. // self::Reload($req);
  507. // $mem = $req->mem;
  508. // $zoneid = $req->zoneid;
  509. // //客户端参数解析
  510. // $friendIds = self::_GetFriendList($mem, $req->uid, $zoneid); // 取好友列表
  511. //
  512. // $userArr = ArrayInit();
  513. // foreach ($friendIds as $index => $uid) {
  514. // $friendInfo = self::initfriendInfo($mem, $uid, $zoneid);
  515. // if ($friendInfo == null) {
  516. // continue;
  517. // }
  518. // $userArr[] = $friendInfo;
  519. // }
  520. // //$mygiftops = self::getOps($mem, $req->uid, $req->zoneid, enum_Friend_op::giftrecord);
  521. // $resp = Resp::ok(array(
  522. // #"friends" => $friendIds,
  523. // 'userGuild' => $userArr,
  524. // ));
  525. // return $resp;
  526. // }
  527. //
  528. // /**
  529. // * 查找好友数量
  530. // * @param Req $req
  531. // */
  532. // public static function getCurrentFriendsCount($req) {
  533. // return $req->mem->scard(MemKey_User::FriendsList_set($req->zoneid, $req->uid));
  534. // }
  535. //
  536. // /**
  537. // * [6107] 获取好友信息列表
  538. // * @param Req $req
  539. // * @return type
  540. // */
  541. // static function getAppFriendInfos($req) {
  542. // $mem = $req->mem;
  543. // //客户端参数解析
  544. // $zoneid = $req->zoneid;
  545. // $fuids = explode(',', $req->paras[0]); // 逗号分割uid字符串
  546. // $max = 8; # 一次最多取八个数据
  547. // $n = count($fuids);
  548. //// var_dump($fuids);
  549. // if ($n > 0 && $n <= $max) {
  550. // $fuidkeys = array_map(function ($i) use($zoneid) {
  551. // return MemKey_User::Info($zoneid, $i);
  552. // }, $fuids);
  553. // $arr = $mem->getMulti($fuidkeys);
  554. // $friendInfos = ArrayInit();
  555. // $n = 0;
  556. // foreach ($arr as $userInfo) {
  557. // isEditor() && $userInfo = new UserGameModel;
  558. // isEditor() && $shareInfo = new UserHeroModel;
  559. // $uid = $fuids[$n++];
  560. // if (!$userInfo # 玩家数据不为空
  561. // || !property_exists($userInfo, 'heros') # 存在heros数据
  562. // || !$userInfo->heros) { # heros数据不为空
  563. // continue;
  564. // }
  565. // $sharedHeroId = $userInfo->heros->firendSupportHeroUID;
  566. // if ($sharedHeroId) {
  567. // $shareInfo = $userInfo->heros->collectHeros->$sharedHeroId;
  568. // } else { // todo: 暂定如果没有设置共享英雄,默认取集合中第一个英雄, 征询策划是否修订规则
  569. // $coll = $userInfo->heros->collectHeros;
  570. // $keys = array_keys((array) $coll);
  571. // if (count($keys) <= 0) {
  572. // continue;
  573. // }
  574. // $sharedHeroId = $keys[0];
  575. // $shareInfo = $userInfo->heros->collectHeros->$sharedHeroId;
  576. // }
  577. // // 额外将英雄的装备数据替换为实例数据
  578. // self::getArmor($userInfo, $shareInfo, 'weapon');
  579. // self::getArmor($userInfo, $shareInfo, 'armor');
  580. // self::getArmor($userInfo, $shareInfo, 'ring');
  581. // $friendInfos[$uid] = array('sharedHero' => $shareInfo,
  582. // 'lastLoginTs' => isset($userInfo->lastLogin) ? $userInfo->lastLogin : 0,
  583. // 'level' => $userInfo->level,
  584. // 'nickname' => $userInfo->name
  585. // );
  586. // }
  587. // if (count($friendInfos) <= 0) {
  588. // $friendInfos = null;
  589. // }
  590. // $resp = Resp::ok(array('ret' => $friendInfos));
  591. // } else {
  592. // $resp = Resp::err(ErrCode::paras_err);
  593. // }
  594. // return $resp;
  595. // }
  596. //
  597. // static function getArmor($userInfo, $hero, $armor) {
  598. // $armorid = $hero->equip->$armor->itemuid;
  599. //
  600. // if ($armorid > 0 && isset($userInfo->store->equipment->$armorid)) {
  601. // $hero->equip->$armor = $userInfo->store->equipment->$armorid;
  602. // } else {
  603. // $hero->equip->$armor = null;
  604. // }
  605. // }
  606. //
  607. //// </editor-fold>
  608. ////
  609. //// <editor-fold defaultstate="collapsed" desc=" 示好 ">
  610. ////
  611. //
  612. // /**
  613. // * [6115]向好友发送礼物(示好)
  614. // * @param Req $req
  615. // */
  616. // static function sendGiftToAppFriend($req) {
  617. // $mem = $req->mem;
  618. // $zoneid = $req->zoneid;
  619. // $uid = $req->uid;
  620. // //客户端参数解析
  621. // $fuids = explode(',', $req->paras[0]); // 逗号分割的uid数组
  622. //// $pr = $req->paras[1]; // other参数 preserved
  623. // $n = count($fuids);
  624. // if ($n <= 0) {
  625. // return Resp::ok(array("ret" => 0));
  626. // }
  627. // $mygiftrecord = self::getOps($mem, $uid, $zoneid, enum_Friend_op::giftrecord);
  628. // $m = 0;
  629. // for ($i = 0; $i < $n; $i++) {
  630. // $fid = $fuids[$i];
  631. // $tsDay = tsDay();
  632. // if (property_exists($mygiftrecord, $fid) // 判断对方是否能够领取礼物(当天已经发送过,则不再发送)
  633. // && $mygiftrecord->$fid >= $tsDay) {
  634. // continue;
  635. // }
  636. // $mygiftrecord->$fid = $tsDay; # 更新发送记录
  637. // $fgiftinfo = self::getOps($mem, $fid, $zoneid, enum_Friend_op::gift);
  638. // if (null == $fgiftinfo) { // 防御
  639. // $fgiftinfo = ObjectInit(); // 没找到好友数据, 则创建
  640. // }
  641. // // 给对方身上插入操作记录
  642. // if (!isset($fgiftinfo->$uid) or ! is_array($fgiftinfo->$uid)) {//防御
  643. // $fgiftinfo->$uid = ArrayInit();
  644. // }
  645. // $arr = $fgiftinfo->$uid;
  646. // $arr[] = tsDay();
  647. // if (count($arr) > 3) { // 最多保留3条记录
  648. // sort($arr);
  649. // array_shift($arr);
  650. // }
  651. // $fgiftinfo->$uid = $arr; // 更新下
  652. // self::saveOps($mem, $fid, $zoneid, $fgiftinfo, enum_Friend_op::gift);
  653. //
  654. // $m++;
  655. // }
  656. // // 回存数据
  657. // self::saveOps($mem, $uid, $zoneid, $mygiftrecord, enum_Friend_op::giftrecord);
  658. // // 其他检查比如任务、成就系统
  659. // // ...
  660. // // 返回结果
  661. // return Resp::ok(array("ret" => $m));
  662. // }
  663. //
  664. // /**
  665. // * [6113]查询游戏中哪些好友给我发送了礼物的列表
  666. // * @param Req $req
  667. // */
  668. // static function getAppFriendGiftList($req) {
  669. // $mem = $req->mem;
  670. // $zoneid = $req->zoneid;
  671. // $uid = $req->uid;
  672. // // 别人的赠送列表
  673. // $fgiftlist = self::getOps($mem, $uid, $zoneid, enum_Friend_op::gift);
  674. // if (count((array) $fgiftlist) <= 0) {
  675. // $fgiftlist = NULL;
  676. // }
  677. // return Resp::ok(array('ret' => $fgiftlist));
  678. // }
  679. //
  680. // /**
  681. // * [6114]领取来自好友的礼物[并回赠]
  682. // * @param Req $req
  683. // */
  684. // static function getAppFriendGift($req) {
  685. // $mem = $req->mem;
  686. // $zoneid = $req->zoneid;
  687. // $uid = $req->uid;
  688. // //客户端参数解析
  689. // $fuids = explode(',', $req->paras[0]); // 逗号分割的uidtsday数组
  690. // $bSendback = true; // 是否回赠
  691. //
  692. // $arr = array();
  693. // array_map(function($f)use(&$arr) {
  694. // $arr[substr($f, -5)] = substr($f, 0, -5); // tsday()占5个字符
  695. // }, $fuids);
  696. // $fgiftlist = self::getOps($mem, $uid, $zoneid, enum_Friend_op::gift);
  697. //
  698. // $recieved = 0;
  699. // foreach ($arr as $ts => $fid) {
  700. // if (isset($fgiftlist->$fid) && in_array($ts, $fgiftlist->$fid)) {
  701. // StlUtil::arrayRemove($fgiftlist->$fid, $ts);
  702. // $recieved++;
  703. // }
  704. // }
  705. // $req->userInfo->game->friendPoint += $recieved;
  706. // self::saveOps($mem, $uid, $zoneid, $fgiftlist, enum_Friend_op::gift);
  707. // UserProc::updateUserInfo();
  708. // if ($bSendback && $recieved > 0) {
  709. // $uids_send = array_unique(array_values($arr));
  710. // $req->paras[0] = implode(',', $uids_send);
  711. //// var_dump($uids_send);
  712. // self::sendGiftToAppFriend($req);
  713. // }
  714. // // 当天领取好友礼物有没有上限? 比如100个心.
  715. // // 检查是否存在对应的礼物记录,
  716. // // 发送礼物
  717. // // 删除礼物记录
  718. // // 回写数据
  719. // // 返回值
  720. //
  721. // return Resp::ok(array("ret" => $recieved));
  722. // }
  723. //
  724. // /**
  725. // * 玩家初始化
  726. // * @param Req $req
  727. // */
  728. // static function Init($req) {
  729. // $mem = $req->mem;
  730. // $z = $req->zoneid;
  731. // $uid = $req->uid;
  732. //// $mem->sadd(MemKey_User::FriendsList_set($z, $uid), "");
  733. // $mem->hset(MemKey_User::FriendsMsgQueue_hash($z, $uid), "sys", "");
  734. // $mem->hmset(MemKey_User::FriendsOps_hash($z, $uid), array("apply" => "{}",
  735. // "applied" => "{}",
  736. // "gift" => "{}",
  737. // "accepted" => "{}",
  738. // "remove" => "{}",
  739. // 'giftrecord' => "{}"));
  740. // }
  741. //
  742. ////
  743. //// </editor-fold>
  744. ////
  745. ////-------------以下是辅助方法-----------------
  746. ////
  747. //
  748. // /**
  749. // * 验证是否好友
  750. // * @param Req $req
  751. // */
  752. // public static function isFriendship($zoneid, $myUid, $fUid) {
  753. // return gMem()->sismember(MemKey_User::FriendsList_set($zoneid, $myUid), $fUid);
  754. // }
  755. //
  756. // /**
  757. // * 添加fuid到好友列表
  758. // */
  759. // private static function _AddFriend($mem, $uid, $zoneid, $fuid) {
  760. // $mem->sadd(MemKey_User::FriendsList_set($zoneid, $uid), $fuid);
  761. // }
  762. //
  763. // /**
  764. // * 从好友列表中删除fuid
  765. // */
  766. // private static function _RemoveFriend($mem, $uid, $zoneid, $fuid) {
  767. // $mem->sremove(MemKey_User::FriendsList_set($zoneid, $uid), $fuid);
  768. // }
  769. //
  770. // private static function _GetFriendList($mem, $uid, $zoneid) {
  771. // $arr = $mem->smembers(MemKey_User::FriendsList_set($zoneid, $uid));
  772. // if (!$arr) { # 数据为空
  773. // $arr = ArrayInit();
  774. // }
  775. // $friendIds = array_values(array_filter($arr, function ($a) {
  776. // return $a != "";
  777. // }));
  778. // return $friendIds;
  779. // }
  780. //
  781. ////
  782. //// <editor-fold defaultstate="collapsed" desc=" 读写玩家好友数据 ">
  783. //
  784. // /**
  785. // * 添加操作
  786. // * @param enum_Friend_op $op
  787. // * @param Req $req
  788. // */
  789. // private static function AddOp($mem, $zoneid, $uid, $op, $uid_from) {
  790. // $enop = new enum_Friend_op($op);
  791. // if (!$enop->isValidValue($op)) {
  792. // return ErrCode::paras_err;
  793. // }
  794. // $ts = now();
  795. // $tOp = FriendProc::getOps($mem, $uid, $zoneid, $op);
  796. //
  797. // $userInfo = UserProc::getUserInfo($mem, $zoneid, $uid_from);
  798. // $userName = $userInfo->game->name;
  799. // $tOp->$uid_from = $ts . "_" . $userName; # 可以按照时间戳排序
  800. // return FriendProc::saveOps($mem, $uid, $zoneid, $tOp, $op);
  801. // }
  802. //
  803. // /**
  804. // * 查询好友异步操作队列
  805. // * @param CRedisUtil $mem
  806. // * @param string $uid
  807. // * @param int $zoneid
  808. // * @param enum_Friend_op $op
  809. // * @return mixed
  810. // */
  811. // private static function getOps($mem, $uid, $zoneid, $op = 0) {
  812. // $ret = ObjectInit();
  813. // if ($op == enum_Friend_op::__default) {
  814. // $ret = $mem->hgetall(MemKey_User::FriendsOps_hash($zoneid, $uid));
  815. // } else {
  816. // $ret = $mem->hget(MemKey_User::FriendsOps_hash($zoneid, $uid), new enum_Friend_op($op));
  817. // }
  818. // if (is_null($ret)) {
  819. // $ret = ObjectInit();
  820. // }
  821. // return $ret;
  822. // }
  823. //
  824. // /**
  825. // * 回写好友异步操作队列
  826. // * @param CRedisUtil $mem
  827. // * @param string $uid
  828. // * @param int $zoneid
  829. // * @param mixed $data
  830. // * @param int $op
  831. // */
  832. // private static function saveOps($mem, $uid, $zoneid, $data, $op) {
  833. // $enop = new enum_Friend_op($op);
  834. // if (!$enop->isValidValue($op)) {
  835. // return ErrCode::paras_err;
  836. // }
  837. //
  838. // if ($op == enum_Friend_op::__default) { # 全部数据
  839. // $mem->hmset(MemKey_User::FriendsOps_hash($zoneid, $uid), $data);
  840. // } else {
  841. // if (is_array($data) && count($data) == 0) {
  842. // $data = "{}";
  843. // }
  844. // $mem->hset(MemKey_User::FriendsOps_hash($zoneid, $uid), $enop, $data);
  845. // }
  846. // return ErrCode::ok;
  847. // }
  848. //
  849. ////
  850. //// // </editor-fold>
  851. ////
  852. //}
  853. //
  854. //class initfriendInfoModel extends Object_ext {
  855. //
  856. // public $uid;
  857. // public $name;
  858. // public $level;
  859. // public $img;
  860. // public $imgBorderId;
  861. // public $guildName;
  862. // public $guildId;
  863. // public $cupScore;
  864. //
  865. // function __construct($tag, $uid, $name, $level, $img, $imgBorderId, $guildName, $guildId, $cupScore) {
  866. // if (1 == func_num_args() && $tag) { # 默认的Object初始化方法
  867. // parent::__construct($tag);
  868. // } else {
  869. // $this->uid = $uid;
  870. // $this->name = $name;
  871. // $this->level = $level;
  872. // $this->img = $img;
  873. // $this->imgBorderId = $imgBorderId;
  874. // $this->guildName = $guildName;
  875. // $this->guildId = $guildId;
  876. // $this->cupScore = $cupScore;
  877. // }
  878. // }
  879. //
  880. //}