Ejemplo n.º 1
0
 def gather_address_list(self, sub_public_address, coin_id, update_at_start, update_at_end, status, offset, limit):
     """
     归集地址列表
     :param sub_public_address: 地址
     :param coin_id: 币种(必填)
     :param update_at_start: 最近一次变动时间start
     :param update_at_end: 最近一次变动时间end
     :param status: 启用状态:0-停用, 1-启用
     :param offset: 当前页数
     :param limit: 每页条数
     :return:
     """
     filters = {}
     if sub_public_address:
         filters["sub_public_address"] = sub_public_address
     filters["coin_id"] = coin_id
     if not update_at_start:
         update_at_start = "0000-00-00"
     else:
         update_at_start = update_at_start
     if not update_at_end:
         update_at_end = "2999-12-31"
     else:
         update_at_end = update_at_end
     if status:
         filters["status"] = status
     with MysqlTools().session_scope() as session:
         if coin_id == _ZERO_S:
             model = WalletBtcGatherModel
         elif coin_id == _SIXTY_S:
             model = WalletEthGatherModel
         elif coin_id == _COIN_ID_EOS:
             model = WalletEosGatherModel
         g = session.query(model).filter_by(**filters).filter(
             model.update_at >= update_at_start,
             model.update_at <= update_at_end)
         count = g.count()
         if int(offset) == 0:
             gather_list = g
         else:
             gather_list = g.limit(
                 limit).offset(get_offset_by_page(offset, limit))
         result_list = []
         for g in gather_list:
             map = {}
             map["sub_public_address"] = str(g.sub_public_address)
             map["coin_id"] = str(coin_id)
             map["amount"] = decimal_to_str(g.amount)
             map["amount_change"] = decimal_to_str(g.amount_change)
             map["status"] = str(g.status)
             map["update_at"] = str(g.update_at)
             result_list.append(map)
         result_map = {}
         result_map["count"] = str(count)
         result_map["list"] = result_list
         return result_map
Ejemplo n.º 2
0
 def get_game_instance(self, user_id=''):
     with MysqlTools().session_scope() as session:
         account_service = AccountService()
         instance_info = session.query(InstantGameInstanceModel). \
             order_by(InstantGameInstanceModel.created_at.desc()).first()
         if instance_info is None:
             self.return_error(40005)
         balance_btc = ''
         balance_eth = ''
         balance_usdt = ''
         balance_eos = ''
         balance_exp = ''
         if user_id != '':
             account_balance = account_service.get_user_token_list(
                 user_id, None, 1, 10)['content'][0]
             balance_btc = account_balance['BTC']
             balance_eth = account_balance['ETH']
             if account_balance.get('EOS', None) is not None:
                 balance_eos = account_balance['EOS']
             else:
                 balance_eos = 0
             balance_usdt = account_balance['USDT']
             balance_exp = account_balance['USDT_EXPERIENCE']
         result = {
             'instance': {
                 'id': instance_info._id,
                 'game_serial': instance_info.game_serial,
                 'game_title': instance_info.game_title,
                 'game_describe': instance_info.game_describe,
                 'need': instance_info.need,
                 'status': instance_info.status,
                 'bet_token': self.get_coin_name(instance_info.bet_token),
                 'max_bet_ratio': instance_info.max_bet_ratio
             },
             'current_price': {
                 'from': get_exchange_rate(int(_COIN_ID_BTC))['from'],
                 'eth': get_exchange_rate(int(_COIN_ID_ETH))['price'],
                 'btc': get_exchange_rate(int(_COIN_ID_BTC))['price'],
                 'eos': get_exchange_rate(int(_COIN_ID_EOS))['price']
             },
             'balance': {
                 'btc': decimal_to_str(balance_btc, 8),
                 'eth': decimal_to_str(balance_eth, 8),
                 'eos': decimal_to_str(balance_eos, 8),
                 'usdt': decimal_to_str(balance_usdt, 4),
                 'exp': decimal_to_str(balance_exp, 4),
             }
         }
         return result
