/// <summary> /// 运行-->根据阶梯调价 /// </summary> /// <param name="groupBuyingEntity"></param> public static void SetStepPrice(ProductGroupBuyingEntity groupBuyingItem) { //必须是Running if (groupBuyingItem.Status != "A") { throw new BusinessException("the current status not allow such opertion"); } using (TransactionScope ts = new TransactionScope()) { //读取已成功支付的正常状态的订单商品数量 int orderNumber = 0; if (groupBuyingItem.GroupBuyingTypeSysNo == 6) {//如果类型为抽奖 orderNumber = GroupBuyingDA.GetCurrentSellCountForLottery(groupBuyingItem.SysNo, groupBuyingItem.IsByGroup); } else { orderNumber = GroupBuyingDA.GetCurrentSellCount(groupBuyingItem.SysNo, groupBuyingItem.IsByGroup); groupBuyingItem.CurrentSellCount = orderNumber; SyncGroupBuyingSellCount(groupBuyingItem); } //根据商品数量读取价格 List <ProductGroupBuying_PriceEntity> gbPriceList = GroupBuyingDA.GetProductGroupBuying_PriceList(groupBuyingItem).OrderBy(e => e.SellCount).ToList(); decimal stepPrice = 0; string isSuccess = "N"; int maxSellCount = gbPriceList.Max(e => e.SellCount); for (int i = 0; i < gbPriceList.Count; i++) { ProductGroupBuying_PriceEntity gbPrice = gbPriceList[i]; if (i == 0) { stepPrice = gbPrice.GroupBuyingPrice; } if (orderNumber >= gbPrice.SellCount) { isSuccess = "Y"; stepPrice = gbPrice.GroupBuyingPrice; } } //如果团购人数大于最高成团人数,则更新结算状态为C string isSettlement = "N"; decimal dealPrice = 0; if (orderNumber >= maxSellCount) { isSettlement = "C"; dealPrice = gbPriceList.Min(e => e.GroupBuyingPrice); } GroupBuyingDA.UpdateCurrentSellCount(groupBuyingItem.SysNo, orderNumber, isSettlement, dealPrice); //只有在最小成团时间为空且团购已成功或者最小成团时间不为空且最小成团失败才更新 if (!(groupBuyingItem.SuccessDate != null && isSuccess == "Y")) { //设置最小成团时间 GroupBuyingDA.SetGroupBuyingSuccesDate(groupBuyingItem.SysNo, isSuccess); } //如果团购类型为抽奖(6),则不需下列操作 if (groupBuyingItem.GroupBuyingTypeSysNo != 6) { List <ProductPriceInfoEntity> itemPriceList = GroupBuyingDA.GetProductPriceInfoList(groupBuyingItem.ProductSysNo, groupBuyingItem.IsByGroup); foreach (ProductPriceInfoEntity itemPrice in itemPriceList) { //更新团购成功时间 if (itemPrice.CurrentPrice != stepPrice) { decimal gbCurentPrice = itemPrice.CurrentPrice; itemPrice.CurrentPrice = stepPrice; //修改价格 //GroupBuyingDA.UpdateItemPrice(itemPrice); GroupBuyingDA.UpdateItemPrice(itemPrice, groupBuyingItem, groupBuyingItem.InDate, "IPPSystemAdmin", DateTime.Now, "团购调价就绪-->运行", "JobConsole", "GroupBuying"); //验证一个规则内差价是否小于0 if (groupBuyingItem.ProductSysNo != 0) { CheckSaleRule(groupBuyingItem.ProductSysNo); } //类型PriceLogType:记录为“团购调价运行”; //申请时间CreateDate:dbo.ProductGroupBuying .InDate; //生效时间UpdateDate:Now; //申请人CreateUser:InUser; //审核人UpdateUser:dbo.ProductGroupBuying.Audituser; //商品原价OldPrice:SnapShotCurrentPrice; //调后价格NewPrice:GroupBuyingCurrentPrice; //调整幅度offset:调后价格减去商品原价减去积分 //返现金额CashRebate:GroupBuyingCashRebate; //积分Point: GroupBuyingPoint //2011-12-1 删除-该功能移入SP Rik.K.Li //decimal offset = 0; //decimal point = 0; //offset = itemPrice.CurrentPrice - gbCurentPrice - point; //GroupBuyingDA.InsertGroupBuyingProductPricechangeLog(itemPrice.ProductSysNo.ToString(), // itemPrice.CurrentPrice.ToString(), // gbCurentPrice.ToString(), // offset.ToString(), // itemPrice.UnitCost, // 0, // 0, // groupBuyingItem.InUser, // groupBuyingItem.InDate, // groupBuyingItem.AuditUser, // DateTime.Now, // "团购调价运行-->阶梯价格", // "JobConsole", // "GroupBuying"); } } } ts.Complete(); } }