drop trigger if exists tri_user;
delimiter $$
create trigger tri_user
BEFORE insert on t_user
FOR EACH ROW
BEGIN
declare count int;
declare bDate DATETIME;
declare uDate DATETIME;
declare days int;
select inTime,count(*) into bDate,count from t_agentmemberrel where memberName = NEW.username;
set uDate = NEW.createTime;
select datediff(bDate, uDate) into days ;
if count=1 THEN
IF days < 7 THEN
update t_agentmemberrel set activeStatus='2' where memberName = NEW.username;
END IF;
END IF;
END $$
delimiter ;