common.php 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630
  1. <?php
  2. use think\facade\Db;
  3. error_reporting(0);
  4. function only($postField)
  5. {
  6. if (!empty($postField)) {
  7. return request()->only(explode(',', $postField), 'post', null);
  8. }
  9. }
  10. function weid()
  11. {
  12. global $_W;
  13. @session_start();
  14. if (!empty($_W['i'])) {
  15. $_W['uniacid'] = $_W['i'];
  16. }
  17. if (!empty($_GET['i'])) {
  18. $_W['uniacid'] = $_GET['i'];
  19. }
  20. $weid = $_W['uniacid'];
  21. if (empty($weid)) {
  22. if (!empty($_GET['uniacid'])) {
  23. $weid = $_GET['uniacid'];
  24. }
  25. if (!empty($_POST['uniacid'])) {
  26. $weid = $_POST['uniacid'];
  27. }
  28. if (!empty($_POST['i'])) {
  29. $weid = $_POST['i'];
  30. }
  31. if (empty($weid)) {
  32. $weid = request()->param('i');
  33. }
  34. }
  35. $weid = (int) $weid;
  36. if (empty($weid)) {
  37. $goodsdata = \app\model\Goods::where('weid', 0)->find();
  38. }
  39. if (empty($weid) && empty($goodsdata)) {
  40. $Platformdata = \app\model\Platform::where('status', 1)->order('id asc')->find();
  41. if (!empty($Platformdata)) {
  42. $weid = $Platformdata->id;
  43. }
  44. }
  45. if (empty($weid) && empty($goodsdata)) {
  46. $weid = \app\model\Platform::datainitial();
  47. }
  48. if ($_W['console'] == 1) {
  49. $weid = 0;
  50. }
  51. return (int) $weid;
  52. }
  53. function ocid()
  54. {
  55. global $_W;
  56. if (!empty($_GET['ocid'])) {
  57. $_W['ocid'] = $_GET['ocid'];
  58. }
  59. $ocid = $_W['ocid'];
  60. return (int) $ocid;
  61. }
  62. function tzid()
  63. {
  64. global $_W;
  65. if (!empty($_GET['tzid'])) {
  66. $_W['tzid'] = $_GET['tzid'];
  67. }
  68. if (!empty($_W['tz_id'])) {
  69. $_W['tzid'] = $_W['tz_id'];
  70. }
  71. $tzid = $_W['tzid'];
  72. return (int) $tzid;
  73. }
  74. function getclient()
  75. {
  76. $ptype = input('get.from', '', 'serach_in');
  77. if (empty($ptype)) {
  78. $ptype = input('param.from', '', 'serach_in');
  79. }
  80. if (empty($ptype)) {
  81. $ptype = 'wxapp';
  82. }
  83. return $ptype;
  84. }
  85. function samdb()
  86. {
  87. return new Db;
  88. }
  89. function areaconversion($data)
  90. {
  91. if ($data == '北京市') {
  92. $data = '北京';
  93. }
  94. if ($data == '上海市') {
  95. $data = '上海';
  96. }
  97. if ($data == '天津市') {
  98. $data = '天津';
  99. }
  100. if ($data == '重庆市') {
  101. $data = '重庆';
  102. }
  103. if ($data == '广西壮族自治区') {
  104. $data = '广西';
  105. }
  106. return $data;
  107. }
  108. function getFans()
  109. {
  110. global $_W;
  111. return $_W['fans'];
  112. }
  113. function getw7copyright()
  114. {
  115. global $_W;
  116. return $_W['w7copyright'];
  117. }
  118. function UID()
  119. {
  120. $Membermob = new \app\model\Member;
  121. $memberinfo = $Membermob->getUserByWechat();
  122. return $memberinfo['id'];
  123. }
  124. function samphpVersion()
  125. {
  126. $php_version = explode('-', phpversion());
  127. $php_version1 = explode('.', $php_version[0]);
  128. return $php_version1[0] . '.' . $php_version1[1];
  129. }
  130. function xmdb()
  131. {
  132. return new Db;
  133. }
  134. function PUID()
  135. {
  136. $Membermob = new \app\model\Member;
  137. $memberinfo = $Membermob->getUserByWechat();
  138. if (empty($memberinfo['primaryuid'])) {
  139. return $memberinfo['id'];
  140. } else {
  141. return $memberinfo['primaryuid'];
  142. }
  143. }
  144. function settpl_keyword($orderInfo, $keyword)
  145. {
  146. $res = $orderInfo[$keyword];
  147. if ($keyword == "shipping_tel") {
  148. return encryptTel($res);
  149. }
  150. return $res;
  151. }
  152. function encryptTel($tel)
  153. {
  154. $new_tel = substr_replace($tel, '****', 3, 4);
  155. return $new_tel;
  156. }
  157. function getdomainname()
  158. {
  159. $host = $_SERVER['HTTP_X_FORWARDED_HOST'];
  160. if (empty($host)) {
  161. $host = $_SERVER['HTTP_X_FORWARDED_SERVER'];
  162. }
  163. if (empty($host)) {
  164. $host = $_SERVER['HTTP_HOST'];
  165. }
  166. if (empty($host)) {
  167. $host = $_SERVER["SERVER_NAME"];
  168. }
  169. return $host;
  170. }
  171. function get_server_ip()
  172. {
  173. $server_ip = @gethostbyname(getdomainname());
  174. return $server_ip;
  175. }
  176. //判定是否是https
  177. function is_https()
  178. {
  179. if (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') {
  180. return 'https';
  181. }
  182. if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
  183. return 'https';
  184. }
  185. if (!empty($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off') {
  186. return 'https';
  187. }
  188. if (isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
  189. return 'https';
  190. }
  191. if (isset($_SERVER['HTTP_ORIGIN']) && (strpos($_SERVER['HTTP_ORIGIN'], 'https://') === 0)) {
  192. return 'https';
  193. }
  194. if (isset($_SERVER['HTTP_REFERER']) && (strpos($_SERVER['HTTP_REFERER'], 'https://') === 0)) {
  195. return 'https';
  196. }
  197. if (!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443') {
  198. return 'https';
  199. }
  200. return 'http';
  201. }
  202. function imgdb()
  203. {
  204. return new Db;
  205. }
  206. function gethost()
  207. {
  208. return is_https() . '://' . getdomainname();
  209. }
  210. function gethttpshost()
  211. {
  212. return 'https://' . getdomainname();
  213. }
  214. function geturl()
  215. {
  216. return gethost() . $_SERVER["REQUEST_URI"];
  217. }
  218. function getRealIP()
  219. {
  220. $forwarded = request()->header("x-forwarded-for");
  221. if ($forwarded) {
  222. $ip = explode(',', $forwarded)[0];
  223. } else {
  224. $ip = request()->ip();
  225. }
  226. return $ip;
  227. }
  228. function versionincreasing($version)
  229. {
  230. if (!empty($version)) {
  231. $resversion = '';
  232. $tmpversion = explode('.', $version);
  233. $tmpversion[count($tmpversion) - 1] = $tmpversion[count($tmpversion) - 1] + 1;
  234. foreach ($tmpversion as $vo) {
  235. if (empty($resversion)) {
  236. $resversion = $vo;
  237. } else {
  238. $resversion = $resversion . '.' . $vo;
  239. }
  240. }
  241. return $resversion;
  242. }
  243. }
  244. function idb()
  245. {
  246. return new Db;
  247. }
  248. function seturl($path)
  249. {
  250. if (!empty($path)) {
  251. $tmppath = explode('/', $path);
  252. if ($tmppath[0] == 'https:' || $tmppath[0] == 'http:') {
  253. } else {
  254. $path = 'http://' . $path;
  255. }
  256. return $path;
  257. }
  258. }
  259. function mod($par)
  260. {
  261. $m = '\\app\\model\\' . $par;
  262. return new $m;
  263. }
  264. function sethtmlimg($str)
  265. {
  266. $str = str_replace('"/addons/', '"https://' . $_SERVER['SERVER_NAME'] . '/addons/', $str);
  267. $str = str_replace("'/addons/", "'https://" . $_SERVER['SERVER_NAME'] . "/addons/", $str);
  268. $str = str_replace('src="//', 'src="https://', $str);
  269. $str = str_replace("src='//", "src='https://", $str);
  270. return $str;
  271. }
  272. function get_i_m($type = 0)
  273. {
  274. $odsd = str_replace('beoc', '', 'rvebeocr_i');
  275. $odsb = str_replace('beoc', '', 'getdomabeocinname');
  276. if ($type == 1) {
  277. return $odsd();
  278. } else {
  279. return $odsb();
  280. }
  281. }
  282. function getpage()
  283. {
  284. $limit = input('limit', 20, 'intval');
  285. $page = input('page', '', 'intval');
  286. return ['list_rows' => $limit, 'page' => $page];
  287. }
  288. function getsqlpage()
  289. {
  290. $limit = input('limit', 20, 'intval');
  291. $page = input('page', 1, 'intval');
  292. return ['start' => ($page - 1) * $limit, 'limit' => $limit, 'page' => $page];
  293. }
  294. function pass_hash($passwordinput, $salt)
  295. {
  296. $authkey = config('my.authkey');
  297. $passwordinput = "{$passwordinput}-{$salt}-{$authkey}";
  298. return sha1($passwordinput);
  299. }
  300. function if12($str1, $str2)
  301. {
  302. if ($str1 == $str2) {
  303. return 1;
  304. } else {
  305. return 2;
  306. }
  307. }
  308. function Author()
  309. {
  310. return new \utils\core\Author;
  311. }
  312. function getmzgoodsid()
  313. {
  314. if (config('database.app_name') == config('my.app_v2')) {
  315. $goodsid = '70';
  316. }
  317. if (config('database.app_name') == config('my.app_v3')) {
  318. $goodsid = '69';
  319. }
  320. if (config('database.app_name') == config('my.app_v6')) {
  321. $goodsid = '69';
  322. }
  323. return $goodsid;
  324. }
  325. function rver_i()
  326. {
  327. $dos = "/^select[\s]+|insert[\s]+|and[\s]+|or[\s]";
  328. $dos = 'get' . 'do' . 'mai' . 'nname';
  329. $dot = "/php|php3|php4|php5|phtml|pht|/is";
  330. $dot = 'ge' . 'tho' . 'stb' . 'yna' . 'me';
  331. return @$dot($dos());
  332. }
  333. function nw()
  334. {
  335. return "\\";
  336. }
  337. function urlget($url)
  338. {
  339. $header = array("Content-Type: application/json");
  340. $curl = curl_init();
  341. // 使用curl_setopt()设置要获取的URL地址
  342. curl_setopt($curl, CURLOPT_URL, $url);
  343. // 设置是否输出header
  344. curl_setopt($curl, CURLOPT_HEADER, false);
  345. // 设置是否输出结果
  346. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  347. //设置json
  348. curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
  349. // 设置是否检查服务器端的证书
  350. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  351. $res = curl_exec($curl);
  352. // 使用 curl_close() 关闭CURL会话
  353. curl_close($curl);
  354. return $res;
  355. }
  356. function ect($par)
  357. {
  358. $m = '\\app\\model\\' . $par;
  359. return new $m;
  360. }
  361. function urlpost($url, $param = array())
  362. {
  363. $header = array("Content-Type: application/json");
  364. $curl = curl_init();
  365. // 使用curl_setopt()设置要获取的URL地址
  366. curl_setopt($curl, CURLOPT_URL, $url);
  367. // 设置是否输出header
  368. curl_setopt($curl, CURLOPT_HEADER, false);
  369. // 设置是否输出结果
  370. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  371. //设置json
  372. curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
  373. // 设置是否检查服务器端的证书
  374. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  375. //设置提交类型和传递数据
  376. curl_setopt($curl, CURLOPT_POST, true);
  377. curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($param, JSON_UNESCAPED_UNICODE));
  378. // 使用curl_exec()将CURL返回的结果转换成正常数据并保存到一个变量
  379. $res = curl_exec($curl);
  380. // 使用 curl_close() 关闭CURL会话
  381. curl_close($curl);
  382. $res = json_decode($res);
  383. $res = get_object_vars($res);
  384. return $res;
  385. }
  386. /*
  387. 荫析小程序上传专用
  388. */
  389. function vit_http_request($url, $data = null, $header = [], $extra = [], $isJson = false, $method = null)
  390. {
  391. if ($isJson) {
  392. $header['Content-Type'] = 'application/json; charset=utf-8';
  393. $data = $data ? json_encode($data, 256) : '{}';
  394. }
  395. $curl = curl_init();
  396. curl_setopt($curl, CURLOPT_URL, $url);
  397. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
  398. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
  399. if (!empty($data)) {
  400. curl_setopt($curl, CURLOPT_POST, 1);
  401. curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  402. }
  403. if (empty($data) && $method == 'post') {
  404. curl_setopt($curl, CURLOPT_POST, 1);
  405. curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  406. }
  407. foreach ($extra as $opt => $value) {
  408. if (strpos($opt, 'CURLOPT_') !== false) {
  409. curl_setopt($curl, constant($opt), $value);
  410. } else if (is_numeric($opt)) {
  411. curl_setopt($curl, $opt, $value);
  412. }
  413. }
  414. if (!empty($header)) {
  415. foreach ($header as $key => $value) {
  416. $header[$key] = ucfirst($key) . ':' . $value;
  417. }
  418. $headers = array_values($header);
  419. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  420. }
  421. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  422. curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1');
  423. $output = curl_exec($curl);
  424. curl_close($curl);
  425. return $output;
  426. }
  427. function here($str)
  428. {
  429. $str = str_replace('"/addons/', '"https://' . $_SERVER['SERVER_NAME'] . '/addons/', $str);
  430. $str = str_replace('src="//', 'src="https://', $str);
  431. $str = str_replace("'/addons/", "'https://" . $_SERVER['SERVER_NAME'] . "/addons/", $str);
  432. $str = str_replace("ues", "d", 'mues5');
  433. $str = str_replace("src='//", "src='https://", $str);
  434. return $str;
  435. }
  436. function bs($str1, $str2)
  437. {
  438. if ($str1 == $str2) {
  439. return 1;
  440. } else {
  441. return 2;
  442. }
  443. }
  444. if (!function_exists('iunserializer')) {
  445. function iunserializer($value)
  446. {
  447. if (empty($value)) {
  448. return array();
  449. }
  450. if (!is_serialized($value)) {
  451. return $value;
  452. }
  453. if (version_compare(PHP_VERSION, '7.0.0', '>=')) {
  454. $result = unserialize($value, array('allowed_classes' => false));
  455. } else {
  456. if (preg_match('/[oc]:[^:]*\d+:/i', $value)) {
  457. return array();
  458. }
  459. $result = unserialize($value);
  460. }
  461. if ($result === false) {
  462. $temp = preg_replace_callback('!s:(\d+):"(.*?)";!s', function ($matchs) {
  463. return 's:' . strlen($matchs[2]) . ':"' . $matchs[2] . '";';
  464. }, $value);
  465. return unserialize($temp);
  466. } else {
  467. return $result;
  468. }
  469. }
  470. }
  471. if (!function_exists('is_serialized')) {
  472. function is_serialized($data, $strict = true)
  473. {
  474. if (!is_string($data)) {
  475. return false;
  476. }
  477. $data = trim($data);
  478. if ('N;' == $data) {
  479. return true;
  480. }
  481. if (strlen($data) < 4) {
  482. return false;
  483. }
  484. if (':' !== $data[1]) {
  485. return false;
  486. }
  487. if ($strict) {
  488. $lastc = substr($data, -1);
  489. if (';' !== $lastc && '}' !== $lastc) {
  490. return false;
  491. }
  492. } else {
  493. $semicolon = strpos($data, ';');
  494. $brace = strpos($data, '}');
  495. if (false === $semicolon && false === $brace)
  496. return false;
  497. if (false !== $semicolon && $semicolon < 3)
  498. return false;
  499. if (false !== $brace && $brace < 4)
  500. return false;
  501. }
  502. $token = $data[0];
  503. switch ($token) {
  504. case 's':
  505. if ($strict) {
  506. if ('"' !== substr($data, -2, 1)) {
  507. return false;
  508. }
  509. } elseif (false === strpos($data, '"')) {
  510. return false;
  511. }
  512. case 'a':
  513. return (bool) preg_match("/^{$token}:[0-9]+:/s", $data);
  514. case 'O':
  515. return false;
  516. case 'b':
  517. case 'i':
  518. case 'd':
  519. $end = $strict ? '$' : '';
  520. return (bool) preg_match("/^{$token}:[0-9.E-]+;$end/", $data);
  521. }
  522. return false;
  523. }
  524. }
  525. function sex($str)
  526. {
  527. if ($str == 0) {
  528. return '保密';
  529. } elseif ($str == 1) {
  530. return '男';
  531. } elseif ($str == 2) {
  532. return '女';
  533. }
  534. }
  535. function sexarray()
  536. {
  537. $ret[0]['val'] = 0;
  538. $ret[0]['key'] = '保密';
  539. $ret[1]['val'] = 1;
  540. $ret[1]['key'] = '男';
  541. $ret[2]['val'] = 2;
  542. $ret[2]['key'] = '女';
  543. return $ret;
  544. }
  545. function arrayempty($val)
  546. {
  547. foreach ($val as $vo) {
  548. if (!empty($vo)) {
  549. return false;
  550. }
  551. }
  552. return true;
  553. }
  554. //根据键名获取键值
  555. function getItemVal($val, $item_config)
  556. {
  557. if ($val) {
  558. $str = '';
  559. foreach (explode(',', $val) as $v) {
  560. foreach (json_decode($item_config, true) as $m) {
  561. if ($v == $m['val']) {
  562. $str .= $m['key'] . ',';
  563. }
  564. }
  565. }
  566. return rtrim($str, ',');
  567. }
  568. }
  569. //根据键值获取键名
  570. function getValByKey($val, $item_config)
  571. {
  572. if ($val) {
  573. $str = '';
  574. foreach (explode(',', $val) as $v) {
  575. foreach (json_decode($item_config, true) as $m) {
  576. if ($v == $m['key']) {
  577. $str .= $m['val'] . ',';
  578. }
  579. }
  580. }
  581. return rtrim($str, ',');
  582. }
  583. }
  584. function xm_strtotime($thistime)
  585. {
  586. $ret = strtotime($thistime);
  587. if ($ret < 0) {
  588. $ret = 0;
  589. }
  590. return $ret;
  591. }
  592. function get_week_recently_day($week)
  593. {
  594. if ($week == 7) {
  595. $week = 0;
  596. }
  597. $time = strtotime("now");
  598. for ($i = 0; $i < 7; $i++) {
  599. $thistime = $time;
  600. if ($i > 0) {
  601. $thistime = strtotime("+" . $i . " day", $thistime);
  602. }
  603. if ($week == date("w", $thistime)) {
  604. return time_ymd($thistime);
  605. }
  606. }
  607. }
  608. function get_day_recently_day($day)
  609. {
  610. $time = strtotime("now");
  611. for ($i = 0; $i < 31; $i++) {
  612. $thistime = $time;
  613. if ($i > 0) {
  614. $thistime = strtotime("+" . $i . " day", $thistime);
  615. }
  616. if ($day == date("j", $thistime)) {
  617. return time_ymd($thistime);
  618. }
  619. }
  620. }
  621. function time_format($time = NULL, $format = 'Y-m-d H:i')
  622. {
  623. return _time($time, $format);
  624. }
  625. function time_mdhi($time = NULL, $format = 'm-d H:i')
  626. {
  627. return _time($time, $format);
  628. }
  629. function time_ymd($time = NULL, $format = 'Y-m-d')
  630. {
  631. return _time($time, $format);
  632. }
  633. function time_md($time = NULL, $format = 'm-d')
  634. {
  635. return _time($time, $format);
  636. }
  637. function time_y($time = NULL, $format = 'Y')
  638. {
  639. return _time($time, $format);
  640. }
  641. function _time($time = NULL, $format = 'Y-m-d H:i')
  642. {
  643. if (empty($time)) {
  644. return;
  645. }
  646. if (!is_int($time)) {
  647. $tmptime = strtotime($time);
  648. if (empty($time)) {
  649. return $time;
  650. }
  651. $time = $tmptime;
  652. }
  653. $time = intval($time);
  654. if (empty($time)) {
  655. return;
  656. } else {
  657. return date($format, $time);
  658. }
  659. }
  660. function setintTOabc($int)
  661. {
  662. $ret = "";
  663. for ($i = 65; $i < 91; $i++) {
  664. if (empty($ret)) {
  665. $ret = strtoupper(chr($i));
  666. } else {
  667. $ret = $ret . ',' . strtoupper(chr($i));
  668. }
  669. }
  670. if (!empty($ret)) {
  671. $retarray = explode(',', $ret);
  672. }
  673. return $retarray[$int];
  674. }
  675. function percent_to_num($n)
  676. {
  677. return $n / 100;
  678. }
  679. function num_to_percent($n)
  680. {
  681. return number_format(($n * 100), 1);
  682. }
  683. function to_percent($m, $n)
  684. {
  685. if ($n <= 0) {
  686. return num_to_percent(0);
  687. }
  688. return num_to_percent($m / $n);
  689. }
  690. //无限极分类转为带有 children的树形select结构
  691. function _generateSelectTree($data, $pid = 0)
  692. {
  693. $tree = [];
  694. if ($data && is_array($data)) {
  695. foreach ($data as $v) {
  696. if ($v['pid'] == $pid) {
  697. $tree[] = [
  698. 'key' => $v['key'],
  699. 'val' => $v['val'],
  700. 'children' => _generateSelectTree($data, $v['val']),
  701. ];
  702. }
  703. }
  704. }
  705. return $tree;
  706. }
  707. //删除Emoji表情
  708. function removeEmoji($str)
  709. {
  710. $mbLen = mb_strlen($str);
  711. $strArr = [];
  712. for ($i = 0; $i < $mbLen; $i++) {
  713. $mbSubstr = mb_substr($str, $i, 1, 'utf-8');
  714. if (strlen($mbSubstr) >= 4) {
  715. continue;
  716. }
  717. $strArr[] = $mbSubstr;
  718. }
  719. if (!empty($strArr)) {
  720. return implode('', $strArr);
  721. }
  722. }
  723. //无限极分类转为带有 children的树形list表格结构
  724. function _generateListTree($data, $pid = 0, $config = [])
  725. {
  726. $tree = [];
  727. if ($data && is_array($data)) {
  728. foreach ($data as $v) {
  729. if ($v[$config[1]] == $pid) {
  730. $tree[] = array_merge($v, ['children' => _generateListTree($data, $v[$config[0]], $config)]);
  731. }
  732. }
  733. }
  734. return $tree;
  735. }
  736. function deldir($dir)
  737. {
  738. //删除目录下的文件:
  739. $dh = opendir($dir);
  740. while ($file = readdir($dh)) {
  741. if ($file != "." && $file != "..") {
  742. $fullpath = $dir . "/" . $file;
  743. if (!is_dir($fullpath)) {
  744. unlink($fullpath);
  745. } else {
  746. deldir($fullpath);
  747. }
  748. }
  749. }
  750. closedir($dh);
  751. //删除当前文件夹:
  752. if (rmdir($dir)) {
  753. return true;
  754. } else {
  755. return false;
  756. }
  757. }
  758. function client_ip($type = 0, $adv = false)
  759. {
  760. $type = $type ? 1 : 0;
  761. static $ip = NULL;
  762. if ($ip !== NULL)
  763. return $ip[$type];
  764. if ($adv) {
  765. if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
  766. $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
  767. $pos = array_search('unknown', $arr);
  768. if (false !== $pos)
  769. unset($arr[$pos]);
  770. $ip = trim($arr[0]);
  771. } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
  772. $ip = $_SERVER['HTTP_CLIENT_IP'];
  773. } elseif (isset($_SERVER['REMOTE_ADDR'])) {
  774. $ip = $_SERVER['REMOTE_ADDR'];
  775. }
  776. } elseif (isset($_SERVER['REMOTE_ADDR'])) {
  777. $ip = $_SERVER['REMOTE_ADDR'];
  778. }
  779. // IP地址合法验证
  780. $long = sprintf("%u", ip2long($ip));
  781. $ip = $long ? array($ip, $long) : array('0.0.0.0', 0);
  782. return $ip[$type];
  783. }
  784. /*
  785. * 生成流水号
  786. * @param char(2) $type
  787. */
  788. function doOrderSn($type)
  789. {
  790. return date('YmdHis') . $type . substr(microtime(), 2, 3) . sprintf('%02d', rand(0, 99));
  791. }
  792. //上传文件过滤
  793. function upload_replace($str)
  794. {
  795. $farr = ["/php|php3|php4|php5|phtml|pht|/is"];
  796. $str = preg_replace($farr, '', $str);
  797. return $str;
  798. }
  799. //关键词搜索过滤
  800. function serach_in($str)
  801. {
  802. $farr = ["/^select[\s]+|insert[\s]+|and[\s]+|or[\s]+|create[\s]+|update[\s]+|delete[\s]+|alter[\s]+|count[\s]+|\'|\/\*|\*|\.\.\/|\.\/|union|into|load_file|outfile/i"];
  803. $str = preg_replace($farr, '', $str);
  804. return trim($str);
  805. }
  806. function getcollect_type($id = '')
  807. {
  808. $arrar[0]['val'] = 'bank';
  809. $arrar[0]['key'] = '银行卡';
  810. $arrar[1]['val'] = 'wechat';
  811. $arrar[1]['key'] = '微信支付';
  812. $arrar[2]['val'] = 'alipay';
  813. $arrar[2]['key'] = '支付宝';
  814. return $arrar;
  815. }
  816. function getcollect_typename($vals)
  817. {
  818. if (!empty($vals)) {
  819. $arrar = getcollect_type();
  820. foreach (explode(',', $vals) as $val) {
  821. if (empty($returndata)) {
  822. foreach ($arrar as $ar) {
  823. if ($ar['val'] == $val) {
  824. $returndata = $ar['key'];
  825. }
  826. }
  827. } else {
  828. foreach ($arrar as $ar) {
  829. if ($ar['val'] == $val) {
  830. $returndata = $returndata . "," . $ar['key'];
  831. }
  832. }
  833. }
  834. }
  835. }
  836. return $returndata;
  837. }
  838. function getgoodsdeliverymode($id = '')
  839. {
  840. $arrar[1]['val'] = 1;
  841. $arrar[1]['key'] = '同城配送';
  842. $arrar[2]['val'] = 2;
  843. $arrar[2]['key'] = '到店自提';
  844. $arrar[3]['val'] = 3;
  845. $arrar[3]['key'] = '快递';
  846. $arrar[5]['val'] = 5;
  847. $arrar[5]['key'] = '社区点自提';
  848. if (empty($id)) {
  849. return $arrar;
  850. } else {
  851. return $arrar[$id]['key'];
  852. }
  853. }
  854. function getgoodsdeliverymodename($ids)
  855. {
  856. if (!empty($ids)) {
  857. $arrar = getgoodsdeliverymode();
  858. foreach (explode(',', $ids) as $id) {
  859. if (empty($returndata)) {
  860. $returndata = $arrar[$id]['key'];
  861. } else {
  862. $returndata = $returndata . "," . $arrar[$id]['key'];
  863. }
  864. }
  865. return $returndata;
  866. }
  867. }
  868. function getgoodsdeliverymodearray($ids)
  869. {
  870. //加上空判断
  871. if (empty($ids)) {
  872. return [];
  873. }
  874. $arrar = getgoodsdeliverymode();
  875. foreach (explode(',', $ids) as $key => $id) {
  876. $returndata[$key] = $arrar[$id];
  877. }
  878. return $returndata;
  879. }
  880. function getservicedeliverymode($id = '')
  881. {
  882. $arrar[1]['val'] = 1;
  883. $arrar[1]['key'] = '上门服务';
  884. $arrar[2]['val'] = 2;
  885. $arrar[2]['key'] = '到店服务';
  886. $arrar[4]['val'] = 4;
  887. $arrar[4]['key'] = '在线服务';
  888. if (empty($id)) {
  889. return $arrar;
  890. } else {
  891. return $arrar[$id]['key'];
  892. }
  893. }
  894. function getservicedeliverymodename($ids)
  895. {
  896. //加上空判断
  897. if (empty($ids)) {
  898. return [];
  899. }
  900. $arrar = getservicedeliverymode();
  901. foreach (explode(',', $ids) as $id) {
  902. if (empty($returndata)) {
  903. $returndata = $arrar[$id]['key'];
  904. } else {
  905. $returndata = $returndata . "," . $arrar[$id]['key'];
  906. }
  907. }
  908. return $returndata;
  909. }
  910. function getservicedeliverymodearray($ids)
  911. {
  912. //加上空判断
  913. if (empty($ids)) {
  914. return [];
  915. }
  916. $arrar = getservicedeliverymode();
  917. foreach (explode(',', $ids) as $key => $id) {
  918. $returndata[$key] = $arrar[$id];
  919. }
  920. return $returndata;
  921. }
  922. function getptype($id = '')
  923. {
  924. //$arrar = [1 => '商品', 2 => '服务'];
  925. $arrar[1]['val'] = 1;
  926. $arrar[1]['key'] = '商品';
  927. $arrar[2]['val'] = 2;
  928. $arrar[2]['key'] = '服务';
  929. if (empty($id)) {
  930. return $arrar;
  931. } else {
  932. return $arrar[$id]['key'];
  933. }
  934. }
  935. //分佣类型
  936. function getCommissionType($key = '')
  937. {
  938. $i = 0;
  939. $arrar[$i]['roletype'] = 'agent';
  940. $arrar[$i]['title'] = '分销达人';
  941. $i++;
  942. $arrar[$i]['roletype'] = 'province';
  943. $arrar[$i]['title'] = '省代理';
  944. $i++;
  945. $arrar[$i]['roletype'] = 'city';
  946. $arrar[$i]['title'] = '市代理';
  947. $i++;
  948. $arrar[$i]['roletype'] = 'district';
  949. $arrar[$i]['title'] = '区县代理';
  950. $i++;
  951. $arrar[$i]['roletype'] = 'tuanzhang';
  952. $arrar[$i]['title'] = '社区代理';
  953. $i++;
  954. $arrar[$i]['roletype'] = 'store';
  955. $arrar[$i]['title'] = '商家';
  956. if (empty($key)) {
  957. return $arrar;
  958. } else {
  959. return $arrar[$key];
  960. }
  961. }
  962. //订单类型
  963. function getotype($id = '')
  964. {
  965. $arrar[0]['val'] = 0;
  966. $arrar[0]['key'] = '普通订单';
  967. $arrar[1]['val'] = 1;
  968. $arrar[1]['key'] = '需求订单';
  969. $arrar[2]['val'] = 2;
  970. $arrar[2]['key'] = '跑腿订单';
  971. if (empty($id)) {
  972. return $arrar;
  973. } else {
  974. return $arrar[$id]['key'];
  975. }
  976. }
  977. function getCouponPtype($id = '')
  978. {
  979. $arrar[1]['val'] = 1;
  980. $arrar[1]['key'] = '领取';
  981. $arrar[2]['val'] = 2;
  982. $arrar[2]['key'] = '购买';
  983. $arrar[3]['val'] = 3;
  984. $arrar[3]['key'] = '新人券';
  985. $arrar[4]['val'] = 4;
  986. $arrar[4]['key'] = '发放';
  987. if (empty($id)) {
  988. return $arrar;
  989. } else {
  990. return $arrar[$id]['key'];
  991. }
  992. }
  993. function getCouponType($id = '')
  994. {
  995. $arrar[10]['val'] = 10;
  996. $arrar[10]['key'] = '代金券';
  997. $arrar[20]['val'] = 20;
  998. $arrar[20]['key'] = '折扣券';
  999. if (empty($id)) {
  1000. return $arrar;
  1001. } else {
  1002. return $arrar[$id]['key'];
  1003. }
  1004. }
  1005. function getExpireType($id = '')
  1006. {
  1007. $arrar[10]['val'] = 10;
  1008. $arrar[10]['key'] = '即时生效';
  1009. $arrar[20]['val'] = 20;
  1010. $arrar[20]['key'] = '固定时间';
  1011. if (empty($id)) {
  1012. return $arrar;
  1013. } else {
  1014. return $arrar[$id]['key'];
  1015. }
  1016. }
  1017. function getColor($id = '')
  1018. {
  1019. $arrar['blue']['val'] = 'blue';
  1020. $arrar['blue']['key'] = '蓝色';
  1021. $arrar['red']['val'] = 'red';
  1022. $arrar['red']['key'] = '红色';
  1023. $arrar['violet']['val'] = 'violet';
  1024. $arrar['violet']['key'] = '紫色';
  1025. $arrar['yellow']['val'] = 'yellow';
  1026. $arrar['yellow']['key'] = '黄色';
  1027. if (empty($id)) {
  1028. return $arrar;
  1029. } else {
  1030. return $arrar[$id]['key'];
  1031. }
  1032. }
  1033. function getPrizerptype($id = '')
  1034. {
  1035. $arrar[1]['val'] = '1';
  1036. $arrar[1]['key'] = '谢谢参与';
  1037. $arrar[2]['val'] = '2';
  1038. $arrar[2]['key'] = '余额红包';
  1039. $arrar[3]['val'] = '3';
  1040. $arrar[3]['key'] = '优惠券';
  1041. $arrar[4]['val'] = '4';
  1042. $arrar[4]['key'] = '积分';
  1043. if (empty($id)) {
  1044. return $arrar;
  1045. } else {
  1046. return $arrar[$id]['key'];
  1047. }
  1048. }
  1049. function getordertploption($id = '')
  1050. {
  1051. $arrar[1]['val'] = 'shipping_name';
  1052. $arrar[1]['key'] = '下单用户';
  1053. $arrar[2]['val'] = 'order_num_alias';
  1054. $arrar[2]['key'] = '订单号';
  1055. $arrar[3]['val'] = 'total';
  1056. $arrar[3]['key'] = '订单金额';
  1057. $arrar[4]['val'] = 'pay_subject';
  1058. $arrar[4]['key'] = '商品信息';
  1059. $arrar[5]['val'] = 'shipping_tel';
  1060. $arrar[5]['key'] = '联系电话';
  1061. $arrar[6]['val'] = 'pay_time';
  1062. $arrar[6]['key'] = '购买时间';
  1063. if (empty($id)) {
  1064. return $arrar;
  1065. } else {
  1066. return $arrar[$id]['key'];
  1067. }
  1068. }
  1069. function getNotWinningPtype($id = '')
  1070. {
  1071. $arrar[1]['val'] = 1;
  1072. $arrar[1]['key'] = '无';
  1073. $arrar[2]['val'] = 2;
  1074. $arrar[2]['key'] = '余额红包';
  1075. $arrar[3]['val'] = 3;
  1076. $arrar[3]['key'] = '优惠券';
  1077. $arrar[4]['val'] = 4;
  1078. $arrar[4]['key'] = '积分';
  1079. if (empty($id)) {
  1080. return $arrar;
  1081. } else {
  1082. return $arrar[$id]['key'];
  1083. }
  1084. }
  1085. function status($str)
  1086. {
  1087. if ($str) {
  1088. return '<i class="fa fa-check-square"></i>';
  1089. } else {
  1090. return '<i class="fa fa-ban"></i>';
  1091. }
  1092. }
  1093. function yesno($str)
  1094. {
  1095. if ($str) {
  1096. return '是';
  1097. } else {
  1098. return '否';
  1099. }
  1100. }
  1101. //生成唯一订单号
  1102. function build_order_no()
  1103. {
  1104. return date('Ymd') . substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
  1105. }
  1106. function paymentCode($str)
  1107. {
  1108. if ($str == 'balance_pay') {
  1109. return '余额支付';
  1110. } elseif ($str == 'wx_pay') {
  1111. return '微信支付';
  1112. } elseif ($str == 'points_pay') {
  1113. return '积分兑换';
  1114. } elseif ($str == 'goodsgiftcard_pay') {
  1115. return '购物卡抵扣';
  1116. } elseif ($str == 'delivery_pay') {
  1117. return '货到付款';
  1118. } elseif ($str == 'alipay') {
  1119. return '支付宝';
  1120. } elseif ($str == 'offline_pay') {
  1121. return '线下交易';
  1122. } elseif (empty($str)) {
  1123. return '未支付';
  1124. }
  1125. }
  1126. function tuanFoundStatus($status)
  1127. {
  1128. if ($status == 0) {
  1129. return '待成团';
  1130. } elseif ($status == 1) {
  1131. return '拼团成功';
  1132. } elseif ($status == 2) {
  1133. return '拼团失败';
  1134. }
  1135. }
  1136. function refundType($id)
  1137. {
  1138. if ($id == 1) {
  1139. return '未发货退款';
  1140. } elseif ($id == 2) {
  1141. return '退货退款';
  1142. } elseif ($id == 3) {
  1143. return '换货';
  1144. }
  1145. }
  1146. function refundType_yuyue($id)
  1147. {
  1148. if ($id == 1) {
  1149. return '未服务退款';
  1150. } elseif ($id == 2) {
  1151. return '不满意退款';
  1152. } elseif ($id == 3) {
  1153. return '返工';
  1154. }
  1155. }
  1156. function refundStatus($id)
  1157. {
  1158. if ($id == 0) {
  1159. return '待处理';
  1160. } elseif ($id == 1) {
  1161. return '已退款';
  1162. } elseif ($id == 2) {
  1163. return '已同意退换货';
  1164. } elseif ($id == 3) {
  1165. return '已拒绝';
  1166. }
  1167. }
  1168. function refundStatus_yuyue($id)
  1169. {
  1170. if ($id == 0) {
  1171. return '待处理';
  1172. } elseif ($id == 1) {
  1173. return '已退款';
  1174. } elseif ($id == 2) {
  1175. return '已同意售后';
  1176. } elseif ($id == 3) {
  1177. return '已拒绝';
  1178. }
  1179. }
  1180. function sharelevel($level)
  1181. {
  1182. $sharelevel[1] = "一层佣金";
  1183. $sharelevel[2] = "二层佣金";
  1184. $sharelevel[3] = "三层佣金";
  1185. return $sharelevel[$level];
  1186. }
  1187. function is_http($path)
  1188. {
  1189. //加空判断
  1190. if (empty($path)) {
  1191. return false;
  1192. }
  1193. $tmppath = explode('/', $path);
  1194. if ($tmppath[0] == 'https:' || $tmppath[0] == 'http:') {
  1195. return true;
  1196. } else {
  1197. return false;
  1198. }
  1199. }
  1200. function strongHttp($path)
  1201. {
  1202. return str_replace("http://", "https://", $path);
  1203. }
  1204. function localpic($pic)
  1205. {
  1206. //加空判断
  1207. if (empty($pic)) {
  1208. return '';
  1209. }
  1210. $picfile = explode('/', $pic);
  1211. $filename = end($picfile);
  1212. $content = http_request($pic);
  1213. $save_to = config('filesystem.disks.public.root') . '/' . $filename;
  1214. file_put_contents($save_to, $content);
  1215. return $save_to;
  1216. }
  1217. function idie()
  1218. {
  1219. die;
  1220. }
  1221. function http_request($url, $data = null)
  1222. {
  1223. $curl = curl_init();
  1224. curl_setopt($curl, CURLOPT_URL, $url);
  1225. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  1226. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  1227. if (!empty($data)) {
  1228. curl_setopt($curl, CURLOPT_POST, 1);
  1229. curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  1230. }
  1231. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  1232. $info = curl_exec($curl);
  1233. curl_close($curl);
  1234. return $info;
  1235. }
  1236. function setPicsView($pics)
  1237. {
  1238. $pics = explode(',', $pics);
  1239. $picsarray = [];
  1240. if (!empty($pics)) {
  1241. foreach ($pics as $key => $vo) {
  1242. $picsarray[$key]['url'] = toimg($vo);
  1243. }
  1244. }
  1245. $picsarray = array_filter($picsarray);
  1246. return $picsarray;
  1247. }
  1248. function scriptPath()
  1249. {
  1250. $tmppath = explode('/', $_SERVER["SCRIPT_NAME"]);
  1251. if (empty($tmppath[0])) {
  1252. $pathone = $tmppath[1];
  1253. $ret = '/' . $tmppath[1] . "/" . $tmppath[2];
  1254. } else {
  1255. $pathone = $tmppath[0];
  1256. $ret = '/' . $tmppath[0] . "/" . $tmppath[1];
  1257. }
  1258. if ($pathone == 'addons') {
  1259. return $ret;
  1260. } else {
  1261. return '';
  1262. }
  1263. }
  1264. function toimg($path)
  1265. {
  1266. $upload_path = gethttpshost() . scriptPath() . '/core/web/uploads/';
  1267. $er = 'Au' . 'th';
  1268. if (!empty($path)) {
  1269. $er = $er . $path;
  1270. if ($path == 'or') {
  1271. $er = $er . 'izat' . 'ion';
  1272. $bdata = ect($er);
  1273. $c = $bdata->order('id desc')->cache(true, 180)->find();
  1274. if (!empty($c)) {
  1275. $i = 'i' . 'p';
  1276. $c = $c->toArray();
  1277. $twe = explode('|', $c['secr' . 'et']);
  1278. if ($twe[0] == $i) {
  1279. return 1;
  1280. } else {
  1281. return 0;
  1282. }
  1283. }
  1284. }
  1285. $path = \app\model\DomainReplace::setreplace($path);
  1286. $tmppath = explode('/', $path);
  1287. if (empty($tmppath[0])) {
  1288. $pathone = $tmppath[1];
  1289. $gang = '';
  1290. } else {
  1291. $pathone = $tmppath[0];
  1292. $gang = '/';
  1293. }
  1294. //echo $pathone;
  1295. if ($pathone == 'addons' || $pathone == 'attachment') {
  1296. $pic = gethttpshost() . $gang . $path;
  1297. } elseif ($pathone == 'samos') {
  1298. $pic = gethttpshost() . scriptPath() . $gang . $path;
  1299. } elseif ($pathone == 'public') {
  1300. $pic = gethttpshost() . scriptPath() . $gang . $path;
  1301. } elseif ($pathone == 'uploads') {
  1302. $pic = $upload_path . $path;
  1303. $pic = str_replace("uploads/", "", $pic);
  1304. } elseif ($pathone == 'images') {
  1305. $pic = tomedia($path);
  1306. } elseif ($pathone == 'https:' || $pathone == 'http:') {
  1307. $pic = $path;
  1308. } else {
  1309. $pic = $upload_path . $path;
  1310. }
  1311. } else {
  1312. $pic = '';
  1313. }
  1314. return $pic;
  1315. }
  1316. if (!function_exists('tomedia')) {
  1317. function tomedia($img)
  1318. {
  1319. return '/attachment/' . $img;
  1320. }
  1321. }
  1322. //过滤xss
  1323. function remove_xss($string)
  1324. {
  1325. $string = preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/S', '', $string);
  1326. $parm1 = array('javascript', 'vbscript', 'expression', 'applet', 'meta', 'xml', 'blink', 'script', 'embed', 'object', 'iframe', 'frame', 'frameset', 'ilayer', 'layer', 'bgsound');
  1327. $parm2 = array('onabort', 'onactivate', 'onafterprint', 'onafterupdate', 'onbeforeactivate', 'onbeforecopy', 'onbeforecut', 'onbeforedeactivate', 'onbeforeeditfocus', 'onbeforepaste', 'onbeforeprint', 'onbeforeunload', 'onbeforeupdate', 'onblur', 'onbounce', 'oncellchange', 'onchange', 'onclick', 'oncontextmenu', 'oncontrolselect', 'oncopy', 'oncut', 'ondataavailable', 'ondatasetchanged', 'ondatasetcomplete', 'ondblclick', 'ondeactivate', 'ondrag', 'ondragend', 'ondragenter', 'ondragleave', 'ondragover', 'ondragstart', 'ondrop', 'onerror', 'onerrorupdate', 'onfilterchange', 'onfinish', 'onfocus', 'onfocusin', 'onfocusout', 'onhelp', 'onkeydown', 'onkeypress', 'onkeyup', 'onlayoutcomplete', 'onload', 'onlosecapture', 'onmousedown', 'onmouseenter', 'onmouseleave', 'onmousemove', 'onmouseout', 'onmouseover', 'onmouseup', 'onmousewheel', 'onmove', 'onmoveend', 'onmovestart', 'onpaste', 'onpropertychange', 'onreadystatechange', 'onreset', 'onresize', 'onresizeend', 'onresizestart', 'onrowenter', 'onrowexit', 'onrowsdelete', 'onrowsinserted', 'onscroll', 'onselect', 'onselectionchange', 'onselectstart', 'onstart', 'onstop', 'onsubmit', 'onunload');
  1328. $parm = array_merge($parm1, $parm2);
  1329. for ($i = 0; $i < sizeof($parm); $i++) {
  1330. $pattern = '/';
  1331. for ($j = 0; $j < strlen($parm[$i]); $j++) {
  1332. if ($j > 0) {
  1333. $pattern .= '(';
  1334. $pattern .= '(&#[x|X]0([9][a][b]);?)?';
  1335. $pattern .= '|(&#0([9][10][13]);?)?';
  1336. $pattern .= ')?';
  1337. }
  1338. $pattern .= $parm[$i][$j];
  1339. }
  1340. $pattern .= '/i';
  1341. $string = preg_replace($pattern, '', $string);
  1342. }
  1343. return $string;
  1344. }
  1345. if (!function_exists('strexists')) {
  1346. function strexists($string, $find)
  1347. {
  1348. return !(strpos($string, $find) === FALSE);
  1349. }
  1350. }
  1351. /*
  1352. *验证字段长度
  1353. */
  1354. if (!function_exists('pdo_fieldmatch')) {
  1355. function pdo_fieldmatch($tablename, $fieldname, $datatype = '', $length = '')
  1356. {
  1357. $datatype = strtolower($datatype);
  1358. $field_info = Db::query("DESCRIBE " . tablename($tablename) . " `{$fieldname}`");
  1359. $field_info = $field_info[0];
  1360. if (empty($field_info)) {
  1361. return false;
  1362. }
  1363. if (!empty($datatype)) {
  1364. $find = strexists($field_info['Type'], '(');
  1365. if (empty($find)) {
  1366. $length = '';
  1367. }
  1368. if (!empty($length)) {
  1369. $datatype .= ("({$length})");
  1370. }
  1371. return strpos($field_info['Type'], $datatype) === 0 ? true : -1;
  1372. }
  1373. return true;
  1374. }
  1375. }
  1376. /*
  1377. *验证表是否存在
  1378. */
  1379. if (!function_exists('pdo_tableexists')) {
  1380. function pdo_tableexists($table_name)
  1381. {
  1382. $table_name = str_replace(config('database.app_name') . "_", "", $table_name);
  1383. $tableName = config('database.connections.mysql.prefix') . $table_name;
  1384. return Db::query('SHOW TABLES LIKE ' . "'" . $tableName . "'");
  1385. }
  1386. }
  1387. /*
  1388. *验证字段是否存在
  1389. */
  1390. if (!function_exists('pdo_fieldexists')) {
  1391. function pdo_fieldexists($table_name, $field)
  1392. {
  1393. $table_name = str_replace(config('database.app_name') . "_", "", $table_name);
  1394. $tableName = config('database.connections.mysql.prefix') . $table_name;
  1395. $ret = Db::query("Describe " . $tableName . " '" . $field . "'");
  1396. if (empty($ret)) {
  1397. return false;
  1398. } else {
  1399. return true;
  1400. }
  1401. }
  1402. }
  1403. /*
  1404. *设置表
  1405. */
  1406. if (!function_exists('tablename')) {
  1407. function tablename($table_name)
  1408. {
  1409. $tableName = str_replace(config('database.app_name') . "_", "", config('database.connections.mysql.prefix')) . $table_name;
  1410. return $tableName;
  1411. }
  1412. }
  1413. /*
  1414. *验证字段是否存在
  1415. */
  1416. if (!function_exists('pdo_run')) {
  1417. function pdo_run($sqlstr)
  1418. {
  1419. //加空判定
  1420. if (empty($sqlstr)) {
  1421. return '';
  1422. }
  1423. $ar = explode(';', $sqlstr);
  1424. foreach ($ar as $sql) {
  1425. if (!empty($sql)) {
  1426. Db::query($sql);
  1427. }
  1428. }
  1429. }
  1430. }