예제 #1
0
 def get_comment_list(self, limit, offset, user_id):
     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(MineCommentsModel). \
             filter(MineCommentsModel.status == 1). \
             order_by(MineCommentsModel.created_at.desc())
         record_count = q.count()
         result_dict['total'] = record_count
         result_dict['count'] = get_page_by_offset(record_count, limit)
         query_result = q.all()
         if query_result is not None:
             for i in query_result:
                 # user_info = account_service.get_inner_user_account_info(session, i.user_id)
                 is_praise = self.get_is_praise(user_id, i.praise_users)
                 result_dict['content'].append({
                     'user_name': i.user_name,
                     'submit_content': i.submit_content,
                     'submit_image': i.submit_image,
                     'submit_thumbnail': i.submit_thumbnail,
                     'praise_number': i.praise_number,
                     'is_praise': is_praise,
                     'status': i.status
                 })
         return result_dict
예제 #2
0
 def get_banner_list(self, limit, offset, title='', site='', online_time_start='',
                     online_time_end='', status='', create_time_start='',
                     create_time_end=''):
     offset = get_offset_by_page(offset, limit)
     result_dict = {
         'limit': limit,
         'offset': offset,
         'count': 0,
         'content': [],
         'total': 0
     }
     with MysqlTools().session_scope() as session:
         q = session.query(BannerManageModel). \
             order_by(BannerManageModel.created_at.desc())
         if title != '':
             q = q.filter(BannerManageModel.title == title)
         if site != '':
             q = q.filter(BannerManageModel.site == site)
         if status != '':
             q = q.filter(BannerManageModel.status == status)
         if create_time_start != '':
             q = q.filter(BannerManageModel.created_at >= create_time_start)
         if create_time_end != '':
             q = q.filter(BannerManageModel.created_at <= create_time_end)
         if online_time_start != '':
             q = q.filter(BannerManageModel.auto_online >= online_time_start)
         if online_time_end != '':
             q = q.filter(BannerManageModel.auto_online <= online_time_end)
         record_count = q.count()
         result_dict['total'] = record_count
         result_dict['count'] = get_page_by_offset(record_count, limit)
         query_result = q.all()
         if query_result is not None:
             for i in query_result:
                 result_dict['content'].append({
                     'id': i._id,
                     "title": i.title,
                     'site': i.site,
                     'status': i.status,
                     'image': i.image,
                     'thumbnail': i.thumbnail,
                     'created_at': str(i.created_at),
                     'auto_online': str(i.auto_online),
                     'remark': i.remark
                 })
         return result_dict
예제 #3
0
    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
예제 #4
0
 def comment_manage_list(self, limit, offset, user_name='', key_word='', release_time_start='',
                         release_time_end='', status='', picture=''):
     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(MineCommentsModel). \
             order_by(MineCommentsModel.created_at.desc())
         if user_name != '':
             q = q.filter(MineCommentsModel.user_name == user_name)
         if key_word != '':
             q = q.filter(MineCommentsModel.submit_content.like('%' + key_word + '%'))
         if status != '':
             q = q.filter(MineCommentsModel.status == status)
         if release_time_start != '':
             q = q.filter(MineCommentsModel.created_at >= release_time_start)
         if release_time_end != '':
             q = q.filter(MineCommentsModel.created_at <= release_time_end)
         if picture == '1':
             q = q.filter(MineCommentsModel.submit_image != '')
         if picture == '0':
             q = q.filter(MineCommentsModel.submit_image == '')
         record_count = q.count()
         result_dict['total'] = record_count
         result_dict['count'] = get_page_by_offset(record_count, limit)
         query_result = q.all()
         if query_result is not None:
             for i in query_result:
                 # user_info = account_service.get_inner_user_account_info(session, i.user_id)
                 result_dict['content'].append({
                     "user_name": i.user_name,
                     'submit_content': i.submit_content,
                     'submit_image': i.submit_image,
                     'submit_thumbnail': i.submit_thumbnail,
                     'praise_number': i.praise_number,
                     'status': i.status
                 })
         return result_dict
