$params['id'],'audit_status'=>ShopEnum::AUDIT_STATUS_PASS,'server_status'=>ShopEnum::SERVERSTATUSOPEN]) ->with(['shop_image']) ->field($field) ->append(['distance_desc','category_ids','work_status_desc','region_desc','business_time_desc']) ->findOrEmpty(); $ids = array_column($detail->category_ids->toArray(),'category_id'); $categoryLists = GoodsCategory::where(['is_show'=>1,'id'=>$ids])->column('name'); $detail['category_name'] = implode('|',$categoryLists); if (!is_array($detail['category_name'])) { $detail['category_name'] = [$detail['category_name']]; } $week = strtolower(date('l')); $shopWeek = $detail[$week] ?? 0; if(!$shopWeek){ $detail['work_status'] = 0; $detail['work_status_desc'] = ShopEnum::getWorkStatus($detail['work_status']); }else{ $nowHi = date('H:i'); $detail['business_start_time'] = format_business_time($detail['business_start_time']); $detail['business_end_time'] = format_business_time($detail['business_end_time']); if($detail['business_start_time'] > $nowHi || $detail['business_end_time'] < $nowHi){ $detail['work_status'] = 0; $detail['work_status_desc'] = ShopEnum::getWorkStatus($detail['work_status']); } } $consumption = Order::where(['pay_status'=>PayEnum::ISPAID]) ->where('shop_id','=',$params['id']) ->value('round(sum(order_amount)/count(id),2) as consumption'); $detail['consumption'] = $consumption ? : 0; $map1 = [ ['SGI.shop_id','=',$params['id']], ]; $detail['goods_lists'] = Goods::alias('G') ->leftjoin('shop_goods_index SGI','G.id = SGI.goods_id') ->whereRaw('(SGI.shop_id ='. $params['id'].') or (G.shop_id = '.$params['id'].' and G.audit_status = '.GoodsEnum::AUDIT_STATUS_PASS .')') ->field('G.id,name,image,price,scribing_price,duration,order_num') ->limit(8) ->select() ->toArray(); $coachIds = ShopCoachApply::where(['shop_id'=>$params['id'],'audit_status'=>ShopEnum::AUDIT_STATUS_PASS])->column('coach_id'); $commentLists = GoodsComment::where(['coach_id'=>$coachIds]) ->field('id,user_id,service_comment,comment,reply') ->append(['goods_comment_image']) ->limit(5) ->select() ->toArray(); $userIds = array_column($commentLists,'user_id'); $userLists = User::where(['id'=>$userIds])->column('nickname,avatar','id'); foreach ($commentLists as $key => $comment_list){ $commentLists[$key]['nickname'] = $userLists[$comment_list['user_id']]['nickname'] ?? ''; $commentLists[$key]['avatar'] = FileService::getFileUrl($userLists[$comment_list['user_id']]['avatar'] ?? ''); } $detail['comment_lists'] = $commentLists; if(!empty($params['terminal'])){ $ip = request()->ip(); // 一个ip一个终端一天只生成一条记录 $record = ShopVisit::where([ 'shop_id' => $params['id'], 'ip' => $ip, 'terminal' => $params['terminal'] ])->whereDay('create_time')->findOrEmpty(); if (!$record->isEmpty()) { // 增加访客在终端的浏览量 $record->visit += 1; $record->save(); } // 生成访客记录 ShopVisit::create([ 'shop_id' => $params['id'], 'ip' => $ip, 'terminal' => $params['terminal'], 'visit' => 1 ]); } $detail['is_collect'] = Collect::where(['relation_id'=>$params['id'],'user_id'=>$userInfo['user_id'] ?? 0,'type'=>3])->findOrEmpty()->toArray() ? 1 : 0; return $detail->toArray(); } public function commentCategory($shopId) { $coachIds = Coach::where(['shop_id'=>$shopId])->field('id')->select()->toArray(); $coachIds = array_column($coachIds,'id'); $orderGoodsIds = Order::alias('O') ->join('order_goods OG','O.id = OG.order_id') ->where(['coach_id'=>$coachIds,'is_comment'=>1]) ->field('OG.id') ->select() ->toArray(); $orderGoodsIds = array_column($orderGoodsIds,'id'); $all_count = GoodsComment::where('order_goods_id','in', $orderGoodsIds)->count(); $image_count = GoodsComment::alias('gc')->where('order_goods_id','in',$orderGoodsIds)->join('goods_comment_image gci', 'gc.id = gci.comment_id')->group('gci.comment_id')->count(); $good_count = GoodsComment::where('order_goods_id', 'in',$orderGoodsIds)->where('service_comment','>',3)->count(); $medium_bad_count = GoodsComment::where('order_goods_id', 'in',$orderGoodsIds)->where('service_comment','<=',3)->count(); if($all_count == 0) { $percentStr = '100%'; $star = 5; }else { $percent = round((($good_count / $all_count) * 100)); $percentStr = round((($good_count / $all_count) * 100)).'%'; if ($percent >= 100) { $star = 5; } else if ($percent >= 80) { $star = 4; } else if ($percent >= 60) { $star = 3; } else if ($percent >= 40) { $star = 2; } else if ($percent >= 20) { $star = 1; } else { $star = 0; } } return ['comment'=> [ [ 'id' => 0, 'name' => '全部', 'count' => $all_count ], [ 'id' => 1, 'name' => '有图', 'count' => $image_count ], [ 'id' => 2, 'name' => '好评', 'count' => $good_count ], [ 'id' => 3, 'name' => '中差评', 'count' => $medium_bad_count ] ] , 'percent' => $percentStr, 'star' => $star, ]; } }