鼠笼管理系统
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.

112 lines
4.2 KiB

<?php
/**
* 鼠笼笼位相关接口
* @author YS
* @version 1.0
*/
class Api_CageController extends Ctrl_Api{
public $Cagemodel;
7 months ago
public $Cagecolormodel;
public function init() {
7 months ago
if(empty($_SESSION['uid'])) {Tool_Fnc::apiMsg('非法调用', '500');}
$this->Cagemodel = new CageModel();
7 months ago
$this->Cagecolormodel = new CagecolorModel();
}
/**
* 鼠笼列表接口
* @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($_POST['order'])?'':$_POST['order'];
$params['keyword'] = empty($_POST['keyword'])?'':$_POST['keyword'];
$params['page'] = empty($_POST['page'])?1:$_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": "添加成功",
7 months ago
* "data": []
* }
*/
public function addAction(){
//查询笼位号
$CageNum = $this->Cagemodel->field('count(*) as num')->where("user_id={$_SESSION['uid']}")->fRow();
$CageNum = empty($CageNum)?1:(int) $CageNum['num']+1;
$data['type'] = $_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($_POST['strains'])||!isset($_POST['strains'])?Tool_Fnc::apiMsg('请选择笼位品系', '500'):Tool_Fnc::safe_string($_POST['strains']);
$data['color'] =empty($_POST['color'])||!isset($_POST['color'])?Tool_Fnc::apiMsg('请选择笼位颜色', '500'):Tool_Fnc::safe_string($_POST['color']);
$data['group'] = empty($_POST['group'])||!isset($_POST['group'])?Tool_Fnc::apiMsg('请选择实验室', '500'):Tool_Fnc::safe_string($_POST['group']);
$data['user_id'] =empty($_POST['user_id'])||!isset($_POST['user_id'])?Tool_Fnc::apiMsg('请选择负责人', '500'):Tool_Fnc::safe_string($_POST['user_id']);
$data['created'] = date('Y-m-d H:i:s',time());
$data['c_user_id'] = $_SESSION['uid'];
$ret = $this->Cagemodel->insert($data);
if(!$ret) Tool_Fnc::apiMsg('笼位建设失败', '500');
Tool_Fnc::apiMsg('笼位建设成功', '200');
}
public function edidAction(){
}
7 months ago
/**
* 获取笼位号
*/
public function getCagenumAction(){
$CageNum = $this->Cagemodel->field('count(*) as num')->where("user_id={$_SESSION['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 = [1=>'库存笼',2=>'繁殖笼'];
Tool_Fnc::apiMsg('获取笼位类型成功', '200',$data);
}
/**
* 获取笼位颜色接口
*/
public function getCagecolorAction(){
$params['field'] = 'color';
$data = $this->Cagecolormodel->getModelList($params);
Tool_Fnc::apiMsg('获取成功', '200',$data);
}
}