You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.3 KiB
54 lines
1.3 KiB
package users
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"recook/internal/back"
|
|
"recook/internal/dbc"
|
|
"recook/internal/model/user"
|
|
"recook/tools"
|
|
"strconv"
|
|
)
|
|
|
|
type NoticelistPem struct {
|
|
Uid int `json:"uid"`
|
|
}
|
|
|
|
func NoticeList(c *gin.Context) {
|
|
var p NoticelistPem
|
|
err := tools.ParseParams(&p, c)
|
|
if err != nil {
|
|
back.Fail(c, err.Error())
|
|
return
|
|
}
|
|
|
|
var ids []uint
|
|
|
|
var userNotice []user.Notice
|
|
dbc.DB.Where("is_show=0 and user_id = ?", p.Uid).Find(&userNotice)
|
|
recommendNum := 0
|
|
var userNoticeNew []user.Notice
|
|
for _, userNoticeList := range userNotice {
|
|
ids = append(ids, userNoticeList.ID)
|
|
//这边要封装下推荐的代码
|
|
if userNoticeList.Type == 1 {
|
|
//"推荐了X位大咖"
|
|
recommendNum++
|
|
} else {
|
|
userNoticeNew = append(userNoticeNew, userNoticeList)
|
|
}
|
|
}
|
|
if recommendNum != 0 {
|
|
userNoticeNew = append(userNoticeNew, user.Notice{
|
|
Type: 1,
|
|
Content: "您成功推荐了" + strconv.Itoa(recommendNum) + "位大咖,恭喜获得" + strconv.Itoa(recommendNum) + "张升级卡和保级卡",
|
|
})
|
|
}
|
|
|
|
dbc.DB.Model(user.Notice{}).Where("id IN (?)", ids).Updates(user.Notice{IsShow: 1})
|
|
|
|
//dbc.DB.Table("recook_user_notice").Where("id IN (?)", ids).Updates(map[string]interface{}{"is_show":"1"})
|
|
|
|
back.Suc(c, "获取成功", &userNoticeNew)
|
|
return
|
|
}
|