示例#1
0
        /**
         * 取消购买BPEC
         */
        public static bool cancelBPEC(byte[] owner, BigInteger tokenId)
        {
            bool bol = false;

            if (Runtime.CheckWitness(owner) && owner.Length == 20)
            {
                object[] objInfo = getAuctionRecord(tokenId);
                if (objInfo.Length > 0)
                {
                    AuctionRecord record = (AuctionRecord)(object)objInfo;
                    if (record.recordState == 0 && owner == record.seller)
                    {
                        object[] args = new object[3] {
                            AuctionOwner, owner, record.value
                        };
                        bool res = (bool)bpecCall("transfer", args);
                        if (res)
                        {
                            // 删除拍卖
                            Storage.Delete(Storage.CurrentContext, "buy".AsByteArray().Concat(tokenId.AsByteArray()));
                            //
                            CancelBPECed(1, owner, record.tokenId);
                            bol = true;
                        }
                    }
                }
            }
            // notify
            if (bol == false)
            {
                CancelBPECed(0, owner, tokenId);
            }

            return(bol);
        }
示例#2
0
        public void CargarSubasta(string nombreProducto)
        {
            string           oferta, nombre;
            AuctionBLL       subastaBLL          = new AuctionBLL();
            Auction          subasta             = new Auction();
            AuctionRecord    historialSubasta    = new AuctionRecord();
            AuctionRecordBLL historialSubastaBLL = new AuctionRecordBLL();

            historialSubasta = historialSubastaBLL.cargarHistorialPorProducto(nombreProducto);
            subasta          = subastaBLL.CargarSubasta(nombreProducto);

            if (historialSubasta is null)
            {
                oferta = "00.00";
                nombre = "Sin ofertante";
            }
            else
            {
                oferta = historialSubasta.Amount.ToString();
                nombre = historialSubasta.User.Name;
            }


            lblIdSubasta.Text         = subasta.AuctionId.ToString();
            lblNombre.Text            = subasta.ProductName;
            lblDescripcion.Text       = subasta.Description;
            lblFechaInicio.Text       = subasta.StartDate.ToString();
            lblFechaFin.Text          = subasta.EndDate.ToString();
            txtOfertaActual.Text      = oferta;
            lblUsuarioOfertaAlta.Text = nombre;
        }
示例#3
0
        /// <summary>
        /// Store auction transaction records
        /// </summary>
        public static void _putAuctionRecord(byte[] tokenId, AuctionRecord info)
        {
            var key = "auction".AsByteArray().Concat(tokenId);

            byte[] bytes = Helper.Serialize(info);
            Storage.Put(Storage.CurrentContext, key, bytes);
        }
示例#4
0
文件: Auction.cs 项目: isoundy000/vr
        /**
         * 存储拍卖成交记录
         */
        private static void _putAuctionRecord(byte[] dressId, AuctionRecord info)
        {
            byte[] txInfo = Helper.Serialize(info);

            var key = "buy".AsByteArray().Concat(dressId);

            Storage.Put(Storage.CurrentContext, key, txInfo);
        }
