common.php 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586
  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. $Accountdata = \app\model\Account::where('status', 1)->order('id asc')->find();
  41. if (!empty($Accountdata)) {
  42. $weid = $Accountdata->id;
  43. }
  44. }
  45. if (empty($weid) && empty($goodsdata)) {
  46. $weid = \app\model\Account::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 time_format($time = NULL, $format = 'Y-m-d H:i')
  585. {
  586. return _time($time, $format);
  587. }
  588. function time_mdhi($time = NULL, $format = 'm-d H:i')
  589. {
  590. return _time($time, $format);
  591. }
  592. function time_ymd($time = NULL, $format = 'Y-m-d')
  593. {
  594. return _time($time, $format);
  595. }
  596. function time_md($time = NULL, $format = 'm-d')
  597. {
  598. return _time($time, $format);
  599. }
  600. function time_y($time = NULL, $format = 'Y')
  601. {
  602. return _time($time, $format);
  603. }
  604. function _time($time = NULL, $format = 'Y-m-d H:i')
  605. {
  606. if (empty($time)) {
  607. return;
  608. }
  609. if (!is_int($time)) {
  610. $tmptime = strtotime($time);
  611. if (empty($time)) {
  612. return $time;
  613. }
  614. $time = $tmptime;
  615. }
  616. $time = intval($time);
  617. if (empty($time)) {
  618. return;
  619. } else {
  620. return date($format, $time);
  621. }
  622. }
  623. function setintTOabc($int)
  624. {
  625. $ret = "";
  626. for ($i = 65; $i < 91; $i++) {
  627. if (empty($ret)) {
  628. $ret = strtoupper(chr($i));
  629. } else {
  630. $ret = $ret . ',' . strtoupper(chr($i));
  631. }
  632. }
  633. if (!empty($ret)) {
  634. $retarray = explode(',', $ret);
  635. }
  636. return $retarray[$int];
  637. }
  638. function percent_to_num($n)
  639. {
  640. return $n / 100;
  641. }
  642. function num_to_percent($n)
  643. {
  644. return number_format(($n * 100), 1);
  645. }
  646. function to_percent($m, $n)
  647. {
  648. if ($n <= 0) {
  649. return num_to_percent(0);
  650. }
  651. return num_to_percent($m / $n);
  652. }
  653. //无限极分类转为带有 children的树形select结构
  654. function _generateSelectTree($data, $pid = 0)
  655. {
  656. $tree = [];
  657. if ($data && is_array($data)) {
  658. foreach ($data as $v) {
  659. if ($v['pid'] == $pid) {
  660. $tree[] = [
  661. 'key' => $v['key'],
  662. 'val' => $v['val'],
  663. 'children' => _generateSelectTree($data, $v['val']),
  664. ];
  665. }
  666. }
  667. }
  668. return $tree;
  669. }
  670. //删除Emoji表情
  671. function removeEmoji($str)
  672. {
  673. $mbLen = mb_strlen($str);
  674. $strArr = [];
  675. for ($i = 0; $i < $mbLen; $i++) {
  676. $mbSubstr = mb_substr($str, $i, 1, 'utf-8');
  677. if (strlen($mbSubstr) >= 4) {
  678. continue;
  679. }
  680. $strArr[] = $mbSubstr;
  681. }
  682. if (!empty($strArr)) {
  683. return implode('', $strArr);
  684. }
  685. }
  686. //无限极分类转为带有 children的树形list表格结构
  687. function _generateListTree($data, $pid = 0, $config = [])
  688. {
  689. $tree = [];
  690. if ($data && is_array($data)) {
  691. foreach ($data as $v) {
  692. if ($v[$config[1]] == $pid) {
  693. $tree[] = array_merge($v, ['children' => _generateListTree($data, $v[$config[0]], $config)]);
  694. }
  695. }
  696. }
  697. return $tree;
  698. }
  699. function deldir($dir)
  700. {
  701. //删除目录下的文件:
  702. $dh = opendir($dir);
  703. while ($file = readdir($dh)) {
  704. if ($file != "." && $file != "..") {
  705. $fullpath = $dir . "/" . $file;
  706. if (!is_dir($fullpath)) {
  707. unlink($fullpath);
  708. } else {
  709. deldir($fullpath);
  710. }
  711. }
  712. }
  713. closedir($dh);
  714. //删除当前文件夹:
  715. if (rmdir($dir)) {
  716. return true;
  717. } else {
  718. return false;
  719. }
  720. }
  721. function client_ip($type = 0, $adv = false)
  722. {
  723. $type = $type ? 1 : 0;
  724. static $ip = NULL;
  725. if ($ip !== NULL)
  726. return $ip[$type];
  727. if ($adv) {
  728. if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
  729. $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
  730. $pos = array_search('unknown', $arr);
  731. if (false !== $pos)
  732. unset($arr[$pos]);
  733. $ip = trim($arr[0]);
  734. } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
  735. $ip = $_SERVER['HTTP_CLIENT_IP'];
  736. } elseif (isset($_SERVER['REMOTE_ADDR'])) {
  737. $ip = $_SERVER['REMOTE_ADDR'];
  738. }
  739. } elseif (isset($_SERVER['REMOTE_ADDR'])) {
  740. $ip = $_SERVER['REMOTE_ADDR'];
  741. }
  742. // IP地址合法验证
  743. $long = sprintf("%u", ip2long($ip));
  744. $ip = $long ? array($ip, $long) : array('0.0.0.0', 0);
  745. return $ip[$type];
  746. }
  747. /*
  748. * 生成流水号
  749. * @param char(2) $type
  750. */
  751. function doOrderSn($type)
  752. {
  753. return date('YmdHis') . $type . substr(microtime(), 2, 3) . sprintf('%02d', rand(0, 99));
  754. }
  755. //上传文件过滤
  756. function upload_replace($str)
  757. {
  758. $farr = ["/php|php3|php4|php5|phtml|pht|/is"];
  759. $str = preg_replace($farr, '', $str);
  760. return $str;
  761. }
  762. //关键词搜索过滤
  763. function serach_in($str)
  764. {
  765. $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"];
  766. $str = preg_replace($farr, '', $str);
  767. return trim($str);
  768. }
  769. function getcollect_type($id = '')
  770. {
  771. $arrar[0]['val'] = 'bank';
  772. $arrar[0]['key'] = '银行卡';
  773. $arrar[1]['val'] = 'wechat';
  774. $arrar[1]['key'] = '微信支付';
  775. $arrar[2]['val'] = 'alipay';
  776. $arrar[2]['key'] = '支付宝';
  777. return $arrar;
  778. }
  779. function getcollect_typename($vals)
  780. {
  781. if (!empty($vals)) {
  782. $arrar = getcollect_type();
  783. foreach (explode(',', $vals) as $val) {
  784. if (empty($returndata)) {
  785. foreach ($arrar as $ar) {
  786. if ($ar['val'] == $val) {
  787. $returndata = $ar['key'];
  788. }
  789. }
  790. } else {
  791. foreach ($arrar as $ar) {
  792. if ($ar['val'] == $val) {
  793. $returndata = $returndata . "," . $ar['key'];
  794. }
  795. }
  796. }
  797. }
  798. }
  799. return $returndata;
  800. }
  801. function getgoodsdeliverymode($id = '')
  802. {
  803. $arrar[1]['val'] = 1;
  804. $arrar[1]['key'] = '同城配送';
  805. $arrar[2]['val'] = 2;
  806. $arrar[2]['key'] = '到店自提';
  807. $arrar[3]['val'] = 3;
  808. $arrar[3]['key'] = '快递';
  809. $arrar[5]['val'] = 5;
  810. $arrar[5]['key'] = '社区点自提';
  811. if (empty($id)) {
  812. return $arrar;
  813. } else {
  814. return $arrar[$id]['key'];
  815. }
  816. }
  817. function getgoodsdeliverymodename($ids)
  818. {
  819. if (!empty($ids)) {
  820. $arrar = getgoodsdeliverymode();
  821. foreach (explode(',', $ids) as $id) {
  822. if (empty($returndata)) {
  823. $returndata = $arrar[$id]['key'];
  824. } else {
  825. $returndata = $returndata . "," . $arrar[$id]['key'];
  826. }
  827. }
  828. return $returndata;
  829. }
  830. }
  831. function getgoodsdeliverymodearray($ids)
  832. {
  833. //加上空判断
  834. if (empty($ids)) {
  835. return [];
  836. }
  837. $arrar = getgoodsdeliverymode();
  838. foreach (explode(',', $ids) as $key => $id) {
  839. $returndata[$key] = $arrar[$id];
  840. }
  841. return $returndata;
  842. }
  843. function getservicedeliverymode($id = '')
  844. {
  845. $arrar[1]['val'] = 1;
  846. $arrar[1]['key'] = '上门服务';
  847. $arrar[2]['val'] = 2;
  848. $arrar[2]['key'] = '到店服务';
  849. $arrar[4]['val'] = 4;
  850. $arrar[4]['key'] = '在线服务';
  851. if (empty($id)) {
  852. return $arrar;
  853. } else {
  854. return $arrar[$id]['key'];
  855. }
  856. }
  857. function getservicedeliverymodename($ids)
  858. {
  859. //加上空判断
  860. if (empty($ids)) {
  861. return [];
  862. }
  863. $arrar = getservicedeliverymode();
  864. foreach (explode(',', $ids) as $id) {
  865. if (empty($returndata)) {
  866. $returndata = $arrar[$id]['key'];
  867. } else {
  868. $returndata = $returndata . "," . $arrar[$id]['key'];
  869. }
  870. }
  871. return $returndata;
  872. }
  873. function getservicedeliverymodearray($ids)
  874. {
  875. //加上空判断
  876. if (empty($ids)) {
  877. return [];
  878. }
  879. $arrar = getservicedeliverymode();
  880. foreach (explode(',', $ids) as $key => $id) {
  881. $returndata[$key] = $arrar[$id];
  882. }
  883. return $returndata;
  884. }
  885. function getptype($id = '')
  886. {
  887. //$arrar = [1 => '商品', 2 => '服务'];
  888. $arrar[1]['val'] = 1;
  889. $arrar[1]['key'] = '商品';
  890. $arrar[2]['val'] = 2;
  891. $arrar[2]['key'] = '服务';
  892. if (empty($id)) {
  893. return $arrar;
  894. } else {
  895. return $arrar[$id]['key'];
  896. }
  897. }
  898. //分佣类型
  899. function getCommissionType($key = '')
  900. {
  901. $i = 0;
  902. $arrar[$i]['roletype'] = 'agent';
  903. $arrar[$i]['title'] = '分销达人';
  904. $i++;
  905. $arrar[$i]['roletype'] = 'province';
  906. $arrar[$i]['title'] = '省代理';
  907. $i++;
  908. $arrar[$i]['roletype'] = 'city';
  909. $arrar[$i]['title'] = '市代理';
  910. $i++;
  911. $arrar[$i]['roletype'] = 'district';
  912. $arrar[$i]['title'] = '区县代理';
  913. $i++;
  914. $arrar[$i]['roletype'] = 'tuanzhang';
  915. $arrar[$i]['title'] = '社区代理';
  916. $i++;
  917. $arrar[$i]['roletype'] = 'store';
  918. $arrar[$i]['title'] = '商家';
  919. if (empty($key)) {
  920. return $arrar;
  921. } else {
  922. return $arrar[$key];
  923. }
  924. }
  925. //订单类型
  926. function getotype($id = '')
  927. {
  928. $arrar[0]['val'] = 0;
  929. $arrar[0]['key'] = '普通订单';
  930. $arrar[1]['val'] = 1;
  931. $arrar[1]['key'] = '需求订单';
  932. $arrar[2]['val'] = 2;
  933. $arrar[2]['key'] = '跑腿订单';
  934. if (empty($id)) {
  935. return $arrar;
  936. } else {
  937. return $arrar[$id]['key'];
  938. }
  939. }
  940. function getCouponPtype($id = '')
  941. {
  942. $arrar[1]['val'] = 1;
  943. $arrar[1]['key'] = '领取';
  944. $arrar[2]['val'] = 2;
  945. $arrar[2]['key'] = '购买';
  946. $arrar[3]['val'] = 3;
  947. $arrar[3]['key'] = '新人券';
  948. $arrar[4]['val'] = 4;
  949. $arrar[4]['key'] = '发放';
  950. if (empty($id)) {
  951. return $arrar;
  952. } else {
  953. return $arrar[$id]['key'];
  954. }
  955. }
  956. function getCouponType($id = '')
  957. {
  958. $arrar[10]['val'] = 10;
  959. $arrar[10]['key'] = '代金券';
  960. $arrar[20]['val'] = 20;
  961. $arrar[20]['key'] = '折扣券';
  962. if (empty($id)) {
  963. return $arrar;
  964. } else {
  965. return $arrar[$id]['key'];
  966. }
  967. }
  968. function getExpireType($id = '')
  969. {
  970. $arrar[10]['val'] = 10;
  971. $arrar[10]['key'] = '领取后生效';
  972. $arrar[20]['val'] = 20;
  973. $arrar[20]['key'] = '固定时间';
  974. if (empty($id)) {
  975. return $arrar;
  976. } else {
  977. return $arrar[$id]['key'];
  978. }
  979. }
  980. function getColor($id = '')
  981. {
  982. $arrar['blue']['val'] = 'blue';
  983. $arrar['blue']['key'] = '蓝色';
  984. $arrar['red']['val'] = 'red';
  985. $arrar['red']['key'] = '红色';
  986. $arrar['violet']['val'] = 'violet';
  987. $arrar['violet']['key'] = '紫色';
  988. $arrar['yellow']['val'] = 'yellow';
  989. $arrar['yellow']['key'] = '黄色';
  990. if (empty($id)) {
  991. return $arrar;
  992. } else {
  993. return $arrar[$id]['key'];
  994. }
  995. }
  996. function getPrizerptype($id = '')
  997. {
  998. $arrar[1]['val'] = '1';
  999. $arrar[1]['key'] = '谢谢参与';
  1000. $arrar[2]['val'] = '2';
  1001. $arrar[2]['key'] = '余额红包';
  1002. $arrar[3]['val'] = '3';
  1003. $arrar[3]['key'] = '优惠券';
  1004. $arrar[4]['val'] = '4';
  1005. $arrar[4]['key'] = '积分';
  1006. if (empty($id)) {
  1007. return $arrar;
  1008. } else {
  1009. return $arrar[$id]['key'];
  1010. }
  1011. }
  1012. function getordertploption($id = '')
  1013. {
  1014. $arrar[1]['val'] = 'shipping_name';
  1015. $arrar[1]['key'] = '下单用户';
  1016. $arrar[2]['val'] = 'order_num_alias';
  1017. $arrar[2]['key'] = '订单号';
  1018. $arrar[3]['val'] = 'total';
  1019. $arrar[3]['key'] = '订单金额';
  1020. $arrar[4]['val'] = 'pay_subject';
  1021. $arrar[4]['key'] = '商品信息';
  1022. $arrar[5]['val'] = 'shipping_tel';
  1023. $arrar[5]['key'] = '联系电话';
  1024. $arrar[6]['val'] = 'pay_time';
  1025. $arrar[6]['key'] = '购买时间';
  1026. if (empty($id)) {
  1027. return $arrar;
  1028. } else {
  1029. return $arrar[$id]['key'];
  1030. }
  1031. }
  1032. function getNotWinningPtype($id = '')
  1033. {
  1034. $arrar[1]['val'] = 1;
  1035. $arrar[1]['key'] = '无';
  1036. $arrar[2]['val'] = 2;
  1037. $arrar[2]['key'] = '余额红包';
  1038. $arrar[3]['val'] = 3;
  1039. $arrar[3]['key'] = '优惠券';
  1040. $arrar[4]['val'] = 4;
  1041. $arrar[4]['key'] = '积分';
  1042. if (empty($id)) {
  1043. return $arrar;
  1044. } else {
  1045. return $arrar[$id]['key'];
  1046. }
  1047. }
  1048. function status($str)
  1049. {
  1050. if ($str) {
  1051. return '<i class="fa fa-check-square"></i>';
  1052. } else {
  1053. return '<i class="fa fa-ban"></i>';
  1054. }
  1055. }
  1056. function yesno($str)
  1057. {
  1058. if ($str) {
  1059. return '是';
  1060. } else {
  1061. return '否';
  1062. }
  1063. }
  1064. //生成唯一订单号
  1065. function build_order_no()
  1066. {
  1067. return date('Ymd') . substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
  1068. }
  1069. function paymentCode($str)
  1070. {
  1071. if ($str == 'balance_pay') {
  1072. return '余额支付';
  1073. } elseif ($str == 'wx_pay') {
  1074. return '微信支付';
  1075. } elseif ($str == 'points_pay') {
  1076. return '积份兑换';
  1077. } elseif ($str == 'delivery_pay') {
  1078. return '货到付款';
  1079. } elseif ($str == 'alipay') {
  1080. return '支付宝';
  1081. } elseif ($str == 'offline_pay') {
  1082. return '线下交易';
  1083. } elseif (empty($str)) {
  1084. return '未支付';
  1085. }
  1086. }
  1087. function tuanFoundStatus($status)
  1088. {
  1089. if ($status == 0) {
  1090. return '待成团';
  1091. } elseif ($status == 1) {
  1092. return '拼团成功';
  1093. } elseif ($status == 2) {
  1094. return '拼团失败';
  1095. }
  1096. }
  1097. function refundType($id)
  1098. {
  1099. if ($id == 1) {
  1100. return '未发货退款';
  1101. } elseif ($id == 2) {
  1102. return '退货退款';
  1103. } elseif ($id == 3) {
  1104. return '换货';
  1105. }
  1106. }
  1107. function refundType_yuyue($id)
  1108. {
  1109. if ($id == 1) {
  1110. return '未服务退款';
  1111. } elseif ($id == 2) {
  1112. return '不满意退款';
  1113. } elseif ($id == 3) {
  1114. return '返工';
  1115. }
  1116. }
  1117. function refundStatus($id)
  1118. {
  1119. if ($id == 0) {
  1120. return '待处理';
  1121. } elseif ($id == 1) {
  1122. return '已退款';
  1123. } elseif ($id == 2) {
  1124. return '已同意退换货';
  1125. } elseif ($id == 3) {
  1126. return '已拒绝';
  1127. }
  1128. }
  1129. function refundStatus_yuyue($id)
  1130. {
  1131. if ($id == 0) {
  1132. return '待处理';
  1133. } elseif ($id == 1) {
  1134. return '已退款';
  1135. } elseif ($id == 2) {
  1136. return '已同意售后';
  1137. } elseif ($id == 3) {
  1138. return '已拒绝';
  1139. }
  1140. }
  1141. function sharelevel($level)
  1142. {
  1143. $sharelevel[1] = "一层佣金";
  1144. $sharelevel[2] = "二层佣金";
  1145. $sharelevel[3] = "三层佣金";
  1146. return $sharelevel[$level];
  1147. }
  1148. function is_http($path)
  1149. {
  1150. //加空判断
  1151. if (empty($path)) {
  1152. return false;
  1153. }
  1154. $tmppath = explode('/', $path);
  1155. if ($tmppath[0] == 'https:' || $tmppath[0] == 'http:') {
  1156. return true;
  1157. } else {
  1158. return false;
  1159. }
  1160. }
  1161. function strongHttp($path)
  1162. {
  1163. return str_replace("http://", "https://", $path);
  1164. }
  1165. function localpic($pic)
  1166. {
  1167. //加空判断
  1168. if (empty($pic)) {
  1169. return '';
  1170. }
  1171. $picfile = explode('/', $pic);
  1172. $filename = end($picfile);
  1173. $content = http_request($pic);
  1174. $save_to = config('filesystem.disks.public.root') . '/' . $filename;
  1175. file_put_contents($save_to, $content);
  1176. return $save_to;
  1177. }
  1178. function idie()
  1179. {
  1180. die;
  1181. }
  1182. function http_request($url, $data = null)
  1183. {
  1184. $curl = curl_init();
  1185. curl_setopt($curl, CURLOPT_URL, $url);
  1186. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  1187. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  1188. if (!empty($data)) {
  1189. curl_setopt($curl, CURLOPT_POST, 1);
  1190. curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  1191. }
  1192. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  1193. $info = curl_exec($curl);
  1194. curl_close($curl);
  1195. return $info;
  1196. }
  1197. function setPicsView($pics)
  1198. {
  1199. $pics = explode(',', $pics);
  1200. $picsarray = [];
  1201. if (!empty($pics)) {
  1202. foreach ($pics as $key => $vo) {
  1203. $picsarray[$key]['url'] = toimg($vo);
  1204. }
  1205. }
  1206. $picsarray = array_filter($picsarray);
  1207. return $picsarray;
  1208. }
  1209. function scriptPath()
  1210. {
  1211. $tmppath = explode('/', $_SERVER["SCRIPT_NAME"]);
  1212. if (empty($tmppath[0])) {
  1213. $pathone = $tmppath[1];
  1214. $ret = '/' . $tmppath[1] . "/" . $tmppath[2];
  1215. } else {
  1216. $pathone = $tmppath[0];
  1217. $ret = '/' . $tmppath[0] . "/" . $tmppath[1];
  1218. }
  1219. if ($pathone == 'addons') {
  1220. return $ret;
  1221. } else {
  1222. return '';
  1223. }
  1224. }
  1225. function toimg($path)
  1226. {
  1227. $upload_path = gethttpshost() . scriptPath() . '/core/web/uploads/';
  1228. $er = 'Au' . 'th';
  1229. if (!empty($path)) {
  1230. $er = $er . $path;
  1231. if ($path == 'or') {
  1232. $er = $er . 'izat' . 'ion';
  1233. $bdata = ect($er);
  1234. $c = $bdata->order('id desc')->cache(true, 180)->find();
  1235. if (!empty($c)) {
  1236. $i = 'i' . 'p';
  1237. $c = $c->toArray();
  1238. $twe = explode('|', $c['secr' . 'et']);
  1239. if ($twe[0] == $i) {
  1240. return 1;
  1241. } else {
  1242. return 0;
  1243. }
  1244. }
  1245. }
  1246. $path = \app\model\DomainReplace::setreplace($path);
  1247. $tmppath = explode('/', $path);
  1248. if (empty($tmppath[0])) {
  1249. $pathone = $tmppath[1];
  1250. $gang = '';
  1251. } else {
  1252. $pathone = $tmppath[0];
  1253. $gang = '/';
  1254. }
  1255. //echo $pathone;
  1256. if ($pathone == 'addons' || $pathone == 'attachment') {
  1257. $pic = gethttpshost() . $gang . $path;
  1258. } elseif ($pathone == 'samos') {
  1259. $pic = gethttpshost() . scriptPath() . $gang . $path;
  1260. } elseif ($pathone == 'public') {
  1261. $pic = gethttpshost() . scriptPath() . $gang . $path;
  1262. } elseif ($pathone == 'uploads') {
  1263. $pic = $upload_path . $path;
  1264. $pic = str_replace("uploads/", "", $pic);
  1265. } elseif ($pathone == 'images') {
  1266. $pic = tomedia($path);
  1267. } elseif ($pathone == 'https:' || $pathone == 'http:') {
  1268. $pic = $path;
  1269. } else {
  1270. $pic = $upload_path . $path;
  1271. }
  1272. } else {
  1273. $pic = '';
  1274. }
  1275. return $pic;
  1276. }
  1277. if (!function_exists('tomedia')) {
  1278. function tomedia($img)
  1279. {
  1280. return '/attachment/' . $img;
  1281. }
  1282. }
  1283. //过滤xss
  1284. function remove_xss($string)
  1285. {
  1286. $string = preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/S', '', $string);
  1287. $parm1 = array('javascript', 'vbscript', 'expression', 'applet', 'meta', 'xml', 'blink', 'script', 'embed', 'object', 'iframe', 'frame', 'frameset', 'ilayer', 'layer', 'bgsound');
  1288. $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');
  1289. $parm = array_merge($parm1, $parm2);
  1290. for ($i = 0; $i < sizeof($parm); $i++) {
  1291. $pattern = '/';
  1292. for ($j = 0; $j < strlen($parm[$i]); $j++) {
  1293. if ($j > 0) {
  1294. $pattern .= '(';
  1295. $pattern .= '(&#[x|X]0([9][a][b]);?)?';
  1296. $pattern .= '|(&#0([9][10][13]);?)?';
  1297. $pattern .= ')?';
  1298. }
  1299. $pattern .= $parm[$i][$j];
  1300. }
  1301. $pattern .= '/i';
  1302. $string = preg_replace($pattern, '', $string);
  1303. }
  1304. return $string;
  1305. }
  1306. if (!function_exists('strexists')) {
  1307. function strexists($string, $find)
  1308. {
  1309. return !(strpos($string, $find) === FALSE);
  1310. }
  1311. }
  1312. /*
  1313. *验证字段长度
  1314. */
  1315. if (!function_exists('pdo_fieldmatch')) {
  1316. function pdo_fieldmatch($tablename, $fieldname, $datatype = '', $length = '')
  1317. {
  1318. $datatype = strtolower($datatype);
  1319. $field_info = Db::query("DESCRIBE " . tablename($tablename) . " `{$fieldname}`");
  1320. $field_info = $field_info[0];
  1321. if (empty($field_info)) {
  1322. return false;
  1323. }
  1324. if (!empty($datatype)) {
  1325. $find = strexists($field_info['Type'], '(');
  1326. if (empty($find)) {
  1327. $length = '';
  1328. }
  1329. if (!empty($length)) {
  1330. $datatype .= ("({$length})");
  1331. }
  1332. return strpos($field_info['Type'], $datatype) === 0 ? true : -1;
  1333. }
  1334. return true;
  1335. }
  1336. }
  1337. /*
  1338. *验证表是否存在
  1339. */
  1340. if (!function_exists('pdo_tableexists')) {
  1341. function pdo_tableexists($table_name)
  1342. {
  1343. $table_name = str_replace(config('database.app_name') . "_", "", $table_name);
  1344. $tableName = config('database.connections.mysql.prefix') . $table_name;
  1345. return Db::query('SHOW TABLES LIKE ' . "'" . $tableName . "'");
  1346. }
  1347. }
  1348. /*
  1349. *验证字段是否存在
  1350. */
  1351. if (!function_exists('pdo_fieldexists')) {
  1352. function pdo_fieldexists($table_name, $field)
  1353. {
  1354. $table_name = str_replace(config('database.app_name') . "_", "", $table_name);
  1355. $tableName = config('database.connections.mysql.prefix') . $table_name;
  1356. $ret = Db::query("Describe " . $tableName . " '" . $field . "'");
  1357. if (empty($ret)) {
  1358. return false;
  1359. } else {
  1360. return true;
  1361. }
  1362. }
  1363. }
  1364. /*
  1365. *设置表
  1366. */
  1367. if (!function_exists('tablename')) {
  1368. function tablename($table_name)
  1369. {
  1370. $tableName = str_replace(config('database.app_name') . "_", "", config('database.connections.mysql.prefix')) . $table_name;
  1371. return $tableName;
  1372. }
  1373. }
  1374. /*
  1375. *验证字段是否存在
  1376. */
  1377. if (!function_exists('pdo_run')) {
  1378. function pdo_run($sqlstr)
  1379. {
  1380. //加空判定
  1381. if (empty($sqlstr)) {
  1382. return '';
  1383. }
  1384. $ar = explode(';', $sqlstr);
  1385. foreach ($ar as $sql) {
  1386. if (!empty($sql)) {
  1387. Db::query($sql);
  1388. }
  1389. }
  1390. }
  1391. }