119 lines
3.7 KiB
PHP
119 lines
3.7 KiB
PHP
<?php
|
|
// 这是home公共文件
|
|
//获取当前登录用户的信息
|
|
function get_login_user($key = "")
|
|
{
|
|
$session_user = get_config('app.session_user');
|
|
if (\think\facade\Session::has($session_user)) {
|
|
$gougu_user = \think\facade\Session::get($session_user);
|
|
if (!empty($key)) {
|
|
if (isset($gougu_user[$key])) {
|
|
return $gougu_user[$key];
|
|
} else {
|
|
return '';
|
|
}
|
|
} else {
|
|
return $gougu_user;
|
|
}
|
|
} else {
|
|
return '';
|
|
}
|
|
}
|
|
/**
|
|
* 客户操作日志
|
|
* @param string $type 操作类型 login add edit view delete,pay
|
|
* @param int $param_id 操作类型
|
|
* @param array $param 提交的参数
|
|
*/
|
|
function add_user_log($type, $param_id = '', $param = [])
|
|
{
|
|
$request = request();
|
|
switch ($type) {
|
|
case 'login':
|
|
$title = '登录';
|
|
break;
|
|
case 'reg':
|
|
$title = '注册';
|
|
break;
|
|
case 'add':
|
|
$title = '新增';
|
|
break;
|
|
case 'edit':
|
|
$title = '编辑';
|
|
break;
|
|
case 'view':
|
|
$title = '查看';
|
|
break;
|
|
case 'delete':
|
|
$title = '删除';
|
|
break;
|
|
case 'pay':
|
|
$title = '支付';
|
|
break;
|
|
default:
|
|
$title = '未知';
|
|
break;
|
|
}
|
|
if ($type == 'login') {
|
|
$login_user = \think\facade\Db::name('user')->where(array('id' => $param_id))->find();
|
|
} else {
|
|
$session_user = get_config('app.session_user');
|
|
$login_user = \think\facade\Session::get($session_user);
|
|
if (empty($login_user)) {
|
|
$login_user['id'] = 0;
|
|
$login_user['nickname'] = '游客';
|
|
}
|
|
}
|
|
|
|
$content = $login_user['nickname'] . '在' . date('Y-m-d H:i:s') . '执行了' . $title . '操作';
|
|
$data = [];
|
|
$data['uid'] = $login_user['id'];
|
|
$data['nickname'] = $login_user['nickname'];
|
|
$data['type'] = $type;
|
|
$data['title'] = $title;
|
|
$data['content'] = $content;
|
|
$data['param_id'] = $param_id;
|
|
$data['param'] = json_encode($param);
|
|
$data['module'] = \think\facade\App::initialize()->http->getName();
|
|
$data['controller'] = app('request')->controller();
|
|
$data['function'] = app('request')->action();
|
|
$data['ip'] = $request->ip();
|
|
$data['create_time'] = time();
|
|
\think\facade\Db::name('user_log')->strict(false)->field(true)->insert($data);
|
|
}
|
|
|
|
//读取导航列表,用于前台
|
|
function get_navs($name)
|
|
{
|
|
if (!get_cache('homeNav' . $name)) {
|
|
$nav_id = \think\facade\Db::name('Nav')->where(['name' => $name, 'status' => 1])->value('id');
|
|
if (empty($nav_id)) {
|
|
return '';
|
|
}
|
|
$list = \think\facade\Db::name('NavInfo')->where(['nav_id' => $nav_id, 'status' => 1])->select();
|
|
\think\facade\Cache::tag('homeNav')->set('homeNav' . $name, $list);
|
|
}
|
|
$navs = get_cache('homeNav' . $name);
|
|
return $navs;
|
|
}
|
|
|
|
//读取指定文章的详情
|
|
function get_article_detail($id)
|
|
{
|
|
$article = \think\facade\Db::name('article')->where(['id' => $id])->find();
|
|
if (empty($article)) {
|
|
return $this->error('文章不存在');
|
|
}
|
|
$keywrod_array = \think\facade\Db::name('ArticleKeywords')
|
|
->field('i.aid,i.keywords_id,k.title')
|
|
->alias('i')
|
|
->join('keywords k', 'k.id = i.keywords_id', 'LEFT')
|
|
->order('i.create_time asc')
|
|
->where(array('i.aid' => $id, 'k.status' => 1))
|
|
->select()->toArray();
|
|
|
|
$article['keyword_ids'] = implode(",", array_column($keywrod_array, 'keywords_id'));
|
|
$article['keyword_names'] = implode(',', array_column($keywrod_array, 'title'));
|
|
return $article;
|
|
}
|