common.php 21 KB

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