<!--#include file="head.asp"-->
<style>body{background-color: #fff;}</style>

<%
'call chktel()

function FillZero(str)
	if len(str)=1 then
	FillZero = "0"&str
	else
	FillZero=str
	end if
end function
time_start=year(now)&FillZero(month(now))&FillZero(day(now))&FillZero(hour(now))&FillZero(minute(now))&FillZero(second(now))


if SafeRequest("act")="udel" then
id=trim(SafeRequest("id"))
if id="" then call PopErr("出现错误")
if len(id)>5 then call PopErr("出现错误")
if isNumeric(id)=false then call PopErr("出现错误")
sql="select * from aydailishang where aydlid="&id&"" 
rs.open sql,conn,1,3
if not(rs.bof and rs.eof) then
if clng(rs("aydluserid"))<>clng(request.Cookies("aynameid")) then  call PopErr("出现错误")
uid=trim(rs("aydluserid"))
sid=trim(rs("aydlsjuserid"))
rs.delete
rs.close
sql="select aygoodsuoyouid,aygooddlid from aygood where aygoodsuoyouid="&clng(uid)&" and aygooddlid="&clng(sid)&"" 
rs.open sql,conn,1,3
if not(rs.bof and rs.eof) then
do while not rs.eof
rs.delete
rs.movenext 
loop
end if
rs.close
sql="select aykanamesuoyou,ayfenleidlid from aykafenlei where aykanamesuoyou="&clng(uid)&" and ayfenleidlid="&clng(sid)&"" 
rs.open sql,conn,1,3
if not(rs.bof and rs.eof) then
do while not rs.eof
rs.delete
rs.movenext 
loop
end if
rs.close

call logadd(request.Cookies("aynameid"),"代理关系删除成功-"&id&"-"&uid&"-"&sid,0,0)
call PopErr2("代理关系删除成功","userdaili")
else
call PopErr("未找到该代理关系")
end if
rs.close
end if


if SafeRequest("act")="sdel" then
id=trim(SafeRequest("id"))
if id="" then call PopErr("出现错误")
if len(id)>5 then call PopErr("出现错误")
if isNumeric(id)=false then call PopErr("出现错误")

sql="select * from aydailishang where aydlid="&id&"" 
rs.open sql,conn,1,3
if not(rs.bof and rs.eof) then
if clng(rs("aydlsjuserid"))<>clng(request.Cookies("aynameid")) then  call PopErr("出现错误")
uid=trim(rs("aydluserid"))
sid=trim(rs("aydlsjuserid"))
rs.delete
rs.close
sql="select aygoodsuoyouid,aygooddlid from aygood where aygoodsuoyouid="&clng(uid)&" and aygooddlid="&clng(sid)&"" 
rs.open sql,conn,1,3
if not(rs.bof and rs.eof) then
do while not rs.eof
rs.delete
rs.movenext 
loop
end if
rs.close
sql="select aykanamesuoyou,ayfenleidlid from aykafenlei where aykanamesuoyou="&clng(uid)&" and ayfenleidlid="&clng(sid)&"" 
rs.open sql,conn,1,3
if not(rs.bof and rs.eof) then
do while not rs.eof
rs.delete
rs.movenext 
loop
end if
rs.close


call logadd(request.Cookies("aynameid"),"代理关系删除成功-"&id&"-"&uid&"-"&sid,0,0)
call PopErr2("代理关系删除成功","userdaili")
else
call PopErr("未找到该代理关系")
end if
rs.close
end if




if SafeRequest("act")="jujue" then
id=trim(SafeRequest("id"))
if id="" then call PopErr("出现错误")
if len(id)>5 then call PopErr("出现错误")
if isNumeric(id)=false then call PopErr("出现错误")
sql="select * from aydailishang where aydlid="&id&"" 
rs.open sql,conn,1,3
if not(rs.bof and rs.eof) then
if clng(rs("aydlsjuserid"))<>clng(request.Cookies("aynameid")) then  call PopErr("出现错误")

set rst=server.CreateObject("adodb.recordset")
sqlt="select * from aytongzhi" 
rst.open sqlt,conn,1,3
rst.addnew
rst("aytongzhilei")=3
rst("aytongzhiuser")=rs("aydluserid")
rst("aytongzhidate")=now()
rst("aytongzhibiao")="您申请的代理被拒绝"
rst("aytongzhicon")="您申请的代理被拒绝，您可以联系上级代理"
rst("suijiid")=trim(rs("aydluserid"))&time_start
rst("t4")=1
rst.update
rst.close

rs("aydlistongguo")=3
rs.update
rs.close
call logadd(request.Cookies("aynameid"),"代理关系拒绝成功-"&id,0,0)
call PopErr2("操作成功","userdaili")
else
call PopErr("未找到该代理关系")
end if
rs.close
end if




if SafeRequest("act")="tongguo" then
id=trim(SafeRequest("id"))
if id="" then call PopErr("出现错误")
if len(id)>5 then call PopErr("出现错误")
if isNumeric(id)=false then call PopErr("出现错误")

sql="select ayisxiaojin,aynameid from ayname where aynameid="&clng(request.Cookies("aynameid"))&"" 
rs.open sql,conn,1,1
if ccur(rs("ayisxiaojin"))<200 then 
call PopErr("总代理或上级代理需开通平台VIP会员！")
response.End()
end if
rs.close


sql="select * from aydailishang where aydlid="&id&"" 
rs.open sql,conn,1,3
if not(rs.bof and rs.eof) then
if clng(rs("aydlsjuserid"))<>clng(request.Cookies("aynameid")) then  call PopErr("出现错误")
uid=trim(rs("aydluserid"))
set rst=server.CreateObject("adodb.recordset")
sqlt="select * from aytongzhi" 
rst.open sqlt,conn,1,3
rst.addnew
rst("aytongzhilei")=3
rst("aytongzhiuser")=rs("aydluserid")
rst("aytongzhidate")=now()
rst("aytongzhibiao")="您申请的代理已经审核通过"
rst("aytongzhicon")="您申请的代理已经审核通过，您现在可以获取代理的商品信息"
rst("suijiid")=trim(rs("aydluserid"))&time_start
rst("t4")=1
rst.update
rst.close

'rs("aydlfandian")="10%"
'rs("aydlfeiyongf")=0
rs("aydltdate")=now()
rs("aydlistongguo")=1
rs.update
rs.close

sql="select aynameid,ayisdaili from ayname where aynameid="&clng(uid)&"" 
rs.open sql,conn,1,3
rs("ayisdaili")=1
rs.update
rs.close
call logadd(request.Cookies("aynameid"),"代理关系审核通过-"&id,0,0)
call PopErr2("审核通过成功，为您跳转到配置页面，请务必完成商品同步或商品独立设置修改！","dailiedit?act=edit&id="&id&"")
else
call PopErr("未找到该代理关系")
end if
rs.close
end if


if SafeRequest("act")="quxiaodl" then
id=trim(SafeRequest("id"))
if id="" then call PopErr("出现错误")
if len(id)>5 then call PopErr("出现错误")
if isNumeric(id)=false then call PopErr("出现错误")
sql="select * from aydailishang where aydlid="&id&"" 
rs.open sql,conn,1,3
if not(rs.bof and rs.eof) then
if clng(rs("aydlsjuserid"))<>clng(request.Cookies("aynameid")) then  call PopErr("出现错误")
uid=trim(rs("aydluserid"))
rs("aydlistongguo")=2
rs.update
rs.close
call logadd(request.Cookies("aynameid"),"代理关系取消-"&id,0,0)
call PopErr2("操作成功","userdaili")
else
call PopErr("未找到该代理关系")
end if
rs.close
end if

if SafeRequest("act")="huifudl" then
id=trim(SafeRequest("id"))
if id="" then call PopErr("出现错误")
if len(id)>5 then call PopErr("出现错误")
if isNumeric(id)=false then call PopErr("出现错误")

sql="select ayisxiaojin,aynameid from ayname where aynameid="&clng(request.Cookies("aynameid"))&"" 
rs.open sql,conn,1,1
if ccur(rs("ayisxiaojin"))<200 then 
call PopErr("总代理或上级代理需开通平台VIP会员")
response.End()
end if
rs.close

sql="select * from aydailishang where aydlid="&id&"" 
rs.open sql,conn,1,3
if not(rs.bof and rs.eof) then
if clng(rs("aydlsjuserid"))<>clng(request.Cookies("aynameid")) then  call PopErr("出现错误")
uid=trim(rs("aydluserid"))
rs("aydlistongguo")=1
rs.update
rs.close
call logadd(request.Cookies("aynameid"),"代理关系恢复-"&id,0,0)
call PopErr2("操作成功","userdaili")
else
call PopErr("未找到该代理关系")
end if
rs.close
end if

if SafeRequest("act")="delsq" then
id=trim(SafeRequest("id"))
if id="" then call PopErr("出现错误")
if len(id)>5 then call PopErr("出现错误")
if isNumeric(id)=false then call PopErr("出现错误")
sql="select * from aydailishang where aydlid="&id&"" 
rs.open sql,conn,1,3
if not(rs.bof and rs.eof) then
if clng(rs("aydluserid"))<>clng(request.Cookies("aynameid")) then  call PopErr("出现错误")
sid=trim(rs("aydlsjuserid"))
rs.delete
rs.close
	set rst=server.CreateObject("adodb.recordset")
	sqlt="select * from aytongzhi" 
	rst.open sqlt,conn,1,3
	rst.addnew
	rst("aytongzhilei")=3
	rst("aytongzhiuser")=sid
	rst("aytongzhidate")=now()
	rst("aytongzhibiao")="商户取消了成为您的代理商申请"
	rst("aytongzhicon")="商户取消了成为您的代理商申请"
	rst("suijiid")=trim(sid)&time_start
	rst("t4")=1
	rst.update
	rst.close
	call logadd(request.Cookies("aynameid"),"代理关系取消-"&id,0,0)
call PopErr2("取消代理申请操作成功","userdaili")
else
rs.close
call PopErr("未找到代理关系")
end if
end if

if SafeRequest("act")="del" then
id=trim(SafeRequest("id"))
if id="" then call PopErr("出现错误")
if len(id)>5 then call PopErr("出现错误")
if isNumeric(id)=false then call PopErr("出现错误")
sql="select * from aydailishang where aydlid="&id&"" 
rs.open sql,conn,1,3
if not(rs.bof and rs.eof) then
if clng(rs("aydluserid"))<>clng(request.Cookies("aynameid")) then  call PopErr("出现错误")
'sid=rs("aydlsjuserid")
rs("aydlistongguo")=2
rs.update
rs.close
call logadd(request.Cookies("aynameid"),"代理关系删除-"&id,0,0)
call PopErr2("操作成功","userdaili")
else
call PopErr("未找到该代理关系")
end if
rs.close
end if

if SafeRequest("act")="huifu111111111111" then
id=trim(SafeRequest("id"))
if id="" then call PopErr("出现错误")
if len(id)>5 then call PopErr("出现错误")
if isNumeric(id)=false then call PopErr("出现错误")
sql="select * from aydailishang where aydlid="&id&"" 
rs.open sql,conn,1,3
if not(rs.bof and rs.eof) then
if clng(rs("aydluserid"))<>clng(request.Cookies("aynameid")) then  call PopErr("出现错误")
'sid=rs("aydlsjuserid")
rs("aydlistongguo")=1
rs.update
rs.close
call logadd(request.Cookies("aynameid"),"代理关系恢复-"&id,0,0)
call PopErr2("操作成功","userdaili")
else
call PopErr("未找到该代理关系")
end if
rs.close
end if

if SafeRequestform("act")="add" then
aydlsjusermail=SafeRequestform("aydlsjusermail")
if trim(aydlsjusermail)="" then call PopErr("请填写上级商家手机号")

sql="select top 1 aynameid,ayusersuo,ayisdaili,aymail from ayname where aytel="&aydlsjusermail&"" 
rs.open sql,conn,1,1
if not(rs.bof and rs.eof) then
	aydlsjuserid=rs("aynameid")
	if clng(aydlsjuserid)=clng(request.Cookies("aynameid")) then call PopErr("不能申请自己为代理")
	if cint(rs("ayusersuo"))=1 then call PopErr("您选择的上级商户ID已被锁定")
	'if cint(rs("ayisdaili"))=1 then call PopErr("您选择的上级商户ID已经是代理商，不能多次代理")
else
call PopErr("您输入的上级代理商家手机号不存在")
end if
rs.close

'sql="select aydlsjuserid from aydailishang where aydlsjuserid='"&request.Cookies("aynameid")&"'" 
'rs.open sql,conn,1,1
'if not(rs.bof and rs.eof) then
'call PopErr("您目前有下级代理商，不能提交申请")
'end if
'rs.close


sql="select * from aydailishang where aydluserid='"&request.Cookies("aynameid")&"' and aydlsjuserid='"&aydlsjuserid&"'" 
rs.open sql,conn,1,3
if not(rs.bof and rs.eof) then
call PopErr("您已经和该上级代理ID有代理关系，不能多次添加")
else
rs.addnew
rs("aydluserid")=trim(request.Cookies("aynameid"))
rs("aydlsjuserid")=trim(aydlsjuserid)
rs.update

	set rst=server.CreateObject("adodb.recordset")
	sqlt="select * from aytongzhi" 
	rst.open sqlt,conn,1,3
	rst.addnew
	rst("aytongzhilei")=3
	rst("aytongzhiuser")=aydlsjuserid
	rst("aytongzhidate")=now()
	rst("aytongzhibiao")="有新的商户申请代理"
	rst("aytongzhicon")="有新的商户申请代理，请尽快处理"
	rst("suijiid")=trim(aydlsjuserid)&time_start
	rst("t4")=1
	rst.update
	rst.close
	call logadd(request.Cookies("aynameid"),"代理关系申请-"&id&"-"&aydlsjuserid,0,0)
call PopErr2("上级代理添加成功，请等待上级代理回复","userdaili")
end if
rs.close

end if




if SafeRequest("act")="huoqu" then

id=trim(SafeRequest("id"))
if id="" then call PopErr("出现错误")
if len(id)>5 then call PopErr("出现错误")
if isNumeric(id)=false then call PopErr("出现错误")

	'获取代理关系信息 
	sql="select * from aydailishang where aydlid="&id&"" 
	rs.open sql,conn,1,1
		if rs.bof and rs.eof then
		call PopErr("未找到该代理关系")
		rs.close
		else

			if clng(rs("aydluserid"))<>clng(request.Cookies("aynameid")) then  call PopErr("出现错误")
			if cint(rs("aydlistongguo"))<>1 then call PopErr("代理关系不成立")
		uid=rs("aydluserid")
		sid=rs("aydlsjuserid")  '上级代理ID
		'sfd=rs("aydlfandian")
		rs.close

		'获取上级代理商户信息
		sql="select aynameid,ayusersuo from ayname where aynameid="&sid&"" 
		rs.open sql,conn,1,1
		if not(rs.bof and rs.eof) then
		if cint(rs("ayusersuo"))=1 then call PopErr("上级代理已被锁定")
		else
		call PopErr("未找到上级代理信息err1")
		end if
		rs.close

		'清空现有分类与商品
		'sql="select aygooddlid,aygoodsuoyouid from aygood where aygooddlid='"&sid&"' and aygoodsuoyouid="&request.Cookies("aynameid")&"" 
		'rs.open sql,conn,1,3
		'if not(rs.bof and rs.eof) then
		'do while not rs.eof
		'rs.delete
		'rs.movenext 
		'loop
		'end if
		'rs.close
		'sql="select ayfenleidlid,aykanamesuoyou from aykafenlei where ayfenleidlid='"&sid&"' and aykanamesuoyou="&request.Cookies("aynameid")&"" 
		'rs.open sql,conn,1,3
		'if not(rs.bof and rs.eof) then
		'do while not rs.eof
		'rs.delete
		'rs.movenext 
		'loop
		'end if
		'rs.close

		'获取上级代理商品分类信息
		sql="select * from aykafenlei where aykanamesuoyou="&sid&" order by ayshangjiid asc" 
		rs.open sql,conn,1,1
		if rs.bof and rs.eof then
		call PopErr("未找到上级代理商品分类信息")
		else
		do while not rs.eof

			'添加本地商品分类
			fenleierji=0
			if clng(rs("ayshangjiid"))<>0 then '二级分类
			
			set rsej=server.CreateObject("adodb.recordset")
			sqlej="select aykafenleiid,aykanamesuoyou,ayflsumid from aykafenlei where aykafenleiid="&rs("ayshangjiid")&" and aykanamesuoyou="&sid&"" 
			rsej.open sqlej,conn,1,1
			if not(rsej.bof and rsej.eof) then
				'查找本地二级分类ID
				set rsejb=server.CreateObject("adodb.recordset")
				sqlejb="select aykafenleiid,ayflsumid,aykanamesuoyou from aykafenlei where ayflsumid='"&trim(rsej("ayflsumid"))&"' and aykanamesuoyou="&clng(request.Cookies("aynameid"))&"" 
				rsejb.open sqlejb,conn,1,1
				if not(rsejb.bof and rsejb.eof) then
				fenleierji=rsejb("aykafenleiid")
				end if
				rsejb.close
			end if
			rsej.close
			end if
			
			
			set rsfl=server.CreateObject("adodb.recordset")
			sqlfl="select * from aykafenlei where ayflsumid='"&trim(rs("ayflsumid"))&"' and aykanamesuoyou="&request.Cookies("aynameid")&"" 
			rsfl.open sqlfl,conn,1,3
			if rsfl.bof and rsfl.eof then
				rsfl.addnew
				rsfl("aykafenleiname")=trim(rs("aykafenleiname"))
				rsfl("ayshangjiid")=clng(fenleierji)
				rsfl("aykafenleisx")=rs("aykafenleisx")
				rsfl("aykanamesuoyou")=clng(request.Cookies("aynameid"))
				rsfl("ayfenleidlid")=clng(sid)
				rsfl("ayflsumid")=trim(rs("ayflsumid"))
				rsfl("ayfenleidlfid")=rs("aykafenleiid")
				rsfl("aykafenleikg")=rs("aykafenleikg")
				rsfl.update
			
				'获取本地分类MD5 ID
				set rsfid=server.CreateObject("adodb.recordset")
				sqlfid="select top 1 aykafenleiid,aykanamesuoyou,ayfenleidlid,aykafenleimd5,ayfldlmd5url from aykafenlei where aykanamesuoyou="&request.Cookies("aynameid")&" and ayfenleidlid="&sid&" order by aykafenleiid desc" 
				rsfid.open sqlfid,conn,1,3
				if not(rsfid.bof and rsfid.eof) then
				md51=md5d(rsfid("aykafenleiid"))
				md52=md5user(rsfid("aykafenleiid"))
				rsfid("aykafenleimd5")=md51
				rsfid("ayfldlmd5url")=md52
				fenleiid=rsfid("aykafenleiid")
				rsfid.update
				end if
				rsfid.close
			
			else
				rsfl("aykafenleikg")=rs("aykafenleikg")
				rsfl.update
			
			
				'获取本地分类MD5 ID
				set rsfid=server.CreateObject("adodb.recordset")
				sqlfid="select top 1 aykafenleiid,aykanamesuoyou,ayflsumid from aykafenlei where ayflsumid='"&trim(rs("ayflsumid"))&"' and aykanamesuoyou="&request.Cookies("aynameid")&"" 
				rsfid.open sqlfid,conn,1,3
				if not(rsfid.bof and rsfid.eof) then
				fenleiid=rsfid("aykafenleiid")
				rsfid.update
				end if
				rsfid.close
			end if
			rsfl.close
			
						
			
	
			'获取上级代理商品信息
			set rssgood=server.CreateObject("adodb.recordset")
			sqlsgood="select * from aygood where aygoodsuoyouid="&sid&" and aygoodfl="&rs("aykafenleiid")&" and aygoodisydl=0 and isptdx=0" 
			rssgood.open sqlsgood,conn,1,1
					
			if not(rssgood.bof and rssgood.eof) then
			do while not rssgood.eof
	
					'添加本地商品
					set rsg=server.CreateObject("adodb.recordset")
					sqlg="select * from aygood where aygsumid='"&trim(rssgood("aygsumid"))&"' and aygoodsuoyouid="&request.Cookies("aynameid")&"" 
					rsg.open sqlg,conn,1,3
					if rsg.bof and rsg.eof then

								'代充模板处理
								aymbgusum=""
								mbid=""

					
						rsg.addnew
						rsg("aygoodsuoyouid")=request.Cookies("aynameid")
						rsg("aygoodfl")=fenleiid
						rsg("aygoodsx")=rssgood("aygoodsx")
						rsg("aygoodname")=trim(rssgood("aygoodname"))
						rsg("ayjiage")=rssgood("ayjiage")

						rsg("ayshmiaoshu")=trim(rssgood("ayshmiaoshu"))
						rsg("goodxx")=trim(rssgood("goodxx"))
						rsg("goodbuyxx")=trim(rssgood("goodbuyxx"))
								
						rsg("ayxiangou")=rssgood("ayxiangou") '限购
						rsg("aypifayes")=rssgood("aypifayes") '批发
								
						if clng(rssgood("aypifa1"))<>0 and rssgood("dailij1")<>0 then 
						rsg("aypifa1")=rssgood("aypifa1")
						rsg("aypifaj1")=rssgood("aypifaj1")
						rsg("dailicb1")=rssgood("dailij1")
						end if
						if clng(rssgood("aypifa2"))<>0 and rssgood("dailij2")<>0 then 
						rsg("aypifa2")=rssgood("aypifa2")
						rsg("aypifaj2")=rssgood("aypifaj2")
						rsg("dailicb2")=rssgood("dailij2")
						end if
						if clng(rssgood("aypifa3"))<>0 and rssgood("dailij3")<>0 then 
						rsg("aypifa3")=rssgood("aypifa3")
						rsg("aypifaj3")=rssgood("aypifaj3")
						rsg("dailicb3")=rssgood("dailij3")
						end if
						if clng(rssgood("aypifa4"))<>0 and rssgood("dailij4")<>0 then 
						rsg("aypifa4")=rssgood("aypifa4")
						rsg("aypifaj4")=rssgood("aypifaj4")
						rsg("dailicb4")=rssgood("dailij4")
						end if
						if clng(rssgood("aypifa5"))<>0 and rssgood("dailij5")<>0 then 
						rsg("aypifa5")=rssgood("aypifa5")
						rsg("aypifaj5")=rssgood("aypifaj5")
						rsg("dailicb5")=rssgood("dailij5")
						end if
						

						rsg("aygoodzhuangtai")=rssgood("aygoodzhuangtai") 
						rsg("aygooddlid")=rssgood("aygoodsuoyouid")
						rsg("aygsumid")=trim(rssgood("aygsumid"))
						rsg("aysjgid")=rssgood("aygoodid")
						
						rsg("kahaoname")="卡号"
						rsg("kaminame")="密码"
						
						'if ccur(rsg("aysjjiage"))=0 then 
						rsg("aysjjiage")=rssgood("aygoodtodaili")
						rsg("aychenben")=rssgood("aygoodtodaili")
						'else
						'rsg("aysjjiage")=rssgood("aysjjiage")
						'rsg("aychenben")=rssgood("aysjjiage")
						'end if
						rsg("aygoodiskucun")=1	'代理商品 不显示实际库存			
						rsg.update
						

						
					else
					

								'代充模板处理
								aymbgusum=""
								mbid=""
							

					
					'response.Write "you-"&trim(rssgood("aygoodname"))&"<br>"
						'rsg("aygoodsuoyouid")=request.Cookies("aynameid")
						rsg("aygoodfl")=fenleiid
						rsg("aygoodsx")=rssgood("aygoodsx")
						rsg("aygoodname")=trim(rssgood("aygoodname"))
						rsg("ayjiage")=rssgood("ayjiage")
						rsg("aygoodzhuangtai")=rssgood("aygoodzhuangtai") 

						rsg("ayshmiaoshu")=trim(rssgood("ayshmiaoshu"))
						rsg("goodxx")=trim(rssgood("goodxx"))
						rsg("goodbuyxx")=trim(rssgood("goodbuyxx"))
						
						rsg("kahaoname")="卡号"
						rsg("kaminame")="密码"

						rsg("aysjjiage")=rssgood("aygoodtodaili")
						rsg("aychenben")=rssgood("aygoodtodaili")
						
						rsg("ayxiangou")=rssgood("ayxiangou") '限购
						rsg("aypifayes")=rssgood("aypifayes") '批发
						
				
						if clng(rssgood("aypifa1"))<>0 and rssgood("dailij1")<>0 then 
						rsg("aypifa1")=rssgood("aypifa1")
						rsg("aypifaj1")=rssgood("aypifaj1")
						rsg("dailicb1")=rssgood("dailij1")
						end if
				
						
						if clng(rssgood("aypifa2"))<>0 and rssgood("dailij2")<>0 then 
						rsg("aypifa2")=rssgood("aypifa2")
						rsg("aypifaj2")=rssgood("aypifaj2")
						rsg("dailicb2")=rssgood("dailij2")
						end if
						
						if clng(rssgood("aypifa3"))<>0 and rssgood("dailij3")<>0 then 
						rsg("aypifa3")=rssgood("aypifa3")
						rsg("aypifaj3")=rssgood("aypifaj3")
						rsg("dailicb3")=rssgood("dailij3")
						end if
						
						if clng(rssgood("aypifa4"))<>0 and rssgood("dailij4")<>0 then 
						rsg("aypifa4")=rssgood("aypifa4")
						rsg("aypifaj4")=rssgood("aypifaj4")
						rsg("dailicb4")=rssgood("dailij4")
						end if
						
						if clng(rssgood("aypifa5"))<>0 and rssgood("dailij5")<>0 then 
						rsg("aypifa5")=rssgood("aypifa5")
						rsg("aypifaj5")=rssgood("aypifaj5")
						rsg("dailicb5")=rssgood("dailij5")
						end if
						rsg("aygoodiskucun")=1	'代理商品 不显示实际库存
						'rsg("aypifayes")=0
						'rsg("ayxiangou")=0
						'rsg("aygooddlid")=rssgood("aygoodsuoyouid")
						'rsg("aygsumid")=trim(rssgood("aygsumid"))
						'rsg("aysjgid")=rssgood("aygoodid")
						
						'if ccur(rsg("aysjjiage"))=0 then 
						'rsg("aysjjiage")=rssgood("aygoodtodaili")
						'rsg("aychenben")=rssgood("aygoodtodaili")
						'else
						'rsg("aysjjiage")=rssgood("aysjjiage")
						'rsg("aychenben")=rssgood("aysjjiage")
						'end if
						
						rsg.update
					end if
					rsg.close
	
			rssgood.movenext 
			loop
			
			end if
			rssgood.close


		rs.movenext 
		loop
		rs.close
'response.End()



		'增加商品MD5数据
		sql="select aygoodid,aygoodsuoyouid,aygooddlid,aygoodmd5,aygdlmd5url from aygood where aygoodsuoyouid="&request.Cookies("aynameid")&" and aygooddlid="&sid&" and aygoodmd5 is null" 
		rs.open sql,conn,1,3
		if not(rs.bof and rs.eof) then
		do while not rs.eof
		md51=md5d(rs("aygoodid"))
		md52=md5user(rs("aygoodid"))
		rs("aygoodmd5")=md51
		rs("aygdlmd5url")=md52
		rs.update
		rs.movenext 
		loop
		end if
		rs.close
		
		'删除上级代理已删除的商品
		set rsd=server.CreateObject("adodb.recordset")
		set rsd2=server.CreateObject("adodb.recordset")
		sqld="select * from aygood where aygoodsuoyouid='"&request.Cookies("aynameid")&"' and aygooddlid='"&sid&"'" 
		rsd.open sqld,conn,1,3
		do while not rsd.eof
			sqld2="select * from aygood where aygoodid='"&rsd("aysjgid")&"' and aygoodsuoyouid='"&sid&"'" 
			rsd2.open sqld2,conn,1,1
			if rsd2.bof and rsd2.eof then
			rsd.delete
			end if
			rsd2.close
		rsd.movenext 
		loop
		rsd.close
		
		'删除上级代理已删除的商品分类
		sqld="select * from aykafenlei where aykanamesuoyou='"&request.Cookies("aynameid")&"' and ayfenleidlid='"&sid&"'" 
		rsd.open sqld,conn,1,3
		do while not rsd.eof
			sqld2="select * from aykafenlei where aykafenleiid='"&rsd("ayfenleidlfid")&"' and aykanamesuoyou='"&sid&"'" 
			rsd2.open sqld2,conn,1,1
			if rsd2.bof and rsd2.eof then
			rsd.delete
			end if
			rsd2.close
		rsd.movenext 
		loop
		rsd.close
		

		end if
		call logadd(request.Cookies("aynameid"),"代理商品获取成功-"&id&"-"&uid&"-"&sid,0,0)
		call PopErr2("获取成功","goodlist")
		end if

end if
%>
<script type="text/javascript">
function check_add()
{
   if(myformadd.aydlsjuserid.value=="")
   {alert("请填写上级商户ID");return false}
	 
}
</script>



<script type="text/javascript">
var xmlhttp;try{xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");}catch (e){try{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}catch (e){try{xmlhttp=new XMLHttpRequest();}catch (e){}}}
function tongbu()
{
document.myform2.alltongbu.disabled="disabled";
document.myform2.alltongbu.value="同步中，请不要关闭或刷新此页。。。"
var istdaili=document.getElementById("istdaili").checked;

	xmlhttp.open("get","dailitongbu.asp?act=alltongbu&istdaili="+istdaili);

		xmlhttp.onreadystatechange=function()
		{
		   if(200==xmlhttp.status)
		   {		

				if(xmlhttp.responseText=="noact"){alert("参数错误E1，请联系管理员");window.location.href="userdaili";return false;}
				if(xmlhttp.responseText=="nouid"){alert("参数错误E2，请联系管理员");window.location.href="userdaili";return false;}
				if(xmlhttp.responseText=="nodaili"){alert("还没有代理关系，参数错误E3，请联系管理员");window.location.href="userdaili";return false;}
				if(xmlhttp.responseText=="nojiage"){alert("你有未设置代理价格的商品\n请先编辑商品，设置代理价格，再进行同步操作");window.location.href="userdaili";return false;}
				
				if(xmlhttp.responseText=="tongbuok")
				{
				alert("同步成功");
				window.location.href="userdaili";
				return false;
				}
		   }else{return false;}
		}
	xmlhttp.send(null); 

	 	 
}
</script>



<main>
<div  class="container">
<div class="ui-lrctnei">
<%call userleft()%>
<div class="r"> 
<div class="ui-content">
                        
					
                            
<div class="neiye">

                   
                                                     
            <!-------------------------------------- 开始 -------------------------------------->									
            <div class="neibiaoti"></div>
            <div class="neibiaoti2">申请代理</div>
            <div class="gexian20"></div>
                	<div class="neitablewu">
                    <form action="" method="post" name="myformadd" id="myformadd" onSubmit="return check_add()"> 
					<table width="1080">
                  		<tr>
                          <td width="130" align="center">上级商家手机号：</td>
                          <td width="180"><input name="aydlsjusermail" type="text" class="reginput" id="aydlsjusermail" style="width:160px;" maxlength="11"></td>
                          <td width="100"><input name="act" type="hidden" id="act" value="add"><input style="cursor:pointer" class="logindlregedit" type="submit" name="Submit" value=" 申请代理 " ></td>
                          <td><div class="regtdd" > 输入要申请加入的上级代理商手机号</div></td>
                        </tr>
                    </table>
                    </form>
            		</div>
                    <div class="gexian20"></div>
            <!-------------------------------------- 结束 -------------------------------------->
            
            
            
            
            <!-------------------------------------- 开始 -------------------------------------->									
            <div class="neibiaoti"></div>
            <div class="neibiaoti2">上级代理列表</div>
            <div class="gexian20"></div>
                	<div class="neitable">
                    <form action="" method="post" name="myform" id="myform">
					<table>
                        <tr class="hd">
                            <td width="100">上级代理商家</td>
                            <td width="100">代理状态</td>
                            <td width="100">店铺链接</td>
                            <td width="100">商家电话</td>
                            <td width="100">商家QQ</td>
                            <td width="100">商家微信</td>
                            <td width="140">申请时间</td>
                            <td width="140">通过时间</td>
                            <td>相关操作</td>
                        </tr>
						<%set rsu=server.CreateObject("adodb.recordset")
                        sql="select * from aydailishang where aydluserid='"&request.Cookies("aynameid")&"' order by aydlsdate desc" 
                        rs.open sql,conn,1,1
                        if not(rs.bof and rs.eof) then
                        do while not rs.eof%>
                  		<tr onmouseover=this.bgColor='#FAFAFA' onmouseout=this.bgColor='#ffffff'>
                            <td>
							<%
                            sqlu="select aynameid,aytrueuser,aygename,aymd5,ayismd5,aytel,ayqq,ayweixinid from ayname where aynameid="&rs("aydlsjuserid")&"" 
                            rsu.open sqlu,conn,1,3
                            if not(rsu.bof and rsu.eof) then
                            response.Write trim(rsu("aytrueuser"))
                            else
                            call PopErr("未找到上级代理用户数据")
                            end if
                            %>	
                            </td>
                            <td>
                            <%
							if rs("aydlistongguo")=0 then response.Write "<span style=color:#F90>申请中</span>"
							if rs("aydlistongguo")=1 then response.Write "<span style=color:#390>正常</span>"
							if rs("aydlistongguo")=2 then response.Write "<span style=color:#666>关闭</span>"
							if rs("aydlistongguo")=3 then response.Write "<span style=color:#F00>拒绝</span>"
							%>
                            </td>
                            <td>
							<%if isnull(trim(rsu("aygename")))=false and trim(rsu("aygename"))<>"" then%>
                            <a href="<%=weburl%><%=trim(rsu("aygename"))%>" target="_blank">查看</a> 
                            <%elseif rsu("ayismd5")=1 then%>
                            <a href="<%=weburl%><%=trim(rsu("aymd5"))%>" target="_blank">查看</a> 
                            <%else%>
                            <a href="<%=weburl%><%=rsu("aynameid")%>" target="_blank">查看</a> 
                            <%end if%>
                            </td>
                            <td><%=rsu("aytel")%></td>
                            <td><%=rsu("ayqq")%></td>
                            <td><%=rsu("ayweixinid")%></td>
                            <%rsu.close%>
                            <td><%=rs("aydlsdate")%></td>
                            <td>
							<%
                            if trim(rs("aydltdate"))<>"" and isnull(trim(rs("aydltdate")))=false then
                            response.Write rs("aydltdate")
                            else
                            response.Write "-"
                            end if
                            %>
                            </td>
                            <td>
							<%
                            if rs("aydlistongguo")=0 then%>
                            <a href="?act=delsq&id=<%=rs("aydlid")%>" onClick="javascript:return confirm('您确定要取消申请吗？');">取消申请</a>
                            <%elseif rs("aydlistongguo")=1 then%>
                            <a href="?act=huoqu&id=<%=rs("aydlid")%>" onClick="javascript:return confirm('您确定要获取商品吗？');">获取商品</a>
                            <a href="?act=del&id=<%=rs("aydlid")%>" onClick="javascript:return confirm('您确定要取消代理吗？');">取消代理</a>
                            
                            <%elseif rs("aydlistongguo")=2 then%>
                            <!--
                            <a href="?act=huifu&id=<%=rs("aydlid")%>" onClick="javascript:return confirm('您确定要删除代理吗？');">恢复代理</a>
                            -->
                            <a href="?act=udel&id=<%=rs("aydlid")%>" onClick="javascript:return confirm('您确定要删除代理吗？');">删除代理</a>
                            <%elseif rs("aydlistongguo")=3 then%>
                            <a href="?act=udel&id=<%=rs("aydlid")%>" onClick="javascript:return confirm('您确定要删除代理吗？');">删除代理</a>
                            <%else
                            response.Write "-"
                            end if%>
                            </td>
                        </tr>
			      <%
                        rs.movenext 
                        loop
                        else%>
                 		<tr><td colspan="9">还没有上级代理信息！</td>
                        </tr>
						<%
                        end if
                        rs.close%>
                    </table>
                    </form>
            		</div>
                    <div class="gexian20"></div>
            <!-------------------------------------- 结束 -------------------------------------->
            
            
            
            <!-------------------------------------- 开始 -------------------------------------->									
            <div class="neibiaoti"></div>
            <div class="neibiaoti2">下级代理列表</div>
            <div class="gexian20"></div>
                	<div class="neitable">
                    <form name="myform2" id="myform2"> 
					<table>
                        <tr class="hd">
                          <td width="100">下级代理商家</td>
                          <td width="100">代理状态</td>
                          <td width="100">店铺链接</td>
                          <td width="100">商家电话</td>
                          <td width="100">商家QQ</td>
                          <td width="100">商家微信</td>
                          <td width="140">申请时间</td>
                          <td width="140">通过时间</td>
                          <td>相关操作</td>
                        </tr>
						<%
						'response.Write request.Cookies("aynameid")
                        sql="select * from aydailishang where aydlsjuserid='"&request.Cookies("aynameid")&"' order by aydlsdate desc" 
                        rs.open sql,conn,1,1
                        if not(rs.bof and rs.eof) then
						
                        do while not rs.eof
						%>
                  		<tr onmouseover=this.bgColor='#FAFAFA' onmouseout=this.bgColor='#ffffff'>
                            <td>
							<%
                            sqlu="select aynameid,aytrueuser,aygename,aymd5,ayismd5,aychengjiao,aytel,ayqq,ayweixinid from ayname where aynameid="&trim(rs("aydluserid"))&"" 
                            rsu.open sqlu,conn,1,3
                            if not(rsu.bof and rsu.eof) then
                            response.Write trim(rsu("aytrueuser"))
                            'else
                            'call PopErr("未找到下级代理用户数据")
                            %>	
                            </td>
                            <td>
                            <%
							if rs("aydlistongguo")=0 then response.Write "<span style=color:#F90>申请中</span>"
							if rs("aydlistongguo")=1 then response.Write "<span style=color:#390>正常</span>"
							if rs("aydlistongguo")=2 then response.Write "<span style=color:#666>关闭</span>"
							if rs("aydlistongguo")=3 then response.Write "<span style=color:#F00>拒绝</span>"
							%>
                            </td>
                            <td>
							<%if isnull(trim(rsu("aygename")))=false and trim(rsu("aygename"))<>"" then%>
                            <a href="<%=weburl%><%=trim(rsu("aygename"))%>" target="_blank">查看</a> 
                            <%elseif rsu("ayismd5")=1 then%>
                            <a href="<%=weburl%><%=trim(rsu("aymd5"))%>" target="_blank">查看</a> 
                            <%else%>
                            <a href="<%=weburl%><%=rsu("aynameid")%>" target="_blank">查看</a> 
                            <%end if%>
                            </td>
                            <td><%=rsu("aytel")%></td>
                            <td><%=rsu("ayqq")%></td>
                            <td><%=rsu("ayweixinid")%></td>
                            <td><%=rs("aydlsdate")%></td>
                            <td>
							<%
                            if trim(rs("aydltdate"))<>"" and isnull(trim(rs("aydltdate")))=false then
                            response.Write rs("aydltdate")
                            else
                            response.Write "-"
                            end if
                            %>
                            </td>
                            <td>
                            <a href="mydingdan_daili_cha?did=<%=rs("aydluserid")%>" target="_blank">查看订单</a>  
							<%
                            if rs("aydlistongguo")=0 then%>
                            <a href="?act=tongguo&id=<%=rs("aydlid")%>" onClick="javascript:return confirm('您确定要通过申请吗？');">通过申请</a>
                            <a href="?act=jujue&id=<%=rs("aydlid")%>" onClick="javascript:return confirm('您确定要拒绝申请吗？');">拒绝申请</a>
                            
                            <%elseif rs("aydlistongguo")=1 then%>
                            <a href="dailitongbu?act=alltongbu&benid=<%=rs("aydluserid")%>">代理同步</a>
                            <a href="dailiedit?act=edit&id=<%=rs("aydlid")%>" >代理设置</a> 
                            <a href="?act=quxiaodl&id=<%=rs("aydlid")%>" onClick="javascript:return confirm('您确定要取消代理吗？');">取消代理</a>
                            
                            <%elseif rs("aydlistongguo")=2 then%>
                            <a href="?act=huifudl&id=<%=rs("aydlid")%>" onClick="javascript:return confirm('您确定要删除代理吗？');">恢复代理</a>
                            <a href="?act=sdel&id=<%=rs("aydlid")%>" onClick="javascript:return confirm('您确定要删除代理吗？');">删除代理</a>
                            
                            <%elseif rs("aydlistongguo")=3 then%>
                            <a href="?act=sdel&id=<%=rs("aydlid")%>" onClick="javascript:return confirm('您确定要删除代理吗？');">删除代理</a>
                            <%else
                            response.Write "-"
                            end if%>
                            </td>
                        </tr>
					  <%
                        else%>
                        <tr class="hd">
                            <td>-</td>
                            <td>-</td>
                            <td>-</td>
                            <td>-</td>
                            <td>-</td>
                            <td>&nbsp;</td>
                            <td>-</td>
                            <td>-</td>
                            <td><a href="?act=sdel&id=<%=rs("aydlid")%>" onClick="javascript:return confirm('您确定要删除代理吗？');">删除代理</a></td>
                        </tr>
						<%end if  
                        rsu.close
                        
                    rs.movenext 
                    loop%>
                    
                    <tr>
                    <td colspan="9"><br>
                    <input type="button" name="button2" value="向所有下级代理同步商品状态" class="logindlreg" id="alltongbu" onclick="return tongbu()" ><br>
                    <input name="istdaili" type="checkbox" id="istdaili">同步代理价格与批发优惠代理价
                    </td>
                    </tr>
					<%else%>
                    <tr><td height="35" colspan="9" align="center" > 还没有下级代理信息！</td></tr>
                    <%
                    end if
                    rs.close%>
                    </table>
                    </form>
            		</div>
                    <div class="gexian20"></div>
            <!-------------------------------------- 结束 -------------------------------------->           
            
            <div class="gexian20"></div>
            <div class="mzsmbox2" style="padding-top:20px;">
            同步：向所有下级同步，仅同步分类与商品的上架状态，名称，删除，新增，是否限购，批发等<br> 
            提示：向所有下级同步，商品的代理价格不会被同步，商品的代理价格可在代理设置中单独设置，或勾选&ldquo;同步代理价格与批发优惠代理价&rdquo;。<br> 
            注意：单独同步代理关系，将同时同步代理价格与批发代理价格
            </div>
           

        <div class="clearfix"></div>
        


</div>








</div>
</div>
</div>
</div>
</main>


<footer>
<div class="container">
</div>
</footer>

</body>
</html>