Exemplo n.º 1
0
        /// <summary>
        /// 竞拍
        /// </summary>
        /// <param name="transferId"></param>
        /// <param name="managerId"></param>
        /// <param name="zoneName"></param>
        /// <returns></returns>
        public AuctionResponse Auction(Guid transferId, Guid managerId, string zoneName)
        {
            AuctionResponse response = new AuctionResponse();

            try
            {
                if (!IsOpen(managerId, zoneName))
                {
                    return(ResponseHelper.Create <AuctionResponse>(MessageCode.TransferNotOpen));
                }
                var entity = GetInfo(transferId);
                if (entity == null)
                {
                    return(ResponseHelper.Create <AuctionResponse>(MessageCode.ItemSoldOut));
                }
                var goldBarEntity = ScoutingGoldbarMgr.GetById(managerId, zoneName);
                if (goldBarEntity == null || goldBarEntity.GoldBarNumber < entity.Price)
                {
                    return(ResponseHelper.Create <AuctionResponse>(MessageCode.ScoutingGoldBarNot));
                }
                if (entity.Status == 1)
                {
                    return(ResponseHelper.Create <AuctionResponse>(MessageCode.ItemSoldOut));
                }
                if (entity.Status == 2)
                {
                    return(ResponseHelper.Create <AuctionResponse>(MessageCode.ItemHaveSellOut));
                }
                if (entity.SellId == managerId)
                {
                    return(ResponseHelper.Create <AuctionResponse>(MessageCode.NotBuyOneself));
                }
                goldBarEntity.GoldBarNumber = goldBarEntity.GoldBarNumber - entity.Price;
                //手续费 5%
                int poundage = entity.Price * 5 / 100;
                if (poundage == 0)
                {
                    poundage = 1;
                }
                else if (poundage > 20)
                {
                    poundage = 20;
                }

                GoldbarRecordEntity auctionRecord = new GoldbarRecordEntity();
                auctionRecord.IsAdd         = false;
                auctionRecord.ManagerId     = managerId;
                auctionRecord.Number        = entity.Price;
                auctionRecord.OperationType = (int)EnumTransactionType.Transfer;
                auctionRecord.RowTime       = DateTime.Now;

                entity.DealEndId       = managerId;
                entity.DealEndPrice    = entity.Price;
                entity.DealEndZoneName = zoneName;
                entity.Status          = 2;
                entity.UpdateTime      = DateTime.Now;
                entity.Poundage        = poundage;
                if (!TransferMainMgr.Update(entity))
                {
                    entity.Status = 0;
                    return(ResponseHelper.Create <AuctionResponse>(MessageCode.NbUpdateFail));
                }
                if (!ScoutingGoldbarMgr.Update(goldBarEntity, null, zoneName))
                {
                    return(ResponseHelper.Create <AuctionResponse>(MessageCode.NbUpdateFail));
                }

                Remove(transferId);
                //出售人邮件
                var sellMail = new MailBuilder(entity.SellId, entity.ItemName, EnumCurrencyType.GoldBar,
                                               entity.Price - poundage);
                //购买人邮件
                var buyMail = new MailBuilder(managerId, entity.ItemCode, entity.ItemName, entity.Price);
                if (!sellMail.Save(entity.SellZoneName))
                {
                    SystemlogMgr.Error("邮件发送失败",
                                       "邮件发送失败,ManagerId:" + entity.SellId + ",ZoneName:" + entity.SellZoneName + ",GoldBarNumber:" +
                                       (entity.Price - poundage));
                }
                if (!buyMail.Save(zoneName))
                {
                    SystemlogMgr.Error("邮件发送失败",
                                       "邮件发送失败,ManagerId:" + managerId + ",ZoneName:" + zoneName + ",GoldBarNumber:" +
                                       (entity.Price - poundage));
                }
                GoldbarRecordMgr.Insert(auctionRecord, null, zoneName);
                response.Data         = new AuctionEntity();
                response.Data.GoldBar = goldBarEntity.GoldBarNumber;
            }
            catch (Exception ex)
            {
                SystemlogMgr.Error("竞拍", ex);
                response.Code = (int)MessageCode.NbParameterError;
            }
            return(response);
        }