USE [OverseaOrderManagement]
GO
/****** Object: StoredProcedure [dbo].[UP_EC_SendPaySuccessMail] Script Date: 10/21/2011 09:38:49 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*************************************************************************
* Name : [UP_EC_VoidSO_SendMailToCustomer]
* Function : Send mail to customer after SO has been payyed successed
* Database : [OverseaOrderManagement]
* DbServer : TransactionDB
* Input : @SOMSG
* Output :
* Table Used :
* ---------------------------------------------------------------------------------------------------
* Author :Bober.B.Song
* CreateDate :2011.10.19
*************************************************************************/
ALTER PROCEDURE [dbo].[UP_EC_SendPaySuccessMail]
--@SOSysNO INT
@SOCode VARCHAR(15)
AS
BEGIN
SET NOCOUNT ON;
DECLARE
--@SOMSG xml,
@SOType INT,
@SOSysNO INT,
--@SOCode VARCHAR(15),
@SODate datetime,-- VARCHAR(50),
@SoDateString varchar(20),
@CustomerEmail NVARCHAR(50),
@LanguageCode CHAR(5),
@CompanyCode CHAR(50),
@StoreCompanyCode VARCHAR(50),
@SaleRulesRowCount INT,
@SaleRulesCurrentRowIndex INT,
@ProductItemListRowCount INT,
@ProductItemListCurrentRowIndex INT,
@CustomerSysNO INT,
@DwellAreaSysNo INT,
@BufferIndex CHAR(2),
@SOMasterBufferSQL NVARCHAR(max),
@SOItemBufferSQL NVARCHAR(max),
@MailSubject NVARCHAR(200),--邮件主题
@MailBody NVARCHAR(max), --邮件体
@MailHeader NVARCHAR(max),--邮件头部分
@CreatedOrderUserEmail NVARCHAR(255),--订货人邮箱
@CreatedOrderUserInfo NVARCHAR(max),----邮件订货人信息
@CreatedOrderUserName NVARCHAR(50),--名称
@CreatedOrderUserProvinceName NVARCHAR(50),--省(自治区、直辖市)
@CreatedOrderUserDistrictName NVARCHAR(20),--县/区
@CreatedOrderUserCityName NVARCHAR(20), --城市
@CreatedOrderUserAddress NVARCHAR(200),--详细地址
@CreatedOrderUserZip NVARCHAR(10),--邮政编码
@CreatedOrderUserPhone NVARCHAR(200),--电话号码
@RecevierInfo NVARCHAR(max),----邮件收货人信息
@RecevierName NVARCHAR(50),--名称
@RecevierContact NVARCHAR(200), --联系人
@ReceiveAreaSysNo INT,
@RecevierProvinceName NVARCHAR(50),--省(自治区、直辖市)
@RecevierCityName NVARCHAR(20),--城市
@RecevierDistrictName NVARCHAR(20),--县/区
@RecevierAddress NVARCHAR(200),--详细地址
@RecevierZip NVARCHAR(10),--邮政编码
@RecevierPhone NVARCHAR(200),--电话号码
@ProductContent NVARCHAR(max),--邮件商品信息
@ProductItemList NVARCHAR(max),--邮件商品item列表
@ProductSysNo INT,--商品编号
@ProductCode NVARCHAR(20),--商品CODE
@CompanyProduct INT,--AZ商品
@ProductStatus INT,--商品状态
@ProductType INT,--商品类型
@BriefName NVARCHAR(100),--商品名称
@Price DECIMAL(19,2),--单价
@Quantity INT,--数量
@TotalPrice DECIMAL(19,2),--小计
@SOGetPointAMT INT, --本单交易成功后您可以获得积分
@SalesRuleInfo NVARCHAR(MAX), --邮件促销优惠信息
@SalesRuleItemList NVARCHAR(MAX),--邮件促销优惠项列表
@SalesRuleName NVARCHAR(200), --规则描述
@SalesRulePerDiscount DECIMAL(19,2), --单次折扣
@SalesRuleUsedTimes INT, --使用次数
@SalesRuleTotalDiscount DECIMAL(19,2), --小计
@SOMemoInfo NVARCHAR(3000),--邮件备注信息
@SOMemo NVARCHAR(1000), --订单备注
@OtherSOInfo NVARCHAR(MAX), --邮件其它信息
@ShippingTypeID INT,
@ShippingTypeName NVARCHAR(50),--配送方式
@PayTypeID INT,
@PayTypeName NVARCHAR(40),--支付方式
@ShipDeliveryType INT,
@SOComeTimeStr VARCHAR(50),
@SOComeTime DATETIME,--希望收货时间
@SOCashAMT DECIMAL(19,2),--现金支付总值(含税)
@SOPointPayInfo NVARCHAR(1000),--邮件积分支付总值
@SOPointPayAMT INT, --积分支付总值(含税)
@SOTotalWeightAMT DECIMAL(19,0),--商品总重(含礼品)
@SOShipPrice DECIMAL(19,2),--运费金额
@SOPremiumAMT DECIMAL(19,2),--保险费
@SOPrepayInfo NVARCHAR(1000),--邮件余额支付信息
@SOPrepayAmount DECIMAL(19,2),--现金余额支付
@SOPaypriceInfo NVARCHAR(1000),--邮件手续费
@SOPayprice DECIMAL(19,2),--手续费
@SODiscountInfo NVARCHAR(1000),--邮件促销优惠
@SODiscountAMT DECIMAL(19,2), --促销优惠
@IsPayWhenRecv INT,--是否是货到付款
@SOChange DECIMAL(19,2),--去零头
@GiftCardInfo NVARCHAR(1000),--礼品卡抵扣
@GiftCardPay DECIMAL(19,2),--礼品卡抵扣
@PromotionDiscount DECIMAL(19,2),--蛋券优惠
@SOAmount DECIMAL(19,2),--商品总额
@SONetPay DECIMAL(19,2),--NetPay总额
@ShipTypeNameInfo NVARCHAR(1000),--运输方式
@SOComeTimeInfo NVARCHAR(1000),--预计送达时间
@SOComeTimePeriod NVARCHAR(50),
@InvoiceType NVARCHAR(10),
@VendorInfoTag NVARCHAR(255),
@MerchantName NVARCHAR(255),
@MerchantSysNo INT,
@SuitName NVARCHAR(300),
@CellPhone CHAR(11),
@SOTrucTotal DECIMAL(19,2),--合计
@CurrentSOTrucTotal DECIMAL(19,2),
@MailBottom NVARCHAR(max),
@BottomFullDateTime NVARCHAR(15),
@CustomerID NVARCHAR(250)
--自定义SOMaster
DECLARE @SOMaster TABLE(
SysNo int,--产品ID
CustomerSysNO NVARCHAR(20),--产品编号
ReceiveContact NVARCHAR(200),--产品名称
CashPay decimal(19, 2),--,--产品数量
OrderDate datetime,
--Price decimal(19, 2)--产品价格
PayPrice decimal(19, 2)
,PremiumAmt decimal(19, 2)
,DiscountAmt decimal(19, 2)
,GiftCardPay decimal(19, 2)
,PrepayAmt decimal(19, 2)
,ShipPrice decimal(19, 2)
,CompanyCode CHAR(50)
,StoreCompanyCode VARCHAR(50)
,LanguageCode CHAR(5)
)
IF(exists(select * from IPP3.dbo.SO_Master where SysNo=@SOCode))
BEGIN
insert into @SOMaster(SysNo,
CustomerSysNO,
ReceiveContact,
CashPay,
OrderDate
,PayPrice
,PremiumAmt
,DiscountAmt
,GiftCardPay
,PrepayAmt
,ShipPrice
,CompanyCode
,StoreCompanyCode
,LanguageCode)
select SysNo,CustomerSysNo,ReceiveContact,CashPay,OrderDate,PayPrice,PremiumAmt
,DiscountAmt
,GiftCardPay
,PrepayAmt
,ShipPrice
,CompanyCode
,StoreCompanyCode
,LanguageCode
from IPP3.dbo.SO_Master where SysNo=@SOCode
END
ELSE
BEGIN
insert into @SOMaster(SysNo,
CustomerSysNO,
ReceiveContact,
CashPay,
OrderDate
,PayPrice
,PremiumAmt
,DiscountAmt
,GiftCardPay
,PrepayAmt
,ShipPrice
,CompanyCode
,StoreCompanyCode
,LanguageCode)
select SysNo,
CustomerSysNO,
ReceiveContact,
CashPay,
OrderDate
,PayPrice
,PremiumAmt
,DiscountAmt
,GiftCardPay
,PrepayAmt
,ShipPrice
,CompanyCode
,StoreCompanyCode
,LanguageCode
from OverseaOrderManagement.dbo.V_EC_SOMaster_Buffer_V1 WITH(NOLOCK)
where SysNo=@SOCode
END
select @CustomerEmail=us.Email, @CustomerID=us.CustomerID,
@SOSysNO=so.SysNo,@CustomerSysNO=so.CustomerSysNO,@RecevierContact = so.ReceiveContact,
@Price=so.CashPay,@SoDate=so.OrderDate,
@SOAmount=(so.CashPay+so.PayPrice+so.PremiumAmt+so.DiscountAmt-so.GiftCardPay-so.PrepayAmt),
@SODiscountAMT=so.GiftCardPay+so.PrepayAmt,
@SOShipPrice=so.ShipPrice,
@CompanyCode = so.CompanyCode,
@StoreCompanyCode = so.StoreCompanyCode,
@LanguageCode = so.LanguageCode
--from OverseaOrderManagement.dbo.V_EC_SOMaster_Buffer_V1 so, IPP3.dbo.Customer us WITH(NOLOCK)
from @SOMaster so, IPP3.dbo.Customer us WITH(NOLOCK)
where so.SysNo=@SOCode and so.CustomerSysNo=us.SysNo
select @SOType=SOType from IPP3.dbo.SO_CheckShipping where SOSysNo=@SOCode
select @SONetPay=PayAmount from IPP3.dbo.Advance_NetPay where SOSysNo=@SOCode
--select @SOSysNO=so.SysNo,@CustomerSysNO=so.CustomerSysNO,@CustomerEmail=us.Email, @CustomerID=us.CustomerID,@RecevierContact = so.ReceiveContact,
--@Price=so.CashPay,@SoDate=so.OrderDate,@SOAmount=so.SOAmt,@SODiscountAMT=so.DiscountAmt,@SOShipPrice=so.ShipPrice,
--@CompanyCode = so.CompanyCode,@StoreCompanyCode = so.StoreCompanyCode,@LanguageCode = so.LanguageCode
-- from IPP3.dbo.SO_Master so, IPP3.dbo.Customer us WITH(NOLOCK)
-- where so.SysNo=@SOCode and so.CustomerSysNo=us.SysNo
--设置邮件头部分
SET @MailHeader=N' <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>elleshop_Chuku_mail</title>
<style type="text/css">
*{ margin:0; padding:0; font-size:12px; line-height: 1.5em;}
body{ font-size:12px; color:#000; font-family:Arial, Helvetica, sans-serif;}
a,a:link,a:hover{ text-decoration:none;}
img{ border:0;}
</style>
</head>
<body>
<table border="0" width="639" align="center" cellpadding="0" cellspacing="0" style="width:639px; margin:0 auto; font-size:12px; color:#000; font-family:Arial, Helvetica, sans-serif">
<tr>
<td><table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="277" rowspan="2" style="font-size:12px; color:#000; font-family:Arial, Helvetica, sans-serif;"><a href="http://www.elleshop.com.cn/">
<img src="http://www.elleshop.com.cn.qa/webresources/default/Nest/elleshopemail/elleshop_logo.gif" alt="China ElleShop" width="277" height="119" /></a></td>
<td width="215" rowspan="2" style="font-size:12px; color:#000; font-family:Arial, Helvetica, sans-serif;">
<img src="http://www.elleshop.com.cn.qa/webresources/default/Nest/elleshopemail/elleshop_mail_top_people.jpg" alt="" width="215" height="119" /></td>
<td width="147" height="76" align="right" valign="bottom" style="font-size:12px; line-height: 22px; color:#000; font-family:Arial, Helvetica, sans-serif;">
</tr>
<tr>
<td align="right" valign="bottom"><a href="http://www.elleshop.com.cn.qa/">
<img src="http://www.elleshop.com.cn.qa/webresources/default/Nest/elleshopemail/elleshop_main_top_back.gif" alt="返回ELLEshop首页" /></a></td>
</tr>
</table><img src="http://www.elleshop.com.cn.qa/webresources/default/Nest/elleshopemail/elleshop_mail_topline.gif" alt="" /></td>
</tr>
<tr>
<td>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td style="padding-left:11px; width: 610px;"><p style="margin-top:15px;font-size:12px">Dear<span style="font-size:12px"> </span>[CreatedOrderUserEmail],</p>
<p style="padding-top:10px;">您在ELLEshop网上商城(http://www.elleshop.com.cn/)的订单已支付成功!</p>
<p style="padding-top:10px;"><a href="http://www.elleshop.com.cn.qa/myelleshop/order" style="font-family: Arial, Helvetica, sans-serif; font-size:12px; color: #000000">点击此处查看订单>></a></p></td>
</tr>
</table>
</td>
</tr>
';
SET @MailHeader = REPLACE(@MailHeader,'[CreatedOrderUserEmail]',ISNULL(@CustomerID,''));
--SET @MailHeader = REPLACE(@MailHeader,'[SOID]',@SOCode);
--设置邮件收货人信息
SET @RecevierInfo=N'<tr>
<td>
<table border="0" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td colspan="3" style="border-bottom:1px solid #676767; font-family:Arial,宋体; padding-top:29px; font-weight:bold; padding-left:11px; padding-bottom:5px;">订单信息:
</td>
</tr>
<tr>
<td width="136" style="padding-left:11px; color:#676767; width:125px; padding-top:23px;white-space:nowrap;">订单编号:<span style="color:#fe0000;">[SOIDTag]</span></td>
<td style="color:#676767; text-align:center; padding-top:23px; padding-right:10px;white-space:nowrap;">收货人:[CreatedOrderUserEmail]</td>
<td width="166" style="color:#676767; width:166px; padding-top:23px;white-space:nowrap;">下单时间:<span style="color:#fe0000;">[SOCreateDateTag]</span></td>
</tr>
</table>
</td>
</tr>';
IF (ISNULL(@SOCode,'')<>'')
BEGIN
--订单编号
--set @SOCode = @SOSysNO
SET @RecevierInfo=REPLACE(@RecevierInfo,N'[SOIDTag]',@SOCode)
--收货人
SET @RecevierContact=REPLACE(@RecevierContact,'<','<')
SET @RecevierContact=REPLACE(@RecevierContact,'>','>')
SET @RecevierInfo = REPLACE(@RecevierInfo,N'[CreatedOrderUserEmail]',ISNULL(@RecevierContact,@CustomerID))
--预定金额
set @Price=REPLACE(@Price,'<','<')
set @Price=REPLACE(@Price,'>','>')
SET @RecevierInfo = REPLACE(@RecevierInfo,N'[CreatedOrderPrice]',ISNULL(@Price,0.00))
--下单时间
SET @SoDateString = CONVERT(NVARCHAR(16), @SODate,20)
SET @RecevierInfo=REPLACE(@RecevierInfo,N'[SOCreateDateTag]',@SoDateString)
END
ELSE
BEGIN
RAISERROR(N'SendSOMail Error: SOID is null or 0!', 11, 1);
END
--设置商品信息
DECLARE @ProductHeader NVARCHAR(MAX),
@ProductBottom NVARCHAR(MAX),
@ProductContentTemplate NVARCHAR(MAX)
--IF @SOType=8
-- BEGIN
-- SET @ProductHeader=N'<tr>
-- <td style="padding-top:29px;">
-- <table border="0" cellspacing="0" cellpadding="0" style="width:639px;">
-- <tr>
-- <td width="280" colspan="2" style="border-bottom:1px solid #676767; font-family:Arial,宋体; font-weight:bold; padding-left:11px; width:280px; padding-bottom:5px; border-top: 1px solid #676767; padding-top: 5px;">商品信息</td>
-- <td width="116" style="border-bottom:1px solid #676767; font-family:Arial,宋体; font-weight:bold; width:116px; padding-bottom:5px; border-top: 1px solid #676767; padding-top: 5px;">订金</td>
-- <td width="116" style="border-bottom:1px solid #676767; font-family:Arial,宋体; font-weight:bold; width:116px; padding-bottom:5px; border-top: 1px solid #676767; padding-top: 5px;">数量</td>
-- <td width="116" style="border-bottom:1px solid #676767; font-family:Arial,宋体; font-weight:bold; width:116px; padding-bottom:5px; border-top: 1px solid #676767; padding-top: 5px;">小计</td>
-- </tr>';
-- END
--ELSE
-- BEGIN
SET @ProductHeader=N'<tr>
<td style="padding-top:29px;">
<table border="0" cellspacing="0" cellpadding="0" style="width:639px;">
<tr>
<td width="280" colspan="2" style="border-bottom:1px solid #676767; font-family:Arial,宋体; font-weight:bold; padding-left:11px; width:280px; padding-bottom:5px; border-top: 1px solid #676767; padding-top: 5px;">商品信息</td>
<td width="116" style="border-bottom:1px solid #676767; font-family:Arial,宋体; font-weight:bold; width:116px; padding-bottom:5px; border-top: 1px solid #676767; padding-top: 5px;">售价</td>
<td width="116" style="border-bottom:1px solid #676767; font-family:Arial,宋体; font-weight:bold; width:116px; padding-bottom:5px; border-top: 1px solid #676767; padding-top: 5px;">数量</td>
<td width="116" style="border-bottom:1px solid #676767; font-family:Arial,宋体; font-weight:bold; width:116px; padding-bottom:5px; border-top: 1px solid #676767; padding-top: 5px;">小计</td>
</tr>';
-- END
--SO Item List底部汇总信息
--IF @SOType=8
--BEGIN
-- --预售订单,显示"预定金额","实付金额"
-- SET @ProductBottom = N'<tr>
-- <td colspan="5" style="font-size:0; line-height:0; height:6px;"></td>
-- </tr>
-- </table>
-- <table border="0" width="100%" cellpadding="0" cellspacing="0">
-- <tr>
-- <td width="131" style="width:131px; padding-top:10px; padding-bottom:10px; border-bottom:1px solid #676767; border-top:1px solid #676767;"><strong style="color:#000000;[PreOrderDisplayTag]">预定金额::¥ [PreOrderMoneyTag]元</strong></td>
-- <td width="160" style=" width:160px; padding-top:10px; padding-bottom:10px; border-bottom:1px solid #676767; border-top:1px solid #676767;"><strong style="color:#000000;">实付金额:<span style="color:#ff0707;">¥ [SOPayAmountTag]元</span></strong></td>
-- </tr>
-- </table>
-- </td>
--</tr>'
--END
--ELSE
--BEGIN
--非预售订单,显示"订单总金额","促销优惠","快递费","实付金额"
SET @ProductBottom = N'<tr>
<td colspan="5" style="font-size:0; line-height:0; height:6px;"></td>
</tr>
</table>
<table border="0" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="172" style="padding-left:11px; width:161px; padding-top:10px; padding-bottom:10px;border-bottom:1px solid #676767; border-top:1px solid #676767;[PreOrderDisplayTag]"><strong style="color:#000000;">订单总金额:¥ [SOAmountTag]</strong></td>
<td width="176" style="width:176px; padding-top:10px; padding-bottom:10px; border-bottom:1px solid #676767; border-top:1px solid #676767;"><strong style="color:#000000;[PreOrderDisplayTag]">促销优惠(含订金):¥ -[SODiscountTag]</strong></td>
<td width="131" style="width:131px; padding-top:10px; padding-bottom:10px; border-bottom:1px solid #676767; border-top:1px solid #676767;"><strong style="color:#000000;[PreOrderDisplayTag]">快递费:¥ [SOShipPriceTag]</strong></td>
<td width="160" style=" width:160px; padding-top:10px; padding-bottom:10px; border-bottom:1px solid #676767; border-top:1px solid #676767;"><strong style="color:#000000;">应付金额:<span style="color:#ff0707;">¥ [SOPayAmountTag]</span></strong></td>
</tr>
</table>
</td>
</tr>'
-- END
--预定金额
--SET @ProductBottom=REPLACE(@ProductBottom,'[PreOrderMoneyTag]',ISNULL(@SOAmount,0.00));
--订单总金额--应付金额
SET @ProductBottom=REPLACE(@ProductBottom,'[SOAmountTag]',ISNULL(@SOAmount,0.00));
--促销优惠
IF @SOType=8
BEGIN
SET @SODiscountAMT = @SODiscountAMT + @SONetPay;
SET @ProductBottom=REPLACE(@ProductBottom,'[SODiscountTag]',ISNULL(@SODiscountAMT,0.00));
End
ELSE
BEGIN
SET @ProductBottom=REPLACE(@ProductBottom,'[SODiscountTag]',ISNULL(@SODiscountAMT,0.00));
END
--快递费
SET @ProductBottom=REPLACE(@ProductBottom,'[SOShipPriceTag]',ISNULL(@SOShipPrice,0.00));
--实付金额
DECLARE @PayAmount DECIMAL(19,2)
--SELECT @PayAmount=SUM(PayAmount) FROM IPP3.dbo.Advance_NetPay WITH(NOLOCK)
--WHERE SOSysNo=@SOSysNO
--SELECT @PayAmount=ISNULL(@PayAmount,0.00)+SUM(PayAmount) FROM IPP3.dbo.Finance_NetPay WITH(NOLOCK)
--WHERE SOSysNo=@SOSysNO
SET @PayAmount=@SOAmount-@SODiscountAMT+@SOShipPrice;
SET @ProductBottom=REPLACE(@ProductBottom,'[SOPayAmountTag]',ISNULL(@PayAmount,0.00));
--新SO_Item
DECLARE @NewSOItem TABLE(
SOSysNo int,
ProductSysNo int,
Quantity int,
Price decimal(19, 2)
)
IF(exists(select * from IPP3.dbo.SO_Item where SOSysNo = @SOCode))
BEGIN
insert into @NewSOItem(SOSysNo,ProductSysNo,Quantity,Price)
select SOSysNo,ProductSysNo,Quantity,Price
from IPP3.dbo.SO_Item where SOSysNo=@SOCode
END
ELSE
BEGIN
insert into @NewSOItem(SOSysNo,ProductSysNo,Quantity,Price)
select SOSysNo,ProductSysNo,Quantity,Price
from OverseaOrderManagement.dbo.V_EC_SOItem_Buffer_V1 WITH(NOLOCK)
where SOSysNo=@SOCode
END
--购买产品
DECLARE @SOItemList TABLE(
ProductID int,--产品ID
ProductCode NVARCHAR(20),--产品编号
BriefName NVARCHAR(200),--产品名称
Quantity int,--,--产品数量
Price decimal(19, 2)--产品价格
)
insert into @SOItemList(ProductID,ProductCode,BriefName,Quantity,Price)
select so.ProductSysNo,pro.ProductID,pro.BriefName,so.Quantity,so.Price
--from IPP3.dbo.SO_Item as so with(NOLOCK)
--inner join IPP3.dbo.SO_Master as som with(NOLOCK) on som.SysNo=so.SOSysNo
--from OverseaOrderManagement.dbo.V_EC_SOItem_Buffer_V1 as so with(NOLOCK)
--inner join OverseaOrderManagement.dbo.V_EC_SOMaster_Buffer_V1 as som with(NOLOCK) on som.SysNo=so.SOSysNo
from @NewSOItem so
inner join @SOMaster som on som.SysNo=so.SOSysNo
inner join IPP3.dbo.Product pro on so.ProductSysNo=pro.SysNo
where som.SysNO=@SOCode
--DECLARE CursorSOItem CURSOR STATIC FORWARD_ONLY FOR
DECLARE CursorSOItem CURSOR FOR
SELECT ProductID,ProductCode,BriefName,Quantity,Price FROM @SOItemList
SET @ProductContent =''
OPEN CursorSOItem
FETCH NEXT FROM CursorSOItem INTO @ProductSysNo,@ProductCode,@BriefName,@Quantity,@Price--,@BrandName
WHILE @@FETCH_STATUS=0
BEGIN
--商品信息模板
SET @ProductContentTemplate = N'<tr>
<td colspan="5" style="font-size:0; line-height:0; height:6px;"></td>
</tr>
<tr style="background:#ececec;">
<td width="80" align="left" valign="top" style=" padding-left:11px;">
<table width="80" border="0" cellspacing="0" cellpadding="0">
<tr>
<td style="padding-top:6px; padding-bottom:10px;width:80px"><a href="[ProductDetailLink]"><img src="[ProductImageTag]" width="70" height="105" /></a></td>
</tr>
</table>
</td>
<td width="17" align="left" valign="top" style="width:175px; padding-left: 10px;padding-right:15px; padding-bottom:15px;">
<table width="175" border="0" align="left" cellpadding="0" cellspacing="0">
<tr>
<td style=" padding-top:20px;color:#000;"><strong>[BrandNameTag]</strong></td>
</tr>
<tr>
<td style=" line-height:22px; color:#676767;"><a style="color:#676767;" href="[ProductDetailLink]">[BriefNameTag]</a></td>
</tr>
<tr>
<td style=" line-height:22px; color:#676767;">[PropertyDesc1Tag][PropertyValue1Tag]</td>
</tr>
<tr>
<td style=" line-height:22px; color:#676767;">[PropertyDesc2Tag][PropertyValue2Tag]</td>
</tr>
</table>
</td>
<td valign="top" style="width:116px;">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td style="color:#000; padding-top:20px;"><strong>¥[PriceTag]</strong></td>
</tr>
</table>
</td>
<td valign="top" style="width:116px;"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td style="color:#000; padding-top:20px;"><strong>[QuantityTag]</strong></td>
</tr>
</table></td>
<td valign="top" style="width:116px;"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td style="color:#000; padding-top:20px;"><strong>¥[SubTotalTag]</strong></td>
</tr>
</table></td>
</tr>';
--定义产品图片变量
DECLARE @ProductImageTag NVARCHAR(300),@ProductDetailLink NVARCHAR(100),
@ProductCodePart1 NVARCHAR(15);
SET @ProductCodePart1 = @ProductCode
--商品图片
DECLARE @CharIndex INT
SET @CharIndex = CHARINDEX(N'_',@ProductCode);
IF @CharIndex > 0
BEGIN
SET @ProductCodePart1=SUBSTRING(@ProductCode,0,@CharIndex);
END
SET @ProductImageTag = N'http://www.elleshop.com.cn.qa:8801/IPPCMSUploadFiles/neweggpic2/neg/P80/'+@ProductCodePart1+N'.jpg';
set @ProductDetailLink=N'http://www.elleshop.com.cn.qa/product/'+@ProductCode+'.htm'
--商品名称
SET @ProductContentTemplate = REPLACE(@ProductContentTemplate, N'[BriefNameTag]', ISNULL(@BriefName,''));
SET @ProductContentTemplate = REPLACE(@ProductContentTemplate, N'[ProductDetailLink]',@ProductDetailLink);
--商品单价
SET @ProductContentTemplate = REPLACE(@ProductContentTemplate, N'[PriceTag]', ISNULL(@Price,''));
--商品数量
SET @ProductContentTemplate = REPLACE(@ProductContentTemplate, N'[QuantityTag]', ISNULL(@Quantity,''));
--小计
SET @ProductContentTemplate = REPLACE(@ProductContentTemplate, N'[SubTotalTag]', @Quantity *@Price);
--商品图片
SET @ProductContentTemplate = REPLACE(@ProductContentTemplate, N'[ProductImageTag]', ISNULL(@ProductImageTag,''));
--商品品牌与属性
DECLARE @GROUPSYSNO INT
DECLARE @BRANDSYSNO INT
DECLARE @BRANDNAME NVARCHAR(100)
DECLARE @PROPERTYDESC1 NVARCHAR(100)
DECLARE @PROPERTYDESC2 NVARCHAR(100)
DECLARE @PROPERTYVALUE1 NVARCHAR(100)
DECLARE @PROPERTYVALUE2 NVARCHAR(100)
SELECT TOP 1 @GROUPSYSNO=ProductGroupSysno
FROM OverseaContentManagement.dbo.ProductCommonInfo AS C
LEFT JOIN IPP3.DBO.PRODUCT AS P
ON C.SYSNO=P.ProductCommonInfoSysno
WHERE P.SYSNO=@ProductSysNo
--品牌
SELECT TOP 1
@BRANDSYSNO = BrandSysno,@BRANDNAME = B.BrandName_Ch
FROM OverseaContentManagement.dbo.ProductGroupInfo AS G
LEFT JOIN OverseaContentManagement.dbo.Brand AS B
ON G.BrandSysno=B.SysNo
WHERE G.SYSNO=@GROUPSYSNO
SET @ProductContentTemplate= REPLACE(@ProductContentTemplate,N'[BrandNameTag]',ISNULL(@BRANDNAME,''));
--属性
SELECT TOP 1 @PROPERTYDESC1 = PropertyDescription1
, @PROPERTYVALUE1 = ValueDescription1
,@PROPERTYDESC2 = PropertyDescription2
,@PROPERTYVALUE2 = ValueDescription2
FROM [IPP3].[DBO].[V_EC_ProductPropertyList]
WHERE ProductGroupSysno=@GROUPSYSNO
IF @PROPERTYDESC1 <> NULL OR LEN(@PROPERTYDESC1)>0
BEGIN
SET @PROPERTYDESC1= @PROPERTYDESC1 + N':';
END
IF @PROPERTYDESC2 <> NULL OR LEN(@PROPERTYDESC2)>0
BEGIN
SET @PROPERTYDESC2 =@PROPERTYDESC2 + N':';
END
SET @ProductContentTemplate = REPLACE(@ProductContentTemplate,N'[PropertyDesc1Tag]', ISNULL(@PROPERTYDESC1,''))
SET @ProductContentTemplate = REPLACE(@ProductContentTemplate,N'[PropertyDesc2Tag]', ISNULL(@PROPERTYDESC2,''))
SET @ProductContentTemplate = REPLACE(@ProductContentTemplate,N'[PropertyValue1Tag]', ISNULL(@PROPERTYVALUE1,''))
SET @ProductContentTemplate = REPLACE(@ProductContentTemplate,N'[PropertyValue2Tag]', ISNULL(@PROPERTYVALUE2,''))
SET @ProductContent=@ProductContent + @ProductContentTemplate;
FETCH NEXT FROM CursorSOItem INTO @ProductSysNo,@ProductCode,@BriefName,@Quantity,@Price
END
CLOSE CursorSOItem
DEALLOCATE CursorSOItem
SET @MailBottom=N'<tr>
<td style=" height:1px; font-size:1px"> </td>
</tr>
<tr>
<td style="padding-top:19px; text-align: center" align="center"><div style="background-color:#ececec"><img src="http://www.elleshop.com.cn.qa/webresources/default/Nest/elleshopemail/elleshop_mail_seriveinfo.gif" alt="本邮件由ELLEshop系统自动发出,请勿直接回复! 如果您有任何疑问或建议,请联系我们 [email protected]" width="639" height="68" /></div></td>
</tr>
<tr>
<td style="padding-top:17px; padding-bottom:12px; text-align: center" align="center">
<div style="background-color:#cc1616">
<a href="http://weibo.com/elleshop%22%3E%3Cimg src="http://www.elleshop.com.cn.qa/webresources/default/Nest/elleshopemail/img_mblog_sina.gif" width="314" height="43" alt="新浪微博:http://weibo.com/elleshop" /></a><a href="http://t.qq.com/elleshop9470%22%3E%3Cimg src="http://www.elleshop.com.cn.qa/webresources/default/Nest/elleshopemail/img_mblog_tencent.gif" width="325" height="43" alt="腾讯微博:http://t.qq.com/elleshop9470" /></a>
</div>
</td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center" style="text-align:center;background: #000;">
<table width="639" border="0" align="center" cellpadding="0" cellspacing="0" style="width:639px;margin-left:auto; margin-right:auto">
<tr>
<td width="639" align="center" style="width: 639px;font-size: 12px;text-align:center; color:#8b8b8b; height:20px; padding-top: 3px; padding-bottom: 3px; line-height:20px; background: #000; color:#fff;">
<span>Copyright © [CopyrightYear] ELLEshop.com.cn</span><span style="padding-left:10px">All rights reserved.</span><span style="padding-left:10px">北京比尔得广告有限公司</span><span style="padding-left:10px">版权所有京ICP证060525号</span></td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>';
--邮件尾部版权日期
SET @MailBottom = REPLACE(@MailBottom,N'[CopyrightYear]', CONVERT(VARCHAR(4),GETDATE(),112));
--合并邮件内容
SET @MailBody=@MailHeader+@RecevierInfo+@ProductHeader+@ProductContent+@ProductBottom+@MailBottom
--PRINT @MailBody
IF (ISNULL(@MailBody,N'')<>'' AND ISNULL(@CustomerEmail,'')<>'')
BEGIN
SET @MailSubject=N'您在ELLEshop的订单SO#'+CONVERT(NVARCHAR(50),@SOCode)+N'--已支付成功'
DECLARE @Status INT
SET @Status=0
INSERT INTO MailDB.dbo.AsyncEmail(
MailAddress,
MailSubject,
MailBody,
Status,
LanguageCode,
CompanyCode,
StoreCompanyCode)
VALUES(
@CustomerEmail,
@MailSubject,
CONVERT(Text, @MailBody),
@Status,
@LanguageCode,
@CompanyCode,
@StoreCompanyCode)
END
END