fix: app message

master
howell 3 years ago
parent c9b6cda0d8
commit 363267b142

@ -5,6 +5,7 @@ import (
"recook/internal/libs/phonedata"
"github.com/golangkit/formatime"
"github.com/jinzhu/gorm"
)
type Information struct {
@ -76,7 +77,7 @@ func (i *Information) IsVip() bool {
return i.Level == 10 || (i.Level == 2 && i.IsOffline && !i.VipUpgradeEnd.Valid)
}
func (i *Information) BeforeCreate() (err error) {
func (i *Information) BeforeCreate(*gorm.DB) (err error) {
if len(i.Mobile) == 11 {
pr, e := phonedata.Find(i.Mobile)
if e != nil {

@ -0,0 +1,58 @@
package msg
import (
"recook/internal/back"
"recook/internal/libs/bean"
"recook/internal/v2/lib/common"
"recook/internal/v2/logic/msg"
"recook/tools"
"github.com/gin-gonic/gin"
)
type Proxy struct{}
func (o Proxy) List(c *gin.Context) {
var args msg.MessageReq
if err := tools.ParseParams(&args, c); err != nil {
back.Fail(c, err.Error())
}
id, _ := common.GetAppUserId(c)
args.UserID = id
data, total := msg.Logic.List(args)
back.Suc(c, "ok", bean.ResultLists{
List: data,
Total: int(total),
})
}
func (o Proxy) Read(c *gin.Context) {
var args msg.MessageReq
if err := tools.ParseParams(&args, c); err != nil {
back.Fail(c, err.Error())
}
id, _ := common.GetAppUserId(c)
args.UserID = id
if err := msg.Logic.Read(args); err != nil {
back.Fail(c, err.Error())
} else {
back.Suc(c, "ok", "")
}
}
func (o Proxy) ReadAll(c *gin.Context) {
var args msg.MessageReq
if err := tools.ParseParams(&args, c); err != nil {
back.Fail(c, err.Error())
}
id, _ := common.GetAppUserId(c)
args.UserID = id
args.IsAll = true
if err := msg.Logic.Read(args); err != nil {
back.Fail(c, err.Error())
} else {
back.Suc(c, "ok", "")
}
}

@ -0,0 +1,35 @@
package msg
import (
"recook/internal/libs/bean"
"recook/internal/v2/model/jyy"
"git.oa00.com/go/mysql"
)
type logic struct{}
var Logic = logic{}
type MessageReq struct {
bean.Page
UserID uint `json:"-"`
ID int `json:"id"`
IsAll bool `json:"-"`
}
func (o logic) List(args MessageReq) (data []jyy.AppUserMessage, total int64) {
query := mysql.Db.Table((&jyy.AppUserMessage{}).TableName())
query.Count(&total)
query.Limit(args.GetLimit()).Offset(args.GetStart()).Find(&data)
return
}
func (o logic) Read(args MessageReq) error {
query := mysql.Db.Table((&jyy.AppUserMessage{}).TableName())
if !args.IsAll {
query = query.Where("id = ?", args.ID)
}
query.Update("is_read", true)
return nil
}

@ -2,6 +2,7 @@ package jyy
import (
"recook/internal/v2/model/recook/goods"
"time"
"github.com/golangkit/formatime"
"gorm.io/gorm"
@ -90,3 +91,24 @@ type Contact struct {
func (o Contact) TableName() string {
return "jyy_contact"
}
type MessageKind int
const (
Profit MessageKind = iota + 1
Order
)
type AppUserMessage struct {
ID int `json:"id"`
UserID int `json:"user_id"`
Message string `json:"message"`
Kind MessageKind `json:"kind"`
IsRead bool `json:"is_read"`
SubID uint64 `json:"sub_id"`
CreatedAt *time.Time `json:"created_at" gorm:"autoCreateTime"`
}
func (o AppUserMessage) TableName() string {
return "recook_user_message_centor"
}

@ -9,6 +9,7 @@ import (
"recook/internal/v2/controller/app/jcook"
"recook/internal/v2/controller/app/jyy"
"recook/internal/v2/controller/app/message"
"recook/internal/v2/controller/app/msg"
"recook/internal/v2/controller/app/operate"
"recook/internal/v2/controller/app/order"
"recook/internal/v2/controller/app/productportrait"
@ -280,4 +281,14 @@ func routerApp(appRouter *gin.RouterGroup) {
}
}
messageController := appRouter.Group("message", authorize)
{
proxy := msg.Proxy{}
{
messageController.POST("list", proxy.List)
messageController.POST("read", proxy.Read)
messageController.POST("read_all", proxy.ReadAll)
}
}
}

Loading…
Cancel
Save