示例#5
0
        public void agregarPuja(AuctionRecord record, int auctionID)
        {
            Subasta_Registro_DAL registro = new Subasta_Registro_DAL();
            Subasta_BLL          subasta  = new Subasta_BLL();
            object itemSubasta            = new object();

            itemSubasta = subasta.cargarSubastaId(auctionID);
            var EndDate = Convert.ToDateTime(itemSubasta.GetType().GetProperty("EndDate").GetValue(itemSubasta, null)).ToString();

            if (DateTime.Compare(Convert.ToDateTime(EndDate), record.BidDate) >= 0)
            {
                if (record.Amount > 0 && record.Amount < 1000000)
                {
                    if (record.UserId != int.Parse((itemSubasta.GetType().GetProperty("UserId").GetValue(itemSubasta, null)).ToString()))
                    {
                        if (itemSubasta.GetType().GetProperty("HighestBid").GetValue(itemSubasta, null) is null)
                        {
                            using (TransactionScope ts = new TransactionScope())
                            {
                                registro.agregarPuja(record);
                                subasta.actualizarSubasta(record.Amount, record.UserId, auctionID);
                                ts.Complete();
                            }
                        }
                        else
                        {
                            if (record.Amount > Convert.ToDecimal((itemSubasta.GetType().GetProperty("HighestBid").GetValue(itemSubasta, null)).ToString()))
                            {
                                using (TransactionScope ts = new TransactionScope())
                                {
                                    registro.agregarPuja(record);
                                    subasta.actualizarSubasta(record.Amount, record.UserId, auctionID);
                                    ts.Complete();
                                }
                            }
                            else
                            {
                                throw new Exception("La oferta debe ser mayor que la oferta actual");
                            }
                        }
                    }
                    else
                    {
                        throw new Exception("No se le permite ofertar en esta subasta");
                    }
                }
                else
                {
                    throw new Exception("La cantidad ingresada debe ser un numero decimal mayor a 0 y menor que 1, 000, 000");
                }
            }
            else
            {
                throw new Exception("La subasta ha finalizado");
            }
        }
示例#6
0
        /**
         * 购买BPEC
         */
        public static bool buyBPEC(byte[] owner, BigInteger tokenId)
        {
            bool bol = false;

            if (Runtime.CheckWitness(owner) && owner.Length == 20)
            {
                object[] objInfo = getAuctionRecord(tokenId);
                if (objInfo.Length > 0)
                {
                    AuctionRecord record = (AuctionRecord)(object)objInfo;
                    if (record.recordState == 0)
                    {
                        UserInfo buyUser = getUserInfo(owner);
                        if (buyUser.balance >= record.sellPrice)
                        {
                            object[] args = new object[3] {
                                AuctionOwner, owner, record.value
                            };
                            bool res = (bool)bpecCall("transfer", args);
                            if (res)
                            {
                                record.recordState = 1;
                                // 修改记录
                                _putAuctionRecord(record.tokenId.AsByteArray(), record);
                                //手续费
                                BigInteger fee   = record.sellPrice * 3 / 100;
                                var        money = record.sellPrice - fee;
                                _subTotal(fee);
                                //修改买家
                                buyUser.balance -= record.sellPrice;
                                var keyWho = new byte[] { 0x11 }.Concat(owner);
                                Storage.Put(Storage.CurrentContext, keyWho, Helper.Serialize(buyUser));
                                //修改卖家
                                UserInfo sellUser = getUserInfo(record.seller);
                                sellUser.balance += money;
                                keyWho            = new byte[] { 0x11 }.Concat(record.seller);
                                Storage.Put(Storage.CurrentContext, keyWho, Helper.Serialize(sellUser));
                                BuyBPECed(1, owner, record.tokenId);
                                bol = true;
                            }
                        }
                    }
                }
            }
            // notify
            if (bol == false)
            {
                BuyBPECed(0, owner, tokenId);
            }

            return(bol);
        }
        public void CreateRecord(string username, string reference, string action)
        {
            var newRecord = new AuctionRecord
            {
                Action    = action,
                Reference = reference,
                User      = new User {
                    Username = username
                }
            };

            _auctionRecords.Add(newRecord);
        }
示例#8
0
        public void CreateRecord(string username, string reference, string action, string details)
        {
            var user = GetUser(username);

            var auctionRecord = new AuctionRecord
            {
                Action    = action,
                Details   = details,
                Reference = reference,
                User      = user
            };

            _context.AuctionRecords.Add(auctionRecord);
            _context.SaveChanges();
        }
        public void suma()
        {
            ScriptManager.RegisterStartupScript(this, typeof(Page), "calculateTotal", "calculateTotal()", true);
            AuctionRecord        record    = new AuctionRecord();
            List <AuctionRecord> lstRecord = new List <AuctionRecord>();

            lstRecord = (List <AuctionRecord>)ViewState["lstRecord"];
            decimal suma = 0;

            foreach (AuctionRecord rec in lstRecord)
            {
                suma = suma + rec.Amount;
            }
            txtSuma.Text = suma.ToString();
        }
