userId], ['o.order_status', '=', 3], ['og.is_comment', '=', YesNoEnum::NO], ]; $wait = OrderGoods::alias('og') ->leftJoin('order o', 'o.id = og.order_id') ->where($waitWhere) ->count(); $finishWhere = [ ['o.user_id', '=', $this->userId], ['o.order_status', '=', 3], ['og.is_comment', '=', YesNoEnum::YES], ]; $finish = OrderGoods::alias('og') ->leftJoin('order o', 'o.id = og.order_id') ->where($finishWhere) ->count(); return [ 'wait' => $wait, 'finish' => $finish ]; } /** * @notes 设置搜索条件 * @return array * @author ljj * @date 2021/8/9 2:47 下午 */ public function setSearch() { $where= []; $where[] = ['o.user_id', '=', $this->userId]; $where[] = ['o.order_status', '=', 3]; if (!isset($this->params['type']) || $this->params['type'] == '') { $where[] = ['og.is_comment','=',0]; return $where; } $where[] = ['og.is_comment','=',$this->params['type']]; return $where; } /** * @notes 查看评价商品列表 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author ljj * @date 2021/8/9 2:47 下午 */ public function lists(): array { $lists = Order::alias('o') ->join('order_goods og', 'og.order_id = o.id') ->join('goods g', 'og.goods_id = g.id') ->leftjoin('goods_comment gc','og.id = gc.order_goods_id') ->field('og.id,og.goods_id,og.item_id,g.image as goods_image,g.name as goods_name,og.goods_price,og.goods_num,og.is_comment') ->where($this->setSearch()) ->limit($this->limitOffset, $this->limitLength) ->order('gc.id desc') ->group('og.id') ->select()->toarray(); foreach ($lists as $key =>$list) { //处理商品图片路径 $lists[$key]['goods_image'] = empty($list['goods_image']) ? '' : FileService::getFileUrl($list['goods_image']); // 商品规格 $lists[$key]['spec_value_str'] = GoodsItem::where('id', $list['item_id'])->value('spec_value_str'); //获取商品评价 $lists[$key]['goods_comment'] = []; if ($list['is_comment'] == 0) { continue; } $lists[$key]['goods_comment'] = GoodsComment::where(['user_id'=>$this->userId,'order_goods_id'=>$list['id']]) ->field('id,goods_comment,comment,create_time,reply') ->with('goods_comment_image') ->find(); } return $lists; } /** * @notes 查看评价商品总数 * @return int * @author ljj * @date 2021/8/9 2:47 下午 */ public function count(): int { return Order::alias('o') ->join('order_goods og', 'og.order_id = o.id') ->join('goods g', 'og.item_id = g.id') ->where($this->setSearch()) ->limit($this->limitOffset, $this->limitLength) ->count(); } }