From fe9b738b1cb89e3b4d320924fceef70a8e1f6fac Mon Sep 17 00:00:00 2001
From: hxp <ale99527@vip.qq.com>
Date: 星期四, 04 三月 2021 14:24:50 +0800
Subject: [PATCH] 8650 【主干】【BT2】活动规则优化(多活动支持的改为单表模式,增加活动分组编号字段区分不同的活动编号;常规活动改为不受合服影响,合服活动独立出来;累计充值活动、集字活动适配为新模式 master冲突补同步);
---
Tool/WebCenter/CouponCode/webapp.py | 121 ++++++++++++++++++++++++++++++++--------
1 files changed, 97 insertions(+), 24 deletions(-)
diff --git a/Tool/WebCenter/CouponCode/webapp.py b/Tool/WebCenter/CouponCode/webapp.py
index 333ab34..2468ab8 100644
--- a/Tool/WebCenter/CouponCode/webapp.py
+++ b/Tool/WebCenter/CouponCode/webapp.py
@@ -24,6 +24,7 @@
from lib import mylog, CommFunc
import os.path
import zipfile
+import time
# get: request.query.username request.GET.get('username','')
# post: request.forms.get('username') request.POST.get('username')
@@ -58,6 +59,15 @@
myapp = Bottle()
+# 闃叉鐭椂闂村唴鐨勫娆℃棤鏁堣闂� accid锛歵ime
+AccID_Cache_Dict = {}
+
+def CleanAccID():
+ global AccID_Cache_Dict
+
+ if len(AccID_Cache_Dict) < 100:
+ return
+ AccID_Cache_Dict = {}
#/api/Coupon/index.php?couponBatchId=%s&agentName=%s"
@@ -116,6 +126,7 @@
# http://center.xxx.com:53003/Coupon/CouponCode.php
@myapp.route('/Coupon/CouponCode.php')
def CouponCode():
+ global AccID_Cache_Dict
dataDict = request.GET
for key, value in dataDict.items():
@@ -128,14 +139,9 @@
codeStr = dataDict.get("code", "")
if not codeStr:
return
-
+ codeStr = codeStr.strip()
+ #鍙槸鐢ㄦ潵鎷兼帴璐﹀彿
spID = dataDict.get("spid", "")
- if not spID:
- tdict = {"jisugame":"jisu", 'spxjgame':'sipu', 'mrgame':'maoer',
- "jisugameios":"jisu", 'spyxxjios':'sipu', 'mrgameios':'maoer'}
-
- # 娌′紶鐨勮瘽榛樿鍜宎ppid涓�鏍�
- spID = tdict.get(agentName, agentName)
accid = dataDict.get("accid", "")
if not accid:
@@ -149,7 +155,21 @@
return
# 杞寲涓烘父鎴忚处鍙�
- accid = "%s@%s@s%s"%(accid, spID, sid)
+ accid = "%s@%s@s%s"%(accid.lower(), spID, sid)
+
+ try:
+ CleanAccID()
+ #mylog.debug("AccID_Cache_Dict : %s"%str(AccID_Cache_Dict))
+ if accid not in AccID_Cache_Dict:
+ AccID_Cache_Dict[accid] = int(time.time())
+ elif time.time() - AccID_Cache_Dict[accid] < 2:
+ mylog.debug("==========bad: fast click %s"%accid)
+ return
+
+ AccID_Cache_Dict[accid] = int(time.time())
+ except:
+ pass
+
dbController = CouponDB.GetDBEventCon()
if not dbController:
@@ -161,7 +181,8 @@
gmresult = {'accID':accid, 'sid':sid, 'channel':agentName}
#-----------缁熶竴鍥哄畾鐮佸鐞�----------------------
- if codeStr in CommonCards:
+ CommonCardsList = CommonCards.get(agentName, [])
+ if codeStr in CommonCardsList:
# 涓嶅悓鍥哄畾鐮佸悇鑷彧鑳介涓�娆�
result, commondata = dbController.find_one(CouponDB.CouponCodeColName + "_Common", {"code":codeStr, "accid":accid})
if commondata:
@@ -195,7 +216,7 @@
wxdata['status'] = 1
wxdata['accid'] = dataDict.get("accid", "") # 姝ゅ鐢ㄥ師濮嬭处鍙�
- wxdata['usetime'] = str(datetime.datetime.today())
+ wxdata['usetime'] = str(datetime.datetime.today()).split(".")[0]
wxdata['appid'] = agentName
wxdata['serverid'] = 's%s'%sid
@@ -209,8 +230,59 @@
SendDataCollectorBillInfo(wxdata, pushurl, operateID)
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:
@@ -322,7 +394,7 @@
for itemList in Items:
pack_data["ItemID%s"%i] = str(itemList[0])
pack_data["ItemCnt%s"%i] = str(itemList[1])
- pack_data["IsBind%s"%i] = '1'
+ pack_data["IsBind%s"%i] = str(itemList[2] if len(itemList) > 2 else 0)
i += 1
pack_data["pack_type"] = "GMT_AddPersonalCompensation"
@@ -337,9 +409,9 @@
post = {}
post['pack'] = pack_data_dict;
post['sign'] = sign;
- result = urllib2.urlopen(gmurl, urllib.urlencode(post), 10)
+ result = urllib2.urlopen(gmurl, urllib.urlencode(post), 3)
- content = result.read()
+ #content = result.read()
result.close()
# 鎴愬姛鎻愮ず
@@ -360,7 +432,7 @@
post['sign'] = sign;
urllib2.urlopen(gmurl, urllib.urlencode(post), 3)
- return content
+ return 0
except Exception, e:
mylog.debug("gm error %s"%e)
return
@@ -434,16 +506,17 @@
post['ip'] = wxdata['ip']
post['level'] = wxdata['level']
post['viplevel'] = wxdata['viplevel']
- post['time'] = wxdata['usetime']
+ post['time'] = int(time.time())
- key = ConfigIO.GetValue("Coupon", "%s_wxkey"%operateID)
+ key = ConfigIO.GetValue("Coupon", "key_%s"%post['appid'])
#md5(appid=$appid®ionid=$regionid&passport=$passport&&money=$money&time=$time$app_secret)
- sign = md5.md5("appid=%s®ionid=%s&passport=%s&money=%s&time=%s%s"%(\
- post['appid'], post['regionid'], post['passport'], post['money'], post['time'], key)).hexdigest()
-
- post['Sign'] = sign
- result = urllib2.urlopen(billurl, urllib.urlencode(post), 3)
- mylog.debug("SendDataCollectorBillInfo result %s"%result.read())
+ signStr = "appid=%s®ionid=%s&passport=%s&money=%s&time=%s%s"%(\
+ post['appid'], post['regionid'], post['passport'], post['money'], post['time'], key)
+ sign = md5.md5(signStr).hexdigest()
+ #mylog.debug("SendDataCollectorBillInfo %s-%s-%s-%s"%(signStr, sign, key, post))
+ post['sign'] = sign
+ result = urllib2.urlopen(billurl +"?" + urllib.urlencode(post), timeout =3)
+ #mylog.debug("SendDataCollectorBillInfo result %s"%result.read())
except Exception, e:
mylog.debug("SendDataCollectorBillInfo error %s"%e)
--
Gitblit v1.8.0