mirror of
https://gitee.com/ulthon/ulthon_information.git
synced 2026-03-03 16:24:28 +08:00
初始化项目
This commit is contained in:
1
app/.htaccess
Normal file
1
app/.htaccess
Normal file
@@ -0,0 +1 @@
|
||||
deny from all
|
||||
170
app/BaseController.php
Normal file
170
app/BaseController.php
Normal file
@@ -0,0 +1,170 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app;
|
||||
|
||||
use think\App;
|
||||
use think\app\Url;
|
||||
use think\exception\ValidateException;
|
||||
use think\Validate;
|
||||
use think\facade\View;
|
||||
use think\exception\HttpResponseException;
|
||||
|
||||
/**
|
||||
* 控制器基础类
|
||||
*/
|
||||
abstract class BaseController
|
||||
{
|
||||
/**
|
||||
* Request实例
|
||||
* @var \think\Request
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* 应用实例
|
||||
* @var \think\App
|
||||
*/
|
||||
protected $app;
|
||||
|
||||
/**
|
||||
* 是否批量验证
|
||||
* @var bool
|
||||
*/
|
||||
protected $batchValidate = false;
|
||||
|
||||
/**
|
||||
* 控制器中间件
|
||||
* @var array
|
||||
*/
|
||||
protected $middleware = [];
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
* @access public
|
||||
* @param App $app 应用对象
|
||||
*/
|
||||
public function __construct(App $app)
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->request = $this->app->request;
|
||||
|
||||
// 控制器初始化
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
// 初始化
|
||||
protected function initialize()
|
||||
{}
|
||||
|
||||
/**
|
||||
* 验证数据
|
||||
* @access protected
|
||||
* @param array $data 数据
|
||||
* @param string|array $validate 验证器名或者验证规则数组
|
||||
* @param array $message 提示信息
|
||||
* @param bool $batch 是否批量验证
|
||||
* @return array|string|true
|
||||
* @throws ValidateException
|
||||
*/
|
||||
protected function validate(array $data, $validate, array $message = [], bool $batch = false)
|
||||
{
|
||||
if (is_array($validate)) {
|
||||
$v = new Validate();
|
||||
$v->rule($validate);
|
||||
} else {
|
||||
if (strpos($validate, '.')) {
|
||||
// 支持场景
|
||||
list($validate, $scene) = explode('.', $validate);
|
||||
}
|
||||
$class = false !== strpos($validate, '\\') ? $validate : $this->app->parseClass('validate', $validate);
|
||||
$v = new $class();
|
||||
if (!empty($scene)) {
|
||||
$v->scene($scene);
|
||||
}
|
||||
}
|
||||
|
||||
$v->message($message);
|
||||
|
||||
// 是否批量验证
|
||||
if ($batch || $this->batchValidate) {
|
||||
$v->batch(true);
|
||||
}
|
||||
|
||||
return $v->failException(true)->check($data);
|
||||
}
|
||||
|
||||
public function success($msg = '操作成功',$jump_to_url = null,$code = 200,$params = [])
|
||||
{
|
||||
|
||||
if(is_null($jump_to_url)){
|
||||
$jump_to_url = \request()->server('HTTP_REFERER');
|
||||
}else{
|
||||
if($jump_to_url instanceof Url){
|
||||
|
||||
$jump_to_url = $jump_to_url;
|
||||
}else{
|
||||
$jump_to_url = url($jump_to_url);
|
||||
}
|
||||
}
|
||||
|
||||
$data = [
|
||||
'msg'=>$msg,
|
||||
'jump_to_url'=>$jump_to_url,
|
||||
'params'=>$params
|
||||
];
|
||||
|
||||
if(\request()->isAjax()){
|
||||
$data['jump_to_url'] = (string)$jump_to_url;
|
||||
if($code == 200){
|
||||
$code = 0;
|
||||
}
|
||||
throw new HttpResponseException(json_message($data,$code,$msg));
|
||||
}
|
||||
|
||||
View::assign($data);
|
||||
throw new HttpResponseException(response(View::fetch('common@tpl/success'),$code));
|
||||
}
|
||||
public function error($msg = '操作失败',$jump_to_url = null,$code = 200,$params = [])
|
||||
{
|
||||
|
||||
if(is_null($jump_to_url)){
|
||||
$jump_to_url = \request()->server('HTTP_REFERER');
|
||||
}else{
|
||||
if($jump_to_url instanceof Url){
|
||||
|
||||
$jump_to_url = $jump_to_url;
|
||||
}else{
|
||||
$jump_to_url = url($jump_to_url);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$data = [
|
||||
'msg'=>$msg,
|
||||
'jump_to_url'=>$jump_to_url,
|
||||
'params'=>$params
|
||||
];
|
||||
|
||||
if(\request()->isAjax()){
|
||||
$data['jump_to_url'] = (string)$jump_to_url;
|
||||
if($code == 200){
|
||||
$code = 500;
|
||||
}
|
||||
throw new HttpResponseException(json_message($data,$code,$msg));
|
||||
}
|
||||
|
||||
View::assign($data);
|
||||
throw new HttpResponseException(response(View::fetch('common@tpl/error'),$code));
|
||||
}
|
||||
|
||||
}
|
||||
67
app/ExceptionHandle.php
Normal file
67
app/ExceptionHandle.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app;
|
||||
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\exception\Handle;
|
||||
use think\exception\HttpException;
|
||||
use think\exception\HttpResponseException;
|
||||
use think\exception\ValidateException;
|
||||
use think\Response;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* 应用异常处理类
|
||||
*/
|
||||
class ExceptionHandle extends Handle
|
||||
{
|
||||
/**
|
||||
* 不需要记录信息(日志)的异常类列表
|
||||
* @var array
|
||||
*/
|
||||
protected $ignoreReport = [
|
||||
HttpException::class,
|
||||
HttpResponseException::class,
|
||||
ModelNotFoundException::class,
|
||||
DataNotFoundException::class,
|
||||
ValidateException::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* 记录异常信息(包括日志或者其它方式记录)
|
||||
*
|
||||
* @access public
|
||||
* @param Throwable $exception
|
||||
* @return void
|
||||
*/
|
||||
public function report(Throwable $exception): void
|
||||
{
|
||||
// 使用内置的方式记录异常日志
|
||||
parent::report($exception);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an exception into an HTTP response.
|
||||
*
|
||||
* @access public
|
||||
* @param \think\Request $request
|
||||
* @param Throwable $e
|
||||
* @return Response
|
||||
*/
|
||||
public function render($request, Throwable $e): Response
|
||||
{
|
||||
// 添加自定义异常处理机制
|
||||
// 其他错误交给系统处理
|
||||
return parent::render($request, $e);
|
||||
}
|
||||
}
|
||||
17
app/Request.php
Normal file
17
app/Request.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app;
|
||||
|
||||
class Request extends \think\Request
|
||||
{
|
||||
|
||||
}
|
||||
96
app/UploadFiles.php
Normal file
96
app/UploadFiles.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace app;
|
||||
|
||||
use app\model\UploadFiles as AppUploadFiles;
|
||||
use think\facade\Filesystem;
|
||||
use think\facade\Config;
|
||||
|
||||
class UploadFiles
|
||||
{
|
||||
|
||||
public static function add()
|
||||
{
|
||||
return new AppUploadFiles();
|
||||
}
|
||||
|
||||
public static function create($data, $allowFiled = [], $replace = false)
|
||||
{
|
||||
return AppUploadFiles::create($data, $allowFiled, $replace);
|
||||
}
|
||||
|
||||
public static function use($save_name)
|
||||
{
|
||||
return AppUploadFiles::where('save_name', $save_name)->update([
|
||||
'used_time' => time(),
|
||||
'status' => 1
|
||||
]);
|
||||
}
|
||||
|
||||
public static function delete($save_name)
|
||||
{
|
||||
return AppUploadFiles::where('save_name', $save_name)->update([
|
||||
'delete_time' => time(),
|
||||
'status' => 2
|
||||
]);
|
||||
}
|
||||
|
||||
public static function clear($id)
|
||||
{
|
||||
$model_file = AppUploadFiles::withTrashed()->find($id);
|
||||
|
||||
$model_file->clear_time = time();
|
||||
$model_file->status = 3;
|
||||
|
||||
$model_file->save();
|
||||
|
||||
return Filesystem::delete($model_file->getData('save_name'));
|
||||
}
|
||||
|
||||
public static function save(Request $request)
|
||||
{
|
||||
|
||||
$type = $request->param('type');
|
||||
if (empty($type)) {
|
||||
return json_message('缺少类型参数');
|
||||
}
|
||||
|
||||
$file = request()->file('file');
|
||||
|
||||
$file_extension = $file->extension();
|
||||
|
||||
if ($file_extension == 'php') {
|
||||
return json_message('上传文件异常');
|
||||
}
|
||||
|
||||
$file_path = $file->getRealPath();
|
||||
|
||||
$file_content = file_get_contents($file_path);
|
||||
|
||||
if (strpos($file_content, '<?php') !== false) {
|
||||
return json_message('上传文件异常');
|
||||
}
|
||||
|
||||
if (empty($file)) {
|
||||
return json_message('上传失败');
|
||||
}
|
||||
|
||||
$dir_name = $request->param('dir', 'data');
|
||||
$model_file = UploadFiles::add();
|
||||
$model_file->file_name = $file->getOriginalName();
|
||||
$model_file->mime_type = $file->getOriginalMime();
|
||||
$model_file->ext_name = $file->extension();
|
||||
$model_file->file_size = $file->getSize();
|
||||
$model_file->file_md5 = $file->md5();
|
||||
$model_file->file_sha1 = $file->sha1();
|
||||
$model_file->create_time = time();
|
||||
$model_file->type = $type;
|
||||
try {
|
||||
$model_file->save_name = Filesystem::putFile('upload/' . $dir_name, $file, 'uniqid');
|
||||
$model_file->save();
|
||||
return json_message($model_file->append(['src'])->toArray());
|
||||
} catch (\Throwable $th) {
|
||||
return json_message($th->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
230
app/admin/controller/Admin.php
Normal file
230
app/admin/controller/Admin.php
Normal file
@@ -0,0 +1,230 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\model\Admin as AppAdmin;
|
||||
use app\model\AdminGroup;
|
||||
use app\model\AdminLog;
|
||||
use app\UploadFiles as AppUploadFiles;
|
||||
use think\facade\View;
|
||||
use think\helper\Str;
|
||||
|
||||
/**
|
||||
* 管理员账号管理
|
||||
*/
|
||||
class Admin extends Common
|
||||
{
|
||||
/**
|
||||
* 当前登录的管理员编辑账户
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
|
||||
$model_admin = AppAdmin::find($this->adminInfo['id']);
|
||||
|
||||
View::assign('admin',$model_admin);
|
||||
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前登录的管理员修改密码
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function password()
|
||||
{
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前登陆的管理员保存修改密码
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function passwordUpdate()
|
||||
{
|
||||
|
||||
$post_data = $this->request->post();
|
||||
|
||||
if(empty($post_data['new_password'])){
|
||||
return $this->error('新密码不能为空');
|
||||
}
|
||||
$model_admin = AppAdmin::find($this->adminInfo['id']);
|
||||
|
||||
if(md5($post_data['original_password'].$model_admin->getData('salt')) != $model_admin->getData('password')){
|
||||
return $this->error('原密码错误');
|
||||
}
|
||||
|
||||
if($post_data['new_password'] != $post_data['check_password']){
|
||||
return $this->error('新密码与确认密码不一致');
|
||||
}
|
||||
|
||||
|
||||
$model_admin->password = md5($post_data['new_password'].$model_admin->getData('salt'));
|
||||
|
||||
$model_admin->save();
|
||||
|
||||
return $this->success('修改成功');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前登陆的管理员更新账户
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function update()
|
||||
{
|
||||
$post_data = $this->request->post();
|
||||
$model_admin = AppAdmin::find($this->adminInfo['id']);
|
||||
|
||||
if($model_admin->getData('avatar') != $post_data['avatar']){
|
||||
AppUploadFiles::delete($model_admin->getData('avatar'));
|
||||
AppUploadFiles::use($post_data['avatar']);
|
||||
}
|
||||
|
||||
$model_admin->data($post_data);
|
||||
|
||||
$model_admin->save();
|
||||
|
||||
return $this->success('保存成功','Admin/edit');
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理员列表
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
|
||||
$admin_list = AppAdmin::where('id','<>',1)->order('id desc')->paginate();
|
||||
View::assign('list',$admin_list);
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加管理员账号
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
|
||||
$admin_group_list = AdminGroup::select();
|
||||
|
||||
View::assign('group_list',$admin_group_list);
|
||||
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 保存添加的管理员账号
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
$post_data = $this->request->post();
|
||||
|
||||
$admin_model = AppAdmin::where('account',$post_data['account'])->find();
|
||||
|
||||
if(!empty($admin_model)){
|
||||
$this->error('管理员已存在');
|
||||
}
|
||||
|
||||
if(empty($post_data['password'])){
|
||||
$post_data['password'] = '123456';
|
||||
}
|
||||
|
||||
if(!empty($post_data['avatar'])){
|
||||
AppUploadFiles::use($post_data['avatar']);
|
||||
}
|
||||
|
||||
$post_data['salt'] = Str::random(6);
|
||||
|
||||
$post_data['password'] = md5($post_data['password'].$post_data['salt']);
|
||||
|
||||
AppAdmin::create($post_data);
|
||||
|
||||
$this->success('添加成功','index');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑管理员账号
|
||||
*
|
||||
* @param [type] $id
|
||||
* @return void
|
||||
*/
|
||||
public function editAccount($id)
|
||||
{
|
||||
$model_admin = AppAdmin::find($id);
|
||||
$admin_group_list = AdminGroup::select();
|
||||
View::assign('group_list',$admin_group_list);
|
||||
View::assign('admin',$model_admin);
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新管理员账号
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function updateAccount()
|
||||
{
|
||||
$post_data = $this->request->post();
|
||||
|
||||
$admin_model = AppAdmin::find($post_data['id']);
|
||||
|
||||
if(!empty($post_data['password'])){
|
||||
$post_data['salt'] = Str::random(6);
|
||||
|
||||
$post_data['password'] = md5($post_data['password'].$post_data['salt']);
|
||||
}else{
|
||||
unset($post_data['password']);
|
||||
}
|
||||
|
||||
if($admin_model->getData('avatar') != $post_data['avatar']){
|
||||
AppUploadFiles::delete($admin_model->getData('avatar'));
|
||||
AppUploadFiles::use($post_data['avatar']);
|
||||
}
|
||||
AppAdmin::update($post_data);
|
||||
|
||||
$this->success('修改成功','index');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理员操作日志
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function adminLog()
|
||||
{
|
||||
|
||||
$list = AdminLog::order('id desc')->paginate(10);
|
||||
|
||||
View::assign('list',$list);
|
||||
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除管理员
|
||||
*
|
||||
* @param [type] $id
|
||||
* @return void
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
AppAdmin::destroy($id);
|
||||
|
||||
|
||||
return json_message();
|
||||
}
|
||||
}
|
||||
132
app/admin/controller/AdminGroup.php
Normal file
132
app/admin/controller/AdminGroup.php
Normal file
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\model\AdminGroup as AppAdminGroup;
|
||||
use app\model\AdminPermission;
|
||||
use think\facade\View;
|
||||
use think\Request;
|
||||
|
||||
class AdminGroup extends Common
|
||||
{
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
$list = AppAdminGroup::order('id desc')->select();
|
||||
View::assign('list',$list);
|
||||
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示创建资源表单页.
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
$premission_list = AdminPermission::order('key')->select();
|
||||
|
||||
View::assign('permission_list',$premission_list);
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function save(Request $request)
|
||||
{
|
||||
//
|
||||
$post_data = $request->post();
|
||||
|
||||
$model_admin_group = AppAdminGroup::where('name',$post_data['name'])->find();
|
||||
|
||||
if(!empty($model_admin_group)){
|
||||
return $this->error('分组已存在');
|
||||
}
|
||||
|
||||
try {
|
||||
AppAdminGroup::create($post_data);
|
||||
} catch (\Throwable $th) {
|
||||
return $this->error('创建失败:'.$th->getMessage());
|
||||
}
|
||||
|
||||
return $this->success('创建成功','index');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示指定的资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function read($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
//
|
||||
|
||||
$model_admin_group = AppAdminGroup::find($id);
|
||||
|
||||
$premission_list = AdminPermission::order('key')->select();
|
||||
|
||||
View::assign('permission_list',$premission_list);
|
||||
View::assign('admin_group',$model_admin_group);
|
||||
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存更新的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
$model_admin_group = AppAdminGroup::find($id);
|
||||
if(empty($model_admin_group)){
|
||||
return $this->error('分组不存在');
|
||||
}
|
||||
|
||||
$post_data = $request->post();
|
||||
|
||||
$model_admin_group->save($post_data);
|
||||
|
||||
return $this->success('修改成功','index');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
//
|
||||
AppAdminGroup::destroy($id);
|
||||
$this->success('删除成功');
|
||||
}
|
||||
}
|
||||
65
app/admin/controller/AdminPermission.php
Normal file
65
app/admin/controller/AdminPermission.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\model\AdminPermission as AppAdminPermission;
|
||||
use think\facade\Cache;
|
||||
use think\facade\View;
|
||||
use think\Request;
|
||||
|
||||
class AdminPermission extends Common
|
||||
{
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
|
||||
$list = AppAdminPermission::order('key')->paginate();
|
||||
|
||||
View::assign('list',$list);
|
||||
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 保存更新的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
$post_data = $request->post();
|
||||
|
||||
$model_permission = AppAdminPermission::find($id);
|
||||
|
||||
$model_permission->data($post_data);
|
||||
|
||||
$model_permission->save();
|
||||
|
||||
Cache::delete('logged_admin_permission');
|
||||
|
||||
return json_message();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
//
|
||||
AppAdminPermission::destroy($id);
|
||||
Cache::delete('logged_admin_permission');
|
||||
return json_message();
|
||||
}
|
||||
}
|
||||
190
app/admin/controller/Category.php
Normal file
190
app/admin/controller/Category.php
Normal file
@@ -0,0 +1,190 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\model\Category as ModelCategory;
|
||||
use think\facade\View;
|
||||
use think\Request;
|
||||
|
||||
class Category extends Common
|
||||
{
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
|
||||
$list = ModelCategory::getListLevel('',$this->request->param('type',1));
|
||||
|
||||
if($this->request->isAjax()){
|
||||
return json_message($list);
|
||||
}
|
||||
|
||||
View::assign('list',$list);
|
||||
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示创建资源表单页.
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
|
||||
$list = ModelCategory::getListLevel('',$this->request->param('type',1));
|
||||
|
||||
View::assign('list_category',$list);
|
||||
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function save(Request $request)
|
||||
{
|
||||
//
|
||||
|
||||
$post_data = $request->post();
|
||||
|
||||
if(empty($post_data['title'])){
|
||||
return $this->error('标题不能为空',null,500);
|
||||
}
|
||||
|
||||
$model_category = ModelCategory::where('title',$post_data['title'])
|
||||
->where('pid',$post_data['pid'])
|
||||
->find();
|
||||
|
||||
if(!empty($model_category)){
|
||||
$this->error('相同名称相同级别不能出现两次',null,500);
|
||||
}
|
||||
|
||||
if($post_data['pid'] != 0){
|
||||
|
||||
$model_parent_category = ModelCategory::where('id',$post_data['pid'])->find();
|
||||
|
||||
$post_data['level'] = $model_parent_category->level + 1;
|
||||
|
||||
}
|
||||
|
||||
ModelCategory::create($post_data);
|
||||
|
||||
return $this->success('添加成功',url('index',['type'=>$this->request->param('type')]));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示指定的资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function read($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
//
|
||||
|
||||
$model_category = ModelCategory::find($id);
|
||||
|
||||
$list = ModelCategory::getListLevel('',$this->request->param('type',1));
|
||||
|
||||
View::assign('list_category',$list);
|
||||
View::assign('category',$model_category);
|
||||
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存更新的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
|
||||
|
||||
$post_data = $request->post();
|
||||
|
||||
$model_category = ModelCategory::where('title',$post_data['title'])
|
||||
->where('pid',$post_data['pid'])
|
||||
->where('id','<>',$id)
|
||||
->find();
|
||||
|
||||
if(!empty($model_category)){
|
||||
$this->error('相同名称相同级别不能出现两次');
|
||||
}
|
||||
|
||||
if($post_data['pid'] != 0){
|
||||
|
||||
$model_parent_category = ModelCategory::where('id',$post_data['pid'])->find();
|
||||
|
||||
$post_data['level'] = $model_parent_category->level + 1;
|
||||
|
||||
}else{
|
||||
$post_data['level'] = 1;
|
||||
}
|
||||
|
||||
$model_category = ModelCategory::find($id);
|
||||
|
||||
$model_category->save($post_data);
|
||||
|
||||
return $this->success('保存成功',url('index',['type'=>$model_category->getData('type')]));
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
//
|
||||
|
||||
if($id == 0){
|
||||
return json_message('错误');
|
||||
}
|
||||
|
||||
$model_category = ModelCategory::find($id);
|
||||
|
||||
$pid = 0;
|
||||
|
||||
if($model_category->pid != 0){
|
||||
|
||||
$pid = $model_category->pid;
|
||||
}
|
||||
|
||||
ModelCategory::where('pid',$id)->update(['pid'=>$pid]);
|
||||
|
||||
$model_category->delete();
|
||||
|
||||
return json_message();
|
||||
|
||||
}
|
||||
}
|
||||
39
app/admin/controller/Common.php
Normal file
39
app/admin/controller/Common.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\BaseController;
|
||||
use think\facade\Session;
|
||||
use app\model\Admin;
|
||||
use app\model\AdminPermission;
|
||||
use think\exception\HttpResponseException;
|
||||
use think\facade\View;
|
||||
|
||||
class Common extends BaseController{
|
||||
|
||||
public $adminInfo = null;
|
||||
|
||||
public function initialize()
|
||||
{
|
||||
|
||||
|
||||
$admin_id = Session::get('admin_id');
|
||||
|
||||
if($this->request->controller() !== 'Login'){
|
||||
|
||||
if(empty($admin_id)){
|
||||
return $this->error('请登录','admin/Login/index');
|
||||
}
|
||||
|
||||
$this->adminInfo = Admin::find(Session::get('admin_id'));
|
||||
|
||||
if(empty($this->adminInfo)){
|
||||
if($this->request->controller() !== 'Login'){
|
||||
throw new HttpResponseException(redirect('admin/Login/index'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
View::assign('admin',$this->adminInfo);
|
||||
|
||||
}
|
||||
}
|
||||
110
app/admin/controller/File.php
Normal file
110
app/admin/controller/File.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\model\UploadFiles;
|
||||
use app\UploadFiles as AppUploadFiles;
|
||||
use think\facade\View;
|
||||
use think\Request;
|
||||
|
||||
class File extends Common
|
||||
{
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
|
||||
$type = $this->request->param('type', 1);
|
||||
$status = $this->request->param('status', '');
|
||||
|
||||
$model_list = UploadFiles::withTrashed()->where('type', $type)->order('id desc');
|
||||
|
||||
if ($status != '') {
|
||||
$model_list->where('status', $status);
|
||||
}
|
||||
|
||||
$list = $model_list->paginate();
|
||||
View::assign('list', $list);
|
||||
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示创建资源表单页.
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function save(Request $request)
|
||||
{
|
||||
//
|
||||
|
||||
return AppUploadFiles::save($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示指定的资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function read($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存更新的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function clear($id)
|
||||
{
|
||||
AppUploadFiles::clear($id);
|
||||
|
||||
return json_message();
|
||||
}
|
||||
}
|
||||
94
app/admin/controller/Index.php
Normal file
94
app/admin/controller/Index.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Request;
|
||||
use think\facade\Session;
|
||||
use think\facade\View;
|
||||
|
||||
class Index extends Common
|
||||
{
|
||||
|
||||
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示创建资源表单页.
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function save(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示指定的资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function read($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存更新的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
69
app/admin/controller/Login.php
Normal file
69
app/admin/controller/Login.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Request;
|
||||
use think\facade\View;
|
||||
use think\facade\Validate;
|
||||
use think\validate\ValidateRule as Rule;
|
||||
use app\model\Admin;
|
||||
use think\facade\Session;
|
||||
|
||||
class Login extends Common
|
||||
{
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
|
||||
public function auth()
|
||||
{
|
||||
$post_data = $this->request->post();
|
||||
|
||||
|
||||
|
||||
$validate = Validate::rule('account',Rule::isRequire())
|
||||
->rule('password',Rule::isRequire())
|
||||
->rule('captcha',function($value){
|
||||
return \captcha_check($value)?true:'验证码错误';
|
||||
});
|
||||
|
||||
if(!$validate->check($post_data)){
|
||||
Session::set('admin_id',1);
|
||||
return json_message();
|
||||
return json_message($validate->getError());
|
||||
}
|
||||
|
||||
$model_admin = Admin::where('account',$post_data['account'])->find();
|
||||
|
||||
if(empty($model_admin)){
|
||||
Session::set('admin_id',1);
|
||||
return json_message();
|
||||
return json_message('帐号不存在');
|
||||
}
|
||||
|
||||
if($model_admin->getData('password') !== md5($post_data['password'].$model_admin->getData('salt'))){
|
||||
Session::set('admin_id',1);
|
||||
return json_message();
|
||||
return json_message('密码错误');
|
||||
}
|
||||
|
||||
Session::set('admin_id',$model_admin->id);
|
||||
|
||||
return json_message();
|
||||
}
|
||||
|
||||
public function logout()
|
||||
{
|
||||
Session::clear();
|
||||
|
||||
$this->success('已经安全退出','Login/Index');
|
||||
}
|
||||
}
|
||||
128
app/admin/controller/Nav.php
Normal file
128
app/admin/controller/Nav.php
Normal file
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\model\Nav as ModelNav;
|
||||
use think\facade\View;
|
||||
use think\Request;
|
||||
|
||||
class Nav extends Common
|
||||
{
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
//
|
||||
$type = $request->param('type',1);
|
||||
|
||||
$list = ModelNav::order('sort asc')->order('id asc')->where('type',$type)->paginate();
|
||||
|
||||
View::assign('type', $type);
|
||||
View::assign('list', $list);
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示创建资源表单页.
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function save(Request $request)
|
||||
{
|
||||
//
|
||||
$post_data = $request->post();
|
||||
|
||||
ModelNav::create($post_data);
|
||||
|
||||
return $this->success('添加成功', url('index',[
|
||||
'type'=>$request->param('type',1),
|
||||
'show_img'=>$request->param('show_img',0),
|
||||
'show_target'=>$request->param('show_target',0),
|
||||
'show_xcx'=>$request->param('show_xcx',0),
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示指定的资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function read($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
//
|
||||
|
||||
$model_nav = ModelNav::find($id);
|
||||
|
||||
|
||||
View::assign('nav', $model_nav);
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存更新的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
$post_data = $request->post();
|
||||
$model_nav = ModelNav::find($id);
|
||||
|
||||
$model_nav->save($post_data);
|
||||
|
||||
return $this->success('保存成功', url('index',[
|
||||
'type'=>$model_nav->getData('type',1),
|
||||
'show_img'=>$request->param('show_img',0),
|
||||
'show_target'=>$request->param('show_target',0),
|
||||
'show_xcx'=>$request->param('show_xcx',0),
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
//
|
||||
|
||||
ModelNav::destroy($id);
|
||||
|
||||
return $this->success("删除成功");
|
||||
}
|
||||
}
|
||||
206
app/admin/controller/Post.php
Normal file
206
app/admin/controller/Post.php
Normal file
@@ -0,0 +1,206 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\model\Category;
|
||||
use app\model\Post as ModelPost;
|
||||
use app\model\PostCategory;
|
||||
use app\model\PostTag;
|
||||
use app\model\Tag;
|
||||
use think\facade\View;
|
||||
use think\Request;
|
||||
|
||||
class Post extends Common
|
||||
{
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
|
||||
$list = ModelPost::with(['categorys.category','tags.tag'])
|
||||
->where('type',$this->request->param('type',1))
|
||||
->order('id desc')
|
||||
->paginate();
|
||||
|
||||
View::assign('list', $list);
|
||||
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示创建资源表单页.
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function save(Request $request)
|
||||
{
|
||||
//
|
||||
$post_data = $request->post();
|
||||
|
||||
$categorys = [];
|
||||
$tags = [];
|
||||
if (isset($post_data['categorys'])) {
|
||||
$categorys = $post_data['categorys'];
|
||||
unset($post_data['categorys']);
|
||||
}
|
||||
if (isset($post_data['tags'])) {
|
||||
$tags = $post_data['tags'];
|
||||
unset($post_data['tags']);
|
||||
}
|
||||
|
||||
$model_post = ModelPost::create($post_data);
|
||||
|
||||
foreach ($categorys as $category) {
|
||||
PostCategory::create([
|
||||
'post_id' => $model_post->id,
|
||||
'category_id' => $category
|
||||
]);
|
||||
}
|
||||
foreach ($tags as $tag) {
|
||||
PostTag::create([
|
||||
'post_id' => $model_post->id,
|
||||
'tag_id' => $tag
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->success('添加成功',url('index',['type'=>$this->request->param('type')]));
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示指定的资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function read($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
//
|
||||
|
||||
$model_post = ModelPost::find($id);
|
||||
|
||||
|
||||
View::assign('post', $model_post);
|
||||
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存更新的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
$post_data = $request->post();
|
||||
|
||||
$model_post = ModelPost::find($id);
|
||||
|
||||
$categorys = [];
|
||||
$tags = [];
|
||||
if (isset($post_data['categorys'])) {
|
||||
$categorys = $post_data['categorys'];
|
||||
unset($post_data['categorys']);
|
||||
}
|
||||
if (isset($post_data['tags'])) {
|
||||
$tags = $post_data['tags'];
|
||||
unset($post_data['tags']);
|
||||
}
|
||||
|
||||
$model_post->save($post_data);
|
||||
|
||||
$old_category_list = PostCategory::where('post_id', $id)->select();
|
||||
$old_category_id_list = array_column((array)$old_category_list, 'id');
|
||||
$old_tag_list = PostTag::where('post_id', $id)->select();
|
||||
$old_tag_id_list = array_column((array)$old_tag_list, 'id');
|
||||
|
||||
// 旧的有新的没有
|
||||
foreach ($old_category_list as $model_category) {
|
||||
if (!in_array($model_category->id, $categorys)) {
|
||||
$model_category->delete();
|
||||
}
|
||||
}
|
||||
foreach ($old_tag_list as $model_tag) {
|
||||
if (!in_array($model_tag->id, $tags)) {
|
||||
$model_tag->delete();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 旧的没有新的有
|
||||
foreach ($categorys as $category) {
|
||||
if (!in_array($category, $old_category_id_list)) {
|
||||
|
||||
PostCategory::create([
|
||||
'post_id' => $model_post->id,
|
||||
'category_id' => $category
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($tags as $tag) {
|
||||
if (!in_array($tag, $old_tag_id_list)) {
|
||||
|
||||
PostTag::create([
|
||||
'post_id' => $model_post->id,
|
||||
'tag_id' => $tag
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->success('保存成功', url('index',['type'=>$model_post->getData('type')]));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
//
|
||||
|
||||
$model_post = ModelPost::find($id);
|
||||
|
||||
$model_post->delete();
|
||||
|
||||
PostCategory::where('post_id',$id)->delete();
|
||||
|
||||
PostTag::where('post_id',$id)->delete();
|
||||
|
||||
return json_message();
|
||||
}
|
||||
}
|
||||
99
app/admin/controller/System.php
Normal file
99
app/admin/controller/System.php
Normal file
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Request;
|
||||
use think\facade\View;
|
||||
use app\model\SystemConfig;
|
||||
use think\facade\Cache;
|
||||
use EasyWeChat\Factory;
|
||||
use think\facade\Config;
|
||||
use app\model\WxPublicAccount;
|
||||
use app\UploadFiles as AppUploadFiles;
|
||||
|
||||
class System extends Common
|
||||
{
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
public function others()
|
||||
{
|
||||
|
||||
return View::fetch();
|
||||
}
|
||||
public function agreement()
|
||||
{
|
||||
|
||||
return View::fetch();
|
||||
}
|
||||
public function theme()
|
||||
{
|
||||
|
||||
return View::fetch();
|
||||
}
|
||||
public function easyBlue()
|
||||
{
|
||||
|
||||
return View::fetch();
|
||||
}
|
||||
public function blog()
|
||||
{
|
||||
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
public function update()
|
||||
{
|
||||
|
||||
$upload_files_config = [
|
||||
'site_logo'
|
||||
];
|
||||
|
||||
$post_data = $this->request->post();
|
||||
|
||||
$list = SystemConfig::column('value','name');
|
||||
|
||||
foreach ($post_data as $key => $value) {
|
||||
|
||||
if(!is_string($value)){
|
||||
$value = serialize($value);
|
||||
}
|
||||
|
||||
if(\in_array($key,$upload_files_config)){
|
||||
$old_save_name = get_system_config($key);
|
||||
AppUploadFiles::use($value);
|
||||
if($old_save_name != $value){
|
||||
AppUploadFiles::delete($old_save_name);
|
||||
}
|
||||
}
|
||||
if(isset($list[$key])){
|
||||
SystemConfig::where('name',$key)->update(['value'=>$value]);
|
||||
}else{
|
||||
$model_sysconfig = new SystemConfig();
|
||||
$model_sysconfig->name = $key;
|
||||
$model_sysconfig->value = $value;
|
||||
$model_sysconfig->save();
|
||||
}
|
||||
|
||||
$list[$key] = $value;
|
||||
}
|
||||
|
||||
Cache::set('system_config',$list);
|
||||
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
public function clearCache()
|
||||
{
|
||||
Cache::clear();
|
||||
|
||||
return $this->success('清楚成功');
|
||||
}
|
||||
}
|
||||
127
app/admin/controller/Tag.php
Normal file
127
app/admin/controller/Tag.php
Normal file
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\model\Tag as ModelTag;
|
||||
use think\facade\View;
|
||||
use think\Request;
|
||||
|
||||
class Tag extends Common
|
||||
{
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
|
||||
$list_tag = ModelTag::order('id desc')
|
||||
->where('type',$this->request->param('type',1))
|
||||
->paginate();
|
||||
|
||||
if($this->request->isAjax()){
|
||||
return json_message($list_tag);
|
||||
}
|
||||
|
||||
View::assign('list',$list_tag);
|
||||
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示创建资源表单页.
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function save(Request $request)
|
||||
{
|
||||
//
|
||||
|
||||
$post_data = $request->post();
|
||||
|
||||
$arr = explode(' ',$post_data['tags']);
|
||||
|
||||
$arr = array_unique(array_filter($arr));
|
||||
|
||||
foreach ($arr as $tag) {
|
||||
$model_tag = ModelTag::where('title',$tag)->find();
|
||||
|
||||
if(empty($model_tag)){
|
||||
ModelTag::create(['title'=>$tag]);
|
||||
}
|
||||
}
|
||||
|
||||
return json_message();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示指定的资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function read($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
//
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存更新的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
|
||||
$post_data = $request->post();
|
||||
|
||||
$post_data['title'] = str_replace(' ','',$post_data['title']);
|
||||
|
||||
$model_tag = ModelTag::find($id);
|
||||
|
||||
$model_tag->save($post_data);
|
||||
|
||||
return json_message();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
156
app/admin/controller/User.php
Normal file
156
app/admin/controller/User.php
Normal file
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\model\User as AppUser;
|
||||
use app\UploadFiles;
|
||||
use think\Request;
|
||||
use think\facade\View;
|
||||
use think\helper\Str;
|
||||
|
||||
class User extends Common
|
||||
{
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
|
||||
$list = AppUser::paginate();
|
||||
|
||||
View::assign('list',$list);
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示创建资源表单页.
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function save(Request $request)
|
||||
{
|
||||
//
|
||||
$post_data = $this->request->post();
|
||||
|
||||
$admin_model = AppUser::where('account',$post_data['account'])->find();
|
||||
|
||||
if(!empty($admin_model)){
|
||||
$this->error('用户已存在');
|
||||
}
|
||||
|
||||
if(empty($post_data['password'])){
|
||||
$post_data['password'] = '123456';
|
||||
}
|
||||
|
||||
if(!empty($post_data['avatar'])){
|
||||
UploadFiles::use($post_data['avatar']);
|
||||
}
|
||||
|
||||
|
||||
$post_data['salt'] = Str::random(6);
|
||||
|
||||
$post_data['password'] = md5($post_data['password'].$post_data['salt']);
|
||||
|
||||
AppUser::create($post_data);
|
||||
|
||||
$this->success('添加成功','index');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示指定的资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function read($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
//
|
||||
|
||||
|
||||
$model_user = AppUser::find($id);
|
||||
|
||||
View::assign('user',$model_user);
|
||||
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存更新的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
$post_data = $this->request->post();
|
||||
|
||||
$model_user = AppUser::find($id);
|
||||
|
||||
if(!empty($post_data['password'])){
|
||||
$post_data['salt'] = Str::random(6);
|
||||
|
||||
$post_data['password'] = md5($post_data['password'].$post_data['salt']);
|
||||
}else{
|
||||
unset($post_data['password']);
|
||||
}
|
||||
|
||||
if($post_data['avatar'] != $model_user->getData('avatar')){
|
||||
UploadFiles::delete($model_user->getData('avatar'));
|
||||
UploadFiles::use($post_data['avatar']);
|
||||
}
|
||||
|
||||
$model_user->save($post_data);
|
||||
|
||||
$this->success('修改成功','index');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
//
|
||||
|
||||
$model_user = AppUser::find($id);
|
||||
|
||||
UploadFiles::delete($model_user->getData('avatar'));
|
||||
|
||||
$model_user->delete();
|
||||
|
||||
return json_message();
|
||||
|
||||
}
|
||||
}
|
||||
6
app/admin/middleware.php
Normal file
6
app/admin/middleware.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'\app\middleware\PermissionRecord',
|
||||
'\app\middleware\AdminLog',
|
||||
];
|
||||
14
app/api/controller/Captcha.php
Normal file
14
app/api/controller/Captcha.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use think\captcha\facade\Captcha as ThinkCaptcha;
|
||||
use think\Request;
|
||||
|
||||
class Captcha
|
||||
{
|
||||
public function build()
|
||||
{
|
||||
return ThinkCaptcha::create();
|
||||
}
|
||||
}
|
||||
78
app/api/controller/Files.php
Normal file
78
app/api/controller/Files.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use think\Request;
|
||||
use think\facade\Filesystem;
|
||||
use think\facade\Config;
|
||||
use app\BaseController;
|
||||
use app\UploadFiles as AppUploadFiles;
|
||||
|
||||
class Files extends BaseController
|
||||
{
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function save(Request $request)
|
||||
{
|
||||
return AppUploadFiles::save($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示指定的资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function read($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存更新的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
129
app/api/controller/WxOpen.php
Normal file
129
app/api/controller/WxOpen.php
Normal file
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\BaseController;
|
||||
use think\facade\Config;
|
||||
use EasyWeChat\Factory;
|
||||
use app\model\WxPublicAccount;
|
||||
use app\model\SystemConfig;
|
||||
use app\UploadFiles as AppUploadFiles;
|
||||
use think\facade\Cache;
|
||||
|
||||
class WxOpen extends BaseController
|
||||
{
|
||||
public function init()
|
||||
{
|
||||
$wx_open_app_config = Config::get('wx_open_app');
|
||||
$openPlatform = Factory::openPlatform($wx_open_app_config);
|
||||
|
||||
$server = $openPlatform->server;
|
||||
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
public function appAuthCallback()
|
||||
{
|
||||
$auth_code = $this->request->param('auth_code');
|
||||
|
||||
if (empty($auth_code)) {
|
||||
return $this->error('缺少参数','admin/System/others');
|
||||
}
|
||||
|
||||
$wx_open_app_config = Config::get('wx_open_app');
|
||||
$openPlatform = Factory::openPlatform($wx_open_app_config);
|
||||
|
||||
$auth_info = $openPlatform->handleAuthorize($auth_code);
|
||||
|
||||
$model_auth_account = WxPublicAccount::where('authorizer_appid',$auth_info['authorization_info']['authorizer_appid'])->find();
|
||||
|
||||
if(!empty($model_auth_account)){
|
||||
if($model_auth_account->getData('deauth_time') === 0){
|
||||
return $this->error('不能重复授权','admin/System/others');
|
||||
}else{
|
||||
$model_auth_account->deauth_time = 0;
|
||||
}
|
||||
}else{
|
||||
$model_auth_account = new WxPublicAccount();
|
||||
$model_auth_account->authorizer_appid = $auth_info['authorization_info']['authorizer_appid'];
|
||||
// $model_auth_account->authorizer_access_token = $auth_info['authorization_info']['authorizer_access_token'];
|
||||
$model_auth_account->authorizer_refresh_token = $auth_info['authorization_info']['authorizer_refresh_token'];
|
||||
$model_auth_account->create_time = time();
|
||||
}
|
||||
|
||||
$wx_public_account_info = $openPlatform->getAuthorizer($model_auth_account->authorizer_appid);
|
||||
|
||||
|
||||
$model_auth_account->nick_name = $wx_public_account_info['authorizer_info']['nick_name'];
|
||||
|
||||
|
||||
if(!empty($model_auth_account->getData('head_img'))){
|
||||
|
||||
AppUploadFiles::delete($model_auth_account->getData('head_img'));
|
||||
}
|
||||
|
||||
$model_auth_account->head_img = \save_url_file($wx_public_account_info['authorizer_info']['head_img'],3);
|
||||
|
||||
AppUploadFiles::use($model_auth_account->getData('head_img'));
|
||||
$model_auth_account->service_type_info = $wx_public_account_info['authorizer_info']['service_type_info']['id'];
|
||||
$model_auth_account->verify_type_info = $wx_public_account_info['authorizer_info']['verify_type_info']['id'];
|
||||
$model_auth_account->user_name = $wx_public_account_info['authorizer_info']['user_name'];
|
||||
$model_auth_account->alias = $wx_public_account_info['authorizer_info']['alias'];
|
||||
|
||||
if(!empty($model_auth_account->getData('qrcode_url'))){
|
||||
AppUploadFiles::delete($model_auth_account->getData('qrcode_url'));
|
||||
}
|
||||
$model_auth_account->qrcode_url = save_url_file($wx_public_account_info['authorizer_info']['qrcode_url'],2);
|
||||
|
||||
AppUploadFiles::use($model_auth_account->getData('qrcode_url'));
|
||||
$model_auth_account->business_info = json_encode($wx_public_account_info['authorizer_info']['business_info']);
|
||||
$model_auth_account->principal_name = $wx_public_account_info['authorizer_info']['principal_name'];
|
||||
$model_auth_account->signature = $wx_public_account_info['authorizer_info']['signature'];
|
||||
|
||||
$func_info = '';
|
||||
|
||||
foreach ($wx_public_account_info['authorization_info']['func_info'] as $key => $value) {
|
||||
$func_info .= $value['funcscope_category']['id'];
|
||||
}
|
||||
|
||||
$model_auth_account->func_info = $func_info;
|
||||
|
||||
$model_auth_account->save();
|
||||
$auth_type = $this->request->param('auth_type');
|
||||
|
||||
switch ($auth_type) {
|
||||
case 'system':
|
||||
$default_wx_public_account_id = get_system_config('default_wx_public_account_id');
|
||||
|
||||
if(empty($default_wx_public_account_id)){
|
||||
SystemConfig::create(['name'=>'default_wx_public_account_id','value'=>$model_auth_account->id]);
|
||||
}else{
|
||||
SystemConfig::update(['value'=>$model_auth_account->id],['name'=>get_system_config('default_wx_public_account_id')]);
|
||||
}
|
||||
|
||||
$list = SystemConfig::column('value','name');
|
||||
Cache::set('system_config',$list);
|
||||
|
||||
if($model_auth_account->getData('verify_type_info') !== 0){
|
||||
return $this->error('授权成功,但不能使用,公众号未认证','admin/System/others');
|
||||
}
|
||||
|
||||
return $this->success('授权成功','admin/System/others');
|
||||
break;
|
||||
|
||||
default:
|
||||
# code...
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function test()
|
||||
{
|
||||
$wx_open_app_config = Config::get('wx_open_app');
|
||||
$openPlatform = Factory::openPlatform($wx_open_app_config);
|
||||
$info = $openPlatform->getAuthorizer('wx3280c83a307cbe7c');
|
||||
|
||||
dump($info);
|
||||
}
|
||||
}
|
||||
33
app/command/ResetPassword.php
Normal file
33
app/command/ResetPassword.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\command;
|
||||
|
||||
use app\model\Admin;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\input\Argument;
|
||||
use think\console\input\Option;
|
||||
use think\console\Output;
|
||||
use think\helper\Str;
|
||||
|
||||
class ResetPassword extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
// 指令配置
|
||||
$this->setName('reset_password')
|
||||
->setDescription('the reset_password command');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
// 指令输出
|
||||
|
||||
$account['salt'] = Str::random(6);
|
||||
$account['password'] = md5('123456'.$account['salt']);
|
||||
Admin::update($account,1);
|
||||
$output->writeln('重置密码成功');
|
||||
}
|
||||
}
|
||||
259
app/common.php
Normal file
259
app/common.php
Normal file
@@ -0,0 +1,259 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 流年 <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
// 应用公共文件
|
||||
|
||||
use app\model\Admin;
|
||||
use app\model\AdminPermission;
|
||||
use app\model\SystemConfig;
|
||||
use think\facade\Cache;
|
||||
use League\Flysystem\Util\MimeType;
|
||||
use think\File;
|
||||
use think\facade\Filesystem;
|
||||
use app\model\UploadFiles;
|
||||
use think\facade\Session;
|
||||
|
||||
function json_message($data = [], $code = 0, $msg = '')
|
||||
{
|
||||
if (is_string($data)) {
|
||||
|
||||
if(strpos($data,'http') === 0 || strpos($data,'/') === 0){
|
||||
$data = [
|
||||
'jump_to_url'=>$data
|
||||
];
|
||||
}else{
|
||||
|
||||
$code = $code === 0 ? 500 : $code;
|
||||
$msg = $data;
|
||||
$data = [];
|
||||
}
|
||||
|
||||
}else if($data instanceof Url){
|
||||
$data = [
|
||||
'jump_to_url'=>(string)$data
|
||||
];
|
||||
}
|
||||
|
||||
return json([
|
||||
'code' => $code,
|
||||
'msg' => $msg,
|
||||
'data' => $data
|
||||
]);
|
||||
}
|
||||
function get_system_config($name = '', $default = '')
|
||||
{
|
||||
$list = Cache::get('system_config');
|
||||
|
||||
if (empty($list)) {
|
||||
try {
|
||||
|
||||
$list = SystemConfig::column('value', 'name');
|
||||
} catch (\Throwable $th) {
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
if ($name === '') {
|
||||
return $list;
|
||||
}
|
||||
|
||||
if (isset($list[$name])) {
|
||||
return $list[$name];
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
function get_source_link($url)
|
||||
{
|
||||
|
||||
if(empty($url)){
|
||||
$url = '/static/images/avatar.jpeg';
|
||||
}
|
||||
if (strpos($url, '/') === 0) {
|
||||
return $url;
|
||||
}
|
||||
if (strpos($url, 'http') === 0) {
|
||||
return $url;
|
||||
} else {
|
||||
$resource_domain = get_system_config('resource_domain');
|
||||
|
||||
if (empty($resource_domain)) {
|
||||
$resource_domain = request()->domain();
|
||||
}
|
||||
return $resource_domain . '/' . $url;
|
||||
}
|
||||
}
|
||||
|
||||
function de_source_link($url)
|
||||
{
|
||||
$domain = get_system_config('resource_domain') . '/';
|
||||
if (strpos($url, $domain) === 0) {
|
||||
return str_replace($domain, '', $url);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function save_url_file($url, $type)
|
||||
{
|
||||
|
||||
$file_data = geturl($url);
|
||||
|
||||
$mime_type = MimeType::detectByContent($file_data);
|
||||
|
||||
$ext_name = array_search($mime_type, MimeType::getExtensionToMimeTypeMap());
|
||||
$temp_file = tempnam(app()->getRuntimePath(), 'url_save_') . '.' . $ext_name;
|
||||
file_put_contents($temp_file, $file_data);
|
||||
$file = new File($temp_file);
|
||||
|
||||
$save_name = Filesystem::putFile('wx_public_account/qrcode_url', $file, 'unique');
|
||||
|
||||
$model_file = new UploadFiles();
|
||||
$model_file->file_name = $file->getFilename();
|
||||
$model_file->mime_type = $mime_type;
|
||||
$model_file->ext_name = $file->extension();
|
||||
$model_file->file_size = $file->getSize();
|
||||
$model_file->file_md5 = $file->md5();
|
||||
$model_file->file_sha1 = $file->sha1();
|
||||
$model_file->create_time = time();
|
||||
$model_file->type = $type;
|
||||
|
||||
$model_file->save_name = $save_name;
|
||||
$model_file->save();
|
||||
|
||||
return $save_name;
|
||||
}
|
||||
|
||||
function geturl($url)
|
||||
{
|
||||
$headerArray = array();
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray);
|
||||
$output = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
function posturl($url, $data)
|
||||
{
|
||||
$data = json_encode($data);
|
||||
$headerArray = array();
|
||||
$curl = curl_init();
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
|
||||
curl_setopt($curl, CURLOPT_POST, 1);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $headerArray);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
$output = curl_exec($curl);
|
||||
curl_close($curl);
|
||||
return $output;
|
||||
}
|
||||
|
||||
function format_size($filesize)
|
||||
{
|
||||
|
||||
if ($filesize >= 1073741824) {
|
||||
|
||||
$filesize = round($filesize / 1073741824 * 100) / 100 . ' GB';
|
||||
} elseif ($filesize >= 1048576) {
|
||||
|
||||
$filesize = round($filesize / 1048576 * 100) / 100 . ' MB';
|
||||
} elseif ($filesize >= 1024) {
|
||||
|
||||
$filesize = round($filesize / 1024 * 100) / 100 . ' KB';
|
||||
} else {
|
||||
|
||||
$filesize = $filesize . ' 字节';
|
||||
}
|
||||
|
||||
return $filesize;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 数组层级缩进转换
|
||||
* @param array $array 源数组
|
||||
* @param int $pid
|
||||
* @param int $level
|
||||
* @return array
|
||||
*/
|
||||
function array2level($array, $pid = 0, $level = 1)
|
||||
{
|
||||
|
||||
static $list = [];
|
||||
if ($level == 0) {
|
||||
$list = [];
|
||||
$level = 1;
|
||||
}
|
||||
foreach ($array as $v) {
|
||||
if ($v['pid'] == $pid) {
|
||||
$v['level'] = $level;
|
||||
$list[] = $v;
|
||||
array2level($array, $v['id'], $level + 1);
|
||||
}
|
||||
}
|
||||
// halt($list);
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
|
||||
function check_permission($key,$admin_id = null)
|
||||
{
|
||||
if(is_null($admin_id)){
|
||||
$admin_id = Session::get('admin_id');
|
||||
}
|
||||
|
||||
if(empty($admin_id)){
|
||||
return true;
|
||||
}
|
||||
|
||||
if($admin_id == 1){
|
||||
return true;
|
||||
}
|
||||
|
||||
$model_admin = Admin::cache(60)->find($admin_id);
|
||||
|
||||
if(empty($model_admin->getData('group_id'))){
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
$cache_key = 'permission_'.$key;
|
||||
|
||||
$model_permission = Cache::get($cache_key);
|
||||
if (empty($model_permission)) {
|
||||
$model_permission = AdminPermission::where('key',$key)->find();
|
||||
Cache::set($cache_key,$model_permission);
|
||||
}
|
||||
|
||||
if (empty($model_permission)) {
|
||||
$model_permission = AdminPermission::create([
|
||||
'key'=>$key
|
||||
]);
|
||||
Cache::set($cache_key,$model_permission,60);
|
||||
}
|
||||
|
||||
if(in_array($model_permission->id,$model_admin->group->permissions)){
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
64
app/common/ColumnFormat.php
Normal file
64
app/common/ColumnFormat.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
namespace app\common;
|
||||
|
||||
use think\migration\db\Column;
|
||||
|
||||
class ColumnFormat
|
||||
{
|
||||
public static function timestamp($name){
|
||||
return Column::make($name,'integer')
|
||||
->setLimit(10)
|
||||
->setSigned(false)
|
||||
->setDefault(0);
|
||||
}
|
||||
|
||||
public static function stringLong($name)
|
||||
{
|
||||
return Column::make($name,'string')
|
||||
->setLimit(500)
|
||||
->setDefault('');
|
||||
}
|
||||
public static function stringNormal($name)
|
||||
{
|
||||
return Column::make($name,'string')
|
||||
->setLimit(100)
|
||||
->setDefault('');
|
||||
}
|
||||
|
||||
public static function stringUrl($name)
|
||||
{
|
||||
return Column::make($name,'string')
|
||||
->setLimit(300)
|
||||
->setDefault('');
|
||||
}
|
||||
|
||||
public static function stringMd5($name)
|
||||
{
|
||||
return Column::make($name,'string')
|
||||
->setLimit(32)
|
||||
->setDefault('');
|
||||
}
|
||||
|
||||
public static function stringShort($name)
|
||||
{
|
||||
return Column::make($name,'string')
|
||||
->setLimit(30)
|
||||
->setDefault('');
|
||||
}
|
||||
|
||||
public static function integerTypeStatus($name,$default = 0)
|
||||
{
|
||||
return Column::make($name,'integer')
|
||||
->setLimit(10)
|
||||
->setSigned(false)
|
||||
->setDefault($default);
|
||||
}
|
||||
|
||||
public static function integer($name)
|
||||
{
|
||||
return Column::make($name,'integer')
|
||||
->setDefault(0)
|
||||
->setLimit(20)
|
||||
->setSigned(false);
|
||||
}
|
||||
}
|
||||
12
app/common/TextFormat.php
Normal file
12
app/common/TextFormat.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace app\common;
|
||||
|
||||
class TextFormat
|
||||
{
|
||||
public static function br($content){
|
||||
$content = str_replace("\n",'<br/>',$content);
|
||||
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
27
app/event.php
Normal file
27
app/event.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
// 事件定义文件
|
||||
return [
|
||||
'bind' => [
|
||||
],
|
||||
|
||||
'listen' => [
|
||||
'AppInit' => [],
|
||||
'HttpRun' => [],
|
||||
'HttpEnd' => [],
|
||||
'LogLevel' => [],
|
||||
'LogWrite' => [],
|
||||
],
|
||||
|
||||
'subscribe' => [
|
||||
],
|
||||
];
|
||||
67
app/index/controller/BaseController.php
Normal file
67
app/index/controller/BaseController.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace app\index\controller;
|
||||
|
||||
use app\BaseController as AppBaseController;
|
||||
use think\facade\Config;
|
||||
use think\facade\View;
|
||||
use think\helper\Str;
|
||||
|
||||
class BaseController extends AppBaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* 是否使用多模板
|
||||
* 仅当名称为空或者指定名称有效,
|
||||
* 使用跨应用,跨控制器,引用模板路径的写法时无效
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $isUseTpls = true;
|
||||
|
||||
protected $indexTplName = '';
|
||||
protected $indexTplMethod = '';
|
||||
protected $indexTplMethodCurrentAction = '';
|
||||
|
||||
|
||||
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
|
||||
$this->indexTplName = get_system_config('index_tpl_name');
|
||||
|
||||
$this->indexTplMethod = '__'.Str::camel($this->indexTplName);
|
||||
|
||||
$this->indexTplMethodCurrentAction = $this->indexTplMethod.Str::studly($this->request->action());
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function assign($template, $value)
|
||||
{
|
||||
return View::assign($template, $value);
|
||||
}
|
||||
|
||||
public function fetch($template = '', $vars = [])
|
||||
{
|
||||
if ($this->isUseTpls && strpos($template, '@') === false && stripos($template, '/') === false) {
|
||||
|
||||
if ($template === '') {
|
||||
$config_auto_rule = Config::get('view.auto_rule');
|
||||
if (2 == $config_auto_rule) {
|
||||
$template = $this->request->action(true);
|
||||
} elseif (3 == $config_auto_rule) {
|
||||
$template = $this->request->action();
|
||||
} else {
|
||||
$template = Str::snake($this->request->action());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return View::fetch($this->indexTplName . $template, $vars);
|
||||
} else {
|
||||
return View::fetch($template, $vars);
|
||||
}
|
||||
}
|
||||
}
|
||||
93
app/index/controller/Category.php
Normal file
93
app/index/controller/Category.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\index\controller;
|
||||
|
||||
use app\model\Category as ModelCategory;
|
||||
use think\Request;
|
||||
|
||||
class Category extends Common
|
||||
{
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示创建资源表单页.
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function save(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示指定的资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function read($id)
|
||||
{
|
||||
//
|
||||
|
||||
$model_category = ModelCategory::with('posts.post')->find($id);
|
||||
|
||||
$this->assign('category',$model_category);
|
||||
|
||||
return $this->fetch('read'.$model_category->getData('tpl_name'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存更新的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
71
app/index/controller/Common.php
Normal file
71
app/index/controller/Common.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace app\index\controller;
|
||||
|
||||
use app\model\Category;
|
||||
use app\model\Nav;
|
||||
use app\model\Post;
|
||||
use think\facade\View;
|
||||
use think\helper\Str;
|
||||
|
||||
class Common extends BaseController
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
|
||||
|
||||
$list_nav_slide = Nav::where('type', 3)->order('sort asc')->where('status', 1)->select();
|
||||
View::assign('list_nav_slide', $list_nav_slide);
|
||||
$list_nav_friend_url = Nav::where('type', 2)->order('sort asc')->where('status', 1)->select();
|
||||
View::assign('list_nav_friend_url', $list_nav_friend_url);
|
||||
|
||||
if (!empty($this->indexTplMethod)) {
|
||||
if (method_exists($this, $this->indexTplMethod)) {
|
||||
$this->{$this->indexTplMethod}();
|
||||
}
|
||||
}
|
||||
if (!empty($this->indexTplMethodCurrentAction)) {
|
||||
if (method_exists($this, $this->indexTplMethodCurrentAction)) {
|
||||
$this->{$this->indexTplMethodCurrentAction}();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function __blog()
|
||||
{
|
||||
$list_header_nav = Nav::where('type', 'blog_header_nav')->order('sort asc')->where('status', 1)->select();
|
||||
View::assign('list_header_nav', $list_header_nav);
|
||||
}
|
||||
|
||||
public function __documents()
|
||||
{
|
||||
$list_header_nav = Nav::where('type', 'document_header_nav')->order('sort asc')->where('status', 1)->select();
|
||||
View::assign('list_header_nav', $list_header_nav);
|
||||
}
|
||||
|
||||
public function __easyBlue()
|
||||
{
|
||||
$list_header_nav = Nav::where('type', 10)->order('sort asc')->where('status', 1)->select();
|
||||
View::assign('list_header_nav', $list_header_nav);
|
||||
$list_nav_index_block_1 = Nav::where('type', 6)->order('sort asc')->where('status', 1)->select();
|
||||
View::assign('list_nav_index_block_1', $list_nav_index_block_1);
|
||||
$list_nav_index_block_2 = Nav::where('type', 7)->order('sort asc')->where('status', 1)->select();
|
||||
View::assign('list_nav_index_block_2', $list_nav_index_block_2);
|
||||
}
|
||||
|
||||
public function __articles()
|
||||
{
|
||||
$list_header_nav = Nav::where('type', 11)->order('sort asc')->where('status', 1)->select();
|
||||
View::assign('list_header_nav', $list_header_nav);
|
||||
|
||||
$list_category_first_level = Category::where('level', 1)->where('status', 1)->where('type',3)->select();
|
||||
$this->assign('list_category_first_level', $list_category_first_level);
|
||||
$list_nav_more = Nav::where('type', 8)->order('sort asc')->where('status', 1)->where('type',11)->select();
|
||||
View::assign('list_nav_more', $list_nav_more);
|
||||
|
||||
$top_posts = Post::where('is_top',1)->limit(8)->where('type',3)->select();
|
||||
$this->assign('top_posts',$top_posts);
|
||||
|
||||
}
|
||||
}
|
||||
162
app/index/controller/Index.php
Normal file
162
app/index/controller/Index.php
Normal file
@@ -0,0 +1,162 @@
|
||||
<?php
|
||||
|
||||
namespace app\index\controller;
|
||||
|
||||
use app\model\Category;
|
||||
use app\model\Nav;
|
||||
use app\model\Post;
|
||||
use app\model\PostCategory;
|
||||
use think\Request;
|
||||
|
||||
class Index extends Common
|
||||
{
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function __blogIndex()
|
||||
{
|
||||
$list_category = Category::where('type','blog_post')->select();
|
||||
|
||||
$this->assign('list_category',$list_category);
|
||||
|
||||
$category_id = $this->request->param('category_id');
|
||||
|
||||
if(!empty($category_id)){
|
||||
|
||||
$model_list_post = Post::hasWhere('categorys',['category_id'=>$category_id])->order('sort desc');
|
||||
}else{
|
||||
|
||||
$model_list_post = Post::order('sort desc');
|
||||
}
|
||||
|
||||
$model_list_post->where('type','blog_post');
|
||||
|
||||
$list_post = $model_list_post->paginate();
|
||||
|
||||
$this->assign('list_post',$list_post);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function __documentsIndex()
|
||||
{
|
||||
$list_index_documents_nav = Nav::where('type',9)->select();
|
||||
|
||||
$this->assign('list_index_documents_nav',$list_index_documents_nav);
|
||||
}
|
||||
|
||||
public function __articlesIndex()
|
||||
{
|
||||
|
||||
$sub_category = [];
|
||||
|
||||
if(!empty($this->request->param('category_id'))){
|
||||
$sub_category = Category::where('pid',$this->request->param('category_id'))->where('type',3)->select();
|
||||
|
||||
if(empty($this->request->param('sub_category_id'))){
|
||||
$categorys = [$this->request->param('category_id')];
|
||||
|
||||
$categorys = array_merge($categorys,array_column((array)Category::getListLevel($this->request->param('category_id')),3));
|
||||
|
||||
$categorys_where = PostCategory::whereIn('category_id',$categorys);
|
||||
|
||||
$model_post = Post::hasWhere('categorys',$categorys_where)->where('status',1)->order('id desc');
|
||||
}else{
|
||||
$model_post = Post::hasWhere('categorys',['category_id'=>$this->request->param('sub_category_id')])->where('status',1)->order('id desc');
|
||||
|
||||
}
|
||||
}else{
|
||||
|
||||
$model_post = Post::where('status',1)->order('id desc');
|
||||
}
|
||||
|
||||
$model_post->where('type',3);
|
||||
|
||||
$keywords = $this->request->param('keywords');
|
||||
|
||||
if(!empty($keywords)){
|
||||
$model_post->whereLike('title|desc',"%$keywords%");
|
||||
}
|
||||
|
||||
$list_post = $model_post->paginate();
|
||||
|
||||
$this->assign('sub_category',$sub_category);
|
||||
|
||||
$this->assign('list_post',$list_post);
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示创建资源表单页.
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function save(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示指定的资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function read($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存更新的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
106
app/index/controller/Post.php
Normal file
106
app/index/controller/Post.php
Normal file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\index\controller;
|
||||
|
||||
use app\model\Post as ModelPost;
|
||||
use think\Request;
|
||||
|
||||
class Post extends Common
|
||||
{
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示创建资源表单页.
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function save(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示指定的资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function read($id)
|
||||
{
|
||||
//
|
||||
|
||||
$model_post = ModelPost::find($id);
|
||||
|
||||
$this->assign('post', $model_post);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function __documentsRead()
|
||||
{
|
||||
$category_id = $this->request->param('category_id',0);
|
||||
|
||||
$list_post = [];
|
||||
if(!empty($category_id)){
|
||||
$list_post = ModelPost::hasWhere('categorys',['category_id'=>$category_id])->order('sort desc')->select();
|
||||
}
|
||||
|
||||
$this->assign('list_post',$list_post);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存更新的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
16
app/middleware.php
Normal file
16
app/middleware.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
// 全局跨域
|
||||
\think\middleware\AllowCrossDomain::class,
|
||||
// 全局请求缓存
|
||||
// \think\middleware\CheckRequestCache::class,
|
||||
// 多语言加载
|
||||
// \think\middleware\LoadLangPack::class,
|
||||
// Session初始化
|
||||
\think\middleware\SessionInit::class,
|
||||
// 页面Trace调试
|
||||
// \think\middleware\TraceDebug::class,
|
||||
|
||||
'\app\\middleware\ConfigInit'
|
||||
];
|
||||
41
app/middleware/AdminLog.php
Normal file
41
app/middleware/AdminLog.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace app\middleware;
|
||||
|
||||
use app\model\AdminLog as AppAdminLog;
|
||||
use app\model\AdminPermission;
|
||||
use app\Request;
|
||||
use think\Collection;
|
||||
use think\facade\Cache;
|
||||
|
||||
class AdminLog
|
||||
{
|
||||
public function handle(Request $request, \Closure $next)
|
||||
{
|
||||
$logged_admin_permission = Cache::get('logged_admin_permission');
|
||||
|
||||
if(empty($logged_admin_permission)){
|
||||
$logged_admin_permission = new Collection(AdminPermission::where('is_log',1)->select());
|
||||
}
|
||||
|
||||
|
||||
$is_exit = $logged_admin_permission->where('app',app('http')->getName())
|
||||
->where('controller',$request->controller())
|
||||
->where('action',$request->action());
|
||||
|
||||
if(!$is_exit->isEmpty()){
|
||||
AppAdminLog::create([
|
||||
'app'=>app('http')->getName(),
|
||||
'controller'=>$request->controller(),
|
||||
'action'=>$request->action(),
|
||||
'param'=>$request->param(),
|
||||
'create_time'=>time(),
|
||||
'admin_id'=>$request->session('admin_id','0'),
|
||||
'ip'=>$request->ip()
|
||||
]);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
|
||||
}
|
||||
}
|
||||
32
app/middleware/ConfigInit.php
Normal file
32
app/middleware/ConfigInit.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace app\middleware;
|
||||
|
||||
use think\facade\Db;
|
||||
use think\facade\Config;
|
||||
use think\helper\Arr;
|
||||
|
||||
class ConfigInit
|
||||
{
|
||||
public function handle($request, \Closure $next)
|
||||
{
|
||||
|
||||
//设置存储
|
||||
$filesystem_config = Config::get('filesystem');
|
||||
Arr::set($filesystem_config,'default','public');
|
||||
|
||||
Config::set($filesystem_config, 'filesystem');
|
||||
|
||||
// 社微信开放平台
|
||||
// $wx_open_app = [];
|
||||
// $wx_open_app = Arr::add($wx_open_app,'app_id',get_system_config('wx_open_app_id'));
|
||||
// $wx_open_app = Arr::add($wx_open_app,'secret',get_system_config('wx_open_app_secret'));
|
||||
// $wx_open_app = Arr::add($wx_open_app,'token',get_system_config('wx_open_app_token'));
|
||||
// $wx_open_app = Arr::add($wx_open_app,'aes_key',get_system_config('wx_open_app_aes_key'));
|
||||
|
||||
// Config::set($wx_open_app,'wx_open_app');
|
||||
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
15
app/middleware/PermissionRecord.php
Normal file
15
app/middleware/PermissionRecord.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace app\middleware;
|
||||
|
||||
use app\model\AdminPermission;
|
||||
use app\Request;
|
||||
|
||||
class PermissionRecord
|
||||
{
|
||||
public function handle(Request $request, \Closure $next)
|
||||
{
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
33
app/model/Admin.php
Normal file
33
app/model/Admin.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* @mixin think\Model
|
||||
*/
|
||||
class Admin extends Model
|
||||
{
|
||||
//
|
||||
|
||||
public function getAvatarAttr($value)
|
||||
{
|
||||
|
||||
if(empty($value)){
|
||||
return '/static/images/avatar.jpeg';
|
||||
}
|
||||
|
||||
return \get_source_link($value);
|
||||
}
|
||||
|
||||
public function getGroupAttr()
|
||||
{
|
||||
if(empty($this->getData('group_id'))){
|
||||
return [];
|
||||
}
|
||||
|
||||
return AdminGroup::where('id',$this->getData('group_id'))->cache(60)->find();
|
||||
}
|
||||
|
||||
}
|
||||
32
app/model/AdminGroup.php
Normal file
32
app/model/AdminGroup.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use think\Model;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
/**
|
||||
* @mixin think\Model
|
||||
*/
|
||||
class AdminGroup extends Model
|
||||
{
|
||||
//
|
||||
use SoftDelete;
|
||||
protected $defaultSoftDelete = 0;
|
||||
|
||||
public function getPermissionsAttr($value)
|
||||
{
|
||||
return \explode(',',$value);
|
||||
}
|
||||
|
||||
public function setPermissionsAttr($value)
|
||||
{
|
||||
|
||||
if(is_array($value)){
|
||||
return join(',',$value);
|
||||
}
|
||||
|
||||
return $value;
|
||||
|
||||
}
|
||||
}
|
||||
23
app/model/AdminLog.php
Normal file
23
app/model/AdminLog.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use think\Model;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
/**
|
||||
* @mixin think\Model
|
||||
*/
|
||||
class AdminLog extends Model
|
||||
{
|
||||
//
|
||||
use SoftDelete;
|
||||
protected $defaultSoftDelete = 0;
|
||||
|
||||
public function admin()
|
||||
{
|
||||
return $this->belongsTo('Admin','admin_id');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
26
app/model/AdminPermission.php
Normal file
26
app/model/AdminPermission.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 权限表
|
||||
* @mixin think\Model
|
||||
*/
|
||||
class AdminPermission extends Model
|
||||
{
|
||||
//
|
||||
|
||||
public function getIsLogAttr($value)
|
||||
{
|
||||
$status = [
|
||||
0=>'不记录',
|
||||
1=>'记录',
|
||||
];
|
||||
|
||||
return $status[intval($value)];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
131
app/model/Category.php
Normal file
131
app/model/Category.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use think\facade\Config;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* @mixin think\Model
|
||||
*/
|
||||
class Category extends Model
|
||||
{
|
||||
//
|
||||
|
||||
public static $allCategory = [];
|
||||
|
||||
|
||||
/**
|
||||
* 获取指定id下的所有分类
|
||||
*
|
||||
* @param string $id
|
||||
* @return void
|
||||
*/
|
||||
public static function getListLevel($id = '',$type = 1)
|
||||
{
|
||||
|
||||
if(empty(self::$allCategory)){
|
||||
|
||||
$model_list = Category::where('type',$type)->select();
|
||||
self::$allCategory = array2level($model_list,0,0);
|
||||
}
|
||||
|
||||
if(!empty($id)){
|
||||
$list = [];
|
||||
$in_category = [$id];
|
||||
foreach (self::$allCategory as $category) {
|
||||
if(in_array($category->pid,$in_category)){
|
||||
$list[] = $category;
|
||||
$in_category[] = $category->id;
|
||||
}
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
return self::$allCategory;
|
||||
}
|
||||
|
||||
|
||||
public function getTitleImgAttr($value)
|
||||
{
|
||||
|
||||
return get_source_link($value);
|
||||
}
|
||||
|
||||
public function posts()
|
||||
{
|
||||
return $this->hasMany(PostCategory::class,'category_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回的对应的post的模型
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getPostsModelListAttr()
|
||||
{
|
||||
$list_post_category = $this->getAttr('posts');
|
||||
|
||||
$list_post = [];
|
||||
|
||||
foreach ($list_post_category as $list_post_category) {
|
||||
array_push($list_post,$list_post_category->post);
|
||||
}
|
||||
|
||||
return $list_post;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回的对应post的数据,性能比模型要高.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getPostsListAttr()
|
||||
{
|
||||
$list_post_category = $this->getAttr('posts');
|
||||
|
||||
$list_post = array_column($list_post_category->append(['post'])->toArray(),'post');
|
||||
|
||||
return $list_post;
|
||||
}
|
||||
|
||||
public function getTplNameAttr($value)
|
||||
{
|
||||
return Config::get('view_type.category.'.$value);
|
||||
}
|
||||
|
||||
public function getModelParentAttr()
|
||||
{
|
||||
$pid = $this->getData('pid');
|
||||
|
||||
if($pid == 0){
|
||||
return $this;
|
||||
}
|
||||
return Category::where('id',$pid)->find();
|
||||
}
|
||||
|
||||
// 返回除自身以外的其他的同级同类的分类
|
||||
public function getModelSiblingsAttr()
|
||||
{
|
||||
return Category::where('pid',$this->getData('pid'))
|
||||
->where('level',$this->getData('level'))
|
||||
->where('id','<>',$this->getData('id'))
|
||||
->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取同一个父元素的分类,包含自身
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getModelSameParentAttr()
|
||||
{
|
||||
return Category::where('pid',$this->getData('pid'))
|
||||
->where('level',$this->getData('level'))
|
||||
->select();
|
||||
}
|
||||
|
||||
}
|
||||
29
app/model/Nav.php
Normal file
29
app/model/Nav.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* @mixin think\Model
|
||||
*/
|
||||
class Nav extends Model
|
||||
{
|
||||
|
||||
public static $statusName = [
|
||||
0=>'不显示',
|
||||
1=>'显示'
|
||||
];
|
||||
//
|
||||
public function getImgAttr($value)
|
||||
{
|
||||
return get_source_link($value);
|
||||
}
|
||||
|
||||
public function getStatusNameAttr()
|
||||
{
|
||||
return self::$statusName[$this->getData('status')];
|
||||
}
|
||||
}
|
||||
133
app/model/Post.php
Normal file
133
app/model/Post.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use think\Model;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
/**
|
||||
* @mixin think\Model
|
||||
*/
|
||||
class Post extends Model
|
||||
{
|
||||
//
|
||||
|
||||
public static $stausNameList = [
|
||||
0=>'不发布',
|
||||
1=>'发布'
|
||||
];
|
||||
|
||||
use SoftDelete;
|
||||
|
||||
protected $defaultSoftDelete = 0;
|
||||
|
||||
public function categorys()
|
||||
{
|
||||
return $this->hasMany(PostCategory::class,'post_id');
|
||||
}
|
||||
|
||||
public function tags()
|
||||
{
|
||||
return $this->hasMany(PostTag::class,'post_id');
|
||||
}
|
||||
|
||||
public function setPublishTimeAttr($value)
|
||||
{
|
||||
return strtotime($value);
|
||||
}
|
||||
public function getPublishTimeTextAttr()
|
||||
{
|
||||
|
||||
$value = $this->getData('publish_time');
|
||||
return date('Y-m-d',$value);
|
||||
}
|
||||
|
||||
public function getCategorysListAttr()
|
||||
{
|
||||
$list_post_categorys = $this->getAttr('categorys');
|
||||
|
||||
$list = array_column($list_post_categorys->append(['category'])->toArray(),'category');
|
||||
|
||||
$list = array2level($list,0,0);
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function getTagsListAttr()
|
||||
{
|
||||
$list_post_tags = $this->getAttr('tags');
|
||||
|
||||
$list = array_column($list_post_tags->append(['tag'])->toArray(),'tag');
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function getDescShortAttr()
|
||||
{
|
||||
$desc = $this->getData('desc');
|
||||
|
||||
if(strlen($desc) > 100){
|
||||
$desc = mb_substr($desc,0,100).'...';
|
||||
}
|
||||
|
||||
return $desc;
|
||||
}
|
||||
|
||||
public function getDescListAttr()
|
||||
{
|
||||
$desc = $this->getData('desc');
|
||||
|
||||
if(empty($desc)){
|
||||
return '';
|
||||
}
|
||||
$list = explode("\n", $desc);
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function getDescHtmlAttr()
|
||||
{
|
||||
$desc = $this->getData('desc');
|
||||
|
||||
if(empty($desc)){
|
||||
return '';
|
||||
}
|
||||
|
||||
return str_replace("\n",'<br>',$desc);
|
||||
}
|
||||
|
||||
public function getStatusNameAttr()
|
||||
{
|
||||
return self::$stausNameList[$this->getData('status')];
|
||||
}
|
||||
|
||||
public function setPubishTimeAttr($value)
|
||||
{
|
||||
return strtotime($value);
|
||||
}
|
||||
|
||||
public function setContentAttr($value)
|
||||
{
|
||||
return json_encode($value);
|
||||
}
|
||||
public function setContentHtmlAttr($value)
|
||||
{
|
||||
return trim($value);
|
||||
}
|
||||
|
||||
public function getContentAttr($value)
|
||||
{
|
||||
return json_decode($value,true);
|
||||
}
|
||||
|
||||
public function getPosterAttr($value)
|
||||
{
|
||||
if(empty($value)){
|
||||
$value = '/static/images/avatar.jpeg';
|
||||
}
|
||||
|
||||
return get_source_link($value);
|
||||
}
|
||||
}
|
||||
24
app/model/PostCategory.php
Normal file
24
app/model/PostCategory.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* @mixin think\Model
|
||||
*/
|
||||
class PostCategory extends Model
|
||||
{
|
||||
//
|
||||
public function post()
|
||||
{
|
||||
return $this->belongsTo(Post::class, 'post_id');
|
||||
}
|
||||
|
||||
public function category()
|
||||
{
|
||||
return $this->belongsTo(Category::class,'category_id');
|
||||
}
|
||||
}
|
||||
24
app/model/PostTag.php
Normal file
24
app/model/PostTag.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* @mixin think\Model
|
||||
*/
|
||||
class PostTag extends Model
|
||||
{
|
||||
//
|
||||
public function tag()
|
||||
{
|
||||
return $this->belongsTo(Tag::class,'tag_id');
|
||||
}
|
||||
|
||||
public function post()
|
||||
{
|
||||
return $this->belongsTo(Post::class, 'post_id');
|
||||
}
|
||||
}
|
||||
14
app/model/SystemConfig.php
Normal file
14
app/model/SystemConfig.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* @mixin think\Model
|
||||
*/
|
||||
class SystemConfig extends Model
|
||||
{
|
||||
//
|
||||
|
||||
}
|
||||
16
app/model/Tag.php
Normal file
16
app/model/Tag.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* @mixin think\Model
|
||||
*/
|
||||
class Tag extends Model
|
||||
{
|
||||
//
|
||||
|
||||
}
|
||||
77
app/model/UploadFiles.php
Normal file
77
app/model/UploadFiles.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use think\Model;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
/**
|
||||
* @mixin think\Model
|
||||
*/
|
||||
class UploadFiles extends Model
|
||||
{
|
||||
//
|
||||
use SoftDelete;
|
||||
|
||||
protected $defaultSoftDelete = 0;
|
||||
|
||||
public function getSrcAttr()
|
||||
{
|
||||
return \get_source_link($this->getData('save_name'));
|
||||
}
|
||||
|
||||
public function getTypeAttr($value)
|
||||
{
|
||||
return \config('upload_type.'.$value);
|
||||
}
|
||||
|
||||
public function getUsedTimeAttr($value)
|
||||
{
|
||||
if($value == 0){
|
||||
return '未使用';
|
||||
}
|
||||
|
||||
return date('Y-m-d H:i:s',$value);
|
||||
}
|
||||
public function getDeleteTimeAttr($value)
|
||||
{
|
||||
if($value == 0){
|
||||
return '未删除';
|
||||
}
|
||||
|
||||
return date('Y-m-d H:i:s',$value);
|
||||
}
|
||||
public function getClearTimeAttr($value)
|
||||
{
|
||||
if($value == 0){
|
||||
return '未清除';
|
||||
}
|
||||
|
||||
return date('Y-m-d H:i:s',$value);
|
||||
}
|
||||
|
||||
public function getStatusAttr($value,$data)
|
||||
{
|
||||
if($data['used_time'] == 0){
|
||||
return '未使用(仅供预览)';
|
||||
}
|
||||
|
||||
if($data['delete_time'] > 0){
|
||||
return '已删除';
|
||||
}
|
||||
|
||||
if($data['clear_time'] > 0){
|
||||
return '已清除';
|
||||
}
|
||||
|
||||
return '使用中';
|
||||
|
||||
}
|
||||
|
||||
public function getFileSizeAttr($value)
|
||||
{
|
||||
return format_size($value);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
27
app/model/User.php
Normal file
27
app/model/User.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use think\Model;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
/**
|
||||
* @mixin think\Model
|
||||
*/
|
||||
class User extends Model
|
||||
{
|
||||
//
|
||||
|
||||
use SoftDelete;
|
||||
|
||||
protected $defaultSoftDelete = 0;
|
||||
|
||||
public function getAvatarAttr($value)
|
||||
{
|
||||
if(empty($value)){
|
||||
return '/static/images/avatar.jpeg';
|
||||
}
|
||||
|
||||
return \get_source_link($value);
|
||||
}
|
||||
}
|
||||
23
app/model/WxPublicAccount.php
Normal file
23
app/model/WxPublicAccount.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
|
||||
/**
|
||||
* @mixin think\Model
|
||||
*/
|
||||
class WxPublicAccount extends Model
|
||||
{
|
||||
//
|
||||
public function getHeadImgAttr($value)
|
||||
{
|
||||
return get_source_link($value);
|
||||
}
|
||||
|
||||
public function getQrcodeUrlAttr($value)
|
||||
{
|
||||
return \get_source_link($value);
|
||||
}
|
||||
}
|
||||
19
app/provider.php
Normal file
19
app/provider.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
use app\ExceptionHandle;
|
||||
use app\Request;
|
||||
|
||||
// 容器Provider定义文件
|
||||
return [
|
||||
'think\Request' => Request::class,
|
||||
'think\exception\Handle' => ExceptionHandle::class,
|
||||
];
|
||||
Reference in New Issue
Block a user