Пример #1
0
def lottery_stage(hall_id, hall_tag):
    """开奖阶段"""
    # log.info("--------------------------开奖阶段--------------------------")
    log.info("开奖阶段>")
    # 进入开奖阶段通知
    lottery_notice(hall_tag)
    # 获取开奖结果
    result = create_result()
    # 设置当前开奖结果
    seq = get_hall_new_sequence(hall_id, hall_tag)
    log.info(result)
    # TODO 这个时候已经可以开始结算用户了
    settle_players.delay(seq, result['wins'])
    set_bonus_and_bet_count.delay(seq, result['wins'])
    # 等待五秒前端动画
    time.sleep(5)
    # 开奖结果通知
    lottery_result_notice(hall_tag, result)
    # 存储开奖结果
    set_result(seq, result['result'])
    # 切换大厅状态
    next_hall_stage(hall_id)
    # 进入结算阶段
    # settle_stage.delay(hall_id, hall_tag, result['wins'])
    settle_stage.apply_async((hall_id, hall_tag, result['wins']), countdown=5)
Пример #2
0
def settle_stage(hall_id, hall_tag, win_types):
    """结算阶段"""
    # log.info("--------------------------结算阶段--------------------------")
    log.info("结算阶段>")
    # 通知进入结算阶段
    settle_notice(hall_tag)
    # 获取最新期号
    seq = get_hall_new_sequence(hall_id, hall_tag)
    # 获取赢家
    win_players = get_win_players(seq, win_types)
    # 发送中奖通知
    winning_notice(win_players, hall_tag, win_types)
    # TODO 异步设置输家,赢家
    set_bet_record.delay(seq, win_types)
    # 切换为结束阶段
    next_hall_stage(hall_id)
    over_stage.apply_async((hall_id, hall_tag), countdown=5)
Пример #3
0
def hall_info(hall_id=None, hall_tag=None):
    """
    获取大厅详情
    :param hall_tag:
    :param hall_id:
    :return:
    """
    ok, obj = Hall.hall_info(hall_id=hall_id, hall_tag=hall_tag)
    if not ok:
        return False, None
    hall = model_to_dict(obj)
    hall['sequence'] = get_hall_new_sequence(obj.id, obj.tag)[-4:]
    result = get_result(get_hall_previous_sequence(obj.id, obj.tag))
    hall[
        'previous_result'] = [] if result == '' or result is None else literal_eval(
            result)
    hall['bet_option'] = hall_bet_option(obj.id)
    hall['chip_option'] = hall_chip_option(obj.id)
    return True, hall
Пример #4
0
def bet(channel_name, **params):
    """
    @api {post} /ReqBet 游戏下注接口
    @apiVersion 1.0.0
    @apiName ReqBet
    @apiGroup WebSocket-Receive
    @apiSuccessExample {json} 通知样例:
    {
        "event": "ReqBet",
        "data": {
            "bet_amount": 200,
            "dice_type": "SUM_THREE"
        }
    }
    """
    log.info('*****************************************')
    log.info(params)
    player_token = get_player_token(channel_name)
    hall_id = get_player_hall(player_token)
    log.info(player_token)
    log.info(hall_id)
    event = NoticeEvent.GameBetErrorNotice.value
    ok, hall = find_by_id(hall_id)
    if not ok:
        log.info('未查询到大厅')
        # bet_error(channel_name, hall.tag)
        return create_result(
            hall.tag, event, {
                'code': ServerCode.CODE41001.value,
                'msg': ServerMsg.CODE41001.value,
                'gold': params['bet_amount']
            })
    if hall.stage != HallStage.BetStage.value:
        log.info("大厅当前阶段【%s】当前阶段不允许下注" % hall.stage)
        bet_error(channel_name, hall.tag)
        return create_result(
            hall.tag, event, {
                'code': ServerCode.CODE41002.value,
                'msg': ServerMsg.CODE41002.value,
                'gold': params['bet_amount']
            })
    form = BetForm(params)
    if not form.is_valid():
        log.info(form.errors)
        return create_result(
            hall.tag, event, {
                'code': ServerCode.CODE41006.value,
                'msg': ServerMsg.CODE41006.value,
                'gold': params['bet_amount']
            })
        # bet_error(channel_name, hall_tag)
    ok, player = Player.find_by_token(player_token)
    if not ok:
        log.info('未查询到玩家')
        return create_result(
            hall.tag, event, {
                'code': ServerCode.CODE41003.value,
                'msg': ServerMsg.CODE41003.value,
                'gold': params['bet_amount']
            })
        # bet_error(channel_name, hall_tag)
    # 获取大厅ID
    hall_id = get_player_hall(player_token)
    sequence = get_hall_new_sequence(hall_id, hall.tag)
    # 检查下注金额
    if not check_value(hall_id, params['bet_amount']):
        log.info('下注金额不正确')
        return create_result(
            hall.tag, event, {
                'code': ServerCode.CODE41004.value,
                'msg': ServerMsg.CODE41004.value,
                'gold': params['bet_amount']
            })
        # bet_error(channel_name, hall_tag)
    # 检查下注类型
    ok, odds = check_bet(hall_id, params['dice_type'])
    if not ok:
        log.info('下注类型不正确')
        return create_result(
            hall.tag, event, {
                'code': ServerCode.CODE41005.value,
                'msg': ServerMsg.CODE41005.value,
                'gold': params['bet_amount']
            })
        # bet_error(channel_name, hall_tag)
    if Decimal(params['bet_amount']) > player.gold:
        log.info('玩家金额不足')
        return create_result(
            hall.tag, event, {
                'code': ServerCode.CODE41007.value,
                'msg': ServerMsg.CODE41007.value,
                'gold': 0
            })
    # 计算下注奖金
    bonus = Decimal(params['bet_amount']) * Decimal(odds)
    # 扣除玩家金币
    update_player_gold(player.token, -params['bet_amount'])
    # 创建下注记录
    BetRecord.create(player.id, sequence, params['bet_amount'],
                     params['dice_type'], bonus)
    return None