<%
'##################################################################                                                                 
'★         web08.net - 威博购物系统                                              
'★  版权所有: web08.net                                                                                                       
'★  程序制作: 威博网络技术公司                                     
'★           email:web08net@hotmail.com                           
'★            Q Q :645095280,475980829
'★	       电话:021-55520018                                                                                                         
'★  相关网址: [产品介绍] http://www.021web.com.cn/gwxt.html
'★            [支持论坛] http://bbs.web08.net/                                                                                     
'★  主页地址: http://www.web08.net/  
'★		http://www.021web.com.cn/			                                                                 
'###################################################################
%>
<%

function IsAdmin(code)
	
	tmp=split(request.cookies("rank"),",")
	for i=0 to ubound(tmp)
		if cint(tmp(i))=cint(code) then 
			istmp=true
			exit for
		else	
			istmp=false
		end if 
	next
	if  istmp=false then
		response.write "<script LANGUAGE='javascript'>alert('您的操作权限不足!');history.go(-1);</script>"
		response.end
		response.Redirect"/weblogin/err.html"
	end if
End function
'##################################
'#获取版本地址
'##################################
Function getVersion()
	Dim fso
	Set fso = CreateObject("Scripting.FileSystemObject")
	web_Version_path=server.mappath(""&Web_Get_RootDir(Web_C_setupfolder)&"update/update.txt")
	If (fso.FileExists(web_Version_path))=false Then
		getVersion ="文件版本缺失" 
	else
		Set MyFile = fso.OpenTextFile(web_Version_path, 1)
		getVersion = MyFile.ReadLine
	end if
End Function
'##################################
'#不带大图的多图
'##################################
 Function showpicture(morepic,photo,id)
	str="<table width='100%' border='0' cellspacing='0' cellpadding='0'>"
	if morepic<>""  then
		picaddr=split(morepic,"|")
		piclen=ubound(picaddr)
		if piclen>=19 then
			piclen=19
		end if
		for ii=0 to piclen
                 	tmpstr1=tmpstr1&"<a href='"&Web_Get_RootDir(Web_C_setupfolder)&picaddr(ii)&"'  rel=lightbox[plants] ><img src="&Web_Get_RootDir(Web_C_setupfolder)&picaddr(ii)&" width='50' height='50' border='0' alt='点击查看效果'></a>"&"&nbsp;&nbsp;"
			if (ii+1) mod 4=0 then
				tmpstr1=tmpstr1&"<br>"
			end if
		next
	end if
       	if photo<>"" then
             str1=str1&"<tr>"
             str1=str1&"<td height='220' align='left' scope='col'>"
             str1=str1&"<img src='"&Web_Get_RootDir(Web_C_setupfolder)&photo&"' width='200' height='200' border='0' rel=lightbox[plants]>"
	     str1=str1&"</td>"
  	     str1=str1&"</tr>"
        end if
	str2=str2
	str2=tmpstr&str2
	str2=str2&"<tr><td align=center>"&tmpstr1&"</td></tr>"
        str2=str2&"</table>"
	showpicture=str&str2
  End Function
 Function getIP()
	Dim strIPAddr
	If Request.ServerVariables("HTTP_X_FORWARDED_FOR") = "" OR InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), "unknown") > 0 Then
		strIPAddr = Request.ServerVariables("REMOTE_ADDR")
	ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",") > 0 Then
		strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",")-1)
	ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";") > 0 Then
		strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";")-1)
	Else
		strIPAddr = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
	End If
	getIP = Trim(Mid(strIPAddr, 1, 30))
 End Function
 function  createuplodfolder(tpath)
	w_tpath=Server.mappath(tpath)
	set fso=server.createobject(C_Web_FSO)
	if fso.folderexists(w_tpath)=false Then
	   fso.CreateFolder(w_tpath)
	end if
 end function

 Function CheckStringLength(txt)
	txt=trim(txt)
	x = len(txt)
	y = 0
	for ii = 1 to x
	if asc(mid(txt,ii,1)) < 0 or asc(mid(txt,ii,1)) >255 then '如果是汉字
		y = y + 2
	else
		y = y + 1
	end if
	next
	CheckStringLength = y
 End Function




