From 74adf3a72663f151dc2c1b87ecb4ea4b0e080a50 Mon Sep 17 00:00:00 2001
From: colly_wyx <wangyixiong_007@163.com>
Date: Fri, 27 Apr 2018 16:21:52 +0800
Subject: [PATCH] 优化

---
 Yfs/Domain/Data.php |   46 +++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 41 insertions(+), 5 deletions(-)

diff --git a/Yfs/Domain/Data.php b/Yfs/Domain/Data.php
index bed4e47..8237215 100644
--- a/Yfs/Domain/Data.php
+++ b/Yfs/Domain/Data.php
@@ -9,6 +9,8 @@
        $this->model = new Model_Data();
        $this->hourly_model = new Model_DataHourly();
        $this->warn_model = new Model_DataWarn();
+       $this->task_model = new Model_Task();
+       $this->data_original_model = new Model_DataOriginal();
     }
 
     /**
@@ -22,17 +24,37 @@
         $arr['lat'] = $data['lat'];
         $arr['address'] = $data['address'];
         foreach ($data['data'] as $value) {
-            $arr['value'] = $value['value'];
+
+            $arr['value'] = (float)$value['value'];
             $arr['create_time'] = $value['time'];
             $arr['date'] = date('Y-m-d', strtotime($value['time']));
-            if($data['type'] == 0){
+            if($value['type'] == 0){
                 $this->model->add($arr);
-                if($arr['is_warn'] == 1){
+                if($value['is_warn'] == 1){
                     $this->warn_model->add($arr);
                 }
             }
-            elseif($data['type'] == 1){
-                $this->hourly_model->add($arr);
+            elseif($value['type'] == 1){
+
+                $arr['hour'] = date('H', strtotime($value['time']));
+                $hourly = $this->hourly_model->get(array('hour' => $arr['hour'], 'date' => $arr['date'], 'user_id' => $arr['user_id']));
+
+                if($hourly){
+                    $_id = $hourly['_id'];
+                    //������������������
+                    $hourly = $arr;
+                    $this->hourly_model->update($hourly, array('_id' => $_id));
+                }
+                else{
+                    $this->hourly_model->add($arr);
+                }
+                $task_arr = array();
+                $task_date = $this->task_model->get(array('date' => $arr['date']));
+                if(!$task_date){
+                   $task_arr['date'] = $arr['date'];
+                   $this->task_model->add($task_arr); 
+                }
+                
             }
             if(isset($arr['_id']))
                 unset($arr['_id']);
@@ -43,6 +65,20 @@
 
     }
 
+    /**
+     * ������������������������
+     * @return [type] [description]
+     */
+    public function originalUpload($data){
+        $arr = array();
+        $arr['data'] = $data['data'];
+        $arr['time'] = $data['time'];
+        $arr['create_time'] = date('Y-m-d H:i:s');   
+        $this->data_original_model->add($arr);
+        return true;
+    }
+
+
     public function getList(){
         return $this->model->getList();
     }

--
Gitblit v1.8.0