| | |
| | | } |
| | | |
| | | /** |
| | | * 聚合 |
| | | * @param [type] $colName [description] |
| | | * @param [type] $params [description] |
| | | * @return [type] [description] |
| | | */ |
| | | public function aggregate($colName, $params){ |
| | | $col = $this->_getCol($colName); |
| | | // 自动处理 '_id' 字段 |
| | | //$query = $this->_parseId($query); |
| | | $result = $col->aggregate($params); |
| | | |
| | | return $result['result']; |
| | | } |
| | | |
| | | /** |
| | | * 统计文档记录数 |
| | | * |
| | | * @param string $colName 集合名 |
| | |
| | | 'upload' => array( |
| | | 'data' => array('name' => 'data', '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' => '结束时间' |
| | | ) |
| | | ), |
| | | |
| | | ); |
| | | } |
| | | |
| | |
| | | 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_service = new Domain_Data(); |
| | | $data_list = $data_service->getUserDataList($this->user_id, $this->start_time, $this->end_time); |
| | | if($data_list){ |
| | | $rs['msg'] = '数据获取成功'; |
| | | $rs['info'] = $data_list; |
| | | } |
| | | else{print_r($data_lsit); |
| | | $rs['code'] = 1; |
| | | $rs['msg'] = '数据获取失败'; |
| | | } |
| | | return $rs; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | |
| | | if($result == 0){ |
| | | $user_service = new Domain_User(); |
| | | $result = $user_service->resetPwd($this->phone, $this->password); |
| | | if($reslt == 0){ |
| | | if($result == 0){ |
| | | $rs['msg'] = '密码重置成功'; |
| | | } |
| | | elseif($result == 1){ |
| | |
| | | foreach ($data['data'] as $value) { |
| | | $arr['value'] = $value['value']; |
| | | $arr['create_time'] = $value['time']; |
| | | $arr['date'] = date('Y-m-d', strtotime($value)); |
| | | $this->model->add($arr); |
| | | if(isset($arr['_id'])) |
| | | unset($arr['_id']); |
| | |
| | | |
| | | } |
| | | |
| | | public function getList(){ |
| | | return $this->model->getList(); |
| | | } |
| | | |
| | | /** |
| | | * 获取用户某个时间段内的数据 |
| | | * @param [type] $user_id [description] |
| | | * @param [type] $start_time [description] |
| | | * @param [type] $end_time [description] |
| | | * @return [type] [description] |
| | | */ |
| | | public function getUserDataList($user_id, $start_time, $end_time){ |
| | | $result = $this->model->aggregate( |
| | | array( |
| | | array( |
| | | '$match' => array('create_time' => array('$gte' => $start_time.' 00:00:00', '$lte' => $end_time.' 23:59:59'), 'user_id' => $user_id) |
| | | ), |
| | | array( |
| | | '$group' => array('_id' => '$date', 'day' => array('$avg' => '$value')) |
| | | ), |
| | | array( |
| | | '$project' => array('_id' => 0, 'date'=> '$_id', 'day' => 1) |
| | | ) |
| | | ) |
| | | ); |
| | | |
| | | print_r($result); |
| | | die(); |
| | | return $this->model->getList(array('user_id' => $user_id, 'create_time' => array('$gte' => $start_time, '$lte' => $end_time))); |
| | | } |
| | | |
| | | |
| | | public function updateTime($data){ |
| | | $id = $data['_id']; |
| | | unset($data['_id']); |
| | | return $this->model->update($data, array('_id' => $id)); |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | |
| | | return $this->db->update($this->table, $data, $query); |
| | | } |
| | | |
| | | public function aggregate($params){ |
| | | return $this->db->aggregate($this->table, $params); |
| | | } |
| | | } |