StatusEnum::ENABLED] ]; if (!empty($user_id)) $where[] = ['user_id' => $user_id]; if (isset($params['store_id'])) { $where[] = ['store_id' => $params['store_id']]; } if (!empty($params['tech_id'])) $where[] = ['tech_id' => $params['tech_id']]; if (!empty($params['tech_user_id'])) $where[] = ['tech_user_id' => $params['tech_user_id']]; $total = OrderReserveComments::find()->where(array_merge(['and'], $where))->count(); $data['comment_count'][] = ['name' => OrderCommentEnum::OC_ALL, 'count' => $total ?? 0]; $good_num = OrderReserveComments::find()->where(array_merge(['and'], $where))->andWhere(['in', 'score', OrderCommentEnum::OC_PRAISE_SCORES])->count(); $data['comment_count'][] = ['name' => OrderCommentEnum::OC_PRAISE, 'count' => $good_num ?? 0]; $count = OrderReserveComments::find()->where(array_merge(['and'], $where))->andWhere(['in', 'score', OrderCommentEnum::OC_MIDDLE_SCORES])->count(); $data['comment_count'][] = ['name' => OrderCommentEnum::OC_MIDDLE, 'count' => $count ?? 0]; $count = OrderReserveComments::find()->where(array_merge(['and'], $where))->andWhere(['in', 'score', OrderCommentEnum::OC_NEGATIVE_SCORES])->count(); $data['comment_count'][] = ['name' => OrderCommentEnum::OC_NEGATIVE, 'count' => $count ?? 0]; if (!empty($params['type'])) { switch ($params['type']) { case OrderCommentEnum::TYPE1: //差评 $where[] = ['in', 'score', [1,2]]; break; case OrderCommentEnum::TYPE2: //中评 $where[] = ['in', 'score',[3]]; break; case OrderCommentEnum::TYPE4: //好评 $where[] = ['in', 'score', [4,5]]; break; } } $ret = OrderReserveComments::listPage([ 'where' => $where, 'order' => 'id desc', 'with' => ['comment' => function($query) { $query->select('id, pic_url, content, score, created_at, is_virtual, virtual_user, virtual_avatar, virtual_time'); }, 'user', 'orderDetail' => function($query) { $query->select('id, goods_id, goods_name, goods_attr_id, goods_attr_name, price, goods_price, num, pic_url'); }], 'limit' => $params['limit'] ?? 10, 'select' => 'id, aging_score, major_score, attitude_score, tags, user_id, order_detail_id,staff_score,show_tech' ]); if (!empty(OrderReserveComments::getStaticError())) return OrderReserveComments::getStaticError(); if (!empty($ret['list'])) { foreach ($ret['list'] as &$item) { $item['tags'] = !empty($item['tags']) ? Json::decode($item['tags']) : []; $item['comment']['pic_url'] = !empty($item['comment']['pic_url']) ? Json::decode($item['comment']['pic_url']) : []; if (!empty($item['comment']['is_virtual'])) { $item['user'] = [ 'nickname' => $item['comment']['virtual_user'], 'avatar_url' => $item['comment']['virtual_avatar'], ]; } $item['created_at'] = date('Y-m-d H:i:s', !empty($item['comment']['is_virtual']) ? $item['comment']['virtual_time'] : $item['comment']['created_at']); unset($item['comment']['is_virtual'], $item['comment']['virtual_user,'], $item['comment']['virtual_avatar'], $item['comment']['virtual_time']); } } $ret['comment_count'] = $data['comment_count']; return $ret; } /** * 获取指定技师的评分 * @param int $mall_id * @param int $user_id * @param int $tech_id * @return int|string */ public function rating(int $mall_id, int $user_id = 0, int $tech_id = 0) { $query = ReservationServiceUser::find()->where(['mall_id' => $mall_id]) ->andWhere(['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]); if (!empty($user_id)) { $query = $query->andWhere(['user_id' => $user_id]); } else if (!empty($tech_id)) { $query = $query->andWhere(['id' => $tech_id]); } else { return 0; } $service_rating = $query->select('service_rating')->scalar(); return !empty($service_rating) ? $service_rating : 0; } public function commentsList($params) { $mall_id = $params['mall_id']; $where = [ ['mall_id' => $mall_id], [ 'status' => StatusEnum::ENABLED], ['goods_id' => $params['goods_id']], ['store_id' => $params['store_id']], ]; if (!empty($params['type'])) { switch ($params['type']) { case OrderCommentEnum::TYPE1: //差评 $where[] = ['in', 'score', OrderCommentEnum::OC_NEGATIVE_SCORES]; break; case OrderCommentEnum::TYPE2: //中评 $where[] = ['in', 'score', OrderCommentEnum::OC_MIDDLE_SCORES]; break; case OrderCommentEnum::TYPE4: //好评 $where[] = ['in', 'score', OrderCommentEnum::OC_PRAISE_SCORES]; break; } } $params['where'] = $where; $params['select'] = 'id,user_id,order_detail_id,pic_url,score,content,created_at'; $params['with'] = ['users']; $params['order'] = 'is_top desc,id desc'; $order_comments_list = OrderComments::listPage($params); if (!empty($order_comments_list['list'])) { $order_detail_ids = array_column($order_comments_list['list'],'order_detail_id'); $order_reserve_comments_list = OrderReserveComments::lists(['where'=>[['order_detail_id'=>$order_detail_ids]],'index'=>'order_detail_id']); $tech_user_ids = array_column($order_reserve_comments_list,'tech_user_id'); $reservation_service_user_list = ReservationServiceUser::lists(['where'=>[['user_id'=>$tech_user_ids],['status'=>StatusEnum::ENABLED]],'index'=>'user_id','select'=>'user_id,avatar,name']); foreach ($order_comments_list['list'] as &$v) { $v['pic_url'] = !empty($v['pic_url']) ? json_decode($v['pic_url'], true) : []; $v['nickname'] = $v['avatar_url'] =''; if(isset($v['users'])){ $v['nickname'] = $v['users']['nickname'] ?? ""; $v['avatar_url'] = $v['users']['avatar_url'] ?? ''; } unset($v['users']); $v['tags'] = []; $v['staff_score'] = $v['environment_score'] = $v['service_score'] = 0; $v['tech_user_name'] = $v['tech_user_avatar'] = ''; if(isset($order_reserve_comments_list[$v['order_detail_id']])){ $order_comment = $order_reserve_comments_list[$v['order_detail_id']]; $v['tags'] = json_decode($order_comment['tags']); $v['staff_score'] = $order_comment['staff_score']; $v['environment_score'] = $order_comment['environment_score']; $v['service_score'] = $order_comment['service_score']; $v['score'] = $order_comment['score']; $tech_user_id = $order_comment['tech_user_id']; if (isset($order_comment) && $order_comment['show_tech'] == 1 && isset($reservation_service_user_list[$tech_user_id])) { $v['tech_user_name'] = $reservation_service_user_list[$tech_user_id]['name']; $v['tech_user_avatar'] = $reservation_service_user_list[$tech_user_id]['avatar']; } } } } return $order_comments_list; } }