Tool/WebCenter/CouponCode/webapp.py
@@ -49,10 +49,20 @@
PushTimeout = ConfigIO.GetInt("Coupon", "PushTimeout", 5)
CommonCards = eval(ConfigIO.GetValue("Coupon", "CommonCards"))
g_mailJsonDict = {} # {channel:MailJson, ...}
# 发放奖励邮件内容json,utf8编码
f = open(os.getcwd() + "\\..\\Coupon\\CodeMail.json", "r")
MailJson = eval(f.read())
f.close()
def GetMailJson(channel):
    global g_mailJsonDict
    if channel in g_mailJsonDict:
        return g_mailJsonDict[channel]
    jsonPath = os.getcwd() + ("\\..\\Coupon\\CodeMail_%s.json" % channel)
    if not os.path.isfile(jsonPath):
        jsonPath = os.getcwd() + "\\..\\Coupon\\CodeMail.json"
    f = open(jsonPath, "r")
    MailJson = eval(f.read())
    f.close()
    g_mailJsonDict[channel] = MailJson
    return MailJson
# 礼包使用返回结果码定义
ErrCode_OK = 0 # 成功,非0的码均代表错误
@@ -304,16 +314,22 @@
        mylog.debug("time pass")
        return SendGm(ErrCode_Invalid, gmresult, pushurl)[1]
    
    maxUseCount = 0 # -1-无限;0或1-默认1次; >1-限制次数; 没有配置的默认0即默认1次
    prefix = "" # 固定前缀
    MailJson = GetMailJson(agentName)
    if couponType in MailJson:
        mailInfo = MailJson[couponType]
        prefix = mailInfo.get("Prefix", "")
        maxUseCount = CommFunc.ToIntDef(mailInfo.get("MaxUseCount", 0))
    elif ConfigIO.HasSection(couponType):
        if ConfigIO.HasOption(couponType, "Prefix"):
            prefix = ConfigIO.GetValue(couponType, "Prefix")
            maxUseCount = ConfigIO.GetInt(couponType, "MaxUseCount")
            
    # h 开头的卡类型可重复使用
    if not codeStr.startswith(prefix + 'h'):
    #if not codeStr.startswith(prefix + 'h'):
    #修改为按配置最大次数判断即可
    if maxUseCount in [0, 1]:
        #再查一次是否用过此批次的其他卡, 
        result, data3 = dbController.find_one(CouponDB.CouponCodeColName + "_" + agentName, \
                                              {"coupontype":data["coupontype"], "accid":accid})
@@ -322,6 +338,13 @@
            gmresult['coupontype'] = data["coupontype"]
            gmresult['code'] = codeStr
            mylog.debug("use again")
            return SendGm(ErrCode_TypeUsed, gmresult, pushurl)[1]
    elif maxUseCount > 1:
        result, resultList = dbController.find(CouponDB.CouponCodeColName + "_" + agentName, {"coupontype":data["coupontype"], "accid":accid}, {"code":1})
        if not result or len(resultList) >= maxUseCount:
            gmresult['coupontype'] = data["coupontype"]
            gmresult['code'] = codeStr
            mylog.debug("use maxUseCount limit. %s" % maxUseCount)
            return SendGm(ErrCode_TypeUsed, gmresult, pushurl)[1]
        
    data['status'] = 1
@@ -340,6 +363,7 @@
def CommCheck(dataDict, coupontype):
    ## 通用常规检查
    
    MailJson = GetMailJson(dataDict.get("channel", ""))
    if coupontype in MailJson:
        mailInfo = MailJson[coupontype]
        lvLimit = mailInfo.get("LV", 0)
@@ -390,6 +414,7 @@
            return errcode, CouponCodeResponse(errcode)
        
        coupontype = gmresult["coupontype"]
        MailJson = GetMailJson(gmresult["channel"])
        if coupontype in MailJson:
            mailInfo = MailJson[coupontype]
            mailTitle = mailInfo.get("MailTitle", "MailTitle")