## 一、家庭档案信息显示
### 1.调试接口
+++
get:http://www.dakaifa.net/index.php?g=App&m=My&a=familyDoc
*int:uid=111#说明文字
limit=2#显示几条
<<<
success
[
{
"id": "27",
"uid": "111",
"cid": "1",
"username": "掌门",
"avatar": "http://dakaifa.net/data/upload/avatar/57b683ca5e92c.jpg",
"age": "50",
"diseases_history": "慢性病",
"name": "子女"
},
{
"id": "34",
"uid": "111",
"cid": "1",
"username": "张威 ",
"avatar": "http://dakaifa.net/data/upload/avatar/579eb36aad16c.jpg",
"age": "30",
"diseases_history": "胃病,慢性病",
"name": "子女"
}
]
<<<
error
+++
### 2.接口代码
```
public function familyDoc(){
$uid=$_GET['uid'];
$limit=$_GET['limit'];
$join = "".C('DB_PREFIX').'file_classify as b on a.cid =b.cid';
$rs=M('Family_files');
$field="a.id,a.uid,a.cid,a.username,a.avatar,a.age,a.diseases_history,b.name";
if($limit){
$docs=$rs->alias("a")->join($join)->field($field)->where("uid={$uid}")->limit($limit)->select();
}else{
$docs=$rs->alias("a")->join($join)->field($field)->where("uid={$uid}")->select();
}
foreach ($docs as &$value) {
$value['avatar']="http://".$_SERVER['SERVER_NAME']."/data/upload/avatar/". $value['avatar'];
}
echo json_encode($docs);
}
```
## 二、家庭档案信息添加
### 1.调试接口
+++
post:http://www.dakaifa.net/index.php?g=App&m=My&a=submit_familyDoc
*username=111#用户名
*age=20#年龄
*avatar=qq.jpg#头像 //不支持
*sex=0#性别
*vaccine_time=1989-09-10#疫苗时间
*health_time=1989-09-10#体检时间
*health_status=优秀#健康状况
*diseases_history=胃病#疾病史
*allergic_history=罗红霉素#过敏史
*yanjiu_survey=不喝酒不吸烟#烟酒史
*health_investment=运动健身,家庭医生与服务#健康投资
*cid=1#分类id
*uid=113#用户id
<<<
success
{
"msg": 1
}
<<<
error
{
"msg": 0
}
+++
### 2.接口代码
```
public function submit_familyDoc(){
// 家庭档案id
$fid=$_POST['fid'];
$familyInfo=$_POST['familyInfo'];
// 处理头像上传
$upload = new \Think\Upload();// 实例化上传类
$upload->maxSize = 3145728 ;// 设置附件上传大小
$upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
$upload->rootPath = './'.C("UPLOADPATH"); // 设置附件上传根目录
$upload->savePath = './avatar/'; // 设置附件上传(子)目录
$info = $upload->upload();
$rst=json_decode($familyInfo,true);
$rst['diseases_history']=implode(',', $rst['diseases_history']);
$rst['allergic_history']=implode(',', $rst['allergic_history']);
$rst['health_investment']=implode(',', $rst['health_investment']);
// 数据写入
$family_model=M('Family_files');
$data=array(
'username'=>$rst['username']?$rst['username']:$_POST['username'],
'avatar' =>$info["upfile"]['savename'],
'sex' => $rst['sex']?$rst['sex']:$_POST['sex'],
'age' => $rst['age']?$rst['age']:$_POST['age'],
'vaccine_time' =>$rst['vaccine_time']?$rst['vaccine_time']:$_POST['vaccine_time'],
'health_time' =>$rst['health_time']?$rst['health_time']:$_POST['health_time'],
'health_status' => $rst['health_status']?$rst['health_status']:$_POST['health_status'],
'diseases_history' => $rst['diseases_history']?$rst['diseases_history']:$_POST['diseases_history'],
'allergic_history' => $rst['allergic_history']?$rst['allergic_history']:$_POST['allergic_history'],
'yanjiu_survey' => $rst['yanjiu_survey']?$rst['yanjiu_survey']:$_POST['yanjiu_survey'],
'health_investment' => $rst['health_investment']?$rst['health_investment']:$_POST['health_investment'],
"cid"=>$rst['cid']?$rst['cid']:$_POST['cid'],
"uid" =>$rst['uid']?$rst['uid']:$_POST['uid'],
);
// 判断数据库中是否存在家庭档案
if($fid){
$ret=$family_model->find($fid);
$old_img=$ret['avatar'];
// 删除原头像
sp_delete_avatar($old_img);
$row= $family_model->where("id={$fid}")->save($data);
}else{
$row= $family_model->add($data);
}
// 判断是否执行成功
if($row){
$arr=array('msg'=>1);
echo json_encode($arr);
}else{
$arr=array('msg'=>0);
echo json_encode($arr);
}
}
```
### 三、显示要修改的家庭档案信息
### 1.调试接口
+++
post:http://www.dakaifa.net/index.php?g=App&m=My&a=updateFamilyDoc
*int:fid=26#用户的家庭档案id
<<<
success
{
"id": "24",
"username": "张天",
"avatar": "http://dakaifa.net/data/upload/avatar/579819b4b91a1.jpg",
"sex": "1",
"age": "28",
"vaccine_time": "1990/1/1",
"health_time": "1990/1/1",
"health_status": "优秀",
"diseases_history": "胃病,慢性病",
"allergic_history": "青霉素,胡萝卜",
"yanjiu_survey": "不吸烟不喝酒",
"health_investment": "购买健康刊物,关注健康咨询和书籍,购买健康保险",
"cid": "3",
"uid": "111"
}
<<<
error
+++
### 2.调试接口
```
public function updateFamilyDoc(){
$id=$_GET['fid'];
// $id=24;
$family_model=M('Family_files');
$rst=$family_model->find($id);
$rst['avatar']="http://".$_SERVER['SERVER_NAME']."/data/upload/avatar/". $rst['avatar'];
// dump($rst);
echo json_encode($rst);
}
```