diff --git a/application/controllers/Api/Squirrel.php b/application/controllers/Api/Squirrel.php index e118586..3c45758 100644 --- a/application/controllers/Api/Squirrel.php +++ b/application/controllers/Api/Squirrel.php @@ -269,9 +269,9 @@ class Api_SquirrelController extends Ctrl_Api{ $data['c_user_id'] = empty($this->POST['uid'])?Tool_Fnc::apiMsg('请先登录', '500'):$this->POST['uid']; $data['count'] =empty($this->POST['count'])||!isset($this->POST['birthday'])?Tool_Fnc::apiMsg('填写幼崽数量', '500'):Tool_Fnc::safe_string($this->POST['count']); $data['birthday'] =empty($this->POST['birthday'])||!isset($this->POST['birthday'])?Tool_Fnc::apiMsg('请选择生日', '500'):Tool_Fnc::safe_string($this->POST['birthday']); - $data['father'] = empty($this->POST['father'])||!isset($this->POST['father'])?0:Tool_Fnc::safe_string($this->POST['father']); - $data['mother'] = empty($this->POST['mother'])||!isset($this->POST['father'])?0:Tool_Fnc::safe_string($this->POST['mother']); - $data['strains'] =empty($this->POST['strains'])||!isset($this->POST['strains'])?Tool_Fnc::apiMsg('请填写品系', '500'):Tool_Fnc::safe_string($this->POST['strains']); + $data['father'] = empty($this->POST['father'])||!isset($this->POST['father'])?"":Tool_Fnc::safe_string($this->POST['father']); + $data['mother'] = empty($this->POST['mother'])||!isset($this->POST['father'])?"":Tool_Fnc::safe_string($this->POST['mother']); + $data['strains'] =empty($this->POST['strains'])||!isset($this->POST['strains'])?"":Tool_Fnc::safe_string($this->POST['strains']); $data['gene'] =empty($this->POST['gene'])||!isset($this->POST['gene'])?"":Tool_Fnc::safe_string($this->POST['gene']); $data['remark'] = empty($this->POST['remark'])||!isset($this->POST['remark'])?'':Tool_Fnc::safe_string($this->POST['remark']); $data['cage'] =empty($this->POST['cage'])||!isset($this->POST['cage'])?Tool_Fnc::apiMsg('未找到当前笼位ID', '500'):Tool_Fnc::safe_string($this->POST['cage']); @@ -295,9 +295,9 @@ class Api_SquirrelController extends Ctrl_Api{ $data['id'] = empty($this->POST['id'])||!isset($this->POST['id'])?Tool_Fnc::apiMsg('系统错误', '500'):Tool_Fnc::safe_string($this->POST['id']); $data['count'] =empty($this->POST['count'])||!isset($this->POST['birthday'])?Tool_Fnc::apiMsg('填写幼崽数量', '500'):Tool_Fnc::safe_string($this->POST['count']); $data['birthday'] =empty($this->POST['birthday'])||!isset($this->POST['birthday'])?Tool_Fnc::apiMsg('请选择生日', '500'):Tool_Fnc::safe_string($this->POST['birthday']); - $data['father'] = empty($this->POST['father'])||!isset($this->POST['father'])?0:Tool_Fnc::safe_string($this->POST['father']); - $data['mother'] = empty($this->POST['mother'])||!isset($this->POST['father'])?0:Tool_Fnc::safe_string($this->POST['mother']); - $data['strains'] =empty($this->POST['strains'])||!isset($this->POST['strains'])?Tool_Fnc::apiMsg('请填写品系', '500'):Tool_Fnc::safe_string($this->POST['strains']); + $data['father'] = empty($this->POST['father'])||!isset($this->POST['father'])?'':Tool_Fnc::safe_string($this->POST['father']); + $data['mother'] = empty($this->POST['mother'])||!isset($this->POST['father'])?'':Tool_Fnc::safe_string($this->POST['mother']); + $data['strains'] =empty($this->POST['strains'])||!isset($this->POST['strains'])?"":Tool_Fnc::safe_string($this->POST['strains']); $data['gene'] =empty($this->POST['gene'])||!isset($this->POST['gene'])?"":Tool_Fnc::safe_string($this->POST['gene']); $data['remark'] = empty($this->POST['remark'])||!isset($this->POST['remark'])?'':Tool_Fnc::safe_string($this->POST['remark']); $data['cage'] =empty($this->POST['cage'])||!isset($this->POST['cage'])?Tool_Fnc::apiMsg('未找到当前笼位ID', '500'):Tool_Fnc::safe_string($this->POST['cage']); @@ -357,11 +357,53 @@ class Api_SquirrelController extends Ctrl_Api{ } public function jianweiAction(){ $number = empty($this->POST['number'])?Tool_Fnc::apiMsg('请输入编号', '500'):$this->POST['number']; + $id = empty($this->POST['id'])?Tool_Fnc::apiMsg('缺少参数', '500'):$this->POST['id']; $bianhao = explode('-',$number); + //获取号段编号 $start = (int) filter_var($bianhao[0], FILTER_SANITIZE_NUMBER_INT); $end = (int) filter_var($bianhao[1], FILTER_SANITIZE_NUMBER_INT); - echo $start; - echo $end;die; + $qianzui = rtrim($bianhao[0],$start); + $a = 1; + //判断开始结束号段标志是否相同 + if(strrpos($qianzui,rtrim($bianhao[1],$end))===false) Tool_Fnc::apiMsg('号段编号不同', '500'); + //查询幼鼠信息 + $NSdata = $this->NewSquirrelmodel->getOneInfo($id); + //判断编号数量和小鼠数量是否相同 + if($NSdata['count']!=($end-$start)) Tool_Fnc::apiMsg('编号数量小于剪尾鼠', '500'); + unset($NSdata['count']); + unset($NSdata['id']); + unset($NSdata['cage']); + $lastafter = $qianzui; + //整理新生小鼠信息 + for ($i = $start;$i<=$end;$i++){ + $after = substr($bianhao[0], 0 , strlen($bianhao[0])-strlen($i)); + $NSdata['number'] = is_numeric(substr($lastafter, -1))?$after.$i:$lastafter.$i; + $NSdata['jianwei_time'] = date("Y-m-d",time()); + $NSdata['cage'] = $NSdata['cage_id']; + $NSdata['type'] = 2; + $data[] = $NSdata; + //判断编号是否存在 + if(!empty($this->Squirrelmodel->where("number = '{$NSdata['number']}'")->fRow())){ + Tool_Fnc::apiMsg("已存在编号{$NSdata['number']}", '500'); + } + $a++; + } + //开始事务 + $this->Squirrelmodel->begin(); + if(!$this->Squirrelmodel->inserts($data)) { + $this->Squirrelmodel->back(); + Tool_Fnc::apiMsg('剪尾标记失败', '1'); + } + $ndata['id'] = $id; + $ndata['is_fen'] = 1; + $ndata['fen_num'] = $end-$start; + if($a != ($end-$start) && !$this->NewSquirrelmodel->update($ndata)) { + $this->Squirrelmodel->back(); + Tool_Fnc::apiMsg('剪尾标记失败', '1'); + } + //结束事务 + $this->Squirrelmodel->commit(); + Tool_Fnc::apiMsg('剪尾完成', '1'); } } diff --git a/application/library/Orm/Base.php b/application/library/Orm/Base.php index 6548dfd..6931801 100644 --- a/application/library/Orm/Base.php +++ b/application/library/Orm/Base.php @@ -239,14 +239,28 @@ class Orm_Base{ $tField = '`'.join('`,`', array_keys($pData)).'`'; $tVal = join("','", $pData); // 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')")){ return $this->db->lastInsertId(); } } return 0; } + function inserts($pDatas, $pReplace = false){ + $field = ""; + foreach($pDatas as $key => $pData){ + if($this->_filter($pData)){ + $tField = '`'.join('`,`', array_keys($pData)).'`'; + $tVal = join("','", $pData); + $field.="('{$tVal}'),"; +// echo ($pReplace? "REPLACE": "INSERT") . " INTO $this->table($tField) VALUES ('$tVal')";exit(); + } + } + $field = rtrim($field,","); + if($this->exec(($pReplace? "REPLACE": "INSERT") . " INTO $this->table($tField) VALUES $field")){ + return $this->db->lastInsertId(); + } + return 0; + } /** * 更新记录 diff --git a/application/models/NewSquirrel.php b/application/models/NewSquirrel.php index 44a7456..19ee613 100644 --- a/application/models/NewSquirrel.php +++ b/application/models/NewSquirrel.php @@ -33,17 +33,28 @@ class NewSquirrelModel extends Orm_Base{ public $pk = 'id'; public function getModelList($params){ $CageModel = new CageModel(); + $SquirrelModel = new SquirrelModel(); //获取幼崽信息 - $data=$this->field('id,count,birthday,father,mother,strains,gene,remark,cage')->where("id>0 {$params['where']}")->fList(); + $data=$this->field('id,count,birthday,father,mother,strains,gene,remark,cage,is_fen')->where("id>0 {$params['where']}")->fList(); foreach($data as $key => &$val){ - $val['cage'] = $CageModel->field('number')->where("id={$val['cage']}")->fRow()['number']; - $val['icon'] = Yaf_Registry::get("config")->web->url->img."/public/icon/small.png"; + if($val['is_fen']==1){ + unset($data[$key]); + }else{ + $val['cage'] = $CageModel->field('number')->where("id={$val['cage']}")->fRow()['number']; + $val['icon'] = Yaf_Registry::get("config")->web->url->img."/public/icon/small.png"; + } + } + $jian = $SquirrelModel->field('id,number,birthday,father,mother,strains_id as strains,gene,remark,cage')->where("type=2 {$params['where']}")->fList(); + foreach($jian as $key => &$va){ + $va['cage'] = $CageModel->field('number')->where("id={$va['cage']}")->fRow()['number']; + $va['icon'] = Yaf_Registry::get("config")->web->url->img."/public/icon/small.png"; } + $data = array_merge($data,$jian); return $data; } public function getOneInfo($squirrel){ $CageModel = new CageModel(); - $data = $this->field('id,count,birthday,father,mother,strains,gene,remark,cage')->where("id={$squirrel}")->fRow(); + $data = $this->field('id,count,birthday,father,mother,strains,gene,remark,cage,weaning_time,nursing_time,grow_time,infertility_time,dose_time,cage cage_id,c_user_id')->where("id={$squirrel}")->fRow(); $data['cage'] = $CageModel->field('number')->where("id={$data['cage']}")->fRow()['number']; $data['icon'] = Yaf_Registry::get("config")->web->url->img."/public/icon/small.png"; return $data; diff --git a/application/models/Squirrel.php b/application/models/Squirrel.php index b880257..b4e710f 100644 --- a/application/models/Squirrel.php +++ b/application/models/Squirrel.php @@ -37,9 +37,9 @@ class SquirrelModel extends Orm_Base{ $cageModel = new CageModel(); $NewSquirrel = new NewSquirrelModel(); //获取仓鼠信息 - $data['slist']=$this->field('id,number,sex,birthday,father,mother,strains_id as strains,gene,hair_color,cage,remark')->where("is_delete=0 and is_kill=0 {$params['where']}")->fList(); + $data['slist']=$this->field('id,number,sex,birthday,father,mother,strains_id as strains,gene,hair_color,cage,remark')->where("is_delete=0 and type=1 and is_kill=0 {$params['where']}")->fList(); foreach($data['slist'] as $key => &$val){ - $val['sex'] = $val['sex']==1?'公':'母'; + $val['sex'] = $val['sex']==1?'雄':'雌'; //获取笼位号 $val['cage'] =$cageModel->getOneInfo($val['cage'])['number']; $val['icon'] = $this->getIcon($val['id'])['icon']; @@ -87,8 +87,8 @@ class SquirrelModel extends Orm_Base{ if($cageinfo['type']==2) $exec->where("cage={$cage}"); } $data = $exec->fList(); - $data[] = ['id'=>0,'number'=>"暂无",'sex'=>2]; - $data[] = ['id'=>0,'number'=>"暂无",'sex'=>1]; + $data[] = ['id'=>0,'number'=>"未知",'sex'=>2]; + $data[] = ['id'=>0,'number'=>"未知",'sex'=>1]; return $data; } public function getIcon($squirrel){