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

<%
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

%>


<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>



<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="gexian"></div>
		    <%
                          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")
                          %>
                    	<form action="?act=add" method="post" name="form" id="form" onSubmit="return check_add()">
                        <table class="neitableanquan" width="1080">
           		  		<tr>
                          <td colspan="2" align="center" width="100">所有商品：</td>
                            <td width="310"><input name="suoyou" type="checkbox" id="suoyou" value="1" checked> 允许</td>
                          <td><div class="regts" > 适用所有商品，以及日后添加的商品，勾选此项时，以下两项设置无效</div></td>
                        </tr>
                 		<tr>
                            <td colspan="2" align="center">商品分类：</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
                          %>
                          </select>
                            </td>
                            <td><div class="regts" > 多选  ctrl+选择</div></td>
                        </tr>
                 		<tr>
                            <td colspan="2" align="center">适用商品：</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>
                            </td>
                            <td><div class="regts" > 多选  ctrl+选择</div></td>
                        </tr>
                        
           		  		<tr>
                            <td colspan="2" align="center">重复使用：</td>
                            <td><input name="ayyouhuiisty" type="checkbox" id="ayyouhuiisty" value="1" /> 允许</td>
                          <td><div class="regts" > 该优惠券允许多买家多次重复使用</div></td>
                        </tr>
           		  		<tr>
                            <td colspan="2" align="center">添加数量：</td>
                            <td><input name="geshu" type="text" class="reginputd" id="geshu" value="10" maxlength="3"></td>
                          <td><div class="regts" > 单次生成不得超过200个</div></td>
                        </tr>
           		  		<tr>
                            <td colspan="2" align="center">优惠券价值：</td>
                            <td>
                            <input name="jiage" class="reginputd" type="text" id="jiage" value="1" maxlength="3">
                            <select name="fangshi" id="fangshi" class="reginputdddd">
                              <option value="0">元</option>
                              <!--<option value="1">%</option>-->
                            </select>
                            </td>
                          <td><div class="regts" > 此项为整数 为优惠的金额</div></td>
                        </tr>
           		  		<tr>
                            <td colspan="2" align="center">优惠券时效：</td>
                            <td><input name="shixiao" class="reginputd" type="text" id="shixiao" value="30" maxlength="3">
                            <select name="" id="" class="reginputdddd">
                              <option value="0">天</option>
                            </select>
                            </td>
                          <td><div class="regts" > 时效以天做单位 不得超过365天 优惠券过期后 系统将自动删除</div></td>
                        </tr>
                        
                 		<tr>
                            <td colspan="2" height="50"></td>
                            <td colspan="2"><input style="cursor:pointer" class="logindlreg" type="submit" name="Submit" value=" 添 加 优 惠 券 " ></td>
                        </tr>
                    </table>
            </form>
            <!-------------------------------------- 结束 -------------------------------------->
                   


                                                                 
                   
            <div class="gexian20"></div>
            <div class="mzsmbox2" style="padding-top:20px;">
            提示：优惠券价值不得高于订单价格50%并禁止0元交易，请参考商品实际情况添加优惠券
            </div>
          </div>
            
           




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



</div>








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


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

</body>
</html>