feat: system notice
This commit is contained in:
@@ -19,6 +19,7 @@ const (
|
||||
CONTRACT = "contract"
|
||||
PRODUCT = "product"
|
||||
SUBSCRIBE = "subscribe"
|
||||
NOTICE = "notice"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -31,6 +32,13 @@ const (
|
||||
Prod = "prod"
|
||||
)
|
||||
|
||||
const (
|
||||
REGISTER_NOTICE_TEMPLATE = "你注册了账号"
|
||||
LOGIN_NOTICE_TEMPLATE = "你登录了账号"
|
||||
SUBSCRIBE_NOTICE_TEMPLATE1 = "你订阅了专业版"
|
||||
SUBSCRIBE_NOTICE_TEMPLATE2 = "你订阅了高级版"
|
||||
)
|
||||
|
||||
var ctx = context.Background()
|
||||
|
||||
// RestPage 分页查询
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"crm/global"
|
||||
"crm/models"
|
||||
"crm/response"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
Read = 1 // 已读
|
||||
UnRead = 2 // 未读
|
||||
)
|
||||
|
||||
type NoticeService struct {
|
||||
}
|
||||
|
||||
// 新建通知
|
||||
func (n *NoticeService) Create(param *models.NoticeParam) int {
|
||||
notice := models.Notice{
|
||||
Content: param.Content,
|
||||
Status: UnRead,
|
||||
Creator: param.Creator,
|
||||
Created: time.Now().Unix(),
|
||||
}
|
||||
if err := global.Db.Create(¬ice).Error; err != nil {
|
||||
return response.ErrCodeFailed
|
||||
}
|
||||
return response.ErrCodeSuccess
|
||||
}
|
||||
|
||||
// 更新通知
|
||||
func (n *NoticeService) Update(param *models.NoticeUpdateParam) int {
|
||||
notice := models.Notice{
|
||||
Id: param.Id,
|
||||
Status: Read,
|
||||
Updated: time.Now().Unix(),
|
||||
}
|
||||
if err := global.Db.Model(¬ice).Updates(¬ice).Error; err != nil {
|
||||
return response.ErrCodeFailed
|
||||
}
|
||||
return response.ErrCodeSuccess
|
||||
}
|
||||
|
||||
// 获取未读通知数量
|
||||
func (n *NoticeService) UnReadCount(uid int64) (models.UnReadNotice, int) {
|
||||
var unRead models.UnReadNotice
|
||||
raw := "select count(*) from notice where status = 2 and creator = ?"
|
||||
if err := global.Db.Raw(raw, uid).Scan(&unRead.Count).Error; err != nil {
|
||||
return unRead, response.ErrCodeFailed
|
||||
}
|
||||
return unRead, response.ErrCodeSuccess
|
||||
}
|
||||
|
||||
// 删除通知
|
||||
func (n *NoticeService) Delete(param *models.NoticeDeleteParam) int {
|
||||
err := global.Db.Delete(&models.Notice{}, param.Ids).Error
|
||||
if err != nil {
|
||||
return response.ErrCodeFailed
|
||||
}
|
||||
return response.ErrCodeSuccess
|
||||
}
|
||||
|
||||
// 获取通知列表
|
||||
func (n *NoticeService) GetList(uid int64) ([]*models.NoticeList, int) {
|
||||
noticeList := make([]*models.NoticeList, 0)
|
||||
if err := global.Db.Table(NOTICE).Where("creator = ?", uid).Order("status desc").Order("created desc").Find(¬iceList).Error; err != nil {
|
||||
return nil, response.ErrCodeFailed
|
||||
}
|
||||
return noticeList, response.ErrCodeSuccess
|
||||
}
|
||||
@@ -20,6 +20,14 @@ const (
|
||||
)
|
||||
|
||||
type SubscribeService struct {
|
||||
noticeService *NoticeService
|
||||
}
|
||||
|
||||
func NewSubscribeService() *SubscribeService {
|
||||
subscribeService := SubscribeService{
|
||||
noticeService: &NoticeService{},
|
||||
}
|
||||
return &subscribeService
|
||||
}
|
||||
|
||||
// 订阅专业版,发起支付
|
||||
@@ -96,11 +104,14 @@ func (s *SubscribeService) Callback(outTradeNo string) (string, int) {
|
||||
|
||||
// 创建订阅信息
|
||||
var expired int64
|
||||
var content string
|
||||
switch order.Version {
|
||||
case 2:
|
||||
expired = time.Now().Unix() + int64(2592000)
|
||||
content = SUBSCRIBE_NOTICE_TEMPLATE1
|
||||
case 3:
|
||||
expired = time.Now().Unix() + int64(31104000)
|
||||
content = SUBSCRIBE_NOTICE_TEMPLATE2
|
||||
}
|
||||
subscribe := models.Subscribe{
|
||||
Version: order.Version,
|
||||
@@ -121,11 +132,12 @@ func (s *SubscribeService) Callback(outTradeNo string) (string, int) {
|
||||
}
|
||||
}
|
||||
|
||||
// 修改支付状态
|
||||
key := fmt.Sprintf("uid:%v:pay:status", order.Uid)
|
||||
if err := global.Rdb.Set(ctx, key, Payed, time.Hour*10).Err(); err != nil {
|
||||
return StringNull, response.ErrCodeFailed
|
||||
}
|
||||
// 订阅通知
|
||||
s.noticeService.Create(&models.NoticeParam{
|
||||
Content: content,
|
||||
Creator: order.Uid,
|
||||
})
|
||||
|
||||
return global.Config.Alipay.PaySuccessURL, response.ErrCodeSuccess
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,14 @@ const (
|
||||
)
|
||||
|
||||
type UserService struct {
|
||||
noticeService *NoticeService
|
||||
}
|
||||
|
||||
func NewUserService() *UserService {
|
||||
userService := UserService{
|
||||
noticeService: &NoticeService{},
|
||||
}
|
||||
return &userService
|
||||
}
|
||||
|
||||
// 用户注册
|
||||
@@ -75,6 +83,12 @@ func (u *UserService) Register(param *models.UserCreateParam) int {
|
||||
}
|
||||
}
|
||||
|
||||
// 注册通知
|
||||
u.noticeService.Create(&models.NoticeParam{
|
||||
Content: REGISTER_NOTICE_TEMPLATE,
|
||||
Creator: newUser.Id,
|
||||
})
|
||||
|
||||
return response.ErrCodeSuccess
|
||||
}
|
||||
|
||||
@@ -106,6 +120,12 @@ func (u *UserService) Login(param *models.UserLoginParam) (*models.UserInfo, int
|
||||
Token: token,
|
||||
}
|
||||
|
||||
// 登录通知
|
||||
u.noticeService.Create(&models.NoticeParam{
|
||||
Content: LOGIN_NOTICE_TEMPLATE,
|
||||
Creator: userInfo.Uid,
|
||||
})
|
||||
|
||||
return &userInfo, response.ErrCodeSuccess
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user