From f8e1a6e92de6abcefecb3f0148ccaa62b56cb6bb Mon Sep 17 00:00:00 2001 From: chenlin Date: Tue, 22 Oct 2024 17:59:50 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=B3=A8=E9=87=8A=E5=AF=B9=E5=A4=96=E6=8F=90?= =?UTF-8?q?=E4=BE=9B=E7=9A=84=E6=8E=A5=E5=8F=A3=EF=BC=8C=E5=8F=AA=E4=BF=9D?= =?UTF-8?q?=E7=95=99=E5=90=8E=E5=8F=B0=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=EF=BC=9B=202.=E6=B7=BB=E5=8A=A0=E5=AE=9A=E6=97=B6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=EF=BC=8C=E6=AF=8F=E6=99=9A01:30=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E7=8E=B0=E6=9C=89=E7=94=A8=E6=88=B7=E6=98=AF=E5=90=A6=E6=9C=89?= =?UTF-8?q?=E9=80=80=E8=AE=A2=E6=83=85=E5=86=B5=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 2 +- app/admin/models/migu.go | 78 ++-------------------------------------- app/admin/router/migu.go | 44 +++++++++++------------ cmd/api/server.go | 12 +------ docs/admin/admin_docs.go | 4 +-- 5 files changed, 29 insertions(+), 111 deletions(-) diff --git a/Makefile b/Makefile index 390baec..dae027e 100644 --- a/Makefile +++ b/Makefile @@ -55,5 +55,5 @@ deploy: dev: - GOOS=linux GOARCH=amd64 go build -o temp_migu_server main.go + GOOS=linux GOARCH=amd64 go build -o temp_migu_admin_server main.go diff --git a/app/admin/models/migu.go b/app/admin/models/migu.go index 1f28e57..49b58a8 100644 --- a/app/admin/models/migu.go +++ b/app/admin/models/migu.go @@ -888,8 +888,8 @@ func GetChannelInfoByChannelCode(channel string, db *gorm.DB) (MgChannel, error) return channelInfo, nil } -// CheckOrderState 定时任务,检查订单状态,是否有1小时退订 -func CheckOrderState() { +// CheckAllOrderState 定时任务,检查历史订阅用户有无退订 +func CheckAllOrderState() { if database.Db == nil { log.Println("Database connection is nil") fmt.Println("Database connection is nil") @@ -899,12 +899,7 @@ func CheckOrderState() { // 查询订单列表中未退订的用户,查询其是否退订;如果退订,则更新退订时间,判断是否为1小时内退订 var orderList []MgOrder - // 获取当前时间前2个小时 - oneHourAgo := time.Now().Add(-2 * time.Hour) - - err := database.Db.Where("is_one_hour_cancel != 1"). - Where("created_at >= ?", oneHourAgo). - Order("created_at desc"). + err := database.Db.Where("state = 1").Order("created_at desc"). Find(&orderList).Error if err != nil { @@ -980,70 +975,3 @@ func CheckOrderState() { } } } - -// CheckAllOrderState 定时任务,检查所有非1小时退订订单 -func CheckAllOrderState() { - if database.Db == nil { - log.Println("Database connection is nil") - fmt.Println("Database connection is nil") - return - } - - // 查询订单列表中未退订的用户,查询其是否退订;如果退订,则更新退订时间,判断是否为1小时内退订 - var orderList []MgOrder - - err := database.Db.Where("is_one_hour_cancel != 1").Order("created_at desc"). - Find(&orderList).Error - - if err != nil { - fmt.Println("query mg_order err:", err.Error()) - return - } - - for i, _ := range orderList { - for j := 0; j < 3; j++ { - var req QueryRightsInfoReq - req.AppChannelList = append(req.AppChannelList, ChannelCode) - req.Mobile = orderList[i].PhoneNumber - - resp, err := MiGuQueryRightsInfo(&req) - if err != nil { - fmt.Println("CheckOrderState MiGuQueryRightsInfo err:", err.Error()) - logger.Errorf("CheckOrderState MiGuQueryRightsInfo err:", err.Error()) - continue - } - - // 有退订数据 - if len(resp.ResultData) != 0 { - if resp.ResultData[0].IsUnsub == 1 { - var cancelFlag int - subscribeTime := orderList[i].SubscribeTime - // 检查 subscribeTime 是否为 nil - if subscribeTime != nil && IsWithinOneHourCancel(*subscribeTime, resp.ResultData[0].UnsubTime) { - cancelFlag = 1 - } - - err = database.Db.Table("mg_order").Where("order_serial = ?", orderList[i].OrderSerial).Updates(map[string]interface{}{ - "state": UnsubscribeOK, - "is_one_hour_cancel": cancelFlag, - "unsubscribe_time": resp.ResultData[0].UnsubTime, - "updated_at": time.Now(), - }).Error - if err != nil { - fmt.Println("CheckOrderState update mg_order err:", err.Error()) - logger.Errorf("CheckOrderState update mg_order err:", err.Error()) - logger.Errorf("CheckOrderState order_serial:", orderList[i].OrderSerial) - continue - } - break - } - } else { - if j == 2 { - fmt.Println("resp.ResultData is null, phone_number is:", req.Mobile) - logger.Errorf("resp.ResultData is null, phone_number is:", req.Mobile) - } - continue - } - } - } -} diff --git a/app/admin/router/migu.go b/app/admin/router/migu.go index 79db8c9..a3cfe34 100644 --- a/app/admin/router/migu.go +++ b/app/admin/router/migu.go @@ -33,26 +33,26 @@ func registerMiGuControlManageRouter(v1 *gin.RouterGroup, authMiddleware *jwt.Gi // registerMiGuControlManageUnAuthRouter 无需认证的路由代码 func registerMiGuControlManageUnAuthRouter(v1 *gin.RouterGroup) { - apiMiGu := migumanage.MiGuDeployService{} - api := v1.Group("/notice") - { - api.GET("subscribe", apiMiGu.SubscribeNotice) // 订购成功通知 - api.GET("unsubscribe", apiMiGu.UnsubscribeNotice) // 退订通知 - } - - apiPost := v1.Group("/migu") - { - apiPost.POST("send_captcha", apiMiGu.SendCaptcha) // 下单接口(下发验证码) - apiPost.POST("submit_order", apiMiGu.SubmitOrder) // 提交接口(提交验证码) - apiPost.POST("order/check", apiMiGu.CheckOrder) // 查询是否已经退订接口 - apiPost.POST("order/check_rights_info", apiMiGu.CheckRightsInfo) // 查询是否已经退订接口(咪咕) - } - - apiEx := v1.Group("/coupon_provider") - { - apiEx.POST("send_captcha", apiMiGu.SendCaptchaEx) // 下单接口(下发验证码)-对外 - apiEx.POST("submit_order", apiMiGu.SubmitOrderEx) // 提交接口(提交验证码)-对外 - apiEx.POST("order/check", apiMiGu.CheckOrderEx) // 查询是否已经退订接口-对外 - apiEx.POST("order/check_rights_info", apiMiGu.CheckRightsInfoEx) // 查询是否已经退订接口(咪咕)-对外 - } + //apiMiGu := migumanage.MiGuDeployService{} + //api := v1.Group("/notice") + //{ + // api.GET("subscribe", apiMiGu.SubscribeNotice) // 订购成功通知 + // api.GET("unsubscribe", apiMiGu.UnsubscribeNotice) // 退订通知 + //} + // + //apiPost := v1.Group("/migu") + //{ + // apiPost.POST("send_captcha", apiMiGu.SendCaptcha) // 下单接口(下发验证码) + // apiPost.POST("submit_order", apiMiGu.SubmitOrder) // 提交接口(提交验证码) + // apiPost.POST("order/check", apiMiGu.CheckOrder) // 查询是否已经退订接口 + // apiPost.POST("order/check_rights_info", apiMiGu.CheckRightsInfo) // 查询是否已经退订接口(咪咕) + //} + // + //apiEx := v1.Group("/coupon_provider") + //{ + // apiEx.POST("send_captcha", apiMiGu.SendCaptchaEx) // 下单接口(下发验证码)-对外 + // apiEx.POST("submit_order", apiMiGu.SubmitOrderEx) // 提交接口(提交验证码)-对外 + // apiEx.POST("order/check", apiMiGu.CheckOrderEx) // 查询是否已经退订接口-对外 + // apiEx.POST("order/check_rights_info", apiMiGu.CheckRightsInfoEx) // 查询是否已经退订接口(咪咕)-对外 + //} } diff --git a/cmd/api/server.go b/cmd/api/server.go index 2517997..0232d4e 100644 --- a/cmd/api/server.go +++ b/cmd/api/server.go @@ -92,21 +92,11 @@ func run() error { // TODO s := gocron.NewScheduler() - //err := s.Every(1).Day().At("18:01").Do(models.CheckOrderState) - //if err != nil { - // fmt.Println("err:", err) - //} - - err := s.Every(10).Minute().Do(models.CheckOrderState) + err := s.Every(1).Day().At("01:30").Do(models.CheckAllOrderState) if err != nil { fmt.Println("err:", err) } - //err = s.Every(1).Day().At("10:28").Do(models.CheckAllOrderState) - //if err != nil { - // fmt.Println("err:", err) - //} - <-s.Start() }() diff --git a/docs/admin/admin_docs.go b/docs/admin/admin_docs.go index d4b73f4..fc3754a 100644 --- a/docs/admin/admin_docs.go +++ b/docs/admin/admin_docs.go @@ -6296,8 +6296,8 @@ var SwaggerInfoadmin = &swag.Spec{ Description: "基于Gin + Vue + Element UI的前后端分离权限管理系统的接口文档\n添加qq群: 521386980 进入技术交流群 请先star,谢谢!", InfoInstanceName: "admin", SwaggerTemplate: docTemplateadmin, - LeftDelim: "{{", - RightDelim: "}}", + //LeftDelim: "{{", + //RightDelim: "}}", } func init() {