GoodsCommentLists.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop100%开源免费商用商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | 商业版本务必购买商业授权,以免引起法律纠纷
  8. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  9. // | gitee下载:https://gitee.com/likeshop_gitee
  10. // | github下载:https://github.com/likeshop-github
  11. // | 访问官网:https://www.likeshop.cn
  12. // | 访问社区:https://home.likeshop.cn
  13. // | 访问手册:http://doc.likeshop.cn
  14. // | 微信公众号:likeshop技术社区
  15. // | likeshop团队 版权所有 拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshopTeam
  18. // +----------------------------------------------------------------------
  19. namespace app\shopapi\lists;
  20. use app\common\enum\GoodsCommentEnum;
  21. use app\common\model\GoodsComment;
  22. use app\common\service\FileService;
  23. class GoodsCommentLists extends BaseShopDataLists
  24. {
  25. /**
  26. * @notes 设置搜索条件
  27. * @return array
  28. * @author ljj
  29. * @date 2021/8/9 11:09 上午
  30. */
  31. public function setSearch()
  32. {
  33. $where= [];
  34. $where[] = ['gc.goods_id','=',$this->params['goods_id']];
  35. if (!isset($this->params['id']) || $this->params['id'] == '') {
  36. return $where;
  37. }
  38. switch ($this->params['id']){
  39. case 1://晒图
  40. $where[]= ['gci.uri','not null',''];
  41. break;
  42. case 2://好评
  43. $where[]= ['gc.goods_comment','>',3];
  44. break;
  45. case 3://中评
  46. $where[]= ['gc.goods_comment','=',3];
  47. break;
  48. case 4://差评
  49. $where[]= ['gc.goods_comment','<',3];
  50. break;
  51. default:
  52. break;
  53. }
  54. return $where;
  55. }
  56. /**
  57. * @notes 查看商品评论列表
  58. * @return array
  59. * @author ljj
  60. * @date 2021/8/9 11:09 上午
  61. */
  62. public function lists(): array
  63. {
  64. $lists = GoodsComment::alias('gc')
  65. ->leftjoin('user u', 'gc.user_id = u.id')
  66. ->leftjoin('goods_item gi', 'gc.item_id = gi.id')
  67. ->leftjoin('goods_comment_image gci', 'gc.id = gci.comment_id')
  68. ->with(['goods_comment_image'])
  69. ->field('gc.id,gc.goods_comment,gc.service_comment,gc.express_comment,gc.description_comment,gc.comment,gc.reply,gc.create_time,gc.virtual,u.nickname,u.avatar,gi.spec_value_str')
  70. ->where($this->setSearch())
  71. ->where(['status'=>GoodsCommentEnum::APPROVED])
  72. ->limit($this->limitOffset, $this->limitLength)
  73. ->order('gc.id','desc')
  74. ->group('gc.id')
  75. ->select()
  76. ->toArray();
  77. foreach ($lists as &$list) {
  78. //处理用户头像路径
  79. if (empty($list['virtual'])) {
  80. // 真实评价
  81. $list['avatar'] = empty($list['avatar']) ? '' : FileService::getFileUrl($list['avatar']);
  82. $list['nickname'] = hide_substr($list['nickname']);
  83. } else {
  84. // 虚拟评价
  85. $virtual = json_decode($list['virtual'], true);
  86. $list['avatar'] = FileService::getFileUrl($virtual['avatar']);
  87. $list['nickname'] = hide_substr($virtual['nickname']);
  88. $list['user_sn'] = $virtual['sn'];
  89. $list['goods_name'] = $virtual['goods_name'];
  90. }
  91. //处理评论图片输出
  92. foreach ($list['goods_comment_image'] as $val) {
  93. $list['image'][] = $val['uri'];
  94. }
  95. unset($list['goods_comment_image']);
  96. }
  97. return $lists;
  98. }
  99. /**
  100. * @notes 查看商品评论总数
  101. * @return int
  102. * @author ljj
  103. * @date 2021/8/9 11:08 上午
  104. */
  105. public function count(): int
  106. {
  107. return GoodsComment::alias('gc')
  108. ->leftjoin('user u', 'gc.user_id = u.id')
  109. ->leftjoin('goods_item gi', 'gc.item_id = gi.id')
  110. ->leftjoin('goods_comment_image gci', 'gc.id = gci.comment_id')
  111. ->where($this->setSearch())
  112. ->where(['status'=>GoodsCommentEnum::APPROVED])
  113. ->group('gc.id')
  114. ->count();
  115. }
  116. }