| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886 |
- <?php
- // 公共助手函数
- use Symfony\Component\VarExporter\VarExporter;
- use think\exception\HttpResponseException;
- use think\Response;
- if (!function_exists('__')) {
- /**
- * 获取语言变量值
- * @param string $name 语言变量名
- * @param array $vars 动态变量值
- * @param string $lang 语言
- * @return mixed
- */
- function __($name, $vars = [], $lang = '')
- {
- if (is_numeric($name) || !$name) {
- return $name;
- }
- if (!is_array($vars)) {
- $vars = func_get_args();
- array_shift($vars);
- $lang = '';
- }
- return \think\Lang::get($name, $vars, $lang);
- }
- }
- if (!function_exists('format_bytes')) {
- /**
- * 将字节转换为可读文本
- * @param int $size 大小
- * @param string $delimiter 分隔符
- * @param int $precision 小数位数
- * @return string
- */
- function format_bytes($size, $delimiter = '', $precision = 2)
- {
- $units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB');
- for ($i = 0; $size >= 1024 && $i < 6; $i++) {
- $size /= 1024;
- }
- return round($size, $precision) . $delimiter . $units[$i];
- }
- }
- if (!function_exists('datetime')) {
- /**
- * 将时间戳转换为日期时间
- * @param int $time 时间戳
- * @param string $format 日期时间格式
- * @return string
- */
- function datetime($time, $format = 'Y-m-d H:i:s')
- {
- $time = is_numeric($time) ? $time : strtotime($time);
- return date($format, $time);
- }
- }
- if (!function_exists('human_date')) {
- /**
- * 获取语义化时间
- * @param int $time 时间
- * @param int $local 本地时间
- * @return string
- */
- function human_date($time, $local = null)
- {
- return \fast\Date::human($time, $local);
- }
- }
- if (!function_exists('cdnurl')) {
- /**
- * 获取上传资源的CDN的地址
- * @param string $url 资源相对地址
- * @param boolean $domain 是否显示域名 或者直接传入域名
- * @return string
- */
- function cdnurl($url, $domain = false)
- {
- $regex = "/^((?:[a-z]+:)?\/\/|data:image\/)(.*)/i";
- $cdnurl = \think\Config::get('upload.cdnurl');
- $url = preg_match($regex, $url) || ($cdnurl && stripos($url, $cdnurl) === 0) ? $url : $cdnurl . $url;
- if ($domain && !preg_match($regex, $url)) {
- $domain = is_bool($domain) ? request()->domain() : $domain;
- $url = $domain . $url;
- }
- return $url;
- }
- }
- if (!function_exists('is_really_writable')) {
- /**
- * 判断文件或文件夹是否可写
- * @param string $file 文件或目录
- * @return bool
- */
- function is_really_writable($file)
- {
- if (DIRECTORY_SEPARATOR === '/') {
- return is_writable($file);
- }
- if (is_dir($file)) {
- $file = rtrim($file, '/') . '/' . md5(mt_rand());
- if (($fp = @fopen($file, 'ab')) === false) {
- return false;
- }
- fclose($fp);
- @chmod($file, 0777);
- @unlink($file);
- return true;
- } elseif (!is_file($file) or ($fp = @fopen($file, 'ab')) === false) {
- return false;
- }
- fclose($fp);
- return true;
- }
- }
- if (!function_exists('rmdirs')) {
- /**
- * 删除文件夹
- * @param string $dirname 目录
- * @param bool $withself 是否删除自身
- * @return boolean
- */
- function rmdirs($dirname, $withself = true)
- {
- if (!is_dir($dirname)) {
- return false;
- }
- $files = new RecursiveIteratorIterator(
- new RecursiveDirectoryIterator($dirname, RecursiveDirectoryIterator::SKIP_DOTS),
- RecursiveIteratorIterator::CHILD_FIRST
- );
- foreach ($files as $fileinfo) {
- $todo = ($fileinfo->isDir() ? 'rmdir' : 'unlink');
- $todo($fileinfo->getRealPath());
- }
- if ($withself) {
- @rmdir($dirname);
- }
- return true;
- }
- }
- if (!function_exists('copydirs')) {
- /**
- * 复制文件夹
- * @param string $source 源文件夹
- * @param string $dest 目标文件夹
- */
- function copydirs($source, $dest)
- {
- if (!is_dir($dest)) {
- mkdir($dest, 0755, true);
- }
- foreach (
- $iterator = new RecursiveIteratorIterator(
- new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS),
- RecursiveIteratorIterator::SELF_FIRST
- ) as $item
- ) {
- if ($item->isDir()) {
- $sontDir = $dest . DS . $iterator->getSubPathName();
- if (!is_dir($sontDir)) {
- mkdir($sontDir, 0755, true);
- }
- } else {
- copy($item, $dest . DS . $iterator->getSubPathName());
- }
- }
- }
- }
- if (!function_exists('mb_ucfirst')) {
- function mb_ucfirst($string)
- {
- return mb_strtoupper(mb_substr($string, 0, 1)) . mb_strtolower(mb_substr($string, 1));
- }
- }
- if (!function_exists('addtion')) {
- /**
- * 附加关联字段数据
- * @param array $items 数据列表
- * @param mixed $fields 渲染的来源字段
- * @return array
- */
- function addtion($items, $fields)
- {
- if (!$items || !$fields) {
- return $items;
- }
- $fieldsArr = [];
- if (!is_array($fields)) {
- $arr = explode(',', $fields);
- foreach ($arr as $k => $v) {
- $fieldsArr[$v] = ['field' => $v];
- }
- } else {
- foreach ($fields as $k => $v) {
- if (is_array($v)) {
- $v['field'] = isset($v['field']) ? $v['field'] : $k;
- } else {
- $v = ['field' => $v];
- }
- $fieldsArr[$v['field']] = $v;
- }
- }
- foreach ($fieldsArr as $k => &$v) {
- $v = is_array($v) ? $v : ['field' => $v];
- $v['display'] = $v['display'] ?? str_replace(['_ids', '_id'], ['_names', '_name'], $v['field']);
- $v['primary'] = $v['primary'] ?? '';
- $v['column'] = $v['column'] ?? 'name';
- $v['model'] = $v['model'] ?? '';
- $v['table'] = $v['table'] ?? '';
- $v['name'] = $v['name'] ?? str_replace(['_ids', '_id'], '', $v['field']);
- }
- unset($v);
- $ids = [];
- $fields = array_keys($fieldsArr);
- foreach ($items as $k => $v) {
- foreach ($fields as $m => $n) {
- if (isset($v[$n])) {
- $ids[$n] = array_merge(isset($ids[$n]) && is_array($ids[$n]) ? $ids[$n] : [], explode(',', $v[$n]));
- }
- }
- }
- $result = [];
- foreach ($fieldsArr as $k => $v) {
- if ($v['model']) {
- $model = new $v['model'];
- } else {
- $model = $v['name'] ? \think\Db::name($v['name']) : \think\Db::table($v['table']);
- }
- $primary = $v['primary'] ? $v['primary'] : $model->getPk();
- $result[$v['field']] = isset($ids[$v['field']]) ? $model->where($primary, 'in', $ids[$v['field']])->column($v['column'], $primary) : [];
- }
- foreach ($items as $k => &$v) {
- foreach ($fields as $m => $n) {
- if (isset($v[$n])) {
- $curr = array_flip(explode(',', $v[$n]));
- $linedata = array_intersect_key($result[$n], $curr);
- $v[$fieldsArr[$n]['display']] = $fieldsArr[$n]['column'] == '*' ? $linedata : implode(',', $linedata);
- }
- }
- }
- return $items;
- }
- }
- if (!function_exists('var_export_short')) {
- /**
- * 使用短标签打印或返回数组结构
- * @param mixed $data
- * @param boolean $return 是否返回数据
- * @return string
- */
- function var_export_short($data, $return = true)
- {
- return var_export($data, $return);
- $replaced = [];
- $count = 0;
- //判断是否是对象
- if (is_resource($data) || is_object($data)) {
- return var_export($data, $return);
- }
- //判断是否有特殊的键名
- $specialKey = false;
- array_walk_recursive($data, function (&$value, &$key) use (&$specialKey) {
- if (is_string($key) && (stripos($key, "\n") !== false || stripos($key, "array (") !== false)) {
- $specialKey = true;
- }
- });
- if ($specialKey) {
- return var_export($data, $return);
- }
- array_walk_recursive($data, function (&$value, &$key) use (&$replaced, &$count, &$stringcheck) {
- if (is_object($value) || is_resource($value)) {
- $replaced[$count] = var_export($value, true);
- $value = "##<{$count}>##";
- } else {
- if (is_string($value) && (stripos($value, "\n") !== false || stripos($value, "array (") !== false)) {
- $index = array_search($value, $replaced);
- if ($index === false) {
- $replaced[$count] = var_export($value, true);
- $value = "##<{$count}>##";
- } else {
- $value = "##<{$index}>##";
- }
- }
- }
- $count++;
- });
- $dump = var_export($data, true);
- $dump = preg_replace('#(?:\A|\n)([ ]*)array \(#i', '[', $dump); // Starts
- $dump = preg_replace('#\n([ ]*)\),#', "\n$1],", $dump); // Ends
- $dump = preg_replace('#=> \[\n\s+\],\n#', "=> [],\n", $dump); // Empties
- $dump = preg_replace('#\)$#', "]", $dump); //End
- if ($replaced) {
- $dump = preg_replace_callback("/'##<(\d+)>##'/", function ($matches) use ($replaced) {
- return isset($replaced[$matches[1]]) ? $replaced[$matches[1]] : "''";
- }, $dump);
- }
- if ($return === true) {
- return $dump;
- } else {
- echo $dump;
- }
- }
- }
- if (!function_exists('letter_avatar')) {
- /**
- * 首字母头像
- * @param $text
- * @return string
- */
- function letter_avatar($text)
- {
- $total = unpack('L', hash('adler32', $text, true))[1];
- $hue = $total % 360;
- list($r, $g, $b) = hsv2rgb($hue / 360, 0.3, 0.9);
- $bg = "rgb({$r},{$g},{$b})";
- $color = "#ffffff";
- $first = mb_strtoupper(mb_substr($text, 0, 1));
- $src = base64_encode('<svg xmlns="http://www.w3.org/2000/svg" version="1.1" height="100" width="100"><rect fill="' . $bg . '" x="0" y="0" width="100" height="100"></rect><text x="50" y="50" font-size="50" text-copy="fast" fill="' . $color . '" text-anchor="middle" text-rights="admin" dominant-baseline="central">' . $first . '</text></svg>');
- $value = 'data:image/svg+xml;base64,' . $src;
- return $value;
- }
- }
- if (!function_exists('hsv2rgb')) {
- function hsv2rgb($h, $s, $v)
- {
- $r = $g = $b = 0;
- $i = floor($h * 6);
- $f = $h * 6 - $i;
- $p = $v * (1 - $s);
- $q = $v * (1 - $f * $s);
- $t = $v * (1 - (1 - $f) * $s);
- switch ($i % 6) {
- case 0:
- $r = $v;
- $g = $t;
- $b = $p;
- break;
- case 1:
- $r = $q;
- $g = $v;
- $b = $p;
- break;
- case 2:
- $r = $p;
- $g = $v;
- $b = $t;
- break;
- case 3:
- $r = $p;
- $g = $q;
- $b = $v;
- break;
- case 4:
- $r = $t;
- $g = $p;
- $b = $v;
- break;
- case 5:
- $r = $v;
- $g = $p;
- $b = $q;
- break;
- }
- return [
- floor($r * 255),
- floor($g * 255),
- floor($b * 255)
- ];
- }
- }
- if (!function_exists('check_nav_active')) {
- /**
- * 检测会员中心导航是否高亮
- */
- function check_nav_active($url, $classname = 'active')
- {
- $auth = \app\common\library\Auth::instance();
- $requestUrl = $auth->getRequestUri();
- $url = ltrim($url, '/');
- return $requestUrl === str_replace(".", "/", $url) ? $classname : '';
- }
- }
- if (!function_exists('check_cors_request')) {
- /**
- * 跨域检测
- */
- function check_cors_request()
- {
- if (isset($_SERVER['HTTP_ORIGIN']) && $_SERVER['HTTP_ORIGIN']) {
- $info = parse_url($_SERVER['HTTP_ORIGIN']);
- $domainArr = explode(',', config('fastadmin.cors_request_domain'));
- $domainArr[] = request()->host(true);
- if (in_array("*", $domainArr) || in_array($_SERVER['HTTP_ORIGIN'], $domainArr) || (isset($info['host']) && in_array($info['host'], $domainArr))) {
- header("Access-Control-Allow-Origin: " . $_SERVER['HTTP_ORIGIN']);
- } else {
- $response = Response::create('跨域检测无效', 'html', 403);
- throw new HttpResponseException($response);
- }
- header('Access-Control-Allow-Credentials: true');
- header('Access-Control-Max-Age: 86400');
- if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
- if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD'])) {
- header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS");
- }
- if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])) {
- header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
- }
- $response = Response::create('', 'html');
- throw new HttpResponseException($response);
- }
- }
- }
- }
- if (!function_exists('xss_clean')) {
- /**
- * 清理XSS
- */
- function xss_clean($content, $is_image = false)
- {
- return \app\common\library\Security::instance()->xss_clean($content, $is_image);
- }
- }
- if (!function_exists('check_ip_allowed')) {
- /**
- * 检测IP是否允许
- * @param string $ip IP地址
- */
- function check_ip_allowed($ip = null)
- {
- $ip = is_null($ip) ? request()->ip() : $ip;
- $forbiddenipArr = config('site.forbiddenip');
- $forbiddenipArr = !$forbiddenipArr ? [] : $forbiddenipArr;
- $forbiddenipArr = is_array($forbiddenipArr) ? $forbiddenipArr : array_filter(explode("\n", str_replace("\r\n", "\n", $forbiddenipArr)));
- if ($forbiddenipArr && \Symfony\Component\HttpFoundation\IpUtils::checkIp($ip, $forbiddenipArr)) {
- $response = Response::create('请求无权访问', 'html', 403);
- throw new HttpResponseException($response);
- }
- }
- }
- if (!function_exists('build_suffix_image')) {
- /**
- * 生成文件后缀图片
- * @param string $suffix 后缀
- * @param null $background
- * @return string
- */
- function build_suffix_image($suffix, $background = null)
- {
- $suffix = mb_substr(strtoupper($suffix), 0, 4);
- $total = unpack('L', hash('adler32', $suffix, true))[1];
- $hue = $total % 360;
- list($r, $g, $b) = hsv2rgb($hue / 360, 0.3, 0.9);
- $background = $background ? $background : "rgb({$r},{$g},{$b})";
- $icon = <<<EOT
- <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 512 512" style="enable-background:new 0 0 512 512;" xml:space="preserve">
- <path style="fill:#E2E5E7;" d="M128,0c-17.6,0-32,14.4-32,32v448c0,17.6,14.4,32,32,32h320c17.6,0,32-14.4,32-32V128L352,0H128z"/>
- <path style="fill:#B0B7BD;" d="M384,128h96L352,0v96C352,113.6,366.4,128,384,128z"/>
- <polygon style="fill:#CAD1D8;" points="480,224 384,128 480,128 "/>
- <path style="fill:{$background};" d="M416,416c0,8.8-7.2,16-16,16H48c-8.8,0-16-7.2-16-16V256c0-8.8,7.2-16,16-16h352c8.8,0,16,7.2,16,16 V416z"/>
- <path style="fill:#CAD1D8;" d="M400,432H96v16h304c8.8,0,16-7.2,16-16v-16C416,424.8,408.8,432,400,432z"/>
- <g><text><tspan x="220" y="380" font-size="124" font-family="Verdana, Helvetica, Arial, sans-serif" fill="white" text-anchor="middle">{$suffix}</tspan></text></g>
- </svg>
- EOT;
- return $icon;
- }
- }
- function Kmod($bn, $sn)
- {
- //fmod() 函数返回除法的浮点数余数
- return intval(fmod(floatval($bn), $sn));
- }
- function p($data, $die = false)
- {
- echo "<pre>";
- print_r($data, $die);
- echo "</pre>";
- }
- /**
- * 保留两位小数
- * @param $number
- * @return float
- */
- function fixed2Float($number)
- {
- return round(floatval((string)$number), 2);
- }
- /**
- * @param $array
- * @param $id
- * @return array 树状Menu
- */
- function recursion($array, $id = 0)
- {
- $resArray = [];
- foreach ($array as $key => $value) {
- if ($value['pid'] == $id) {
- $resArray[$key] = $array[$key];
- $resArray[$key]['children'] = recursion($array, $value['id']);
- }
- }
- return array_merge($resArray);
- }
- // 基础状态
- abstract class E_BASE_STATUS
- {
- const Default = 'default';
- const Normal = 'normal';
- const Hidden = 'hidden';
- const Checking = 'checking';
- }
- abstract class E_MASSAGER_STATUS extends E_BASE_STATUS
- {
- const Checking = 'checking';
- const Close = 'close';
- }
- abstract class E_GENDER_TYPE
- {
- const Man = "man";
- const Woman = "woman";
- }
- // 服务分类
- abstract class E_SERVICE_TYPE
- {
- const App = 'app';
- const Store = 'store';
- }
- //订单状态
- abstract class E_ORDER_STATUS
- {
- const Default = 'default'; // 默认状态
- const Purchase = 'purchase'; // 已购买
- const Proceed = 'proceed'; // 助教接单 - 进行中
- const WaitFeedback = 'wait_feedback'; // 等待反馈
- const Finish = 'finish'; // 服务完成
- const Reject = 'reject'; // 助教拒绝
- const Cancel = 'cancel'; // 用户取消取消
- const AdminCancel = 'admin_cancel'; // 管理员终止订单
- const AutoCancel = 'auto_cancel'; // 过期自动取消
- }
- const ALL_ORDER_STATUS = [
- \E_ORDER_STATUS::Default,
- \E_ORDER_STATUS::Purchase,
- \E_ORDER_STATUS::Proceed,
- \E_ORDER_STATUS::WaitFeedback,
- \E_ORDER_STATUS::Finish,
- \E_ORDER_STATUS::Reject,
- \E_ORDER_STATUS::Cancel,
- \E_ORDER_STATUS::AdminCancel,
- \E_ORDER_STATUS::AutoCancel
- ];
- // 取消退单
- abstract class E_CHARGEBACK_TYPE
- {
- const TemporaryEmergency = 'temporary_emergency'; // 临时有事
- const LooksMajor = 'looks_major'; // 理疗师长相或专业因素 50% 出行费不退
- const Proceed = 'major_manner'; // 专业因素|服务态度 全退
- const WaitFeedback = 'wait_feedback'; // 等待反馈
- const Finish = 'finish'; // 服务完成
- }
- abstract class E_VOUCHER_STATUS extends E_BASE_STATUS
- {
- const Use = 'use';
- const Expire = 'expire';
- }
- abstract class E_TRIP_TYPE
- {
- const Bus = 'bus';
- const Taxi = "taxi";
- }
- abstract class E_ORDER_PAY_TYPE // 支付方式
- {
- const ALi = 'ali';
- const Wechat = 'wechat';
- const Balance = 'balance';
- const Bank = 'bank';
- }
- const ALL_ORDER_PAY_TYPE = [\E_ORDER_PAY_TYPE::ALi, \E_ORDER_PAY_TYPE::Balance, \E_ORDER_PAY_TYPE::Wechat];
- abstract class E_ORDER_PROGRESS_TYPE // 订单子进程
- {
- const Take = 'take'; // 接单
- const Depart = 'depart';
- const Arrive = 'arrive';
- const Start = 'start';
- const Over = 'over';
- }
- const ALL_ORDER_PROGRESS_TYPE = [
- \E_ORDER_PROGRESS_TYPE::Take,
- \E_ORDER_PROGRESS_TYPE::Depart,
- \E_ORDER_PROGRESS_TYPE::Arrive,
- \E_ORDER_PROGRESS_TYPE::Start,
- \E_ORDER_PROGRESS_TYPE::Over,
- ];
- abstract class E_USER_BILL_CURRENCY_TYPE
- {
- const Money = "money";
- const Score = "score";
- }
- abstract class E_USER_BILL_CHANGE_TYPE
- {
- const BalanceWxRecharge = [1, "微信余额充值"];
- const BalanceAliRecharge = [2, "支付宝余额充值"];
- const BalanceOrderConsumption = [3, "订单消费余额"];
- const BalanceOrderRefund = [4, "订单取消退还余额"];
- const WxOrderConsumption = [5, "微信支付订单"];
- const WxOrderRefund = [6, "微信支付订单退款"];
- const AdminRecharge = [7, "管理员充值余额"];
- const AdminReduce = [8, "管理员扣除余额"];
- const ProfitIncrease = [9, "推荐分佣"];
- const Deposit = [10, "提现"];
- const MemberCharge = [11, "充值会员"];
- const BalanceDeduction = [12, "余额抵扣"];
- const BalanceDeductionRefund = [13, "余额抵扣退回"];
- const ScoreOrderGive = [20, "订单赠送积分"];
- const ScoreLotteryConsumption = [21, "抽奖消费积分"];
- const ScoreExchangeVoucher = [22, "积分兑换优惠券"];
- const ScoreOrderRefund = [23, "取消订单退还积分"];
- }
- abstract class E_PROFIT_BILL_CHANGE_TYPE
- {
- const Profit = "profit"; // 分润
- const Drawings = "drawings"; // 提现
- const ClosingExpend = "closing_expend"; // 结算支出
- const ClosingIncome = "closing_income"; // 结算收入
- const ChannelExpend = "channel_expend"; // 渠道支出
- const ChannelIncome = "channel_income"; // 渠道收入
- }
- abstract class E_M_BILL_CHANGE_TYPE
- {
- const Profit = 101; // 服务费
- const Travel = 102; // 出行费
- const Deposit = 103; // 提现
- const ClosingIncome = 104; // 结算收入
- const ChannelExpend = 105; // 渠道支出
- const ChannelIncome = 106; // 渠道收入
- }
- abstract class E_ADMIN_TYPE
- {
- const Platform = 'platform';
- const Agency = 'agency';
- const Store = 'store';
- }
- abstract class E_IDENTITY_TYPE extends E_ADMIN_TYPE
- {
- const Massager = 'massager';
- const User = 'user';
- }
- class SResult
- {
- private $_code;
- private $_msg = '';
- private $_data = null;
- public function __construct($code = 0, $msg = '', $data = null)
- {
- $this->_code = $code;
- $this->_msg = $msg;
- $this->_data = $data;
- }
- public function code()
- {
- return $this->_code;
- }
- public function msg()
- {
- return $this->_msg;
- }
- public function data()
- {
- return $this->_data;
- }
- }
- function http_request($url, $get = null, $post = null)
- {
- if (isset($get))
- $url .= ((substr_count($url, '?') > 0 ? "&" : "?") . http_build_query($get));
- // 初始化一个cURL会话
- $ch = curl_init($url);
- if (isset($post)) {
- curl_setopt($ch, CURLOPT_POST, TRUE); #开启post
- curl_setopt($ch, CURLOPT_POSTFIELDS, $post); #post数据
- }
- curl_setopt($ch, CURLOPT_HEADER, 0); #是否需要头部信息(否)
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); #如果成功只将结果返回,不自动输出任何内容。
- curl_setopt($ch, CURLOPT_TIMEOUT, 5); #设置允许执行的最长秒数。
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); #在发起连接前等待的时间,如果设置为0,则无限等待。
- //忽略证书
- if (substr($url, 0, 5) == 'https') {
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
- }
- $curl_result = curl_exec($ch);
- if ($curl_result) {
- $data = $curl_result;
- } else {
- $data = curl_error($ch);
- }
- curl_close($ch); #关闭cURL会话
- return json_decode($data);
- }
- function fmtMonth($m)
- {
- $m = (int)$m;
- if ($m > 10)
- return $m;
- return "0{$m}";
- }
- function ym($year = null, $month = null)
- {
- if ($year && $month) {
- $month = (int)$month;
- return $month > 10 ? "{$year}-{$month}" : "{$year}-0{$month}";
- }
- return date('Y-m');
- }
- abstract class E_M_INTERIOR_SCORE
- {
- const Duration = "duration";
- const Praise = "praise";
- const Negative = "negative";
- const Performance = "performance";
- const Reorder = "reorder";
- }
- const ALL_E_M_I_S = [
- "duration",
- "praise",
- "negative",
- "performance",
- "reorder"
- ];
- function splittingDate($start_time, $end_time)
- {
- $minute_20 = 10 * 60;
- $date_array = [];
- while ($start_time <= $end_time) {
- array_push($date_array, strtotime(date('Y-m-d H:i', $start_time)));
- $start_time += $minute_20;
- }
- return $date_array;
- }
- if (!function_exists('qrcodeBase64')) {
- function qrcodeBase64($url, $params)
- {
- $p_str = array_map(function ($key) use ($params) {
- return "$key={$params[$key]}";
- }, array_keys($params));
- $qr = new Endroid\QrCode\QrCode($url . "?" . join("&", $p_str), new Endroid\QrCode\Encoding\Encoding("UTF-8"));
- $pngWriter = new Endroid\QrCode\Writer\PngWriter();
- $pngResult = $pngWriter->write($qr);
- $base64 = $pngResult->getDataUri();
- //默认普通上传文件
- return upload_pic(explode(",", $base64)[1]);
- }
- }
- if (!function_exists('upload_pic')) {
- function upload_pic($thumb)
- {
- if (!$thumb) return null;
- $fileroot = ROOT_PATH . 'public' . DS . 'uploads' . DS . 'qrcode';//设置图片保存路径
- if (!is_dir($fileroot)) mkdir($fileroot, 0777, true);//没有保存目录则创建
- $filename = date("YmdHis") . '_' . rand(10000, 99999) . '.png';//生成文件名
- file_put_contents($fileroot . DS . $filename, base64_decode($thumb));
- return DS . 'uploads' . DS . 'qrcode' . DS . $filename;
- }
- }
- function parse_area($area_code)
- {
- $result = [
- 'p_code' => null,
- 'city_code' => null,
- 'county_code' => null
- ];
- if (strlen((string)$area_code) != 6)
- return $result;
- $result['p_code'] = (int)($area_code / 1000) * 1000;
- if ($area_code % 1000 > 0) {
- $result['city_code'] = (int)($area_code / 100) * 100;
- }
- if ($area_code % 100 > 0) {
- $result['county_code'] = $area_code;
- }
- return $result;
- }
|