示例#10
0
        /**
         * 存储拍卖成交记录
         */
        private static void _putAuctionRecord(byte[] tokenId, AuctionRecord info)
        {
            /*
             * // 用一个老式实现法
             * byte[] auctionInfo = _ByteLen(info.seller.Length).Concat(info.seller);
             * auctionInfo = _ByteLen(info.buyer.Length).Concat(info.buyer);
             * auctionInfo = auctionInfo.Concat(_ByteLen(info.sellPrice.AsByteArray().Length)).Concat(info.sellPrice.AsByteArray());
             * auctionInfo = auctionInfo.Concat(_ByteLen(info.sellTime.AsByteArray().Length)).Concat(info.sellTime.AsByteArray());
             */
            // 新式实现方法只要一行
            byte[] txInfo = Helper.Serialize(info);

            var key = "buy".AsByteArray().Concat(tokenId);

            Storage.Put(Storage.CurrentContext, key, txInfo);
        }
示例#11
0
        protected void btnGuardar_Click(object sender, EventArgs e)
        {
            decimal  ofertaAcutual = Convert.ToDecimal(txtOfertaActual.Text);
            decimal  oferta        = Convert.ToDecimal(txtOfertar.Text);
            DateTime fechaInicio;
            DateTime fechaFinal;
            DateTime FechaActual;

            FechaActual = DateTime.Now;
            fechaInicio = Convert.ToDateTime(txtInicio.Text);
            fechaFinal  = Convert.ToDateTime(txtFin.Text);
            if (fechaInicio <= FechaActual && fechaFinal >= FechaActual)
            {
                if (ofertaAcutual < oferta)
                {
                    SubastaBLL    bl      = new SubastaBLL();
                    Auction       subasta = new Auction();
                    AuctionRecord record  = new AuctionRecord();
                    subasta.AuctionId   = Convert.ToInt32(txtNumSubasta.Text);
                    subasta.ProductName = txtNombre.Text;
                    subasta.Description = txtDescripcion.Text;
                    subasta.StartDate   = Convert.ToDateTime(txtInicio.Text);
                    subasta.EndDate     = Convert.ToDateTime(txtFin.Text);
                    subasta.HighestBid  = Convert.ToDecimal(txtOfertar.Text);
                    User user = new User();
                    user           = (User)Session["User"];
                    subasta.Winner = user.UserId;
                    bl.UpdateSubasta(subasta);
                    record.AuctionId = Convert.ToInt32(txtNumSubasta.Text);
                    record.UserId    = user.UserId;
                    record.Amount    = Convert.ToDecimal(txtOfertar.Text);
                    record.BidDate   = Convert.ToDateTime(FechaActual);
                    bl.AgregarAuctionRecord(record);
                    ClientScript.RegisterStartupScript(this.GetType(), "alerta", "alert('La oferta se realizo corretamente')", true);
                }
                else
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "alerta", "alert('La oferta debe ser mayor a la actual')", true);
                }
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "alerta", "alert('Error, La subasta Estara disponible en las fechas marcadas')", true);
            }
        }
示例#12
0
        public void HacerOferta()
        {
            AuctionRecord    ofertaParam = new AuctionRecord();
            AuctionRecordBLL ofertaBLL   = new AuctionRecordBLL();

            ofertaParam.AuctionId = int.Parse(lblIdSubasta.Text);
            ofertaParam.UserId    = (int)Session["UserId"];
            ofertaParam.Amount    = Convert.ToDecimal(txtOferta.Text);
            ofertaParam.BidDate   = DateTime.Now;

            try
            {
                ofertaBLL.OfertaMasAlta(ofertaParam);
            }
            catch (Exception ex)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "Alta", "alert ('" + ex.Message + "')", true);
            }
        }
