SET NUMERIC_ROUNDABORT OFF
GO
SET ANSI_PADDING, ANSI_WARNINGS, CONCAT_NULL_YIELDS_NULL, ARITHABORT, QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
IF EXISTS (SELECT * FROM tempdb..sysobjects WHERE id=OBJECT_ID('tempdb..#tmpErrors')) DROP TABLE #tmpErrors
GO
CREATE TABLE #tmpErrors (Error int)
GO
SET XACT_ABORT ON
GO
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
GO
BEGIN TRANSACTION
GO
PRINT N'Altering [dbo].[PE_Comment]'
GO
ALTER TABLE [dbo].[PE_Comment] ADD
[ReferenceId] [int] NULL,
[IsTop] [bit] NULL
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Altering [dbo].[PE_PayPlatForm]'
GO
ALTER TABLE [dbo].[PE_PayPlatForm] ADD
[PayPlatformIcon] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL,
[Remark] [ntext] COLLATE Chinese_PRC_CI_AS NULL
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Altering [dbo].[PR_Accessories_PayPlatform_Update]'
GO
ALTER PROCEDURE [dbo].[PR_Accessories_PayPlatform_Update]
    (
      @PayPlatformID INT ,
      @PayPlatformName NVARCHAR(100) ,
      @AccountsID NVARCHAR(100) ,
      @MD5 NVARCHAR(200) ,
      @Rate DECIMAL(18, 10) ,
      @OrderID INT ,
      @IsDisabled BIT ,
      @IsDefault BIT,
      @PayPlatformIcon NVARCHAR(255),
      @Remark NTEXT
    )
AS 
    IF @IsDefault = 1 
        BEGIN
            UPDATE  PE_PayPlatform
            SET     [IsDefault] = 0
            WHERE   [IsDefault] = 1
        END
 
    UPDATE  PE_PayPlatform
    SET     [PayPlatformName] = @PayPlatformName ,
            [AccountsID] = @AccountsID ,
            [MD5] = @MD5 ,
            [Rate] = @Rate ,
            [OrderID] = @OrderID ,
            [IsDisabled] = @IsDisabled ,
            [IsDefault] = @IsDefault,
            [PayPlatformIcon] = @PayPlatformIcon,
            [Remark] = @Remark
    WHERE   [PayPlatformID] = @PayPlatformID
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Altering [dbo].[PR_Accessories_PayPlatform_Add]'
GO
ALTER PROCEDURE [dbo].[PR_Accessories_PayPlatform_Add]
    (
      @PayPlatformID INT ,
      @PayPlatformName NVARCHAR(100) ,
      @AccountsID NVARCHAR(100) ,
      @MD5 NVARCHAR(200) ,
      @Rate NUMERIC(18, 2) ,
      @IsDisabled BIT ,
      @IsDefault BIT,
      @PayPlatformIcon nvarchar(255),
      @Remark NTEXT
    )
