日常更新

This commit is contained in:
2019-09-29 21:19:30 +08:00
parent c29b8358be
commit 07faf60918
196 changed files with 1367 additions and 524 deletions

View File

@@ -249,14 +249,14 @@ function get_nav_url($url) {
*/
function get_cover($cover_id, $field = null) {
if (empty($cover_id)) {
return BASE_PATH . '/static/images/default.png';
return '/static/common/images/default.png';
}
$picture = db('Picture')->where(array('status' => 1, 'id' => $cover_id))->find();
$picture = \think\facade\Db::name('Picture')->where(array('status' => 1, 'id' => $cover_id))->find();
if ($field == 'path') {
if (!empty($picture['url'])) {
$picture['path'] = $picture['url'] ? BASE_PATH . $picture['url'] : BASE_PATH . '/static/images/default.png';
$picture['path'] = $picture['url'] ? $picture['url'] : '/static/common/images/default.png';
} else {
$picture['path'] = $picture['path'] ? BASE_PATH . $picture['path'] : BASE_PATH . '/static/images/default.png';
$picture['path'] = $picture['path'] ? $picture['path'] : '/static/common/images/default.png';
}
}
return empty($field) ? $picture : $picture[$field];

View File

@@ -22,7 +22,8 @@ class Ad extends Admin{
$res = $adp->paginate(25, false, array(
'query' => $this->request->param()
));
$data = $res->toArray();
$data = $res->append(['show_type_text', 'status_text'])->toArray();
$this->data['data'] = $data;
return $this->data;
}
@@ -44,6 +45,7 @@ class Ad extends Admin{
$info['appid'] = rand_string(10, 1); //八位数字appid
$info['appsecret'] = rand_string(32); //32位数字加字母秘钥
$this->data['data'] = array(
'show_type' => $adp->show_type,
'info' => $info
);
@@ -71,6 +73,7 @@ class Ad extends Admin{
$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;
@@ -104,7 +107,7 @@ class Ad extends Admin{
$res = $ad->paginate(25, false, array(
'query' => $this->request->param()
));
$data = $res->toArray();
$data = $res->append(['cover','status_text'])->toArray();
$this->data['data'] = $data;
return $this->data;
}

View File

@@ -9,13 +9,97 @@
namespace app\controller\admin;
use app\controller\Admin;
use app\Model\Category as CategoryModel;
class Category extends Admin{
/**
* @title 系统首页
* @title 栏目列表
*/
public function index(){
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('删除失败!');
}
}
}

View File

@@ -9,16 +9,101 @@
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);
$map = array();
$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 系统首页
* @title 添加频道
*/
public function index(){
$this->data['data'] = array(
'tree' => array()
);
return $this->data;
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('删除失败!');
}
}
}

View File

@@ -10,12 +10,89 @@ namespace app\controller\admin;
use app\controller\Admin;
use app\model\Form as FormModel;
class Form extends Admin{
/**
* @title 系统首页
*/
public function index(){
public function index(FormModel $form){
if ($this->request->isAjax()) {
$res = $form->paginate(25, false, array(
'query' => $this->request->param()
));
$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('删除失败!');
}
}
}

View File

@@ -20,7 +20,8 @@ class Index extends Admin{
/**
* @title 系统首页
*/
public function index(){
public function index(Menu $menu){
$this->data['data'] = array('menu' => $menu->getMenu($this->request));
return $this->data;
}

View File

@@ -32,7 +32,11 @@ class Admin {
}
return json($this->data);
} else {
return $response->data($this->fetch());
if(\is_string($this->data) && $this->data != ''){
return $response;
}else{
return $response->data($this->fetch());
}
}
}

View File

@@ -8,7 +8,6 @@
// +----------------------------------------------------------------------
namespace app\http\middleware;
use think\facade\Cache;
use think\facade\Session;
use think\facade\View;
@@ -17,8 +16,6 @@ use think\facade\View;
*/
class AdminAuth {
protected $data = ['menu' => [], 'meta_title' => ''];
public function handle($request, \Closure $next) {
$user = Session::get('user');
@@ -28,39 +25,12 @@ class AdminAuth {
$request->isAdmin = true;
}
$this->getMenu($request); //设置菜单
$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();
}
}
/**
* @title 显示菜单
*/
protected function getMenu($request) {
$list = [];
$current_controller = '/' . str_replace('.', '/', strtolower($request->controller()));
$current_url = $current_controller . '/' . strtolower($request->action());
$menu = Cache::get('menu');
if (!$menu) {
$res = (new \app\model\Menu())->where('is_menu', 1)->select();
foreach ($res as $key => $item) {
$menu[$item['id']] = $item->toArray();
}
Cache::set('menu', $menu);
}
foreach ($menu as $key => $value) {
if($current_url == $value['url']){
$this->data['meta_title'] = $value['title'];
}
if ($request->isAdmin || in_array($value['id'], array())) {
$list[$value['id']] = $value;
}
}
$menuList = list_to_tree($list);
$this->data['menu'] = $menuList;
View::assign($this->data);
}
}

View File

@@ -3,7 +3,18 @@ namespace app\model;
use think\Model;
class Ad extends 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']] : '未知';
}
}

View File

@@ -3,7 +3,31 @@ namespace app\model;
use think\Model;
class AdPlace extends 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
app/model/Category.php Normal file
View File

@@ -0,0 +1,19 @@
<?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 {
}

17
app/model/Form.php Normal file
View File

@@ -0,0 +1,17 @@
<?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']] : '未知';
}
}

View File

@@ -10,12 +10,40 @@
namespace app\model;
use think\Model;
use think\Request;
use think\facade\Cache;
/**
* @title: 菜单模型
* @title: ²Ëµ¥Ä£ÐÍ
*/
class Menu extends Model {
/**
* @title ÏÔʾ²Ëµ¥
*/
public function getMenu(Request $request) {
$list = [];
$current_controller = '/' . str_replace('.', '/', strtolower($request->controller()));
$current_url = $current_controller . '/' . strtolower($request->action());
$menu = Cache::get('menu');
if (!$menu) {
$res = (new \app\model\Menu())->where('is_menu', 1)->order('sort asc, id asc')->select();
foreach ($res as $key => $item) {
$menu[$item['id']] = $item->toArray();
}
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;
}
public function getAuthMenuList(){
$list = $this->select();
$data = list_to_tree($list->toArray(), 'id', 'pid');