helpers.php 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466
  1. <?php
  2. use App\Services\Common\CurlService;
  3. use Carbon\Carbon;
  4. use Illuminate\Support\Facades\Cache;
  5. use Illuminate\Support\Str;
  6. //免费会员ID
  7. define("DISABLE_ICO", 1);
  8. if (!function_exists('theme_asset')) {
  9. /**
  10. * Generate an asset path for the application theme.
  11. *
  12. * @param string $path
  13. * @param bool $secure
  14. * @return string
  15. */
  16. function theme_asset($path, $secure = null)
  17. {
  18. $theme_root = 'themes/' . config('theme.theme') . '/assets/';
  19. return app('url')->asset($theme_root . $path, $secure);
  20. }
  21. }
  22. if (!function_exists('upload_asset')) {
  23. /**
  24. * Generate an asset path for the upload system.
  25. *
  26. * @param string $path
  27. * @return string
  28. */
  29. function upload_asset($path)
  30. {
  31. return \Illuminate\Support\Facades\Storage::disk('public')->url($path);
  32. }
  33. }
  34. if (!function_exists('validator_check')) {
  35. /**
  36. * 根据验证规则返回值是否验证通过
  37. * @param $value
  38. * @param $rule
  39. * @return boolean
  40. */
  41. function validator_check($value, $rule)
  42. {
  43. $valid = validator(['check' => $value], ['check' => $rule]);
  44. if ($valid->fails()) {
  45. return false;
  46. }
  47. return true;
  48. }
  49. }
  50. if (!function_exists('render_template')) {
  51. /**
  52. * 渲染系统模板(短信,邮件)
  53. * @param string $template
  54. * @param array $params
  55. * @return mixed|string
  56. */
  57. function render_template(string $template, array $params)
  58. {
  59. if (empty($params)) {
  60. return $template;
  61. }
  62. preg_match_all('/\$\{(.*)\}/U', $template, $match_array);
  63. foreach ($match_array[0] as $key => $match) {
  64. $replace = array_get($params, $match_array[1][$key], "({$match_array[1][$key]}未匹配)");
  65. $template = str_replace($match, $replace, $template);
  66. }
  67. return $template;
  68. }
  69. }
  70. /**
  71. * 移动端请求判断
  72. */
  73. function isMobile()
  74. {
  75. // 如果有HTTP_X_WAP_PROFILE则一定是移动设备
  76. if (isset($_SERVER['HTTP_X_WAP_PROFILE'])) {
  77. return true;
  78. }
  79. // 如果via信息含有wap则一定是移动设备
  80. if (isset($_SERVER['HTTP_VIA'])) {
  81. // 找不到为flase,否则为true
  82. return stristr($_SERVER['HTTP_VIA'], "wap") ? true : false;
  83. }
  84. // 脑残法,判断手机发送的客户端标志,兼容性有待提高
  85. if (isset($_SERVER['HTTP_USER_AGENT'])) {
  86. $clientkeywords = ['nokia',
  87. 'sony',
  88. 'ericsson',
  89. 'mot',
  90. 'samsung',
  91. 'htc',
  92. 'sgh',
  93. 'lg',
  94. 'sharp',
  95. 'sie-',
  96. 'philips',
  97. 'panasonic',
  98. 'alcatel',
  99. 'lenovo',
  100. 'iphone',
  101. 'ipod',
  102. 'blackberry',
  103. 'meizu',
  104. 'android',
  105. 'netfront',
  106. 'symbian',
  107. 'ucweb',
  108. 'windowsce',
  109. 'palm',
  110. 'operamini',
  111. 'operamobi',
  112. 'openwave',
  113. 'nexusone',
  114. 'cldc',
  115. 'midp',
  116. 'wap',
  117. 'mobile',
  118. ];
  119. // 从HTTP_USER_AGENT中查找手机浏览器的关键字
  120. if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) {
  121. return true;
  122. }
  123. }
  124. // 协议法,因为有可能不准确,放到最后判断
  125. if (isset($_SERVER['HTTP_ACCEPT'])) {
  126. // 如果只支持wml并且不支持html那一定是移动设备
  127. // 如果支持wml和html但是wml在html之前则是移动设备
  128. if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html')))) {
  129. return true;
  130. }
  131. }
  132. return false;
  133. }
  134. function upload_img_path($path, $secure = null)
  135. {
  136. if (preg_match('/^images\//', $path)) {
  137. $img_path = 'uploads/';
  138. return app('url')->asset($img_path . $path, $secure);
  139. } else {
  140. return $path;
  141. }
  142. }
  143. function upload_path($path, $secure = null)
  144. {
  145. $img_path = 'uploads/';
  146. return app('url')->asset($img_path . $path, $secure);
  147. }
  148. function public_data_path($path, $secure = null)
  149. {
  150. $img_path = '';
  151. return app('url')->asset($img_path . $path, $secure);
  152. }
  153. function change_datetime_format($datetime, $format = "Y-m-d H:i:s")
  154. {
  155. $date = '';
  156. if ($datetime) {
  157. $date = date($format, strtotime($datetime));
  158. }
  159. return $date;
  160. }
  161. //截取字符
  162. function cut_str($sourcestr, $cutlength, $start = 0, $dot = '')
  163. {
  164. $returnstr = '';
  165. $i = 0;
  166. $n = 0;
  167. $str_length = strlen($sourcestr);
  168. $mb_str_length = mb_strlen($sourcestr, 'utf-8');
  169. while (($n < $cutlength) && ($i <= $str_length)) {
  170. $temp_str = substr($sourcestr, $i, 1);
  171. $ascnum = ord($temp_str);
  172. if ($ascnum >= 224) {
  173. $returnstr = $returnstr . substr($sourcestr, $i, 3);
  174. $i = $i + 3;
  175. $n++;
  176. } elseif ($ascnum >= 192) {
  177. $returnstr = $returnstr . substr($sourcestr, $i, 2);
  178. $i = $i + 2;
  179. $n++;
  180. } elseif (($ascnum >= 65) && ($ascnum <= 90)) {
  181. $returnstr = $returnstr . substr($sourcestr, $i, 1);
  182. $i = $i + 1;
  183. $n++;
  184. } else {
  185. $returnstr = $returnstr . substr($sourcestr, $i, 1);
  186. $i = $i + 1;
  187. $n = $n + 0.5;
  188. }
  189. }
  190. if ($mb_str_length > $cutlength) {
  191. $returnstr = $returnstr . $dot;
  192. }
  193. return $returnstr;
  194. }
  195. /**
  196. * [url_rewrite 伪静态]
  197. * @param [type] $alias [description]
  198. * @param [array] $get [传值]
  199. * @param boolean $rewrite [是否开启伪静态]
  200. * @return [string] [链接]
  201. */
  202. function url_rewrite($alias = null, $get = null, $subsite_id = 0, $rewrite = true)
  203. {
  204. //获取页面信息
  205. $page_list = App\Repositories\PageRepository::pageCache();
  206. $url = $url_prefix = '';
  207. if (array_get($get, 'key') && config('aix.system.site_safety.site_vo_code.site_rewrite') == 1) {
  208. $get['key'] = urlencode($get['key']);
  209. }
  210. //$subsite_set = config('aix.system.site_safety.subsite.close_subsite');
  211. //$subsite_id = Cache::get('subsite_id');
  212. /*if (!$subsite_set) {
  213. $url_prefix = subsite_url($alias, $url, $subsite_id);
  214. preg_match("/^((https|http|ftp|rtsp|mms):\/\/)?([^(\/|\?)]+)/i", $url_prefix, $matches);
  215. $http_host = $matches ? $matches[3] : '';
  216. } else {
  217. $http_host = \Illuminate\Support\Facades\Request::server('HTTP_HOST');
  218. }*/
  219. $http_host = \Illuminate\Support\Facades\Request::server('HTTP_HOST');
  220. if ($page_list[$alias]['url'] == '0' || $rewrite == false) { //原始链接
  221. if ($page_list[$alias]->route && $page_list[$alias]->route != '/') {
  222. $url = route($page_list[$alias]->route);
  223. } else {
  224. $url = '/';
  225. }
  226. } else {
  227. if ($url = $page_list[$alias]['rewrite']) {
  228. if ($page_list[$alias]['pagetpye'] == '2' && empty($get['page'])) {
  229. $get['page'] = 1;
  230. }
  231. if ($get) {
  232. foreach ($get as $k => $val) {
  233. $data['($' . $k . ')'] = $val;
  234. }
  235. $url = strtr($url, $data);
  236. }
  237. $url = preg_replace('/\(\$(\w+)\)/', '', $url);
  238. } else {
  239. if ($page_list[$alias]->route && $page_list[$alias]->route != '/') {
  240. $url = $page_list[$alias]->route;
  241. //$url = route($page_list[$alias]->route);
  242. } else {
  243. $url = '';
  244. }
  245. }
  246. }
  247. return $url_prefix . $url;
  248. }
  249. //添加手机端时需要修改
  250. //后台配置分站信息时需要修改
  251. function subsite_url($alias, $url, $subsite_id)
  252. {
  253. return config('aix.system.site.site.site_domain') . $url;
  254. }
  255. /**
  256. * 友好时间
  257. */
  258. function sub_day($endday, $staday, $range = '')
  259. {
  260. $value = $endday - $staday;
  261. if ($value < 0) {
  262. return '';
  263. } elseif ($value >= 0 && $value < 59) {
  264. return ($value + 1) . "秒";
  265. } elseif ($value >= 60 && $value < 3600) {
  266. $min = intval($value / 60);
  267. return $min . "分钟";
  268. } elseif ($value >= 3600 && $value < 86400) {
  269. $h = intval($value / 3600);
  270. return $h . "小时";
  271. } elseif ($value >= 86400 && $value < 86400 * 30) {
  272. $d = intval($value / 86400);
  273. return intval($d) . "天";
  274. } elseif ($value >= 86400 * 30 && $value < 86400 * 30 * 12) {
  275. $mon = intval($value / (86400 * 30));
  276. return $mon . "月";
  277. } else {
  278. $y = intval($value / (86400 * 30 * 12));
  279. return $y . "年";
  280. }
  281. }
  282. /**
  283. * 时间转为上、下午
  284. */
  285. if (!function_exists('PA')) {
  286. function PA($data)
  287. {
  288. $data = str_replace('AM', '上午', $data);
  289. $data = str_replace('PM', '下午', $data);
  290. return $data;
  291. }
  292. }
  293. /**
  294. * [获取职位所属分站subsite_id]
  295. * @return [数组] [job] 职位信息
  296. * 等后台设置了分站信息时再完善此功能
  297. */
  298. function get_jobs_subsite_id($job)
  299. {
  300. if (config('aix.system.site_safety.subsite.close_subsite')) {
  301. return '';
  302. } else {
  303. $subsite_id = 0;
  304. }
  305. return $subsite_id;
  306. }
  307. /**
  308. * 等后台设置了分站信息时再完善此功能
  309. */
  310. function check_url($now_subsite_id, $subsite_id)
  311. {
  312. if (!$subsite_id) {
  313. $subsite_id = 0;
  314. }
  315. if ($now_subsite_id != $subsite_id) {
  316. throw new ResponseException('页面不存在', [], '404');
  317. }
  318. }
  319. /**
  320. * 时间格式变换
  321. */
  322. function daterange($endday, $staday, $format = 'Y-m-d', $color = '', $range = 3)
  323. {
  324. $value = $endday - $staday;
  325. if ($value < 0) {
  326. return '';
  327. } elseif ($value >= 0 && $value < 59) {
  328. $return = ($value + 1) . "秒前";
  329. } elseif ($value >= 60 && $value < 3600) {
  330. $min = intval($value / 60);
  331. $return = $min . "分钟前";
  332. } elseif ($value >= 3600 && $value < 86400) {
  333. $h = intval($value / 3600);
  334. $return = $h . "小时前";
  335. } elseif ($value >= 86400) {
  336. $d = intval($value / 86400);
  337. if ($d > $range) {
  338. return date($format, $staday);
  339. } else {
  340. $return = $d . "天前";
  341. }
  342. }
  343. if ($color) {
  344. $return = "<span id=\"r_time\" style=\"color:{$color}\">" . $return . "</span>";
  345. }
  346. return $return;
  347. }
  348. function date_format_new($time)
  349. {
  350. $sec = Carbon::now()->diffInSeconds(date('Y-m-d H:i:s', $time));
  351. return Carbon::now()->addSeconds($sec)->diffForHumans();
  352. }
  353. /**
  354. * 获取地区名
  355. * @param $id
  356. * @return mixed
  357. */
  358. if (!function_exists('get_district_cn')) {
  359. function get_district_cn($id)
  360. {
  361. $district_cn = [];
  362. $district = explode('.', $id);
  363. foreach ($district as $key => $val) {
  364. if ($val) {
  365. $dist_cn = App\Models\CategoryDistrict::where('id', $val)->select(['name'])->first();
  366. $district_cn[] = $dist_cn['name'];
  367. }
  368. }
  369. return implode('/', $district_cn);
  370. }
  371. }
  372. if (!function_exists('get_tag_cn')) {
  373. function get_tag_cn($id)
  374. {
  375. $tag_cn = [];
  376. $tag = explode(',', $id);
  377. foreach ($tag as $key => $val) {
  378. $job_tag_cn = App\Models\Category::where('id', $val)->select(['demand'])->first();
  379. $tag_cn[] = $job_tag_cn['demand'];
  380. }
  381. return implode(',', $tag_cn);
  382. }
  383. }
  384. if (!function_exists('getDistrict')) {
  385. function getDistrict($id)
  386. {
  387. $parent_id = App\Models\CategoryDistrict::where('id', $id)->select(['parent_id', 'id'])->first();
  388. $parents = App\Models\CategoryDistrict::where('id', $parent_id->parent_id)->select(['parent_id', 'id'])->first();
  389. return $parents->parent_id . '.' . $parent_id->parent_id . '.' . $id;
  390. }
  391. }
  392. if (!function_exists('get_job_category_cn')) {
  393. function get_job_category_cn($id)
  394. {
  395. $job_category = explode('.', $id);
  396. foreach ($job_category as $key => $val) {
  397. $category_cn = App\Models\CategoryJobs::where('id', $val)->select(['name'])->first();
  398. $cate_cn[] = $category_cn['name'];
  399. }
  400. return implode('/', $cate_cn);
  401. }
  402. }
  403. if (!function_exists('get_job_category')) {
  404. function get_job_category($id)
  405. {
  406. $job_category = \App\Models\CategoryJobs::where('id', $id)->select(['name'])->first();
  407. return $job_category['name'];
  408. }
  409. }
  410. if (!function_exists('get_category')) {
  411. function get_category($id)
  412. {
  413. $category = \App\Models\Category::where('id', $id)->select(['demand'])->first();
  414. return $category ? $category['demand'] : null;
  415. }
  416. }
  417. if (!function_exists('get_category_major')) {
  418. function get_category_major($id)
  419. {
  420. $category = \App\Models\CategoryMajor::where('id', $id)->select(['name'])->first();
  421. return $category ? $category['name'] : null;
  422. }
  423. }
  424. /**
  425. * [ddate 时间差]
  426. */
  427. function ddate($s, $e)
  428. {
  429. $starttime = strtotime($s);
  430. $endtime = strtotime($e);
  431. $startyear = date('Y', $starttime);
  432. $startmonth = date('m', $starttime);
  433. $endyear = date('Y', $endtime);
  434. $endmonth = date('m', $endtime);
  435. $return = '';
  436. $return_year = $endyear - $startyear;
  437. $return_month = $endmonth - $startmonth;
  438. if ($return_month < 0) {
  439. $return_month += 12;
  440. $return_year -= 1;
  441. }
  442. if ($return_year > 0) {
  443. $return .= $return_year . '年';
  444. }
  445. if ($return_month > 0) {
  446. $return .= $return_month . '个月';
  447. }
  448. return $return;
  449. }
  450. //两个时间相差天数
  451. function diffBetweenTwoDays($day1, $day2)
  452. {
  453. $day1 = date("Y-m-d", strtotime($day1));
  454. $day2 = date("Y-m-d", strtotime($day2));
  455. $second1 = strtotime($day1);
  456. $second2 = strtotime($day2);
  457. if ($second1 < $second2) {
  458. $tmp = $second2;
  459. $second2 = $second1;
  460. $second1 = $tmp;
  461. }
  462. return ($second1 - $second2) / 86400;
  463. }
  464. function _get_total_work_duration($list)
  465. {
  466. $total_year = 0;
  467. $total_month = 0;
  468. $return = '';
  469. if (!empty($list)) {
  470. foreach ($list as $key => $value) {
  471. $current_duration = strpos($value['duration'], '年');
  472. if ($current_duration === false) {
  473. $total_month += intval($value['duration']);
  474. } else {
  475. $arr = explode("年", $value['duration']);
  476. $total_year += intval($arr[0]);
  477. $total_month += intval($arr[1]);
  478. }
  479. }
  480. }
  481. $add_year = intval($total_month / 12);
  482. $total_year += $add_year;
  483. $total_month = intval($total_month % 12);
  484. if ($total_year > 0) {
  485. $return .= $total_year . '年';
  486. }
  487. if ($total_month > 0) {
  488. $return .= $total_month . '个月';
  489. }
  490. return $return;
  491. }
  492. function _get_duration($list)
  493. {
  494. if (!empty($list)) {
  495. foreach ($list as $key => $value) {
  496. $start = $value['startyear'] . '-' . $value['startmonth'];
  497. $end = $value['endyear'] . '-' . $value['endmonth'];
  498. $list[$key]['duration'] = ddate($start, $end);
  499. }
  500. }
  501. return $list;
  502. }
  503. function contact_hide($data, $IsWhat = 2)
  504. {
  505. if ($IsWhat == 1) {
  506. return preg_replace('/([0[0-9]{2,3}[-]?[1-9]]|[1-9])[0-9]{2,4}([0-9]{3}[-]?[0-9]?)/i', '$1****$2', $data);
  507. } elseif ($IsWhat == 2) {
  508. return preg_replace('/(1[34578]{1}[0-9])[0-9]{4}([0-9]{4})/i', '$1****$2', $data);
  509. } elseif ($IsWhat == 3) {
  510. $email_array = explode("@", $data);
  511. $n = mb_strlen($email_array[0], 'utf-8');
  512. return str_pad(substr($email_array[0], 0, intval($n / 2)), $n, '*') . $email_array[1];
  513. } else {
  514. $n = mb_strlen($data, 'utf-8');
  515. $str = str_pad('', intval($n / 2), '*');
  516. return str_replace(substr($data, intval($n / 4), intval($n / 2)), $str, $data);
  517. }
  518. }
  519. /**
  520. * 根据生日计算年龄
  521. * @param string $birthday 出生年月日
  522. * @return string
  523. */
  524. if (!function_exists('birth_to_age')) {
  525. function birth_to_age($birthday)
  526. {
  527. $age = strtotime($birthday);
  528. if ($age === false) {
  529. return false;
  530. }
  531. list($y1, $m1, $d1) = explode("-", date("Y-m-d", $age));
  532. list($y2, $m2, $d2) = explode("-", date("Y-m-d"));
  533. $age = $y2 - $y1;
  534. if ((int)($m2 . $d2) < (int)($m1 . $d1)) {
  535. $age -= 1;
  536. }
  537. return $age;
  538. }
  539. }
  540. /**
  541. * 时间转换
  542. * @param $time
  543. * @return bool|false|string
  544. */
  545. if (!function_exists('fdate')) {
  546. function fdate($time)
  547. {
  548. $sec = Carbon::now()->diffInSeconds(date('Y-m-d H:i:s', $time));
  549. return Carbon::now()->addSeconds($sec)->diffForHumans();
  550. }
  551. }
  552. /**
  553. * 获取图片
  554. */
  555. if (!function_exists('attach')) {
  556. function attach($attach, $type)
  557. {
  558. if (empty($attach)) {
  559. return false;
  560. }
  561. if (false === strpos($attach, 'http://')) {
  562. //本地附件
  563. return '/data/upload/' . $type . '/' . $attach;
  564. } else {
  565. //URL链接
  566. return $attach;
  567. }
  568. }
  569. }
  570. if (!function_exists('getCityInfo')) {
  571. function getCityInfo($ids)
  572. {
  573. if (!$ids) {
  574. return ['district' => '', 'district_cn' => ''];
  575. }
  576. $categoryDistrict = app('App\Repositories\CategoryDistrictRepository');
  577. $city = $categoryDistrict->getDistrictCache('all');
  578. if (false == $city_cate = Cache::get('city_search_list')) {
  579. $city_cate = $categoryDistrict->citySearchCache();
  580. }
  581. $spell = $categoryDistrict->cityCateCache();
  582. foreach (explode(',', $ids) as $val) {
  583. $a = array_filter(explode('_', $city_cate[$val]));
  584. $c = count($a);
  585. if (!$c) {
  586. continue;
  587. } elseif ($c == 1) {
  588. $district_cn[] = $city[0][$a[0]];
  589. } elseif ($c > 1) {
  590. $district_cn[] = $city[$a[$c - 2]][$a[$c - 1]];
  591. }
  592. foreach ($a as $key => $v) {
  593. $b[] = $key == 0 ? $city[0][$v] : $city[$a[$key - 1]][$v];
  594. $s[] = $spell['id'][$v]['spell'];
  595. }
  596. $district_cn_all[] = implode('/', $b);
  597. $district[] = implode('.', $a);
  598. $district_spell[] = implode('.', $s);
  599. }
  600. return ['district' => implode(',', $district), 'district_cn_all' => implode(',', $district_cn_all), 'district_cn' => implode(',', $district_cn), 'district_spell' => implode(',', $district_spell)];
  601. }
  602. }
  603. /**
  604. * 访问百度api获取当前坐标
  605. */
  606. function _get_baidumap_api()
  607. {
  608. $api = 'https://api.map.baidu.com/location/ip';
  609. $data['ip'] = '117.136.67.3';
  610. $data['ak'] = config('aix.system.map.map.map_ak');
  611. $data['coor'] = 'bd09ll';
  612. $data['s'] = 1;
  613. $result = https_request($api, $data);
  614. return $result;
  615. }
  616. function https_request($url, $data = null)
  617. {
  618. if (function_exists('curl_init')) {
  619. $curl = curl_init();
  620. curl_setopt($curl, CURLOPT_URL, $url);
  621. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
  622. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
  623. curl_setopt($curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
  624. if (!empty($data)) {
  625. curl_setopt($curl, CURLOPT_POST, 1);
  626. curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  627. }
  628. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  629. $output = curl_exec($curl);
  630. curl_close($curl);
  631. return $output;
  632. } else {
  633. return false;
  634. }
  635. }
  636. /**
  637. * 获取客户端IP地址
  638. * @param integer $type 返回类型 0 返回IP地址 1 返回IPV4地址数字
  639. * @return mixed
  640. */
  641. function get_client_ip($type = 0)
  642. {
  643. $type = $type ? 1 : 0;
  644. static $ip = NULL;
  645. if ($ip !== NULL) return $ip[$type];
  646. if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
  647. $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
  648. $pos = array_search('unknown', $arr);
  649. if (false !== $pos) unset($arr[$pos]);
  650. $ip = trim($arr[0]);
  651. } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
  652. $ip = $_SERVER['HTTP_CLIENT_IP'];
  653. } elseif (isset($_SERVER['REMOTE_ADDR'])) {
  654. $ip = $_SERVER['REMOTE_ADDR'];
  655. }
  656. // IP地址合法验证
  657. $long = sprintf("%u", ip2long($ip));
  658. $ip = $long ? [$ip, $long] : ['0.0.0.0', 0];
  659. return $ip[$type];
  660. }
  661. /**
  662. *计算坐标点周围某段距离的正方形的四个点
  663. * @param lng float 经度
  664. * @param lat float 纬度
  665. * @param distance float 该点所在圆的半径,该圆与此正方形内切,默认值为0.5千米
  666. * @return array 正方形的四个点的经纬度坐标
  667. */
  668. function square_point($lng, $lat, $distance = 0.5)
  669. {
  670. $earth_radius = 6378.138;
  671. $dlng = 2 * asin(sin($distance / (2 * $earth_radius)) / cos(deg2rad($lat)));
  672. $dlng = rad2deg($dlng);
  673. $dlat = $distance / $earth_radius;
  674. $dlat = rad2deg($dlat);
  675. return [
  676. 'lt' => ['lat' => $lat + $dlat, 'lng' => $lng - $dlng],
  677. 'rt' => ['lat' => $lat + $dlat, 'lng' => $lng + $dlng],
  678. 'lb' => ['lat' => $lat - $dlat, 'lng' => $lng - $dlng],
  679. 'rb' => ['lat' => $lat - $dlat, 'lng' => $lng + $dlng],
  680. ];
  681. }
  682. /**
  683. * @return string
  684. * @throws ErrorException
  685. */
  686. function getAddressByIp()
  687. {
  688. $ip = request()->ip();
  689. if (cache()->has($ip . "_address")) {
  690. return cache($ip . "_address");
  691. }
  692. $curl = new CurlService();
  693. $curl->setOpt(CURLOPT_HTTPHEADER, [
  694. 'Content-Type:application/json',
  695. 'charset=utf-8', //编码
  696. ]);
  697. $curl->setTimeout(2);
  698. $curl->setOpt(CURLOPT_SSL_VERIFYHOST, 0);
  699. $curl->setOpt(CURLOPT_SSL_VERIFYPEER, 0);
  700. $res = $curl->get('http://ip.taobao.com/service/getIpInfo.php?ip=' . $ip);
  701. try {
  702. $res = json_decode($res);
  703. if (isset($res->data->region)) {
  704. $address = $res->data->region . '-' . $res->data->city;
  705. cache()->put($ip . "_address", $address, 24 * 60);
  706. return $address;
  707. }
  708. return "未知";
  709. } catch (\Exception $exception) {
  710. return "未知";
  711. }
  712. }
  713. function isCreditNo($vStr)
  714. {
  715. $vCity = [
  716. '11', '12', '13', '14', '15', '21', '22',
  717. '23', '31', '32', '33', '34', '35', '36',
  718. '37', '41', '42', '43', '44', '45', '46',
  719. '50', '51', '52', '53', '54', '61', '62',
  720. '63', '64', '65', '71', '81', '82', '91',
  721. ];
  722. if (!preg_match('/^([\d]{17}[xX\d]|[\d]{15})$/', $vStr)) return false;
  723. if (!in_array(substr($vStr, 0, 2), $vCity)) return false;
  724. $vStr = preg_replace('/[xX]$/i', 'a', $vStr);
  725. $vLength = strlen($vStr);
  726. if ($vLength == 18) {
  727. $vBirthday = substr($vStr, 6, 4) . '-' . substr($vStr, 10, 2) . '-' . substr($vStr, 12, 2);
  728. } else {
  729. $vBirthday = '19' . substr($vStr, 6, 2) . '-' . substr($vStr, 8, 2) . '-' . substr($vStr, 10, 2);
  730. }
  731. if (date('Y-m-d', strtotime($vBirthday)) != $vBirthday) return false;
  732. if ($vLength == 18) {
  733. $vSum = 0;
  734. for ($i = 17; $i >= 0; $i--) {
  735. $vSubStr = substr($vStr, 17 - $i, 1);
  736. $vSum += (pow(2, $i) % 11) * (($vSubStr == 'a') ? 10 : intval($vSubStr, 11));
  737. }
  738. if ($vSum % 11 != 1) return false;
  739. }
  740. return true;
  741. }
  742. function getResumeStatus()
  743. {
  744. if (config('aix.personal_set.per_set.show_set.resume_display') == 2) {
  745. $date = [1, 2];
  746. } else {
  747. $date = [2];
  748. }
  749. return $date;
  750. }
  751. function getJobsStatus()
  752. {
  753. if (config('aix.companyset.comset.show_set.jobs_display') == 1) {
  754. $date = [1];
  755. } else {
  756. $date = [1, 2];
  757. }
  758. return $date;
  759. }
  760. function getLastDates($counts)
  761. {
  762. $days = [];
  763. for ($i = $counts; $i >= 0; $i--) {
  764. $days[] = date("Y-m-d", strtotime('-' . $i . 'day'));
  765. }
  766. return $days;
  767. }
  768. function string_to_array($delimiters, $str, $default = [])
  769. {
  770. if (empty($str)) {
  771. return $default;
  772. }
  773. $delimiter = is_array($delimiters) ? $delimiters[0] : $delimiters;
  774. if (is_array($delimiters)) {
  775. $str = str_replace($delimiters, $delimiter, $str);
  776. }
  777. return array_map('change_number_to_int', explode($delimiter, $str));
  778. }
  779. function change_number_to_int($val)
  780. {
  781. if (is_numeric($val)) {
  782. return intval($val);
  783. }
  784. return $val;
  785. }
  786. /**
  787. * 触发搜索引擎更新事件
  788. * @param string $model
  789. * @param array|string $where
  790. * @param string $operate_type
  791. */
  792. function event_search_update(string $model, $where, string $operate_type)
  793. {
  794. event(new \App\Search\Events\SearchUpdateEvent($model, $where, $operate_type));
  795. }
  796. function getComUserName($company_id)
  797. {
  798. $company = \App\Models\Company::where('id', $company_id)->select(['username'])->first();
  799. return $company->username;
  800. }
  801. function handle_seo_info($seoInfo)
  802. {
  803. if (isset($seoInfo) || !is_array($seoInfo)) {
  804. return false;
  805. }
  806. //var_dump($pageSeo);
  807. $pageSeoJson = json_encode($seoInfo);
  808. //替换系统配置变量
  809. $searchs = ['{#site_name}', '{#site_domain}', '{#site_keywords}', '{#site_description}'];
  810. $replaces = [subsite_config('aix.system.site.site.site_name'),
  811. config('aix.system.site.site.site_domain'),
  812. subsite_config('aix.system.site.site.site_keyword'),
  813. subsite_config('aix.system.site.site.site_description')];
  814. $pageSeoJson = str_replace($searchs, $replaces, $pageSeoJson);
  815. //var_dump($pageSeoJson);
  816. //替换传递变量
  817. $seoData = View::shared('seo_data', []);
  818. preg_match_all('/(?:\{\$)(.*?)(?:\})/', $pageSeoJson, $matchers);
  819. //var_dump($matchers);
  820. if ($matchers) {
  821. foreach ($matchers[1] as $index => $template) {
  822. $replace_value = "";
  823. if (count(explode('.', $template)) > 1) {
  824. list($subject, $property) = explode('.', $template, 2);
  825. $replace_value = isset($seoData[$subject][$property]) ? $seoData[$subject][$property] : "";
  826. }
  827. $pageSeoJson = str_replace($matchers[0][$index], $replace_value, $pageSeoJson);
  828. }
  829. }
  830. //var_dump(json_decode($pageSeoJson, true));
  831. return json_decode($pageSeoJson, true);
  832. }
  833. /**
  834. * 根据域名获取分站id
  835. * @return bool|int
  836. */
  837. function get_subsite_id()
  838. {
  839. $subsiteService = app('App\Services\SubsiteService');
  840. return $subsiteService->getSiteId();
  841. }
  842. function get_subsite_sitename($subsite_id)
  843. {
  844. $subsiteRepository = app('App\Repositories\SubsiteRepository');
  845. $result = $subsiteRepository->find($subsite_id);
  846. return $result->sitename;
  847. }
  848. /**
  849. * 根据域名获取分站域名
  850. * @return bool|int
  851. */
  852. function get_subsite_domain($subsite_id = 0)
  853. {
  854. $subsiteService = app('App\Services\SubsiteService');
  855. return $subsiteService->getSubsiteDomain($subsite_id);
  856. }
  857. /**
  858. * 根据用户获取剩余分站信息。
  859. * @param $user
  860. * @return mixed
  861. */
  862. function get_subsite_by_user($user)
  863. {
  864. $subsiteService = app('App\Services\SubsiteService');
  865. return $subsiteService->getSubsite($user);
  866. }
  867. /**
  868. * 根据所有站点信息。
  869. * @param $user
  870. * @return mixed
  871. */
  872. function get_all_subsite()
  873. {
  874. $subsiteService = app('App\Services\SubsiteService');
  875. return $subsiteService->getAllSubsite();
  876. }
  877. function get_subsite_open()
  878. {
  879. return get_all_subsite() ? true : false;
  880. }
  881. /**
  882. * 下截文件到本地
  883. * @param $url
  884. * @param $path
  885. * @return string
  886. */
  887. function download($url, $path)
  888. {
  889. $content = file_get_contents($url);
  890. \Illuminate\Support\Facades\Storage::disk('public')->put($path, $content);
  891. return \Illuminate\Support\Facades\Storage::disk('public')->url($path);
  892. }
  893. if (!function_exists('get_sitename')) {
  894. function get_sitename($id)
  895. {
  896. $subsiteRepository = app('App\Repositories\SubsiteRepository');
  897. $result = $subsiteRepository->findWhereIn('id', $id);
  898. foreach ($result as $key => $val) {
  899. $res[] = $val->sitename;
  900. }
  901. return implode(',', $res);
  902. }
  903. }
  904. /**
  905. * 判断是否是在微信公众号打开的
  906. */
  907. if (!function_exists('is_weixin')) {
  908. function is_weixin()
  909. {
  910. if (Str::contains(request()->userAgent(), ["MicroMessenger"])) {
  911. return true;
  912. } else {
  913. return false;
  914. }
  915. }
  916. }
  917. /**
  918. * 判断是否是在IE浏览器打开
  919. */
  920. if (!function_exists('is_ie')) {
  921. function is_ie()
  922. {
  923. if (Str::contains(request()->userAgent(), ["Trident", "MSIE"])) {
  924. return true;
  925. } else {
  926. return false;
  927. }
  928. }
  929. }
  930. /**
  931. * 是否访问手机端路由
  932. * @return bool
  933. */
  934. function is_mobile_route()
  935. {
  936. if (Str::contains(request()->route()->getPrefix(), 'mobile')) {
  937. return true;
  938. }
  939. return false;
  940. }
  941. /**
  942. * 是否访问硬件平板路由
  943. * @return bool
  944. */
  945. function is_pad_route()
  946. {
  947. if (Str::contains(request()->route()->getPrefix(), 'pad')) {
  948. return true;
  949. }
  950. return false;
  951. }
  952. /**
  953. * 是否访问才情系统
  954. * @return bool
  955. */
  956. function is_statistics_route()
  957. {
  958. if (Str::contains(request()->route()->getPrefix(), 'statistics')) {
  959. return true;
  960. }
  961. return false;
  962. }
  963. /**
  964. * 获取分站的配置,如果没有则返回正常的系统配置
  965. * @param $key
  966. * @param null $default
  967. * @param null $subsite_id 指定分站id,否则会自动获取
  968. * @return \Illuminate\Config\Repository|mixed
  969. */
  970. function subsite_config($key, $default = null, $subsite_id = null)
  971. {
  972. $subsiteService = app('App\Services\SubsiteService');
  973. return $subsiteService->getSubsiteConfig($key, $default, $subsite_id);
  974. }
  975. if (!function_exists('format_wage')) {
  976. function format_wage($wage)
  977. {
  978. $format_wae = preg_replace('/([\x80-\xff]*)/i', '', $wage);
  979. $format_wae = str_replace('/', '', $format_wae);
  980. return $format_wae;
  981. }
  982. }
  983. if (!function_exists('explode_wage')) {
  984. function explode_wage($wage)
  985. {
  986. if (preg_match_all('(\d+)', $wage, $reg)) {
  987. $reg = $reg[0];
  988. $min = $reg[0];
  989. if (count($reg) > 1) {
  990. $max = $reg[1];
  991. } else {
  992. $max = 0;
  993. }
  994. } else {
  995. $min = $wage;
  996. $max = 0;
  997. }
  998. $format_wae = [
  999. ['wage_min', '>=', $min],
  1000. ['wage_max', '<=', $max],
  1001. ];
  1002. return $format_wae;
  1003. }
  1004. }
  1005. /*
  1006. 字段单独验证
  1007. */
  1008. function fieldRegex($value, $rule)
  1009. {
  1010. $validate = [
  1011. 'require' => '/.+/',
  1012. 'email' => '/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/',
  1013. 'mobile' => '/^13[0-9]{9}$|14[0-9]{9}$|15[0-9]{9}$|18[0-9]{9}$|17[0-9]{9}$|19[0-9]{9}$/',
  1014. 'tel' => '/^(([0\\+]\\d{2,3}-)?(0\\d{2,3})-)?(\\d{7,8})(-(\\d{3,}))?$/',
  1015. 'url' => '/^http(s?):\/\/(?:[A-za-z0-9-]+\.)+[A-za-z]{2,4}(?:[\/\?#][\/=\?%\-&~`@[\]\':+!\.#\w]*)?$/',
  1016. 'currency' => '/^\d+(\.\d+)?$/',
  1017. 'number' => '/^\d+$/',
  1018. 'zip' => '/^\d{6}$/',
  1019. 'integer' => '/^[-\+]?\d+$/',
  1020. 'double' => '/^[-\+]?\d+(\.\d+)?$/',
  1021. 'english' => '/^[A-Za-z]+$/',
  1022. 'img' => '(.*)\\.(jpg|bmp|gif|ico|pcx|jpeg|tif|png|raw|tga)$/',
  1023. 'in' => '/^(\d{1,10},)*(\d{1,10})$/',
  1024. 'qq' => '/^[1-9]*[1-9][0-9]*$/',
  1025. ];
  1026. // 检查是否有内置的正则表达式
  1027. if (isset($validate[strtolower($rule)]))
  1028. $rule = $validate[strtolower($rule)];
  1029. return preg_match($rule, $value) === 1;
  1030. }
  1031. if (!function_exists('dealContactPhone')) {
  1032. function dealContactPhone($phone)
  1033. {
  1034. $landline_tel = explode('-', $phone);
  1035. $tel_arr = [];
  1036. foreach ($landline_tel as $k => $v) {
  1037. if ($v) {
  1038. $tel_arr[] = $v;
  1039. }
  1040. }
  1041. return implode('-', $tel_arr);
  1042. }
  1043. }
  1044. function getCompanyName($company_id)
  1045. {
  1046. $Company = \App\Models\Company::find($company_id);
  1047. return $Company;
  1048. }
  1049. /**
  1050. * @param $uid
  1051. * @param $utype 1企业, 2个人
  1052. * @return string
  1053. */
  1054. function hashid_encode($uid, $utype)
  1055. {
  1056. if ($utype == 1) {
  1057. $uid = '10' . $uid;
  1058. } else {
  1059. $uid = '20' . $uid;
  1060. }
  1061. $hashid = new \Hashids\Hashids(config('app.name'), 16);
  1062. return $hashid->encode($uid);
  1063. }
  1064. /**
  1065. * @param $hash_id
  1066. * @return mixed
  1067. */
  1068. function hashid_decode($hash_id)
  1069. {
  1070. $hashid = new \Hashids\Hashids(config('app.name'), 16);
  1071. $uid = $hashid->decode($hash_id);
  1072. if (!$uid) {
  1073. return false;
  1074. }
  1075. $res['utype'] = substr($uid[0], 0, 1);
  1076. $res['id'] = substr($uid[0], 2);
  1077. return $res;
  1078. }
  1079. /**
  1080. * 获取二维码
  1081. * @param string $content 二维码内容
  1082. * @param bool|string $useLogo 是否使用logo,默认使用网站logo,如果使用自定义可以传logo地址(绝对).
  1083. * @param int $htmlSize img标签的大小
  1084. * @param int $htmlMargin img标签的边距
  1085. * @param int $imageSize 二维码图片的大小
  1086. * @param int $imageMargin 二维码图片的边距
  1087. * @return string 返回html img标签
  1088. */
  1089. function get_qrcode_html(
  1090. string $content,
  1091. $useLogo = false,
  1092. int $htmlSize = 250,
  1093. int $htmlMargin = 0,
  1094. int $imageSize = 300,
  1095. int $imageMargin = 2
  1096. )
  1097. {
  1098. if ($useLogo !== false && !file_exists($useLogo)) {
  1099. $useLogo = public_path('images/logo.png');
  1100. }
  1101. $qrcode = \SimpleSoftwareIO\QrCode\Facades\QrCode::format('png')
  1102. ->size($imageSize)
  1103. ->margin($imageMargin)
  1104. ->encoding('utf-8')
  1105. ->errorCorrection("Q");
  1106. if ($useLogo !== false) {
  1107. $qrcode->merge($useLogo, 0.2, true);
  1108. }
  1109. $img = base64_encode($qrcode->generate($content));
  1110. return "<img style='width:{$htmlSize}px;height:{$htmlSize}px;margin:{$htmlMargin};' src='data:image/png;base64,{$img}'>";
  1111. }
  1112. /**
  1113. * 获取二维码
  1114. * @param string $content 二维码内容
  1115. * @param bool|string $useLogo 是否使用logo,默认使用网站logo,如果使用自定义可以传logo地址.
  1116. * @param int $size 二维码图片大小
  1117. * @param int $margin 二维码图片边距
  1118. * @param string $saveFloder 保存的文件夹,相对路径,可以多层,例如 'image/','image/qrcode/'
  1119. * @return string 返回图片的相对地址.
  1120. */
  1121. function get_qrcode_file(string $content, $useLogo = false, int $size = 240, int $margin = 2, $saveFloder = '')
  1122. {
  1123. if ($useLogo !== false && !file_exists($useLogo)) {
  1124. $useLogo = public_path('images/logo.png');
  1125. }
  1126. //生成png,返回图片url
  1127. $filename = 'qrcode/' . $saveFloder . md5($content . $useLogo . $size . $margin) . '.png';
  1128. if (\Illuminate\Support\Facades\Storage::disk('public')->exists($filename)) {
  1129. return $filename;
  1130. }
  1131. $qrcode = \SimpleSoftwareIO\QrCode\Facades\QrCode::format('png')
  1132. ->size($size)
  1133. ->margin($margin)
  1134. ->encoding('utf-8')
  1135. ->errorCorrection("Q");
  1136. if ($useLogo !== false) {
  1137. $qrcode->merge($useLogo, 0.2, true);
  1138. }
  1139. $img = $qrcode->generate($content);
  1140. \Illuminate\Support\Facades\Storage::disk('public')->put($filename, $img);
  1141. return $filename;
  1142. }
  1143. if (!function_exists('get_sex')) {
  1144. /**
  1145. * 根据身份证号码获取性别
  1146. * @param string $idcard 身份证号码
  1147. * @return int $sex 性别 1男 2女 0未知
  1148. */
  1149. function get_sex($idcard)
  1150. {
  1151. if (empty($idcard)) return null;
  1152. $sexint = (int)substr($idcard, 16, 1);
  1153. return $sexint % 2 === 0 ? '女' : '男';
  1154. }
  1155. }
  1156. if (!function_exists('get_birthday')) {
  1157. /**
  1158. * 根据身份证号码获取生日
  1159. * @param string $idcard 身份证号码
  1160. * @return $birthday
  1161. */
  1162. function get_birthday($idcard)
  1163. {
  1164. if (empty($idcard)) return null;
  1165. $bir = substr($idcard, 6, 8);
  1166. $year = (int)substr($bir, 0, 4);
  1167. return $year;
  1168. }
  1169. }
  1170. function apiAddress($address)
  1171. {
  1172. $url = 'https://api.map.baidu.com/geocoder/v2/?address=' . $address . '&output=json&ak=' . subsite_config('aix.system.map.map.map_ak') . "&s=1";
  1173. try {
  1174. if ($result = file_get_contents($url)) {
  1175. $data = [];
  1176. $res = json_decode($result, true);
  1177. if ($res['status'] == 0) {
  1178. $results = $res['result'];
  1179. $data['lng'] = $results['location']['lng'];
  1180. $data['lat'] = $results['location']['lat'];
  1181. }
  1182. return $data;
  1183. }
  1184. } catch (Exception $exception) {
  1185. return [];
  1186. }
  1187. }
  1188. if (!function_exists('landline_tel')) {
  1189. /**
  1190. * 座机去掉最后一个-
  1191. * @param string $landline_tel 座机号码
  1192. * @return $landline_tel
  1193. */
  1194. function landline_tel($landline_tel)
  1195. {
  1196. if (empty($landline_tel)) return null;
  1197. $arr_tel = explode('-', $landline_tel);
  1198. $landline_tel = '';
  1199. if (isset($arr_tel[0]) && $arr_tel[0] != '') {
  1200. $landline_tel .= $arr_tel[0];
  1201. }
  1202. if (isset($arr_tel[1]) && $arr_tel[1] != '') {
  1203. $landline_tel .= '-' . $arr_tel[1];
  1204. }
  1205. if (isset($arr_tel[2]) && $arr_tel[2] != '') {
  1206. $landline_tel .= '-' . $arr_tel[2];
  1207. }
  1208. return $landline_tel;
  1209. }
  1210. }
  1211. if (!function_exists('getUser')) {
  1212. /**
  1213. * 获取登陆信息
  1214. * @return $user
  1215. */
  1216. function getUser()
  1217. {
  1218. $user = [];
  1219. if (auth('web-member')->check()) {
  1220. $user = auth('web-member')->user();
  1221. } elseif (auth('web-company')->check()) {
  1222. $user = auth('web-company')->user();
  1223. }
  1224. return $user;
  1225. }
  1226. }
  1227. if (!function_exists('getOrderType')) {
  1228. /**
  1229. * 获取订单类型
  1230. * @return $user
  1231. */
  1232. function getOrderType($id)
  1233. {
  1234. $ordertype = [
  1235. 1 => "套餐升级", 2 => "充值积分", 3 => "简历置顶", 4 => "醒目标签", 5 => "简历模板", 6 => "简历包", 7 => "短信包", 8 => "职位置顶", 9 => "职位紧急", 10 => "企业模板", 12 => "预约刷新职位", 13 => "职位刷新", 14 => "简历下载", 15 => "职位包", 16 => "招聘会包",
  1236. ];
  1237. if (!isset($ordertype[$id])) {
  1238. return "其他";
  1239. } else {
  1240. return $ordertype[$id];
  1241. }
  1242. }
  1243. }
  1244. if (!function_exists('isExpire')) {
  1245. /**
  1246. * 判断套餐是否到期
  1247. * @return $user
  1248. */
  1249. function isExpire(\App\Models\MembersSetmeal $mySetmeal): bool
  1250. {
  1251. if (empty($mySetmeal)) {
  1252. return true;
  1253. }
  1254. if (strtotime($mySetmeal->endtime) < time() && $mySetmeal->endtime != 0) {
  1255. return true;
  1256. } else {
  1257. return false;
  1258. }
  1259. }
  1260. }
  1261. if (!function_exists('getMsImg')) {
  1262. /**
  1263. * 获取套餐图片
  1264. * @return $user
  1265. */
  1266. function getMsImg($mySetmeal_id = null): string
  1267. {
  1268. if (empty($mySetmeal_id)) {
  1269. $user = auth('web-company')->user();
  1270. $MS = \App\Models\MembersSetmeal::where('uid', $user->id);
  1271. $mySetmeal_id = $MS->setmeal_img;
  1272. }
  1273. $result = Cache::get('setmeals' . $mySetmeal_id);
  1274. if (null === $result) {
  1275. $setmeal = \App\Models\Setmeal::find($mySetmeal_id);
  1276. Cache::put('setmeals' . $mySetmeal_id, serialize($setmeal), 86400);
  1277. } else {
  1278. $setmeal = unserialize($result);
  1279. }
  1280. if (!empty($setmeal->setmeal_img)) { //上传图标不为空
  1281. return "/storage/" . $setmeal->setmeal_img;
  1282. } else {
  1283. return attach($setmeal->id . '.png', 'setmeal_img');
  1284. }
  1285. }
  1286. }
  1287. /**
  1288. * @param $data
  1289. * @param int $code
  1290. * @param string $status
  1291. * @return \Illuminate\Http\JsonResponse
  1292. * ajax 成功的请求返回
  1293. */
  1294. if (!function_exists('AjaxSuccess')) {
  1295. function AjaxSuccess($data, $code = 200, $message = "success")
  1296. {
  1297. return response()->json(['status' => $code, 'msg' => $message, 'data' => $data]);
  1298. }
  1299. }
  1300. /**
  1301. * @param $data
  1302. * @param int $code
  1303. * @param string $status
  1304. * @return \Illuminate\Http\JsonResponse
  1305. * ajax 失败的请求返回
  1306. */
  1307. if (!function_exists('AjaxError')) {
  1308. function AjaxError($data, $status = 0)
  1309. {
  1310. return response()->json(['status' => $status, 'msg' => $data]);
  1311. }
  1312. }
  1313. function vali_person_reg($card_t_cn, $value)
  1314. {
  1315. if ($card_t_cn == 306) {
  1316. if (isCreditNo($value)) {
  1317. return true;
  1318. }
  1319. } elseif ($card_t_cn == 307) {
  1320. if (isCreditNo($value, $card_t_cn)) {
  1321. return true;
  1322. }
  1323. } elseif ($card_t_cn == 308) {
  1324. if (isCreditNo($value, $card_t_cn)) {
  1325. return true;
  1326. }
  1327. } elseif ($card_t_cn == 309) {
  1328. if (isCreditNo($value, $card_t_cn)) {
  1329. return true;
  1330. }
  1331. } elseif ($card_t_cn == 310) {
  1332. if (preg_match('/^H[0-9]{10}$/', $value)) {
  1333. return true;
  1334. }
  1335. } elseif ($card_t_cn == 311) {
  1336. if (preg_match('/^[0-9]{8}$/', $value)) {
  1337. return true;
  1338. }
  1339. } elseif ($card_t_cn == 312) {
  1340. if (preg_match('/^M[0-9]{10}$/', $value)) {
  1341. return true;
  1342. }
  1343. } else {
  1344. if (isCreditNo($value)) {
  1345. return true;
  1346. }
  1347. }
  1348. return false;
  1349. }