CageSetModel=new CageSetModel(); $this->SquirrelSetModel=new SquirrelSetModel(); $this->POST =json_decode(file_get_contents('php://input'),true); $this->ExcelSetModel=new ExcelSetModel(); } /** * 获取设置接口 */ public function getSetInfoAction(){ $params['user_id'] = empty($this->POST['uid'])?Tool_Fnc::apiMsg('请先登录', '500'):$this->POST['uid']; //笼位设置 $data['cageSet'] = $this->CageSetModel->getsetinfo($params); //鼠设置 $data['squirrelSet'] = $this->SquirrelSetModel->getsetinfo($params); //excel导出设置 $data['excelSet'] = $this->ExcelSetModel->getsetinfo($params); Tool_Fnc::apiMsg('获取成功', '200',$data); } /** * 获取设置接口 */ public function editSetAction(){ $uid = empty($this->POST['uid'])?Tool_Fnc::apiMsg('请先登录', '500'):$this->POST['uid']; $cageSet = $this->POST['cageSet']; $cageSet['c_user_id']=$uid; $squirrelSet = $this->POST['squirrelSet']; $squirrelSet['user_id']=$uid; $excelSet = $this->POST['excelSet']; $excelSet['now_squirrel']=json_encode($excelSet['now_squirrel']); $excelSet['handle_squirrel']=json_encode($excelSet['handle_squirrel']); $excelSet['user_id']=$uid; $this->CageSetModel->save($cageSet); $this->SquirrelSetModel->save($squirrelSet); $this->ExcelSetModel->save($excelSet); Tool_Fnc::apiMsg('设置成功', '200'); //写入配置 } public function getUserinfoAction(){ $uid = empty($this->POST['uid'])?Tool_Fnc::apiMsg('请先登录', '500'):$this->POST['uid']; $UserModel = new UserModel(); $data = $UserModel->field("*")->where("id={$uid}")->fRow(); //获取笼位数量 $Cagemodel = new CageModel(); $CageNum = $Cagemodel->field('count(*) as num')->where("c_user_id={$uid}")->fRow(); $data['cage_num'] = $CageNum['num']; unset($data['password']); Tool_Fnc::apiMsg('获取成功', '200',$data); } public function excelDaochuAction(){ $Squirrel = new SquirrelModel(); $CageModel = new CageModel(); //获取用户excel设置 $params['user_id'] = empty($this->POST['uid'])?Tool_Fnc::apiMsg('请先登录', '500'):$this->POST['uid']; $excelSet= $this->ExcelSetModel->getsetinfo($params); $header = ['number'=>"编号",'sex'=>"性别","birthday"=>"生日","strains_id"=>"品系","gene"=>"基因","cage_num"=>"笼号","content"=>"描述","hair_color"=>"毛色","fenlong"=>"分笼","fanzhi"=>"配繁","breeding_tag"=>"体重","see_bole_tag"=>"见栓","give_medicine"=>"给药","father"=>"父亲","mother"=>"母亲","remark"=>"备注"]; $field = ['number'=>"number",'sex'=>"sex","birthday"=>"birthday","strains_id"=>"strains_id","gene"=>"gene","cage_num"=>"cage","content"=>"remark as content","hair_color"=>"hair_color","fenlong"=>"created","fanzhi"=>"grow_time","breeding_tag"=>"grow_time as weight","see_bole_tag"=>"infertility_time","give_medicine"=>"nursing_time","father"=>"father","mother"=>"mother","remark"=>"remark"]; foreach($excelSet['now_squirrel'] as $k1 => $val){ if($val) $now_header[] = $header[$k1]; if($val) $now_field[] = $field[$k1]; } $excel = implode(",",$now_header)."\n"; //获取现存鼠数据 $fields = implode(",",$now_field); $nowdata = $Squirrel->field("{$fields}")->where("c_user_id={$params['user_id']} and is_kill=0")->fList(); foreach($nowdata as $key => &$val){ if(isset($val["sex"])) $val["sex"] = $val["sex"]==1?"公":"母"; if(isset($val["cage"])) $val["cage"] = $CageModel->getOneInfo($val["cage"])['number']; $excel.=implode(",",$val)."\n"; } foreach($excelSet['handle_squirrel'] as $k2 => $va){ if($va) $handle_header[] = $header[$k2]; if($va) $handle_field[] = $field[$k2]; } $excel .= implode(",",$handle_header)."\n"; //获取处理鼠数据 $fields = implode(",",$handle_field); $handledata = $Squirrel->field("{$fields}")->where("c_user_id={$params['user_id']} and is_kill=1")->fList(); foreach($handledata as $key => &$val){ if(isset($val["sex"])) $val["sex"] = $val["sex"]==1?"公":"母"; if(isset($val["cage"])) $val["cage"] = $CageModel->getOneInfo($val["cage"])['number']; $excel.=implode(",",$val)."\n"; } $path = APPLICATION_PATH."/public/upload/excel/"; $excel = iconv('utf-8','gbk',$excel); $fileName = 'EXCEL导出鼠信息'.time(). '.csv'; file_put_contents($path.$fileName, $excel); $data['url']=Yaf_Registry::get("config")->web->url->img."/public/upload/excel/".$fileName; echo $data['url'];die; Tool_Fnc::apiMsg('获取成功', '200',$data); } }