<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Administrator
 * Date: 17-6-12
 * Time: 上午9:21
 * To change this template use File | Settings | File Templates.
 */
set_time_limit(7200);
require_once ('config.php');
$flagFile = APPLICATION_PATH . '/../data/log/zcProductBeianCheck.lock';
if (@file_exists($flagFile)) {
    echo 'Another process is running.'."\r\n";
    echo $flagFile."\r\n";
    exit();
}
echo RUNTIME . "Starting.\r\n\r\n";
try {
    $counts = Service_ProductGoods::getByCondition(array('zzc_status_lt'=>'-1','zzc_status_neq'=>2),'count(*)');
    $pageSize = 20;
    if($counts>0){
        $cmblApi=new Service_CMBLApiProcess();

        $pages = ceil($counts/$pageSize);
        for($page=1;$page<=$pages;$page++){
            $goodsList = Service_ProductGoods::getByCondition(array('zzc_status_lt'=>'-1','zzc_status_neq'=>2),'*',$pageSize,$page,'pg_id desc');
            foreach($goodsList as $goodsRow){
                //beian($goodsRow);
                $cmblApi->checkzcbeianStatus($goodsRow);
            }
        }
    }
    echo '[' . date('Y-m-d H:i:s') . ']'."备案更新状态全部处理完成"."\r\n";
} catch (Exception $e) {
    @unlink($flagFile);
    echo '[' . date('Y-m-d H:i:s') . '] Fail Exception:' . $e->getMessage() ."\r\n";
}

echo "\r\n[" . date('Y-m-d H:i:s') . "] End run\r\n";
@unlink($flagFile);