92 lines
2.9 KiB
PHP
92 lines
2.9 KiB
PHP
<?php
|
|
namespace Admin\Controller;
|
|
use Think\Controller;
|
|
class CraftController extends AdminController{
|
|
public function __construct(){
|
|
parent::__construct();
|
|
$this->table=D("craft");
|
|
}
|
|
|
|
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)->relation(true)->order("craft_id desc")->limit($page->firstRow, $page->listRows)->select();
|
|
foreach($data as $k=>$v){
|
|
$data[$k]['used'] = false;
|
|
if(D('flow_craft')->where(array('craft_id'=>$v['craft_id']))->find()){
|
|
$data[$k]['used'] = true;
|
|
}
|
|
}
|
|
$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{
|
|
$craft_id = I('craft_id');
|
|
$data= $this->table->find($craft_id);
|
|
$this->data = $data;
|
|
$this->craft_type = D('craft_type')->field('type_id as value,type_name as name')->select();
|
|
$this->display();
|
|
}
|
|
}
|
|
|
|
|
|
//删除
|
|
public function delete(){
|
|
$craft_id=I('craft_id');
|
|
$data = $this->table->find($craft_id);
|
|
if($data['craft_who_add']!=UID){
|
|
$this->error('没有权限删除别人的资料');
|
|
}
|
|
$this->table->delete($craft_id);
|
|
D("UserLog")->add("delete",$this->table->getTableName(),$craft_id);
|
|
$this->success("操作成功");
|
|
}
|
|
|
|
} |