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

70 lines
3.4 KiB

<?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='{$params['uid']}'")->fRow();
$limmit = empty($shownum['line_num'])?20:$shownum['line_num']*4;
$sql = "select id,number,color,strains,type from cage where c_user_id={$params['uid']} and is_delete=0";
if(!empty($params['keyword'])){
$sql .=" and (number like '%{$params['keyword']}%' or strains like '%{$params['keyword']}%')";
}
if(!empty($params['order'])){
$sql .=" order by {$params['order']} {$params['desc']}";
}else{
$sql .=" order by id {$params['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){
//查询鼠编号
$val['squirrel'] = $this->query("select number from squirrel where cage={$val['id']} and is_kill=0 and is_delete=0 and type=1 limit 0,6");
//查询公鼠
$sql = "select count(*) num from squirrel where cage={$val['id']} and is_kill=0 and is_delete=0 and sex=1 and type=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 and type=1";
$womannum = $this->query($sql);
if(!empty($womannum)){
$val['womannum'] = $womannum[0]['num'];
}
//查询其他
$sql = "select count(*) num from squirrel where cage={$val['id']} and is_kill=0 and is_delete=0 and sex=0 and type=1";
$othernum = $this->query($sql);
if(!empty($othernum)){
$val['othernum'] = $othernum[0]['num'];
}
$val['type_color'] = $val['type']==2?'#FF0000':'';
}
$data['page'] = $params['page'];
return $data;
}
public function getOneInfo($id){
$UserModel = new UserModel();
$info = $this->field('*')->where("id='{$id}'")->fRow();
//负责人id
$info['user'] = $UserModel->field('realname')->where("id={$info['user_id']}")->fRow()['realname'];
return $info;
}
}