qc.ifish7.com/Application/Admin/Controller/AdCatController.class.php

85 lines
2.7 KiB
PHP

<?php
namespace Admin\Controller;
use Think\Controller;
class AdCatController extends AdminController{
public function __construct(){
parent::__construct();
$this->table=D("AdCat");
$this->adtypeInc=array("图片轮播","单张图片","广告代码");
}
//
public function index(){
$data=$this->table->order("sort asc,adid asc")->select();
$this->assign('data', $data);
$this->display($type);
}
//
public function add(){
if(IS_POST){
$data=$this->table->create();
if (!$data){//验证
$this->error($this->table->getError());
}
$id=$this->table->add($data);
//写日志
D("UserLog")->add("add",$this->table->getTableName(),$id);
$this->success($id);
}else{
$this->pubid=make_pubid();
$this->display();
}
}
public function editor(){
if(IS_POST){
$data=$this->table->create();
if (!$data){//验证
$this->error($this->table->getError());
}
$this->table->save($data);
D("UserLog")->add("update",$this->table->getTableName(),$data[$this->table->getPk()]);
$this->success($data);
}else{
$adid=I("get.adid",0,"int");
$r=$this->table->find($adid);
$this->assign("r",$r);
$this->display();
}
}
//
public function delete(){
$ids=I("ids");
if(!$ids){
$this->error("请选择信息!");
}
if(is_array($ids)){
foreach($ids as $id){
$ad=M("ad")->where("adid=".$id)->count();
if($ad){
$this->error("该广告位下面有广告内容,请先删除广告内容!");
}
$this->table->delete($id);
}
}else{
$ad=M("ad")->where("adid=".$ids)->count();
if($ad){
$this->error("该广告位下面有广告内容,请先删除广告内容!");
}
$this->table->delete($ids);
}
D("UserLog")->add("delete",$this->table->getTableName(),$ids);
$this->success("删除成功");
}
//字段排序
public function sort(){
$ids=I("adid");
$sort=I("sort");
foreach($ids as $key=>$id){
$data['adid']=(int)$id;
$data['sort']=(int)$sort[$key];
$this->table->save($data);
}
$this->success("排序更改成功");
}
}