'#############################################
'# 商品编号规则
'#############################################
 Function getpronum()
	conndb	
 	set rs_num=server.createobject("adodb.recordset")
	if IsSqlDataBase =1 then
        	sql="select * from Web_ProNum order by level asc"
	else
		sql="select * from Web_ProNum order by [level] asc"
	end if
	rs_num.open sql,conn,1,3
	i=0
	do while not rs_num.eof 
		response.write getprorule(rs_num("id"),rs_num("level"))
	rs_num.movenext
	i=i+1
	loop
	rs_num.close
	response.write "<input type='hidden' name='pmuncount' value='"&i&"'> <input name='pnum' type='text'  id='pnum' size='20' maxlength='60' value=''>"
 End function

 Function getprorule(pid,level)
	set rs_rule=server.createobject("adodb.recordset")
	if IsSqlDataBase =1 then
        	sql="select * from Web_ProNumRule Where fid="&pid&"  order by level asc"
	else
		sql="select * from Web_ProNumRule Where fid="&pid&"  order by [level] asc"
	end if
	rs_rule.open sql,conn,1,3
	if not rs_rule.eof then 
		prostr=prostr&" <select name='pronum"&level&"' >"
			prostr=prostr&"<option value='' >"&getonevalue("Web_ProNum","name","id="&pid&"")&"</option>"
		do while not rs_rule.eof 
			prostr=prostr&"<option value='"&rs_rule("name")&"' >"&trim(rs_rule("title"))&"--"&trim(rs_rule("name"))&"</option>"
		rs_rule.movenext
		loop
		rs_rule.close
		prostr=prostr&"<select>"
	end if
	getprorule=prostr
   end  Function

function isIp(ipadd)
	isIp=false
	set oReg=new RegExp
	oReg.IgnoreCase=true
	oReg.global=true
	oReg.Pattern="(\d{1,4}\.\d{1,4}\.\d{1,4}\.\d{1,4})|(\d{1,4}\.\d{1,4}\.\d{1,4}\.\d{1,4}\/\d{1,2})"
	if oReg.test(ipadd) then isIp=true
		set oReg=nothing
end function
Function IP2Num(sip)
'限制某段IP地址
    dim str1,str2,str3,str4
    dim num
    IP2Num=0
    if isnumeric(left(sip,2)) then
        str1=left(sip,instr(sip,".")-1)
        sip=mid(sip,instr(sip,".")+1)
        str2=left(sip,instr(sip,".")-1)
        sip=mid(sip,instr(sip,".")+1)
        str3=left(sip,instr(sip,".")-1)
        str4=mid(sip,instr(sip,".")+1)
        num=cint(str1)*256*256*256+cint(str2)*256*256+cint(str3)*256+cint(str4)-1
        IP2Num = num
    end if
end function

Function Randxnum(v_len)
	Randomize
	for i=1 to v_len-1
		upperbound=upperbound&"9"
		lowerbound=lowerbound&"0"
	next
	upperbound=upperbound&"9"
	lowerbound="1"&lowerbound
	tmpid=tmpid & Int((upperbound - lowerbound + 1) * Rnd + lowerbound) 
	Randxnum=tmpid
End Function

Function Web_get_serialnum(v_num1,v_type)
	if trim(v_type)="" and trim(v_num1)="" then	
		Web_get_serialnum=CreateproductID()
		exit function
	end if
	if v_type<>"" then
		Web_get_serialnum=v_type	
	else
		openrs
		'sql="select replace(p_pid,'"&v_num1&"','') as num from web_product where  p_pid like '"&v_num1&"%'"
		sql="select p_pid as num from web_product where  p_pid like '"&v_num1&"%'"

		response.write sql
		rs.open sql,conn,3,1
		if not rs.eof then 
			tt=0
			tmparray=rs.getrows()
			for i=0 to ubound(tmparray,2)
				w_tt_1=replace(tmparray(0,i),v_num1,"")
				if isnumeric(w_tt_1)=true then
					if w_tt_1>tt then
						tt=w_tt_1
					end if 
				end if 
			next
			if tt=0 then
				Web_get_serialnum="000001"
			else
				tmpnum=tt+1
				for i=1	 to (5-len(tmpnum))
					str=str&"0"
				next
				Web_get_serialnum=str&tmpnum
			end if 
		else
			Web_get_serialnum="000001"
		end if 
		closers
	end if
End Function
'###################################################
'#通信工具
'###################################################
 Function GetchatsList(flagid)
	if flagid<>"" then
		if flagid=0 then
			select0="selected"
		elseif flagid=1 then
			select1="selected"
		elseif flagid=2 then
			select2="selected"
		elseif flagid=3 then	
			select3="selected"		
		elseif flagid=4 then
			select4="selected"
		end if
	else
			select0=""
			select1=""
			select2=""
			select3=""
			select4=""
 	end if
  	GetchatsList=GetchatsList&"<option value='0' "&select0&">QQ</option>"
  	GetchatsList=GetchatsList&"<option value='1'  "&select1&">MSN</option>"
  	GetchatsList=GetchatsList&"<option value='2'  "&select2&">skype</option>"
  	GetchatsList=GetchatsList&"<option value='3'  "&select3&">淘宝旺旺</option>"
  	GetchatsList=GetchatsList&"<option value='4'  "&select4&">贸易通</option>"
     	GetchatsList=GetchatsList
 end Function
 Function Showchatstype(flagid)
	if flagid=0 then
		chatsname="QQ"
	elseif flagid=1 then
		chatsname="MSN"
	elseif flagid=2 then
		chatsname="skype"
	elseif flagid=3 then	
		chatsname="淘宝旺旺"		
	elseif flagid=4 then
		chatsname="贸易通"
	end if
	Showchatstype=chatsname
 end Function

