日期:2014-05-20 浏览次数:20697 次
begin
CALL user_yongpin_synchro();
end
BEGIN
#Routine body goes here...
DELETE FROM user_yongpin WHERE user_yongpin.mtime < now()
OR NOT EXISTS(
SELECT 1 FROM job_ploy
WHERE job_ploy.yongpin_detail_ID = user_yongpin.yongpinID
AND job_ploy.job_type_ID =
(SELECT user_info.job_type_ID
FROM user_info
WHERE user_info.ID = user_yongpin.user_info_ID)
);
INSERT INTO user_yongpin
(yongpinID, remain, mtime, user_info_ID)
SELECT
job_ploy.yongpin_detail_ID, job_ploy.yongpin_num,
DATE_ADD(user_info.etime,INTERVAL (((YEAR(NOW()) - YEAR(user_info.etime)) * 12) + (MONTH(NOW()) - MONTH(user_info.etime))) + job_ploy.yongpin_limit - (((YEAR(NOW()) - YEAR(user_info.etime)) * 12) + (MONTH(NOW()) - MONTH(user_info.etime))) % job_ploy.yongpin_limit MONTH),
user_info.ID
FROM job_ploy
JOIN user_info ON job_ploy.job_type_ID = user_info.job_type_ID
WHERE NOT EXISTS (
SELECT user_yongpin.ID FROM user_yongpin
WHERE user_yongpin.user_info_ID = user_info.ID
AND user_yongpin.yongpinID = job_ploy.yongpin_detail_ID
AND user_yongpin.mtime > now()
/*AND user_info.job_type_ID = job_ploy.job_type_ID*/
);
END