Forráskód Böngészése

频繁发的测试

chenjunkai 5 éve
szülő
commit
64bfa10a3e
2 módosított fájl, 135 hozzáadás és 111 törlés
  1. 31 17
      controller/Lottery.py
  2. 104 94
      web/ansjer_answer/lottery/index.html

+ 31 - 17
controller/Lottery.py

@@ -147,29 +147,43 @@ class drawView(TemplateView):
         if tko.code == 0:
             phone = tko.userID
             qs = phoneNumModel.objects.filter(phone=phone, status=0)
-            # if True:
-            if qs.exists():
-                test = randomMachine()
+            if True:
+            # if qs.exists():
                 # status c611=>1 , c612=>2 ,不中间=>3
                 # 权重
-                test.setWeight({1: 1, 2: 1, 3: 1})
-                has_chow = test.drawing()
+                test = randomMachine()
+                # test.setWeight({1: 1, 2: 1, 3: 50})
+                # has_chow = test.drawing()
                 user = phoneNumModel.objects.filter(phone=phone)
                 count_1 = phoneNumModel.objects.filter(status=1).count()
                 count_2 = phoneNumModel.objects.filter(status=2).count()
-                print('has_chow')
+                print('count_1')
+                print(count_1)
+                print('count_2')
+                print(count_2)
+                if count_1 >= 5 > count_2:
+                    print('type1')
+                    # 权重组
+                    chow_weight = {2: 1, 3: 50}
+                    test.setWeight(chow_weight)
+                    has_chow = test.drawing()
+                elif count_1 < 5 <= count_2:
+                    print('type2')
+                    chow_weight = {1: 1, 3: 50}
+                    test.setWeight(chow_weight)
+                    has_chow = test.drawing()
+                elif count_2 == 5 == count_2:
+                    print('type3')
+                    has_chow = 3
+                else:
+                    print('type4')
+                    chow_weight = {1: 1, 2: 1, 3: 50}
+                    test.setWeight(chow_weight)
+                    has_chow = test.drawing()
+                # 如果抽奖额度满了
                 print(has_chow)
-                if has_chow == 1 and count_1 == 5:
-                    print('count1')
-                    print(count_1)
-                    user.update(status=3)
-                    return response.json(0, {'status': 3})
-                if has_chow == 2 and count_2 == 5:
-                    print('count2')
-                    print(count_2)
-                    user.update(status=3)
-                    return response.json(0, {'status': 3})
-                user.update(status=has_chow)
+
+            # user.update(status=has_chow)
                 return response.json(0, {'status': has_chow})
             else:
                 # 您已抽过奖

+ 104 - 94
web/ansjer_answer/lottery/index.html

@@ -106,7 +106,9 @@
     <p>适用浏览器:360、FireFox、Chrome、Safari、Opera、傲游、搜狗、世界之窗. 不支持IE8及以下浏览器。</p>
 </div>
 
-<div style="height: 30px; line-height: 30px; background: #28BD19; display: none;  text-align: center; color: white;" id="error">错误提示</div>
+<div style="height: 30px; line-height: 30px; background: #28BD19; display: none;  text-align: center; color: white;"
+     id="error">错误提示
+</div>
 <!--进来抽奖的界面-->
 <div style="display: none;" id="drawTab">
     <div class="turntable-bg">
@@ -114,13 +116,13 @@
         <div class="rotate"><img id="rotate" src="images/turntable.png" alt="turntable" style="width:100%;height:100%;">
         </div>
     </div>
-    
+
     <div style="display: none;" id="to_drawTab">
-		<div style='padding-top: 30px;text-align: center;color: white;'>用户名:<span id="username"></span>
-		<a onclick='DetailsTab()'>中奖记录</a>
-		</div>	
-	</div>
-    
+        <div style='padding-top: 30px;text-align: center;color: white;'>用户名:<span id="username"></span>
+            <a onclick='DetailsTab()'>中奖记录</a>
+        </div>
+    </div>
+
     <div id="loginFormID" style="display: block;text-align: center;     color: #90807b;">
         <div style="margin-top: 40px;"><input type="text" id="phone" maxlength="11" placeholder="输入手机号码"
                                               value="" style="height: 30px; width: 250px;"><span
@@ -178,7 +180,7 @@
 
 </script>
 <script type="text/javascript">
