From d9e452bb40e789cca654f12d46aabe997dde61de Mon Sep 17 00:00:00 2001 From: "yangsai@163.com" <2624183217@qq.com> Date: Tue, 14 May 2024 13:54:20 +0800 Subject: [PATCH] =?UTF-8?q?YS:=E9=BC=A0=E7=AC=BC=E5=90=8E=E5=8F=B0?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=8F=8A=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/controllers/Api/Cage.php | 92 ++++++++++++++++++ application/controllers/Api/Login.php | 114 +++++++++++++++++++++++ application/controllers/Api/Squirrel.php | 96 +++++++++++++++++++ application/controllers/Index.php | 2 +- application/library/Orm/Base.php | 2 +- application/library/Tool/Fnc.php | 3 +- application/models/Cage.php | 54 +++++++++++ application/models/CageSet.php | 19 ++++ application/models/Squirrel.php | 27 ++++++ application/models/User.php | 23 +++++ conf/application.ini | 8 +- 11 files changed, 433 insertions(+), 7 deletions(-) create mode 100644 application/controllers/Api/Cage.php create mode 100644 application/controllers/Api/Login.php create mode 100644 application/controllers/Api/Squirrel.php create mode 100644 application/models/Cage.php create mode 100644 application/models/CageSet.php create mode 100644 application/models/Squirrel.php create mode 100644 application/models/User.php diff --git a/application/controllers/Api/Cage.php b/application/controllers/Api/Cage.php new file mode 100644 index 0000000..50cca54 --- /dev/null +++ b/application/controllers/Api/Cage.php @@ -0,0 +1,92 @@ +Cagemodel = new CageModel(); + } + /** + * 鼠笼列表接口 + * @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": "添加成功", + * "data": { + * "username": "用户名", + * "type": "1",用户类型 + * "realname": "真实姓名", + * "faculties": "1",院系 + * "specialized": "1",专业 + * "group": "1",课题组 + * "teacher": "1",导师 + * "phone": "13566987478",手机号 + * "status": "1",审核状态 + * "is_delete": "0"是否删除 + * } + * } + */ + 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(){ + + } +} + diff --git a/application/controllers/Api/Login.php b/application/controllers/Api/Login.php new file mode 100644 index 0000000..bd25e10 --- /dev/null +++ b/application/controllers/Api/Login.php @@ -0,0 +1,114 @@ +Usermodel = new UserModel(); + } + /** + * 鼠笼系统登录接口 + * @param $Username 用户名 + * @param $Password 密码 + * @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 indexAction(){ + //用户名 + $Username = empty($_POST['Username'])||!isset($_POST['Username'])? Tool_Fnc::apiMsg('请输入正确的用户名或密码', '500'):Tool_fnc::safe_string($_POST['Username']); + //密码 + $Password = empty($_POST['Password'])||!isset($_POST['Password'])? Tool_Fnc::apiMsg('请输入正确的用户名或密码', '500'):Tool_fnc::safe_string($_POST['Password']); + $Type = empty($_POST['Type'])||!isset($_POST['Type'])? Tool_Fnc::apiMsg('请选择登录的人员类型', '500'):Tool_fnc::safe_string($_POST['Type']); + $Userinfo = $this->Usermodel->field('*')->where("username='{$Username}' and status=1 and type={$Type}")->fRow(); + empty($Userinfo)?Tool_Fnc::apiMsg('请输入正确的用户名或密码', '500'):$Userinfo; + $Userinfo['password']!=md5($Password.Yaf_Registry::get("config")->psd->default->appsecret)?Tool_Fnc::apiMsg('请输入正确的用户名或密码', '500'):$Userinfo['password']; + unset($Userinfo['password']); + $_SESSION['uid'] = $Userinfo['id']; + $_SESSION['username'] = $Userinfo['username']; + $_SESSION['type'] = $Userinfo['type']; + unset($Userinfo['id']); + if($Userinfo['status']!=1) Tool_Fnc::apiMsg('账号审核中请耐心等待', '500'); + + Tool_Fnc::apiMsg('登陆成功', '200',$Userinfo); + } + /** + * 鼠笼系统注册接口 + * @param username 用户名 + * @param password 密码 + * @param type 用户类型 + * @param realname 用户类型 + * @param faculties 用户类型 + * @param specialized 用户类型 + * @param group 用户类型 + * @param teacher 用户类型 + * @return + * { + * "errorcode": "200", + * "message": "注册成功", + * "data": { + * "username": "用户名", + * "password": "1",密码 + * "type": "用户类型", + * "realname": "1",真实姓名 + * "faculties": "1",院系 + * "specialized": "1",专业 + * "group": "1",课题组 + * "teacher": "13566987478",导师 + * } + * } + */ + public function registerAction(){ + //用户名 + $username = empty($_POST['username'])||!isset($_POST['username'])? Tool_Fnc::apiMsg('请输入用户名', '500'):Tool_fnc::safe_string($_POST['username']); + //密码 + $password = empty($_POST['password'])||!isset($_POST['password'])? Tool_Fnc::apiMsg('请输入密码', '500'):Tool_fnc::safe_string($_POST['password']); + //用户类型 + $type = empty($_POST['type'])||!isset($_POST['type'])? Tool_Fnc::apiMsg('请选择用户类型', '500'):Tool_fnc::safe_string($_POST['type']); + //真实姓名 + $realname = empty($_POST['realname'])||!isset($_POST['realname'])? Tool_Fnc::apiMsg('请输入真实姓名', '500'):Tool_fnc::safe_string($_POST['realname']); + //院系 + $faculties = empty($_POST['faculties'])||!isset($_POST['faculties'])? Tool_Fnc::apiMsg('请选择院系', '500'):Tool_fnc::safe_string($_POST['faculties']); + //专业 + $specialized = empty($_POST['specialized'])||!isset($_POST['specialized'])? Tool_Fnc::apiMsg('请选择专业', '500'):Tool_fnc::safe_string($_POST['specialized']); + //课题组 + $group = empty($_POST['group'])||!isset($_POST['group'])? Tool_Fnc::apiMsg('请选择课题组', '500'):Tool_fnc::safe_string($_POST['group']); + //导师 + $teacher = empty($_POST['teacher'])||!isset($_POST['teacher'])? Tool_Fnc::apiMsg('请选择导师', '500'):Tool_fnc::safe_string($_POST['teacher']); + //查询用户名是否存在 + $Userinfo = $this->Usermodel->field('*')->where("username='{$username}' and type={$type} and is_delete=0")->fRow(); + if(!empty($Userinfo)) Tool_Fnc::apiMsg('当前选择人员类型已存在此用户名,请重新填写用户名', '500'); + $data['username'] = $username; + $data['password'] = $password; + $data['realname'] = $realname; + $data['type'] = $type; + $data['faculties'] = $faculties; + $data['specialized'] = $specialized; + $data['group'] = $group; + $data['teacher'] = $teacher; + $ret = $this->Usermodel->save($data); + if(!$ret) Tool_Fnc::apiMsg('注册失败', '500'); + Tool_Fnc::apiMsg('注册成功,等待管理员审核通过', '200'); + + } + } + diff --git a/application/controllers/Api/Squirrel.php b/application/controllers/Api/Squirrel.php new file mode 100644 index 0000000..72db828 --- /dev/null +++ b/application/controllers/Api/Squirrel.php @@ -0,0 +1,96 @@ +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(){ + + } + /** + * 小鼠添加接口 + * @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'] = $_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($_POST['sex'])||!isset($_POST['sex'])?Tool_Fnc::apiMsg('请选择性别', '500'):Tool_Fnc::safe_string($_POST['sex']); + $data['birthday'] =empty($_POST['birthday'])||!isset($_POST['birthday'])?Tool_Fnc::apiMsg('请填写生日', '500'):Tool_Fnc::safe_string($_POST['birthday']); + $data['father'] = empty($_POST['father'])||!isset($_POST['father'])?0:Tool_Fnc::safe_string($_POST['father']); + $data['mother'] = empty($_POST['mother'])||!isset($_POST['father'])?0:Tool_Fnc::safe_string($_POST['mother']); + $data['strains_id'] =empty($_POST['strains_id'])||!isset($_POST['strains_id'])?Tool_Fnc::apiMsg('请选择品系', '500'):Tool_Fnc::safe_string($_POST['strains_id']); + $data['gene'] =empty($_POST['gene'])||!isset($_POST['gene'])?Tool_Fnc::apiMsg('请填写基因', '500'):Tool_Fnc::safe_string($_POST['gene']); + $data['hair_color'] =empty($_POST['hair_color'])||!isset($_POST['hair_color'])?Tool_Fnc::apiMsg('请选择毛色', '500'):Tool_Fnc::safe_string($_POST['hair_color']); + $data['remark'] = empty($_POST['remark'])||!isset($_POST['remark'])?Tool_Fnc::apiMsg('请填写备注', '500'):Tool_Fnc::safe_string($_POST['remark']); + $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']; + $ret = $this->Squirrelmodel->insert($data); + if(!$ret) Tool_Fnc::apiMsg('小鼠建档失败', '500'); + Tool_Fnc::apiMsg('小鼠建档成功', '200'); + } + public function edidAction(){ + + } +} + diff --git a/application/controllers/Index.php b/application/controllers/Index.php index 0a29e97..643f1cd 100644 --- a/application/controllers/Index.php +++ b/application/controllers/Index.php @@ -4,7 +4,7 @@ */ class IndexController extends Ctrl_Base{ public function indexAction(){ - header('Location:/Admin_Admin/index');exit; + header('Location:/index_index/index');exit; } } diff --git a/application/library/Orm/Base.php b/application/library/Orm/Base.php index 0c972b5..6548dfd 100644 --- a/application/library/Orm/Base.php +++ b/application/library/Orm/Base.php @@ -238,7 +238,7 @@ class Orm_Base{ if($this->_filter($pData)){ $tField = '`'.join('`,`', array_keys($pData)).'`'; $tVal = join("','", $pData); -// echo $tSql = ($pReplace? "REPLACE": "INSERT") . " INTO `$this->table`($tField) VALUES ('$tVal')";exit(); +// echo ($pReplace? "REPLACE": "INSERT") . " INTO $this->table($tField) VALUES ('$tVal')";exit(); #Tool_Fnc::writefile('/home/zhangyueru/xx',$tSql); if($this->exec(($pReplace? "REPLACE": "INSERT") . " INTO $this->table($tField) VALUES ('$tVal')")){ diff --git a/application/library/Tool/Fnc.php b/application/library/Tool/Fnc.php index ab741b2..1c6a180 100644 --- a/application/library/Tool/Fnc.php +++ b/application/library/Tool/Fnc.php @@ -380,10 +380,11 @@ HTML; public static function safe_string($pString,$pFlag = 0){ $pString=trim($pString); $pString=str_replace(array("union","into","load_file","outfile"),array("UNION","INTO","LOAD—FILE","OUTFILE"),$pString); + $get_magic_quotes_gpc = (($quotes_gpc = ini_get('magic_quotes_gpc')) && strtolower($quotes_gpc) !== 'off'); if(!$pFlag){ $pString=htmlspecialchars($pString,ENT_QUOTES); } - if (!get_magic_quotes_gpc())$pString=addslashes($pString); + if (!$get_magic_quotes_gpc)$pString=addslashes($pString); return $pString; } public static function de_safe_string($pString){ diff --git a/application/models/Cage.php b/application/models/Cage.php new file mode 100644 index 0000000..64acd63 --- /dev/null +++ b/application/models/Cage.php @@ -0,0 +1,54 @@ + array('type' => "int(11)",'comment' => ''), + 'number' => array('type' => "varchar(45)",'comment' => '笼位编号'), + 'strains' => array('type' => "varchar(45)",'comment' => '品系'), + 'type' => array('type' => "int(11)",'comment' => '笼位类型 '), + 'color' => array('type' => "varchar(255)",'comment' => '笼位颜色'), + 'group' => array('type' => "varchar(255)",'comment' => '实验室对应用户课题组'), + 'user_id' => array('type' => "varchar(255)",'comment' => '负责人id'), + 'c_user_id' => array('type' => "varchar(255)",'comment' => '添加人id'), + 'code' => array('type' => "varchar(255)",'comment' => '二维码信息'), + 'is_delete' => array('type' => "int(11)",'comment' => '是否删除'), + 'created' => array('type' => "varchar(255)",'comment' => '添加时间'), + ); + public $pk = 'id'; + public function getModelList($params){ + //查询当前笼位一行显示几个 + $cagemodel = new CageSetModel(); + $shownum = $cagemodel->field('line_num')->where("c_user_id='{$_SESSION['id']}'")->fRow(); + $limmit = empty($shownum['line_num'])?20:$shownum['line_num']*5; + $sql = "select cage.id,cage.number,cage.color,strains.title strains from cage left join strains on cage.strains=strains.id"; + if(!empty($params['keywords'])){ + $sql .="cage.number like '%{$params['order']}%'"; + } + if(!empty($params['order'])){ + $sql .=" order by cage.{$params['order']} desc"; + }else{ + $sql .=" order by cage.id desc"; + } + $data['count'] = count($this->query($sql)); + $offset = ($params['page']-1)*$limmit; + $sql .=" limit {$offset},{$limmit}"; + $data['data'] = $this->query($sql); + foreach($data['data'] as $key => &$val){ + //查询公鼠 + $sql = "select count(*) num from squirrel where cage={$val['id']} and is_kill=0 and is_delete=0 and sex=1"; + $mannum = $this->query($sql); + if(!empty($mannum)){ + $val['mannum'] = $mannum[0]['num']; + } + //查询母鼠 + $sql = "select count(*) num from squirrel where cage={$val['id']} and is_kill=0 and is_delete=0 and sex=2"; + $womannum = $this->query($sql); + if(!empty($womannum)){ + $val['womannum'] = $womannum[0]['num']; + } + } + $data['page'] = $params['page']; + return $data; + } +} + diff --git a/application/models/CageSet.php b/application/models/CageSet.php new file mode 100644 index 0000000..b9f2b39 --- /dev/null +++ b/application/models/CageSet.php @@ -0,0 +1,19 @@ + array('type' => "int(11)",'comment' => ''), + 'line_num' => array('type' => "varchar(45)",'comment' => '笼位编号'), + 'big_num_max' => array('type' => "varchar(45)",'comment' => '品系'), + 'small_num_max' => array('type' => "int(11)",'comment' => '笼位类型 '), + 'big_small_num' => array('type' => "varchar(255)",'comment' => '笼位颜色'), + 'split_remind' => array('type' => "varchar(255)",'comment' => '实验室对应用户课题组'), + 'timeout_split_remind' => array('type' => "varchar(255)",'comment' => '负责人id'), + 'overload_remind' => array('type' => "varchar(255)",'comment' => '添加人id'), + 'fight' => array('type' => "varchar(255)",'comment' => '二维码信息'), + 'c_user_id' => array('type' => "int(11)",'comment' => '是否删除'), + ); + public $pk = 'id'; + +} + diff --git a/application/models/Squirrel.php b/application/models/Squirrel.php new file mode 100644 index 0000000..13142fd --- /dev/null +++ b/application/models/Squirrel.php @@ -0,0 +1,27 @@ + array('type' => "int(11)",'comment' => ''), + 'number' => array('type' => "varchar(45)",'comment' => '笼位编号'), + 'sex' => array('type' => "varchar(45)",'comment' => '性别'), + 'birthday' => array('type' => "int(11)",'comment' => '小鼠生日'), + 'father' => array('type' => "varchar(255)",'comment' => '小鼠父亲'), + 'mother' => array('type' => "varchar(255)",'comment' => '小鼠母亲'), + 'strains_id' => array('type' => "varchar(255)",'comment' => '小鼠品系'), + 'gene' => array('type' => "varchar(255)",'comment' => '小鼠基因'), + 'hair_color' => array('type' => "varchar(255)",'comment' => '小鼠毛色'), + 'remark' => array('type' => "int(11)",'comment' => '备注'), + 'is_kill' => array('type' => "varchar(255)",'comment' => '是否杀死'), + 'is_delete' => array('type' => "varchar(255)",'comment' => '是否删除'), + 'cage' => array('type' => "varchar(255)",'comment' => '笼位id'), + 'type' => array('type' => "varchar(255)",'comment' => '是否为新生小鼠'), + 'created' => array('type' => "varchar(255)",'comment' => '是否为新生小鼠'), + 'c_user_id' => array('type' => "varchar(255)",'comment' => '是否为新生小鼠'), + ); + public $pk = 'id'; + public function getModelList(){ + + } +} + diff --git a/application/models/User.php b/application/models/User.php new file mode 100644 index 0000000..41ebc04 --- /dev/null +++ b/application/models/User.php @@ -0,0 +1,23 @@ + array('type' => "int(11)",'comment' => ''), + 'username' => array('type' => "varchar(45)",'comment' => '用户名'), + 'password' => array('type' => "varchar(45)",'comment' => '密码'), + 'type' => array('type' => "int(11)",'comment' => '注册人员类型 '), + 'realname' => array('type' => "varchar(255)",'comment' => '真实姓名'), + 'faculties' => array('type' => "varchar(255)",'comment' => '院系'), + 'specialized' => array('type' => "varchar(255)",'comment' => '专业'), + 'group' => array('type' => "varchar(255)",'comment' => '课题组'), + 'teacher' => array('type' => "varchar(255)",'comment' => '导师'), + 'phone' => array('type' => "int(11)",'comment' => '手机号'), + 'status' => array('type' => "int(11)",'comment' => '审核状态'), + 'is_delete' => array('type' => "int(11)",'comment' => '是否删除'), + ); + public $pk = 'id'; + public function getModelList(){ + + } +} + diff --git a/conf/application.ini b/conf/application.ini index aa03ca4..371dc94 100644 --- a/conf/application.ini +++ b/conf/application.ini @@ -3,14 +3,13 @@ application.directory=APPLICATION_PATH "/application" application.dispatcher.throwException=FALSE application.dispatcher.catchException=FALSE -db.default.dsn = "mysql:dbname=medical_wx_zhyy;host=127.0.0.1" +db.default.dsn = "mysql:dbname=squirrel_cage;host=127.0.0.1" db.default.username = root db.default.password = "root" -db.database.dsn = "mysql:dbname=medical_wx_zhyy;host=127.0.0.1" +db.database.dsn = "mysql:dbname=squirrel_cage;host=127.0.0.1" db.database.username = root -db.database.password = "ZAQ!2wsxroot" - +db.database.password = "root" redis.default.host = 127.0.0.1 redis.default.port = 6379 redis.default.db = 2 @@ -20,6 +19,7 @@ web.url.getui = "http://ys.medical_wx.huayan100.com/" web.url.czzyyapi = "http://192.168.90.24:4419/" ocr.default.datadir="/home/data/ocrimg/" +psd.default.appsecret = 'renzhoukeji' mail.default.host="smtp.163.com" mail.default.from="wanghao163_1@163.com"