Ejemplo n.º 3
0
 def gather_record(self, public_address, coin_id, operate_at_start, operate_at_end, offset, limit):
     """
     归集操作记录
     :param public_address: 归集地址
     :param coin_id: 币种
     :param operate_at_start: 操作时间start
     :param operate_at_end: 操作时间end
     :param offset: 当前页数
     :param limit: 每页条数
     :return:
     """
     filters = {}
     if public_address:
         filters["public_address"] = public_address
     if coin_id:
         filters["coin_id"] = coin_id
     if not operate_at_start:
         operate_at_start = "0000-00-00"
     else:
         operate_at_start = operate_at_start
     if not operate_at_end:
         operate_at_end = "2999-12-31"
     else:
         operate_at_end = operate_at_end
     with MysqlTools().session_scope() as session:
         g = session.query(ForeignGatherRecordModel).filter_by(**filters).filter(
             ForeignGatherRecordModel.created_at >= operate_at_start,
             ForeignGatherRecordModel.created_at <= operate_at_end)
         count = g.count()
         gather_list = g.order_by(desc(ForeignGatherRecordModel._id)).limit(
             limit).offset(get_offset_by_page(offset, limit))
         result_list = []
         for g in gather_list:
             map = {}
             map["record_id"] = str(g.record_id)  # ID
             map["created_at"] = str(g.created_at)  # 操作时间
             map["coin_id"] = str(g.coin_id)  # 币种
             map["amount"] = decimal_to_str(g.purpose_amount)  # 数量
             map["fee"] = decimal_to_str(g.actual_fee)  # 归集手续费
             withdraw_list = session.query(ForeignWithdrawOrderRecordModel).filter(
                 ForeignWithdrawOrderRecordModel.relate_flow_no == g.record_id)
             map["number"] = str(withdraw_list.count())  # 操作账号数量
             map["public_address"] = str(g.public_address)  # 归集地址
             result_list.append(map)
         result_map = {}
         result_map["count"] = str(count)
         result_map["list"] = result_list
         return result_map
Ejemplo n.º 4
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
Ejemplo n.º 5
0
 def indiana_detail(self, instance_id, participate_id):
     release_time = '---------------'
     full_load_time = '---------------'
     lottery_time = '---------------'
     with MysqlTools().session_scope() as session:
         instance_info = session.query(GameDigitalInstanceModel). \
             filter(GameDigitalInstanceModel._id == instance_id).first()
         if instance_info is None:
             self.return_error(40005)
         bet_serial = ''
         if instance_info.status == 2:
             release_time = str(instance_info.release_time)
             full_load_time = str(instance_info.full_load_time)
             lottery_time = str(instance_info.lottery_time)
             # 中奖号
             winning_info = session.query(WinningRecordModel). \
                 filter(WinningRecordModel.game_instance_id == instance_id).first()
             bet_serial = winning_info.bet_serial
         elif instance_info.status == 0:
             release_time = str(instance_info.release_time)
         elif instance_info.status == 1:
             release_time = str(instance_info.release_time)
             full_load_time = str(instance_info.full_load_time)
         part_info = session.query(ParticipateInModel). \
             filter(ParticipateInModel._id == participate_id).first()
         if part_info is None:
             self.return_error(40016)
         if int(part_info.pay_token) == int(_COIN_ID_EXP):
             pay_number = str(int(part_info.pay_number))
         else:
             pay_number = decimal_to_str(part_info.pay_number, 8)
     return {
         'game_serial': instance_info.game_serial,
         'status': instance_info.status,
         'need': instance_info.need,
         'bet_token': instance_info.bet_token,
         'bet_unit': instance_info.bet_unit,
         'reward_token': instance_info.reward_token,
         'reward_quantity': instance_info.reward_quantity,
         'release_time': release_time,
         'full_load_time': full_load_time,
         'lottery_time': lottery_time,
         'bet_serial': bet_serial,
         'participation': instance_info.participation,
         'part_in_time': str(part_info.created_at),
         'bet_number': part_info.bet_number,
         'merge_id': part_info.merge_id,
         'pay_token': part_info.pay_token,
         'pay_number': pay_number
     }
