parent
ce3933bd6f
commit
c5535e5d2b
@ -0,0 +1,59 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue