POSTGRESQL

8 篇文章 0 订阅
1 篇文章 0 订阅
CREATE OR REPLACE FUNCTION "public"."tradegift3(src_id int4, dst_id int4, gift_id int4, gift_count i"(IN src_id int4, IN dst_id int4, IN gift_id int4, IN gift_count int4, IN gift_type int4, IN total_out int4, IN total_in int4, IN trade_type int4, IN room_id int4, OUT ret_sucess int4, OUT src_nk int4, OUT src_nb int4, OUT dst_nk int4, OUT dst_nb int4, OUT dst_nchestnum int4)
  RETURNS "pg_catalog"."record" AS $BODY$
DECLARE
r0 RECORD;
todaycost integer;
bnewchest integer;
today date;
BEGIN
   src_nk:=0;
   src_nb:=0;
   dst_nk:=0;
   dst_nb:=0;
   dst_nchestnum:=0;
   todaycost:=0;
   bnewchest:=0;
   select now() as val into r0;
   select now() into today;
   update tbuseraccount set nk=nk-total_out where nuserid=src_id and nk>=total_out;
   if FOUND then
       if trade_type=1 then
         update tbuseraccount set nb=nb+total_in where nuserid=dst_id;
       else
         update tbuseraccount set nk=nk+total_in where nuserid=dst_id;
       end if;
       
       insert into tbusertradelog(nuserid,nbuddyid,ngiftid,ncount,dtime,ngifttype,nvcbid,nusermoney,nbuddymoney) VALUES(src_id,dst_id,gift_id,gift_count,r0.val,gift_type,room_id,total_out,total_in);

       select ncost into todaycost from tbusertodaycost where nuserid=src_id and ddate=today;
       if FOUND then
          todaycost := todaycost + total_out;
  update tbusertodaycost set ncost=ncost + total_out where nuserid=src_id;
       else
          todaycost := total_out;
  update tbusertodaycost set ncost=total_out, ddate=today where nuserid=src_id;
  if not FOUND then
    insert into tbusertodaycost(nuserid,ncost,ddate) values(src_id,total_out,today);
  end if;
end if;

if todaycost >= 10000000 then
   bnewchest :=1;
   update tbusertodaycost set ncost=0 where nuserid=src_id;
   update tbuseraccount set nchestnum=nchestnum+1 where nuserid=src_id;
   select nchestnum into dst_nchestnum from tbuseraccount where nuserid=src_id;
 end if;
  
       select nk,nb from tbuseraccount where nuserid=src_id into src_nk,src_nb;
       select nk,nb from tbuseraccount where nuserid=dst_id into dst_nk,dst_nb;
       ret_sucess=0;
       if bnewchest=1 then
          ret_sucess=1;
       end if;

       RETURN;
   end if;

   ret_sucess=-1;
   RETURN;
END;
$BODY$
  LANGUAGE 'plpgsql' VOLATILE COST 100
;

ALTER FUNCTION "public"."tradegift3(src_id int4, dst_id int4, gift_id int4, gift_count i"(IN src_id int4, IN dst_id int4, IN gift_id int4, IN gift_count int4, IN gift_type int4, IN total_out int4, IN total_in int4, IN trade_type int4, IN room_id int4, OUT ret_sucess int4, OUT src_nk int4, OUT src_nb int4, OUT dst_nk int4, OUT dst_nb int4, OUT dst_nchestnum int4) OWNER TO "ksbox";

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值