HeroDiscussProc.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?php
  2. //
  3. //namespace loyalsoft;
  4. //
  5. ///**
  6. // * 评价内容
  7. // */
  8. //class DiscussItem extends Object_ext {
  9. //
  10. // public $uid;
  11. // public $name;
  12. // public $msg;
  13. // public $ts;
  14. // public $praise;
  15. // public $praised_uids;
  16. //
  17. // /**
  18. // * @return int 重新计算此条评论的排行
  19. // */
  20. // public function Score() {
  21. // return $this->ts + $this->praise * glc()->Hero_Discuss_Praise_weight;
  22. // }
  23. //
  24. //}
  25. //
  26. ///**
  27. // * 英雄评论模块
  28. // * @version
  29. // * 1.0.0 Created at 2017-3-24. by --gwang
  30. // * @author gwang (mail@wanggangzero.cn)
  31. // * @copyright ? 2017-3-24, SJZ LoyalSoft Corporation & gwang. All rights reserved.
  32. // */
  33. //class HeroDiscussProc {
  34. //
  35. // /**
  36. // * 每次请求返回的评论数量
  37. // */
  38. // const PageItemCount = 50;
  39. //
  40. // /**
  41. // * [6317]发表评价
  42. // * @param Req $req
  43. // */
  44. // static function Post($req) {
  45. // $mem = $req->mem;
  46. // $uid = $req->uid;
  47. // $heroId = $req->paras[0]; # 英雄ID
  48. // $content = $req->paras[1]; # 评价内容
  49. // $item = new DiscussItem(array(# # 创建一条评论
  50. // 'uid' => $uid,
  51. // 'name' => $req->userInfo->game->baseInfo->name,
  52. // 'msg' => $content,
  53. // 'ts' => now(),
  54. // 'praise' => 0, # # 赞
  55. // 'praised_uids' => ArrayInit()
  56. // ));
  57. // if ($mem->hexists(MemKey_GameRun::HeroDiscusses_item_hash($heroId), $uid)) {
  58. // $item = self::_GetDiscussItem($mem, $heroId, $uid);
  59. // } else {
  60. // self::_SaveDiscussItem($heroId, $uid, $item); # 保存评论
  61. // $mem->zadd(MemKey_GameRun::HeroDiscusses_score_zset($heroId), #
  62. // array($uid => $item->Score())); # # 写入排行数据
  63. // }
  64. // // todo: 添加总评论数量限制, 超过一定数量清理部分评论
  65. // return Resp::ok(array("ret" => $item)); # 成功后返回评论内容,
  66. // // ps.客户端可以对比返回的内容是否和发送的内容一致,不一致代表已经有过评论了,不可以再发布新评论, 这个设定有跟待策划商议.
  67. // }
  68. //
  69. // /**
  70. // * [6319] 删除评价
  71. // * @param Req $req
  72. // */
  73. // static function DeletePost($req) {
  74. // $uid = $req->uid;
  75. // $heroId = $req->paras[0]; # 英雄ID
  76. // $msg = "";
  77. // if ($req->mem->hdel(MemKey_GameRun::HeroDiscusses_item_hash($heroId), $uid)) {
  78. // $msg = "success";
  79. // }
  80. // return Resp::ok(array('ret' => $msg));
  81. // }
  82. //
  83. // /**
  84. // * [6320] 给英雄打分(同一个英雄只能打一次分)
  85. // * @param Req $req
  86. // */
  87. // static function Score($req) {
  88. // $uid = $req->uid;
  89. // list($heroId, $score) = $req->paras; # 提取参数: 英雄ID, 打分值
  90. // my_Assert($score > 0 && $score <= 5, ErrCode::paras_err); # 参数非法: 打分区间不对
  91. //// $pubifno = $req->mem->get(MemKey_User::Union_PublicState_hash($uid)); # 玩家各区共享的数据
  92. // $pubifno = new PublicStateModel(); # 玩家各区共享的数据
  93. // $pubifno->readDataFromMem(MemKey_User::Union_PublicState_hash($uid));
  94. // $scoredlist = $pubifno->scoredheros;
  95. // if (is_null($scoredlist) || !is_array($scoredlist)) {
  96. // $scoredlist = ArrayInit();
  97. // }
  98. // if (CommUtil::isInArray($scoredlist, $heroId)) { # 判断玩家是否给此英雄打过分了
  99. // return Resp::ok(array('err' => 1, 'msg' => 'has scored!')); # -- 业务逻辑内部错误码
  100. // }
  101. // // 添加打分数据,
  102. // // 取英雄的打分数据 {cnt:xxx,totalscore:xxx}
  103. // $heroscore = $req->mem->get(MemKey_GameRun::HeroDiscusses_userScore_normal($heroId));
  104. // if (is_null($heroscore)) {
  105. // $heroscore = ObjectInit();
  106. // $heroscore->amt = 0;
  107. // $heroscore->totalscore = 0;
  108. // }
  109. // $heroscore->amt += 1;
  110. // $heroscore->totalscore += $score;
  111. // $scoredlist[] = $heroId; # 玩家记录打分记录
  112. // $pubifno->scoredheros = $scoredlist; # 回存数据
  113. // $pubifno->updateData(MemKey_User::Union_PublicState_hash($uid));
  114. //
  115. // $req->mem->set(MemKey_GameRun::HeroDiscusses_userScore_normal($heroId), $heroscore);
  116. // $newscore = $heroscore->amt > 0 ? $heroscore->totalscore / $heroscore->amt : 0;
  117. // return Resp::ok(array('err' => 0, # # 返回
  118. // 'score' => round($newscore, 2)));
  119. // }
  120. //
  121. // /**
  122. // * [6316]查看评价
  123. // * @param Req $req
  124. // */
  125. // static function GetDiscusses($req) {
  126. // $heroId = $req->paras[0]; # 英雄ID
  127. // $start = $req->paras[1]; # 起始索引
  128. // $indexs = $req->mem->zrange(MemKey_GameRun::HeroDiscusses_score_zset($heroId), #
  129. // $start, $start + self::PageItemCount);
  130. // $arr = $req->mem->hmget(MemKey_GameRun::HeroDiscusses_item_hash($heroId), $indexs);
  131. //
  132. // $heroscore = $req->mem->get(MemKey_GameRun::HeroDiscusses_userScore_normal($heroId));
  133. // if (is_null($heroscore)) {
  134. // $heroscore = ObjectInit();
  135. // $heroscore->amt = 0;
  136. // $heroscore->totalscore = 0;
  137. // }
  138. // $score = $heroscore->amt > 0 ? $heroscore->totalscore / $heroscore->amt : 0;
  139. // return Resp::ok(array("ret" => $arr, 'score' => round($score, 2)));
  140. // }
  141. //
  142. // /**
  143. // * [6318]给评论点赞
  144. // * @param Req $req
  145. // */
  146. // static function PriaseMsg($req) {
  147. // $mem = $req->mem;
  148. // $uid = $req->uid;
  149. // $heroId = $req->paras[0]; # 英雄ID
  150. // $discussId = $req->paras[1]; # 评论ID
  151. //
  152. // $msg = self::_GetDiscussItem($mem, $heroId, $discussId); # 取数据
  153. // if (!$msg) {
  154. // return Resp::ok(array("err" => -1)); # 评论不存在
  155. // }
  156. // if (isset($msg->praised_uids) && in_array($uid, $msg->praised_uids)) {
  157. // return Resp::ok(array("err" => 1, # # 已赞过
  158. // 'praise' => $msg->praise));
  159. // }
  160. // $msg->praise += 1; # 点赞
  161. // $msg->praised_uids[] = $uid; # 添加点赞记录
  162. // self ::_SaveDiscussItem($heroId, $discussId, $msg); # 回写数据
  163. // $mem->zadd(MemKey_GameRun::HeroDiscusses_score_zset($heroId), #
  164. // array($discussId => $msg->Score())); # 更新排名
  165. // return Resp::ok(array("err" => 0, # # 返回最新的被赞数量
  166. // 'praise' => $msg->praise));
  167. // }
  168. //
  169. //// <editor-fold defaultstate="collapsed" desc="辅助函数">
  170. //
  171. // /**
  172. // * 取评论
  173. // * @param CRedisUtil $mem
  174. // * @param string $heroId
  175. // * @param string $discussId
  176. // * @return DiscussItem Description
  177. // */
  178. // static private function _GetDiscussItem($mem, $heroId, $discussId) {
  179. // $ret = $mem->hget(MemKey_GameRun::HeroDiscusses_item_hash($heroId), $discussId);
  180. // if ($ret) {
  181. // return new DiscussItem($ret);
  182. // }
  183. // return null;
  184. // }
  185. //
  186. // /**
  187. // * 回写评论
  188. // * @param type $heroId
  189. // * @param type $discussId
  190. // * @param type $item
  191. // */
  192. // static private function _SaveDiscussItem($heroId, $discussId, $item) {
  193. // gMem()->hset(MemKey_GameRun::HeroDiscusses_item_hash($heroId), $discussId, $item); // 回写数据
  194. // }
  195. //
  196. //// </editor-fold>
  197. //}