From ec5c1db884a367d0f38f134aefcf2f2e54019d2c Mon Sep 17 00:00:00 2001 From: "yangsai@163.com" <2624183217@qq.com> Date: Wed, 15 May 2024 17:26:46 +0800 Subject: [PATCH] =?UTF-8?q?YS:=E6=8E=A5=E5=8F=A3=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/controllers/Api/Basicinfo.php | 1 + application/controllers/Api/Cage.php | 43 +++++++++++++------ application/controllers/Api/Squirrel.php | 28 +++++++++++- application/controllers/Api/Sysset.php | 32 ++++++++++++++ application/models/Cage.php | 4 ++ application/models/CageSet.php | 5 ++- application/models/Cagecolor.php | 15 +++++++ application/models/ExcelSet.php | 52 +++++++++++++++++++++++ application/models/Squirrel.php | 41 +++++++++++++++++- application/models/SquirrelSet.php | 24 +++++++++++ 10 files changed, 229 insertions(+), 16 deletions(-) create mode 100644 application/controllers/Api/Sysset.php create mode 100644 application/models/Cagecolor.php create mode 100644 application/models/ExcelSet.php create mode 100644 application/models/SquirrelSet.php diff --git a/application/controllers/Api/Basicinfo.php b/application/controllers/Api/Basicinfo.php index 3943a99..45de004 100644 --- a/application/controllers/Api/Basicinfo.php +++ b/application/controllers/Api/Basicinfo.php @@ -10,6 +10,7 @@ class Api_BasicinfoController extends Ctrl_Api{ public $GeneModel; public $GroupModel; public function init(){ + if(empty($_SESSION['uid'])) {Tool_Fnc::apiMsg('非法调用', '500');} $this->StrainsModel=new StrainsModel(); $this->GeneModel=new GeneModel(); $this->GroupModel=new GroupModel(); diff --git a/application/controllers/Api/Cage.php b/application/controllers/Api/Cage.php index 50cca54..58335a0 100644 --- a/application/controllers/Api/Cage.php +++ b/application/controllers/Api/Cage.php @@ -7,8 +7,11 @@ */ class Api_CageController extends Ctrl_Api{ public $Cagemodel; + public $Cagecolormodel; public function init() { + if(empty($_SESSION['uid'])) {Tool_Fnc::apiMsg('非法调用', '500');} $this->Cagemodel = new CageModel(); + $this->Cagecolormodel = new CagecolorModel(); } /** * 鼠笼列表接口 @@ -52,18 +55,7 @@ class Api_CageController extends Ctrl_Api{ * { * "errorcode": "200", * "message": "添加成功", - * "data": { - * "username": "用户名", - * "type": "1",用户类型 - * "realname": "真实姓名", - * "faculties": "1",院系 - * "specialized": "1",专业 - * "group": "1",课题组 - * "teacher": "1",导师 - * "phone": "13566987478",手机号 - * "status": "1",审核状态 - * "is_delete": "0"是否删除 - * } + * "data": [] * } */ public function addAction(){ @@ -88,5 +80,32 @@ class Api_CageController extends Ctrl_Api{ public function edidAction(){ } + /** + * 获取笼位号 + */ + 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); + } } diff --git a/application/controllers/Api/Squirrel.php b/application/controllers/Api/Squirrel.php index 72db828..dd4546f 100644 --- a/application/controllers/Api/Squirrel.php +++ b/application/controllers/Api/Squirrel.php @@ -7,8 +7,17 @@ */ class Api_SquirrelController extends Ctrl_Api{ public $Squirrelmodel; + public $CageModel; + public $CageSetModel; + public $SquirrelSetModel; + public $ExcelSetModel; public function init() { + if(empty($_SESSION['uid'])) {Tool_Fnc::apiMsg('非法调用', '500');} $this->Squirrelmodel = new SquirrelModel(); + $this->CageModel = new CageModel(); + $this->CageSetModel=new CageSetModel(); + $this->SquirrelSetModel=new SquirrelSetModel(); + $this->ExcelSetModel=new ExcelSetModel(); } /** * 鼠笼列表接口 @@ -34,7 +43,12 @@ class Api_SquirrelController extends Ctrl_Api{ * } */ public function listAction(){ - + $cage = empty($_POST['cage_id'])||!isset($_POST['cage_id'])?Tool_Fnc::apiMsg('缺少重要参数', '500'):Tool_Fnc::safe_string($_POST['cage_id']); + $type = empty($_POST['type'])||!isset($_POST['type'])?1:Tool_Fnc::safe_string($_POST['type']); + $params['where'] = "and cage = {$cage}"; + $params['type'] =$type; + $data = $this->Squirrelmodel->getModelList($params); + Tool_Fnc::apiMsg('获取成功', '200',$data); } /** * 小鼠添加接口 @@ -68,6 +82,7 @@ class Api_SquirrelController extends Ctrl_Api{ //查询笼位号 $CageNum = $this->Squirrelmodel->field('count(*) as num')->fRow(); $CageNum = empty($CageNum)?1:(int) $CageNum['num']+1; + $data['type'] = $_POST['type']; $data['number'] = "SN00000".$CageNum; if($CageNum>9) $data['number'] = "SN0000".$CageNum; @@ -85,6 +100,17 @@ class Api_SquirrelController extends Ctrl_Api{ $data['cage'] =empty($_POST['cage'])||!isset($_POST['cage'])?Tool_Fnc::apiMsg('未找到当前笼位ID', '500'):Tool_Fnc::safe_string($_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'); diff --git a/application/controllers/Api/Sysset.php b/application/controllers/Api/Sysset.php new file mode 100644 index 0000000..50b668e --- /dev/null +++ b/application/controllers/Api/Sysset.php @@ -0,0 +1,32 @@ +CageSetModel=new CageSetModel(); + $this->SquirrelSetModel=new SquirrelSetModel(); + $this->ExcelSetModel=new ExcelSetModel(); + } + /** + * 获取设置接口 + */ + public function getSetInfoAction(){ + $params['user_id'] = $_SESSION['uid']; + //笼位设置 + $data['cageSet'] = $this->CageSetModel->getsetinfo($params); + //鼠设置 + $data['squirrelSet'] = $this->SquirrelSetModel->getsetinfo($params); + //excel导出设置 + $data['excelSet'] = $this->ExcelSetModel->getsetinfo($params); + Tool_Fnc::apiMsg('获取成功', '200',$data); + } + +} \ No newline at end of file diff --git a/application/models/Cage.php b/application/models/Cage.php index c7fb581..5e014e1 100644 --- a/application/models/Cage.php +++ b/application/models/Cage.php @@ -51,5 +51,9 @@ class CageModel extends Orm_Base{ $data['page'] = $params['page']; return $data; } + public function getOneInfo($id){ + $info = $this->field('*')->where("id='{$id}'")->fRow(); + return $info; + } } diff --git a/application/models/CageSet.php b/application/models/CageSet.php index b9f2b39..624f522 100644 --- a/application/models/CageSet.php +++ b/application/models/CageSet.php @@ -14,6 +14,9 @@ class CageSetModel extends Orm_Base{ 'c_user_id' => array('type' => "int(11)",'comment' => '是否删除'), ); public $pk = 'id'; - + public function getsetinfo($params){ + $data = $this->field('*')->where('c_user_id='.$params['user_id'])->fRow(); + return $data; + } } diff --git a/application/models/Cagecolor.php b/application/models/Cagecolor.php new file mode 100644 index 0000000..64c131f --- /dev/null +++ b/application/models/Cagecolor.php @@ -0,0 +1,15 @@ + array('type' => "int(11)",'comment' => ''), + 'color' => array('type' => "varchar(45)",'comment' => '颜色编码'), + 'is_delete' => array('type' => "varchar(45)",'comment' => '是否删除'), + 'created' => array('type' => "int(11)",'comment' => '添加时间'), + ); + public $pk = 'id'; + public function getModelList($params){ + return $this->field("{$params['field']}")->where('is_delete=0')->fList(); + } +} + diff --git a/application/models/ExcelSet.php b/application/models/ExcelSet.php new file mode 100644 index 0000000..e4845cd --- /dev/null +++ b/application/models/ExcelSet.php @@ -0,0 +1,52 @@ + array('type' => "int(11)",'comment' => 'excel设置id'), + 'now_squirrel' => array('type' => "varchar(45)",'comment' => '现存鼠导出设置'), + 'handle_squirrel' => array('type' => "varchar(45)",'comment' => '处理鼠导出设置'), + 'user_id' => array('type' => "int(11)",'comment' => '是否删除'), + ); + public $pk = 'id'; + public function getsetinfo($params){ + $data = $this->field('*')->where('='.$params['user_id'])->fRow(); + if(empty($data)){ + //现存鼠 + $data['now_squirrel']['number'] = true; + $data['now_squirrel']['sex'] = true; + $data['now_squirrel']['birthday'] = true; + $data['now_squirrel']['strains_id'] = true; + $data['now_squirrel']['gene'] = true; + $data['now_squirrel']['cage_num'] = true; + $data['now_squirrel']['content'] = true; + $data['now_squirrel']['hair_color'] = true; + $data['now_squirrel']['fenlong'] = true; + $data['now_squirrel']['fanzhi'] = true; + $data['now_squirrel']['breeding_tag'] = true; + $data['now_squirrel']['see_bole_tag'] = true; + $data['now_squirrel']['give_medicine'] = true; + $data['now_squirrel']['father'] = true; + $data['now_squirrel']['mother'] = true; + $data['now_squirrel']['remark'] = true; + //处理鼠 + $data['handle_squirrel']['number'] = true; + $data['handle_squirrel']['sex'] = true; + $data['handle_squirrel']['birthday'] = true; + $data['handle_squirrel']['strains_id'] = true; + $data['handle_squirrel']['gene'] = true; + $data['handle_squirrel']['cage_num'] = true; + $data['handle_squirrel']['content'] = true; + $data['handle_squirrel']['hair_color'] = true; + $data['handle_squirrel']['fenlong'] = true; + $data['handle_squirrel']['fanzhi'] = true; + $data['handle_squirrel']['breeding_tag'] = true; + $data['handle_squirrel']['see_bole_tag'] = true; + $data['handle_squirrel']['give_medicine'] = true; + $data['handle_squirrel']['father'] = true; + $data['handle_squirrel']['mother'] = true; + $data['handle_squirrel']['remark'] = true; + } + return $data; + } +} + diff --git a/application/models/Squirrel.php b/application/models/Squirrel.php index 13142fd..48de419 100644 --- a/application/models/Squirrel.php +++ b/application/models/Squirrel.php @@ -18,10 +18,47 @@ class SquirrelModel extends Orm_Base{ 'type' => array('type' => "varchar(255)",'comment' => '是否为新生小鼠'), 'created' => array('type' => "varchar(255)",'comment' => '是否为新生小鼠'), 'c_user_id' => array('type' => "varchar(255)",'comment' => '是否为新生小鼠'), + 'weaning_time' => array('type' => "varchar(255)",'comment' => '是否为新生小鼠'), + 'nursing_time' => array('type' => "varchar(255)",'comment' => '是否为新生小鼠'), + 'grow_time' => array('type' => "varchar(255)",'comment' => '是否为新生小鼠'), + 'infertility_time' => array('type' => "varchar(255)",'comment' => '是否为新生小鼠'), + 'dose_time' => array('type' => "varchar(255)",'comment' => '是否为新生小鼠'), + 'jianwei_time' => array('type' => "varchar(255)",'comment' => '是否为新生小鼠'), + 'test_time' => array('type' => "varchar(255)",'comment' => '是否为新生小鼠'), + 'kill_time' => array('type' => "varchar(255)",'comment' => '是否为新生小鼠'), + 'del_time' => array('type' => "varchar(255)",'comment' => '是否为新生小鼠'), ); public $pk = 'id'; - public function getModelList(){ - + public function getModelList($params){ + //获取仓鼠信息 + $data['slist']=$this->field('*')->where("is_delete=0 and is_kill=0 {$params['where']}")->fList(); + //获取繁殖笼幼崽信息 + $data['youzailishi'] = $params['type']==2?:[]; + return $data; + } + public function isFull($cage){ + $params['user_id'] = $_SESSION['uid']; + $CageSetModel = new CageSetModel(); + $time = date('Y-m-d',time()); + //获取鼠笼配置 + $cageSet = $CageSetModel->getsetinfo($params); + //查询当前是否有幼崽 + $small = $this->field('count(*) num')->where("cage={$cage} and is_delete=0 and is_kill=0 and nursing_time>'{$time}'")->fRow(); + //查询当前鼠笼是否有成年鼠 + $big = $this->field('count(*) num')->where("cage={$cage} and is_delete=0 and is_kill=0 and nursing_time<'{$time}'")->fRow(); + $data = true; + if($small['num']>0&&$big['num']>0){ + if($cageSet['big_small_num']<=$big['num']) $data = false; + } + if($small['num']>0&&$big['num']==0){ + if($cageSet['small_num_max']<=$big['num']) $data = false; + } + if($small['num']==0&&$big['num']>0){ + if($cageSet['big_num_max']<=$big['num']) $data = false; + }else{ + $data = true; + } + return $data; } } diff --git a/application/models/SquirrelSet.php b/application/models/SquirrelSet.php new file mode 100644 index 0000000..4b63b8b --- /dev/null +++ b/application/models/SquirrelSet.php @@ -0,0 +1,24 @@ + array('type' => "int(11)",'comment' => ''), + 'weaning_time' => array('type' => "varchar(45)",'comment' => '笼位编号'), + 'nursing_time' => array('type' => "varchar(45)",'comment' => '断奶时间'), + 'male_grow_time' => array('type' => "int(11)",'comment' => '雄性鼠成长时间'), + 'female_grow_time' => array('type' => "varchar(255)",'comment' => '雌性鼠成长时间'), + 'infertility_time' => array('type' => "varchar(255)",'comment' => '不育鼠时间'), + 'dose_time' => array('type' => "varchar(255)",'comment' => '给药后持续几天显示给药标识'), + 'color_time' => array('type' => "varchar(255)",'comment' => '记住几个近期给药的颜色'), + 'breeding_tag' => array('type' => "varchar(255)",'comment' => '配繁标识'), + 'see_bole_tag' => array('type' => "varchar(255)",'comment' => '见栓标识'), + 'user_id' => array('type' => "int(11)",'comment' => '添加用户id'), + 'created' => array('type' => "int(11)",'comment' => '添加时间'), + ); + public $pk = 'id'; + public function getsetinfo($params){ + $data = $this->field('*')->where('user_id='.$params['user_id'])->fRow(); + return $data; + } +} +