YS:鼠笼后台管理及接口

master
yangsai@163.com 10 months ago
parent b83a7eb453
commit d9e452bb40
  1. 92
      application/controllers/Api/Cage.php
  2. 114
      application/controllers/Api/Login.php
  3. 96
      application/controllers/Api/Squirrel.php
  4. 2
      application/controllers/Index.php
  5. 2
      application/library/Orm/Base.php
  6. 3
      application/library/Tool/Fnc.php
  7. 54
      application/models/Cage.php
  8. 19
      application/models/CageSet.php
  9. 27
      application/models/Squirrel.php
  10. 23
      application/models/User.php
  11. 8
      conf/application.ini

@ -0,0 +1,92 @@
<?php
/**
* 鼠笼笼位相关接口
* @author YS
* @version 1.0
*/
class Api_CageController extends Ctrl_Api{
public $Cagemodel;
public function init() {
$this->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(){
}
}

@ -0,0 +1,114 @@
<?php
/**
* 鼠笼前台登录接口
* @author YS
* @version 1.0
*/
class Api_LoginController extends Ctrl_Api{
public $Usermodel;
public function init() {
$this->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');
}
}

@ -0,0 +1,96 @@
<?php
/**
* 鼠笼笼位相关接口
* @author YS
* @version 1.0
*/
class Api_SquirrelController extends Ctrl_Api{
public $Squirrelmodel;
public function init() {
$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(){
}
/**
* 小鼠添加接口
* @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(){
}
}

@ -4,7 +4,7 @@
*/
class IndexController extends Ctrl_Base{
public function indexAction(){
header('Location:/Admin_Admin/index');exit;
header('Location:/index_index/index');exit;
}
}

@ -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')")){

@ -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){

@ -0,0 +1,54 @@
<?php
class CageModel extends Orm_Base{
public $table = 'cage';
public $field = array(
'id' => 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;
}
}

@ -0,0 +1,19 @@
<?php
class CageSetModel extends Orm_Base{
public $table = 'cage_set';
public $field = array(
'id' => 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';
}

@ -0,0 +1,27 @@
<?php
class SquirrelModel extends Orm_Base{
public $table = 'squirrel';
public $field = array(
'id' => 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(){
}
}

@ -0,0 +1,23 @@
<?php
class UserModel extends Orm_Base{
public $table = 'user';
public $field = array(
'id' => 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(){
}
}

@ -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"

Loading…
Cancel
Save