Squirrelmodel = new SquirrelModel(); $this->CageModel = new CageModel(); $this->CageSetModel=new CageSetModel(); $this->SquirrelSetModel=new SquirrelSetModel(); $this->ExcelSetModel=new ExcelSetModel(); $this->POST =json_decode(file_get_contents('php://input'),true); } /** * 鼠笼列表接口 * @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(){ $cage = empty($this->POST['cage_id'])||!isset($this->POST['cage_id'])?Tool_Fnc::apiMsg('缺少重要参数', '500'):Tool_Fnc::safe_string($this->POST['cage_id']); $type = empty($this->POST['type'])||!isset($this->POST['type'])?1:Tool_Fnc::safe_string($this->POST['type']); $params['where'] = "and cage = {$cage}"; $params['type'] =$type; $data = $this->Squirrelmodel->getModelList($params); Tool_Fnc::apiMsg('获取成功', '200',$data); } /** * 小鼠添加接口 * @param $sex 性别 * @param $birthday 生日 * @param $father 父亲id * @param $mather 母亲id * @param $strains_id 品系id * @param $gene 基因id * @param $hair_color 毛色 * @param $remark 备注 * @param $cage 笼位号 * @return * { * "errorcode": "200", * "message": "添加成功", * "data": { * "sex": "用户名",性别 * "birthday": "1",生日 * "father": "1",母亲id * "mather": "2",母亲id * "strains_id": "1",品系id * "gene": "1",基因id * "hair_color": "1",毛色 * "remark": "备注",备注 * "cage": "1",笼位号id * } * } */ public function addAction(){ //查询笼位号 $CageNum = $this->Squirrelmodel->field('count(*) as num')->fRow(); $CageNum = empty($CageNum)?1:(int) $CageNum['num']+1; $data['type'] = $this->POST['type']; $data['number'] = "SN00000".$CageNum; if($CageNum>9) $data['number'] = "SN0000".$CageNum; if($CageNum>99) $data['number'] = "SN000".$CageNum; if($CageNum>999) $data['number'] = "SN00".$CageNum; if($CageNum>9999) $data['number'] = "SN0".$CageNum; $data['sex'] =empty($this->POST['sex'])||!isset($this->POST['sex'])?Tool_Fnc::apiMsg('请选择性别', '500'):Tool_Fnc::safe_string($this->POST['sex']); $data['birthday'] =empty($this->POST['birthday'])||!isset($this->POST['birthday'])?Tool_Fnc::apiMsg('请填写生日', '500'):Tool_Fnc::safe_string($this->POST['birthday']); $data['father'] = empty($this->POST['father'])||!isset($this->POST['father'])?0:Tool_Fnc::safe_string($this->POST['father']); $data['mother'] = empty($this->POST['mother'])||!isset($this->POST['father'])?0:Tool_Fnc::safe_string($this->POST['mother']); $data['strains_id'] =empty($this->POST['strains_id'])||!isset($this->POST['strains_id'])?Tool_Fnc::apiMsg('请选择品系', '500'):Tool_Fnc::safe_string($this->POST['strains_id']); $data['gene'] =empty($this->POST['gene'])||!isset($this->POST['gene'])?Tool_Fnc::apiMsg('请填写基因', '500'):Tool_Fnc::safe_string($this->POST['gene']); $data['hair_color'] =empty($this->POST['hair_color'])||!isset($this->POST['hair_color'])?Tool_Fnc::apiMsg('请选择毛色', '500'):Tool_Fnc::safe_string($this->POST['hair_color']); $data['remark'] = empty($this->POST['remark'])||!isset($this->POST['remark'])?Tool_Fnc::apiMsg('请填写备注', '500'):Tool_Fnc::safe_string($this->POST['remark']); $data['cage'] =empty($this->POST['cage'])||!isset($this->POST['cage'])?Tool_Fnc::apiMsg('未找到当前笼位ID', '500'):Tool_Fnc::safe_string($this->POST['cage']); $data['created'] = date('Y-m-d H:i:s',time()); $data['c_user_id'] = $_SESSION['uid']; //判断鼠笼鼠的数量是否可以容纳 if(!$this->Squirrelmodel->isFull($data['cage'])) Tool_Fnc::apiMsg('当前笼位已满,请重新选择笼位添加', '500'); //获取当前用户仓鼠的配置 $params['user_id'] = $_SESSION['uid']; $squirrelSet = $this->SquirrelSetModel->getsetinfo($params); //根据生日获取各个提醒时间 $data['weaning_time'] = date("Y-m-d",strtotime("+{$squirrelSet['weaning_time']} day",strtotime($data['birthday']))); $data['nursing_time'] = date("Y-m-d",strtotime("+{$squirrelSet['nursing_time']} day",strtotime($data['birthday']))); $data['grow_time'] =$data['sex']==1? date("Y-m-d",strtotime("+{$squirrelSet['male_grow_time']} days",strtotime($data['birthday']))):date("Y-m-d",strtotime("+{$squirrelSet['female_grow_time']} days",strtotime($data['birthday']))); $data['infertility_time'] = date("Y-m-d",strtotime("+{$squirrelSet['infertility_time']} month",strtotime($data['birthday']))); $data['dose_time'] = date("Y-m-d",strtotime("+{$squirrelSet['dose_time']} day",strtotime($data['birthday']))); $ret = $this->Squirrelmodel->insert($data); if(!$ret) Tool_Fnc::apiMsg('小鼠建档失败', '500'); Tool_Fnc::apiMsg('小鼠建档成功', '200'); } /** * 小鼠编辑接口 * @param $sex 性别 * @param $birthday 生日 * @param $father 父亲id * @param $mather 母亲id * @param $strains_id 品系id * @param $gene 基因id * @param $hair_color 毛色 * @param $remark 备注 * @param $cage 笼位号 * @return * { * "errorcode": "200", * "message": "添加成功", * "data": { * "sex": "用户名",性别 * "birthday": "1",生日 * "father": "1",母亲id * "mather": "2",母亲id * "strains_id": "1",品系id * "gene": "1",基因id * "hair_color": "1",毛色 * "remark": "备注",备注 * "cage": "1",笼位号id * } * } */ public function editAction(){ $data['id'] = empty($this->POST['id'])||!isset($this->POST['id'])?Tool_Fnc::apiMsg('系统错误', '500'):Tool_Fnc::safe_string($this->POST['id']); $data['sex'] =empty($this->POST['sex'])||!isset($this->POST['sex'])?Tool_Fnc::apiMsg('请选择性别', '500'):Tool_Fnc::safe_string($this->POST['sex']); $data['birthday'] =empty($this->POST['birthday'])||!isset($this->POST['birthday'])?Tool_Fnc::apiMsg('请填写生日', '500'):Tool_Fnc::safe_string($this->POST['birthday']); $data['father'] = empty($this->POST['father'])||!isset($this->POST['father'])?0:Tool_Fnc::safe_string($this->POST['father']); $data['mother'] = empty($this->POST['mother'])||!isset($this->POST['father'])?0:Tool_Fnc::safe_string($this->POST['mother']); $data['strains_id'] =empty($this->POST['strains_id'])||!isset($this->POST['strains_id'])?Tool_Fnc::apiMsg('请选择品系', '500'):Tool_Fnc::safe_string($this->POST['strains_id']); $data['gene'] =empty($this->POST['gene'])||!isset($this->POST['gene'])?Tool_Fnc::apiMsg('请填写基因', '500'):Tool_Fnc::safe_string($this->POST['gene']); $data['hair_color'] =empty($this->POST['hair_color'])||!isset($this->POST['hair_color'])?Tool_Fnc::apiMsg('请选择毛色', '500'):Tool_Fnc::safe_string($this->POST['hair_color']); $data['remark'] = empty($this->POST['remark'])||!isset($this->POST['remark'])?'':Tool_Fnc::safe_string($this->POST['remark']); // $data['cage'] =empty($this->POST['cage'])||!isset($this->POST['cage'])?Tool_Fnc::apiMsg('未找到当前笼位ID', '500'):Tool_Fnc::safe_string($this->POST['cage']); $data['created'] = date('Y-m-d H:i:s',time()); // $data['c_user_id'] = $_SESSION['uid']; // //判断鼠笼鼠的数量是否可以容纳 // if(!$this->Squirrelmodel->isFull($data['cage'])) Tool_Fnc::apiMsg('当前笼位已满,请重新选择笼位添加', '500'); //获取当前用户仓鼠的配置 $params['user_id'] = $_SESSION['uid']; $squirrelSet = $this->SquirrelSetModel->getsetinfo($params); //根据生日获取各个提醒时间 $data['weaning_time'] = date("Y-m-d",strtotime("+{$squirrelSet['weaning_time']} day",strtotime($data['birthday']))); $data['nursing_time'] = date("Y-m-d",strtotime("+{$squirrelSet['nursing_time']} day",strtotime($data['birthday']))); $data['grow_time'] =$data['sex']==1? date("Y-m-d",strtotime("+{$squirrelSet['male_grow_time']} days",strtotime($data['birthday']))):date("Y-m-d",strtotime("+{$squirrelSet['female_grow_time']} days",strtotime($data['birthday']))); $data['infertility_time'] = date("Y-m-d",strtotime("+{$squirrelSet['infertility_time']} month",strtotime($data['birthday']))); $data['dose_time'] = date("Y-m-d",strtotime("+{$squirrelSet['dose_time']} day",strtotime($data['birthday']))); $ret = $this->Squirrelmodel->update($data); if(!$ret) Tool_Fnc::apiMsg('信息更新失败', '500'); Tool_Fnc::apiMsg('信息更新成功', '200'); } /** * 获取小鼠详情接口 * @param $id 小鼠id * @return * { * "errorcode": "200", * "message": "添加成功", * "data": { * "sex": "用户名",性别 * "birthday": "1",生日 * "father": "1",母亲id * "mather": "2",母亲id * "strains_id": "1",品系id * "gene": "1",基因id * "hair_color": "1",毛色 * "remark": "备注",备注 * "cage": "1",笼位号id * } * } */ public function getInfoAction(){ $id = $this->POST['id']; } }