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

112 lines
3.4 KiB
PHP

<?php
namespace Admin\Controller;
use Think\Controller;
class CraftParamController extends AdminController{
public function __construct(){
parent::__construct();
$this->table=D("CraftParam");
}
public function index(){
//搜索
$where=array();
//工艺名称
$flow_craft_id=I("flow_craft_id");
if($flow_craft_id){
$where['flow_craft_id'] = $flow_craft_id;
}
else{
$this->error('非法操作,无工艺选择');
}
$listRows=C("display.admin_shownum");//每页显示多少条
$total=$this->table->where($where)->count();
$page = new \Think\Page($total, $listRows);
$data=$this->table->where($where)->order("param_id")->limit($page->firstRow, $page->listRows)->select();
$listpage = $page->show();
$this->assign("listpage", $listpage);
$this->data=$data;
$this->craft = D('flow_craft')->relation(true)->find($flow_craft_id);
$flow_id = $this->craft['flow']['flow_id'];
$used = false;
if(D('product')->where(array('flow_id'=>$flow_id))->find()){
$used = true;
}
$this->used = $used;
$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->flow_craft_id = I('flow_craft_id');
$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{
$param_id = I('param_id');
$data= $this->table->find($param_id);
$this->data = $data;
$this->display();
}
}
//删除
public function delete(){
$param_id=I('param_id');
$this->table->delete($param_id);
D("UserLog")->add("delete",$this->table->getTableName(),$param_id);
$this->success("操作成功");
}
public function import(){
if(IS_POST){
$flow_craft_id = I('flow_craft_id');
$template_id = I('template_id');
$data = D("craft_template_param")->where(array('template_id'=>$template_id))->select();
foreach ($data as $k=>$v){
unset($v['param_id']);
unset($v['template_id']);
$v['flow_craft_id'] = $flow_craft_id;
$this->table->add($v);
}
$this->success('success');
}
else{
$this->flow_craft_id = I('flow_craft_id');
$this->template = D("craft_template")->field('template_id as value, template_name as name')->select();
$this->display();
}
}
}