def dice_records(self, limit, offset, user_id='', start_id=None):
        offset = get_offset_by_page(offset, limit)
        result_dict = {
            'limit': limit,
            'offset': offset,
            'count': 0,
            'content': []
        }
        account_service = AccountService()
        with MysqlTools().session_scope() as session:
            q = session.query(DiceParticipateInModel). \
                order_by(DiceParticipateInModel.created_at.desc())
            if user_id != '':
                q = q.filter(DiceParticipateInModel.user_id == user_id)
            record_count = q.count()
            result_dict['count'] = get_page_by_offset(record_count, limit)
            if start_id is not None:
                start_id = str(start_id)
                q = q.filter(DiceParticipateInModel._id < start_id)
            participate_list = q.limit(limit).offset(offset).all()
            for i in participate_list:
                user_info = account_service.get_inner_user_account_info(
                    session, i.user_id)
                user_name = user_info['nick_name']
                result = {
                    'id':
                    i._id,
                    'user_name':
                    user_name,
                    'dice_result':
                    i.dice_result,
                    'dice_time':
                    timestamp_to_str(int(float(i.dice_timestamp)),
                                     format_style="%Y-%m-%d %H:%M:%S"),
                    'reward_token':
                    self.get_coin_name(i.reward_token),
                    'reward_quantity':
                    decimal_to_str(i.reward_quantity, 6)
                }
                if i.reward_token == int(_COIN_ID_USDT):
                    result['reward_quantity'] = decimal_to_str(
                        i.reward_quantity, 4)
                result_dict['content'].append(result)

        return result_dict
