424 lines
15 KiB
PHP
424 lines
15 KiB
PHP
<?php
|
|
namespace Admin\Controller;
|
|
use Think\Controller;
|
|
class InfoController extends CatController{
|
|
public function __construct(){
|
|
parent::__construct();
|
|
$this->table=D("Info");
|
|
$catid=I("catid",0,"int");
|
|
$modelid=I("modelid",0,"int");
|
|
if($modelid){
|
|
$modelid=$modelid;
|
|
}else{
|
|
$modelid=$GLOBALS['cat'][$catid]["modelid"];
|
|
}
|
|
//
|
|
if($catid){
|
|
$this->catid=$catid;
|
|
$this->cat=$GLOBALS['cat'][$this->catid];
|
|
}
|
|
//
|
|
$this->modelinfo=$GLOBALS['model'][$modelid];
|
|
$this->modelid=$modelid;
|
|
if(!$this->modelinfo){
|
|
$this->error("模型不存在!");
|
|
}
|
|
//
|
|
$this->modelform=APP_PATH.'Data/modelTemp/'.$this->cat['modelid'].".php";
|
|
$view_where[type]="view";
|
|
if($this->admin_lang){
|
|
$view_where["lang"]=$this->admin_lang;
|
|
}
|
|
$this->viewtemp=M("template")->where($view_where)->order("sort asc,template_id desc")->select();
|
|
}
|
|
//列表
|
|
public function index(){
|
|
//判断是否在用户勾选权限内[超级管理员不做验证]
|
|
if(!check_user_cat("info_view",$this->catid)){
|
|
$this->error("您没有权限查看此栏目!");
|
|
}
|
|
//
|
|
$where=array();
|
|
$where['catid']=array("IN",getSonCat($this->catid));
|
|
$where['modelid']=$this->modelid;
|
|
//审核
|
|
$checked=I("get.checked");
|
|
if($checked==1){
|
|
$where['checked']=1;
|
|
}elseif($checked==9){
|
|
$where['checked']=0;
|
|
}
|
|
//分类
|
|
$this->catOption=$this->getCat(($this->currentCatid));
|
|
$this->catOption="<option value='{$this->currentCatid}' ".$this_selected.">{$GLOBALS['cat'][$this->currentCatid][name]}</option>".$this->catOption;
|
|
//判断是不是单页栏目
|
|
if($this->cat["is_page"]){
|
|
$this->is_page();
|
|
return;
|
|
}
|
|
//ID
|
|
$id=I("get.id");
|
|
if($id){
|
|
$where['id']=$id;
|
|
}
|
|
//关键词
|
|
$keywords=I("get.keywords");
|
|
if($keywords){
|
|
$where['keywords|title|id']=array('LIKE','%'.$keywords.'%');
|
|
}
|
|
//按指定字段搜索
|
|
$field=explode(",",trim($this->modelinfo["is_search"],","));
|
|
if($field){
|
|
foreach($field as $v){
|
|
if(I($v)){
|
|
$where[$v]=I($v);
|
|
}
|
|
}
|
|
}
|
|
//查询与分页
|
|
$listRows=C("display.admin_shownum");//每页显示多少条
|
|
$total=$this->table->relation("cat")->where($where)->count();
|
|
$page = new \Think\Page($total, $listRows);
|
|
$order=$this->cat["reorder"]?$this->cat["reorder"]:"sort asc,is_top desc,is_good desc,newstime desc";//默认排序方式
|
|
$data=$this->table->relation("cat")->where($where)->order($order)->limit($page->firstRow,$page->listRows)->select();
|
|
$this->assign("listpage", $page->show());
|
|
//数据再处理
|
|
foreach($data as $key=>$v){
|
|
//栏目名称
|
|
$data[$key][cat]=M("cat")->find($v[catid]);
|
|
}
|
|
$this->assign("data",$data);
|
|
//判断是否有自定义列表模板
|
|
if($this->modelinfo[listtemp]){
|
|
$this->display($this->modelinfo[listtemp]);
|
|
}else{
|
|
$this->display();
|
|
}
|
|
|
|
}
|
|
public function add(){
|
|
if(!check_user_cat("info_add",I("catid"))){
|
|
$this->error("您没有操作权限");
|
|
}
|
|
if(IS_POST){
|
|
if (!$this->table->relation(true)->create()){//验证
|
|
$this->error($this->table->relation(true)->getError());
|
|
}
|
|
$result=$this->table->data_add();
|
|
D("UserLog")->add("add",$this->table->getTableName(),$result[id],$_POST[title]);
|
|
if(!$result){
|
|
$this->error($this->table->getError());
|
|
}
|
|
//刷新静态页
|
|
$this->updateViewHtml($result[id]);
|
|
$this->success($result);
|
|
}else{
|
|
$this->cat=$this->selfModelCat2();
|
|
$this->pubid=make_pubid();
|
|
$this->display();
|
|
}
|
|
}
|
|
public function editor(){
|
|
if(!check_user_cat("info_editor",I("catid"))){
|
|
$this->error("您没有操作权限");
|
|
}
|
|
if(IS_POST){
|
|
if (!$this->table->create()){//验证
|
|
$this->error($this->table->getError());
|
|
}
|
|
$result=$this->table->data_editor();
|
|
D("UserLog")->add("update",$this->table->getTableName(),$result[id],$_POST[title]);
|
|
if(!$result){
|
|
$this->error($this->table->getError());
|
|
}
|
|
//刷新静态页
|
|
$this->updateViewHtml($result[id]);
|
|
$this->success($data);
|
|
|
|
}else{
|
|
$id=I("get.id",0,"int");
|
|
$r=$this->table->relation(true)->find($id);
|
|
if(!$r){$this->error("信息不存在");};
|
|
//副表数据合并
|
|
if($r["cms_".$this->modelinfo[table_name]."_data"]){
|
|
$newdata=array_merge($r,$r["cms_".$this->modelinfo[table_name]."_data"]);
|
|
unset($newdata["cms_".$this->modelinfo[table_name]."_data"]);
|
|
$r=$newdata;
|
|
}
|
|
//防止在某些情况下没有pubid
|
|
$r["pubid"]=$r["pubid"]?$r["pubid"]:make_pubid();
|
|
//
|
|
$this->cat=$this->selfModelCat2();
|
|
//
|
|
$this->assign("r",$r);
|
|
$this->display();
|
|
}
|
|
}
|
|
//删除
|
|
public function delete(){
|
|
if(!check_user_cat("info_delete",I("catid"))){
|
|
$this->error("您没有操作权限");
|
|
}
|
|
$ids=I("ids");
|
|
//删除静态页
|
|
$this->deleteViewHtml($ids);
|
|
$result=$this->table->data_delete($ids);
|
|
if(!$result){
|
|
$this->error($this->table->getError());
|
|
}
|
|
D("UserLog")->add("delete",$this->table->getTableName(),$ids);
|
|
$this->success("删除成功");
|
|
}
|
|
//字段排序
|
|
public function sort(){
|
|
$id=I("id");
|
|
$sort=I("sort");
|
|
foreach($id as $key=>$vid){
|
|
$data['id']=(int)$vid;
|
|
$data['sort']=(int)$sort[$key];
|
|
$this->table->save($data);
|
|
}
|
|
D("UserLog")->add("update",$this->table->getTableName(),$ids);
|
|
$this->success("排序更改成功");
|
|
}
|
|
//审核
|
|
public function checked(){
|
|
if(!check_user_cat("info_checked",I("catid"))){
|
|
$this->error("您没有操作权限");
|
|
}
|
|
$checked=I("get.checked",0,"intval");
|
|
$ids=I("ids");
|
|
if(!$ids){$this->error("请勾选信息!");};
|
|
foreach($ids as $key=>$vid){
|
|
$data['id']=(int)$vid;
|
|
$data['checked']=(int)$checked;
|
|
$this->table->save($data);
|
|
//刷新静态页
|
|
if($checked){
|
|
$this->updateViewHtml($data['id']);
|
|
}else{
|
|
$this->deleteViewHtml($data['id']);
|
|
}
|
|
}
|
|
D("UserLog")->add("update",$this->table->getTableName(),$ids);
|
|
$this->success("审核操作成功");
|
|
}
|
|
//置顶
|
|
public function set_top(){
|
|
$ids=I("ids");
|
|
if(!$ids){$this->error("请勾选信息!");};
|
|
foreach($ids as $key=>$vid){
|
|
$data['id']=(int)$vid;
|
|
$data['is_top']=I("get.is_top",0,"intval");
|
|
$this->table->save($data);
|
|
}
|
|
D("UserLog")->add("update",$this->table->getTableName(),$ids);
|
|
$this->success("置顶操作成功");
|
|
}
|
|
//推荐
|
|
public function set_good(){
|
|
$ids=I("ids");
|
|
if(!$ids){$this->error("请勾选信息!");};
|
|
foreach($ids as $key=>$vid){
|
|
$data['id']=(int)$vid;
|
|
$data['is_good']=I("get.is_good",0,"intval");
|
|
$this->table->save($data);
|
|
}
|
|
D("UserLog")->add("update",$this->table->getTableName(),$ids);
|
|
$this->success("推荐操作成功");
|
|
}
|
|
//数据导入
|
|
public function import(){
|
|
if(IS_POST){
|
|
$Export=new \Admin\Model\ImportDataModel($_POST);
|
|
//数据验证
|
|
$result=$Export->create();
|
|
if(!is_array($result)){
|
|
$this->error($Export->getError());
|
|
}
|
|
//创建数据表对象
|
|
$Export->creatExcelObj();
|
|
//获取表格数据
|
|
$Export->getExcelData();
|
|
//提取表格第一行做为字段名称
|
|
$Export->getFieldName();
|
|
//提取图片文件,并保存到服务器
|
|
$Export->saveImg();
|
|
//修正$this->fieldKey,$this->fieldName
|
|
//$Export->repairFieldName();
|
|
$result=$Export->insertData();
|
|
$this->success($result);
|
|
}else{
|
|
$this->cat=$this->selfModelCat();
|
|
$this->display();
|
|
}
|
|
}
|
|
//单页信息
|
|
public function is_page(){
|
|
if(IS_POST){
|
|
if (!$this->table->create()){//验证
|
|
$this->error($this->table->getError());
|
|
}
|
|
//保存数据
|
|
if(I("post.id")){
|
|
$result=$this->table->data_editor();
|
|
}else{
|
|
$result=$this->table->data_add();
|
|
}
|
|
if(!$result){
|
|
$this->error($this->table->getError());
|
|
}
|
|
$this->success($data);
|
|
|
|
}else{
|
|
$r=$this->table->relation(true)->where(array("catid"=>$this->catid))->order("id desc")->find();
|
|
if(!$r){
|
|
$r["pubid"]= make_pubid();
|
|
}else{
|
|
//副表数据合并
|
|
if($r["cms_".$this->modelinfo[table_name]."_data"]){
|
|
$newdata=array_merge($r,$r["cms_".$this->modelinfo[table_name]."_data"]);
|
|
unset($newdata["cms_".$this->modelinfo[table_name]."_data"]);
|
|
$r=$newdata;
|
|
}
|
|
}
|
|
$this->assign("r",$r);
|
|
$this->display("is_page");
|
|
}
|
|
}
|
|
//整站所有相同模型的栏目(用在 信息移动,复制页面里的)
|
|
private function selfModelCat($pid=0,$str=""){
|
|
$where["pid"]=$pid;
|
|
$where["status"]=1;
|
|
$cat=M("cat")->field("catid,level,name,modelid,status,sort,pid")->where($where)->order("sort asc,catid desc")->select();
|
|
if(count($cat)>0){
|
|
foreach($cat as $v){
|
|
$nbsp_str="";
|
|
for($i=1;$i<$v[level];$i++){
|
|
$nbsp_str.=" ";
|
|
}
|
|
if($v["modelid"]!=$this->modelid){
|
|
$this_selected="disabled";
|
|
$disabled_str="(<b>模型不同</b>)";
|
|
}else{
|
|
$this_selected="";
|
|
$disabled_str="";
|
|
}
|
|
$str.="<option value='{$v[catid]}' ".$this_selected.">{$nbsp_str}|-{$v[name]} $disabled_str</option>";
|
|
$str=$this->selfModelCat($v[catid],$str);
|
|
}
|
|
return $str;
|
|
}else{
|
|
return $str;
|
|
}
|
|
}
|
|
//当前栏目下相同模型的栏目(用在 信息移动,复制页面里的)
|
|
private function selfModelCat2($pid=0,$str=""){
|
|
$where["pid"]=$pid;
|
|
$where["status"]=1;
|
|
$cat=M("cat")->field("catid,level,name,modelid,status,sort,pid")->where($where)->order("sort asc,catid desc")->select();
|
|
if(count($cat)>0){
|
|
foreach($cat as $v){
|
|
$nbsp_str="";
|
|
for($i=1;$i<$v[level];$i++){
|
|
$nbsp_str.=" ";
|
|
}
|
|
if($v["modelid"]!=$this->modelid){
|
|
$this_selected="disabled";
|
|
$disabled_str="(<i>模型不同</i>)";
|
|
}else{
|
|
$this_selected="";
|
|
$disabled_str="";
|
|
}
|
|
//默认选中当前栏目
|
|
if($v["catid"]==$this->catid){
|
|
$this_selected2="selected";
|
|
}else{
|
|
$this_selected2="";
|
|
}
|
|
$str.="<option value='{$v[catid]}' ".$this_selected." ".$this_selected2.">{$nbsp_str}|-{$v[name]} $disabled_str</option>";
|
|
$str=$this->selfModelCat2($v[catid],$str);
|
|
}
|
|
return $str;
|
|
}else{
|
|
return $str;
|
|
}
|
|
}
|
|
//复制信息
|
|
public function copy(){
|
|
if(IS_POST){
|
|
$ids=I("ids");
|
|
if(!$ids){
|
|
$this->error("请选择信息");
|
|
}
|
|
$catid=I("target_catid","intval",0);
|
|
if(!$catid){
|
|
$this->error("请选择目标栏目");
|
|
}
|
|
$data=$this->table->where(array(
|
|
"id"=>array("in",$ids)
|
|
))->select();
|
|
foreach($data as $v){
|
|
$oldId=$v["id"];
|
|
//主表插入
|
|
unset($v["id"]);
|
|
$v["catid"]=$catid;
|
|
$id=$this->table->add($v);
|
|
//副表插入
|
|
$fbData=M("cms_".$this->modelinfo[table_name]."_data")->find($oldId);
|
|
$fbData["id"]=$id;
|
|
M("cms_".$this->modelinfo[table_name]."_data")->add($fbData);
|
|
}
|
|
$this->table->updateInfoNum($catid);
|
|
D("UserLog")->add("add",$this->table->getTableName(),$ids);
|
|
$this->success("操作成功");
|
|
}else{
|
|
$this->cat=$this->selfModelCat();
|
|
$this->display();
|
|
}
|
|
}
|
|
//移动信息
|
|
public function move(){
|
|
if(IS_POST){
|
|
$ids=I("ids");
|
|
if(!$ids){
|
|
$this->error("请选择信息");
|
|
}
|
|
$catid=I("target_catid","intval",0);
|
|
if(!$catid){
|
|
$this->error("请选择目标栏目");
|
|
}
|
|
$data=$this->table->where(array(
|
|
"id"=>array("in",$ids)
|
|
))->select();
|
|
foreach($data as $v){
|
|
$update["id"]=$v[id];
|
|
$update["catid"]=$catid;
|
|
$id=$this->table->save($update);
|
|
}
|
|
$this->table->updateInfoNum($this->catid);
|
|
$this->table->updateInfoNum($catid);
|
|
D("UserLog")->add("update",$this->table->getTableName(),$ids);
|
|
$this->success("操作成功");
|
|
}else{
|
|
$this->cat=$this->selfModelCat();
|
|
$this->display("copy");
|
|
}
|
|
}
|
|
//更新静态页
|
|
private function updateViewHtml($id){
|
|
$r=$this->table->find($id);
|
|
if($this->cat[view_type]=="static"&&$r["checked"]){
|
|
\Admin\Model\UpdateModel::detailHtml($this->catid,$id,$this->cat["classpath"]);
|
|
}
|
|
}
|
|
//删除静态页
|
|
private function deleteViewHtml($ids){
|
|
$where["id"]= is_array($ids)?array("IN",$ids):$ids;
|
|
$data=$this->table->where($where)->select();
|
|
foreach($data as $v){
|
|
$url=".".$GLOBALS["cat"][$v["catid"]]["classpath"].$v["id"].".html";
|
|
@unlink($url);
|
|
}
|
|
}
|
|
} |