Mysql 存储过程应用

关闭订单存储过程

begin

declare done int default 0;

declare orderid varchar(22);

#声明查询订单的游标

declare cur cursor for select orders.order_id from orders where orders.order_state =  'wait_pay';

#异常处理

declare continue handler for sqlstate '02000' set done = 1;

#打开游标

open cur;

#遍历数据

fetch next from cur into orderid;

repeat

if not done then

#根据订单编号查询订单的下单时间

select orders.order_xiatime into @a from orders where order_id=orderid;

#根据订单下单时间获取1天后的时间(先用一天,存储过程正常使用后改为12小时间)

SELECT ADDDATE(@a, INTERVAL 24 Hour) into @b;

#判断会员在1天内是否未做任何处理

if @b<now() then

#自动更新订单的状态

update orders set order_state='trade_colsed',order_closetime = now() ,close_order_reason='订单关闭时间到,定时任务正常关闭' where order_id=orderid;

#若有多个操作可以在这里接着些

#回收库存(调用另一个存储过程)

call recoveryOfInventory(orderid);

end if;

end if;

fetch next from cur into orderid;

until done end repeat;

close cur;


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章