Comment.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /**
  3. * Comment.php UTF-8
  4. *
  5. *
  6. * @date : 2017/11/24 17:19
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huo\controller\comment;
  13. use huo\controller\common\Base;
  14. use huo\logic\comment\CommentLogic;
  15. use huolib\status\CommonStatus;
  16. class Comment extends Base {
  17. protected $comment_logic;
  18. public function __construct(CommentLogic $comment_logic = null) {
  19. if (null === $comment_logic) {
  20. $this->comment_logic = new CommentLogic();
  21. } else {
  22. $this->comment_logic = $comment_logic;
  23. }
  24. }
  25. /**
  26. * 获取列表
  27. *
  28. * @param array $param
  29. * @param string $page
  30. *
  31. * @return array
  32. */
  33. public function getList($param = [], $page) {
  34. $_map['table_name'] = $param['type_name'];
  35. $_map['object_id'] = $param['object_id'];
  36. $_cnt = $this->comment_logic->getCnt($_map);
  37. if (empty($_cnt)) {
  38. $_data = [];
  39. } else {
  40. $_order = '-create_time';
  41. $_data = $this->comment_logic->getList($_map, $page, $_order);
  42. }
  43. $_rdata = [
  44. 'count' => $_cnt,
  45. 'list' => $_data,
  46. ];
  47. $code = CommonStatus::NO_ERROR;
  48. return $this->huoSuccess($code, CommonStatus::getMsg($code), $_rdata);
  49. }
  50. /**
  51. * 添加评论
  52. *
  53. * @param array $param
  54. * @param int $mem_id
  55. *
  56. * @return array
  57. */
  58. public function addComment($param, $mem_id) {
  59. $param['mem_id'] = $mem_id;
  60. $_rs = $this->comment_logic->addComment($param);
  61. $code = CommonStatus::NO_ERROR;
  62. if (!$_rs) {
  63. $code = CommonStatus::INNER_ERROR;
  64. }
  65. return $this->huoSuccess($code, CommonStatus::getMsg($code));
  66. }
  67. /**
  68. * 获取列表
  69. *
  70. * @param int $mem_id 玩家ID
  71. * @param string $page
  72. *
  73. * @return array
  74. */
  75. public function getMyGameCommentList($mem_id, $page) {
  76. $_map['table_name'] = 'game';
  77. $_map['mem_id'] = $mem_id;
  78. $_cnt = $this->comment_logic->getCnt($_map);
  79. if (empty($_cnt)) {
  80. $_data = [];
  81. } else {
  82. $_order = '-create_time';
  83. $_data = $this->comment_logic->getListAndGame($_map, $page, $_order);
  84. }
  85. $_rdata = [
  86. 'count' => $_cnt,
  87. 'list' => $_data,
  88. ];
  89. $code = CommonStatus::NO_ERROR;
  90. return $this->huoSuccess($code, CommonStatus::getMsg($code), $_rdata);
  91. }
  92. /**
  93. * 获取评论数量
  94. *
  95. * @param int $mem_id 玩家ID
  96. *
  97. * @return array
  98. */
  99. public function getCnt($mem_id) {
  100. $_map['table_name'] = 'game';
  101. $_map['mem_id'] = $mem_id;
  102. $_cnt = $this->comment_logic->getCnt($_map);
  103. $_rdata = [
  104. 'comment_cnt' => $_cnt,
  105. ];
  106. $code = CommonStatus::NO_ERROR;
  107. return $this->huoSuccess($code, CommonStatus::getMsg($code), $_rdata);
  108. }
  109. }