第一个版本1.0.0发布

This commit is contained in:
toogee 2020-01-01 13:17:19 +08:00
parent 0b6baac0cb
commit b15b55e1e9
1256 changed files with 129910 additions and 45 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
/.idea
/.vscode
*.log
.env

42
.travis.yml Normal file
View File

@ -0,0 +1,42 @@
sudo: false
language: php
branches:
only:
- stable
cache:
directories:
- $HOME/.composer/cache
before_install:
- composer self-update
install:
- composer install --no-dev --no-interaction --ignore-platform-reqs
- zip -r --exclude='*.git*' --exclude='*.zip' --exclude='*.travis.yml' ThinkPHP_Core.zip .
- composer require --update-no-dev --no-interaction "topthink/think-image:^1.0"
- composer require --update-no-dev --no-interaction "topthink/think-migration:^1.0"
- composer require --update-no-dev --no-interaction "topthink/think-captcha:^1.0"
- composer require --update-no-dev --no-interaction "topthink/think-mongo:^1.0"
- composer require --update-no-dev --no-interaction "topthink/think-worker:^1.0"
- composer require --update-no-dev --no-interaction "topthink/think-helper:^1.0"
- composer require --update-no-dev --no-interaction "topthink/think-queue:^1.0"
- composer require --update-no-dev --no-interaction "topthink/think-angular:^1.0"
- composer require --dev --update-no-dev --no-interaction "topthink/think-testing:^1.0"
- zip -r --exclude='*.git*' --exclude='*.zip' --exclude='*.travis.yml' ThinkPHP_Full.zip .
script:
- php think unit
deploy:
provider: releases
api_key:
secure: TSF6bnl2JYN72UQOORAJYL+CqIryP2gHVKt6grfveQ7d9rleAEoxlq6PWxbvTI4jZ5nrPpUcBUpWIJHNgVcs+bzLFtyh5THaLqm39uCgBbrW7M8rI26L8sBh/6nsdtGgdeQrO/cLu31QoTzbwuz1WfAVoCdCkOSZeXyT/CclH99qV6RYyQYqaD2wpRjrhA5O4fSsEkiPVuk0GaOogFlrQHx+C+lHnf6pa1KxEoN1A0UxxVfGX6K4y5g4WQDO5zT4bLeubkWOXK0G51XSvACDOZVIyLdjApaOFTwamPcD3S1tfvuxRWWvsCD5ljFvb2kSmx5BIBNwN80MzuBmrGIC27XLGOxyMerwKxB6DskNUO9PflKHDPI61DRq0FTy1fv70SFMSiAtUv9aJRT41NQh9iJJ0vC8dl+xcxrWIjU1GG6+l/ZcRqVx9V1VuGQsLKndGhja7SQ+X1slHl76fRq223sMOql7MFCd0vvvxVQ2V39CcFKao/LB1aPH3VhODDEyxwx6aXoTznvC/QPepgWsHOWQzKj9ftsgDbsNiyFlXL4cu8DWUty6rQy8zT2b4O8b1xjcwSUCsy+auEjBamzQkMJFNlZAIUrukL/NbUhQU37TAbwsFyz7X0E/u/VMle/nBCNAzgkMwAUjiHM6FqrKKBRWFbPrSIixjfjkCnrMEPw=
file:
- ThinkPHP_Core.zip
- ThinkPHP_Full.zip
skip_cleanup: true
on:
tags: true

View File

@ -1,36 +0,0 @@
# TaoLer
#### Description
TaoLer社区系统thinkphp6+layui+fly php框架
#### Software Architecture
Software architecture description
#### Installation
1. xxxx
2. xxxx
3. xxxx
#### Instructions
1. xxxx
2. xxxx
3. xxxx
#### Contribution
1. Fork the repository
2. Create Feat_xxx branch
3. Commit your code
4. Create Pull Request
#### Gitee Feature
1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
2. Gitee blog [blog.gitee.com](https://blog.gitee.com)
3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
4. The most valuable open source project [GVP](https://gitee.com/gvp)
5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)

View File

@ -1,23 +1,29 @@
# TaoLer # TaoLer 1.0.0
TaoLer 1.0 2020.1.1
#### 介绍 #### 介绍
TaoLer社区系统thinkphp6+layui+fly php框架 TaoLer社区系统thinkphp6+layui+fly php框架
#### 软件架构 #### 软件架构
软件架构说明 软件架构说明
ThinkPHP6核心框架layui前端Fly模板。
#### 安装教程 #### 安装教程
1. xxxx 1. git地址 https://gitee.com/toogee/TaoLer/repository/archive/master.zip
2. xxxx 2. 官网下载 http://www.aieok.com
3. xxxx 3. 解压后项目域名部署为public对外访问http:://www.youdomain.com/install/index
4. 安装前需要准保好建立数据库信息(数据库连接地址,数据库用户名,数据库密码,数据库端口,数据库名称)
5. 安装过程注意记录好设置后台的用户名和密码。
#### 使用说明 #### 使用说明
1. xxxx 1. 安装后本系统已配置默认演示数据,可以删除原数据或者进行数据的修改
2. xxxx 2. 后台可设置分类cate,一定要设置英文别名
3. xxxx 3. 首页有置顶模块,列表文章模块,右侧包含广告模块,回复展示模块
#### 文档
1. 参考官网分享文章
#### 参与贡献 #### 参与贡献
@ -26,6 +32,16 @@ TaoLer社区系统thinkphp6+layui+fly php框架
3. 提交代码 3. 提交代码
4. 新建 Pull Request 4. 新建 Pull Request
#### 版权信息
非商业可免费使用,没有功能限制,但不能更改版本信息,如需更改可购买授权。
本项目包含的第三方源码和二进制文件之版权信息另行标注。
版权所有Copyright © 2019 by aieok.com (http://www.aieok.com)
All rights reserved。
#### 码云特技 #### 码云特技

2
app/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/api
/home

1
app/.htaccess Normal file
View File

@ -0,0 +1 @@
deny from all

94
app/BaseController.php Normal file
View File

@ -0,0 +1,94 @@
<?php
declare (strict_types = 1);
namespace app;
use think\App;
use think\exception\ValidateException;
use think\Validate;
/**
* 控制器基础类
*/
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);
}
}

58
app/ExceptionHandle.php Normal file
View File

@ -0,0 +1,58 @@
<?php
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);
}
}

8
app/Request.php Normal file
View File

@ -0,0 +1,8 @@
<?php
namespace app;
// 应用请求对象类
class Request extends \think\Request
{
}

2
app/admin/controller/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
KeyAuth.php
Version.php

View File

@ -0,0 +1,188 @@
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2019-10-15
* Time: 15:40
*/
namespace app\admin\controller;
use app\common\controller\AdminController;
use app\admin\validate\Admin as AdminValidate;
use app\admin\model\Admin as AdminModel;
use think\facade\View;
use think\facade\Request;
use think\facade\Db;
use think\facade\Session;
use think\exception\ValidateException;
use app\common\model\User as UserModel;
class Admin extends AdminController
{
//管理员
public function adminList()
{
if(Request::isAjax()){
$admins = Db::name('admin')
->alias('a')
->join('auth_group u','a.auth_group_id = u.id')
->field('a.id as aid,username,mobile,email,title,last_login_ip,a.status as astatus,last_login_time')
->where('a.delete_time',0)
->select();
$count = $admins->count();
if($admins){
$res = ['code'=>0,'msg'=>'','count'=>$count];
foreach($admins as $k => $v){
$data = ['id'=>$v['aid'],'loginname'=>$v['username'],'telphone'=>$v['mobile'],'email'=>$v['email'],'role'=>$v['title'],'ip'=>$v['last_login_ip'],'check'=>$v['astatus'],'logintime'=>date("Y-m-d",$v['last_login_time'])];
$res['data'][] = $data;
}
}
return json($res);
}
return View::fetch('list');
}
//管理员审核
public function adminCheck()
{
$data = Request::param();
//获取状态
$res = Db::name('admin')->where('id',$data['id'])->save(['status' => $data['status']]);
if($res){
if($data['status'] == 1){
return json(['code'=>0,'msg'=>'设置管理员通过','icon'=>6]);
} else {
return json(['code'=>0,'msg'=>'管理员已取消','icon'=>5]);
}
}else {
return json(['code'=>1,'msg'=>'审核出错']);
}
}
//添加管理员
public function adminForm()
{
if(Request::isAjax()){
$data = Request::param();
$data['create_time'] = time();
$salt = substr(md5($data['create_time']),-6);
$data['password'] = substr_replace(md5($data['password']),$salt,0,6);
$result = Db::name('admin')->save($data);
Db::name('auth_group_access')->save(['uid'=>$data['id'],'group_id'=>$data['auth_group_id']]);
if($result){
$res = ['code'=>1,'msg'=>'添加成功'];
}else{
$res = ['code'=>0,'msg'=>'添加失败'];
}
return json($res);
}
$auth_group = Db::name('auth_group')->select();
View::assign(['auth_group'=>$auth_group]);
return View::fetch('adminform');
}
//管理员编辑
public function adminEdit()
{
$admin = AdminModel::find(input('id'));
if(Request::isAjax()){
$data = Request::param();
if(empty($data['password'])){
unset($data['password']);
} else {
$t = strtotime($admin['create_time']);
$salt = substr(md5($t),-6);
$data['password'] = md5(substr_replace(md5($data['password']),$salt,0,6));
}
$data['update_time'] = time();
$result = $admin->update($data);
Db::name('auth_group_access')->where('uid',$data['id'])->update(['group_id'=>$data['auth_group_id']]);
if($result){
$res = ['code'=>1,'msg'=>'编辑成功'];
}else{
$res = ['code'=>0,'msg'=>'编辑失败'];
}
return json($res);
}
$auth_group = Db::name('auth_group')->select();
View::assign(['admin'=>$admin,'auth_group'=>$auth_group]);
return View::fetch();
}
//删除管理员
public function delete($id)
{
if(Request::isAjax()){
$user =AdminModel::find($id);
$result = $user->delete();
if($result){
return json(['code'=>1,'msg'=>'删除成功']);
}else{
return json(['code'=>0,'msg'=>'删除失败']);
}
}
}
public function info()
{
$admin = AdminModel::find(Session::get('admin_id'));
if(Request::isAjax()){
$data = Request::param();
$result = $admin->update($data);
if($result){
$res = ['code'=>0,'msg'=>'更新成功'];
} else {
$res = ['code'=>1,'msg'=>'更新失败'];
}
return json($res);
}
View::assign('admin',$admin);
return View::fetch('set/user/info');
}
/**
* 显示指定的资源
*
* @param int $id
* @return \think\Response
*/
public function repass()
{
//
$admin = AdminModel::find(Session::get('admin_id'));
if(Request::isAjax()){
$data = Request::param();
$salt = substr(md5(strtotime($admin['create_time'])),-6);
$pwd = substr_replace(md5($data['oldPassword']),$salt,0,6);
$data['oldPassword'] = md5($pwd);
if($admin['password'] != $data['oldPassword']){
$res = ['code'=>1,'msg'=>'当前密码错误'];
} elseif($data['password'] != $data['repassword']){
$res = ['code'=>1,'msg'=>'两次密码不一致'];
} else {
$password = md5(substr_replace(md5($data['password']),$salt,0,6));
$result = $admin->update([
'id' => $admin['id'],
'password' => $password
]);
if($result){
$res = ['code'=>0,'msg'=>'更新成功'];
} else {
$res = ['code'=>1,'msg'=>'更新失败'];
}
}
return json($res);
}
View::assign('admin',$admin);
return View::fetch('set/user/repass');
}
}

View File

@ -0,0 +1,107 @@
<?php
namespace app\admin\controller;
use app\common\controller\AdminController;
use app\admin\validate\Admin;
use app\admin\model\Admin as adminModel;
use think\facade\View;
use think\facade\Request;
use think\facade\Db;
use think\exception\ValidateException;
use app\admin\model\AuthGroup as AuthGroupModel;
use app\admin\model\AuthRule as AuthRuleModel;
class AuthGroup extends AdminController
{
/**
protected function initialize()
{
parent::initialize();
}
*/
//角色
public function list()
{
if(Request::isAjax()){
$role = Db::name('auth_group')->select();
$count = $role->count();
$res = [];
if($role){
$res = ['code'=>0,'msg'=>'','count'=>$count];
foreach($role as $k => $v){
$data = ['id'=>$v['id'],'rolename'=>$v['title'],'limits'=>$v['limits'],'descr'=>$v['descr'],'check'=>$v['status']];
$res['data'][] = $data;
}
}
return json($res);
}
return View::fetch('role');
}
//角色管理
public function role()
{
//
return View::fetch('role');
}
//角色添加
public function roleAdd()
{
if(Request::isAjax()){
$data = Request::param();
$result = AuthGroupModel::create($data);
if($result) {
$res = ['code'=>1,'msg'=>'添加成功'];
} else {
$res = ['code'=>0,'msg'=>'添加失败'];
}
return json($res);
}
$menus = $this->getMenus();
View::assign('menus',$menus);
return View::fetch('roleadd');
}
//角色编辑
public function roleEdit()
{
if(Request::isAjax()){
$data = Request::param();
/*
if(!strpos($data['rules'],'1,2,3,4,5'))
{
$data['rules'] = substr_replace($data['rules'],"1,2,3,4,5,",0,0);
}
*/
$rule = AuthGroupModel::update($data);
if($rule){
$res = ['code'=>1,'msg'=>'保存成功'];
} else {
$res = ['code'=>1,'msg'=>'保存成功'];
}
return json($res);
}
$menus = $this->getMenus();
View::assign('menus',$menus);
$authGroup = AuthGroupModel::select();
$auth = AuthGroupModel::find(input('id'));
$ru = $auth->rules;
View::assign(['authGroup'=>$authGroup,'auth'=>$auth,'ru'=>$ru]);
return View::fetch('roleedit');
}
}

View File

@ -0,0 +1,169 @@
<?php
namespace app\admin\controller;
use app\common\controller\AdminController;
use think\facade\Request;
use think\facade\Db;
use think\facade\View;
use app\admin\model\AuthRule as AuthRuleModel;
class AuthRule extends AdminController
{
//权限列表
public function index()
{
//获取权限列表
if(Request::isAjax()){
$rule = new AuthRuleModel();
$auth_rules = $rule->authRuleTree();
$count = count($auth_rules);
$res = [];
if($auth_rules){
$res = ['code'=>0,'msg'=>'','count'=>$count];
foreach($auth_rules as $k => $v){
//$data = $v->getData();
$data = ['id'=>$v['id'],'sort'=>$v['sort'],'title'=>str_repeat('---',$v['level']*2).$v['title'],'name'=>$v['name'],'icon'=>$v['icon'],'status'=>$v['status'],'level'=>$v['level']+1,'ishidden'=>$v['ishidden']];
$res['data'][] = $data;
}
}
return json($res);
}
return View::fetch();
}
//添加权限
public function add()
{
//
if(Request::isAjax()){
$data = Request::param();
//halt($data);
$plevel = Db::name('auth_rule')->field('level')->find($data['pid']);
if($plevel){
$data['level'] = $plevel['level']+1;
} else {
$data['level'] = 0;
}
$list = Db::name('auth_rule')->save($data);
if($list){
return json(['code'=>0,'msg'=>'添加权限成功']);
}else{
return json(['code'=>-1,'msg'=>'添加权限失败']);
}
}
$rule = new AuthRuleModel();
$auth_rules = $rule->authRuleTree();
View::assign('AuthRule',$auth_rules);
return View::fetch();
}
//权限编辑
public function edit()
{
$rule = new AuthRuleModel();
if(Request::isAjax()){
$data = Request::param();
$ruId = $rule->find($data['pid']); //查询出上级ID
if($ruId){
$plevel = $ruId->level; //上级level等级
$data['level'] = $plevel+1;
} else {
$data['level'] = 0;
}
$zi = $rule->where('pid',$data['id'])->select();//查询出下级
if($zi){
$zi->update(['level'=>$data['level']+1]);
}
$save = AuthRuleModel::update($data);
if($save){
$res = ['code'=>0,'msg'=>'修改成功'];
} else {
$res = ['code'=>1,'msg'=>'修改失败'];
}
return json($res);
}
$auth_rules = $rule->authRuleTree();
$rules = $rule->find(input('id'));
View::assign(['AuthRule'=>$auth_rules,'rules'=>$rules]);
return View::fetch();
}
//权限开关
public function Check()
{
$data = Request::param();
//获取状态
$res = Db::name('auth_rule')->where('id',$data['id'])->save(['status' => $data['status']]);
if($res){
if($data['status'] == 1){
return json(['code'=>0,'msg'=>'权限开启','icon'=>6]);
} else {
return json(['code'=>0,'msg'=>'权限禁用','icon'=>5]);
}
}else {
return json(['code'=>1,'msg'=>'审核出错']);
}
}
//菜单显示控制
public function menuShow()
{
$data = Request::param();
//var_dump($data);
$rules = Db::name('auth_rule')->save($data);
if($rules){
if($data['ishidden'] == 1){
return json(['code'=>1,'msg'=>'设置菜单显示','icon'=>6]);
} else {
return json(['code'=>1,'msg'=>'取消菜单显示','icon'=>5]);
}
}else{
$res = ['code'=>0,'msg'=>'设置失败'];
}
return json($res);
}
//排序
public function sort()
{
$data = Request::param();
$rules = Db::name('auth_rule')->save($data);
if($rules){
$res = ['code'=>1,'msg'=>'排序成功'];
}else{
$res = ['code'=>0,'msg'=>'排序失败'];
}
return json($res);
}
public function delete($id)
{
$rule = AuthRuleModel::find($id);
$result = $rule->delete();
if($result){
$res = ['code'=>1,'msg'=>'删除成功'];
} else {
$res = ['code'=>0,'msg'=>'删除失败'];
}
return json($res);
}
}

View File

