<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%option explicit%>
<!--#include file="../Conn.asp"-->
<!--#include file="../HSK_Cls/HSK.MemberCls.asp"-->
<%
Dim KSCls
Set KSCls = New ExpressDetailCls
KSCls.Run()
Set KSCls = Nothing

Class ExpressDetailCls
	Private ComeUrl,Action,LoginTF
	Private KS,KSUser,RS,I,ID
	Private Price(1),Price1,Price2,Price3,Price4
	Private Point(1),Point1,Point2,Point3,Point4
	Private Sub Class_Initialize()
		Set KS=New PublicCls
		Set KSUser = New UserCls
		'以下为结算方式扣余额价格，可自行修改，如要免费请填写0
		Price1 = 0			'已扫描单号，凭任务编号领取价格，默认0是免费
		Price2 = 0.5		'已扫描单号，单独购买价格，默认是0.5元/条
		Price3 = 0.5		'未扫描单号，凭任务编号领取价格，默认是0.5元/条
		Price4 = 1			'未扫描单号，单独购买价格，默认是1元/条
		
		'以下为结算方式扣发布点，可自行修改，如要免费请填写0
		Point1 = 0			'已扫描单号，凭任务编号领取扣发布点，默认0是免费
		Point2 = 1			'已扫描单号，单独购买扣发布点，默认是扣1点/条
		Point3 = 1			'未扫描单号，凭任务编号领取扣发布点，默认扣1点/条
		Point4 = 2			'未扫描单号，单独购买扣发布点，默认是2点/条
	End Sub
	Private Sub Class_Terminate()
		Set KS=Nothing
		Set KSUser=Nothing
		Call CloseConn()
	End Sub

	Public Sub Run()
		ComeUrl=Request.ServerVariables("HTTP_REFERER")
		LoginTF=Cbool(KSUser.UserLoginChecked)
		IF LoginTF=false  Then
		  GCls.ComeUrl=ComeUrl	'GCls.GetUrl()
		  Response.Redirect("/user/login/")
		  Exit Sub
		End If
		
IF KS.CheckOuterUrl()=False Then
	ID=KS.ChkClng(KS.S("ID"))
	IF ID<>0 Then
		If KS.S("N") = "1" Then
			Call DoSucceed()
			Exit Sub
		End If
		If KS.S("Action")="Buy" Then
			Call DoBuy()
			Exit Sub
		ElseIf KS.S("Action")="Succeed" Then
			Call DoSucceed()
			Exit Sub
		End If
		
		Set RS=Server.CreateObject("ADODB.RECORDSET")
		RS.Open "Select Top 1 * From Express Where Status=0 And ID="& ID,Conn,1,1
		If Not RS.Eof Then
			If DateDiff("s", Now, RS("ScanDate")) < 0 Then
				Price(0) = Price1
				Price(1) = Price2
				Point(0) = Point1
				Point(1) = Point2
			Else
				Price(0) = Price3
				Price(1) = Price4
				Point(0) = Point3
				Point(1) = Point4
			End If
