common.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. <?php
  2. // 应用公共文件
  3. /**
  4. *
  5. * @param type $algo
  6. * @param type $password
  7. * @param type $salt
  8. * @param type $hash_iterations
  9. * @return type
  10. */
  11. function simple_hash($algo = 'md5', $password = '', $salt = '', $hash_iterations = 2) {
  12. $res = '';
  13. $pass = $salt . $password;
  14. $encoded = hash($algo, $pass, true);
  15. $iteration = $hash_iterations - 1;
  16. if ($iteration > 0) {
  17. for ($i = 0; $i < $iteration; $i++) {
  18. $encoded = hash($algo, $encoded, true);
  19. }
  20. }
  21. $tmp = unpack('H*', $encoded);
  22. if (!empty($tmp) && !empty($tmp[1])) {
  23. $res = $tmp[1];
  24. }
  25. return $res;
  26. }
  27. /**
  28. * 检查权限
  29. * @param type $url
  30. * @param type $old_url
  31. * @return type
  32. */
  33. function chkCommission($url, $old_url) {
  34. return app\common\api\MenuApi::chkPermission($url, $old_url);
  35. }
  36. /**
  37. * 随机字符ID
  38. * @return type
  39. */
  40. function getStringId() {
  41. $day = random_int(10, 30);
  42. $time = strtotime("-4 years -6 months -" . $day . " days");
  43. $randnum = random_int(100000000, 999999999);
  44. $randnum = str_shuffle($randnum);
  45. return $time . $randnum;
  46. }
  47. function isNullOrEmpty($obj) {
  48. if (!$obj || $obj == "" || !isset($obj))
  49. return "";
  50. return $obj;
  51. }
  52. function getTreeList($array, $id_field = "id", $pid_field = "pid", $value = "0") {
  53. static $result = [];
  54. foreach ($array as $key => $item) {
  55. if ($value == $item[$pid_field]) {
  56. $result[] = $item;
  57. unset($array[$key]);
  58. getTreeList($array, $id_field, $pid_field, $item[$id_field]);
  59. }
  60. }
  61. return $result;
  62. }
  63. /**
  64. * 读取excel
  65. * @param type $filepath
  66. * @param type $sheetIndex
  67. * @return type
  68. */
  69. function getExcelDatas($filepath, $sheetIndex = 0) {
  70. $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($filepath);
  71. $sheet = $spreadsheet->getSheet($sheetIndex);
  72. /* $reader_type = \PHPExcel_IOFactory::identify($filepath);
  73. $reader = \PHPExcel_IOFactory::createReader($reader_type);
  74. $phpexcel = $reader->load($filepath);
  75. $sheet = $phpexcel->getSheet($sheetIndex); */
  76. return $sheet->toArray();
  77. }
  78. /**
  79. * 导出excel
  80. * @param type $columns 列标题
  81. * @param type $rows 内容
  82. * @param string $filename 文件名
  83. * @param string $settings 样式批设置
  84. * @param type $sheetname sheet标题
  85. * @param type $saveurl 保存位置
  86. * @param type $author 作者
  87. */
  88. function export($columns, $rows, $filename = "jjrcw", $settings = [], $sheetname = "sheet1", $saveurl = "php://output", $author = "晋江人才网") {
  89. $datatype = new \PhpOffice\PhpSpreadsheet\Cell\DataType;
  90. $spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
  91. $spreadsheet->getProperties()->setCreator($author)
  92. ->setLastModifiedBy($author)
  93. ->setTitle($filename)
  94. ->setSubject($filename);
  95. $spreadsheet->setActiveSheetIndex(0);
  96. $objPHPExcel = $spreadsheet->getActiveSheet();
  97. $objPHPExcel->setTitle($sheetname);
  98. $filename .= "_" . time();
  99. $titleStartLine = 1;
  100. $rowStartLine = $titleStartLine + 1;
  101. $colCount = count($columns);
  102. $rowCount = count($rows);
  103. //设置表头
  104. for ($i = 0; $i < $colCount; $i++) {
  105. $objPHPExcel->setCellValue(getExcelColumnByIndex($i) . $titleStartLine, $columns[$i]);
  106. }
  107. //设置正文内容
  108. for ($i = 0; $i < $rowCount; $i++) {
  109. for ($n = 0; $n < $colCount; $n++) {
  110. if (is_numeric($rows[$i][$n]) && strlen($rows[$i][$n]) > 11) {
  111. //超过11位的数字转成文本方以免被转化为科学数
  112. $objPHPExcel->setCellValueExplicit(getExcelColumnByIndex($n) . ($rowStartLine + $i), $rows[$i][$n], $datatype::TYPE_STRING);
  113. } else {
  114. $objPHPExcel->setCellValue(getExcelColumnByIndex($n) . ($rowStartLine + $i), $rows[$i][$n]);
  115. }
  116. }
  117. }
  118. $objPHPExcel->getDefaultColumnDimension()->setWidth(16); //默认列宽
  119. $objPHPExcel->getDefaultRowDimension()->setRowHeight(30); //默认列高
  120. //样式设置
  121. $defaultSetting = getCommonExcelSetting($colCount, $rowCount);
  122. $mergeSettings = [];
  123. foreach ($defaultSetting as $key => $set) {
  124. $mergeSettings[$key] = is_array($set) ? array_merge((array) $set, (array) $settings[$key]) : ($settings[$key] ?: $set);
  125. unset($settings[$key]);
  126. }
  127. $mergeSettings = $settings ? array_merge($mergeSettings, $settings) : $mergeSettings;
  128. foreach ($mergeSettings as $type => $cfg) {
  129. switch ($type) {
  130. case "width":
  131. for ($i = 0; $i < count($cfg); $i++) {
  132. $objPHPExcel->getColumnDimension($cfg[$i][0])->setWidth($cfg[$i][1]);
  133. }
  134. break;
  135. case "height":
  136. for ($i = 0; $i < count($cfg); $i++) {
  137. $objPHPExcel->getRowDimension($cfg[$i][0])->setRowHeight($cfg[$i][1]);
  138. }
  139. break;
  140. case "background-color":
  141. for ($i = 0; $i < count($cfg); $i++) {
  142. $objPHPExcel->getStyle($cfg[$i][0])->getFill()->setFillType(PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)->getStartColor($cfg[$i][1])->setARGB($cfg[$i][1]);
  143. }
  144. break;
  145. case "border":
  146. $objPHPExcel->getStyle($cfg)->applyFromArray(array(
  147. "borders" => array(
  148. "allBorders" => array(
  149. 'borderStyle' => PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN
  150. )
  151. )
  152. ));
  153. break;
  154. case "align":
  155. for ($i = 0; $i < count($cfg); $i++) {
  156. switch ($cfg[$i][1]) {
  157. case "left":
  158. $hAlign = PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_LEFT;
  159. break;
  160. case "right":
  161. $hAlign = PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_RIGHT;
  162. break;
  163. case "hCenter":
  164. $hAlign = PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER;
  165. break;
  166. case "hJustify":
  167. $hAlign = PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_JUSTIFY;
  168. break;
  169. case "top":
  170. $vAlign = PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_TOP;
  171. break;
  172. case "bottom":
  173. $vAlign = PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_BOTTOM;
  174. break;
  175. case "vCenter":
  176. $vAlign = PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER;
  177. break;
  178. case "vJustify":
  179. $vAlign = PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_JUSTIFY;
  180. break;
  181. }
  182. $align = [];
  183. if ($hAlign) {
  184. $align["horizontal"] = $hAlign;
  185. }
  186. if ($vAlign) {
  187. $align["vertical"] = $vAlign;
  188. }
  189. $objPHPExcel->getStyle($cfg[$i][0])->applyFromArray([
  190. "alignment" => $align
  191. ]);
  192. }
  193. break;
  194. case "font":
  195. for ($i = 0; $i < count($cfg); $i++) {
  196. $ft = $cfg[$i][1];
  197. $fm = $cfg[$i][2] ?: "宋体";
  198. $fb = $cfg[$i][3] ?: false;
  199. $fc = $cfg[$i][4] ?: "000000";
  200. switch ($cfg[$i][0]) {
  201. default:
  202. $objPHPExcel->getStyle($cfg[$i][0])->getFont()->setName($fm)->setSize($ft)->setBold($fb)->getColor()->setRGB($fc);
  203. break;
  204. }
  205. }
  206. break;
  207. case "color":
  208. for ($i = 0; $i < count($cfg); $i++) {
  209. $objPHPExcel->getStyle($cfg[$i][0])->getFont()->getColor()->setARGB($cfg[$i][1]);
  210. }
  211. break;
  212. case "format":
  213. for ($i = 0; $i < count($cfg); $i++) {
  214. switch ($cfg[$i][0]) {
  215. case "string":
  216. $objPHPExcel->getStyle($cfg[$i][1])->getNumberFormat()->setFormatCode(PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
  217. break;
  218. case "usd":
  219. $objPHPExcel->getStyle($cfg[$i][1])->getNumberFormat()->setFormatCode(PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_CURRENCY_USD_SIMPLE);
  220. break;
  221. default:
  222. $objPHPExcel->getStyle($cfg[$i][1])->getNumberFormat()->setFormatCode(PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED2);
  223. break;
  224. }
  225. }
  226. break;
  227. case "wrap":
  228. for ($i = 0; $i < count($cfg); $i++) {
  229. $objPHPExcel->getStyle($cfg[$i])->getAlignment()->setWrapText(true); //cellvalue包含\n设为自动换行
  230. }
  231. break;
  232. case "scale":
  233. $objPHPExcel->getSheetView()->setZoomScale($cfg ?: 100);
  234. break;
  235. case "freeze":
  236. $objPHPExcel->freezePane($cfg);
  237. break;
  238. case "filter":
  239. $objPHPExcel->setAutoFilter($cfg);
  240. break;
  241. }
  242. }
  243. header('Content-Type: application/vnd.ms-excel');
  244. header('Content-Disposition: attachment;filename="' . $filename . '.xls"');
  245. $writer = new \PhpOffice\PhpSpreadsheet\Writer\Xls($spreadsheet);
  246. $writer->save($saveurl);
  247. //删除临时的sheet
  248. $spreadsheet->disconnectWorksheets();
  249. unset($spreadsheet);
  250. exit;
  251. }
  252. /**
  253. * 根据传入的数值(游标),从26个英文字母的数组中查询,返回excel列标
  254. * @param int $index 游标从0开始
  255. * @return string 返回列标
  256. */
  257. function getExcelColumnByIndex(int $index) {
  258. $letters = 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');
  259. if ($letters[$index])
  260. return $letters[$index];
  261. $rowIndex = floor($index / 26) - 1;
  262. $colIndex = $index % 26;
  263. return $letters[$rowIndex] . $letters[$colIndex];
  264. }
  265. /**
  266. * 公共的excel设置
  267. * @return type
  268. */
  269. function getCommonExcelSetting($columns, $rows) {
  270. return $settings = [
  271. "background-color" => [[sprintf("A1:%s1", getExcelColumnByIndex($columns - 1)), "0066CC"]],
  272. "color" => [[sprintf("A1:%s1", getExcelColumnByIndex($columns - 1)), "FFFFFF"]],
  273. "border" => sprintf("A1:%s%d", getExcelColumnByIndex($columns - 1), $rows + 1),
  274. "wrap" => [sprintf("A2:%s%d", getExcelColumnByIndex($columns - 1), $rows + 1)],
  275. "align" => [[sprintf("A1:%s%d", getExcelColumnByIndex($columns - 1), $rows + 1), "hCenter"], [sprintf("A1:%s%d", getExcelColumnByIndex($columns - 1), $rows + 1), "vCenter"]]
  276. ];
  277. }
  278. /**
  279. * 检查是不是excel格式,不确定是否都是可用文件,主要还是第一和最后一个比较常见
  280. * @param type $mime
  281. * @return type
  282. */
  283. function isExcelFile($mime) {
  284. return in_array($mime, [
  285. "application/vnd.ms-excel",
  286. "application/msexcel",
  287. "application/x-msexcel",
  288. "application/x-ms-excel",
  289. "application/x-excel",
  290. "application/x-dos_ms_excel",
  291. "application/xls",
  292. "application/x-xls",
  293. "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
  294. ]);
  295. }
  296. /**
  297. * 获取主机名带协议
  298. * @return http[s]://xxxx
  299. */
  300. function getHostWithProtocol() {
  301. $protocol = (strpos(strtolower($_SERVER['SERVER_PROTOCOL']), 'http/2.0') !== false || $_SERVER["HTTPS"] == "on" || $_SERVER["REQUEST_SCHEME"] == "https" ? 'https' : 'http') . "://";
  302. return $protocol . $_SERVER["HTTP_HOST"];
  303. }
  304. /**
  305. * 获得上传文件的路径
  306. * @param $path
  307. * @param $stillOriginalPath 如果是pdf这类文件会生成fileview格式的url,此参数为真是则生成原始url
  308. * @return string
  309. */
  310. function getStoragePath($path, $stillOriginalPath = false) {
  311. if (!$path)
  312. return "";
  313. if (strpos($path, "jjrcw") === 0) {
  314. $path = "https://rc.jucai.gov.cn/ftp/{$path}";
  315. } else {
  316. $path = getHostWithProtocol() . "/storage/{$path}";
  317. }
  318. if (isImage($path) || $stillOriginalPath)
  319. return $path;
  320. return getFileView($path);
  321. }
  322. function getFileView($path) {
  323. return $path;
  324. //$complete_path = "https://report.jinjianghc.com/" . getStoragePath($path);
  325. return "https://fileview.jinjianghc.com/onlinePreview?url=" . base64_encode($path) . "&officePreviewType=pdf";
  326. }
  327. function isImage($filename) {
  328. $types = '.gif|.jpeg|.png|.bmp'; //定义检查的图片类型
  329. try {
  330. $info = getimagesize($filename);
  331. if ($info && stripos($types, image_type_to_extension($info['2'])) !== false) {
  332. return true;
  333. }
  334. return false;
  335. } catch (\think\exception $e) {
  336. //文件不存在,根据拓展名返回
  337. $types = "gif|jpg|jpeg|png|bmp";
  338. $pathinfo = pathinfo($filename);
  339. $ext = $pathinfo["extension"];
  340. if ($pathinfo && $ext && stripos($types, $ext) !== false) {
  341. return true;
  342. }
  343. return false;
  344. }
  345. }
  346. function chkEnterpriseFull($ep) {
  347. switch ($ep->special) {
  348. case 0:
  349. if ($ep["type"] == 1) {
  350. $checkEnterpriseFullFields = ["agencyType", "enterpriseTag", "enterpriseType", "bankCard", "bankNetwork", "bank", "imgurl", "bankImg", "beian"];
  351. if ($ep["agencyType"] == 1) {
  352. $checkEnterpriseFullFields[] = "industryFieldNew";
  353. $checkEnterpriseFullFields[] = "industryFieldOld";
  354. $checkEnterpriseFullFields[] = "domainImg";
  355. }
  356. if (in_array($ep["enterpriseType"], ['guishang', 'gaoxinjishu', 'zhuanjingtexin'])) {
  357. $checkEnterpriseFullFields[] = "typeImg";
  358. }
  359. } else {
  360. $checkEnterpriseFullFields = ["bankCard", "bankNetwork", "bank", "imgurl", "bankImg", "beian"];
  361. }
  362. break;
  363. case 1:
  364. $checkEnterpriseFullFields = ["institutionTag"];
  365. break;
  366. case 3:
  367. $checkEnterpriseFullFields = ["organizationTag"];
  368. break;
  369. }
  370. $errorCounts = 0;
  371. while ($chk = array_shift($checkEnterpriseFullFields)) {
  372. if ($ep[$chk] == null)
  373. $errorCounts++;
  374. }
  375. if ($errorCounts > 0) {
  376. echo sprintf("<script>"
  377. . "parent.layer.confirm('系统升级,您的资料需要同步更新,请移步机构用户中心进行修改【机构信息变更】。',"
  378. . "function(){"
  379. . "var url='/enterprise/index/centerPage';"
  380. . "top.$('a.J_menuItem[href=\"'+url+'\"]').click();clkTab();"
  381. . "},function(){parent.layer.closeAll();});function clkTab(){setTimeout(function(){if(top.$('iframe.J_iframe[data-id=\"/enterprise/index/centerPage\"]').contents().find('a[href=\"#tab-2\"]').length==1){"
  382. . "top.$('iframe.J_iframe[data-id=\"/enterprise/index/centerPage\"]').contents().find('*.active').removeClass('active');"
  383. . "top.$('iframe.J_iframe[data-id=\"/enterprise/index/centerPage\"]').contents().find('ul.nav-tabs li').eq(1).addClass('active');"
  384. . "top.$('iframe.J_iframe[data-id=\"/enterprise/index/centerPage\"]').contents().find('#tab-2').addClass('active');parent.layer.closeAll();"
  385. . "}else{clkTab();}},20);};"
  386. . "</script>");
  387. return false;
  388. }
  389. return true;
  390. }
  391. function generate_password($length = 8) {
  392. $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%&*?';
  393. $password = '';
  394. for ($i = 0; $i < $length; $i++) {
  395. // 这里提供两种字符获取方式
  396. // 第一种是使用 substr 截取$chars中的任意一位字符;
  397. // 第二种是取字符数组 $chars 的任意元素
  398. // $password .= substr($chars, mt_rand(0, strlen($chars) – 1), 1);
  399. $password .= $chars[mt_rand(0, strlen($chars) - 1)];
  400. }
  401. return $password;
  402. }
  403. /**
  404. * 判断是否为合法的身份证号码
  405. * @param $mobile
  406. * @return int
  407. */
  408. function isCreditNo($vStr) {
  409. $vCity = array(
  410. '11', '12', '13', '14', '15', '21', '22',
  411. '23', '31', '32', '33', '34', '35', '36',
  412. '37', '41', '42', '43', '44', '45', '46',
  413. '50', '51', '52', '53', '54', '61', '62',
  414. '63', '64', '65', '71', '81', '82', '91'
  415. );
  416. if (!preg_match('/^([\d]{17}[xX\d]|[\d]{15})$/', $vStr))
  417. return false;
  418. if (!in_array(substr($vStr, 0, 2), $vCity))
  419. return false;
  420. $vStr = preg_replace('/[xX]$/i', 'a', $vStr);
  421. $vLength = strlen($vStr);
  422. if ($vLength == 18) {
  423. $vBirthday = substr($vStr, 6, 4) . '-' . substr($vStr, 10, 2) . '-' . substr($vStr, 12, 2);
  424. } else {
  425. $vBirthday = '19' . substr($vStr, 6, 2) . '-' . substr($vStr, 8, 2) . '-' . substr($vStr, 10, 2);
  426. }
  427. if (date('Y-m-d', strtotime($vBirthday)) != $vBirthday)
  428. return false;
  429. if ($vLength == 18) {
  430. $vSum = 0;
  431. for ($i = 17; $i >= 0; $i--) {
  432. $vSubStr = substr($vStr, 17 - $i, 1);
  433. $vSum += (pow(2, $i) % 11) * (($vSubStr == 'a') ? 10 : intval($vSubStr, 11));
  434. }
  435. if ($vSum % 11 != 1)
  436. return false;
  437. }
  438. return true;
  439. }
  440. function get_client_ip() {
  441. $forwarded = request()->header("x-forwarded-for");
  442. if ($forwarded) {
  443. $ip = explode(',', $forwarded)[0];
  444. } else {
  445. $ip = request()->ip();
  446. }
  447. return $ip;
  448. }
  449. /**
  450. * 通过CURL发送HTTP请求
  451. * @param string $url //请求URL
  452. * @param array $postFields //请求参数
  453. * @return mixed
  454. *
  455. */
  456. function curlPost($url, $postFields) {
  457. $postFields = json_encode($postFields);
  458. $ch = curl_init();
  459. curl_setopt($ch, CURLOPT_URL, $url);
  460. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  461. 'Content-Type: application/json; charset=utf-8' //json版本需要填写 Content-Type: application/json;
  462. )
  463. );
  464. curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); //若果报错 name lookup timed out 报错时添加这一行代码
  465. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  466. curl_setopt($ch, CURLOPT_POST, 1);
  467. curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
  468. curl_setopt($ch, CURLOPT_TIMEOUT, 60);
  469. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  470. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  471. $ret = curl_exec($ch);
  472. if (false == $ret) {
  473. $result = curl_error($ch);
  474. } else {
  475. $rsp = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  476. if (200 != $rsp) {
  477. $result = "请求状态 " . $rsp . " " . curl_error($ch);
  478. } else {
  479. $result = $ret;
  480. }
  481. }
  482. curl_close($ch);
  483. return $result;
  484. }
  485. function getCacheById($key, $field, $fieldKey = null) {
  486. $redis = \app\common\Redis::instance(think\facade\Config::get("cache.stores.redis.select"));
  487. $info = $redis->hGet($key, $field);
  488. $result = json_decode($info, true);
  489. if ($fieldKey)
  490. return $result[$fieldKey];
  491. return $result;
  492. }
  493. function getJsonConfig($filepath, $field) {
  494. if (file_exists($filepath)) {
  495. return json_decode(file_get_contents($filepath), true)[$field];
  496. }
  497. return null;
  498. }
  499. //加密前补齐
  500. function mystr_pad($data, $len = 16) {
  501. $n = $len - strlen($data) % $len;
  502. $data = $data . str_repeat(chr($n), $n);
  503. return $data;
  504. }
  505. // 解密后去掉补齐
  506. function mystr_unpad($data) {
  507. $n = ord(substr($data, -1));
  508. return substr($data, 0, -$n);
  509. }
  510. //计算两个日期的时间差
  511. function diffDate($date1, $date2) {
  512. if (strtotime($date1) > strtotime($date2)) {
  513. $ymd = $date2;
  514. $date2 = $date1;
  515. $date1 = $ymd;
  516. }
  517. $date1 = date('Y-m-d', strtotime($date1));
  518. $date2 = date('Y-m-d', strtotime($date2));
  519. list($y1, $m1, $d1) = explode('-', $date1);
  520. list($y2, $m2, $d2) = explode('-', $date2);
  521. $y = $m = $d = $_m = 0;
  522. $math = ($y2 - $y1) * 12 + $m2 - $m1;
  523. $y = intval(floor($math / 12));
  524. $m = intval($math % 12);
  525. $d = (mktime(0, 0, 0, $m2, $d2, $y2) - mktime(0, 0, 0, $m2, $d1, $y2)) / 86400;
  526. if ($d < 0) {
  527. $m -= 1;
  528. $d += date('j', mktime(0, 0, 0, $m2, 0, $y2));
  529. }
  530. return array($y, $m, $d);
  531. }
  532. function formatDateByMonth($date1, $date2, $data = []) {
  533. if (strtotime($date1) > strtotime($date2)) {
  534. $ymd = $date2;
  535. $date2 = $date1;
  536. $date1 = $ymd;
  537. }
  538. $sTime = strtotime(date('Y-m-01', strtotime($date1)));
  539. $eTime = strtotime(date('Y-m-01', strtotime($date2)));
  540. $month_arr = [];
  541. for ($sTime; $sTime <= $eTime; $sTime = strtotime('+1 month', $sTime)) {
  542. $month_arr[date('Ym', $sTime)] = date('Y-m', $sTime); // 取得递增月;
  543. }
  544. if (is_array($data) && count($data) > 0) {
  545. foreach ($data as $item) {
  546. if (array_key_exists($item['aae003'], $month_arr)) {
  547. $month_arr[$item['aae003']] .= "<span style='color:green'>已缴费</span>";
  548. }
  549. }
  550. }
  551. return $month_arr;
  552. }
  553. function proSearch($str, $arr) {
  554. $match_res = [];
  555. array_filter($arr, function($arr) use ($str, &$match_res) {
  556. if (stripos($arr['value'], $str) !== false) {
  557. $match_res[] = $arr['value'];
  558. return true;
  559. } else {
  560. return false;
  561. }
  562. });
  563. }