SQL Server?洢?????????α?
???????????? ???????[ 2015/3/18 11:50:17 ] ????????????? ??????? ?α?
???????????????????????2???α???洢????
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[CancelOrderBySystem]
AS
BEGIN
declare /*????????*/
@Status varchar(100)?? --??
@TimeNow datetime?? --??????
@TradeID varchar(50)?? --????????
@GoodsID int?? --???ID
@Num int?? --????
@SkuID int --???ID
set @Status='TRADE_CLOSED_BY_SYSTEM' /*????????*/
set @TimeNow=getdate()
begin transaction; --??????????
--????????????????
--??????????????????????????ж????????й??
--?????й????????ж??????????й????????????
--????й??????ж?ù??????????????????????????
--??????????
declare cancelOrder_Cursor cursor for --?????α?
select TradeID from WxTrade where Status='WAIT_BUYER_PAY' and OutTime<=@TimeNow
OPEN cancelOrder_Cursor --???α?
FETCH NEXT FROM cancelOrder_Cursor --????α???????????
into @TradeID --???????????α?????е????????
----------------------???α?????????begin --------------------------
WHILE (@@FETCH_STATUS = 0) --FETCH?????г??
BEGIN
--??????????
update WxTrade set Status=@Status??CloseTime=@TimeNow where TradeID=@TradeID
--???????????棬???????????????????????
declare orderDetail_Cursor cursor for --?????α?
select GoodsID??SkuID??Num from WxOrder where TradeID=@TradeID
OPEN orderDetail_Cursor --???α????????
FETCH NEXT FROM orderDetail_Cursor --????α???????????
into @GoodsID??@SkuID??@Num --???????????α?????е????ID?????ID??????
----------------------???????α????????begin ----------------------
------------------------------------------------------------------------
WHILE (@@FETCH_STATUS = 0) --FETCH?????г??
BEGIN
if(@SkuID is null)
BEGIN
--??й????????ж??????????й???????????棬??????
if not exists(select SkuID from [Sku] where GoodsID=@GoodsID)
BEGIN
update Goods set Quantity=Quantity+@Num where GoodsID=@GoodsID
END
END
else
BEGIN
--????й??????ж?ù??????????????????????????
if exists(select SkuID from [Sku] where SkuID=@SkuID)
BEGIN
update [Sku] set ItemQuantity=ItemQuantity+@Num where SkuID=@SkuID
update Goods set Quantity=Quantity+@Num where GoodsID=@GoodsID
END
END
FETCH NEXT FROM orderDetail_Cursor --????α??????У????????
into @GoodsID??@SkuID??@Num --???????????α?????е????ID?????ID??????
END
CLOSE orderDetail_Cursor --????α????????
DEALLOCATE orderDetail_Cursor --????α????????
----------------------???????α????????end ----------------------
----------------------------------------------------------------------
FETCH NEXT FROM cancelOrder_Cursor --????α??????У?????????
into @TradeID --???????????α?????е????????
End
CLOSE cancelOrder_Cursor --????α?????????
DEALLOCATE cancelOrder_Cursor --????α?????????
----------------------???α?????????end --------------------------
if(@@error>0)
begin
rollback transaction
return 0
end
else
begin
commit transaction
return 1
end
END
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11