<?php
|
/**
|
* 用户信息类
|
*/
|
|
class Api_Data extends PhalApi_Api {
|
|
public function getRules() {
|
return array(
|
'upload' => array(
|
'data' => array('name' => 'data', 'type' => 'string' ,'require' => false, 'source' => 'post', 'desc' => '上传数据'),
|
'data_1' => array('name' => 'data_1', 'type' => 'array' ,'require' => false, 'source' => 'post', 'desc' => '上传数据'),
|
),
|
'originalUpload' => array(
|
'data' => array('name' => 'data', 'type' => 'string' ,'require' => false, 'source' => 'post', 'desc' => '上传数据'),
|
'data_1' => array('name' => 'data_1', 'type' => 'array' ,'require' => false, 'source' => 'post', 'desc' => '上传数据'),
|
'user_id' => array(
|
'name' => 'user_id', 'type' => 'string', 'require' => true, 'desc' => '用户id'
|
),
|
'time' => array(
|
'name' => 'time', 'type' => 'string', 'require' => true, 'desc' => '时间'
|
),
|
|
),
|
'getUserDataList' => array(
|
'user_id' => array(
|
'name' => 'user_id', 'type' => 'string', 'require' => true, 'desc' => '用户id'
|
),
|
'start_time' => array(
|
'name' => 'start_time', 'type' => 'string', 'require' => true, 'desc' => '开始时间'
|
),
|
'end_time' => array(
|
'name' => 'end_time', 'type' => 'string', 'require' => true, 'desc' => '结束时间'
|
)
|
),
|
|
);
|
}
|
|
/**
|
* 上传数据
|
* @desc 用于上传用户辐射数据
|
* @return bool code 操作码,0表示注册成功, 1表示注册
|
* @return string msg 返回提示
|
*/
|
public function upload(){
|
$rs = array('code' => 0, 'msg' => '');
|
$data_service = new Domain_Data();
|
|
if(!empty($this->data)){
|
$data = json_decode($this->data,true);
|
}
|
else{
|
$data = $this->data_1;
|
}
|
//$data = json_decode($this->data, true);
|
//print_r(count($data['data']));die();
|
//if(json_last_error() == JSON_ERROR_NONE){
|
|
if(count($data) > 0){
|
|
$data_service->upload($data);
|
$rs['msg'] = "数据上报成功";
|
}
|
// }
|
// else{
|
// $rs['code'] = 1;
|
// $rs['msg'] = "json格式异常";
|
// }
|
return $rs;
|
}
|
|
/**
|
* 原始数据上传
|
* @return [type] [description]
|
*/
|
public function originalUpload(){
|
$rs = array('code' => 0, 'msg' => '');
|
$data_service = new Domain_Data();
|
if($data_service->originalUpload($this))
|
$rs['msg'] = "原始数据上报成功";
|
else
|
$rs['msg'] = "原始数据上报失败";
|
return $rs;
|
}
|
|
/**
|
* 获取数据
|
* @desc 获取数据
|
* @return string user_id 用户id
|
* @return string start_time 起始时间
|
* @return string end_time 结束时间
|
*/
|
public function getUserDataList(){
|
$rs = array('code' => 0, 'msg' => '', 'info' => array());
|
$data_daily_service = new Domain_DataDaily();
|
if($this->start_time == $this->end_time || $data_daily_service->checkTime($this->start_time, $this->end_time)){
|
$result = $data_daily_service->getUserDataList($this->user_id, $this->start_time, $this->end_time);
|
if($result){
|
$res_avg = $data_daily_service->getUserDataAvg($this->user_id, $this->start_time, $this->end_time);
|
if($res_avg < 0.16){
|
$res_status = '绝对安全';
|
}
|
elseif($res_avg >= 0.16 && $res_avg < 0.8){
|
$res_status = '建议回避';
|
}
|
elseif($res_avg >= 0.8 && $res_avg < 2){
|
$res_status = '及时闪躲';
|
}
|
else{
|
$res_status = '紧急撤离';
|
}
|
$rs['msg'] = '数据获取成功';
|
$rs['info'] = array('data' => $result, 'avg' => $res_avg, 'status' => $res_status);
|
}
|
else{
|
$rs['msg'] = '没有数据';
|
$rs['info'] = array('data' => array(), 'avg' => 0, 'status' => '安全');
|
}
|
}
|
else{
|
$rs['code'] = 1;
|
$rs['msg'] = '开始时间必须小于结束时间或两者时间间隔必须大于等于7天';
|
}
|
return $rs;
|
}
|
|
//public function updateTime(){
|
// $data_service = new Domain_Data();
|
// $datas = $data_service->getList();
|
// foreach ($datas as $value) {
|
// $data['_id'] = $value['_id'];
|
// $data['date'] = date('Y-m-d', strtotime($value['create_time']));
|
// $data_service->updateTime($data);
|
// }
|
|
// }
|
|
|
|
|
}
|