Example #2
0
    def bet_in(self, dic):
        id = dic.get("game_instance_id", "")  # 项目id
        user_id = dic.get("user_id", "")  # 用户id
        user_channel_id = dic.get("user_channel_id", "")  # 用户下注渠道id
        conin_id = dic.get("conin_id", "")  # 投入币种id
        bet_amount = dic.get("bet_amount", "")  # 投注数量
        merge_id = dic.get("merge_id", -1)  # 合并投注id
        # transaction_password = dic.get("transaction_password", "")  # 交易密码

        with MysqlTools().session_scope() as session:
            # 查询项目
            model = session.query(GameDigitalInstanceModel).filter(
                GameDigitalInstanceModel._id == id).with_for_update().first()
            if model is None:
                return self.return_error(60001)
            if model.status == 1:
                return self.return_error(60002)
            if model.status == 2:
                return self.return_error(60003)
            if model.status == 0:
                can_bet = model.need - model.bet_number
                if can_bet <= 0:
                    return self.return_error(60002)
                if int(bet_amount) > can_bet:
                    return self.return_error(60004)

            if model.support_token >= 0 and int(
                    conin_id) != model.support_token and int(conin_id) != int(
                        _COIN_ID_EXP):
                return self.return_error(60008)

            # 查询币价 币种实际需要金额
            exchange_rate = get_exchange_rate(int(conin_id))

            # (投注数量 * 投注单位) / 投注币种兑换usdt比例
            bet_money = (int(bet_amount) *
                         model.bet_unit) / exchange_rate['price']

            # 体验金相关逻辑
            if int(conin_id) == int(_COIN_ID_EXP):
                # 检查本次投注体验金使用数量 (允许范围: 1~10)
                if int(bet_amount) < 1 or int(bet_amount) > 10:
                    self.return_error(60015)
                # 体验金使用额度
                exp = int(model.experience / 100 * model.need)
                # 检查项目体验金占比剩余额度以及个人当天最大体验金使用额度(每天最多用10个)
                limit = self.check_instance_exp_limit(session, user_id, id)
                instance_limit = limit['instance_limit']
                user_limit = limit['user_limit']
                if user_limit > 10 - int(bet_amount):
                    self.return_error(60017)
                if instance_limit >= exp:
                    self.return_error(60016)

            # 查询用户资产
            account_service = AccountService()
            user_info = account_service.get_inner_user_account_by_token(
                session, user_id, conin_id)
            if isinstance(user_info, int):
                if user_info == 20001:
                    return self.return_error(20001)

            balance = get_decimal(user_info.get("balance"),
                                  digits=8,
                                  decimal_type="down")

            # 账户余额 < 需要下注金额
            if balance < bet_money:
                return self.return_error(60005)

            # 验证交易密码
            # if account_service.check_pay_password(user_id, transaction_password) is False:
            #     return self.return_error(35024)
            # raise_logger("begin", "game_bet_in", "info")
            # 获取下注编号
            game_numbers = session.query(GameNumbersSetModel).filter(
                GameNumbersSetModel.game_serial ==
                model.game_serial).with_for_update().all()
            numbers = []
            for num in game_numbers:
                numbers.append(num.number)
            numbers = random.sample(numbers, int(bet_amount))
            # raise_logger("get game_numbers", "game_bet_in", "info")
            if isinstance(numbers, list):
                nick_name = account_service.get_inner_user_account_info(
                    session, user_id).get("nick_name")
                try:
                    # 添加参与记录
                    participate_in_model = ParticipateInModel(
                        game_instance_id=model._id,
                        template_id=model.template_id,
                        game_serial=model.game_serial,
                        game_title=model.game_title,
                        release_type=model.release_type,
                        bet_token=model.bet_token,
                        bet_unit=model.bet_unit,
                        user_id=user_id,
                        nick_name=nick_name,
                        channel=user_channel_id,
                        bet_number=int(bet_amount),
                        pay_token=int(conin_id),
                        pay_number=get_decimal(bet_money,
                                               digits=8,
                                               decimal_type="down"),
                        award_numbers=json.dumps(numbers),
                        user_type=0,
                        merge_id=merge_id)
                    session.add(participate_in_model)
                    session.flush()
                    # raise_logger("add participate_in_model", "game_bet_in", "info")
                    # 提交扣款申请
                    result = account_service.do_bet(
                        session, user_id, conin_id,
                        get_decimal(bet_money, digits=8, decimal_type="down"),
                        str(participate_in_model._id), int(bet_amount),
                        model.game_serial, user_channel_id)
                    # raise_logger("do_bet success", "game_bet_in", "info")
                    if isinstance(result, int):
                        if result == 0:
                            # 修改项目状态
                            game_service = GameService()
                            # raise_logger("modifyDigitalInstance begin", "game_bet_in", "info")
                            if game_service.modifyDigitalInstance(
                                    model, {
                                        "game_id": id,
                                        "add_bet_number": int(bet_amount),
                                        "full_load_time":
                                        participate_in_model.created_at,
                                        "add_people": 1
                                    }) is False:
                                session.rollback()
                                raise_logger("modifyDigitalInstance err",
                                             "game_bet_in", "info")
                                return self.return_error(80005)
                            # raise_logger("modifyDigitalInstance succ", "game_bet_in", "info")
                            try:
                                created_at_str = str(
                                    participate_in_model.created_at)
                                update_at_str = str(
                                    participate_in_model.update_at)
                                deleted_at_str = str(
                                    participate_in_model.deleted_at)
                                deleted_str = str(participate_in_model.deleted)
                                if BlockChainInfoService(
                                ).insert_block_chain_info(
                                        user_id,
                                        participate_in_model.game_instance_id,
                                        1,
                                    {
                                        "id":
                                        participate_in_model._id,
                                        "created_at":
                                        created_at_str[0:19],
                                        "update_at":
                                        update_at_str[0:19],
                                        "deleted_at":
                                        deleted_at_str[0:19],
                                        "deleted":
                                        deleted_str[0:19],
                                        "game_instance_id":
                                        str(participate_in_model.
                                            game_instance_id),
                                        "template_id":
                                        participate_in_model.template_id,
                                        "game_serial":
                                        participate_in_model.game_serial,
                                        "bet_token":
                                        participate_in_model.bet_token,
                                        "user_id":
                                        participate_in_model.user_id,
                                        "nick_name":
                                        participate_in_model.nick_name,
                                        "channel":
                                        participate_in_model.channel,
                                        "pay_token":
                                        participate_in_model.pay_token,
                                        "bet_number":
                                        participate_in_model.bet_number,
                                        "pay_number":
                                        str(participate_in_model.pay_number),
                                        "award_numbers":
                                        participate_in_model.award_numbers,
                                        "user_type":
                                        participate_in_model.user_type,
                                    }):
                                    participate_in_model.chain_status = 1
                                    # raise_logger("insert_block succ", "game_bet_in", "info")
                                else:
                                    raise_logger("insert_block err",
                                                 "game_bet_in", "info")
                            except Exception as e:
                                session.rollback()
                                raise_logger(e, "game_bet_in", "info")
                            # raise_logger("pri del GameNumbersSetModel", "game_bet_in", "info")
                            for i in numbers:
                                # raise_logger("pri del GameNumbersSetModel", "game_bet_in", "info")
                                # game_number_filters = {"game_serial": model.game_serial, "number": i}
                                session.query(GameNumbersSetModel). \
                                    filter(GameNumbersSetModel.game_serial == model.game_serial,
                                           GameNumbersSetModel.number == i).delete()
                                # number_filter.time_stamp = 1
                                # session.delete(num_filters)
                            # raise_logger("GameNumbersSetModel delete succ", "game_bet_in", "info")

                            # # 检测游戏是否售罄需要申请开奖
                            # instance = session.query(GameDigitalInstanceModel).filter(
                            #     GameDigitalInstanceModel._id == id).first()
                            if int(model.status) == 1:
                                add_result = WalletEosService().lottery_adduce(
                                    id, get_timestamp(model.full_load_time))
                                if not add_result:
                                    raise_logger("lottery_adduce fail",
                                                 "game_bet_in", "info")

                            session.commit()
                            # raise_logger("commit succ", "game_bet_in", "info")
                            try:
                                # # 提交验证是否需要上线新项目
                                game_service.automatic_release(
                                    session, model.template_id)
                            except Exception as e:
                                raise_logger(e, "game_bet_in", "info")

                            can_merge = False
                            if int(
                                    bet_amount
                            ) >= model.merge_threshold and merge_id == -1:
                                can_merge = True
                            # raise_logger("pri return", "game_bet_in", "info")
                            return {
                                'numbers': numbers,
                                'can_merge': can_merge,
                                'part_in_id': participate_in_model._id
                            }

                        else:
                            session.rollback()
                            return self.return_error(60009)
                    else:
                        session.rollback()
                        return self.return_error(60010)

                except Exception as e:
                    raise_logger(e, "game_bet_in", "info")
                    session.rollback()
                    return self.return_error(60011)

                if isinstance(numbers, int):
                    session.rollback()
                    return self.return_error(60012)

            else:
                session.rollback()
                return self.return_error(60007)