Ejemplo n.º 6
0
 def gather_address_record(self, sub_public_address, relevant_address, transfer_at_start, transfer_at_end,
                           operation_type, offset,
                           limit):
     """
     归集地址流水
     :param sub_public_address: 地址(必填)
     :param relevant_address: 相关地址
     :param transfer_at_start: 操作时间start
     :param transfer_at_end: 操作时间end
     :param operation_type: 操作类型:1-收款, 2-出款[提现类型: 0-用户提现, 1-用户中奖, 2-归集, 3-归集转归集]
     :param offset: 当前页数
     :param limit: 每页条数
     :return:
     """
     if not transfer_at_start:
         transfer_at_start = "0000-00-00"
     else:
         transfer_at_start = transfer_at_start
     if not transfer_at_end:
         transfer_at_end = "2999-12-31"
     else:
         transfer_at_end = transfer_at_end
     with MysqlTools().session_scope() as session:
         coin_id = _ZERO_S
         gather = session.query(WalletBtcGatherModel).filter(
             WalletBtcGatherModel.sub_public_address == sub_public_address).first()
         if gather is None:
             coin_id = _SIXTY_S
         f = session.query(ForeignWithdrawOrderRecordModel, UserAccountModel).filter(
             ForeignWithdrawOrderRecordModel.transfer_at >= transfer_at_start,
             ForeignWithdrawOrderRecordModel.transfer_at <= transfer_at_end)
         if relevant_address:
             f = f.filter(or_(
                 ForeignWithdrawOrderRecordModel.from_address == relevant_address,
                 ForeignWithdrawOrderRecordModel.withdraw_address == relevant_address))
         if not operation_type:  # 全部
             fw = f.outerjoin(
                 UserAccountModel,
                 ForeignWithdrawOrderRecordModel.account_id == UserAccountModel.account_id)
         elif operation_type == _ONE_S:  # 收款
             fw = f.filter(
                 ForeignWithdrawOrderRecordModel.withdraw_type == _TWO_S).outerjoin(
                 UserAccountModel,
                 ForeignWithdrawOrderRecordModel.account_id == UserAccountModel.account_id)
         elif operation_type == _TWO_S:  # 出款
             fw = f.filter(
                 ForeignWithdrawOrderRecordModel.withdraw_type == _ZERO_S).outerjoin(
                 UserAccountModel,
                 ForeignWithdrawOrderRecordModel.account_id == UserAccountModel.account_id)
         count = fw.count()
         record_list = fw.order_by(desc(ForeignWithdrawOrderRecordModel.transfer_at)).limit(
             limit).offset(get_offset_by_page(offset, limit))
         result_list = []
         for r in record_list:
             map = {}
             map["order_no"] = str(r.ForeignWithdrawOrderRecordModel.order_no)
             map["user_name"] = ""
             try:
                 map["user_name"] = str(r.UserAccountModel.user_name)
             except:
                 pass
             map["transfer_at"] = str(r.ForeignWithdrawOrderRecordModel.transfer_at)
             map["withdraw_amount"] = decimal_to_str(r.ForeignWithdrawOrderRecordModel.withdraw_amount)
             map["withdraw_fee"] = decimal_to_str(r.ForeignWithdrawOrderRecordModel.withdraw_fee)
             map["operation_type"] = ""
             map["relevant_address"] = ""
             withdraw_type = str(r.ForeignWithdrawOrderRecordModel.withdraw_type)
             from_address = str(r.ForeignWithdrawOrderRecordModel.from_address)
             withdraw_address = str(r.ForeignWithdrawOrderRecordModel.withdraw_address)
             if withdraw_type == _ZERO_S:  # 提现
                 map["operation_type"] = "2"  # 出款
                 map["relevant_address"] = withdraw_address
             elif withdraw_type == _TWO_S:  # 归集
                 map["operation_type"] = "1"  # 收款
                 map["relevant_address"] = from_address
             map["operation_user"] = str(r.ForeignWithdrawOrderRecordModel.operation_user)
             result_list.append(map)
         result_map = {}
         result_map["count"] = str(count)
         result_map["list"] = result_list
         return result_map
