/// <summary> /// 更新佣金规则 /// </summary> public static void UpdateCommissionRule(CommissionRule entity) { DataCommand cmd = DataCommandManager.GetDataCommand("UpdateCommissionRule"); cmd.SetParameterValue <CommissionRule>(entity); cmd.ExecuteNonQuery(); }
/// <summary> /// 加载佣金规则 /// </summary> public static CommissionRule LoadCommissionRule(int SysNo) { DataCommand cmd = DataCommandManager.GetDataCommand("LoadCommissionRule"); cmd.SetParameterValue("@SysNo", SysNo); CommissionRule result = cmd.ExecuteEntity <CommissionRule>(); return(result); }
public void IsApplication_Should_Return_True_For_Video_Product_Learning_to_Ski() { var rule = new CommissionRule(); var product = new Product { Attribute = ProductAttribute.PHYSICAL }; rule.IsApplicable(product).Should().BeTrue(); rule.Apply().Should().Be("Generating commision payment to the agent"); }
/// <summary> /// 创建佣金规则 /// </summary> public static int InsertCommissionRule(CommissionRule entity) { DataCommand cmd = DataCommandManager.GetDataCommand("InsertCommissionRule"); cmd.SetParameterValue <CommissionRule>(entity); cmd.ExecuteNonQuery(); int sysNo = (int)cmd.GetParameterValue("@SysNo"); return(sysNo); }
public void Add_Commission_Rule_For_Book() { Payment payment = new Payment(); payment.PaymentType = Enum_PaymentType.Book; payment.ProductName = "My Story"; payment.IsBook = true; IRule rule = new CommissionRule(); ruleManager.AddRule(rule); var ruleResult = ruleManager.ExecuteRules(payment); bool isCommissionRuleApplied = ruleResult.Contains("Commission Payment to Agent"); Assert.IsTrue(isCommissionRuleApplied); }
private void SetOrderCommissionForRMA(CommissionRule rule, CommissionLog item) { var orderCommission = dal.GetOrderCommissionLog(item.SoSysNo); if (orderCommission == null) { item.CommissionAmt = -rule.OrderCommissionFee; } else { item.CommissionItemSysNo = orderCommission.CommissionItemSysNo; item.CommissionAmt = -orderCommission.Price; } item.Price = item.CommissionAmt; }
public void Commision_Rule_Test() { IBussinessRuleEngine businessEngine = new BusinessRuleEngine(); var rule = new CommissionRule(); businessEngine.AddRule(rule); var agent = new Agent { Name = "Test" }; var product = new Product { Attribute = ProductAttribute.PHYSICAL, Id = 1, Type = ProductType.Book, Name = "Learning Python" }; var orderEngine = new OrderProcessor(businessEngine, agent); orderEngine.Add(new OrderLine(product, 1)); orderEngine.Process().Single().Should().Be("Generating commision payment to the agent"); }
private void ComputeCommissionForVendor(IGrouping <int, CommissionLog> vendor) { CommissionMaster master; try { if (vendor.Key == 0) { throw new Exception(string.Format("错误数据,VendorSysNo为0,ProductSysNo:{0}", String.Join(",", vendor.Select(x => x.ProductSysNo.ToString()).ToArray()))); } using (TransactionScope scope = new TransactionScope()) { #region 计算供应商的佣金 master = dal.GetCommissionMasterByMerchantSysNo(vendor.Key); bool isOnlyCalcRentFee = IsOnlyCalculateRentFee(master); //计算店租佣金 //<-增加手动结算的修复处理 2012-4-24 //SetCommissionTimeInfo(master); SetCommissionTimeInfo(master, this.now); //-> SetTotalRent(master); if (!isOnlyCalcRentFee) { var itemsForComputing = new List <CommissionItem>(); var logsForVendor = new List <CommissionLog>(); var agentGroup = from i in vendor group i by i.VendorManufacturerSysNo into g select g; foreach (var agent in agentGroup) { var item = dal.GetCommissionItemByVMSysNo(agent.Key, master.SysNo); itemsForComputing.Add(item); var logsForItem = new List <CommissionLog>(); CommissionRule rule = null; foreach (var itemWithSameAgent in agent) { #region 计算代理信息的佣金 if (rules.ContainsKey(itemWithSameAgent.VendorManufacturerSysNo)) { rule = rules[itemWithSameAgent.VendorManufacturerSysNo]; if (itemWithSameAgent.ReferenceSysNo > 0) { if (itemWithSameAgent.SysNo.HasValue) { #region 更新log switch (itemWithSameAgent.Type) { case Constants.CommissionLogType.OrderCommission: if (itemWithSameAgent.ReferenceType == Constants.OrderType.SO) { itemWithSameAgent.CommissionAmt = rule.OrderCommissionFee; itemWithSameAgent.Price = rule.OrderCommissionFee; } else if (itemWithSameAgent.HaveAutoRMA == 1) { itemWithSameAgent.CommissionAmt = -rule.OrderCommissionFee; itemWithSameAgent.Price = -rule.OrderCommissionFee; //SetOrderCommissionForRMA(rule, itemWithSameAgent); } break; case Constants.CommissionLogType.SaleCommission: if (itemWithSameAgent.ReferenceType == Constants.OrderType.SO) { var salesPrice = itemWithSameAgent.Price - itemWithSameAgent.Point / 10m - itemWithSameAgent.DiscountAmt / itemWithSameAgent.Qty; itemWithSameAgent.Price = salesPrice; decimal?promotiondiscount = itemWithSameAgent.PromotionDiscount.HasValue ? itemWithSameAgent.PromotionDiscount : 0; //优惠券折扣 itemWithSameAgent.CommissionAmt = Math.Round((itemWithSameAgent.Price * itemWithSameAgent.Qty) + promotiondiscount.Value, 2); } else { var salesPrice = itemWithSameAgent.Price - itemWithSameAgent.Point / 10m - itemWithSameAgent.DiscountAmt; itemWithSameAgent.Price = salesPrice; itemWithSameAgent.CommissionAmt = Math.Round(itemWithSameAgent.Price * itemWithSameAgent.Qty, 2); } break; case Constants.CommissionLogType.DeliveryFee: itemWithSameAgent.CommissionAmt = rule.DeliveryFee; itemWithSameAgent.Price = rule.DeliveryFee; break; default: break; } dal.UpdateCommissionLog(itemWithSameAgent); logsForItem.Add(itemWithSameAgent); logsForVendor.Add(itemWithSameAgent); #endregion } else { #region 新增LOG if (itemWithSameAgent.ReferenceType == Constants.OrderType.SO) { #region SO //计算实际出售价格 var salesPrice = itemWithSameAgent.Price - itemWithSameAgent.Point / 10m - itemWithSameAgent.DiscountAmt / itemWithSameAgent.Qty; itemWithSameAgent.Price = salesPrice; //优惠券折扣 decimal?promotiondiscount = itemWithSameAgent.PromotionDiscount.HasValue ? itemWithSameAgent.PromotionDiscount : 0; //新建log CommissionLog orderCommission = new CommissionLog { CommissionItemSysNo = item.SysNo, ReferenceSysNo = itemWithSameAgent.ReferenceSysNo, ReferenceType = itemWithSameAgent.ReferenceType, ProductSysNo = itemWithSameAgent.ProductSysNo, Price = rule.OrderCommissionFee, InUser = GlobalSettings.UserName, EditUser = GlobalSettings.UserName, Type = Constants.CommissionLogType.OrderCommission, CommissionAmt = rule.OrderCommissionFee }; logsForItem.Add(orderCommission); logsForVendor.Add(orderCommission); //新建log CommissionLog deliveryFee = new CommissionLog { CommissionItemSysNo = item.SysNo, ReferenceSysNo = itemWithSameAgent.ReferenceSysNo, ReferenceType = itemWithSameAgent.ReferenceType, ProductSysNo = itemWithSameAgent.ProductSysNo, Price = rule.DeliveryFee, InUser = GlobalSettings.UserName, EditUser = GlobalSettings.UserName, Type = Constants.CommissionLogType.DeliveryFee, CommissionAmt = rule.DeliveryFee }; logsForItem.Add(deliveryFee); logsForVendor.Add(deliveryFee); //新建log CommissionLog salesCommission = new CommissionLog { CommissionItemSysNo = item.SysNo, ReferenceSysNo = itemWithSameAgent.ReferenceSysNo, ReferenceType = itemWithSameAgent.ReferenceType, ProductSysNo = itemWithSameAgent.ProductSysNo, Price = itemWithSameAgent.Price, Qty = itemWithSameAgent.Qty, InUser = GlobalSettings.UserName, EditUser = GlobalSettings.UserName, Type = Constants.CommissionLogType.SaleCommission, CommissionAmt = Math.Round((itemWithSameAgent.Price * itemWithSameAgent.Qty) + promotiondiscount.Value, 2) , PromotionDiscount = promotiondiscount.Value }; dal.CreateCommissionLog(salesCommission); logsForItem.Add(salesCommission); logsForVendor.Add(salesCommission); #endregion } else { #region RMA var salesPrice = itemWithSameAgent.Price - itemWithSameAgent.Point / 10m - itemWithSameAgent.DiscountAmt; itemWithSameAgent.Price = salesPrice; //物流拒收需要退回订单提成 if (itemWithSameAgent.HaveAutoRMA == 1) { //新建log CommissionLog orderCommission = new CommissionLog { CommissionItemSysNo = item.SysNo, ReferenceSysNo = itemWithSameAgent.ReferenceSysNo, ReferenceType = itemWithSameAgent.ReferenceType, ProductSysNo = itemWithSameAgent.ProductSysNo, Price = -rule.OrderCommissionFee, InUser = GlobalSettings.UserName, EditUser = GlobalSettings.UserName, Type = Constants.CommissionLogType.OrderCommission, CommissionAmt = -rule.OrderCommissionFee }; logsForItem.Add(orderCommission); logsForVendor.Add(orderCommission); } //新建log CommissionLog salesCommission = new CommissionLog { CommissionItemSysNo = item.SysNo, ReferenceSysNo = itemWithSameAgent.ReferenceSysNo, ReferenceType = itemWithSameAgent.ReferenceType, ProductSysNo = itemWithSameAgent.ProductSysNo, Price = itemWithSameAgent.Price, Qty = itemWithSameAgent.Qty, InUser = GlobalSettings.UserName, EditUser = GlobalSettings.UserName, Type = Constants.CommissionLogType.SaleCommission, CommissionAmt = Math.Round(itemWithSameAgent.Price * itemWithSameAgent.Qty, 2) }; dal.CreateCommissionLog(salesCommission); logsForItem.Add(salesCommission); logsForVendor.Add(salesCommission); #endregion } #endregion } } //记录使用的佣金规则编号 item.RuleSysNo = rule.SysNo; } #endregion } if (rule != null) { item.TotalSaleAmt = Math.Round(logsForItem .Where(x => { return(x.Type == Constants.CommissionLogType.SaleCommission); }) .Sum(x => x.CommissionAmt), 2); if (rule.SalesRule == null) { break; } var salesRule = rule.SalesRule.ToObject <SalesRuleEntity>(); item.Rent = rule.RentFee * master.Percentage; if (salesRule != null) { item.SalesCommissionFee = Math.Max(GetSaleCommissionAmount(item.TotalSaleAmt, salesRule), salesRule.MinCommissionAmt); } item.EditUser = GlobalSettings.UserName; } } #region 计算订单提成 var queryOrderCommission = from i in logsForVendor where i.Type == Constants.CommissionLogType.OrderCommission group i by new { i.ReferenceSysNo, i.ReferenceType } into g select g; List <CommissionLog> orderFee = new List <CommissionLog>(); foreach (var orderCommission in queryOrderCommission) { if (orderCommission.Key.ReferenceType == Constants.OrderType.SO) { var soList = from i in orderCommission where i.ReferenceType == Constants.OrderType.SO orderby i.CommissionAmt descending select i; orderFee.Add(soList.First()); } } foreach (var orderCommission in queryOrderCommission) { if (orderCommission.Key.ReferenceType == Constants.OrderType.RMA) { var rmaList = from i in orderCommission where i.ReferenceType == Constants.OrderType.RMA orderby i.CommissionAmt select i; var rma = rmaList.First(); var so1 = dal.GetOrderCommissionLog(rma.SoSysNo); var so2 = orderFee.Where(so => so.Type == Constants.OrderType.SO && so.ReferenceSysNo == rma.SoSysNo).OrderByDescending(so => so.Price).FirstOrDefault(); if (so2 != null) { rma.CommissionItemSysNo = so2.CommissionItemSysNo; rma.Price = -so2.Price; } else if (so1 != null) { rma.CommissionItemSysNo = so1.CommissionItemSysNo; rma.Price = -so1.Price; } orderFee.Add(rma); } } #endregion #region 计算配送费 var queryDeliveryFee = from i in logsForVendor where i.Type == Constants.CommissionLogType.DeliveryFee group i by new { i.ReferenceSysNo, i.ReferenceType } into g select g; List <CommissionLog> delivery = new List <CommissionLog>(); foreach (var deliveryCommission in queryDeliveryFee) { var soList = from i in deliveryCommission orderby i.CommissionAmt descending select i; var so = soList.FirstOrDefault(); if (so != null) { delivery.Add(so); } } #endregion #region 更新SOC DEF LOG foreach (var item in itemsForComputing) { var ordersBelongToItem = from log in orderFee where log.CommissionItemSysNo == item.SysNo select log; item.OrderCommissionFee = ordersBelongToItem.Sum(x => x.CommissionAmt); dal.DeleteCommissionLog(item.SysNo, Constants.CommissionLogType.OrderCommission); foreach (var log in ordersBelongToItem) { dal.CreateCommissionLog(log); } var deliverysBelongToItem = from log in delivery where log.CommissionItemSysNo == item.SysNo select log; dal.DeleteCommissionLog(item.SysNo, Constants.CommissionLogType.DeliveryFee); foreach (var log in deliverysBelongToItem) { dal.CreateCommissionLog(log); } item.DeliveryFee = deliverysBelongToItem.Sum(x => x.CommissionAmt); dal.UpdateCommissionItem(item); } #endregion master.OrderCommissionFee = itemsForComputing.Sum(x => x.OrderCommissionFee); master.DeliveryFee = itemsForComputing.Sum(x => x.DeliveryFee); master.SalesCommissionFee = itemsForComputing.Sum(x => x.SalesCommissionFee); } master.TotalAmt = master.DeliveryFee + master.OrderCommissionFee + master.RentFee + master.SalesCommissionFee; dal.UpdateCommissionMaster(master); scope.Complete(); #endregion } if (merchants.Select(x => x.SysNo).Contains(master.MerchantSysNo)) { SettleCommission(master); } } catch (Exception ex) { var message = ex.Message + Environment.NewLine + ex.StackTrace; OnDisplayMessage(message); SendMail(GlobalSettings.MailSubject, message); } }
public static void SaveStoreAgentProduct(List <VendorAgentInfo> agentsInfoes, int sellerSysNo, string createUserName , bool isRequest) { var singleAgentInfo = new List <VendorAgentInfo>(); #region check 是否存在重复的代理,品牌,C3 if (isRequest == false) { var message = new StringBuilder(); var originAgentInfo = StoreService.QueryStoreAgentInfos(sellerSysNo); agentsInfoes.ForEach(p => { var isExists = originAgentInfo.Any(q => q.C3Name == p.C3Name && q.BrandInfo.SysNo == p.BrandInfo.SysNo); if (isExists) { message.AppendFormat("{0},{1},{2}已代理<br/>", p.BrandInfo.BrandNameLocal, p.C3Name, p.AgentLevel); } else { singleAgentInfo.Add(p); } }); if (message.Length > 0) { throw new BusinessException(message.ToString()); } } #endregion var agentedProduct = StoreDA.QueryStoreAgentInfos(sellerSysNo).Where(p => p.RequestType == VendorModifyRequestStatus.VerifyPass); using (var trans = TransactionManager.Create()) { agentsInfoes.ForEach(p => { if (p.AgentSysNo.HasValue && agentedProduct.Any(q => q.AgentSysNo == p.AgentSysNo.Value)) { return; } p.RequestType = VendorModifyRequestStatus.Apply; //CreateVendorManufacturerInfo VendorAgentInfo createdVendorAgentInfo; if (p.AgentSysNo.HasValue) { //p.Status = VendorAgentStatus.Normal; //提交审核需要将Status置零 if (isRequest) { p.Status = VendorAgentStatus.Normal; } createdVendorAgentInfo = StoreDA.UpdateVendorManufacturerInfo(p, sellerSysNo); } else { createdVendorAgentInfo = StoreDA.CreateVendorManufacturerInfo(p, sellerSysNo); } p.AgentSysNo = createdVendorAgentInfo.AgentSysNo; //CreateVendorCommissionInfo //根据C3和Brand获取佣金规则,设置VendorCommissionInfo //p.BrandInfo.SysNo //p.C3SysNo if (p.BrandInfo != null && p.BrandInfo.SysNo.HasValue) { CommissionRule rule = StoreDA.QueryCommissionRule(p.BrandInfo.SysNo.Value, p.C3SysNo.Value); if (rule != null) { if (p.VendorCommissionInfo == null) { p.VendorCommissionInfo = new VendorCommissionInfo(); } p.VendorCommissionInfo.DeliveryFee = rule.DeliveryFee; //p.VendorCommissionInfo.GuaranteedAmt= p.VendorCommissionInfo.RentFee = rule.RentFee; if (string.IsNullOrWhiteSpace(rule.SalesRule)) { p.VendorCommissionInfo.SaleRuleEntity = new VendorStagedSaleRuleEntity(); } else { p.VendorCommissionInfo.SaleRuleEntity = SerializationUtility.XmlDeserialize <VendorStagedSaleRuleEntity>(rule.SalesRule); } p.VendorCommissionInfo.OrderCommissionAmt = rule.OrderCommissionFee; } } StoreDA.CreateVendorCommissionInfo(p, sellerSysNo, createUserName); #region 写入品牌商检信息 //seller portal不需要些商检信息,在ecc中品牌审核通过后写品牌的商检信息 //var brandFiling = new StoreBrandFiling(); //brandFiling.AgentLevel = p.AgentLevel; //brandFiling.BrandSysNo = p.BrandInfo.SysNo.Value; //brandFiling.CompanyCode = p.CompanyCode; //brandFiling.EditDate = DateTime.Now; //brandFiling.EditUserName = createUserName; //brandFiling.EditUserSysNo = sellerSysNo; //brandFiling.InDate = DateTime.Now; //brandFiling.InUserName = createUserName; //brandFiling.InUserSysNo = sellerSysNo; //brandFiling.Staus = 1; //brandFiling.SellerSysNo = sellerSysNo; //brandFiling.InspectionNo = CommonService.GenerateInspectionNo(); //StoreDA.InsertStoreBrandFiling(brandFiling); #endregion #region 写申请表 if (isRequest) { VendorModifyRequestInfo requestVendorAgentInfo = new VendorModifyRequestInfo { ActionType = VendorModifyActionType.Add, RequestType = VendorModifyRequestType.Manufacturer, VendorSysNo = sellerSysNo, //生产商的编号读取品牌对应的生产商 //ManufacturerSysNo = agentInfo.ManufacturerInfo.SysNo.Value, VendorManufacturerSysNo = p.AgentSysNo.Value, AgentLevel = p.AgentLevel, C2SysNo = p.C2SysNo, C3SysNo = p.C3SysNo, Status = VendorModifyRequestStatus.Apply, SettlePercentage = p.SettlePercentage, SettleType = p.SettleType, BuyWeekDay = p.BuyWeekDay, SendPeriod = p.SendPeriod, BrandSysNo = p.BrandInfo.SysNo, CompanyCode = p.CompanyCode, //CRL20146 By Kilin //写代销结算类型 //SettlePeriodType = vendorInfo.VendorFinanceInfo.SettlePeriodType, SettlePeriodType = null, AutoAudit = false, MaxNoPayTimeForOrder = p.MaxNoPayTimeForOrder, IsNeedConfirmOrder = p.IsNeedConfirmOrder //]] }; // StoreDA.CreateModifyRequest(requestVendorAgentInfo, sellerSysNo); } #endregion }); trans.Complete(); } }
/// <summary> /// 创建佣金规则 /// </summary> /// <param name="rule"></param> /// <returns></returns> public virtual CommissionRule CreateCommissionRule(CommissionRule rule) { CommissionRule newRule = CommissionDA.CreateCommission(rule); return(newRule); }
/// <summary> /// 创建新的佣金规则 /// </summary> /// <param name="newCommissionRule"></param> /// <returns></returns> public CommissionRule CreateCommission(CommissionRule newCommissionRule) { return(newCommissionRule); }