예제 #5
0
    def search_robot_config(self, dic):
        limit = int(dic.get('limit', 10))
        offset = get_offset_by_page(dic.get('offset', 1), limit)
        start_id = dic.get("start_id", None)

        total = 0
        count = 0
        with MysqlTools().session_scope() as session:
            game_config = session.query(RobotGameConfigRecordModel).filter(
                RobotGameConfigRecordModel._id == dic['id']).first()
            q = session.query(RobotConfigRecordModel).filter(
                RobotConfigRecordModel.time_stamp == game_config.time_stamp)

            total = q.count()
            count = get_page_by_offset(total, limit)

            if start_id is not None:
                q = q.filter(RobotConfigRecordModel._id < str(start_id))
            query_result = q.order_by(RobotConfigRecordModel._id.asc()).limit(
                limit).offset(offset).all()

            content = []
            if len(query_result) > 0:
                for i in query_result:
                    content.append({
                        'user_id': str(i.user_id),
                        'nick_name': i.nick_name,
                        'bet_number': str(i.bet_number),
                        'pay_token': str(i.pay_token),
                        'bet_plan_time': str(i.bet_plan_time),
                        'bet_status': str(i.bet_status),
                    })

            return {
                'limit': dic.get('limit', 10),
                'offset': dic.get('offset', 1),
                'count': count,
                'total:': total,
                'content': content
            }
    def newest_online_record(game_serial, page_num, page_limit, start_id,
                             record_type, timezone):
        # response structure
        response_dict = {
            'limit': page_limit,
            'offset': page_num,
            'count': 0,
            'content': []
        }
        page_offset = get_offset_by_page(page_num, page_limit)
        page_limit = str(page_limit)

        # query info
        with MysqlTools().session_scope() as session:
            query = session.query(
                BlockChainInfoModel._id, BlockChainInfoModel.instance_id,
                BlockChainInfoModel.record_type,
                BlockChainInfoModel.participate_id,
                BlockChainInfoModel.on_chain_info,
                BlockChainInfoModel.on_chain_at).filter(
                    BlockChainInfoModel.on_chain_status == 1,
                    BlockChainInfoModel.deleted == False).order_by(
                        BlockChainInfoModel.on_chain_at.desc())

            # 计算不分页的总页数
            record_count = query.count()
            response_dict['count'] = get_page_by_offset(
                record_count, page_limit)

            if game_serial is not None:
                query = query.filter(
                    BlockChainInfoModel.game_serial == game_serial)

            if record_type is not None:
                query = query.filter(
                    BlockChainInfoModel.record_type == record_type)

            if start_id is not None:
                start_id = str(start_id)
                query = query.filter(BlockChainInfoModel._id < start_id)

            query = query.limit(page_limit).offset(page_offset)

            record_list = query.all()

            for one_record in record_list:
                on_chain_info = json.loads(one_record.on_chain_info)
                response_dict['content'].append({
                    'id':
                    one_record._id,
                    'instance_id':
                    one_record.instance_id,
                    "record_type":
                    RECORD_TYPE_DICT[one_record.record_type],
                    "nick_name":
                    on_chain_info.get("nick_name", ""),
                    "bet_number":
                    on_chain_info.get("bet_number", ""),
                    "participate_id":
                    one_record.participate_id,
                    "on_chain_at":
                    time_transform_from_zone(
                        one_record.on_chain_at.strftime("%Y-%m-%d %H:%M:%S"),
                        timezone)
                })

            return response_dict
