HeroDiscussProc.php 8.3 KB

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