示例#13
0
        public void OfertaMasAlta(AuctionRecord ofertaParam)
        {
            AuctionRecordDAL ofertaHistorial = new AuctionRecordDAL();
            Auction          oferta;
            AuctionBLL       subastaBLL = new AuctionBLL();
            int idSubasta = ofertaParam.AuctionId;



            oferta = subastaBLL.CargarSubasta(idSubasta);

            if (oferta.UserId == ofertaParam.UserId)
            {
                throw new Exception("No se le permite ofertar en esta subasta");
            }
            else
            {
                if (ofertaParam.Amount <= oferta.HighestBid)
                {
                    throw new Exception("La cantidad ingresada debe ser mayor que la oferta actual");
                }
                else
                {
                    if (oferta.EndDate < ofertaParam.BidDate)
                    {
                        throw new Exception("La subasta ha finalizado");
                    }
                    else
                    {
                        if (ofertaParam.Amount > 1000000)
                        {
                            throw new Exception("La cantidad debe ser menor a 1,000,000");
                        }
                        else
                        {
                            ofertaHistorial.nuevaOferta(ofertaParam);
                            ofertaHistorial.OfertaMasAlta(ofertaParam);
                        }
                    }
                }
            }
        }
示例#14
0
        /**
         * 拍卖出售BPEC
         */
        public static bool saleBPEC(byte[] owner, BigInteger price, BigInteger value)
        {
            bool bol       = false;
            var  recordKey = Storage.Get(Storage.CurrentContext, "AuctionRecord").AsBigInteger();

            if (Runtime.CheckWitness(owner) && owner.Length == 20 && value > 0)
            {
                object[] args = new object[3] {
                    owner, AuctionOwner, value
                };
                bool res = (bool)bpecCall("transfer", args);
                if (res)
                {
                    //
                    var           nowtime = Blockchain.GetHeader(Blockchain.GetHeight()).Timestamp;
                    AuctionRecord record  = new AuctionRecord();
                    record.tokenId    += 1;
                    record.seller      = owner;
                    record.sellTime    = nowtime;
                    record.sellPrice   = price;
                    record.value       = value;
                    record.recordState = 0;
                    // 入库记录
                    _putAuctionRecord(record.tokenId.AsByteArray(), record);
                    //保存主键
                    Storage.Put(Storage.CurrentContext, "AuctionRecord", record.tokenId.AsByteArray());
                    SaleBPECed(1, owner, value, record.tokenId, nowtime);
                    bol = true;
                }
            }
            // notify
            if (bol == false)
            {
                SaleBPECed(0, owner, value, recordKey, 0);
            }

            return(bol);
        }
        public async Task <IActionResult> PostAuctionRecord([FromBody] AuctionRecord auctionRecord)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var auction = await db.Auctions.SingleOrDefaultAsync(a => a.Id == auctionRecord.Gid);

            if (auction == null)
            {
                return(NotFound());
            }
            if (auction.StartTime > DateTime.Now)
            {
                ThrowHttpResponseException("拍卖未开始");
            }
            if (auction.EndTime <= DateTime.Now)
            {
                if (auction.EndStatus == EndStatus.进行中)
                {
                    if (auction.NowPrice > 0 && auction.Mid > 0)
                    {
                        auction.EndStatus = EndStatus.成交;
                    }
                    else
                    {
                        auction.EndStatus = EndStatus.流拍;
                    }
                    await db.SaveChangesAsync();
                }
                ThrowHttpResponseException("拍卖已结束");
            }
            if (auction.NowPrice >= auctionRecord.Money)
            {
                ThrowHttpResponseException("已经有人出价比你高,请重新出价");
            }
            if (auctionRecord.Money < auction.NowPrice + auction.StepSize)
            {
                ThrowHttpResponseException("出价少于步长");
            }

            auction.EndStatus = EndStatus.进行中;
            auction.BidCount += 1;
            auction.Mid       = auctionRecord.Mid;
            auction.NowPrice  = auctionRecord.Money;

            db.AuctionRecords.Add(auctionRecord);
            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (AuctionRecordExists(auctionRecord.Id))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }
            var member = await db.Members.SingleOrDefaultAsync(m => m.Id == auctionRecord.Mid);

            string msg = $"{member.NickName} 拍品编号 {auction.Bidnb} 出价 ¥{auctionRecord.Money} 有效";

            RefreshAuctionRecordsWithRoom("room" + auction.Id, msg);
            RefreshAuctions(msg);

            return(Ok());
        }