예제 #7
0
    def search_model(self, dic):
        count = 0
        total = 0
        number_games = []
        object_games = []

        if dic is None:
            dic = {}

        limit = int(dic.get('limit', 10))
        offset = get_offset_by_page(dic.get('offset', 1), limit)
        start_id = dic.get("start_id", None)

        with MysqlTools().session_scope() as session:
            q = session.query(GameDigitalTemplateModel)
            if dic.get('id', '') != '':
                q = q.filter(GameDigitalTemplateModel._id == dic['id'])
            if dic.get('game_title', '') != '':
                q = q.filter(
                    GameDigitalTemplateModel.game_title == dic['game_title'])
            if dic.get('reward_quantity', '') != '':
                q = q.filter(GameDigitalTemplateModel.reward_quantity == int(
                    dic['reward_quantity']))

            if dic.get('release_time_start', '') != '':
                q = q.filter(GameDigitalTemplateModel.created_at >=
                             dic['release_time_start'])
            if dic.get('release_time_end', '') != '':
                q = q.filter(GameDigitalTemplateModel.created_at <=
                             dic['release_time_end'])

            if dic.get('template_status', '') != '':
                q = q.filter(GameDigitalTemplateModel.template_status == int(
                    dic['template_status']))
            if dic.get('auto_release', '') != '':
                q = q.filter(GameDigitalTemplateModel.auto_release == int(
                    dic['auto_release']))

            total = q.count()
            count = get_page_by_offset(total, limit)

            if start_id is not None:
                q = q.filter(GameDigitalTemplateModel._id < str(start_id))

            query_result = q.order_by(
                GameDigitalTemplateModel._id.desc()).limit(limit).offset(
                    offset).all()

            # if len(query_result) == 0:
            #     return self.return_error(50001)
            if len(query_result) >= 0:
                for i in query_result:
                    number_games.append({
                        'id':
                        str(i._id),
                        'game_title':
                        i.game_title,
                        'reward_token':
                        i.reward_token,
                        'bet_token':
                        i.bet_token,
                        'bet_unit':
                        i.bet_unit,
                        'reward_quantity':
                        i.reward_quantity,
                        'need_ceiling':
                        i.need_ceiling,
                        'need_floor':
                        i.need_floor,
                        'exceeded_ratio':
                        i.exceeded_ratio,
                        'experience':
                        i.experience,
                        'merge_threshold':
                        i.merge_threshold,
                        'handling_fee':
                        str(i.handling_fee),
                        'support_token':
                        i.support_token,
                        'template_status':
                        i.template_status,
                        'auto_release':
                        i.auto_release,
                        'game_describe':
                        i.game_describe,
                        # 'phase_prefix': i.phase_prefix,
                        # 'phase_date': i.phase_date,
                        'phase_serial':
                        i.phase_prefix + i.phase_date + i.phase_serial,
                        'agreement':
                        i.agreement,
                        'agreement_name':
                        i.agreement_name,
                        'created_at':
                        str(i.created_at),
                        'update_at':
                        str(i.update_at)
                    })
                # print("number_games:", number_games)

        if dic.get("model_type") == "1":
            return {
                'limit': dic.get('limit', 10),
                'offset': dic.get('offset', 1),
                'count': count,
                'total': total,
                'number_games': number_games
            }

        if dic.get("model_type") == "2":
            return {
                'limit': dic.get('limit', 10),
                'offset': dic.get('offset', 1),
                'count': count,
                'total': total,
                'object_games': object_games
            }

        return {
            "data": {
                "number_games": number_games,
                "object_games": object_games
            }
        }