Example #3
0
    def main_page(self):
        with MysqlTools().session_scope() as session:
            account_service = AccountService()
            banners = []
            announcements = []
            participates = []
            instance_info = {}
            merges = []
            banner_list = session.query(BannerManageModel). \
                filter(BannerManageModel.status == 1).all()
            if len(banner_list) > 0:
                for banner in banner_list:
                    banners.append({
                        'image': banner.image,
                        'site': banner.site
                    })
            announcement_list = session.query(AnnouncementManageModel). \
                filter(AnnouncementManageModel.status == 1).all()
            if len(announcement_list) > 0:
                for announcement in announcement_list:
                    announcements.append({
                        'title': announcement.title,
                        'site': announcement.site
                    })
            participate_list = session.query(ParticipateInModel). \
                order_by(ParticipateInModel.created_at.desc()).limit(5).offset(0).all()
            if len(participate_list) > 0:
                for participate in participate_list:
                    if participate.user_type == 0:
                        user_info = account_service.get_inner_user_account_info(
                            session, participate.user_id)
                        user_name = user_info['nick_name']
                    else:
                        user_name = participate.nick_name
                    participates.append({
                        "user":
                        user_name,
                        "bet_time":
                        str(participate.created_at),
                        "channel":
                        participate.channel,
                        "bet_token":
                        participate.bet_token,
                        "bet_number":
                        participate.bet_number,
                        "pay_token":
                        participate.pay_token,
                        "pay_number":
                        str(participate.pay_number)
                    })
            instance = session.query(GameDigitalInstanceModel). \
                order_by(GameDigitalInstanceModel.status.asc(),
                         GameDigitalInstanceModel.created_at.desc()).first()

            ins_instance = session.query(InstantGameInstanceModel). \
                order_by(InstantGameInstanceModel.status.asc(),
                         InstantGameInstanceModel.created_at.desc()).first()
            if ins_instance is None:
                ins_instance = {
                    'id': '',
                    'game_serial': '',
                    # 'game_title': instance.game_title,
                    # 'game_describe': instance.game_describe,
                    # 'status': instance.status,
                    'support_token': '',
                    'reward_token': '',
                    'reward_quantity': '',
                }
            else:
                ins_instance = {
                    'id': ins_instance._id,
                    'game_serial': ins_instance.game_serial,
                    'support_token': ins_instance.support_token,
                    'reward_token': ins_instance.reward_token,
                    'reward_quantity': ins_instance.reward_quantity,
                }
            winner = ''
            bet_serial = ''
            bet_number = 0
            merge_id = -1
            if instance is not None:
                merge_list = session.query(MergeParticipateInModel). \
                    filter(MergeParticipateInModel.game_instance_id == instance._id). \
                    order_by(MergeParticipateInModel.created_at.desc()).limit(3).offset(0).all()
                if len(merge_list) > 0:
                    merge_id = 1
                    for merge in merge_list:
                        initiate_user = account_service.get_inner_user_account_info(
                            session, merge.initiate_user_id)
                        merges.append({
                            'merge_id':
                            merge._id,
                            'name':
                            initiate_user['nick_name'],
                            'portrait':
                            initiate_user['profile_picture']
                        })
                if instance.status == 2:
                    winning_record = session.query(WinningRecordModel). \
                        filter(WinningRecordModel.game_instance_id == instance._id).first()
                    if winning_record is not None:
                        if winning_record.user_type == 0:
                            account_service = AccountService()
                            user_info = account_service.get_inner_user_account_info(
                                session, winning_record.user_id)
                            winner = user_info['nick_name']
                        elif winning_record.user_type == 1:
                            robot = session.query(RobotAccountModel).filter(
                                RobotAccountModel.user_id ==
                                winning_record.user_id).first()
                            winner = robot.nick_name
                        else:
                            winner = 'X@17Yau8'
                        bet_serial = winning_record.bet_serial
                        merge_id = winning_record.merge_id
                        bet_number = winning_record.bet_number
                # progress = 0
                progress = (instance.bet_number / instance.need) * 100
                if 0 < progress < 1:
                    progress = 1
                if progress > 1:
                    progress = int(progress)
                result = {
                    'banner_list': banners,
                    'announcement_list': announcements,
                    'ins_instance': ins_instance,
                    'instance': {
                        'id': instance._id,
                        'game_serial': instance.game_serial,
                        'game_title': instance.game_title,
                        'game_describe': instance.game_describe,
                        'progress': progress,
                        'remain': int(instance.need - instance.bet_number),
                        'status': instance.status,
                        'lottery_time': str(instance.lottery_time),
                        'winners': winner,
                        'bet_serial': bet_serial,
                        'bet_token': self.get_coin_name(instance.bet_token),
                        'bet_number': bet_number,
                        'reward_token':
                        self.get_coin_name(instance.reward_token),
                        'reward_quantity': instance.reward_quantity,
                        'merge_id': merge_id,
                        'merge_list': merges
                    },
                    'participate': participates
                }
            else:
                result = {
                    'banner_list': banners,
                    'announcement_list': announcements,
                    'instance': {},
                    'participate': participates
                }
        return result
