common.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: 流年 <liu21st@gmail.com>
  10. // +----------------------------------------------------------------------
  11. // 应用公共文件
  12. use think\facade\Db;
  13. // 高德地图Key
  14. define('AMAP_KEY', '937f431e40453c79c1c18af4a69c6b79');
  15. function array_get($array, $key, $default = null)
  16. {
  17. return isset($array[$key]) ? $array[$key] : $default;
  18. }
  19. function page_result1($code = 0, $msg = '', $data = [])
  20. {
  21. exit(json_encode([
  22. 'code' => $code,
  23. 'msg' => $msg,
  24. 'data' => $data,
  25. ]));
  26. }
  27. function url(string $url = '', array $vars = [], $suffix = true, $domain = true)
  28. {
  29. return \think\facade\Route::buildUrl($url, $vars)->suffix($suffix)->domain($domain);
  30. }
  31. /**
  32. * a.合成图片信息 复制一张图片的矩形区域到另外一张图片的矩形区域
  33. * @param [type] $bg_image [目标图]
  34. * @param [type] $sub_image [被添加图]
  35. * @param [type] $add_x [目标图x坐标位置]
  36. * @param [type] $add_y [目标图y坐标位置]
  37. * @param [type] $add_w [目标图宽度区域]
  38. * @param [type] $add_h [目标图高度区域]
  39. * @param [type] $out_image [输出图路径]
  40. * @return [type] [description]
  41. */
  42. function image_copy_image($bg_image, $sub_image, $add_x, $add_y, $add_w, $add_h, $out_image)
  43. {
  44. if ($sub_image) {
  45. $bg_image_c = imagecreatefromstring(file_get_contents($bg_image));
  46. $sub_image_c = imagecreatefromstring(file_get_contents($sub_image));
  47. 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));
  48. //保存到out_image
  49. imagejpeg($bg_image_c, $out_image, 80);
  50. imagedestroy($sub_image_c);
  51. imagedestroy($bg_image_c);
  52. return true;
  53. }
  54. }
  55. function image_copy_text($dst_path, $text, $font, $size, $picwith, $x, $y, $red, $grn, $blu)
  56. {
  57. $dst = imagecreatefromstring(file_get_contents($dst_path));
  58. $arr = imagettfbbox($size, 0, $font, $text);
  59. $text_width = $arr[2] - $arr[0];
  60. $x = $picwith == 0 ? $x : intval(($picwith - $text_width) / 2);
  61. //打上文字
  62. $black = imagecolorallocate($dst, $red, $grn, $blu);//字体颜色0x00, 0x00, 0x00
  63. imagefttext($dst, $size, 0, $x, $y, $black, $font, $text);
  64. //输出图片
  65. list($dst_w, $dst_h, $dst_type) = getimagesize($dst_path);
  66. switch ($dst_type) {
  67. case 1://GIF
  68. header('Content-Type: image/gif');
  69. imagegif($dst, $dst_path);
  70. break;
  71. case 2://JPG
  72. header('Content-Type: image/jpeg');
  73. imagejpeg($dst, $dst_path);
  74. break;
  75. case 3://PNG
  76. header('Content-Type: image/png');
  77. imagepng($dst, $dst_path);
  78. break;
  79. default:
  80. break;
  81. }
  82. imagedestroy($dst);
  83. }
  84. function subtext($text, $length)
  85. {
  86. if (mb_strlen($text, 'utf8') > $length) {
  87. return mb_substr($text, 0, $length, 'utf8') . '...';
  88. } else {
  89. return $text;
  90. }
  91. }
  92. /**
  93. * 公共数据导出实现功能
  94. * @param $expTitle 导出文件名
  95. * @param $expCellName 导出文件列名称
  96. * @param $expTableData 导出数据
  97. */
  98. function export_excel($expTitle, $expCellName, $expTableData)
  99. {
  100. $xlsTitle = iconv('utf-8', 'gb2312', $expTitle);//文件名称
  101. $fileName = $expTitle . date('_Ymd');//or $xlsTitle 文件名称可根据自己情况设定
  102. $cellNum = count($expCellName);
  103. $dataNum = count($expTableData);
  104. $objPHPExcel = new PHPExcel();//方法一
  105. $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',
  106. 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ', 'AK', 'AL', 'AM', 'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX',
  107. 'AY', 'AZ', 'BA', 'BB', 'BC', 'BD', 'BE', 'BF', 'BG', 'BH', 'BI', 'BJ', 'BK', 'BL', 'BM', 'BN'];
  108. //设置头部导出时间备注
  109. $objPHPExcel->getActiveSheet(0)->mergeCells('A1:' . $cellName[$cellNum - 1] . '1');//合并单元格
  110. $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', $expTitle . ' 导出时间:' . date('Y-m-d H:i:s'));
  111. //设置列名称
  112. for ($i = 0; $i < $cellNum; $i++) {
  113. $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cellName[$i] . '2', $expCellName[$i][1]);
  114. }
  115. //赋值
  116. for ($i = 0; $i < $dataNum; $i++) {
  117. for ($j = 0; $j < $cellNum; $j++) {
  118. $keyarr = explode(".", $expCellName[$j][0]);
  119. $value = $expTableData[$i];
  120. foreach ($keyarr as $k => $v) {
  121. $value = $value[$v];
  122. }
  123. if (!empty($expCellName[$j][2])) {
  124. $value = $expCellName[$j][2][$value];
  125. }
  126. $objPHPExcel->getActiveSheet(0)->setCellValueExplicit(
  127. $cellName[$j] . ($i + 3),
  128. $value,
  129. PHPExcel_Cell_DataType::TYPE_STRING
  130. );
  131. }
  132. }
  133. ob_end_clean();//这一步非常关键,用来清除缓冲区防止导出的excel乱码
  134. header('pragma:public');
  135. header('Content-type:application/vnd.ms-excel;charset=utf-8;name="' . $xlsTitle . '.xls"');
  136. header("Content-Disposition:attachment;filename=$fileName.xls");//"xls"参考下一条备注
  137. $objWriter = \PHPExcel_IOFactory::createWriter(
  138. $objPHPExcel,
  139. 'Excel2007'
  140. );//"Excel2007"生成2007版本的xlsx,"Excel5"生成2003版本的xls
  141. $objWriter->save('php://output');
  142. }
  143. /**
  144. * excel表格读取
  145. * @param string $filename 文件路劲
  146. */
  147. function read_excel($filename)
  148. {
  149. //设置excel格式
  150. $ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
  151. if ($ext == 'xlsx') {
  152. $reader = PHPExcel_IOFactory::createReader('Excel2007');
  153. } else {
  154. $reader = PHPExcel_IOFactory::createReader('Excel5');
  155. }
  156. //载入excel文件
  157. $excel = $reader->load($filename);
  158. //读取第一张表
  159. $sheet = $excel->getSheet(0);
  160. //获取总行数
  161. $row_num = $sheet->getHighestRow();
  162. //获取总列数
  163. $col_num = $sheet->getHighestColumn();
  164. $data = []; //数组形式获取表格数据
  165. for ($col = 'A'; $col <= $col_num; $col++) {
  166. //从第二行开始,去除表头(若无表头则从第一行开始)
  167. for ($row = 2; $row <= $row_num; $row++) {
  168. $data[$row - 2][] = $sheet->getCell($col . $row)->getValue();
  169. }
  170. }
  171. return $data;
  172. }
  173. //二维数组去重
  174. function assoc_unique($arr, $key)
  175. {
  176. $tmp_arr = [];
  177. foreach ($arr as $k => $v) {
  178. if (in_array($v[$key], $tmp_arr)) {//搜索$v[$key]是否在$tmp_arr数组中存在,若存在返回true
  179. unset($arr[$k]);
  180. } else {
  181. $tmp_arr[] = $v[$key];
  182. }
  183. }
  184. sort($arr); //sort函数对数组进行排序
  185. return $arr;
  186. }
  187. /**
  188. * 阿里云身份证信息识别
  189. */
  190. function aliyun_ocr_idcard($file)
  191. {
  192. $url = "https://dm-51.data.aliyun.com/rest/160601/ocr/ocr_idcard.json";
  193. $appcode = config('wxconfig.aliAppCode');
  194. // $file = "你的文件路径";
  195. //如果输入带有inputs, 设置为True,否则设为False
  196. $is_old_format = false;
  197. //如果没有configure字段,config设为空
  198. $config = [
  199. "side" => "face",
  200. ];
  201. //$config = array()
  202. if ($fp = fopen($file, "rb", 0)) {
  203. $binary = fread($fp, filesize($file)); // 文件读取
  204. fclose($fp);
  205. $base64 = base64_encode($binary); // 转码
  206. }
  207. $headers = [];
  208. array_push($headers, "Authorization:APPCODE " . $appcode);
  209. //根据API的要求,定义相对应的Content-Type
  210. array_push($headers, "Content-Type" . ":" . "application/json; charset=UTF-8");
  211. $querys = "";
  212. if ($is_old_format == true) {
  213. $request = [];
  214. $request["image"] = [
  215. "dataType" => 50,
  216. "dataValue" => "$base64",
  217. ];
  218. if (count($config) > 0) {
  219. $request["configure"] = [
  220. "dataType" => 50,
  221. "dataValue" => json_encode($config),
  222. ];
  223. }
  224. $body = json_encode(["inputs" => [$request]]);
  225. } else {
  226. $request = [
  227. "image" => "$base64",
  228. ];
  229. if (count($config) > 0) {
  230. $request["configure"] = json_encode($config);
  231. }
  232. $body = json_encode($request);
  233. }
  234. $method = "POST";
  235. $curl = curl_init();
  236. curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
  237. curl_setopt($curl, CURLOPT_URL, $url);
  238. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  239. curl_setopt($curl, CURLOPT_FAILONERROR, false);
  240. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  241. curl_setopt($curl, CURLOPT_HEADER, true);
  242. if (1 == strpos("$" . $url, "https://")) {
  243. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  244. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  245. }
  246. curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
  247. $result = curl_exec($curl);
  248. $header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
  249. $rheader = substr($result, 0, $header_size);
  250. $rbody = substr($result, $header_size);
  251. $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
  252. if ($httpCode == 200) {
  253. if ($is_old_format) {
  254. $output = json_decode($rbody, true);
  255. $result_str = $output["outputs"][0]["outputValue"]["dataValue"];
  256. } else {
  257. $result_str = $rbody;
  258. }
  259. $result_arr = json_decode($result_str, true);
  260. if ($result_arr['success'] == false) {
  261. return false;
  262. } else {
  263. return [
  264. "name" => $result_arr['name'],
  265. "nationality" => $result_arr['nationality'],
  266. "num" => $result_arr['num'],
  267. "sex" => $result_arr['sex'],
  268. "birth" => date('Y-m-d', strtotime($result_arr['birth'])),
  269. "nationality" => $result_arr['nationality'],
  270. "address" => $result_arr['address'],
  271. ];
  272. }
  273. return $result_str;
  274. } else {
  275. return false;
  276. }
  277. }
  278. // 两个日期间数组
  279. function periodDate($start_time, $end_time)
  280. {
  281. $start_time = strtotime($start_time);
  282. $end_time = strtotime($end_time);
  283. $i = 0;
  284. while ($start_time <= $end_time) {
  285. $arr[date('Y-m-d', $start_time)] = 0;
  286. $start_time = strtotime('+1 day', $start_time);
  287. $i++;
  288. }
  289. return $arr;
  290. }
  291. // 数组键值分开
  292. function arrKeyVal($arr)
  293. {
  294. $keyArr = [];
  295. $valArr = [];
  296. if (!empty($arr)) {
  297. foreach ($arr as $k => $v) {
  298. $keyArr[] = $k;
  299. $valArr[] = $v;
  300. }
  301. }
  302. return ['keyarr' => $keyArr, 'valarr' => $valArr];
  303. }
  304. //获取ip
  305. // function get_client_ip() {
  306. // $ip = $_SERVER['REMOTE_ADDR'];
  307. // if (isset($_SERVER['HTTP_CLIENT_IP']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_SERVER['HTTP_CLIENT_IP'])) {
  308. // $ip = $_SERVER['HTTP_CLIENT_IP'];
  309. // } elseif(isset($_SERVER['HTTP_X_FORWARDED_FOR']) AND preg_match_all('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s', $_SERVER['HTTP_X_FORWARDED_FOR'], $matches)) {
  310. // foreach ($matches[0] AS $xip) {
  311. // if (!preg_match('#^(10|172\.16|192\.168)\.#', $xip)) {
  312. // $ip = $xip;
  313. // break;
  314. // }
  315. // }
  316. // }
  317. // return $ip;
  318. // }
  319. //能否发布
  320. function is_released($workerid)
  321. {
  322. $comjobs_count = Db::name('comjobs')
  323. ->where('workerid', $workerid)
  324. ->count();
  325. $demand_count = Db::name("demand")
  326. ->where('workerid', $workerid)
  327. ->count();
  328. $supply_data = Db::name("supply")
  329. ->where('workerid', $workerid)
  330. ->count();
  331. $count = $comjobs_count + $demand_count + $supply_data;
  332. if ($count >= 3) {
  333. $rtn['code'] = 1001;
  334. $rtn['msg'] = "您的审核还未通过,最多只能发3条信息";
  335. return $rtn;
  336. } else {
  337. $rtn['code'] = 0;
  338. // $rtn['code'] = 1001;
  339. }
  340. return $rtn;
  341. }
  342. /**
  343. * 根据经纬度和半径计算出范围
  344. * @param string $lat 纬度
  345. * @param String $lng 经度
  346. * @param float $radius 半径
  347. * @return Array 范围数组
  348. */
  349. function calcScope($lat, $lng, $radius)
  350. {
  351. $degree = (24901 * 1609) / 360.0;
  352. $dpmLat = 1 / $degree;
  353. $radiusLat = $dpmLat * $radius;
  354. $minLat = $lat - $radiusLat; // 最小纬度
  355. $maxLat = $lat + $radiusLat; // 最大纬度
  356. $mpdLng = $degree * cos($lat * (PI / 180));
  357. $dpmLng = 1 / $mpdLng;
  358. $radiusLng = $dpmLng * $radius;
  359. $minLng = $lng - $radiusLng; // 最小经度
  360. $maxLng = $lng + $radiusLng; // 最大经度
  361. /** 返回范围数组 */
  362. $scope = [
  363. 'minLat' => $minLat,
  364. 'maxLat' => $maxLat,
  365. 'minLng' => $minLng,
  366. 'maxLng' => $maxLng,
  367. ];
  368. return $scope;
  369. }
  370. /**
  371. * 根据经纬度和半径查询在此范围内的所有的对象
  372. * @param String $lat 纬度
  373. * @param String $lng 经度
  374. * @param float $radius 半径
  375. * @return Array 计算出来的结果
  376. */
  377. //public function searchByLatAndLng($lat, $lng, $radius) {
  378. // $scope = $this->calcScope($lat, $lng, $radius); // 调用范围计算函数,获取最大最小经纬度
  379. // /** 查询经纬度在 $radius 范围内的对象的详细地址 */
  380. // $sql = 'SELECT `字段` FROM `表名` WHERE `Latitude` < '.$scope['maxLat'].' and `Latitude` > '.$scope['minLat'].' and `Longitude` < '.$scope['maxLng'].' and `Longitude` > '.$scope['minLng'];
  381. // $stmt = self::$db->query($sql);
  382. // $res = $stmt->fetchAll(PDO::FETCH_ASSOC); // 获取查询结果并返回
  383. // return $res;
  384. //}
  385. /**
  386. * 获取两个经纬度之间的距离
  387. * @param string $lat1 纬一
  388. * @param String $lng1 经一
  389. * @param String $lat2 纬二
  390. * @param String $lng2 经二
  391. * @return float 返回两点之间的距离
  392. */
  393. function calcDistance($lat1, $lng1, $lat2, $lng2)
  394. {
  395. /** 转换数据类型为 double */
  396. $lat1 = doubleval($lat1);
  397. $lng1 = doubleval($lng1);
  398. $lat2 = doubleval($lat2);
  399. $lng2 = doubleval($lng2);
  400. /** 以下算法是 Google 出来的,与大多数经纬度计算工具结果一致 */
  401. $theta = $lng1 - $lng2;
  402. $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
  403. $dist = acos($dist);
  404. $dist = rad2deg($dist);
  405. $miles = $dist * 60 * 1.1515;
  406. return ($miles * 1.609344);
  407. }
  408. //$lon1 用户当前经度 $lat1用户当前纬度 $lon2数据库经度的字段名 $lat2数据库纬度的字段名
  409. function distance_sql($lon1 = '116.434164', $lat1 = '39.909843', $lon2 = 'longitude', $lat2 = 'latitude')
  410. {
  411. $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) ";
  412. return $sql;
  413. }
  414. /**
  415. * CURL请求
  416. * @param $url 请求url地址
  417. * @param $method 请求方法 get post
  418. * @param null $postfields post数据数组
  419. * @param array $headers 请求header信息
  420. * @return mixed
  421. */
  422. function http_request($url, $method = "GET", $postfields = null, $headers = [])
  423. {
  424. $method = strtoupper($method);
  425. $ci = curl_init();
  426. /* Curl settings */
  427. curl_setopt($ci, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
  428. curl_setopt($ci, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0");
  429. curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 60); /* 在发起连接前等待的时间,如果设置为0,则无限等待 */
  430. curl_setopt($ci, CURLOPT_TIMEOUT, 7); /* 设置cURL允许执行的最长秒数 */
  431. curl_setopt($ci, CURLOPT_RETURNTRANSFER, true);
  432. switch ($method) {
  433. case "POST":
  434. curl_setopt($ci, CURLOPT_POST, true);
  435. if (!empty($postfields)) {
  436. $tmpdatastr = is_array($postfields) ? http_build_query($postfields) : $postfields;
  437. curl_setopt($ci, CURLOPT_POSTFIELDS, $tmpdatastr);
  438. }
  439. break;
  440. default:
  441. curl_setopt($ci, CURLOPT_CUSTOMREQUEST, $method); /* //设置请求方式 */
  442. break;
  443. }
  444. $ssl = preg_match('/^https:\/\//i', $url) ? TRUE : FALSE;
  445. curl_setopt($ci, CURLOPT_URL, $url);
  446. if ($ssl) {
  447. curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, FALSE); // https请求 不验证证书和hosts
  448. curl_setopt($ci, CURLOPT_SSL_VERIFYHOST, FALSE); // 不从证书中检查SSL加密算法是否存在
  449. }
  450. //curl_setopt($ci, CURLOPT_HEADER, true); /*启用时会将头文件的信息作为数据流输出*/
  451. curl_setopt($ci, CURLOPT_FOLLOWLOCATION, 1);
  452. curl_setopt($ci, CURLOPT_MAXREDIRS, 2); /* 指定最多的HTTP重定向的数量,这个选项是和CURLOPT_FOLLOWLOCATION一起使用的 */
  453. curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);
  454. curl_setopt($ci, CURLINFO_HEADER_OUT, true);
  455. /* curl_setopt($ci, CURLOPT_COOKIE, $Cookiestr); * *COOKIE带过去** */
  456. $response = curl_exec($ci);
  457. curl_close($ci);
  458. return $response;
  459. }
  460. /**
  461. * 数据导入
  462. * @param string $file excel文件
  463. * @param string $crop
  464. * @param string $sheet
  465. * @return array 返回解析数据
  466. * @throws PHPExcel_Exception
  467. * @throws PHPExcel_Reader_Exception
  468. */
  469. function importExecl($file = '', $cell = [], $crop = 0, $sheet = 0)
  470. {
  471. $file = iconv("utf-8", "gb2312", $file); //转码
  472. if (empty($file) OR !file_exists($file)) {
  473. die('file not exists!');
  474. }
  475. $objRead = new PHPExcel_Reader_Excel2007(); //建立reader对象
  476. if (!$objRead->canRead($file)) {
  477. $objRead = new PHPExcel_Reader_Excel5();
  478. if (!$objRead->canRead($file)) {
  479. die('No Excel!');
  480. }
  481. }
  482. $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'];
  483. $obj = $objRead->load($file); //建立excel对象
  484. $currSheet = $obj->getSheet($sheet); //获取指定的sheet表
  485. $columnH = $currSheet->getHighestColumn(); //取得最大的列号
  486. $columnCnt = array_search($columnH, $cellName);
  487. $rowCnt = $currSheet->getHighestRow(); //获取总行数
  488. $data = [];
  489. for ($_row = 1; $_row <= $rowCnt; $_row++) { //读取内容
  490. if ($_row > $crop) {
  491. for ($_column = 0; $_column <= $columnCnt; $_column++) {
  492. $cellId = $cellName[$_column] . $_row;
  493. $cellValue = $currSheet->getCell($cellId)->getValue();
  494. //$cellValue = $currSheet->getCell($cellId)->getCalculatedValue(); #获取公式计算的值
  495. if ($cellValue instanceof PHPExcel_RichText) { //富文本转换字符串
  496. $cellValue = $cellValue->__toString();
  497. } else {
  498. $cellValue = (string)$cellValue;
  499. }
  500. if (!empty($cell[$_column])) {
  501. $data[$_row][$cell[$_column]] = $cellValue;
  502. } else {
  503. $data[$_row][] = $cellValue;
  504. }
  505. }
  506. }
  507. }
  508. return array_values($data);
  509. }
  510. /**
  511. * 获取唯一单号
  512. */
  513. function getUniId()
  514. {
  515. $order_id_main = date('YmdHis') . rand(10000000,99999999);
  516. $order_id_len = strlen($order_id_main);
  517. $order_id_sum = 0;
  518. for($i=0; $i<$order_id_len; $i++){
  519. $order_id_sum += (int)(substr($order_id_main,$i,1));
  520. }
  521. $osn = $order_id_main . str_pad((100 - $order_id_sum % 100) % 100,2,'0',STR_PAD_LEFT);
  522. return $osn;
  523. }