/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSave_Click(object sender, RoutedEventArgs e) { if (oldEndDate == VM.EndDate) { CPApplication.Current.CurrentPage.Context.Window.Alert(ResGiftCardInfo.Information_NoValueForUpdate, Newegg.Oversea.Silverlight.Controls.Components.MessageType.Warning); } else { CPApplication.Current.CurrentPage.Context.Window.Confirm(ResGiftCardInfo.Information_NeedForUpdateAgain, (obj, args) => { if (args.DialogResult == DialogResultType.OK) { GiftCardInfo item = VM.ConvertVM <GiftCardVM, GiftCardInfo>(); item.Customer = customerInfo; facade.UpdateGiftCardInfo(item, (obj2, args2) => { if (args2.FaultsHandle()) { return; } CPApplication.Current.CurrentPage.Context.Window.Alert(ResGiftCardInfo.Information_OperateSuccessful, Newegg.Oversea.Silverlight.Controls.Components.MessageType.Information); CloseDialog(DialogResultType.OK); }); } }); } }
/// <summary> /// 作废 /// </summary> /// <param name="items"></param> /// <param name="callback"></param> public void SetGiftCardInvalid(GiftCardInfo item, EventHandler <RestClientEventArgs <dynamic> > callback) { string relativeUrl = "/IMService/GiftCardInfo/SetGiftCardInvalid"; item.EditUser = new UserInfo { SysNo = CPApplication.Current.LoginUser.userSysNo, UserName = CPApplication.Current.LoginUser.LoginName, UserDisplayName = CPApplication.Current.LoginUser.DisplayName }; restClient.Update(relativeUrl, item, callback); }
protected override void MapUnknownElement(XElement element, Multimap <int, object> map) { if (element.Name.LocalName == "GiftCardInfo") { try { var giftCardInfo = new GiftCardInfo(); foreach (var el in element.Elements()) { switch (el.Name.LocalName) { case nameof(GiftCardInfo.RecipientEmail): { giftCardInfo.RecipientEmail = el.Value; break; } case nameof(GiftCardInfo.RecipientName): { giftCardInfo.RecipientName = el.Value; break; } case nameof(GiftCardInfo.SenderName): { giftCardInfo.SenderName = el.Value; break; } case nameof(GiftCardInfo.SenderEmail): { giftCardInfo.SenderEmail = el.Value; break; } case nameof(GiftCardInfo.Message): { giftCardInfo.Message = el.Value; break; } default: throw new InvalidEnumArgumentException(el.Name.LocalName); } } GiftCardInfo = giftCardInfo; } catch (Exception ex) { throw new XmlException("Error while trying to parse from additional XML: " + nameof(ProductVariantAttributeSelection), ex); } } }
private void CreateGiftCard() { GiftCardInfo giftCard = Factory.NewGiftCard(1); giftCard.Insert(); new GiftCardCouponCodeInfo { GiftCardCouponCodeGiftCardID = giftCard.GiftCardID, GiftCardCouponCodeCode = GIFT_CARD_COUPON_CODE }.Insert(); }
public GiftCardInfo GetGiftCardInfoByReferenceSOSysNo(int soSysNo, int customerSysNo, GiftCardType internalType, CardMaterialType type) { DataCommand dc = DataCommandManager.GetDataCommand("GetGiftCardInfoByReferenceSOSysNo"); dc.SetParameterValue("@ReferenceSOSysNo", soSysNo); dc.SetParameterValue("@CustomerSysNo", customerSysNo); dc.SetParameterValue("@InternalType", internalType); dc.SetParameterValue("@Type", type); GiftCardInfo result = dc.ExecuteEntity <GiftCardInfo>(); return(result); }
/// <summary> /// 作废 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnVoid_Click(object sender, RoutedEventArgs e) { GiftCardInfo item = VM.ConvertVM <GiftCardVM, GiftCardInfo>(); facade.SetGiftCardInvalid(item, (obj, args) => { if (args.FaultsHandle()) { return; } CPApplication.Current.CurrentPage.Context.Window.Alert(ResGiftCardInfo.Information_OperateSuccessful, Newegg.Oversea.Silverlight.Controls.Components.MessageType.Information); CloseDialog(DialogResultType.OK); }); }
/// <summary> /// 操作礼品卡的状态 /// </summary> /// <param name="action"></param> /// <param name="items"></param> /// <returns></returns> public string OperateGiftCardStatus(string action, GiftCardInfo item) { StringBuilder messageBuilder = new StringBuilder(); XmlWriterSettings setting = new XmlWriterSettings(); setting.Encoding = Encoding.Unicode; using (XmlWriter xmlWriter = XmlWriter.Create(messageBuilder, setting)) { xmlWriter.WriteStartElement("Message"); xmlWriter.WriteStartElement("Header"); #region header xmlWriter.WriteElementString("Action", action); xmlWriter.WriteElementString("Version", "V1"); xmlWriter.WriteElementString("From", "IPP.Content"); xmlWriter.WriteElementString("CompanyCode", item.CompanyCode); xmlWriter.WriteElementString("StoreCompanyCode", item.CompanyCode); #endregion xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("Body"); xmlWriter.WriteElementString("EditUser", item.EditUser.UserDisplayName);//需要当前用户名 #region giftcard list xmlWriter.WriteStartElement("GiftCard"); xmlWriter.WriteElementString("Code", item.CardCode);//BarCode // update begindate and enddate in sp don't know why setting here if (!action.Equals("ActiveGiftVoucher")) { xmlWriter.WriteElementString("BeginDate", item.BeginDate.Value.ToString("yyyy-MM-dd")); xmlWriter.WriteElementString("EndDate", item.EndDate.Value.ToString("yyyy-MM-dd")); } xmlWriter.WriteEndElement(); if (action == "AdjustExpireDate") { xmlWriter.WriteElementString("Memo", "从时间" + (item.PreEndDate.HasValue ? item.PreEndDate.Value.ToString("yyyy-MM-dd") : "") + "修改到时间" + item.EndDate.Value.ToString("yyyy-MM-dd")); } #endregion xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement(); } DataCommand cmd = DataCommandManager.GetDataCommand("OperateGiftCard"); cmd.SetParameterValue("Msg", messageBuilder.ToString()); cmd.ExecuteNonQuery(); return(cmd.GetParameterValue("StatusCode").ToString()); }
public static string LookPassword(string Code, int CurrentCustomerSysNo) { DataCommand cmd = DataCommandManager.GetDataCommand("LookGiftCardPassword"); cmd.SetParameterValue("@CustomerSysNo", CurrentCustomerSysNo); cmd.SetParameterValue("@Code", Code); GiftCardInfo tmp = cmd.ExecuteEntity <GiftCardInfo>(); if (tmp != null) { return(CryptoManager.GetCrypto(CryptoAlgorithm.DES).Decrypt(tmp.Password)); } else { return(null); } }
public virtual ActionResult Apply(string code, GiftCardInfo card) { if (string.IsNullOrEmpty(code)) { return(JsonError("code is null or empty")); } if (card == null) { return(JsonError("card details are missing")); } try { var cart = ShoppingCart; var existing = cart.InitialPayments.Any(x => x.Provider is GiftCardPaymentProvider && (x.Details as GiftCardInfo).CardNumber == card.CardNumber); if (existing) { return(JsonError("Checkout-Gift-Card-Already-Added")); } var balanceDue = (cart.Totals as Prices.OrderTotals).BalanceDue; if (balanceDue <= 0) { return(JsonError("Checkout-Gift-Card-Zero-Balance-Due")); } var paymentFactory = Context.Entity.Resolve <ActiveCommerce.Payments.PaymentFactory>(); var payment = paymentFactory.Create(code); var manager = Context.Entity.Resolve <IGiftCardManager>(); if (!manager.Validate(card)) { return(JsonError("Gift-Card-Not-Valid")); } card.Balance = manager.GetBalance(card); if (card.Balance <= 0) { return(JsonError("Gift-Card-Insufficient-Balance")); } payment.Details = card; cart.InitialPayments.Add(payment); AdjustPaymentAmounts(); } catch (Exception e) { return(JsonError(e.Message)); } return(Json(true)); }
public string Get(ControllerContext controllerContext) { var defaultModelBinder = new DefaultModelBinder(); var modelType = typeof(GiftCardInfo); var giftCardInfo = new GiftCardInfo(); var metadataForType = ModelMetadataProviders.Current.GetMetadataForType(() => giftCardInfo, modelType); metadataForType.Model = giftCardInfo; var modelBindingContext = new ModelBindingContext { ModelMetadata = metadataForType, ValueProvider = new FormValueProvider(controllerContext) }; var model = defaultModelBinder.BindModel(controllerContext, modelBindingContext) as GiftCardInfo; return(model == null ? null : JsonConvert.SerializeObject(model)); }
private static void SetCheckoutResult(OrderPipelineProcessResult orderProcessResult, CheckOutResult checkoutResult, CheckOutContext context) { checkoutResult.OrderProcessResult = orderProcessResult; checkoutResult.HasSucceed = orderProcessResult.HasSucceed; checkoutResult.ShoppingItemParam = context.ShoppingItemParam; if (orderProcessResult.ErrorMessages != null) { checkoutResult.ErrorMessages = orderProcessResult.ErrorMessages.SelectMany(msg => { if (!String.IsNullOrWhiteSpace(msg)) { return(msg.Split(new string[] { System.Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).ToList()); } return(new List <String>(0)); }) .ToList(); checkoutResult.ErrorMessages.RemoveAll(x => String.IsNullOrWhiteSpace(x)); } if (orderProcessResult != null && orderProcessResult.ReturnData != null) { //优惠券使用情况 checkoutResult.ApplyCouponCode = orderProcessResult.ReturnData.CouponCode; checkoutResult.ApplyCouponName = orderProcessResult.ReturnData.CouponName; checkoutResult.ApplyedCouponDesc = orderProcessResult.ReturnData.CouponErrorDesc; //积分使用情况 checkoutResult.UsePointPay = orderProcessResult.ReturnData.PointPay; checkoutResult.MaxPointPay = orderProcessResult.ReturnData.MaxPointPay; checkoutResult.UsePointPayDesc = orderProcessResult.ReturnData.UsePointPayDesc; //礼品卡使用情况 checkoutResult.ApplyedGiftCardDesc = orderProcessResult.ReturnData.GiftCardErrorDesc; checkoutResult.BindingGiftCardList = orderProcessResult.ReturnData.BindingGiftCardList; if (orderProcessResult.ReturnData.GiftCardList != null) { checkoutResult.ApplyedGiftCardList = orderProcessResult.ReturnData.GiftCardList.Select(g => { GiftCardInfo giftCardInfo = (GiftCardInfo)g.Clone(); giftCardInfo.Password = ConfuseGiftCardPassword(g.Password, orderProcessResult.ReturnData.Customer.SysNo); return(giftCardInfo); }).ToList(); } } }
/// <summary> /// 根据 礼品卡编号 和密码 获取 对应的礼品卡信息 /// </summary> /// <param name="code">礼品卡 卡号</param> /// <param name="password">礼品卡 密码</param> internal static GiftCardInfo GetGiftCardByCodeAndPassword(string code, string password) { string TempPassword = CryptoManager.GetCrypto(CryptoAlgorithm.DES).Encrypt(password); GiftCardInfo giftCard = null; List <string> codeList = new List <string>(); codeList.Add(code); List <ECCentral.BizEntity.IM.GiftCardInfo> infoList = ObjectFactory <IIMBizInteract> .Instance.GetGiftCardsByCodeList(codeList); if (infoList != null && infoList.Count > 0) { foreach (var item in infoList) { if (item.Password == TempPassword) { giftCard = item; } } } return(giftCard); }
public virtual void SetGiftCardInvalid(GiftCardInfo item) { giftCardAppService.SetGiftCardInvalid(item); }
/// <summary> /// 计算礼品卡支付金额 /// </summary> /// <param name="order"></param> private void CalculateGiftCardPayAmount(OrderInfo order) { if (order.GiftCardList == null || order.GiftCardList.Count <= 0) { foreach (KeyValuePair <string, OrderInfo> kvs in order.SubOrderList) { kvs.Value.GiftCardPayAmount = 0m; } } else { PreCheckCalculateGiftCardPay(order); if (order.GiftCardList == null || order.GiftCardList.Count <= 0) { foreach (KeyValuePair <string, OrderInfo> kvs in order.SubOrderList) { kvs.Value.GiftCardPayAmount = 0m; } } else { order.GiftCardList.ForEach(giftCardInfo => { giftCardInfo["ActAvailableAmount"] = giftCardInfo.AvailableAmount; }); //优先使用快过期的礼品卡 order.GiftCardList.Sort((giftCard1, giftCard2) => { var diffDate1 = giftCard1.ValidEndDate.Subtract(DateTime.Today); var diffDate2 = giftCard2.ValidEndDate.Subtract(DateTime.Today); return(diffDate1.CompareTo(diffDate2)); }); List <OrderInfo> subPreOrderInfoList = order.SubOrderList.Select(kvs => kvs.Value) .Where(x => x.SOAmount - x.TaxAmount > 0m).ToList(); //按照订单金额降序排列,订单金额高的优先使用礼品卡支付 subPreOrderInfoList.Sort((subOrder1, subOrder2) => { return(-1 * (subOrder1.SOAmount - subOrder1.TaxAmount).CompareTo((subOrder2.SOAmount - subOrder2.TaxAmount))); }); foreach (OrderInfo subPreOrderInfo in subPreOrderInfoList) { subPreOrderInfo.GiftCardList = new List <GiftCardInfo>(); //计算总计可以使用礼品卡支付的金额,需要扣除关税,关税不能使用礼品卡抵扣 decimal totalCanUseGiftPayAmount = subPreOrderInfo.SOAmount - subPreOrderInfo.TaxAmount - subPreOrderInfo.PointPayAmount - subPreOrderInfo.CouponAmount; //从礼品卡列表中选出可用余额大于0的礼品卡 var availableGiftCardList = order.GiftCardList.Where(g => g.AvailableAmount > 0).ToList(); foreach (GiftCardInfo giftCardInfo in availableGiftCardList) { //该子单已经使用礼品卡付清,结束本轮循环,计算下一张子单 if (totalCanUseGiftPayAmount <= 0) { break; } GiftCardInfo clonedGiftCardInfo = (GiftCardInfo)giftCardInfo.Clone(); //该张礼品卡可用余额小于登录总共可用于礼品卡支付的金额,那么这张礼品卡将全额支付 //否则该张礼品卡使用部分金额来支付剩余待支付金额 if (giftCardInfo.AvailableAmount <= totalCanUseGiftPayAmount) { clonedGiftCardInfo.UseAmount = giftCardInfo.AvailableAmount; } else { clonedGiftCardInfo.UseAmount = totalCanUseGiftPayAmount; } //扣减该张礼品卡的可用余额,更新该张礼品卡的使用金额 giftCardInfo.AvailableAmount -= clonedGiftCardInfo.UseAmount; giftCardInfo.UseAmount += clonedGiftCardInfo.UseAmount; totalCanUseGiftPayAmount -= clonedGiftCardInfo.UseAmount; subPreOrderInfo.GiftCardList.Add(clonedGiftCardInfo); } //计算子单使用礼品卡抵扣金额 subPreOrderInfo.GiftCardPayAmount = subPreOrderInfo.GiftCardList.Sum(g => g.UseAmount); } } } //重新计算整单礼品卡支付金额 order.GiftCardPayAmount = order.SubOrderList.Sum(x => x.Value.GiftCardPayAmount); }
private static CheckOutResult PreCheckAndBuild(CheckOutContext context, ShoppingCart shoppingCart, int customerSysNo, int orderSource , Func <OrderInfo, OrderPipelineProcessResult> action) { CheckOutResult result = new CheckOutResult(); MemberInfo memberInfo = CustomerDA.GetCustomerInfo(customerSysNo); CheckOutContext newCheckoutContenxt = new CheckOutContext(); if (context != null) { newCheckoutContenxt = context.Clone(); } CustomerInfo customerInfo = new CustomerInfo() { AccountBalance = memberInfo.ValidPrepayAmt, AccountPoint = memberInfo.ValidScore, CustomerRank = (int)memberInfo.CustomerRank, ID = memberInfo.CustomerID, SysNo = memberInfo.SysNo, Name = memberInfo.CustomerName, IsEmailConfirmed = memberInfo.IsEmailConfirmed, IsPhoneValided = memberInfo.IsPhoneValided, CellPhone = memberInfo.CellPhone, SocietyID = memberInfo.SocietyID }; result.Customer = customerInfo; //用户个人实名认证信息 result.CustomerAuthenticationInfo = CustomerDA.GetCustomerAuthenticationInfo(customerSysNo); //用户购物发票信息 result.CustomerInvoiceInfo = CustomerDA.GetCustomerInvoiceInfo(customerSysNo); if (result.CustomerInvoiceInfo == null) { result.CustomerInvoiceInfo = new Entity.Member.CustomerInvoiceInfo() { CustomerSysNo = customerSysNo, InvoiceTitle = customerInfo.Name }; } //收货地址 var custShippingAddressListResult = GetCustomerShippingAddressList(context, customerSysNo); result.ShippingAddressList = custShippingAddressListResult.ShippingAddressList; result.SelShippingAddress = custShippingAddressListResult.SelShippingAddress; //支付方式&配送方式 var payAndShipTypeResult = GetPayAndShipTypeList(context, customerSysNo, shoppingCart); result.PaymentCategoryList = payAndShipTypeResult.PaymentCategoryList; result.SelPaymentCategoryID = payAndShipTypeResult.SelPaymentCategoryID; result.PayTypeList = payAndShipTypeResult.PayTypeList; result.SelPayType = payAndShipTypeResult.SelPayType; result.ShipTypeList = payAndShipTypeResult.ShipTypeList; result.SelShipType = payAndShipTypeResult.SelShipType; //根据CheckOutContext 进一步构造shoppingCartResult.ReturnData对象 OrderInfo preOrderInfo = SOPipelineProcessor.Convert2OrderInfo(shoppingCart); preOrderInfo.Customer = customerInfo; preOrderInfo.PayTypeID = result.SelPayType.PayTypeID.ToString(); preOrderInfo.ShipTypeID = result.SelShipType.ShipTypeSysNo.ToString(); preOrderInfo.Memo = newCheckoutContenxt.OrderMemo; preOrderInfo.CouponCode = newCheckoutContenxt.PromotionCode; preOrderInfo.ChannelID = shoppingCart.ChannelID; preOrderInfo.LanguageCode = shoppingCart.LanguageCode; preOrderInfo.OrderSource = orderSource; preOrderInfo.VirualGroupBuyOrderTel = context != null ? context.VirualGroupBuyOrderTel : ""; preOrderInfo.Contact = new ContactInfo() { AddressAreaID = result.SelShippingAddress.ReceiveAreaSysNo, //AddressAreaID = result.SelShippingAddress.ReceiveAreaCitySysNo, AddressTitle = result.SelShippingAddress.AddressTitle, AddressDetail = result.SelShippingAddress.ReceiveAddress, MobilePhone = result.SelShippingAddress.ReceiveCellPhone, Phone = result.SelShippingAddress.ReceivePhone, Name = result.SelShippingAddress.ReceiveName, ZipCode = result.SelShippingAddress.ReceiveZip, ID = result.SelShippingAddress.SysNo, }; //使用余额进行支付,给订单的余额支付金额赋值,在SOPipline中会对订单的余额支付金额重新进行计算 if (newCheckoutContenxt.IsUsedPrePay > 0) { preOrderInfo.BalancePayAmount = customerInfo.AccountBalance; } //积分 preOrderInfo.PointPay = newCheckoutContenxt.PointPay; //礼品卡 if (newCheckoutContenxt.GiftCardList != null && newCheckoutContenxt.GiftCardList.Count > 0) { preOrderInfo.GiftCardList = new List <GiftCardInfo>(); foreach (var giftCardContext in newCheckoutContenxt.GiftCardList) { if (!string.IsNullOrWhiteSpace(giftCardContext.Crypto)) { giftCardContext.Password = ExtractGiftCardPassword(giftCardContext.Password, customerSysNo); } GiftCardInfo giftCardInfo = new GiftCardInfo() { Code = giftCardContext.Code, Password = giftCardContext.Password }; giftCardInfo["Crypto"] = giftCardContext.Crypto; preOrderInfo.GiftCardList.Add(giftCardInfo); } } //购物发票,1表示要开发票 if (newCheckoutContenxt.NeedInvoice == 1) { preOrderInfo.Receipt = new ReceiptInfo() { PersonalInvoiceTitle = result.CustomerInvoiceInfo.InvoiceTitle }; } //执行真正的action操作 OrderPipelineProcessResult checkOutResult = action(preOrderInfo); SetCheckoutResult(checkOutResult, result, newCheckoutContenxt); return(result); }
/// <summary> /// 强制失效 /// </summary> /// <param name="items"></param> public virtual void SetGiftCardInvalid(GiftCardInfo item) { ObjectFactory <GiftCardProcessor> .Instance.SetGiftCardInvalid(item); }
/// <summary> /// 添加礼品卡 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void hlkb_SOGiftCard_AddGiftCard_Click(object sender, RoutedEventArgs e) { string strCode = txtGiftCardNumber.Text; string strPassword = txtGiftCardPassword.Password; if (!string.IsNullOrEmpty(strCode) && !string.IsNullOrEmpty(strPassword)) { new SOQueryFacade().QueryGiftCardByCodeAndPassword(strCode, strPassword, (obj, args) => { if (args.FaultsHandle()) { return; } GiftCardInfo giftCardInfo = args.Result; string errorInfo = string.Empty; if (giftCardInfo != null && GiftCardInfoVMList != null && GiftCardInfoVMList.Count > 0) { foreach (var item in GiftCardInfoVMList) { if (item.CardCode == giftCardInfo.CardCode) { errorInfo = ResSOMaintain.Info_AddGiftCard_Code_Error; CPApplication.Current.CurrentPage.Context.Window.Alert(errorInfo, MessageType.Error); return; } } } if (giftCardInfo == null) { errorInfo = ResSOMaintain.Info_AddGiftCard_Error; } else if (giftCardInfo.Status != ECCentral.BizEntity.IM.GiftCardStatus.Valid) { errorInfo = ResSOMaintain.Info_AddGiftCard_Status_Error; } else if (giftCardInfo.BindingCustomer != null) { errorInfo = ResSOMaintain.Info_AddGiftCard_BindCustomerSysNo_Error; } else if (giftCardInfo.AvailAmount == 0) { errorInfo = ResSOMaintain.Info_AddGiftCard_AvailableAmount_Error; } else if (giftCardInfo.EndDate < DateTime.Now) { errorInfo = ResSOMaintain.Info_AddGiftCard_Expired_Error; } else if (giftCardInfo.BeginDate > DateTime.Now) { errorInfo = ResSOMaintain.Info_AddGiftCard_LessBeginDate_Error; } if (string.IsNullOrEmpty(errorInfo)) { if (GiftCardInfoVMList == null) { GiftCardInfoVMList = new List <GiftCardInfoVM>(); } else { GiftCardInfoVMList.Add(giftCardInfo.Convert <GiftCardInfo, GiftCardInfoVM>()); dgridSOGiftCardInfo.ItemsSource = GiftCardInfoVMList; } } else { CPApplication.Current.CurrentPage.Context.Window.Alert(errorInfo, MessageType.Error); } }); } }