|
@@ -17,13 +17,13 @@ use think\facade\Db;
|
|
|
define('AMAP_KEY', '937f431e40453c79c1c18af4a69c6b79');
|
|
|
|
|
|
|
|
|
-function page_result1($code=0, $msg='', $data=array())
|
|
|
+function page_result1($code = 0, $msg = '', $data = [])
|
|
|
{
|
|
|
- exit(json_encode(array(
|
|
|
- 'code' => $code,
|
|
|
- 'msg' => $msg,
|
|
|
- 'data' => $data
|
|
|
- )));
|
|
|
+ exit(json_encode([
|
|
|
+ 'code' => $code,
|
|
|
+ 'msg' => $msg,
|
|
|
+ 'data' => $data,
|
|
|
+ ]));
|
|
|
}
|
|
|
|
|
|
|
|
@@ -41,57 +41,57 @@ function page_result1($code=0, $msg='', $data=array())
|
|
|
function image_copy_image($bg_image, $sub_image, $add_x, $add_y, $add_w, $add_h, $out_image)
|
|
|
{
|
|
|
if ($sub_image) {
|
|
|
- $bg_image_c = imagecreatefromstring(file_get_contents($bg_image));
|
|
|
+ $bg_image_c = imagecreatefromstring(file_get_contents($bg_image));
|
|
|
$sub_image_c = imagecreatefromstring(file_get_contents($sub_image));
|
|
|
imagecopyresampled($bg_image_c, $sub_image_c, $add_x, $add_y, 0, 0, $add_w, $add_h, imagesx($sub_image_c), imagesy($sub_image_c));
|
|
|
//保存到out_image
|
|
|
imagejpeg($bg_image_c, $out_image, 80);
|
|
|
imagedestroy($sub_image_c);
|
|
|
imagedestroy($bg_image_c);
|
|
|
- return true;
|
|
|
+ return true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
-function image_copy_text($dst_path, $text, $font, $size, $picwith, $x, $y, $red, $grn, $blu){
|
|
|
- $dst = imagecreatefromstring(file_get_contents($dst_path));
|
|
|
- $arr = imagettfbbox($size,0,$font,$text);
|
|
|
- $text_width = $arr[2]-$arr[0];
|
|
|
- $x = $picwith==0 ? $x : intval(($picwith - $text_width)/2);
|
|
|
- //打上文字
|
|
|
- $black = imagecolorallocate($dst, $red, $grn, $blu);//字体颜色0x00, 0x00, 0x00
|
|
|
- imagefttext($dst, $size, 0, $x, $y, $black, $font, $text);
|
|
|
- //输出图片
|
|
|
- list($dst_w, $dst_h, $dst_type) = getimagesize($dst_path);
|
|
|
- switch ($dst_type) {
|
|
|
- case 1://GIF
|
|
|
- header('Content-Type: image/gif');
|
|
|
- imagegif($dst, $dst_path);
|
|
|
- break;
|
|
|
- case 2://JPG
|
|
|
- header('Content-Type: image/jpeg');
|
|
|
- imagejpeg($dst, $dst_path);
|
|
|
- break;
|
|
|
- case 3://PNG
|
|
|
- header('Content-Type: image/png');
|
|
|
- imagepng($dst, $dst_path);
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
- imagedestroy($dst);
|
|
|
+function image_copy_text($dst_path, $text, $font, $size, $picwith, $x, $y, $red, $grn, $blu)
|
|
|
+{
|
|
|
+ $dst = imagecreatefromstring(file_get_contents($dst_path));
|
|
|
+ $arr = imagettfbbox($size, 0, $font, $text);
|
|
|
+ $text_width = $arr[2] - $arr[0];
|
|
|
+ $x = $picwith == 0 ? $x : intval(($picwith - $text_width) / 2);
|
|
|
+ //打上文字
|
|
|
+ $black = imagecolorallocate($dst, $red, $grn, $blu);//字体颜色0x00, 0x00, 0x00
|
|
|
+ imagefttext($dst, $size, 0, $x, $y, $black, $font, $text);
|
|
|
+ //输出图片
|
|
|
+ list($dst_w, $dst_h, $dst_type) = getimagesize($dst_path);
|
|
|
+ switch ($dst_type) {
|
|
|
+ case 1://GIF
|
|
|
+ header('Content-Type: image/gif');
|
|
|
+ imagegif($dst, $dst_path);
|
|
|
+ break;
|
|
|
+ case 2://JPG
|
|
|
+ header('Content-Type: image/jpeg');
|
|
|
+ imagejpeg($dst, $dst_path);
|
|
|
+ break;
|
|
|
+ case 3://PNG
|
|
|
+ header('Content-Type: image/png');
|
|
|
+ imagepng($dst, $dst_path);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ imagedestroy($dst);
|
|
|
}
|
|
|
|
|
|
function subtext($text, $length)
|
|
|
{
|
|
|
- if(mb_strlen($text, 'utf8') > $length) {
|
|
|
- return mb_substr($text, 0, $length, 'utf8').'...';
|
|
|
+ if (mb_strlen($text, 'utf8') > $length) {
|
|
|
+ return mb_substr($text, 0, $length, 'utf8') . '...';
|
|
|
} else {
|
|
|
return $text;
|
|
|
}
|
|
|
-
|
|
|
-}
|
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -102,14 +102,14 @@ function subtext($text, $length)
|
|
|
*/
|
|
|
function export_excel($expTitle, $expCellName, $expTableData)
|
|
|
{
|
|
|
- $xlsTitle = iconv('utf-8', 'gb2312', $expTitle);//文件名称
|
|
|
- $fileName = $expTitle . date('_Ymd');//or $xlsTitle 文件名称可根据自己情况设定
|
|
|
- $cellNum = count($expCellName);
|
|
|
- $dataNum = count($expTableData);
|
|
|
+ $xlsTitle = iconv('utf-8', 'gb2312', $expTitle);//文件名称
|
|
|
+ $fileName = $expTitle . date('_Ymd');//or $xlsTitle 文件名称可根据自己情况设定
|
|
|
+ $cellNum = count($expCellName);
|
|
|
+ $dataNum = count($expTableData);
|
|
|
$objPHPExcel = new PHPExcel();//方法一
|
|
|
- $cellName = array('A','B', 'C','D', 'E', 'F','G','H','I', 'J', 'K','L','M', 'N', 'O', 'P', 'Q','R','S', 'T','U','V', 'W', 'X','Y', 'Z', 'AA',
|
|
|
- 'AB', 'AC','AD','AE', 'AF','AG','AH','AI', 'AJ', 'AK', 'AL','AM','AN','AO','AP','AQ','AR', 'AS', 'AT','AU', 'AV','AW', 'AX',
|
|
|
- 'AY', 'AZ');
|
|
|
+ $cellName = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'AA',
|
|
|
+ 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ', 'AK', 'AL', 'AM', 'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX',
|
|
|
+ 'AY', 'AZ'];
|
|
|
//设置头部导出时间备注
|
|
|
$objPHPExcel->getActiveSheet(0)->mergeCells('A1:' . $cellName[$cellNum - 1] . '1');//合并单元格
|
|
|
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', $expTitle . ' 导出时间:' . date('Y-m-d H:i:s'));
|
|
@@ -121,8 +121,8 @@ function export_excel($expTitle, $expCellName, $expTableData)
|
|
|
for ($i = 0; $i < $dataNum; $i++) {
|
|
|
for ($j = 0; $j < $cellNum; $j++) {
|
|
|
$keyarr = explode(".", $expCellName[$j][0]);
|
|
|
- $value = $expTableData[$i];
|
|
|
- foreach ($keyarr as $k=>$v) {
|
|
|
+ $value = $expTableData[$i];
|
|
|
+ foreach ($keyarr as $k => $v) {
|
|
|
$value = $value[$v];
|
|
|
}
|
|
|
if (!empty($expCellName[$j][2])) {
|
|
@@ -155,7 +155,7 @@ function read_excel($filename)
|
|
|
{
|
|
|
//设置excel格式
|
|
|
$ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
|
|
|
- if ($ext=='xlsx') {
|
|
|
+ if ($ext == 'xlsx') {
|
|
|
$reader = PHPExcel_IOFactory::createReader('Excel2007');
|
|
|
} else {
|
|
|
$reader = PHPExcel_IOFactory::createReader('Excel5');
|
|
@@ -168,20 +168,21 @@ function read_excel($filename)
|
|
|
$row_num = $sheet->getHighestRow();
|
|
|
//获取总列数
|
|
|
$col_num = $sheet->getHighestColumn();
|
|
|
- $data = []; //数组形式获取表格数据
|
|
|
- for ($col='A';$col<=$col_num;$col++) {
|
|
|
+ $data = []; //数组形式获取表格数据
|
|
|
+ for ($col = 'A'; $col <= $col_num; $col++) {
|
|
|
//从第二行开始,去除表头(若无表头则从第一行开始)
|
|
|
- for ($row=2;$row<=$row_num;$row++) {
|
|
|
- $data[$row-2][] = $sheet->getCell($col.$row)->getValue();
|
|
|
+ for ($row = 2; $row <= $row_num; $row++) {
|
|
|
+ $data[$row - 2][] = $sheet->getCell($col . $row)->getValue();
|
|
|
}
|
|
|
}
|
|
|
return $data;
|
|
|
}
|
|
|
|
|
|
//二维数组去重
|
|
|
-function assoc_unique($arr, $key) {
|
|
|
+function assoc_unique($arr, $key)
|
|
|
+{
|
|
|
|
|
|
- $tmp_arr = array();
|
|
|
+ $tmp_arr = [];
|
|
|
|
|
|
foreach ($arr as $k => $v) {
|
|
|
|
|
@@ -209,87 +210,87 @@ function assoc_unique($arr, $key) {
|
|
|
*/
|
|
|
function aliyun_ocr_idcard($file)
|
|
|
{
|
|
|
- $url = "https://dm-51.data.aliyun.com/rest/160601/ocr/ocr_idcard.json";
|
|
|
+ $url = "https://dm-51.data.aliyun.com/rest/160601/ocr/ocr_idcard.json";
|
|
|
$appcode = config('wxconfig.aliAppCode');
|
|
|
// $file = "你的文件路径";
|
|
|
//如果输入带有inputs, 设置为True,否则设为False
|
|
|
$is_old_format = false;
|
|
|
//如果没有configure字段,config设为空
|
|
|
- $config = array(
|
|
|
- "side" => "face"
|
|
|
- );
|
|
|
+ $config = [
|
|
|
+ "side" => "face",
|
|
|
+ ];
|
|
|
//$config = array()
|
|
|
if ($fp = fopen($file, "rb", 0)) {
|
|
|
$binary = fread($fp, filesize($file)); // 文件读取
|
|
|
fclose($fp);
|
|
|
$base64 = base64_encode($binary); // 转码
|
|
|
}
|
|
|
- $headers = array();
|
|
|
+ $headers = [];
|
|
|
array_push($headers, "Authorization:APPCODE " . $appcode);
|
|
|
//根据API的要求,定义相对应的Content-Type
|
|
|
- array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");
|
|
|
+ array_push($headers, "Content-Type" . ":" . "application/json; charset=UTF-8");
|
|
|
$querys = "";
|
|
|
if ($is_old_format == true) {
|
|
|
- $request = array();
|
|
|
- $request["image"] = array(
|
|
|
- "dataType" => 50,
|
|
|
- "dataValue" => "$base64"
|
|
|
- );
|
|
|
+ $request = [];
|
|
|
+ $request["image"] = [
|
|
|
+ "dataType" => 50,
|
|
|
+ "dataValue" => "$base64",
|
|
|
+ ];
|
|
|
|
|
|
if (count($config) > 0) {
|
|
|
- $request["configure"] = array(
|
|
|
- "dataType" => 50,
|
|
|
- "dataValue" => json_encode($config)
|
|
|
- );
|
|
|
+ $request["configure"] = [
|
|
|
+ "dataType" => 50,
|
|
|
+ "dataValue" => json_encode($config),
|
|
|
+ ];
|
|
|
}
|
|
|
- $body = json_encode(array("inputs" => array($request)));
|
|
|
+ $body = json_encode(["inputs" => [$request]]);
|
|
|
} else {
|
|
|
- $request = array(
|
|
|
- "image" => "$base64"
|
|
|
- );
|
|
|
+ $request = [
|
|
|
+ "image" => "$base64",
|
|
|
+ ];
|
|
|
if (count($config) > 0) {
|
|
|
$request["configure"] = json_encode($config);
|
|
|
}
|
|
|
$body = json_encode($request);
|
|
|
}
|
|
|
$method = "POST";
|
|
|
- $curl = curl_init();
|
|
|
+ $curl = curl_init();
|
|
|
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
|
|
|
curl_setopt($curl, CURLOPT_URL, $url);
|
|
|
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
|
|
curl_setopt($curl, CURLOPT_FAILONERROR, false);
|
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
|
|
curl_setopt($curl, CURLOPT_HEADER, true);
|
|
|
- if (1 == strpos("$".$url, "https://")) {
|
|
|
+ if (1 == strpos("$" . $url, "https://")) {
|
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
|
|
}
|
|
|
curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
|
|
|
- $result = curl_exec($curl);
|
|
|
+ $result = curl_exec($curl);
|
|
|
$header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
|
|
|
- $rheader = substr($result, 0, $header_size);
|
|
|
- $rbody = substr($result, $header_size);
|
|
|
- $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
|
|
+ $rheader = substr($result, 0, $header_size);
|
|
|
+ $rbody = substr($result, $header_size);
|
|
|
+ $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
|
|
if ($httpCode == 200) {
|
|
|
if ($is_old_format) {
|
|
|
- $output = json_decode($rbody, true);
|
|
|
+ $output = json_decode($rbody, true);
|
|
|
$result_str = $output["outputs"][0]["outputValue"]["dataValue"];
|
|
|
} else {
|
|
|
$result_str = $rbody;
|
|
|
}
|
|
|
$result_arr = json_decode($result_str, true);
|
|
|
- if ($result_arr['success']==false) {
|
|
|
+ if ($result_arr['success'] == false) {
|
|
|
return false;
|
|
|
} else {
|
|
|
- return array(
|
|
|
- "name" => $result_arr['name'],
|
|
|
- "nationality" => $result_arr['nationality'],
|
|
|
- "num" => $result_arr['num'],
|
|
|
- "sex" => $result_arr['sex'],
|
|
|
- "birth" => date('Y-m-d', strtotime($result_arr['birth'])),
|
|
|
- "nationality" => $result_arr['nationality'],
|
|
|
- "address" => $result_arr['address']
|
|
|
- );
|
|
|
+ return [
|
|
|
+ "name" => $result_arr['name'],
|
|
|
+ "nationality" => $result_arr['nationality'],
|
|
|
+ "num" => $result_arr['num'],
|
|
|
+ "sex" => $result_arr['sex'],
|
|
|
+ "birth" => date('Y-m-d', strtotime($result_arr['birth'])),
|
|
|
+ "nationality" => $result_arr['nationality'],
|
|
|
+ "address" => $result_arr['address'],
|
|
|
+ ];
|
|
|
}
|
|
|
return $result_str;
|
|
|
} else {
|
|
@@ -298,16 +299,15 @@ function aliyun_ocr_idcard($file)
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
// 两个日期间数组
|
|
|
function periodDate($start_time, $end_time)
|
|
|
{
|
|
|
$start_time = strtotime($start_time);
|
|
|
- $end_time = strtotime($end_time);
|
|
|
- $i=0;
|
|
|
- while ($start_time<=$end_time) {
|
|
|
+ $end_time = strtotime($end_time);
|
|
|
+ $i = 0;
|
|
|
+ while ($start_time <= $end_time) {
|
|
|
$arr[date('Y-m-d', $start_time)] = 0;
|
|
|
- $start_time = strtotime('+1 day', $start_time);
|
|
|
+ $start_time = strtotime('+1 day', $start_time);
|
|
|
$i++;
|
|
|
}
|
|
|
return $arr;
|
|
@@ -316,15 +316,15 @@ function periodDate($start_time, $end_time)
|
|
|
// 数组键值分开
|
|
|
function arrKeyVal($arr)
|
|
|
{
|
|
|
- $keyArr = array();
|
|
|
- $valArr = array();
|
|
|
+ $keyArr = [];
|
|
|
+ $valArr = [];
|
|
|
if (!empty($arr)) {
|
|
|
- foreach ($arr as $k=>$v) {
|
|
|
+ foreach ($arr as $k => $v) {
|
|
|
$keyArr[] = $k;
|
|
|
$valArr[] = $v;
|
|
|
}
|
|
|
}
|
|
|
- return array('keyarr'=>$keyArr, 'valarr'=>$valArr);
|
|
|
+ return ['keyarr' => $keyArr, 'valarr' => $valArr];
|
|
|
}
|
|
|
|
|
|
//获取ip
|
|
@@ -347,24 +347,23 @@ function arrKeyVal($arr)
|
|
|
function is_released($workerid)
|
|
|
{
|
|
|
$comjobs_count = Db::name('comjobs')
|
|
|
- ->where('workerid',$workerid)
|
|
|
- ->count();
|
|
|
+ ->where('workerid', $workerid)
|
|
|
+ ->count();
|
|
|
|
|
|
$demand_count = Db::name("demand")
|
|
|
- ->where('workerid',$workerid)
|
|
|
- ->count();
|
|
|
+ ->where('workerid', $workerid)
|
|
|
+ ->count();
|
|
|
|
|
|
$supply_data = Db::name("supply")
|
|
|
- ->where('workerid',$workerid)
|
|
|
- ->count();
|
|
|
+ ->where('workerid', $workerid)
|
|
|
+ ->count();
|
|
|
|
|
|
$count = $comjobs_count + $demand_count + $supply_data;
|
|
|
- if($count >= 3)
|
|
|
- {
|
|
|
+ if ($count >= 3) {
|
|
|
$rtn['code'] = 1001;
|
|
|
- $rtn['msg'] = "您的审核还未通过,最多只能发3条信息";
|
|
|
+ $rtn['msg'] = "您的审核还未通过,最多只能发3条信息";
|
|
|
return $rtn;
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
|
|
|
$rtn['code'] = 0;
|
|
|
// $rtn['code'] = 1001;
|
|
@@ -382,33 +381,34 @@ function is_released($workerid)
|
|
|
* @return Array 范围数组
|
|
|
*/
|
|
|
|
|
|
-function calcScope($lat, $lng, $radius) {
|
|
|
- $degree = (24901*1609)/360.0;
|
|
|
- $dpmLat = 1/$degree;
|
|
|
- $radiusLat = $dpmLat*$radius;
|
|
|
- $minLat = $lat - $radiusLat; // 最小纬度
|
|
|
- $maxLat = $lat + $radiusLat; // 最大纬度
|
|
|
- $mpdLng = $degree*cos($lat * (PI/180));
|
|
|
- $dpmLng = 1 / $mpdLng;
|
|
|
- $radiusLng = $dpmLng*$radius;
|
|
|
- $minLng = $lng - $radiusLng; // 最小经度
|
|
|
- $maxLng = $lng + $radiusLng; // 最大经度
|
|
|
+function calcScope($lat, $lng, $radius)
|
|
|
+{
|
|
|
+ $degree = (24901 * 1609) / 360.0;
|
|
|
+ $dpmLat = 1 / $degree;
|
|
|
+ $radiusLat = $dpmLat * $radius;
|
|
|
+ $minLat = $lat - $radiusLat; // 最小纬度
|
|
|
+ $maxLat = $lat + $radiusLat; // 最大纬度
|
|
|
+ $mpdLng = $degree * cos($lat * (PI / 180));
|
|
|
+ $dpmLng = 1 / $mpdLng;
|
|
|
+ $radiusLng = $dpmLng * $radius;
|
|
|
+ $minLng = $lng - $radiusLng; // 最小经度
|
|
|
+ $maxLng = $lng + $radiusLng; // 最大经度
|
|
|
|
|
|
/** 返回范围数组 */
|
|
|
- $scope = array(
|
|
|
- 'minLat' => $minLat,
|
|
|
- 'maxLat' => $maxLat,
|
|
|
- 'minLng' => $minLng,
|
|
|
- 'maxLng' => $maxLng
|
|
|
- );
|
|
|
+ $scope = [
|
|
|
+ 'minLat' => $minLat,
|
|
|
+ 'maxLat' => $maxLat,
|
|
|
+ 'minLng' => $minLng,
|
|
|
+ 'maxLng' => $maxLng,
|
|
|
+ ];
|
|
|
return $scope;
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据经纬度和半径查询在此范围内的所有的对象
|
|
|
- * @param String $lat 纬度
|
|
|
- * @param String $lng 经度
|
|
|
+ * @param String $lat 纬度
|
|
|
+ * @param String $lng 经度
|
|
|
* @param float $radius 半径
|
|
|
* @return Array 计算出来的结果
|
|
|
*/
|
|
@@ -431,7 +431,8 @@ function calcScope($lat, $lng, $radius) {
|
|
|
* @return float 返回两点之间的距离
|
|
|
*/
|
|
|
|
|
|
-function calcDistance($lat1, $lng1, $lat2, $lng2) {
|
|
|
+function calcDistance($lat1, $lng1, $lat2, $lng2)
|
|
|
+{
|
|
|
/** 转换数据类型为 double */
|
|
|
$lat1 = doubleval($lat1);
|
|
|
$lng1 = doubleval($lng1);
|
|
@@ -439,15 +440,15 @@ function calcDistance($lat1, $lng1, $lat2, $lng2) {
|
|
|
$lng2 = doubleval($lng2);
|
|
|
/** 以下算法是 Google 出来的,与大多数经纬度计算工具结果一致 */
|
|
|
$theta = $lng1 - $lng2;
|
|
|
- $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
|
|
|
- $dist = acos($dist);
|
|
|
- $dist = rad2deg($dist);
|
|
|
+ $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
|
|
|
+ $dist = acos($dist);
|
|
|
+ $dist = rad2deg($dist);
|
|
|
$miles = $dist * 60 * 1.1515;
|
|
|
return ($miles * 1.609344);
|
|
|
}
|
|
|
|
|
|
//$lon1 用户当前经度 $lat1用户当前纬度 $lon2数据库经度的字段名 $lat2数据库纬度的字段名
|
|
|
-function distance_sql($lon1='116.434164',$lat1='39.909843',$lon2='longitude',$lat2='latitude')
|
|
|
+function distance_sql($lon1 = '116.434164', $lat1 = '39.909843', $lon2 = 'longitude', $lat2 = 'latitude')
|
|
|
{
|
|
|
$sql = "round(6378.138*2*asin(sqrt(pow(sin( ({$lat1}*pi()/180-{$lat2}*pi()/180)/2),2)+cos({$lat1}*pi()/180)*cos({$lat2}*pi()/180)* pow(sin( ({$lon1}*pi()/180-{$lon2}*pi()/180)/2),2)))*1000) ";
|
|
|
return $sql;
|
|
@@ -495,8 +496,63 @@ function http_request($url, $method = "GET", $postfields = null, $headers = [])
|
|
|
curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);
|
|
|
curl_setopt($ci, CURLINFO_HEADER_OUT, true);
|
|
|
/* curl_setopt($ci, CURLOPT_COOKIE, $Cookiestr); * *COOKIE带过去** */
|
|
|
- $response = curl_exec($ci);
|
|
|
+ $response = curl_exec($ci);
|
|
|
|
|
|
curl_close($ci);
|
|
|
return $response;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 数据导入
|
|
|
+ * @param string $file excel文件
|
|
|
+ * @param string $crop
|
|
|
+ * @param string $sheet
|
|
|
+ * @return string 返回解析数据
|
|
|
+ * @throws PHPExcel_Exception
|
|
|
+ * @throws PHPExcel_Reader_Exception
|
|
|
+ */
|
|
|
+
|
|
|
+function importExecl($file = '', $cell = [], $crop = 0, $sheet = 0)
|
|
|
+{
|
|
|
+ $file = iconv("utf-8", "gb2312", $file); //转码
|
|
|
+ if (empty($file) OR !file_exists($file)) {
|
|
|
+ die('file not exists!');
|
|
|
+ }
|
|
|
+
|
|
|
+ $objRead = new PHPExcel_Reader_Excel2007(); //建立reader对象
|
|
|
+ if (!$objRead->canRead($file)) {
|
|
|
+ $objRead = new PHPExcel_Reader_Excel5();
|
|
|
+ if (!$objRead->canRead($file)) {
|
|
|
+ die('No Excel!');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $cellName = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ', 'AK', 'AL', 'AM', 'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX', 'AY', 'AZ'];
|
|
|
+ $obj = $objRead->load($file); //建立excel对象
|
|
|
+ $currSheet = $obj->getSheet($sheet); //获取指定的sheet表
|
|
|
+ $columnH = $currSheet->getHighestColumn(); //取得最大的列号
|
|
|
+ $columnCnt = array_search($columnH, $cellName);
|
|
|
+ $rowCnt = $currSheet->getHighestRow(); //获取总行数
|
|
|
+
|
|
|
+ $data = [];
|
|
|
+ for ($_row = 1; $_row <= $rowCnt; $_row++) { //读取内容
|
|
|
+ if ($_row > $crop) {
|
|
|
+ for ($_column = 0; $_column <= $columnCnt; $_column++) {
|
|
|
+ $cellId = $cellName[$_column] . $_row;
|
|
|
+ $cellValue = $currSheet->getCell($cellId)->getValue();
|
|
|
+ //$cellValue = $currSheet->getCell($cellId)->getCalculatedValue(); #获取公式计算的值
|
|
|
+ if ($cellValue instanceof PHPExcel_RichText) { //富文本转换字符串
|
|
|
+ $cellValue = $cellValue->__toString();
|
|
|
+ }
|
|
|
+ if (!empty($cell[$_column])) {
|
|
|
+ $data[$_row][$cell[$_column]] = $cellValue;
|
|
|
+ } else {
|
|
|
+ $data[$_row][] = $cellValue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return array_values($data);
|
|
|
+
|
|
|
}
|