微信储值卡订单过期存储过程_版本1
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: <Author,,jankie> -- Create date: <Create Date,,2017-09-12 10:26> -- Description: <Description,,查询订单是否过期> --如果订单过期会自动设置IsDealWith为已处理。并且将Status设置为Closed_OutTime+'当时订单的状态' -- ============================================= -- exec [dbo].[IsClosedStoredCardOrders] '0','10','957' ALTER PROCEDURE [dbo].[IsClosedStoredCardOrders] @PageNumber int, @PageSize int, @BID int AS BEGIN declare /*声明标量*/ @TradeID varchar(100), @TimeNow datetime, --当前时间 @Status varchar(100) set @TimeNow=getdate() begin transaction; --开始执行事务 --查询所有已经过期的订单,更新过期订单的字段 declare updateOrder_Cursor cursor for --声明游标 select Status,TradeID from ( select Row_number() over(order by CreateDate) as rownum,* from ValueCardSaveTradeLog Where TradeID=TradeID and OutTime<=@TimeNow )as t1 where t1.rownum>=(@PageNumber)*@PageSize+1 and t1.rownum<=((@PageNumber+1)*@PageSize) and BID=@BID OPEN updateOrder_Cursor --打开游标 FETCH NEXT FROM updateOrder_Cursor --获取游标的下一行数据 into @Status, --使变量获得当前游标指定行的订单状态 @TradeID --使变量获得当前游标指定行的订单的单号 ----------------------外部游标(主订单)begin -------------------------- WHILE (@@FETCH_STATUS = 0) --FETCH语句执行成功 begin --如果不是手动关闭或者还没关闭就开始执行语句,其他的就让游标跳过不更新 if(substring(ltrim(rtrim(@Status)),0,7)='NotPay' --or substring(ltrim(rtrim(@Status)),0,16)='HadPayNotInsert' --后面修改的需求,已付款待充值不能过期关闭,因为这是有问题的订单,只能手动关闭。 or substring(ltrim(rtrim(@Status)),0,10)='FinishPay') begin --substring --更新订单状态Status,IsDealWith update ValueCardSaveTradeLog set Status='Closed_OutTime_'+@Status,IsDealWith='1' where TradeID=@TradeID end --substring FETCH NEXT FROM updateOrder_Cursor --获取游标的下一行(主订单) into @Status, --使变量获得当前游标指定行的订单状态 @TradeID --是变量获得当前指定行的订单单号 end CLOSE updateOrder_Cursor --关闭游标(主订单) DEALLOCATE updateOrder_Cursor --释放游标(注订单) ----------------------外部游标(主订单)end -------------------------- if(@@error>0) begin rollback transaction --print '0' return 0 end else begin commit transaction --print '1' return 1 end END GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO