if exists(select 1 from sysobjects where name='t_rm_vip_savelist_insert')
  drop Trigger t_rm_vip_savelist_insert
go

CREATE trigger t_rm_vip_savelist_insert on t_rm_vip_savelist
for insert
as
begin

  declare @ls_cardid char(20),       -- 会员卡号
      @ln_consum_amt numeric(16,4),  -- 充值金额
      @ls_oper_type char(1),
      @ls_var_value char(255),
      @ls_branch_no varchar(10),
      @g_branch_no varchar(10)

      SELECT @ls_var_value = sys_var_value  FROM mess_t_sys_system WHERE Upper(LTRIM(RTRIM(sys_var_id))) = Upper(LTRIM(RTRIM('card_save'))) --充值卡充值后发短信

      select @ls_oper_type = oper_type ,@ls_cardid =card_id ,@ln_consum_amt=consum_amt from inserted 

       --机构值
      select @ls_branch_no = sys_var_value from t_sys_system where sys_var_id = 'g_branch_no'

      if @ls_oper_type='4'  and left(@ls_var_value,1) = '1'
	 begin
	     insert into mess_t_vip_message(mess_type,branch_no,card_id,savelist_amt,oper_type,send_flag)
	     values('4',@ls_branch_no,@ls_cardid,@ln_consum_amt,'4','0')
	 end


      SELECT @ls_var_value = sys_var_value  FROM mess_t_sys_system WHERE Upper(LTRIM(RTRIM(sys_var_id))) = Upper(LTRIM(RTRIM('savecard_pay'))) --充值卡付款后发短信     

      if @ls_oper_type = '5' and left(@ls_var_value,1) = '1' 
          insert into mess_t_vip_message(mess_type,branch_no,card_id,savelist_amt,oper_type,send_flag)
	  values('4',@ls_branch_no,@ls_cardid,@ln_consum_amt,'5','0')
end
go
