Browse Source

添加抽奖验证码

wangshan 9 years ago
parent
commit
c054ab13bf

+ 7 - 0
core/src/qfw/active/activemanage.go

@@ -5,6 +5,7 @@ package active
 
 import (
 	"fmt"
+	"github.com/dchest/captcha"
 	"github.com/go-xweb/xweb"
 	"gopkg.in/mgo.v2/bson"
 	"math/rand"
@@ -88,9 +89,15 @@ func (a *Activemanage) Luckdraw(activecode, id string) error {
 
 //
 func (a *Activemanage) Getluckdraw() error {
+	fmt.Println("checkcode:", a.GetString("checkCodeId"))
 	flog := "F"
 	//提示语
 	msg := ""
+	if a.GetSession("CheckCodeId") == nil || !captcha.VerifyString(a.GetSession("CheckCodeId").(string), a.GetString("checkCodeId")) {
+		flog := "M"
+		msg = "验证码错误!请重新输入验证码!"
+		return a.Write(`{"flog":"` + flog + `","msg":"` + msg + `"}`)
+	}
 	id := ""
 	today := time.Now()
 	openid := a.GetSession("s_m_openid").(string)

+ 1 - 1
core/src/timetask.json

@@ -1 +1 @@
-{"comment":{"c_rate":720,"commentrate":900},"market":{"demand":{"attr":["i_hits","i_bids","i_status"],"timepoint":"2016-01-27 17:58:50"},"service":{"attr":["i_hits","i_sales","i_comments","i_score","i_appcounts"],"timepoint":"2016-01-27 17:58:50"}},"marketisstart":true,"marketrate":300}
+{"comment":{"c_rate":720,"commentrate":900},"market":{"demand":{"attr":["i_hits","i_bids","i_status"],"timepoint":"2016-01-28 09:39:35"},"service":{"attr":["i_hits","i_sales","i_comments","i_score","i_appcounts"],"timepoint":"2016-01-28 09:39:35"}},"marketisstart":true,"marketrate":300}

+ 104 - 36
core/src/web/templates/active/luckdraw.html

@@ -21,7 +21,7 @@
 .lotteryMain{ width:100%;}
 .lotteryBg{ width:100%; height:608px; margin:0 auto; background:url(/images/activeimages/lotteryBg.png) no-repeat top center; position:relative; overflow:hidden;background-size: 375px 508px;}
 #run{ width:145px; height:145px; position:absolute; left:50%; top:50%;  margin-left:-73px; margin-top:-53px; z-index:1; transform:rotate(0deg); -ms-transform:rotate(0deg); }
-#btn_run{ width:80px; height:80px; background:url(/images/activeimages/btn_start.png) no-repeat; border:none; outline:none; position:absolute; left:50%; top:50%; margin-left:-40px; margin-top:-22px; z-index:2;cursor:pointer;background-position:0px 0px;background-size: 100% 100%;}
+#btn_run_one{ width:80px; height:80px; background:url(/images/activeimages/btn_start.png) no-repeat; border:none; outline:none; position:absolute; left:50%; top:50%; margin-left:-40px; margin-top:-22px; z-index:2;cursor:pointer;background-position:0px 0px;background-size: 100% 100%;}
 .col-xs-12 p{
 	margin:0px 0px 5px;
 }
@@ -33,6 +33,52 @@
    data-target="#myModal">
    开始
 </button>
+<button class="btn btn-primary btn-lg mycode  hidden" data-toggle="modal" 
+   data-target="#mycode">
+   开始
+</button>
+
+
+<!-- 模态框(Modal) -->
+<div class="modal fade" id="mycode" tabindex="-1" role="dialog" 
+   aria-labelledby="myModalLabel" aria-hidden="true" style="padding-top: 25%;">
+   <div class="modal-dialog">
+      <div class="modal-content">
+	
+         <div class="modal-header">
+            <button type="button" class="close" 
+               data-dismiss="modal" aria-hidden="true" style="width: 40px;height: 30px;">
+                  &times;
+            </button>
+            <h4 class="modal-title" id="myModalLabel">
+               企明星新年大抽奖
+            </h4>
+         </div>
+         <div class="modal-body">
+           	 <div class="form-group" style="margin-top:20px;">
+				<label class="col-md-3 control-label"><span style="color:#D03102;margin-right:5px;">*</span>请输入抽奖验证码:</label>
+				<div class="input-group col-md-6 checkCodeId">
+					<input type="text" name="checkCodeId" class="form-control inputxt" maxlength="4" id="chedkcode" style="height:52px;">
+					<span class="input-group-addon " id="phone-checkCodeId">
+						<img id="phone_captcha" src="/tool/captcha" onClick="reLoadCaptcha('phone_captcha');">
+						<a onClick="reLoadCaptcha('phone_captcha');" class="text-primary">刷新</a>
+					</span>
+				</div>
+			  </div>
+				<div style="margin-top:20px;" class="form-group">
+				<div class="col-sm-2"></div>
+				<div class="col-sm-4 ">
+				<input type="button" class="btn btn-primary" id="btn_run"  value="开始抽奖">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+				</div>
+				<div class="col-sm-6"></div>
+				</div>
+	
+         </div>
+         <div class="modal-footer">
+         </div>
+      </div><!-- /.modal-content -->
+</div><!-- /.modal -->
+</div>
 <!-- 模态框(Modal) -->
 <div class="modal fade" id="myModal" tabindex="-1" role="dialog" 
    aria-labelledby="myModalLabel" aria-hidden="true" style="padding-top: 25%;">
@@ -59,7 +105,7 @@
 <section class="lotteryMain">
 	<div class="lotteryBg">
     	<img id="run" src="/images/activeimages/start.png" />
-        <input id="btn_run" type="button" value="" />
+        <input id="btn_run_one" type="button" value="" />
     </div>
 </section> 
 <div class="col-xs-12" style="color:#fff; margin-top:-135px;font-weight:600;">
@@ -73,54 +119,76 @@
 </div> 
 <script>
 
+
+function reLoadCaptcha(){
+	document.getElementById('phone_captcha').src='/tool/captcha?rnd='+Math.random()
+}
 $(function(){ 
+	$("#btn_run_one").click(function(){
+		$(".mycode").click();
+	    });
     var flog = {{.T.flog}};
 	if (flog == "A"){
 		$(".modal-body").html("{{.T.msg}}")
 		$(".modstart").click();
-		$("#btn_run").attr('disabled',true).css("cursor","pointer").css("background","url(/images/activeimages/btn_end.png) no-repeat").css("background-size","100% 100%");
+		$("#btn_run_one").attr('disabled',true).css("cursor","pointer").css("background","url(/images/activeimages/btn_end.png) no-repeat").css("background-size","100% 100%");
 	}else if (flog == "B"){
 		$(".modal-body").html("{{.T.msg}}")
 		$(".modstart").click();
-		$("#btn_run").attr('disabled',true).css("cursor","pointer").css("background","url(/images/activeimages/btn_end.png) no-repeat").css("background-size","100% 100%");
+		$("#btn_run_one").attr('disabled',true).css("cursor","pointer").css("background","url(/images/activeimages/btn_end.png) no-repeat").css("background-size","100% 100%");
 	}
-     $("#btn_run").click(function(){
-		$("#btn_run").attr('disabled',true).css("cursor","default"); 
+
+    $("#btn_run").click(function(){
         lottery(); 
     });
 	
+	
 }); 
 function lottery(){ 
-    $.ajax({ 
-        type: 'post', 
-        url: '/activity/luckdraw', 
-        dataType: 'json', 
-        cache: false, 
-        error: function(){return false;}, 
-        success:function(obj){
-			if (obj.flog == "T"){
-				$("#run").rotate({ 
-					duration:5000, //转动时间 
-					angle: 0, //默认角度
-					animateTo:360*3+obj.rotate, //转动角度 
-					easing: $.easing.easeOutSine, 
-					callback: function(){ 
-						//alert(obj.results); 
-						$("#btn_run").attr('disabled',true).css("cursor","pointer").css("background","url(/images/activeimages/btn_end.png) no-repeat").css("background-size","100% 100%"); 
-							$(".modal-body").html(obj.msg)
-							$(".modstart").click();
-							$("#btn_run").attr('disabled',true).css("cursor","pointer").css("background","url(/images/activeimages/btn_end.png) no-repeat").css("background-size","100% 100%");
-					} 
-				});
-			}else if (obj.flog=="A"){
-				$(".modal-body").html(obj.msg)
-				$(".modstart").click();
-			}else if (obj.flog=="F"){
-				$(".modal-body").html("  小主来晚了,抽奖活动已过期!如果有疑问请联系企明星!")
-				$(".modstart").click();
-			}
-        } 
-    }); 
+	var chedkcode = $("#chedkcode").val();
+	if(chedkcode&&chedkcode.length==4){
+	    $.ajax({ 
+	        type: 'post', 
+	        url: '/activity/luckdraw', 
+			data:{"checkCodeId":chedkcode},
+	        dataType: 'json', 
+	        cache: false, 
+	        error: function(){return false;}, 
+	        success:function(obj){
+				if (obj.flog=="M"){
+					//$("#mycode").modal("show");
+					reLoadCaptcha();
+					return
+				}else if (obj.flog == "T"){
+					$("#mycode").modal("hide");
+					$("#run").rotate({ 
+						duration:5000, //转动时间 
+						angle: 0, //默认角度
+						animateTo:360*3+obj.rotate, //转动角度 
+						easing: $.easing.easeOutSine, 
+						callback: function(){ 
+							//alert(obj.results); 
+								$(".modal-body").html(obj.msg)
+								$(".modstart").click();
+								$("#btn_run_one").attr('disabled',true).css("cursor","pointer").css("background","url(/images/activeimages/btn_end.png) no-repeat").css("background-size","100% 100%");
+						} 
+					});
+				}else if (obj.flog=="A"){
+					$("#mycode").modal("hide");
+					$(".modal-body").html(obj.msg)
+					$(".modstart").click();
+				}else if (obj.flog=="F"){
+					$("#mycode").modal("hide");
+					$(".modal-body").html("  小主来晚了,抽奖活动已过期!如果有疑问请联系企明星!")
+					$(".modstart").click();
+				}
+				
+	        } 
+	    }); 
+	}else{
+		reLoadCaptcha();
+	}
+	
 };
 </script>  
 </body>