From 7cf3b55023b15801be555998966c2dc134b12755 Mon Sep 17 00:00:00 2001
From: hxp <ale99527@vip.qq.com>
Date: 星期五, 05 三月 2021 19:24:32 +0800
Subject: [PATCH] 8840 兑换码支持限制玩家等级可使用(支持角色等级、vip等级;修复非h开头的卡类型不同批次卡可重复使用的bug)

---
 Tool/WebCenter/CouponCode/webapp.py |  112 +++++++++++++++++++++++---------------------------------
 1 files changed, 46 insertions(+), 66 deletions(-)

diff --git a/Tool/WebCenter/CouponCode/webapp.py b/Tool/WebCenter/CouponCode/webapp.py
index 2468ab8..afef13f 100644
--- a/Tool/WebCenter/CouponCode/webapp.py
+++ b/Tool/WebCenter/CouponCode/webapp.py
@@ -50,9 +50,11 @@
         
 Def_CardMsg = {
                0:"CodeRewardSys2", #  鍏戞崲鐮佹棤鏁�
-               1: "CodeRewardSys1", #   鍏戞崲鍗″鍔卞凡鍙戣嚦閭欢
+               1:"CodeRewardSys1", #   鍏戞崲鍗″鍔卞凡鍙戣嚦閭欢
                2:"CodeRewardSys3", #  鍏戞崲鐮佸凡浣跨敤杩�
                3:"CodeRewardSys4",  # 鍚岀被鍨嬪厬鎹㈢爜鍙兘浣跨敤涓�娆�
+               4:"LvErr", # 绛夌骇涓嶈冻
+               5:"VipLevel", # VIP绛夌骇涓嶈冻
          }
                 
                 
@@ -191,6 +193,11 @@
             mylog.debug("common status=2")
             return SendGm(gmresult, pushurl)
         
+        commCheckStatus = CommCheck(dataDict, codeStr)
+        if commCheckStatus != None:
+            gmresult['status'] = commCheckStatus
+            return SendGm(gmresult, pushurl)
+        
         gmresult['status'] = 1
         gmresult['code'] = codeStr
         gmresult['coupontype'] = codeStr  # 缁熶竴鏍煎紡锛屾湇鍔″櫒涓嶄竴瀹氭湁鐢紝鍥哄畾鐮佹牴鎹� codeStr 鍙戝鍔�
@@ -228,63 +235,11 @@
             dbController.update(CouponDB.CouponWXColName, {"code":codeStr, "operateid":operateID}, wxdata)
             # 閫氱煡鍚庡彴璁板綍
             SendDataCollectorBillInfo(wxdata, pushurl, operateID)
-        return 
+        return
     
-    #-----------鎵归噺鍏戞崲鐮佸鐞嗭紝鍚岀被鍨嬪彲閲嶅棰嗗彇----------------------
-    if codeStr.startswith('h'):
-        result, data = dbController.find_one(CouponDB.CouponCodeColName + "_" + agentName, {"code":codeStr, "channel":agentName})
-
-        if not data:
-            #鏃犳鍗�
-            gmresult['status'] = 0
-            mylog.debug("no card")
-            return SendGm(gmresult, pushurl)
-        if int(data['status']) == 1:
-            #宸蹭娇鐢紝鍚屽崱鍙疯褰曢粯璁ゅ彲鐢紝閬垮厤鏂嚎鍙戦�佸け璐ョ殑鎯呭喌锛堟湭杩斿洖缁撴灉楠岃瘉鎯呭喌涓嬶級
-            gmresult['status'] = 2
-            mylog.debug("card used!")
-            return SendGm(gmresult, pushurl)
-        
-        result, data2 = dbController.find_one(CouponDB.CouponBatchColName, {"couponid":data["couponid"]})
-        if not data2:
-            #姝ゆ壒娆″崱宸插垹闄�
-            gmresult['status'] = 0
-            mylog.debug("no couponid")
-            return SendGm(gmresult, pushurl)
-        if int(data2['status']) == 1:
-            #鏆傚仠浣跨敤璇ユ壒娆″崱
-            gmresult['status'] = 0
-            mylog.debug("couponid frozed")
-            return SendGm(gmresult, pushurl)
-        if (data2["minserverno"] != 0 and data2["maxserverno"] != 0):
-            if int(data2["minserverno"]) > sid or int(data2["maxserverno"]) < sid:
-                #涓嶅湪鎸囧畾鍖�
-                gmresult['status'] = 0
-                mylog.debug("no sid")
-                return SendGm(gmresult, pushurl)
-        if data2["expiretime"] != "" and datetime.datetime.today() > GetDateTimeByStr(data2["expiretime"]):
-            #宸茶繃鏈�
-            gmresult['status'] = 0
-            mylog.debug("time pass")
-            return SendGm(gmresult, pushurl)
-        
-        #鍙噸澶嶉鍙栧垯涓嶉獙璇佸悓鎵规鍗�
-        data['status'] = 1
-        data['accid'] = accid
-        data['usetime'] = str(datetime.datetime.today())
-        
-        dbController.update(CouponDB.CouponCodeColName + "_" + agentName, {"code":codeStr, "channel":agentName}, data)
-        # 0 涓嶅彲鐢紝1.鍙敤鍙戞斁濂栧姳 锛�2.宸蹭娇鐢� 3.鍚岀被鍨嬪崱涓嶈兘浣跨敤涓ゆ
-        gmresult['status'] = 1
-        gmresult['code'] = codeStr
-        gmresult['coupontype'] = data["coupontype"]
-        
-        mylog.debug("card ok!")
-        return SendGm(gmresult, pushurl)
-
     #-----------鎵归噺鍏戞崲鐮佸鐞嗭紝鍚岀被鍨嬪彧棰嗗彇涓�娆�----------------------
     result, data = dbController.find_one(CouponDB.CouponCodeColName + "_" + agentName, {"code":codeStr, "channel":agentName})
