public void RecommendCustomerAddExperienceSendMail(ECCentral.BizEntity.Customer.CustomerBasicInfo recommendCustomerInfo, string newCustomerID, decimal experience) { try { string customerEmail = recommendCustomerInfo.Email == null ? null : recommendCustomerInfo.Email.Trim(); if (customerEmail == null) { return; } KeyValueVariables keyValueVariables = new KeyValueVariables(); keyValueVariables.Add("RmdCustomerID", recommendCustomerInfo.CustomerID); keyValueVariables.Add("NewCustomerID", newCustomerID); keyValueVariables.Add("Experience", experience); ExternalDomainBroker.SendExternalEmail(customerEmail, "SO_ShipOut_UserAddExperience", keyValueVariables, recommendCustomerInfo.FavoriteLanguageCode); } catch (Exception ex) { ExceptionHelper.HandleException(ex); } }
/// <summary> /// 作废订单时检查订单的支付信息 /// </summary> /// <param name="soSysNo"></param> protected virtual void AbandonSOIncomeCheck() //IPP3:SOCommonBP.SOIncomeCheck(soInfo.BaseInfo.SystemNumber, soInfo.MessageHeaderInfo.CompanyCode); { // 1. 检查是否有待审核的网上支付记录,如果存在则要作废或生成负收款 if (ExternalDomainBroker.IsExistOriginNetPay(SOSysNo)) { BizExceptionHelper.Throw("SO_Abandon_IsExistNetPay"); } // 2. 检查是否有有效的收款记录, 如果存在生成负收款 if (CurrentSOIncome != null && CurrentAOIncome == null) { if (CurrentSOIncome.Status == SOIncomeStatus.Confirmed) { BizExceptionHelper.Throw("SO_Abandon_ExistSOIncome_Confirmed"); } else if (CurrentSOIncome.Status == SOIncomeStatus.Origin) { BizExceptionHelper.Throw("SO_Abandon_ExistSOIncome_Origin"); } } }
/// <summary> /// 拆分订单发票 /// </summary> /// <param name="soSysNo">订单系统编号</param> /// <param name="invoiceItems"></param> public virtual void CancelSplitSOInvoice(int soSysNo) { SOBaseInfo soInfo = GetSOBaseInfoBySOSysNo(soSysNo); switch (soInfo.Status.Value) { case SOStatus.Origin: case SOStatus.WaitingOutStock: { //取消拆分发票 ExternalDomainBroker.CancelSplitInvoice(soSysNo); //更新订单信息 SODA.UpdateSOForSplitInvoice(soSysNo, false); } break; default: BizExceptionHelper.Throw("SO_CacelSplitInvoice_StatusIsError"); break; } }
/// <summary> /// 拆分订单发票 /// </summary> /// <param name="soSysNo">订单系统编号</param> /// <param name="invoiceItems"></param> public virtual void SplitSOInvoice(int soSysNo, List <ECCentral.BizEntity.Invoice.SubInvoiceInfo> invoiceItems) { SOBaseInfo soInfo = GetSOBaseInfoBySOSysNo(soSysNo); switch (soInfo.Status.Value) { case SOStatus.Origin: case SOStatus.WaitingOutStock: { //拆分发票 ExternalDomainBroker.SplitInvoice(invoiceItems); //更新订单信息 SODA.UpdateSOForSplitInvoice(soSysNo, true); } break; default: BizExceptionHelper.Throw("SO_SplitInvoice_StatusIsError"); break; } }
public void SendSMS(SOInfo soInfo, BizEntity.Customer.SMSType type) { try { ECCentral.BizEntity.Customer.CustomerBasicInfo customerInfo = GetCustomerBaseInfo(soInfo.BaseInfo.CustomerSysNo.Value); string customerLanguageCode = customerInfo.FavoriteLanguageCode; string smsContent = ObjectFactory <ECCentral.Service.IBizInteract.ICustomerBizInteract> .Instance.GetSMSContent(soInfo.WebChannel == null?null : soInfo.WebChannel.ChannelID, customerLanguageCode, soInfo.ShippingInfo.ShipTypeSysNo.Value, type); if (string.IsNullOrEmpty(smsContent)) { return; } string mobilePhone = string.Empty; if (!string.IsNullOrEmpty(soInfo.ReceiverInfo.MobilePhone)) { mobilePhone = soInfo.ReceiverInfo.MobilePhone; } else { mobilePhone = soInfo.ReceiverInfo.Phone; } if (smsContent.IndexOf("SO#") != -1) { smsContent = smsContent.Replace("SO#", soInfo.BaseInfo.SOID); } else { return; } // 上海仓库自提且分期付款,特殊短信内容 ExternalDomainBroker.SendSMS(mobilePhone, smsContent, BizEntity.Common.SMSPriority.Normal); } catch (Exception ex) { ExceptionHelper.HandleException(ex); } }
private void FailedGroupBuyProcess(GroupBuyingInfo gbInfo) { TransactionOptions options = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }; using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options)) { try { SODA.UpdateGroupBuySOItemSettlementStatusByGroupBuySysNo(gbInfo.SysNo.Value, BizEntity.SO.SettlementStatus.PlanFail); } catch { SODA.UpdateGroupBuySOItemSettlementStatusByGroupBuySysNo(gbInfo.SysNo.Value, BizEntity.SO.SettlementStatus.Fail); SODA.UpdateGroupBuySOSettlementStatusByGroupBuySysNo(gbInfo.SysNo.Value, BizEntity.SO.SettlementStatus.Fail); } ExternalDomainBroker.UpdateGroupBuySettlementStatus(gbInfo.SysNo.Value, GroupBuyingSettlementStatus.Yes); scope.Complete(); } }
/// <summary> /// 验证订单支付状态 /// </summary> /// <param name="isForce"></param> /// <returns></returns> private SOStatus ValidateSOPayStatus() { SOStatus status = CurrentSO.BaseInfo.Status.Value; BizEntity.Common.PayType ptInfo = ExternalDomainBroker.GetPayTypeBySysNo(CurrentSO.BaseInfo.PayTypeSysNo.Value); if (ptInfo == null) { BizExceptionHelper.Throw("SO_Audit_PayTypeNotExist", CurrentSO.BaseInfo.PayTypeSysNo.ToString()); } else if (CurrentSO.BaseInfo.PayWhenReceived.HasValue && CurrentSO.BaseInfo.PayWhenReceived.Value) { //货到付款可以直接出库 status = SOStatus.WaitingOutStock; } else if (ValidateSOIncome()) { //支付无误,为待出库(电子卡直接完成) status = SOStatus.WaitingOutStock; } return(status); }
private string GetOrginComputerNo(int?stockA, string companyCode) { if (!stockA.HasValue) { return(string.Empty); } string result = string.Empty; string whcomfig = ExternalDomainBroker.GetSystemConfigurationValue("GrouldSettingValue", companyCode); if (string.IsNullOrEmpty(whcomfig)) { BizExceptionHelper.Throw("Res_SO_SysConfigurationError"); } Dictionary <string, string> dic_whs = new Dictionary <string, string>(); string[] strs = whcomfig.Split(new char[] { ',' }); foreach (string str in strs) { string[] srs = str.Split(new char[] { ':' }); dic_whs.Add(srs[0], srs[1]); } foreach (var wh in dic_whs) { if (wh.Key == stockA.ToString()) { result = wh.Value; } } if (result == string.Empty) { BizExceptionHelper.Throw("Res_SO_NotExistsKeyStock", stockA.Value.ToString()); } return(result); }
public void SendMessageToWMS(SOInfo soInfo, WMSAction action, OPCCallBackType callBackType) { object mark = new object(); List <int> stockSysNoList = (from item in soInfo.Items where item.StockSysNo.HasValue && item.ProductType != SOProductType.Coupon && item.ProductType != SOProductType.ExtendWarranty select item.StockSysNo.Value).Distinct().ToList(); lock (mark) { int masterID = this.SaveOPCMaster(soInfo, action, callBackType); foreach (int stockSysNo in stockSysNoList) { WarehouseInfo wareInfo = ExternalDomainBroker.GetWarehouseInfo(stockSysNo); string stockID = wareInfo == null ? "" : wareInfo.WarehouseID; if (String.IsNullOrEmpty(stockID)) { BizExceptionHelper.Throw("SO_Audit_StockIsNotExist", stockSysNo.ToString()); } int transactionID = this.SaveOPCTransaction(soInfo.SysNo.Value, stockSysNo, masterID, soInfo.CompanyCode); WMSSOActionRequestMessage requestEntity = new WMSSOActionRequestMessage { SOSysNo = soInfo.SysNo.Value, CompanyCode = soInfo.CompanyCode, ActionDate = DateTime.Now, ActionReason = string.Format("{0} SO", action.ToDisplayText()), StockSysNo = stockSysNo, TransactionSysNo = transactionID, StockID = stockID, Language = soInfo.BaseInfo.LanguageCode, ActionType = WMSActionToAction(action), ActionUser = ServiceContext.Current.UserSysNo }; this.SaveOPCMessage(soInfo, transactionID, requestEntity); EventPublisher.Publish <WMSSOActionRequestMessage>(requestEntity); } } }
public void InsertKnownFraudCustomer(KnownFraudCustomer entity) { if (m_da.GetKFCByCustomerSysNo(entity.CustomerSysNo.Value) != null) { return; } int maxBlockMark = 0; if (!int.TryParse(ExternalDomainBroker.GetSystemConfigurationValue("GRADENUM", entity.CompanyCode), out maxBlockMark)) { maxBlockMark = 5; } List <KnownFraudCustomer> list = m_da.GetKFCByIPAndTel(entity.IPAddress, entity.MobilePhone, entity.Telephone, entity.CompanyCode); //存在同一个IP地址且同一个手机号码相同记录重复5条 //则其相关的客户信息升级到Block if (list != null && list.Count + 1 >= maxBlockMark) { list.ForEach(item => { item.KFCType = KFCType.QiZha; item.LastEditDate = item.CreateDate; item.LastEditUserName = item.CreateUserName; m_da.UpdateKnowFrandCustomerStatus(item); }); entity.KFCType = KFCType.QiZha; m_da.InsertKnowFrandCustomer(entity); } else { m_da.InsertKnowFrandCustomer(entity); } }
/// <summary> /// 更新团购订单 /// </summary> /// <param name="CurrentSO"></param> /// <returns></returns> public void Update() { ValidationSOEntity(); ValidationGroupBuyingRules(); SOItemInfo groupBuyProduct = CurrentSO.Items.Find(item => item.ProductSysNo == ProductSysNo); if (groupBuyProduct == null) { return; } //可能有赠品,但是只会有一个主商品 int groupBuySysNo = groupBuyProduct.ReferenceSysNo.Value; GroupBuyingInfo gbInfo = ExternalDomainBroker.GetGroupBuyInfoBySysNo(groupBuySysNo); decimal dealPrice = gbInfo.GBPrice.HasValue ? gbInfo.GBPrice.Value : -1; if (dealPrice < 0) { throw new BizException(ResourceHelper.Get("SO_Audit_GroupNotDealPrice", CurrentSO.SysNo)); } if (groupBuyProduct != null && dealPrice < groupBuyProduct.Price) { SOInfo newSOInfo = new SOInfo(); //newSOInfo.SOItemList = SerializeHelper.DeepClone(soInfo.SOItemList); List <SOItemInfo> otherItems = CurrentSO.Items.FindAll(x => x.ProductSysNo != ProductSysNo); decimal oldSOAmt = 0.0m; if (otherItems != null && otherItems.Count > 0) { oldSOAmt = otherItems.Sum(x => x.OriginalPrice.Value * x.Quantity.Value); } decimal newSOAmt = oldSOAmt; if (groupBuyProduct.ProductType == SOProductType.Product) { groupBuyProduct.Price = dealPrice; groupBuyProduct.OriginalPrice = dealPrice; groupBuyProduct.SettlementStatus = SettlementStatus.Success; //团购订单不能用优惠卷 newSOAmt += dealPrice * groupBuyProduct.Quantity.Value; } int refundPoint = 0; decimal refundPrepay = 0.0m; decimal refundGiftCard = 0.0m; decimal difference = CurrentSO.BaseInfo.SOAmount.Value - newSOAmt; decimal newPrepayAmt = CurrentSO.BaseInfo.PrepayAmount.Value; decimal newGiftCardPay = CurrentSO.BaseInfo.GiftCardPay.Value; decimal newPremiumAmt = CurrentSO.BaseInfo.PremiumAmount.Value; int newPointPay = CurrentSO.BaseInfo.PointPay.Value; decimal newCashPay = newSOAmt - Math.Abs(CurrentSO.BaseInfo.PointPayAmount.Value); ECCentral.BizEntity.Common.ShippingType shippingType = ExternalDomainBroker.GetShippingTypeBySysNo(CurrentSO.ShippingInfo.ShipTypeSysNo.Value); if (CurrentSO.BaseInfo.IsPremium.Value) { if (shippingType != null && newSOAmt > shippingType.PremiumBase) { newPremiumAmt = UtilityHelper.ToMoney(newSOAmt * shippingType.PremiumRate.Value); } } decimal pointToMoneyRatio = ExternalDomainBroker.GetPointToMoneyRatio(); #region 退款逻辑 //退款优先级:1.先退现金支付(注意:不在这里退还),2.退余额支付,3.退礼品卡支付,4.退积分支付 // 1. 需退还的:余额支付金额,退礼支付品金额,积分支付金额的总合 decimal refundPayAmount = CurrentSO.BaseInfo.PrepayAmount.Value + CurrentSO.BaseInfo.GiftCardPay.Value + CurrentSO.BaseInfo.PointPayAmount.Value - (newSOAmt + newPremiumAmt + CurrentSO.BaseInfo.ShipPrice.Value); // 2. 如果使用余额支付,退到余额 if (refundPayAmount > 0) { refundPrepay = refundPayAmount > CurrentSO.BaseInfo.PrepayAmount ? CurrentSO.BaseInfo.PrepayAmount.Value : refundPayAmount; newPrepayAmt = CurrentSO.BaseInfo.PrepayAmount.Value - refundPrepay; refundPayAmount = refundPayAmount - refundPrepay; // 3. 如果使用礼品卡支付,退到礼品卡 if (refundPayAmount > 0) { refundGiftCard = refundPayAmount > CurrentSO.BaseInfo.GiftCardPay ? CurrentSO.BaseInfo.GiftCardPay.Value : refundPayAmount; newGiftCardPay = CurrentSO.BaseInfo.GiftCardPay.Value - refundGiftCard; refundPayAmount = refundPayAmount - refundGiftCard; // 4. 如果使用积分支付,退积分 if (refundPayAmount > 0) { decimal refundPointAmount = refundPayAmount > CurrentSO.BaseInfo.PointPayAmount ? CurrentSO.BaseInfo.PointPayAmount.Value : refundPayAmount; refundPayAmount = refundPayAmount - refundPointAmount; decimal newPontPayAmount = CurrentSO.BaseInfo.PointPayAmount.Value - refundPointAmount; newPointPay = (int)(newPontPayAmount * pointToMoneyRatio); refundPoint = (int)(refundPointAmount * pointToMoneyRatio); newCashPay = newSOAmt - newPontPayAmount; } } } #endregion ECCentral.BizEntity.Common.PayType payType = ExternalDomainBroker.GetPayTypeBySysNo(CurrentSO.BaseInfo.PayTypeSysNo.Value); decimal newPayPrice = Math.Max(UtilityHelper.ToMoney(payType.PayRate.Value * (newCashPay + CurrentSO.BaseInfo.ShipPrice.Value + newPremiumAmt - newPrepayAmt - newGiftCardPay)), 0M); CurrentSO.BaseInfo.SOAmount = newSOAmt; CurrentSO.BaseInfo.PremiumAmount = newPremiumAmt; CurrentSO.BaseInfo.PayPrice = newPayPrice; CurrentSO.BaseInfo.GiftCardPay = newGiftCardPay; CurrentSO.BaseInfo.PointPay = newPointPay; CurrentSO.BaseInfo.PointPayAmount = CurrentSO.BaseInfo.PointPay.Value / pointToMoneyRatio; CurrentSO.BaseInfo.PrepayAmount = newPrepayAmt; TransactionOptions options = new TransactionOptions(); options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted; using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options)) { SODA.UpdateGroupBuySOAmount(CurrentSO.BaseInfo); SODA.UpdateGroupBuyProduct(groupBuyProduct); if (refundPrepay > 0) { ExternalDomainBroker.AdjustPrePay(new BizEntity.Customer.CustomerPrepayLog { AdjustAmount = refundPrepay, CustomerSysNo = CurrentSO.BaseInfo.CustomerSysNo, Note = "Update SO For GroupBuying", PrepayType = ECCentral.BizEntity.Customer.PrepayType.SOPay, SOSysNo = CurrentSO.SysNo, }); } if (refundGiftCard > 0) { ExternalDomainBroker.GiftCardVoidForSOUpdate(newGiftCardPay, CurrentSO.SOGiftCardList, CurrentSO.CompanyCode); } if (refundPoint > 0) { ExternalDomainBroker.AdjustPoint(new BizEntity.Customer.AdjustPointRequest { CustomerSysNo = CurrentSO.BaseInfo.CustomerSysNo, Memo = "Update Group Buying SO", OperationType = ECCentral.BizEntity.Customer.AdjustPointOperationType.AddOrReduce, Point = refundPoint, PointType = (int)ECCentral.BizEntity.Customer.AdjustPointType.UpdateSO, SOSysNo = CurrentSO.SysNo, Source = SOConst.DomainName }); } scope.Complete(); } } WriteLog(BizEntity.Common.BizLogType.Sale_SO_Update, "IPP更改团购订单"); }
public SOInfo CloneSO(SOInfo entity) { //获取原先的订单 SOInfo oriSO = GetSOBySOSysNo(entity.SysNo.Value); if (oriSO.Items.Exists(x => x.PriceType == SOProductPriceType.GoldAcc || x.PriceType == SOProductPriceType.GuanAiAcc || x.PriceType == SOProductPriceType.SdoAccPrice)) { BizExceptionHelper.Throw("SO_CloneSO_GuanAiAccCannotClone"); } //捆绑销售不能拆分 if (!CheckSaleRule(oriSO, entity)) { BizExceptionHelper.Throw("SO_CloneSO_ComboCanNotClone"); } oriSO.Items.Clear(); oriSO.Items = entity.Items; oriSO.SysNo = NewSOSysNo(); oriSO.BaseInfo.HoldStatus = SOHoldStatus.Unhold; oriSO.BaseInfo.HoldReason = string.Empty; oriSO.BaseInfo.HoldUser = 0; //验证 if (oriSO.Items.Exists(item => item.ProductType == SOProductType.SelfGift)) { BizExceptionHelper.Throw("SO_CloneSO_NeweggGiftCannotClone"); } //合约机订单 团购订单 依旧换新订单不能拆分 if (oriSO.BaseInfo.SOType == SOType.GroupBuy) { BizExceptionHelper.Throw("SO_CloneSO_ParticularCannotClone"); } //帐期不能拆分 if (oriSO.BaseInfo.PayTypeSysNo.Value == 4) { BizExceptionHelper.Throw("SO_CloneSO_ZhangQiCannotClone"); } //存在AO不能拆分 if (ExternalDomainBroker.GetValidSOIncomeInfo(entity.SysNo.Value, BizEntity.Invoice.SOIncomeOrderType.AO) != null) { BizExceptionHelper.Throw("SO_CloneSO_ExistsAOCannotCannotClone"); } ExternalDomainBroker.CreateOperationLog("Create SO", BizLogType.Sale_SO_Create, entity.BaseInfo.SysNo.Value, entity.CompanyCode); ProcessSO(new SOAction.SOCommandInfo { Command = SOAction.SOCommand.Create, SOInfo = oriSO }); string note = oriSO.SysNo.ToString() + "["; oriSO.Items.ForEach(item => { note += item.ProductSysNo.ToString(); }); note += "]"; SODA.UpdateSONote(oriSO.SysNo.Value, note); ExternalDomainBroker.CreateOperationLog("更新订单(拆单)", BizLogType.Sale_SO_Update, entity.BaseInfo.SysNo.Value, entity.CompanyCode); return(oriSO); }
/// <summary> /// 填充调用与外Domain相关的字段 /// </summary> /// <param name="soList"></param> protected void FillSOInfo(List <SOInfo> soList) { if (soList != null && soList.Count > 0) { List <SOItemInfo> soItemList = new List <SOItemInfo>(); List <int> productSysNoList = new List <int>(); List <int> customerSysNoList = new List <int>(); List <SOItemInfo> exItemList = new List <SOItemInfo>(); soList.ForEach(soInfo => { //取得订单使用的礼品卡记录 soInfo.SOGiftCardList = ExternalDomainBroker.GetSOGiftCardBySOSysNo(soInfo.SysNo.Value); if (!customerSysNoList.Exists(no => no == soInfo.BaseInfo.CustomerSysNo.Value)) { customerSysNoList.Add(soInfo.BaseInfo.CustomerSysNo.Value); } soInfo.Items.ForEach(item => { item.ProductID = string.Empty; switch (item.ProductType.Value) { case SOProductType.Coupon: item.ProductID = item.ProductSysNo.ToString(); soItemList.Add(item); break; case SOProductType.ExtendWarranty: exItemList.Add(item); break; default: { soItemList.Add(item); if (!productSysNoList.Exists(sysNo => sysNo == item.ProductSysNo)) { productSysNoList.Add(item.ProductSysNo.Value); } break; } } }); }); List <CustomerBasicInfo> customerList = ExternalDomainBroker.GetCustomerBasicInfo(customerSysNoList); if (customerList != null) { customerList.ForEach(c => { SOInfo soInfo = soList.Find(so => so.BaseInfo.CustomerSysNo == c.CustomerSysNo); if (soInfo != null) { soInfo.BaseInfo.CustomerID = c.CustomerID; soInfo.BaseInfo.CustomerName = c.CustomerName; } }); } if (productSysNoList.Count > 0) { List <ECCentral.BizEntity.IM.ProductInfo> productList = ExternalDomainBroker.GetProductInfoListByProductSysNoList(productSysNoList); if (productList != null) { productList.ForEach(product => { List <SOItemInfo> itemList = soItemList.FindAll(item => { return(item.ProductType != SOProductType.Coupon && item.ProductType != SOProductType.ExtendWarranty && item.ProductSysNo == product.SysNo); }); foreach (SOItemInfo item in itemList) { item.ProductID = product.ProductID; } }); exItemList.ForEach(ei => { int mpNo = int.TryParse(ei.MasterProductSysNo, out mpNo) ? mpNo : int.MinValue; SOItemInfo mp = soItemList.Find(i => i.ProductSysNo == mpNo); if (mp != null) { ei.ProductID = mp.ProductID + "E"; } }); } } } }
public ECCentral.BizEntity.Invoice.SOIncomeInfo GetValidSOIncomeInfo(int orderSysNo) { return(ExternalDomainBroker.GetValidSOIncomeInfo(orderSysNo)); }
/// <summary> /// 根据 礼品卡编号 和密码 获取 对应的礼品卡信息 /// </summary> /// <param name="code">礼品卡 卡号</param> /// <param name="password">礼品卡 密码</param> public GiftCardInfo QueryGiftCardByCodeAndPassword(string code, string password) { return(ExternalDomainBroker.GetGiftCardByCodeAndPassword(code, password)); }
public void CustomsPass() { XElement orderConfig = AppSettingHelper.OrderBizConfig; int userSysno = int.Parse(orderConfig.Element(XName.Get("SellerPortalUserInfo")).Element(XName.Get("UserSysNo")).Value); // int.Parse(orderConfig.SellerPortalUserInfo.UserSysNo); SOInfo soInfo = CurrentSO; //1.检查SO信息 //ValidateSOInfo(soInfo); if (soInfo.BaseInfo.Status.HasValue && soInfo.BaseInfo.Status.Value != SOStatus.Reported) { string errorMsg = string.Format("SO单{0}的状态不是“已申报待通关”,不能执行出库操作!", soInfo.BaseInfo.SOID); BizExceptionHelper.Throw(errorMsg); } #region 修改订单状态,调整库存,创建代销转财务记录 TransactionOptions option = new TransactionOptions(); option.IsolationLevel = IsolationLevel.ReadUncommitted; option.Timeout = TransactionManager.DefaultTimeout; using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, option)) { soInfo.BaseInfo.Status = SOStatus.CustomsPass; //设置出库状态 SODA.UpdateSOStatusToCustomsPass(soInfo.SysNo.Value); List <BizEntity.Inventory.InventoryAdjustItemInfo> adjustItemList = new List <BizEntity.Inventory.InventoryAdjustItemInfo>(); foreach (SOItemInfo soItem in soInfo.Items) { switch (soItem.ProductType.Value) { case SOProductType.Product: case SOProductType.Gift: case SOProductType.Award: case SOProductType.SelfGift: case SOProductType.Accessory: adjustItemList.Add(new BizEntity.Inventory.InventoryAdjustItemInfo { AdjustQuantity = soItem.Quantity.Value, ProductSysNo = soItem.ProductSysNo.Value, StockSysNo = soItem.StockSysNo.Value }); break; case SOProductType.Coupon: case SOProductType.ExtendWarranty: break; } } //调整库存 ExternalDomainBroker.AdjustProductInventory(new BizEntity.Inventory.InventoryAdjustContractInfo { SourceActionName = BizEntity.Inventory.InventoryAdjustSourceAction.OutStock, SourceBizFunctionName = BizEntity.Inventory.InventoryAdjustSourceBizFunction.SO_Order, ReferenceSysNo = soInfo.SysNo.Value.ToString(), AdjustItemList = adjustItemList }); //Bowen:代码调整,加入事务中 2013-08-08 //模式2,3创建代销转财务日志 CreateConsigenToAccInfo(soInfo); #region 更新客户等级以及积分经验值 //增加客户经验值 //更新客户等级 //调整客户经验值(内部修改客户等级) int customerSysNo = soInfo.BaseInfo.CustomerSysNo.Value; decimal adjustValue = soInfo.BaseInfo.CashPay + soInfo.BaseInfo.PayPrice.Value + soInfo.BaseInfo.ShipPrice.Value + soInfo.BaseInfo.PremiumAmount.Value + soInfo.BaseInfo.PromotionAmount.Value; string logMemo = string.Format("SO#{0}:购物加经验值。", soInfo.SysNo); ExternalDomainBroker.AdjustCustomerExperience(customerSysNo, adjustValue, BizEntity.Customer.ExperienceLogType.MerchantSOOutbound, logMemo); //增加推荐用户的经验值 AddExperienceByRecommend(soInfo); //给款到发货用户加积分 AddPointForCustomer(soInfo); #endregion 更新客户等级以及积分经验值 #region 财务应收 //创建收款单 ECCentral.BizEntity.Invoice.SOIncomeInfo soIncomeInfo = ExternalDomainBroker.GetValidSOIncomeInfo(soInfo.SysNo.Value, BizEntity.Invoice.SOIncomeOrderType.SO); if (soIncomeInfo == null) { soIncomeInfo = new BizEntity.Invoice.SOIncomeInfo(); soIncomeInfo.OrderType = BizEntity.Invoice.SOIncomeOrderType.SO; soIncomeInfo.OrderSysNo = soInfo.SysNo; soIncomeInfo.OrderAmt = UtilityHelper.TruncMoney(soInfo.BaseInfo.SOTotalAmount); soIncomeInfo.IncomeAmt = UtilityHelper.TruncMoney(soInfo.BaseInfo.OriginalReceivableAmount); soIncomeInfo.PrepayAmt = Math.Max(soInfo.BaseInfo.PrepayAmount.Value, 0); soIncomeInfo.IncomeStyle = ECCentral.BizEntity.Invoice.SOIncomeOrderStyle.Normal; //soIncomeInfo.IncomeUserSysNo = soInfo.LastEditUserSysNumber ?? 0; //soIncomeInfo.IncomeTime = DateTime.Now; soIncomeInfo.Status = ECCentral.BizEntity.Invoice.SOIncomeStatus.Origin; soIncomeInfo.GiftCardPayAmt = soInfo.BaseInfo.GiftCardPay; soIncomeInfo.PointPay = soInfo.BaseInfo.PointPay; soIncomeInfo.PayAmount = soInfo.BaseInfo.OriginalReceivableAmount; if (soInfo.BaseInfo.SOSplitMaster.HasValue) { soIncomeInfo.MasterSoSysNo = soInfo.BaseInfo.SOSplitMaster; //获取母单号 } ExternalDomainBroker.CreateSOIncome(soIncomeInfo); } #endregion 财务应收 //this.PublishMessage(); scope.Complete(); } #endregion SOSendMessageProcessor messageProcessor = ObjectFactory <SOSendMessageProcessor> .Instance; //发送邮件 messageProcessor.SOOutStockSendEmailToCustomer(soInfo); //发送短信提醒 //发送短信 messageProcessor.SendSMS(soInfo, BizEntity.Customer.SMSType.OrderOutBound); if (soInfo.InvoiceInfo.IsVAT.Value && soInfo.InvoiceInfo.InvoiceType == ECCentral.BizEntity.Invoice.InvoiceType.SELF) { //增票提醒短信 messageProcessor.SendVATSMS(soInfo); //发送增值税发票SSB EventPublisher.Publish <ECCentral.Service.EventMessage.ImportVATSSBMessage>(new ECCentral.Service.EventMessage.ImportVATSSBMessage { SOSysNo = soInfo.SysNo.Value, StockSysNo = soInfo.Items[0].StockSysNo.Value, OrderType = EventMessage.ImportVATOrderType.SO }); } //调用OverseaInvoiceReceiptManagement.dbo.UP_InvoiceSync //插入Inovice_Master ObjectFactory <ECCentral.Service.IBizInteract.IInvoiceBizInteract> .Instance.SOOutStockInvoiceSync(soInfo.SysNo.Value, soInfo.Items[0].StockSysNo.Value, soInfo.InvoiceInfo.InvoiceNo, soInfo.CompanyCode); //EventPublisher.Publish<ECCentral.Service.EventMessage.CreateInvoiceSSBMessage>(new ECCentral.Service.EventMessage.CreateInvoiceSSBMessage //{ // CompanyCode = soInfo.CompanyCode, // InvoiceNo = soInfo.InvoiceInfo.InvoiceNo, // SOSysNo = soInfo.SysNo.Value, // StockSysNo = soInfo.Items[0].StockSysNo.Value //}); //记录日志 WriteLog(ECCentral.BizEntity.Common.BizLogType.Sale_SO_CustomsPass, "通关成功"); }
/// <summary> /// 网关订单查询 /// </summary> /// <param name="soSysNo">订单编号</param> public TransactionQueryBill QueryBill(string soSysNo) { return(ExternalDomainBroker.QueryBill(soSysNo)); }
/// <summary> /// 调整仓库,返还库存 /// </summary> protected virtual void AdjustInventory() { List <BizEntity.Inventory.InventoryAdjustItemInfo> adjustItemList = new List <BizEntity.Inventory.InventoryAdjustItemInfo>(); SOProcessor sopro = new SOProcessor(); DateTime? SOCreatDate = CurrentSO.BaseInfo.CreateTime; int SOSysNo = int.Parse(CurrentSO.BaseInfo.SOID); foreach (SOItemInfo soItem in CurrentSO.Items) { //如果订单已经支付直接返还库存 if (sopro.NetpaySOCheckReturnInventory(SOSysNo)) { switch (soItem.ProductType.Value) { case SOProductType.Product: case SOProductType.Gift: case SOProductType.Award: case SOProductType.SelfGift: case SOProductType.Accessory: adjustItemList.Add(new BizEntity.Inventory.InventoryAdjustItemInfo { AdjustQuantity = soItem.Quantity.Value, ProductSysNo = soItem.ProductSysNo.Value, StockSysNo = soItem.StockSysNo.Value }); break; case SOProductType.Coupon: case SOProductType.ExtendWarranty: break; } } else { //开启促销活动里的商品支持付款后扣减在线库存 if (AppSettingManager.GetSetting(SOConst.DomainName, "PaymentInventory").ToString().ToLower() == "true") { //判断商品是否是在促销活动时间里买的商品,如果是,就返还库存 if (sopro.CheckReturnInventory(soItem.ProductSysNo.Value, SOCreatDate.Value)) { switch (soItem.ProductType.Value) { case SOProductType.Product: case SOProductType.Gift: case SOProductType.Award: case SOProductType.SelfGift: case SOProductType.Accessory: adjustItemList.Add(new BizEntity.Inventory.InventoryAdjustItemInfo { AdjustQuantity = soItem.Quantity.Value, ProductSysNo = soItem.ProductSysNo.Value, StockSysNo = soItem.StockSysNo.Value }); break; case SOProductType.Coupon: case SOProductType.ExtendWarranty: break; } } } else { switch (soItem.ProductType.Value) { case SOProductType.Product: case SOProductType.Gift: case SOProductType.Award: case SOProductType.SelfGift: case SOProductType.Accessory: adjustItemList.Add(new BizEntity.Inventory.InventoryAdjustItemInfo { AdjustQuantity = soItem.Quantity.Value, ProductSysNo = soItem.ProductSysNo.Value, StockSysNo = soItem.StockSysNo.Value }); break; case SOProductType.Coupon: case SOProductType.ExtendWarranty: break; } } } } ExternalDomainBroker.AdjustProductInventory(new BizEntity.Inventory.InventoryAdjustContractInfo { ReferenceSysNo = SOSysNo.ToString(), SourceActionName = IsImmediatelyReturnStock ? BizEntity.Inventory.InventoryAdjustSourceAction.Abandon_RecoverStock : BizEntity.Inventory.InventoryAdjustSourceAction.Abandon, IsOutStockAbandon = IsOutStockOrder ? true : false, SourceBizFunctionName = BizEntity.Inventory.InventoryAdjustSourceBizFunction.SO_Order, AdjustItemList = adjustItemList }); }
/// <summary> /// 作废订单 /// </summary> /// <param name="isSynch">是否同步作废</param> /// <param name="IsImmediatelyReturnStock">是否立即返还库存</param> /// <param name="isAO"></param> protected virtual void AbandonSO() { int couponSysNo = CouponList != null && CouponList.Count > 0 ? CouponList[0].ProductSysNo.Value : 0; string couponCode = string.Empty; var shopProducts = CurrentSO.Items.Where(p => p.InventoryType == BizEntity.IM.ProductInventoryType.GetShopInventory); //ERP库存调整 ERPInventoryAdjustInfo erpAdjustInfo = new ERPInventoryAdjustInfo { OrderSysNo = this.CurrentSO.SysNo.Value, OrderType = "SO", AdjustItemList = new List <ERPItemInventoryInfo>(), Memo = "作废减少销售数量" }; foreach (var item in shopProducts) { ERPItemInventoryInfo adjustItem = new ERPItemInventoryInfo { ProductSysNo = item.ProductSysNo, B2CSalesQuantity = -item.Quantity.Value }; erpAdjustInfo.AdjustItemList.Add(adjustItem); } if (erpAdjustInfo.AdjustItemList.Count > 0) { string adjustXml = ECCentral.Service.Utility.SerializationUtility.ToXmlString(erpAdjustInfo); ObjectFactory <ICommonBizInteract> .Instance.CreateOperationLog(string.Format("作废减少销售数量:{0}", adjustXml) , BizLogType.Sale_SO_VoideSO , this.CurrentSO.SysNo.Value , this.CurrentSO.CompanyCode); //ObjectFactory<IAdjustERPInventory>.Instance.AdjustERPInventory(erpAdjustInfo); } //IsolationLevel与上层事务IsolationLevel有冲突,去除 //TransactionOptions options = new TransactionOptions //{ // IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted //}; //using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) #region 如果是拆分后的子单,还需要更新主单信息。 if (CurrentSO.BaseInfo.SplitType == SOSplitType.SubSO) { //重新计算主订单SOAmt,ShipPrice,PrepayAmt,PremiumAmt SOInfo masterSO = SODA.GetSOBySOSysNo(CurrentSO.BaseInfo.SOSplitMaster.Value); masterSO.BaseInfo.PremiumAmount -= CurrentSO.BaseInfo.PremiumAmount; masterSO.BaseInfo.PrepayAmount -= CurrentSO.BaseInfo.PrepayAmount; masterSO.BaseInfo.ShipPrice -= CurrentSO.BaseInfo.ShipPrice; masterSO.BaseInfo.SOAmount -= CurrentSO.BaseInfo.SOAmount; masterSO.BaseInfo.GainPoint -= CurrentSO.BaseInfo.GainPoint; masterSO.BaseInfo.PointPay -= CurrentSO.BaseInfo.PointPay; masterSO.BaseInfo.PromotionAmount -= CurrentSO.BaseInfo.PromotionAmount; masterSO.BaseInfo.PayPrice -= CurrentSO.BaseInfo.PayPrice; masterSO.BaseInfo.CouponAmount -= CurrentSO.BaseInfo.CouponAmount; masterSO.BaseInfo.PointPayAmount -= CurrentSO.BaseInfo.PointPayAmount; //删除对应主单中的商品 foreach (SOItemInfo item in CurrentSO.Items) { //除优惠券外的商品 if (item.ProductType != SOProductType.Coupon) { SODA.DeleteSOItemBySOSysNoAndProductSysNo(masterSO.SysNo.Value, item.ProductSysNo.Value); } } //更新主订单金额 SODA.UpdateSOAmountInfo(masterSO.BaseInfo); } #endregion 如果是子单,还需要更新主单信息 //取消优惠券使用 CancelCoupon(); // 保存作废订单信息 SaveCurrentSO(); //if (AppSettingManager.GetSetting(SOConst.DomainName, "PaymentInventory").ToString().ToLower() != "true") //{ // // 调整仓库,返还商品库存 // AdjustInventory(); //} //SOProcessor sopro = new SOProcessor(); //DateTime? SOCreatDate = CurrentSO.BaseInfo.CreateTime; //foreach (var item in CurrentSO.Items) //{ // if (sopro.CheckReturnInventory(item.ProductSysNo.Value, SOCreatDate.Value)) // { // // 调整仓库,返还商品库存 // AdjustInventory(); // } //} //调整仓库,返还商品库存 AdjustInventory(); //订单支付 CancelSOPay(); // 如果订单有奖品,则要退还奖品。 if (CurrentSO.Items != null && CurrentSO.Items.Exists(x => x.ProductType == SOProductType.Award)) { ExternalDomainBroker.ReturnAwardForSO(SOSysNo); } // 取消配送 CancelDelivery(); // 作废订单的虚库申请 AbandonSOVirtualItemRequest(); // 提交作废订单之前,所做的操作。 PreCommit(); WriteLog(CurrentSO); }
/// <summary> /// 分摊子订单 /// </summary> /// <param name="subSOList"></param> private void CalculateSubSO(List <SOInfo> subSOList) { // 按金额升序排列,保证分摊的最后订单的金额最大,减少分摊误差。 subSOList.Sort((o1, o2) => { return(o1.BaseInfo.SOAmount.Value.CompareTo(o2.BaseInfo.SOAmount.Value)); }); decimal masterSOTotalPrice = CurrentSO.BaseInfo.PromotionAmount.Value; //计算金额基数 decimal masterSOTotalWeight = 0; //计算重量基数 CurrentSO.Items.ForEach(item => { masterSOTotalPrice += item.Quantity.Value * item.OriginalPrice.Value; masterSOTotalWeight += item.Quantity.Value * item.Weight.Value; }); #region 分摊主的费用到子订单 int t_PointPay = CurrentSO.BaseInfo.PointPay.Value; decimal t_ShipPrice = CurrentSO.BaseInfo.ShipPrice.Value; decimal t_PayPrice = CurrentSO.BaseInfo.PayPrice.Value; decimal t_PremiumAmt = CurrentSO.BaseInfo.PremiumAmount.Value; decimal t_PrepayAmt = CurrentSO.BaseInfo.PrepayAmount.Value; decimal t_PromotionValue = CurrentSO.BaseInfo.CouponAmount.Value; decimal t_GiftCardPay = CurrentSO.BaseInfo.GiftCardPay.Value; decimal?t_OriginShipPrice = CurrentSO.ShippingInfo.OriginShipPrice ?? 0; decimal?t_PackageFee = CurrentSO.ShippingInfo.PackageFee ?? 0; decimal?t_RegisteredFee = CurrentSO.ShippingInfo.RegisteredFee ?? 0; decimal?t_ShippingFee = CurrentSO.ShippingInfo.ShippingFee ?? 0; decimal?t_Weight3PL = CurrentSO.ShippingInfo.Weight3PL ?? 0; decimal?t_WeightSO = CurrentSO.ShippingInfo.Weight ?? 0; int subSOIndex = 0; foreach (SOInfo soInfo in subSOList) { bool isLastSubSO = ++subSOIndex == subSOList.Count; decimal subSOWeight = 0; //订单总重量 decimal subSOTotalPrice = 0; //订单去优惠券折扣后的总价 soInfo.BaseInfo.PromotionAmount = 0; soInfo.BaseInfo.GainPoint = 0; soInfo.BaseInfo.CouponAmount = 0; soInfo.Items.ForEach(item => { item.SOSysNo = soInfo.SysNo; soInfo.BaseInfo.PromotionAmount += item.PromotionAmount.Value; //计算销售规则拆扣 soInfo.BaseInfo.GainPoint += item.GainPoint; //计算获得的积分 soInfo.BaseInfo.CouponAmount += item.CouponAmount; //计算优惠券折扣 subSOWeight += item.Weight.Value * item.Quantity.Value; //价格引用Price,而不是OriginalPrice,因为总价中不包含优惠券折扣。 subSOTotalPrice += item.Quantity.Value * item.Price.Value + item.PromotionAmount.Value; }); soInfo.ShippingInfo.Weight = subSOWeight; #region 分摊订单费用 decimal weightRate = subSOWeight / (masterSOTotalWeight <= 0 ? 1 : masterSOTotalWeight); //重量分摊比例 decimal priceRate = subSOTotalPrice / (masterSOTotalPrice <= 0 ? 1 : masterSOTotalPrice); //金额分摊比例 if (!isLastSubSO) // 不是最后一个子订单 { //根据重量来分摊运费 soInfo.BaseInfo.ShipPrice = UtilityHelper.ToMoney(CurrentSO.BaseInfo.ShipPrice.Value * weightRate); t_ShipPrice -= soInfo.BaseInfo.ShipPrice.Value; //根据价格来分摊积分支付 soInfo.BaseInfo.PointPay = (int)(Math.Round(CurrentSO.BaseInfo.PointPay.Value * priceRate)); t_PointPay -= soInfo.BaseInfo.PointPay.Value; soInfo.BaseInfo.PointPayAmount = Convert.ToDecimal(soInfo.BaseInfo.PointPay) / ExternalDomainBroker.GetPointToMoneyRatio(); //计算积分支付 //根据价格来分摊手续费 soInfo.BaseInfo.PayPrice = UtilityHelper.ToMoney(CurrentSO.BaseInfo.PayPrice.Value * priceRate); t_PayPrice -= soInfo.BaseInfo.PayPrice.Value; //根据价格来分摊积保价费 soInfo.BaseInfo.PremiumAmount = UtilityHelper.ToMoney(CurrentSO.BaseInfo.PremiumAmount.Value * priceRate); t_PremiumAmt -= soInfo.BaseInfo.PremiumAmount.Value; //余额支付的分摊比例 decimal priceRate_Prepay = soInfo.BaseInfo.SOTotalAmount / (CurrentSO.BaseInfo.SOTotalAmount <= 0 ? 1 : CurrentSO.BaseInfo.SOTotalAmount); //根据商品总价分摊余额支付 soInfo.BaseInfo.PrepayAmount = UtilityHelper.ToMoney(CurrentSO.BaseInfo.PrepayAmount.Value * priceRate_Prepay);//分摊余额支付 t_PrepayAmt -= soInfo.BaseInfo.PrepayAmount.Value; //根据商品总价分摊礼品卡支付 soInfo.BaseInfo.GiftCardPay = UtilityHelper.ToMoney(CurrentSO.BaseInfo.GiftCardPay.Value * priceRate_Prepay);//分摊礼品支付 t_GiftCardPay -= soInfo.BaseInfo.GiftCardPay.Value; } else // 最后一个子订单 { soInfo.BaseInfo.ShipPrice = UtilityHelper.ToMoney(t_ShipPrice); soInfo.BaseInfo.PointPay = t_PointPay; soInfo.BaseInfo.PointPayAmount = Convert.ToDecimal(soInfo.BaseInfo.PointPay) / ExternalDomainBroker.GetPointToMoneyRatio(); //计算积分支付 soInfo.BaseInfo.PayPrice = UtilityHelper.ToMoney(t_PayPrice); soInfo.BaseInfo.PremiumAmount = UtilityHelper.ToMoney(t_PremiumAmt); //余额支付的分摊比例 decimal priceRate_Prepay = soInfo.BaseInfo.SOTotalAmount / (CurrentSO.BaseInfo.SOTotalAmount <= 0 ? 1 : CurrentSO.BaseInfo.SOTotalAmount); soInfo.BaseInfo.PrepayAmount = UtilityHelper.ToMoney(t_PrepayAmt); soInfo.BaseInfo.GiftCardPay = UtilityHelper.ToMoney(t_GiftCardPay); } if (CurrentSO.SOGiftCardList.Count > 0) { decimal itemGiftCardPay = soInfo.BaseInfo.GiftCardPay.Value; foreach (ECCentral.BizEntity.IM.GiftCardRedeemLog giftCard in CurrentSO.SOGiftCardList) { if (itemGiftCardPay <= 0) { break; } if (giftCard.Amount <= 0) { continue; } if (giftCard.Amount >= itemGiftCardPay) { giftCard.Amount -= itemGiftCardPay; soInfo.SOGiftCardList.Add(new ECCentral.BizEntity.IM.GiftCardRedeemLog { Code = giftCard.Code, Amount = itemGiftCardPay }); itemGiftCardPay = 0; break; } else { itemGiftCardPay -= giftCard.Amount.Value; soInfo.SOGiftCardList.Add(new ECCentral.BizEntity.IM.GiftCardRedeemLog { Code = giftCard.Code, Amount = giftCard.Amount }); giftCard.Amount = 0; } if (itemGiftCardPay == 0M) { break; } } } if (IsAutoSplit) { soInfo.BaseInfo.Status = SOStatus.WaitingOutStock;//拆分后子单为待出库状态 } else { soInfo.BaseInfo.Status = SOStatus.Origin;//拆分后子单为待审核状态 } //拆单后需要重新计算每个子单是否是大件 soInfo.BaseInfo.IsLarge = SOCommon.ValidateIsLarge(soInfo.ShippingInfo.Weight.Value); // 是否大件商品 if (!isLastSubSO) { soInfo.ShippingInfo.OriginShipPrice = UtilityHelper.ToMoney((CurrentSO.ShippingInfo.OriginShipPrice ?? 0) * weightRate); t_OriginShipPrice -= soInfo.ShippingInfo.OriginShipPrice; soInfo.ShippingInfo.PackageFee = UtilityHelper.ToMoney((CurrentSO.ShippingInfo.PackageFee ?? 0) * weightRate); t_PackageFee -= soInfo.ShippingInfo.PackageFee; soInfo.ShippingInfo.RegisteredFee = UtilityHelper.ToMoney((CurrentSO.ShippingInfo.RegisteredFee ?? 0) * weightRate); t_RegisteredFee -= soInfo.ShippingInfo.RegisteredFee; soInfo.ShippingInfo.ShippingFee = UtilityHelper.ToMoney((CurrentSO.ShippingInfo.ShippingFee ?? 0) * weightRate); t_ShippingFee -= soInfo.ShippingInfo.ShippingFee; soInfo.ShippingInfo.Weight3PL = (int)((CurrentSO.ShippingInfo.Weight3PL ?? 0) * weightRate); t_Weight3PL -= soInfo.ShippingInfo.Weight3PL; soInfo.ShippingInfo.Weight = (int)((CurrentSO.ShippingInfo.Weight ?? 0) * weightRate); t_WeightSO -= soInfo.ShippingInfo.Weight; } else { soInfo.ShippingInfo.OriginShipPrice = t_OriginShipPrice; soInfo.ShippingInfo.PackageFee = t_PackageFee; soInfo.ShippingInfo.RegisteredFee = t_RegisteredFee; soInfo.ShippingInfo.ShippingFee = t_ShippingFee; soInfo.ShippingInfo.Weight3PL = t_Weight3PL; soInfo.ShippingInfo.Weight = t_WeightSO; } #endregion AssignSubSOPromotion(soInfo); AssignSubSOInvoice(soInfo); if (SubSOAssign != null) { SubSOAssign(soInfo); } List <ItemGrossProfitInfo> gorsses = new List <ItemGrossProfitInfo>(); foreach (ItemGrossProfitInfo gross in CurrentSO.ItemGrossProfitList) { foreach (SOItemInfo item in soInfo.Items) { if (gross.ProductSysNo == item.ProductSysNo) { ItemGrossProfitInfo subgross = SerializationUtility.DeepClone(gross); subgross.SOSysNo = soInfo.SysNo.Value; soInfo.ItemGrossProfitList.Add(subgross); } } } } #endregion }
/// <summary> /// 计算现金支付,需要先计算总金额,Promotion,积分。 /// soInfo.SOMaster.CashPay /// </summary> /// <param name="soInfo"></param> public void CalcCashPay(SOInfo soInfo) { soInfo.BaseInfo.CouponAmount = UtilityHelper.ToMoney(soInfo.Items.Sum(item => item.CouponAmount)); soInfo.BaseInfo.PointPayAmount = UtilityHelper.ToMoney(Convert.ToDecimal(soInfo.BaseInfo.PointPay) / ExternalDomainBroker.GetPointToMoneyRatio()); }
/// <summary> /// 处理无效的团购订单 /// </summary> /// <returns></returns> public void ProcessorInvalidGroupBuySO(SOInfo soInfo) { if (soInfo == null || !soInfo.SysNo.HasValue) { return; } int soSysNo = soInfo.SysNo.Value; try { //获取所有Item List <SOItemInfo> items = (from item in soInfo.Items where item.ActivityType == SOProductActivityType.GroupBuy select item).ToList(); if (items == null || items.Count == 0) { return; } //如果含有未处理的团购商品就过 if (items.Exists(x => x.ReferenceSysNo.HasValue && x.ReferenceSysNo != 0 && !x.SettlementStatus.HasValue)) { return; } else if (items.Exists(x => x.SettlementStatus == SettlementStatus.Fail)) { //更新订单团购处理状态 SODA.UpdateGroupBuySOSettlementStatusBySOSysNo(soSysNo, SettlementStatus.Fail); } else if (items.Exists(x => x.SettlementStatus == SettlementStatus.PlanFail)) { //只含P,作废 if (!items.Exists(x => x.SettlementStatus != SettlementStatus.PlanFail)) { ECCentral.BizEntity.Invoice.NetPayInfo netPayInfo = ExternalDomainBroker.GetSOValidNetPay(soSysNo); if (netPayInfo != null) { //ExternalDomainBroker.AuditNetPay(netPayInfo.SysNo.Value); ExternalDomainBroker.AuditNetPay4GroupBuy(netPayInfo.SysNo.Value); ExternalDomainBroker.CreateAOForJob(soSysNo, BizEntity.Invoice.RefundPayType.PrepayRefund, ResourceHelper.Get("Res_SO_Job_GropBuySOAbandon"), null); } ObjectFactory <SOProcessor> .Instance.ProcessSO(new SOAction.SOCommandInfo { Command = SOAction.SOCommand.Abandon, SOInfo = soInfo }); } else { //更新订单团购处理状态 SODA.UpdateGroupBuySOSettlementStatusBySOSysNo(soSysNo, SettlementStatus.PlanFail); } } else if (!items.Exists(x => x.ReferenceSysNo.HasValue && x.ReferenceSysNo != 0 && x.SettlementStatus != SettlementStatus.Success)) { ECCentral.BizEntity.Invoice.NetPayInfo netPayInfo = ExternalDomainBroker.GetSOValidNetPay(soSysNo); //审核NetPay if (netPayInfo != null) { //ExternalDomainBroker.AuditNetPay(netPayInfo.SysNo.Value); ExternalDomainBroker.AuditNetPay4GroupBuy(netPayInfo.SysNo.Value); } SODA.UpdateGroupBuySOSettlementStatusBySOSysNo(soSysNo, SettlementStatus.Success); } } catch (Exception ex) { SODA.UpdateGroupBuySOSettlementStatusBySOSysNo(soSysNo, SettlementStatus.Fail); ExceptionHelper.HandleException(ex); } }
//改单 /// <summary> /// 改单 /// </summary> /// <param name="soSysNo">订单编号</param> public virtual void Update(int soSysNo) { var soProcessor = ObjectFactory <SOProcessor> .Instance; var soInfo = soProcessor.GetSOBySOSysNo(soSysNo); if (soInfo == null) { BizExceptionHelper.Throw("SO_SOIsNotExist"); } //是否货到付款 bool isPayWhenRecv = soProcessor.IsPayWhenReceived(soInfo.BaseInfo.PayTypeSysNo.Value); //查询订单出库记录 string outStock = m_da.GetOutStockString(soSysNo); //还没有出仓记录 if (string.IsNullOrEmpty(outStock)) { //直接作废 soProcessor.ProcessSO(new SOAction.SOCommandInfo { SOInfo = soInfo, Command = SOAction.SOCommand.Abandon }); return; } //获取出库收款信息 var invoiceMasterList = ExternalDomainBroker.GetSOInvoiceMaster(soSysNo); //计算总出库金额相关数据 //保价费 decimal premiumAmt = invoiceMasterList .Where(p => p.PremiumAmt.HasValue) .Sum(p => p.PremiumAmt.Value); //运费 decimal shippingCharge = invoiceMasterList .Where(p => p.ShippingCharge.HasValue) .Sum(p => p.ShippingCharge.Value); //附加费 decimal extraAmt = invoiceMasterList .Where(p => p.ExtraAmt.HasValue) .Sum(p => p.ExtraAmt.Value); //折扣金额 decimal discountAmt = invoiceMasterList .Where(p => p.DiscountAmt.HasValue) .Sum(p => p.DiscountAmt.Value); //优惠卷抵扣 decimal promotionAmt = invoiceMasterList .Where(p => p.PromotionAmt.HasValue) .Sum(p => p.PromotionAmt.Value); //获得积分? int pointAmt = invoiceMasterList .Where(p => p.GainPoint.HasValue) .Sum(p => p.GainPoint.Value); //出库发票额 decimal sumExtendPrice = invoiceMasterList .Where(p => p.InvoiceAmt.HasValue) .Sum(p => p.InvoiceAmt.Value); //礼品卡支付总额 decimal sumGiftCardPay = invoiceMasterList .Where(p => p.GiftCardPayAmt.HasValue) .Sum(p => p.GiftCardPayAmt.Value); //积分支付总额 decimal pointPay = invoiceMasterList .Where(p => p.PointPaid.HasValue) .Sum(p => p.PointPaid.Value); //计算多余额应退金额 decimal returnAmt = GetReturnAmt(soSysNo, sumExtendPrice, soInfo.BaseInfo.GiftCardPay.Value); //计算应退积分 int returnPoint = GetReturnPoint(soInfo, pointPay); //已预付款 decimal prePayAmount = invoiceMasterList .Where(p => p.PrepayAmt.HasValue) .Sum(p => p.PrepayAmt.Value); //预退款总额 decimal preReturnAmount = soInfo.BaseInfo.PrepayAmount.Value + prePayAmount; TransactionOptions options = new TransactionOptions(); options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted; options.Timeout = TransactionManager.DefaultTimeout; using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options)) { //删除未出库分仓的所有Item DeleteOrderItem4UpdatePending(soInfo.Items, soInfo.SysNo.Value, outStock); #region 更新so单据信息 //更新so单据信息 //删除后的SOInfo需要重新读取 //注意这里虽然事务没有提交,但是可以读取脏数据的方法获取 soInfo = soProcessor.GetSOBySOSysNo(soSysNo); soInfo.BaseInfo.PremiumAmount = premiumAmt; soInfo.BaseInfo.ShipPrice = shippingCharge; soInfo.BaseInfo.PayPrice = extraAmt; soInfo.BaseInfo.PointPay = 0; soInfo.BaseInfo.PromotionAmount = discountAmt; soInfo.BaseInfo.CouponAmount = promotionAmt; soInfo.BaseInfo.GainPoint = pointAmt; soInfo.BaseInfo.SOAmount = 0.0M; soInfo.Items.ForEach(x => { if (x.ProductType.HasValue && x.ProductType.Value != SOProductType.Coupon) { soInfo.BaseInfo.SOAmount += x.OriginalPrice * x.Quantity; } }); //现金支付为只读 //soInfo.BaseInfo.CashPay = soInfo.SOMaster.SOAmt + soInfo.SOMaster.PromotionValue + soMP.PointPay; soInfo.BaseInfo.PointPay = Convert.ToInt32(-1 * pointPay * ExternalDomainBroker.GetPointToMoneyRatio()); if (prePayAmount < 0.0M) { soInfo.BaseInfo.PrepayAmount = (-1) * prePayAmount; } soInfo.BaseInfo.GiftCardPay = (-1) * sumGiftCardPay; soProcessor.ProcessSO(new SOAction.SOCommandInfo { Command = SOAction.SOCommand.Update, SOInfo = soInfo }); #endregion 更新so单据信息 //更新改单状态 m_da.UpdateSOPendingStatus(soSysNo, SOPendingStatus.ChangeOrder); #warning 需要重构 重新计算是否并单 //重新计算是否并单 ObjectFactory <ISODA> .Instance.UpdateSOCombineInfo(soInfo.BaseInfo.SysNo.Value); //金额拆分 SOPriceSpliter priceSpliter = ObjectFactory <SOPriceSpliter> .Instance; priceSpliter.CurrentSO = soInfo; priceSpliter.SplitSO(); //重发消息 Resend_ShippingMessage(soSysNo); #region 调整积分 var pointAdjustReq = new ECCentral.BizEntity.Customer.AdjustPointRequest(); pointAdjustReq.CustomerSysNo = soInfo.BaseInfo.CustomerSysNo; pointAdjustReq.OperationType = ECCentral.BizEntity.Customer.AdjustPointOperationType.Abandon; pointAdjustReq.Point = returnPoint; pointAdjustReq.SOSysNo = soInfo.SysNo; pointAdjustReq.Source = "OrderMgmt"; pointAdjustReq.PointType = (int)ECCentral.BizEntity.Customer.AdjustPointType.UpdateSO; pointAdjustReq.Memo = ResourceHelper.Get("SO_Pending_ReturnPointMemo"); ExternalDomainBroker.AdjustPoint(pointAdjustReq); #endregion 调整积分 #region 退款(退余额) if (isPayWhenRecv) { //支持货到付款的改单 if (preReturnAmount > 0.0M) //(prepayAmt > sumExtendPrice) //预付款大于已出库总金额,要将多余的钱退回客户 { var customerPrepayReq = new CustomerPrepayLog(); customerPrepayReq.CustomerSysNo = soInfo.BaseInfo.CustomerSysNo; customerPrepayReq.SOSysNo = soInfo.SysNo; customerPrepayReq.AdjustAmount = preReturnAmount; customerPrepayReq.PrepayType = PrepayType.RemitReturn; customerPrepayReq.Note = ResourceHelper.Get("SO_Pending_PreReturnMemo", preReturnAmount); ExternalDomainBroker.AdjustPrePay(customerPrepayReq); } } else {//生成对应的多付款退款记录(invoiceservice)更新财务收款单中的OrderAmt金额(invoiceservice) if (returnAmt > 0) { //查询收款单 var incomeOrg = ExternalDomainBroker.GetValidSOIncomeInfo(soSysNo, SOIncomeOrderType.SO); if (incomeOrg == null) { BizExceptionHelper.Throw("SO_Income_Unknow", soSysNo.ToString()); } //修改原始的订单金额 incomeOrg.OrderAmt = incomeOrg.OrderAmt - returnAmt; ExternalDomainBroker.UpdateSOIncomeOrderAmount(incomeOrg.SysNo.Value, incomeOrg.OrderAmt.Value); //更新 //创建付款收支单 var income = new SOIncomeInfo { OrderSysNo = soInfo.SysNo , OrderAmt = -returnAmt , IncomeAmt = -returnAmt , OrderType = SOIncomeOrderType.OverPayment , Note = ResourceHelper.Get("SO_Pending_ReturnMemo") , Status = SOIncomeStatus.Origin , IncomeStyle = SOIncomeOrderStyle.Advanced , CompanyCode = soInfo.CompanyCode }; ExternalDomainBroker.CreateSOIncome(income); //创建银行收支单 SOIncomeRefundInfo refundInfo = new SOIncomeRefundInfo { SOSysNo = soInfo.SysNo , OrderSysNo = soInfo.SysNo , OrderType = RefundOrderType.OverPayment , RefundPayType = RefundPayType.PrepayRefund , RefundReason = 5 , Status = RefundStatus.Origin , Note = ResourceHelper.Get("SO_Pending_ReturnMemo") , RefundCashAmt = returnAmt , RefundPoint = 0 , ToleranceAmt = 0 , CompanyCode = soInfo.CompanyCode }; ExternalDomainBroker.CreateSOIncomeRefundInfo(refundInfo); } } #endregion 退款(退余额) #region 退礼品卡 //退礼品卡 if (sumGiftCardPay < 0.0M) { if (soInfo.SOGiftCardList != null) { List <GiftCard> reqList = new List <GiftCard>(); decimal needToPayAmt = sumGiftCardPay * (-1); for (int i = 0; i < soInfo.SOGiftCardList.Count; i++) { if (needToPayAmt <= 0) { soInfo.SOGiftCardList.RemoveAt(i); i--; continue; } soInfo.SOGiftCardList[i].AvailAmount = soInfo.SOGiftCardList[i].Amount.HasValue ? soInfo.SOGiftCardList[i].Amount.Value : 0; if (soInfo.SOGiftCardList[i].AvailAmount >= needToPayAmt) { soInfo.SOGiftCardList[i].Amount = needToPayAmt; soInfo.SOGiftCardList[i].AvailAmount -= needToPayAmt; needToPayAmt = 0; } else { soInfo.SOGiftCardList[i].Amount = soInfo.SOGiftCardList[i].AvailAmount; soInfo.SOGiftCardList[i].AvailAmount = 0; needToPayAmt -= soInfo.SOGiftCardList[i].Amount.Value; } reqList.Add(new GiftCard { Code = soInfo.SOGiftCardList[i].Code, ReferenceSOSysNo = soSysNo, CustomerSysNo = soInfo.SOGiftCardList[i].CustomerSysNo.Value, ConsumeAmount = soInfo.SOGiftCardList[i].Amount.Value }); } ExternalDomainBroker.GiftCardDeduction(reqList, soInfo.CompanyCode); } } #endregion 退礼品卡 scope.Complete(); } ExternalDomainBroker.WriteBizLog(ResourceHelper.Get("SO_Pending_UpdateLogFormat", soSysNo) , BizLogType.Sale_SO_Update , soSysNo , soInfo.CompanyCode); }
/// <summary> /// 创建财务负收款并作废订单 /// </summary> /// <param name="refundInfo"></param> /// <returns></returns> public void CreateAOAndAbandonSO(SOIncomeRefundInfo refundInfo) { IsOutStockOrder = false; if (CurrentSO.BaseInfo.Status == SOStatus.CustomsPass) { IsOutStockOrder = true; } if (CurrentSO.BaseInfo.Status != SOStatus.Origin && CurrentSO.BaseInfo.Status != SOStatus.WaitingOutStock //&& CurrentSO.BaseInfo.Status != SOStatus.OutStock ) { BizExceptionHelper.Throw("SO_CreateAO_SOStatusIsError"); } if (CurrentSOIncome == null) { BizExceptionHelper.Throw("SO_CreateAO_SOIncomeIsNull"); } SOIncomeInfo soIncomeInfo = new SOIncomeInfo { OrderAmt = -CurrentSOIncome.OrderAmt, OrderType = SOIncomeOrderType.AO, Note = ResourceHelper.Get("Res_SO_Abandon_CreateAO"), ReferenceID = "", Status = SOIncomeStatus.Origin, OrderSysNo = CurrentSO.SysNo, IncomeAmt = -(CurrentSOIncome.OrderAmt - CurrentSOIncome.PrepayAmt - CurrentSOIncome.GiftCardPayAmt), PayAmount = -(CurrentSOIncome.OrderAmt - CurrentSOIncome.PrepayAmt - CurrentSOIncome.GiftCardPayAmt), IncomeStyle = CurrentSOIncome.IncomeStyle, PrepayAmt = -CurrentSOIncome.PrepayAmt, GiftCardPayAmt = -CurrentSOIncome.GiftCardPayAmt, PointPay = -CurrentSOIncome.PointPay, CompanyCode = CurrentSO.CompanyCode }; SOIncomeRefundInfo soIncomeRefundInfo = new SOIncomeRefundInfo { OrderSysNo = refundInfo.SOSysNo, OrderType = RefundOrderType.AO, SOSysNo = refundInfo.SOSysNo, RefundPayType = refundInfo.RefundPayType, BankName = refundInfo.BankName, BranchBankName = refundInfo.BranchBankName, CardNumber = refundInfo.CardNumber, CardOwnerName = refundInfo.CardOwnerName, PostAddress = refundInfo.PostAddress, PostCode = refundInfo.PostCode, ReceiverName = refundInfo.ReceiverName, Note = refundInfo.Note, HaveAutoRMA = false, RefundPoint = 0, RefundReason = refundInfo.RefundReason, CompanyCode = CurrentSO.CompanyCode }; if (refundInfo.RefundPayType == RefundPayType.CashRefund) { soIncomeRefundInfo.Status = RefundStatus.Audit; } else { soIncomeRefundInfo.Status = RefundStatus.Origin; } if (refundInfo.RefundPayType == RefundPayType.TransferPointRefund) { soIncomeInfo.IncomeAmt = 0; soIncomeRefundInfo.RefundCashAmt = 0; soIncomeRefundInfo.RefundPoint = Convert.ToInt32(Decimal.Round(CurrentSO.BaseInfo.SOAmount.Value * ExternalDomainBroker.GetPointToMoneyRatio(), 0)); soIncomeRefundInfo.RefundGiftCard = CurrentSOIncome.GiftCardPayAmt; } else { soIncomeRefundInfo.RefundCashAmt = CurrentSOIncome.OrderAmt - CurrentSOIncome.GiftCardPayAmt; soIncomeRefundInfo.RefundGiftCard = CurrentSOIncome.GiftCardPayAmt; } ValidateAbandonSO(false); bool isHold = CurrentSO.BaseInfo.HoldStatus == SOHoldStatus.BackHold; if (IsOutStockOrder) { isHold = true; } //如果后台锁定 if (!isHold) { isHold = Holder.Hold(SOHolder.SOHoldReason.AbandonOrder, OPCCallBackType.AOAbandonCallBack); if (!isHold) { BizExceptionHelper.Throw("SO_Abandon_HoldIsAsyn"); } } if (isHold) //如果订单已经锁定 { CreateAOAndAbandonSO(soIncomeInfo, soIncomeRefundInfo); if (IsOutStockOrder) { SODA.UpdateSOStatusToReportedFailure(CurrentSO.SysNo.Value); CurrentSO.BaseInfo.Status = SOStatus.Reject; } SendMessage(); } }
/// <summary> /// 发送订单拦截邮件 /// </summary> /// <param name="info"></param> public virtual void SendSOOrderInterceptEmail(SOInfo info, string Language) { KeyValueVariables keyValueVariables = new KeyValueVariables(); keyValueVariables.Add("SOSysNo", info.BaseInfo.SysNo.Value); keyValueVariables.Add("CustomerSysNo", info.BaseInfo.CustomerSysNo); keyValueVariables.Add("OrderDate", info.BaseInfo.CreateTime); SOStatusChangeInfo statusAuditInfo = info.StatusChangeInfoList.Find(x => { return(x.Status == SOStatus.WaitingOutStock); }); if (statusAuditInfo == null) { keyValueVariables.Add("AuditTime", DBNull.Value); } else { keyValueVariables.Add("AuditTime", statusAuditInfo.ChangeTime.Value.ToString()); } SOStatusChangeInfo statusOutStockInfo = info.StatusChangeInfoList.Find(x => { return(x.Status == SOStatus.OutStock); }); if (statusOutStockInfo == null) { keyValueVariables.Add("OutStockTime", DBNull.Value); } else { keyValueVariables.Add("OutStockTime", statusOutStockInfo.ChangeTime.Value.ToString()); } keyValueVariables.Add("SOTotalAmount", info.BaseInfo.SOTotalAmount); keyValueVariables.Add("PayType", info.BaseInfo.PayTypeSysNo); keyValueVariables.Add("UserSysNo", ServiceContext.Current.UserSysNo); List <string> emailList = new List <string>(); List <string> emailCCList = new List <string>(); if (info.SOInterceptInfoList != null && info.SOInterceptInfoList.Count == 1) { foreach (var item in info.SOInterceptInfoList) { if (!string.IsNullOrEmpty(item.EmailAddress)) { emailList.Add(item.EmailAddress); } if (!string.IsNullOrEmpty(item.CCEmailAddress)) { emailCCList.Add(item.CCEmailAddress); } } } else if (info.SOInterceptInfoList != null && info.SOInterceptInfoList.Count == 2) { if (info.SOInterceptInfoList[0].EmailAddress != info.SOInterceptInfoList[1].EmailAddress || info.SOInterceptInfoList[0].CCEmailAddress != info.SOInterceptInfoList[1].CCEmailAddress) { emailList.Add(info.SOInterceptInfoList[1].EmailAddress); emailCCList.Add(info.SOInterceptInfoList[1].CCEmailAddress); } } else if (info.SOInterceptInfoList != null && info.SOInterceptInfoList.Count > 2) { if (info.SOInterceptInfoList[0].EmailAddress != info.SOInterceptInfoList[info.SOInterceptInfoList.Count - 1].EmailAddress || info.SOInterceptInfoList[0].CCEmailAddress != info.SOInterceptInfoList[info.SOInterceptInfoList.Count - 1].CCEmailAddress) { emailList.Add(info.SOInterceptInfoList[info.SOInterceptInfoList.Count - 1].EmailAddress); emailCCList.Add(info.SOInterceptInfoList[info.SOInterceptInfoList.Count - 1].CCEmailAddress); } else { foreach (var item in info.SOInterceptInfoList) { emailList.Add(item.EmailAddress); emailCCList.Add(item.CCEmailAddress); } } } if (emailList != null && emailList.Count > 0) { ExternalDomainBroker.SendInternalEmail(emailList.Join(";"), emailCCList.Join(";"), "SO_OrderIntercept", keyValueVariables, Language); } }
/// <summary> /// 是否是无效配送时间点 /// </summary> /// <param name="so">订单</param> /// <param name="timestring">时间区域字符串的集合</param> /// <param name="holidays">所有假期,如果传值为null,将在程序中重新读取</param> /// <returns>无效返回真,否则返回假</returns> internal static bool IsInValidDeliveryTime(SOInfo so, string timestring, List <Holiday> holidays, bool isForceAudit) { bool isInvalid = false; //强制审核不用效验 if (isForceAudit) { return(isInvalid); } //未有配送时间无需判断 if (!so.ShippingInfo.DeliveryDate.HasValue) { return(isInvalid); } //订单类型团购不用判断 if (so.BaseInfo.SOType == SOType.GroupBuy) { return(isInvalid); } //配送信息 var shipType = ExternalDomainBroker.GetShippingTypeBySysNo(so.ShippingInfo.ShipTypeSysNo.Value); //配送类型是0,3的不检查 //只检查1和2 if (shipType.DeliveryType != ShipDeliveryType.OneDayOnce && shipType.DeliveryType != ShipDeliveryType.OneDayTwice) { return(isInvalid); } //节假日 List <Holiday> shipHolidays = null; if (holidays == null) { shipHolidays = ExternalDomainBroker.GetHolidayAfterToday(so.CompanyCode) .FindAll(x => x.ShipTypeSysNo == shipType.SysNo || !x.ShipTypeSysNo.HasValue); } else { shipHolidays = holidays.FindAll(x => x.ShipTypeSysNo == shipType.SysNo || !x.ShipTypeSysNo.HasValue); } //时间节点 List <TimeSpan> timepoints = null; if (string.IsNullOrEmpty(timestring)) { timepoints = GetDeliveryTimePointBySO(so); } else { timepoints = ParseTimeSpot(timestring); } if (timepoints.Count == 0) { return(isInvalid); } //计算器 DeliveryIteration calculator = new DeliveryIteration(DateTime.Now, (int)shipType.DeliveryType, shipHolidays, timepoints, shipType.IntervalDays ?? 0, null); calculator.Roll(); DateTime latestDate = calculator.LatestDate; int finalSection = calculator.FinalSection; //比较 if (so.ShippingInfo.DeliveryDate < latestDate) { isInvalid = true; } else if (so.ShippingInfo.DeliveryDate == latestDate) { if (so.ShippingInfo.DeliveryTimeRange < finalSection) { isInvalid = true; } } return(isInvalid); }
public virtual void Split() { SubSOList = new List <SOInfo>(); // 1. 效验是否满足基本拆分条件 Precheck(); //拆当前订单 SplitCurrentSO(); // 子订单分摊计算 CalculateSubSO(SubSOList); #region 保存订单信息到数据库 // 保存订单信息到数据库 TransactionOptions options = new TransactionOptions(); options.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted; using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options)) { #region 保存主订单信息 SOStatusChangeInfo statusChangeInfo = new SOStatusChangeInfo { ChangeTime = DateTime.Now, OldStatus = CurrentSO.BaseInfo.Status.Value, OperatorSysNo = ServiceContext.Current.UserSysNo, OperatorType = SOOperatorType.User, Status = SOStatus.Split, SOSysNo = CurrentSO.SysNo }; //更新主单状态 if (!SODA.UpdateSOStatusToSplit(statusChangeInfo)) { BizExceptionHelper.Throw("SO_Split_SOStatus_NotOriginal"); } //更新主单标记为已拆分 CurrentSO.BaseInfo.Status = SOStatus.Split; #endregion //插入子单数据到数据库 foreach (SOInfo subSOInfo in SubSOList) { SaveSubSO(subSOInfo); } #region 调整订单相关日志 //调整礼品卡使用日志 List <SOBaseInfo> subSOBaseInfoList = SubSOList.Select <SOInfo, SOBaseInfo>(subSOInfo => subSOInfo.BaseInfo).ToList(); if (CurrentSO.SOGiftCardList.Count > 0) { Dictionary <int, List <ECCentral.BizEntity.IM.GiftCardRedeemLog> > subSOGiftCardDictionary = new Dictionary <int, List <ECCentral.BizEntity.IM.GiftCardRedeemLog> >(); SubSOList.ForEach(subSOInfo => { subSOGiftCardDictionary.Add(subSOInfo.SysNo.Value, subSOInfo.SOGiftCardList); }); ExternalDomainBroker.SplitSOGiftCard(CurrentSO.BaseInfo, subSOGiftCardDictionary); } //调整积分 //调整余额支付 //作废主单积分日志 if (CurrentSO.BaseInfo.PointPay > 0) { ExternalDomainBroker.SplitSOPoint(CurrentSO.BaseInfo, subSOBaseInfoList); } //作废主单余额日志 if (CurrentSO.BaseInfo.PrepayAmount > 0) { ExternalDomainBroker.AdjustPrePay(new BizEntity.Customer.CustomerPrepayLog { AdjustAmount = CurrentSO.BaseInfo.PrepayAmount, PrepayType = ECCentral.BizEntity.Customer.PrepayType.SOPay, SOSysNo = SOSysNo, Note = "拆分订单,作废主订单余额支付", CustomerSysNo = CurrentSO.BaseInfo.CustomerSysNo }); SubSOList.ForEach(subSOInfo => { if (subSOInfo.BaseInfo.PrepayAmount.Value != 0M) { ExternalDomainBroker.AdjustPrePay(new BizEntity.Customer.CustomerPrepayLog { AdjustAmount = -subSOInfo.BaseInfo.PrepayAmount, PrepayType = ECCentral.BizEntity.Customer.PrepayType.SOPay, SOSysNo = SOSysNo, Note = "拆分订单,子订单使用余额支付", CustomerSysNo = subSOInfo.BaseInfo.CustomerSysNo }); } }); } //如果是款到发货订单,拆分NetPay if (!CurrentSO.BaseInfo.PayWhenReceived.Value) { ExternalDomainBroker.SplitSOIncome(CurrentSO.BaseInfo, subSOBaseInfoList); } #endregion scope.Complete(); } #endregion //给客户发拆分邮件 ObjectFactory <SOSendMessageProcessor> .Instance.SendSplitSOEmail(CurrentSO, SubSOList); if (IsAutoSplit) { foreach (SOInfo subSO in SubSOList) { SOAction soAction = SOActionFactory.Create(new SOCommandInfo { Command = SOCommand.Audit, SOInfo = subSO }); if (soAction is SOAudit) { (soAction as SOAudit).SendMessage(); } } } //记录增票更改日志记录 if (CurrentSO.InvoiceInfo.IsVAT.Value) { WriteSOChangeVATLog(SubSOList); } //记日志 WriteLog(); }
internal static void CreateInvoice(SOInfo soInfo) { int soSysNo = soInfo.SysNo.Value; List <SOPriceMasterInfo> soPriceList = ObjectFactory <ISOPriceDA> .Instance.GetSOPriceBySOSysNo(soSysNo); if (soPriceList != null) { soPriceList.RemoveAll(priceInfo => { return(priceInfo.Status == SOPriceStatus.Deactivate); }); } if (soPriceList == null || soPriceList.Count < 1) { ObjectFactory <SOSendMessageProcessor> .Instance.ElectronicSOPriceNotExists(soInfo); BizExceptionHelper.Throw("SO_CreateInvoice_PriceInfoIsNull"); } List <ECCentral.BizEntity.Invoice.InvoiceMasterInfo> invoiceList = ExternalDomainBroker.GetSOInvoiceMaster(soSysNo); if (invoiceList == null || invoiceList.Count < 1) { SOItemInfo couponItem = soInfo.Items.Find(item => item.ProductType == SOProductType.Coupon); int? couponCodeSysNo = couponItem == null ? null : couponItem.ProductSysNo; SOPriceMasterInfo priceInfo = soPriceList[0]; BizEntity.Invoice.InvoiceInfo invoiceInfo = new BizEntity.Invoice.InvoiceInfo(); invoiceInfo.InvoiceTransactionInfoList = new List <BizEntity.Invoice.InvoiceTransactionInfo>(); invoiceInfo.MasterInfo = new BizEntity.Invoice.InvoiceMasterInfo { CustomerID = soInfo.BaseInfo.CustomerID, CustomerSysNo = soInfo.BaseInfo.CustomerSysNo, SONumber = soSysNo, InvoiceDate = priceInfo.InDate, InvoiceAmt = priceInfo.InvoiceAmount, PayTypeSysNo = soInfo.BaseInfo.PayTypeSysNo, PayTypeName = "", RMANumber = 0, OriginalInvoiceNumber = 0, InvoiceMemo = null, ShippingCharge = priceInfo.ShipPrice, StockSysNo = priceInfo.StockSysNo, OrderDate = soInfo.BaseInfo.CreateTime, DeliveryDate = soInfo.ShippingInfo.DeliveryDate, SalesManSysNo = soInfo.BaseInfo.SalesManSysNo, IsWholeSale = soInfo.BaseInfo.IsWholeSale, IsPremium = soInfo.BaseInfo.IsPremium, PremiumAmt = priceInfo.PremiumAmount, ShipTypeSysNo = soInfo.ShippingInfo.ShipTypeSysNo, ExtraAmt = priceInfo.PayPrice, SOAmt = priceInfo.SOAmount, DiscountAmt = priceInfo.PromotionAmount, GainPoint = priceInfo.GainPoint, PointPaid = -priceInfo.PointPayAmount, PrepayAmt = -priceInfo.PrepayAmount, PromotionAmt = priceInfo.CouponAmount, ReceiveAreaSysNo = soInfo.ReceiverInfo.AreaSysNo, ReceiveContact = soInfo.ReceiverInfo.Name, ReceiveAddress = soInfo.ReceiverInfo.Address, ReceiveCellPhone = soInfo.ReceiverInfo.MobilePhone, ReceivePhone = soInfo.ReceiverInfo.Phone, ReceiveZip = soInfo.ReceiverInfo.Zip, ReceiveName = soInfo.InvoiceInfo.Header, GiftCardPayAmt = -priceInfo.GiftCardPay, InvoiceNo = null, InvoiceType = soInfo.InvoiceInfo.InvoiceType, MerchantSysNo = soInfo.Merchant.SysNo, CompanyCode = soInfo.CompanyCode, PromotionCustomerSysNo = soInfo.BaseInfo.CustomerSysNo, PromotionCodeSysNo = couponCodeSysNo, IsUseChequesPay = false,//soInfo.BaseInfo.IsUseChequesPay, CashPaid = priceInfo.CashPay, }; priceInfo.Items.ForEach(item => { SOItemInfo soItem = soInfo.Items.Find(i => { return(i.ProductSysNo == item.ProductSysNo && i.ProductType == item.ProductType); }); string itemCode = soItem == null ? String.Empty : soItem.ProductID; switch (item.ProductType.Value) { case SOProductType.Coupon: itemCode = String.Format("Promot-{0}", item.ProductSysNo); break; case SOProductType.ExtendWarranty: itemCode = String.Format("{0}E", itemCode); break; } invoiceInfo.InvoiceTransactionInfoList.Add(new BizEntity.Invoice.InvoiceTransactionInfo { ItemCode = itemCode, PrintDescription = item.ProductType.Value.ToEnumDesc(), ItemType = item.ProductType, UnitPrice = item.Price, Quantity = item.Quantity, ExtendPrice = item.Price * item.Quantity, ReferenceSONumber = soSysNo, Weight = soItem.Weight, GainPoint = soItem.GainAveragePoint, PayType = soItem.PayType, PremiumAmt = item.PremiumAmount, ShippingCharge = item.ShipPrice, ExtraAmt = item.PayPrice, CashPaid = item.CashPay, PointPaid = item.PointPayAmount, DiscountAmt = item.PromotionAmount, PrepayAmt = -item.PrepayAmount, Warranty = soItem.Warranty, BriefName = soItem.ProductName, OriginalPrice = soItem.OriginalPrice, PromotionDiscount = item.CouponAmount, MasterProductSysNo = soItem.MasterProductSysNo, UnitCost = soItem.CostPrice, CompanyCode = soInfo.CompanyCode, GiftCardPayAmt = -item.GiftCardPay, UnitCostWithoutTax = soItem.NoTaxCostPrice, ProductSysNo = soItem.ProductSysNo, PriceType = soItem.PriceType, ItemDescription = item.ProductType.Value.ToEnumDesc(), }); }); ExternalDomainBroker.CreateInvoice(invoiceInfo); } }
/// <summary> /// 恢复主单为待审核状态,并作废所有子单 /// </summary> /// <param name="soSysNo">子单系统编号</param> /// <param name="companyCode"></param> /// <returns></returns> public void RestoreSOMaster() { SOInfo masterSO = CurrentSO; //查询所有子单 List <SOInfo> subSOList = ObjectFactory <SOProcessor> .Instance.GetSubSOByMasterSOSysNo(CurrentSO.SysNo.Value); if (subSOList == null && subSOList.Count == 0) { BizExceptionHelper.Throw("SO_CancelSplit_NotExistSubSO"); return; } //检查主单和子单的状态 foreach (SOInfo subSO in subSOList) { if (subSO.BaseInfo.Status == SOStatus.Abandon || subSO.BaseInfo.Status == SOStatus.OutStock || subSO.BaseInfo.Status == SOStatus.Split) { BizExceptionHelper.Throw("SO_CancelSplit_SubIsOutStock"); } } if (masterSO.BaseInfo.Status != SOStatus.Split) { BizExceptionHelper.Throw("SO_CancelSplit_MasterSOStatusIsChanged"); } List <SOBaseInfo> subSOBaseInfoList = subSOList.Select <SOInfo, SOBaseInfo>(subSOInfo => subSOInfo.BaseInfo).ToList(); TransactionOptions options = new TransactionOptions(); options.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted; using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options)) { //重新创建主单积分日志 if (masterSO.BaseInfo.PointPay > 0) { ExternalDomainBroker.CancelSplitSOPoint(masterSO.BaseInfo, subSOBaseInfoList); } if (masterSO.BaseInfo.PrepayAmount > 0) { ExternalDomainBroker.AdjustPrePay(new BizEntity.Customer.CustomerPrepayLog { AdjustAmount = -CurrentSO.BaseInfo.PrepayAmount, PrepayType = ECCentral.BizEntity.Customer.PrepayType.SOPay, SOSysNo = SOSysNo, Note = "Res_SO_CancelSplit_MasterSOPrePay", CustomerSysNo = CurrentSO.BaseInfo.CustomerSysNo }); subSOList.ForEach(subSOInfo => { if (subSOInfo.BaseInfo.PrepayAmount.Value != 0M) { ExternalDomainBroker.AdjustPrePay(new BizEntity.Customer.CustomerPrepayLog { AdjustAmount = subSOInfo.BaseInfo.PrepayAmount, PrepayType = ECCentral.BizEntity.Customer.PrepayType.SOPay, SOSysNo = SOSysNo, Note = "Res_SO_CancelSplit_AbandonSubSOPrePay", CustomerSysNo = subSOInfo.BaseInfo.CustomerSysNo }); } }); } if (masterSO.BaseInfo.GiftCardPay > 0) { Dictionary <int, List <ECCentral.BizEntity.IM.GiftCardRedeemLog> > subSOGiftCardDictionary = new Dictionary <int, List <ECCentral.BizEntity.IM.GiftCardRedeemLog> >(); subSOList.ForEach(subSOInfo => { subSOGiftCardDictionary.Add(subSOInfo.SysNo.Value, subSOInfo.SOGiftCardList); }); ExternalDomainBroker.CancelSplitSOGiftCard(masterSO.BaseInfo, subSOGiftCardDictionary); } //款到发货订单,恢复主单NetPay记录 if (!masterSO.BaseInfo.PayWhenReceived.Value) { ExternalDomainBroker.CancelSplitSOIncome(masterSO.BaseInfo, subSOBaseInfoList); } SODA.UpdateSOStatus(new SOStatusChangeInfo { ChangeTime = DateTime.Now, OldStatus = masterSO.BaseInfo.Status, Status = SOStatus.Origin, OperatorType = ServiceContext.Current.UserSysNo == 0 ? SOOperatorType.System : SOOperatorType.User, OperatorSysNo = ServiceContext.Current.UserSysNo, SOSysNo = CurrentSO.SysNo }); masterSO.BaseInfo.Status = SOStatus.Origin; foreach (SOInfo subSO in subSOList) { SODA.UpdateSOStatus(new SOStatusChangeInfo { ChangeTime = DateTime.Now, OldStatus = subSO.BaseInfo.Status, Status = SOStatus.Abandon, OperatorType = ServiceContext.Current.UserSysNo == 0 ? SOOperatorType.System : SOOperatorType.User, OperatorSysNo = ServiceContext.Current.UserSysNo, SOSysNo = subSO.SysNo }); } scope.Complete(); } SendMsgToWMS(subSOList); }
/// <summary> /// 如果是新客户的第一张订单,为推荐人增加经验值 /// </summary> /// <param name="soInfo">订单</param> /// <param name="customerInfo">订单客户</param> public void AddExperienceByRecommend(SOInfo soInfo) { SOBaseInfo soBaseInfo = soInfo.BaseInfo; ECCentral.BizEntity.Customer.CustomerBasicInfo customerInfo = ExternalDomainBroker.GetCustomerInfo(soBaseInfo.CustomerSysNo.Value).BasicInfo; string companyCode = soInfo.CompanyCode; // 对象为空 if (customerInfo == null || soInfo == null) { return; } // 该客户没有推荐人 if (!customerInfo.RecommendedByCustomerSysNo.HasValue || customerInfo.RecommendedByCustomerSysNo.Value == 0) { return; } // 判断订单是否是该客户的第一张成功出库的订单 if (!SODA.IsFirstSO(soInfo.SysNo.Value, soBaseInfo.CustomerSysNo.Value)) { return; } // 获取推荐人信息 ECCentral.BizEntity.Customer.CustomerBasicInfo rmdCustomerInfo = ExternalDomainBroker.GetCustomerInfo(customerInfo.RecommendedByCustomerSysNo.Value).BasicInfo; // 没有相应的推荐人信息 if (rmdCustomerInfo == null) { return; } // 推荐人不能是客户自己 if (customerInfo.CustomerSysNo == rmdCustomerInfo.CustomerSysNo) { return; } // 如果推荐人被禁用,不对其增加经验值 if (rmdCustomerInfo.Status.Value == BizEntity.Customer.CustomerStatus.InValid) { return; } // 订单金额 decimal soAmount = soBaseInfo.CashPay + soBaseInfo.PayPrice.Value + soBaseInfo.ShipPrice.Value + soBaseInfo.PremiumAmount.Value + soBaseInfo.PromotionAmount.Value; // 推荐人经验值的增加数量为订单金额的10% decimal rate = AppSettingHelper.RecommendExperienceRatio; decimal addExperience = decimal.Round(soAmount * rate, 0); // 应该增加的经验值,4舍5入到整数 // 如果增加值<1, if (addExperience > 0) { string logMemo = string.Format("SO#{0}:引荐新用户,首次购物成功,加经验值。", soInfo.SysNo); ExternalDomainBroker.AdjustCustomerExperience(rmdCustomerInfo.CustomerSysNo.Value, addExperience, BizEntity.Customer.ExperienceLogType.Recommend, logMemo); ObjectFactory <SOSendMessageProcessor> .Instance.RecommendCustomerAddExperienceSendMail(rmdCustomerInfo, customerInfo.CustomerID, addExperience); } }