<!--#include virtual="/show/userhead.asp"-->

<script>document.getElementById('o_7').setAttribute("class", "ed"); document.getElementById("t_7").style.display="";document.getElementById('s_7_2').setAttribute("class", "ed6");</script>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<title><%=webname%>-优惠券</title> 

<script language=javascript>
function CheckIfEnglish( String )<!--检验表单必须是字母或数字-->
{ 
    var Letters = "abcdefghijklmnopqrstuvwxyz0123456789-";
     var i;
     var c;
      if(String.charAt( 0 )=='-')
	return false;
      if( String.charAt( String.length - 1 ) == '-' )
          return false;
     for( i = 0; i < String.length; i ++ )
     {
          c = String.charAt( i );
	  if (Letters.indexOf( c ) < 0)
	     return false;
     }
     return true;
}
function CheckIfid( String )<!--检验表单必须是数字-->
{ 
    var Letters = "1234567890";
     var i;
     var c;
      if(String.charAt( 0 )=='-')
	return false;
      if( String.charAt( String.length - 1 ) == '-' )
          return false;
     for( i = 0; i < String.length; i ++ )
     {
          c = String.charAt( i );
	  if (Letters.indexOf( c ) < 0)
	     return false;
     }
     return true;
}
function Checkjinid( String )<!--检验表单必须是数字-->
{ 
    var Letters = "1234567890.";
     var i;
     var c;
      if(String.charAt( 0 )=='-')
	return false;
      if( String.charAt( String.length - 1 ) == '-' )
          return false;
     for( i = 0; i < String.length; i ++ )
     {
          c = String.charAt( i );
	  if (Letters.indexOf( c ) < 0)
	     return false;
     }
     return true;
}
function ischinese(s)<!--检验表单必须是中文-->
{
var ret=true;
for(var i=0;i<s.length;i++)
ret=ret && (s.charCodeAt(i)>=10000);
return ret;
}
</script>
<script language=javascript>
function check_add()
{
   
   if(form.geshu.value=="" || !CheckIfid(form.geshu.value))
   {alert("数量填写错误");return false}
    if(form.geshu.value > 200)
	{alert("单次生成数量不得超过200");return false;}
   
   if(form.jiage.value=="" || !CheckIfid(form.jiage.value))
   {alert("价格填写错误");return false}
     if(form.jiage.value < 1)
	{alert("价格填写错误 应大于0");return false;}
	
   if(form.shixiao.value=="" || !CheckIfid(form.shixiao.value))
   {alert("时效填写错误");return false}
	if(form.shixiao.value > 365)
	{alert("时效填写错误 不得大于365");return false;}
    
}
</script>
<%
Function RndNumber(Min,Max) 
Randomize 
RndNumber=Int((Max - Min + 1) * Rnd() + Min) 
End Function 

act=SafeRequest("act")

if act="add" then
feileiid=SafeRequestform("feileiid")
shangid=SafeRequestform("shangid")
geshu=SafeRequestform("geshu")
fangshi=SafeRequestform("fangshi")
jiage=SafeRequestform("jiage")
shixiao=SafeRequestform("shixiao")
suoyou=SafeRequestform("suoyou")
ayyouhuiisty=SafeRequestform("ayyouhuiisty")

if ayyouhuiisty="" then ayyouhuiisty=0
if suoyou="" then
if feileiid="" and shangid="" then call PopErr("分类和商品必须选定一个")
end if

if geshu="" then call PopErr("数量填写错误")
if jiage="" then call PopErr("价格填写错误")
if shixiao="" then call PopErr("时效填写错误")

sql="select * from ayyouhuiquan" 
rs.open sql,conn,1,3

for i=1 to cint(geshu)

suiji=RndNumber(10000000,99999999)&minute(now())&RndNumber(1000000,9999999)

	rs.addnew
	rs("ayyouhuiquan")=suiji
	rs("ayyouhuisuoyou")=clng(request.Cookies("aynameid"))
	rs("ayyouhuifangshi")=cint(fangshi)
	rs("ayyouhuijiage")=cint(jiage)
	rs("ayyouhuidate")=now()
	rs("ayyouhuishixiao")=cint(shixiao)
	rs("ayyouhuiisty")=ayyouhuiisty
	if feileiid<>"" then rs("ayyouhuiflid")=feileiid
	if shangid<>"" then rs("ayyouhuishangid")=shangid
	if suoyou<>"" then rs("ayyouhuiall")=cint(suoyou)
	rs.update
next
	rs.close
	call logadd(request.Cookies("aynameid"),"优惠券添加成功",0,0)
	call PopErr2("优惠券已添加成功","myyouhui")
end if

%><br>
<DIV id=main2> 
<DIV style="PADDING-LEFT:0px">
<DIV id=main_right_content>


