def verifyPurchase(cls, para): signed_data = json.loads(para['signed_data']) uid = para['uid'] product_id = signed_data['productId'] cfg = CfgTable(CfgTable.CFG_STORE, product_id) if cfg.exists(): user = User(uid) if user.level <= int(cfg.max_level): amount = int(int(cfg.amount) * (1 + int(cfg.extra) * 1.0 / 100)) user.coin += amount Log.info('Purchased uid=%d product_id=%s buy_coin=%d' % (uid, product_id, amount)) data = {'buy_coin': amount} Stat().incr(data) return {'coin': user.coin} else: Log.error('level execeeded') return Error.INVALID_PARAM else: Log.error('No such product id') return Error.INVALID_PARAM """
def sync_table(table, id_column): print 'Syncing ', table CfgTable.truncate(table) data = {} t=Table(table, metadata, autoload=True) for i in t.select().execute(): data[getattr(i, id_column)] = dict(i) CfgTable.save(table, data)
def getRandomMachineId(lv): data = CfgTable.load(CfgTable.CFG_MACHINE_INFO) pool = [] for d in data: if lv >= int(d['unlock_level']): pool.append(int(d['id'])) return random.choice(pool)
def getRandomBet(lv): data = CfgTable.load(CfgTable.CFG_LEVEL_BET) ok_bet = [] for d in data: if lv >= int(d['level']): ok_bet.append(int(d['bet'])) return random.choice(ok_bet)
def getMaxBet(lv): data = CfgTable.load(CfgTable.CFG_LEVEL_BET) ok_bet = [] for d in data: if lv >= int(d['level']): ok_bet.append(int(d['bet'])) return max(ok_bet)
def isBetValid(lv, bet): data = CfgTable.load(CfgTable.CFG_LEVEL_BET) ok_bet = [] for d in data: if lv >= int(d['level']): ok_bet.append(int(d['bet'])) return bet in ok_bet
def getMediumBet(lv): data = CfgTable.load(CfgTable.CFG_LEVEL_BET) ok_bet = [] for d in data: if lv >= int(d['level']): ok_bet.append(int(d['bet'])) i = len(ok_bet) / 2 return ok_bet[i]
def refresh(cls): for data in CfgTable.load(CfgTable.CFG_TOURNAMENT): tid = int(data['tid']) base_prize = int(data['prize']) total_time = int(data['time']) print 'tid:%s base_prize:%s, total_time=%s' % (tid, base_prize, total_time) tour = Tournament(tid) if not tour.exists(): print 'create tour' tour.reset() elif tour.isEnd(total_time): print "rewarding tid=%d"%tid tour.reward(base_prize) print 'recreate tour' tour.reset()
def load(cls, para): uid = para['uid'] ret = [] for data in CfgTable.load(CfgTable.CFG_TOURNAMENT): tid = int(data['tid']) base_prize = int(data['prize']) tour = Tournament(tid) if not tour.exists(): continue info = tour.getRangeInfo(uid) info['prize'] += base_prize info['tid'] = tid info['name'] = data['name'] total_time = int(data['time']) info['total_time'] = total_time left_time = tour.start_time + total_time - int(time.time()) if left_time < 0: left_time = 0 """ print 'tid:', tid print 'start_time', tour.start_time print 'now:', int(time.time()) print 'left_time', left_time print 'total_time', total_time """ info['left_time'] = left_time ret.append(info) ret = sorted(ret, key = lambda x: x['tid']) return {'tournament_info':ret}
def load(para): ret = {} data_version = para['data_version'] version = para['version'] ret['data'] = CfgTable.loadAll(data_version, version) constants = {} constants['resource_prefix'] = Config.RESOURCE_PREFIX constants['data_version'] = Version.loadCurDataVersion() from UserShareGift import UserShareGift constants['levelup_share_coin'] = UserShareGift.SHARE_COIN[UserShareGift.TYPE_LEVELUP] constants['combo_share_coin'] = UserShareGift.SHARE_COIN[UserShareGift.TYPE_COMBO] constants['mega_share_coin'] = UserShareGift.SHARE_COIN[UserShareGift.TYPE_MEGA] constants['bonus_share_coin'] = UserShareGift.SHARE_COIN[UserShareGift.TYPE_BONUS] constants['share_friend_num'] = 5 ret['constants'] = constants return ret