From 327df6ae83ee1d3cc61dd4589bf03e2217f40d4d Mon Sep 17 00:00:00 2001
From: colly <576734462@qq.com>
Date: Mon, 07 Aug 2017 15:01:12 +0800
Subject: [PATCH] 修改上传及添加聚合函数

---
 Yfs/Domain/Data.php    |   39 +++++++++++++++++++
 Yfs/Api/User.php       |    2 
 Yfs/Api/Data.php       |   37 ++++++++++++++++++
 Library/Mongo/Lite.php |   15 +++++++
 Yfs/Model/Base.php     |    3 +
 5 files changed, 95 insertions(+), 1 deletions(-)

diff --git a/Library/Mongo/Lite.php b/Library/Mongo/Lite.php
index 9d16b53..243b077 100644
--- a/Library/Mongo/Lite.php
+++ b/Library/Mongo/Lite.php
@@ -374,6 +374,21 @@
     }
 
     /**
+     * ������
+     * @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 ���������
diff --git a/Yfs/Api/Data.php b/Yfs/Api/Data.php
index 05d742f..3ccdf4e 100644
--- a/Yfs/Api/Data.php
+++ b/Yfs/Api/Data.php
@@ -10,6 +10,18 @@
             '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' => '������������'
+                )
+            ),
+
         );
     }
 
@@ -35,4 +47,29 @@
         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;
+    }
+
+
+
+
 }
diff --git a/Yfs/Api/User.php b/Yfs/Api/User.php
index 0fe23f6..1f73228 100644
--- a/Yfs/Api/User.php
+++ b/Yfs/Api/User.php
@@ -156,7 +156,7 @@
         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){
diff --git a/Yfs/Domain/Data.php b/Yfs/Domain/Data.php
index c5851ec..8a447f1 100644
--- a/Yfs/Domain/Data.php
+++ b/Yfs/Domain/Data.php
@@ -22,6 +22,7 @@
         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']);
@@ -32,6 +33,44 @@
 
     }
 
+    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));
+    }
+
     
 
 }
diff --git a/Yfs/Model/Base.php b/Yfs/Model/Base.php
index 58de6e3..c4c6f7d 100644
--- a/Yfs/Model/Base.php
+++ b/Yfs/Model/Base.php
@@ -50,4 +50,7 @@
         return $this->db->update($this->table, $data, $query);
     }
 
+    public function aggregate($params){
+        return $this->db->aggregate($this->table, $params);
+    }
 }

--
Gitblit v1.8.0