<?php
namespace Clue\Lib;

use Dever;
Class Cron
{
	public function stat_api()
	{
		$start=mktime(0,0,0,date('m'),date('d'),date('Y'))-86400;
        $end = $start+86400-1;
        $data = Dever::db('work/branch')->state();
        foreach ($data as $k => $v) {
        	$w['follow_group_id'] = $v['group_id'];
        	$w['start'] = $start;
        	$w['end'] = $end;
        	$where['group_id'] = $v['group_id'];
        	$where['day'] = $start;
        	// $cy = Dever::db('clue/info_log')->getCountAll($w);
        	$info = Dever::db('clue/info')->getAll($w);
        	$create = Dever::db('clue/info')->getAll(array('start'=>$start,'end'=>$end,'create_group_id'=>$v['group_id']));
        	$cinfo = array_merge($info,$create);
        	$rest = array();
        	foreach ($cinfo as $k1 =>$v1) {
        		$rest[$v1['id']]=$v1;
        	}
        	$where['group_num'] = count($rest);
        	$w['type'] = '1,2,3,4,5';
        	$where['num'] = Dever::db('clue/info')->getHAll($w);
        	$w['type'] = 1;
        	$where['d_num'] = Dever::db('clue/info')->getHAll($w);
        	$w['type'] = 2;
        	$where['dg_num'] = Dever::db('clue/info')->getHAll($w);
        	$wh['type'] = 3;
        	$wh['gstart'] = $start;
        	$wh['gend'] = $end;
        	$wh['follow_group_id'] = $v['group_id'];
        	$where['g_num'] = Dever::db('clue/info')->getHAll($w);
        	$w1['follow_group_id'] = $v['group_id'];
        	$w1['fstart'] = $start;
        	$w1['fend'] = $end;
        	$w1['type'] = 5;
        	$where['qx_num'] = Dever::db('clue/info')->getHAll($w1);
        	$w1['type'] = 4;
        	$where['f_num'] = Dever::db('clue/info')->getHAll($w1);
        	$res = Dever::db('clue/info_stat')->find(array('group_id'=>$v['group_id'],'day'=>$start,'clear'=>true));
        	$where['clear'] = true;
        	if ($res) {
        		$where['where_id'] = $res['id'];
        		Dever::db('clue/info_stat')->update($where);
        	} else{
        		Dever::db('clue/info_stat')->insert($where);
        	}
        	// print_R($where);die;
        	// $data[''] = Dever::db('clue/info')->
        }
		
	}
}