AS 
    DECLARE @TempID INT
    SELECT  @TempID = ( ISNULL(MAX(OrderId), 0) + 1 )
    FROM    PE_PayPlatform
    IF @IsDefault = 1 
        BEGIN
            UPDATE  PE_PayPlatform
            SET     [IsDefault] = 0
            WHERE   [IsDefault] = 1
        END	
    SET NOCOUNT OFF 
    INSERT  INTO PE_PayPlatform
            ( [PayPlatformID] ,
              [PayPlatformName] ,
              [AccountsID] ,
              [MD5] ,
              [Rate] ,
              [OrderID] ,
              [IsDisabled] ,
              [IsDefault],
              [PayPlatformIcon],
              [Remark]
		)
    VALUES  ( @PayPlatformID ,
              @PayPlatformName ,
              @AccountsID ,
              @MD5 ,
              @Rate ,
              @TempID ,
              @IsDisabled ,
              @IsDefault,
              @PayPlatformIcon,
              @Remark
		)
    RETURN
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Altering [dbo].[PE_Orders]'
GO
ALTER TABLE [dbo].[PE_Orders] ADD
[GroupBuyID] [int] NULL,
[IsNotice] [bit] NULL,
[SecondsKillID] [int] NULL
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Altering [dbo].[PR_Shop_Order_Add]'
GO
ALTER PROCEDURE [dbo].[PR_Shop_Order_Add]
    (
      @OrderID INT ,
      @OrderNum NVARCHAR(20) ,
      @UserName NVARCHAR(100) ,
      @AgentName NVARCHAR(50) ,
      @Functionary NVARCHAR(50) ,
      @ClientID INT ,
      @MoneyTotal MONEY ,
      @MoneyGoods MONEY ,
      @NeedInvoice BIT ,
      @InvoiceContent NTEXT ,
      @Invoiced BIT ,
      @MoneyReceipt MONEY ,
      @BeginDate DATETIME ,
      @InputTime DATETIME ,
      @ContacterName NVARCHAR(50) ,
      @Address NVARCHAR(255) ,
      @ZipCode NVARCHAR(10) ,
      @Mobile NVARCHAR(50) ,
      @Phone NVARCHAR(50) ,
      @Email NVARCHAR(50) ,
      @PaymentType INT ,
      @DeliverType INT ,
      @Status INT ,
      @DeliverStatus INT ,
      @EnableDownload BIT ,
      @PresentMoney MONEY ,
      @PresentPoint INT ,
      @PresentExp INT ,
      @Discount_Payment FLOAT ,
      @Charge_Deliver MONEY ,
      @Memo NTEXT ,
      @OrderType INT ,
      @CouponID INT ,
      @OrderKind INT,
      @GroupBuyID INT,
      @IsNotice BIT,
	  @SecondsKillID INT
    )
AS 
    INSERT  INTO [PE_Orders]
            ( [OrderID] ,
              [OrderNum] ,
              [UserName] ,
              [AgentName] ,
              [Functionary] ,
              [ClientID] ,
              [MoneyTotal] ,
              [MoneyGoods] ,
              [NeedInvoice] ,
              [InvoiceContent] ,
              [Invoiced] ,
              [MoneyReceipt] ,
              [BeginDate] ,
              [InputTime] ,
              [ContacterName] ,
              [Address] ,
              [ZipCode] ,
              [Mobile] ,
              [Phone] ,
              [Email] ,
              [PaymentType] ,
              [DeliverType] ,
              [Status] ,
              [DeliverStatus] ,
              [EnableDownload] ,
              [PresentMoney] ,
              [PresentPoint] ,
              [PresentExp] ,
              [Discount_Payment] ,
              [Charge_Deliver] ,
              [Memo] ,
              [OrderType] ,
              [CouponID] ,
              [OrderKind],
              [GroupBuyID],
              [IsNotice],
			  [SecondsKillID]
		)
    VALUES  ( @OrderID ,
              @OrderNum ,
              @UserName ,
              @AgentName ,
              @Functionary ,
              @ClientID ,
              @MoneyTotal ,
              @MoneyGoods ,
              @NeedInvoice ,
              @InvoiceContent ,
              @Invoiced ,
              @MoneyReceipt ,
              @BeginDate ,
              @InputTime ,
              @ContacterName ,
              @Address ,
              @ZipCode ,
              @Mobile ,
              @Phone ,
              @Email ,
              @PaymentType ,
              @DeliverType ,
              @Status ,
              @DeliverStatus ,
              @EnableDownload ,
              @PresentMoney ,
              @PresentPoint ,
              @PresentExp ,
              @Discount_Payment ,
              @Charge_Deliver ,
              @Memo ,
              @OrderType ,
              @CouponID ,
              @OrderKind,
              @GroupBuyID,
              @IsNotice,
			  @SecondsKillID
	      )
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Altering [dbo].[PE_OrderItem]'
GO
ALTER TABLE [dbo].[PE_OrderItem] ADD
[GroupBuyID] [int] NULL,
[SecondsKillID] [int] NULL
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Altering [dbo].[PE_CommonProduct]'
GO
ALTER TABLE [dbo].[PE_CommonProduct] ADD
[SubTitle] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Altering [dbo].[PE_Client]'
GO
ALTER TABLE [dbo].[PE_Client] ALTER COLUMN [IsBusiness] [int] NULL
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Altering [dbo].[PR_Crm_Client_Update]'
GO
ALTER PROCEDURE [dbo].[PR_Crm_Client_Update]
    (
      @ClientID INT ,
      @ParentID INT ,
      @ClientNum NVARCHAR(20) ,
      @ClientType INT ,
      @ClientName NVARCHAR(100) ,
      @ShortedForm NVARCHAR(20) ,
      @Area INT ,
      @ClientField INT ,
      @ValueLevel INT ,
      @CreditLevel INT ,
      @Importance INT ,
      @ConnectionLevel INT ,
      @GroupID INT ,
      @SourceType INT ,
      @PhaseType INT ,
      @Remark NTEXT ,
      @UpdateTime DATETIME ,
      @Owner NVARCHAR(50) ,
      @IsBusiness INT,
	  @UpdateOwnerTime DATETIME
    )