Example #4
0
    def game_instance_info_list(self, limit, offset, status='', start_id=None):
        offset = get_offset_by_page(offset, limit)
        result_dict = {
            'limit': limit,
            'offset': offset,
            'count': 0,
            'content': []
        }
        account_service = AccountService()
        with MysqlTools().session_scope() as session:
            if status != '':
                q = session.query(GameDigitalInstanceModel). \
                    order_by(GameDigitalInstanceModel.status.asc(),
                             GameDigitalInstanceModel.created_at.desc(),
                             GameDigitalInstanceModel._id != 0)
                q = q.filter(GameDigitalInstanceModel.status == status)
            else:
                q = session.query(GameDigitalInstanceModel). \
                    order_by(GameDigitalInstanceModel.created_at.desc(),
                             GameDigitalInstanceModel._id != 0)
            record_count = q.count()
            result_dict['count'] = get_page_by_offset(record_count, limit)
            if start_id is not None:
                start_id = str(start_id)
                q = q.filter(GameDigitalInstanceModel._id < start_id)
            query_result = q.limit(limit).offset(offset).all()
            winner = ''
            bet_serial = ''
            bet_number = 0
            # --------------- 即时开 --------------- #
            if status == '':
                ins_instance = session.query(InstantGameInstanceModel). \
                    order_by(InstantGameInstanceModel.created_at.desc()).first()
                if ins_instance is not None:
                    result_dict['content'].append({
                        'id':
                        ins_instance._id,
                        'created_at':
                        str(ins_instance.created_at),
                        'game_serial':
                        ins_instance.game_serial,
                        'game_title':
                        ins_instance.game_title,
                        'progress':
                        0,
                        'remain':
                        0,
                        'bet_token':
                        self.get_coin_name(ins_instance.bet_token),
                        'bet_number':
                        0,
                        'reward_token':
                        self.get_coin_name(ins_instance.reward_token),
                        'reward_quantity':
                        ins_instance.reward_quantity,
                        'support_token':
                        ins_instance.support_token,
                        'status':
                        -1,
                        'lottery_time':
                        str(ins_instance.lottery_time),
                        'winners':
                        '',
                        'bet_serial':
                        '',
                        'game_describe':
                        ins_instance.game_describe,
                        'participation':
                        ins_instance.participation,
                        'merge_id':
                        -1,
                        'merge_list': []
                    })
            # --------------- 即时开end --------------- #
            for i in query_result:
                merge_id = -1
                merges = []
                merge_list = session.query(MergeParticipateInModel). \
                    filter(MergeParticipateInModel.game_instance_id == i._id). \
                    order_by(MergeParticipateInModel.created_at.desc()).limit(3).offset(0).all()
                if len(merge_list) > 0:
                    merge_id = 1
                    for merge in merge_list:
                        initiate_user = account_service.get_inner_user_account_info(
                            session, merge.initiate_user_id)
                        merges.append({
                            'merge_id':
                            merge._id,
                            'name':
                            initiate_user['nick_name'],
                            'portrait':
                            initiate_user['profile_picture']
                        })
                if i.status == 2:
                    winning_record = session.query(WinningRecordModel). \
                        filter(WinningRecordModel.game_instance_id == i._id).first()
                    if winning_record is not None:
                        if winning_record.user_type == 0:
                            account_service = AccountService()
                            user_info = account_service.get_inner_user_account_info(
                                session, winning_record.user_id)
                            winner = user_info['nick_name']
                        elif winning_record.user_type == 1:
                            robot = session.query(RobotAccountModel).filter(
                                RobotAccountModel.user_id ==
                                winning_record.user_id).first()
                            winner = robot.nick_name
                        else:
                            winner = 'X@17Yau8'
                        bet_serial = winning_record.bet_serial
                        merge_id = winning_record.merge_id
                        bet_number = winning_record.bet_number
                progress = 0
                progress = (i.bet_number / i.need) * 100
                if 0 < progress < 1:
                    progress = 1
                if progress > 1:
                    progress = int(progress)

                result_dict['content'].append({
                    'id':
                    i._id,
                    'created_at':
                    str(i.created_at),
                    'game_serial':
                    i.game_serial,
                    'game_title':
                    i.game_title,
                    'progress':
                    progress,
                    'remain':
                    int(i.need - i.bet_number),
                    'bet_token':
                    self.get_coin_name(i.bet_token),
                    'bet_number':
                    bet_number,
                    'reward_token':
                    self.get_coin_name(i.reward_token),
                    'reward_quantity':
                    i.reward_quantity,
                    'support_token':
                    i.support_token,
                    'status':
                    i.status,
                    'lottery_time':
                    str(i.lottery_time),
                    'winners':
                    winner,
                    'bet_serial':
                    bet_serial,
                    'game_describe':
                    i.game_describe,
                    'participation':
                    i.participation,
                    'merge_id':
                    merge_id,
                    'merge_list':
                    merges
                })
        return result_dict