@ -0,0 +1,151 @@
<?php
namespace app\admin\controller;
use app\common\controller\AdminController;
use app\admin\validate\Admin;
use app\admin\model\Admin as adminModel;
use app\common\model\Cate;
use app\common\model\Comment;
use think\facade\View;
use think\facade\Request;
use think\facade\Db;
use think\facade\Session;
use think\exception\ValidateException;
class Forum extends AdminController
{
//帖子列表
public function list()
{
if(Request::isAjax()){
$forumList = Db::name('article')
->alias('a')
->join('user u','a.user_id = u.id')
->field('a.id as aid,name,user_img,title,a.update_time,is_top')
->where('a.delete_time',0)
->order('a.create_time', 'desc')
->paginate(15);
$res = [];
if($forumList){
$res['code'] = 0;
$res['msg'] = '';
$res['count'] = $forumList->total();
foreach($forumList as $k=>$v){
$res['data'][]= ['id'=>$v['aid'],'poster'=>$v['name'],'avatar'=>$v['user_img'],'content'=>$v['title'],'posttime'=>date("Y-m-d",$v['update_time']),'top'=>$v['is_top']];
}
}
return json($res);
}
return View::fetch();
}
//编辑帖子
public function listForm()
{
if(Request::isAjax()){
$data = Request::param();
$form = Db::name('article')->find($data['id']);
//halt($form);
}
return View::fetch();
}
//帖子分类
public function tags()
{
if(Request::isAjax()){
$list = Cate::select();
if($list){
$res['code'] = 0;
$res['msg'] = '';
$res['count']= count($list);
$res['data'] = [];
foreach($list as $k=>$v){
$res['data'][] = ['id' => $v['id'],'tags'=>$v['catename'],'sort'=>$v['sort'],'ename'=>$v['ename']];
}
}
return json($res);
}
return View::fetch();
}
//添加帖子分类
public function addtags()
{
if(Request::isAjax()){
$data = Request::param();
//halt($data);
$list = Db::name('cate')->save($data);
if($list){
return json(['code'=>0,'msg'=>'添加分类成功']);
}else{
return json(['code'=>-1,'msg'=>'添加分类失败']);
}
}
return view('tagsform');
}
//编辑帖子分类
public function tagsform()
{
if(Request::isAjax()){
$data = Request::param();
//halt($data);
$list = Db::name('cate')->where('id',$data['id'])->save($data);
if($list){
return json(['code'=>0,'msg'=>'修改分类成功']);
}else{
return json(['code'=>-1,'msg'=>'修改分类失败']);
}
}
return View::fetch();
}
//删除帖子分类
public function tagsdelete()
{
if(Request::isAjax()){
$data = Request::param();
$cate = new Cate;
$result = $cate->del($data);
if($result == 1){
return json(['code'=>0,'msg'=>'删除分类成功']);
}else{
return json(['code'=>-1,'msg'=>'删除分类失败']);
}
}
}
//帖子评论
public function replys()
{
if(Request::isAjax()) {
$replys = Comment::with(['user','article'])->paginate(15);
$count = $replys->total();
$res = [];
if ($replys) {
$res = ['code'=>0,'msg'=>'','count'=>$count];
foreach($replys as $k => $v){
//var_dump($v);
$res['data'][] = ['id'=>$k+1,'replyer'=>$v->user->name,'cardid'=>$v->article->title,'avatar'=>$v->user->user_img,'content'=>$v['content'],'replytime'=>$v['create_time']];
}
}
return json($res);
}
return View::fetch();
}
public function replysform()
{
return View::fetch();
}
}

View File

@ -0,0 +1,47 @@
<?php
namespace app\admin\controller;
use app\common\controller\AdminController;
use think\facade\View;
use think\facade\Db;
use think\facade\Session;
use think\facade\Request;
use app\admin\model\Admin;
use app\admin\model\Article;
class Index extends AdminController
{
protected function initialize()
{
parent::initialize();
}
public function index()
{
return View::fetch('index');
}
public function set()
{
return view();
}
public function message(){
return view();
}
public function home(){
$sys = Db::name('system')->find(1);
View::assign('sys',$sys);
return View::fetch();
}
public function layout(){
return view();
}
}

View File

@ -0,0 +1,57 @@
<?php
namespace app\admin\controller;
use think\facade\View;
use think\facade\Request;
use think\facade\Session;
use app\admin\validate\Admin;
use think\exception\ValidateException;
class Login
{
//登录
public function index()
{
if(Session::has('admin_id')){
return redirect('/admin/index/index');
}
if(Request::isAjax()){
$data = Request::param();
try{
validate(Admin::class)
->scene('Login')
->check($data);
} catch(ValidateException $e){
return json(['code'=>-1,'msg'=>$e->getError()]);
}
$user = new \app\admin\model\Admin();
$res = $user->login($data);
if ($res == 1) {
$res = ['code'=>0,'msg'=>'登陆成功'];
//$res['data']['access_token'] = $data['__token__'];
} else {
$res = ['code'=>-1,'msg'=>$res,'url'=>'admin/login'];
}
return json($res);
}
return View::fetch('login');
}
//注册
public function reg()
{
if(Session::has('admin_id')){
return redirect('/admin/index/index');
}
return View::fetch('reg');
}
}

View File

@ -0,0 +1,11 @@
<?php
namespace app\admin\controller;
use app\common\controller\AdminController;
class Menu extends AdminController
{
public function index(){
return view();
}
}

View File

@ -0,0 +1,153 @@
<?php
namespace app\admin\controller;
use app\common\controller\AdminController;
use think\facade\View;
use think\facade\Request;
use think\facade\Db;
use app\admin\model\System;
use app\admin\model\MailServer;
use think\facade\Config;
use think\exception\ValidateException;
class Set extends AdminController
{
protected function initialize()
{
parent::initialize();
}
/**
* 显示资源列表
*
* @return \think\Response
*/
public function website()
{
//$sysInfo = Db::name('system')->find(1);
$sysInfo = System::find(1);
if(Request::isAjax()){
$data = Request::param();
$result = $sysInfo->allowField(['webname','webtitle','domain','keywords','descript','copyright','blackname'])->save($data);
if($result){
return json(['code'=>0,'msg'=>'更新成功']);
} else {
return json(['code'=>-1,'msg'=>'更新失败']);
}
}
$syscy = $this->check($sysInfo['base_url']);
View::assign(['sysInfo'=>$sysInfo,'syscy'=>$syscy]);
return View::fetch('set/system/website');
}
/**
* 显示创建资源表单页.
*
* @return \think\Response
*/
public function email()
{
//$mailserver = Db::name('mail_server')->find(1);
$mailserver = MailServer::find(1);
//邮箱配置
if(Request::isAjax()){
$data = Request::param();
$res = $mailserver->save($data);
//dump($data);
if($res){
return json(['code'=>0,'msg'=>'更新成功']);
} else {
return json(['code'=>-1,'msg'=>'更新失败']);
}
}
View::assign('mailserver',$mailserver);
return View::fetch('set/system/email');
}
/**
* 显示编辑资源表单页.
*
* @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)
{
//
}
//上传logo
public function upload()
{
$file = request()->file('file');
try {
validate(['image'=>'filesize:2048|fileExt:jpg,png,gif|image:200,200,jpg'])
->check(array($file));
$savename = \think\facade\Filesystem::disk('public')->putFile('logo',$file);
} catch (think\exception\ValidateException $e) {
echo $e->getMessage();
}
$upload = Config::get('filesystem.disks.public.url');
if($savename){
$name_path =str_replace('\\',"/",$upload.'/'.$savename);
$result = Db::name('system')->where('id', 1)->update(['logo'=>$name_path]);
if($result){
$res = ['code'=>0,'msg'=>'上传logo成功'];
} else {
$res = ['code'=>1,'msg'=>'上传错误'];
}
}
return json($res);
}
public function check($url)
{
$url = $url.'?u='.Request::domain();
$ch =curl_init ();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($ch,CURLOPT_POST, 1);
$data = curl_exec($ch);
$httpCode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
curl_close($ch);
if($httpCode == '200'){
$cy = json_decode($data);
if(!empty($cy)){
$cylevel = $cy->level;
return $cylevel;
}
} else {
return 0;
}
}
}

View File

@ -0,0 +1,126 @@
<?php
namespace app\admin\controller;
use app\common\controller\AdminController;
use think\facade\View;
use think\facade\Db;
use think\facade\Request;
use think\facade\Config;
use think\exception\ValidateException;
use app\admin\model\Slider as SliderModel;
class Slider extends AdminController
{
/**
* 显示资源列表
*
* @return \think\Response
*/
public function index()
{
//幻灯列表
$sliders = Db::name('slider')->select();
View::assign('slider',$sliders);
return View::fetch();
}
/**
* 显示创建资源表单页.
*
* @return \think\Response
*/
public function add()
{
//添加幻灯
if(Request::isAjax()){
$data = Request::param();
$data['slid_start'] = strtotime($data['slid_start']);
$data['slid_over'] = strtotime($data['slid_over']);
$result = Db::name('slider')->save($data);
if($result){
$res = ['code'=>1,'msg'=>'添加成功'];
}else{
$res = ['code'=>0,'msg'=>'添加失败'];
}
return json($res);
}
return View::fetch();
}
/**
* 编辑幻灯
*
* @param int $id
* @return \think\Response
*/
public function edit($id)
{
$slider = Db::name('slider')->find($id);
if(Request::isAjax()){
$data = Request::param();
//var_dump($data);
$data['slid_start'] = strtotime($data['slid_start']);
$data['slid_over'] = strtotime($data['slid_over']);
$result = Db::name('slider')->where('id',$id)->save($data);
if($result){
$res = ['code'=>1,'msg'=>'编辑成功'];
}else{
$res = ['code'=>0,'msg'=>'编辑失败'];
}
return json($res);
}
View::assign('slider',$slider);
return View::fetch();
}
/**
* 保存更新的资源
*
* @param
* @param int $id
* @return \think\Response
*/
public function uploadImg()
{
$id = Request::param();
$file = request()->file('file');
try {
validate(['image'=>'filesize:2048|fileExt:jpg,png,gif|image:200,200,jpg'])
->check(array($file));
$savename = \think\facade\Filesystem::disk('public')->putFile('slider',$file);
} catch (think\exception\ValidateException $e) {
echo $e->getMessage();
}
$upload = Config::get('filesystem.disks.public.url');
if($savename){
$name_path =str_replace('\\',"/",$upload.'/'.$savename);
$res = ['code'=>0,'msg'=>'上传flash成功','src'=>$name_path];
} else {
$res = ['code'=>1,'msg'=>'上传错误'];
}
return json($res);
}
/**
* 删除指定资源
*
* @param int $id
* @return \think\Response
*/
public function delete($id)
{
//
$slider = SliderModel::find($id);
$res = $slider->delete();
if($res){
return json(['code'=>1,'msg'=>'删除成功']);
} else {
return json(['code'=>0,'msg'=>'删除失败']);
}
}
}

View File

@ -0,0 +1,471 @@
<?php
/**
* 升级包规定的目录结构
* xxx_版本号.zip(xxx_1.0.0.zip)
* |
* |————mysql
* | |
* | |___mysql_update.sql(更新脚本) //create table test(id init(11)); create table test2(id init(11));
*
* | |___mysql_rockback.sql回滚脚本 //drop table test; //drop table test2;
* |
* |____php
*
*/
namespace app\admin\controller;
use app\common\controller\AdminController;
use think\facade\View;
use think\facade\Request;
use think\facade\Db;
use think\exception\ValidateException;
use app\admin\controller\Uzip;
use think\facade\Cache;
class Upgrade extends AdminController
{
public $update_log = "../runtime/update/update_log.log"; //系统升级日志
public $return_log = "../runtime/update/return_log.log"; //系统回滚日志
public $progress_log = "../runtime/update/progress_log.log"; //记录进度
public $root_dir = "../"; //站点代码的根目录
public $backup_dir = "../runtime/update/backup_dir/"; //备份目录
public $upload_dir = "../runtime/update/upload_dir/"; //升级包目录
public $sys_version_num; //当前系统的版本
public function __construct()
{
$this->sys_version_num = Db::name('system')->where('id',1)->value('sys_version_num');
}
/** 展示升级界面 */
public function index()
{
$sys_version_num = Db::name('system')->field('sys_version_num,key,upcheck_url,upgrade_url')->find(1);
View::assign('ver_num',$sys_version_num);
return View::fetch();
}
//设置key
public function key()
{
$data = Request::param();
if($data['key']== ''){
return json(['code'=>0,'msg'=>'请填写正确的key']);
}
$res = Db::name('system')->update(['key'=>$data['key'],'id'=>1]);
if($res){
$res = ['code'=>1,'msg'=>'保存成功'];
} else {
$res = ['code'=>0,'msg'=>'保存失败'];
}
return json($res);
}
//修改key
public function keyedit()
{
$key = Db::name('system')->field('key,upcheck_url,upgrade_url')->find(1);
if(Request::isAjax()){
$data = Request::param();
if($data['key']== ''){
return json(['code'=>0,'msg'=>'请正确填写申请到的key']);
}
$res = Db::name('system')->update(['key'=>$data['key'],'upcheck_url'=>$data['upcheck_url'],'upgrade_url'=>$data['upgrade_url'],'id'=>1]);
if($res){
$res = ['code'=>1,'msg'=>'修改成功'];
} else {
$res = ['code'=>0,'msg'=>'修改失败'];
}
return json($res);
}
View::assign('key',$key);
return View::fetch();
}
//升级前的版本检测
public function check($url)
{
$url = $url.'?ver='.$this->sys_version_num;
$ch =curl_init ();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($ch,CURLOPT_POST, 1);
$data = curl_exec($ch);
$httpCode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
curl_close($ch);
if($httpCode != '200'){
return json(['code'=>0,'msg'=>'连接服务器失败,稍后重试...']);
}
$versions = json_decode($data);
//判断状态
$version_code = $versions->code;
if($version_code == 0){
return json(['code'=>$version_code,'msg'=>$versions->msg]);
}
//版本比较
$version_num = $versions->version;
$up_num =$versions->up_num;
$res = version_compare($version_num,$this->sys_version_num,'>');
if($res){
return json(['code'=>1,'msg'=>'发现新版本','version'=>$version_num,'upnum'=>$up_num]);
} else {
return json(['code'=>0,'msg'=>'暂时还没更新哦! ==8']);
}
}
/**
* 自动更新
*/
public function upload()
{
$data = Request::param();
if(empty($data['key'])){
return json(["code"=>0,"msg"=>"请配置正确升级key"]);
}
$url = $data['url'].'?domain='.Request::domain().'&key='.$data['key'].'&ver='.$this->sys_version_num;
$ch =curl_init ();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($ch,CURLOPT_POST, 1);
$data = curl_exec($ch);
$httpCode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
curl_close($ch);
if($httpCode != '200'){
return json(['code'=>0,'msg'=>'连接服务器失败,稍后重试...']);
}
//获取远程文件
$versions = json_decode($data);
//判断状态
$version_code = $versions->code;
if($version_code == 0){
return json(['code'=>$version_code,'msg'=>$versions->msg]);
}
$version_num = $versions->version;
$file_url = $versions->src;
//判断远程文件是否可用存在
$header = get_headers($file_url, true);
if(!isset($header[0]) && (strpos($header[0], '200') || strpos($header[0], '304'))){
return json(["code"=>0,"msg"=>"获取远程文件失败"]);
}
//把远程文件放入本地
$package_file = $this->upload_dir.'tao_'.$version_num.'.zip';
if(!is_dir($this->upload_dir)){
$this->create_dirs($this->upload_dir);
}
$cpfile = copy($file_url,$package_file);
if(!$cpfile)
{
return json(["code"=>0,"msg"=>"下载升级文件失败"]);
}
//记录下日志
$this->save_log("上传升级包成功!");
$this->update_progress("20%");
//升级前备份代码
$ex = array('app','view');
$backup_code_res = $this->copydir('../', $this->backup_dir, $ex);
if(!$backup_code_res){
$this->save_log("备份失败!");
return json(["code"=>0,"msg"=>"备份失败"]);
}
$this->update_progress("30%");
//执行升级
$upres = $this->execute_update($package_file);
//更新版本
Db::name('system')->update(['sys_version_num'=>$version_num,'id'=>1]);
if($upres){
return json(["code"=>1,"msg"=>"升级成功"]);
}else {
return json(["code"=>0,"msg"=>"升级失败"]);
}
}
/**
* 处理升级包上传
*/
public function uploadZip()
{
$files = request()->file('file');
if($files)
{
$name = $files->getOriginalName();
if(!$name)
{
return json(["code"=>0,"msg"=>"请上传升级包文件"]);
}
}
//校验后缀
$astr = explode('.',$name);
$ext = array_pop($astr);
if($ext != 'zip')
{
return json(["code"=>0,"msg"=>"请上传文件格式不对"]);
}
//对比版本号
$astr = explode('_',$name);
$version_num = str_replace(".zip", '',array_pop($astr));
//var_dump($version_num);
if(!$version_num)
{
return json(["code"=>0,"msg"=>"获取版本号失败"]);
}
//对比
if(!$this->compare_version($version_num))
{
return json(["code"=>0,"msg"=>"版本升级不能降级!请检查..."]);
}
$package_file = $this->upload_dir.$name;
//$mv = $files->move('/../tmp/web/upload_dir',$version_num);
$mfile = move_uploaded_file($files,$package_file);
if(!$mfile)
{
return json(["code"=>0,"msg"=>"上传文件失败"]);
}
//记录下日志
$this->save_log("上传升级包成功!");
$this->update_progress("20%");
//升级前备份代码
$ex = array('app','view');
$backup_code_res = $this->copydir('../', $this->backup_dir, $ex);
if(!$backup_code_res){
$this->save_log("备份失败!");
return json(["code"=>0,"msg"=>"备份失败"]);
}
$this->update_progress("30%");
//执行升级
$upres = $this->execute_update($package_file);
//更新版本
Db::name('system')->update(['sys_version_num'=>$version_num,'id'=>1]);
if($upres){
return json(["code"=>1,"msg"=>"升级成功"]);
}else {
return json(["code"=>0,"msg"=>"升级失败"]);
}
}
/**
* 升级操作
* @return [type] [description]
*/
private function execute_update($package_file)
{
//解压 如何使用zip加密压缩这里解压缩的时候注意要解密
$uzip = new Uzip();
$unzip_res = $uzip->uzip($package_file,$this->upload_dir,true);
//halt($unzip_res);
if(!$unzip_res)
{
$this->save_log("解压失败");
return json(["code"=>0,"msg"=>"解压失败"]);
}
//解压成功,得到文件夹
$package_name = str_replace(".zip","",$package_file);
//var_dump($package_name);
$this->update_progress("50%");
/*
//升级mysql
if(file_exists($this->upload_dir.'/'.$package_file."/mysql/mysql_update.sql"))
{
$result = $this->database_operation($this->upload_dir.'/'.$package_file."/mysql/mysql_update.sql");
if(!$result['code'])
{
echo json($result);die;
}
}
*/
$this->update_progress("70%");
if(is_dir($package_name.'/'))
{
//升级PHP
$cp_res = $this->copydir($package_name.'/', $this->root_dir);
if(!$cp_res)
{
$this->save_log("php更新失败");
//数据库回滚
if(file_exists($this->upload_dir.'/'.$package_file."/mysql/mysql_rockback.sql"))
{
$this->save_log("数据库回滚");
$this->database_operation($this->upload_dir.'/'.$package_file."/mysql/mysql_rockback.sql");
}
//php代码回滚 升级前备份的代码
$backup_code_res = $this->copydir($this->backup_dir, $this->zip_dir);
if($backup_code_res){
$this->save_log("php回滚");
return json(["code"=>0,"msg"=>"php更新失败"]);
}
}
}
//把解压的升级包清除
//$del_zip = unlink($package_file);
$this->delDirAndFile($this->upload_dir);
$this->delDirAndFile($this->backup_dir);
$this->update_progress("100%");
//更新系统的版本号了
//更新php的版本号了(应该跟svngit的版本号一致)
//更新数据库的版本号了(应该跟svngit的版本号一致)
return true;
}
/**
* 比较代码版本
* @return [type] [description]
*/
private function compare_version($version_num='1.0.0')
{
return version_compare($version_num,$this->sys_version_num,'>');
//return json(['code'=>1,'msg'=>'版本','data'=>$version]);
}
/**
* 数据库操作
*/
public function database_operation($file)
{
$mysqli = new mysqli("localhost","root","root","test");
if($mysqli->connect_errno)
{
return json(["code"=>0,"msg"=>"Connect failed:".$mysqli->connect_error]);
}
$sql = file_get_contents($file);
$a = $mysqli->multi_query($sql);
return ["code"=>1,"msg"=>"数据库操作OK"];
}
/**
* 返回系统升级的进度
*/
public function update_progress($progress)
{
exec(" echo '".$progress."' > $this->progress_log ");
}
/**
* 记录日志
*/
public function save_log($msg,$action="update")
{
$msg .= date("Y-m-d H:i:s").":".$msg."\n";
if($action == "update")
{
exec(" echo '".$msg."' >> $this->update_log ");
}else
{
exec(" echo '".$msg."' >> $this->return_log ");
}
}
/**
* 复制文件夹$source下的文件和子文件夹下的内容到$dest下 升级+备份代码
* @param $source
* @param $dest
* @param $ex 定义指定复制的目录,默认全复制
*/
public function copydir($source, $dest, $ex=array())
{
if (!file_exists($dest)) mkdir($dest);
if($handle = opendir($source)){
while (($file = readdir($handle)) !== false) {
if (( $file != '.' ) && ( $file != '..' )) {
if ( is_dir($source . $file) ) {
if(count($ex) != 0){
if(in_array($file,$ex)){
$this->copydir($source . $file.'/', $dest . $file.'/');
}
}else{
$this->copydir($source . $file.'/', $dest . $file.'/');
}
} else {
copy($source. $file, $dest . $file);
}
}
}
closedir($handle);
} else {
return false;
}
return true;
}
/**
* 删除文件夹及内容
* @param $dirPath
* @param $nowDir 是否删除当前文件夹$dirPath true false
*/
public function delDirAndFile( $dirPath, $nowDir=false )
{
if ( $handle = opendir($dirPath) ) {
while ( false !== ( $item = readdir( $handle ) ) ) {
if ( $item != '.' && $item != '..' ) {
$path = $dirPath.$item;
//var_dump($path);
if (is_dir($path)) {
$this->delDirAndFile($path.'/');
rmdir($path.'/');
} else {
unlink($path);
}
}
}
closedir( $handle );
/*
if($nowDir == true){
if(!rmdir($dirPath)){
return false;
}
}
*/
} else {
return false;
}
return true;
}
}

