if exists(select 1 from sysobjects where name='tr_mess_t_vip_message_i')
  drop trigger tr_mess_t_vip_message_i
go

create trigger [dbo].[tr_mess_t_vip_message_i] on [dbo].[mess_t_vip_message]
after INSERT
as
BEGIN
	declare @ls_cardid char(20), 
			@card_type  char(2),
			@ls_flow_no char(20),
			@ls_branch_no varchar(10),
			@ln_acc_num numeric(16,4)
			
	select 	@ls_cardid=card_id,
			@card_type=card_type,
			@ln_acc_num=acc_num,
			@ls_flow_no=flow_no,
			@ls_branch_no=branch_no
		from INSERTED
	
   --没有注册微信就不更新
   if not exists(select * from t_rm_vip_info where card_id=@ls_cardid and isnull(openid,'')<>'')
   begin
		delete mess_t_vip_message_wx where card_id=@ls_cardid
		return
   end

	
	--复制一份到微信推送
	insert into mess_t_vip_message_wx
	(
			mess_type, send_flag, oper_date, branch_no, card_id, 
			card_type, to_card_type, father_card, giv_acc_num, oper_type, 
			change_amt,	savelist_amt, flow_no, item_no, acc_num, 
			flow_amt, send_year, send_date, card_little, mess_flow_id
	)
	select mess_type, send_flag, oper_date, branch_no, card_id, 
		card_type, to_card_type, father_card, giv_acc_num, oper_type, 
		change_amt, savelist_amt, flow_no, item_no, acc_num, 
		flow_amt, send_year, send_date, card_little, flow_id
	from INSERTED
	
END
go
