コード例 #1
0
ファイル: SecKillBP.cs プロジェクト: sanlonezhang/ql
        private static void SetAbandon(int countdownSysNo)
        {
            //必须是Ready或者VerifyFaild状态
            SecKillEntity entity = SecKillDA.GetCountDownItemBySysno(countdownSysNo);

            if (entity.Status != (int)CountdownStatus.Ready && entity.Status != (int)CountdownStatus.VerifyFaild)
            {
                throw new BusinessException("the current status not allow such opertion");
            }

            int SysNo = SecKillDA.GetProductNotAutoSetVirtualKey(entity.ProductSysNo
                                                                 , (int)NotAutoSetVirtualType.CountDown, entity.SysNo);

            entity.Status = (int)CountdownStatus.Abandon;
            TransactionOptions transactionOptions = new TransactionOptions();

            transactionOptions.IsolationLevel = IsolationLevel.ReadCommitted;
            using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required, transactionOptions))
            {
                if (entity.IsReservedQty == 1)
                {
                    UpdateReservedQTY(entity);
                }
                SetVirtualQty_WhenCountDownAbandon(entity, SysNo);
                if (entity.IsPromotionSchedule == 1)
                {
                    SecKillDA.RollbackMaxPerOrder(entity.ProductSysNo);
                }
                SecKillDA.CountDownEndReleaseWithholdQty(entity.SysNo);
                SecKillDA.UpdateCountdownStatus(entity);
                SecKillDA.UpdateProduct_Ex(entity.ProductSysNo, string.Empty);
                ts.Complete();
            }
        }
コード例 #2
0
ファイル: SecKillBP.cs プロジェクト: sanlonezhang/ql
        public static void SetFinish(int countdownSysNo)
        {
            //必须是Running
            SecKillEntity oCountdown = SecKillDA.GetCountDownItemBySysno(countdownSysNo);

            if (oCountdown.Status != (int)CountdownStatus.Running)
            {
                throw new BusinessException("the current status not allow such opertion");
            }

            oCountdown.Status = (int)CountdownStatus.Finish;
            //edit by kathy 2009-12-10
            //先更改限时抢购的状态为完成,在调整相应的虚拟库存。
            //SetInventoryVirtualQty_whenCountdownItemIsRun 此job每五分钟会检测运行态的countdownitem:
            //inventory的virtualQty和inventory_stock的virtualQty之和是否相等,如果不等,把inventory的virtualQty更改成inventory_stock的virtualQty之和)


            ItemEntity itemPrice = SecKillDA.LoadItemPrice(oCountdown.ProductSysNo);

            itemPrice.CurrentPrice = oCountdown.SnapShotCurrentPrice;
            itemPrice.CashRebate   = oCountdown.SnapShotCashRebate;
            itemPrice.Point        = oCountdown.SnapShotPoint;
            //限时抢购完成更改虚库信息
            int SysNo = SecKillDA.GetProductNotAutoSetVirtualKey(oCountdown.ProductSysNo
                                                                 , (int)NotAutoSetVirtualType.CountDown, oCountdown.SysNo);
            TransactionOptions transactionOptions = new TransactionOptions();

            transactionOptions.IsolationLevel = IsolationLevel.ReadCommitted;
            using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required, transactionOptions))
            {
                SecKillDA.UpdateCountdown(oCountdown);
                SetVirtualQty_CountDownFinish(oCountdown, SysNo);

                SecKillDA.CountDownEndReleaseWithholdQty(oCountdown.SysNo);
                SecKillDA.UpdateItemPrice(itemPrice);
                SecKillDA.UpdateProduct_Ex(oCountdown.ProductSysNo, string.Empty);
                if (oCountdown.IsPromotionSchedule == 1)
                {
                    SecKillDA.RollbackMaxPerOrder(oCountdown.ProductSysNo);
                }
                ts.Complete();
            }
        }
コード例 #3
0
ファイル: SecKillBP.cs プロジェクト: sanlonezhang/ql
        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);
        }