Example #5
0
    def bet_in(self, dic):
        change_type_41 = '41'  # 即时开中奖
        change_type_42 = '42'  # 即时开投注
        id = dic.get("game_instance_id", "")  # 项目id
        user_id = dic.get("user_id", "")  # 用户id
        user_channel_id = dic.get("user_channel_id", "")  # 用户下注渠道id
        conin_id = dic.get("coin_id", "")  # 投入币种id
        bet_amount = dic.get("bet_amount", "")  # 投注数量
        bet_start = dic.get("bet_start", 0)
        bet_end = dic.get("bet_end", 0)
        faker = True
        # merge_id = dic.get("merge_id", -1)  # 合并投注id
        # transaction_password = dic.get("transaction_password", "")  # 交易密码
        with MysqlTools().session_scope() as session:
            # 查询项目
            model = session.query(InstantGameInstanceModel).filter(
                InstantGameInstanceModel._id == id).first()
            template = session.query(InstantGameTemplateModel). \
                order_by(InstantGameTemplateModel._id.desc()).first()
            if model is None:
                return self.return_error(60001)
            if model.status == 1:
                return self.return_error(60002)
            if model.status == 2:
                return self.return_error(60003)
            if model.status == 0:
                can_bet = model.need - model.bet_number
                if can_bet <= 0:
                    return self.return_error(60002)
                if int(bet_amount) > can_bet:
                    return self.return_error(60004)

            if model.support_token >= 0 and int(
                    conin_id) != model.support_token and int(conin_id) != int(
                        _COIN_ID_EXP):
                return self.return_error(60008)

            if int(bet_amount) > model.need * (model.max_bet_ratio / 100):
                return self.return_error(40025)

            # 查询币价 币种实际需要金额
            exchange_rate = get_exchange_rate(int(conin_id))

            # (投注数量 * 投注单位) / 投注币种兑换usdt比例
            bet_money = (int(bet_amount) *
                         model.bet_unit) / exchange_rate['price']

            # 体验金相关逻辑
            if int(conin_id) == int(_COIN_ID_EXP):
                # 检查本次投注体验金使用数量 (允许范围: 1~10)
                if int(bet_amount) < 1 or int(bet_amount) > 10:
                    self.return_error(60015)
                # 体验金使用额度
                exp = int(model.experience / 100 * model.need)
                # 检查项目体验金占比剩余额度以及个人当天最大体验金使用额度(每天最多用10个)
                limit = self.check_instance_exp_limit(session, user_id,
                                                      model.game_serial)
                # instance_limit = limit['instance_limit']
                user_limit = limit['user_limit']
                total_pay_number = limit['total_pay_number']
                if user_limit > 10 - int(bet_amount):
                    self.return_error(60017)
                # if instance_limit >= exp:
                #     self.return_error(60016)
                if total_pay_number >= int(
                        model.need) * model.reward_quantity * (
                            (100 + template.exceeded_ratio) / 100):
                    model.full_load_time = datetime.datetime.utcnow()
                    faker = False
            else:
                limit = self.check_instance_exp_limit(session, user_id,
                                                      model.game_serial)
                total_pay_number = limit['total_pay_number']
                raise_logger("总下注金额" + "USDT:" + str(total_pay_number),
                             "game_publish_lottery", "info")
                if total_pay_number >= int(
                        model.need) * model.reward_quantity * (
                            (100 + template.exceeded_ratio) / 100):
                    model.full_load_time = datetime.datetime.utcnow()
                    faker = False

            # 查询用户资产
            account_service = AccountService()
            user_info = account_service.get_inner_user_account_by_token(
                session, user_id, conin_id)
            if isinstance(user_info, int):
                if user_info == 20001:
                    return self.return_error(20001)

            balance = get_decimal(user_info.get("balance"),
                                  digits=8,
                                  decimal_type="down")

            # 账户余额 < 需要下注金额
            if balance < bet_money:
                return self.return_error(60005)

            # 获取下注编号
            numbers = []
            user_lottery_num_list = []
            i = int(bet_amount)
            # start_num = random.randint(1, model.need 0- int(bet_amount))
            bet_start = int(bet_start)
            bet_end = int(bet_end)
            user_lottery_num_list.append(bet_start)
            user_lottery_num_list.append(bet_end)
            while i > 0:
                numbers.append(bet_start)
                bet_start += 1
                i -= 1
            if isinstance(numbers, list):
                nick_name = account_service.get_inner_user_account_info(
                    session, user_id).get("nick_name")
                # 添加参与记录
                participate_in_model = ParticipateInModel(
                    game_instance_id=0,
                    template_id=model.template_id,
                    game_serial=model.game_serial,
                    game_title=model.game_title,
                    release_type=model.release_type,
                    bet_token=model.bet_token,
                    bet_unit=model.bet_unit,
                    user_id=user_id,
                    nick_name=nick_name,
                    channel=user_channel_id,
                    bet_number=int(bet_amount),
                    pay_token=int(conin_id),
                    pay_number=get_decimal(bet_money,
                                           digits=8,
                                           decimal_type="down"),
                    award_numbers=json.dumps(numbers),
                    user_type=0,
                    merge_id=-1)
                session.add(participate_in_model)
                session.flush()
                # raise_logger("add participate_in_model", "game_bet_in", "info")
                # 提交扣款申请
                result = account_service.do_bet(
                    session, user_id, conin_id,
                    get_decimal(bet_money, digits=8, decimal_type="down"),
                    str(participate_in_model._id), int(bet_amount),
                    model.game_serial, user_channel_id, change_type_42)
                # raise_logger("do_bet success", "game_bet_in", "info")
                if isinstance(result, int):
                    if result == 0:
                        instant_game_service = InstantGameModelService()
                        # print('user_lottery_num_list-=-=', user_lottery_num_list)
                        # print('model.need-=-=', model.need)
                        # print('faker-=-=', faker)
                        lottery_result = WalletEosService().\
                            lottery_instant_adduce(get_timestamp(), user_lottery_num_list, model.need, faker)
                        # print('lottery_result-=-=', lottery_result)
                        if not any(lottery_result):
                            raise_logger("lottery_result empty", "game_bet_in",
                                         "info")
                            session.rollback()
                            return self.return_error(40026)
                        # 开奖
                        hash_numbers = lottery_result['block_hash']
                        raise_logger(
                            "项目:" + str(id) + "   中奖区块号:" + str(hash_numbers),
                            "game_publish_lottery", "info")
                        if hash_numbers == "":
                            raise_logger("开奖异常:80001", "game_publish_lottery",
                                         "info")
                            return False
                        # prize_number = int(hash_numbers, 16) % model.need + 1
                        prize_number = lottery_result['lottery_num']
                        raise_logger(
                            "项目:" + str(id) + "    中奖号码:" + str(prize_number),
                            "game_publish_lottery", "info")
                        participate_in_model.win_number = prize_number
                        participate_in_model.block_no = lottery_result[
                            'block_num']
                        participate_in_model.bet_hash = hash_numbers
                        participate_in_model.received_time = lottery_result[
                            'timestamp']
                        # 中奖
                        is_win = False
                        if prize_number in numbers:
                            is_win = True
                            participate_in_model.result = 1
                            model.lottery_time = datetime.datetime.utcnow()
                            instant_game_service.automatic_release(
                                session, model.template_id)
                            do_win = account_service.do_win(
                                session, user_id, model.reward_token,
                                model.reward_quantity,
                                str(participate_in_model._id), int(bet_amount),
                                model.game_serial, change_type_41)
                            if isinstance(do_win, int) is False:
                                raise_logger("分钱失败" + "user:"******"game_publish_lottery", "info")
                                session.rollback()
                                return False
                            if do_win != 0:
                                raise_logger("分钱失败" + "user:"******"game_publish_lottery", "info")
                                session.rollback()
                                return False

                        session.commit()

                        return {
                            'is_win': is_win,
                            'prize_number': prize_number,
                            'part_in_id': participate_in_model._id
                        }
                    else:
                        session.rollback()
                        return self.return_error(60009)
                else:
                    session.rollback()
                    return self.return_error(60010)
            else:
                session.rollback()
                return self.return_error(60007)
