<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Administrator
 * Date: 17-6-8
 * Time: 上午11:23
 * To change this template use File | Settings | File Templates.
 */
set_time_limit(7200);
require_once ('config.php');
$flagFile = APPLICATION_PATH . '/../data/log/zhangceProductBeian.lock';
if (@file_exists($flagFile)) {
    echo 'Another process is running.'."\r\n";
    echo $flagFile."\r\n";
    exit();
}

//$Account = array('E0882','E0870','E0861','E0874','E0907','E0884','E0859','E0852','E0853','E0855','E0449','E0856','E0238','E0309','E0876','E0213','E0860','E0220','E0725','E0337','E0863','E0857','E0880','E0891','E0866','E0622','E0881','E0259','E0555','E0237','E0877','E8888','E0341','E0879','E0885','E0893','E0589','E0838','E0912','E0811','E0869','E0728','E0225',);
define('RUNTIME', '[' . date('Y-m-d H:i:s') . '] ');
echo RUNTIME . "Starting.\r\n\r\n";

try {
    $counts = Service_ProductGoods::getProductByCondition(array('zzc_status'=>'-1','customer_platform'=>'oms','pg_status_neq'=>1),'count(*)');
    $pageSize = 20;
    if($counts>0){
        $cmblApi=new Service_CMBLApiProcess();

        $pages = ceil($counts/$pageSize);
        for($page=1;$page<=$pages;$page++){
            $goodsList = Service_ProductGoods::getProductByCondition(array('zzc_status'=>'-1','customer_platform'=>'oms','pg_status_neq'=>1),'product_goods.*',$pageSize,$page,'product_goods.product_id desc');
            foreach($goodsList as $goodsRow){
                //beian($goodsRow);
                //$product = Service_Product::getByField($goodsRow['product_id'],'product_id');
                /*if (empty($product) || !in_array($product['customer_code'], $Account)) {
                    echo "非电商账号账号的单[" . $sendRow['refercence_no'] . "]，不发送\r\n";
                    continue;
                }else{
                    $cmblApi->zzcBeian($goodsRow);
                }*/
                $cmblApi->zzcBeian($goodsRow);
                //break;
            }
            //break;
        }
    }
} 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);