示例#16
0
        /**
         * 购买拍卖克隆
         */
        public static bool cloneOnAuction(byte[] sender, BigInteger motherGlaId, BigInteger fatherGlaId)
        {
            if (!Runtime.CheckWitness(sender))
            {
                //没有签名
                return(false);
            }

            object[] objFatherInfo = _getAuctionInfo(fatherGlaId.AsByteArray());
            if (objFatherInfo.Length > 0)
            {
                AuctionInfo fatherInfo = (AuctionInfo)(object)objFatherInfo;
                byte[]      owner      = fatherInfo.owner;

                if (fatherInfo.sellType == 1)
                {
                    var nowtime    = Blockchain.GetHeader(Blockchain.GetHeight()).Timestamp;
                    var secondPass = (nowtime - fatherInfo.sellTime) / 1000;

                    BigInteger senderMoney = Storage.Get(Storage.CurrentContext, sender).AsBigInteger();
                    BigInteger curBuyPrice = computeCurrentPrice(fatherInfo.beginPrice, fatherInfo.endPrice, fatherInfo.duration, secondPass);
                    var        fee         = curBuyPrice * 30 / 1000;
                    if (fee < TX_MIN_FEE)
                    {
                        fee = TX_MIN_FEE;
                    }
                    if (curBuyPrice < fee)
                    {
                        curBuyPrice = fee;
                    }

                    if (senderMoney < curBuyPrice)
                    {
                        // 钱不够
                        return(false);
                    }

                    // 开始克隆
                    object[] args = new object[3] {
                        sender, motherGlaId, fatherGlaId
                    };
                    bool res = (bool)nftCall("bidOnClone_app", args);
                    if (!res)
                    {
                        return(false);
                    }

                    // 扣钱
                    Storage.Put(Storage.CurrentContext, sender, senderMoney - curBuyPrice);

                    // 扣除手续费
                    curBuyPrice -= fee;
                    _subTotal(fee);

                    // 钱记在卖家名下
                    BigInteger nMoney     = 0;
                    byte[]     salerMoney = Storage.Get(Storage.CurrentContext, owner);
                    if (salerMoney.Length > 0)
                    {
                        nMoney = salerMoney.AsBigInteger();
                    }
                    nMoney = nMoney + curBuyPrice;
                    Storage.Put(Storage.CurrentContext, owner, nMoney);

                    //// 不要删除拍卖记录
                    //Storage.Delete(Storage.CurrentContext, tokenId.AsByteArray());

                    // 成交记录
                    AuctionRecord record = new AuctionRecord();
                    record.tokenId   = fatherGlaId;
                    record.seller    = owner;
                    record.buyer     = sender;
                    record.sellType  = 1;
                    record.sellPrice = curBuyPrice + fee;
                    record.sellTime  = nowtime;

                    _putAuctionRecord(fatherGlaId.AsByteArray(), record);

                    // notify
                    AuctionClone(sender, motherGlaId, fatherGlaId, curBuyPrice, fee, nowtime);
                    return(true);
                }
            }
            return(false);
        }
示例#17
0
        public void AgregarAuctionRecord(AuctionRecord record)
        {
            SubastaDAL dal = new SubastaDAL();

            dal.AgregarAuctionRecord(record);
        }
