|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Def_CardMsg = { | 
|---|
|  |  |  | 0:"CodeRewardSys2", #  兑换码无效 | 
|---|
|  |  |  | 1: "CodeRewardSys1", #   兑换卡奖励已发至邮件 | 
|---|
|  |  |  | 1:"CodeRewardSys1", #   兑换卡奖励已发至邮件 | 
|---|
|  |  |  | 2:"CodeRewardSys3", #  兑换码已使用过 | 
|---|
|  |  |  | 3:"CodeRewardSys4",  # 同类型兑换码只能使用一次 | 
|---|
|  |  |  | 4:"LvErr", # 等级不足 | 
|---|
|  |  |  | 5:"VipLevel", # VIP等级不足 | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | myapp = Bottle() | 
|---|
|  |  |  |  | 
|---|
|  |  |  | # 防止短时间内的多次无效访问 accid:time | 
|---|
|  |  |  | 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" | 
|---|
|  |  |  | 
|---|
|  |  |  | # 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(): | 
|---|
|  |  |  | 
|---|
|  |  |  | codeStr = dataDict.get("code", "") | 
|---|
|  |  |  | if not codeStr: | 
|---|
|  |  |  | return | 
|---|
|  |  |  |  | 
|---|
|  |  |  | codeStr = codeStr.strip() | 
|---|
|  |  |  | #只是用来拼接账号 | 
|---|
|  |  |  | spID = dataDict.get("spid", "") | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | # 转化为游戏账号 | 
|---|
|  |  |  | 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: | 
|---|
|  |  |  | # 无法获取数据库 | 
|---|
|  |  |  | 
|---|
|  |  |  | gmresult = {'accID':accid, 'sid':sid, 'channel':agentName} | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #-----------统一固定码处理---------------------- | 
|---|
|  |  |  | CommonCards = CommonCards.get(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: | 
|---|
|  |  |  | # 已使用 | 
|---|
|  |  |  | gmresult['status'] = 2 | 
|---|
|  |  |  | 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 | 
|---|
|  |  |  | 
|---|
|  |  |  | 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 | 
|---|
|  |  |  | 
|---|
|  |  |  | #已使用,同卡号记录默认可用,避免断线发送失败的情况(未返回结果验证情况下) | 
|---|
|  |  |  | 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"]}) | 
|---|
|  |  |  | 
|---|
|  |  |  | 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()) | 
|---|
|  |  |  | 
|---|
|  |  |  | 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: | 
|---|
|  |  |  | 
|---|
|  |  |  | 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" | 
|---|
|  |  |  | 
|---|
|  |  |  | 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() | 
|---|
|  |  |  |  | 
|---|
|  |  |  | # 成功提示 | 
|---|
|  |  |  | 
|---|
|  |  |  | post['sign'] = sign; | 
|---|
|  |  |  | urllib2.urlopen(gmurl, urllib.urlencode(post), 3) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return content | 
|---|
|  |  |  | return 0 | 
|---|
|  |  |  | except Exception, e: | 
|---|
|  |  |  | mylog.debug("gm error %s"%e) | 
|---|
|  |  |  | return | 
|---|