common.php 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. // 应用公共文件
  12. use app\services\pay\PayServices;
  13. use crmeb\services\CacheService;
  14. use crmeb\services\HttpService;
  15. use Fastknife\Service\ClickWordCaptchaService;
  16. use think\exception\ValidateException;
  17. use crmeb\services\FormBuilder as Form;
  18. use app\services\other\UploadService;
  19. use Fastknife\Service\BlockPuzzleCaptchaService;
  20. use app\services\system\lang\LangTypeServices;
  21. use app\services\system\lang\LangCodeServices;
  22. use app\services\system\lang\LangCountryServices;
  23. use think\facade\Config;
  24. use think\facade\Log;
  25. use think\facade\Db;
  26. if (!function_exists('crmebLog')) {
  27. /**
  28. * CRMEB Log 日志
  29. * @param $msg
  30. * @author 吴汐
  31. * @email 442384644@qq.com
  32. * @date 2023/03/03
  33. */
  34. function crmebLog($msg)
  35. {
  36. Log::write($msg, 'crmeb');
  37. }
  38. }
  39. if (!function_exists('success')) {
  40. /**
  41. * 响应助手函数
  42. * @param mixed $msg 响应消息
  43. * @param array|null $data 响应数据
  44. * @param array|null $replace 消息替换数组
  45. * @return \think\Response
  46. * @see \crmeb\utils\Json::success()
  47. */
  48. function success($msg = 'success', ?array $data = null, ?array $replace = [])
  49. {
  50. return app('json')->success($msg, $data, $replace);
  51. }
  52. }
  53. if (!function_exists('fail')) {
  54. /**
  55. * 失败响应助手函数
  56. * @param mixed $msg 响应消息
  57. * @param array|null $data 响应数据
  58. * @param array|null $replace 消息替换数组
  59. * @return \think\Response
  60. * @see \crmeb\utils\Json::fail()
  61. */
  62. function fail($msg = 'fail', ?array $data = null, ?array $replace = [])
  63. {
  64. return app('json')->fail($msg, $data, $replace);
  65. }
  66. }
  67. if (!function_exists('getWorkerManUrl')) {
  68. /**
  69. * 获取客服数据
  70. * @return mixed
  71. */
  72. function getWorkerManUrl()
  73. {
  74. $ws = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'wss://' : 'ws://';
  75. $host = $_SERVER['HTTP_HOST'];
  76. $data['admin'] = $ws . $host . '/notice';
  77. $data['chat'] = $ws . $host . '/msg';
  78. return $data;
  79. }
  80. }
  81. if (!function_exists('object2array')) {
  82. /**
  83. * 对象转数组
  84. * @param $object
  85. * @return array|mixed
  86. */
  87. function object2array($object)
  88. {
  89. $array = [];
  90. if (is_object($object)) {
  91. foreach ($object as $key => $value) {
  92. $array[$key] = $value;
  93. }
  94. } else {
  95. $array = $object;
  96. }
  97. return $array;
  98. }
  99. }
  100. if (!function_exists('exception')) {
  101. /**
  102. * 抛出异常处理
  103. * @param $msg
  104. * @param int $code
  105. * @param string $exception
  106. * @throws \think\Exception
  107. */
  108. function exception($msg, $code = 0, $exception = '')
  109. {
  110. $e = $exception ?: '\think\Exception';
  111. throw new $e($msg, $code);
  112. }
  113. }
  114. if (!function_exists('sys_config')) {
  115. /**
  116. * 获取系统单个配置
  117. * @param string $name
  118. * @param string $default
  119. * @return string
  120. */
  121. function sys_config(string $name, $default = '')
  122. {
  123. if (empty($name))
  124. return $default;
  125. $sysConfig = app('sysConfig')->get($name);
  126. if (is_array($sysConfig)) {
  127. foreach ($sysConfig as &$item) {
  128. if (!is_array($item)) {
  129. if (strpos($item, '/uploads/system/') !== false || strpos($item, '/statics/system_images/') !== false) $item = set_file_url($item);
  130. }
  131. }
  132. } else {
  133. if (strpos($sysConfig, '/uploads/system/') !== false || strpos($sysConfig, '/statics/system_images/') !== false) $sysConfig = set_file_url($sysConfig);
  134. }
  135. $config = is_array($sysConfig) ? $sysConfig : trim($sysConfig);
  136. if ($config === '' || $config === false) {
  137. return $default;
  138. } else {
  139. return $config;
  140. }
  141. }
  142. }
  143. if (!function_exists('sys_data')) {
  144. /**
  145. * 获取系统单个数据
  146. * @param string $name
  147. * @return string
  148. */
  149. function sys_data(string $name, int $limit = 0)
  150. {
  151. return app('sysGroupData')->getData($name, $limit);
  152. }
  153. }
  154. if (!function_exists('filter_emoji')) {
  155. // 过滤掉emoji表情
  156. function filter_emoji($str)
  157. {
  158. $str = preg_replace_callback( //执行一个正则表达式搜索并且使用一个回调进行替换
  159. '/./u',
  160. function (array $match) {
  161. return strlen($match[0]) >= 4 ? '' : $match[0];
  162. },
  163. $str);
  164. return $str;
  165. }
  166. }
  167. if (!function_exists('str_middle_replace')) {
  168. /** TODO 系统未使用
  169. * @param string $string 需要替换的字符串
  170. * @param int $start 开始的保留几位
  171. * @param int $end 最后保留几位
  172. * @return string
  173. */
  174. function str_middle_replace($string, $start, $end)
  175. {
  176. $strlen = mb_strlen($string, 'UTF-8');//获取字符串长度
  177. $firstStr = mb_substr($string, 0, $start, 'UTF-8');//获取第一位
  178. $lastStr = mb_substr($string, -1, $end, 'UTF-8');//获取最后一位
  179. return $strlen == 2 ? $firstStr . str_repeat('*', mb_strlen($string, 'utf-8') - 1) : $firstStr . str_repeat("*", $strlen - 2) . $lastStr;
  180. }
  181. }
  182. if (!function_exists('sensitive_words_filter')) {
  183. /**
  184. * 敏感词过滤
  185. *
  186. * @param string
  187. * @return string
  188. */
  189. function sensitive_words_filter($str)
  190. {
  191. if (!$str) return '';
  192. $file = app()->getAppPath() . 'public/statics/plug/censorwords/CensorWords';
  193. $words = file($file);
  194. foreach ($words as $word) {
  195. $word = str_replace(array("\r\n", "\r", "\n", "/", "<", ">", "=", " "), '', $word);
  196. if (!$word) continue;
  197. $ret = preg_match("/$word/", $str, $match);
  198. if ($ret) {
  199. return $match[0];
  200. }
  201. }
  202. return '';
  203. }
  204. }
  205. if (!function_exists('make_path')) {
  206. /**
  207. * 上传路径转化,默认路径
  208. * @param $path
  209. * @param int $type
  210. * @param bool $force
  211. * @return string
  212. */
  213. function make_path($path, int $type = 2, bool $force = false)
  214. {
  215. $path = DS . ltrim(rtrim($path));
  216. switch ($type) {
  217. case 1:
  218. $path .= DS . date('Y');
  219. break;
  220. case 2:
  221. $path .= DS . date('Y') . DS . date('m');
  222. break;
  223. case 3:
  224. $path .= DS . date('Y') . DS . date('m') . DS . date('d');
  225. break;
  226. }
  227. try {
  228. if (is_dir(app()->getRootPath() . 'public' . DS . 'uploads' . $path) == true || mkdir(app()->getRootPath() . 'public' . DS . 'uploads' . $path, 0777, true) == true) {
  229. return trim(str_replace(DS, '/', $path), '.');
  230. } else return '';
  231. } catch (\Exception $e) {
  232. if ($force)
  233. throw new \Exception($e->getMessage());
  234. // return '无法创建文件夹,请检查您的上传目录权限:' . app()->getRootPath() . 'public' . DS . 'uploads' . DS . 'attach' . DS;
  235. return '';
  236. }
  237. }
  238. }
  239. if (!function_exists('curl_file_exist')) {
  240. /**
  241. * CURL 检测远程文件是否在
  242. * @param $url
  243. * @return bool
  244. */
  245. function curl_file_exist($url)
  246. {
  247. $ch = curl_init();
  248. try {
  249. curl_setopt($ch, CURLOPT_URL, $url);
  250. curl_setopt($ch, CURLOPT_HEADER, 1);
  251. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  252. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
  253. $contents = curl_exec($ch);
  254. if (preg_match("/404/", $contents)) return false;
  255. if (preg_match("/403/", $contents)) return false;
  256. return true;
  257. } catch (\Exception $e) {
  258. return false;
  259. }
  260. }
  261. }
  262. if (!function_exists('set_file_url')) {
  263. /**
  264. * 设置附加路径
  265. * @param $url
  266. * @return bool
  267. */
  268. function set_file_url($image, $siteUrl = '')
  269. {
  270. if (!strlen(trim($siteUrl))) $siteUrl = sys_config('site_url');
  271. if (!$image) return $image;
  272. if (is_array($image)) {
  273. foreach ($image as &$item) {
  274. $domainTop1 = substr($item, 0, 4);
  275. $domainTop2 = substr($item, 0, 2);
  276. if ($domainTop1 != 'http' && $domainTop2 != '//')
  277. $item = $siteUrl . str_replace('\\', '/', $item);
  278. }
  279. } else {
  280. $domainTop1 = substr($image, 0, 4);
  281. $domainTop2 = substr($image, 0, 2);
  282. if ($domainTop1 != 'http' && $domainTop2 != '//')
  283. $image = $siteUrl . str_replace('\\', '/', $image);
  284. }
  285. return $image;
  286. }
  287. }
  288. if (!function_exists('set_http_type')) {
  289. /**
  290. * 修改 https 和 http
  291. * @param string $url 域名
  292. * @param int $type 0 返回https 1 返回 http
  293. * @return string
  294. */
  295. function set_http_type($url, $type = 0)
  296. {
  297. // 基本验证
  298. if (empty($url)) {
  299. return $url;
  300. }
  301. // 检查是否是完整 URL
  302. $is_full_url = (strpos($url, '://') !== false);
  303. if ($is_full_url) {
  304. // 处理完整 URL
  305. if ($type) {
  306. // 转换为 HTTP
  307. $url = preg_replace('/^https:/i', 'http:', $url);
  308. } else {
  309. // 转换为 HTTPS
  310. $url = preg_replace('/^http:/i', 'https:', $url);
  311. }
  312. }
  313. return $url;
  314. }
  315. }
  316. if (!function_exists('check_card')) {
  317. /**
  318. * 身份证验证
  319. * @param $card
  320. * @return bool
  321. */
  322. function check_card($card)
  323. {
  324. $city = [11 => "北京", 12 => "天津", 13 => "河北", 14 => "山西", 15 => "内蒙古", 21 => "辽宁", 22 => "吉林", 23 => "黑龙江 ", 31 => "上海", 32 => "江苏", 33 => "浙江", 34 => "安徽", 35 => "福建", 36 => "江西", 37 => "山东", 41 => "河南", 42 => "湖北 ", 43 => "湖南", 44 => "广东", 45 => "广西", 46 => "海南", 50 => "重庆", 51 => "四川", 52 => "贵州", 53 => "云南", 54 => "西藏 ", 61 => "陕西", 62 => "甘肃", 63 => "青海", 64 => "宁夏", 65 => "新疆", 71 => "台湾", 81 => "香港", 82 => "澳门", 91 => "国外 "];
  325. $tip = "";
  326. $match = "/^\d{6}(18|19|20)?\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/";
  327. $pass = true;
  328. if (!$card || !preg_match($match, $card)) {
  329. //身份证格式错误
  330. $pass = false;
  331. } else if (!$city[substr($card, 0, 2)]) {
  332. //地址错误
  333. $pass = false;
  334. } else {
  335. //18位身份证需要验证最后一位校验位
  336. if (strlen($card) == 18) {
  337. $card = str_split($card);
  338. //∑(ai×Wi)(mod 11)
  339. //加权因子
  340. $factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
  341. //校验位
  342. $parity = [1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2];
  343. $sum = 0;
  344. $ai = 0;
  345. $wi = 0;
  346. for ($i = 0; $i < 17; $i++) {
  347. $ai = $card[$i];
  348. $wi = $factor[$i];
  349. $sum += $ai * $wi;
  350. }
  351. $last = $parity[$sum % 11];
  352. if ($parity[$sum % 11] != $card[17]) {
  353. // $tip = "校验位错误";
  354. $pass = false;
  355. }
  356. } else {
  357. $pass = false;
  358. }
  359. }
  360. if (!$pass) return false;/* 身份证格式错误*/
  361. return true;/* 身份证格式正确*/
  362. }
  363. }
  364. if (!function_exists('check_link')) {
  365. /**
  366. * 地址验证
  367. * @param string $link
  368. * @return false|int
  369. */
  370. function check_link(string $link)
  371. {
  372. return preg_match("/^(http|https|ftp):\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+[\/=\?%\-&_~`@[\]\’:+!]*([^<>\”])*$/", $link);
  373. }
  374. }
  375. if (!function_exists('check_phone')) {
  376. /**
  377. * 手机号验证
  378. * @param $phone
  379. * @return false|int
  380. */
  381. function check_phone($phone)
  382. {
  383. return preg_match("/^1[3456789]\d{9}$/", $phone);
  384. }
  385. }
  386. if (!function_exists('anonymity')) {
  387. /**
  388. * 匿名处理处理用户昵称
  389. * @param $name
  390. * @return string
  391. */
  392. function anonymity($name, $type = 1)
  393. {
  394. if ($type == 1) {
  395. return mb_substr($name, 0, 1, 'UTF-8') . '**' . mb_substr($name, -1, 1, 'UTF-8');
  396. } else {
  397. $strLen = mb_strlen($name, 'UTF-8');
  398. $min = 3;
  399. if ($strLen <= 1)
  400. return '*';
  401. if ($strLen <= $min)
  402. return mb_substr($name, 0, 1, 'UTF-8') . str_repeat('*', $min - 1);
  403. else
  404. return mb_substr($name, 0, 1, 'UTF-8') . str_repeat('*', $strLen - 1) . mb_substr($name, -1, 1, 'UTF-8');
  405. }
  406. }
  407. }
  408. if (!function_exists('sort_list_tier')) {
  409. /**
  410. * 分级排序
  411. * @param $data
  412. * @param int $pid
  413. * @param string $field
  414. * @param string $pk
  415. * @param string $html
  416. * @param int $level
  417. * @param bool $clear
  418. * @return array
  419. */
  420. function sort_list_tier($data, $pid = 0, $field = 'pid', $pk = 'id', $html = '|-----', $level = 1, $clear = true)
  421. {
  422. static $list = [];
  423. if ($clear) $list = [];
  424. foreach ($data as $k => $res) {
  425. if ($res[$field] == $pid) {
  426. $res['html'] = str_repeat($html, $level);
  427. $list[] = $res;
  428. unset($data[$k]);
  429. sort_list_tier($data, $res[$pk], $field, $pk, $html, $level + 1, false);
  430. }
  431. }
  432. return $list;
  433. }
  434. }
  435. if (!function_exists('sort_city_tier')) {
  436. /**
  437. * 城市数据整理
  438. * @param $data
  439. * @param int $pid
  440. * @param string $field
  441. * @param string $pk
  442. * @param string $html
  443. * @param int $level
  444. * @param bool $clear
  445. * @return array
  446. */
  447. function sort_city_tier($data, $pid = 0, $navList = [])
  448. {
  449. foreach ($data as $k => $menu) {
  450. if ($menu['parent_id'] == $pid) {
  451. unset($menu['parent_id']);
  452. unset($data[$k]);
  453. $menu['c'] = sort_city_tier($data, $menu['v']);
  454. $navList[] = $menu;
  455. }
  456. }
  457. return $navList;
  458. }
  459. }
  460. if (!function_exists('time_tran')) {
  461. /**
  462. * 时间戳人性化转化
  463. * @param $time
  464. * @return string
  465. */
  466. function time_tran($time)
  467. {
  468. $t = time() - $time;
  469. $f = array(
  470. '31536000' => '年',
  471. '2592000' => '个月',
  472. '604800' => '星期',
  473. '86400' => '天',
  474. '3600' => '小时',
  475. '60' => '分钟',
  476. '1' => '秒'
  477. );
  478. foreach ($f as $k => $v) {
  479. if (0 != $c = floor($t / (int)$k)) {
  480. return $c . $v . '前';
  481. }
  482. }
  483. }
  484. }
  485. if (!function_exists('url_to_path')) {
  486. /**
  487. * url转换路径
  488. * @param $url
  489. * @return string
  490. */
  491. function url_to_path($url)
  492. {
  493. $path = trim(str_replace('/', DS, $url), DS);
  494. if (0 !== strripos($path, 'public'))
  495. $path = 'public' . DS . $path;
  496. return app()->getRootPath() . $path;
  497. }
  498. }
  499. if (!function_exists('path_to_url')) {
  500. /**
  501. * 路径转url路径
  502. * @param $path
  503. * @return string
  504. */
  505. function path_to_url($path)
  506. {
  507. return trim(str_replace(DS, '/', $path), '.');
  508. }
  509. }
  510. if (!function_exists('image_to_base64')) {
  511. /**
  512. * 获取图片转为base64
  513. * @param string $avatar
  514. * @return bool|string
  515. */
  516. function image_to_base64($avatar = '', $timeout = 9)
  517. {
  518. $avatar = str_replace('https', 'http', $avatar);
  519. try {
  520. $url = parse_url($avatar);
  521. if ($url['scheme'] . '://' . $url['host'] == sys_config('site_url')) {
  522. $pattern = '/<\?php(.*?)\?>/s';
  523. $imgData = preg_replace($pattern, '', file_get_contents(public_path() . substr($url['path'], 1)));
  524. return "data:image/jpeg;base64," . base64_encode($imgData);
  525. }
  526. $url = $url['host'];
  527. $header = [
  528. 'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0',
  529. 'Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
  530. 'Accept-Encoding: gzip, deflate, br',
  531. 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
  532. 'Host:' . $url
  533. ];
  534. $dir = pathinfo($url);
  535. $host = $dir['dirname'];
  536. $refer = $host . '/';
  537. $curl = curl_init();
  538. curl_setopt($curl, CURLOPT_REFERER, $refer);
  539. curl_setopt($curl, CURLOPT_URL, $avatar);
  540. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  541. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
  542. curl_setopt($curl, CURLOPT_ENCODING, 'gzip');
  543. curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $timeout);
  544. curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
  545. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
  546. $data = curl_exec($curl);
  547. $code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
  548. curl_close($curl);
  549. if ($code == 200) {
  550. return "data:image/jpeg;base64," . base64_encode($data);
  551. } else {
  552. return false;
  553. }
  554. } catch (\Exception $e) {
  555. return false;
  556. }
  557. }
  558. }
  559. if (!function_exists('put_image')) {
  560. /**
  561. * 获取图片转为base64
  562. * @param string $avatar
  563. * @return bool|string
  564. */
  565. function put_image($url, $filename = '')
  566. {
  567. if ($url == '') {
  568. return false;
  569. }
  570. try {
  571. if ($filename == '') {
  572. $ext = pathinfo($url, PATHINFO_EXTENSION);
  573. if (!in_array($ext, ['jpg', 'jpeg', 'png'])) {
  574. return false;
  575. }
  576. $filename = time() . "." . $ext;
  577. }
  578. // SSRF 防护:验证 URL 安全性
  579. $urlParts = parse_url($url);
  580. if (!$urlParts || !isset($urlParts['scheme']) || !in_array($urlParts['scheme'], ['http', 'https'])) {
  581. return false;
  582. }
  583. $host = $urlParts['host'] ?? '';
  584. if (!$host) {
  585. return false;
  586. }
  587. // 阻止访问内网地址和私有 IP
  588. $ip = gethostbyname($host);
  589. if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) === false) {
  590. return false;
  591. }
  592. // 保存文件到指定目录
  593. $imgData = file_get_contents($url);
  594. if ($imgData === false) {
  595. return false;
  596. }
  597. $pattern = '/<\?php(.*?)\?>/s';
  598. $imgData = preg_replace($pattern, '', $imgData);
  599. // 额外过滤短标签
  600. $imgData = preg_replace('/<\?=(.*?)\?>/s', '', $imgData);
  601. $imgData = preg_replace('/<\?[\s](.*?)\?>/s', '', $imgData);
  602. if ($imgData !== false) {
  603. $path = 'uploads' . DS . 'qrcode' . DS . $filename;
  604. if (file_put_contents($path, $imgData) !== false) {
  605. return $path;
  606. }
  607. }
  608. } catch (\Exception $e) {
  609. }
  610. return false;
  611. }
  612. }
  613. if (!function_exists('debug_file')) {
  614. /**
  615. * 文件调试
  616. * @param $content
  617. */
  618. function debug_file($content, string $fileName = 'error', string $ext = 'txt')
  619. {
  620. $msg = '[' . date('Y-m-d H:i:s', time()) . '] [ DEBUG ] ';
  621. $pach = app()->getRuntimePath();
  622. file_put_contents($pach . $fileName . '.' . $ext, $msg . print_r($content, true) . "\r\n", FILE_APPEND);
  623. }
  624. }
  625. if (!function_exists('sql_filter')) {
  626. /**
  627. * sql 参数过滤
  628. * @param string $str
  629. * @return mixed
  630. */
  631. function sql_filter(string $str)
  632. {
  633. $filter = ['select ', 'insert ', 'update ', 'delete ', 'drop', 'truncate ', 'declare', 'xp_cmdshell', '/add', ' or ', 'exec', 'create', 'chr', 'mid', ' and ', 'execute'];
  634. $toupper = array_map(function ($str) {
  635. return strtoupper($str);
  636. }, $filter);
  637. return str_replace(array_merge($filter, $toupper, ['%20']), '', $str);
  638. }
  639. }
  640. if (!function_exists('filter_str')) {
  641. /**
  642. * 过滤字符串敏感字符
  643. * @param $str
  644. * @return array|mixed|string|string[]|null
  645. */
  646. function filter_str($str)
  647. {
  648. $param_filter_type = sys_config('param_filter_type');
  649. if ($param_filter_type != 0) {
  650. $rules = preg_split('/\r\n|\r|\n/', base64_decode(sys_config('param_filter_data')));
  651. if ($param_filter_type == 1) {
  652. foreach ($rules as $item) {
  653. if (preg_match($item, $str)) {
  654. throw new \Exception('接口请求失败:非法操作!');
  655. }
  656. }
  657. }
  658. if (filter_var($str, FILTER_VALIDATE_URL)) {
  659. $url = parse_url($str);
  660. if (!isset($url['scheme'])) return $str;
  661. $host = $url['scheme'] . '://' . $url['host'];
  662. $str = $host . preg_replace($rules, '', str_replace($host, '', $str));
  663. } else {
  664. $str = preg_replace($rules, '', $str);
  665. }
  666. }
  667. return $str;
  668. }
  669. }
  670. if (!function_exists('is_brokerage_statu')) {
  671. /**
  672. * 是否能成为推广人
  673. * @param float $price
  674. * @return bool
  675. */
  676. function is_brokerage_statu(float $price)
  677. {
  678. if (!sys_config('brokerage_func_status')) {
  679. return false;
  680. }
  681. $storeBrokerageStatus = sys_config('store_brokerage_statu', 1);
  682. if ($storeBrokerageStatus == 1) {
  683. return false;
  684. } else if ($storeBrokerageStatus == 2) {
  685. return true;
  686. } else {
  687. $storeBrokeragePrice = sys_config('store_brokerage_price', 0);
  688. return $price >= $storeBrokeragePrice;
  689. }
  690. }
  691. }
  692. if (!function_exists('array_unique_fb')) {
  693. /**
  694. * 二维数组去掉重复值
  695. * @param $array
  696. * @return array
  697. */
  698. function array_unique_fb($array)
  699. {
  700. $out = array();
  701. foreach ($array as $key => $value) {
  702. if (!in_array($value, $out)) {
  703. $out[$key] = $value;
  704. }
  705. }
  706. $out = array_values($out);
  707. return $out;
  708. }
  709. }
  710. if (!function_exists('get_crmeb_version')) {
  711. /**
  712. * 获取CRMEB系统版本号
  713. * @param string $default
  714. * @return string
  715. */
  716. function get_crmeb_version($default = 'v1.0.0')
  717. {
  718. try {
  719. $version = parse_ini_file(app()->getRootPath() . '.version');
  720. return $version['version'] ?? $default;
  721. } catch (\Throwable $e) {
  722. return $default;
  723. }
  724. }
  725. }
  726. if (!function_exists('get_crmeb_version_vode')) {
  727. /**
  728. * 获取CRMEB系统版本号
  729. * @param string $default
  730. * @return string
  731. */
  732. function get_crmeb_version_vode($default = '0')
  733. {
  734. try {
  735. $version = parse_ini_file(app()->getRootPath() . '.version');
  736. return $version['version_code'] ?? $default;
  737. } catch (\Throwable $e) {
  738. return $default;
  739. }
  740. }
  741. }
  742. if (!function_exists('get_file_link')) {
  743. /**
  744. * 获取文件带域名的完整路径
  745. * @param string $link
  746. * @return string
  747. */
  748. function get_file_link(string $link)
  749. {
  750. if (!$link) {
  751. return '';
  752. }
  753. if (substr($link, 0, 4) === "http" || substr($link, 0, 2) === "//") {
  754. return $link;
  755. } else {
  756. return app()->request->domain() . $link;
  757. }
  758. }
  759. }
  760. if (!function_exists('tidy_tree')) {
  761. /**
  762. * 格式化分类
  763. * @param $menusList
  764. * @param int $pid
  765. * @param array $navList
  766. * @return array
  767. */
  768. function tidy_tree($menusList, $pid = 0, $navList = [])
  769. {
  770. foreach ($menusList as $k => $menu) {
  771. if ($menu['parent_id'] == $pid) {
  772. unset($menusList[$k]);
  773. $menu['children'] = tidy_tree($menusList, $menu['id']);
  774. if ($menu['children']) $menu['expand'] = true;
  775. $navList[] = $menu;
  776. }
  777. }
  778. return $navList;
  779. }
  780. }
  781. if (!function_exists('create_form')) {
  782. /**
  783. * 表单生成方法
  784. * @param string $title
  785. * @param array $field
  786. * @param $url
  787. * @param string $method
  788. * @return array
  789. * @throws \FormBuilder\Exception\FormBuilderException
  790. */
  791. function create_form(string $title, array $field, $url, string $method = 'POST')
  792. {
  793. $form = Form::createForm((string)$url);//提交地址
  794. $form->setMethod($method);//提交方式
  795. $form->setRule($field);//表单字段
  796. $form->setTitle($title);//表单标题
  797. $rules = $form->formRule();
  798. $title = $form->getTitle();
  799. $action = $form->getAction();
  800. $method = $form->getMethod();
  801. $info = '';
  802. $status = true;
  803. $methodData = ['POST', 'PUT', 'GET', 'DELETE'];
  804. if (!in_array(strtoupper($method), $methodData)) {
  805. throw new ValidateException('请求方式有误');
  806. }
  807. return compact('rules', 'title', 'action', 'method', 'info', 'status');
  808. }
  809. }
  810. if (!function_exists('msectime')) {
  811. /**
  812. * 获取毫秒数
  813. * @return float
  814. */
  815. function msectime()
  816. {
  817. list($msec, $sec) = explode(' ', microtime());
  818. return (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
  819. }
  820. }
  821. if (!function_exists('array_bc_sum')) {
  822. /**
  823. * 获取一维数组的总合高精度
  824. * @param array $data
  825. * @return string
  826. */
  827. function array_bc_sum(array $data)
  828. {
  829. $sum = '0';
  830. foreach ($data as $item) {
  831. $sum = bcadd($sum, (string)$item, 2);
  832. }
  833. return $sum;
  834. }
  835. }
  836. if (!function_exists('get_tree_children')) {
  837. /**
  838. * tree 子菜单
  839. * @param array $data 数据
  840. * @param string $childrenname 子数据名
  841. * @param string $keyName 数据key名
  842. * @param string $pidName 数据上级key名
  843. * @return array
  844. */
  845. function get_tree_children(array $data, string $childrenname = 'children', string $keyName = 'id', string $pidName = 'pid')
  846. {
  847. $list = array();
  848. foreach ($data as $value) {
  849. $list[$value[$keyName]] = $value;
  850. }
  851. $tree = array(); //格式化好的树
  852. foreach ($list as $item) {
  853. if (isset($list[$item[$pidName]])) {
  854. $list[$item[$pidName]][$childrenname][] = &$list[$item[$keyName]];
  855. } else {
  856. $tree[] = &$list[$item[$keyName]];
  857. }
  858. }
  859. return $tree;
  860. }
  861. }
  862. if (!function_exists('get_tree_children_value')) {
  863. function get_tree_children_value(array $data, $value, string $childrenname = 'children', string $keyName = 'id')
  864. {
  865. static $childrenValue = [];
  866. foreach ($data as $item) {
  867. $childrenData = $item[$childrenname] ?? [];
  868. if (count($childrenData)) {
  869. return get_tree_children_value($childrenData, $childrenname, $keyName);
  870. } else {
  871. if ($item[$keyName] == $value) {
  872. $childrenValue[] = $item['value'];
  873. }
  874. }
  875. }
  876. return $childrenValue;
  877. }
  878. }
  879. if (!function_exists('get_tree_value')) {
  880. /**
  881. * 获取
  882. * @param array $data
  883. * @param int|string $value
  884. * @return array
  885. */
  886. function get_tree_value(array $data, $value)
  887. {
  888. // static $childrenValue = [];
  889. // foreach ($data as &$item) {
  890. // if ($item['value'] == $value) {
  891. // $childrenValue[] = $item['value'];
  892. // if ($item['pid']) {
  893. // $value = $item['pid'];
  894. // unset($item);
  895. // return get_tree_value($data, $value);
  896. // }
  897. // }
  898. // }
  899. // return $childrenValue;
  900. $childrenValue = []; // 用于存储找到的子值的数组
  901. foreach ($data as $item) {
  902. if ($item['value'] == $value) { // 如果当前项的'value'键与给定值匹配
  903. $childrenValue[] = $item['value']; // 将当前值添加到子值数组中
  904. if ($item['pid']) { // 如果当前项有'pid'值,表示有父项
  905. // 递归调用get_tree_value函数,并将父项的'pid'值作为新的$value参数
  906. $childrenValue = array_merge($childrenValue, get_tree_value($data, $item['pid']));
  907. }
  908. }
  909. }
  910. return $childrenValue; // 返回包含所有子值的数组
  911. }
  912. }
  913. if (!function_exists('get_image_thumb')) {
  914. /**
  915. * 获取缩略图
  916. * @param $filePath
  917. * @param string $type all|big|mid|small
  918. * @param bool $is_remote_down
  919. * @return mixed|string|string[]
  920. */
  921. function get_image_thumb($filePath, string $type = 'all', bool $is_remote_down = false)
  922. {
  923. if (!$filePath || !is_string($filePath) || strpos($filePath, '?') !== false) return $filePath;
  924. try {
  925. $upload = UploadService::getOssInit($filePath, $is_remote_down);
  926. //TODO
  927. $fileArr = explode('/', $filePath);
  928. $data = $upload->thumb($filePath, end($fileArr), $type);
  929. $image = $type == 'all' ? $data : $data[$type] ?? $filePath;
  930. } catch (\Throwable $e) {
  931. $image = $filePath;
  932. }
  933. $data = parse_url($image);
  934. if (!isset($data['host']) && (substr($image, 0, 2) == './' || substr($image, 0, 1) == '/')) {//不是完整地址
  935. $image = sys_config('site_url') . $image;
  936. }
  937. //请求是https 图片是http 需要改变图片地址
  938. //TODO 是否要读取后台配置url
  939. if (strpos(request()->domain(), 'https:') !== false && strpos($image, 'https:') === false) {
  940. $image = str_replace('http:', 'https:', $image);
  941. }
  942. return $image;
  943. }
  944. }
  945. if (!function_exists('get_thumb_water')) {
  946. /**
  947. * 处理数组获取缩略图、水印
  948. * @param $list
  949. * @param string $type
  950. * @param array|string[] $field 1、['image','images'] type 取值参数:type 2、['small'=>'image','mid'=>'images'] type 取field数组的key
  951. * @param bool $is_remote_down
  952. * @return array|mixed|string|string[]
  953. */
  954. function get_thumb_water($list, string $type = 'small', array $field = ['image'], bool $is_remote_down = false)
  955. {
  956. // 未开启缩略图功能 直接返回原数据
  957. if (!sys_config('image_thumb_status', 0)) {
  958. return $list;
  959. }
  960. if (!$list || !$field) return $list;
  961. $baseType = $type;
  962. $data = $list;
  963. if (is_string($list)) {
  964. $field = [$type => 'image'];
  965. $data = ['image' => $list];
  966. }
  967. if (is_array($data)) {
  968. foreach ($field as $type => $key) {
  969. if (is_integer($type)) {//索引数组,默认type
  970. $type = $baseType;
  971. }
  972. //一维数组
  973. if (isset($data[$key])) {
  974. if (is_array($data[$key])) {
  975. $path_data = [];
  976. foreach ($data[$key] as $k => $path) {
  977. $path_data[] = get_image_thumb($path, $type, $is_remote_down);
  978. }
  979. $data[$key] = $path_data;
  980. } else {
  981. $data[$key] = get_image_thumb($data[$key], $type, $is_remote_down);
  982. }
  983. } else {
  984. foreach ($data as &$item) {
  985. if (!isset($item[$key]))
  986. continue;
  987. if (is_array($item[$key])) {
  988. $path_data = [];
  989. foreach ($item[$key] as $k => $path) {
  990. $path_data[] = get_image_thumb($path, $type, $is_remote_down);
  991. }
  992. $item[$key] = $path_data;
  993. } else {
  994. $item[$key] = get_image_thumb($item[$key], $type, $is_remote_down);
  995. }
  996. }
  997. }
  998. }
  999. }
  1000. return is_string($list) ? ($data['image'] ?? '') : $data;
  1001. }
  1002. }
  1003. if (!function_exists('getLang')) {
  1004. /**
  1005. * 多语言翻译函数:根据当前语言环境将传入的“中文语言标识”翻译成对应语言文本,并支持变量替换
  1006. *
  1007. * 执行流程:
  1008. * 1. 异常捕获:整个逻辑包裹在 try-catch 中,任何环节出错直接返回原标识,避免系统因语言模块异常而中断
  1009. * 2. 依赖注入:一次性获取三个核心服务实例
  1010. * - LangCountryServices:负责国家/地区与语言类型的映射
  1011. * - LangTypeServices:负责语言类型(如 zh-CN、en-US)的元数据
  1012. * - LangCodeServices:负责语言码表(code => 翻译文本)的读取
  1013. * 3. 语言范围(range)判定优先级:
  1014. * ① 优先读取请求头 cb-lang(前端/接口主动指定)
  1015. * ② 若无,则读取系统默认语言(LangTypeServices.is_default = 1)
  1016. * ③ 若系统未配置默认语言,则读取浏览器 Accept-Language 首个语言标签
  1017. * ④ 若仍为空,则强制 fallback 到 zh-CN,确保后续逻辑有值可用
  1018. * 4. 缓存加速:所有“一经写入、极少变动”的数据统一使用 CacheService::remember() 缓存 3600 秒,降低数据库压力
  1019. * - sys_lang_source_map:中文 remarks => code 的映射,用于把传入的“中文标识”转成内部 code
  1020. * - type_id_{range}:根据语言简码(如 zh-CN)反查对应的 type_id
  1021. * - lang_type_data:所有启用的语言类型 id => file_name 映射表,用于校验语言是否合法
  1022. * - lang_{file_name}:具体语言包 code => 翻译文本 的完整数组
  1023. * 5. 翻译过程:
  1024. * - 若语言类型不存在,直接返回原标识
  1025. * - 若“中文标识”在映射表中存在且对应 code 在语言包中存在,则取翻译文本;否则返回原标识
  1026. * 6. 变量替换:支持 {:变量名} 语法,将翻译文本中的占位符批量替换为 $replace 数组中的值
  1027. * 7. 异常兜底:catch 中记录详细错误日志(文件名/行号/异常信息),依旧返回原标识,保证业务继续
  1028. *
  1029. * @param string $msg 中文语言标识(remarks),如 "用户名不能为空"
  1030. * @param array $replace 可选的变量映射,如 ['name' => '手机号'],会将文本中的 {:name} 替换为“手机号”
  1031. * @return string 最终翻译后的文本;任何异常或找不到翻译时返回原标识
  1032. */
  1033. function getLang($msg, array $replace = [])
  1034. {
  1035. /* 整个翻译过程一旦出错,直接返回原标识,避免中断业务 */
  1036. try {
  1037. /* --------------- 1. 依赖注入:获取语言相关服务 --------------- */
  1038. /** @var LangCountryServices $langCountryServices */
  1039. $langCountryServices = app()->make(LangCountryServices::class);
  1040. /** @var LangTypeServices $langTypeServices */
  1041. $langTypeServices = app()->make(LangTypeServices::class);
  1042. /** @var LangCodeServices $langCodeServices */
  1043. $langCodeServices = app()->make(LangCodeServices::class);
  1044. /* --------------- 2. 确定当前语言范围(range) --------------- */
  1045. $request = app()->request;
  1046. // 优先取前端/接口指定的语言
  1047. $range = $request->header('cb-lang');
  1048. if (!$range) {
  1049. // 未指定时,读取系统默认语言
  1050. $range = CacheService::remember('range_name', function () use ($langTypeServices) {
  1051. return $langTypeServices->value(['is_default' => 1], 'file_name');
  1052. });
  1053. if (!$range) {
  1054. // 系统也未配置默认语言,则尝试使用浏览器 Accept-Language
  1055. if ($request->header('accept-language') !== null) {
  1056. $range = explode(',', $request->header('accept-language'))[0];
  1057. } else {
  1058. // 最终兜底:简体中文
  1059. $range = 'zh-CN';
  1060. }
  1061. }
  1062. }
  1063. /* --------------- 3. 读取各类映射数据(带缓存) --------------- */
  1064. // 中文 remarks => code 映射表,用于把传入的“中文标识”转成内部 code
  1065. $langZhCn = CacheService::remember('sys_lang_source_map', function () use ($langCodeServices) {
  1066. return $langCodeServices->getColumn(['type_id' => 1], 'code', 'remarks');
  1067. }, 3600);
  1068. // 根据语言简码(如 zh-CN)反查对应的 type_id
  1069. $typeId = CacheService::remember('type_id_' . $range, function () use ($langCountryServices, $range) {
  1070. return $langCountryServices->value(['code' => $range], 'type_id') ?: 1;
  1071. }, 3600);
  1072. // 所有启用的语言类型 id => file_name 映射表
  1073. $langData = CacheService::remember('lang_type_data', function () use ($langTypeServices) {
  1074. return $langTypeServices->getColumn(['status' => 1, 'is_del' => 0], 'file_name', 'id');
  1075. }, 3600);
  1076. /* --------------- 4. 校验语言类型是否合法 --------------- */
  1077. if (!isset($langData[$typeId])) {
  1078. return $msg;
  1079. }
  1080. /* --------------- 5. 读取当前语言包(code => 翻译文本) --------------- */
  1081. $langStr = 'lang_' . str_replace('-', '_', $langData[$typeId]); // 构造缓存 key
  1082. $lang = CacheService::remember($langStr, function () use ($typeId, $langCodeServices) {
  1083. return $langCodeServices->getColumn(['type_id' => $typeId], 'lang_explain', 'code');
  1084. }, 3600);
  1085. /* --------------- 6. 获取翻译文本 --------------- */
  1086. if (isset($langZhCn[$msg]) && isset($lang[$langZhCn[$msg]])) {
  1087. // 映射表存在且语言包中存在对应 code,则使用翻译文本
  1088. $message = (string)$lang[$langZhCn[$msg]];
  1089. } else {
  1090. // 找不到翻译,返回原标识
  1091. $message = $msg;
  1092. }
  1093. /* --------------- 7. 变量替换(支持 {:变量名} 语法) --------------- */
  1094. if (!empty($replace) && is_array($replace)) {
  1095. // 构造占位符数组,如 ['name'] -> ['{:name}']
  1096. $key = array_map(function ($v) { return "{:{$v}}"; }, array_keys($replace));
  1097. // 批量替换
  1098. $message = str_replace($key, array_values($replace), $message);
  1099. }
  1100. return $message;
  1101. } catch (\Throwable $e) {
  1102. /* 记录详细错误日志,依旧返回原标识,保证业务继续 */
  1103. Log::error('获取语言msg:' . $msg . '发生错误,错误原因是:' . json_encode([
  1104. 'file' => $e->getFile(),
  1105. 'message' => $e->getMessage(),
  1106. 'line' => $e->getLine()
  1107. ]));
  1108. return $msg;
  1109. }
  1110. }
  1111. }
  1112. if (!function_exists('aj_captcha_check_one')) {
  1113. /**
  1114. * 验证滑块1次验证
  1115. * @param string $token
  1116. * @param string $pointJson
  1117. * @return bool
  1118. */
  1119. function aj_captcha_check_one(string $captchaType, string $token, string $pointJson)
  1120. {
  1121. aj_get_serevice($captchaType)->check($token, $pointJson);
  1122. return true;
  1123. }
  1124. }
  1125. if (!function_exists('aj_captcha_check_two')) {
  1126. /**
  1127. * 验证滑块2次验证
  1128. * @param string $token
  1129. * @param string $pointJson
  1130. * @return bool
  1131. */
  1132. function aj_captcha_check_two(string $captchaType, string $captchaVerification)
  1133. {
  1134. aj_get_serevice($captchaType)->verificationByEncryptCode($captchaVerification);
  1135. return true;
  1136. }
  1137. }
  1138. if (!function_exists('aj_captcha_create')) {
  1139. /**
  1140. * 创建验证码
  1141. * @return array
  1142. */
  1143. function aj_captcha_create(string $captchaType)
  1144. {
  1145. return aj_get_serevice($captchaType)->get();
  1146. }
  1147. }
  1148. if (!function_exists('aj_get_serevice')) {
  1149. /**
  1150. * @param string $captchaType
  1151. * @return ClickWordCaptchaService|BlockPuzzleCaptchaService
  1152. */
  1153. function aj_get_serevice(string $captchaType)
  1154. {
  1155. $config = Config::get('ajcaptcha');
  1156. switch ($captchaType) {
  1157. case "clickWord":
  1158. $service = new ClickWordCaptchaService($config);
  1159. break;
  1160. case "blockPuzzle":
  1161. $service = new BlockPuzzleCaptchaService($config);
  1162. break;
  1163. default:
  1164. throw new ValidateException('captchaType参数不正确!');
  1165. }
  1166. return $service;
  1167. }
  1168. }
  1169. if (!function_exists('out_push')) {
  1170. /**
  1171. * 默认数据推送
  1172. * @param string $pushUrl
  1173. * @param array $data
  1174. * @param string $tip
  1175. * @return bool
  1176. */
  1177. function out_push(string $pushUrl, array $data, string $tip = ''): bool
  1178. {
  1179. $param = json_encode($data, JSON_UNESCAPED_UNICODE);
  1180. $res = HttpService::postRequest($pushUrl, $param, ['Content-Type:application/json', 'Content-Length:' . strlen($param)]);
  1181. $res = $res ? json_decode($res, true) : [];
  1182. if (!$res || !isset($res['code']) || $res['code'] != 0) {
  1183. \think\facade\Log::error(['msg' => $tip . '推送失败', 'data' => $res]);
  1184. return false;
  1185. }
  1186. return true;
  1187. }
  1188. }
  1189. if (!function_exists('dump_sql')) {
  1190. /**
  1191. * 打印sql
  1192. * @param string $pushUrl
  1193. * @param array $data
  1194. * @param string $tip
  1195. * @return bool
  1196. */
  1197. function dump_sql()
  1198. {
  1199. Db::listen(function ($sql) {
  1200. var_dump($sql);
  1201. });
  1202. }
  1203. }
  1204. if (!function_exists('toIntArray')) {
  1205. /**
  1206. * 处理ids等并过滤参数
  1207. * @param $data
  1208. * @param string $separator
  1209. * @return array
  1210. */
  1211. function toIntArray($data, string $separator = ',')
  1212. {
  1213. if (!is_string($data) && !is_int($data)) {
  1214. return array_unique(array_diff(array_map('intval', $data), [0]));
  1215. } else {
  1216. return !empty($data) ? array_unique(array_diff(array_map('intval', explode($separator, $data)), [0])) : [];
  1217. }
  1218. }
  1219. }