def recharge_strategy(player_token, value): value = decimal.Decimal(value) activate = KeyValue.get_value(Keys.RECHARGE_TACTICS_ACTIVATE.value) if activate != str(True): return info = KeyValue.get_value(Keys.RECHARGE_TACTICS_INFO.value) if info is None or info == {}: return info = json.loads(info) now_time = int(time.strftime("%Y%m%d%H%M%S")) reward = 0 if int(info['range'][0]) < now_time < int(info['range'][1]): if info['method'] == "INTERVAL": # 区间 for v in info['value']: if decimal.Decimal(v['min']) <= value < decimal.Decimal(v['max']): reward = v['reward'] break if info['method'] == "FIXED": # 固定值 for v in info['value']: if decimal.Decimal(v['recharge_amount']) == value: reward = v['reward_amount'] break if info['method'] == "PERCENTAGE": # 百分比 x = decimal.Decimal(info['value']) / 100 reward = value * x if reward == 0: return if info['type'] == RechargeType.GOLD.value: Player.update_player_gold(player_token, reward) elif info['type'] == RechargeType.INTEGRAL.value: Player.update_player_integral(player_token, reward)
def pig_open(player_id, token): """ 开奖 :return: gold """ gold = random.randint(1, 50) Player.update_player_integral(token, -500) ok, player = Player.update_player_gold(token, gold, gold) value = int(KeyValue.get_value(Keys.GOLDEN_PIG.value)) KeyValue.update_value(Keys.GOLDEN_PIG.value, (value - 1)) PigRecord.create(player_id=player_id, gold=gold) update_player_info(player) return gold