Created
July 29, 2019 09:46
-
-
Save trinvh/353827d4dc38f16d5899417c87706362 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
drop trigger if exists inetdb.inetdbkhuyenmai_theo_gio; | |
use inetdb; | |
DELIMITER $$ | |
CREATE TRIGGER inetdbkhuyenmai_theo_gio BEFORE INSERT ON tblvoucherlog | |
FOR EACH ROW | |
BEGIN | |
-- select the newest payment of this user from paymenttb | |
SET @RECENT_PAYMENT_TYPE = (SELECT VoucherType FROM tblvoucherlog WHERE UserId = NEW.UserId ORDER BY VoucherId DESC LIMIT 1); | |
if(NEW.VoucherType = 9) THEN | |
IF | |
HOUR(CURTIME()) IN (7, 8, 9, 19, 20, 14, 15, 16) | |
AND dayname(CURDATE()) IN ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday') | |
AND NEW.Amount > 9999 | |
THEN | |
UPDATE tbluser SET MoneyRemain = MoneyRemain + (NEW.Amount * 0.5) WHERE UserId = NEW.UserId; | |
END IF; | |
END IF; | |
END $$ | |
DELIMITER ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment