toArray(); } } dd(...$args); } function path_to_url($path, $disk = 'public') { // 如果 image 字段本身就已经是完整的 url 就直接返回 if (\Illuminate\Support\Str::startsWith($path, ['http://', 'https://'])) { return $path; } return \Illuminate\Support\Facades\Storage::disk($disk)->url($path); } function api_route($name, $v = 'v1') { return app('Dingo\Api\Routing\UrlGenerator')->version($v)->route($name); } function f_money($money, $sed = ',') { return number_format($money, 2, '.', $sed); } function php2js($arr) { return json_encode($arr, true); } function js2php($json) { return json_decode($json, true); } function arr2option($arr) { return collect($arr)->map(function ($key, $val) { return [ 'label' => $key, 'value' => $val, 's_value' => (string)$val ]; })->values(); } function str2arr($str, $glue = ',') { return explode($glue, $str); } function arr2str($arr, $glue = ',') { return implode($glue, array_wrap($arr)); } function wechat_fee($money) { return bcmul($money, 100, 0); } /** * 通过身份证号获取年龄 * @param $id_card * @return bool|false|string * User: Mead */ function idCard2age($id_card) { $year = substr($id_card, 6, 4); $monthDay = substr($id_card, 10, 4); $age = date('Y') - $year; if ($monthDay > date('md')) { $age--; } return $age; } function now() { return date('Y-m-d H:i:s'); } /** * 计算两点地理坐标之间的距离 * @param float $longitude1 起点经度 * @param float $latitude1 起点纬度 * @param float $longitude2 终点经度 * @param float $latitude2 终点纬度 * @param Int $unit 单位 1:米 2:千米 * @param Int $decimal 精度 保留小数位数 * @return float|int */ function getDistance($longitude1, $latitude1, $longitude2, $latitude2, $unit = 2, $decimal = 2) { $EARTH_RADIUS = 6370.996; // 地球半径系数 $PI = 3.1415926; $radLat1 = $latitude1 * $PI / 180.0; $radLat2 = $latitude2 * $PI / 180.0; $radLng1 = $longitude1 * $PI / 180.0; $radLng2 = $longitude2 * $PI / 180.0; $a = $radLat1 - $radLat2; $b = $radLng1 - $radLng2; $distance = 2 * asin(sqrt(pow(sin($a / 2), 2) + cos($radLat1) * cos($radLat2) * pow(sin($b / 2), 2))); $distance = $distance * $EARTH_RADIUS * 1000; if ($unit == 2) { $distance = $distance / 1000; } $distance = round($distance, $decimal); return $distance; } /** * 手机号中间四位隐藏 * @param $mobile * @return mixed * User: Mead */ function mobile_hidden($mobile) { return substr_replace($mobile, '****', 3, 4); } function format_mileage($km) { if ($km >= 1) { return "{$km}km"; } else { $m = $km * 1000; return "{$m}m"; } } /** * 格式化分钟 * @param $min * @return string * User: Mead */ function format_minutes($min) { $hours = 0; if ($min >= 60) { $hours = floor($min / 60); } $minute = $min % 60; $str = ''; if ($hours) { $str .= "{$hours}小时"; } if ($minute) { $str .= "{$minute}分"; } return $str; } /** * 重新生成订单号 * @param $no * User: Mead */ function order_repeat($no) { $order = str2arr($no, '-')[0]; return $order . '-' . rand(1, 9); } function curl_get($url) { $curl = curl_init(); //设置抓取的url curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);//设置获取的信息以文件流的形式返回,而不是直接输出 $data = curl_exec($curl); //执行命令 curl_close($curl); //关闭URL请求 return js2php($data); } function makeNoTag($tag) { return config('bike.no_tag') . $tag; } function log_record($name, $data) { \Illuminate\Support\Facades\Log::error("==============>{$name}<=============="); \Illuminate\Support\Facades\Log::error($data); \Illuminate\Support\Facades\Log::error("<==============完结==============>"); }