File: /www/wwwroot/dd.cwoyt.com/Application/Admin/Controller/BannerController.class.php
<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 赛脑 <2233759493@qq.com> <http://www.sn.com>
// +----------------------------------------------------------------------
namespace Admin\Controller;
use User\Api\UserApi as UserApi;
use COM\Page;
/**
* 产品控制器
* @author 赛脑 <2233759493@qq.com>
*/
class BannerController extends AdminController {
public $infoadmin = array();
public function __construct(){
parent::__construct();
$perid = M('member')->where('uid = '.UID)->getField('perid');
$infoadmin = M('permissions')->where('perid = '.$perid)->field('product')->find();
if($infoadmin['product']){
$infoadmin['system'] = explode(',',$infoadmin['product']);
}
if(!$infoadmin['product']){
$this->error('参数错误!');
}
$this->infoadmin = $infoadmin;
$nav_type = 'product';
$nav_type_li = 'banner';
$this->assign('nav_type', $nav_type);
$this->assign('nav_type_li', $nav_type_li);
}
/**
* 产品列表
* @author 赛脑 <2233759493@qq.com>
*/
public function index(){
if(UID != 1){
$infoadmin = $this->peradmin;
if(!in_array("banner",$infoadmin['product'])){
$this->error('参数错误!');
}
}
$count = M('banner')->count();
$page = new Page($count,100);
$list = M('banner')->limit($page->firstRow.','.$page->listRows)->order('sort asc')->select();
$pages = $page->show();
$this->assign('count', $count);
$this->assign('_list', $list);
$this->assign('_page', $pages);
$this->meta_title = '幻灯片管理';
$this->display();
}
public function add(){
if(UID != 1){
$infoadmin = $this->peradmin;
if(!in_array("banner_add",$infoadmin['product'])){
$this->error('参数错误!');
}
}
if(IS_POST){
$data = array(
'title' => trim(I('post.title')),
'sort' => I('post.sort'),
'status' => I('post.status'),
'url' => I('post.url'),
'thumb' => I('post.thumb'),
);
if($data['status'] == 'on'){
$data['status'] = 1;
}else{
$data['status'] = 2;
}
if(I('post.bid')){
if(UID != 1){
$infoadmin = $this->peradmin;
if(!in_array("banner_update",$infoadmin['product'])){
$this->error('参数错误!');
}
}
action_log('banner_update', 'member', UID, UID);
M('banner')->where('bid = '.I('post.bid'))->save($data);
$this->success('编辑成功!',U('index'));
}else{
if(UID != 1){
$infoadmin = $this->peradmin;
if(!in_array("banner_add",$infoadmin['product'])){
$this->error('参数错误!');
}
}
M('banner')->add($data);
action_log('banner_add', 'member', UID, UID);
$this->success('添加成功!',U('index'));
}
}else{
$bid = I('get.bid');
$info = M('banner')->where('bid = '.$bid)->find();
$this->assign('info', $info);
$this->meta_title = '幻灯片管理';
$this->display();
}
}
public function sorts(){
if(IS_POST){
foreach(I('post.sort') as $k=>$v){
M('banner')->where('bid = '.$k)->save(array('sort' => $v));
}
}
$this->success('操作成功!',U('index'));
}
public function del(){
if(UID != 1){
$infoadmin = $this->peradmin;
if(!in_array("banner_del",$infoadmin['product'])){
$this->error('参数错误!');
}
}
$bid = I('get.bid');
M('banner')->where('bid = '.$bid)->delete();
action_log('banner_del', 'member', UID, UID);
$this->success('删除成功!',U('index'));
}
public function del_arr(){
if(IS_POST){
foreach($_POST['bid'] as $k=>$v){
M('banner')->where('bid = '.$v)->delete();
}
action_log('banner_del', 'member', UID, UID);
$this->success('删除成功!');
}
}
}