AS 
    UPDATE  [PE_Client]
    SET     ParentID = @ParentID ,
            ClientNum = @ClientNum ,
            ClientType = @ClientType ,
            ClientName = @ClientName ,
            ShortedForm = @ShortedForm ,
            Area = @Area ,
            ClientField = @ClientField ,
            ValueLevel = @ValueLevel ,
            CreditLevel = @CreditLevel ,
            Importance = @Importance ,
            ConnectionLevel = @ConnectionLevel ,
            GroupID = @GroupID ,
            SourceType = @SourceType ,
            PhaseType = @PhaseType ,
            Remark = @Remark ,
            UpdateTime = @UpdateTime ,
            Owner = @Owner ,
            IsBusiness = @IsBusiness,
			UpdateOwnerTime = @UpdateOwnerTime
    WHERE   ClientID = @ClientID
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Altering [dbo].[PR_Crm_Client_Add]'
GO
ALTER PROCEDURE [dbo].[PR_Crm_Client_Add]
    (
      @ClientID INT ,
      @ParentID INT ,
      @ClientNum NVARCHAR(20) ,
      @ClientType INT ,
      @ClientName NVARCHAR(100) ,
      @ShortedForm NVARCHAR(20) ,
      @Area INT ,
      @ClientField INT ,
      @ValueLevel INT ,
      @CreditLevel INT ,
      @Importance INT ,
      @ConnectionLevel INT ,
      @GroupID INT ,
      @SourceType INT ,
      @PhaseType INT ,
      @Remark NTEXT ,
      @CreateTime DATETIME ,
      @UpdateTime DATETIME ,
      @Owner NVARCHAR(50) ,
      @IsBusiness INT,
	  @UpdateOwnerTime DATETIME
	
    )
AS 
    INSERT  INTO [PE_Client]
            ( [ClientID] ,
              [ParentID] ,
              [ClientNum] ,
              [ClientType] ,
              [ClientName] ,
              [ShortedForm] ,
              [Area] ,
              [ClientField] ,
              [ValueLevel] ,
              [CreditLevel] ,
              [Importance] ,
              [ConnectionLevel] ,
              [GroupID] ,
              [SourceType] ,
              [PhaseType] ,
              [Remark] ,
              [CreateTime] ,
              [UpdateTime] ,
              [Owner] ,
              [LastContactedTime] ,
              [IsBusiness] ,
			  [UpdateOwnerTime]
            )
    VALUES  ( @ClientID ,
              @ParentID ,
              @ClientNum ,
              @ClientType ,
              @ClientName ,
              @ShortedForm ,
              @Area ,
              @ClientField ,
              @ValueLevel ,
              @CreditLevel ,
              @Importance ,
              @ConnectionLevel ,
              @GroupID ,
              @SourceType ,
              @PhaseType ,
              @Remark ,
              @CreateTime ,
              @UpdateTime ,
              @Owner ,
              GETDATE() ,
              @IsBusiness,
			  @UpdateOwnerTime
            )
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Altering [dbo].[PR_Crm_Address_Update]'
GO
ALTER PROCEDURE [dbo].[PR_Crm_Address_Update]
    (
      @AddressID INT ,    --地址Id
      @UserName NVARCHAR(100) ,    --用户名
      @ConsigneeName NVARCHAR(255) ,
      @HomePhone NVARCHAR(30) ,    --固定电话
      @Mobile NVARCHAR(30) ,    --移动电话
      @Country NVARCHAR(50) ,    --国家
      @Province NVARCHAR(30) ,    --省份
      @City NVARCHAR(30) ,    --城市
      @Area NVARCHAR(30) ,
      @Address NVARCHAR(255) ,    --详细地址
      @ZipCode NVARCHAR(50),    --邮编
	  @IsDefault BIT
    )
