/// <summary> /// Check 厂商赠品的赠品不能作为其它赠品活动的赠品 /// </summary> /// <param name="info"></param> /// <returns></returns> private List <String> CheckVendorGiftRules(SaleGiftBatchInfo info) { List <SaleGiftInfo> giftInfoListTmp = new List <SaleGiftInfo>(); List <String> msgTmp = new List <String>(); foreach (var item in info.Gifts) { giftInfoListTmp.AddRange(_da.GetGiftItemListByProductSysNo(item.ProductSysNo.Value, SaleGiftStatus.Run)); giftInfoListTmp.AddRange(_da.GetGiftItemListByProductSysNo(item.ProductSysNo.Value, SaleGiftStatus.Ready)); giftInfoListTmp.AddRange(_da.GetGiftItemListByProductSysNo(item.ProductSysNo.Value, SaleGiftStatus.WaitingAudit)); if (info.SaleGiftType == SaleGiftType.Vendor) { if (giftInfoListTmp != null && giftInfoListTmp.Where(p => p.SysNo != info.SysNo && p.Type != SaleGiftType.Vendor).ToList().Count > 0) { //msgTmp.Add(string.Format("厂商赠品 ({0}) 在其他赠品活动中存在有效的重复的记录!", ExternalDomainBroker.GetSimpleProductInfo(item.ProductSysNo.Value).ProductID)); msgTmp.Add(string.Format(ResouceManager.GetMessageString("MKT.Promotion.SaleGift", "SaleGift_ExsisitActivityInOther"), ExternalDomainBroker.GetSimpleProductInfo(item.ProductSysNo.Value).ProductID)); continue; } } else { if (giftInfoListTmp != null && giftInfoListTmp.Where(p => p.SysNo != info.SysNo && p.Type == SaleGiftType.Vendor).ToList().Count > 0) { //msgTmp.Add(string.Format("赠品 ({0}) 在厂商赠品活动中存在有效的重复的记录!", ExternalDomainBroker.GetSimpleProductInfo(item.ProductSysNo.Value).ProductID)); msgTmp.Add(string.Format(ResouceManager.GetMessageString("MKT.Promotion.SaleGift", "SaleGift_ExsisitActivityInMerchant"), ExternalDomainBroker.GetSimpleProductInfo(item.ProductSysNo.Value).ProductID)); continue; } } } return(msgTmp); }
public SaleGiftBatchInfo ToEntity() { SaleGiftBatchInfo info = this.ConvertVM <SaleGiftBatchInfoVM, SaleGiftBatchInfo>(); info.RuleName = new BizEntity.LanguageContent(); info.RuleDescription = new BizEntity.LanguageContent(); info.RuleName.Content = this.PromotionName; info.RuleDescription.Content = this.PromotionDescription; return(info); }
/// <summary> /// 批量创建赠品。 /// </summary> /// <param name="viewModel"></param> /// <param name="callback"></param> public void BatchCreateSaleGift(SaleGiftBatchInfoVM viewModel, EventHandler <RestClientEventArgs <object> > callback) { SaleGiftBatchInfo info = viewModel.ToEntity(); info.InUser = CPApplication.Current.LoginUser.LoginName; info.CompanyCode = CPApplication.Current.CompanyCode; string relativeUrl = "/MKTService/SaleGift/BatchCreateSaleGift"; restClient.Create <object>(relativeUrl, info, (obj, args) => { if (args.FaultsHandle()) { return; } callback(obj, args); }); }
/// <summary> /// 根据购买的商品,赠品信息创建赠品规则信息。单品买赠及厂商赠品时,商品为单个,同时买赠时商品为多个。 /// </summary> /// <param name="promotionInfo"></param> /// <param name="productList"></param> private void CreateGiftAndRules(SaleGiftBatchInfo promotionInfo, List <ProductItemInfo> productList) { PSOrderCondition orderCondition = new PSOrderCondition(); orderCondition.OrderMinAmount = 0M; //Create Gift Master int?giftMasterSysNo = _SaleGiftDA.CreateMaster(new SaleGiftInfo { Title = promotionInfo.RuleName, Description = promotionInfo.RuleDescription, Type = promotionInfo.SaleGiftType, Status = promotionInfo.Status, BeginDate = promotionInfo.BeginDate, EndDate = promotionInfo.EndDate, OrderCondition = orderCondition, PromotionLink = promotionInfo.PromotionLink, InUser = promotionInfo.InUser, DisCountType = promotionInfo.RebateCaculateMode, VendorSysNo = promotionInfo.VendorSysNo, CompanyCode = promotionInfo.CompanyCode }); //Generate SaleRules UpdateSaleRules(new BatchCreateSaleGiftSaleRuleInfo { IsGlobal = true, ProductList = productList, PromotionSysNo = giftMasterSysNo.Value, InUser = promotionInfo.InUser, CompanyCode = promotionInfo.CompanyCode }); //Create Gifts CreateGiftRules(new BatchCreateGiftRuleInfo { GiftComboType = promotionInfo.IsSpecifiedGift?SaleGiftGiftItemType.AssignGift:SaleGiftGiftItemType.GiftPool, ProductList = promotionInfo.Gifts, SumCount = promotionInfo.TotalQty, PromotionSysNo = giftMasterSysNo.Value, IsSpecial = 0, InUser = promotionInfo.InUser, CompanyCode = promotionInfo.CompanyCode }); }
private void ValidatePromotion(SaleGiftBatchInfo promotionInfo) { if (promotionInfo.RuleName == null || string.IsNullOrEmpty(promotionInfo.RuleName.Content)) { //throw new BizException("规则名称不能为空!"); throw new Exception(ResouceManager.GetMessageString("MKT.Promotion.SaleGift", "SaleGift_RuleNameRequired")); } if (promotionInfo.BeginDate == null) { //throw new BizException("请输入开始时间!"); throw new Exception(ResouceManager.GetMessageString("MKT.Promotion.SaleGift", "SaleGift_NeedStartDate")); } if (promotionInfo.EndDate == null) { //throw new BizException("请输入结束时间!"); throw new Exception(ResouceManager.GetMessageString("MKT.Promotion.SaleGift", "SaleGift_NeedEndDate")); } }
public void BatchCreateSaleGift(SaleGiftBatchInfo saleGiftBatchInfo) { _processor.BatchCreateSaleGift(saleGiftBatchInfo); }
public void BatchCreateSaleGift(SaleGiftBatchInfo info) { ObjectFactory <BatchCreateSaleGiftAppService> .Instance.BatchCreateSaleGift(info); }
/// <summary> /// 从IMDomain获取商品及赠品的商品信息,主要是状态信息。 /// </summary> private void InitProductInfosFromIM(SaleGiftBatchInfo saleGiftBatchInfo) { List <int> productSysNos = new List <int>(); if (saleGiftBatchInfo.ProductItems1 != null) { foreach (ProductItemInfo item in saleGiftBatchInfo.ProductItems1) { productSysNos.Add(item.ProductSysNo.Value); } } if (saleGiftBatchInfo.ProductItems2 != null) { foreach (ProductItemInfo item in saleGiftBatchInfo.ProductItems2) { productSysNos.Add(item.ProductSysNo.Value); } } if (saleGiftBatchInfo.Gifts != null) { foreach (ProductItemInfo item in saleGiftBatchInfo.Gifts) { productSysNos.Add(item.ProductSysNo.Value); } } List <ProductInfo> products = ExternalDomainBroker.GetProductInfoListByProductSysNoList(productSysNos); //将商品的相关信息,状态、价格信息等赋值给Item. RetryFunc <ProductItemInfo, int> copyItemInfo = (ProductItemInfo item) => { ProductInfo swapItem = products.Find(p => p.SysNo == item.ProductSysNo); if (swapItem != null) { item.ProductStatus = swapItem.ProductStatus; item.ProductID = swapItem.ProductID; item.ProductName = swapItem.ProductName; item.CurrentPrice = swapItem.ProductPriceInfo.CurrentPrice.Value; item.C3SysNo = swapItem.ProductBasicInfo.ProductCategoryInfo.SysNo; item.BrandSysNo = swapItem.ProductBasicInfo.ProductBrandInfo.SysNo; } return(0); }; if (saleGiftBatchInfo.ProductItems1 != null) { foreach (ProductItemInfo item in saleGiftBatchInfo.ProductItems1) { copyItemInfo(item); } } if (saleGiftBatchInfo.ProductItems2 != null) { foreach (ProductItemInfo item in saleGiftBatchInfo.ProductItems2) { copyItemInfo(item); } } if (saleGiftBatchInfo.Gifts != null) { foreach (ProductItemInfo item in saleGiftBatchInfo.Gifts) { copyItemInfo(item); } } }
/// <summary> /// 批量创建赠品。 /// </summary> /// <param name="saleGiftBatchInfo"></param> public void BatchCreateSaleGift(SaleGiftBatchInfo saleGiftBatchInfo) { if (saleGiftBatchInfo == null) { return; } //从IMDomain获取商品及赠品的商品信息,主要是状态信息。 InitProductInfosFromIM(saleGiftBatchInfo); //厂商赠品的赠品不能作为其它赠品活动的赠品 List <string> errorMsgList = this.CheckVendorGiftRules(saleGiftBatchInfo); if (errorMsgList.Count > 0) { throw new BizException(errorMsgList.Join(Environment.NewLine)); } using (TransactionScope ts = new TransactionScope()) { try { if (saleGiftBatchInfo.Gifts == null || saleGiftBatchInfo.Gifts.Count <= 0 || saleGiftBatchInfo.Gifts.Count > 8) { //throw new Exception("赠品必须设置1-8之间"); throw new Exception(ResouceManager.GetMessageString("MKT.Promotion.SaleGift", "SaleGift_GiftNeedBeteew1And8")); } if (saleGiftBatchInfo.SaleGiftType == SaleGiftType.Single) { #region 单品买赠 if (saleGiftBatchInfo.ProductItems1 == null || saleGiftBatchInfo.ProductItems1.Count <= 0 || saleGiftBatchInfo.ProductItems1.Count > 30) { //throw new BizException("商品必须设置1-30之间"); throw new Exception(ResouceManager.GetMessageString("MKT.Promotion.SaleGift", "SaleGift_QuantityNeedBeteew1And30")); } foreach (ProductItemInfo p in saleGiftBatchInfo.ProductItems1) { List <ProductItemInfo> list = new List <ProductItemInfo>(); list.Add(p); CreateGiftAndRules(saleGiftBatchInfo, list);//根据购买的商品,赠品信息创建赠品规则信息。单品买赠及厂商赠品是,商品为单个,同时买赠时商品为多个。 } #endregion } else if (saleGiftBatchInfo.SaleGiftType == SaleGiftType.Vendor) { #region 厂商赠品 if (saleGiftBatchInfo.ProductItems1 == null || saleGiftBatchInfo.ProductItems1.Count <= 0 || saleGiftBatchInfo.ProductItems1.Count > 30) { //throw new BizException("商品数量必须设置1-30之间"); throw new Exception(ResouceManager.GetMessageString("MKT.Promotion.SaleGift", "SaleGift_QuantityNeedBeteew1And30")); } foreach (ProductItemInfo p in saleGiftBatchInfo.ProductItems1) { List <ProductItemInfo> list = new List <ProductItemInfo>(); list.Add(p); CreateGiftAndRules(saleGiftBatchInfo, list);//根据购买的商品,赠品信息创建赠品规则信息。单品买赠及厂商赠品是,商品为单个,同时买赠时商品为多个。 } #endregion } else { #region 时购买 if (saleGiftBatchInfo.ProductItems1 == null || saleGiftBatchInfo.ProductItems1.Count <= 0 || saleGiftBatchInfo.ProductItems1.Count > 30) { //throw new BizException("左侧商品数量必须设置1-30之间"); throw new Exception(ResouceManager.GetMessageString("MKT.Promotion.SaleGift", "SaleGift_LeftQuantityNeedBeteew1And30")); } if (saleGiftBatchInfo.ProductItems2 == null || saleGiftBatchInfo.ProductItems2.Count < 0 || saleGiftBatchInfo.ProductItems2.Count > 30) { //throw new BizException("右侧商品数量必须设置1-30个"); throw new Exception(ResouceManager.GetMessageString("MKT.Promotion.SaleGift", "SaleGift_RightQuantityNeedBeteew1And30")); } //是组合捆绑还是交叉捆绑 if (saleGiftBatchInfo.CombineType == SaleGiftCombineType.Assemble) { if (saleGiftBatchInfo.ProductItems2.Count > 11) { //throw new BizException("当组合类型为组合捆绑右侧商品最多只能设置11个"); throw new Exception(ResouceManager.GetMessageString("MKT.Promotion.SaleGift", "SaleGift_RightQuantityNeed11")); } foreach (ProductItemInfo p in saleGiftBatchInfo.ProductItems1) { List <ProductItemInfo> collection = new List <ProductItemInfo>(); collection.AddRange(saleGiftBatchInfo.ProductItems2); collection.Add(p); CreateGiftAndRules(saleGiftBatchInfo, collection);//根据购买的商品,赠品信息创建赠品规则信息。单品买赠及厂商赠品是,商品为单个,同时买赠时商品为多个。 } } else { if (saleGiftBatchInfo.ProductItems2.Count > 30) { //throw new BizException("右侧商品必须设置1-30之间"); throw new Exception(ResouceManager.GetMessageString("MKT.Promotion.SaleGift", "SaleGift_RightQuantityNeedBeteew1And30")); } foreach (ProductItemInfo left in saleGiftBatchInfo.ProductItems1) { foreach (ProductItemInfo right in saleGiftBatchInfo.ProductItems2) { List <ProductItemInfo> collection = new List <ProductItemInfo>(); collection.Add(right); collection.Add(left); CreateGiftAndRules(saleGiftBatchInfo, collection);//根据购买的商品,赠品及赠品规则信息。单品买赠及厂商赠品是,商品为单个,同时买赠时商品为多个。 } } } #endregion } } catch (Exception ex) { throw new BizException(ex.Message); } ts.Complete(); } //return saleGiftBatchInfo; }