public static void GetInventoryInfoToWrite(int ProductSysNo, string CurrentStatus) { int AffectedVirtualQty = 0; InventoryEntity inventory = SecKillDA.GetInventoryByProductSysNo(ProductSysNo); if (inventory != null) { AffectedVirtualQty = inventory.VirtualQty; } //获取当前的分仓的虚库数量 List <InventoryStockEntity> Invstocklist = SecKillDA.GetInventoryStock(ProductSysNo); StringBuilder stockvirtualqty = new StringBuilder(); foreach (InventoryStockEntity itemStock in Invstocklist) { stockvirtualqty.Append(string.Format("{0}:{1};", itemStock.StockSysNo, itemStock.VirtualQty)); } string msg = DateTime.Now.ToString() + " 商品:" + ProductSysNo.ToString() + " " + CurrentStatus + " \r\n\t Inventory--VirtualQty: " + AffectedVirtualQty + "\r\n InventoryStock--VirtualQty: " + stockvirtualqty; WriteLog(msg); bool sendmailflag = Convert.ToBoolean(ConfigurationManager.AppSettings["SendMailFlag"]); if (sendmailflag == true) { SecKillDA.SendMailAboutInventoryInfo(msg, ProductSysNo, CurrentStatus); } }
private static bool SetRunning(int countdownSysNo) { //必须是Ready状态,切换价格和库存 SecKillEntity countdownItem = SecKillDA.GetCountDownItemBySysno(countdownSysNo); if (countdownItem.Status != (int)CountdownStatus.Ready) { throw new BusinessException("不是就绪状态"); } TransactionOptions transactionOptions = new TransactionOptions(); transactionOptions.IsolationLevel = IsolationLevel.ReadCommitted; using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required, transactionOptions)) { //最前端修改,不会影响其他逻辑 if (countdownItem.IsReservedQty == 1) { //这里改,更新库存. UpdateReservedQTY(countdownItem); } countdownItem.Status = (int)CountdownStatus.Running; #region 设置限时抢购为原始价格并记录抢购价格//获取商品价格 ItemEntity itemPrice = SecKillDA.LoadItemPrice(countdownItem.ProductSysNo); countdownItem.SnapShotCurrentPrice = itemPrice.CurrentPrice; countdownItem.SnapShotCashRebate = itemPrice.CashRebate; countdownItem.SnapShotPoint = itemPrice.Point; itemPrice.CurrentPrice = countdownItem.CountDownCurrentPrice; itemPrice.CashRebate = countdownItem.CountDownCashRebate; itemPrice.Point = countdownItem.CountDownPoint; #endregion InventoryEntity inventory = SecKillDA.GetInventoryByProductSysNo(countdownItem.ProductSysNo); countdownItem.AffectedVirtualQty = inventory.VirtualQty; //获取当前的分仓的虚库数量 List <InventoryStockEntity> Invstocklist = SecKillDA.GetInventoryStock(countdownItem.ProductSysNo); StringBuilder stockonlineqty = new StringBuilder(); foreach (InventoryStockEntity itemStock in Invstocklist) { stockonlineqty.Append(string.Format("{0}:{1};", itemStock.StockSysNo , itemStock.AvailableQty + itemStock.ConsignQty + itemStock.VirtualQty)); } //判断是否满足各分仓的OnlineQty>=各分仓的限时抢购数量 //--逻辑已经修改,不满足分仓数量也可以限时抢购 string curVirtualQty = string.Empty; IsCanRunningCountDown(Invstocklist, countdownItem, out curVirtualQty); countdownItem.SnapShotCurrentVirtualQty = curVirtualQty; #region 设置记录为不自动设置虚拟库存 ProductNotAutoSetVirtualEntity oEntity = new ProductNotAutoSetVirtualEntity(); oEntity.CountDownSysNo = countdownSysNo; oEntity.CreateTime = DateTime.Now; oEntity.CreateUserSysNo = 493; oEntity.NotAutoSetVirtualType = (int)NotAutoSetVirtualType.CountDown; oEntity.Note = "CountDown Run"; oEntity.ProductSysNo = countdownItem.ProductSysNo; oEntity.Status = 0; ProductNotAutoSetVirtualInsert(oEntity); #endregion #region 通过虚库控制库存 注释此间代码 if (1 == 2) { #region 获取当前商品总库信息 string curStockQty = string.Empty; if (!BatchUpdateStockVirtual_Run(countdownItem, stockonlineqty.ToString())) { return(false); } List <InventoryStockEntity> inventoryStocklist = SecKillDA.GetInventoryStock(countdownItem.ProductSysNo); //处理库存差额, 库存差额是为计算可用库存做准备的。最小为0,为0代表实际库存就是可卖库存。 int AffectedVirtualQty = 0; foreach (InventoryStockEntity stock in inventoryStocklist) { AffectedVirtualQty += stock.VirtualQty; curStockQty += stock.StockSysNo + ":" + (stock.AvailableQty + stock.ConsignQty + stock.VirtualQty).ToString() + ";"; } if (!(countdownItem.IsLimitedQty == 1 && countdownItem.IsReservedQty == 1)) { countdownItem.AffectedStock = curStockQty; } #endregion ////更改总仓虚库 //if (!SetVirtualQty(countdownItem.ProductSysNo, AffectedVirtualQty)) //{ // return false; //} InventoryEntity inventory2 = SecKillDA.GetInventoryByProductSysNo(countdownItem.ProductSysNo); if (countdownItem.IsLimitedQty == 0 && countdownItem.IsReservedQty == 0) { countdownItem.CountDownQty = inventory2.AvailableQty + inventory2.ConsignQty;// +inventory2.VirtualQty; } else if (countdownItem.IsLimitedQty == 0 && inventory2.AvailableQty + inventory2.ConsignQty + inventory2.VirtualQty != countdownItem.CountDownQty) { countdownItem.CountDownQty = inventory2.AvailableQty + inventory2.ConsignQty;// +inventory2.VirtualQty; } } #endregion SecKillDA.CountDownStartWithholdQty(countdownItem.SysNo); SecKillDA.UpdateCountdown(countdownItem); SecKillDA.UpdateItemPrice(itemPrice); if (countdownItem.IsPromotionSchedule == 1) { SecKillDA.UpdateMaxPerOrder(countdownItem.ProductSysNo, countdownItem.MaxPerOrder); } if (!string.IsNullOrEmpty(countdownItem.PromotionType) && countdownItem.PromotionType.ToUpper() == "DC") { SecKillDA.UpdateProduct_Ex(countdownItem.ProductSysNo, "DC"); } ts.Complete(); } return(true); }