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

114 lines
3.6 KiB
PHP

<?php
namespace Admin\Controller;
use Think\Controller;
class FlowCraftController extends AdminController{
public function __construct(){
parent::__construct();
$this->table=D("FlowCraft");
}
public function index(){
//搜索
$where=array();
//工艺名称
$flow_id=I("flow_id");
if($flow_id){
$where['flow_id'] = $flow_id;
}
else{
$this->error('非法操作');
}
$used = false;
if(D('product')->where(array('flow_id'=>$flow_id))->find()){
$used = true;
}
$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("order_id")->limit($page->firstRow, $page->listRows)->select();
// var_dump($data);exit;
$listpage = $page->show();
$this->assign("listpage", $listpage);
$this->data=$data;
$this->flow_name = D('flow')->find($flow_id)['flow_name'];
$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_id = I('flow_id');
$data = D('craft')->relation(true)->select();
$res = array();
foreach ($data as $k=>$v){
$name = $v['craft_name'] . ' - ' .$v['craft_code'] .' - ' . $v['craft_remark'].' - ' .$v['craft_type']['type_name'] . ' - '. $v['who_add']['user_name'];
$res[] = array('name'=>$name,'value'=>$v['craft_id']);
}
$this->craft = json_encode($res) ;
// D('craft')->field('craft_id as value,craft_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{
$flow_craft_id = I('flow_craft_id');
$data= $this->table->find($flow_craft_id);
$this->data = $data;
$this->craft = D('craft')->field('craft_id as value,craft_name as name')->select();
$this->display();
}
}
//删除
public function delete(){
$flow_craft_id=I('flow_craft_id');
$this->table->delete($flow_craft_id);
D("UserLog")->add("delete",$this->table->getTableName(),$flow_craft_id);
$this->success("操作成功");
}
//字段排序
public function sort(){
$order_id=I("order_id");
$flow_craft_id=I("flow_craft_id");
foreach($order_id as $k=>$v){
$data['order_id']=(int)$order_id[$k];
$data['flow_craft_id']=(int)$flow_craft_id[$k];
$this->table->save($data);
}
$this->success("排序更改成功");
}
}