/// <summary> /// 买1件商品,根据配送方式,配送地址,读取邮费价格【按单个商品独立计算运费】 /// </summary> /// <param name="shipping"></param> /// <param name="shippingRegion"></param> /// <param name="product"></param> /// <returns></returns> public static decimal ReadShippingMoney(int shippingId, string regionId, ProductInfo product) { decimal shippingMoney = 0; ShippingInfo shipping = ShippingBLL.Read(shippingId); ShippingRegionInfo shippingRegion = ShippingRegionBLL.SearchShippingRegion(shippingId, regionId); switch (shipping.ShippingType) { case (int)ShippingType.Fixed: shippingMoney = shippingRegion.FixedMoeny; break; case (int)ShippingType.Weight: decimal cartProductWeight = 1 * product.Weight; if (cartProductWeight <= shipping.FirstWeight) { shippingMoney = shippingRegion.FirstMoney; } else { shippingMoney = shippingRegion.FirstMoney + Math.Ceiling((cartProductWeight - shipping.FirstWeight) / shipping.AgainWeight) * shippingRegion.AgainMoney; } break; case (int)ShippingType.ProductCount: int cartProductCount = 1; shippingMoney = shippingRegion.OneMoeny + (cartProductCount - 1) * shippingRegion.AnotherMoeny; break; default: break; } return(shippingMoney); }
/// <summary> /// 计算订单的邮费 /// </summary> /// <param name="order"></param> /// <returns></returns> public static decimal ReadOrderShippingMoney(OrderInfo order) { decimal shippingMoney = order.ShippingMoney; ShippingInfo shipping = ShippingBLL.Read(order.ShippingId); ShippingRegionInfo shippingRegion = ShippingRegionBLL.SearchShippingRegion(order.ShippingId, order.RegionId); switch (shipping.ShippingType) { case (int)ShippingType.Fixed: shippingMoney = shippingRegion.FixedMoeny; break; case (int)ShippingType.Weight: decimal orderProductWeight = 0; foreach (OrderDetailInfo orderDetail in OrderDetailBLL.ReadList(order.Id)) { orderProductWeight += orderDetail.ProductWeight * orderDetail.BuyCount; } if (orderProductWeight <= shipping.FirstWeight) { shippingMoney = shippingRegion.FirstMoney; } else { shippingMoney = shippingRegion.FirstMoney + Math.Ceiling((orderProductWeight - shipping.FirstWeight) / shipping.AgainWeight) * shippingRegion.AgainMoney; } break; case (int)ShippingType.ProductCount: int orderProductCount = 0; foreach (OrderDetailInfo orderDetail in OrderDetailBLL.ReadList(order.Id)) { if (orderDetail.ParentId == 0) { orderProductCount += orderDetail.BuyCount; } } shippingMoney = shippingRegion.OneMoeny + (orderProductCount - 1) * shippingRegion.AnotherMoeny; break; default: break; } return(shippingMoney); }
/// <summary> /// 退款到账户余额及各支付渠道 /// </summary> /// <param name="orderRefund"></param> public static void RefundToAnyPay(OrderRefundInfo orderRefund) { if (orderRefund.Status != (int)OrderRefundStatus.Returning) { return; } if (RefundOnline) { if (PayPlugins.ReadPayPlugins(orderRefund.RefundPayKey).IsOnline == 1 && (OrderBLL.Read(orderRefund.OrderId).AliPayTradeNo.Trim() != string.Empty || OrderBLL.Read(orderRefund.OrderId).WxPayTradeNo.Trim() != string.Empty))//只有在线付款才走线上流程,并且存在支付交易号(支付宝微信任意一个) { //退款到各支付渠道 //如需退余额,将在第三方支付退款成功后操作 //这样做的好处在于保障了余额能够被准确退还。不会出现退了余额,但支付宝或微信因为人为或意外的原因没退成功的情况。 if (orderRefund.RefundMoney > 0) { //HttpContext.Current.Response.Redirect(string.Format("/Plugins/Pay/{0}/Refund.aspx?order_refund_id={1}", orderRefund.RefundPayKey, orderRefund.Id)); HttpContext.Current.Response.Redirect(string.Format("/Plugins/Pay/{0}/Refund.aspx?order_refund_id={1}&returnurl={2}", orderRefund.RefundPayKey, orderRefund.Id, RefundRedirectUrl)); } else { //只需退款到余额 //在这里写自己的逻辑 if (orderRefund.RefundBalance > 0) { //HttpContext.Current.Response.Redirect(string.Format("/Admin/OrderRefundToBalance.aspx?order_refund_id={0}", orderRefund.Id)); HttpContext.Current.Response.Redirect(string.Format("/Admin/OrderRefundToBalance.aspx?order_refund_id={0}&returnurl={1}", orderRefund.Id, RefundRedirectUrl)); } } } else//线下退款则直接更改状态,所以线下退款只能管理员自己审核。 { orderRefund.Remark = "退款完成"; orderRefund.Status = (int)OrderRefundStatus.HasReturn; orderRefund.TmRefund = DateTime.Now; OrderRefundBLL.Update(orderRefund); OrderRefundActionBLL.Add(new OrderRefundActionInfo { OrderRefundId = orderRefund.Id, Status = 1, Tm = DateTime.Now, UserType = 2, UserId = Cookies.Admin.GetAdminID(false), UserName = Cookies.Admin.GetAdminName(false), Remark = orderRefund.Remark }); #region 发送订单退款成功通知 int isSendNotice = ShopConfig.ReadConfigInfo().RefundOrder; int isSendEmail = ShopConfig.ReadConfigInfo().RefundOrderEmail; int isSendMessage = ShopConfig.ReadConfigInfo().RefundOrderMsg; string key = "RefundOrder"; OrderInfo order = OrderBLL.Read(orderRefund.OrderId); if (isSendNotice == (int)BoolType.True && key != string.Empty) { if (isSendEmail == (int)BoolType.True) {//发邮件 try { EmailContentInfo emailContent = EmailContentHelper.ReadSystemEmailContent(key); EmailSendRecordInfo emailSendRecord = new EmailSendRecordInfo(); emailSendRecord.Title = emailContent.EmailTitle; emailSendRecord.Content = emailContent.EmailContent.Replace("$UserName$", order.UserName).Replace("$OrderNumber$", order.OrderNumber).Replace("$PayName$", order.PayName).Replace("$ShippingName$", ShippingBLL.Read(order.ShippingId).Name).Replace("$ShippingNumber$", order.ShippingNumber).Replace("$ShippingDate$", order.ShippingDate.ToString("yyyy-MM-dd")); emailSendRecord.IsSystem = (int)BoolType.True; emailSendRecord.EmailList = order.Email; emailSendRecord.IsStatisticsOpendEmail = (int)BoolType.False; emailSendRecord.SendStatus = (int)SendStatus.No; emailSendRecord.AddDate = RequestHelper.DateNow; emailSendRecord.SendDate = RequestHelper.DateNow; emailSendRecord.ID = EmailSendRecordBLL.AddEmailSendRecord(emailSendRecord); EmailSendRecordBLL.SendEmail(emailSendRecord); //result = "通知邮件已发送。"; } catch { //result = "未发送通知邮件。"; } } if (isSendMessage == (int)BoolType.True) {//发短信 //result += "未发送通知短信。"; } } #endregion if (string.IsNullOrEmpty(RefundRedirectUrl)) { HttpContext.Current.Response.Redirect(string.Format("/Admin/OrderRefundAdd.aspx?id={0}", orderRefund.Id)); } else { HttpContext.Current.Response.Redirect(RefundRedirectUrl); } } } else { //处理订单、商品的退款状态,线下退款 //在这里写自己的逻辑 HttpContext.Current.Response.Redirect(string.Format("/Admin/OrderRefundToBalance.aspx?order_refund_id={0}&returnurl={1}", orderRefund.Id, RefundRedirectUrl)); } }