AS 
    UPDATE  [PE_Address]
    SET     [AddressID] = @AddressID ,    --地址Id
            [UserName] = @UserName ,    --用户名
            [ConsigneeName] = @ConsigneeName ,
            [HomePhone] = @HomePhone ,    --固定电话
            [Mobile] = @Mobile ,    --移动电话
            [Country] = @Country ,    --国家
            [Province] = @Province ,    --省份	
            [City] = @City ,    --城市
            [Area] = @Area ,
            [Address] = @Address ,    --详细地址
            [ZipCode] = @ZipCode,    --邮编
			[IsDefault] = @IsDefault
    WHERE   [AddressID] = @AddressID
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Altering [dbo].[PR_Crm_Address_Add]'
GO
ALTER PROCEDURE [dbo].[PR_Crm_Address_Add]
    (
      @AddressID INT ,    --地址Id
      @UserName NVARCHAR(100) ,    --用户名
      @HomePhone NVARCHAR(30) = '' ,    --固定电话
      @Mobile NVARCHAR(30) = '' ,    --移动电话
      @Country NVARCHAR(50) ,    --国家
      @Province NVARCHAR(30) ,    --省份
      @City NVARCHAR(30) = '' ,    --城市
      @Area NVARCHAR(30) = '' ,
      @Address NVARCHAR(255) ,    --详细地址
      @ZipCode NVARCHAR(50) = '' ,    --邮编
      @ConsigneeName NVARCHAR(255) = '',
	  @IsDefault BIT
    )
AS 
    IF @IsDefault<>1 AND NOT EXISTS ( SELECT  *
                    FROM    PE_Address
                    WHERE   UserName = @UserName ) 
        BEGIN
            SET @IsDefault = 1
        END

    INSERT  INTO [PE_Address]
            ( [AddressID] ,    --地址Id
              [UserName] ,    --用户名
              [ConsigneeName] ,
              [HomePhone] ,    --固定电话
              [Mobile] ,    --移动电话
              [Country] ,    --国家
              [Province] ,    --省份
              [City] ,    --城市
              [Area] ,
              [Address] ,    --详细地址
              [ZipCode] ,    --邮编
              [IsDefault]    --是否默认
		)
    VALUES  ( @AddressID ,
              @UserName ,
              @ConsigneeName ,
              @HomePhone ,
              @Mobile ,
              @Country ,
              @Province ,
              @City ,
              @Area ,
              @Address ,
              @ZipCode ,
              @IsDefault
	      )
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Altering [dbo].[PE_Trademark]'
GO
ALTER TABLE [dbo].[PE_Trademark] ADD
[TrademarkShortIntro] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL,
[TrademarkBeginDate] [datetime] NULL,
[TrademarkAdBannerPhoto] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL,
[TrademarkAdMultiPhoto] [nvarchar] (500) COLLATE Chinese_PRC_CI_AS NULL,
[TrademarkAdMiddlePhoto] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Altering [dbo].[PR_Shop_Trademark_Add]'
GO
ALTER PROCEDURE [dbo].[PR_Shop_Trademark_Add]
    (
      @TrademarkName NVARCHAR(200) ,
      @TrademarkType INT ,
      @ProducerID INT ,
      @IsElite BIT ,
      @TrademarkPhoto NVARCHAR(255) ,
      @TrademarkIntro NTEXT,
      @SearchIndex Char(1),
	  @TrademarkShortIntro NVARCHAR(500),
      @TrademarkBeginDate DATETIME,
      @TrademarkAdBannerPhoto NVARCHAR(100) ,
	  @TrademarkAdMultiPhoto NVARCHAR(500) ,
	  @TrademarkAdMiddlePhoto NVARCHAR(100) 
    )
