def _clearCreateTableData(cls, serverId): """清除重启进程对应的创建牌桌数据 只在GT服调用 """ ftlog.debug('CreateTableData.clearCreateTableData serverId:', serverId) daobase.executeMixLua(cls.CLEAR_CREATE_TABLE_SCRIPT_NAME, 3, cls._getCreateTableNoKey(), serverId, cls._getTableNoMapTableIdKey())
def removeCreateTableNo(cls, serverId, tableNoKey): """删除redis中自建桌验证码数据 只在GT服调用 """ daobase.executeMixLua(cls.REMOVE_CREATE_TABLE_SCRIPT_NAME, 4, cls._getCreateTableNoKey(), tableNoKey, serverId, cls._getTableNoMapTableIdKey(), ) ftlog.info('<<< serverId=',serverId,'tableNoKey',tableNoKey,caller=cls)
def _clearCreateTableData(cls, serverId): """清除重启进程对应的创建牌桌数据 只在GT服调用 """ ftlog.debug('CreateTableData.clearCreateTableData serverId:', serverId) daobase.executeMixLua(cls.CLEAR_CREATE_TABLE_SCRIPT_NAME , 3 , cls._getCreateTableNoKey() , serverId , cls._getTableNoMapTableIdKey() )
def getVipPacketNumber(cls, bankId, issue): ''' 获得VIP专属红包剩余数量 ''' vip_cursor_path = cls.getMixKeypath(bankId, issue, "cursor:vip") return daobase.executeMixLua(cls.getpacketnumber_key, 1, vip_cursor_path)
def getNormalPacketNumber(cls, bankId, issue): ''' 获得普通红包剩余数量 ''' nor_cursor_path = cls.getMixKeypath(bankId, issue, "cursor:nor") return daobase.executeMixLua(cls.getpacketnumber_key, 1, nor_cursor_path)
def getAllPacketNumber(cls, bankId, issue): ''' 获得所有红包剩余数量 ''' vip_cursor_path = cls.getMixKeypath(bankId, issue, "cursor:vip") nor_cursor_path = cls.getMixKeypath(bankId, issue, "cursor:nor") return daobase.executeMixLua(cls.getpacketnumber_key, 2, vip_cursor_path, nor_cursor_path)
def selectPacket(cls, bankId, issue, isVIP): ''' 按照规则随机领取一个红包,若红包已经领光,则返回None 规则:VIP用户优先领取VIP专属红包,VIP专属红包领光后才领取普通红包 ''' vip_cursor_path = cls.getMixKeypath(bankId, issue, "cursor:vip") nor_cursor_path = cls.getMixKeypath(bankId, issue, "cursor:nor") return daobase.executeMixLua(cls.selectpacket_key, 4, isVIP, vip_cursor_path, nor_cursor_path, random.randint(1, 100000000))
def __exchange(self, rdskey, uid, excode, deviceid, receive_num = 0, unique = 0): if receive_num >= 1: result = daobase.executeMixLua(self._scriptNameNew, 6, uid, rdskey, excode, unique, deviceid, receive_num) else: result = daobase.executeMixLua(self._scriptName, 4, uid, rdskey, excode, unique) ftlog.debug('ExchangeCode->__exchange() waitForRedis return', result) error_des = '' if result == 1: error_des = u'每位用户只能兑换一次' elif result == 2: error_des = u'该兑换码已经使用' elif result == 3: error_des = u'该兑换码无效' elif result == 4: error_des = u'该兑换码使用次数已用完' elif result == 5: error_des = u'每个设备只能兑换一次' return result, error_des
def __exchange(self, rdskey, uid, excode, unique=0): result = daobase.executeMixLua(self._scriptName, 4, uid, rdskey, excode, unique) ftlog.debug('ExchangeCode->__exchange() waitForRedis return', result) error_des = '' if result == 1: error_des = u'每位用户只能兑换一次' elif result == 2: error_des = u'该兑换码已经使用' elif result == 3: error_des = u'该兑换码无效' return result, error_des
def setPacketData(cls, bankId, issue, packet_data, count_data): ''' 设置红包内容,用于多进程同步 多个进程可能同时有多个设置,但是保证返回的是同一个 注意:设置的data未必是返回的数据 @:return 真实设置成功的红包数据,可能是其他进程设置成功的 ''' data_path = cls.getMixKeypath(bankId, issue, "data") vip_cursor_path = cls.getMixKeypath(bankId, issue, "cursor:vip") nor_cursor_path = cls.getMixKeypath(bankId, issue, "cursor:nor") packets_data_str = json.dumps(packet_data) cursor_data_str = json.dumps(count_data) return daobase.executeMixLua(cls.setpacketdata_key, 5, data_path, packets_data_str, vip_cursor_path, nor_cursor_path, cursor_data_str)
def addCreateTableNo(cls, tableId, roomId, serverId, tableNoKey): """添加自建桌验证码数据 只在GT服调用 """ ftlog.debug('CreateTableData.addCreateTableNo tableId:', tableId, ' roomId:', roomId, ' serverId:', serverId, ' tableNoKey:', tableNoKey) tableNoMapValue = json.dumps([tableId, roomId]) result = daobase.executeMixLua(cls.ADD_CREATE_TABLE_NO_SCRIPT_NAME, 6, cls._getCreateTableNoKey(), tableNoKey, serverId, cls._getTableNoMapTableIdKey(), tableId, tableNoMapValue) ftlog.debug("===addCreateTableNo===", serverId, tableNoKey, result) return result
def reset(self, datetime_point): ''' 重新生成红包,清空上次的领取剩余,重新满池 :param datetime_point 红包领取时间点 ''' r = Redis.readMixHash("dizhu:hongbaorecord", str(datetime_point)) if r: return False general_listmap = {} # {"user:coupon":[...], "item:1007":[...], ...} for item in self._general: itemtype = item.get("type") num = item.get("num") if itemtype == "random.split": total = item.get("total") minv = item.get("min") general_listmap[item.get( "itemId")] = Random.getNormalDistributionRandomSequence( total, minv, num) elif itemtype == "random.fixed": count = item.get("count") general_listmap[item.get("itemId")] = [ count for _ in xrange(num) ] vip_listmap = {} # {"user:coupon":[...], "item:1007":[...], ...} for item in self._vip: itemtype = item.get("type") num = item.get("num") if itemtype == "random.split": total = item.get("total") minv = item.get("min") vip_listmap[item.get( "itemId")] = Random.getNormalDistributionRandomSequence( total, minv, num) elif itemtype == "random.fixed": count = item.get("count") vip_listmap[item.get("itemId")] = [count for _ in xrange(num)] normaljsonstr = json.dumps(general_listmap) vipjsonstr = json.dumps(vip_listmap) result = daobase.executeMixLua(_REDIS_LUA_PUSHLIST_NAME, 3, normaljsonstr, vipjsonstr, str(datetime_point)) ftlog.debug("RedEnvelopeWrapper.reset: result=", result) return result
def addCreateTableNo(cls, tableId, roomId, serverId, tableNoKey): """添加自建桌验证码数据 只在GT服调用 """ ftlog.debug('CreateTableData.addCreateTableNo tableId:', tableId , ' roomId:', roomId , ' serverId:', serverId , ' tableNoKey:', tableNoKey) tableNoMapValue = json.dumps([tableId,roomId]) result = daobase.executeMixLua(cls.ADD_CREATE_TABLE_NO_SCRIPT_NAME , 6 , cls._getCreateTableNoKey() , tableNoKey , serverId , cls._getTableNoMapTableIdKey() , tableId , tableNoMapValue ) ftlog.info("===addCreateTableNo===",serverId, tableNoKey, result) return result
def outStock(self, stockId, count): assert (count > 0) return daobase.executeMixLua(self._REDIS_LUA_OUT_STOCK_NAME, 3, self._key, stockId, count)
def deliveryProductForPeriodLimit(self, periodId, productId, count, timestamp): return daobase.executeMixLua(self._REDIS_LUA_PERIOD_LIMIT_DELIVERY_NAME, 4, self.buildKey(productId), periodId, count, timestamp)
def unlockProductForPeriodLimit(self, periodId, productId, count, timestamp): return daobase.executeMixLua(self._REDIS_LUA_PERIOD_LIMIT_UNLOCK_NAME, 4, self.buildKey(productId), periodId, count, timestamp)
def get(self, userId, gameId, clientId, activityId): ''' {'isOK': True, 'nowTime': 1452161428.0, 'nextTime': 1452218400.0, 'hasGet': False, 'isRemain': True, 'tip': tip} ''' clientconf = self._clientConf serverconf = self._serverConf dataWrapper = self._dataWrapper timelist = Tool.dictGet(clientconf, "config.activate.timeList") startdate = serverconf.get("start") enddate = serverconf.get("end") #检测是否过期 if not self.checkOperative(): tip = Tool.dictGet(clientconf, "config.activate.outdateTip") return {"isOK": False, "tip": tip} #活动已经过期 nowstamp = Tool.datetimeToTimestamp(datetime.now()) rconf = {"isOK": True, "nowTime": nowstamp} arrive_timepoint = dataWrapper.getLastestTimePoint(timelist, startdate) next_timepoint = dataWrapper.getNextTimePoint(timelist, enddate) if next_timepoint: # 若存在下一个时间点 rconf["nextTime"] = Tool.datetimeToTimestamp(next_timepoint) if not arrive_timepoint: #未达到领取时间 tip = Tool.dictGet(clientconf, "config.activate.cannotGetTip") rconf.update({"isOK": False, "tip": tip}) return rconf has_get = dataWrapper.hasGet(userId, arrive_timepoint) # 是否已经领取 ftlog.debug("TYActivityDdzRedEnvelope.get: userId", userId, " has_get=", has_get) if has_get: # 已经领取了 tip = Tool.dictGet(clientconf, "config.activate.alreadyGetTip") rconf.update({"isOK": False, "tip": tip}) return rconf isvip = (UserInfo.getVipLevel(userId) > 0) result = daobase.executeMixLua(_REDIS_LUA_GET_NAME, 2, isvip, random.randint(1, 10000000)) ftlog.debug("TYActivityDdzRedEnvelope.get: userId", userId, " result=", result, "isvip=", isvip) if not result: tip = Tool.dictGet(clientconf, "config.activate.emptyGetTip") rconf.update({"isOK": False, "tip": tip}) return rconf # 领取红包的结果 result_count = result[1] # 领取红包项的配置 itemconf = _redenvelopeWrapper.getItemConfigWithPath(result[0]) result_name = str(itemconf.get('desc')) # 构造邮箱信息 assetsdict = {"assets": result_name, "count": str(result_count)} mail = Tool.dictGet(clientconf, "config.mail") mail = strutil.replaceParams(mail, assetsdict) # 发送奖励和邮箱信息 assets = {'itemId': itemconf.get("itemId"), 'count': result_count} UserBag.sendAssetsToUser(6, userId, assets, 'DDZ_ACT_REDENVELOPE', mail) # 发送LED的(条件满足) ok = self.sendLedIfNeed(userId, itemconf, result_count) ftlog.debug("TYActivityDdzRedEnvelope.get: sendLed-> userId=", userId, " ok=", ok) # 记录领取物品 assets.update({"itemDesc": itemconf.get('desc')}) dataWrapper.markGet(userId, arrive_timepoint, assets) # 日志记录领取 ftlog.debug("TYActivityDdzRedEnvelope:Get, ", "userId", userId, "gettime", str(datetime.now()), "assets", assets.get("itemId"), "count", assets.get("count"), "desc", assets.get("itemDesc"), "detail", assets) # 构造协议信息 itemtip = Tool.dictGet(clientconf, "config.activate.itemGetTip") itemtip = strutil.replaceParams(itemtip, assetsdict) rconf.update({ "isOK": True, "itemDesc": result_name, "itemCount": result_count, "tip": itemtip }) ftlog.debug("TYActivityDdzRedEnvelope.get: userId=", userId, " itemconf=", itemconf, "arrive_timepoint=", str(arrive_timepoint), "rconf=", rconf) return rconf
def getGeneralCount(self): return daobase.executeMixLua(_REDIS_LUA_GETCOUNT_NAME, 1, "general")
def getCount(self): return daobase.executeMixLua(_REDIS_LUA_GETCOUNT_NAME, 1, "all")