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.

60 lines
1.2 KiB

package push
import (
"recook/internal/back"
"recook/internal/v2/lib/common"
"recook/internal/v2/model/jpush"
"recook/tools"
"git.oa00.com/go/mysql"
"github.com/gin-gonic/gin"
"github.com/jinzhu/gorm"
)
type Proxy struct {
}
type PusherActivity struct {
RegisterID string `json:"register_id"`
Type int `json:"int" binding:"oneof=1 2"`
}
func (o Proxy) Active(c *gin.Context) {
id, err := common.GetAppUserId(c)
if err != nil {
back.Fail(c, err.Error())
return
}
var args PusherActivity
if err := tools.ParseParams(&args, c); err != nil {
back.Err(c, err.Error())
return
}
var ju jpush.JPush
if err := mysql.Db.First(&ju, "user_id = ?", id).Error; err != nil {
if err != gorm.ErrRecordNotFound {
back.Err(c, err.Error())
return
} else {
// create
if err := mysql.Db.Create(&jpush.JPush{
UserId: id,
RegistrationId: args.RegisterID,
Type: args.Type,
}).Error; err != nil {
back.Err(c, err.Error())
return
}
}
} else {
if err := mysql.Db.Model(&ju).Updates(jpush.JPush{
RegistrationId: args.RegisterID,
Type: args.Type,
}).Error; err != nil {
back.Err(c, err.Error())
return
}
}
}