common.php 20 KB

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