示例#18
0
        /**
         * 从拍卖场购买,将钱划入合约名下,将物品给买家
         */
        public static bool buyOnAuction(byte[] sender, BigInteger tokenId)
        {
            if (!Runtime.CheckWitness(sender))
            {
                //没有签名
                return(false);
            }

            object[] objInfo = _getAuctionInfo(tokenId.AsByteArray());
            if (objInfo.Length > 0)
            {
                AuctionInfo info  = (AuctionInfo)(object)objInfo;
                byte[]      owner = info.owner;

                var nowtime    = Blockchain.GetHeader(Blockchain.GetHeight()).Timestamp;
                var secondPass = (nowtime - info.sellTime) / 1000;

                BigInteger senderMoney = Storage.Get(Storage.CurrentContext, sender).AsBigInteger();
                BigInteger curBuyPrice = computeCurrentPrice(info.beginPrice, info.endPrice, info.duration, secondPass);
                var        fee         = curBuyPrice * 30 / 1000;
                if (fee < TX_MIN_FEE)
                {
                    fee = TX_MIN_FEE;
                }
                if (curBuyPrice < fee)
                {
                    curBuyPrice = fee;
                }

                if (senderMoney < curBuyPrice)
                {
                    // 钱不够
                    return(false);
                }

                // 首先转移物品
                object[] args = new object[3] {
                    ExecutionEngine.ExecutingScriptHash, sender, tokenId
                };
                bool res = (bool)nftCall("transfer_app", args);
                if (!res)
                {
                    return(false);
                }

                // 扣钱
                Storage.Put(Storage.CurrentContext, sender, senderMoney - curBuyPrice);

                // 扣除手续费
                BigInteger sellPrice = curBuyPrice - fee;
                _subTotal(fee);

                // 钱记在卖家名下
                BigInteger nMoney     = 0;
                byte[]     salerMoney = Storage.Get(Storage.CurrentContext, owner);
                if (salerMoney.Length > 0)
                {
                    nMoney = salerMoney.AsBigInteger();
                }
                nMoney = nMoney + sellPrice;
                Storage.Put(Storage.CurrentContext, owner, nMoney);

                // 删除拍卖记录
                Storage.Delete(Storage.CurrentContext, tokenId.AsByteArray());

                // 成交记录
                AuctionRecord record = new AuctionRecord();
                record.tokenId   = tokenId;
                record.seller    = owner;
                record.buyer     = sender;
                record.sellType  = 0;
                record.sellPrice = curBuyPrice;
                record.sellTime  = nowtime;

                _putAuctionRecord(tokenId.AsByteArray(), record);

                if (owner == ContractOwner)
                {
                    Gene0Record gene0Record;
                    byte[]      v = (byte[])Storage.Get(Storage.CurrentContext, "gene0Record");
                    if (v.Length == 0)
                    {
                        gene0Record = new Gene0Record();
                    }
                    else
                    {
                        object[] infoRec = (object[])Helper.Deserialize(v);
                        gene0Record = (Gene0Record)(object)infoRec;
                    }
                    int idx = (int)gene0Record.totalSellCount % 5;
                    if (idx == 0)
                    {
                        gene0Record.lastPrice0 = curBuyPrice;
                    }
                    else if (idx == 1)
                    {
                        gene0Record.lastPrice1 = curBuyPrice;
                    }
                    else if (idx == 2)
                    {
                        gene0Record.lastPrice1 = curBuyPrice;
                    }
                    else if (idx == 3)
                    {
                        gene0Record.lastPrice1 = curBuyPrice;
                    }
                    else if (idx == 4)
                    {
                        gene0Record.lastPrice1 = curBuyPrice;
                    }

                    gene0Record.totalSellCount += 1;

                    //
                    byte[] infoRec2 = Helper.Serialize(gene0Record);
                    Storage.Put(Storage.CurrentContext, "gene0Record", infoRec2);
                }

                // notify
                AuctionBuy(sender, tokenId, curBuyPrice, fee, nowtime);
                return(true);
            }
            return(false);
        }