Ejemplo n.º 7
0
    def gather_record_all(self, user_name, from_address, operate_at_start, operate_at_end, withdraw_address, coin_id,
                          confirm_at_start, confirm_at_end, withdraw_status, offset, limit):
        """
        归集操作记录详情
        :param user_name: 用户名
        :param from_address: 用户钱包地址
        :param operate_at_start: 操作时间start
        :param operate_at_end: 操作时间end
        :param withdraw_address: 归集地址
        :param coin_id: 币种
        :param confirm_at_start: 结束时间start
        :param confirm_at_end: 结束时间end
        :param withdraw_status: 状态: 1-归集中, 2-成功, 3-失败
        :param offset: 当前页数
        :param limit: 每页条数
        :return:
        """
        u_filters = {}
        if user_name:
            u_filters["user_name"] = user_name

        f_filters = {}
        f_filters["withdraw_type"] = _TWO_S
        if from_address:
            f_filters["from_address"] = from_address
        if withdraw_address:
            f_filters["withdraw_address"] = withdraw_address
        if coin_id:
            f_filters["coin_id"] = coin_id
        if withdraw_status:
            f_filters["withdraw_status"] = withdraw_status
        if not operate_at_start:
            operate_at_start = "0000-00-00"
        else:
            operate_at_start = operate_at_start
        if not operate_at_end:
            operate_at_end = "2999-12-31"
        else:
            operate_at_end = operate_at_end
        if not confirm_at_start:
            confirm_at_start = "0000-00-00"
        else:
            confirm_at_start = confirm_at_start
        if not confirm_at_end:
            confirm_at_end = "2999-12-31"
        else:
            confirm_at_end = confirm_at_end
        with MysqlTools().session_scope() as session:
            g = session.query(ForeignWithdrawOrderRecordModel, UserAccountModel).filter_by(
                **f_filters).filter(
                ForeignWithdrawOrderRecordModel.created_at >= operate_at_start,
                ForeignWithdrawOrderRecordModel.created_at <= operate_at_end,
                ForeignWithdrawOrderRecordModel.confirm_at >= confirm_at_start,
                ForeignWithdrawOrderRecordModel.confirm_at <= confirm_at_end).outerjoin(
                UserAccountModel,
                ForeignWithdrawOrderRecordModel.account_id == UserAccountModel.account_id).filter_by(**u_filters)
            count = g.count()
            gather_list = g.order_by(desc(ForeignWithdrawOrderRecordModel._id)).limit(
                limit).offset(get_offset_by_page(offset, limit))
            result_map = {}
            list = []
            for g in gather_list:
                map = {}
                map["user_name"] = ""
                try:
                    map["user_name"] = str(g.UserAccountModel.user_name)  # 用户名
                except:
                    pass
                map["order_no"] = str(g.ForeignWithdrawOrderRecordModel.order_no)
                map["from_address"] = str(g.ForeignWithdrawOrderRecordModel.from_address)  # 用户钱包地址
                map["created_at"] = str(g.ForeignWithdrawOrderRecordModel.created_at)  # 操作时间
                map["coin_id"] = str(g.ForeignWithdrawOrderRecordModel.coin_id)  # 归集币种
                map["withdraw_amount"] = decimal_to_str(g.ForeignWithdrawOrderRecordModel.withdraw_amount)  # 数量
                map["withdraw_fee"] = decimal_to_str(g.ForeignWithdrawOrderRecordModel.withdraw_fee)  # 手续费
                map["confirm_at"] = str(g.ForeignWithdrawOrderRecordModel.confirm_at)  # 结束时间
                map["withdraw_address"] = str(g.ForeignWithdrawOrderRecordModel.withdraw_address)  # 归集地址
                map["withdraw_status"] = str(g.ForeignWithdrawOrderRecordModel.withdraw_status)
                list.append(map)
            result_map["count"] = count
            result_map["list"] = list
            return result_map
