<?php
exit('exit');

/**
 * @author solar
 * @todo 批量处理产品备案
 */
require_once ('config.php');
$flagFile = APPLICATION_PATH . '/../data/log/batchProductRecord.lock';
if (@file_exists($flagFile)) {
    echo 'Anather process is running.'."\r\n";
    echo $flagFile."\r\n";
    exit();
}
$link = fopen($flagFile, 'wb');
fclose($link);
define('RUNTIME', '[' . date('Y-m-d H:i:s') . '] ');
echo RUNTIME . "Starting.\r\n\r\n";

/*$hemRow = Service_HsElementMap::getByField(4620);
var_dump($hemRow, trim($hemRow['hem_detail']), trim($hemRow['hem_detail'],chr(194).chr(160)), ord(substr($hemRow['hem_detail'], -2, 1)));
exit('exit');*/

try {
	//$sql = "select product_id from product as p where p.customer_code='E0193' and p.hs_code IN('8523511000','8471900090','8471800000','8473309000');";
	//$sql = "select product_id from product as p where p.customer_code='E0193' and p.product_id IN(328,392,442,375);";
	//$sql = "SELECT * FROM `product` WHERE `customer_code`='E0217' AND `product_status`=2";
	//$sql = "SELECT * FROM `product` WHERE `customer_code` = 'E0216' AND hs_code = '8504409990' AND product_status =2";
	$sql = "select product_id from product as p where p.product_sku IN('YL1161402','YL3095514','YL2086301') AND p.product_status =0;";
	$list = Service_Product::getModelInstance()->getAdapter()->fetchAll($sql);
	foreach($list as $row) {
		$result = Service_Product::handleRecord($row['product_id']);
		echo '产品['.$row['product_id'].']处理成功'."\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);