<H2><SPAN>优惠券</SPAN></H2>
<DIV class=main3>
	  <%
	  sql="select * from aykafenlei where aykanamesuoyou="&request.Cookies("aynameid")&" and ayshangjiid=0 order by aykafenleisx asc" 
	  rs.open sql,conn,1,1
	  if rs.bof and rs.eof then 
	  call PopErr2("请先添加商品分类","fenlei")
	  else
	  %>
<form action="?act=add" method="post" name="form" id="form" onSubmit="return check_add()">
  <table width="99%" border="0" align="center" cellpadding="0" cellspacing="5" class="table_style_a1">
    <tr>
      <td colspan="2">
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#F00">提示：优惠券价值不得高于订单价格50%并禁止0元交易，请参考商品实际情况添加优惠券</span>
      </td>
      </tr>
    <tr>
      <td width="140" align="center">允许所有商品：</td>
      <td><input name="suoyou" type="checkbox" id="suoyou" value="1" checked>
        <span style="color: #999999">（所有商品分类以及所有商品均可以使用优惠券 包括新添加的分类和商品 勾选此项时 以下两项设置无效）</span></td>
    </tr>
    
    
    <tr>
      <td align="center">允许使用的商品分类：<br>
        允许多选  ctrl+选择</td>
      <td><select name="feileiid" size="8" multiple id="feileiid" style="width:300px" >
        <%do while not rs.eof%>
        <option value="<%=rs("aykafenleiid")%>"><%=rs("aykafenleiname")%></option>
        <%
			set rserji=server.CreateObject("adodb.recordset")
			sql="select * from aykafenlei where aykanamesuoyou="&request.Cookies("aynameid")&" and ayshangjiid="&rs("aykafenleiid")&" order by aykafenleisx asc" 
			rserji.open sql,conn,1,1
			if not(rserji.bof and rserji.eof) then
			do while not rserji.eof%>
        <option value="<%=rserji("aykafenleiid")%>">&nbsp;&nbsp;┕<%=rserji("aykafenleiname")%></option>
        <%
			rserji.movenext 
			loop
	    	rserji.close
			end if
	  rs.movenext 
	  loop
	  rs.close
	  end if
	  %>
      </select>
       </td>
    </tr>
    <tr>
      <td align="center">允许使用的商品：<br>允许多选 ctrl+选择</td>
      <td>
	  	  <%
	  sql="select * from aygood where aygoodsuoyouid="&request.Cookies("aynameid")&" order by aygoodsx asc" 
	  rs.open sql,conn,1,1
	  if rs.bof and rs.eof then 
	  call PopErr2("请先添加商品分类","fenlei")
	  else
	  %>
	  <select name="shangid" size="8"  multiple id="shangid" style="width:300px" >
        <%do while not rs.eof%>
        <option value="<%=rs("aygoodid")%>"><%=rs("aygoodname")%></option>
	  <%
	  rs.movenext 
	  loop
	  rs.close
	  end if
	  %>
      </select> <br><span style="color: #999999">（注意：优惠券使用顺序为 首先允许使用商品分类 商品分类未设置的 则选择允许使用的商品)</span></td>
    </tr>
    <tr>
      <td align="center">允许重复使用</td>
      <td><input name="ayyouhuiisty" type="checkbox" id="ayyouhuiisty" value="1" />
	  <span style="color: #999999">（该优惠券允许多买家多次重复使用）</span></td>
    </tr>
    <tr>
      <td align="center">生成优惠券数量：</td>
      <td><input name="geshu" type="text" class="inputty" id="geshu" value="10" size="7" maxlength="3">
      个 <span style="color: #999999">（单次生成不得超过200个）</span></td>
    </tr>
    <tr>
      <td align="center">优惠券价值：</td>
      <td><p>
        <input name="jiage" class="inputty" type="text" id="jiage" value="1" size="7" maxlength="3">
        <select name="fangshi" id="fangshi" >
          <option value="0">元</option>
          <!--<option value="1">%</option>-->
        </select> 
        <span style="color: #999999">（此项为整数 为优惠的金额）</span></p>
       </td>
    </tr>
    <tr>
      <td align="center">优惠券时效：</td>
      <td><input name="shixiao" class="inputty" type="text" id="shixiao" value="30" size="7" maxlength="3">
      天 <span style="color: #999999">（时效以天做单位 不得超过365天 优惠券过期后 系统将自动删除）</span></td>
    </tr>
    <tr>
      <td colspan="2" align="center"><input style="cursor:pointer"  class="butbaocun" type="submit" name="Submit" value=" 生 成 优 惠 券 "></td>
      </tr>
  </table>
</form>
</DIV>
 

</DIV></DIV>
<DIV class=clear></DIV></DIV>
</DIV>

<br>

	<!--#include virtual="/show/foot.asp"-->

