示例#1
0
    def check_game_sold_out_by_eos(self, id, block_no, block_hash, timestamp,
                                   received_time):
        with MysqlTools().session_scope() as session:
            model = session.query(GameDigitalInstanceModel).filter(
                GameDigitalInstanceModel._id == id,
                GameDigitalInstanceModel.status ==
                1).with_for_update().first()
            if model is None:
                return False
            result_block = {
                'block_no': block_no,
                'block_hash': block_hash,
                'timestamp': timestamp,
                'received_time': received_time
            }
            hash_numbers = result_block["block_hash"]
            raise_logger("项目:" + str(id) + "   中奖区块号:" + str(hash_numbers),
                         "game_publish_lottery", "info")

            if hash_numbers == "":
                raise_logger("开奖异常:80001", "game_publish_lottery", "info")
                return False

            prize_number = int(hash_numbers, 16) % model.need + 1
            raise_logger("项目:" + str(id) + "    中奖号码:" + str(prize_number),
                         "game_publish_lottery", "info")
            # print("中奖号码", str(prize_number))

            participate_in = ParticipateInService()
            records = participate_in.search_model(session, id)
            # 无人参与
            if len(records) <= 0:
                raise_logger("无人参与80002", "game_publish_lottery", "info")
                return False

            user_id = ""
            user_pay_token = 0
            user_bet_number = 0
            user_type = 0
            merge_id = -1
            part_in_id = -1
            for item in records:
                numbers = json.loads(item.award_numbers)
                if prize_number in numbers:
                    part_in_id = item._id
                    user_id = item.user_id
                    user_pay_token = item.pay_token
                    user_bet_number = item.bet_number
                    user_type = item.user_type
                    merge_id = item.merge_id
                    break

            # 无人中奖
            if user_id == "":
                raise_logger("无人中奖80003", "game_publish_lottery", "info")
                return False

            raise_logger("中奖user_id:" + str(user_id), "game_publish_lottery",
                         "info")

            win_record = session.query(GameDigitalInstanceModel).filter(
                WinningRecordModel.game_instance_id == id).first()
            # game_instance_id已经存在开奖纪录
            if win_record:
                raise_logger(str(id) + "开奖纪录", "game_publish_lottery", "info")
                return False

            # 修改game实体添加开奖时间 和币价信息
            game_service = GameService()
            lottery_time_str = str(get_utc_now())
            lottery_time = lottery_time_str[0:19]

            if game_service.modifyDigitalInstance(model, {
                    "game_id": id,
                    "lottery_time": lottery_time
            }) is False:
                raise_logger("开奖纪录modifyDigitalInstance   False",
                             "game_publish_lottery", "info")
                return False

            raise_logger("开奖纪录modifyDigitalInstance 修改成功",
                         "game_publish_lottery", "info")

            try:
                # 添加开奖纪录
                winning_record_model = WinningRecordModel(
                    created_at=lottery_time,
                    game_instance_id=id,
                    game_serial=model.game_serial,
                    bet_serial=str(prize_number),
                    bet_hash=hash_numbers,
                    reward_token=model.reward_token,
                    reward_quantity=model.reward_quantity,
                    user_id=user_id,
                    bet_token=user_pay_token,
                    bet_number=user_bet_number,
                    user_type=user_type,
                    block_no=result_block['block_no'],
                    timestamp=result_block['timestamp'],
                    received_time=result_block['received_time'],
                    participation=model.participation,
                    block_type="0",
                    merge_id=merge_id)
                session.add(winning_record_model)
                session.flush()

                raise_logger("添加开奖纪录", "game_publish_lottery", "info")

                # 真实用户 添加 中奖金额
                if user_type == 0:
                    account_service = AccountService()
                    # 合买逻辑
                    if merge_id != -1:
                        raise_logger("合买逻辑", "game_publish_lottery", "info")
                        total_bet = session.query(func.sum(ParticipateInModel.bet_number).label('total')). \
                            filter(ParticipateInModel.merge_id == merge_id).first()
                        win_users = session.query(ParticipateInModel). \
                            filter(ParticipateInModel.merge_id == merge_id).all()
                        for win_user in win_users:
                            reward_quantity = win_user.bet_number / int(float(total_bet.total)) * model.reward_quantity \
                                              * (1 - float(model.handling_fee) / 100)
                            result = account_service.do_win_new_session(
                                win_user.user_id, model.reward_token,
                                decimal.Decimal(reward_quantity),
                                str(part_in_id), win_user.bet_number,
                                win_user.game_serial)
                            if isinstance(result, int) is False:
                                raise_logger(
                                    "分钱失败" + "user:"******"game_publish_lottery", "info")
                                session.rollback()
                                return False
                            if result != 0:
                                raise_logger(
                                    "分钱失败" + "user:"******"game_publish_lottery", "info")
                                session.rollback()
                                return False
                    else:
                        raise_logger("非合买逻辑", "game_publish_lottery", "info")
                        # 实际奖励金额 = 奖励金额 * (1-手续费%)
                        reward_quantity = model.reward_quantity * (
                            1 - model.handling_fee / 100)
                        result = account_service.do_win(
                            session, user_id, model.reward_token,
                            reward_quantity, str(part_in_id), user_bet_number,
                            model.game_serial)

                        if isinstance(result, int) is False:
                            raise_logger("分钱失败" + "user:"******"game_publish_lottery", "info")
                            session.rollback()
                            return False
                        if result != 0:
                            raise_logger("分钱失败" + "user:"******"game_publish_lottery", "info")
                            session.rollback()
                            return False

                raise_logger("分钱成功", "game_publish_lottery", "info")

                try:
                    # 添加上链数据
                    lottery_time_str = str(model.lottery_time)
                    release_time_str = str(model.release_time)
                    full_load_time_str = str(model.full_load_time)
                    nick_name = session.query(
                        ParticipateInModel.nick_name).filter(
                            ParticipateInModel.user_id == user_id).first()
                    if BlockChainInfoService().insert_block_chain_info(
                            "", id, 0,
                        {
                            "id": winning_record_model._id,
                            "game_instance_id":
                            winning_record_model.game_instance_id,
                            "game_serial": winning_record_model.game_serial,
                            "bet_serial": winning_record_model.bet_serial,
                            "bet_hash": winning_record_model.bet_hash,
                            "reward_token": winning_record_model.reward_token,
                            "reward_quantity":
                            winning_record_model.reward_quantity,
                            "user_id": winning_record_model.user_id,
                            "bet_token": winning_record_model.bet_token,
                            "bet_number": winning_record_model.bet_number,
                            "user_type": winning_record_model.user_type,
                            "block_no": winning_record_model.block_no,
                            "timestamp": winning_record_model.timestamp,
                            "received_time":
                            winning_record_model.received_time,
                            "block_type": winning_record_model.block_type,
                            "participation":
                            winning_record_model.participation,
                            "lottery_time": lottery_time_str[0:19],
                            "game_describe": model.game_describe,
                            "nick_name": nick_name,
                            "need": model.need,
                            "release_time": release_time_str[0:19],
                            "full_load_time": full_load_time_str[0:19],
                        }):
                        winning_record_model.chain_status = 1

                except Exception as e:
                    raise_logger("开奖insert_block_chain_info     Exception",
                                 "game_publish_lottery", "info")
                session.commit()
                return True

            except Exception as e:
                raise_logger(e.__str__(), "game_publish_lottery", "info")
                session.rollback()
                return False
