yangsai@163.com 6 months ago
parent b7f8d02b0e
commit 12469c9402
  1. 54
      application/controllers/Api/Cage.php

@ -136,24 +136,48 @@ class Api_CageController extends Ctrl_Api{
public function cagemovellistAction(){
$uid = empty($this->POST['uid'])?Tool_Fnc::apiMsg('请先登录', '500'):$this->POST['uid'];
$id = empty($this->POST['id'])?Tool_Fnc::apiMsg('小鼠ID', '500'):$this->POST['id'];
$keyword = empty($this->POST['keyword'])?'':$this->POST['keyword'];
$squirrel = $this->SquirrelModel->getOneInfo($id);
$data = $this->Cagemodel->field('id,number,color,strains,type ')->where("c_user_id='{$uid}' and id!={$squirrel['cage']}")->fList();
$data = $this->Cagemodel->field('id,number,color,strains,type ');
$data = $data->where("c_user_id='{$uid}' and id!={$squirrel['cage']} and is_delete=0");
if(!empty($keyword)){
$data = $data->where("c_user_id='{$uid}' and id!={$squirrel['cage']} and is_delete=0 and (number like '%{$keyword}%' or strains like '%{$keyword}%')");
}
$data = $data->fList();
foreach($data as $key => $val){
if(!$this->SquirrelModel->isFull($val['cage'],$uid)) unset($data[$key]);
//查询公鼠
$sql = "select count(*) num from squirrel where cage={$data[$key]['id']} and is_kill=0 and is_delete=0 and sex=1";
$mannum = $this->Cagemodel->query($sql);
if(!empty($mannum)){
if($val['type']==2 && $squirrel['sex']==1) unset($data[$key]);
$data[$key]['mannum'] = $mannum[0]['num'];
}
//查询母鼠
$sql = "select count(*) num from squirrel where cage={$data[$key]['id']} and is_kill=0 and is_delete=0 and sex=2";
$womannum = $this->Cagemodel->query($sql);
if(!empty($womannum)){
$data[$key]['womannum'] = $womannum[0]['num'];
}
$data[$key]['type_color'] = $data[$key]['type']==2?'#FF0000':'';
if($this->SquirrelModel->isFull($val['cage'],$uid)) {
//查询公鼠
$sql = "select count(*) num from squirrel where cage={$data[$key]['id']} and is_kill=0 and is_delete=0 and sex=1";
$mannum = $this->Cagemodel->query($sql);
if(!empty($mannum)){
$data[$key]['mannum'] = $mannum[0]['num'];
// if(($val['type']==2 && $squirrel['sex']==1) || $squirrel['sex']==2) unset($data[$key]);
}
//查询母鼠
$sql = "select count(*) num from squirrel where cage={$data[$key]['id']} and is_kill=0 and is_delete=0 and sex=2";
$womannum = $this->Cagemodel->query($sql);
if(!empty($womannum)){
$data[$key]['womannum'] = $womannum[0]['num'];
// if($squirrel['sex']==1) unset($data[$key]);
}
if($val['type']==2){
if($squirrel['sex']==1){
if((int)$this->SquirrelModel->field("count(*) num")->where("sex=1 and cage={$val['id']} and id!={$squirrel['id']}")->fList()['num']==1) unset($data[$key]);
}if($squirrel['sex']==2){
if((int)$this->SquirrelModel->field("count(*) num")->where("sex=2 and cage={$val['id']} and id!={$squirrel['id']}")->fList()['num']==2) unset($data[$key]);
}
}else{
//查询笼位是否有不同性别鼠
if($squirrel['sex']==1){
if(!empty($this->SquirrelModel->field("*")->where("sex=2 and cage={$val['id']} and id!={$squirrel['id']}")->fRow())) unset($data[$key]);
}if($squirrel['sex']==2){
if(!empty($this->SquirrelModel->field("*")->where("sex=1 and cage={$val['id']} and id!={$squirrel['id']}")->fRow())) unset($data[$key]);
}
}
}else{
unset($data[$key]);
}
}
Tool_Fnc::apiMsg('获取成功 ', '200',$data);
}

Loading…
Cancel
Save