<?php
	session_start();	
		
	require_once("db/db.php");	
	require_once("common/common.php");
		
	$strdoid = trim($_REQUEST['doid']);
	$strclistno = trim($_REQUEST['clistno']);

	$intOldCount = 0;
	//1.先读取数据库中的数量
	$sql = sprintf("Select Item_Count From WX_Temp_List Where ListNo=%s",$strclistno);
	$result = querySql($sql);
	
	if($row = fetch_array($result))
	{
		$intOldCount = $row['Item_Count'];
	}
	freeResult($result);	//释放数据库
		
	//2.开始更新数量
	if($strdoid =='1')
	{
		$sql = sprintf("Update WX_Temp_List Set Item_Count = Item_Count + 1 Where ListNo=%s",$strclistno);
		if(executeSql($sql))
		{
			$intOldCount = $intOldCount + 1;
		}
	}
	else
	{
		if($intOldCount>0)
		{
			$sql = sprintf("Update WX_Temp_List Set Item_Count = Item_Count - 1 Where ListNo=%s And Item_Count>0",$strclistno);
			if(executeSql($sql))
			{
				$intOldCount = $intOldCount - 1;
				$sql = sprintf("DELETE FROM WX_Temp_List WHERE ListNo=%s And Item_Count=0",$strclistno);
				executeSql($sql);
			}
		}
	}
	
	if($intOldCount<0)
	{
		$intOldCount = 0;
	}
	
	//得到新数量和金额
	$fltSumValue = 0;
	$intSumCount = 0;
	$strdefcartid = trim($_SESSION["main_defcarttempid"]);
	$strDListNo = trim($_SESSION["main_posChainDListNo"]);	//部门流水号
	$strDListNo = str_replace(',','',$strDListNo);
	
	$sql = sprintf("Select Sum(Item_Count)AS SumCount,Sum(Round(Item_Price * Item_Count,1))AS SumValue From WX_Temp_List Where CartTempID='%s' And DListNo=%s",$strdefcartid,$strDListNo);
	$result = querySql($sql);
	
	if($row = fetch_array($result))
	{
		$intSumCount = $row['SumCount'];
		$fltSumValue = $row['SumValue'];
	}
	freeResult($result);	//释放数据库
	
	//生成输出显示字符串 2*8*256.5
	$strRetText = number_format($intOldCount,0).'*'.number_format($intSumCount,0).'*'.number_format($fltSumValue,1);
	
	echo $strRetText;

	closeDb();		
?>



