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.
164 lines
7.3 KiB
164 lines
7.3 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'];
|
|
$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("user_id={$data['c_user_id']}")->fRow();
|
|
$CageNum = empty($CageNum)?1:(int) $CageNum['num']+1;
|
|
$data['type'] = $this->POST['type'];
|
|
$data['number'] = "NO.0000".$CageNum;
|
|
if($CageNum>9) $data['number'] = "NO.000".$CageNum;
|
|
if($CageNum>99) $data['number'] = "NO.00".$CageNum;
|
|
if($CageNum>999) $data['number'] = "NO.0".$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'] = "NO.0000".$CageNum;
|
|
if($CageNum>9) $data['number'] = "NO.000".$CageNum;
|
|
if($CageNum>99) $data['number'] = "NO.00".$CageNum;
|
|
if($CageNum>999) $data['number'] = "NO.0".$CageNum;
|
|
Tool_Fnc::apiMsg('获取笼位号成功', '200',$data);
|
|
}
|
|
/**
|
|
* 获取笼位类型接口
|
|
*/
|
|
public function getCagetypeAction(){
|
|
$data = array(['id'=>1,'title'=>'库存笼'],['id'=>2,'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}";
|
|
$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;
|
|
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'];
|
|
$squirrel = $this->SquirrelModel->getOneInfo($id);
|
|
$data = $this->Cagemodel->field('id,number,color,strains,type ')->where("c_user_id='{$uid}' and id!={$squirrel['cage']}")->fList();
|
|
foreach($data as $key => $val){
|
|
if(!$this->SquirrelModel->isFull($val['cage'],$uid)) unset($data[$key]);
|
|
//查询公鼠
|
|
$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'];
|
|
}
|
|
//查询母鼠
|
|
$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'];
|
|
}
|
|
$data[$key]['type_color'] = $data[$key]['type']==2?'#FF0000':'';
|
|
}
|
|
Tool_Fnc::apiMsg('获取成功 ', '200',$data);
|
|
}
|
|
}
|
|
|
|
|