为了方便自己参考,忘记语法,这里代码备忘:
begin
DECLARE m_cnt int ;
DECLARE m_store_id int ;
DECLARE m_buy_uid int ;
DECLARE m_buy_user_bonus decimal ; #买方的提成
DECLARE m_store_bonus decimal ;
DECLARE m_store_price int ;
select id,bonus,price into m_store_id,m_store_bonus,m_store_price
from lf_store where store_uid= p_sell_uid and status = 0 and type=p_type limit 0,1;
if m_store_id > 0 then #说明有库存可以使用,修改双方库存结构
select agent.id,agent.bonus into m_buy_uid, m_buy_user_bonus from lf_agent agent left join lf_user user on user.id = agent.uid where user.username = p_target_user_name;
if m_buy_uid > 0 then
update lf_store set status = 1 where id = m_store_id;
insert into lf_profit (sell_uid,buy_username,type,bonus,price) values(
p_sell_uid,p_target_user_name,p_type,m_store_bonus,m_store_price);
insert into lf_store (store_uid,agent_uid,type, bonus,status,price)values(m_buy_uid,p_sell_uid,p_type,m_buy_user_bonus,0,m_store_price);
else
set o_code = 1000;
end if;
else
set o_code = 2000;
end if;
end
参数为:
in p_sell_uid int,in p_target_user_name varchar(50),in p_type int,in p_catid int,out o_code int
网友评论