protected function formatUsers($users) { if (!$users) { return []; } $user_list = []; $user_ids = []; foreach ($users as $user) { $user_ids[] = $user->user_id; if ($user->type == UserBase::TYPE_ADMIN) { $type_text = '管理员'; } elseif ($user->type == UserBase::TYPE_BUSINESS) { $type_text = '商家'; } else { $type_text = '用户'; } $user_list[] = array_merge($user->toArray(), ['type_text' => $type_text, 'status_text' => $user->isOpen() ? '已激活' : '未激活', 'is_active' => $user->isOpen(), 'image_url' => '', 'image_url_real1' => '', 'image_url_real2' => '', 'image_url_real3' => '', 'water_count' => 0, 'black_water' => 0, 'send_water' => 0, 'public_count' => 0, 'giving' => 0, 'user_address' => '', 'user_desc' => '', 'user_http' => '', 'user_company_lat' => '', 'user_company_lng' => '']); } //获得头像信息 $user_image_rt = UserImage::whereIn('user_id', $user_ids)->get(); foreach ($user_list as &$user) { foreach ($user_image_rt as $user_image_rt_v) { if ($user_image_rt_v->type == 1 && $user['user_id'] == $user_image_rt_v->user_id) { $user['image_url'] = $user_image_rt_v->path(); } elseif ($user_image_rt_v->type == 2 && $user['user_id'] == $user_image_rt_v->user_id) { $user['image_url_real1'] = $user_image_rt_v->path(); } elseif (empty($user['image_url_real2']) && $user_image_rt_v->type == 3 && $user['user_id'] == $user_image_rt_v->user_id) { $user['image_url_real2'] = $user_image_rt_v->path(); } elseif ($user_image_rt_v->type == 3 && $user['user_id'] == $user_image_rt_v->user_id) { $user['image_url_real3'] = $user_image_rt_v->path(); } } } //获得亲水值 $user_financial_rt = UserFinancial::whereIn('user_id', $user_ids)->get(); foreach ($user_list as &$user) { foreach ($user_financial_rt as $user_financial_rt_v) { if ($user['user_id'] == $user_financial_rt_v->user_id) { $user['water_count'] = $user_financial_rt_v->water_count; $user['send_water'] = $user_financial_rt_v->send_water; $user['public_count'] = $user_financial_rt_v->public_count; $user['giving'] = $user_financial_rt_v->giving; } } } //获得黑水值 $user_black_rt = UserBlackWater::whereIn('user_id', $user_ids)->get(); foreach ($user_list as &$user) { foreach ($user_black_rt as $user_black_rt_v) { if ($user['user_id'] == $user_black_rt_v->user_id) { $user['black_water'] = $user_black_rt_v->send_water; } } } //获得公司信息 $user_company_extend_rt = UserCompanyExtend::whereIn('user_id', $user_ids)->get(); foreach ($user_list as &$user) { foreach ($user_company_extend_rt as $user_company_extend_rt_v) { if ($user['user_id'] == $user_company_extend_rt_v->user_id) { $user['user_address'] = $user_company_extend_rt_v->user_address; $user['user_company_name'] = $user_company_extend_rt_v->user_company_name; $user['user_desc'] = $user_company_extend_rt_v->user_desc; $user['user_http'] = $user_company_extend_rt_v->user_http; $user['user_company_lat'] = $user_company_extend_rt_v->user_company_lat; $user['user_company_lng'] = $user_company_extend_rt_v->user_company_lng; } } } return $user_list; }
/** * 水地图列表 * @param $params * @return array */ public function mapList($params) { if ($params->get('longitude') && $params->get('latitude')) { // $squares = $this->returnSquarePoint($params->get('longitude'), $params->get('latitude'), $params->get('radius') ?: null); // $result = UserCompanyExtend::where('user_company_lat', '>', '0') // ->where('user_company_lat', '>=', $squares['right-bottom']['lat']) // ->where('user_company_lat', '<=', $squares['left-top']['lat']) // ->where('user_company_lng', '>=', $squares['left-top']['lng']) // ->where('user_company_lng', '<=', $squares['right-bottom']['lng']) // ->get(); $user_company_extend = new UserCompanyExtend(); $result = $user_company_extend->get(); if (empty($result)) { return ['status' => true, 'message' => '获取成功!', 'info' => []]; } $user_ids = []; foreach ($result as $result_val) { $user_ids[] = $result_val->user_id; } $user_images_result = UserImage::whereIn('user_id', $user_ids)->Head()->get(); $images = []; if (!empty($user_images_result)) { foreach ($user_images_result as $user_images_result_val) { $images[$user_images_result_val->user_id] = $user_images_result_val->path(); } } $user_financial_result = UserFinancial::whereIn('user_id', $user_ids)->get(); $financial = []; if (!empty($user_financial_result)) { foreach ($user_financial_result as $user_financial_result_val) { $financial[$user_financial_result_val->user_id] = $user_financial_result_val->water_count; } } $data = []; foreach ($result as $result_value) { $data[] = ['store_id' => $result_value->user_id, 'store_name' => $result_value->user_company_name, 'image_url' => isset($images[$result_value->user_id]) ? $images[$result_value->user_id] : '', 'left_num' => isset($financial[$result_value->user_id]) ? $financial[$result_value->user_id] : 0, 'latitude' => $result_value->user_company_lat, 'longitude' => $result_value->user_company_lng, 'distance' => $this->getDistance($params->get('latitude'), $params->get('longitude'), $result_value->user_company_lat, $result_value->user_company_lng)]; } return ['status' => true, 'msg' => 'success', 'info' => $data]; } else { return ['status' => false, 'message' => '缺少经纬度参数!', 'info' => []]; } }