130 lines
4.5 KiB
PHP
130 lines
4.5 KiB
PHP
<?php
|
|
namespace Admin\Controller;
|
|
use Think\Controller;
|
|
class FlowController extends AdminController{
|
|
public function __construct(){
|
|
parent::__construct();
|
|
$this->table=D("flow");
|
|
}
|
|
|
|
public function index(){
|
|
//搜索
|
|
$where=array();
|
|
$where['order_id'] = array('neq',9);
|
|
//工艺名称
|
|
$flow_name=I("get.flow_name");
|
|
if($flow_name){
|
|
$where['flow_name'] = array('LIKE','%'.$flow_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("order_id ,flow_id desc")->limit($page->firstRow, $page->listRows)->select();
|
|
foreach ($data as $k=>$v){
|
|
$data[$k]['used'] = false;
|
|
if(D('product')->where(array('flow_id'=>$v['flow_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);
|
|
$flow_id = I('flow_id');
|
|
if($flow_id){
|
|
$flow_craft_data = D('flow_craft')->where(array('flow_id'=>$flow_id))->select();
|
|
if($flow_craft_data){
|
|
foreach ($flow_craft_data as $k=>$v){
|
|
$flow_craft_id = $v['flow_craft_id'];
|
|
unset($v['flow_craft_id']);
|
|
$v['flow_id'] = $result;
|
|
$this_flow_craft_id = D('flow_craft')->add($v);
|
|
|
|
$param_data = D('craft_param')->where(array('flow_craft_id'=>$flow_craft_id))->select();
|
|
if($param_data){
|
|
foreach ($param_data as $k_param=>$v_param){
|
|
unset($v_param['param_id']);
|
|
$v_param['flow_craft_id'] = $this_flow_craft_id;
|
|
D('craft_param')->add($v_param);
|
|
}
|
|
}
|
|
|
|
$price_data = D('craft_price')->where(array('flow_craft_id'=>$flow_craft_id))->select();
|
|
if($price_data){
|
|
foreach ($price_data as $k_price=>$v_price){
|
|
unset($v_price['price_id']);
|
|
$v_price['flow_craft_id'] = $this_flow_craft_id;
|
|
D('craft_price')->add($v_price);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
$this->success($data);
|
|
}
|
|
else{
|
|
$this->flow = D('flow')->field('flow_id as value, flow_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_id = I('flow_id');
|
|
$data= $this->table->find($flow_id);
|
|
$this->data = $data;
|
|
$this->display();
|
|
}
|
|
}
|
|
|
|
|
|
//删除
|
|
public function delete(){
|
|
$flow_id=I('flow_id');
|
|
$data = $this->table->find($flow_id);
|
|
if($data['flow_who_add']!=UID){
|
|
$this->error('没有权限删除别人的资料');
|
|
}
|
|
$this->table->delete($flow_id);
|
|
D("UserLog")->add("delete",$this->table->getTableName(),$flow_id);
|
|
$this->success("操作成功");
|
|
}
|
|
|
|
public function change_order(){
|
|
$flow_id = I('flow_id');
|
|
$order_id = I('order_id');
|
|
$this->table->where(array('flow_id'=>$flow_id))->save(array('order_id'=>$order_id));
|
|
$this->success();
|
|
}
|
|
|
|
} |