示例#2
0
    def bet_in(self, dic):
        change_type_41 = '41'  # 即时开中奖
        change_type_42 = '42'  # 即时开投注
        id = dic.get("game_instance_id", "")  # 项目id
        user_id = dic.get("user_id", "")  # 用户id
        user_channel_id = dic.get("user_channel_id", "")  # 用户下注渠道id
        conin_id = dic.get("coin_id", "")  # 投入币种id
        bet_amount = dic.get("bet_amount", "")  # 投注数量
        bet_start = dic.get("bet_start", 0)
        bet_end = dic.get("bet_end", 0)
        faker = True
        # merge_id = dic.get("merge_id", -1)  # 合并投注id
        # transaction_password = dic.get("transaction_password", "")  # 交易密码
        with MysqlTools().session_scope() as session:
            # 查询项目
            model = session.query(InstantGameInstanceModel).filter(
                InstantGameInstanceModel._id == id).first()
            template = session.query(InstantGameTemplateModel). \
                order_by(InstantGameTemplateModel._id.desc()).first()
            if model is None:
                return self.return_error(60001)
            if model.status == 1:
                return self.return_error(60002)
            if model.status == 2:
                return self.return_error(60003)
            if model.status == 0:
                can_bet = model.need - model.bet_number
                if can_bet <= 0:
                    return self.return_error(60002)
                if int(bet_amount) > can_bet:
                    return self.return_error(60004)

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

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

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

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

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

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

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

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

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

                        session.commit()

                        return {
                            'is_win': is_win,
                            'prize_number': prize_number,
                            'part_in_id': participate_in_model._id
                        }
                    else:
                        session.rollback()
                        return self.return_error(60009)
                else:
                    session.rollback()
                    return self.return_error(60010)
            else:
                session.rollback()
                return self.return_error(60007)
