<?php
/**
 * Copy Right IJH.CC
 * Each engineer has a duty to keep the code elegant
 * $Id$
 */
if(!defined('__CORE_DIR')){
    exit("Access Denied");
}
class Ctl_Biz_Tongji extends Ctl_Biz
{

    public function money($params)
    {
        $this->check_login();
        $sday = date('Ymd', __TIME);
        $lday = date('Ymd', __TIME - 31*86400);
        $week_day = date('Ymd', __TIME - 8 * 86400);
        $filter = array('shop_id'=>$this->shop_id, 'day'=>$lday.'~'.$sday);
        $today_money = $week_money = $month_money = $total_money = 0;
        $items = array();
        for($i = 0; $i < 30; $i ++ ){
            $day = date('Ymd', __TIME - (30-$i)*86400);
            $date = date('Y-m-d', __TIME - (30-$i)*86400);
            $items[$day] = array('day'=>$day, 'date'=>$date, 'count'=>0, 'money'=>0);
        }
        if($count_list = K::M('order/order')->count_by_day($filter, 1, 31)){
            foreach($count_list as $k=>$v){
                $dmoney = $v['day_money'] + $v['day_amount'] + $v['day_hongbao'];
                if($sday == $v['day']){
                    $today_money = $dmoney;
                }else{
                    if($week_day >= $v['day']){
                        $week_money += $dmoney;
                    }
                    $month_money += $dmoney;
                    $items[$k]['money'] = $dmoney;
                }
            }
        }
        $total_money = $this->shop['total_money'];
        $this->msgbox->set_data('data', array('items'=>array_values($items), 'today_money'=>$today_money, 'week_money'=>$week_money,'month_money'=>$month_money));
    }

    public function order($params)
    {
        
    }

    public function source($params)
    {
        
    }

}