'###########################
'+ 过滤
'#############################
 Function NoSqlHack(web_inputStr)
	Dim w_NoSqlHack_AllStr,f_NoSqlHack_Str,f_NoSqlHack_i,Str_InputStr
	Str_InputStr=web_inputStr
	w_NoSqlHack_AllStr="*|and |exec |insert |select |delete |update |count |master |truncate |declare |and	|exec	|insert	|select	|delete	|update	|count	|master	|truncate	|declare	|char(|mid(|chr("
	w_NoSqlHack_Str = Split(w_NoSqlHack_AllStr,"|")

	For w_NoSqlHack_i=LBound(w_NoSqlHack_Str) To Ubound(w_NoSqlHack_Str)
		If Instr(LCase(Str_InputStr),f_NoSqlHack_Str(w_NoSqlHack_i))<>0 Then
			If w_NoSqlHack_Str(f_NoSqlHack_i)="'" Then w_NoSqlHack_Str(f_NoSqlHack_i)=" \' "
			Response.Write "<html><title>警告</title><body bgcolor=""EEEEEE"" leftmargin=""60"" topmargin=""30""><font style=""font-size:16px;font-weight:bolder;color:blue;""><li>您提交的数据有恶意字符</li></font><font style=""font-size:14px;font-weight:bolder;color:red;""><br><li>您的数据已经被记录!</li><br><li>您的IP："&Request.ServerVariables("Remote_Addr")&"</li><br><li>操作日期："&Now&"</li></font></body></html><!--Powered by Foosun Inc.,AddTime:"&now&"-->"
			Response.End
		End if
	Next
	NoSqlHack = Replace(Str_InputStr,"'","''")
End Function 

Function NoHtmlHackInput(Str) '过滤跨站脚本和HTML标签
	Dim regEx
	Set regEx = New RegExp
	regEx.IgnoreCase = True
	regEx.Pattern = "<|>|(script)|on(mouseover|mouseon|mouseout|click|dblclick|blur|focus|change)|eval|\t"
	If regEx.Test(LCase(Str)) Then
			Response.Write "<html><title>警告</title><body bgcolor=""EEEEEE"" leftmargin=""60"" topmargin=""30""><font style=""font-size:16px;font-weight:bolder;color:blue;""><li>您提交的数据有恶意字符</li></font><font style=""font-size:14px;font-weight:bolder;color:red;""><br><li>提交的内容不能包括[<|>|(script)|on(mouseover|mouseon|mouseout|click|dblclick|blur|focus|change)|eval]</li><li>您的数据已经被记录!</li><br><li>您的IP："&Request.ServerVariables("Remote_Addr")&"</li><br><li>操作日期："&Now&"</li></font></body></html><!--Powered by Foosun Inc.,AddTime:"&now&"-->"
			Response.End
	End If
	Set regEx = Nothing
	NoHtmlHackInput = Str
End Function
Function replacefilename(Str) '过滤动态可执行文件后缀名
		replacefilename=replace(str,".asp","")
		replacefilename=replace(replacefilename,".asa","")
		replacefilename=replace(replacefilename,".aspx","")
		replacefilename=replace(replacefilename,".js","")
		replacefilename=replace(replacefilename,".php","")
		replacefilename=replace(replacefilename,".asp","")
		replacefilename=replace(replacefilename,".inc","")
End Function
'###########################
'+ 生成随机字符串
'#############################
Function web_getCode(iCount) 
	Dim arrChar 
	Dim j,k,strCode 	
	arrChar = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" 
	k=Len(arrChar) 
	Randomize 
	For i=1 to iCount 
		j=Int(k * Rnd )+1 
		strCode = strCode & Mid(arrChar,j,1) 
	Next 
	web_getCode = strCode 
