您好,登錄后才能下訂單哦!
CREATE PROCEDURE `addTicket`(in vipsql VARCHAR(255),in ordersql VARCHAR(255),in detailkey varchar(255),in detailsql VARCHAR(255)) comment '掛單(售藥窗口)'
BEGIN
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION ,NOT FOUND
rollback;
start transaction;
set @vid=@oid='';
set @outstr='';
set @errcode=200;
set @errmsg='成功';
if vipsql=0 then
set @tem=vipsql;
prepare tem from @tem;
execute tem;
set @rows=row_count();
if @rows<=0 then
set @errcode=501;
set @errmsg='插入到【會員表】失敗';
rollback;
end if;
set @vid=LAST_INSERT_ID();
else
set @vid=vipsql;
end if;
select order_outpatient_num into @cnum from `order` order by order_outpatient_num desc limit 1;
if locate(curdate()+0,@cnum)=0||@cnum='' then
set @cnum=concat(curdate()+0,'00000001');
else
set @cnum=@cnum+1;
end if;
set ordersql=concat(ordersql,"'",@vid,"','",@cnum,"')");
set @ordersql=ordersql;
prepare temp from @ordersql;
execute temp;
set @rows=row_count();
if @rows<=0 then
set @errcode=502;
set @errmsg='插入到【訂單表】失敗';
rollback;
end if;
set @oid=LAST_INSERT_ID();
set @num=(length(detailsql)-length(replace(detailsql,'*#*','')))/3+1;
set @i=1;
while @i<=@num do
if @i=1 then
set @strsql=substring_index(detailsql,'*#*',@i);
else
set @strsql=substring_index(detailsql,'*#*',@i);
set @strsql=substring_index(@strsql,'*#*',-1);
end if;
set @outstr=concat(@outstr,@strsql,"'",@cnum,"','",@oid,"'),");
set @i=@i+1;
end while;
set @outstr=concat(detailkey,@outstr);
set @outstr=left(@outstr,char_length(@outstr)-1);
prepare temp0 from @outstr;
execute temp0;
set @rows=row_count();
if @rows<=0 then
set @errcode=503;
set @errmsg='插入到【訂單詳情表】失敗';
rollback;
end if;
commit;
select @errcode as errcode,@errmsg as errmsg;
END
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。