/// <summary> /// 拍卖结束后,求出对应产品的最新成交价格,历史评价价格,最低价,最高价 /// </summary> /// <param name="paimaiItem"></param> /// <returns></returns> private void CalculateProductInfo(PaimaiItem paimaiItem) { var price = GetProductPrice(paimaiItem.productId, paimaiItem.paimaiId); var db = new jd(); if ((int)price != 0) { db.productPrices.Add(new productPrice { price = (decimal)price, productId = paimaiItem.productId, createTime = DateTime.Now }); } //检查产品是否存在 var productList = db.products.Single(pro => pro.productId == paimaiItem.productId); var auction = db.auctions.Single(pro => pro.auctionId == paimaiItem.paimaiId); //productList.auctionEndCount = productList.auctionEndCount + 1; if (productList.auctionAvgPrice == null) { productList.auctionAvgPrice = (decimal)paimaiItem.currentPrice; } else { productList.auctionAvgPrice = (productList.auctionEndCount * productList.auctionAvgPrice + (decimal)paimaiItem.currentPrice) / (productList.auctionEndCount + 1); } if (productList.auctionEndCount == null) { productList.auctionEndCount = 1; } else { productList.auctionEndCount = productList.auctionEndCount + 1; } if (productList.auctionTopPrice == null) { productList.auctionTopPrice = (decimal)paimaiItem.currentPrice; } else if (productList.auctionTopPrice < (decimal)paimaiItem.currentPrice) { productList.auctionTopPrice = (decimal)paimaiItem.currentPrice; } if (productList.auctionLowPrice == null) { productList.auctionLowPrice = (decimal)paimaiItem.currentPrice; } else if (productList.auctionLowPrice > (decimal)paimaiItem.currentPrice) { productList.auctionLowPrice = (decimal)paimaiItem.currentPrice; } if ((int)price != 0) { productList.price = (decimal)price; } productList.updateTime = DateTime.Now; auction.auctionStatus = (int)AuctionStatus.EndAuction; auction.updateTime = DateTime.Now; auction.currentPrice = (decimal)paimaiItem.currentPrice; auction.bidCount = paimaiItem.bidCount; db.SaveChanges(); }
/// <summary> /// 保存拍卖明细数据 /// </summary> /// <param name="paimaiItem"></param> /// <returns></returns> private void SavePaimaiDetail(PaimaiItem paimaiItem) { var db = new jd(); //检查产品是否存在 var productList = db.products.Where(pro => pro.productId == paimaiItem.productId); //如果不存在则添加 if (!productList.Any()) { db.products.Add(new product { productId = paimaiItem.productId, name = paimaiItem.describe, auctionCount = 0, createTime = DateTime.Now }); db.SaveChanges(); } else { var oneProduct = productList.Single(); if (!string.IsNullOrEmpty(paimaiItem.describe) && string.IsNullOrEmpty(oneProduct.name)) { oneProduct.name = paimaiItem.describe; oneProduct.updateTime = DateTime.Now; db.SaveChanges(); } } //检查拍卖编号是否存在 var auction = db.auctions.Where(pro => pro.auctionId == paimaiItem.paimaiId); if (!auction.Any()) { db.auctions.Add(new auction { currentPrice = (decimal)paimaiItem.currentPrice, productId = paimaiItem.productId, auctionId = paimaiItem.paimaiId, startTime = paimaiItem.startTime, endTime = paimaiItem.endTime, bidCount = paimaiItem.bidCount, auctionStatus = paimaiItem.auctionStatus, createTime = DateTime.Now }); var product = db.products.First(pro => pro.productId == paimaiItem.productId); product.auctionCount = product.auctionCount + 1; db.SaveChanges(); } else { var auctionItem = auction.Single(); auctionItem.auctionStatus = paimaiItem.auctionStatus; auctionItem.currentPrice = (decimal)paimaiItem.currentPrice; auctionItem.endTime = paimaiItem.endTime; auctionItem.startTime = paimaiItem.startTime; auctionItem.bidCount = paimaiItem.bidCount; auctionItem.updateTime = DateTime.Now; db.SaveChanges(); } }