common.php 19 KB

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