common.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: 流年 <liu21st@gmail.com>
  10. // +----------------------------------------------------------------------
  11. use \think\facade\Config as ThinkConf;
  12. use \think\facade\Log;
  13. // 应用公共文件
  14. // 通用预定义
  15. define('SHOW', 1);
  16. define('HIDE', 0);
  17. define('ENABLED', 1);
  18. define('DISABLED', 0);
  19. define('YES', 1);
  20. define('NO', 0);
  21. // 订单常量
  22. // 订单状态(-1 : 申请退款 -2 : 退货成功 0:待发货;1:待收货;2:已收货;3:待评价;-1:已退款)
  23. define('ORDER_REFUND_REQUSTED', -1);
  24. define('ORDER_REFUNDED', -2);
  25. define('ORDER_WAITING_SHIP', 0);
  26. define('ORDER_WAITING_RECEIPT', 1);
  27. define('ORDER_RECEIPTED', 2);
  28. define('ORDER_WAITING_COMMENT', 3);
  29. // 佣金类型
  30. define('BILL_ALL', 0); // 全部
  31. define('BILL_SPEND', 1); // 消费
  32. define('BILL_RECHARGE', 2); // 充值
  33. define('BILL_BROKERAGE', 3); // 返佣
  34. define('BILL_EXTRACT', 4); // 提现
  35. // 退款状态
  36. // 0 未退款 1 申请中 2 已退款
  37. define('REFUND_NO', 0);
  38. define('REFUNDING', 1);
  39. define('REFUNDED', 2);
  40. // 提现状态
  41. // 0 审核中, -1 未通过, 1 已提现
  42. define('EXTRACT_AUDITING', 0);
  43. define('EXTRACT_FAILED', -1);
  44. define('EXTRACT_SUC', 1);
  45. // 配送方式
  46. // 配送方式 1=快递 ,2=门店自提
  47. define('SHIPPING_EXPRESS', 1);
  48. define('SHIPPING_SELF_COLLECT', 2);
  49. // 分銷方式
  50. define('DISTRIBUTE_SPECIFIED', 1); // 指定分銷
  51. define('DISTRIBUTE_EVERYONE', 2); // 人人分銷
  52. // 文件上传类型
  53. define('UPLOAD_FS', 1);
  54. define('UPLOAD_QINIU', 2);
  55. define('UPLOAD_ALI_OSS', 3);
  56. define('UPLOAD_TENCENT_COS', 4);
  57. // 每天秒数
  58. define('SECONDS_OF_ONEDAY', 86400);
  59. define('DS', DIRECTORY_SEPARATOR);
  60. // 商品规格类型
  61. define('SPEC_TYPE_SINGLE', 0);
  62. define('SPEC_TYPE_MULTI', 1);
  63. /**
  64. *
  65. */
  66. function errlog($log)
  67. {
  68. return Log::error($log);
  69. }
  70. function warnlog($log)
  71. {
  72. return Log::warning($log);
  73. }
  74. function debuglog($log)
  75. {
  76. return Log::debug($log);
  77. }
  78. function infolog($log)
  79. {
  80. return Log::info($log);
  81. }
  82. /**
  83. * 获取所有 幸运2021 活动及其子活动 ID 列表
  84. */
  85. function get_luckies(): array
  86. {
  87. return [
  88. ThinkConf::get('activity.lucky_cate_id'),
  89. ThinkConf::get('activity.lucky_a_cate_id'),
  90. ThinkConf::get('activity.lucky_b_cate_id'),
  91. ];
  92. }
  93. /**
  94. * 根据配置拼接幸运活动完整名称
  95. */
  96. function get_luck_name(): string
  97. {
  98. $spec_name = ThinkConf::get('activity.lucky_spec_name');
  99. $spec_items = ThinkConf::get('activity.lucky_spec_items');
  100. return $spec_name . implode('', $spec_items);
  101. }
  102. /**
  103. * 获取 提现类型, 帐号,用于日志或者消息
  104. */
  105. function get_extract_name($extract): array
  106. {
  107. if (!$extract || !isset($extract['extract_type'])) {
  108. return ['未知', ''];
  109. }
  110. switch ($extract['extract_type']) {
  111. case 'weixin':
  112. return ['微信支付', $extract['wechat'] ?? ''];
  113. case 'alipay':
  114. return ['支付宝', $extract['alipay_code'] ?? ''];
  115. case 'bank':
  116. return [$extract['bank_address'] ?? '未知银行', $extract['bank_code'] ?? ''];
  117. }
  118. return ['未知', ''];
  119. }
  120. /**
  121. * 獲取活動賠付比例
  122. * @cid 分類ID
  123. */
  124. function getRate($sid): float
  125. {
  126. $activities = [
  127. ThinkConf::get('activity.clearance_cate_id') => ThinkConf::get('activity.clearrance_rate'),
  128. ThinkConf::get('activity.lucky_cate_id') => ThinkConf::get('activity.luck_rate'),
  129. ThinkConf::get('activity.lucky_a_cate_id') => ThinkConf::get('activity.luck_a_rate'),
  130. ThinkConf::get('activity.lucky_b_cate_id') => ThinkConf::get('activity.luck_b_rate'),
  131. ];
  132. return $activities[$sid] ?? 0.0;
  133. }
  134. /**
  135. * 获取商品需要赔付多少钱
  136. * @product: 商品各属性, 必须设置 price, cost 字段
  137. * @rate: 当前商品所属活动的赔付百分比
  138. */
  139. function getReputation($product, $rate): float
  140. {
  141. return bcadd(bcmul(bcsub($product['price'], $product['cost'], 2), $rate, 2), $product['price'], 2);
  142. }
  143. if (!function_exists('exception')) {
  144. /**
  145. * 抛出异常处理
  146. *
  147. * @param string $msg 异常消息
  148. * @param integer $code 异常代码 默认为0
  149. * @param string $exception 异常类
  150. *
  151. * @throws Exception
  152. */
  153. function exception($msg, $code = 0, $exception = '')
  154. {
  155. $e = $exception ?: '\think\Exception';
  156. throw new $e($msg, $code);
  157. }
  158. }
  159. if (!function_exists('sys_config')) {
  160. /**
  161. * 获取系统单个配置
  162. * @param string $name
  163. * @param string $default
  164. * @return string
  165. */
  166. function sys_config(string $name, $default = '')
  167. {
  168. if (empty($name))
  169. return $default;
  170. $config = trim(app('sysConfig')->get($name));
  171. if ($config === '' || $config === false) {
  172. return $default;
  173. } else {
  174. return $config;
  175. }
  176. }
  177. }
  178. if (!function_exists('sys_data')) {
  179. /**
  180. * 获取系统单个配置
  181. * @param string $name
  182. * @return string|array
  183. */
  184. function sys_data(string $name, int $limit = 0)
  185. {
  186. return app('sysGroupData')->getData($name, $limit);
  187. }
  188. }
  189. if (!function_exists('filter_emoji')) {
  190. // 过滤掉emoji表情
  191. function filter_emoji($str)
  192. {
  193. $str = preg_replace_callback( //执行一个正则表达式搜索并且使用一个回调进行替换
  194. '/./u',
  195. function (array $match) {
  196. return strlen($match[0]) >= 4 ? '' : $match[0];
  197. },
  198. $str
  199. );
  200. return $str;
  201. }
  202. }
  203. if (!function_exists('str_middle_replace')) {
  204. /** TODO 系统未使用
  205. * @param string $string 需要替换的字符串
  206. * @param int $start 开始的保留几位
  207. * @param int $end 最后保留几位
  208. * @return string
  209. */
  210. function str_middle_replace($string, $start, $end)
  211. {
  212. $strlen = mb_strlen($string, 'UTF-8'); //获取字符串长度
  213. $firstStr = mb_substr($string, 0, $start, 'UTF-8'); //获取第一位
  214. $lastStr = mb_substr($string, -1, $end, 'UTF-8'); //获取最后一位
  215. return $strlen == 2 ? $firstStr . str_repeat('*', mb_strlen($string, 'utf-8') - 1) : $firstStr . str_repeat("*", $strlen - 2) . $lastStr;
  216. }
  217. }
  218. if (!function_exists('sensitive_words_filter')) {
  219. /**
  220. * 敏感词过滤
  221. *
  222. * @param string
  223. * @return string
  224. */
  225. function sensitive_words_filter($str)
  226. {
  227. if (!$str) return '';
  228. $file = app()->getAppPath() . 'public/static/plug/censorwords/CensorWords';
  229. $words = file($file);
  230. foreach ($words as $word) {
  231. $word = str_replace(array("\r\n", "\r", "\n", "/", "<", ">", "=", " "), '', $word);
  232. if (!$word) continue;
  233. $ret = preg_match("/$word/", $str, $match);
  234. if ($ret) {
  235. return $match[0];
  236. }
  237. }
  238. return '';
  239. }
  240. }
  241. if (!function_exists('make_path')) {
  242. /**
  243. * 上传路径转化,默认路径
  244. * @param $path
  245. * @param int $type
  246. * @param bool $force
  247. * @return string
  248. */
  249. function make_path($path, int $type = 2, bool $force = false)
  250. {
  251. $path = DS . ltrim(rtrim($path));
  252. switch ($type) {
  253. case 1:
  254. $path .= DS . date('Y');
  255. break;
  256. case 2:
  257. $path .= DS . date('Y') . DS . date('m');
  258. break;
  259. case 3:
  260. $path .= DS . date('Y') . DS . date('m') . DS . date('d');
  261. break;
  262. }
  263. try {
  264. if (is_dir(app()->getRootPath() . 'public' . DS . 'uploads' . $path) == true || mkdir(app()->getRootPath() . 'public' . DS . 'uploads' . $path, 0777, true) == true) {
  265. return trim(str_replace(DS, '/', $path), '.');
  266. } else return '';
  267. } catch (\Exception $e) {
  268. if ($force)
  269. throw new \Exception($e->getMessage());
  270. return '无法创建文件夹,请检查您的上传目录权限:' . app()->getRootPath() . 'public' . DS . 'uploads' . DS . 'attach' . DS;
  271. }
  272. }
  273. }
  274. if (!function_exists('curl_file_exist')) {
  275. /**
  276. * CURL 检测远程文件是否在
  277. * @param $url
  278. * @return bool
  279. */
  280. function curl_file_exist($url)
  281. {
  282. $ch = curl_init();
  283. try {
  284. curl_setopt($ch, CURLOPT_URL, $url);
  285. curl_setopt($ch, CURLOPT_HEADER, 1);
  286. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  287. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
  288. $contents = curl_exec($ch);
  289. if (preg_match("/404/", $contents)) return false;
  290. if (preg_match("/403/", $contents)) return false;
  291. return true;
  292. } catch (\Exception $e) {
  293. return false;
  294. }
  295. }
  296. }
  297. if (!function_exists('set_file_url')) {
  298. /**
  299. * 设置附加路径
  300. * @param $url
  301. * @return bool
  302. */
  303. function set_file_url($image, $siteUrl = '')
  304. {
  305. if (!strlen(trim($siteUrl))) $siteUrl = sys_config('site_url');
  306. $domainTop = substr($image, 0, 4);
  307. if ($domainTop == 'http') return $image;
  308. $image = str_replace('\\', '/', $image);
  309. return $siteUrl . $image;
  310. }
  311. }
  312. if (!function_exists('set_http_type')) {
  313. /**
  314. * 修改 https 和 http
  315. * @param string $url 域名
  316. * @param int $type 0 返回https 1 返回 http
  317. * @return string
  318. */
  319. function set_http_type($url, $type = 0)
  320. {
  321. $domainTop = substr($url, 0, 5);
  322. if ($type) {
  323. if ($domainTop == 'https') $url = 'http' . substr($url, 5, strlen($url));
  324. } else {
  325. if ($domainTop != 'https') $url = 'https:' . substr($url, 5, strlen($url));
  326. }
  327. return $url;
  328. }
  329. }
  330. if (!function_exists('check_card')) {
  331. /**
  332. * 身份证验证
  333. * @param $card
  334. * @return bool
  335. */
  336. function check_card($card)
  337. {
  338. $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 => "国外 "];
  339. $tip = "";
  340. $match = "/^\d{6}(18|19|20)?\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/";
  341. $pass = true;
  342. if (!$card || !preg_match($match, $card)) {
  343. //身份证格式错误
  344. $pass = false;
  345. } else if (!$city[substr($card, 0, 2)]) {
  346. //地址错误
  347. $pass = false;
  348. } else {
  349. //18位身份证需要验证最后一位校验位
  350. if (strlen($card) == 18) {
  351. $card = str_split($card);
  352. //∑(ai×Wi)(mod 11)
  353. //加权因子
  354. $factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
  355. //校验位
  356. $parity = [1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2];
  357. $sum = 0;
  358. $ai = 0;
  359. $wi = 0;
  360. for ($i = 0; $i < 17; $i++) {
  361. $ai = $card[$i];
  362. $wi = $factor[$i];
  363. $sum += $ai * $wi;
  364. }
  365. $last = $parity[$sum % 11];
  366. if ($parity[$sum % 11] != $card[17]) {
  367. // $tip = "校验位错误";
  368. $pass = false;
  369. }
  370. } else {
  371. $pass = false;
  372. }
  373. }
  374. if (!$pass) return false;/* 身份证格式错误*/
  375. return true;/* 身份证格式正确*/
  376. }
  377. }
  378. if (!function_exists('check_phone')) {
  379. /**
  380. * 手机号验证
  381. * @param $phone
  382. * @return false|int
  383. */
  384. function check_phone($phone)
  385. {
  386. return preg_match("/^1[3456789]\d{9}$/", $phone);
  387. }
  388. }
  389. if (!function_exists('anonymity')) {
  390. /**
  391. * 匿名处理处理用户昵称
  392. * @param $name
  393. * @return string
  394. */
  395. function anonymity($name)
  396. {
  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. if (!function_exists('sort_list_tier')) {
  408. /**
  409. * 分级排序
  410. * @param $data
  411. * @param int $pid
  412. * @param string $field
  413. * @param string $pk
  414. * @param string $html
  415. * @param int $level
  416. * @param bool $clear
  417. * @return array
  418. */
  419. function sort_list_tier($data, $pid = 0, $field = 'pid', $pk = 'id', $html = '|-----', $level = 1, $clear = true)
  420. {
  421. static $list = [];
  422. if ($clear) $list = [];
  423. foreach ($data as $k => $res) {
  424. if ($res[$field] == $pid) {
  425. $res['html'] = str_repeat($html, $level);
  426. $list[] = $res;
  427. unset($data[$k]);
  428. sort_list_tier($data, $res[$pk], $field, $pk, $html, $level + 1, false);
  429. }
  430. }
  431. return $list;
  432. }
  433. }
  434. if (!function_exists('time_tran')) {
  435. /**
  436. * 时间戳人性化转化
  437. * @param $time
  438. * @return string
  439. */
  440. function time_tran($time)
  441. {
  442. $t = time() - $time;
  443. $f = array(
  444. '31536000' => '年',
  445. '2592000' => '个月',
  446. '604800' => '星期',
  447. '86400' => '天',
  448. '3600' => '小时',
  449. '60' => '分钟',
  450. '1' => '秒'
  451. );
  452. foreach ($f as $k => $v) {
  453. if (0 != $c = floor($t / (int)$k)) {
  454. return $c . $v . '前';
  455. }
  456. }
  457. }
  458. }
  459. if (!function_exists('url_to_path')) {
  460. /**
  461. * url转换路径
  462. * @param $url
  463. * @return string
  464. */
  465. function url_to_path($url)
  466. {
  467. $path = trim(str_replace('/', DS, $url), DS);
  468. if (0 !== strripos($path, 'public'))
  469. $path = 'public' . DS . $path;
  470. return app()->getRootPath() . $path;
  471. }
  472. }
  473. if (!function_exists('path_to_url')) {
  474. /**
  475. * 路径转url路径
  476. * @param $path
  477. * @return string
  478. */
  479. function path_to_url($path)
  480. {
  481. return trim(str_replace(DS, '/', $path), '.');
  482. }
  483. }
  484. if (!function_exists('image_to_base64')) {
  485. /**
  486. * 获取图片转为base64
  487. * @param string $avatar
  488. * @return bool|string
  489. */
  490. function image_to_base64($avatar = '', $timeout = 9)
  491. {
  492. try {
  493. $url = parse_url($avatar);
  494. $url = $url['host'];
  495. $header = [
  496. 'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0',
  497. 'Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
  498. 'Accept-Encoding: gzip, deflate, br',
  499. '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',
  500. 'Host:' . $url
  501. ];
  502. $dir = pathinfo($url);
  503. $host = $dir['dirname'];
  504. $refer = $host . '/';
  505. $curl = curl_init();
  506. curl_setopt($curl, CURLOPT_REFERER, $refer);
  507. curl_setopt($curl, CURLOPT_URL, $avatar);
  508. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  509. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
  510. curl_setopt($curl, CURLOPT_ENCODING, 'gzip');
  511. curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $timeout);
  512. curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
  513. $data = curl_exec($curl);
  514. $code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
  515. curl_close($curl);
  516. if ($code == 200) {
  517. return "data:image/jpeg;base64," . base64_encode($data);
  518. } else {
  519. return false;
  520. }
  521. } catch (\Exception $e) {
  522. return false;
  523. }
  524. }
  525. }
  526. if (!function_exists('put_image')) {
  527. /**
  528. * 获取图片转为base64
  529. * @param string $avatar
  530. * @return bool|string
  531. */
  532. function put_image($url, $filename = '')
  533. {
  534. if ($url == '') {
  535. return false;
  536. }
  537. try {
  538. if ($filename == '') {
  539. $ext = pathinfo($url);
  540. if ($ext['extension'] != "jpg" && $ext['extension'] != "png" && $ext['extension'] != "jpeg") {
  541. return false;
  542. }
  543. $filename = time() . "." . $ext['extension'];
  544. }
  545. //文件保存路径
  546. ob_start();
  547. readfile($url);
  548. $img = ob_get_contents();
  549. ob_end_clean();
  550. $path = 'uploads/qrcode';
  551. $fp2 = fopen($path . '/' . $filename, 'a');
  552. fwrite($fp2, $img);
  553. fclose($fp2);
  554. return $path . '/' . $filename;
  555. } catch (\Exception $e) {
  556. return false;
  557. }
  558. }
  559. }
  560. if (!function_exists('debug_file')) {
  561. /**
  562. * 文件调试
  563. * @param $content
  564. */
  565. function debug_file($content, string $fileName = 'error', string $ext = 'txt')
  566. {
  567. $msg = '[' . date('Y-m-d H:i:s', time()) . '] [ DEBUG ] ';
  568. $pach = app()->getRuntimePath();
  569. file_put_contents($pach . $fileName . '.' . $ext, $msg . print_r($content, true) . "\r\n", FILE_APPEND);
  570. }
  571. }
  572. if (!function_exists('sql_filter')) {
  573. /**
  574. * sql 参数过滤
  575. * @param string $str
  576. * @return mixed
  577. */
  578. function sql_filter(string $str)
  579. {
  580. $filter = ['select ', 'insert ', 'update ', 'delete ', 'drop', 'truncate ', 'declare', 'xp_cmdshell', '/add', ' or ', 'exec', 'create', 'chr', 'mid', ' and ', 'execute'];
  581. $toupper = array_map(function ($str) {
  582. return strtoupper($str);
  583. }, $filter);
  584. return str_replace(array_merge($filter, $toupper, ['%20']), '', $str);
  585. }
  586. }
  587. if (!function_exists('is_brokerage_statu')) {
  588. /**
  589. * 是否能成为推广人
  590. * @param float $price
  591. * @return bool
  592. */
  593. function is_brokerage_statu(float $price)
  594. {
  595. $storeBrokerageStatus = sys_config('store_brokerage_statu', DISTRIBUTE_SPECIFIED);
  596. if ($storeBrokerageStatus == DISTRIBUTE_SPECIFIED) {
  597. return false;
  598. } else {
  599. $storeBrokeragePrice = sys_config('store_brokerage_price', 0); // 滿足金額
  600. return $price >= $storeBrokeragePrice;
  601. }
  602. }
  603. }
  604. if (!function_exists('array_unique_fb')) {
  605. /**
  606. * 二维数组去掉重复值
  607. * @param $array
  608. * @return array
  609. */
  610. function array_unique_fb($array)
  611. {
  612. $out = array();
  613. foreach ($array as $key => $value) {
  614. if (!in_array($value, $out)) {
  615. $out[$key] = $value;
  616. }
  617. }
  618. $out = array_values($out);
  619. return $out;
  620. }
  621. }
  622. if (!function_exists('ts_of_day')) {
  623. function ts_of_day($timestamp = null)
  624. {
  625. if ($timestamp == null) {
  626. $timestamp = time();
  627. }
  628. $tm = localtime($timestamp, true);
  629. return $timestamp - $tm['tm_hour'] * 60 * 60 - $tm['tm_min'] * 60 - $tm['tm_sec'];
  630. }
  631. }
  632. if (!function_exists('mapped_implode')) {
  633. function mapped_implode($glue, $array, $symbol = '=')
  634. {
  635. return implode(
  636. $glue,
  637. array_map(
  638. function ($k, $v) use ($symbol) {
  639. return $k . $symbol . $v;
  640. },
  641. array_keys($array),
  642. array_values($array)
  643. )
  644. );
  645. }
  646. }
  647. if (!function_exists('async_call')) {
  648. function async_call(string $className, array $classArgs, string $methodName, array $methodArgs)
  649. {
  650. }
  651. }