Example #6
0
 def get_instant_part_in_list(self,
                              limit,
                              offset,
                              game_serial='',
                              bet_time_start='',
                              bet_time_end='',
                              result='',
                              user_name='',
                              start_id=None):
     offset = get_offset_by_page(offset, limit)
     result_dict = {
         'limit': limit,
         'offset': offset,
         'count': 0,
         'content': [],
         'total': 0
     }
     with MysqlTools().session_scope() as session:
         account_service = AccountService()
         q = session.query(ParticipateInModel)
         if user_name != '':
             q = q.filter(ParticipateInModel.nick_name == user_name)
         if game_serial != '':
             q = q.filter(ParticipateInModel.game_serial == game_serial)
         if bet_time_start != '':
             q = q.filter(ParticipateInModel.created_at >= bet_time_start)
         if bet_time_end != '':
             q = q.filter(ParticipateInModel.created_at <= bet_time_end)
         if result != '':
             q = q.filter(ParticipateInModel.result == result)
         game_instance_id = 0
         q = q.filter(
             ParticipateInModel.game_instance_id == game_instance_id)
         record_count = q.count()
         result_dict['total'] = record_count
         result_dict['count'] = get_page_by_offset(record_count, limit)
         if start_id is not None:
             start_id = str(start_id)
             q = q.filter(ParticipateInModel._id < start_id)
         q = q.order_by(ParticipateInModel.created_at.desc())
         participate_in_list = q.limit(limit).offset(offset).all()
         for participate in participate_in_list:
             # user_type 0:真实用户  1:机器人
             if participate.user_type == 0:
                 user_info = account_service.get_inner_user_account_info(
                     session, participate.user_id)
                 user_name = user_info['nick_name']
             else:
                 user_name = participate.nick_name
             is_win = False
             if participate.win_number in participate.award_numbers:
                 is_win = True
             result_dict['content'].append({
                 "id":
                 participate._id,
                 "user":
                 user_name,
                 "bet_time":
                 str(participate.created_at),
                 "channel":
                 participate.channel,
                 "bet_token":
                 self.get_coin_name(participate.bet_token),
                 "bet_unit":
                 participate.bet_unit,
                 "bet_number":
                 decimal_to_str(participate.bet_number, 8),
                 "pay_token":
                 self.get_coin_name(participate.pay_token),
                 "pay_number":
                 decimal_to_str(participate.pay_number, 8),
                 'game_serial':
                 participate.game_serial,
                 "is_win":
                 is_win
             })
     return result_dict