82 lines
2.5 KiB
PHP
82 lines
2.5 KiB
PHP
<?php
|
|
namespace Admin\Controller;
|
|
use Think\Controller;
|
|
class CraftTemplateController extends AdminController{
|
|
public function __construct(){
|
|
parent::__construct();
|
|
$this->table=D("craft_template");
|
|
}
|
|
|
|
public function index(){
|
|
//搜索
|
|
$where=array();
|
|
// //工艺名称
|
|
// $craft_name=I("get.craft_name");
|
|
// if($craft_name){
|
|
// $where['craft_name'] = array('LIKE','%'.$craft_name.'%');
|
|
// }
|
|
|
|
$listRows=C("display.admin_shownum");//每页显示多少条
|
|
$total=$this->table->where($where)->count();
|
|
$page = new \Think\Page($total, $listRows);
|
|
$data=$this->table->where($where)->limit($page->firstRow, $page->listRows)->select();
|
|
$listpage = $page->show();
|
|
$this->assign("listpage", $listpage);
|
|
$this->data=$data;
|
|
$this->display();
|
|
}
|
|
|
|
public function add(){
|
|
if(IS_POST){
|
|
$data=$this->table->create();
|
|
|
|
if (!$data){//验证
|
|
$this->error($this->table->getError());
|
|
}
|
|
//数据添加
|
|
$result=$this->table->data_add();
|
|
if(!$result){
|
|
$this->error($this->table->getError());
|
|
}
|
|
D("UserLog")->add("add",$this->table->getTableName(),$result);
|
|
$this->success($data);
|
|
}
|
|
else{
|
|
$this->craft_type = D('craft_type')->field('type_id as value,type_name as name')->select();
|
|
$this->display();
|
|
}
|
|
}
|
|
//
|
|
public function editor(){
|
|
if(IS_POST){
|
|
$data=$this->table->create();
|
|
|
|
if (!$data){//验证
|
|
$this->error($this->table->getError());
|
|
}
|
|
$result=$this->table->data_save();
|
|
if(!$result){
|
|
$this->error($this->table->getError());
|
|
}
|
|
D("UserLog")->add("update",$this->table->getTableName(),$result);
|
|
$this->success($data);
|
|
}
|
|
else{
|
|
$template_id = I('template_id');
|
|
$data= $this->table->find($template_id);
|
|
$this->data = $data;
|
|
$this->display();
|
|
}
|
|
}
|
|
|
|
|
|
//删除
|
|
public function delete(){
|
|
$template_id=I('template_id');
|
|
$this->table->delete($template_id);
|
|
D('craft_template_param')->where(array('template_id'=>$template_id))->delete();
|
|
D("UserLog")->add("delete",$this->table->getTableName(),$template_id);
|
|
$this->success("操作成功");
|
|
}
|
|
|
|
} |