-	setTimeout('$("#drawTab").fadeIn(1500);', 10);
+    setTimeout('$("#drawTab").fadeIn(1500);', 10);
     let draw_status = 0; //中奖状态
 
     function setCookie(key, val, seconds) {
@@ -218,7 +220,7 @@
                             $("#rec_addr").val(addrJson['rec_addr'])
                         }
                     } else {
-                    	console.log(data['msg'])
+                        console.log(data['msg'])
                     }
                 }
             );
@@ -228,52 +230,59 @@
     }
 
     function DetailsTab() {
-        if (draw_status == 1 || draw_status == 2) {
-//      	alert('恭喜你');
+        if (draw_status == 1) {
+            alert('恭喜你中奖 获得一台c611');
             $('#drawTab').hide();
             $('#detailsTab').show();
-        } else {
-//          alert( '很遗憾,你没有中奖');
-//			$("#error").html("很遗憾,你没有中奖");
-//			setTimeout('$("#error").fadeIn(1);', 100);
-//			setTimeout('$("#error").fadeOut(2000);', 100);
+            return
+        }
+        if (draw_status == 2) {
+            alert('恭喜你中奖 获得一台c612');
+            $('#drawTab').hide();
+            $('#detailsTab').show();
+            return;
+        }
+        if (draw_status == 3) {
+            alert('很遗憾,你没有中奖');
+            return;
         }
     }
-    
-    var phone_countdown=60;
+
+    var phone_countdown = 60;
+
     function phone_settime() {
-		if(phone_countdown == 0) {
-			$("#get_code").html("获取验证码");
-			phone_countdown = 60;
-			return;
-		} else {
-			$("#get_code").html("重新发送(" + phone_countdown + ")");
-			phone_countdown--;
-		}
-		setTimeout(function() {
-			phone_settime()
-		}, 1000)
-	}
+        if (phone_countdown == 0) {
+            $("#get_code").html("获取验证码");
+            phone_countdown = 60;
+            return;
+        } else {
+            $("#get_code").html("重新发送(" + phone_countdown + ")");
+            phone_countdown--;
+        }
+        setTimeout(function () {
+            phone_settime()
+        }, 1000)
+    }
 
     //获取验证码方法
     function authCode() {
         let phone = $('#phone').val();
-        if(phone==""){
-			alert("手机不可以为空!");
-			$('#phone').focus();
-			return;
-		}else if(!/^1[0-9]{10}$/.test(phone)){
-			alert("手机不正确!");
-			$('#phone').focus();
-			return;
-		}
+        if (phone == "") {
+            alert("手机不可以为空!");
+            $('#phone').focus();
+            return;
+        } else if (!/^1[0-9]{10}$/.test(phone)) {
+            alert("手机不正确!");
+            $('#phone').focus();
+            return;
+        }
         let post_data = {'phone': phone}
         // 初始化目录
         $.postJSON(
             http_ip_prot + 'lottery/authcode', JSON.stringify(post_data),
             function (data) {
                 if (data['code'] == 0) {
-					phone_settime();
+                    phone_settime();
                 } else {
                     alert(data['msg'])
                 }
@@ -285,22 +294,22 @@
     function doAuthLogin() {
         let phone = $('#phone').val();
         let authcode = $('#code').val();
-      
-		if(phone==""){
-			alert("手机不可以为空!");
-			$('#phone').focus();
-			return;
-		}else if(!/^1[0-9]{10}$/.test(phone)){
-			alert("手机不正确!");
-			$('#phone').focus();
-			return;
-		}
-		if(authcode==""){
-			alert("验证码不可以为空!");
-			$('#code').focus();
-			return;
-		}
-		
+
+        if (phone == "") {
+            alert("手机不可以为空!");
+            $('#phone').focus();
+            return;
+        } else if (!/^1[0-9]{10}$/.test(phone)) {
+            alert("手机不正确!");
+            $('#phone').focus();
+            return;
+        }
+        if (authcode == "") {
+            alert("验证码不可以为空!");
+            $('#code').focus();
+            return;
+        }
+
         let post_data = {
             'phone': phone,
             'authcode': authcode
@@ -313,9 +322,9 @@
                     setCookie('access_token', data['res']['access_token'], data['res']['access_expire'])
                     setCookie('refresh_token', data['res']['refresh_token'], data['res']['refresh_expire'])
 //                  InitIndex()
- 						$("#username").html(phone);
-                        $("#loginFormID").hide();
-                        $('#to_drawTab').show();
+                    $("#username").html(phone);
+                    $("#loginFormID").hide();
+                    $('#to_drawTab').show();
                 } else {
                     alert(data['msg'])
                 }
@@ -344,10 +353,10 @@
                         console.log('很遗憾没有中奖');
                     }
                     doDrawRollAction(status);
-                } else if(data['code']==309) {
+                } else if (data['code'] == 309) {
                     alert('请绑定手机再来抽奖吧!');
-                } else{
-                	alert(data['msg']);
+                } else {
+                    alert(data['msg']);
                 }
             },
             false,//异步
@@ -386,12 +395,12 @@
 
     //获取验证码
     $('#get_code').click(function () {
-    	if (phone_countdown == 60){
-    		authCode();
-    	}else{
-    		confirm("不要频繁点击获取验证码!");
-    	}
-        
+        if (phone_countdown == 60) {
+            authCode();
+        } else {
+            confirm("不要频繁点击获取验证码!");
+        }
+
     });
     //# 登录
     $('#loginId').click(function () {
@@ -403,8 +412,6 @@
     });
 
 
-	
-	
     InitIndex()
 
     var bRotate = false;
@@ -419,7 +426,10 @@
             callback: function () {
                 //alert("¥" + txt);
                 alert(txt)
-                DetailsTab();
+                if (draw_status == 1 || draw_status == 2) {
+                    $('#drawTab').hide();
+                    $('#detailsTab').show();
+                }
                 bRotate = !bRotate;
             }
         })
