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

89 lines
2.5 KiB
PHP

<?php
namespace Admin\Controller;
use Think\Controller;
class AdController extends AdminController{
public function __construct(){
parent::__construct();
$this->table=D("Ad");
}
//
public function index(){
$where["adid"]=I("get.adid",0,"intval");
if(!$where["adid"]){
$this->error("缺少adid参数");
}
$data=$this->table->where($where)->order("sort asc,id asc")->select();
$this->adid=$where["adid"];
$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{
$adid=I("get.adid",0,"intval");
if(!$adid){
$this->error("缺少adid参数");
}
$this->adid=$adid;
$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{
$id=I("get.id",0,"int");
$r=$this->table->find($id);
$this->assign("r",$r);
$this->display();
}
}
//
public function delete(){
$ids=I("ids");
if(!$ids){
$this->error('请选择信息!');
return false;
}
if(is_array($ids)){
foreach($ids as $id){
$this->table->delete($id);
}
}else{
$this->table->delete($ids);
}
D("UserLog")->add("delete",$this->table->getTableName(),$ids);
$this->success("删除成功");
}
//字段排序
public function sort(){
$ids=I("id");
$sort=I("sort");
foreach($ids as $key=>$id){
$data['id']=(int)$id;
$data['sort']=(int)$sort[$key];
$this->table->save($data);
}
$this->success("排序更改成功");
}
}