zoukankan      html  css  js  c++  java
  • 团队触发器

    USE [MogoData355]
    GO
    /****** 对象:  Trigger [dbo].[UserWithdrawOrderStatus]    脚本日期: 07/05/2013 14:17:51 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER TRIGGER [dbo].[UserWithdrawOrderStatus] 
       ON  [dbo].[User_Withdraw_Detail] 
       AFTER UPDATE
    AS 
    BEGIN    
        SET NOCOUNT ON;
        DECLARE @Count int;
        DECLARE @FinishCount int;
        DECLARE @FailCount int;
        DECLARE @Woid int;
       if (update(Status))
           BEGIN
           SELECT @Woid = WOID from inserted;
           select @Count =count(*) from User_Withdraw_Detail where woid = @Woid ;
           select @FinishCount=count(*) from User_Withdraw_Detail where woid =  @Woid and (Status =3 or Status =4) ;
           select @FailCount=count(*) from User_Withdraw_Detail where woid =  @Woid and Status =4;
            if (@Count = @FinishCount)
            BEGIN
                    if (@FailCount > 0)
                    BEGIN
                        update User_Withdraw_Order set Status = 4 where ID = @Woid
                    END
                    else
                    BEGIN
                        update User_Withdraw_Order set Status = 3 where ID = @Woid
                    END
            END
    
    --        if (@FailCount > 0)
    --            BEGIN
    --                update User_Withdraw_Order set Status = 4 where ID = @Woid
    --            END
      END
    END   
    --------------------------------------------------------------
    USE [MogoData355]
    GO
    /****** 对象:  Trigger [dbo].[UserWithdrawDetailSuccess]    脚本日期: 07/05/2013 14:17:48 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    
    
    ALTER TRIGGER [dbo].[UserWithdrawDetailSuccess] 
       ON  [dbo].[User_Withdraw_Detail] 
       AFTER UPDATE
    AS 
    BEGIN    
        SET NOCOUNT ON;
        DECLARE @Status int;
        DECLARE @UID uniqueidentifier;
        DECLARE @Amount money;
        DECLARE @NoteNum varchar(20);
        DECLARE @WOID int;
        DECLARE @ID int
       if (update(Status))
       BEGIN
       SELECT @UID=UID, @Status=Status,@Amount=Amount,@NoteNum =WOID+'0'+ID, @ID=ID,@WOID =WOID from inserted 
        if (@Status=3)
          BEGIN
            --UPDATE User_Income SET Withdraw=(select sum(Amount) as Amount from User_Withdraw 
            --where UID=@UID and Status=3)*1000 where UID=@UID
            INSERT INTO User_Income_Detail(UID,Date,Type,Amount,Note,Summed)
            VALUES (@UID,CONVERT(VARCHAR(10),GETDATE(),120),-1,-@Amount,@NoteNum,1)
          END
         if (@Status=4)
          BEGIN
            --UPDATE User_Income SET Withdraw=(select sum(Amount) as Amount from User_Withdraw 
            --where UID=@UID and Status=3)*1000 where UID=@UID
            update  User_Withdraw_Detail set Tax =0,RealityAmount=0 where ID = @ID and WOID = @WOID
          END
       END   
    END
    
    
    ---------------------------------------------------------------------
    USE [MogoData355]
    GO
    /****** 对象:  Trigger [dbo].[UserWithdrawOrderRealityAmoun]    脚本日期: 07/05/2013 14:19:22 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER TRIGGER [dbo].[UserWithdrawOrderRealityAmoun] 
       ON  [dbo].[User_Withdraw_Order] 
       AFTER UPDATE
    AS 
    BEGIN    
        SET NOCOUNT ON;
        DECLARE @Status tinyint;
        DECLARE @WOID int;
       if (update(Status))
           BEGIN
             SELECT @Status = [Status], @WOID = ID from inserted;
             if(@Status = 3 or @Status = 4)
                BEGIN
                    update User_Withdraw_Order set RealityAmount =
                    (select isnull(sum(RealityAmount),0.0) from User_Withdraw_Detail where WOID = @WOID and Status=3),
                    Tax =
                    (select isnull (sum(Tax),0.0) from User_Withdraw_Detail where WOID = @WOID and Status=3)
                    where ID = @WOID
                END
           END
    END   
  • 相关阅读:
    linux常用命令(4)rm命令
    Apache Commons 工具类
    Apache Commons 工具类介绍及简单使用
    linux常用命令(3)mkdir命令
    linux常用命令(2)pwd命令
    linux常用命令(1)cd命令
    小程序调用方法
    php用json_encode中文问题
    基于thinkphp的RBAC权限控制
    thinkphp获取ip地址及位置信息
  • 原文地址:https://www.cnblogs.com/l25321937/p/3191080.html
Copyright © 2011-2022 走看看