@@ -431,22 +441,22 @@
         //var a = [0, 1, 2, 3, 4, 5, 6];
         doDraw()
     });
-    
-    if($.cookie("rmbUser") == "true") {
-		let index_num_cookie = $.cookie('index_num');
-		console.log(index_num_cookie) 
-		if(index_num_cookie==2){
-			$.cookie("index_num", 3, {expires: 7}); //7天
-        	let index_num_cookie = $.cookie('index_num');
-        	console.log(index_num_cookie)
-		}else if(index_num_cookie==1){
-			window.location.href="../subject.html";
-		}else if(index_num_cookie==3){
+
+    if ($.cookie("rmbUser") == "false") {
+        let index_num_cookie = $.cookie('index_num');
+        console.log(index_num_cookie)
+        if (index_num_cookie == 2) {
+            $.cookie("index_num", 3, {expires: 7}); //7天
+            let index_num_cookie = $.cookie('index_num');
+            console.log(index_num_cookie)
+        } else if (index_num_cookie == 1) {
+            window.location.href = "../subject.html";
+        } else if (index_num_cookie == 3) {
 //			window.location.href="index.html";
-		}else{
-			window.location.href="../index.html";
-		}
-	}
+        } else {
+            window.location.href = "../index.html";
+        }
+    }
 
     function doDrawRollAction(status) {
         //抽奖值
@@ -554,16 +564,16 @@
                 break;
         }
     }
-    
+
 </script>
 <script type="text/javascript">
-    var ua = navigator.userAgent.toLowerCase();
-    var isWeixin = ua.indexOf('micromessenger') != -1;
-    var isAndroid = ua.indexOf('android') != -1;
-    var isIos = (ua.indexOf('iphone') != -1) || (ua.indexOf('ipad') != -1);
-    if (!isWeixin) {
-        document.head.innerHTML = '<title>抱歉,出错了</title><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0"><link rel="stylesheet" type="text/css" href="weua.css">';
-        document.body.innerHTML = '<div class="weui_msg"><div class="weui_icon_area"><i class="weui_icon_info weui_icon_msg"></i></div><div class="weui_text_area"><h4 class="weui_msg_title">请在微信客户端打开链接</h4></div></div>';
+   // var ua = navigator.userAgent.toLowerCase();
+    //var isWeixin = ua.indexOf('micromessenger') != -1;
+    //var isAndroid = ua.indexOf('android') != -1;
+    //var isIos = (ua.indexOf('iphone') != -1) || (ua.indexOf('ipad') != -1);
+    //if (!isWeixin) {
+     //   document.head.innerHTML = '<title>抱歉,出错了</title><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0"><link rel="stylesheet" type="text/css" href="weua.css">';
+       // document.body.innerHTML = '<div class="weui_msg"><div class="weui_icon_area"><i class="weui_icon_info weui_icon_msg"></i></div><div class="weui_text_area"><h4 class="weui_msg_title">请在微信客户端打开链接</h4></div></div>';
     }
 </script>
 </body>