params['goods_id']]; if (!isset($this->params['id']) || $this->params['id'] == '') { return $where; } switch ($this->params['id']){ case 1://晒图 $where[]= ['gci.uri','not null','']; break; case 2://好评 $where[]= ['gc.goods_comment','>',3]; break; case 3://中评 $where[]= ['gc.goods_comment','=',3]; break; case 4://差评 $where[]= ['gc.goods_comment','<',3]; break; default: break; } return $where; } /** * @notes 查看商品评论列表 * @return array * @author ljj * @date 2021/8/9 11:09 上午 */ public function lists(): array { $lists = GoodsComment::alias('gc') ->leftjoin('user u', 'gc.user_id = u.id') ->leftjoin('goods_item gi', 'gc.item_id = gi.id') ->leftjoin('goods_comment_image gci', 'gc.id = gci.comment_id') ->with(['goods_comment_image']) ->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') ->where($this->setSearch()) ->where(['status'=>GoodsCommentEnum::APPROVED]) ->limit($this->limitOffset, $this->limitLength) ->order('gc.id','desc') ->group('gc.id') ->select() ->toArray(); foreach ($lists as &$list) { //处理用户头像路径 if (empty($list['virtual'])) { // 真实评价 $list['avatar'] = empty($list['avatar']) ? '' : FileService::getFileUrl($list['avatar']); $list['nickname'] = hide_substr($list['nickname']); } else { // 虚拟评价 $virtual = json_decode($list['virtual'], true); $list['avatar'] = FileService::getFileUrl($virtual['avatar']); $list['nickname'] = hide_substr($virtual['nickname']); $list['user_sn'] = $virtual['sn']; $list['goods_name'] = $virtual['goods_name']; } //处理评论图片输出 foreach ($list['goods_comment_image'] as $val) { $list['image'][] = $val['uri']; } unset($list['goods_comment_image']); } return $lists; } /** * @notes 查看商品评论总数 * @return int * @author ljj * @date 2021/8/9 11:08 上午 */ public function count(): int { return GoodsComment::alias('gc') ->leftjoin('user u', 'gc.user_id = u.id') ->leftjoin('goods_item gi', 'gc.item_id = gi.id') ->leftjoin('goods_comment_image gci', 'gc.id = gci.comment_id') ->where($this->setSearch()) ->where(['status'=>GoodsCommentEnum::APPROVED]) ->group('gc.id') ->count(); } }