AS 
    INSERT  INTO PE_Trademark
            ( TrademarkName ,
              TrademarkType ,
              ProducerID ,
              IsElite ,
              TrademarkPhoto ,
              TrademarkIntro ,
              Passed,
              SearchIndex,
			  TrademarkShortIntro,
	          TrademarkBeginDate,
              TrademarkAdBannerPhoto,
              TrademarkAdMultiPhoto,
              TrademarkAdMiddlePhoto
            )
    VALUES  ( @TrademarkName ,
              @TrademarkType ,
              @ProducerID ,
              @IsElite ,
              @TrademarkPhoto ,
              @TrademarkIntro ,
              1,
              @SearchIndex,
			  @TrademarkShortIntro,
		      @TrademarkBeginDate,
		      @TrademarkAdBannerPhoto,
		      @TrademarkAdMultiPhoto,
		      @TrademarkAdMiddlePhoto 
            )
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Altering [dbo].[PE_ShoppingCarts]'
GO
ALTER TABLE [dbo].[PE_ShoppingCarts] ADD
[GroupBuyID] [int] NULL,
[SecondsKillID] [int] NULL
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Altering [dbo].[PR_Shop_ShoppingCarts_Add]'
GO
ALTER PROCEDURE [dbo].[PR_Shop_ShoppingCarts_Add]
    (
      @UserName NVARCHAR(100) ,
      @CartID NVARCHAR(50) ,
      @ProductID INT ,
      @Quantity INT ,
      @IsPresent BIT ,
      @UpdateTime DATETIME ,
      @TableName NVARCHAR(200) ,
      @Property NVARCHAR(50) ,
      @BelongsToProductID INT,
	  @GroupBuyID INT,
	  @SecondsKillID INT
    )
AS 
    INSERT  INTO PE_ShoppingCarts
            ( UserName ,
              CartID ,
              ProductID ,
              Quantity ,
              IsPresent ,
              UpdateTime ,
              TableName ,
              Property ,
              BelongsToProductID,
              GroupBuyID,
			  SecondsKillID	
	      )
    VALUES  ( @UserName ,
              @CartID ,
              @ProductID ,
              @Quantity ,
              @IsPresent ,
              @UpdateTime ,
              @TableName ,
              @Property ,
              @BelongsToProductID,
              @GroupBuyID,
			  @SecondsKillID	
	      )
	
    RETURN
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Altering [dbo].[PR_Shop_Trademark_Update]'
GO
ALTER PROCEDURE [dbo].[PR_Shop_Trademark_Update]
    (
      @TrademarkID INT ,
      @TrademarkName NVARCHAR(200) ,
      @TrademarkType INT ,
      @ProducerId INT ,
      @IsElite BIT ,
      @TrademarkPhoto NVARCHAR(255) ,
      @TrademarkIntro NTEXT	,
      @SearchIndex Char(1),
	  @TrademarkShortIntro NVARCHAR(500),
      @TrademarkBeginDate DATETIME,
      @TrademarkAdBannerPhoto NVARCHAR(100) ,
	  @TrademarkAdMultiPhoto NVARCHAR(500) ,
	  @TrademarkAdMiddlePhoto NVARCHAR(100) 
    )
