重新初始化

This commit is contained in:
2020-02-17 20:47:06 +08:00
parent 5c320206fb
commit 58d999ed73
4016 changed files with 1271 additions and 302396 deletions
+22
View File
@@ -0,0 +1,22 @@
<?php
declare (strict_types = 1);
namespace app;
use think\Service;
/**
* 应用服务类
*/
class AppService extends Service
{
public function register()
{
// 服务注册
}
public function boot()
{
// 服务启动
}
}
+1 -1
View File
@@ -72,7 +72,7 @@ abstract class BaseController
} else {
if (strpos($validate, '.')) {
// 支持场景
list($validate, $scene) = explode('.', $validate);
[$validate, $scene] = explode('.', $validate);
}
$class = false !== strpos($validate, '\\') ? $validate : $this->app->parseClass('validate', $validate);
$v = new $class();
+2 -1163
View File
File diff suppressed because it is too large Load Diff
+17 -124
View File
@@ -8,140 +8,33 @@
// +----------------------------------------------------------------------
namespace app\controller;
use app\BaseController;
use sent\auth\Auth;
use think\facade\Cache;
use think\facade\Config;
use think\facade\Db;
/**
* @title 后端公共模块
*/
class Admin extends BaseController {
class Admin extends Base {
// 使用内置PHP模板引擎渲染模板输出
protected $tpl_config = [
'tpl_replace_string' => [
'__static__' => '/static',
'__img__' => '/static/admin/images',
'__css__' => '/static/admin/css',
'__js__' => '/static/admin/js',
'__public__' => '/static/admin',
],
];
protected $middleware = [
'\app\http\middleware\Validate',
'\app\http\middleware\Admin',
];
protected $data = ['data' => [], 'code' => 0, 'msg' => ''];
protected function initialize() {
$config = Cache::get('system_config');
if (!$config) {
$config = (new \app\model\Config())->lists();
Cache::set('system_config', $config);
}
$this->data['config'] = $config;
}
protected function success($msg, $url = '') {
$this->data['code'] = 0;
$this->data['msg'] = $msg;
$this->data['url'] = $url ? $url->__toString() : '';
return $this->data;
}
protected function error($msg, $url = '') {
$this->data['code'] = 1;
$this->data['msg'] = $msg;
$this->data['url'] = $url ? $url->__toString() : '';
return $this->data;
}
/**
* 授权配置
* @param [type] $request [description]
* @return [type] [description]
*/
protected function auth($request) {
// 是否是超级管理员
define('IS_ROOT', is_administrator());
if (!IS_ROOT && Config::get('admin_allow_ip')) {
// 检查IP地址访问
if (!in_array(get_client_ip(), explode(',', Config::get('admin_allow_ip')))) {
$this->error('403:禁止访问');
}
}
// 检测系统权限
if (!IS_ROOT) {
$access = $this->accessControl();
if (false === $access) {
$this->error('403:禁止访问');
} elseif (null === $access) {
$dynamic = $this->checkDynamic(); //检测分类栏目有关的各项动态权限
if ($dynamic === null) {
//检测访问权限
if (!$this->checkRule($this->url_path, array('in', '1,2'))) {
$this->error('未授权访问!');
} else {
// 检测分类及内容有关的各项动态权限
$dynamic = $this->checkDynamic();
if (false === $dynamic) {
$this->error('未授权访问!');
}
}
} elseif ($dynamic === false) {
$this->error('未授权访问!');
}
}
Db::name('config')->select();
if (!is_login() and !in_array($this->request->url, array('admin/index/login', 'admin/index/logout', 'admin/index/verify'))) {
$this->redirect('admin/index/login');
}
}
/**
* 权限检测
* @param string $rule 检测的规则
* @param string $mode check模式
* @return boolean
* @author 朱亚杰 <xcoolcc@gmail.com>
*/
final protected function checkRule($rule, $type = AuthRule::rule_url, $mode = 'url') {
static $Auth = null;
if (!$Auth) {
$Auth = new Auth();
}
if (!$Auth->check($rule, session('user_auth.uid'), $type, $mode)) {
return false;
}
return true;
}
/**
* 检测是否是需要动态判断的权限
* @return boolean|null
* 返回true则表示当前访问有权限
* 返回false则表示当前访问无权限
* 返回null,则表示权限不明
*
* @author 朱亚杰 <xcoolcc@gmail.com>
*/
protected function checkDynamic() {
if (IS_ROOT) {
return true; //管理员允许访问任何页面
}
return null; //不明,需checkRule
}
/**
* action访问控制,在 **登陆成功** 后执行的第一项权限检测任务
*
* @return boolean|null 返回值必须使用 `===` 进行判断
*
* 返回 **false**, 不允许任何人访问(超管除外)
* 返回 **true**, 允许任何管理员访问,无需执行节点权限检测
* 返回 **null**, 需要继续执行节点权限检测决定是否允许访问
* @author 朱亚杰 <xcoolcc@gmail.com>
*/
final protected function accessControl() {
$allow = Config::get('allow_visit');
$deny = Config::get('deny_visit');
$check = strtolower($this->request->controller() . '/' . $this->request->action());
if (!empty($deny) && in_array_case($check, $deny)) {
return false; //非超管禁止访问deny中的方法
}
if (!empty($allow) && in_array_case($check, $allow)) {
return true;
}
return null; //需要检测节点权限
}
}
}
+37
View File
@@ -0,0 +1,37 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\controller;
use app\BaseController;
use think\facade\View;
class Base extends BaseController {
use \liliuwei\think\Jump;
// 使用内置PHP模板引擎渲染模板输出
protected $tpl_config = [
'view_dir_name' => 'public' . DIRECTORY_SEPARATOR . 'template',
'tpl_replace_string' => [
'__static__' => '/static',
'__img__' => '/static/front/images',
'__css__' => '/static/front/css',
'__js__' => '/static/front/js',
'__public__' => '/static/front',
],
];
public $data = []; //渲染数据
protected function fetch($template = '') {
View::config($this->tpl_config);
View::assign($this->data);
View::fetch($template);
}
}
+6 -6
View File
@@ -6,10 +6,10 @@
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\model;
namespace app\controller;
use think\Model;
class Link extends Model {
}
class Front extends Base {
public function index() {
return $this->fetch();
}
}
-61
View File
@@ -1,61 +0,0 @@
<?php
namespace app\controller;
use app\BaseController;
class Index extends BaseController {
protected $middleware = ['\app\http\middleware\Front'];
public function weixin(){
}
/**
* @title 网站首页
*/
public function index() {
}
/**
* @title 搜索页
*/
public function search() {
}
/**
* @title 专题页
*/
public function topic() {
}
/**
* @title 模型数据列表
*/
public function lists() {
}
/**
* @title 栏目数据列表
*/
public function category() {
}
/**
* @title 模型数据详情
*/
public function detail() {
}
/**
* @title 未知页面调整到此方法
*/
public function miss() {
}
}
-20
View File
@@ -1,20 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\controller\admin;
use app\controller\Admin;
class Action extends Admin{
/**
* @title 系统首页
*/
public function index(){
}
}
-181
View File
@@ -1,181 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\controller\admin;
use app\controller\Admin;
use app\model\AdPlace;
use app\model\Ad as AdModel;
class Ad extends Admin{
/**
* @title 广告位列表
*/
public function index(AdPlace $adp){
if ($this->request->isAjax()) {
$param = $this->request->param();
$res = $adp->paginate($this->request->pageConfig);
$data = $res->append(['show_type_text', 'status_text'])->toArray();
$this->data['data'] = $data;
return $this->data;
}
}
/**
* @title 添加广告位
*/
public function add(AdPlace $adp){
if ($this->request->isPost()) {
$data = $this->request->post();
$result = $adp->save($data);
if (false !== $result) {
return $this->success('成功添加', url('/admin/ad/index'));
}else{
return $this->error($this->model->getError());
}
}else{
$info['appid'] = rand_string(10, 1); //八位数字appid
$info['appsecret'] = rand_string(32); //32位数字加字母秘钥
$this->data['data'] = array(
'show_type' => $adp->show_type,
'info' => $info
);
return $this->data;
}
}
/**
* @title 编辑广告位
*/
public function edit(AdPlace $adp){
if ($this->request->isPost()) {
$data = $this->request->post();
if (!isset($data['id']) || !$data['id']) {
return $this->error('非法操作!');
}
$result = $adp->exists(true)->save($data);
if (false !== $result) {
return $this->success('修改成功', url('/admin/ad/index'));
}else{
return $this->error($this->model->getError());
}
}else{
$info = $adp->where('id', $this->request->param('id'))->find();
$this->data['template'] = "add";
$this->data['data'] = array(
'show_type' => $adp->show_type,
'info' => $info
);
return $this->data;
}
}
/**
* @title 删除广告位
*/
public function del(AdPlace $adp){
$ids = $this->request->param('ids', 0);
if(!$ids){
return $this->error('非法操作!');
}else{
$ids = \explode(",", $ids);
}
$result = $adp->where('id', 'IN', $ids)->delete();
if(false !== $result){
return $this->success('删除成功!');
}else{
return $this->error('删除失败!');
}
}
/**
* @title 广告列表
*/
public function lists(AdModel $ad){
if ($this->request->isAjax()) {
$res = $ad->paginate($this->request->pageConfig);
$data = $res->append(['cover','status_text'])->toArray();
$this->data['data'] = $data;
return $this->data;
}
}
/**
* @title 添加广告
*/
public function addad(AdModel $ad){
if ($this->request->isPost()) {
$data = $this->request->post();
$result = $ad->save($data);
if (false !== $result) {
return $this->success('成功添加', url('/admin/ad/index'));
}else{
return $this->error($this->model->getError());
}
}else{
$info['appid'] = rand_string(10, 1); //八位数字appid
$info['appsecret'] = rand_string(32); //32位数字加字母秘钥
$this->data['data'] = array(
'info' => $info
);
return $this->data;
}
}
/**
* @title 编辑广告
*/
public function editad(AdModel $ad){
if ($this->request->isPost()) {
$data = $this->request->post();
if (!isset($data['id']) || !$data['id']) {
return $this->error('非法操作!');
}
$result = $ad->exists(true)->save($data);
if (false !== $result) {
return $this->success('修改成功', url('/admin/ad/index'));
}else{
return $this->error($this->model->getError());
}
}else{
$info = $ad->where('id', $this->request->param('id'))->find();
$this->data['template'] = "addad";
$this->data['data'] = array(
'info' => $info
);
return $this->data;
}
}
/**
* @title 删除广告
*/
public function delad(AdModel $ad){
$ids = $this->request->param('ids', 0);
if(!$ids){
return $this->error('非法操作!');
}else{
$ids = \explode(",", $ids);
}
$result = $ad->where('id', 'IN', $ids)->delete();
if(false !== $result){
return $this->success('删除成功!');
}else{
return $this->error('删除失败!');
}
}
}
-28
View File
@@ -1,28 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\controller\admin;
use app\controller\Admin;
class Addons extends Admin{
/**
* @title 系统首页
*/
public function index(){
}
/**
* @title 钩子列表
*/
public function hooks(){
}
}
-21
View File
@@ -1,21 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\controller\admin;
use app\controller\Admin;
class Attribute extends Admin{
/**
* @title 系统首页
*/
public function index(){
}
}
-105
View File
@@ -1,105 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\controller\admin;
use app\controller\Admin;
use app\Model\Category as CategoryModel;
class Category extends Admin{
/**
* @title 栏目列表
*/
public function index(CategoryModel $category){
if($this->request->isAjax()){
$tree = $this->request->param('tree', 0);
$map = array();
$res = $category->where($map)->order('sort asc, id asc')->select();
$list = $res->toArray();
if($tree){
if (!empty($list)) {
$tree = new \com\Tree();
$list = $tree->toFormatTree($list);
}
}
$this->data['data'] = $list;
return $this->data;
}
}
/**
* @title 添加栏目
*/
public function add(CategoryModel $category){
if ($this->request->isPost()) {
$data = $this->request->post();
$result = $category->save($data);
if (false !== $result) {
return $this->success('成功添加', url('/admin/category/index'));
}else{
return $this->error($this->model->getError());
}
}else{
$info['appid'] = rand_string(10, 1); //八位数字appid
$info['appsecret'] = rand_string(32); //32位数字加字母秘钥
$this->data['data'] = array(
'info' => $info
);
return $this->data;
}
}
/**
* @title 编辑栏目
*/
public function edit(CategoryModel $category){
if ($this->request->isPost()) {
$data = $this->request->post();
if (!isset($data['id']) || !$data['id']) {
return $this->error('非法操作!');
}
$result = $category->exists(true)->save($data);
if (false !== $result) {
return $this->success('修改成功', url('/admin/category/index'));
}else{
return $this->error($this->model->getError());
}
}else{
$info = $category->where('id', $this->request->param('id'))->find();
$this->data['template'] = "add";
$this->data['data'] = array(
'info' => $info
);
return $this->data;
}
}
/**
* @title 删除栏目
*/
public function del(CategoryModel $category){
$ids = $this->request->param('ids', 0);
if(!$ids){
return $this->error('非法操作!');
}else{
$ids = \explode(",", $ids);
}
$result = $category->where('id', 'IN', $ids)->delete();
if(false !== $result){
return $this->success('删除成功!');
}else{
return $this->error('删除失败!');
}
}
}
-114
View File
@@ -1,114 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\controller\admin;
use app\controller\Admin;
use app\Model\Channel as ChannelModel;
class Channel extends Admin{
/**
* @title 频道列表
*/
public function index(ChannelModel $channel){
if($this->request->isAjax()){
$tree = $this->request->param('tree', 0);
$type = $this->request->param('type', 0);
$map = array();
if($type){
$map['type'] = $type;
}
$res = $channel->where($map)->order('sort asc, id asc')->select();
$list = $res->toArray();
if($tree){
if (!empty($list)) {
$tree = new \com\Tree();
$list = $tree->toFormatTree($list);
}
}
$this->data['data'] = $list;
return $this->data;
}else{
$this->data['data'] = array(
'type' => $this->request->param('type', 0),
);
return $this->data;
}
}
/**
* @title 添加频道
*/
public function add(ChannelModel $channel){
if ($this->request->isPost()) {
$data = $this->request->post();
$result = $channel->save($data);
if (false !== $result) {
return $this->success('成功添加', url('/admin/channel/index'));
}else{
return $this->error($this->model->getError());
}
}else{
$info['appid'] = rand_string(10, 1); //八位数字appid
$info['appsecret'] = rand_string(32); //32位数字加字母秘钥
$this->data['data'] = array(
'info' => $info
);
return $this->data;
}
}
/**
* @title 编辑频道
*/
public function edit(ChannelModel $channel){
if ($this->request->isPost()) {
$data = $this->request->post();
if (!isset($data['id']) || !$data['id']) {
return $this->error('非法操作!');
}
$result = $channel->exists(true)->save($data);
if (false !== $result) {
return $this->success('修改成功', url('/admin/channel/index'));
}else{
return $this->error($this->model->getError());
}
}else{
$info = $channel->where('id', $this->request->param('id'))->find();
$this->data['template'] = "add";
$this->data['data'] = array(
'info' => $info
);
return $this->data;
}
}
/**
* @title 删除频道
*/
public function del(ChannelModel $channel){
$ids = $this->request->param('ids', 0);
if(!$ids){
return $this->error('非法操作!');
}else{
$ids = \explode(",", $ids);
}
$result = $channel->where('id', 'IN', $ids)->delete();
if(false !== $result){
return $this->success('删除成功!');
}else{
return $this->error('删除失败!');
}
}
}
-98
View File
@@ -1,98 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\controller\admin;
use app\controller\Admin;
use think\facade\Db;
use app\model\Client as ClientModel;
class Client extends Admin{
/**
* @title 系统首页
*/
public function index(ClientModel $client){
if ($this->request->isAjax()) {
$param = $this->request->param();
$res = $client->paginate($this->request->pageConfig);
$data = $res->toArray();
$this->data['data'] = $data;
return $this->data;
}
}
/**
* @title 添加客户端
*/
public function add(ClientModel $client){
if ($this->request->isPost()) {
$data = $this->request->post();
$result = $client->save($data);
if (false !== $result) {
return $this->success('成功添加', url('/admin/client/index'));
}else{
return $this->error($this->model->getError());
}
}else{
$info['appid'] = rand_string(10, 1); //八位数字appid
$info['appsecret'] = rand_string(32); //32位数字加字母秘钥
$this->data['data'] = array(
'info' => $info
);
return $this->data;
}
}
/**
* @title 编辑客户端
*/
public function edit(ClientModel $client){
if ($this->request->isPost()) {
$data = $this->request->post();
if (!isset($data['id']) || !$data['id']) {
return $this->error('非法操作!');
}
$result = $client->exists(true)->save($data);
if (false !== $result) {
return $this->success('修改成功', url('/admin/client/index'));
}else{
return $this->error($this->model->getError());
}
}else{
$info = $client->where('id', $this->request->param('id'))->find();
$this->data['template'] = "add";
$this->data['data'] = array(
'info' => $info
);
return $this->data;
}
}
/**
* @title 删除客户端
*/
public function del(ClientModel $client){
$ids = $this->request->param('ids', 0);
if(!$ids){
return $this->error('非法操作!');
}else{
$ids = \explode(",", $ids);
}
$result = $client->where('id', 'IN', $ids)->delete();
if(false !== $result){
return $this->success('删除成功!');
}else{
return $this->error('删除失败!');
}
}
}
-240
View File
@@ -1,240 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\controller\admin;
use app\controller\Admin;
use app\model\Config as ConfigModel;
use think\facade\Cache;
class Config extends Admin {
/**
* @title 系统首页
*/
public function index(ConfigModel $config) {
if($this->request->isAjax()){
$param = $this->request->param();
$group = input('group', 0, 'trim');
$name = input('name', '', 'trim');
$system_config = Cache::get('system_config');
/* 查询条件初始化 */
$map = array('status' => 1);
if ($group) {
$map['group'] = $group;
}
if ($name) {
$map['name'] = array('like', '%' . $name . '%');
}
$res = $config->where($map)->order('id desc')->paginate($this->request->pageConfig);
$data = $res->append(['type_text','group_text'])->toArray();
$this->data['data'] = $data;
return $this->data;
}else{
$data = array(
'group_id' => $this->request->get('group', 0),
);
$this->data['data'] = $data;
return $this->data;
}
}
/**
* @title 系统首页
*/
public function group(ConfigModel $config) {
if ($this->request->isAjax()) {
$data = $this->request->param();
$result = $config->updateConfig($data);
if (false !== $result) {
$this->data['code'] = 0;
$this->data['msg'] = "更新成功!";
}else{
$this->data['code'] = 1;
$this->data['msg'] = $config->error;
}
return $this->data;
} else {
$id = $this->request->param('id', 1);
$res = $config->where(array('status' => 1, 'group' => $id))->field('id,name,title,extra,value,remark,type')->order('sort')->select();
$list = $res->toArray();
$this->data['data'] = array('list' => $list, 'id' => $id);
return $this->data;
}
}
/**
* @title 新增配置
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
public function add(ConfigModel $config) {
if ($this->request->isPost()) {
$config = model('Config');
$data = $this->request->post();
if ($data) {
$id = $config->validate(true)->save($data);
if ($id) {
cache('db_config_data', null);
//记录行为
action_log('update_config', 'config', $id, session('user_auth.uid'));
return $this->success('新增成功', url('index'));
} else {
return $this->error('新增失败');
}
} else {
return $this->error($config->getError());
}
} else {
$this->data['data'] = array('info' => array());
$this->data['template'] = "edit";
return $this->data;
}
}
/**
* @title 编辑配置
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
public function edit(ConfigModel $config) {
if ($this->request->isPost()) {
$config = model('Config');
$data = $this->request->post();
if ($data) {
$result = $config->validate('Config.edit')->save($data, array('id' => $data['id']));
if (false !== $result) {
cache('db_config_data', null);
//记录行为
action_log('update_config', 'config', $data['id'], session('user_auth.uid'));
return $this->success('更新成功', Cookie('__forward__'));
} else {
return $this->error($config->getError(), '');
}
} else {
return $this->error($config->getError());
}
} else {
$id = $this->request->param('id', 0);
if (!$id) {
$this->data['msg'] = "非法操作!";
return $this->data;
}
$info = array();
/* 获取数据 */
$info = $config->field(true)->find($id);
if (false === $info) {
return $this->error('获取配置信息错误');
}
$this->data['data'] = array(
'info' => $info,
);
return $this->data;
}
}
/**
* @title 批量保存配置
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
public function save($config) {
if ($config && is_array($config)) {
$Config = db('Config');
foreach ($config as $name => $value) {
$map = array('name' => $name);
$Config->where($map)->setField('value', $value);
}
}
cache('db_config_data', null);
return $this->success('保存成功!');
}
/**
* @title 删除配置
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
public function del() {
$id = array_unique((array) input('id', 0));
if (empty($id)) {
return $this->error('请选择要操作的数据!');
}
$map = array('id' => array('in', $id));
if (db('Config')->where($map)->delete()) {
cache('DB_CONFIG_DATA', null);
//记录行为
action_log('update_config', 'config', $id, session('user_auth.uid'));
return $this->success('删除成功');
} else {
return $this->error('删除失败!');
}
}
/**
* @title 配置排序
* @author huajie <banhuajie@163.com>
*/
public function sort() {
if ($this->request->isGet()) {
$ids = input('ids');
//获取排序的数据
$map = array('status' => array('gt', -1));
if (!empty($ids)) {
$map['id'] = array('in', $ids);
} elseif (input('group')) {
$map['group'] = input('group');
}
$list = db('Config')->where($map)->field('id,title')->order('sort asc,id asc')->select();
$this->assign('list', $list);
$this->setMeta('配置排序');
return $this->fetch();
} elseif ($this->request->isPost()) {
$ids = input('post.ids');
$ids = explode(',', $ids);
foreach ($ids as $key => $value) {
$res = db('Config')->where(array('id' => $value))->setField('sort', $key + 1);
}
if ($res !== false) {
return $this->success('排序成功!', Cookie('__forward__'));
} else {
return $this->error('排序失败!');
}
} else {
return $this->error('非法请求!');
}
}
/**
* @title 主题选择
*/
public function themes(ConfigModel $config) {
if ($this->request->isPost()) {
$result = $config->where('name', $name . '_themes')->setField('value', $id);
if (false !== $result) {
\think\Cache::clear();
return $this->success('设置成功!');
}else{
return $this->error('设置失败!');
}
}else{
$list = $config->getThemesList();
$this->data['data'] = array(
'pc' => $this->data['config']['pc_themes'],
'mobile' => $this->data['config']['mobile_themes'],
'list' => $list,
);
return $this->data;
}
}
}
-38
View File
@@ -1,38 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\controller\admin;
use app\controller\Admin;
/**
*
*/
class Content extends Admin{
/**
* @title 内容列表页
*/
public function index(){
}
/**
* @title 内容添加
*/
public function add(){
if ($this->request->isAjax()) {
$result = false;
if (false !== $result) {
return $this->success();
}else{
return $this->error();
}
}
}
}
-70
View File
@@ -1,70 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\controller\admin;
use app\controller\Admin;
use think\facade\Db;
class Database extends Admin{
/**
* @title 数据备份
*/
public function export(){
$list = Db::query('SHOW TABLE STATUS');
$list = array_map('array_change_key_case', $list);
$this->data['data'] = array(
'list' => $list
);
return $this->data;
}
/**
* @title 数据导入
*/
public function import(){
//列出备份文件列表
$path = app()->getRuntimePath() . 'backup';
if (!is_dir($path)) {
mkdir($path, 0755, true);
}
$path = realpath($path);
$flag = \FilesystemIterator::KEY_AS_FILENAME;
$glob = new \FilesystemIterator($path, $flag);
$list = array();
foreach ($glob as $name => $file) {
if (preg_match('/^\d{8,8}-\d{6,6}-\d+\.sql(?:\.gz)?$/', $name)) {
$name = sscanf($name, '%4s%2s%2s-%2s%2s%2s-%d');
$date = "{$name[0]}-{$name[1]}-{$name[2]}";
$time = "{$name[3]}:{$name[4]}:{$name[5]}";
$part = $name[6];
if (isset($list["{$date} {$time}"])) {
$info = $list["{$date} {$time}"];
$info['part'] = max($info['part'], $part);
$info['size'] = $info['size'] + $file->getSize();
} else {
$info['part'] = $part;
$info['size'] = $file->getSize();
}
$extension = strtoupper(pathinfo($file->getFilename(), PATHINFO_EXTENSION));
$info['compress'] = ($extension === 'SQL') ? '-' : $extension;
$info['time'] = strtotime("{$date} {$time}");
$list["{$date} {$time}"] = $info;
}
}
$this->data['data'] = array(
'list' => $list
);
return $this->data;
}
}
-96
View File
@@ -1,96 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\controller\admin;
use app\controller\Admin;
use app\model\Form as FormModel;
class Form extends Admin{
/**
* @title 系统首页
*/
public function index(FormModel $form){
if ($this->request->isAjax()) {
$res = $form->paginate($this->request->pageConfig);
$data = $res->toArray();
$this->data['data'] = $data;
return $this->data;
}
}
/**
* @title 添加客户端
*/
public function add(FormModel $form){
if ($this->request->isPost()) {
$data = $this->request->post();
$result = $form->save($data);
if (false !== $result) {
return $this->success('成功添加', url('/admin/form/index'));
}else{
return $this->error($this->model->getError());
}
}else{
$info['appid'] = rand_string(10, 1); //八位数字appid
$info['appsecret'] = rand_string(32); //32位数字加字母秘钥
$this->data['data'] = array(
'info' => $info
);
return $this->data;
}
}
/**
* @title 编辑客户端
*/
public function edit(FormModel $form){
if ($this->request->isPost()) {
$data = $this->request->post();
if (!isset($data['id']) || !$data['id']) {
return $this->error('非法操作!');
}
$result = $form->exists(true)->save($data);
if (false !== $result) {
return $this->success('修改成功', url('/admin/form/index'));
}else{
return $this->error($this->model->getError());
}
}else{
$info = $form->where('id', $this->request->param('id'))->find();
$this->data['template'] = "add";
$this->data['data'] = array(
'info' => $info
);
return $this->data;
}
}
/**
* @title 删除客户端
*/
public function del(FormModel $form){
$ids = $this->request->param('ids', 0);
if(!$ids){
return $this->error('非法操作!');
}else{
$ids = \explode(",", $ids);
}
$result = $form->where('id', 'IN', $ids)->delete();
if(false !== $result){
return $this->success('删除成功!');
}else{
return $this->error('删除失败!');
}
}
}
-32
View File
@@ -1,32 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\controller\admin;
use app\controller\Admin;
class Group extends Admin{
/**
* @title 系统首页
*/
public function index(){
if ($this->request->isAjax()) {
# code...
}
}
/**
* @title 权限列表
*/
public function access(){
if ($this->request->isAjax()) {
# code...
}
}
}
+11 -62
View File
@@ -9,8 +9,6 @@
namespace app\controller\admin;
use app\controller\Admin;
use app\model\Menu;
use think\facade\Session;
/**
* @title 后端公共模块
@@ -18,75 +16,26 @@ use think\facade\Session;
class Index extends Admin {
/**
* @title 系统首页
* @title 后台首页
* @return html [description]
*/
public function index(Menu $menu) {
$this->data['data'] = array('menu' => $menu->getAuthMenuList($this->request));
return $this->data;
public function index() {
return $this->fetch();
}
/**
* @title 系统首页
*/
public function dashboard() {
}
/**
* @title 更新缓存
*/
public function clear() {
if ($this->request->isAjax()) {
$root = app()->getRootPath() . 'runtime/';
$this->delDirAndFile($root);
return $this->success('更新成功!');
}
}
/** 递归删除文件
* @param $dirName
* @param bool $subdir
*/
protected function delDirAndFile($dirName) {
$list = glob($dirName . '*');
foreach ($list as $file) {
if (is_dir($file)) {
$this->delDirAndFile($file . '/');
} else {
@unlink($file);
}
}
@rmdir($dirName);
}
/**
* @title 后台登录
* @return html [description]
*/
public function login(\app\model\Member $member) {
if ($this->request->isAjax()) {
$username = $this->request->param('username', '');
$password = $this->request->param('password', '');
$user = $member->login($username, $password);
if ($user) {
Session::set('user', $user);
$this->data['url'] = "/admin/index/index.html";
$this->data['msg'] = "登录成功!";
} else {
Session::set('user', null);
$this->data['code'] = 1;
$this->data['msg'] = "登录失败!";
}
return $this->data;
}
public function login() {
return $this->fetch();
}
/**
* @title 后台
* @title 后台退
* @return html [description]
*/
public function logout() {
Session::set('user', null);
$this->data['code'] = 0;
$this->data['msg'] = "成功退出!";
return $this->data;
return $this->fetch();
}
}
}
-96
View File
@@ -1,96 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\controller\admin;
use app\controller\Admin;
use app\model\Link as LinkModel;
class Link extends Admin{
/**
* @title 友链列表
*/
public function index(LinkModel $link){
if ($this->request->isAjax()) {
$res = $link->paginate($this->request->pageConfig);
$data = $res->toArray();
$this->data['data'] = $data;
return $this->data;
}
}
/**
* @title 添加友链
*/
public function add(LinkModel $link){
if ($this->request->isPost()) {
$data = $this->request->post();
$result = $link->save($data);
if (false !== $result) {
return $this->success('成功添加', url('/admin/link/index'));
}else{
return $this->error($this->model->getError());
}
}else{
$info['appid'] = rand_string(10, 1); //八位数字appid
$info['appsecret'] = rand_string(32); //32位数字加字母秘钥
$this->data['data'] = array(
'info' => $info
);
return $this->data;
}
}
/**
* @title 编辑友链
*/
public function edit(LinkModel $link){
if ($this->request->isPost()) {
$data = $this->request->post();
if (!isset($data['id']) || !$data['id']) {
return $this->error('非法操作!');
}
$result = $link->exists(true)->save($data);
if (false !== $result) {
return $this->success('修改成功', url('/admin/link/index'));
}else{
return $this->error($this->model->getError());
}
}else{
$info = $link->where('id', $this->request->param('id'))->find();
$this->data['template'] = "add";
$this->data['data'] = array(
'info' => $info
);
return $this->data;
}
}
/**
* @title 删除友链
*/
public function del(LinkModel $link){
$ids = $this->request->param('ids', 0);
if(!$ids){
return $this->error('非法操作!');
}else{
$ids = \explode(",", $ids);
}
$result = $link->where('id', 'IN', $ids)->delete();
if(false !== $result){
return $this->success('删除成功!');
}else{
return $this->error('删除失败!');
}
}
}
-89
View File
@@ -1,89 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\controller\admin;
use app\controller\Admin;
use app\Model\Menu as MenuModel;
class Menu extends Admin{
/**
* @title 系统首页
*/
public function index(){
if($this->request->isAjax()){
$tree = $this->request->param('tree', 0);
$menu = new MenuModel();
$map = array();
$res = $menu->where($map)->order('sort asc, id asc')->select();
$list = $res->toArray();
if($tree){
if (!empty($list)) {
$tree = new \com\Tree();
$list = $tree->toFormatTree($list);
}
}
$this->data['data'] = $list;
return $this->data;
}
}
/**
* @title 编辑菜单
*/
public function edit(){
$menu = new MenuModel();
if($this->request->isAjax()){
$data = $this->request->post();
$result = $menu->where('id', $data['id'])->save($data);
if (false !== $result) {
$this->data['code'] = 0;
$this->data['msg'] = '更新成功!';
}else{
$this->data['code'] = 1;
$this->data['msg'] = '更新失败!';
}
return $this->data;
}else{
$id = $this->request->param('id', 0);
if (!$id) {
return $this->error('非法操作!');
}
$info = $menu->where('id', $id)->find();
$this->data['data'] = array('info'=>$info);
return $this->data;
}
}
/**
* @title 添加菜单
*/
public function add(){
if($this->request->isAjax()){
return $this->data;
}else{
$this->data['template'] = 'edit';
return $this->data;
}
}
/**
* @title 移除菜单
*/
public function remove(){
if($this->request->isAjax()){
return $this->data;
}
}
}
-21
View File
@@ -1,21 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\controller\admin;
use app\controller\Admin;
class Model extends Admin{
/**
* @title 系统首页
*/
public function index(){
}
}
-42
View File
@@ -1,42 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\controller\admin;
use app\controller\Admin;
use app\model\Rewrite;
use app\model\SeoRule;
class Seo extends Admin{
/**
* @title 系统首页
*/
public function index(SeoRule $seo){
if($this->request->isAjax()){
//读取规则列表
$map = array('status' => array('=', 0));
$res = $seo->where($map)->order('sort asc')->paginate($this->request->pageConfig);
$this->data['data'] = $res->toArray();
return $this->data;
}
}
/**
* @title 重写规则
*/
public function rewrite(Rewrite $rewrite){
$this->data['data'] = array(
'list' => array()
);
return $this->data;
}
}
-43
View File
@@ -1,43 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\controller\admin;
use app\controller\Admin;
class User extends Admin{
/**
* @title 系统首页
*/
public function index(){
if ($this->request->isAjax()) {
return $this->data;
}
}
/**
* @title 个人资料
*/
public function profile(){
}
/**
* @title 检测密码正确性
*/
public function checkPassword(){
return true;
}
/**
* @title 修改密码
*/
public function resetpwd(){
}
}
-8
View File
@@ -1,8 +0,0 @@
<?php
namespace app\controller\api;
use app\BaseController;
class Index extends BaseController {
}
-8
View File
@@ -1,8 +0,0 @@
<?php
namespace app\controller\user;
use app\BaseController;
class Index extends BaseController {
}
+3 -54
View File
@@ -9,73 +9,22 @@
namespace app\http\middleware;
use think\facade\Session;
use think\facade\View;
/**
* @title 后台中间件
*/
class Admin {
protected $data = [];
protected $outAuth = ['admin/index/login', 'admin/index/logout', 'admin/index/verify'];
public function handle($request, \Closure $next) {
$user = Session::get('user');
$user = Session::get('user');
$request->url = str_replace(".", "/", strtolower($request->controller())) . '/' . $request->action();
if (!Session::has('user') && !$user['uid'] && !in_array($request->url, $this->outAuth)) {
return redirect('admin/index/login');
}
$request->isAdmin = 1;
$request->user = $user;
$request->pageConfig = array(
'list_rows' => $request->param('limit', 20),
'page' => $request->param('page', 1),
'page' => $request->param('page', 1),
);
$response = $next($request);
if (is_array($response->getData())) {
$this->data = array_merge($this->data, $response->getData());
} else {
$this->data = $response->getData();
}
if ($request->isAjax()) {
if (isset($this->data['config'])) {
unset($this->data['config']);
}
return json($this->data);
} else {
if (\is_string($this->data) && $this->data != '') {
return $response;
} else {
return $response->data($this->fetch());
}
}
}
/**
* @title 显示类
*/
protected function fetch($template = '') {
// 使用内置PHP模板引擎渲染模板输出
$config = array(
'tpl_replace_string' => array(
'__static__' => '/static',
'__img__' => '/static/admin/images',
'__css__' => '/static/admin/css',
'__js__' => '/static/admin/js',
'__public__' => '/static/admin',
),
);
$template = (isset($this->data['template']) && $this->data['template']) ? $this->data['template'] : $template;
View::config($config);
View::assign('sent_version', sent_version);
View::assign('config', (isset($this->data['config']) ? $this->data['config'] : []));
View::assign((isset($this->data['data']) ? $this->data['data'] : []));
return View::fetch($template);
return $response;
}
}
-36
View File
@@ -1,36 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\http\middleware;
use think\facade\Session;
use think\facade\View;
/**
* @title 后台中间件
*/
class AdminAuth {
public function handle($request, \Closure $next) {
$user = Session::get('user');
if (Session::has('user') && $user['uid']) {
$request->user = $user;
if ($user['uid'] == 1) {
$request->isAdmin = true;
}
$current_url = '/' . str_replace('.', '/', strtolower($request->controller())) . '/' . strtolower($request->action());
$meta_title = $current_url;
View::assign('meta_title', $meta_title);
return $next($request);
} else {
return redirect(url('admin.index/login'))->remember();
}
}
}
-52
View File
@@ -1,52 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\http\middleware;
use think\facade\View;
/**
* @title 后台中间件
*/
class Front {
protected $data = [];
public function handle($request, \Closure $next) {
$response = $next($request);
$this->data = $response->getData();
if ($request->isAjax()) {
return json($this->data);
}else{
return $response->data($this->fetch());
}
}
/**
* @title 显示类
*/
protected function fetch($template = ''){
// 使用内置PHP模板引擎渲染模板输出
$config = array(
'tpl_replace_string' => array(
'__static__' => '/static',
'__img__' => '/static/front/images',
'__css__' => '/static/front/css',
'__js__' => '/static/front/js',
'__public__' => '/static/front',
)
);
if (is_string($this->data)) {
$this->data = array('data' => $this->data);
}
View::config($config);
View::assign($this->data);
return View::engine('Think')->fetch($template);
}
}
-32
View File
@@ -1,32 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\http\validate\admin;
use think\Validate;
class Client extends Validate {
protected $rule = [
'title' => 'require|unique:client',
'appid' => 'require|unique:client',
'appsecret' => 'require',
];
protected $message = [
'title.require' => '客户端标题不能为空!',
'appid.require' => 'APPID不能为空!',
'appsecret.require' => '秘钥不能为空!',
];
protected $scene = [
'add' => ['title', 'appid', 'appsecret'],
'edit' => ['title', 'appid', 'appsecret'],
];
}
-29
View File
@@ -1,29 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\http\validate\admin;
use think\Validate;
class Index extends Validate {
protected $rule = [
'username' => 'require',
'password' => 'require',
];
protected $message = [];
/**
* @title 登录验证
*/
public function sceneLogin() {
return $this->only(['username','password']);
}
}
+6 -8
View File
@@ -1,12 +1,10 @@
<?php
// 全局中间件定义文件
return [
// 全局请求缓存
// \think\middleware\CheckRequestCache::class,
// 多语言加载
// \think\middleware\LoadLangPack::class,
// Session初始化
\think\middleware\SessionInit::class,
// 页面Trace调试
// \think\middleware\TraceDebug::class,
// 全局请求缓存
// \think\middleware\CheckRequestCache::class,
// 多语言加载
// \think\middleware\LoadLangPack::class,
// Session初始化
\think\middleware\SessionInit::class,
];
-20
View File
@@ -1,20 +0,0 @@
<?php
namespace app\model;
use think\Model;
class Ad extends Model {
public $status = array(
1 => '开启',
0 => '关闭'
);
public function getCoverAttr($value, $data){
return get_cover($data['cover_id'], 'path');
}
public function getStatusTextAttr($value, $data){
return isset($this->status[$data['status']]) ? $this->status[$data['status']] : '未知';
}
}
-33
View File
@@ -1,33 +0,0 @@
<?php
namespace app\model;
use think\Model;
class AdPlace extends Model {
protected $type = array(
'start_time' => 'timestamp',
'end_time' => 'timestamp'
);
public $show_type = array(
1 => '幻灯片',
2 => '对联',
3 => '图片列表',
4 => '图文列表',
5 => '文字列表',
6 => '代码广告'
);
public $status = array(
1 => '开启',
0 => '关闭'
);
public function getShowTypeTextAttr($value, $data){
return isset($this->show_type[$data['show_type']]) ? $this->show_type[$data['show_type']] : '未知';
}
public function getStatusTextAttr($value, $data){
return isset($this->status[$data['status']]) ? $this->status[$data['status']] : '未知';
}
}
-19
View File
@@ -1,19 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\model;
use think\Model;
/**
* @title: À¸Ä¿Ä£ÐÍ
*/
class Category extends Model {
}
-9
View File
@@ -1,9 +0,0 @@
<?php
namespace app\model;
use think\Model;
class Channel extends Model
{
}
-15
View File
@@ -1,15 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\model;
use think\Model;
class Client extends Model {
}
-122
View File
@@ -1,122 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\model;
use think\facade\Cache;
use think\Model;
/**
* 设置模型
*/
class Config extends Model {
protected $type = array(
'id' => 'integer',
);
protected $auto = array('name', 'update_time', 'status' => 1);
protected $insert = array('create_time');
protected function setNameAttr($value) {
return strtolower($value);
}
protected function getTypeTextAttr($value, $data) {
$config = Cache::get('system_config');
$type = $config['config_type_list'];
$type_text = explode(',', $type[$data['type']]);
return $type_text[0];
}
protected function getGroupTextAttr($value, $data) {
$config = Cache::get('system_config');
$group = $config['config_group_list'];
return isset($group[$data['group']]) ? $group[$data['group']] : '未分组';
}
public function lists() {
$map = array('status' => 1);
$res = $this->where($map)->field('type,name,value')->select();
$config = array();
foreach ($res->toArray() as $value) {
$config[$value['name']] = $this->parse($value['type'], $value['value']);
}
return $config;
}
public function updateConfig($data) {
if (empty($data['config'])) {
$this->error = "无更新";
return false;
}
foreach ($data['config'] as $key => $value) {
self::update(['value' => $value], ['name' => $key], ['value']);
}
Cache::set('system_config', null);
return true;
}
/**
* 根据配置类型解析配置
* @param integer $type 配置类型
* @param string $value 配置值
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
private function parse($type, $value) {
switch ($type) {
case 'textarea': //解析数组
$array = preg_split('/[,;\r\n]+/', trim($value, ",;\r\n"));
if (strpos($value, ':')) {
$value = array();
foreach ($array as $val) {
$list = explode(':', $val);
if (isset($list[2])) {
$value[$list[0]] = $list[1] . ',' . $list[2];
} else {
$value[$list[0]] = $list[1];
}
}
} else {
$value = $array;
}
break;
}
return $value;
}
public function getThemesList() {
$files = array();
$files['pc'] = $this->getList('pc');
$files['mobile'] = $this->getList('mobile');
return $files;
}
protected function getList($type) {
$path = './template/';
$file = opendir($path);
while (false !== ($filename = readdir($file))) {
if (!in_array($filename, array('.', '..'))) {
$files = $path . $filename . '/info.php';
if (is_file($files)) {
$info = include $files;
if (isset($info['type']) && $info['type'] == $type) {
$info['id'] = $filename;
$info['img'] = '/template/' . $filename . '/' . $info['img'];
$list[] = $info;
} else {
continue;
}
}
}
}
return isset($list) ? $list : array();
}
}
-10
View File
@@ -1,10 +0,0 @@
<?php
namespace app\model;
use think\Model;
class Content extends Model {
// 定义默认的表后缀(默认查询中文数据)
protected $suffix = '';
}
-17
View File
@@ -1,17 +0,0 @@
<?php
namespace app\model;
use think\Model;
class Form extends Model {
public $status = array(
1 => '开启',
0 => '关闭'
);
public function getStatusTextAttr($value, $data){
return isset($this->status[$data['status']]) ? $this->status[$data['status']] : '未知';
}
}
-125
View File
@@ -1,125 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\model;
use think\Model;
/**
* @title: 用户模型
*/
class Member extends Model {
protected $pk = 'uid';
protected $createTime = 'reg_time';
protected $updateTime = 'last_login_time';
protected $insert = ['reg_ip'];
protected $type = [
'uid' => 'integer',
'reg_time' => 'integer',
];
public $loginVisible = array('uid', 'username', 'nickname', 'access_token'); //用户登录成功返回的字段
protected function setPasswordAttr($value) {
$salt = rand_string(6);
$this->set('salt', $salt);
return md5($value . $salt);
}
protected function setRegIpAttr($value) {
return get_client_ip(1);
}
protected function getAccessTokenAttr($value, $data) {
return authcode($data['uid'] . '|' . $data['username'] . '|' . $data['password'], 'ENCODE');
}
/**
* @title 用户登录
* param username:用户名、手机号码、邮箱 password:密码、手机验证码、开源类型 type:登录类型(账号密码登录、手机号码+验证码登录、开源账号登录)
*/
public function login($username, $password, $type = 1) {
$map = array();
if (preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $username)) {
$type = 2;
} elseif (preg_match("/^1[34578]{1}\d{9}$/", $username)) {
$type = 3;
}
switch ($type) {
case 1:
$map['username'] = $username;
break;
case 2:
$map['email'] = $username;
break;
case 3:
$map['mobile'] = $username;
break;
default:
return false; //参数错误
}
if (!$username) {
return false;
}
$user = $this->where($map)->find();
if (isset($user['uid']) && $user['uid'] && $user['status']) {
/* 验证用户密码 */
if (md5($password . $user['salt']) === $user['password']) {
/* 更新登录信息 */
(new MemberLog())->record($user);
return $user->append(array('access_token'))->visible($this->loginVisible)->toArray(); //登录成功,返回用户信息
} else {
$this->error = "密码错误";
return false; //密码错误
}
} else {
$this->error = "用户不存在或被禁用";
return false;
}
}
/**
* @title: 注册
*/
public function register($data) {
$result = self::create($data);
if (false !== $result) {
$user = $this->where('uid', $result->uid)->find();
} else {
$this->error = "注册失败!";
return false;
}
/* 更新登录信息 */
(new MemberLog())->record($user);
return $user->append(array('access_token'))->visible($this->loginVisible)->toArray(); //登录成功,返回用户信息
}
/**
* @title: 获取用户列表
*/
public function getUserList() {
}
/**
* @title: 获取用户信息
*/
public function getInfo($uid) {
}
public function socialite() {
return $this->hasMany('MemberSocialite', 'uid', 'uid');
}
}
-29
View File
@@ -1,29 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\model;
use think\Model;
/**
* @title: 用户日志模型
*/
class MemberLog extends Model {
public function record($user){
/* 更新登录信息 */
$data = array(
'uid' => $user['uid'],
'login' => array('inc', '1'),
'last_login_time' => time(),
'last_login_ip' => get_client_ip(1),
);
Member::where(array('uid'=>$user['uid']))->update($data);
}
}
-59
View File
@@ -1,59 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\common\model;
/**
* 用户模型
*/
class MemberSocialite extends Base{
protected $type = array(
'uid' => 'integer',
);
public function register(){
if ($socialite->where('openid', $data['info']['openid'])->value('id')) {
$this->error = "请勿重复注册!";
return false;
} else {
$account = array(
'username' => $data['info']['openid'],
'password' => rand_string(8),
);
$result = self::create($account);
if (false !== $result) {
$socialite_info = $data['info'];
$user = $this->where('uid', $result->uid)->find();
$socialite_info['uid'] = $user['uid'];
$socialite_info['type'] = $data['open_type'];
$socialite->register($socialite_info);
} else {
$this->error = "注册失败!";
return false;
}
}
}
public function wechatLogin($user_info){
$socialite = $this->where('openid', $user_info['openid'])->where('type', 'wechat')->find();
$member = new Member();
if ($socialite) {
$this->where('id', $socialite['id'])->update($user_info);
if ($socialite['uid'] > 0) {
//绑定了用户则自动登录
$user = $member->where('uid', $socialite['uid'])->find();
$member->autoLogin($user);
}
}else{
$user_info['type'] = 'wechat';
$this->insert($user_info);
}
}
}
-45
View File
@@ -1,45 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\model;
use think\facade\Cache;
use think\Model;
use think\Request;
/**
* @title: ²Ëµ¥Ä£ÐÍ
*/
class Menu extends Model {
/**
* @title ÏÔʾ²Ëµ¥
*/
public function getAuthMenuList(Request $request) {
$list = [];
$current_controller = '/' . str_replace('.', '/', strtolower($request->controller()));
$current_url = $request->url;
$menu = Cache::get('menu');
if (!$menu) {
$res = self::where('is_menu', 1)->order('sort asc, id asc')->select()->toArray();
foreach ($res as $key => $item) {
$menu[$item['id']] = $item;
}
Cache::set('menu', $menu);
}
foreach ($menu as $key => $value) {
if ($request->isAdmin || in_array($value['id'], array())) {
$list[$value['id']] = $value;
}
}
$menuList = list_to_tree($list);
return $menuList;
}
}
-9
View File
@@ -1,9 +0,0 @@
<?php
namespace app\model;
use think\Model;
class Model extends Model
{
}
-8
View File
@@ -1,8 +0,0 @@
<?php
namespace app\model;
use think\Model;
class Rewrite extends Model {
}
-8
View File
@@ -1,8 +0,0 @@
<?php
namespace app\model;
use think\Model;
class SeoRule extends Model {
}
+9
View File
@@ -0,0 +1,9 @@
<?php
use app\AppService;
// 系统服务定义文件
// 服务在完成全局初始化之后执行
return [
AppService::class,
];