qa-ifish7/web/Application/Admin/Controller/CraftPriceController.class.php

88 lines
2.7 KiB
PHP

<?php
namespace Admin\Controller;
use Think\Controller;
class CraftPriceController extends AdminController{
public function __construct(){
parent::__construct();
$this->table=D("craft_price");
}
public function index(){
//搜索
$where=array();
//工艺名称
$flow_craft_id=I("get.flow_craft_id");
if($flow_craft_id){
$where['flow_craft_id'] = array('flow_craft_id'=>$flow_craft_id);
}
$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->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{
$flow_craft_id = I('flow_craft_id');
$data= $this->table->where(array('flow_craft_id'=>$flow_craft_id))->find();
$this->data = $data;
$this->flow_craft_id = $flow_craft_id;
$this->display();
}
}
//删除
public function delete(){
$craft_id=I('craft_id');
$this->table->delete($craft_id);
D("UserLog")->add("delete",$this->table->getTableName(),$craft_id);
$this->success("操作成功");
}
}