$start_time, "end_date" => $end_time ]; switch ($company['company_type']) { case 18: $parmas['brigade_id'] = $company['responsible_area']; $parmas['village_code'] = $company['village']; $parmas['street_code'] = $company['street']; $parmas['district_code'] = $company['area']; $parmas['city_code'] = $company['city']; break; case 17: $parmas['village_code'] = $company['responsible_area']; $parmas['street_code'] = $company['street']; $parmas['district_code'] = $company['area']; $parmas['city_code'] = $company['city']; break; case 16: $parmas['street_code'] = $company['responsible_area']; $parmas['district_code'] = $company['area']; $parmas['city_code'] = $company['city']; break; case 15: $parmas['district_code'] = $company['area']; $parmas['city_code'] = $company['city']; break; case 14: $parmas['city_code'] = $company['city']; break; default: Log::error('任务结算失败,公司类型错误:' . $company['company_type']); Log::error('片区交易错误:' . $company); return false; } try { $res = HttpClient::create()->request('GET', env('url.shop_prefix') . '/api/order/statistics', [ 'query' => $parmas, ]); $json = json_decode($res->getContent(), true); $arr['total_price'] = 0; $arr['status'] = 0; $arr['day_money'] = 0; $name = '片区交易'; if ($json['status'] == 200) { $arr['total_price'] = $json['data']['total_price']; //基础金额*(每日基户数*天数)//且户数小于公司总户数 $user_count = UserInformationg::where('company_id', $company['id'])->count(); $day_count = TaskTemplate::where('id', $template_id)->value('day_count'); // if ($day_count == 0) { $user_count_two = 5 * 1; } else { $user_count_two = 5 * $day_count; } if ($user_count_two > $user_count) { $user_count_money = 58 * $user_count; } else { $user_count_money = 58 * $user_count_two; } if ($json['data']['total_price'] > $user_count_money) { $arr['status'] = 1; $name = '片区交易'; } $arr['day_money'] = $user_count_money; } else { Log::error('获取订单金额失败:' . $json . '参数:' . json_encode($parmas)); } return ['name' => $name, 'arr' => $arr]; } catch (\Exception $e) { Log::error('获取订单金额失败:' . $e->getMessage() . '参数:' . json_encode($parmas)); return false; } } public function shang_date_list($company, $querys) { $start_time = date('Y-m-d'); $time = strtotime($start_time) + 86399; $end_time = date('Y-m-d H:i:s', $time); if (isset($querys['start_time']) && isset($querys['end_time'])) { $start_time = $querys['start_time']; $end_time = $querys['end_time']; } $parmas = [ "start_date" => $start_time, "end_date" => $end_time ]; switch ($company['company_type']) { case 18: $parmas['brigade_id'] = $company['responsible_area']; $parmas['village_code'] = $company['village']; $parmas['street_code'] = $company['street']; $parmas['district_code'] = $company['area']; $parmas['city_code'] = $company['city']; break; case 17: $parmas['village_code'] = $company['responsible_area']; $parmas['street_code'] = $company['street']; $parmas['district_code'] = $company['area']; $parmas['city_code'] = $company['city']; break; case 16: $parmas['street_code'] = $company['responsible_area']; $parmas['district_code'] = $company['area']; $parmas['city_code'] = $company['city']; break; case 15: $parmas['district_code'] = $company['area']; $parmas['city_code'] = $company['city']; break; case 14: $parmas['city_code'] = $company['city']; break; default: return false; } if (isset($querys['page'])) { $parmas['page'] = $querys['page']; } try { $list = HttpClient::create()->request('GET', env('url.shop_prefix') . '/api/region/order', [ 'query' => $parmas, ]); $json_list = json_decode($list->getContent(), true); $data = []; if ($json_list['status'] == 200) { $data = $json_list['data']['list']; } return $data; } catch (\Exception $e) { return false; } } /** * * 获取坐标的距离 */ public function coordinate($parmas, $longitude1, $latitude1) { $res = HttpClient::create()->request('GET', env('project.logistic_domain') . '/api/getCarHistory', [ 'query' => $parmas, ]); $json = json_decode($res->getContent(), true); $points = $json['data']; if (empty($points)) { return false; } $target = [ "lat" => $latitude1, "lon" => $longitude1 ]; $closestPoint = $this->getClosestPoint($points, $target); return $this->calculateDistance($target['lon'], $target['lat'], $closestPoint[0]['lon'], $closestPoint[0]['lat']); } /** * * 计算两点之间的距离 */ function getClosestPoint($points, $target) { $minDistance = PHP_INT_MAX; $closestPoint = null; foreach ($points as $point) { // halt($point,$target); $distance = sqrt(pow(($point['lat'] - $target['lat']), 2) + pow(($point['lon'] - $target['lon']), 2)); if ($distance < $minDistance) { $minDistance = $distance; $closestPoint = $point; } else { $distance = 0; } } return [$closestPoint, $distance]; } /** * * 计算两点之间的距离 * 返回米 */ function calculateDistance($longitude1, $latitude1, $longitude2, $latitude2) { $earthRadius = 6371; // 地球半径,单位为公里 $dLat = deg2rad($latitude2 - $latitude1); $dLon = deg2rad($longitude2 - $longitude1); $a = sin($dLat / 2) * sin($dLat / 2) + cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * sin($dLon / 2) * sin($dLon / 2); $c = 2 * asin(sqrt($a)); return round($earthRadius * $c*1000) ; } }