View File

@ -0,0 +1,129 @@
<?php
namespace app\admin\controller;
use app\common\controller\AdminController;
use app\admin\validate\Admin;
use app\admin\model\Admin as adminModel;
use think\facade\View;
use think\facade\Request;
use think\facade\Config;
use think\facade\Db;
use think\facade\Session;
use think\exception\ValidateException;
use app\common\model\User as UserModel;
class User extends AdminController
{
/**
protected function initialize()
{
parent::initialize();
}
*/
//用户表
public function list()
{
if(Request::isAjax()){
$user = Db::name('user')->where(['delete_time'=>0])->select();
$count = $user->count();
$res = [];
if($user){
$res = ['code'=>0,'msg'=>'','count'=>$count];
foreach($user as $k => $v){
$data = ['id'=>$v['id'],'username'=>$v['name'],'avatar'=>$v['user_img'],'phone'=>$v['phone'],'email'=>$v['email'],'sex'=>$v['sex'],'ip'=>$v['last_login_ip'],'jointime'=>date("Y-m-d",$v['create_time']),'status'=>$v['status']];
$res['data'][] = $data;
}
}
return json($res);
}
return View::fetch();
}
//添加用户
public function userForm()
{
//
if(Request::isAjax()){
$data = Request::param();
$result = Db::name('user')->save($data);
if($result){
$res = ['code'=>1,'msg'=>'添加成功'];
}else{
$res = ['code'=>0,'msg'=>'添加失败'];
}
return json($res);
}
return View::fetch('userform');
}
//编辑用户
public function userEdit()
{
if(Request::isAjax()){
$data = Request::param();
$result = Db::name('user')->update($data);
if($result){
$res = ['code'=>1,'msg'=>'编辑成功'];
}else{
$res = ['code'=>0,'msg'=>'编辑失败'];
}
return json($res);
}
$user = Db::name('user')->find(input('id'));
View::assign('user',$user);
return View::fetch('useredit');
}
//删除用户
public function delete($id)
{
if(Request::isAjax()){
$user =UserModel::find($id);
$result = $user->delete();
if($result){
return json(['code'=>1,'msg'=>'删除成功']);
}else{
return json(['code'=>0,'msg'=>'删除失败']);
}
}
}
//上传头像
public function uploadImg()
{
$file = request()->file('file');
try {
validate(['image'=>'filesize:2048|fileExt:jpg,png,gif|image:200,200,jpg'])
->check(array($file));
$savename = \think\facade\Filesystem::disk('public')->putFile('head_pic',$file);
} catch (think\exception\ValidateException $e) {
echo $e->getMessage();
}
$upload = Config::get('filesystem.disks.public.url');
if($savename){
$name_path =str_replace('\\',"/",$upload.'/'.$savename);
$res = ['code'=>0,'msg'=>'上传头像成功','src'=>$name_path];
} else {
$res = ['code'=>1,'msg'=>'上传错误'];
}
return json($res);
}
//退出登陆
public function logout()
{
Session::clear();
$res = ['code'=>0,'msg'=>'退出成功' ];
return json($res);
}
}

View File

@ -0,0 +1,96 @@
<?php
namespace app\admin\controller;
use app\common\controller\AdminController;
class Uzip extends AdminController
{
/**
*header('Content-type:text/html;charset=utf-8');
*@param $filename 解压文件
*@param $dir 解压到路径
*@param $overwrite 是否覆盖文件 true false
*/
public function uzip($filename, $dir ,$overwrite=true)
{
if(!is_dir($dir)) {
//mkdir($dir, 0777, true);//创建目录保存解压内容
$this->create_dirs($dir);
}
if(file_exists($filename)) {
$resource = zip_open($filename);
while($zip = zip_read($resource)) {
if(zip_entry_open($resource, $zip)) {
//获得文件名mac压缩成zip解压需要过滤资源库隐藏文件
$file_content = zip_entry_name($zip);
// 如果文件不在根目录中
$pos_last_slash = strrpos($file_content, "/");
$file_name = substr($file_content, $pos_last_slash+1);
if(empty($file_name)){
$pt = $this->create_dirs($dir.$file_content);
}
if($file_name) {
$save_path = $dir.$file_content;
if(file_exists($save_path)) {
if($overwrite === true){
//echo $file_name . '<pre />';
$file_size = zip_entry_filesize($zip);
$file = zip_entry_read($zip, $file_size);
$fpc = file_put_contents($save_path, $file);
//zip_entry_close($zip);
}else{
//echo '文件夹内已存在文件 "' . $file_name . '" <pre />';
return json(['code'=>0,'msg'=>'文件夹内已存在文件']);
}
}else {
//echo $file_name . '<pre />';
$file_size = zip_entry_filesize($zip);
$file = zip_entry_read($zip, $file_size);
$fpc = file_put_contents($save_path, $file);
//zip_entry_close($zip);
}
}
zip_entry_close($zip);
}
}
zip_close($resource);
}else{
return false;
}
return true;
}
public function create_dirs($path)
{
if (!is_dir($path))
{
$directory_path = "";
$directories = explode("/",$path);
array_pop($directories);
foreach($directories as $directory)
{
$directory_path .= $directory."/";
if (!is_dir($directory_path))
{
mkdir($directory_path);
chmod($directory_path, 0777);
}
}
}
}
}

6
app/admin/middleware.php Normal file
View File

@ -0,0 +1,6 @@
<?php
return [
app\middleware\Auth::class,
//'logedcheck' => \app\middleware\logedCheck::class,
];

1
app/admin/model/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
Version.php

50
app/admin/model/Admin.php Normal file
View File

@ -0,0 +1,50 @@
<?php
namespace app\admin\model;
use think\Model;
use think\facade\Db;
use think\facade\Session;
//use think\facade\Request;
use think\model\concern\SoftDelete;
class Admin extends Model
{
//软删除
use SoftDelete;
protected $deleteTime = 'delete_time';
protected $defaultSoftDelete = 0;
//登陆校验
public function login($data)
{
//查询用户
$admin = Db::name('admin')->where('username',$data['username'])->find();
if($admin['status'] !=1){
return '用户被禁用或未审核,请联系管理员';
}
//对输入的密码字段进行MD5加密再进行数据库的查询
$salt = substr(md5($admin['create_time']),-6);
$pwd = substr_replace(md5($data['password']),$salt,0,6);
$data['password'] = md5($pwd);
if($admin['password'] == $data['password']){
//将用户数据写入Session
Session::set('admin_id',$admin['id']);
Session::set('admin_name',$admin['username']);
Db::name('admin')->where('id',$admin['id'])->update(
[
'last_login_time' => time(),
'last_login_ip' => request()->ip(),
]
);
//用户名密码正确返回1
return 1;
}else{
return '用户名或密码错误';
}
}
}

View File

@ -0,0 +1,10 @@
<?php
namespace app\admin\model;
use think\Model;
class Article extends Model
{
//
}

View File

@ -0,0 +1,35 @@
<?php
namespace app\admin\model;
use think\Model;
use think\facade\Db;
use think\facade\Session;
//use think\model\concern\SoftDelete;
class AuthGroup extends Model
{
//软删除
use SoftDelete;
protected $deleteTime = 'delete_time';
protected $defaultSoftDelete = 0;
//登陆校验
public function authRuleTree()
{
$authRules = $this->order('sort asc')->select();
return $this->sort($authRules);
}
public function sort($data,$pid=0)
{
static $arr = array();
foreach($data as $k=> $v){
if($v['pid']==$pid){
$arr[] = $v;
$this->sort($data,$v['id']);
}
}
return $arr;
}
}

View File

@ -0,0 +1,35 @@
<?php
namespace app\admin\model;
use think\Model;
use think\facade\Db;
use think\facade\Session;
//use think\model\concern\SoftDelete;
class AuthRule extends Model
{
//软删除
//use SoftDelete;
//protected $deleteTime = 'delete_time';
//protected $defaultSoftDelete = 0;
//登陆校验
public function authRuleTree()
{
$authRules = $this->order('sort asc')->select();
return $this->sort($authRules);
}
public function sort($data,$pid=0)
{
static $arr = array();
foreach($data as $k=> $v){
if($v['pid']==$pid){
$arr[] = $v;
$this->sort($data,$v['id']);
}
}
return $arr;
}
}

View File

@ -0,0 +1,24 @@
<?php
namespace app\admin\model;
use think\Model;
use think\facade\Db;
use think\facade\Session;
use think\facade\Request;
//use think\model\concern\SoftDelete;
class MailServer extends Model
{
//软删除
//use SoftDelete;
//protected $deleteTime = 'delete_time';
//protected $defaultSoftDelete = 0;
//登陆校验
public function email()
{
}
}

View File

@ -0,0 +1,17 @@
<?php
namespace app\admin\model;
use think\Model;
use think\model\concern\SoftDelete;
class Slider extends Model
{
//软删除
use SoftDelete;
protected $deleteTime = 'delete_time';
protected $defaultSoftDelete = 0;
}

View File

@ -0,0 +1,24 @@
<?php
namespace app\admin\model;
use think\Model;
use think\facade\Db;
use think\facade\Session;
use think\facade\Request;
//use think\model\concern\SoftDelete;
class System extends Model
{
//软删除
//use SoftDelete;
//protected $deleteTime = 'delete_time';
//protected $defaultSoftDelete = 0;
//登陆校验
public function website()
{
}
}

View File

@ -0,0 +1,60 @@
<?php
namespace app\admin\validate;
use think\Validate;
class Admin extends Validate
{
protected $rule = [
'username|用户名' => 'require|min:2|max:18|unique:admin',
'password|密码' => 'require|min:6|max:20',
'repassword|确认密码'=>'require|confirm:password',
'nickname|昵称' => 'require|min:2|max:20',
'email|邮箱' => 'require|email|unique:admin',
'captcha|验证码' => 'require|captcha',
'city|城市' => 'min:2',
'sign|签名' => 'min:10',
'sex|性别' => 'require',
'nowpass|密码' => 'require|min:6|max:20',
];
//登陆验证场景
public function sceneLogin()
{
return $this->only(['username','password','captcha'])
->remove('username', 'unique');
}
//注册验证场景
public function sceneReg()
{
return $this->only(['username','password','repassword','email','captcha']);
//->append('email','unique:user');
// ->remove('password', 'confirm');
}
//密码找回
public function sceneForget()
{
return $this->only(['email','captcha']);
}
//密码重设
public function sceneRepass()
{
return $this->only(['password','repassword','captcha']);
}
//用户资料
public function sceneSet()
{
return $this->only(['email','nickname','ctity','sex','sign'])
->remove('email','unique');
}
//设置新密码
public function sceneSetpass()
{
return $this->only(['nowpass','password','repassword']);
}
}

246
app/common.php Normal file
View File

