common.php 20 KB

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