AS 
    UPDATE  PE_Trademark
    SET     TrademarkName = @TrademarkName ,
            TrademarkType = @TrademarkType ,
            ProducerID = @ProducerId ,
            IsElite = @IsElite ,
            TrademarkPhoto = @TrademarkPhoto ,
            TrademarkIntro = @TrademarkIntro,
            SearchIndex=@SearchIndex,
			TrademarkShortIntro=@TrademarkShortIntro,
	        TrademarkBeginDate=@TrademarkBeginDate,
            TrademarkAdBannerPhoto=@TrademarkAdBannerPhoto,
            TrademarkAdMultiPhoto=@TrademarkAdMultiPhoto,
            TrademarkAdMiddlePhoto=@TrademarkAdMiddlePhoto
    WHERE   TrademarkID = @TrademarkID
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Altering [dbo].[PR_Shop_OrderItem_Update]'
GO
ALTER PROCEDURE [dbo].[PR_Shop_OrderItem_Update]
    (
      @ItemID INT ,    --ID
      @OrderID INT ,    --订单ID
      @ProductID INT ,    --产品ID
      @TableName NVARCHAR(255) ,
      @Property NVARCHAR(255) ,
      @SaleType INT ,    --销售类型  1--正常销售  2--换购  3--赠送  4--批发
      @Price_Market MONEY ,    --原价
      @Price MONEY ,    --系统计算出的销售价
      @TruePrice MONEY ,    --实际销售价
      @Amount INT ,    --订购数量
      @SubTotal MONEY ,    --订购金额
      @BeginDate DATETIME ,    --开始计算服务期限日期
      @ServiceTerm INT ,    --服务期限
      @ServiceTermUnit INT ,    --服务年限单位　0－年，1－月，2－日
      @Remark NVARCHAR(255) ,    --备注
      @PresentMoney MONEY ,    --返还的现金券
      @PresentPoint INT ,    --赠送点券
      @PresentExp INT ,   --赠送的积分
      @ProductCharacter INT ,
      @ProductName NVARCHAR(255) ,
      @Unit NVARCHAR(20) ,
      @Weight FLOAT ,
      @TrueAmount INT ,
      @TrueSubTotal MONEY,
      @GroupBuyID INT,
	  @SecondsKillID INT
    )
AS 
    UPDATE  [PE_OrderItem]
    SET     [ItemID] = @ItemID ,    --ID
            [OrderID] = @OrderID ,    --订单ID
            [ProductID] = @ProductID ,    --产品ID
            [TableName] = @TableName ,
            [Property] = @Property ,
            [SaleType] = @SaleType ,    --销售类型  1--正常销售  2--换购  3--赠送  4--批发
            [Price_Market] = @Price_Market ,    --原价
            [Price] = @Price ,    --系统计算出的销售价
            [TruePrice] = @TruePrice ,    --实际销售价
            [Amount] = @Amount ,    --订购数量
            [SubTotal] = @SubTotal ,    --订购金额
            [BeginDate] = @BeginDate ,    --开始计算服务期限日期
            [ServiceTerm] = @ServiceTerm ,    --服务期限
            [ServiceTermUnit] = @ServiceTermUnit ,    --服务年限单位　0－年，1－月，2－日
            [Remark] = @Remark ,    --备注
            [PresentMoney] = @PresentMoney ,    --返还的现金券
            [PresentPoint] = @PresentPoint ,    --赠送点券
            [PresentExp] = @PresentExp ,    --赠送的积分
            [ProductCharacter] = @ProductCharacter ,
            [ProductName] = @ProductName ,
            [Unit] = @Unit ,
            [Weight] = @Weight ,
            [TrueAmount] = @TrueAmount ,
            [TrueSubTotal] = @TrueSubTotal,
            [GroupBuyID]=@GroupBuyID,
			[SecondsKillID]=@SecondsKillID
    WHERE   [ItemID] = @ItemID
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Altering [dbo].[PR_Shop_OrderItem_Add]'
GO
ALTER PROCEDURE [dbo].[PR_Shop_OrderItem_Add]
    (
      @ItemID INT ,
      @OrderID INT ,
      @ProductID INT ,
      @TableName NVARCHAR(255) ,
      @Property NVARCHAR(255) ,
      @SaleType INT ,
      @Price_Market MONEY ,
      @Price MONEY ,
      @TruePrice MONEY ,
      @Amount INT ,
      @SubTotal MONEY ,
      @BeginDate DATETIME ,
      @ServiceTerm INT ,
      @ServiceTermUnit INT ,
      @Remark NVARCHAR(255) ,
      @PresentMoney MONEY ,
      @PresentPoint INT ,
      @PresentExp INT ,
      @ProductCharacter INT ,
      @ProductName NVARCHAR(255) ,
      @Unit NVARCHAR(20) ,
      @Weight FLOAT ,
      @TrueAmount INT ,
      @TrueSubTotal MONEY,
	  @GroupBuyID INT,
	  @SecondsKillID INT
    )
