table=D("Product"); } public function index(){ //搜索 $where=array(); //产品名称 $product_name=I("get.product_name"); if($product_name){ $where['product_name'] = array('LIKE','%'.$product_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("product_id desc")->limit($page->firstRow, $page->listRows)->select(); foreach ($data as $k=>$v){ $data[$k]['used'] = false; if(D('task')->where(array('product_id'=>$v['product_id']))->find()){ $data[$k]['used'] = true; } $flow_status = D('flow')->find($v['flow_id'])['order_id']; if($flow_status == 1){ $data[$k]['used'] = false; } } $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{ $flow_data = D('flow')->where(array('order_id'=>0))->field('flow_id as value,flow_name as name')->select(); foreach ($flow_data as $k=>$v){ $flow_data[$k]['full'] = true; $flow_craft_data = D('flow_craft')->where(array('flow_id'=>$v['value']))->select(); foreach ($flow_craft_data as $k1=>$v1){ if(!D('craft_param')->where(array('flow_craft_id'=>$v1['flow_craft_id']))->find()){ $flow_data[$k]['full'] = false; } } } $flow = array(); foreach ($flow_data as $k=>$v) { if($v['full']){ $flow[] = $v; } } $this->flow = $flow; $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{ $product_id = I('product_id'); $data= $this->table->find($product_id); $this->data = $data; $this->flow = D('flow')->field('flow_id as value,flow_name as name')->select(); $this->display(); } } //删除 public function delete(){ $product_id=I('product_id'); $data = $this->table->find($product_id); if($data['product_who_add']!=UID){ $this->error('没有权限删除别人的资料'); } $this->table->delete($product_id); D("UserLog")->add("delete",$this->table->getTableName(),$product_id); $this->success("操作成功"); } }