<?php
header("Content-Type:text/html;charset=UTF-8");
require("../class/connect.php");
require("../class/db_sql.php");
include_once("TopSdk.php");
$link=db_connect();

$c = new TopClient;
$c->appkey = "21593156";
$c->secretKey = "5e7150469d4282d871cd37599d531506";
$req = new ItemGetRequest;
$req->setFields("num_iid,title,desc,pic_url,price");

$r_pnid=$_GET['pnid']; 

$req->setNumIid($r_pnid);

$result = $c->execute($req, $sessionKey);//得到实例化数组
$t_code=$result->code;
if($t_code==530){
    $r_titleurl = mysql_query("SELECT titleurl FROM  phome_ecms_download WHERE pnid='{$r_pnid}'");
	$r_titurl=mysql_fetch_array($r_titleurl);
	echo '<div style="border-bottom:1px  dotted #CCCCCC; line-height:30px; margin:0 10; width:600px; height:auto; font-size:12px; padding-left:10px">ID = '.$r_pnid.' 已下架或删除  未入库 <a href="'.$r_titurl[titleurl].'" target="_blank">'.$r_titurl[titleurl].'</a> </div>';
  }
  
else{
	$t_ptitle=$result->item->title;//得到标题
	$t_psoftsay=$result->item->desc;//详细介绍
	$t_titlepic=$result->item->pic_url;//得到主图片
	$t_pprice=$result->item->price;//得到价格
	$t_psales=getOrdersSales($r_pnid);//得到销量
	
    $r_psales = mysql_query("SELECT psales FROM  phome_ecms_download WHERE pnid='{$r_pnid}'");
	$r_row=mysql_fetch_array($r_psales);
	if($t_psales>$r_row[psales] ){
	
	mysql_query("UPDATE phome_ecms_download SET titlepic='{$t_titlepic}',psoftsay='{$t_psoftsay}',ptitle='{$t_ptitle}',pprice='{$t_pprice}',psales='{$t_psales}' WHERE pnid='{$r_pnid}'");
	
 	echo '<div style="border-bottom:1px  dotted #CCCCCC; line-height:30px; margin:0 10; width:600px; height:auto; font-size:12px; padding-left:10px">ID = '.$r_pnid.' 原来销量'.$r_row[psales].' 目前销量'.$t_psales.' 已完成入库 </div>';
     }
	  else{
	  echo '<div style="border-bottom:1px  dotted #CCCCCC; line-height:30px; margin:0 10; width:600px; height:auto; font-size:12px; padding-left:10px">ID = '.$r_pnid.' 原来销量'.$r_row[psales].' 目前销量'.$t_psales.' 销量下降 未入库</div>';
	  }
}

db_close();
?>