@ -0,0 +1,246 @@
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
use think\facade\Request;
use think\facade\Db;
use think\facade\Session;
// 应用公共文件
function mailto($to,$title,$content)
{
$mail = new PHPMailer(true); // Passing `true` enables exceptions
$mailserver = Db::name('mail_server')->find(1);
try {
//Server settings
$mail->SMTPDebug = 0; // Enable verbose debug output
$mail->CharSet = 'utf-8'; //b
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = $mailserver['host']; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = $mailserver['mail']; // SMTP username
$mail->Password = $mailserver['password']; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = $mailserver['port']; // TCP port to connect to
//Recipients
$mail->setFrom($mailserver['mail'], $mailserver['nickname']);
$mail->addAddress($to); // Add a recipient
//$mail->addAddress('ellen@example.com'); // Name is optional
//$mail->addReplyTo('info@example.com', 'Information');
//$mail->addCC('cc@example.com');
//$mail->addBCC('bcc@example.com');
//Attachments
//$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $title;
$mail->Body = $content;
//$mail->AltBody =$user ;
return $mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
}
//根据user area_id查询区域简称
function getAsing($area_id){
return Db::name('user_area')->where('id',$area_id)->value('asing');
}
//根据用户主键ID查询用户名称
if(!function_exists('getUserName'))
{
function getUserName($user_id)
{
return Db::name('user')->where('id',$user_id)->value('name');
}
}
if(!function_exists('getUserImg'))
{
function getUserImg($user_id)
{
return Db::name('user')->where('id',$user_id)->value('user_img');
}
}
//根据文章分类ID查询分类名
function getCateName($cate_ename)
{
return Db::name('cate')->where('ename',$cate_ename)->value('catename');
}
//过滤文章摘要
function getArtContent($content)
{
return mb_substr(strip_tags($content),0,50).'更多详情...';
}
//根据帖子收藏主键ID查询帖子名称
if(!function_exists('getArticName'))
{
function getArticName($article_id)
{
return Db::name('article')->where('id',$article_id)->value('title');
}
}
//根据评论时间查询是否已过修改期
function getLimtTime($create_time)
{
$nt = time();
$lt = intval(($nt - strtotime($create_time))/86400);
return $lt;
}
//根据用户名查询主页
function jump()
{
$username = Request::param('username');
return Db::name('user')->where('name',$username)->find();
}
/**
* 数组层级缩进转换
* @param array $array 源数组
* @param int $pid
* @param int $level
* @return array
*/
function array2level($array, $pid = 0, $level = 1)
{
static $list = [];
foreach ($array as $v) {
if ($v['pid'] == $pid) {
$v['level'] = $level;
$list[] = $v;
array2level($array, $v['id'], $level + 1);
}
}
return $list;
}
/**
* 构建层级(树状)数组
* @param array $array 要进行处理的一维数组,经过该函数处理后,该数组自动转为树状数组
* @param string $pid_name 父级ID的字段名
* @param string $child_key_name 子元素键名
* @return array|bool
*/
function array2tree(&$array, $pid_name = 'pid', $child_key_name = 'children')
{
$counter = array_children_count($array, $pid_name);
if (!isset($counter[0]) || $counter[0] == 0) {
return $array;
}
$tree = [];
while (isset($counter[0]) && $counter[0] > 0) {
$temp = array_shift($array);
if (isset($counter[$temp['id']]) && $counter[$temp['id']] > 0) {
array_push($array, $temp);
} else {
if ($temp[$pid_name] == 0) {
$tree[] = $temp;
} else {
$array = array_child_append($array, $temp[$pid_name], $temp, $child_key_name);
}
}
$counter = array_children_count($array, $pid_name);
}
return $tree;
}
/**
* 子元素计数器
* @param array $array
* @param int $pid
* @return array
*/
function array_children_count($array, $pid)
{
$counter = [];
foreach ($array as $item) {
$count = isset($counter[$item[$pid]]) ? $counter[$item[$pid]] : 0;
$count++;
$counter[$item[$pid]] = $count;
}
return $counter;
}
/**
* 把元素插入到对应的父元素$child_key_name字段
* @param $parent
* @param $pid
* @param $child
* @param string $child_key_name 子元素键名
* @return mixed
*/
function array_child_append($parent, $pid, $child, $child_key_name)
{
foreach ($parent as &$item) {
if ($item['id'] == $pid) {
if (!isset($item[$child_key_name])) {
$item[$child_key_name] = [];
}
$item[$child_key_name][] = $child;
}
}
return $parent;
}
//菜单递归
function getTree($data)
{
$tree = [];
foreach ($data as $array) {
if(isset($data[$array['pid']])) {
$data[$array['pid']]['children'][] = &$data[$array['id']];
//$tree = $data;
} else {
$tree[] = &$data[$array['id']];
}
}
return $tree;
}
//按钮权限检查
function checkRuleButton($rules_button)
{
$admin_id = Session::get('admin_id');
$auth = new xiaodi\Auth();
$res = $auth->check($rules_button,$admin_id );
if($res || $admin_id == 1){
return true;
} else {
return false;
}
}
//菜单结构
function getSpaceNmu($level)
{
return str_repeat('---',$level);
}

View File

@ -0,0 +1,238 @@
<?php
declare (strict_types = 1);
namespace app\common\controller;
use think\Controller;
use think\App;
use think\Response;
use think\exception\ValidateException;
use think\Validate;
use think\exception\HttpResponseException;
use think\facade\Session;
use think\facade\Cache;
use think\facade\View;
use think\facade\Db;
use xiaodi\Auth;
/**
* 控制器基础类
*/
abstract class AdminController
{
/**
* 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()
{
//权限auth检查
//$this->checkAuth();
$this->getMenu();
}
/**
* 验证数据
* @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);
}
//权限检查
/**
* 权限检查
* @return bool
*/
/*
protected function checkAuth()
{
if (!Session::has('admin_id')) {
echo '请去登陆';
return redirect('/admin/login/index');
//$this->error('请登录');
//return ['code'=>0,'url'=>'/user/login'];
}
$app = app('http')->getName();
$controller = $this->request->controller();
$action = $this->request->action();
// 排除权限
$not_check = ['admin/Index/index','admin/Index/home','admin/Set/info','admin/Set/password'];
if (!in_array($app . '/' . $controller . '/' . $action, $not_check)) {
$auth = new Auth();
$admin_id = Session::get('admin_id');
if (!$auth->check($app . '/' . $controller . '/' . $action, $admin_id) && $admin_id != 1) {
//$this->error('没有权限');
echo '<script>alert("没有权限");location.back()</script>';
//return redirect('admin/user/login');
}
}
}
*/
/**
* 获取侧边栏菜单
*/
protected function getMenu()
{
$menu = [];
$admin_id = Session::get('admin_id');
$auth = new Auth();
$auth_rule_list = Db::name('auth_rule')->where(['status'=> 1,'ishidden'=>1])->order(['sort' => 'asc'])->select();
//var_export($auth_rule_list);
foreach ($auth_rule_list as $value) {
if ($auth->check($value['name'], $admin_id) || $admin_id == 1) {
$menu[] = $value;
}
}
$menu = !empty($menu) ? array2tree($menu) : [];
return View::assign('menu', $menu);
}
/**
* 获取角色菜单
*/
protected function getMenus()
{
$menu = [];
$auth_rule_list = Db::name('auth_rule')->where(['status'=> 1])->order(['sort' => 'ASC', 'id' => 'ASC'])->select();
//var_export($auth_rule_list);
foreach ($auth_rule_list as $value) {
$menu[] = $value;
}
$menus = !empty($menu) ? array2tree($menu) : [];
//$menu2 = getTree($menu);
return $menus;
//return View::assign('menus', $menus);
}
//判断是否已登录?
protected function isLogged()
{
if(Session::has('admin_id')){
return redirect('admin/index/index');
}
}
//判断是否需要登录?
protected function isLogin()
{
if(!Session::has('admin_id')){
return redirect('/admin/login/index');
}
}
//显示当前登录管理员
protected function showAdmin()
{
$id = Session::get('admin_id');
//1.查询管理用户
$adminHead = Admin::find($id);
//2.将User变量赋给模板 公共模板nav.html
View::assign('adminHead',$adminHead);
}
/**创建目录
* This function creates recursive directories if it doesn't already exist
*
* @param String The path that should be created
*
* @return void
*/
protected function create_dirs($path)
{
if (!is_dir($path))
{
$directory_path = "";
$directories = explode("/",$path);
array_pop($directories);
foreach($directories as $directory)
{
$directory_path .= $directory."/";
if (!is_dir($directory_path))
{
mkdir($directory_path);
chmod($directory_path, 0777);
}
}
}
}
}

View File

@ -0,0 +1,257 @@
<?php
declare (strict_types = 1);
namespace app\common\controller;
use think\App;
use think\Response;
use think\facade\View;
use think\facade\Db;
use think\exception\ValidateException;
use think\exception\HttpResponseException;
use think\facade\Session;
use think\facade\Cache;
/**
* 控制器基础类
*/
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()
{
//系统配置
$this->showSystem();
//显示分类导航
$this->showNav();
$this->showUser();
}
/**
* 验证数据
* @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);
}
/**
* 操作错误跳转
* @param mixed $msg 提示信息
* @param string $url 跳转的URL地址
* @param mixed $data 返回的数据
* @param integer $wait 跳转等待时间
* @param array $header 发送的Header信息
* @return void
*/
protected function error($msg = '', string $url = null, $data = '', int $wait = 3, array $header = []): Response
{
if (is_null($url)) {
$url = request()->isAjax() ? '' : 'javascript:history.back(-1);';
} elseif ($url) {
$url = (strpos($url, '://') || 0 === strpos($url, '/')) ? $url : app('route')->buildUrl($url);
}
$result = [
'code' => 0,
'msg' => $msg,
'data' => $data,
'url' => $url,
'wait' => $wait,
];
$type = (request()->isJson() || request()->isAjax()) ? 'json' : 'html';
if ('html' == strtolower($type)) {
$type = 'jump';
}
$response = Response::create($result, $type)->header($header)->options(['jump_template' => app('config')->get('app.dispatch_error_tmpl')]);
throw new HttpResponseException($response);
}
/**
* 返回封装后的API数据到客户端
* @param mixed $data 要返回的数据
* @param integer $code 返回的code
* @param mixed $msg 提示信息
* @param string $type 返回数据格式
* @param array $header 发送的Header信息
* @return Response
*/
protected function result($data, int $code = 0, $msg = '', string $type = '', array $header = []): Response
{
$result = [
'code' => $code,
'msg' => $msg,
'time' => time(),
'data' => $data,
];
$type = $type ?: 'json';
$response = Response::create($result, $type)->header($header);
throw new HttpResponseException($response);
}
/**
* 操作成功跳转
* @param mixed $msg 提示信息
* @param string $url 跳转的URL地址
* @param mixed $data 返回的数据
* @param integer $wait 跳转等待时间
* @param array $header 发送的Header信息
* @return void
*/
protected function success($msg = '', string $url = null, $data = '', int $wait = 3, array $header = []): Response
{
if (is_null($url) && isset($_SERVER["HTTP_REFERER"])) {
$url = $_SERVER["HTTP_REFERER"];
} elseif ($url) {
$url = (strpos($url, '://') || 0 === strpos($url, '/')) ? $url : app('route')->buildUrl($url);
}
$result = [
'code' => 1,
'msg' => $msg,
'data' => $data,
'url' => $url,
'wait' => $wait,
];
$type = (request()->isJson() || request()->isAjax()) ? 'json' : 'html';
// 把跳转模板的渲染下沉,这样在 response_send 行为里通过getData()获得的数据是一致性的格式
if ('html' == strtolower($type)) {
$type = 'jump';
}
$response = Response::create($result, $type)->header($header)->options(['jump_template' => app('config')->get('app.dispatch_success_tmpl')]);
throw new HttpResponseException($response);
}
//判断是否已登录?
protected function isLogged()
{
if(Session::has('user_id')){
$this->success('您已登录','/index/index/index');
}
}
//判断是否需要登录?
protected function isLogin()
{
if(!Session::has('user_id')){
$this->error('请登录','/index/user/login');
}
}
/* //判断密码找回是否已进行了邮件发送?
protected function isMailed()
{
if(Cache::get('repass') != 1){
$this->error('错误请求,请正确操作!','/index/user/forget');
}
}*/
// 显示导航
protected function showNav()
{
//1.查询分类表获取所有分类
$cateList = Db::name('cate')->where(['status'=>1,'delete_time'=>0])->order('sort','asc')->select();
//2.将catelist变量赋给模板 公共模板nav.html
View::assign('cateList',$cateList);
}
//显示用户
protected function showUser()
{
$user['user_id'] = Session::get('user_id');
//1.查询用户
$user = Db::name('user')->field('id,name,nickname,user_img,sex,auth,city,email,sign,point')->where('id',$user['user_id'])->find();
//2.将User变量赋给模板 公共模板nav.html
View::assign('user',$user);
}
//显示网站设置
protected function showSystem()
{
//1.查询分类表获取所有分类
$sysInfo = Db::name('system')->cache(true)->find(1);
View::assign('sysInfo',$sysInfo);
}
}

View File

@ -0,0 +1,82 @@
<?php
namespace app\common\model;
use think\Model;
use think\model\concern\SoftDelete;
class Article extends Model
{
//protected $pk = 'id'; //主键
protected $autoWriteTimestamp = true; //开启自动时间戳
protected $createTime = 'create_time';
protected $updateTime = 'update_time';
//开启自动设置
protected $auto = [];
//仅新增有效
protected $insert = ['create_time','status'=>1,'is_top'=>0,'is_hot'=>0];
//仅更新有效
protected $update = ['update_time'];
//软删除
use SoftDelete;
protected $deleteTime = 'delete_time';
protected $defaultSoftDelete = 0;
//文章关联栏目表
public function cate()
{
return $this->belongsTo('Cate','cate_id','id');
}
//文章关联评论
public function comments()
{
return $this->hasMany('Comment','article_id','id');
}
//文章关联用户
public function user()
{
return $this->belongsTo('User','user_id','id');
}
//文章添加
public function add($data)
{
$result = $this->save($data);
if($result) {
return 1;
} else {
return '文章添加失败!';
}
}
//文章编辑
public function edit($data)
{
$article = $this->find($data['id']);
$result = $article->save($data);
if($result) {
return 1;
} else {
return '文章修改失败!';
}
}
//文章
public function detail()
{
$arts = Article::all();
return $arts;
}
//置顶文章
public function artTop()
{
$artTop = Article::where('status',1)->where('is_top',1)->select();
return $artTop;
}
}

28
app/common/model/Cate.php Normal file
View File

