我已经给了一个任务发送电子邮件提醒客户在我们的数据库通知他们的年度订阅即将到期。发送期限为账户过期前7天30天,15天。已发送的电子邮件将不会重新发送,直到下一个时间段到达(例如[email protected]帐户即将在2012-06-01到期。服务器在2012-05-02发送电子邮件,然后等到2012-05如果状态没有改变,-17再次发送)。此外,如果account_status.statusId不是3,服务器将不会再次发送消息,并重新设置account_metadata.v至7MySQL选择电子邮件发送帐户到期提醒
下面的示例数据列表:
占
id email
1 [email protected]
2 [email protected]
3 [email protected]
4 [email protected]
5 Curae;@Phasellus.edu
6 [email protected]
7 [email protected]
8 [email protected]
9 [email protected]
10 [email protected]
11 [email protected]
12 [email protected]
13 [email protected]
14 [email protected]
15 [email protected]
16 [email protected]
17 [email protected]
18 [email protected]
19 [email protected]
20 [email protected]
21 [email protected]
22 [email protected]
23 [email protected]
24 [email protected]
25 [email protected]
26 [email protected]
27 [email protected]
28 [email protected]
29 [email protected].ca
30 [email protected]
ACCOUNT_STATUS
id statusId accountId time
1 1 2 2011-06-01 21:54:37
2 1 3 2011-06-02 09:07:14
3 1 4 2011-06-02 09:13:20
4 1 5 2011-06-02 09:54:44
5 1 6 2011-06-02 10:15:52
6 1 7 2011-06-02 10:17:22
7 2 7 2011-06-02 10:21:25
8 1 8 2011-06-02 11:09:03
9 1 9 2011-06-02 11:09:18
10 1 10 2011-06-02 11:13:29
11 1 11 2011-06-02 11:21:11
12 1 12 2011-06-02 11:21:35
13 3 5 2011-06-02 11:41:04
14 3 2 2011-06-02 11:46:07
15 1 13 2011-06-02 11:49:18
16 3 13 2011-06-02 11:53:45
17 1 14 2011-06-02 12:02:26
18 3 14 2011-06-02 12:10:54
19 1 15 2011-06-02 13:41:19
20 1 16 2011-06-02 15:27:03
21 3 16 2011-06-02 15:42:58
22 1 17 2011-06-02 15:46:05
23 1 18 2011-06-02 15:59:56
24 1 19 2011-06-02 16:13:41
25 1 20 2011-06-02 16:17:36
26 1 21 2011-06-02 16:47:04
27 1 22 2011-06-02 16:47:39
28 1 23 2011-06-02 18:35:29
29 1 24 2011-06-02 19:17:06
30 1 25 2011-06-02 20:07:33
一ccount_metadata
id accountId k v
27033 2 remindEmail 3
27034 3 remindEmail 3
27035 4 remindEmail 3
27036 5 remindEmail 3
27037 6 remindEmail 3
27038 7 remindEmail 3
27039 8 remindEmail 3
27040 9 remindEmail 7
27041 10 remindEmail 7
27042 11 remindEmail 7
27043 12 remindEmail 7
27044 13 remindEmail 3
27045 14 remindEmail 3
27046 15 remindEmail 7
27047 16 remindEmail 3
27048 17 remindEmail 7
27049 18 remindEmail 7
需要注意的是:
accounts.id
和account_metadata.accountId
是唯一accounts.id = account_metadata.accountId = account_status.accountId
- 所有三个表是Innodb的
MySQL的查询我目前有有:
如果statusId在ACCOUNT_STATUS不是3,remindEmail至7然后设置值:
UPDATE `account_status` AS acs, `accounts` AS a, `account_metadata` AS am SET am.v = '7' WHERE acs.statusId != 3 AND acs.accountId = a.id AND a.id = am.accountId AND am.k = 'remindEmail';
已将电子邮件提醒取决于周期(30天=> 7,15天=> 3 ,7天=> 1)前1年
status = 3
:SELECT am.accountId, a.email, am.k, am.v, acs.time FROM accounts a INNER JOIN account_status acs ON a.id = acs.accountId INNER JOIN account_metadata am ON a.id = am.accountId WHERE acs.statusId = 3 AND am.k = 'remindEmail' AND NOW() <= DATE_ADD(acs.time, INTERVAL 365 DAY) AND NOW() > DATE_ADD(acs.time, INTERVAL 365 - ((am.v & 1) * 7 + (am.v & 2) * 8 + (am.v & 4) * 15) DAY) AND am.v = %s;
更新
account_metadata.v
到新的状态:UPDATE `account_metadata` AS am SET am.v = '%s' WHERE am.accountId = '%s' AND am.k = 'remindEmail';
这里的问题是,account_status.accountId
不是唯一的(看到accountId = 13
上表)。这会导致#1将某些行重置为7,并且客户感觉他们被垃圾邮件。有没有办法修改#2和/或#1来选择最新的account_status.statusId
(基于account_status.time
)或更新最近的account_status.stautsId
?
它似乎永远不会回报。 – user1045217