<?php

/**
 * 店铺月销量统计
 * 执行时间：每隔1天执行一次
 */
define("APPLICATION_PATH", realpath(dirname(__FILE__) . '/../../../')); //指向public的上一级
require APPLICATION_PATH . '/scripts/crontab/common.php';
$pageIndex = \Our\PageConst::taskPageBegin;
$pageSize = \Our\PageConst::taskPageSize;
do{
    $limit = array($pageIndex * $pageSize, $pageSize);
    $data = \DAO\Order\OrderModel::getInstance()->getCounts('payment_time >= '.(time()-30*24*60*60),'count(order_id) as num,store_id','store_id',$limit);
//$data = \DAO\Order\OrderModel::getInstance()->getCounts('payment_time >= 1518303150','store_id,count(order_id) as num','store_id');
    if($data){
        foreach ($data as &$v){
            $v['updatetime'] = time();
        }
        \DAO\StoreMonthSalesModel::getInstance()->insertAllOrUpdate($data);
    }
    $pageIndex++;
}while(!empty($data));