@ -0,0 +1,28 @@
<?php
namespace app\common\model;
use think\Model;
use think\model\concern\SoftDelete;
class Cate extends Model
{
//软删除
use SoftDelete;
protected $deleteTime = 'delete_time';
protected $defaultSoftDelete = 0;
public function del($data)
{
$cates = $this->find($data['id']);
$res = $cates->delete();
if($res){
return 1;
}else{
return -1;
}
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace app\common\model;
use think\Model;
use think\model\concern\SoftDelete;
class Collection extends Model
{
//protected $pk = 'id'; //主键
protected $autoWriteTimestamp = true; //开启自动时间戳
protected $createTime = 'create_time';
//软删除
use SoftDelete;
protected $deleteTime = 'delete_time';
protected $defaultSoftDelete = 0;
//收藏关联文章
public function article()
{
return $this->belongsTo('Article','article_id','id');
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace app\common\model;
use think\Model;
use think\model\concern\SoftDelete;
class Comment extends Model
{
protected $autoWriteTimestamp = true; //开启自动时间戳
protected $createTime = 'create_time';
protected $updateTime = 'update_time';
//软删除
use SoftDelete;
protected $deleteTime = 'delete_time';
protected $defaultSoftDelete = 0;
public function article()
{
//评论关联文章
return $this->belongsTo('Article','article_id','id');
}
public function user()
{
//评论关联用户
return $this->belongsTo('User','user_id','id');
}
}

28
app/common/model/Sign.php Normal file
View File

@ -0,0 +1,28 @@
<?php
namespace app\common\model;
use think\Model;
use think\model\concern\SoftDelete;
use think\Db;
use think\facade\Session;
class Sign extends Model
{
protected $pk = 'id'; //主键
protected $autoWriteTimestamp = true; //开启自动时间戳
protected $createTime = 'create_time';
protected $updateTime = 'update_time';
//用户关联评论
public function user()
{
return $this->hasMany('User','user_id','id');
}
}

View File

@ -0,0 +1,21 @@
<?php
namespace app\common\model;
use think\Model;
class System extends Model
{
public function add()
{
$system = System::all();
}
}

View File

@ -0,0 +1,21 @@
<?php
namespace app\common\model;
use think\Model;
use think\model\concern\SoftDelete;
class UpgradeAuth extends Model
{
//protected $pk = 'id'; //主键
protected $autoWriteTimestamp = true; //开启自动时间戳
protected $createTime = 'create_time';
//软删除
use SoftDelete;
protected $deleteTime = 'delete_time';
protected $defaultSoftDelete = 0;
}

128
app/common/model/User.php Normal file
View File

@ -0,0 +1,128 @@
<?php
namespace app\common\model;
use think\Model;
use think\model\concern\SoftDelete;
use think\facade\Db;
use think\facade\Session;
class User extends Model
{
protected $pk = 'id'; //主键
protected $autoWriteTimestamp = true; //开启自动时间戳
protected $createTime = 'false';
protected $updateTime = 'update_time';
//protected $auto = ['password']; //定义自动处理的字段
//自动对password进行md5加密
protected function setPasswordAttr($value){
return md5($value);
}
//软删除
use SoftDelete;
protected $deleteTime = 'delete_time';
protected $defaultSoftDelete = 0;
//只读字段,禁止更改
//protected $readonly = ['email'];
//用户关联评论
public function comments()
{
return $this->hasMany('Comment','user_id','id');
}
//用户关联所属区域
public function userArea()
{
return $this->belongsTo('UserArea','user_raea_id','id');
}
//登陆校验
public function login($data)
{
//查询用户
$user = Db::name('user')->whereOr('email',$data['name'])->whereOr('name',$data['name'])->find();
//halt($user);
//对输入的密码字段进行MD5加密再进行数据库的查询
$salt = substr(md5($user['create_time']),-6);
$pwd = substr_replace(md5($data['password']),$salt,0,6);
$data['password'] = md5($pwd);
if($user['password'] == $data['password']){
//将用户数据写入Session
Session::set('user_id',$user['id']);
Session::set('user_name',$user['name']);
//查询结果1表示有用户用户名密码正确
return 1;
}else{
return '用户名或密码错误';
}
}
//注册校验
public function reg($data)
{
//随机存入默认头像
$code = mt_rand('1','11');
$data['user_img'] = "./static/res/images/avatar/$code.jpg";
$data['create_time'] = time();
$salt = substr(md5($data['create_time']),-6);
$data['password'] = substr_replace(md5($data['password']),$salt,0,6);
$result = $this->save($data);
if ($result) {
return 1;
} else{
return '注册失败';
}
}
//重置密码
public function respass($data)
{ //halt($data);
$user = $this->where('id',$data['uid'])->find();
$salt = substr(md5($user['create_time']),-6);
$data['password'] = substr_replace(md5($data['password']),$salt,0,6);
$result = $user->save($data);
if ($result) {
return 1;
} else{
return '更改失败';
}
}
//更新设置
public function setNew($data)
{
$userId = $data['user_id'];
$user = User::where('id',$userId)->find();
$result = $user->allowField(['email','nickname','sex','city','sign'])->save($data);
if($result){
return 1;
}else{
return '修改失败';
}
}
//用户修改密码
public function setpass($data)
{
$user = $this->find($data['user_id']);
$salt = substr(md5($user['create_time']),-6);
$pwd = substr_replace(md5($data['nowpass']),$salt,0,6);
$data['nowpass'] = md5($pwd);
$result = $data['nowpass'] == $user['password'];
if(!$result){
return '当前密码不正确';
}
$data['password'] = substr_replace(md5($data['password']),$salt,0,6);
$user->password = $data['password'];
$result = $user->save();
if($result){
return 1;
}else{
return '修改失败,请改换密码';
}
}
}

View File

@ -0,0 +1,23 @@
<?php
namespace app\common\model;
use think\Model;
class UserArea extends Model
{
protected $autoWriteTimestamp = true; //开启自动时间戳
protected $createTime = 'create_time';
//软删除
//use SoftDelete;
//protected $deleteTime = 'delete_time';
//protected $defaultSoftDelete = 0;
public function user()
{
//评论关联用户
return $this->belongsTo('User','user_id','id');
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace app\common\model;
use think\Model;
//use think\model\concern\SoftDelete;
class UserZan extends Model
{
protected $autoWriteTimestamp = true; //开启自动时间戳
protected $createTime = 'create_time';
//软删除
//use SoftDelete;
//protected $deleteTime = 'delete_time';
//protected $defaultSoftDelete = 0;
public function comment()
{
//评论关联文章
return $this->belongsTo('Comment','comment_id','id');
}
public function user()
{
//评论关联用户
return $this->belongsTo('User','user_id','id');
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace app\common\validate;
use think\Validate;
class Article extends Validate
{
protected $rule = [
'title|标题' => 'require|min:4|max:50',
'content|内容' => 'require',
'cate_id|分类' => 'require',
'captcha|验证码' => 'require|captcha'
];
public function sceneArtadd()
{
return $this->only(['cate_id','title','content','captcha']);
}
}

View File

@ -0,0 +1,80 @@
<?php
namespace app\common\validate;
use think\Validate;
class User extends Validate
{
protected $rule = [
'name|用户名' => 'require|min:2|max:18|unique:user',
'email|邮箱' => 'require|email|unique:user',
'password|密码' => 'require|min:6|max:20',
'repassword|确认密码'=>'require|confirm:password',
'nickname|昵称' => 'require|min:2|max:20',
'captcha|验证码' => 'require|captcha',
'city|城市' => 'min:2|max:25',
'sign|签名' => 'min:10|max:100',
'sex|性别' => 'require',
'nowpass|新密码' => 'require|min:6|max:20',
'code|校验码' => 'require|length:4',
];
//邮件邮件码验证
public function sceneCode()
{
return $this->only(['code',]);
}
//name登陆验证场景
public function sceneLoginName()
{
return $this->only(['name','password','captcha'])
->remove('name', 'unique');
}
//emai登陆验证场景
public function sceneLoginEmail()
{
return $this->only(['email','password','captcha'])
->remove('email', 'unique');
}
//注册验证场景
public function sceneReg()
{
return $this->only(['name','email','password','repassword','captcha']);
}
//密码找回
public function sceneForget()
{
return $this->only(['email','captcha'])
->remove('email', 'unique');
}
//密码重设
public function sceneRepass()
{
return $this->only(['password','repassword','captcha']);
}
//密码重置
public function sceneRespass()
{
return $this->only(['password','repassword','captcha']);
}
//用户资料
public function sceneSet()
{
return $this->only(['email','nickname','ctity','sex','sign'])
->remove('email','unique');
}
//设置新密码
public function sceneSetpass()
{
return $this->only(['nowpass','password','repassword']);
}
}

17
app/event.php Normal file
View File

@ -0,0 +1,17 @@
<?php
// 事件定义文件
return [
'bind' => [
],
'listen' => [
'AppInit' => [],
'HttpRun' => [],
'HttpEnd' => [],
'LogLevel' => [],
'LogWrite' => [],
],
'subscribe' => [
],
];

1
app/index/controller/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
Api.php

View File

@ -0,0 +1,272 @@
<?php
namespace app\index\controller;
use app\common\controller\BaseController;
use think\facade\View;
use think\facade\Request;
use think\facade\Db;
use app\common\model\Cate;
use app\common\model\User;
use app\common\model\Comment;
use app\common\model\Collection;
use app\common\model\Article as ArticleModel;
use think\exception\ValidateException;
use think\facade\Config;
class Article extends BaseController
{
protected $middleware = [
'logincheck' => ['except' => ['cate','detail'] ],
];
//文章分类
public function cate(){
$where =[];
//获取分类ID
$ename = Request::param('ename');
$cate = Db::name('cate')->where('ename',$ename)->find();
$types = input('type');
if($cate){
$where = ['cate_id' => $cate['id']];
}else{
$where = true;
}
switch ($types) {
//查询文章,10个分1页
case 'all':
$artList = ArticleModel::withCount(['user','cate','comments'])->where('status',1)->where($where)->order(['is_top'=>'desc','create_time'=>'desc'])->paginate(10);
break;
case 'hot':
$artList = ArticleModel::withCount(['user','cate','comments'])->where('status',1)->where($where)->where('is_hot',1)->order(['is_top'=>'desc','create_time'=>'desc'])->paginate(10);
break;
case 'top':
$artList = ArticleModel::withCount(['user','cate','comments'])->where('status',1)->where($where)->where('is_top',1)->order(['is_top'=>'desc','create_time'=>'desc'])->paginate(10);
break;
default:
$artList = ArticleModel::withCount(['user','cate','comments'])->where('status',1)->where($where)->order(['is_top'=>'desc','create_time'=>'desc'])->paginate(10);
break;
}
// 热议文章
$artHot = ArticleModel::withCount('comments')->where('status',1)->whereTime('create_time', 'year')->order('comments_count','desc')->limit(10)->select();
//分类右栏广告
$ad_cate = Db::name('slider')->where('slid_status',1)->where('delete_time',0)->where('slid_type',4)->whereTime('slid_over','>=',time())->select();
//通用右栏
$ad_comm = Db::name('slider')->where('slid_status',1)->where('delete_time',0)->where('slid_type',3)->whereTime('slid_over','>=',time())->select();
View::assign(['type'=>$types,'artList'=>$artList,'artHot'=>$artHot,'ad_cate'=>$ad_cate,'ad_comm'=>$ad_comm]);
return View::fetch();
}
//文章详情页
public function detail($id = 1)
{
//获取文章ID
$id = Request::param('id');
//查询文章
$article = ArticleModel::withCount(['user','cate','comments'])->find($id);
$article->inc('pv')->update();
/*
$nt = time();
$ft = $article->comments;
$ct[] = [];
foreach($ft as $c){
$t = $c->create_time;
$ct[] = intval(($nt - strtotime($t))/86400);
}
dump($nt);
dump($ct);
$this->assign('ct',$ct);
$article->append(['comment.ct'])->toArray();
//halt($article);
*/
// 热议文章
$artHot = ArticleModel::withCount('comments')->where('status',1)->whereTime('create_time', 'year')->order('comments_count','desc')->limit(10)->select();
//文章广告
$ad_article = Db::name('slider')->where('slid_status',1)->where('delete_time',0)->where('slid_type',3)->whereTime('slid_over','>=',time())->select();
//通用右栏
$ad_comm = Db::name('slider')->where('slid_status',1)->where('delete_time',0)->where('slid_type',3)->whereTime('slid_over','>=',time())->select();
View::assign(['article'=>$article,'artHot'=>$artHot,'ad_art'=>$ad_article,'ad_comm'=>$ad_comm]);
return View::fetch();
}
//文章评论
public function comment()
{
//if (Request::isAjax()){
//获取评论
$data = Request::only(['content','article_id','user_id']);
//用户留言存入数据库
if (Comment::create($data)) {
$res = ['code'=>1, 'msg'=>'留言成功'];
} else{
$res = ['code'=>0, 'msg'=>'留言失败'];
}
return json($res);
}
//添加文章
public function add()
{
if(Request::isAjax()){
$data = Request::post();
$validate = new \app\common\validate\Article; //调用验证器
$result = $validate->scene('Artadd')->check($data); //进行数据验证
if(true !==$result){
return $this->error($validate->getError());
} else {
$article = new \app\common\model\Article;
$result = $article->add($data);
if($result == 1) {
$aid = Db::name('article')->max('id');
return json(['code'=>1,'msg'=>'发布成功','url'=>'/'.app('http')->getName().'/jie/'.$aid.'.html']);
} else {
$this->error($result);
}
}
}
return View::fetch();
}
//编辑文章
public function edit()
{
$aid = input('id');
$article = Db::name('article')->find($aid);
if(Request::isAjax()){
$data = Request::post();
$validate = new \app\common\validate\Article(); //调用验证器
$res = $validate->scene('Artadd')->check($data); //进行数据验证
if(true !==$res){
//echo '<script>alert("'.$res.'");location.back()</script>';
return $this->error($validate->getError());
} else {
$article = new \app\common\model\Article;
$result = $article->edit($data);
if($result == 1) {
return json(['code'=>1,'msg'=>'修改成功','url'=>'/'.app('http')->getName().'/jie/'.$aid.'.html']);
} else {
$this->error($result);
}
}
}
View::assign('article',$article);
return View::fetch();
}
//删除文章
public function delete()
{
$article = ArticleModel::find(input('id'));
$result = $article->together(['comments'])->delete();
if($result) {
$res = ['code'=>1,'msg'=>'删除文章成功','url'=>'/index/user/post'];
} else {
$res = ['code'=>0,'msg'=>'删除文章失败'];
}
return json($res);
}
//添加文章和编辑页富文本编辑器图片上传
public function lay_img_upload()
{
$file = Request()->file('file');
if(empty($file)){
$result["code"] = "1";
$result["msg"] = "请选择图片";
$result['data']["src"] = '';
}else{
// 移动到框架应用根目录/public/uploads/ 目录下
$info = $file->move('uploads/' );
if($info){
$infos = $info->getInfo();
// 源文件名
$name = $infos['name'];
$name_path =str_replace('\\',"/",$info->getSaveName());
//成功上传后 获取上传信息
$result["code"] = '0';
$result["msg"] = "上传成功";
$result['data']["src"] = "/uploads/".$name_path;
$result['data']["title"] = $name;
}else{
// 上传失败获取错误信息
$result["code"] = "2";
$result["msg"] = "上传出错";
$result['data']["src"] ='';
}
}
return json_encode($result);
}
//文本编辑器图片上传
public function text_img_upload()
{
$file = request()->file('file');
try {
validate(['image'=>'filesize:2048|fileExt:jpg,png,gif'])
->check(array($file));
$savename = \think\facade\Filesystem::disk('public')->putFile('article_pic',$file);
} catch (think\exception\ValidateException $e) {
echo $e->getMessage();
}
$upload = Config::get('filesystem.disks.public.url');
if($savename){
//$name = $file->hashName();
$name_path =str_replace('\\',"/",$upload.'/'.$savename);
//halt($name_path);
//$image = \think\Image::open("uploads/$name_path");
//$image->thumb(168, 168)->save("uploads/$name_path");
$res = ['status'=>0,'msg'=>'上传成功','url'=> $name_path];
}else{
$res = ['status'=>1,'msg'=>'上传错误'];
}
return json($res);
}
//文章置顶,状态
public function jieset(){
$data = Request::param();
$article = ArticleModel::find($data['id']);
if($data['field'] === 'top') {
if($data['rank']==1){
$article->save(['is_top' => 1]);
$res['status'] = 0;
$res['msg'] ='置顶成功';
} else {
$article->save(['is_top' => 0]);
$res['status'] = 0;
$res['msg'] ='已取消置顶';
}
} else {
if($data['rank']==1){
$article->save(['is_hot' => 1]);
$res['status'] = 0;
$res['msg'] ='已设精贴';
} else {
$article->save(['is_hot' => 0]);
$res['status'] = 0;
$res['msg'] ='精贴已取消';
}
}
return json($res);
}
}

View File

@ -0,0 +1,64 @@
<?php
namespace app\index\controller;
use app\common\controller\BaseController;
use think\facade\Session;
use app\common\model\Collection as CollectionModel;
use app\common\model\Article;
use think\facade\Request;
use think\facade\Db;
class Collection extends BaseController
{
// protected $type = [
// 'cid' => 'integer',
// ];
//文章收藏
public function add(){
//$data = Request::param();
$data['article_id'] = intval(input('cid'));
$data['user_id'] = session::get('user_id');
$result = CollectionModel::create($data);
if($result){
$res['status'] = 0;
//$res=['type' => 'add','type' => 'remove', 'msg' => '收藏成功'];
}
return $res;
}
//取消收藏
public function remove(){
$cid = input('cid');
$aid = intval($cid);
$user['user_id'] = session::get('user_id');
//$result = CollectionModel::where('cid',$arid)->select();
$result = Db::name('collection')->where(['article_id' => $aid,'user_id' => $user['user_id']])->delete();
if($result){
$res['status'] = 0;
//$res=['type' => 'add','type' => 'remove', 'msg' => '收藏成功'];
}
return $res;
}
//收藏查询
public function find(){
//$cid = Request::param();
$cid = input('cid');
$aid = intval($cid);
$user['user_id'] = session::get('user_id');
//halt($artid);
$collectData = Db::name('collection')->where(['article_id' => $aid,'user_id' => $user['user_id']])->find();
if($collectData){
$res['status'] = 0;
$res['data']['collection'] = $collectData['article_id'];
} else {
$res['status'] = 0;
$res['data'] = '';
}
return json($res);
}
}

View File

@ -0,0 +1,109 @@
<?php
namespace app\index\controller;
use app\common\controller\BaseController;
use think\facade\Session;
use app\common\model\Comment as CommentModel;
use app\common\model\Article;
use app\common\model\UserZan;
use think\facade\Request;
use think\Db;
class Comment extends BaseController
{
//采纳评论
public function jiedaCai(){
$id = input('id');
$comms = CommentModel::find($id);
$result = $comms->save(['cai' =>1]);
$res = [];
if($result){
$art = Article::find($comms['article_id']);
$jie = $art->save(['jie' => 1]);
if($jie){
$res['status'] = 0;
}
}
return json($res);
}
//删除评论
public function jiedaDelete(){
$id = input('id');
//$arid = intval($id);
$comms = CommentModel::find($id);
$result = $comms->delete();
//$result = Db::name('collection')->where('article_id',$arid)->delete();
if($result){
//$res=['type' => 'add','type' => 'remove', 'msg' => '收藏成功'];
$res = [
'status' => 0,
];
}
return json($res);
}
//编辑评论
public function getDa()
{
$this->isLogin();
$id = input('id');
$comms = CommentModel::find($id);
$res['rows'] = [];
if($comms) {
$res['status'] = 0;
$res['rows']['content'] = $comms['content'];
}
return json($res);
}
//更新评论
public function updateDa()
{
$this->isLogin();
$id = input('id');
$content = input('content');
$comms = CommentModel::find($id);
$result = $comms->save(['content' => $content]);
if($result) {
$res['status'] = 0;
$res['msg'] = '更新成功';
} else {
$res['msg'] = '更新失败';
}
return json($res);
}
//点赞评论
public function jiedaZan()
{
$this->isLogin();
$data['comment_id'] = input('post.id');
$data['user_id'] = session('user_id');
//查询是否已存在点赞
$zan = UserZan::where(['comment_id'=>input('post.id'),'user_id'=>session('user_id')])->find();
Session::set('ok',$zan['comment_id']);
if(!$zan ){ //如果没有点过赞执行点赞操作
$coms = CommentModel::find(input('post.id'));
if($coms['user_id'] == session('user_id')){
return $res=['msg' => '不能给自己点赞哦'];
} else {
$res = UserZan::create($data);
if($res){
//评论点赞数加1
$coms->save(['zan' => $coms['zan']+1]);
return $res=['status' => 0, 'msg' => '点赞成功'];
}else {
$this->error('点赞失败');
}
}
} else {
return $res=['msg' => '你已赞过了'];
}
}
}

View File

@ -0,0 +1,10 @@
<?php
namespace app\index\controller;
class Error
{
public function __call($method, $args)
{
return 'error request!';
}
}

View File

@ -0,0 +1,13 @@
<?php
namespace app\index\controller;
use app\common\controller\BaseController;
class FriendLink extends BaseController
{
public function link()
{
}
}

View File

@ -0,0 +1,128 @@
<?php
namespace app\index\controller;
use app\common\controller\BaseController;
use think\facade\View;
use think\facade\Request;
use think\facade\Db;
use app\common\model\Article;
use app\common\model\User;
use app\common\model\Cate;
use app\common\model\Comment;
class Index extends BaseController
{
public function index()
{
//幻灯
$sliders = Db::name('slider')->where('slid_status',1)->where('delete_time',0)->where('slid_type',1)->whereTime('slid_over','>=',time())->select();
//置顶文章
$artTop = Article::where(['is_top'=>1,'status'=>1,'delete_time'=>0])->with([
'cate' => function($query){
$query->where('delete_time',0);
}
])->with(['user'])->withCount(['comments'])->order('create_time','desc')->limit(5)->select();
//查询首页文章显示15条
$types = input('type');
$artList = Article::withCount(['user','cate','comments'])->where(['status'=>1,'delete_time'=>0])->order('create_time','desc')->limit(15)->select();
//热议文章
$artHot = Article::withCount('comments')->field('title,comments_count')->where(['status'=>1,'delete_time'=>0])->whereTime('create_time', 'year')->order('comments_count','desc')->limit(10)->select();
//首页赞助
$ad_index = Db::name('slider')->where('slid_status',1)->where('delete_time',0)->where('slid_type',2)->whereTime('slid_over','>=',time())->select();
//首页右栏
$ad_comm = Db::name('slider')->where('slid_status',1)->where('delete_time',0)->where('slid_type',3)->whereTime('slid_over','>=',time())->select();
//友情链接
$friend_links = Db::name('friend_link')->field('linkname,linksrc')->select();
$vs = [
'slider' => $sliders,
'artTop' => $artTop,
'artList' => $artList,
'artHot' => $artHot,
'type' => $types,
'ad_index' => $ad_index,
'ad_comm' => $ad_comm,
'flinks' => $friend_links,
];
View::assign($vs);
return View::fetch();
}
//回帖榜
public function reply()
{
$user = User::withCount('comments')->order('comments_count','desc')->limit(20)->select();
if($user)
{
$res['status'] = 0;
$res['data'] = array();
foreach ($user as $key=>$v) {
$u['uid'] = $v['id'];
$u['count(*)'] = $v['comments_count'];
if($v['nickname'])
{
$u['user'] = ['username'=>$v['nickname'],'avatar'=>$v['user_img']];
} else {
$u['user'] = ['username'=>$v['name'],'avatar'=>$v['user_img']];
}
$res['data'][] = $u;
}
}
return json($res);
}
//搜索功能
public function search()
{
//$this->showUser();
//全局查询条件
$map = []; //所有的查询条件封装到数组中
//条件1
$map[] = ['status','=',1]; //这里等号不能省略
//实现搜索功能
$keywords = input('keywords');
if(!empty($keywords)){
//条件2
$map[] = ['title','like','%'.$keywords.'%'];
$artList = Article::where($map)->withCount('comments')->order('create_time','desc')->paginate(10);
$counts = $artList->count();
$searchs = [
'artList' => $artList,
'keywords' => $keywords,
'counts' => $counts
];
View::assign($searchs);
//友情链接
$friend_links = Db::name('friend_link')->field('linkname,linksrc')->select();
View::assign('flinks',$friend_links);
// 查询热议
$artHot = Article::withCount('comments')->field('title,comments_count')->where('status',1)->whereTime('create_time', 'year')->order('comments_count','desc')->limit(10)->select();
View::assign('artHot',$artHot);
} else{
return '请输入关键词';
}
return View::fetch('search');
}
public function jump()
{
$username = Request::param('username');
$u = Db::name('user')->whereOr('nickname', $username)->whereOr('name', $username)->find();
return redirect('index/user/home',['id'=>$u['id']]);
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace app\index\controller;
use app\common\controller\BaseController;
use think\facade\Request;
use think\facade\Session;
use think\facade\Cache;
use think\Db;
class User extends BaseController
{
//用户中心
public function username()
{
$user['user_id'] = session::get('user_id');
$username = session::get('user_name');
$u = Request::param('username');
//halt($u);
return view();
}
}

View File

@ -0,0 +1,187 @@
<?php
namespace app\index\Controller;
use app\common\controller\BaseController;
use app\common\validate\User as userValidate;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\Request;
use think\facade\Session;
use think\facade\Cookie;
use think\facade\Cache;
use think\facade\View;
use app\common\model\User as userModel;
class Login extends BaseController
{
//已登陆检测
protected $middleware = ['logedcheck'];
//用户登陆
public function index()
{
//var_dump($_SERVER);
if(Request::isAjax()) {
$data = Request::param();
//邮箱正则表达式
$pattern = "/^([0-9A-Za-z\\-_\\.]+)@([0-9a-z]+\\.[a-z]{2,3}(\\.[a-z]{2})?)$/i";
//判断输入的是邮箱还是用户名
if (preg_match($pattern, $data['name'])){
$data['email'] = $data['name'];
unset($data['name']);
//输入邮箱email登陆验证
try{
validate(userValidate::class)
->scene('loginEmail')
->check($data);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return json(['code'=>0,'msg'=>$e->getError()]);
}
$data['name'] = $data['email'];
unset($data['email']);
} else {
//用户名name登陆验证
try{
validate(userValidate::class)
->scene('loginName')
->check($data);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return json(['code'=>0,'msg'=>$e->getError()]);
}
}
//登陆请求
$user = new \app\common\model\User();
$res = $user->login($data);
if ($res == 1) {
return json(['code'=>'1','msg'=>'登陆成功','url'=>'/index/index/index']);
} else {
return json(['code'=>'0','msg'=>$res]);
}
}
return View::fetch('login');
}
//注册
public function reg()
{
if(Request::isAjax()){
$data = Request::only(['name','email','password','repassword','captcha']);
//校验场景中reg的方法数据
try{
validate(userValidate::class)
->scene('Reg')
->check($data);
} catch (ValidateException $e) {
return json(['code'=>0,'msg'=>$e->getError()]);
}
$user = new userModel;
$result = $user->reg($data);
if ($result == 1) {
$res = ['code'=>1,'msg'=>'注册成功','url'=>'/index/login/index'];
}else {
$res = ['code'=>0,'msg'=>$result];
}
return json($res);
}
//加载注册模板
return View::fetch();
}
//找回密码
public function forget()
{
if(Request::isAjax()){
$data = Request::param();
try{
validate(userValidate::class)
->scene('Forget')
->check($data);
} catch (ValidateException $e) {
return json(['code'=>0,'msg'=>$e->getError()]);
}
//查询用户
$user = Db::name('user')->where('email',$data['email'])->find();
if($user) {
$code = mt_rand('1111','9999');
Cache::set('code',$code,600);
Cache::set('userid',$user['id'],600);
$result = mailto($data['email'],'重置密码','Hi亲爱的'.$user['name'].':</br>您正在维护您的信息请在10分钟内验证您的验证码为:'.$code);
if($result){
Cache::set('repass',1,60); //设置repass标志为1存入Cache
$res = ['code'=>1,'msg'=>'验证码已发送成功,请去邮箱查看!','url'=>'/index/login/postcode'];
} else {
$res = ['code'=>0,'msg'=>'验证码发送失败!'];
}
}else{
$res = ['code' =>0,'msg'=>'邮箱错误或不存在'];
}
return json($res);
}
return View::fetch();
}
//接收验证码
public function postcode()
{
if(Cache::get('repass') != 1){
return json(['code'=>0,'msg'=>'请求错误!','url'=>'/index/login/forget']);
}
if(Request::isAjax()){
$code = Request::only(['code']);
try{
validate(userValidate::class)
->scene('Code')
->check($code);
} catch (ValidateException $e) {
return json(['code'=>0,'msg'=>$e->getError()]);
}
if(Cache::get('code')==$code['code']) { //无任何输入情况下需排除code为0和Cache为0的情况
//Cache::delete('repass');
Cache::set('repass',2,60);
$res = ['code'=>'1','msg'=>'验证成功','url'=>'/index/login/respass'];
} else {
$res = ['code'=>0,'msg'=>'验证码错误或已过期!'];
}
return json($res);
}
return View::fetch('forget');
}
//忘记密码找回重置
public function respass()
{
if(Cache::get('repass') != 2){
return json(['code'=>0,'msg'=>'请求错误!','url'=>'/index/login/forget']);
}
if(Request::isAjax()){
$data = Request::param();
try{
validate(userValidate::class)
->scene('Repass')
->check($data);
} catch (ValidateException $e) {
return json(['code'=>0,'msg'=>$e->getError()]);
}
$data['uid'] = Cache::get('userid');
$user = new \app\common\model\User();
$res = $user->respass($data);
if ($res == 1) {
return json(['code'=>'1','msg'=>'修改成功','url'=>'/index/login/index']);
} else {
return json(['code'=>'0','msg'=>'$res']);
}
}
return View::fetch('forget');
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace app\index\controller;
use app\common\controller\BaseController;
use think\facade\Session;
use think\facade\Request;
use think\Db;
class Message extends BaseController
{
//消息
public function nums(){
//$res['status'] = 0;
$res=['status' =>0,'count' => 0, 'msg' => 'nums'];
return $res;
}
}

View File

@ -0,0 +1,268 @@
<?php
namespace app\index\controller;
use app\common\controller\BaseController;
use app\common\model\User;
use think\facade\Session;
use think\facade\Db;
use think\facade\View;
use think\Collection;
use think\Response;
class Sign extends BaseController
{
protected $uid;
protected function _initialize()
{
parent::_initialize();
$this->uid = session('user_id');
}
public function lists()
{
//总榜
$totallist = Db::name('user_sign')->alias('s')->join('user u', 's.uid=u.id', 'LEFT')->field('s.uid,s.id,max(s.days) as days,u.name as name,u.user_img as user_img')->group('s.uid')->order('days desc')->limit(20)->select();
$time = time();
$start_stime = strtotime(date('Y-m-d 0:0:0', $time)) - 1;
$end_stime = strtotime(date('Y-m-d 23:59:59', $time)) + 1;
//今日最快
$fastlist = Db::name('user_sign')->alias('s')->join('user u', 's.uid=u.id')->field('s.*,u.name as name,u.user_img as user_img')->where("s.stime > $start_stime and s.stime < $end_stime")->order('s.id asc')->limit(20)->select();
//最新
$newlist = Db::name('user_sign')->alias('s')->join('user u', 's.uid=u.id')->field('s.*,u.name as name,u.user_img as user_img')->order('id desc')->limit(20)->select();
View::assign('totallist', $totallist);
View::assign('fastlist', $fastlist);
View::assign('newlist', $newlist);
return View::fetch();
}
/**
* 执行当天签到
* @return json 签到成功返回 {status:1,info:'已签到'}
*/
public function sign()
{
if (!Session::has('user_id') || !Session::has('user_name')) {
return json(array('code' => 0, 'msg' => '亲,登陆后才能签到哦','url' => 'index/login/index'));
} else {
$uid = session('user_id');
$todayData = $this->todayData()->getData();
//var_dump($todayData);
if ($todayData['is_sign'] == 1) { //数组中是返回的是一个对象,不能直接用[]来显示,正确的输出方法是:$pic[0]->title问题解决
exit('{"code":-1,"msg":"你今天已经签过到了"}');
} else {
$data = $this->getInsertData($uid);
$days = $data['days'];
// 无今天数据
$data['uid'] = $uid;
$data['stime'] = time();
$id = Db::name('user_sign')->insertGetId($data);
if ($id) {
//$will_getscore
//$score = $this->getTodayScores($days);
$score = $todayData['will_getscore'];
$date=date('Ymd');
$msg='';
$teshudate=['20180215','20180216','20180217','20180218','20180219','20180220','20180221'];
//签到奖励
if(in_array($date,$teshudate)){
$randnum=rand(1,99);
$msg='新年好!您额外获得随机奖励'.$randnum.'金币!';
point_note($randnum, $uid, 'NewYearReward', $id);
}
session('signdate', $date);
if ($score > 0) {
// 为该用户添加积分
$user = User::find($uid);
$point = $user['point']+$score;
$user->save(['point' => $point]);
//point_note($score, $uid, $id);
}
return json(['code'=>200,'score'=>$score,'days'=>$days,'msg'=>$msg]);
// exit('{"code":200,"score":"' . $score . '","days":"' . $days . '"}');
} else {
exit('{"code":-1,"msg":"签到失败,请刷新后重试!"}');
}
}
}
}
/**
* 返回每次签到要插入的数据
*
* @param int $uid 用户id
* @return array(
* 'days' => '天数',
* 'is_sign' => '昨天是否签到,用1表示已经签到',
* 'stime' => '签到时间',
* );
*/
protected function getInsertData($uid)
{
// 昨天的连续签到天数
$start_time = strtotime(date('Y-m-d 0:0:0', time() - 86400)) - 1;
$end_time = strtotime(date('Y-m-d 23:59:59', time() - 86400)) + 1;
$days = Db::name('user_sign')->where("uid = $uid and stime > $start_time and stime < $end_time")->value('days');
if ($days) {
$days++;
$is_sign = 1;
$time = time();
// if($days > 30){
// $days = 1;
// }
} else {
//$days=1;
$is_sign = 0;
$days = 1;
$time = '';
}
return [
'days' => $days,
'is_sign' => $is_sign,
'stime' => $time,
];
}
/**
* 用户当天签到的数据
* @return array 签到信息 is_sign,stime
*/
public function todayData()
{
$time = time();
$start_stime = strtotime(date('Y-m-d 0:0:0', $time)) - 1;
$end_stime = strtotime(date('Y-m-d 23:59:59', $time)) + 1;
$res = Db::name('user_sign')->where('uid',session('user_id'))->where('stime', '>', $start_stime)->where('stime', '<', $end_stime)->find();
$score = 0;
if ($res) {
$is_sign = 1;
//昨天已签到
//已连续签到 已获取
$days = $res['days'];
$score = $this->getTodayScores($res['days']);
$will_getscore = $this->getTodayScores($res['days'] + 1);
} else {
//今天没有签,看昨天
$is_sign = 0;
$yestoday = $this->getInsertData(session('user_id'));
if ($yestoday['is_sign']) {
//今天连续天数
$days = $yestoday['days'] - 1;
$will_getscore = $this->getTodayScores($yestoday['days']);
} else {
//今天第一天
$days = 0;
$will_getscore = $this->getTodayScores(1);
}
//已连续签到 可获取
$score = $this->getTodayScores($days);
}
$data = [
'is_sign' => $is_sign,
'days' => $days,
'score' => $score,
'will_getscore' => $will_getscore,
];
return json($data);
}
/**
* 积分规则,返回连续签到的天数对应的积分
*
* @param int $days 当天应该得的分数
* @return int 积分
*/
protected function getTodayScores($days)
{
$score = 0;
$scores = Db::name('user_signrule')->where("days <= $days")->order('days desc')->limit(1)->value('score');
if ($scores) {
$score = $scores;
}
return $score;
}
public function getsignrule()
{
$rules = Db::name('user_signrule')->order('days asc')->select();
return json(array('code' => 200, 'msg' => $rules));
}
/**
* 显示签到列表
*
* @param array $signDays 某月签到的日期 array(1,2,3,4,5,12,13)
* @param int $year 可选,年份
* @param int $month 可选,月份
* @return string 日期列表<li>1</li>....
*/
public function showDays($signDays, $year = '', $month = '')
{
$time = time();
$year = $year ? $year : date('Y', $time);
$month = $month ? $month : date('m', $time);
$daysTotal = date('t', mktime(0, 0, 0, $month, 1, $year));
$now = date('Y-m-d', $time);
$str = '';
// $i=0;
for ($j = 1; $j <= $daysTotal; $j++) {
// $i++;
$someDay = date('Y-m-d', strtotime("$year-$month-$j"));
// 小于今天的日期样式
if ($someDay <= $now) {
// 当天日期样式 tdc = todayColor
if ($someDay == $now) {
// 当天签到过的
if (in_array($j, $signDays)) {
$str .= '<li class="current fw tdc">' . $j . '</li>';
} else {
$str .= '<li class="today fw tdc">' . $j . '</li>';
}
} else {
// 签到过的日期样式 current bfc = beforeColor , fw = font-weight
if (in_array($j, $signDays)) {
$str .= '<li class="current fw bfc">' . $j . '</li>';
} else {
$str .= '<li class="fw bfc">' . $j . '</li>';
}
}
} else {
$str .= '<li>' . $j . '</li>';
}
}
return $str;
}
/**
* 获取当月签到的天数,与 $this->showDays() 配合使用
* @return 当月签到日期 array(1,2,3,4,5,12,13)
*/
public function getMonthSign()
{
$time = time();
$year = date('Y', $time);
$month = date('m', $time);
$day = date("t", strtotime("$year-$month"));
$start_stime = strtotime("$year-$month-1 0:0:0") - 1;
$end_stime = strtotime("$year-$month-$day 23:59:59") + 1;
$list = Db::name('user_sign')->where("uid = {$this->uid} and stime > $start_stime and stime < $end_stime")->order('stime asc')->column('stime');
//if(is_array($list)){
foreach ($list as $key => $value) {
$list[$key] = date('j', $value);
}
//}
//return $list;
return json_encode($list);
}
}

View File

@ -0,0 +1,198 @@
<?php
namespace app\index\controller;
use app\common\controller\BaseController;
use app\common\validate\User as userValidate;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\Request;
use think\facade\Session;
use think\facade\Cookie;
use think\facade\Cache;
use think\facade\View;
use app\common\model\Article;
use app\common\model\Collection;
use app\common\model\User as userModel;
use think\facade\Config;
class User extends BaseController
{
protected $middleware = [
'logincheck' => ['except' => ['home'] ],
];
//用户中心
public function index()
{
//$this->isLogin();
$user['user_id'] = session::get('user_id');
$username = session::get('user_name');
return view();
}
//文章管理
public function post()
{
//发表的帖子
$user['user_id'] = session::get('user_id');
$username = session::get('user_name');
$article = Article::withCount('comments')->where('user_id',$user['user_id'])->order('update_time','desc')->paginate([
'list_rows'=>10,
'page',
'path' => 'post',
'fragment' => 'index',
'var_page' => 'page',
]);
$page = $article->render();
View::assign(['article'=>$article,'page'=>$page]);
//收藏的帖子
$collect = Collection::with('article')->where('user_id',$user['user_id'])->order('create_time','desc')->paginate(10);
$count =$collect->total();
View::assign(['collect'=>$collect,'count'=>$count]);
return View::fetch();
}
//取消文章收藏
public function colltDel()
{
$collt = Collection::where('article_id',input('id'))->where('user_id',session::get('user_id'))->find();
$result = $collt->delete();
if($result){
$this->success('取消成功');
} else {
$this->error('取消失败了');
}
}
//用户设置-我的资料
public function set()
{
if(Request::isAjax()){
$data = Request::param();
$validate = new \app\common\validate\User();
$result = $validate->scene('Set')->check($data);
if(!$result){
$this->error($validate->getError());
} else {
$user = new \app\common\model\User();
$result = $user->setNew($data);
if($result==1){
return ['code'=>1,'msg'=>'资料更新成功','url'=>'/index/user/set'];
} else {
$this->error($result);
}
}
}
return View::fetch();
}
//更换头像
public function uploadHeadImg()
{
$file = request()->file('file');
try {
validate(['image'=>'filesize:2048|fileExt:jpg,png,gif|image:200,200,jpg'])
->check(array($file));
$savename = \think\facade\Filesystem::disk('public')->putFile('head_pic',$file);
} catch (think\exception\ValidateException $e) {
echo $e->getMessage();
}
$upload = Config::get('filesystem.disks.public.url');
if($savename){
//$name = $file->hashName();
$name_path =str_replace('\\',"/",$upload.'/'.$savename);
//$image = \think\Image::open("uploads/$name_path");
//$image->thumb(168, 168)->save("uploads/$name_path");
//查出当前用户并把得到的用户头像更新
$userId = Session::get('user_id');
$result = Db::name('user')
->where('id',$userId)
->update(['user_img'=>$name_path]);
if($result) {
$res = ['status'=>0,'msg'=>'头像更新成功'];
} else {
$res = ['status'=>1,'msg'=>'头像更新失败'];
}
}else{
$res = ['status'=>1,'msg'=>'上传错误'];
}
return json($res);
}
public function message()
{
return view();
}
//个人页
public function home()
{
$userID = input('id');
Session::get('user_id');
//用户
$u = Db::name('user')->field('name,nickname,city,sex,sign,user_img,point,create_time')->find($userID ?: Session::get('user_id'));
//用户发贴
$arts = Db::name('user')->alias('u')->join('article a','u.id = a.user_id')->field('u.id,a.id,a.title,a.pv,a.is_hot,a.create_time')->where('a.user_id',input('id') ?: Session::get('user_id'))->select();
//用户回答
$reys = Db::name('comment')->alias('c')->join('article a','c.article_id = a.id')->field('a.id,a.title,c.content,c.create_time')->where('c.user_id',input('id') ?: Session::get('user_id'))->select();
View::assign('u',$u);
View::assign('arts',$arts);
View::assign('reys',$reys);
return View::fetch();
}
public function layout()
{
return View::fetch();
}
//邮箱激活
public function activate()
{
$this->isLogin();
$user['user_id'] = session::get('user_id');
$user = UserModel::find($user['user_id']);
$this->assign('user',$user);
return view();
}
//修改密码
public function setpass()
{
if(Request::isAjax()){
$data = Request::param();
$validate = new \app\common\validate\User();
$res = $validate->scene('setPass')->check($data);
if(!$res){
return $this->error($validate->getError());
}
$user = new \app\common\model\User();
$result = $user->setpass($data);
if($result == 1) {
Session::clear();
return $this->success('密码修改成功 请登录', '/index/user/login');
} else {
return $this->error($result);
}
}
}
//退出账户
public function logout()
{
Session::clear();
return json(array('code' => 200, 'msg' => '退出成功'));
}
}

7
app/index/middleware.php Normal file
View File

@ -0,0 +1,7 @@
<?php
return [
//app\middleware\LoginCheck::class,
//app\middleware\CheckRegister::class,
//'logedcheck' => \app\middleware\logedCheck::class,
];

153
app/install/common.php Normal file
View File

@ -0,0 +1,153 @@
<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------
// 检测环境是否支持可写
//define('IS_WRITE', true);
use Think\Request;
use think\facade\Session;
use think\facade\Config;
use think\facade\Env;
/**
* 写入配置文件
* @param array $config 配置信息
* @return string
*/
function write_config($config)
{
if (is_array($config)) {
//读取配置内容
$conf = file_get_contents(Env::get('module_path') . 'data/database.tpl');
//替换配置项
foreach ($config as $name => $value) {
$conf = str_replace("[{$name}]", $value, $conf);
}
//写入应用配置文件
if (file_put_contents(Env::get('config_path') . 'database.php', $conf)) {
show_msg('配置文件写入成功!');
} else {
show_msg('配置文件写入失败!', 'error');
Session::set('error', true, 'install');
}
return true;
}
}
/**
* 创建数据表
* @param resource $db 数据库连接资源
* @param string $prefix
*/
function create_tables($db, $prefix = '') {
// 导入sql数据并创建表
$sql = file_get_contents('../app/install/data/taoler.sql');
//替换表前缀
$orginal = 'tao_';
($orginal==$prefix) ? true : $sql = str_replace(" `{$orginal}", " `{$prefix}", $sql);
$sql_array=preg_split("/;[\r\n]+/", $sql);
//开始安装
//var_dump($sql_array);
foreach ($sql_array as $k => $v) {
if (!empty($v)) {
//$v=$v.';';
if (substr($v, 0, 12) == 'CREATE TABLE') {
//echo 'ddddddddddddddddd';
$name = preg_replace("/^CREATE TABLE `(\w+)` .*/s", "\\1", $v);
$msg = "创建数据表{$name}";
if (false !== $db->query($v)) {
//show_msg($msg . '...成功!');
//echo '成功';
} else {
echo '失败';
//show_msg($msg . '...失败!', 'error');
//Session::set('error', true, 'install');
}
} else {
$db->query($v);
}
//echo substr($v, 0, 12).'--';
// $db->query($v);
}
}
}
function register_administrator($db, $prefix, $admin) {
//show_msg('开始注册创始人帐号...');
$password = password_hash($admin['password'], PASSWORD_DEFAULT);
$sql="INSERT INTO {$prefix}user(group_id,username,password,email,create_time) VALUE(1,'{$admin['username']}','{$password}','{$admin['email']}','{time()}')";
//执行sql
$db->execute($sql);
//show_msg('创始人帐号注册完成!');
}
/**
* 更新数据表
* @param resource $db 数据库连接资源
* @param string $prefix
* @author lyq <605415184@qq.com>
*/
function update_tables($db, $prefix = '') {
//读取SQL文件
$sql = file_get_contents(APP_PATH . 'install/data/update.sql');
$sql = str_replace("\r", "\n", $sql);
$sql = explode(";\n", $sql);
//替换表前缀
$sql = str_replace(" `tao_", " `{$prefix}", $sql);
//开始安装
show_msg('开始升级数据库...');
foreach ($sql as $value) {
$value = trim($value);
if (empty($value)) {
continue;
}
if (substr($value, 0, 12) == 'CREATE TABLE') {
$name = preg_replace("/^CREATE TABLE `(\w+)` .*/s", "\\1", $value);
$msg = "创建数据表{$name}";
if (false !== $db->execute($value)) {
show_msg($msg . '...成功!');
} else {
show_msg($msg . '...失败!', 'error');
Session::set('error', true, 'install');
}
} else {
if (substr($value, 0, 8) == 'UPDATE `') {
$name = preg_replace("/^UPDATE `(\w+)` .*/s", "\\1", $value);
$msg = "更新数据表{$name}";
} else if (substr($value, 0, 11) == 'ALTER TABLE') {
$name = preg_replace("/^ALTER TABLE `(\w+)` .*/s", "\\1", $value);
$msg = "修改数据表{$name}";
} else if (substr($value, 0, 11) == 'INSERT INTO') {
$name = preg_replace("/^INSERT INTO `(\w+)` .*/s", "\\1", $value);
$msg = "写入数据表{$name}";
}
if (($db->execute($value)) !== false) {
show_msg($msg . '...成功!');
} else {
show_msg($msg . '...失败!', 'error');
Session::set('error', true, 'install');
}
}
}
}
/**
* 及时显示提示信息
* @param string $msg 提示信息
* @param string $class
* @param string $jump
*/
function show_msg($msg, $class = '',$jump='') {
echo "<script type=\"text/javascript\">showmsg(\"{$msg}\", \"{$class}\",\"{$jump}\")</script>";
flush();
ob_flush();
}

View File

@ -0,0 +1,26 @@
<?php
return [
// 数据库连接配置信息
'connections' => [
'install' => [
// 数据库类型
'type' => 'mysql',
// 服务器地址
'hostname' => '127.0.0.1',
// 数据库名
'database' => '',
// 用户名
'username' => 'root',
// 密码
'password' => '',
// 端口
'hostport' => '3306',
// 数据库连接参数
'params' => [],
// 数据库编码默认采用utf8
'charset' => 'utf8',
// 数据库表前缀
'prefix' => 'tao_',
],
],
];

View File

@ -0,0 +1,207 @@
<?php
namespace app\install\controller;
use app\common\controller\BaseController;
use think\facade\View;
use think\facade\Db;
use think\facade\Request;
use think\facade\Session;
class Index extends BaseController
{
/**
* 安装向导
*/
// 检测是否安装过
protected function initialize(){
if(is_file('../install.lock')){
echo "<script>alert('已经成功安装了TaoLer社区系统安装系统已锁定。如需重新安装请删除根目录下的install.lock文件')</script>";
die();
}
}
//安装首页
public function index()
{
Session::set('agre',true);
return View::fetch('agreement');
}
//test
public function test()
{
if(Session::pull('agre')){
Session::set('cre',true);
return View::fetch('test');
} else {
return 'error,请返回安装!';
}
}
//test
public function create(){
if(Session::pull('cre')){
Session::set('suc',true);
return View::fetch('create');
} else {
return 'error,请返回安装!';
}
}
// 安装成功页面
public function complete(){
if(Session::has('suc') != 'true'){
return 'error,请返回安装!';
}
// 判断是否为post
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$data = $_POST;
//var_dump($data);
if (!preg_match("/^[a-zA-Z]{1}([0-9a-zA-Z]|[._]){4,19}$/", $data['admin_user'])) {
die("<script>alert('后台管理用户名不符合规范至少包含4个字符需以字母开头');history.go(-1)</script>");
}
if (!preg_match("/^[\@A-Za-z0-9\!\#\$\%\^\&\*\.\~]{6,22}$/", $data['admin_pass'])) {
die("<script>alert('登录密码至少包含6个字符。可使用字母数字和符号。');history.go(-1)</script>");
}
if ($data['admin_pass'] != $data['admin_pass2']) {
die("<script>alert('两次输入的密码不一致');history.go(-1)</script>");
}
$_SESSION['adminusername'] = $data['admin_user'];
// 生成管理员
$username = $data['admin_user'];
$create_time = time();
$salt = substr(md5($create_time),-6);
$pass = md5(substr_replace(md5($data['admin_pass']),$salt,0,6));
if ($data['DB_TYPE'] == 'mysql') {
//数据库
$db_s = <<<php
<?php
return [
// 数据库连接配置信息
'connections' => [
'install' => [
// 数据库类型
'type' => 'mysql',
// 服务器地址
'hostname' => '{$data['DB_HOST']}',
// 数据库名
'database' => '{$data['DB_NAME']}',
// 用户名
'username' => '{$data['DB_USER']}',
// 密码
'password' => '{$data['DB_PWD']}',
// 端口
'hostport' => '{$data['DB_PORT']}',
// 数据库连接参数
'params' => [],
// 数据库编码默认采用utf8
'charset' => 'utf8',
// 数据库表前缀
'prefix' => '{$data['DB_PREFIX']}',
],
],
];
php;
// 创建数据库链接配置文件
$fp = fopen('../app/install/config/database.php', "r+b");
fputs($fp, $db_s);
fclose($fp);
$db = Db::connect('install');
//var_dump($db);
$sql = 'CREATE DATABASE IF NOT EXISTS '.$data['DB_NAME'].' DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci';
//$db->execute($sql);
//创建数据表
create_tables($db, $data['DB_PREFIX']);
//管理员
$table_admin = $data['DB_PREFIX'] . "admin";
$table_user = $data['DB_PREFIX'] . "user";
$sql_admin = "UPDATE $table_admin SET username = '{$username}', password = '{$pass}', status=1,create_time = '{$create_time}' WHERE id = 1";
$sql_user = "UPDATE $table_user SET name = '{$username}', password = '{$pass}', status=1, auth=1, create_time = '{$create_time}' WHERE id = 1";
$db->execute($sql_admin);
$db->execute($sql_user);
Db::getConnection()->close();
}
$db_str = <<<php
<?php
return [
// 自定义时间查询规则
'time_query_rule' => [],
// 自动写入时间戳字段
// true为自动识别类型 false关闭
// 字符串则明确指定时间字段类型 支持 int timestamp datetime date
'auto_timestamp' => true,
// 时间字段取出后的默认时间格式
'datetime_format' => 'Y-m-d H:i:s',
// 数据库连接配置信息
'connections' => [
'mysql' => [
// 数据库类型
'type' => 'mysql',
// 服务器地址
'hostname' => '{$data['DB_HOST']}',
// 数据库名
'database' => '{$data['DB_NAME']}',
// 用户名
'username' => '{$data['DB_USER']}',
// 密码
'password' => '{$data['DB_PWD']}',
// 端口
'hostport' => '{$data['DB_PORT']}',
// 数据库连接参数
'params' => [],
// 数据库编码默认采用utf8
'charset' => 'utf8',
// 数据库表前缀
'prefix' => '{$data['DB_PREFIX']}',
// 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)
'deploy' => 0,
// 数据库读写是否分离 主从式有效
'rw_separate' => false,
// 读写分离后 主服务器数量
'master_num' => 1,
// 指定从服务器序号
'slave_no' => '',
// 是否严格检查字段是否存在
'fields_strict' => true,
// 是否需要断线重连
'break_reconnect' => false,
// 监听SQL
'trigger_sql' => true,
// 开启字段缓存
'fields_cache' => false,
// 字段缓存路径
'schema_cache_path' => app()->getRuntimePath() . 'schema' . DIRECTORY_SEPARATOR,
],
],
];
php;
// 创建数据库链接配置文件
$fp = fopen('../config/database.php', "r+b");
fwrite($fp, $db_str);
fclose($fp);
file_put_contents('../install.lock', 'lock');
Session::clear();
return View::fetch('complete');
} else {
return '安装失败';
}
}
}

557
app/install/data/taoler.sql Normal file

File diff suppressed because one or more lines are too long

10
app/middleware.php Normal file
View File

@ -0,0 +1,10 @@
<?php
// 全局中间件定义文件
return [
// 全局请求缓存
// \think\middleware\CheckRequestCache::class,
// 多语言加载
// \think\middleware\LoadLangPack::class,
// Session初始化
\think\middleware\SessionInit::class
];

51
app/middleware/Auth.php Normal file
View File

@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
namespace app\middleware;
use xiaodi\Auth as UserAuth;
use think\facade\Session;
class Auth
{
/**
* 处理请求
*
* @param Request $request
* @param \Closure $next
* @return Response
*/
public function handle($request, \Closure $next)
{
//halt($request->pathinfo());
$response = $next($request);
if($request->controller() !== 'Login' && $request->action() !=='logout')
{
//登陆检验
if (!Session::has('admin_id')) {
return redirect('/admin/login/index');
}
$app = app('http')->getName();
$controller = $request->controller();
$action = $request->action();
// 排除权限
$not_check = ['admin/Index/index','admin/Index/home','admin/Set/info','admin/Set/password','admin/User/logout'];
if (!in_array($app . '/' . $controller . '/' . $action, $not_check)) {
$auth = new UserAuth();
$admin_id = Session::get('admin_id');
if (!$auth->check($app . '/' . $controller . '/' . $action, $admin_id) && $admin_id != 1) {
//return response('<script>alert("没有权限");location.back()</script>');
return response('没有权限');
}
}
}
return $response;
}
}

View File

@ -0,0 +1,23 @@
<?php
namespace app\middleware;
use think\facade\Db;
use think\facade\Request;
class CheckRegister
{
public function handle($request, \Closure $next)
{
//排除特殊注册用户名
if($request->action(true)=='reg'){
$disname = Db::name('system')->where('id',1)->value('blackname');
$data = explode("|",$disname);
foreach($data as $v){
if ($request->param('name') == $v) {
return json(['msg'=>'该用户名禁止注册,请更换名称']);
}
}
}
return $next($request);
}
}

View File

@ -0,0 +1,16 @@
<?php
namespace app\middleware;
use think\facade\Session;
class LogedCheck
{
public function handle($request, \Closure $next)
{
//已登陆跳出
if(Session::has('user_id')){
return redirect('user/index');
}
return $next($request);
}
}

View File

@ -0,0 +1,17 @@
<?php
namespace app\middleware;
use think\facade\Session;
class LoginCheck
{
public function handle($request, \Closure $next)
{
//需要登陆的操作
if(Session::has('user_id')){
return $next($request);
} else {
return redirect('/login/index');
}
}
}

9
app/provider.php Normal file
View File

@ -0,0 +1,9 @@
<?php
use app\ExceptionHandle;
use app\Request;
// 容器Provider定义文件
return [
'think\Request' => Request::class,
'think\exception\Handle' => ExceptionHandle::class,
];

26
build.example.php Normal file
View File

@ -0,0 +1,26 @@
<?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>
// +----------------------------------------------------------------------
/**
* php think build 自动生成应用的目录结构的定义示例
*/
return [
// 需要自动创建的文件
'__file__' => [],
// 需要自动创建的目录
'__dir__' => ['controller', 'model', 'view'],
// 需要自动创建的控制器
'controller' => ['Index'],
// 需要自动创建的模型
'model' => ['User'],
// 需要自动创建的模板
'view' => ['index/index'],
];

49
composer.json Normal file
View File

@ -0,0 +1,49 @@
{
"name": "topthink/think",
"description": "the new thinkphp framework",
"type": "project",
"keywords": [
"framework",
"thinkphp",
"ORM"
],
"homepage": "http://thinkphp.cn/",
"license": "Apache-2.0",
"authors": [
{
"name": "liu21st",
"email": "liu21st@gmail.com"
}
],
"require": {
"php": ">=7.1.0",
"topthink/framework": "6.0.*-dev",
"topthink/think-orm": "2.0.*-dev",
"topthink/think-view": "^1.0",
"topthink/think-multi-app": "^1.0",
"topthink/think-captcha": "^3.0",
"xiaodi/think-auth": "^3.0",
"phpmailer/phpmailer": "^6.1"
},
"require-dev": {
"symfony/var-dumper": "^4.2",
"topthink/think-trace":"^1.0"
},
"autoload": {
"psr-4": {
"app\\": "app"
},
"psr-0": {
"": "extend/"
}
},
"config": {
"preferred-install": "dist"
},
"scripts": {
"post-autoload-dump": [
"@php think service:discover",
"@php think vendor:publish"
]
}
}

1176
composer.lock generated Normal file

File diff suppressed because it is too large Load Diff

38
config/app.php Normal file
View File

@ -0,0 +1,38 @@
<?php
// +----------------------------------------------------------------------
// | 应用设置
// +----------------------------------------------------------------------
use think\facade\Env;
return [
// 应用地址
'app_host' => Env::get('app.host', ''),
// 应用的命名空间
'app_namespace' => '',
// 是否启用路由
'with_route' => true,
// 是否启用事件
'with_event' => true,
// 开启应用快速访问
'app_express' => true,
// 默认应用
'default_app' => 'index',
// 默认时区
'default_timezone' => 'Asia/Shanghai',
// 应用映射(自动多应用模式有效)
'app_map' => [],
// 域名绑定(自动多应用模式有效)
'domain_bind' => [],
// 禁止URL访问的应用列表自动多应用模式有效
'deny_app_list' => [],
// 异常页面的模板文件
'exception_tmpl' => app()->getThinkPath() . 'tpl/think_exception.tpl',
// 错误显示信息,非调试模式有效
'error_message' => '页面错误!请稍后再试~',
// 显示错误信息
'show_error_msg' => false,
];

30
config/cache.php Normal file
View File

@ -0,0 +1,30 @@
<?php
use think\facade\Env;
// +----------------------------------------------------------------------
// | 缓存设置
// +----------------------------------------------------------------------
return [
// 默认缓存驱动
'default' => Env::get('cache.driver', 'file'),
// 缓存连接方式配置
'stores' => [
'file' => [
// 驱动方式
'type' => 'File',
// 缓存保存目录
'path' => '',
// 缓存前缀
'prefix' => '',
// 缓存有效期 0表示永久缓存
'expire' => 0,
// 缓存标签前缀
'tag_prefix' => 'tag:',
// 序列化机制 例如 ['serialize', 'unserialize']
'serialize' => [],
],
// 更多的缓存连接
],
];

40
config/captcha.php Normal file
View File

@ -0,0 +1,40 @@
<?php
// +----------------------------------------------------------------------
// | Captcha配置文件
// +----------------------------------------------------------------------
return [
//验证码位数
'length' => 6,
// 验证码字符集合
'codeSet' => '2345678abcdefhijkmnpqrstuvwxyzABCDEFGHJKLMNPQRTUVWXY',
// 验证码过期时间
'expire' => 1800,
// 是否使用中文验证码
'useZh' => false,
// 是否使用算术验证码
'math' => false,
// 是否使用背景图
'useImgBg' => false,
//验证码字符大小
'fontSize' => 14,
// 是否使用混淆曲线
'useCurve' => true,
//是否添加杂点
'useNoise' => true,
// 验证码字体 不设置则随机
'fontttf' => '',
//背景颜色
'bg' => [243, 251, 254],
// 验证码图片高度
'imageH' => 36,
// 验证码图片宽度
'imageW' => 0,
//算术验证码
'math' => true,
// 添加额外的验证码设置
verify => [
'length'=>6,
],
];

9
config/console.php Normal file
View File

@ -0,0 +1,9 @@
<?php
// +----------------------------------------------------------------------
// | 控制台配置
// +----------------------------------------------------------------------
return [
// 指令定义
'commands' => [
],
];

18
config/cookie.php Normal file
View File

@ -0,0 +1,18 @@
<?php
// +----------------------------------------------------------------------
// | Cookie设置
// +----------------------------------------------------------------------
return [
// cookie 保存时间
'expire' => 0,
// cookie 保存路径
'path' => '/',
// cookie 有效域名
'domain' => '',
// cookie 启用安全传输
'secure' => false,
// httponly设置
'httponly' => false,
// 是否使用 setcookie
'setcookie' => true,
];

52
config/database.php Normal file
View File

@ -0,0 +1,52 @@
<?php
return [
// 自定义时间查询规则
'time_query_rule' => [],
// 自动写入时间戳字段
// true为自动识别类型 false关闭
// 字符串则明确指定时间字段类型 支持 int timestamp datetime date
'auto_timestamp' => true,
// 时间字段取出后的默认时间格式
'datetime_format' => 'Y-m-d H:i:s',
// 数据库连接配置信息
'connections' => [
'mysql' => [
// 数据库类型
'type' => 'mysql',
// 服务器地址
'hostname' => '127.0.0.1',
// 数据库名
'database' => '',
// 用户名
'username' => 'root',
// 密码
'password' => '',
// 端口
'hostport' => '3306',
// 数据库连接参数
'params' => [],
// 数据库编码默认采用utf8
'charset' => 'utf8',
// 数据库表前缀
'prefix' => 'tao_',
// 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)
'deploy' => 0,
// 数据库读写是否分离 主从式有效
'rw_separate' => false,
// 读写分离后 主服务器数量
'master_num' => 1,
// 指定从服务器序号
'slave_no' => '',
// 是否严格检查字段是否存在
'fields_strict' => true,
// 是否需要断线重连
'break_reconnect' => false,
// 监听SQL
'trigger_sql' => true,
// 开启字段缓存
'fields_cache' => false,
// 字段缓存路径
'schema_cache_path' => app()->getRuntimePath() . 'schema' . DIRECTORY_SEPARATOR,
],
],
];

37
config/filesystem.php Normal file
View File

@ -0,0 +1,37 @@
<?php
use think\facade\Env;
return [
// 默认磁盘
'default' => Env::get('filesystem.driver', 'local'),
// 磁盘列表
'disks' => [
'local' => [
'type' => 'local',
'root' => app()->getRuntimePath() . 'storage',
],
'public' => [
// 磁盘类型
'type' => 'local',
// 磁盘路径
'root' => app()->getRootPath() . 'public/storage',
// 磁盘路径对应的外部URL路径
'url' => '/storage',
// 可见性
'visibility' => 'public',
],
// 更多的磁盘配置信息
'tmp' => [
// 磁盘类型
'type' => 'local',
// 磁盘路径
'root' => app()->getRootPath() . 'tmp/web',
// 磁盘路径对应的外部URL路径
'url' => '/web',
// 可见性
'visibility' => 'tmp',
],
],
];

27
config/lang.php Normal file
View File

@ -0,0 +1,27 @@
<?php
// +----------------------------------------------------------------------
// | 多语言设置
// +----------------------------------------------------------------------
use think\facade\Env;
return [
// 默认语言
'default_lang' => Env::get('lang.default_lang', 'zh-cn'),
// 允许的语言列表
'allow_lang_list' => [],
// 多语言自动侦测变量名
'detect_var' => 'lang',
// 是否使用Cookie记录
'use_cookie' => true,
// 多语言cookie变量
'cookie_var' => 'think_lang',
// 扩展语言包
'extend_list' => [],
// Accept-Language转义为对应语言包名称
'accept_language' => [
'zh-hans-cn' => 'zh-cn',
],
// 是否支持语言分组
'allow_group' => false,
];

46
config/log.php Normal file
View File

@ -0,0 +1,46 @@
<?php
use think\facade\Env;
// +----------------------------------------------------------------------
// | 日志设置
// +----------------------------------------------------------------------
return [
// 默认日志记录通道
'default' => Env::get('log.channel', 'file'),
// 日志记录级别
'level' => [],
// 日志类型记录的通道 ['error'=>'email',...]
'type_channel' => [],
// 关闭全局日志写入
'close' => false,
// 全局日志处理 支持闭包
'processor' => null,
// 日志通道列表
'channels' => [
'file' => [
// 日志记录方式
'type' => 'File',
// 日志保存目录
'path' => '',
// 单文件日志写入
'single' => false,
// 独立日志级别
'apart_level' => [],
// 最大日志文件数量
'max_files' => 0,
// 使用JSON格式记录
'json' => false,
// 日志处理
'processor' => null,
// 关闭通道日志写入
'close' => false,
// 日志输出格式化
'format' => '[%s][%s] %s',
// 是否实时写入
'realtime_write' => false,
],
// 其它日志通道配置
],
];

11
config/middleware.php Normal file
View File

@ -0,0 +1,11 @@
<?php
// 中间件配置
return [
// 别名或分组
'alias' => [
'logedcheck' => \app\middleware\LogedCheck::class,
'logincheck' => \app\middleware\LoginCheck::class,
],
// 优先级设置,此数组中的中间件会按照数组中的顺序优先执行
'priority' => [],
];

51
config/route.php Normal file
View File

@ -0,0 +1,51 @@
<?php
// +----------------------------------------------------------------------
// | 路由设置
// +----------------------------------------------------------------------
return [
// pathinfo分隔符
'pathinfo_depr' => '/',
// URL伪静态后缀
'url_html_suffix' => 'html',
// URL普通方式参数 用于自动生成
'url_common_param' => true,
// 是否开启路由延迟解析
'url_lazy_route' => false,
// 是否强制使用路由
'url_route_must' => false,
// 合并路由规则
'route_rule_merge' => false,
// 路由是否完全匹配
'route_complete_match' => false,
// 是否开启路由缓存
'route_check_cache' => false,
// 路由缓存连接参数
'route_cache_option' => [],
// 路由缓存Key
'route_check_cache_key' => '',
// 访问控制器层名称
'controller_layer' => 'controller',
// 空控制器名
'empty_controller' => 'Error',
// 是否使用控制器后缀
'controller_suffix' => false,
// 默认的路由变量规则
'default_route_pattern' => '[\w\.]+',
// 是否开启请求缓存 true自动缓存 支持设置请求缓存规则
'request_cache' => false,
// 请求缓存有效期
'request_cache_expire' => null,
// 全局请求缓存排除规则
'request_cache_except' => [],
// 默认控制器名
'default_controller' => 'Index',
// 默认操作名
'default_action' => 'index',
// 操作方法后缀
'action_suffix' => '',
// 默认JSONP格式返回的处理方法
'default_jsonp_handler' => 'jsonpReturn',
// 默认JSONP处理方法
'var_jsonp_handler' => 'callback',
];

19
config/session.php Normal file
View File

@ -0,0 +1,19 @@
<?php
// +----------------------------------------------------------------------
// | 会话设置
// +----------------------------------------------------------------------
return [
// session name
'name' => 'PHPSESSID',
// SESSION_ID的提交变量,解决flash上传跨域
'var_session_id' => '',
// 驱动方式 支持file cache
'type' => 'file',
// 存储连接标识 当type使用cache的时候有效
'store' => null,
// 过期时间
'expire' => 1440,
// 前缀
'prefix' => '',
];

10
config/trace.php Normal file
View File

@ -0,0 +1,10 @@
<?php
// +----------------------------------------------------------------------
// | Trace设置 开启调试模式后有效
// +----------------------------------------------------------------------
return [
// 内置Html和Console两种方式 支持扩展
'type' => 'Html',
// 读取的日志通道名
'channel' => '',
];

25
config/view.php Normal file
View File

@ -0,0 +1,25 @@
<?php
// +----------------------------------------------------------------------
// | 模板设置
// +----------------------------------------------------------------------
return [
// 模板引擎类型使用Think
'type' => 'Think',
// 默认模板渲染规则 1 解析为小写+下划线 2 全部转换小写 3 保持操作方法
'auto_rule' => 3,
// 模板目录名
'view_dir_name' => 'view',
// 模板后缀
'view_suffix' => 'html',
// 模板文件名分隔符
'view_depr' => DIRECTORY_SEPARATOR,
// 模板引擎普通标签开始标记
'tpl_begin' => '{',
// 模板引擎普通标签结束标记
'tpl_end' => '}',
// 标签库标签开始标记
'taglib_begin' => '{',
// 标签库标签结束标记
'taglib_end' => '}',
];

2
extend/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*
!.gitignore

8
public/.htaccess Normal file
View File

@ -0,0 +1,8 @@
<IfModule mod_rewrite.c>
Options +FollowSymlinks -Multiviews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>

BIN
public/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

24
public/index.php Normal file
View File

@ -0,0 +1,24 @@
<?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 think;
require __DIR__ . '/../vendor/autoload.php';
// 执行HTTP应用并响应
$http = (new App())->http;
$response = $http->run();
$response->send();
$http->end($response);

2
public/robots.txt Normal file
View File

@ -0,0 +1,2 @@
User-agent: *
Disallow:

17
public/router.php Normal file
View 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>
// +----------------------------------------------------------------------
// $Id$
if (is_file($_SERVER["DOCUMENT_ROOT"] . $_SERVER["SCRIPT_NAME"])) {
return false;
} else {
require __DIR__ . "/index.php";
}

View File

@ -0,0 +1,130 @@
/**
@NamelayuiAdmin iframe版全局配置
@Author贤心
@Sitehttp://www.layui.com/admin/
@LicenseLPPLlayui付费产品协议
*/
layui.define(['laytpl', 'layer', 'element', 'util'], function(exports){
exports('setter', {
container: 'LAY_app' //容器ID
,base: layui.cache.base //记录静态资源所在路径
,views: layui.cache.base + 'tpl/' //动态模板所在目录
,entry: 'index' //默认视图文件名
,engine: '.html' //视图文件后缀名
,pageTabs: true //是否开启页面选项卡功能。iframe版推荐开启
,version: new Date().getTime() //这样你每次刷新页面,都会更新一次缓存
,name: 'layuiAdmin'
,tableName: 'layuiAdmin' //本地存储表名
,MOD_NAME: 'admin' //模块事件名
,debug: true //是否开启调试模式。如开启,接口异常时会抛出异常 URL 等信息
//自定义请求字段
,request: {
tokenName: false //自动携带 token 的字段名access_token。可设置 false 不携带。
}
//自定义响应字段
,response: {
statusName: 'code' //数据状态的字段名称
,statusCode: {
ok: 0 //数据状态一切正常的状态码
,logout: 1001 //登录状态失效的状态码
,error: -1 //增加登录失败的状态码
}
,msgName: 'msg' //状态信息的字段名称
,dataName: 'data' //数据详情的字段名称
}
//扩展的第三方模块
,extend: [
'echarts', //echarts 核心包
'echartsTheme' //echarts 主题
]
//主题配置
,theme: {
//内置主题配色方案
color: [{
main: '#20222A' //主题色
,selected: '#009688' //选中色
,alias: 'default' //默认别名
},{
main: '#03152A'
,selected: '#3B91FF'
,alias: 'dark-blue' //藏蓝
},{
main: '#2E241B'
,selected: '#A48566'
,alias: 'coffee' //咖啡
},{
main: '#50314F'
,selected: '#7A4D7B'
,alias: 'purple-red' //紫红
},{
main: '#344058'
,logo: '#1E9FFF'
,selected: '#1E9FFF'
,alias: 'ocean' //海洋
},{
main: '#3A3D49'
,logo: '#2F9688'
,selected: '#5FB878'
,alias: 'green' //墨绿
},{
main: '#20222A'
,logo: '#F78400'
,selected: '#F78400'
,alias: 'red' //橙色
},{
main: '#28333E'
,logo: '#AA3130'
,selected: '#AA3130'
,alias: 'fashion-red' //时尚红
},{
main: '#24262F'
,logo: '#3A3D49'
,selected: '#009688'
,alias: 'classic-black' //经典黑
},{
logo: '#226A62'
,header: '#2F9688'
,alias: 'green-header' //墨绿头
},{
main: '#344058'
,logo: '#0085E8'
,selected: '#1E9FFF'
,header: '#1E9FFF'
,alias: 'ocean-header' //海洋头
},{
header: '#393D49'
,alias: 'classic-black-header' //经典黑头
},{
main: '#50314F'
,logo: '#50314F'
,selected: '#7A4D7B'
,header: '#50314F'
,alias: 'purple-red-header' //紫红头
},{
main: '#28333E'
,logo: '#28333E'
,selected: '#AA3130'
,header: '#AA3130'
,alias: 'fashion-red-header' //时尚红头
},{
main: '#28333E'
,logo: '#009688'
,selected: '#009688'
,header: '#009688'
,alias: 'green-header' //墨绿头
}]
//初始的颜色索引,对应上面的配色方案数组索引
//如果本地已经有主题色记录则以本地记录为优先除非请求本地数据localStorage
,initColorIndex: 0
}
});
});

View File

@ -0,0 +1,36 @@
{
"code": 0
,"msg": ""
,"count": "100"
,"data": [{
"prograss": "开会"
,"time": "一小时"
,"complete": "已完成"
,"LAY_CHECKED": true
},{
"prograss": "项目开发"
,"time": "两小时"
,"complete": "进行中"
,"LAY_CHECKED": true
},{
"prograss": "陪吃饭"
,"time": "一小时"
,"complete": "未完成"
},{
"prograss": "修改小bug"
,"time": "半小时"
,"complete": "未完成"
},{
"prograss": "修改大bug"
,"time": "两小时"
,"complete": "未完成"
},{
"prograss": "修改小bug"
,"time": "半小时"
,"complete": "未完成"
},{
"prograss": "修改大bug"
,"time": "两小时"
,"complete": "未完成"
}]
}

View File

@ -0,0 +1,76 @@
{
"code": 0
,"msg": ""
,"count": "100"
,"data": [{
"id": 111
,"title": "社区开始接受 “赞助商广告” 投放"
,"username": "贤心"
,"channel": "公告"
,"href": "http://fly.layui.com/jie/15697/"
,"crt": 61632
},{
"id": 222
,"title": "layui 一周年"
,"username": "猫吃"
,"channel": "讨论"
,"href": "http://fly.layui.com/jie/16622/"
,"crt": 61632
},{
"id": 333
,"title": "四个月的前端"
,"username": "fd"
,"channel": "分享"
,"href": "http://fly.layui.com/jie/16651/"
,"crt": 61632
},{
"id": 333
,"title": "如何评价LayUI和他的作者闲心"
,"username": "纸飞机"
,"channel": "提问"
,"href": "http://fly.layui.com/jie/9352/"
,"crt": 61632
},{
"id": 333
,"title": "如何评价LayUI和他的作者闲心"
,"username": "纸飞机"
,"channel": "提问"
,"href": "http://fly.layui.com/jie/9352/"
,"crt": 61632
},{
"id": 333
,"title": "如何评价LayUI和他的作者闲心"
,"username": "纸飞机"
,"channel": "提问"
,"href": "http://fly.layui.com/jie/9352/"
,"crt": 61632
},{
"id": 333
,"title": "如何评价LayUI和他的作者闲心"
,"username": "纸飞机"
,"channel": "提问"
,"href": "http://fly.layui.com/jie/9352/"
,"crt": 61632
},{
"id": 333
,"title": "如何评价LayUI和他的作者闲心"
,"username": "纸飞机"
,"channel": "提问"
,"href": "http://fly.layui.com/jie/9352/"
,"crt": 61632
},{
"id": 333
,"title": "如何评价LayUI和他的作者闲心"
,"username": "纸飞机"
,"channel": "提问"
,"href": "http://fly.layui.com/jie/9352/"
,"crt": 61632
},{
"id": 333
,"title": "如何评价LayUI和他的作者闲心"
,"username": "纸飞机"
,"channel": "提问"
,"href": "http://fly.layui.com/jie/9352/"
,"crt": 61632
}]
}

View File

@ -0,0 +1,46 @@
{
"code": 0
,"msg": ""
,"count": "100"
,"data": [{
"keywords": "贤心是男是女"
,"frequency": 8520
,"userNums": 2216
},{
"keywords": "Java程序员能找到女朋友吗"
,"frequency": 666
,"userNums": 333
},{
"keywords": "此表格是静态模拟数据"
,"frequency": 666
,"userNums": 333
},{
"keywords": "layui官方教程"
,"frequency": 666
,"userNums": 333
},{
"keywords": "layui官方教程"
,"frequency": 666
,"userNums": 333
},{
"keywords": "layui官方教程"
,"frequency": 666
,"userNums": 333
},{
"keywords": "layui官方教程"
,"frequency": 666
,"userNums": 333
},{
"keywords": "layui官方教程"
,"frequency": 666
,"userNums": 333
},{
"keywords": "layui官方教程"
,"frequency": 666
,"userNums": 333
},{
"keywords": "layui官方教程"
,"frequency": 666
,"userNums": 333
}]
}

View File

@ -0,0 +1,56 @@
{
"code": 0
,"msg": ""
,"count": "100"
,"data": [{
"id": "001"
,"reviewers": "赵"
,"content": "我又爱上编程了"
,"commtime": 20160312
},{
"id": "002"
,"reviewers": "钱"
,"content": "女生出门要小心"
,"commtime": 20160821
},{
"id": "003"
,"reviewers": "孙"
,"content": "框架就用layui"
,"commtime": 20161212
},{
"id": "004"
,"reviewers": "李"
,"content": "心姐么么哒"
,"commtime": 20170311
},{
"id": "005"
,"reviewers": "周"
,"content": "希望明天是个好天气"
,"commtime": 20170612
},{
"id": "006"
,"reviewers": "吴"
,"content": "我又爱上编程了"
,"commtime": 20171112
},{
"id": "007"
,"reviewers": "郑"
,"content": "女生出门要小心"
,"commtime": 20171230
},{
"id": "008"
,"reviewers": "王"
,"content": "框架就用layui"
,"commtime": 20180112
},{
"id": "009"
,"reviewers": "冯"
,"content": "心姐么么哒"
,"commtime": 20180221
},{
"id": "010"
,"reviewers": "陈"
,"content": "希望明天是个好天气"
,"commtime": 20180312
}]
}

View File

@ -0,0 +1,62 @@
{
"code": 0
,"msg": ""
,"count": "100"
,"data": [{
"id": "001"
,"label": "美食"
,"title": "舌尖上的中国第一季"
,"author": "作者-1"
,"content": "通过中华美食的多个侧面,来展现食物给中国人生活带来的仪式、伦理等方面的文化;见识中国特色食材以及与食物相关、构成中国美食特有气质的一系列元素;了解中华饮食文化的精致和源远流长"
,"uploadtime": 20121204
,"status": true
},{
"id": "002"
,"label": "美食"
,"title": "舌尖上的中国第二季"
,"author": "作者-2"
,"content": "以食物为窗口,读懂中国——通过美食,使人们可以有滋有味地认知这个古老的东方国度。“一方水土一方人”,本片将通过展示人们日常生活中与美食相关的多重侧面,描绘与感知中国人的文化传统、家族观念、生活态度与故土难离。人们收获、保存、烹饪、生产美食,并在其过程中留存和传承食物所承载的味觉记忆、饮食习俗、文化样态与家常情感。"
,"uploadtime": 20141204
,"status": false
},{
"id": "003"
,"label": "美食"
,"title": "舌尖上的中国第三季"
,"author": "作者-3"
,"content": "以食物为窗口,读懂中国——通过美食,使人们可以有滋有味地认知这个古老的东方国度。“一方水土一方人”,本片将通过展示人们日常生活中与美食相关的多重侧面,描绘与感知中国人的文化传统、家族观念、生活态度与故土难离。人们收获、保存、烹饪、生产美食,并在其过程中留存和传承食物所承载的味觉记忆、饮食习俗、文化样态与家常情感将世界美食和中国美食进行比照。春耕、夏耘、秋收、冬藏,天人合一的东方哲学让中国饮食依时而变,智慧灵动,中医营养摄生学说创造了食材运用的新天地,儒家人伦道德则把心意和家的味道端上我们的餐桌。淘洗历史,糅合时光,一代又一代的中国人在天地间升起烟火,用至精至诚的心意烹制食物,一餐一食之间,中国人展示个性,确认归属,构建文明,理解和把握着世界的奥妙。"
,"uploadtime": 20161204
,"status": false
},{
"id": "004"
,"label": "历史"
,"title": "诸葛亮骂王朗"
,"author": "作者-1"
,"content": "皓首匹夫!苍髯老贼!你即将命归于九泉之下,届时,有何面目见汉朝二十四代先帝?二臣贼子!你枉活七十有六,一生未立寸功,只会摇唇舞舌,助曹为虐!一条断脊之犬,还敢在我军阵前狺狺狂吠!我从未见过如此厚颜无耻之人!!!"
,"uploadtime": 20180201
,"status": false
},{
"id": "005"
,"label": "新闻"
,"title": "新时代特色中国梦"
,"author": "作者-1"
,"content": "今天,我们比历史上任何时期都更接近、更有信心和能力实现中华民族伟大复兴的目标。新时代已经到来,蓝图已经绘就,中国梦离我们越来越近了。"
,"uploadtime": 20180512
,"status": false
},{
"id": "006"
,"label": "新闻"
,"title": "新时代特色中国梦"
,"author": "作者-2"
,"content": "梦想不会主动走向我们,只有我们去主动实现梦想。行百里者半九十。虽然中国梦离我们越来越近了,但是要实现中国梦,还要靠我们以永不懈怠的精神状态、功在不舍的坚强意志,不忘初心,继续前进。"
,"uploadtime": 20180514
,"status": false
},{
"id": "007"
,"label": "体育"
,"title": "皇马大战利物浦"
,"author": "作者-3"
,"content": "对欧足联而言,更想要产生个新冠军。连续三年都是同一个冠军队,这会毁掉欧冠……”格里姆表态,“皇马有梦幻般的阵容,但从促进竞争的角度而言,另一支球队获胜会更好。"
,"uploadtime": 20180515
,"status": false
}]
}

Some files were not shown because too many files have changed in this diff Show More