public void InsertActivityProductList() { var model = new SalePromotionActivityModel() { ActivityId = "640a77c6-1d5a-43b3-b13c-426990b74f7e", StartTime = (DateTime.Now - TimeSpan.FromHours(10)).ToString(), EndTime = (DateTime.Now + TimeSpan.FromHours(10)).ToString(), AuditStatus = 2, LastUpdateUserName = "******" }; using (var client = new SalePromotionActivityClient()) { var list = new List <SalePromotionActivityProduct>() { new SalePromotionActivityProduct() { } }; string activityId = "640a77c6-1d5a-43b3-b13c-426990b74f7e"; string userName = "******"; var result = client.InsertActivityProductList(list, activityId, userName).Result; Assert.IsTrue(result); } }
/// <summary> /// 修改活动信息 /// </summary> /// <param name="model"></param> /// <returns></returns> public static async Task <OperationResult <bool> > UpdateActivityAsync(SalePromotionActivityModel model) { OperationResult <bool> result; //检查名称重复 var is_repeat = await DalSalePromotionActivity.CheckNameRepeatAsync(model.Name, model.ActivityId); if (!is_repeat) { return(OperationResult.FromError <bool>("1", "活动名称已存在")); } else { var updateResult = await DalSalePromotionActivity.UpdateActivityAsync(model); if (!updateResult) { result = OperationResult.FromResult(false); } else { result = OperationResult.FromResult(true); } } return(result); }
public void UpdateActivityAfterAudit() { var model = new SalePromotionActivityModel() { ActivityId = "640a77c6-1d5a-43b3-b13c-426990b74f7e", StartTime = (DateTime.Now - TimeSpan.FromHours(10)).ToString(), EndTime = (DateTime.Now + TimeSpan.FromHours(10)).ToString(), AuditStatus = 2, LastUpdateUserName = "******" }; using (var client = new SalePromotionActivityClient()) { var result = client.UpdateActivityAfterAudit(model).Result; Assert.IsTrue(result); } }
public void TestInsertActivity() { using (var client = new SalePromotionActivityClient()) { var model = new SalePromotionActivityModel() { Name = "测试活动1", ActivityId = Guid.NewGuid().ToString(), PromotionType = (int)SalePromotionActivityType.FullDiscount, Is_DefaultLabel = 1, Is_PurchaseLimit = 1, StartTime = DateTime.Now.ToString(), EndTime = DateTime.Now.ToString(), AuditStatus = (int)SalePromotionActivityAuditStatus.WaitAudit, Is_UnShelve = 1, CreateUserName = "******" }; var result = client.InsertActivityAsync(model).Result; Assert.IsTrue(result.Result); } }
public void TestUpdateActivity() { var model = new SalePromotionActivityModel() { ActivityId = "a008b183-5429-4b97-b5ca-c8c999322728", AuditStatus = 0, Banner = "2", ChannelKeyList = new List <string>() { "key1", "key2" }, CreateDateTime = null, StartTime = DateTime.Now.ToString(), EndTime = DateTime.Now.ToString(), LastUpdateUserName = "******" }; using (var client = new SalePromotionActivityClient()) { var result = client.UpdateActivityAsync(model).Result; Assert.IsTrue(result.Result); } }
/// <summary> /// 获取当前组有效的产品数量和价格 /// </summary> /// <param name="group"></param> /// <param name="productSoldNums"></param> /// <param name="currentActivityRules"></param> /// <param name="currentActivity"></param> /// <param name="currentActivityRequestNum"></param> /// <param name="currentActivityRequestTotalPrice"></param> /// <returns></returns> private Tuple <int, decimal> GetEffictiveCurrentActivityRequestNumAndPrice(IGrouping <string, CompProduct> group, IEnumerable <ActivityPidSoldNumModel> productSoldNums, List <SalePromotionActivityDiscount> currentActivityRules, SalePromotionActivityModel currentActivity, int currentActivityRequestNum, decimal currentActivityRequestTotalPrice) { foreach (var product in group.AsEnumerable()) { if (_verifyPayAndInstallMethod) { if (product.Pid.StartsWith("TR", StringComparison.CurrentCultureIgnoreCase) && currentActivity.InstallMethod > 0 && product.RequestInstallMethod != currentActivity.InstallMethod) { currentActivityRequestNum = currentActivityRequestNum - product.RequestNum; currentActivityRequestTotalPrice = currentActivityRequestTotalPrice - product.RequestPrice * product.RequestNum; continue; } if (product.Pid.StartsWith("TR", StringComparison.CurrentCultureIgnoreCase) && currentActivity.PaymentMethod > 0 && product.RequestPaymentMethod != currentActivity.PaymentMethod) { currentActivityRequestNum = currentActivityRequestNum - product.RequestNum; currentActivityRequestTotalPrice = currentActivityRequestTotalPrice - product.RequestPrice * product.RequestNum; continue; } } var currentProductSoldNum = productSoldNums.FirstOrDefault(s => string.Equals(s.Pid, product.Pid))?.SoldNum ?? 0; if (product.LimitQuantity < currentProductSoldNum + product.RequestNum) { currentActivityRequestNum = currentActivityRequestNum - product.RequestNum; currentActivityRequestTotalPrice = currentActivityRequestTotalPrice - product.RequestPrice * product.RequestNum; continue; } } return(new Tuple <int, decimal>(currentActivityRequestNum, currentActivityRequestTotalPrice)); }
/// <summary> /// 遍历活动组内的每个产品 /// </summary> /// <param name="group"></param> /// <param name="productSoldNums"></param> /// <param name="currentActivityRules"></param> private async Task ForEachActivityGroupProducts(IGrouping <string, CompProduct> group, IEnumerable <ActivityPidSoldNumModel> productSoldNums, List <SalePromotionActivityDiscount> currentActivityRules, SalePromotionActivityModel currentActivity, int currentActivityRequestNum, decimal currentActivityRequestTotalPrice) { var effictiveCurrentActivityRequestNumAndPrice = GetEffictiveCurrentActivityRequestNumAndPrice(group, productSoldNums, currentActivityRules, currentActivity, currentActivityRequestNum, currentActivityRequestTotalPrice); currentActivityRequestNum = effictiveCurrentActivityRequestNumAndPrice.Item1; currentActivityRequestTotalPrice = effictiveCurrentActivityRequestNumAndPrice.Item2; foreach (var product in group) { if (_isCreateOrder) { await DiscountActivityInfoManager.IncreaseActivityProductSoldNumCache(currentActivity.ActivityId, product.Pid, product.RequestNum, TimeSpan.FromMinutes(1)); } if (_verifyPayAndInstallMethod) { if (product.Pid.StartsWith("TR", StringComparison.CurrentCultureIgnoreCase) && currentActivity.InstallMethod > 0 && product.RequestInstallMethod != currentActivity.InstallMethod) { _returnList.Add(new ProductHitDiscountResponse() { DiscountPrice = product.RequestPrice, HasDiscountActivity = true, DiscountRule = null, IsHit = false, Pid = product.Pid, FailCode = ProductHitFailCode.GetFailCodeAndDescriptionOfInstall(currentActivity.InstallMethod).Item1, FailMessage = ProductHitFailCode.GetFailCodeAndDescriptionOfInstall(currentActivity.InstallMethod).Item2, }); continue; } if (product.Pid.StartsWith("TR", StringComparison.CurrentCultureIgnoreCase) && currentActivity.PaymentMethod > 0 && product.RequestPaymentMethod != currentActivity.PaymentMethod) { _returnList.Add(new ProductHitDiscountResponse() { DiscountPrice = product.RequestPrice, HasDiscountActivity = true, DiscountRule = null, IsHit = false, Pid = product.Pid, FailCode = ProductHitFailCode.GetFailCodeAndDescriptionOfPay(currentActivity.PaymentMethod).Item1, FailMessage = ProductHitFailCode.GetFailCodeAndDescriptionOfPay(currentActivity.PaymentMethod).Item2, }); continue; } } var currentProductSoldNum = productSoldNums.FirstOrDefault(s => string.Equals(s.Pid, product.Pid))?.SoldNum ?? 0; if (product.LimitQuantity < currentProductSoldNum + product.RequestNum) { _returnList.Add(new ProductHitDiscountResponse() { DiscountPrice = product.RequestPrice, HasDiscountActivity = true, DiscountRule = null, IsHit = false, Pid = product.Pid, FailCode = nameof(ProductHitFailCode.NotEnoughStock), FailMessage = ProductHitFailCode.NotEnoughStock, }); continue; } var judgeHitResult = JudgeHitDiscount(product.Pid, product.RequestPrice, product.RequestNum, currentActivityRules, currentActivityRequestNum, currentActivityRequestTotalPrice); var isHit = judgeHitResult.Item1; _returnList.Add(new ProductHitDiscountResponse() { DiscountPrice = judgeHitResult.Item2, HasDiscountActivity = true, DiscountRule = judgeHitResult.Item3, IsHit = isHit, Pid = product.Pid, FailCode = !isHit ? judgeHitResult.Item3.DiscountMethod == 1 ? nameof(ProductHitFailCode.NotEnoughMoney) : nameof(ProductHitFailCode.NotEnoughNum) : string.Empty, FailMessage = !isHit ? judgeHitResult.Item3.DiscountMethod == 1 ? ProductHitFailCode.NotEnoughMoney : ProductHitFailCode.NotEnoughNum : string.Empty, }); } }
public async Task <OperationResult <SelectActivityListModel> > SelectActivityListAsync(SalePromotionActivityModel model, int pageIndex, int pageSize) { return(await SalePromotionActivityManager.SelectActivityListAsync(model, pageIndex, pageSize)); }
public async Task <OperationResult <bool> > UpdateActivityAfterAuditAsync(SalePromotionActivityModel model) { return(await SalePromotionActivityManager.UpdateActivityAfterAuditAsync(model)); }
public async Task <OperationResult <bool> > InsertActivityAsync(SalePromotionActivityModel model) { return(await SalePromotionActivityManager.InsertActivityAsync(model)); }
public static async Task <OperationResult <SelectActivityListModel> > SelectActivityListAsync(SalePromotionActivityModel model, int pageIndex, int pageSize) { return(await OperationResult.FromResultAsync(DalSalePromotionActivity.SelectActivityListAsync(model, pageIndex, pageSize))); }