鼠笼管理系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

196 lines
9.4 KiB

<?php
/**
* 鼠笼笼位相关接口
* @author YS
* @version 1.0
*/
class Api_CageController extends Ctrl_Api{
public $Cagemodel;
public $POST;
public $Cagecolormodel;
public $SquirrelModel;
public $Usermodel;
public function init() {
$this->Cagemodel = new CageModel();
$this->POST =json_decode(file_get_contents('php://input'),true);
$this->Cagecolormodel = new CagecolorModel();
$this->Usermodel = new UserModel();
$this->SquirrelModel = new SquirrelModel();
}
/**
* 鼠笼列表接口
* @param $strains 品系
* @param $number 笼位号
* @param $type 笼位属性
* @return
* {
* "errorcode": "200",
* "message": "登陆成功",
* "data": {
* "username": "用户名",
* "type": "1",用户类型
* "realname": "真实姓名",
* "faculties": "1",院系
* "specialized": "1",专业
* "group": "1",课题组
* "teacher": "1",导师
* "phone": "13566987478",手机号
* "status": "1",审核状态
* "is_delete": "0"是否删除
* }
* }
*/
public function listAction(){
$params['order'] = empty($this->POST['order'])?'':$this->POST['order'];
$params['uid'] = empty($this->POST['uid'])?Tool_Fnc::apiMsg('请先登录', '500'):$this->POST['uid'];
$params['keyword'] = empty($this->POST['keyword'])?'':$this->POST['keyword'];
$params['page'] = empty($this->POST['page'])?1:$this->POST['page'];
$params['desc'] = empty($this->POST['desc'])||!isset($this->POST['desc'])?'desc':Tool_Fnc::safe_string($this->POST['desc']);
$data = $this->Cagemodel->getModelList($params);
Tool_Fnc::apiMsg('笼位获取成功', '200',$data);
}
/**
* 鼠笼添加接口
* @param $strains 笼位品系
* @param $number 笼位号
* @param $type 笼位类型
* @param $color 笼位颜色
* @param $group 实验室
* @param $user_id 负责人
* @return
* {
* "errorcode": "200",
* "message": "添加成功",
* "data": []
* }
*/
public function addAction(){
//查询笼位号
$data['c_user_id'] = empty($this->POST['uid'])?Tool_Fnc::apiMsg('请先登录', '500'):$this->POST['uid'];
$CageNum = $this->Cagemodel->field('count(*) as num')->where("c_user_id={$data['c_user_id']}")->fRow();
$CageNum = empty($CageNum)?1:(int) $CageNum['num']+1;
$data['type'] = $this->POST['type'];
$data['number'] = $CageNum;
$data['strains'] =empty($this->POST['strains'])||!isset($this->POST['strains'])?Tool_Fnc::apiMsg('请选择笼位品系', '500'):Tool_Fnc::safe_string($this->POST['strains']);
$data['color'] =empty($this->POST['color'])||!isset($this->POST['color'])?Tool_Fnc::apiMsg('请选择笼位颜色', '500'):Tool_Fnc::safe_string($this->POST['color']);
$data['group'] = empty($this->POST['group'])||!isset($this->POST['group'])?Tool_Fnc::apiMsg('请选择实验室', '500'):Tool_Fnc::safe_string($this->POST['group']);
$data['user_id'] =empty($this->POST['user_id'])||!isset($this->POST['user_id'])?Tool_Fnc::apiMsg('请选择负责人', '500'):Tool_Fnc::safe_string($this->POST['user_id']);
$data['created'] = date('Y-m-d H:i:s',time());
$ret = $this->Cagemodel->insert($data);
if(!$ret) Tool_Fnc::apiMsg('笼位建设失败', '500');
Tool_Fnc::apiMsg('笼位建设成功', '200');
}
/**
* 获取笼位号
*/
public function getCagenumAction(){
$uid = empty($this->POST['uid'])?Tool_Fnc::apiMsg('请先登录', '500'):$this->POST['uid'];
$CageNum = $this->Cagemodel->field('count(*) as num')->where("user_id={$uid}")->fRow();
$CageNum = empty($CageNum)?1:(int) $CageNum['num']+1;
$data['number'] = $CageNum;
Tool_Fnc::apiMsg('获取笼位号成功', '200',$data);
}
/**
* 获取笼位类型接口
*/
public function getCagetypeAction(){
$data = array(['id'=>1,'title'=>'库存笼'],['id'=>2,'title'=>'繁殖笼'],['id'=>3,'title'=>'其他']);
Tool_Fnc::apiMsg('获取笼位类型成功', '200',$data);
}
/**
* 获取笼位颜色接口
*/
public function getCagecolorAction(){
$params['field'] = 'color';
$data = $this->Cagecolormodel->getModelList($params);
Tool_Fnc::apiMsg('获取成功', '200',$data);
}
/**
* 获取负责人接口
*/
public function getUserAction(){
$uid = empty($this->POST['uid'])?Tool_Fnc::apiMsg('请先登录', '500'):$this->POST['uid'];
$data = $this->Usermodel->getUser($uid);
Tool_Fnc::apiMsg('获取成功', '200',$data);
}
public function getCageinfoACtion(){
$id = empty($this->POST['id'])?Tool_Fnc::apiMsg('缺少笼位ID', '500'):$this->POST['id'];
$params['where'] = "and cage = {$id}";
$data['cage'] = $this->Cagemodel->getOneInfo($id);
$data['cage']['code'] = Yaf_Registry::get("config")->web->url->img."?id={$id}&type={$data['cage']['type']}&number={$data['cage']['number']}";
$data['squirrel'] = $this->SquirrelModel->getModelList($params);
Tool_Fnc::apiMsg('获取成功', '200',$data);
}
public function cageMoveAction(){
$uid = empty($this->POST['uid'])?Tool_Fnc::apiMsg('请先登录', '500'):$this->POST['uid'];
$id = empty($this->POST['id'])?Tool_Fnc::apiMsg('小鼠ID', '500'):$this->POST['id'];
$cage = empty($this->POST['cage'])?Tool_Fnc::apiMsg('笼位ID', '500'):$this->POST['cage'];
$data['id'] = $id;
$data['cage'] = $cage;
$data['type'] = 1;
if(!$this->SquirrelModel->update($data)) Tool_Fnc::apiMsg('笼位未发生变化', '500');
Tool_Fnc::apiMsg('转移成功', '200');
}
//获取转移笼位列表
public function cagemovellistAction(){
$uid = empty($this->POST['uid'])?Tool_Fnc::apiMsg('请先登录', '500'):$this->POST['uid'];
$id = empty($this->POST['id'])?Tool_Fnc::apiMsg('小鼠ID', '500'):$this->POST['id'];
$order = empty($this->POST['order'])?'id':$this->POST['order'];
$keyword = empty($this->POST['keyword'])?'':$this->POST['keyword'];
$squirrel = $this->SquirrelModel->getOneInfo($id);
$data = $this->Cagemodel->field('id,number,color,strains,type ');
$data = $data->where("c_user_id='{$uid}' and id!={$squirrel['cage']} and is_delete=0 order by {$order} desc");
if(!empty($keyword)){
$data = $data->where("c_user_id='{$uid}' and id!={$squirrel['cage']} and is_delete=0 and (number like '%{$keyword}%' or strains like '%{$keyword}%') order by {$order} desc");
}
$data = $data->fList();
foreach($data as $key => $val){
$data[$key]['type_color'] = $data[$key]['type']==2?'#FF0000':'';
if($this->SquirrelModel->isFull($val['cage'],$uid)) {
//查询公鼠
$sql = "select count(*) num from squirrel where cage={$data[$key]['id']} and is_kill=0 and is_delete=0 and sex=1";
$mannum = $this->Cagemodel->query($sql);
if(!empty($mannum)){
$data[$key]['mannum'] = $mannum[0]['num'];
// if(($val['type']==2 && $squirrel['sex']==1) || $squirrel['sex']==2) unset($data[$key]);
}
//查询母鼠
$sql = "select count(*) num from squirrel where cage={$data[$key]['id']} and is_kill=0 and is_delete=0 and sex=2";
$womannum = $this->Cagemodel->query($sql);
if(!empty($womannum)){
$data[$key]['womannum'] = $womannum[0]['num'];
// if($squirrel['sex']==1) unset($data[$key]);
}
if($val['type']==2){
if($squirrel['sex']==1){
if((int)$this->SquirrelModel->field("count(*) num")->where("sex=1 and cage={$val['id']} and id!={$squirrel['id']}")->fList()['num']==1) unset($data[$key]);
}if($squirrel['sex']==2){
if((int)$this->SquirrelModel->field("count(*) num")->where("sex=2 and cage={$val['id']} and id!={$squirrel['id']}")->fList()['num']==2) unset($data[$key]);
}
}else{
//查询笼位是否有不同性别鼠
if($squirrel['sex']==1){
if(!empty($this->SquirrelModel->field("*")->where("sex=2 and cage={$val['id']} and id!={$squirrel['id']}")->fRow())) unset($data[$key]);
}if($squirrel['sex']==2){
if(!empty($this->SquirrelModel->field("*")->where("sex=1 and cage={$val['id']} and id!={$squirrel['id']}")->fRow())) unset($data[$key]);
}
}
}else{
unset($data[$key]);
}
}
Tool_Fnc::apiMsg('获取成功 ', '200',$data);
}
public function delcageAction(){
$uid = empty($this->POST['uid'])?Tool_Fnc::apiMsg('请先登录', '500'):$this->POST['uid'];
$id = empty($this->POST['id'])?Tool_Fnc::apiMsg('小鼠ID', '500'):$this->POST['id'];
$ids = implode(",",$id);
$sql = "update {$this->Cagemodel->table} set is_delete=1 where c_user_id={$uid} and id in ({$ids})";
if(!$this->Cagemodel->exec($sql)) Tool_Fnc::apiMsg('删除失败', '500');
Tool_Fnc::apiMsg('已删除', '200');
}
}