helpers.php 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470
  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,$header = 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($header)){
  625. curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
  626. curl_setopt($curl, CURLOPT_HEADER, 0);//返回response头部信息
  627. }
  628. if (!empty($data)) {
  629. curl_setopt($curl, CURLOPT_POST, 1);
  630. curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  631. }
  632. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  633. $output = curl_exec($curl);
  634. curl_close($curl);
  635. return $output;
  636. } else {
  637. return false;
  638. }
  639. }
  640. /**
  641. * 获取客户端IP地址
  642. * @param integer $type 返回类型 0 返回IP地址 1 返回IPV4地址数字
  643. * @return mixed
  644. */
  645. function get_client_ip($type = 0)
  646. {
  647. $type = $type ? 1 : 0;
  648. static $ip = NULL;
  649. if ($ip !== NULL) return $ip[$type];
  650. if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
  651. $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
  652. $pos = array_search('unknown', $arr);
  653. if (false !== $pos) unset($arr[$pos]);
  654. $ip = trim($arr[0]);
  655. } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
  656. $ip = $_SERVER['HTTP_CLIENT_IP'];
  657. } elseif (isset($_SERVER['REMOTE_ADDR'])) {
  658. $ip = $_SERVER['REMOTE_ADDR'];
  659. }
  660. // IP地址合法验证
  661. $long = sprintf("%u", ip2long($ip));
  662. $ip = $long ? [$ip, $long] : ['0.0.0.0', 0];
  663. return $ip[$type];
  664. }
  665. /**
  666. *计算坐标点周围某段距离的正方形的四个点
  667. * @param lng float 经度
  668. * @param lat float 纬度
  669. * @param distance float 该点所在圆的半径,该圆与此正方形内切,默认值为0.5千米
  670. * @return array 正方形的四个点的经纬度坐标
  671. */
  672. function square_point($lng, $lat, $distance = 0.5)
  673. {
  674. $earth_radius = 6378.138;
  675. $dlng = 2 * asin(sin($distance / (2 * $earth_radius)) / cos(deg2rad($lat)));
  676. $dlng = rad2deg($dlng);
  677. $dlat = $distance / $earth_radius;
  678. $dlat = rad2deg($dlat);
  679. return [
  680. 'lt' => ['lat' => $lat + $dlat, 'lng' => $lng - $dlng],
  681. 'rt' => ['lat' => $lat + $dlat, 'lng' => $lng + $dlng],
  682. 'lb' => ['lat' => $lat - $dlat, 'lng' => $lng - $dlng],
  683. 'rb' => ['lat' => $lat - $dlat, 'lng' => $lng + $dlng],
  684. ];
  685. }
  686. /**
  687. * @return string
  688. * @throws ErrorException
  689. */
  690. function getAddressByIp()
  691. {
  692. $ip = request()->ip();
  693. if (cache()->has($ip . "_address")) {
  694. return cache($ip . "_address");
  695. }
  696. $curl = new CurlService();
  697. $curl->setOpt(CURLOPT_HTTPHEADER, [
  698. 'Content-Type:application/json',
  699. 'charset=utf-8', //编码
  700. ]);
  701. $curl->setTimeout(2);
  702. $curl->setOpt(CURLOPT_SSL_VERIFYHOST, 0);
  703. $curl->setOpt(CURLOPT_SSL_VERIFYPEER, 0);
  704. $res = $curl->get('http://ip.taobao.com/service/getIpInfo.php?ip=' . $ip);
  705. try {
  706. $res = json_decode($res);
  707. if (isset($res->data->region)) {
  708. $address = $res->data->region . '-' . $res->data->city;
  709. cache()->put($ip . "_address", $address, 24 * 60);
  710. return $address;
  711. }
  712. return "未知";
  713. } catch (\Exception $exception) {
  714. return "未知";
  715. }
  716. }
  717. function isCreditNo($vStr)
  718. {
  719. $vCity = [
  720. '11', '12', '13', '14', '15', '21', '22',
  721. '23', '31', '32', '33', '34', '35', '36',
  722. '37', '41', '42', '43', '44', '45', '46',
  723. '50', '51', '52', '53', '54', '61', '62',
  724. '63', '64', '65', '71', '81', '82', '91',
  725. ];
  726. if (!preg_match('/^([\d]{17}[xX\d]|[\d]{15})$/', $vStr)) return false;
  727. if (!in_array(substr($vStr, 0, 2), $vCity)) return false;
  728. $vStr = preg_replace('/[xX]$/i', 'a', $vStr);
  729. $vLength = strlen($vStr);
  730. if ($vLength == 18) {
  731. $vBirthday = substr($vStr, 6, 4) . '-' . substr($vStr, 10, 2) . '-' . substr($vStr, 12, 2);
  732. } else {
  733. $vBirthday = '19' . substr($vStr, 6, 2) . '-' . substr($vStr, 8, 2) . '-' . substr($vStr, 10, 2);
  734. }
  735. if (date('Y-m-d', strtotime($vBirthday)) != $vBirthday) return false;
  736. if ($vLength == 18) {
  737. $vSum = 0;
  738. for ($i = 17; $i >= 0; $i--) {
  739. $vSubStr = substr($vStr, 17 - $i, 1);
  740. $vSum += (pow(2, $i) % 11) * (($vSubStr == 'a') ? 10 : intval($vSubStr, 11));
  741. }
  742. if ($vSum % 11 != 1) return false;
  743. }
  744. return true;
  745. }
  746. function getResumeStatus()
  747. {
  748. if (config('aix.personal_set.per_set.show_set.resume_display') == 2) {
  749. $date = [1, 2];
  750. } else {
  751. $date = [2];
  752. }
  753. return $date;
  754. }
  755. function getJobsStatus()
  756. {
  757. if (config('aix.companyset.comset.show_set.jobs_display') == 1) {
  758. $date = [1];
  759. } else {
  760. $date = [1, 2];
  761. }
  762. return $date;
  763. }
  764. function getLastDates($counts)
  765. {
  766. $days = [];
  767. for ($i = $counts; $i >= 0; $i--) {
  768. $days[] = date("Y-m-d", strtotime('-' . $i . 'day'));
  769. }
  770. return $days;
  771. }
  772. function string_to_array($delimiters, $str, $default = [])
  773. {
  774. if (empty($str)) {
  775. return $default;
  776. }
  777. $delimiter = is_array($delimiters) ? $delimiters[0] : $delimiters;
  778. if (is_array($delimiters)) {
  779. $str = str_replace($delimiters, $delimiter, $str);
  780. }
  781. return array_map('change_number_to_int', explode($delimiter, $str));
  782. }
  783. function change_number_to_int($val)
  784. {
  785. if (is_numeric($val)) {
  786. return intval($val);
  787. }
  788. return $val;
  789. }
  790. /**
  791. * 触发搜索引擎更新事件
  792. * @param string $model
  793. * @param array|string $where
  794. * @param string $operate_type
  795. */
  796. function event_search_update(string $model, $where, string $operate_type)
  797. {
  798. event(new \App\Search\Events\SearchUpdateEvent($model, $where, $operate_type));
  799. }
  800. function getComUserName($company_id)
  801. {
  802. $company = \App\Models\Company::where('id', $company_id)->select(['username'])->first();
  803. return $company->username;
  804. }
  805. function handle_seo_info($seoInfo)
  806. {
  807. if (isset($seoInfo) || !is_array($seoInfo)) {
  808. return false;
  809. }
  810. //var_dump($pageSeo);
  811. $pageSeoJson = json_encode($seoInfo);
  812. //替换系统配置变量
  813. $searchs = ['{#site_name}', '{#site_domain}', '{#site_keywords}', '{#site_description}'];
  814. $replaces = [subsite_config('aix.system.site.site.site_name'),
  815. config('aix.system.site.site.site_domain'),
  816. subsite_config('aix.system.site.site.site_keyword'),
  817. subsite_config('aix.system.site.site.site_description')];
  818. $pageSeoJson = str_replace($searchs, $replaces, $pageSeoJson);
  819. //var_dump($pageSeoJson);
  820. //替换传递变量
  821. $seoData = View::shared('seo_data', []);
  822. preg_match_all('/(?:\{\$)(.*?)(?:\})/', $pageSeoJson, $matchers);
  823. //var_dump($matchers);
  824. if ($matchers) {
  825. foreach ($matchers[1] as $index => $template) {
  826. $replace_value = "";
  827. if (count(explode('.', $template)) > 1) {
  828. list($subject, $property) = explode('.', $template, 2);
  829. $replace_value = isset($seoData[$subject][$property]) ? $seoData[$subject][$property] : "";
  830. }
  831. $pageSeoJson = str_replace($matchers[0][$index], $replace_value, $pageSeoJson);
  832. }
  833. }
  834. //var_dump(json_decode($pageSeoJson, true));
  835. return json_decode($pageSeoJson, true);
  836. }
  837. /**
  838. * 根据域名获取分站id
  839. * @return bool|int
  840. */
  841. function get_subsite_id()
  842. {
  843. $subsiteService = app('App\Services\SubsiteService');
  844. return $subsiteService->getSiteId();
  845. }
  846. function get_subsite_sitename($subsite_id)
  847. {
  848. $subsiteRepository = app('App\Repositories\SubsiteRepository');
  849. $result = $subsiteRepository->find($subsite_id);
  850. return $result->sitename;
  851. }
  852. /**
  853. * 根据域名获取分站域名
  854. * @return bool|int
  855. */
  856. function get_subsite_domain($subsite_id = 0)
  857. {
  858. $subsiteService = app('App\Services\SubsiteService');
  859. return $subsiteService->getSubsiteDomain($subsite_id);
  860. }
  861. /**
  862. * 根据用户获取剩余分站信息。
  863. * @param $user
  864. * @return mixed
  865. */
  866. function get_subsite_by_user($user)
  867. {
  868. $subsiteService = app('App\Services\SubsiteService');
  869. return $subsiteService->getSubsite($user);
  870. }
  871. /**
  872. * 根据所有站点信息。
  873. * @param $user
  874. * @return mixed
  875. */
  876. function get_all_subsite()
  877. {
  878. $subsiteService = app('App\Services\SubsiteService');
  879. return $subsiteService->getAllSubsite();
  880. }
  881. function get_subsite_open()
  882. {
  883. return get_all_subsite() ? true : false;
  884. }
  885. /**
  886. * 下截文件到本地
  887. * @param $url
  888. * @param $path
  889. * @return string
  890. */
  891. function download($url, $path)
  892. {
  893. $content = file_get_contents($url);
  894. \Illuminate\Support\Facades\Storage::disk('public')->put($path, $content);
  895. return \Illuminate\Support\Facades\Storage::disk('public')->url($path);
  896. }
  897. if (!function_exists('get_sitename')) {
  898. function get_sitename($id)
  899. {
  900. $subsiteRepository = app('App\Repositories\SubsiteRepository');
  901. $result = $subsiteRepository->findWhereIn('id', $id);
  902. foreach ($result as $key => $val) {
  903. $res[] = $val->sitename;
  904. }
  905. return implode(',', $res);
  906. }
  907. }
  908. /**
  909. * 判断是否是在微信公众号打开的
  910. */
  911. if (!function_exists('is_weixin')) {
  912. function is_weixin()
  913. {
  914. if (Str::contains(request()->userAgent(), ["MicroMessenger"])) {
  915. return true;
  916. } else {
  917. return false;
  918. }
  919. }
  920. }
  921. /**
  922. * 判断是否是在IE浏览器打开
  923. */
  924. if (!function_exists('is_ie')) {
  925. function is_ie()
  926. {
  927. if (Str::contains(request()->userAgent(), ["Trident", "MSIE"])) {
  928. return true;
  929. } else {
  930. return false;
  931. }
  932. }
  933. }
  934. /**
  935. * 是否访问手机端路由
  936. * @return bool
  937. */
  938. function is_mobile_route()
  939. {
  940. if (Str::contains(request()->route()->getPrefix(), 'mobile')) {
  941. return true;
  942. }
  943. return false;
  944. }
  945. /**
  946. * 是否访问硬件平板路由
  947. * @return bool
  948. */
  949. function is_pad_route()
  950. {
  951. if (Str::contains(request()->route()->getPrefix(), 'pad')) {
  952. return true;
  953. }
  954. return false;
  955. }
  956. /**
  957. * 是否访问才情系统
  958. * @return bool
  959. */
  960. function is_statistics_route()
  961. {
  962. if (Str::contains(request()->route()->getPrefix(), 'statistics')) {
  963. return true;
  964. }
  965. return false;
  966. }
  967. /**
  968. * 获取分站的配置,如果没有则返回正常的系统配置
  969. * @param $key
  970. * @param null $default
  971. * @param null $subsite_id 指定分站id,否则会自动获取
  972. * @return \Illuminate\Config\Repository|mixed
  973. */
  974. function subsite_config($key, $default = null, $subsite_id = null)
  975. {
  976. $subsiteService = app('App\Services\SubsiteService');
  977. return $subsiteService->getSubsiteConfig($key, $default, $subsite_id);
  978. }
  979. if (!function_exists('format_wage')) {
  980. function format_wage($wage)
  981. {
  982. $format_wae = preg_replace('/([\x80-\xff]*)/i', '', $wage);
  983. $format_wae = str_replace('/', '', $format_wae);
  984. return $format_wae;
  985. }
  986. }
  987. if (!function_exists('explode_wage')) {
  988. function explode_wage($wage)
  989. {
  990. if (preg_match_all('(\d+)', $wage, $reg)) {
  991. $reg = $reg[0];
  992. $min = $reg[0];
  993. if (count($reg) > 1) {
  994. $max = $reg[1];
  995. } else {
  996. $max = 0;
  997. }
  998. } else {
  999. $min = $wage;
  1000. $max = 0;
  1001. }
  1002. $format_wae = [
  1003. ['wage_min', '>=', $min],
  1004. ['wage_max', '<=', $max],
  1005. ];
  1006. return $format_wae;
  1007. }
  1008. }
  1009. /*
  1010. 字段单独验证
  1011. */
  1012. function fieldRegex($value, $rule)
  1013. {
  1014. $validate = [
  1015. 'require' => '/.+/',
  1016. 'email' => '/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/',
  1017. '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}$/',
  1018. 'tel' => '/^(([0\\+]\\d{2,3}-)?(0\\d{2,3})-)?(\\d{7,8})(-(\\d{3,}))?$/',
  1019. 'url' => '/^http(s?):\/\/(?:[A-za-z0-9-]+\.)+[A-za-z]{2,4}(?:[\/\?#][\/=\?%\-&~`@[\]\':+!\.#\w]*)?$/',
  1020. 'currency' => '/^\d+(\.\d+)?$/',
  1021. 'number' => '/^\d+$/',
  1022. 'zip' => '/^\d{6}$/',
  1023. 'integer' => '/^[-\+]?\d+$/',
  1024. 'double' => '/^[-\+]?\d+(\.\d+)?$/',
  1025. 'english' => '/^[A-Za-z]+$/',
  1026. 'img' => '(.*)\\.(jpg|bmp|gif|ico|pcx|jpeg|tif|png|raw|tga)$/',
  1027. 'in' => '/^(\d{1,10},)*(\d{1,10})$/',
  1028. 'qq' => '/^[1-9]*[1-9][0-9]*$/',
  1029. ];
  1030. // 检查是否有内置的正则表达式
  1031. if (isset($validate[strtolower($rule)]))
  1032. $rule = $validate[strtolower($rule)];
  1033. return preg_match($rule, $value) === 1;
  1034. }
  1035. if (!function_exists('dealContactPhone')) {
  1036. function dealContactPhone($phone)
  1037. {
  1038. $landline_tel = explode('-', $phone);
  1039. $tel_arr = [];
  1040. foreach ($landline_tel as $k => $v) {
  1041. if ($v) {
  1042. $tel_arr[] = $v;
  1043. }
  1044. }
  1045. return implode('-', $tel_arr);
  1046. }
  1047. }
  1048. function getCompanyName($company_id)
  1049. {
  1050. $Company = \App\Models\Company::find($company_id);
  1051. return $Company;
  1052. }
  1053. /**
  1054. * @param $uid
  1055. * @param $utype 1企业, 2个人
  1056. * @return string
  1057. */
  1058. function hashid_encode($uid, $utype)
  1059. {
  1060. if ($utype == 1) {
  1061. $uid = '10' . $uid;
  1062. } else {
  1063. $uid = '20' . $uid;
  1064. }
  1065. $hashid = new \Hashids\Hashids(config('app.name'), 16);
  1066. return $hashid->encode($uid);
  1067. }
  1068. /**
  1069. * @param $hash_id
  1070. * @return mixed
  1071. */
  1072. function hashid_decode($hash_id)
  1073. {
  1074. $hashid = new \Hashids\Hashids(config('app.name'), 16);
  1075. $uid = $hashid->decode($hash_id);
  1076. if (!$uid) {
  1077. return false;
  1078. }
  1079. $res['utype'] = substr($uid[0], 0, 1);
  1080. $res['id'] = substr($uid[0], 2);
  1081. return $res;
  1082. }
  1083. /**
  1084. * 获取二维码
  1085. * @param string $content 二维码内容
  1086. * @param bool|string $useLogo 是否使用logo,默认使用网站logo,如果使用自定义可以传logo地址(绝对).
  1087. * @param int $htmlSize img标签的大小
  1088. * @param int $htmlMargin img标签的边距
  1089. * @param int $imageSize 二维码图片的大小
  1090. * @param int $imageMargin 二维码图片的边距
  1091. * @return string 返回html img标签
  1092. */
  1093. function get_qrcode_html(
  1094. string $content,
  1095. $useLogo = false,
  1096. int $htmlSize = 250,
  1097. int $htmlMargin = 0,
  1098. int $imageSize = 300,
  1099. int $imageMargin = 2
  1100. )
  1101. {
  1102. if ($useLogo !== false && !file_exists($useLogo)) {
  1103. $useLogo = public_path('images/logo.png');
  1104. }
  1105. $qrcode = \SimpleSoftwareIO\QrCode\Facades\QrCode::format('png')
  1106. ->size($imageSize)
  1107. ->margin($imageMargin)
  1108. ->encoding('utf-8')
  1109. ->errorCorrection("Q");
  1110. if ($useLogo !== false) {
  1111. $qrcode->merge($useLogo, 0.2, true);
  1112. }
  1113. $img = base64_encode($qrcode->generate($content));
  1114. return "<img style='width:{$htmlSize}px;height:{$htmlSize}px;margin:{$htmlMargin};' src='data:image/png;base64,{$img}'>";
  1115. }
  1116. /**
  1117. * 获取二维码
  1118. * @param string $content 二维码内容
  1119. * @param bool|string $useLogo 是否使用logo,默认使用网站logo,如果使用自定义可以传logo地址.
  1120. * @param int $size 二维码图片大小
  1121. * @param int $margin 二维码图片边距
  1122. * @param string $saveFloder 保存的文件夹,相对路径,可以多层,例如 'image/','image/qrcode/'
  1123. * @return string 返回图片的相对地址.
  1124. */
  1125. function get_qrcode_file(string $content, $useLogo = false, int $size = 240, int $margin = 2, $saveFloder = '')
  1126. {
  1127. if ($useLogo !== false && !file_exists($useLogo)) {
  1128. $useLogo = public_path('images/logo.png');
  1129. }
  1130. //生成png,返回图片url
  1131. $filename = 'qrcode/' . $saveFloder . md5($content . $useLogo . $size . $margin) . '.png';
  1132. if (\Illuminate\Support\Facades\Storage::disk('public')->exists($filename)) {
  1133. return $filename;
  1134. }
  1135. $qrcode = \SimpleSoftwareIO\QrCode\Facades\QrCode::format('png')
  1136. ->size($size)
  1137. ->margin($margin)
  1138. ->encoding('utf-8')
  1139. ->errorCorrection("Q");
  1140. if ($useLogo !== false) {
  1141. $qrcode->merge($useLogo, 0.2, true);
  1142. }
  1143. $img = $qrcode->generate($content);
  1144. \Illuminate\Support\Facades\Storage::disk('public')->put($filename, $img);
  1145. return $filename;
  1146. }
  1147. if (!function_exists('get_sex')) {
  1148. /**
  1149. * 根据身份证号码获取性别
  1150. * @param string $idcard 身份证号码
  1151. * @return int $sex 性别 1男 2女 0未知
  1152. */
  1153. function get_sex($idcard)
  1154. {
  1155. if (empty($idcard)) return null;
  1156. $sexint = (int)substr($idcard, 16, 1);
  1157. return $sexint % 2 === 0 ? '女' : '男';
  1158. }
  1159. }
  1160. if (!function_exists('get_birthday')) {
  1161. /**
  1162. * 根据身份证号码获取生日
  1163. * @param string $idcard 身份证号码
  1164. * @return $birthday
  1165. */
  1166. function get_birthday($idcard)
  1167. {
  1168. if (empty($idcard)) return null;
  1169. $bir = substr($idcard, 6, 8);
  1170. $year = (int)substr($bir, 0, 4);
  1171. return $year;
  1172. }
  1173. }
  1174. function apiAddress($address)
  1175. {
  1176. $url = 'https://api.map.baidu.com/geocoder/v2/?address=' . $address . '&output=json&ak=' . subsite_config('aix.system.map.map.map_ak') . "&s=1";
  1177. try {
  1178. if ($result = file_get_contents($url)) {
  1179. $data = [];
  1180. $res = json_decode($result, true);
  1181. if ($res['status'] == 0) {
  1182. $results = $res['result'];
  1183. $data['lng'] = $results['location']['lng'];
  1184. $data['lat'] = $results['location']['lat'];
  1185. }
  1186. return $data;
  1187. }
  1188. } catch (Exception $exception) {
  1189. return [];
  1190. }
  1191. }
  1192. if (!function_exists('landline_tel')) {
  1193. /**
  1194. * 座机去掉最后一个-
  1195. * @param string $landline_tel 座机号码
  1196. * @return $landline_tel
  1197. */
  1198. function landline_tel($landline_tel)
  1199. {
  1200. if (empty($landline_tel)) return null;
  1201. $arr_tel = explode('-', $landline_tel);
  1202. $landline_tel = '';
  1203. if (isset($arr_tel[0]) && $arr_tel[0] != '') {
  1204. $landline_tel .= $arr_tel[0];
  1205. }
  1206. if (isset($arr_tel[1]) && $arr_tel[1] != '') {
  1207. $landline_tel .= '-' . $arr_tel[1];
  1208. }
  1209. if (isset($arr_tel[2]) && $arr_tel[2] != '') {
  1210. $landline_tel .= '-' . $arr_tel[2];
  1211. }
  1212. return $landline_tel;
  1213. }
  1214. }
  1215. if (!function_exists('getUser')) {
  1216. /**
  1217. * 获取登陆信息
  1218. * @return $user
  1219. */
  1220. function getUser()
  1221. {
  1222. $user = [];
  1223. if (auth('web-member')->check()) {
  1224. $user = auth('web-member')->user();
  1225. } elseif (auth('web-company')->check()) {
  1226. $user = auth('web-company')->user();
  1227. }
  1228. return $user;
  1229. }
  1230. }
  1231. if (!function_exists('getOrderType')) {
  1232. /**
  1233. * 获取订单类型
  1234. * @return $user
  1235. */
  1236. function getOrderType($id)
  1237. {
  1238. $ordertype = [
  1239. 1 => "套餐升级", 2 => "充值积分", 3 => "简历置顶", 4 => "醒目标签", 5 => "简历模板", 6 => "简历包", 7 => "短信包", 8 => "职位置顶", 9 => "职位紧急", 10 => "企业模板", 12 => "预约刷新职位", 13 => "职位刷新", 14 => "简历下载", 15 => "职位包", 16 => "招聘会包",
  1240. ];
  1241. if (!isset($ordertype[$id])) {
  1242. return "其他";
  1243. } else {
  1244. return $ordertype[$id];
  1245. }
  1246. }
  1247. }
  1248. if (!function_exists('isExpire')) {
  1249. /**
  1250. * 判断套餐是否到期
  1251. * @return $user
  1252. */
  1253. function isExpire(\App\Models\MembersSetmeal $mySetmeal): bool
  1254. {
  1255. if (empty($mySetmeal)) {
  1256. return true;
  1257. }
  1258. if (strtotime($mySetmeal->endtime) < time() && $mySetmeal->endtime != 0) {
  1259. return true;
  1260. } else {
  1261. return false;
  1262. }
  1263. }
  1264. }
  1265. if (!function_exists('getMsImg')) {
  1266. /**
  1267. * 获取套餐图片
  1268. * @return $user
  1269. */
  1270. function getMsImg($mySetmeal_id = null): string
  1271. {
  1272. if (empty($mySetmeal_id)) {
  1273. $user = auth('web-company')->user();
  1274. $MS = \App\Models\MembersSetmeal::where('uid', $user->id);
  1275. $mySetmeal_id = $MS->setmeal_img;
  1276. }
  1277. $result = Cache::get('setmeals' . $mySetmeal_id);
  1278. if (null === $result) {
  1279. $setmeal = \App\Models\Setmeal::find($mySetmeal_id);
  1280. Cache::put('setmeals' . $mySetmeal_id, serialize($setmeal), 86400);
  1281. } else {
  1282. $setmeal = unserialize($result);
  1283. }
  1284. if (!empty($setmeal->setmeal_img)) { //上传图标不为空
  1285. return "/storage/" . $setmeal->setmeal_img;
  1286. } else {
  1287. return attach($setmeal->id . '.png', 'setmeal_img');
  1288. }
  1289. }
  1290. }
  1291. /**
  1292. * @param $data
  1293. * @param int $code
  1294. * @param string $status
  1295. * @return \Illuminate\Http\JsonResponse
  1296. * ajax 成功的请求返回
  1297. */
  1298. if (!function_exists('AjaxSuccess')) {
  1299. function AjaxSuccess($data, $code = 200, $message = "success")
  1300. {
  1301. return response()->json(['status' => $code, 'msg' => $message, 'data' => $data]);
  1302. }
  1303. }
  1304. /**
  1305. * @param $data
  1306. * @param int $code
  1307. * @param string $status
  1308. * @return \Illuminate\Http\JsonResponse
  1309. * ajax 失败的请求返回
  1310. */
  1311. if (!function_exists('AjaxError')) {
  1312. function AjaxError($data, $status = 0)
  1313. {
  1314. return response()->json(['status' => $status, 'msg' => $data]);
  1315. }
  1316. }
  1317. function vali_person_reg($card_t_cn, $value)
  1318. {
  1319. if ($card_t_cn == 306) {
  1320. if (isCreditNo($value)) {
  1321. return true;
  1322. }
  1323. } elseif ($card_t_cn == 307) {
  1324. if (isCreditNo($value, $card_t_cn)) {
  1325. return true;
  1326. }
  1327. } elseif ($card_t_cn == 308) {
  1328. if (isCreditNo($value, $card_t_cn)) {
  1329. return true;
  1330. }
  1331. } elseif ($card_t_cn == 309) {
  1332. if (isCreditNo($value, $card_t_cn)) {
  1333. return true;
  1334. }
  1335. } elseif ($card_t_cn == 310) {
  1336. if (preg_match('/^H[0-9]{10}$/', $value)) {
  1337. return true;
  1338. }
  1339. } elseif ($card_t_cn == 311) {
  1340. if (preg_match('/^[0-9]{8}$/', $value)) {
  1341. return true;
  1342. }
  1343. } elseif ($card_t_cn == 312) {
  1344. if (preg_match('/^M[0-9]{10}$/', $value)) {
  1345. return true;
  1346. }
  1347. } else {
  1348. if (isCreditNo($value)) {
  1349. return true;
  1350. }
  1351. }
  1352. return false;
  1353. }