<!--#include virtual="/inc/conn.asp"-->
<!--#include virtual="/inc/chkuser.asp"-->
<%
call lognameadmin()

set rs2=server.CreateObject("adodb.recordset")



if request.QueryString("act")="del" then
																						 '上级代理商家ID
		sql="select aygooddlid,aygoodid,aysjgid,aygoodsuoyouid,aychenben from aygood where aygooddlid<>0 order by aygoodid desc" 
		rs.open sql,conn,1,3
		if not(rs.bof and rs.eof) then
		
					do while not(rs.eof) 
					
										'上级商品ID
									if rs("aysjgid")<>"" then

										sql2="select aygoodid,aysjgid,aychenben from aygood where aygoodid="&rs("aysjgid")&"" 
										rs2.open sql2,conn,1,1
										if not(rs2.bof and rs2.eof) then
											if ccur(rs("aychenben"))<ccur(rs2("aychenben")) then
											rs.delete
											end if
										else
											rs.delete
										end if
										rs2.close

									else
									rs.delete
									end if
										
					rs.movenext
					loop
		
		
		
		else
		response.Write "【平台未找到代理商品】"
		end if
		rs.close


response.Write "已删除成功"
response.End()

end if


'单独删除ID
if request.QueryString("act")="delsp" then

	id=request.QueryString("id")
	
	if id="" then 
	response.Write "ID ERR"
	response.End()
	end if
	
	conn.execute("delete from aygood where aygoodid="&id&"")
	
	response.Write id&"上已删除"
	response.End()

end if

%>
<a href="?act=del">【删除有问题的代理商品】</a><br><br>
<%

'查找本地商品=下级代理商品	rs	 												  上级代理商家ID
sql="select aygooddlid,aygoodid,aysjgid,aygoodsuoyouid,aychenben from aygood where aygooddlid<>0 order by aygoodid desc" 
rs.open sql,conn,1,3
if not(rs.bof and rs.eof) then

			do while not(rs.eof) 
							
								'上级商品ID
							if rs("aysjgid")<>"" then
							
									'rs2 获取上级商品信息
									sql2="select aygoodid,aysjgid,aychenben from aygood where aygoodid="&rs("aysjgid")&"" 
									rs2.open sql2,conn,1,1
									if not(rs2.bof and rs2.eof) then
												
												'本商品成本价		'上级商品成本价
										if ccur(rs("aychenben"))<ccur(rs2("aychenben")) then
										response.Write "本地商户ID-"&rs("aygoodsuoyouid")&"&nbsp;&nbsp;本地商品ID-"&rs("aygoodid")&"  本地商品成本价&nbsp;"&Formatnumber(rs("aychenben"),3,true,-1,0)&"&nbsp;&nbsp;"
										response.Write "上级代理商品成本价&nbsp;"&Formatnumber(rs2("aychenben"),3,true,-1,0)&"&nbsp;&nbsp;<span style='color:#F00'><a href=?act=delsp&id="&rs("aygoodid")&">【本地商品成本价低于上级代理成本价】</a></span> <br>"
										end if
									
									else
										response.Write "本地商户ID-"&rs("aygoodsuoyouid")&"&nbsp;&nbsp;本地商品ID-"&rs("aygoodid")&"  本地商品成本价&nbsp;"&Formatnumber(rs("aychenben"),3,true,-1,0)&"&nbsp;&nbsp;"
										response.Write "&nbsp;&nbsp;<span style='color:#F00'><a href=?act=delsp&id="&rs("aygoodid")&">【未找到上级代理商品ID】</a></span><br>"
									end if
									rs2.close
								
							else
							response.Write "本地商户ID-"&rs("aygoodsuoyouid")&"&nbsp;&nbsp;本地商品ID-"&rs("aygoodid")&"  本地商品成本价&nbsp;"&Formatnumber(rs("aychenben"),3,true,-1,0)&"&nbsp;&nbsp;"
							response.Write "&nbsp;&nbsp;本地商品ID-"&rs("aygoodid")&"-<span style='color:#F00'><a href=?act=delsp&id="&rs("aygoodid")&">【本地商品显示的上级商品ID为空值】</a></span><br>"
							end if
								
			rs.movenext
			loop





else
response.Write "【平台没有代理商品】"
end if
rs.close
%>