%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>快递单详细浏览</title>
<script src="../HSK_JS/jquery.js" type="text/javascript"></script>
<style type="text/css">
body {background:#ffffff; color:#106899; font:12px/20px Arial,Verdana,Tahoma,"宋体";margin:0 auto;}
*{padding:0px;margin:0px;}
.clear{	clear: both;height:0px;display:block;*display:inline;}
a{text-decoration:none;color:#20537A;}
a:hover{text-decoration:underline;}
.orange,.orange a{color:#FF5500;}
.center_tbl td {border-bottom:1px solid #E5F5FF; line-height:34px; height:35px; clear:both; background-color:#FFF}
.center_tbl tr:hover td{background-color:#EBF5FF}
</style>
</head>
<body>
<script language="javascript">
function getRV(b){var d="";var a=document.getElementsByName(b);for(var c=0;c<a.length;c++){if(a[c].checked){d=a[c].value}}return d}
function ChkForm(){
	if (getRV('getType')=='1'){
		if($('#TaskID').val()==''){
			alert('请输入任务编号!');
			$('#TaskID').focus();
			return false;
		}
	}
}
</script>
<table  width="100%" border="0" align="center" cellpadding="1" cellspacing="1">
  <tr>
  	<td align="center" bgcolor="#FFFEDF" style="height:30px; line-height:30px; color:red; font-weight:bold; border:1px solid #FC3;">
    好消息！凡是在平台发布实物任务，均可凭任务编号领取真实快递单号！<br />
	如果没有发布任务只想单独购买快递单也可以！欢迎选购！</td>
  </tr>
</table>
  
<table  width="100%" border="0" align="center" cellpadding="1" cellspacing="1" class="center_tbl">
 <form id="form1" name="form1" method="post" action="?ID=<%=ID%>&Action=Buy" onSubmit="return ChkForm()">
 <tr class="tdbg">
  <td width="28%" height="35" align="right" class="clefttitle"><strong><span>快递单号：</span></strong></td>
  <td width="72%">&nbsp;<strong><%=Left(RS("KuaiDiNum"),4) & "********"%></strong> &nbsp; [购买后显示完整单号]</td>
 </tr>
  <tr class="tdbg" height="35">
  	<td align="right" class="clefttitle"><strong>领取结算方式：</strong></td>
    <td>&nbsp;<label for="PayType" class="orange"><input name="PayType" type="radio" id="PayType" value="1" checked="checked" /> 扣账户余额</label>&nbsp; &nbsp;价格：凭任务编号领取价格是：<strong class="orange">￥<%=KS.GetN(Price(0), 2)%></strong> 元 &nbsp; &nbsp; 单独购买价格是：<strong class="orange">￥<%=KS.GetN(Price(1), 2)%></strong> 元<br>
    &nbsp;<label for="PayType2" class="orange"><input type="radio" name="PayType" id="PayType2" value="2" /> 扣账户发布点</label>&nbsp; &nbsp;价格：凭任务编号领取发布点是：<strong class="orange"><%=KS.GetN(Point(0), 2)%> </strong>点 &nbsp; &nbsp; 单独购买发布点是：<strong class="orange"><%=KS.GetN(Point(1), 2)%> </strong>点
    </td>
  </tr>
  <tr class="tdbg" height="35">
  	<td align="right" class="clefttitle"><strong>选择领取方式：</strong></td>
    <td>&nbsp;<label for="getType"><input name="getType" type="radio" id="getType" value="1" checked="checked" onClick="tasktr.style.display='block'" /> 我有任务编号</label>
    <label for="getType2"><input type="radio" name="getType" id="getType2" value="2" onClick="tasktr.style.display='none'" /> 我要单独购买</label>
    </td>
  </tr>
  <tr class="tdbg" height="35" id="tasktr">
  	<td align="right" class="clefttitle"><strong>输入任务编号：</strong></td>
    <td>&nbsp;<input name='TaskID' value='' type='text' id='TaskID' class='textbox' maxlength="20" /> 
      <span style="color:red;">注：一个编号只可以领取一次</span></td>
  </tr>
  <tr>
  	<td colspan="2" align="center" bgcolor="#EEF1F1" style="height:60px; line-height:60px;"><input type="image" name="Save" src="/style/images/ConfirmButton.gif" /></td>
  </tr>
  </form>
</table>
</body>
</html>
<%
		RS.Close
		Set RS = Nothing
	Else
		KS.Die "<script language=""Javascript"">alert('抱歉！你下手太慢了，该单号已经被别人领走了！');parent.location.reload();parent.closeWindow();</script>"
	End If
End If
Else
	KS.AlertHistory "请不要非法提交，谢谢！","-1"	
End If
End Sub

Sub DoBuy()
Dim RS, GetType, TaskID, Money, PayType
TaskID = KS.CheckXSS(KS.S("TaskID"))
GetType = KS.ChkClng(KS.S("GetType"))
PayType = KS.ChkClng(KS.S("PayType"))
If GetType = 1 Then
	If KS.IsNul(TaskID) Then
		KS.AlertHistory "抱歉！请先填写任务编号再提交，要么选择单独购买单号！","-1"
	End If
	If Conn.Execute("Select Top 1 ID From KS_U_sxyrw Where Inputer='" & KSUser.UserName & "' And KS_TaskID = '" & TaskID & "'").Eof Then
		KS.AlertHistory "抱歉！该任务编号不存在或不是你所发布的，请返回核实再试！","-1"
	End If
	If Not Conn.Execute("Select Top 1 ID From KS_U_sxyrw Where KS_XuShiTF = 0 And KS_TaskID = '" & TaskID & "'").Eof Then
		KS.AlertHistory "抱歉！虚拟任务不可以领取快递单号，请返回核实再试！","-1"
	End If
	If Not Conn.Execute("Select Top 1 ID From Express Where TaskID = '" & TaskID & "'").Eof Then
		KS.AlertHistory "抱歉！该任务编号已经领取过了！","-1"
	End If
End If

	Set RS=Server.CreateObject("ADODB.RECORDSET")
	RS.Open "Select Top 1 * From Express Where Status=0 And ID=" & ID,Conn,1,3
	If Not RS.Eof Then
		If DateDiff("s", Now, RS("ScanDate")) < 0 Then
			Price(0) = Price1
			Price(1) = Price2
			Point(0) = Point1
			Point(1) = Point2
		Else
			Price(0) = Price3
			Price(1) = Price4
			Point(0) = Point3
			Point(1) = Point4
		End If
		
		If PayType = 1 Then
			If GetType = 1 Then Money = Price(0) Else Money = Price(1)
			If Round(Money, 2) > Round(KSUser.GetUserInfo("Money"),2) Then
				RS.Close
				Set RS = Nothing
				KS.AlertHistory "抱歉！您的账户余额不足，请充值后再来订购，或选择扣发布点方式结算！","-1"
			End If
		Else
			If GetType = 1 Then Money = Point(0) Else Money = Point(1)
			If Round(Money, 2) > Round(KSUser.GetUserInfo("Point"),2) Then
				RS.Close
				Set RS = Nothing
				KS.AlertHistory "抱歉！您的账户发布点不足，请先购买发布点后再来订购，或选择扣余额方式结算！","-1"
			End If
		End If

		RS("Status") = 1
		RS("BuyUserName") = KSUser.UserName
		If GetType = 1 Then RS("TaskID") = TaskID
		RS("BuyDate") = Now()
		RS("IP") = KS.GetIP()
		RS.Update
		If PayType = 1 Then
			If Round(Money, 2) > 0 Then
				Call KS.MoneyInOrOut(KSUser.UserName,KSUser.GetUserInfo("RealName"),Money,4,2,now,0,"系统","领取一条真实快递单！",0,0,1)
			End If
		Else
			If Round(Money, 2) > 0 Then
				Call KS.PointInOrOut(0,0,KSUser.UserName,2,Round(Money,2),"系统","领取一条真实快递单！",0)
			End If
		End If
	
		Dim Content: Content="快递公司：" & RS("ComName") & "<br>"
			Content = Content & "快递单号：" & RS("KuaiDiNum") & "<br>"
			Content = Content & "发货地：" & RS("CFCity") & "<br>"
			Content = Content & "收货地：" & RS("MDCity") & "<br>"
			Content = Content & "收货人：" & RS("SHUserName") & "<br>"
			Content = Content & "联系电话：" & RS("Mobile") & "<br>"
			Content = Content & "预计扫描时间：" & RS("ScanDate") & "<br>"
			Content = Content & "领取时间：" & RS("BuyDate") & "<br>"
		RS.Close
		Set RS = Nothing
		Call KSUser.AddLog(KSUser.UserName,"领取一条真实快递单！",1)
		Call KS.SendInfo(KSUser.UserName,"System","恭喜您成功领取一条真实快递单","快递单信息如下：<br>" & Content)
		KS.Alert "恭喜！领取成功！\n\n同时购买单号信息已发送到你的站内信箱，请注意查收！\n\n点击确定按钮后显示完整单号信息，请复制保存好！","?ID=" & ID & "&Action=Succeed"
	Else
		KS.AlertHistory "抱歉！你下手太慢了，该单号已经被别人领走了！","-1"
	End If

End Sub


Sub DoSucceed()
	Set RS=Server.CreateObject("ADODB.RECORDSET")
	RS.Open "Select Top 1 * From Express Where BuyUserName = '" & KSUser.UserName & "' And Status=1 And ID="& ID,Conn,1,1
	If Not RS.Eof Then
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>快递单详细浏览</title>
<script src="../HSK_JS/jquery.js" type="text/javascript"></script>
<style type="text/css">
body {background:#ffffff; color:#106899; font:12px/20px Arial,Verdana,Tahoma,"宋体";margin:0 auto;}
*{padding:0px;margin:0px;}
.button{cursor: pointer;height:23px;border:1px solid #cccccc;background:url(/style/images/button/button_bg.gif) left repeat-x;}
</style>
</head>
<body>
<script language="javascript">
//复制内容进剪贴板
function copyToClipboard(txt,msg) {
	  if(window.clipboardData) {
			  window.clipboardData.clearData();		
			  window.clipboardData.setData("Text", txt);		
	  } else if (window.netscape) {		
		   try {		
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");		
		   } catch (e) {		
				alert("被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将 'signed.applets.codebase_principal_support'设置为'true'");		
		   }		
		   var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);		
		   if (!clip)		
				return;		
		   var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);		
		   if (!trans)		
				return;		
		   trans.addDataFlavor('text/unicode');		
		   var str = new Object();		
		   var len = new Object();		
		   var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);		
		   var copytext = txt;		
		   str.data = copytext;		
		   trans.setTransferData("text/unicode",str,copytext.length*2);		
		   var clipid = Components.interfaces.nsIClipboard;		
		   if (!clip)		
				return false;		
		   clip.setData(trans,null,clipid.kGlobalClipboard);
	  } else {	
			alert('抱歉！该浏览器(非IE内核)不支持复制，请用鼠标选中账号右键复制！');
			return;	
	  }			  
	  msg = (typeof(msg)=="undefined")?'复制成功！':msg;		
	  alert(msg);	
 }
</script>
<table  width="100%" border="0" align="center" cellpadding="1" cellspacing="1">
  <tr>
  	<td align="center" bgcolor="#FFFEDF" style="height:30px; line-height:30px; color:red; font-weight:bold; border:1px solid #FC3;">
    好消息！凡是在平台发布实物任务，均可凭任务编号领取真实快递单号！<br />
	如果没有发布任务只想单独购买快递单也可以！欢迎选购！</td>
  </tr>
</table>
<table  width="100%" border="0" align="center" cellpadding="1" cellspacing="1">
  <tr>
  	<td align="center" bgcolor="#E8F8FF" style="height:30px; line-height:30px; color:blue;"><%
	If Not KS.IsNul(RS("TaskID")) Then
		KS.Echo "以下快递单信息是你凭任务编号：<strong>" & RS("TaskID") & "</strong> 领取的，请复制保存好！"
	Else
		KS.Echo "以下快递单信息是你花了大洋购买所得，请复制保存好！"
	End If %></td>
  </tr>
</table>
<table  width="100%" border="0" align="center" cellpadding="1" cellspacing="1" class="center_tbl">
  <tr class="tdbg">
    <td align="center" class="clefttitle"><textarea name="Content" id="Content" cols="50" rows="9"><%
	KS.Echo "快递公司：" & RS("ComName") & vbCrlf
	KS.Echo "快递单号：" & RS("KuaiDiNum") & vbCrlf
	KS.Echo "发货地：" & RS("CFCity") & vbCrlf
	KS.Echo "收货地：" & RS("MDCity") & vbCrlf
	KS.Echo "收货人：" & RS("SHUserName") & vbCrlf
	KS.Echo "联系电话：" & RS("Mobile") & vbCrlf
	KS.Echo "预计扫描时间：" & RS("ScanDate") & vbCrlf
	KS.Echo "领取时间：" & RS("BuyDate")
	%></textarea> &nbsp;<input type="submit" name="bt" id="bt" class="button" value=" 复制内容 " onClick="copyToClipboard($('#Content').val(),'快递单号信息复制成功！')" />
    </td>
  </tr>
  <tr>
  	<td align="center" style="height:50px; line-height:50px;"><input type="image" name="Save" src="/style/images/CloseButton.gif" onClick="parent.closeWindow();" /></td>
  </tr>
</table>
</body>
</html>
<%
		RS.Close
		Set RS = Nothing
	Else
		KS.AlertHistory "抱歉！该单号不存在或已被删除了！","-1"
	End If
End Sub

End Class
%>