AS 
    INSERT  INTO PE_OrderItem
            ( [ItemID] ,
              [OrderID] ,
              [ProductID] ,
              [TableName] ,
              [Property] ,
              [SaleType] ,
              [Price_Market] ,
              [Price] ,
              [TruePrice] ,
              [Amount] ,
              [SubTotal] ,
              [BeginDate] ,
              [ServiceTerm] ,
              [ServiceTermUnit] ,
              [Remark] ,
              [PresentMoney] ,
              [PresentPoint] ,
              [PresentExp] ,
              [ProductCharacter] ,
              [ProductName] ,
              [Unit] ,
              [Weight] ,
              [TrueAmount] ,
              [TrueSubTotal],
              [GroupBuyID],
			  [SecondsKillID]
            )
    VALUES  ( @ItemID ,
              @OrderID ,
              @ProductID ,
              @TableName ,
              @Property ,
              @SaleType ,
              @Price_Market ,
              @Price ,
              @TruePrice ,
              @Amount ,
              @SubTotal ,
              @BeginDate ,
              @ServiceTerm ,
              @ServiceTermUnit ,
              @Remark ,
              @PresentMoney ,
              @PresentPoint ,
              @PresentExp ,
              @ProductCharacter ,
              @ProductName ,
              @Unit ,
              @Weight ,
              @TrueAmount ,
              @TrueSubTotal,
              @GroupBuyID,
			  @SecondsKillID
            )
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Altering [dbo].[PR_Shop_Trademark_GetById]'
GO
ALTER PROCEDURE [dbo].[PR_Shop_Trademark_GetById] ( @TrademarkID INT )
AS 
    SELECT    TrademarkID ,
            TrademarkName ,
            ProducerID ,
            IsElite ,
            TrademarkType ,
            TrademarkPhoto ,
            TrademarkIntro ,
            Passed ,
            OnTop ,
            IsElite,
            SearchIndex
              TrademarkShortIntro,
	          TrademarkBeginDate,
              TrademarkAdBannerPhoto,
              TrademarkAdMultiPhoto,
              TrademarkAdMiddlePhoto          
    FROM    PE_Trademark
    WHERE   TrademarkID = 1
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Altering [dbo].[PR_Shop_Order_Update]'
GO
ALTER PROCEDURE [dbo].[PR_Shop_Order_Update]
    (
      @OrderID INT ,
      @UserName NVARCHAR(100) ,
      @AgentName NVARCHAR(50) ,
      @Functionary NVARCHAR(50) ,
      @MoneyTotal MONEY ,
      @MoneyGoods MONEY ,
      @NeedInvoice BIT ,
      @InvoiceContent NTEXT ,
      @BeginDate DATETIME ,
      @Address NVARCHAR(255) ,
      @ZipCode NVARCHAR(10) ,
      @Mobile NVARCHAR(50) ,
      @Phone NVARCHAR(50) ,
      @Email NVARCHAR(50) ,
      @PaymentType INT ,
      @DeliverType INT ,
      @Status INT ,
      @Discount_Payment FLOAT ,
      @MoneyReceipt MONEY ,
      @EnableDownload BIT ,
      @DeliverStatus INT ,
      @Charge_Deliver MONEY ,
      @Memo NTEXT ,
      @PresentMoney MONEY ,
      @PresentPoint INT ,
      @PresentExp INT ,
      @OrderType INT ,
      @CouponID INT ,
      @InputTime DATETIME ,
      @ContacterName NVARCHAR(50) ,
      @OrderKind INT,
	  @GroupBuyID INT,
      @IsNotice BIT,
	  @SecondsKillID INT
    )
