colly
2017-08-08 0828d06637e9b212877ddcc52f58f5cdc98728ac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
/**
 * 用户业务类
 */
class Domain_DataDaily {
 
    public function __construct(){
        //DI()->redis = new Redis_Lite(DI()->config->get('app.redis.servers'));
       $this->model = new Model_DataDaily();
    }
 
    /**
     * 获取用户某个时间段内的数据
     * @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){
        $start_time = strtotime($start_time);
        $end_time = strtotime($end_time);
        $diff_days = ($end_time - $start_time) / 86400;
        $total_days = $diff_days + 1;//时间段内总天数
        $step = ($total_days - $total_days % 7) / 7;
        $days_arr=  array();
        for($i = 0; $i < 7*$step ; $i+=$step){
            $days_arr[] = date('Y-m-d', strtotime('+'.$i.' day', $start_time));
        }
        $result = $this->model->getList(array('user_id' => $user_id, 'date' => array('$in' => $days_arr)));
        return $result;
    }
 
    /**
     * 验证时间
     * @param  [type] $start_time [description]
     * @param  [type] $end_time   [description]
     * @return [type]             [description]
     */
    public function checkTime($start_time, $end_time){
        $start_time = strtotime($start_time);
        $end_time = strtotime($end_time);
        if($start_time > $end_time){
            return false;
        }
        $diff_days = ($end_time - $start_time) / 86400;
        $total_days = $diff_days + 1;//时间段内总天数
        if($total_days < 7){
            return false;
        }
        return true;
    }
 
    
 
}