Ejemplo n.º 8
0
    def gather_record_details(self, record_id, user_name, from_address, operate_at_start, operate_at_end,
                              withdraw_status,
                              confirm_at_start, confirm_at_end, offset, limit):
        """
        归集操作记录详情
        :param record_id: record_id
        :param user_name: 用户名
        :param from_address: 用户钱包地址
        :param operate_at_start: 操作时间start
        :param operate_at_end: 操作时间end
        :param withdraw_status: 状态: 1-归集中, 2-成功, 3-失败
        :param confirm_at_start: 结束时间start
        :param confirm_at_end: 结束时间end
        :param offset: 当前页数
        :param limit: 每页条数
        :return:
        """
        u_filters = {}
        if user_name:
            u_filters["user_name"] = user_name

        f_filters = {}
        f_filters["relate_flow_no"] = record_id
        if from_address:
            f_filters["from_address"] = from_address
        if withdraw_status:
            f_filters["withdraw_status"] = withdraw_status
        if not operate_at_start:
            operate_at_start = "0000-00-00"
        else:
            operate_at_start = operate_at_start
        if not operate_at_end:
            operate_at_end = "2999-12-31"
        else:
            operate_at_end = operate_at_end
        if not confirm_at_start:
            confirm_at_start = "0000-00-00"
        else:
            confirm_at_start = confirm_at_start
        if not confirm_at_end:
            confirm_at_end = "2999-12-31"
        else:
            confirm_at_end = confirm_at_end
        with MysqlTools().session_scope() as session:
            gather_model = session.query(ForeignGatherRecordModel).filter(
                ForeignGatherRecordModel.record_id == record_id).first()
            result_map = {}
            info = {}
            info["coin_id"] = str(gather_model.coin_id)
            info["amount"] = decimal_to_str(gather_model.actual_amount)
            info["fee"] = decimal_to_str(gather_model.actual_fee)
            withdraw_list = session.query(ForeignWithdrawOrderRecordModel).filter(
                ForeignWithdrawOrderRecordModel.relate_flow_no == record_id)
            info["number"] = str(withdraw_list.count())  # 操作账号数量
            info["created_at"] = str(gather_model.created_at)
            info["public_address"] = str(gather_model.public_address)
            result_map["info"] = info
            g = session.query(ForeignWithdrawOrderRecordModel, UserAccountModel).filter_by(
                **f_filters).filter(
                ForeignWithdrawOrderRecordModel.created_at >= operate_at_start,
                ForeignWithdrawOrderRecordModel.created_at <= operate_at_end,
                ForeignWithdrawOrderRecordModel.confirm_at >= confirm_at_start,
                ForeignWithdrawOrderRecordModel.confirm_at <= confirm_at_end).outerjoin(
                UserAccountModel,
                ForeignWithdrawOrderRecordModel.account_id == UserAccountModel.account_id).filter_by(**u_filters)
            count = g.count()
            gather_list = g.limit(
                limit).offset(get_offset_by_page(offset, limit))
            list = []
            for g in gather_list:
                map = {}
                map["user_name"] = ""
                try:
                    map["user_name"] = str(g.UserAccountModel.user_name)  # 用户名
                except:
                    pass
                map["from_address"] = str(g.ForeignWithdrawOrderRecordModel.from_address)  # 用户钱包地址
                map["created_at"] = str(g.ForeignWithdrawOrderRecordModel.created_at)  # 操作时间
                map["coin_id"] = str(g.ForeignWithdrawOrderRecordModel.coin_id)  # 币种
                map["withdraw_amount"] = decimal_to_str(g.ForeignWithdrawOrderRecordModel.withdraw_amount)  # 数量
                map["withdraw_fee"] = decimal_to_str(g.ForeignWithdrawOrderRecordModel.withdraw_fee)  # 手续费
                map["confirm_at"] = str(g.ForeignWithdrawOrderRecordModel.confirm_at)  # 结束时间
                map["withdraw_address"] = str(g.ForeignWithdrawOrderRecordModel.withdraw_address)  # 归集地址
                map["withdraw_status"] = str(g.ForeignWithdrawOrderRecordModel.withdraw_status)  # 状态
                list.append(map)
            result_map["count"] = count
            result_map["list"] = list
            return result_map