AS 
    UPDATE  [PE_Orders]
    SET     [UserName] = @UserName ,
            [AgentName] = @AgentName ,
            [Functionary] = @Functionary ,
            [MoneyTotal] = @MoneyTotal ,
            [MoneyGoods] = @MoneyGoods ,
            [NeedInvoice] = @NeedInvoice ,
            [InvoiceContent] = @InvoiceContent ,
            [BeginDate] = @BeginDate ,
            [Address] = @Address ,
            [ZipCode] = @ZipCode ,
            [Mobile] = @Mobile ,
            [Phone] = @Phone ,
            [Email] = @Email ,
            [PaymentType] = @PaymentType ,
            [DeliverType] = @DeliverType ,
            [Status] = @Status ,
            [Discount_Payment] = @Discount_Payment ,
            [Charge_Deliver] = @Charge_Deliver ,
            [MoneyReceipt] = @MoneyReceipt ,
            [EnableDownload] = @EnableDownload ,
            [DeliverStatus] = @DeliverStatus ,
            [Memo] = @Memo ,
            [PresentMoney] = @PresentMoney ,
            [PresentPoint] = @PresentPoint ,
            [PresentExp] = @PresentExp ,
            [OrderType] = @OrderType ,
            [CouponID] = @CouponID ,
            [InputTime] = @InputTime ,
            [ContacterName] = @ContacterName ,
            [OrderKind] = @OrderKind,
            [GroupBuyID]=@GroupBuyID,
            [IsNotice]=@IsNotice,
			[SecondsKillID]=@SecondsKillID
    WHERE   OrderID = @OrderID
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating [dbo].[PE_ClientAssist]'
GO
CREATE TABLE [dbo].[PE_ClientAssist]
(
[AssistID] [int] NOT NULL,
[ClientID] [int] NOT NULL,
[AdminID] [int] NOT NULL
)
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating primary key [PK_PE_ClientAssist] on [dbo].[PE_ClientAssist]'
GO
ALTER TABLE [dbo].[PE_ClientAssist] ADD CONSTRAINT [PK_PE_ClientAssist] PRIMARY KEY CLUSTERED  ([AssistID])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating [dbo].[PE_D_ProductSuite]'
GO
CREATE TABLE [dbo].[PE_D_ProductSuite]
(
[Id] [int] NOT NULL,
[ProductId] [int] NULL,
[GeneralId] [int] NULL,
[Property] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL
)
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating [dbo].[PE_Model_FilterField]'
GO
CREATE TABLE [dbo].[PE_Model_FilterField]
(
[ID] [int] NOT NULL,
[ModelID] [int] NULL,
[FieldName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
[FieldValue] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL
)
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating [dbo].[PE_PC_PreConsultation]'
GO
CREATE TABLE [dbo].[PE_PC_PreConsultation]
(
[ID] [int] NULL,
[ConsultContent] [nvarchar] (1000) COLLATE Chinese_PRC_CI_AS NULL,
[ProductId] [int] NULL,
[CategoryId] [int] NULL,
[UserName] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL,
[InputDateTime] [datetime] NULL,
[AuditStatus] [bit] NULL,
[ReplyStatus] [bit] NULL
)
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating [dbo].[PE_PC_PreConsultationReply]'
GO
CREATE TABLE [dbo].[PE_PC_PreConsultationReply]
(
[ID] [int] NULL,
[ConsultationID] [int] NULL,
[ReplyContent] [nvarchar] (max) COLLATE Chinese_PRC_CI_AS NULL,
[ReplyDateTime] [datetime] NULL,
[Replyer] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL,
[ProductID] [int] NULL
)
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
PRINT N'Creating index [IX_PE_OrderHistoryItem_OrderHistoryID] on [dbo].[PE_OrderHistoryItem]'
GO
CREATE NONCLUSTERED INDEX [IX_PE_OrderHistoryItem_OrderHistoryID] ON [dbo].[PE_OrderHistoryItem] ([OrderHistoryID])
GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END
GO
IF EXISTS (SELECT * FROM #tmpErrors) ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT>0 BEGIN
PRINT 'The database update succeeded'
COMMIT TRANSACTION
END
ELSE PRINT 'The database update failed'
GO
DROP TABLE #tmpErrors
GO
