From c5535e5d2b07a9db41750d5cc95c470cd5ae80aa Mon Sep 17 00:00:00 2001 From: howell <2827207845@qq.com> Date: Wed, 16 Mar 2022 10:55:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=BF=80=E6=B4=BB=E6=9E=81=E5=85=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/v2/controller/app/push/push.go | 59 +++++++++++++++++++++++++ internal/v2/lib/common/function.go | 5 ++- internal/v2/router/app.go | 8 ++++ 3 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 internal/v2/controller/app/push/push.go diff --git a/internal/v2/controller/app/push/push.go b/internal/v2/controller/app/push/push.go new file mode 100644 index 0000000..1b0dc0a --- /dev/null +++ b/internal/v2/controller/app/push/push.go @@ -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 + } + } + +} diff --git a/internal/v2/lib/common/function.go b/internal/v2/lib/common/function.go index 4e716aa..8831fa3 100644 --- a/internal/v2/lib/common/function.go +++ b/internal/v2/lib/common/function.go @@ -3,8 +3,6 @@ package common import ( "errors" "fmt" - "github.com/gin-gonic/gin" - "github.com/shopspring/decimal" "image" _ "image/gif" _ "image/jpeg" @@ -20,6 +18,9 @@ import ( "recook/tools" "reflect" "time" + + "github.com/gin-gonic/gin" + "github.com/shopspring/decimal" ) // @Style 获取登录管理账号信息 diff --git a/internal/v2/router/app.go b/internal/v2/router/app.go index f759340..864fa5d 100644 --- a/internal/v2/router/app.go +++ b/internal/v2/router/app.go @@ -12,6 +12,7 @@ import ( "recook/internal/v2/controller/app/operate" "recook/internal/v2/controller/app/order" "recook/internal/v2/controller/app/productportrait" + "recook/internal/v2/controller/app/push" "recook/internal/v2/controller/app/seckill" "recook/internal/v2/controller/app/shoppingcart" "recook/internal/v2/controller/app/upgrade" @@ -271,5 +272,12 @@ func routerApp(appRouter *gin.RouterGroup) { vipController.POST("is_used", proxy.VipIsUsed) } } + pushController := appRouter.Group("push", authorize) + { + proxy := push.Proxy{} + { + pushController.POST("active", proxy.Active) + } + } }