From 7f3ef982b08f185cab128260e1f9bf775db46620 Mon Sep 17 00:00:00 2001 From: chenlin Date: Tue, 22 Oct 2024 17:41:42 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=B3=A8=E9=87=8A=E5=90=8E=E5=8F=B0=E9=83=A8?= =?UTF-8?q?=E5=88=86=E6=8E=A5=E5=8F=A3=EF=BC=8C=E5=90=8E=E7=AB=AF=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E4=BD=BF=E7=94=A8=E5=8F=A6=E5=A4=96=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=EF=BC=9B=202.=E4=BF=AE=E6=94=B9=E5=9B=9E?= =?UTF-8?q?=E8=B0=83=E9=80=9A=E7=9F=A5=E6=8E=A5=E5=8F=A3=EF=BC=8C=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E5=AD=90=E6=B8=A0=E9=81=93=E6=97=B6=EF=BC=8C=E5=A6=82?= =?UTF-8?q?=E6=9E=9C=E6=B8=A0=E9=81=93=E4=BF=A1=E6=81=AF=E6=9C=89=E5=A4=87?= =?UTF-8?q?=E6=B3=A8"add=20channel"=E5=88=99=E5=9C=A8=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E7=9A=84url=E6=B7=BB=E5=8A=A0=E5=8F=82=E6=95=B0channel?= =?UTF-8?q?=EF=BC=8C=E5=9B=9E=E4=BC=A0=E4=B8=BB=E6=B8=A0=E9=81=93=E7=BC=96?= =?UTF-8?q?=E7=A0=81=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/apis/migumanage/migu_notice.go | 4 +- app/admin/models/migu.go | 77 +++--------------------- app/admin/router/migu.go | 42 ++++++------- cmd/api/server.go | 10 --- docs/admin/admin_docs.go | 4 +- 5 files changed, 34 insertions(+), 103 deletions(-) diff --git a/app/admin/apis/migumanage/migu_notice.go b/app/admin/apis/migumanage/migu_notice.go index 007c995..f3bca28 100644 --- a/app/admin/apis/migumanage/migu_notice.go +++ b/app/admin/apis/migumanage/migu_notice.go @@ -135,7 +135,7 @@ func (e MiGuDeployService) SubscribeNotice(c *gin.Context) { if channelInfo.SubscribeURL != "" { for i := 0; i < 3; i++ { resp, err := models.NoticeSubChannel(channelInfo.SubscribeURL, orderInfo.OrderSerial, - orderInfo.ChannelTradeNo, "1") + orderInfo.ChannelTradeNo, "1", channelInfo.MainChannelCode, channelInfo.Remarks) if err != nil { fmt.Println("NoticeSubChannel err:", err) fmt.Println("i is:", i) @@ -238,7 +238,7 @@ func (e MiGuDeployService) UnsubscribeNotice(c *gin.Context) { if channelInfo.SubscribeURL != "" { for i := 0; i < 3; i++ { resp, err := models.NoticeSubChannel(channelInfo.SubscribeURL, orderInfo.OrderSerial, - orderInfo.ChannelTradeNo, "2") + orderInfo.ChannelTradeNo, "2", channelInfo.MainChannelCode, channelInfo.Remarks) if err != nil { continue } diff --git a/app/admin/models/migu.go b/app/admin/models/migu.go index 1f28e57..b1de017 100644 --- a/app/admin/models/migu.go +++ b/app/admin/models/migu.go @@ -13,6 +13,7 @@ import ( "math/rand" "net/http" "net/url" + "strings" "sync" "time" ) @@ -32,6 +33,8 @@ const ( UnsubscribeOK = 2 // 退订 SKUCODE = "miguyouxizuanshihuiyuan-yy" + + AddRemark = "add channel" ) // 以下是数据库表结构 @@ -704,7 +707,7 @@ func MiGuQueryRightsInfo(r *QueryRightsInfoReq) (QueryRightsInfoResp, error) { } // NoticeSubChannel 回调通知接口 (GET 请求,返回string类型,响应头为text/plain) -func NoticeSubChannel(baseUrl, linkId, extData, status string) (string, error) { +func NoticeSubChannel(baseUrl, linkId, extData, status, mainChannelCode, remarks string) (string, error) { // 构建 GET 请求的 URL requestUrl, err := url.Parse(baseUrl) if err != nil { @@ -716,6 +719,11 @@ func NoticeSubChannel(baseUrl, linkId, extData, status string) (string, error) { query.Set("orderId", linkId) query.Set("extData", extData) query.Set("status", status) + + if strings.Contains(remarks, AddRemark) { + query.Set("channel", mainChannelCode) + } + requestUrl.RawQuery = query.Encode() fmt.Println("NoticeSubChannel url:", requestUrl.String()) @@ -980,70 +988,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..e16145a 100644 --- a/app/admin/router/migu.go +++ b/app/admin/router/migu.go @@ -8,27 +8,27 @@ import ( // registerMiGuControlManageRouter 需认证的路由代码 func registerMiGuControlManageRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) { - apiMiGu := migumanage.MiGuDeployService{} - api := v1.Group("/admin") - { - api.POST("product/list", apiMiGu.ProductList) // 查询权益产品 - api.POST("product/add", apiMiGu.AddProduct) // 新增产品 - //api.POST("product/update", apiMiGu.UpdateProduct) // 编辑产品 - //api.POST("product/delete", apiMiGu.DeleteProduct) // 删除产品 - - api.POST("channel/list", apiMiGu.ChannelList) // 查询渠道列表 - api.POST("channel/add", apiMiGu.AddChannel) // 新增渠道 - //api.POST("channel/update", apiMiGu.UpdateChannel) // 编辑渠道 - //api.POST("channel/delete", apiMiGu.DeleteChannel) // 删除渠道 - - api.POST("transaction/list", apiMiGu.TransactionList) // 查询交易流水记录 - api.POST("order/list", apiMiGu.OrderList) // 查询订单列表 - api.POST("historical_summary/list", apiMiGu.HistoricalSummaryList) // 历史汇总查询 - api.POST("realtime_summary/list", apiMiGu.RealtimeSummaryList) // 当日实时汇总 - api.POST("user_retention/list", apiMiGu.UserRetentionList) // 用户留存记录 - api.POST("sys_channel/list", apiMiGu.SysChannelList) // 查询系统所有渠道编码 - api.POST("home/data", apiMiGu.HomepageDataSummary) // 查询首页汇总数据 - } + //apiMiGu := migumanage.MiGuDeployService{} + //api := v1.Group("/admin") + //{ + // api.POST("product/list", apiMiGu.ProductList) // 查询权益产品 + // api.POST("product/add", apiMiGu.AddProduct) // 新增产品 + // //api.POST("product/update", apiMiGu.UpdateProduct) // 编辑产品 + // //api.POST("product/delete", apiMiGu.DeleteProduct) // 删除产品 + // + // api.POST("channel/list", apiMiGu.ChannelList) // 查询渠道列表 + // api.POST("channel/add", apiMiGu.AddChannel) // 新增渠道 + // //api.POST("channel/update", apiMiGu.UpdateChannel) // 编辑渠道 + // //api.POST("channel/delete", apiMiGu.DeleteChannel) // 删除渠道 + // + // api.POST("transaction/list", apiMiGu.TransactionList) // 查询交易流水记录 + // api.POST("order/list", apiMiGu.OrderList) // 查询订单列表 + // api.POST("historical_summary/list", apiMiGu.HistoricalSummaryList) // 历史汇总查询 + // api.POST("realtime_summary/list", apiMiGu.RealtimeSummaryList) // 当日实时汇总 + // api.POST("user_retention/list", apiMiGu.UserRetentionList) // 用户留存记录 + // api.POST("sys_channel/list", apiMiGu.SysChannelList) // 查询系统所有渠道编码 + // api.POST("home/data", apiMiGu.HomepageDataSummary) // 查询首页汇总数据 + //} } // registerMiGuControlManageUnAuthRouter 无需认证的路由代码 diff --git a/cmd/api/server.go b/cmd/api/server.go index 2517997..1ca2de8 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) 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() {