136 lines
5.2 KiB
PHP
136 lines
5.2 KiB
PHP
<?php
|
|
namespace Admin\Controller;
|
|
use Think\Controller;
|
|
class ModelController extends AdminController{
|
|
public function __construct(){
|
|
parent::__construct();
|
|
$this->table=D("model");
|
|
$this->table_id=I("table_id",0,"int");
|
|
$this->tableName=M("table")->where(array("table_id"=>$this->table_id))->getField("table_name");
|
|
//展示该数据表下所有的字段
|
|
$this->table_field=M("table_field")->where(array("table_id"=>$this->table_id))->order("sort asc,field_id asc")->select();
|
|
}
|
|
public function index(){
|
|
$data=$this->table->where(array("table_id"=>$this->table_id))->order('sort asc')->select();
|
|
$this->assign("data",$data);
|
|
$this->display();
|
|
}
|
|
public function add(){
|
|
if(IS_POST){
|
|
if (!$this->table->create()){//验证
|
|
$this->error($this->table->getError());
|
|
}
|
|
$data=$this->table->data_save();
|
|
if($_POST[modelid]){
|
|
D("UserLog")->add("update",$this->table->getTableName(),$data[modelid]);
|
|
}else{
|
|
D("UserLog")->add("add",$this->table->getTableName(),$data[modelid]);
|
|
}
|
|
$this->success($data);
|
|
}else{
|
|
//
|
|
$this->display();
|
|
}
|
|
}
|
|
public function editor(){
|
|
$modelid=I("get.modelid",0,"int");
|
|
$r=$this->table->find($modelid);
|
|
//将formtemp中的字段名称更新到字段列表中
|
|
$field_name_arr=array();
|
|
$field_arr=array();
|
|
$formtype_arr=explode("\r\n",$r["formtemp"]);
|
|
foreach($formtype_arr as $v){
|
|
$f=explode("<!--field-->",$v);
|
|
$field_arr[]=$f[1];
|
|
$field_name_arr[$f[1]]=$f[0];
|
|
}
|
|
$new_table_field=array();
|
|
$table_field=$this->table_field;
|
|
foreach($table_field as $v){
|
|
//更新字段名
|
|
if(in_array($v["field"], $field_arr)){
|
|
$v["name"]=$field_name_arr[$v["field"]];
|
|
}
|
|
//判断该字段分别在每个勾选项里是否有勾选
|
|
$v["is_enter_checked"]=strstr($r[is_enter],",".$v["field"].",")?1:0;
|
|
$v["is_contribute_checked"]=strstr($r[is_contribute],",".$v["field"].",")?1:0;
|
|
$v["must_enter_checked"]=strstr($r[must_enter],",".$v["field"].",")?1:0;
|
|
$v["is_list_checked"]=strstr($r[is_list],",".$v["field"].",")?1:0;
|
|
$v["is_search_checked"]=strstr($r[is_search],",".$v["field"].",")?1:0;
|
|
$v["is_sort_checked"]=strstr($r[is_sort],",".$v["field"].",")?1:0;
|
|
//
|
|
$new_table_field[]=$v;
|
|
}
|
|
$this->table_field=$new_table_field;
|
|
//
|
|
$this->assign("r",$r);
|
|
$this->display();
|
|
}
|
|
//编辑栏目字段
|
|
public function editorCatModel(){
|
|
if(IS_POST){
|
|
$this->table->saveCatModel();
|
|
$this->success("ok");
|
|
}else{
|
|
$modelid=I("get.modelid",0,"int");
|
|
$r=$this->table->find($modelid);
|
|
//将formtemp中的字段名称更新到字段列表中
|
|
$field_name_arr=array();
|
|
$field_arr=array();
|
|
$formtype_arr=explode("\r\n",$r["cat_formtemp"]);
|
|
foreach($formtype_arr as $v){
|
|
$f=explode("<!--field-->",$v);
|
|
$field_arr[]=$f[1];
|
|
$field_name_arr[$f[1]]=$f[0];
|
|
}
|
|
$new_table_field=array();
|
|
$table_field=M("cat_field")->order("sort asc,field_id asc")->select();
|
|
foreach($table_field as $v){
|
|
//更新字段名
|
|
if(in_array($v["field"], $field_arr)){
|
|
$v["name"]=$field_name_arr[$v["field"]];
|
|
}
|
|
//判断该字段分别在每个勾选项里是否有勾选
|
|
$v["cat_is_enter_checked"]=strstr($r[cat_is_enter],",".$v["field"].",")?1:0;
|
|
$v["cat_must_enter_checked"]=strstr($r[cat_must_enter],",".$v["field"].",")?1:0;
|
|
//
|
|
$new_table_field[]=$v;
|
|
}
|
|
$this->table_field=$new_table_field;
|
|
//
|
|
$this->assign("modelid",$modelid);
|
|
$this->display();
|
|
}
|
|
}
|
|
//删除节点
|
|
public function delete(){
|
|
$modelid=I("modelid",0,'intval');
|
|
|
|
$result=$this->table->data_delete($modelid);
|
|
if(!$result){
|
|
$this->error($this->table->getError());
|
|
}
|
|
D("UserLog")->add("delete",$this->table->getTableName(),$modelid);
|
|
$this->success("删除成功");
|
|
}
|
|
//字段排序
|
|
public function sort(){
|
|
$ids=I("modelid");
|
|
$sort=I("sort");
|
|
foreach($ids as $key=>$id){
|
|
$data['modelid']=(int)$id;
|
|
$data['sort']=(int)$sort[$key];
|
|
$this->table->save($data);
|
|
}
|
|
$this->success("排序更改成功");
|
|
}
|
|
//获取导入的excel模板
|
|
public function getExportExcelDemo(){
|
|
$modelid=I("modelid",0,'intval');
|
|
if(!$modelid){
|
|
$this->error("缺少[modelid]参数!");
|
|
}else{
|
|
$this->table->getExportExcelDemo($modelid,I("get.cat_type"));
|
|
}
|
|
}
|
|
} |