End Function 
'###########################
'+ 生成优惠券券号
'#############################

 sub CreateBenefitCode(web_filepath,onlyid,wordtext)
		dim fso
		set fso=Server.CreateObject(C_Web_FSO)
    		'自动生成文件名
    		Tfilename=onlyid&"."
    		Tfilenameend=split(web_filepath,".")
    		Tfilename=Tfilename&Tfilenameend(1)
		oldfilename2=split(web_filepath,"/")(2)
		OldFileName=split(web_filepath,".")(1)
		
		'复制文件
		c_filepath="../../uploadimage/Benefit/"&Tfilename
		filepath=server.mappath("../../"&web_filepath)
		W_filepath=server.mappath("../../"&"uploadimage/Benefit/")
		fso.CopyFile filepath,W_filepath&"/"
		
		'改名
		'PhysicalPath = Server.MapPath("../../uploadimage/Benefit") & "\" & oldfilename2
		response.write PhysicalPath&"<br>"
			if FSO.FileExists(PhysicalPath) = False then
				'response.write Server.MapPath("../../"&"uploadimage/Benefit") & "/" & oldfilename2&"<br>"
				Set FileObj = FSO.GetFile(Server.MapPath("../../"&"uploadimage/Benefit") & "\" & oldfilename2)
				FileObj.Name =Tfilename
				Set FileObj = Nothing
			end if
		PhysicalPath="../../uploadimage/Benefit/"&Tfilename&""
		AddWaterMark WordText,PhysicalPath
 end sub
'###########################
'+ 删除图片
'#############################
sub delphoto(photopath)
	Tphotopath=server.mappath(photopath)
  	Set fso = CreateObject(C_Web_FSO)
	If (fso.FileExists(Tphotopath)) Then
		'response.write Tphotopath
		fso.DeleteFile(Tphotopath)
		response.end
	 End If
end sub
'###########################
'+ 获得会员等级名称
'#############################
	Function getuclassname(classid)
		
		if classid<>"" then
		classid=split(classid,",")
		for i=0 to ubound(classid)
			if (i+1) mod 6=0 then
				pnamestr="<br>"
			else
				pnamestr=""
			end if
		p_namelist=p_namelist&"<font color='#ff0000'>&nbsp;&nbsp;"&getonevalue("Web_UserClass","UC_Name","id="&classid(i)&"")&"&nbsp;&nbsp;</font>,"&pnamestr
		
		next
	End if
	getuclassname=p_namelist
	end Function
'###########################
'+ 获得商品分类列表
'#############################
	Function proclassname(classid)
		
		if classid<>"" then
		classid=split(classid,",")
		for i=0 to ubound(classid)
			if (i+1) mod 6=0 then
				pnamestr="<br>"
			else
				pnamestr=""
			end if
		p_namelist=p_namelist&"<font color='#ff0000'>&nbsp;&nbsp;"&getonevalue("Web_ProClass","name","id="&classid(i)&"")&"&nbsp;&nbsp;</font>,"&pnamestr
		
		next
	End if
	proclassname=p_namelist
	end Function
'###########################
'+ 获得商品名称
'#############################
	Function getproname(classid)
		
		if classid<>"" then
		classid=split(classid,",")
		for i=0 to ubound(classid)
			if (i+1) mod 6=0 then
				pnamestr="<br>"
			else
				pnamestr=""
			end if
		p_namelist=p_namelist&"<font color='#ff0000'>&nbsp;&nbsp;"&getonevalue("Web_product","p_Name","id="&classid(i)&"")&"&nbsp;&nbsp;</font>,"&pnamestr
		
		next
	End if
	getproname=p_namelist
	end Function
'###########################
'+ 获得批发方案
'#############################
Function ws_uclass(tclasslist,muid)
	if tclasslist<>"" and muid <>"" then
		dclassid=split(tclasslist,"@")
		for ni=0 to ubound(dclassid)
			web_classid=split(dclassid(ni),"$$")(0)
				if  cint(web_classid)=cint(muid) then
			 		w_str=1
					exit for	
				else
					w_str=0
				end if
		next
	End if
	ws_uclass= w_str
end Function

'获取循环次数
function ws_getnum(mclasslist,tuid)
	
    if mclasslist<>"" and tuid <>"" then
	tclasslist=split(mclasslist,"@")
	for bi=0 to ubound(tclasslist)
		t_classid=split(tclasslist(bi),"$$")
		for ii=0 to ubound(t_classid)
				'response.write t_classid(0)&"--"&tuid&"---"&ubound(split(t_classid(1),","))&"<br>"
	     			if clng(t_classid(0))=clng(tuid) then
		    			ws_getnum=ubound(split(t_classid(1),","))
					 exit for
	     			end if
		   	 
		next
	
	next
     else
	ws_getnum=0
    end if
end function
'classlist 项目内容
'uid 用户名称id
'num 获取数量 循环次数
'cflag 0  为获取数量
'cflag 1 为获取折扣
function ws_getpronum(classlist,uid,num,cflag)

     if classlist<>"" and uid <>"" then
	tclasslist=split(classlist,"@")
	for i=0 to ubound(tclasslist)
		t_classid=split(tclasslist(i),"$$")
		for ii=0 to ubound(t_classid)
	     		if  cint(t_classid(0))=uid then
				web_t_classid=split(t_classid(1),",")
				for iii=0 to ubound(web_t_classid)
					if cint(iii)=num then
						if cint(cflag)=1 then
					  	 	web_num=split(web_t_classid(iii),"|")(1)
						else
							web_num=split(web_t_classid(iii),"|")(0)
					
						end if
						exit for
					end if
				   
				next
	
	     		end if
	   		
		next
	next
    end if
	ws_getpronum=web_num
end function

'********************************************
'函数名：isInteger
'作  用：整数检验
'********************************************
	Public function isInteger(para)
		   on error resume Next
		   Dim str
		   Dim l,i
		   If isNUll(para) then 
			  isInteger=false
			  exit function
		   End if
		   str=cstr(para)
		   If trim(str)="" then
			  isInteger=false
			  exit function
		   End if
		   l=len(str)
		   For i=1 to l
			   If mid(str,i,1)>"9" or mid(str,i,1)<"0" then
				  isInteger=false 
				  exit function
			   End if
		   Next
		   isInteger=true
		   If err.number<>0 then err.clear
	End function

'***************************************************
'函数名：CheckStr
'作  用：过滤字符
'***************************************************
Function CheckStr(Str)
	If Trim(Str)="" Or IsNull(str) Then 
	CheckStr=""
	Exit Function
	End If
	Checkstr=Replace(Str,"'","''")
End Function


'###############################################################################################################################################
'									会员等级函数
'###############################################################################################################################################
'***************************************************
'函数名：web_GetclassName
'作  用：传递一个会员名称，返回这个会员的登记积分名称
'***************************************************
 Function web_GetclassName(username)
		score=getonevalue("web_user","u_score","u_username='"&username&"'")
		conndb
		set rss=server.createobject("adodb.recordset")
		if IsSqlDataBase =1 then
        	  	sql="select top 1 UC_Name from Web_UserClass   where UC_Score<="&score&" order by UC_Score DESC"
		else
	  		sql="select top 1 UC_Name from Web_UserClass   where clng(UC_Score)<="&trim(score)&" order by UC_Score DESC"	
		end if

	
  		rss.open sql,conn,1,3	
		if rss.eof then 
		else
			Onename=rss("UC_Name")
		end if 
		rss.close : set rss=nothing
	
	web_GetclassName=Onename
 End Function
'***************************************************
'函数名：web_GetclassName
'作  用：传递一个会员名称，返回这个会员的登记图片
'***************************************************
 Function web_GetclassNamepic(username)
		score=getonevalue("web_user","u_score","u_username='"&username&"'")
		conndb
		set rss=server.createobject("adodb.recordset")
		if IsSqlDataBase =1 then
        	  	  sql="select top 1 UC_PicURL from Web_UserClass   where UC_Score<="&score&" order by UC_Score DESC"
		else
	  		  sql="select top 1 UC_PicURL from Web_UserClass   where clng(UC_Score)<="&trim(score)&" order by UC_Score DESC"
		end if

  		rss.open sql,conn,1,3	
		if rss.eof then 
		else
			Onename=rss("UC_PicURL")
		end if 
		rss.close : set rss=nothing
	
	web_GetclassNamepic=Onename
 End Function
'***************************************************
'函数名：web_Getclassdiscount
'作  用：传递一个会员名称，返回这个会员的折扣
'***************************************************
 Function web_Getclassdiscount(username)
		score=getonevalue("web_user","u_score","u_username='"&username&"'")
		conndb
		set rss=server.createobject("adodb.recordset")
		if IsSqlDataBase =1 then
  			sql="select top 1 UC_discount from Web_UserClass   where UC_Score<="&score&" order by UC_Score DESC"
		else
			sql="select top 1 UC_discount from Web_UserClass   where clng(UC_Score)<="&trim(score)&" order by UC_Score DESC"
		end if
  		rss.open sql,conn,1,3	
		if rss.eof then 
		else
			Onename=rss("UC_discount")
		end if 
		rss.close : set rss=nothing
	
	web_Getclassdiscount=Onename
 End Function
'***************************************************
'函数名：web_Getclassqz
'作  用：传递一个会员名称，返回这个会员的权重
'***************************************************
 Function web_Getclassqz(username)
		score=getonevalue("web_user","u_score","u_username='"&username&"'")
		conndb
		set rss=server.createobject("adodb.recordset")
		if IsSqlDataBase =1 then
  			sql="select top 1 UC_qz from Web_UserClass   where UC_Score<="&score&" order by UC_Score DESC"
		else
			sql="select top 1 UC_qz from Web_UserClass   where clng(UC_Score)<="&trim(score)&" order by UC_Score DESC"
		end if
  		rss.open sql,conn,1,3	
		if rss.eof then 
		else
			Onename=rss("UC_qz")
		end if 
		rss.close : set rss=nothing
	
	wweb_Getclassqz=Onename
 End Function
'***************************************************
'函数名：getuclasssocre
'作  用：传递一个会员等级编号返回这个会员的分值段
'***************************************************
 Function GetuClassSocre(uclassid)
	conndb
	score=getonevalue("Web_UserClass","UC_Score","id="&uclassid&"")
	if score="-1NISNUL" then
		GetuClassSocre="0|0"
	else
		set rss=server.createobject("adodb.recordset")
		if IsSqlDataBase =1 then
  			sql="select top 1 UC_Score from Web_UserClass   where UC_Score>"&score&" order by UC_Score asc"
		else
			sql="select top 1 UC_Score from Web_UserClass   where clng(UC_Score)>"&trim(score)&" order by UC_Score asc"
		end if
		'response.write sql
  		rss.open sql,conn,1,3	
		if rss.eof then 
			OneScore="0"
		else
			OneScore=rss("UC_Score")
		end if 
		rss.close : set rss=nothing
		GetuClassSocre=score&"|"&OneScore
	end if
 End Function
'***************************************************
'函数名：getuserclassname
'作  用：传递一个会员积分返回这个会员的等级
'***************************************************
 Function GetUserClassName(score)
		conndb
		set rss=server.createobject("adodb.recordset")
		if IsSqlDataBase =1 then
        	  		sql="select top 1 UC_Name from Web_UserClass   where UC_Score<="&score&" order by UC_Score DESC"
		else
		  		sql="select top 1 UC_Name from Web_UserClass   where clng(UC_Score)<="&trim(score)&" order by UC_Score DESC"
		end if

  		rss.open sql,conn,1,3	
		if rss.eof then 
		else
			Onename=rss("UC_Name")
		end if 
		rss.close : set rss=nothing
	
	GetUserClassName=Onename
 End Function
'***************************************************
'函数名：getuserclassid
'作  用：传递一个会员积分返回这个会员的等级编号
'***************************************************
 Function getuserclassid(score)
		conndb
		set rss=server.createobject("adodb.recordset")
		if IsSqlDataBase =1 then
  			sql="select top 1 id from Web_UserClass   where UC_Score<="&score&" order by UC_Score DESC"
		else
			sql="select top 1 id from Web_UserClass   where clng(UC_Score)<="&trim(score)&" order by UC_Score DESC"
		end if
  		rss.open sql,conn,1,3	
		if rss.eof then 
		else
			Onename=rss("id")
		end if 
		rss.close : set rss=nothing
	
	getuserclassid=Onename
 End Function
'***************************************************
'函数名：GetUserClassDisrate()
'作  用：传递一个积分返回这个会员的等级折扣
'***************************************************
 Function GetUserClassDisrate(score)
		if isnumeric(score)=false then 
			w_score=0
		else
			w_score=score
		end if 
		conndb
		set rss=server.createobject("adodb.recordset")
		if IsSqlDataBase =1 then
  			sql="select top 1 UC_discount from Web_UserClass   where UC_Score<="&score&" order by UC_Score DESC"
		else
			sql="select top 1 UC_discount from Web_UserClass   where clng(UC_Score)<="&trim(w_score)&" order by UC_Score DESC"
		end if
  		rss.open sql,conn,1,3	
		if rss.eof then 
			Onediscount=1
		else
			Onediscount=rss("UC_discount")/100
		end if 
		rss.close : set rss=nothing
	
	GetUserClassDisrate=Onediscount
 End Function


'***************************************************
'函数名：GetUserClassprice()
'作  用：传递一个会员积分、自定义价格返回该会员等级的商品价格
'***************************************************
 Function GetUserClassprice(score,myprice)
		classid=getuserclassid(score)
		GetUserClassprice=Web_c_SetMyPrice(classid,myprice)
		
 End Function
'***************************************************
'函数名：ReTurnUserClassid()
'作  用：传递一个会员名称，返回该会员等级编号
'***************************************************
 Function ReTurnUserClassid(userid)
	uscore=getonevalue("web_user","u_score","u_username='"&userid&"'")
	ReTurnUserClassid=getuserclassid(uscore)	
 End Function
 Function ReTurnUserAvailScore(userid)
		
	defaultscore=getonevalue("Web_UserClass","UC_Score","UC_default=1")
	if defaultscore="-1NISNUL" or isnull(defaultscore)=true then
		defaultscore=0
	else
		defaultscore=defaultscore
	end if
	allscore=getonevalue("web_user","U_Score","u_username='"&userid&"'")
	if allscore="-1NISNUL" then
		allscore=0
	else
		allscore=allscore
	end if
	if  clng(allscore)<clng(defaultscore) then
		ReTurnUserAvailScore=0
	else
		ReTurnUserAvailScore=allscore-defaultscore
	end if
	
 End Function

'***************************************************
'函数名：ReTurnUserClassid()
'作  用：传递一个会员名称，返回该会员的有效使用积分
'***************************************************

'###############################################################################################################################################
'							购物车函数
'###############################################################################################################################################
'***************************************************
'函数名：checkischanagesale()
'作  用：传递一个购物车编号返回是否已经存在换购商品
'***************************************************
 Function checkischanagesale(cartid)
	conndb
	set rs_cart=conn.execute("select * from Web_Cart where C_cartid='"&cartid&"'")
	if not rs_cart.eof then
		do while not rs_cart.eof
 		
			goodid=rs_cart("C_goodsid")
			 if Web_C_Checkexist("p_changsale","web_product","where id="&goodid&" and p_changsale=1")=1 then
				checkischanagesale=1
				Exit Do         
		  	else
				checkischanagesale=0
		 	end if
		rs_cart.movenext
		loop
		rs_cart.close
	else
		checkischanagesale=0
	end if
 end  Function
'***************************************************
'函数名：countcartmoney()
'作  用：传递一个购物车编号统计购物车中金额的多少
'***************************************************
 Function countcartmoney(cartid)
	conndb
	set rs_cart=conn.execute("select * from Web_Cart where C_cartid='"&cartid&"'")
	if not rs_cart.eof then
		do while not rs_cart.eof
			  t_money=t_money+rs_cart("c_preprice")*rs_cart("c_goodscount")
		rs_cart.movenext
		loop
		rs_cart.close
	else
		countcartmoney=0
	end if
	countcartmoney=t_money
 end  Function

'***************************************************
'函数名：getcartordermoney()
'作  用：传递一个购物车编号返回是购物车中换购商品的订单总额
'***************************************************
 Function getcartordermoney(cartid)
	conndb
	set rs_cart=conn.execute("select * from Web_Cart where C_cartid='"&cartid&"'")
	if not rs_cart.eof then
		do while not rs_cart.eof
 		
			goodid=rs_cart("C_goodsid")
			 if Web_C_Checkexist("p_changsale","web_product","where id="&goodid&" and p_changsale=1")=1 then
				getcartordermoney=getonevalue("web_product","p_ordermoney","id="&goodid&"")
				Exit Do         
		  	else
				getcartordermoney=0
		 	end if
		rs_cart.movenext
		loop
		rs_cart.close
	else
		getcartordermoney=0
	end if
 end  Function
'***************************************************
'函数名：getcartchanageproid()
'作  用：传递一个购物车编号返回是购物车中换购商品的编号
'***************************************************
 Function getcartchanageproid(cartid)
	conndb
	set rs_cart=conn.execute("select * from Web_Cart where C_cartid='"&cartid&"'")
	if not rs_cart.eof then
		do while not rs_cart.eof
 		
			goodid=rs_cart("C_goodsid")
			 if Web_C_Checkexist("p_changsale","web_product","where id="&goodid&" and p_changsale=1")=1 then
				getcartchanageproid=goodid
				Exit Do         
		  	else
				getcartchanageproid=0
		 	end if
		rs_cart.movenext
		loop
		rs_cart.close
	else
		getcartchanageproid=0
	end if
 end  Function
'***************************************************
'函数名：showwholesale()
'作  用：显示对应等级的批发信息
'***************************************************
 Function showwholesale(wholelistid,userid)
	
	if userid<>"0" then
		tuserid=userid
	else
		tuserid=0
	end if
	w_content=getonevalue("web_wholesale","w_content","id="&wholelistid&"")
	w_name=getonevalue("web_wholesale","w_name","id="&wholelistid&"")
	showlist1="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;批发方案名称:<font color=#FF6600>"&w_name&"</font> "&"<br>"
	showlist2="备注:批发方案时,不能再享受其他折扣"
	
	for ii=0 to  ws_getnum(w_content,tuserid)
		
		showlist=showlist&"当您购买商品数量大于或者等于<font color=#ff000>"&ws_getpronum(w_content,tuserid,ii,0)&"</font> 件时, 商品折扣为<font color=#ff000>"&ws_getpronum(w_content,tuserid,ii,1)&"%</font>。"&"<br>"
	next
	showwholesale=showlist1&showlist&showlist2
 end  Function	


'***************************************************
'函数名：Returndiscount()
'作  用：传递批发方案编号,用户编号,购物车中的商品数量
'返  回: 该会员的批发方案等级折扣
'***************************************************
 Function Returndiscount(wholelistid,userid,pronum)
	if userid<>"0" then
		tuserid=ReTurnUserClassid(userid)
	else
		tuserid=0
	end if
	w_content=getonevalue("web_wholesale","w_content","id="&wholelistid&"")
	if ws_getnum(w_content,tuserid)<>0 then
		for ii=0 to  ws_getnum(w_content,tuserid)
			if pronum>=ws_getpronum(w_content,tuserid,ii,0) then
				p_discount=ws_getpronum(w_content,tuserid,ii,1)
				p_num=ws_getpronum(w_content,tuserid,ii,0)
			else
		  		if ii=0 then
					p_discount=100
		   		else
					p_discount=p_discount
					p_num=p_num
		   		end if
			end if
		next
	else
		p_discount=100
	end if
	Returndiscount=p_discount
 end  Function	

'***************************************************
'函数名：Returnpronum()
'作  用：传递批发方案编号,用户编号,购物车中的商品数量,判断是否存在商量
'返  回: 该会员的批发方案等级折扣  1表示存在相关的商品数量 ，0 表示批发方案中没有该商品数量
'***************************************************
 Function Returnpronum(wholelistid,userid,pronum)
	
	if userid<>"0" then
		tuserid=ReTurnUserClassid(userid)
	else
		tuserid=0
	end if
	w_content=getonevalue("web_wholesale","w_content","id="&wholelistid&"")
	p_num=0
	for ii=0 to  ws_getnum(w_content,tuserid)
		'response.write pronum&"--"&ws_getpronum(w_content,tuserid,ii,0)&"<br>"
		if int(pronum)>=cint(ws_getpronum(w_content,tuserid,ii,0)) then
			p_num=1
			exit for
		else
			p_num=p_num
		   
		end if
	next
	Returnpronum=p_num

 end  Function	

'***************************************************
'函数名：Scorehistory()
'作  用：增加积分消耗历史记录
'返  回: 
'***************************************************
 Function Scorehistory(Score,tflag,userid)
	select case tflag
		case 1
		  	web_description="积分转换预存款"
			t_flag=1
		case 2
		  	web_description="积分兑换礼品"
			t_flag=1
		case 3
		  	web_description="用户注册赠送积分"
			t_flag=0
		case 4
		  	web_description="积分抵扣货款"
			t_flag=1
		case 5
		  	web_description="用户发表文章赠送积分"
			t_flag=0
		case 6
		  	web_description="推荐好友赠送积分"
			t_flag=0
		case 7
		  	web_description="购买商品赠积分"
			t_flag=0
		case 8
		  	web_description="等级默认积分"
			t_flag=0
		case 9
		  	web_description="商品评价获赠加分"
			t_flag=0
		case 10
		  	web_description="活动赠送积分"
			t_flag=0
	end select
	conndb
	sql="insert into Web_ScoreHistory([sh_title],[sh_score],[sh_flag],[sh_type],[sh_addtime],[userid]) values('"&web_description&"','"&Score&"','"&t_flag&"','"&Tflag&"','"&timeformat(now(),0)&"','"&userid&"')"
	conn.execute(sql)

 end Function
'***************************************************
'函数名：Scorehistory()
'作  用：增加积分消耗历史记录
'返  回: 
'***************************************************
 Function Benefithistory(Score,tflag)
	select case tflag
		case 1
		  	web_description="优惠券转换预存款"
		case 2
		  	web_description="优惠券兑换礼品"
		case 3
		  	web_description="优惠券抵扣货款"
	end select
	conndb
	sql="insert into Web_ScoreHistory([sh_title],[sh_score],[sh_flag],[sh_type],[sh_addtime],[userid]) values('"&web_description&"','"&Score&"',1,'"&Tflag&"','"&timeformat(now(),0)&"','"&session("kkuid")&"')"
	conn.execute(sql)
 end Function
'***************************************************
'函数名：getRelation()
'作  用：获得相关商品
'返  回: 
'***************************************************
 Function getRelation(productid)
	Relationpro=getonevalue("web_product","p_Relationpro","id="&productid&"")
	if Relationpro="0" then
		web_product=0
	else
		web_product=ubound(split(Relationpro,","))+1
	end if 
	getRelation=web_product
 end Function
'***************************************************
'函数名：getRelationfile()
'作  用：获得相关文章
'返  回: 
'***************************************************
 Function getRelationfile(productid)
	Relationpro=getonevalue("web_product","p_Relationfile","id="&productid&"")
	if Relationpro="0" or isnull(Relationpro)=true then
		web_product=0
	else
		web_product=ubound(split(Relationpro,","))+1
	end if 
	getRelationfile=web_product
 end Function

%>