BEGIN
/*计算用户提成总金额*/
declare amountPrice,pays,rates,goodsPrice DECIMAL(10,2) DEFAULT 0;
DECLARE flag int,getUserId;
#if(userlevel=1) then
SELECT member_id into getUserId from 33hao_member where openid=open_id
declare cur cursor for select commission1_rate rates,commission1_pay pays,goods_price from 33hao_goods_common;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET flag=1;
SET flag=0;
OPEN cur;
REPEAT
FETCH cur into rates,pays,goodsPrice;
if(rates=null) then
set amountPrice=amountPrice+pays;
ELSE
set amountPrice=amountPrice+goodsPrice*rates;
end if;
UNTIL flag end REPEAT;
CLOSE cur;
RETURN amountPrice;
end