站内信设计(群发+私信)实践

一:数据库设计

DROP TABLE IF EXISTS message_read;
CREATE TABLE message_read (
id int(11) NOT NULL AUTO_INCREMENT,
wxAccountId int(11) DEFAULT NULL COMMENT ‘公众号id’,
messageId int(11) DEFAULT NULL COMMENT ‘消息id’,
delete_flag int(11) DEFAULT NULL COMMENT ‘删除标志:0未删除 1:已删除’,
PRIMARY KEY (id),
KEY wxAccountId (wxAccountId),
KEY messageId (messageId)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS message_text;
CREATE TABLE message_text (
id int(11) NOT NULL AUTO_INCREMENT,
title varchar(50) DEFAULT NULL COMMENT ‘标题’,
content varchar(1024) DEFAULT NULL COMMENT ‘内容’,
created_at datetime DEFAULT NULL COMMENT ‘创建时间’,
status int(11) DEFAULT ‘0’ COMMENT ‘0:未发送 1:已发送 ‘,
type int(1) DEFAULT ‘0’ COMMENT ‘0/全局1/私有’,
from_id int(11) DEFAULT NULL COMMENT ‘发送者account_id’,
to_id int(11) DEFAULT NULL COMMENT ‘接收者account_id’,
PRIMARY KEY (id),
KEY from_id (from_id),
KEY to_id (to_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

二:查询已读和未读的列表
SELECT *,(
SELECT count(*)
FROM message_read
WHERE t.id = message_read.messageId
AND message_read.wxAccountId = #wxAccountId#
) AS readStatus
FROM message_text t
where t.id not in(select messageId from message_read where wxAccountId=#wxAccountId# and delete_flag=1) and t.status = 1 and t.type = 0 or t.to_id = #wxAccountId#
order by readStatus asc

三:查询未读的邮件数目

select count(*) from message_text t where t.id not in(select messageId from message_read where wxAccountId = #wxAccountId#) and t.status = 1 and (t.to_id = #wxAccountId# or t.type = 0)​

当阅读【未读】的站内信时,在message_read中插入一条阅读记录
当删除【已读】的站内信时,将message_read的delete_flag置为1

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

十五楼亮哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值