提示:' . $controller . ' 这个路由没用定义
';
}
return $url;
}
/**
* 链接设置,可以是控制器,也可以路径
* @param $path
* @param $method
* @param $option
*/
function admin_merchant_url($path, $method = 'index', $option = [])
{
//$url=strtolower($path).'/'.strtolower($method).'/?'.http_build_query($option);
$controller = 'Merchant\\' . ucwords($path) . 'Controller@' . lcfirst(ucwords($method));
try {
$url = action($controller, $option);
} catch (Exception $e) {
return '
提示:' . $controller . ' 这个路由没用定义
';
}
return $url;
}
function admin($field = '')
{
$info = \Illuminate\Support\Facades\Auth::guard('admin')->user();
return $field ? $info[$field] : $info;
}
function merchant($field = '')
{
$info = \Illuminate\Support\Facades\Auth::guard('merchant')->user();
return $field ? $info[$field] : $info;
}
function user($field = '')
{
$info = \Illuminate\Support\Facades\Auth::guard('web')->user();
return $field ? $info[$field] : $info;
}
function to_linux_path($str)
{
return str_replace("\\", '/', $str);
}
function config_cache_default($key, $default = '')
{
$str = config_cache($key);
if (!$str) {
$str = $default ?? '';
}
return $str;
}
/**
* 配置缓存,永久,不更新则永久
* @param $config_key
* @param array $data
* @return \Illuminate\Cache\CacheManager|mixed|string
* @throws Exception
*/
function config_cache($config_key, $data = [])
{
$param = explode('.', $config_key);
//\Illuminate\Support\Facades\Cache::forget($param[0]);
if (empty($data)) {
$config = cache($param[0]);
$config = unserialize($config);
if (empty($config)) {
//缓存文件不存在就读取数据库
$res = \App\Models\Config::get()->toArray();
if ($res) {
foreach ($res as $k => $val) {
$config[$val['ename']] = $val['content'];
}
//存入缓存
\Illuminate\Support\Facades\Cache::forever($param[0], serialize($config));
}
}
if (count($param) > 1) {
if (array_key_exists($param[1], $config)) {
return $config[$param[1]];
}
return false;
} else {
return $config;
}
} else {
//更新缓存
$result = \App\Models\Config::get()->toArray();
if (count($result) > 0) {
foreach ($result as $val) {
$temp[$val['ename']] = $val['content'];
}
foreach ($data as $k => $v) {
$newArr = ['ename' => $k, 'content' => trim($v)];
if (!isset($temp[$k])) {
\App\Models\Config::create($newArr);//新key数据插入数据库
} else {
if ($v != $temp[$k])
\App\Models\Config::where("ename", $k)->update($newArr);//缓存key存在且值有变更新此项
}
}
//更新后的数据库记录
$newRes = \App\Models\Config::get()->toArray();
foreach ($newRes as $rs) {
$newData[$rs['ename']] = $rs['content'];
}
} else {
foreach ($data as $k => $v) {
$newArr[] = ['ename' => $k, 'content' => trim($v)];
}
\App\Models\Config::insert($newArr);
$newData = $data;
}
$newData = serialize($newData);
\Illuminate\Support\Facades\Cache::forever($param[0], $newData);
}
}
/**
* 显示css
* @param $where
* @return string
*/
function show($where)
{
if ($where) {
return "display:block;";
} else {
return 'display:none;';
}
}
/**
* 隐藏css
* @param $where
* @return string
*/
function hide($where)
{
if ($where) {
return "display:none;";
} else {
return 'display:show;';
}
}
/**
* 表单状态
* @param $str
* @param $value
* @param string $type
* @return string
*/
function status_form($str, $value, $type = 'checked')
{
if ($str == $value) {
return $type;
}
}
/**
* 数组转键值
* @param $data
* @param $key
* @return array
*/
function data_to_key($data, $key)
{
if (count($data) <= 0) return [];
$narr = [];
foreach ($data as $k => $v) {
$narr[$v[$key]] = $v;
}
return $narr;
}
function make_card($num, $id, $start = 1, $config = [])
{
$ym = date('Ymd');
if ($num == 0) return;
$num = $num + $start; //卡的张数,即记录数
$row = [];
for ($i = $start; $i < $num; $i++) {
$seek = mt_rand(0, 9999) . mt_rand(0, 9999) . mt_rand(0, 9999); //12位
$start = mt_rand(0, 20);
$str = strtoupper(substr(md5($seek), $start, 12));
$str = str_replace("O", chr(mt_rand(65, 78)), $str);
$str = str_replace("0", chr(mt_rand(65, 78)), $str);
$row[] = [
'number' => $str,
'active_id' => $id,
'user_id' => 0,
'created_at' => date('Y-m-d H:i:s'),
'create_user_type' => $config['create_user_type'],
'create_user_id' => $config['create_user_id']
];
}
return $row;
}
function number_chunk($number, $size)
{
$data = [];
if ($number < $size) {
$data = [
'time' => 0,
'number' => $number,
'ys' => 0
];
} else {
$time = floor($number / $size);
$yushu = $number % $size;
$data = [
'time' => $time,
'number' => $size,
'ys' => $yushu
];
}
return $data;
}
/**
* 发送短信验证码
* @param $mobiles 手机
* @param string $tpl_id 短信模板id
* @param array $params 短信参数
* @param string $sms_sign 前面
* @return array|\Illuminate\Http\JsonResponse|string
* @throws Exception
*/
function send_sms($mobiles, $tpl_id = '', $params = [], $return = 0, $sms_sign = '婚礼之恋')
{
//测试期间关闭发送
// return '发送成功';
$appid = config_cache('config.sms_appid');
$appkey = config_cache('config.sms_appkey');
//根据手机多少,判断时群发还是单挑
if (is_string($mobiles)) {
$ssender = new \Qcloud\Sms\SmsSingleSender($appid, $appkey);
$result = $ssender->sendWithParam("86", $mobiles, $tpl_id,
$params, $sms_sign, "", ""); // 签名参数未提供或者为空时,会使用默认签名发送短信
$rsp = json_decode($result, true);
}
if (is_array($mobiles)) {
$msender = new \Qcloud\Sms\SmsMultiSender($appid, $appkey);
$result = $msender->sendWithParam("86", $mobiles, $tpl_id, $params, $sms_sign, "", ""); // 签名参数未提供或者为空时,会使用默认签名发送短信
$rsp = json_decode($result, true);
}
\Illuminate\Support\Facades\Log::info($result);
if ($rsp['result'] == 0) {
if ($return) {
return ['error' => 0, 'msg' => '发送成功'];
}
if (request()->ajax() || request()->wantsJson()) {
return response()->json(['error' => 0, 'msg' => '发送成功']);
}
//return '发送成功';
} else {
if ($return) {
return ['error' => 1, 'msg' => '发送失败'];
}
if (request()->ajax() || request()->wantsJson()) {
return response()->json(['error' => 1, 'msg' => '发送失败']);
}
//return '发送失败';
}
}
function get_arr_index($arr, $index = 'first')
{
$arr = array_flip($arr);
if ($index == 'first') {
return current($arr);
}
if ($index == 'last') {
return end($arr);
}
}
function in_arr_value($key, $arr, $default = '', $type = 'text')
{
if (array_key_exists($key, $arr)) {
switch ($type) {
case 'text':
return $arr[$key];
break;
case 'radio':
if ($default == $arr[$key]) {
return 'checked';
}
break;
case 'select':
if ($default == $arr[$key]) {
return 'selected';
}
break;
case 'checkbox':
$arr_c = json_decode($arr[$key], true);
if (in_array($default, $arr_c)) {
return 'checked';
}
break;
case 'more_upload':
$arr_c = json_decode(urldecode($arr[$key]), true);
$arr_c = $arr_c ? $arr_c : [];
return $arr_c;
break;
}
} else {
if (in_array($type, ['more_upload'])) {
return [];
}
return $default;
}
}
function thumbs($str, $type = 1, $class_name = '')
{
if (!$str) return false;
$thumb_arr = json_decode($str, true);
if (count($thumb_arr) <= 0) return false;
$html_str = '';
foreach ($thumb_arr as $v) {
if ($type == 1) {
$html_str .= '