예제 #8
0
    def search_game_robot_config(self, dic):
        if dic is None:
            dic = {}

        limit = int(dic.get('limit', 10))
        offset = get_offset_by_page(dic.get('offset', 1), limit)
        start_id = dic.get("start_id", None)

        total = 0
        count = 0
        with MysqlTools().session_scope() as session:
            q = session.query(RobotGameConfigRecordModel)
            if dic.get('id', '') != '':
                q = q.filter(RobotGameConfigRecordModel._id == dic['id'])
            if dic.get('game_serial', '') != '':
                q = q.filter(RobotGameConfigRecordModel.game_serial ==
                             dic['game_serial'])
            if dic.get('plan_start_time_first', '') != '':
                q = q.filter(RobotGameConfigRecordModel.start_of_plan_time >=
                             dic['start_of_plan_time'])
            if dic.get('plan_start_time_finish', '') != '':
                q = q.filter(RobotGameConfigRecordModel.start_of_plan_time <=
                             dic['start_of_plan_time'])

            if dic.get('plan_end_time_first', '') != '':
                q = q.filter(RobotGameConfigRecordModel.end_of_plan_time >=
                             dic['plan_end_time_first'])
            if dic.get('plan_end_time_finish', '') != '':
                q = q.filter(RobotGameConfigRecordModel.end_of_plan_time <=
                             dic['plan_end_time_first'])

            if dic.get('status', '') != '':
                q = q.filter(
                    RobotGameConfigRecordModel.status == int(dic['status']))

            if dic.get('real_end_time_first', '') != '':
                q = q.filter(RobotGameConfigRecordModel.end_of_real_time ==
                             dic['real_end_time_first'])
            if dic.get('real_end_time_finish', '') != '':
                q = q.filter(RobotGameConfigRecordModel.end_of_real_time ==
                             dic['real_end_time_finish'])

            if dic.get('robot_bet_type', '') != '':
                q = q.filter(RobotGameConfigRecordModel.robot_bet_type == int(
                    dic['robot_bet_type']))

            total = q.count()
            count = get_page_by_offset(total, limit)

            if start_id is not None:
                q = q.filter(RobotGameConfigRecordModel._id < str(start_id))

            query_result = q.order_by(
                RobotGameConfigRecordModel._id.desc()).limit(limit).offset(
                    offset).all()

            if len(query_result) <= 0:
                return self.return_error(50001)

            content = []
            for i in query_result:
                robots = session.query(RobotConfigRecordModel).filter(
                    RobotConfigRecordModel.time_stamp == i.time_stamp)
                count = robots.count()
                finish_count = robots.filter(
                    RobotConfigRecordModel.bet_status == 1).count()

                yet_bet_number = 0
                if count != 0:
                    for robot in robots:
                        yet_bet_number = yet_bet_number + robot.bet_number

                end_of_real_time = ''
                if ("1970-01-01 00:00:00" != str(i.end_of_real_time)
                        and "0000-00-00 00:00:00" != str(i.end_of_real_time)):
                    end_of_real_time = str(i.end_of_real_time)

                completion = "0"
                if count != 0:
                    completion = str(finish_count / count * 100) + "%"

                content.append({
                    'id': str(i._id),
                    'game_serial': i.game_serial,
                    'robot_number': str(i.robot_number),
                    'yet_bet_number': str(yet_bet_number),
                    'total_bet_number': str(i.total_bet_number),
                    'created_at': str(i.created_at),
                    'start_of_plan_time': str(i.start_of_plan_time),
                    'end_of_plan_time': str(i.end_of_plan_time),
                    'end_of_real_time': end_of_real_time,
                    'completion': completion,
                    'status': str(i.status),
                    'robot_bet_type': str(i.robot_bet_type),
                    'created_user_id': str(i.created_user_id)
                })

            return {
                'limit': dic.get('limit', 10),
                'offset': dic.get('offset', 1),
                'count': count,
                'total': total,
                'content': content
            }
 def instant_game_list(self,
                       limit,
                       offset,
                       game_serial='',
                       release_time_start='',
                       release_time_end='',
                       full_load_time_start='',
                       full_load_time_end='',
                       lottery_time_start='',
                       lottery_time_end='',
                       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:
         q = session.query(InstantGameInstanceModel)
         if game_serial != '':
             q = q.filter(
                 InstantGameInstanceModel.game_serial == game_serial)
         if release_time_start != '':
             q = q.filter(
                 InstantGameInstanceModel.created_at >= release_time_start)
         if release_time_end != '':
             q = q.filter(
                 InstantGameInstanceModel.created_at <= release_time_end)
         if full_load_time_start != '':
             q = q.filter(InstantGameInstanceModel.full_load_time >=
                          full_load_time_start)
         if full_load_time_end != '':
             q = q.filter(InstantGameInstanceModel.full_load_time <=
                          full_load_time_end)
         if lottery_time_start != '':
             q = q.filter(
                 InstantGameInstanceModel.lottery_time >= lottery_time_start
             )
         if lottery_time_end != '':
             q = q.filter(
                 InstantGameInstanceModel.lottery_time <= lottery_time_end)
         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(InstantGameInstanceModel._id < start_id)
         q = q.order_by(InstantGameInstanceModel.created_at.desc())
         query_result = q.limit(limit).offset(offset).all()
         if query_result is not None:
             for i in query_result:
                 total_bet_number = session.query(
                     func.sum(ParticipateInModel.bet_number * ParticipateInModel.bet_unit)). \
                     filter(ParticipateInModel.game_serial == i.game_serial,
                            ParticipateInModel.pay_token != int(_COIN_ID_EXP)).first()
                 total_bet = 0
                 if total_bet_number[0] is not None:
                     total_bet = int(total_bet_number[0])
                 result_dict['content'].append({
                     'id':
                     i._id,
                     'game_serial':
                     i.game_serial,  # 期号
                     'game_title':
                     i.game_title,
                     'bet_unit':
                     i.bet_unit,
                     'bet_token':
                     self.get_coin_name(i.bet_token),
                     'reward_quantity':
                     i.reward_quantity,  # 奖励数量
                     'reward_token':
                     self.get_coin_name(i.reward_token),  # 奖励币种
                     'release_time':
                     str(i.created_at),  # 上线时间
                     'status':
                     i.status,
                     'need':
                     i.need,  # 本期份额
                     'full_load_time':
                     str(i.full_load_time),  # 超募完成时间
                     'lottery_time':
                     str(i.lottery_time),  # 下线时间
                     'release_type':
                     i.release_type,
                     'participation':
                     i.participation,
                     'total_bet':
                     total_bet
                 })
         return result_dict
예제 #10
0
    def indiana_record_new(self, limit, offset, user_id, start_id=None):
        offset = get_offset_by_page(offset, limit)
        result_dict = {
            'limit': limit,
            'offset': offset,
            'count': 0,
            'content': []
        }
        with MysqlTools().session_scope() as session:
            q = session.query(ParticipateInModel._id,
                              ParticipateInModel.game_instance_id, ParticipateInModel.game_serial,
                              ParticipateInModel.bet_token,
                              ParticipateInModel.award_numbers,
                              ParticipateInModel.win_number,
                              (ParticipateInModel.bet_unit * ParticipateInModel.bet_number).label(
                                  'total_bet'),
                              ParticipateInModel.merge_id, ParticipateInModel.created_at,
                              ParticipateInModel.pay_token, ParticipateInModel.pay_number). \
                filter(ParticipateInModel.user_id == user_id). \
                order_by(ParticipateInModel.created_at.desc())
            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(ParticipateInModel._id < start_id)
            participate_list = q.limit(limit).offset(offset).all()
            for i in participate_list:
                award_numbers_list = i.award_numbers
                if i.game_instance_id == 0:
                    instance_info = session.query(InstantGameInstanceModel.need, InstantGameInstanceModel.status,
                                                  InstantGameInstanceModel.bet_token,
                                                  InstantGameInstanceModel.participation). \
                        filter(InstantGameInstanceModel.game_serial == i.game_serial).first()
                    if instance_info is None:
                        continue
                    if i.win_number in award_numbers_list:
                        is_win = True
                    else:
                        is_win = False
                else:
                    instance_info = session.query(GameDigitalInstanceModel.need, GameDigitalInstanceModel.status,
                                                  GameDigitalInstanceModel._id,
                                                  GameDigitalInstanceModel.bet_token,
                                                  GameDigitalInstanceModel.participation). \
                        filter(GameDigitalInstanceModel._id == i.game_instance_id).first()
                    if instance_info is None:
                        continue
                    if instance_info.status == 2:
                        winning_record = session.query(WinningRecordModel). \
                            filter(WinningRecordModel.game_instance_id == instance_info._id).first()
                        if winning_record.bet_serial in award_numbers_list:
                            is_win = True
                        else:
                            is_win = False
                    else:
                        is_win = False
                if int(i.pay_token) == int(_COIN_ID_EXP):
                    pay_number = int(i.pay_number)
                else:
                    pay_number = decimal_to_str(i.pay_number, 8)
                result_dict['content'].append({
                    'is_win':
                    is_win,
                    'instance_id':
                    i.game_instance_id,
                    'participate_id':
                    i._id,
                    'game_serial':
                    i.game_serial,
                    'bet_token':
                    self.get_coin_name(i.bet_token),
                    'total_bet':
                    int(i.total_bet),
                    # 'need': instance_info.need,
                    'status':
                    instance_info.status,
                    'need_token':
                    self.get_coin_name(instance_info.bet_token),
                    # 'probability': probability,
                    # 'ranking': math.ceil((lower / total) * 100),
                    'merge_id':
                    i.merge_id,
                    'part_in_time':
                    str(i.created_at),
                    "pay_token":
                    self.get_coin_name(i.pay_token),
                    "pay_number":
                    pay_number
                })

        return result_dict
예제 #11
0
    def indiana_record(self, limit, offset, user_id, start_id=None):
        offset = get_offset_by_page(offset, limit)
        result_dict = {
            'limit': limit,
            'offset': offset,
            'count': 0,
            'content': []
        }
        with MysqlTools().session_scope() as session:
            q = session.query(ParticipateInModel._id,
                              ParticipateInModel.game_instance_id, ParticipateInModel.game_serial,
                              ParticipateInModel.bet_token,
                              (ParticipateInModel.bet_unit * ParticipateInModel.bet_number).label(
                                  'total_bet'),
                              ParticipateInModel.merge_id, ParticipateInModel.created_at,
                              ParticipateInModel.pay_token, ParticipateInModel.pay_number). \
                filter(ParticipateInModel.user_id == user_id). \
                order_by(ParticipateInModel.created_at.desc())
            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(ParticipateInModel._id < start_id)
            participate_list = q.limit(limit).offset(offset).all()
            for i in participate_list:
                instance_info = session.query(GameDigitalInstanceModel.need, GameDigitalInstanceModel.status,
                                              GameDigitalInstanceModel.bet_token,
                                              GameDigitalInstanceModel.participation). \
                    filter(GameDigitalInstanceModel._id == i.game_instance_id).first()
                if instance_info is None:
                    continue
                total = instance_info.participation
                lower = session.query((func.count(ParticipateInModel._id)).label('lower_users')). \
                    filter(ParticipateInModel.game_instance_id == i.game_instance_id,
                           ParticipateInModel.bet_unit * ParticipateInModel.bet_number < int(i.total_bet)). \
                    first()
                hc = hcf(int(i.total_bet), int(instance_info.need))
                probability = str(int(int(i.total_bet) / hc)) + '/' + str(
                    int(int(instance_info.need) / hc))
                if lower is None:
                    lower = total
                else:
                    lower = lower.lower_users
                if int(i.pay_token) == int(_COIN_ID_EXP):
                    pay_number = int(i.pay_number)
                else:
                    pay_number = decimal_to_str(i.pay_number, 8)
                result_dict['content'].append({
                    'instance_id':
                    i.game_instance_id,
                    'participate_id':
                    i._id,
                    'game_serial':
                    i.game_serial,
                    'bet_token':
                    self.get_coin_name(i.bet_token),
                    'total_bet':
                    int(i.total_bet),
                    'need':
                    instance_info.need,
                    'status':
                    instance_info.status,
                    'need_token':
                    self.get_coin_name(instance_info.bet_token),
                    'probability':
                    probability,
                    'ranking':
                    math.ceil((lower / total) * 100),
                    'merge_id':
                    i.merge_id,
                    'part_in_time':
                    str(i.created_at),
                    "pay_token":
                    self.get_coin_name(i.pay_token),
                    "pay_number":
                    pay_number
                })

        return result_dict
예제 #12
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
예제 #13
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