1.注释对外提供的接口,只保留后台相关接口;
2.添加定时任务,每晚01:30查询现有用户是否有退订情况;
This commit is contained in:
parent
bd4f3e6333
commit
f8e1a6e92d
2
Makefile
2
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
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) // 查询是否已经退订接口(咪咕)-对外
|
||||
//}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}()
|
||||
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user