Пример #1
0
        public static void SalesOrderMailSuccessful(OrderInfo order)
        {
            foreach (var subOrder in order.SubOrderList.Values)
            {
                if (subOrder.SOType == (int)SOType.VirualGroupBuy)
                {
                    continue;
                }
                ECommerce.Entity.Member.CustomerInfo customer = CustomerDA.GetCustomerByID(subOrder.Customer.ID);

                if (string.IsNullOrEmpty(customer.Email))
                {
                    return;
                }

                AsyncEmail email = new AsyncEmail();
                email.MailAddress = customer.Email;
                email.CustomerID  = customer.CustomerID;
                email.Status      = (int)EmailStatus.NotSend;
                string token = Guid.NewGuid().ToString("N");
                email.ImgBaseUrl     = ConfigurationManager.AppSettings["CDNWebDomain"].ToString();
                email.SetNewTokenUrl = "/EmailVerifySucceed?token=" + token + "&sysno=" + customer.SysNo.ToString() + "&email=" + System.Web.HttpUtility.HtmlEncode(customer.Email);

                string subject = string.Empty;
                email.MailBody    = MailHelper.GetMailTemplateBody("SalesOrderMailSuccessful", out subject);
                email.MailSubject = subject.Replace("[SOSysNo]", subOrder.ID.ToString());

                //订单内容
                email.MailBody = email.MailBody.Replace("[SOSysNo]", subOrder.ID.ToString());
                email.MailBody = email.MailBody.Replace("[OrderTime]", subOrder.InDate.ToString("yyyy年MM月dd日 HH时mm分"));

                email.MailBody = email.MailBody.Replace("[CustomerID]", subOrder.Customer.ID);
                email.MailBody = email.MailBody.Replace("[CustomerName]", subOrder.Customer.Name);
                email.MailBody = email.MailBody.Replace("[ContactName]", subOrder.Contact.Name);
                email.MailBody = email.MailBody.Replace("[ContactMobilePhone]", subOrder.Contact.MobilePhone);
                email.MailBody = email.MailBody.Replace("[ContactPhone]", subOrder.Contact.Phone);

                var    area    = CommonFacade.GetArea(subOrder.Contact.AddressAreaID);
                string address = string.Format("{0} {1} {2} {3}", area.ProvinceName, area.CityName, area.DistrictName, subOrder.Contact.AddressDetail);
                email.MailBody = email.MailBody.Replace("[ContactAddress]", address);
                email.MailBody = email.MailBody.Replace("[ContactZipCode]", subOrder.Contact.ZipCode);

                email.MailBody = email.MailBody.Replace("[ShipTypeName]", (string)subOrder["ShipTypeName"]);
                email.MailBody = email.MailBody.Replace("[PayTypeName]", subOrder.PayTypeName);
                email.MailBody = email.MailBody.Replace("[CashPayAmountWithTax]", (subOrder.CashPayAmount + subOrder.TaxAmount).ToString("F2"));
                email.MailBody = email.MailBody.Replace("[TotalWeight]", (((decimal)subOrder.TotalWeight) / 1000).ToString("F3"));
                email.MailBody = email.MailBody.Replace("[ShippingAmount]", subOrder.ShippingAmount.ToString("F2"));
                email.MailBody = email.MailBody.Replace("[TaxAmount]", subOrder.TaxAmount.ToString("F2"));
                email.MailBody = email.MailBody.Replace("[CouponAmount]", subOrder.CouponAmount.ToString("F2"));
                email.MailBody = email.MailBody.Replace("[GiftCardPayAmount]", subOrder.GiftCardPayAmount.ToString("F2"));
                email.MailBody = email.MailBody.Replace("[BalancePayAmount]", subOrder.BalancePayAmount.ToString("F2"));
                email.MailBody = email.MailBody.Replace("[TotalDiscountAmount]", subOrder.TotalDiscountAmount.ToString("F2"));
                email.MailBody = email.MailBody.Replace("[PointPayAmount]", subOrder.PointPayAmount.ToString("F2"));
                email.MailBody = email.MailBody.Replace("[SOAmount]", subOrder.SOAmount.ToString("F2"));
                email.MailBody = email.MailBody.Replace("[SOMemo]", subOrder.Memo);
                email.MailBody = email.MailBody.Replace("[SendTime]", DateTime.Now.ToString("yyyy-MM-dd"));
                email.MailBody = email.MailBody.Replace("[Year]", DateTime.Now.Year.ToString());

                string domain = ConfigurationManager.AppSettings["WebDomain"].ToString();

                StringBuilder sb = new StringBuilder();

                if (subOrder.OrderItemGroupList != null)
                {
                    subOrder.OrderItemGroupList.ForEach(groupItem =>
                    {
                        groupItem.ProductItemList.ForEach(item =>
                        {
                            sb.Append("<tr style=\"background:#fff;\">");
                            sb.AppendFormat("<td align=\"center\" valign=\"middle\" style=\"padding-left:5px; border-left:1px solid #eeeeee; border-top:1px solid #eeeeee;\"><a href=\"{0}\"><img src=\"{1}\" width=\"50\" height=\"50\" border=\"0\" /></a></td>", domain + "/product/detail/" + item.ProductSysNo, ProductFacade.BuildProductImage(ImageSize.P60, item.DefaultImage));
                            sb.AppendFormat("<td align=\"center\" style=\"padding-left:5px; border-left:1px solid #eeeeee; border-top:1px solid #eeeeee;\"><p>{0}</p></td>", item.ProductID);
                            sb.AppendFormat("<td valign=\"middle\" style=\"padding-left:5px; border-left:1px solid #eeeeee; border-top:1px solid #eeeeee; border-right:1px solid #eeeeee;\"><a href=\"{0}\" style=\"color:#ff6600; text-decoration:none; line-height:18px;\">{1}</a></td>", domain + "/product/detail/" + item.ProductSysNo, item.ProductName);
                            sb.AppendFormat("<td align=\"center\" style=\"border-right:1px solid #eeeeee; border-top:1px solid #eeeeee;\">&yen;{0}</td>", item.UnitSalePrice.ToString("F2"));
                            sb.AppendFormat("<td align=\"center\" style=\"border-right:1px solid #eeeeee; border-top:1px solid #eeeeee;\">{0}</td>", item.UnitQuantity);
                            sb.AppendFormat("<td align=\"center\" style=\"border-right:1px solid #eeeeee; border-top:1px solid #eeeeee;\">&yen;{0}</td>", item.TotalSalePrice.ToString("F2"));
                            sb.Append("</tr>");
                        });
                    });
                }
                if (subOrder.GiftItemList != null)
                {
                    var mergedSaleGiftList = new List <OrderGiftItem>();
                    subOrder.GiftItemList.ForEach(gift =>
                    {
                        if (!mergedSaleGiftList.Exists(g =>
                        {
                            if (g.ProductSysNo == gift.ProductSysNo)
                            {
                                g.UnitQuantity += gift.UnitQuantity;
                                return(true);
                            }
                            return(false);
                        }))
                        {
                            mergedSaleGiftList.Add(gift);
                        }
                    });
                    foreach (var item in mergedSaleGiftList)
                    {
                        sb.Append("<tr style=\"background:#FFF4F2;\">");
                        sb.AppendFormat("<td style=\"padding-left:5px; border-left:1px solid #eeeeee; border-top:1px solid #eeeeee;\">&nbsp;</td>");
                        sb.AppendFormat("<td style=\"padding-left:5px; border-left:1px solid #eeeeee; border-top:1px solid #eeeeee;\">&nbsp;</td>");
                        sb.AppendFormat("<td valign=\"middle\" style=\"padding-left:5px; border-left:1px solid #eeeeee; border-top:1px solid #eeeeee; border-right:1px solid #eeeeee;line-height:18px;\"><span style=\"color:#ff6600; padding-right:8px;\">[赠品]</span>{0}</td>", item.ProductName);
                        sb.AppendFormat("<td align=\"center\" style=\"border-right:1px solid #eeeeee; border-top:1px solid #eeeeee;\">&yen;{0}</td>", item.UnitSalePrice.ToString("F2"));
                        sb.AppendFormat("<td align=\"center\" style=\"border-right:1px solid #eeeeee; border-top:1px solid #eeeeee;\">{0}</td>", item.UnitQuantity);
                        sb.AppendFormat("<td align=\"center\" style=\"border-right:1px solid #eeeeee; border-top:1px solid #eeeeee;\">&yen;{0}</td>", item.TotalSalePrice.ToString("F2"));
                        sb.Append("</tr>");
                    }
                }
                if (subOrder.AttachmentItemList != null)
                {
                    foreach (var item in subOrder.AttachmentItemList)
                    {
                        sb.Append("<tr style=\"background:#FFF4F2;\">");
                        sb.AppendFormat("<td style=\"padding-left:5px; border-left:1px solid #eeeeee; border-top:1px solid #eeeeee;\">&nbsp;</td>");
                        sb.AppendFormat("<td style=\"padding-left:5px; border-left:1px solid #eeeeee; border-top:1px solid #eeeeee;\">&nbsp;</td>");
                        sb.AppendFormat("<td valign=\"middle\" style=\"padding-left:5px; border-left:1px solid #eeeeee; border-top:1px solid #eeeeee; border-right:1px solid #eeeeee;line-height:18px;\"><span style=\"color:#ff6600; padding-right:8px;\">[附件]</span>{0}</td>", item.ProductName);
                        sb.AppendFormat("<td align=\"center\" style=\"border-right:1px solid #eeeeee; border-top:1px solid #eeeeee;\">&yen;{0}</td>", item.UnitSalePrice.ToString("F2"));
                        sb.AppendFormat("<td align=\"center\" style=\"border-right:1px solid #eeeeee; border-top:1px solid #eeeeee;\">{0}</td>", item.UnitQuantity);
                        sb.AppendFormat("<td align=\"center\" style=\"border-right:1px solid #eeeeee; border-top:1px solid #eeeeee;\">&yen;{0}</td>", item.TotalSalePrice.ToString("F2"));
                        sb.Append("</tr>");
                    }
                }
                if (subOrder.TotalRewardedPoint >= 0)
                {
                    sb.Append("<tr style=\"background:#fff;\">");
                    sb.AppendFormat("<td colspan=\"6\" style=\"border-bottom:1px solid #eeeeee; border-top:1px solid #eeeeee; height:41px; text-align:center; font-weight:bold;\" align=\"center\">本单交易成功后您可以获得积分:<strong style=\"color:#c40000; font-size:12px; font-family:microsoft yahei;\">{0}</strong></td>", subOrder.TotalRewardedPoint);
                    sb.Append("</tr>");
                }

                email.MailBody = email.MailBody.Replace("[OrderContent]", sb.ToString()).Replace("[WebBaseUrl]", domain).Replace("[ImgBaseUrl]", email.ImgBaseUrl);
                EmailDA.SendEmail(email);
            }
        }