Skip to content

Instantly share code, notes, and snippets.

@mimosz
Created September 22, 2011 08:48
Show Gist options
  • Save mimosz/1234367 to your computer and use it in GitHub Desktop.
Save mimosz/1234367 to your computer and use it in GitHub Desktop.
同步
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>库存更新结果</title>
<link href="../css/base.css" type="text/css" rel="stylesheet">
<style type="text/css">
body {
background: url('../images/allbg.gif');
margin: 8px;
}
table {
background: #666666;
width: 90%;
text-align: center;
border-collapse: separate;
border-spacing: 2px;
}
table td, table th {
padding: 1;
}
</style>
</head>
<body>
<?php
error_reporting(E_ALL ^ E_NOTICE);
set_time_limit(0);
define("CUR_PATH",dirname(__FILE__)."/");
include_once CUR_PATH."../../include/AdminApi/AdminApi.php";
$adminApi = new AdminApi(CUR_PATH."../../include/",false);
switch (true){
case !$adminApi->check():
echo "<script>top.location.href='../login.php';</script>\n</body>\n</html>";
exit();
case $adminApi->getPermit("00040003") <= 0:
echo "<script>alert('您的权限不足,操作失败');location.href='../welcome.php';</script></body></html>";
exit();
default:
$num = trim($_POST["num"]);
$store = $_POST["store"];
include_once CUR_PATH."../../include/SysCommon/Global.php";
include_once CUR_PATH."../../include/TaoBaoApi/TopSdk.php";
$client = new TopClient();
$client->appkey = WSM_APPKEY;
$client->secretKey = WSM_APPSECRET;
}
?>
<?php
if (isset($store)){
?>
<table>
<caption>库存更新结果</caption>
<thead>
<tr>
<th>商家编码</th>
<th>原库存</th>
<th>新库存</th>
</tr>
</thead>
<tbody>
<?php
while(list($key,$val) = each($store)){
$skuid = trim($key);
if($key == ""){
echo "<!-- 沒有鍵值 -->";
continue;
}else{
echo "<tr>\n";
echo "<td>".$key."</td>\n";
$quantity = $val - $num;
$quantity = $quantity < 0 ? 0 : $quantity;
$req = new SkusCustomGetRequest();
$req->setOuterId($skuid);
$req->setFields("num_iid,quantity,sku_id");
$time_start = microtime(true);
echo "<!-- 接口調用 ".$time_start." 開始 -->";
$result = $client->execute($req);
$time_end = microtime(true);
$time = $time_end - $time_start;
echo "<!-- 接口調用".$time_end."结束, ".$time." -->";
echo "<td>".$result->skus->sku->quantity."</td>\n"
$num_iid = $result->skus->sku->num_iid;
$sku_id = $result->skus->sku->sku_id;
$req = new ItemQuantityUpdateRequest();
$req->setNumIid($num_iid);
$req->setOuterId($skuid);
$req->setQuantity($quantity);
$req->setType(1);
$time_start = microtime(true);
echo "<!-- 接口調用 ".$time_start." 開始 -->";
$result = $client->execute($req);
$time_end = microtime(true);
$time = $time_end - $time_start;
echo "<!-- 接口調用".$time_end."结束, ".$time." -->";
for($i=0;$i<sizeof($result->item->skus->sku);$i++){
if(strval($result->item->skus->sku[$i]->sku_id) == $sku_id){
echo "<td>".$result->item->skus->sku[$i]->quantity."</td>\n";
break;
}
}
echo "</tr>\n";
}
}
?>
</tbody>
</table>
<?php } ?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment