[关闭]
@Wahson 2019-10-09T10:55:49.000000Z 字数 2826 阅读 542

公众号报价推送设计

  1. 1. 报价可强制立即推送
  2. 2. 可指定区域(城市)、牌号、公司推送
  3. 3. 记录每个用户推送记录
  4. 4. 限制每个客户每天推送次数
  5. 5. 可自定义发送模板部分内容(除发送时间,报价详情)
  6. 6. 发送预览功能,给自己先发一条消息,确保内容符合要求,再群发用户
  7. 7. 权限管理,仅管理员以上可以看到主动推送功能

业务规则:

  1. 主动触发推送为强制推送,推送结果会影响下一次定时推送的时间
  2. 定时推送时,本次推送时间应大于等于 上次推送(定时或主动推送)时间 + 最小推送间隔
  3. 限制时间段内最多发送次数,超过不再向用户发送消息
  4. 本次定时推送,内容与上一次推送的相同时不发送

数据模型

消息发送成功后,保存发送历史,更新推送记录,记录发送时间,累计发送次数
业务消息指业务流程上的消息通知,如订单成交通知等,报价消息指定时、主动推送的报价消息

  1. create table wx_push_his(
  2. id bigint not null auto_increment primary key,
  3. wx_user_id bigint not null comment '微信用户id',
  4. content varchar(512) not null comment '推送内容,json',
  5. inner_app_id int(3) not null comment 'wx_app.id',
  6. push_type smallint(3) not null comment '推送类型,1:业务通知(biz_notice);2:报价通知(price_notice)',
  7. created_at timestamp default current_timestamp() not null,
  8. remark varchar(64) null comment '备注'
  9. ) charset = utf8mb4 engine = innoDb comment '微信消息推送历史';
  10. create table wx_push_record(
  11. id bigint not null auto_increment primary key,
  12. wx_user_id bigint not null comment '微信用户id',
  13. inner_app_id int(3) not null comment 'wx_app.id',
  14. times_of_curr_day int(3) not null default 0 comment '当天推送次数,每天清零',
  15. last_push_at timestamp not null comment '上一次推送时间',
  16. push_type smallint(3) not null comment '推送类型,1:业务提醒(biz_notice);2:报价通知(price_notice)',
  17. created_at timestamp default current_timestamp() not null,
  18. updated_at timestamp default current_timestamp() not null,
  19. remark varchar(64) null comment '备注',
  20. constraint uniq_user_app unique (wx_user_id, inner_app_id, push_type)
  21. ) charset = utf8mb4 engine = innoDb comment '微信推送记录表';

actor初始化时缓存策略数据,通过binlog(增,删,改)进行更新
一个app_id会有多个策略,查询返回数组

  1. create table wx_push_strategy(
  2. id bigint not null auto_increment primary key,
  3. inner_app_id int(3) not null comment 'wx_app.id',
  4. min_interval smallint(5) not null comment '推送最小间隔,单位:分钟',
  5. max_times_of_period smallint(5) default null comment '每个用户在本推送时段内推送最多次数,为null时为无限次',
  6. push_start_time time default '10:00:00' not null comment '推送开始时间',
  7. push_end_time time default '17:00:00' not null comment '推送结束时间',
  8. created_at timestamp default current_timestamp() not null,
  9. updated_at timestamp default current_timestamp() not null,
  10. remark varchar(64) null comment '备注',
  11. key idx_app_id(inner_app_id)
  12. ) charset = utf8mb4 engine = innoDb comment '微信消息推送策略';
  1. use product_db;
  2. create table product_offer_stats(
  3. id int(10) not null auto_increment primary key ,
  4. product_id int not null comment '产品id',
  5. category varchar(12) not null comment '产品分类',
  6. designation varchar(32) not null comment '产品牌号',
  7. manufacturer_id int not null comment '生产商ID',
  8. manufacturer_name varchar(32) not null comment '生产商名称',
  9. min_price decimal(13, 2) default 0.00 not null comment '最低价',
  10. max_price decimal(13, 2) default 0.00 not null comment '最高价',
  11. avg_price decimal(13, 2) default 0.00 not null comment '均价',
  12. offer_date date not null comment '报价日期',
  13. created_at timestamp default current_timestamp() not null,
  14. key idx_offer_date_product(offer_date, product_id)
  15. ) charset = utf8mb4 engine = innoDb comment '报价统计';
  16. select * from product_offer_stats where product_id = 1 and offer_date > current_date - 5 order by offer_date desc limit 1;
  17. explain select * from product_offer_stats where id in (select max(id)
  18. from product_offer_stats
  19. where offer_date > current_date - 5
  20. group by product_id
  21. )
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注