CommentLogic.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /**
  3. * CommentLogic.php UTF-8
  4. *
  5. *
  6. * @date : 2017/11/24 16:20
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huo\logic\comment;
  13. use huo\model\comment\CommentModel;
  14. use huo\model\common\CommonModel;
  15. class CommentLogic extends CommonModel {
  16. /**
  17. * 获取评论列表
  18. *
  19. * @param array $where
  20. * @param string $page
  21. * @param string $order
  22. *
  23. * @return array
  24. */
  25. public function getList($where = [], $page = '1,10', $order = '') {
  26. $_map = $where;
  27. $_order = $this->orderFilter($order);
  28. $_datas = CommentModel::where($_map)->page($page)->order($_order)->select();
  29. if (empty($_datas)) {
  30. return null;
  31. }
  32. $_list = [];
  33. foreach ($_datas as $_data) {
  34. $_comment = null;
  35. $_comment['id'] = $_data['id'];
  36. $_comment['parent_id'] = $_data['parent_id'];
  37. $_comment['mem_id'] = $_data['mem_id'];
  38. $_comment['icon'] = $_data['mem']['avatar'];
  39. $_comment['to_mem_id'] = $_data['to_mem_id'];
  40. $_comment['object_id'] = $_data['object_id'];
  41. $_comment['create_time'] = $_data['create_time'];
  42. $_comment['full_name'] = $_data['mem']['nickname'];
  43. $_comment['path'] = null;
  44. $_comment['url'] = '';
  45. $_comment['content'] = $_data['content'];
  46. $_list[] = $_comment;
  47. }
  48. return $_list;
  49. }
  50. /**
  51. * 获取数量
  52. *
  53. * @param array $where
  54. *
  55. * @return int|string
  56. */
  57. public function getCnt($where = []) {
  58. $_map = $where;
  59. $_cnt = CommentModel::where($_map)->count();
  60. return $_cnt;
  61. }
  62. /**
  63. * 添加评论
  64. *
  65. * @param array $data
  66. *
  67. * @return bool
  68. */
  69. public function addComment($data = []) {
  70. $_data['parent_id'] = $this->getVal($data, 'parent_id', 0);
  71. $_data['mem_id'] = $this->getVal($data, 'mem_id', 0);
  72. $_data['to_mem_id'] = $this->getVal($data, 'to_mem_id', 0);
  73. $_data['object_id'] = $this->getVal($data, 'object_id', 0);
  74. $_data['table_name'] = $this->getVal($data, 'table_name', 'game');
  75. $_data['content'] = $this->getVal($data, 'content');
  76. $_rs = CommentModel::setComment($_data);
  77. if ($_rs) {
  78. return true;
  79. } else {
  80. return false;
  81. }
  82. }
  83. /**
  84. * 获取评论列表
  85. *
  86. * @param array $where
  87. * @param string $page
  88. * @param string $order
  89. *
  90. * @return array
  91. */
  92. public function getListAndGame($where = [], $page = '1,10', $order = '') {
  93. $_map = $where;
  94. $_order = $this->orderFilter($order);
  95. $_datas = CommentModel::with('game')->where($_map)->page($page)->order($_order)->select();
  96. if (empty($_datas)) {
  97. return null;
  98. }
  99. $_list = [];
  100. foreach ($_datas as $_data) {
  101. $_comment = null;
  102. $_comment['comment_id'] = $_data['id'];
  103. $_comment['game_id'] = $_data['object_id'];
  104. $_comment['gamename'] = isset($_data['game']['name']) ? $_data['game']['name'] : '';
  105. $_comment['icon'] = isset($_data['game']['icon']) ? $_data['game']['icon'] : '';
  106. $_comment['create_time'] = $_data['create_time'];
  107. $_comment['content'] = $_data['content'];
  108. $_list[] = $_comment;
  109. }
  110. return $_list;
  111. }
  112. }