示例#3
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)
        }
示例#4
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
示例#5
0
 def check_dice_sold_out_by_eos(self):
     # raise_logger("sold_out开始" + " 时间:" + get_utc_now().strftime(
     #     "%Y-%m-%d %H:%M:%S.%f"), "game_bet_in", "info")
     with MysqlTools().session_scope() as session:
         account_service = AccountService()
         not_lottery_list = session.query(DiceParticipateInModel). \
             filter(DiceParticipateInModel.dice_result == -1).all()
         if len(not_lottery_list) > 0:
             for not_lottery in not_lottery_list:
                 # raise_logger("需开奖记录id=" + str(not_lottery._id) + " 时间:" + get_utc_now().strftime(
                 #     "%Y-%m-%d %H:%M:%S.%f"), "game_bet_in", "info")
                 lottery_block = not_lottery.block_no
                 lottery_eos_block_info = session.query(SyncEosModel). \
                     filter(SyncEosModel.block_num == lottery_block).first()
                 if lottery_eos_block_info is not None:
                     # raise_logger("找到开奖区块lottery_block" + str(
                     #     lottery_eos_block_info.block_hash) + " 时间:" + get_utc_now().strftime(
                     #     "%Y-%m-%d %H:%M:%S.%f"), "game_bet_in", "info")
                     not_lottery.block_timestamp = lottery_eos_block_info.time_stamp
                     not_lottery.block_hash = lottery_eos_block_info.block_hash
                     dice_result = -1
                     banker_dice = int(not_lottery.block_hash,
                                       16) % 3  # 0石头 1剪刀 2布
                     user_dice = not_lottery.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
                     not_lottery.banker_dice = banker_dice
                     not_lottery.dice_result = dice_result
                     session.flush()
                     if dice_result in [0, 1]:
                         reward_quantity = 0
                         dice_config = session.query(DiceConfigModel). \
                             filter(DiceConfigModel.support_token_id == not_lottery.bet_token).first()
                         if dice_config is None:
                             return self.return_error(40022)
                         if dice_result == 0:
                             # 用户获胜 中奖金额为投注金额+奖励金额(投注金额=奖励金额) 扣除手续费
                             reward_quantity = (
                                 not_lottery.reward_quantity +
                                 not_lottery.bet_number) * (
                                     100 - dice_config.handling_fee) / 100
                         elif dice_result == 1:
                             # 平局 中奖金额为投注金额
                             reward_quantity = not_lottery.bet_number
                         result = account_service.do_win(
                             session, not_lottery.user_id,
                             not_lottery.reward_token, reward_quantity,
                             'dice_win' + str(not_lottery._id),
                             not_lottery.user_dice, not_lottery.dice_serial)
                         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()
         # raise_logger("sold_out结束" + " 时间:" + get_utc_now().strftime(
         #     "%Y-%m-%d %H:%M:%S.%f"), "game_bet_in", "info")
     return {'result': True}