Ejemplo n.º 9
0
    def sub_address_list(self, user_name, sub_public_address, conditions, coin_id, offset, limit):
        """
        子账户地址列表
        :param user_name: 用户名
        :param sub_public_address: 钱包地址
        :param conditions: 归集条件(大于等于xx个单位)
        :param coin_id: 币种(必填)
        :param offset: 当前页数
        :param limit: 每页条数
        :return:
        """
        f_filters = {}
        u_filters = {}
        if user_name:
            u_filters["user_name"] = user_name
        if sub_public_address:
            f_filters["sub_public_address"] = sub_public_address
        if not conditions:
            conditions = 0
        with MysqlTools().session_scope() as session:
            model = None
            if coin_id == _ZERO_S:
                model = WalletBtcModel
            elif coin_id == _SIXTY_S:
                model = WalletEthModel
            w = session.query(model, UserAccountModel).filter(
                model.amount >= conditions, model.account_id != "").filter_by(**f_filters).outerjoin(
                UserAccountModel,
                model.account_id == UserAccountModel.account_id).filter_by(**u_filters)
            count = w.count()
            # 计算可归集总额
            total_amount = 0
            for o in w:
                amount = 0
                if coin_id == _ZERO_S:
                    amount = o.WalletBtcModel.amount
                elif coin_id == _SIXTY_S:
                    amount = o.WalletEthModel.amount
                total_amount = total_amount + amount

            wallet_list = w.limit(
                limit).offset(get_offset_by_page(offset, limit))
            result_list = []
            for w in wallet_list:
                map = {}
                map["user_name"] = ""
                try:
                    map["user_name"] = str(w.UserAccountModel.user_name)
                except:
                    pass
                map["coin_id"] = coin_id
                amount = 0
                if coin_id == _ZERO_S:
                    map["sub_public_address"] = str(w.WalletBtcModel.sub_public_address)
                    amount = w.WalletBtcModel.amount
                    map["amount"] = decimal_to_str(amount)
                    map["amount_frozen"] = decimal_to_str(w.WalletBtcModel.amount_frozen)
                elif coin_id == _SIXTY_S:
                    map["sub_public_address"] = str(w.WalletEthModel.sub_public_address)
                    amount = w.WalletEthModel.amount
                    map["amount"] = decimal_to_str(amount)
                    map["amount_frozen"] = decimal_to_str(w.WalletEthModel.amount_frozen)
                result_list.append(map)
            result_map = {}
            result_map["count"] = str(count)
            result_map["total_amount"] = decimal_to_str(total_amount)
            result_map["list"] = result_list
            return result_map
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 12
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
Ejemplo n.º 13
0
    def dice_sold_out_new(self, dice_id):
        change_type_31 = '31'  # 扣款
        change_type_32 = '32'  # 返还
        change_type_33 = '33'  # 中奖
        reward_quantity = decimal.Decimal(0)
        with MysqlTools().session_scope() as session:
            account_service = AccountService()
            dice_info = session.query(DiceParticipateInModel). \
                filter(DiceParticipateInModel._id == dice_id).first()
            if dice_info is None:
                self.return_error(40021)
            ec = TokenNodeConfModel.get_eos_node_script(script_unit=_THREE_S)
            latest_eos_block_info = ec.http_get_latest_block()
            # print('latest_eos_block_info=-=-=', latest_eos_block_info)
            dice_info.block_no = latest_eos_block_info.get('block_num', None)
            dice_info.block_timestamp = latest_eos_block_info.get(
                'timestamp', None)
            dice_info.block_hash = latest_eos_block_info.get('id', None)
            if dice_info.block_no is None or \
                    dice_info.block_timestamp is None or \
                    dice_info.block_hash is None:
                self.return_error(40024)
            else:
                dice_result = -1
                banker_dice = int(dice_info.block_hash, 16) % 3  # 0石头 1剪刀 2布
                user_dice = dice_info.user_dice  # 0石头 1剪刀 2布
                if banker_dice == user_dice:
                    dice_result = 1  # 0用户胜 1平局 2庄家胜 -1未知
                else:
                    if banker_dice == 0 and user_dice == 1:
                        dice_result = 2
                    elif banker_dice == 0 and user_dice == 2:
                        dice_result = 0
                    elif banker_dice == 1 and user_dice == 0:
                        dice_result = 0
                    elif banker_dice == 1 and user_dice == 2:
                        dice_result = 2
                    elif banker_dice == 2 and user_dice == 0:
                        dice_result = 2
                    elif banker_dice == 2 and user_dice == 1:
                        dice_result = 0
                dice_info.banker_dice = banker_dice
                dice_info.dice_result = dice_result
                # session.flush()
                if dice_result in [0, 1]:
                    change_type = change_type_32
                    dice_config = session.query(DiceConfigModel). \
                        filter(DiceConfigModel.support_token_id == dice_info.bet_token).first()
                    if dice_config is None:
                        return self.return_error(40022)
                    if dice_result == 0:
                        change_type = change_type_33
                        # 用户获胜 中奖金额为投注金额+奖励金额(投注金额=奖励金额) 扣除手续费
                        reward_quantity = (
                            dice_info.reward_quantity + dice_info.bet_number
                        ) * (100 - dice_config.handling_fee) / 100
                        dice_info.reward_quantity = reward_quantity
                    elif dice_result == 1:
                        change_type = change_type_32
                        # 平局 中奖金额为投注金额
                        reward_quantity = dice_info.bet_number
                    result = account_service.do_win(
                        session, dice_info.user_id, dice_info.reward_token,
                        reward_quantity, 'dice_win' + str(dice_info._id),
                        dice_info.user_dice, dice_info.dice_serial,
                        change_type)
                    if isinstance(result, int) is False:
                        raise_logger(
                            "dice分钱失败" + "user:"******"game_publish_lottery", "info")
                        session.rollback()
                        return False
                    if result != 0:
                        raise_logger(
                            "dice分钱失败" + "user:"******"game_publish_lottery", "info")
                        session.rollback()
                        return False
            # ret_info = dice_info
            # print(ret_info)
            session.commit()
            session.refresh(dice_info)
            # session.expunge(dice_info)
        response = {
            'dice_result': dice_info.dice_result,
            'banker_dice': dice_info.banker_dice,
            'user_dice': dice_info.user_dice,
            # 'dice_timestamp': timestamp_to_str(dice_info.dice_timestamp, format_style="%Y-%m-%d %H:%M:%S"),
            'dice_id': str(dice_info._id),
            'dice_serial': dice_info.dice_serial,
            'reward_token': self.get_coin_name(dice_info.reward_token),
            'reward_quantity': decimal_to_str(reward_quantity, 6)
            # 'reward_quantity': decimal_to_str(
            #     str((dice_info.bet_number + dice_info.bet_number) * decimal.Decimal(0.99)), 6)
        }

        if dice_info.reward_token == int(_COIN_ID_USDT):
            response['reward_quantity'] = decimal_to_str(reward_quantity, 4)
        return response
