def getRanking(self, userId, rankingDefine): ''' @return: (TYRankingList, timestamp, rankingList) ''' timestamp = pktimestamp.getCurrentTimestamp() cacheRanking = self._cacheRankings.get(rankingDefine.rankingId) if (not cacheRanking or (timestamp - cacheRanking[1]) >= cacheRanking[0].rankingDefine.cacheTimes or pktimestamp.getDayStartTimestamp(timestamp) != pktimestamp.getDayStartTimestamp(cacheRanking[1])): cacheRanking = self._getRanking(rankingDefine, timestamp) if cacheRanking: self._cacheRankings[rankingDefine.rankingId] = cacheRanking if ftlog.is_debug(): ftlog.debug( 'RankTcpHandler.getRanking cache userId=', userId, 'rankingId=', rankingDefine.rankingId, 'rankingIssueNumber=', cacheRanking[0].issueNumber, 'rankingCycle=', ('[%s,%s)' % (cacheRanking[0].timeCycle.startTime, cacheRanking[0].timeCycle.endTime)), 'timestamp=', datetime.fromtimestamp(timestamp).strftime( '%Y-%m-%d %H:%M:%S'), 'data=', cacheRanking[2]) else: if rankingDefine.rankingId in self._cacheRankings: del self._cacheRankings[rankingDefine.rankingId] if ftlog.is_debug(): ftlog.debug('RankTcpHandler.getRanking remove userId=', userId, 'rankingId=', rankingDefine.rankingId) return cacheRanking
def getRanking(self, userId, rankingDefine): ''' @return: (TYRankingList, timestamp, rankingList) ''' timestamp = pktimestamp.getCurrentTimestamp() cacheRanking = self._cacheRankings.get(rankingDefine.rankingId) if (not cacheRanking or (timestamp - cacheRanking[1]) >= cacheRanking[0].rankingDefine.cacheTimes or pktimestamp.getDayStartTimestamp(timestamp) != pktimestamp.getDayStartTimestamp(cacheRanking[1])): cacheRanking = self._getRanking(rankingDefine, timestamp) if cacheRanking: self._cacheRankings[rankingDefine.rankingId] = cacheRanking if ftlog.is_debug(): ftlog.debug('RankTcpHandler.getRanking cache userId=', userId, 'rankingId=', rankingDefine.rankingId, 'rankingIssueNumber=', cacheRanking[0].issueNumber, 'rankingCycle=', ('[%s,%s)' % (cacheRanking[0].timeCycle.startTime, cacheRanking[0].timeCycle.endTime)), 'timestamp=', datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S'), 'data=', cacheRanking[2]) else: if rankingDefine.rankingId in self._cacheRankings: del self._cacheRankings[rankingDefine.rankingId] if ftlog.is_debug(): ftlog.debug('RankTcpHandler.getRanking remove userId=', userId, 'rankingId=', rankingDefine.rankingId) return cacheRanking
def _adjustUserBenefits(self, gameId, userBenefits, timestamp): if (pktimestamp.getDayStartTimestamp(timestamp) != pktimestamp.getDayStartTimestamp(userBenefits.updateTime)): userBenefits.updateTime = timestamp userBenefits.times = 0 return True return False
def _adjustUserBenefits(self, gameId, userBenefits, timestamp): if (pktimestamp.getDayStartTimestamp(timestamp) != pktimestamp.getDayStartTimestamp(userBenefits.updateTime)): userBenefits.updateTime = timestamp userBenefits.times = 0 return True return False
def loadStatus(self, userId, timestamp=None): if timestamp is None: timestamp = pktimestamp.getCurrentTimestamp() status = self._dao.loadStatus(userId) if (not status or (pktimestamp.getDayStartTimestamp(status.flipTime) != pktimestamp.getDayStartTimestamp(timestamp))): status = DizhuFlipCardStatus(timestamp, {}, []) status.maxFlipCount = self._maxFlipCount status.nslogin = pkgamedata.getGameAttrInt(userId, 6, 'nslogin') return status
def calcCheckinState(self, status, timestamp): ''' @return: (checkinDays, canCheckin) ''' # 没签过到 if not status: return 0, 1 diffDays = (pktimestamp.getDayStartTimestamp(timestamp) \ - pktimestamp.getDayStartTimestamp(status.lastCheckinTime)) / 86400 # 没有连续签到,重置为0 if diffDays < 0 or diffDays > 1: ftlog.debug('TYDailyCheckin.calcCheckinState firstCheckin=', datetime.fromtimestamp(status.firstCheckinTime).strftime('%Y-%m-%d %H:%M:%S'), 'lastCheckin=', datetime.fromtimestamp(status.lastCheckinTime).strftime('%Y-%m-%d %H:%M:%S'), 'timestamp=', datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S'), 'diffDays=', diffDays, 'return=', '(0, 1)') return 0, 1 # 计算连续签到天数 checkinDays = max((pktimestamp.getDayStartTimestamp(timestamp) \ - pktimestamp.getDayStartTimestamp(status.firstCheckinTime)) / 86400, 0) canCheckin = 1 # 今天已经签过到了 if diffDays == 0: canCheckin = 0 # 连续签到满了,重新开始计算 if checkinDays >= len(self._dailyRewards): ftlog.debug('TYDailyCheckin.calcCheckinState firstCheckin=', datetime.fromtimestamp(status.firstCheckinTime).strftime('%Y-%m-%d %H:%M:%S'), 'lastCheckin=', datetime.fromtimestamp(status.lastCheckinTime).strftime('%Y-%m-%d %H:%M:%S'), 'timestamp=', datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S'), 'diffDays=', diffDays, 'checkinDays=', checkinDays, 'return=', '(0, %s)' % (canCheckin)) return 0, canCheckin ftlog.debug('TYDailyCheckin.calcCheckinState firstCheckin=', datetime.fromtimestamp(status.firstCheckinTime).strftime('%Y-%m-%d %H:%M:%S'), 'lastCheckin=', datetime.fromtimestamp(status.lastCheckinTime).strftime('%Y-%m-%d %H:%M:%S'), 'timestamp=', datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S'), 'diffDays=', diffDays, 'checkinDays=', checkinDays, 'return=', '(%s, %s)' % (checkinDays, canCheckin)) return checkinDays, canCheckin
def _doUpdate(cls, userId, clientId, timestamp): mo = MsgPack() mo.setCmd('hall_rp_task') mo.setResult('action', 'update') mo.setResult('userId', userId) status = hall_red_packet_task.loadUserStatus(userId) curTime = timestamp expiresTime = curTime createTimeStr = None try: createTimeStr = userdata.getAttr(userId, 'createTime') createDT = datetime.strptime(createTimeStr, '%Y-%m-%d %H:%M:%S.%f') createTime = pktimestamp.datetime2Timestamp(createDT) expiresTime = pktimestamp.getDayStartTimestamp( createTime) + 86400 * 8 except: ftlog.error('RedPacketTaskTcpHandler._doUpdate BadCreateTime', 'userId=', userId, 'createTime=', createTimeStr) mo.setResult('curTime', curTime) mo.setResult('expiresTime', expiresTime) if status.finished or not status.task: acts = hall_red_packet_task.getActs() mo.setResult('acts', cls.encodeActs(userId, clientId, acts)) else: mo.setResult('task', cls.encodeTask(userId, clientId, status)) mo.setResult('helpUrl', hall_red_packet_task.getHelpUrl(userId, clientId)) mo.setResult('tips', hall_red_packet_task.getTaskTips(userId, clientId)) mo.setResult('boardTip', hall_red_packet_task.getBoardTip(userId, clientId)) return mo
def calcTaskExpires(cls, userId): ''' 结算新手任务是否过期 ''' createTimeStr = userdata.getAttr(userId, 'createTime') createTime = pktimestamp.timestrToTimestamp(createTimeStr, '%Y-%m-%d %H:%M:%S.%f') return pktimestamp.getDayStartTimestamp(createTime) + neituiguang.NEW_USER_DAYS * 86400
def testMemberCard(self): memberCardKind = hallitem.itemSystem.findItemKind(item_membercard_id) userAssets = hallitem.itemSystem.loadUserAssets(self.userId) userBag = userAssets.getUserBag() self.assertEqual(userBag.getAllKindItem(memberCardKind), []) userBag.addItemUnitsByKind(self.gameId, memberCardKind, 1, self.timestamp, 0, 'TEST_ADJUST', 0) memberCardItem = userBag.getItemByKind(memberCardKind) self.assertEqual(memberCardItem.remaining, 0) self.assertEqual(memberCardItem.expiresTime, pktimestamp.getDayStartTimestamp(self.timestamp + 86400*2)) # self, item, userAssets, # gameId, isDayFirst, timestamp #memberCardKind.processWhenUserLogin(memberCardItem, userAssets, self.gameId, False, self.timestamp) self.assertRaises(TYItemAlreadyCheckinException, userBag.doAction, self.gameId, memberCardItem, 'checkin') self.timestamp += 86400 result = userBag.doAction(self.gameId, memberCardItem, 'checkin').gotAssetList #memberCardKind.processWhenUserLogin(memberCardItem, userAssets, self.gameId, False, self.timestamp) #memberCardKind.processWhenUserLogin(memberCardItem, userAssets, self.gameId, True) self.assertEqual(len(result), 1) self.assertEqual(result[0][0].kindId, 'user:chip') self.assertEqual(result[0][1], 30000) self.assertEqual(result[0][2], 30000) self.assertRaises(TYItemAlreadyCheckinException, userBag.doAction, self.gameId, memberCardItem, 'checkin')
def testMemberCard(self): memberCardKind = hallitem.itemSystem.findItemKind(item_membercard_id) userAssets = hallitem.itemSystem.loadUserAssets(self.userId) userBag = userAssets.getUserBag() self.assertEqual(userBag.getAllKindItem(memberCardKind), []) userBag.addItemUnitsByKind(self.gameId, memberCardKind, 1, self.timestamp, 0, 'TEST_ADJUST', 0) memberCardItem = userBag.getItemByKind(memberCardKind) self.assertEqual(memberCardItem.remaining, 0) self.assertEqual( memberCardItem.expiresTime, pktimestamp.getDayStartTimestamp(self.timestamp + 86400 * 2)) # self, item, userAssets, # gameId, isDayFirst, timestamp #memberCardKind.processWhenUserLogin(memberCardItem, userAssets, self.gameId, False, self.timestamp) self.assertRaises(TYItemAlreadyCheckinException, userBag.doAction, self.gameId, memberCardItem, 'checkin') self.timestamp += 86400 result = userBag.doAction(self.gameId, memberCardItem, 'checkin').gotAssetList #memberCardKind.processWhenUserLogin(memberCardItem, userAssets, self.gameId, False, self.timestamp) #memberCardKind.processWhenUserLogin(memberCardItem, userAssets, self.gameId, True) self.assertEqual(len(result), 1) self.assertEqual(result[0][0].kindId, 'user:chip') self.assertEqual(result[0][1], 30000) self.assertEqual(result[0][2], 30000) self.assertRaises(TYItemAlreadyCheckinException, userBag.doAction, self.gameId, memberCardItem, 'checkin')
def queryDailyFreeGive(userId, gameId): ''' :desc: 查询每日低保赠送 :param :return: { "dailyFreeGiveCountConf": dailyFreeGiveCountConf , "dailyFreeGiveAmountConf": dailyFreeGiveAmountConf , "dailyFreeGiveLimitConf": dailyFreeGiveLimitConf , "freeGiveCountLeft": freeGiveCountLeft } ''' retParam = { "dailyFreeGiveCountConf": 0, "dailyFreeGiveAmountConf": 0, "dailyFreeGiveLimitConf": 0, "freeGiveCountLeft": 0, "canRecieveFreeGive": 0 } debug('queryDailyFreeGive, userId =', userId, 'gameId =', gameId) try: dailyFreeGiveCountConf, dailyFreeGiveAmountConf, dailyFreeGiveLimitConf = getDailyFreeGiveConfig( ) if dailyFreeGiveCountConf <= 0 or dailyFreeGiveAmountConf <= 0 or dailyFreeGiveLimitConf <= 0: debug('daily free give not configured') return retParam retParam["dailyFreeGiveCountConf"] = dailyFreeGiveCountConf retParam["dailyFreeGiveAmountConf"] = dailyFreeGiveAmountConf retParam["dailyFreeGiveLimitConf"] = dailyFreeGiveLimitConf # 检查今天低保送豆的资格是否已经用完 lastFreeGiveTime, freeGiveCountLeft = loadDailyFreeGiveStatus(userId) if lastFreeGiveTime < pktimestamp.getDayStartTimestamp(): freeGiveCountLeft = dailyFreeGiveCountConf if freeGiveCountLeft <= 0: debug('free give count <= 0, userId =', userId, 'freeGiveCountLeft =', freeGiveCountLeft) return retParam retParam["freeGiveCountLeft"] = freeGiveCountLeft # 检查玩家的chip是否低于赠送下限 chip = userchip.getUserChipAll(userId) if chip >= dailyFreeGiveLimitConf: debug('user chip bigger then min, userChip =', chip, 'minChip =', dailyFreeGiveLimitConf) return retParam retParam["canRecieveFreeGive"] = 1 debug('can give user free chip, userId =', userId, 'gameId =', gameId, 'lastFreeGiveTime =', lastFreeGiveTime, 'freeGiveCountLeft =', freeGiveCountLeft) return retParam except Exception as e: ftlog.error(e)
def calcTaskExpires(cls, userId): ''' 结算新手任务是否过期 ''' createTimeStr = userdata.getAttr(userId, 'createTime') createTime = pktimestamp.timestrToTimestamp(createTimeStr, '%Y-%m-%d %H:%M:%S.%f') return pktimestamp.getDayStartTimestamp( createTime) + neituiguang.NEW_USER_DAYS * 86400
def setUserGiftBuff(userId, buffType, timestamp): try: isEjected = pktimestamp.getDayStartTimestamp() d = {'expiretime': timestamp, 'ejected': isEjected} return daobase.executeUserCmd( userId, 'HSET', 'GiftBuff' + ':' + str(DIZHU_GAMEID) + ':' + str(userId), str(buffType), strutil.dumps(d)) except: ftlog.error('new_table_remote.setUserWinStreakGiftBuff gameId=', DIZHU_GAMEID, 'userId=', userId) return None
def testGentlemanStaff(self): itemKind = hallitem.itemSystem.findItemKind(item_gentleman_staff_id) userAssets = hallitem.itemSystem.loadUserAssets(self.userId) userBag = userAssets.getUserBag() self.assertEqual(userBag.getAllKindItem(itemKind), []) item = userBag.addItemUnitsByKind(self.gameId, itemKind, 1, self.timestamp, 0, 'TEST_ADJUST', 0)[0] self.assertEqual(item, userBag.getItemByKind(itemKind)) self.assertEqual(item.remaining, 0) self.assertEqual(item.expiresTime, pktimestamp.getDayStartTimestamp(self.timestamp + 86400*2)) # 测试佩戴 unwearItemList = userBag.doAction(self.gameId, item, 'wear').unweardItemList self.assertEqual(unwearItemList, []) # 测试佩戴异常 self.assertRaises(TYItemAlreadyWoreException, userBag.doAction, self.gameId, item, 'wear') # self.assertEqual(userBag.consumeItemUnits(self.gameId, item, 1, self.timestamp, 0, 0), 1) self.assertEqual(item.isWore, 0) self.assertTrue(item.isExpires(self.timestamp)) # 过期时佩戴抛异常 self.assertRaises(TYItemAlreadyExpiresException, userBag.doAction, self.gameId, item, 'wear') # 测试取消佩戴 item = userBag.addItemUnits(self.gameId, item, 1, self.timestamp, 0, 0) ftlog.info('*************** item.expiresTime=', item.expiresTime) userBag.doAction(self.gameId, item, 'wear') # 测试佩戴互斥 itemRevolverKind = hallitem.itemSystem.findItemKind(item_revolver_id) revolverItem = userBag.addItemUnitsByKind(self.gameId, itemRevolverKind, 1, self.timestamp, 0, 'TEST_ADJUST', 0)[0] # 佩戴revolverItem unwearItemList = userBag.doAction(self.gameId, revolverItem, 'wear').unweardItemList self.assertEqual(len(unwearItemList), 1) self.assertEqual(unwearItemList[0], item) self.assertEqual(item.isWore, 0) self.assertEqual(revolverItem.isWore, 1) # 测试修复 userAssets.addAsset(self.gameId, 'user:chip', 200, self.timestamp, 'TEST_ADJUST', 0) self.assertEqual(userBag.consumeItemUnits(self.gameId, item, 1, self.timestamp, 'TEST_ADJUST', 0), 1) self.assertRaises(TYAssetNotEnoughException, userBag.doAction, self.gameId, item, 'repair', self.timestamp) # 增加修复费 userAssets.addAsset(self.gameId, 'user:chip', 100, self.timestamp, 'TEST_ADJUST', 0) consumeAssetsList = userBag.doAction(self.gameId, item, 'repair').consumeAssetList self.assertEqual(item.balance(self.timestamp), 10) self.assertEqual(len(consumeAssetsList), 1) self.assertEqual(consumeAssetsList[0][0].kindId, 'user:chip') self.assertEqual(consumeAssetsList[0][1], 300) self.assertEqual(consumeAssetsList[0][2], 0)
def getUserGiftBuff(userId, buffType): try: ret = daobase.executeUserCmd( userId, 'HGET', 'GiftBuff' + ':' + str(DIZHU_GAMEID) + ':' + str(userId), str(buffType)) if ret: jstr = strutil.loads(ret) return jstr.get('expiretime'), jstr.get( 'ejected') == pktimestamp.getDayStartTimestamp() return None, None except: ftlog.error('new_table_remote.setUserWinStreakGiftBuff gameId=', DIZHU_GAMEID, 'userId=', userId) return None, None
def _deltaDays(t1, t2): return (pktimestamp.getDayStartTimestamp(t1) - pktimestamp.getDayStartTimestamp(t2)) / 86400
def _deltaDays(t1, t2): return (pktimestamp.getDayStartTimestamp(t1) - pktimestamp.getDayStartTimestamp(t2)) / 86400
def _getCurrentCycle(self, timestamp): startTime = pktimestamp.getDayStartTimestamp(timestamp) return TYTimeCycle(startTime, startTime + 86400)
def isNewUser(self): registerDays = ( pktimestamp.getDayStartTimestamp(self._timestamp) - pktimestamp.getDayStartTimestamp(self._registerTime)) / 86044 return registerDays <= NEW_USER_DAYS
def calcCheckinState(self, status, timestamp): ''' @return: (checkinDays, canCheckin) ''' # 没签过到 if not status: return 0, 1 diffDays = (pktimestamp.getDayStartTimestamp(timestamp) \ - pktimestamp.getDayStartTimestamp(status.lastCheckinTime)) / 86400 # 没有连续签到,重置为0 if diffDays < 0 or diffDays > 1: ftlog.debug( 'TYDailyCheckin.calcCheckinState firstCheckin=', datetime.fromtimestamp( status.firstCheckinTime).strftime('%Y-%m-%d %H:%M:%S'), 'lastCheckin=', datetime.fromtimestamp( status.lastCheckinTime).strftime('%Y-%m-%d %H:%M:%S'), 'timestamp=', datetime.fromtimestamp(timestamp).strftime( '%Y-%m-%d %H:%M:%S'), 'diffDays=', diffDays, 'return=', '(0, 1)') return 0, 1 # 计算连续签到天数 checkinDays = max((pktimestamp.getDayStartTimestamp(timestamp) \ - pktimestamp.getDayStartTimestamp(status.firstCheckinTime)) / 86400, 0) canCheckin = 1 # 今天已经签过到了 if diffDays == 0: canCheckin = 0 # 连续签到满了,重新开始计算 if checkinDays >= len(self._dailyRewards): ftlog.debug( 'TYDailyCheckin.calcCheckinState firstCheckin=', datetime.fromtimestamp( status.firstCheckinTime).strftime('%Y-%m-%d %H:%M:%S'), 'lastCheckin=', datetime.fromtimestamp( status.lastCheckinTime).strftime('%Y-%m-%d %H:%M:%S'), 'timestamp=', datetime.fromtimestamp(timestamp).strftime( '%Y-%m-%d %H:%M:%S'), 'diffDays=', diffDays, 'checkinDays=', checkinDays, 'return=', '(0, %s)' % (canCheckin)) return 0, canCheckin ftlog.debug( 'TYDailyCheckin.calcCheckinState firstCheckin=', datetime.fromtimestamp( status.firstCheckinTime).strftime('%Y-%m-%d %H:%M:%S'), 'lastCheckin=', datetime.fromtimestamp( status.lastCheckinTime).strftime('%Y-%m-%d %H:%M:%S'), 'timestamp=', datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S'), 'diffDays=', diffDays, 'checkinDays=', checkinDays, 'return=', '(%s, %s)' % (checkinDays, canCheckin)) return checkinDays, canCheckin
def testGentlemanStaff(self): itemKind = hallitem.itemSystem.findItemKind(item_gentleman_staff_id) userAssets = hallitem.itemSystem.loadUserAssets(self.userId) userBag = userAssets.getUserBag() self.assertEqual(userBag.getAllKindItem(itemKind), []) item = userBag.addItemUnitsByKind(self.gameId, itemKind, 1, self.timestamp, 0, 'TEST_ADJUST', 0)[0] self.assertEqual(item, userBag.getItemByKind(itemKind)) self.assertEqual(item.remaining, 0) self.assertEqual( item.expiresTime, pktimestamp.getDayStartTimestamp(self.timestamp + 86400 * 2)) # 测试佩戴 unwearItemList = userBag.doAction(self.gameId, item, 'wear').unweardItemList self.assertEqual(unwearItemList, []) # 测试佩戴异常 self.assertRaises(TYItemAlreadyWoreException, userBag.doAction, self.gameId, item, 'wear') # self.assertEqual( userBag.consumeItemUnits(self.gameId, item, 1, self.timestamp, 0, 0), 1) self.assertEqual(item.isWore, 0) self.assertTrue(item.isExpires(self.timestamp)) # 过期时佩戴抛异常 self.assertRaises(TYItemAlreadyExpiresException, userBag.doAction, self.gameId, item, 'wear') # 测试取消佩戴 item = userBag.addItemUnits(self.gameId, item, 1, self.timestamp, 0, 0) ftlog.info('*************** item.expiresTime=', item.expiresTime) userBag.doAction(self.gameId, item, 'wear') # 测试佩戴互斥 itemRevolverKind = hallitem.itemSystem.findItemKind(item_revolver_id) revolverItem = userBag.addItemUnitsByKind(self.gameId, itemRevolverKind, 1, self.timestamp, 0, 'TEST_ADJUST', 0)[0] # 佩戴revolverItem unwearItemList = userBag.doAction(self.gameId, revolverItem, 'wear').unweardItemList self.assertEqual(len(unwearItemList), 1) self.assertEqual(unwearItemList[0], item) self.assertEqual(item.isWore, 0) self.assertEqual(revolverItem.isWore, 1) # 测试修复 userAssets.addAsset(self.gameId, 'user:chip', 200, self.timestamp, 'TEST_ADJUST', 0) self.assertEqual( userBag.consumeItemUnits(self.gameId, item, 1, self.timestamp, 'TEST_ADJUST', 0), 1) self.assertRaises(TYAssetNotEnoughException, userBag.doAction, self.gameId, item, 'repair', self.timestamp) # 增加修复费 userAssets.addAsset(self.gameId, 'user:chip', 100, self.timestamp, 'TEST_ADJUST', 0) consumeAssetsList = userBag.doAction(self.gameId, item, 'repair').consumeAssetList self.assertEqual(item.balance(self.timestamp), 10) self.assertEqual(len(consumeAssetsList), 1) self.assertEqual(consumeAssetsList[0][0].kindId, 'user:chip') self.assertEqual(consumeAssetsList[0][1], 300) self.assertEqual(consumeAssetsList[0][2], 0)
def receiveDailyFreeGive(userId, gameId): ''' :desc: 领取每日低保赠送 :param :return: ''' debug('receiveDailyFreeGive, userId =', userId, 'gameId =', gameId) try: dailyFreeGiveCountConf, dailyFreeGiveAmountConf, dailyFreeGiveLimitConf = getDailyFreeGiveConfig( ) if dailyFreeGiveCountConf <= 0 or dailyFreeGiveAmountConf <= 0 or dailyFreeGiveLimitConf <= 0: debug('daily free give not configured') return None # 检查玩家的chip是否低于下限 chip = userchip.getUserChipAll(userId) if chip >= dailyFreeGiveLimitConf: debug('user chip bigger then min, userChip =', chip, 'minChip =', dailyFreeGiveLimitConf) return None # 检查今天低保送豆的资格是否已经用完 lastFreeGiveTime, freeGiveCountLeft = loadDailyFreeGiveStatus(userId) if lastFreeGiveTime < pktimestamp.getDayStartTimestamp(): freeGiveCountLeft = dailyFreeGiveCountConf if freeGiveCountLeft <= 0: debug('free give count <= 0, userId =', userId, 'freeGiveCountLeft =', freeGiveCountLeft) return None debug('can give user free chip, userId =', userId, 'gameId =', gameId, 'userChip =', userchip, 'lastFreeGiveTime =', lastFreeGiveTime, 'freeGiveCountLeft =', freeGiveCountLeft) # 更新资格 lastFreeGiveTime, freeGiveCountLeft = pktimestamp.getCurrentTimestamp( ), freeGiveCountLeft - 1 saveDailyFreeGiveStatus(userId, lastFreeGiveTime, freeGiveCountLeft) # 低保赠送 userAssets = hallitem.itemSystem.loadUserAssets(userId) assetKind, _addCount, _final = userAssets.addAsset( gameId, 'user:chip', dailyFreeGiveAmountConf, lastFreeGiveTime, 'SZMJ_DAILY_FREE_GIVE_REWARD', 0) debug('user receive daily free chip, userId =', userId, 'gameId =', gameId, 'addCount =', _addCount, 'final =', _final, 'lastFreeGiveTime =', lastFreeGiveTime, 'freeGiveCountLeft =', freeGiveCountLeft) changed = [] if assetKind.keyForChangeNotify: changed.append(assetKind.keyForChangeNotify) datachangenotify.sendDataChangeNotify(gameId, userId, changed) return assetKind, _addCount, _final, freeGiveCountLeft except Exception as e: ftlog.error(e)
def isSameCycle(self, timestamp1, timestamp2): return pktimestamp.getDayStartTimestamp(timestamp1) \ == pktimestamp.getDayStartTimestamp(timestamp2)
def isNewUser(self): registerDays = (pktimestamp.getDayStartTimestamp(self._timestamp) - pktimestamp.getDayStartTimestamp(self._registerTime)) / 86044 return registerDays <= NEW_USER_DAYS
def _getCurrentCycle(self, timestamp): startTime = pktimestamp.getDayStartTimestamp(timestamp) return TYTimeCycle(startTime, startTime + 86400)