-
+    
     if not data:
         #鏃犳鍗�
         gmresult['status'] = 0
@@ -294,6 +249,11 @@
         #宸蹭娇鐢紝鍚屽崱鍙疯褰曢粯璁ゅ彲鐢紝閬垮厤鏂嚎鍙戦�佸け璐ョ殑鎯呭喌锛堟湭杩斿洖缁撴灉楠岃瘉鎯呭喌涓嬶級
         gmresult['status'] = 2
         mylog.debug("card used!")
+        return SendGm(gmresult, pushurl)
+    
+    commCheckStatus = CommCheck(dataDict, data["coupontype"])
+    if commCheckStatus != None:
+        gmresult['status'] = commCheckStatus
         return SendGm(gmresult, pushurl)
     
     result, data2 = dbController.find_one(CouponDB.CouponBatchColName, {"couponid":data["couponid"]})
@@ -318,17 +278,20 @@
         gmresult['status'] = 0
         mylog.debug("time pass")
         return SendGm(gmresult, pushurl)
-    #鍐嶆煡涓�娆℃槸鍚︾敤杩囨鎵规鐨勫叾浠栧崱, 
-    result, data3 = dbController.find_one(CouponDB.CouponCodeColName + "_" + agentName, \
-                                          {"couponid":data["couponid"], "accid":accid})
-    if data3:
-        #鐢ㄨ繃鍚岀被鍗★紝宸茶褰曡繃涓嶅啀鍋氭柊璁板綍
-        gmresult['status'] = 3
-        gmresult['coupontype'] = data["coupontype"]
-        gmresult['code'] = codeStr
-        mylog.debug("use again")
-        return SendGm(gmresult, pushurl)
     
+    # h 寮�澶寸殑鍗$被鍨嬪彲閲嶅浣跨敤
+    if not codeStr.startswith('h'):
+        #鍐嶆煡涓�娆℃槸鍚︾敤杩囨鎵规鐨勫叾浠栧崱, 
+        result, data3 = dbController.find_one(CouponDB.CouponCodeColName + "_" + agentName, \
+                                              {"coupontype":data["coupontype"], "accid":accid})
+        if data3:
+            #鐢ㄨ繃鍚岀被鍗★紝宸茶褰曡繃涓嶅啀鍋氭柊璁板綍
+            gmresult['status'] = 3
+            gmresult['coupontype'] = data["coupontype"]
+            gmresult['code'] = codeStr
+            mylog.debug("use again")
+            return SendGm(gmresult, pushurl)
+        
     data['status'] = 1
     data['accid'] = accid
     data['usetime'] = str(datetime.datetime.today())
@@ -342,7 +305,24 @@
     mylog.debug("card ok!")
     return SendGm(gmresult, pushurl)
 
-
+def CommCheck(dataDict, coupontype):
+    ## 閫氱敤甯歌妫�鏌�
+    
+    # 浣跨敤绛夌骇
+    lvLimit = ConfigIO.GetInt(coupontype, "LV")
+    playerLV = CommFunc.ToIntDef(dataDict.get("level", 0))
+    if lvLimit > 0 and playerLV < lvLimit:
+        mylog.debug("playerLV(%s) < lvLimit(%s)" % (playerLV, lvLimit))
+        return 4
+    
+    # vip绛夌骇鐩稿叧
+    vipLVLimit = ConfigIO.GetInt(coupontype, "VIPLV")
+    playerVIPLV = CommFunc.ToIntDef(dataDict.get("viplevel", 0))
+    if vipLVLimit > 0 and playerVIPLV < vipLVLimit:
+        mylog.debug("playerVIPLV(%s) < vipLVLimit(%s)" % (playerVIPLV, vipLVLimit))
+        return 5
+    
+    return
 
 def SendGm(gmresult, pushurl):
     try:

--
Gitblit v1.8.0