Ejemplo n.º 14
0
    def dice_chip_in_fast(self, user_id, user_channel_id, coin_id, bet_amount,
                          user_dice):
        change_type_31 = '31'  # 扣款
        change_type_32 = '32'  # 返还
        change_type_33 = '33'  # 中奖
        with MysqlTools().session_scope() as session:
            # 查询用户资产
            account_service = AccountService()
            user_info = account_service.get_inner_user_account_by_token(
                session, user_id, coin_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")
            # 账户余额 < 需要下注金额
            bet_number = get_decimal(bet_amount, digits=4, decimal_type="down")
            if balance < bet_number:
                return self.return_error(60005)
            dice_serial = dice_generate_phase()
            # 获取最新eos区块,计算开奖区块高度
            dice_time = get_timestamp()
            ec = TokenNodeConfModel.get_eos_node_script(script_unit=_THREE_S)
            latest_eos_block_info = ec.http_get_latest_block()
            # print('latest_eos_block_info=-=-=', latest_eos_block_info)
            block_no = latest_eos_block_info['block_num']

            dice_part_in_model = DiceParticipateInModel(
                dice_serial=dice_serial,
                user_id=user_id,
                user_dice=user_dice,
                channel=user_channel_id,
                bet_number=bet_number,
                bet_token=coin_id,
                reward_token=coin_id,
                reward_quantity=bet_number,
                dice_timestamp=dice_time,
                block_no=block_no)
            session.add(dice_part_in_model)
            session.flush()
            # 提交扣款申请
            dice_part_id = dice_part_in_model._id
            result = account_service.do_bet(
                session, user_id, coin_id, bet_number,
                'dice_bet' + str(dice_part_in_model._id), 1, dice_serial,
                user_channel_id, change_type_31)
            if result != 0:
                session.rollback()
                raise_logger("do_bet result" + str(result), "game_bet_in",
                             "info")

            # -------------------------------- 开奖 -------------------------------- #
            block_timestamp = latest_eos_block_info['timestamp']
            block_hash = latest_eos_block_info['id']
            dice_result = -1
            banker_dice = int(block_hash, 16) % 3  # 0石头 1剪刀 2布
            user_dice = int(user_dice)
            if banker_dice == user_dice:
                dice_result = 1  # 0用户胜 1平局 2庄家胜 -1未知
            else:
                if banker_dice == 0 and user_dice == 1:
                    dice_result = 2
                elif banker_dice == 0 and user_dice == 2:
                    dice_result = 0
                elif banker_dice == 1 and user_dice == 0:
                    dice_result = 0
                elif banker_dice == 1 and user_dice == 2:
                    dice_result = 2
                elif banker_dice == 2 and user_dice == 0:
                    dice_result = 2
                elif banker_dice == 2 and user_dice == 1:
                    dice_result = 0
            dice_part_in_model.banker_dice = banker_dice
            dice_part_in_model.dice_result = dice_result
            dice_part_in_model.block_hash = block_hash
            dice_part_in_model.block_timestamp = block_timestamp
            # session.flush()
            change_type = change_type_32

            # ------------ 中奖控制 ------------ #
            winning_control = 0
            if dice_result in [0, 1]:
                win_dice_num = session.query(func.count(DiceParticipateInModel._id)). \
                    filter(DiceParticipateInModel.user_id == user_id,
                           DiceParticipateInModel.dice_result == 0,
                           func.date_format(DiceParticipateInModel.created_at, "%Y-%m-%d") ==
                           func.date_format(get_utc_now(), "%Y-%m-%d")).first()
                if win_dice_num[0] >= decimal.Decimal(500):
                    raise_logger(
                        "dice winning control userid = " + str(user_id),
                        "game_bet_in", "info")
                    dice_part_in_model.banker_dice = user_dice
                    dice_part_in_model.dice_result = 1
                    dice_result = 1
                    winning_control = 1
            # ------------ 中奖控制结束 ------------ #

            if dice_result in [0, 1]:
                reward_quantity = 0
                dice_config = session.query(DiceConfigModel). \
                    filter(DiceConfigModel.support_token_id == dice_part_in_model.bet_token).first()
                if dice_config is None:
                    return self.return_error(40022)
                if dice_result == 0:
                    change_type = change_type_33
                    # 用户获胜 中奖金额为投注金额+奖励金额(投注金额=奖励金额) 扣除手续费
                    reward_quantity = (dice_part_in_model.reward_quantity +
                                       dice_part_in_model.bet_number) * (
                                           100 -
                                           dice_config.handling_fee) / 100
                elif dice_result == 1:
                    change_type = change_type_32
                    # 平局 中奖金额为投注金额
                    reward_quantity = dice_part_in_model.bet_number
                result = account_service.do_win(
                    session, dice_part_in_model.user_id,
                    dice_part_in_model.reward_token, reward_quantity,
                    'dice_win' + str(dice_part_in_model._id),
                    dice_part_in_model.user_dice,
                    dice_part_in_model.dice_serial, change_type)
                if isinstance(result, int) is False:
                    raise_logger(
                        "dice分钱失败" + "user:"******"game_publish_lottery", "info")
                    session.rollback()
                    return False
                if result != 0:
                    raise_logger(
                        "dice分钱失败" + "user:"******"game_publish_lottery", "info")
                    session.rollback()
                    return False
            # -------------------------------- 开奖结束 -------------------------------- #

            session.commit()
            if winning_control == 1:
                return self.return_error(40023)
        return {
            'dice_result':
            dice_result,
            'banker_dice':
            banker_dice,
            'user_dice':
            user_dice,
            'dice_timestamp':
            timestamp_to_str(dice_time, format_style="%Y-%m-%d %H:%M:%S"),
            'dice_id':
            str(dice_part_id),
            'dice_serial':
            dice_serial,
            'reward_token':
            self.get_coin_name(coin_id),
            'reward_quantity':
            decimal_to_str(
                str((bet_number + bet_number) * decimal.Decimal(0.99)), 6)
        }
Ejemplo n.º 15
0
 def get_dice_award_rate(self, user_id):
     with MysqlTools().session_scope() as session:
         account_service = AccountService()
         award_rate_info = session.query(DiceParticipateInModel.user_dice,
                                         func.count(DiceParticipateInModel._id).label('total_award')). \
             filter(DiceParticipateInModel.dice_result == 0). \
             group_by(DiceParticipateInModel.user_dice).all()
         stone = 0
         scissors = 0
         cloth = 0
         # balance_btc = ''
         # balance_eth = ''
         # balance_usdt = ''
         # balance_eos = ''
         # balance_exp = ''
         # print(award_rate_info)
         account_balance = account_service.get_user_token_list(
             user_id, None, 1, 10)['content'][0]
         balance_btc = account_balance['BTC']
         balance_eth = account_balance['ETH']
         if account_balance.get('EOS', None) is not None:
             balance_eos = account_balance['EOS']
         else:
             balance_eos = 0
         balance_usdt = account_balance['USDT']
         balance_exp = account_balance['USDT_EXPERIENCE']
         if len(award_rate_info) > 0:
             award_total = 0
             for award_rate in award_rate_info:
                 award_total += award_rate[1]
                 if award_rate[0] == 0:
                     stone = award_rate[1]
                 elif award_rate[0] == 1:
                     scissors = award_rate[1]
                 elif award_rate[0] == 2:
                     cloth = award_rate[1]
             stone_rate = stone / award_total * 100
             scissors_rate = scissors / award_total * 100
             cloth_rate = cloth / award_total * 100
             result = {
                 'stone': decimal_to_str(stone_rate, 2),
                 'scissors': decimal_to_str(scissors_rate, 2),
                 'cloth': decimal_to_str(cloth_rate, 2),
                 'balance': {
                     'btc': decimal_to_str(balance_btc, 8),
                     'eth': decimal_to_str(balance_eth, 8),
                     'eos': decimal_to_str(balance_eos, 8),
                     'usdt': decimal_to_str(balance_usdt, 4),
                     'exp': decimal_to_str(balance_exp, 4)
                 }
             }
             # print(result)
             return result
         else:
             return {
                 'stone': '',
                 'scissors': '',
                 'cloth': '',
                 'balance': {
                     'btc': decimal_to_str(balance_btc, 8),
                     'eth': decimal_to_str(balance_eth, 8),
                     'eos': decimal_to_str(balance_eos, 8),
                     'usdt': decimal_to_str(balance_usdt, 4),
                     'exp': decimal_to_str(balance_exp, 4)
                 }
             }