|
@@ -34,6 +34,7 @@ type unpaidOrder struct {
|
|
|
remindStatus int //1-下单时间2小时提醒 2-剩余2小时自动关闭时再次提醒
|
|
|
vipType int //-1:直接购买 0:试用 1:续费 2:升级
|
|
|
orderMoney int //订单金额
|
|
|
+ productType string
|
|
|
}
|
|
|
|
|
|
/*新的订单存库以后,再存入内存中
|
|
@@ -44,8 +45,9 @@ type unpaidOrder struct {
|
|
|
*@param orderCode 订单编号
|
|
|
*@param userId 用户id
|
|
|
*@param prepayTime 购买时间
|
|
|
+ *@param productType 产品类型
|
|
|
*/
|
|
|
-func (m *msgRemind) Add(orderId, orderMoney, vipType, remindStatus int, orderCode, userId string, prepayTime int64) {
|
|
|
+func (m *msgRemind) add(orderId, orderMoney, vipType, remindStatus int, orderCode, userId string, prepayTime int64, productType string) {
|
|
|
log.Println("未支付待提醒订单加入", orderId, orderCode, userId, prepayTime)
|
|
|
m.unpaidOrders.Store(orderId, &unpaidOrder{
|
|
|
orderCode: orderCode,
|
|
@@ -55,19 +57,20 @@ func (m *msgRemind) Add(orderId, orderMoney, vipType, remindStatus int, orderCod
|
|
|
orderMoney: orderMoney,
|
|
|
vipType: vipType,
|
|
|
remindStatus: remindStatus,
|
|
|
+ productType: productType,
|
|
|
})
|
|
|
}
|
|
|
|
|
|
/*删除待提醒的订单
|
|
|
*@param orderId 订单id
|
|
|
*/
|
|
|
-func (m *msgRemind) Delete(orderId int) {
|
|
|
+func (m *msgRemind) delete(orderId int) {
|
|
|
log.Println("删除待提醒的订单", orderId)
|
|
|
m.unpaidOrders.Delete(orderId)
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
- *订单支付成功以后,消息通知处理
|
|
|
+ *超级订阅订单支付成功以后,消息通知处理
|
|
|
*@param orderId 订单id
|
|
|
*@param orderCode 订单编号
|
|
|
*@param userId 用户id
|
|
@@ -77,7 +80,7 @@ func (m *msgRemind) Delete(orderId int) {
|
|
|
func (m *msgRemind) PaySuccess(orderId int, orderCode, userId, prepayTime string, vipType int) {
|
|
|
go func() {
|
|
|
defer util.Catch()
|
|
|
- log.Println("支付成功以后,消息提醒处理", orderId, orderCode, userId, prepayTime)
|
|
|
+ log.Println("超级订阅支付成功以后,消息提醒处理", orderId, orderCode, userId, prepayTime)
|
|
|
m.unpaidOrders.Delete(orderId)
|
|
|
user, ok := MQFW.FindById("user", userId, `{"s_m_openid":1,"s_jpushid":1,"s_opushid":1,"s_appponetype":1,"i_ispush":1,"l_vip_endtime":1}`)
|
|
|
if !ok || user == nil || len(*user) == 0 {
|
|
@@ -88,19 +91,21 @@ func (m *msgRemind) PaySuccess(orderId int, orderCode, userId, prepayTime string
|
|
|
s_jpushid, _ := (*user)["s_jpushid"].(string)
|
|
|
s_opushid, _ := (*user)["s_opushid"].(string)
|
|
|
s_appponetype, _ := (*user)["s_appponetype"].(string)
|
|
|
- log.Println("支付成功,推送消息", userId, "s_m_openid", s_m_openid, "s_jpushid", s_jpushid, "s_opushid", s_opushid, "s_appponetype", s_appponetype)
|
|
|
+ log.Println("超级订阅支付成功,推送消息", userId, "s_m_openid", s_m_openid, "s_jpushid", s_jpushid, "s_opushid", s_opushid, "s_appponetype", s_appponetype)
|
|
|
if isPushWx == 1 && s_m_openid != "" {
|
|
|
l_vip_endtime := (*user)["l_vip_endtime"]
|
|
|
expireTime := util.FormatDateWithObj(&l_vip_endtime, util.Date_Short_Layout)
|
|
|
+ PaySuccess_WTMCS.Reload()
|
|
|
+ wtmc := PaySuccess_WTMCS.Get(MessageConfig.WxTpl_PaySuccess.First.Value)
|
|
|
wxPushOk, _ := qrpc.WxSendTmplMsg(Config.Weixinrpc, &qrpc.WxTmplMsg{
|
|
|
OpenId: s_m_openid,
|
|
|
TplId: MessageConfig.WxTpl_PaySuccess.Id,
|
|
|
TmplData: map[string]*qrpc.TmplItem{
|
|
|
"first": &qrpc.TmplItem{
|
|
|
- Value: fmt.Sprintf(MessageConfig.WxTpl_PaySuccess.First.Value, orderCode),
|
|
|
+ Value: strings.ReplaceAll(wtmc.FirstData, "@订单号", orderCode),
|
|
|
},
|
|
|
"keyword1": &qrpc.TmplItem{
|
|
|
- Value: fmt.Sprintf(MessageConfig.WxTpl_PaySuccess.Keyword1.Value, m.getVipType(vipType)),
|
|
|
+ Value: fmt.Sprintf(MessageConfig.WxTpl_PaySuccess.Keyword1.Value, "超级订阅"+m.getVipType(vipType)),
|
|
|
},
|
|
|
"keyword2": &qrpc.TmplItem{
|
|
|
Value: orderCode,
|
|
@@ -112,9 +117,9 @@ func (m *msgRemind) PaySuccess(orderId int, orderCode, userId, prepayTime string
|
|
|
Value: expireTime,
|
|
|
},
|
|
|
},
|
|
|
- Url: Config.WebDomain + "/front/sess/" + Se_Topnet.EncodeString(s_m_openid+",uid,"+strconv.Itoa(int(time.Now().Unix()))+",msgremind") + "__" + hex.EncodeToString([]byte(fmt.Sprintf("type=paid"))),
|
|
|
+ Url: Config.WebDomain + "/front/sess/" + Se_Topnet.EncodeString(s_m_openid+",uid,"+strconv.Itoa(int(time.Now().Unix()))+",msgremind") + "__" + hex.EncodeToString([]byte(fmt.Sprintf("type=paid&advertcode=%s", wtmc.AdvertCode))),
|
|
|
})
|
|
|
- log.Println("支付成功,微信推送", userId, wxPushOk)
|
|
|
+ log.Println("超级订阅支付成功,微信推送", userId, wxPushOk, wtmc.AdvertCode, wtmc.FirstData)
|
|
|
} else if s_opushid != "" || s_jpushid != "" {
|
|
|
appPushOk := qrpc.AppPush(Config.AppPushServiceRpc, map[string]interface{}{
|
|
|
"phoneType": s_appponetype,
|
|
@@ -123,22 +128,88 @@ func (m *msgRemind) PaySuccess(orderId int, orderCode, userId, prepayTime string
|
|
|
"url": "/jyapp/free/sess/" + Se_Topnet.EncodeString(userId+",uid,"+strconv.Itoa(int(time.Now().Unix()))+",msgremind") + "__" + hex.EncodeToString([]byte(fmt.Sprintf("type=paid"))),
|
|
|
"userId": userId,
|
|
|
"type": "vipNotice",
|
|
|
- "descript": fmt.Sprintf(MessageConfig.WxTpl_PaySuccess.First.Value, orderCode),
|
|
|
+ "descript": fmt.Sprintf(MessageConfig.App_PaySuccess, orderCode),
|
|
|
"title": "剑鱼提醒",
|
|
|
})
|
|
|
- log.Println("支付成功,app推送", userId, appPushOk)
|
|
|
+ log.Println("超级订阅支付成功,app推送", userId, appPushOk)
|
|
|
}
|
|
|
}()
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
- *订单支付成功以后,消息通知处理
|
|
|
+ *大会员订单支付成功以后,消息通知处理
|
|
|
*@param orderId 订单id
|
|
|
*@param orderCode 订单编号
|
|
|
*@param userId 用户id
|
|
|
*@param prepayTime 购买时间
|
|
|
*@param vipType -1:直接购买 0:试用 1:续费 2:升级
|
|
|
*/
|
|
|
+func (m *msgRemind) BigMemberPaySuccess(orderId int, orderCode, userId, prepayTime string, vipType int) {
|
|
|
+ go func() {
|
|
|
+ defer util.Catch()
|
|
|
+ log.Println("大会员支付成功以后,消息提醒处理", orderId, orderCode, userId, prepayTime)
|
|
|
+ m.unpaidOrders.Delete(orderId)
|
|
|
+ user, ok := MQFW.FindById("user", userId, `{"s_m_openid":1,"s_jpushid":1,"s_opushid":1,"s_appponetype":1,"i_ispush":1,"l_vip_endtime":1}`)
|
|
|
+ if !ok || user == nil || len(*user) == 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ isPushWx := util.IntAllDef((*user)["i_ispush"], 1)
|
|
|
+ s_m_openid, _ := (*user)["s_m_openid"].(string)
|
|
|
+ s_jpushid, _ := (*user)["s_jpushid"].(string)
|
|
|
+ s_opushid, _ := (*user)["s_opushid"].(string)
|
|
|
+ s_appponetype, _ := (*user)["s_appponetype"].(string)
|
|
|
+ log.Println("大会员支付成功,推送消息", userId, "s_m_openid", s_m_openid, "s_jpushid", s_jpushid, "s_opushid", s_opushid, "s_appponetype", s_appponetype)
|
|
|
+ if isPushWx == 1 && s_m_openid != "" {
|
|
|
+ l_vip_endtime := (*user)["l_vip_endtime"]
|
|
|
+ expireTime := util.FormatDateWithObj(&l_vip_endtime, util.Date_Short_Layout)
|
|
|
+ PaySuccess_WTMCS.Reload()
|
|
|
+ wtmc := PaySuccess_WTMCS.Get(MessageConfig.WxTpl_PaySuccess.First.Value)
|
|
|
+ wxPushOk, _ := qrpc.WxSendTmplMsg(Config.Weixinrpc, &qrpc.WxTmplMsg{
|
|
|
+ OpenId: s_m_openid,
|
|
|
+ TplId: MessageConfig.WxTpl_PaySuccess.Id,
|
|
|
+ TmplData: map[string]*qrpc.TmplItem{
|
|
|
+ "first": &qrpc.TmplItem{
|
|
|
+ Value: strings.ReplaceAll(wtmc.FirstData, "@订单号", orderCode),
|
|
|
+ },
|
|
|
+ "keyword1": &qrpc.TmplItem{
|
|
|
+ Value: fmt.Sprintf(MessageConfig.WxTpl_PaySuccess.Keyword1.Value, "大会员"+m.getVipType(vipType)),
|
|
|
+ },
|
|
|
+ "keyword2": &qrpc.TmplItem{
|
|
|
+ Value: orderCode,
|
|
|
+ },
|
|
|
+ "keyword3": &qrpc.TmplItem{
|
|
|
+ Value: strings.Split(prepayTime, " ")[0],
|
|
|
+ },
|
|
|
+ "keyword4": &qrpc.TmplItem{
|
|
|
+ Value: expireTime,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ Url: Config.WebDomain + "/front/sess/" + Se_Topnet.EncodeString(s_m_openid+",uid,"+strconv.Itoa(int(time.Now().Unix()))+",msgremind") + "__" + hex.EncodeToString([]byte(fmt.Sprintf("type=biemember_paid&&advertcode=%s", wtmc.AdvertCode))),
|
|
|
+ })
|
|
|
+ log.Println("大会员支付成功,微信推送", userId, wxPushOk, wtmc.AdvertCode, wtmc.FirstData)
|
|
|
+ } else if s_opushid != "" || s_jpushid != "" {
|
|
|
+ appPushOk := qrpc.AppPush(Config.AppPushServiceRpc, map[string]interface{}{
|
|
|
+ "phoneType": s_appponetype,
|
|
|
+ "otherPushId": s_opushid,
|
|
|
+ "jgPushId": s_jpushid,
|
|
|
+ "url": "/jyapp/free/sess/" + Se_Topnet.EncodeString(userId+",uid,"+strconv.Itoa(int(time.Now().Unix()))+",msgremind") + "__" + hex.EncodeToString([]byte(fmt.Sprintf("type=paid"))),
|
|
|
+ "userId": userId,
|
|
|
+ "type": "vipNotice",
|
|
|
+ "descript": fmt.Sprintf(MessageConfig.App_PaySuccess, orderCode),
|
|
|
+ "title": "剑鱼提醒",
|
|
|
+ })
|
|
|
+ log.Println("大会员支付成功,app推送", userId, appPushOk)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
+ *订单支付成功以后,消息通知处理
|
|
|
+ *@param orderId 订单id
|
|
|
+ *@param userId 用户id
|
|
|
+ *@param price 价格
|
|
|
+ *@param product 产品类型
|
|
|
+ */
|
|
|
func (m *msgRemind) DistributionSuccess(orderId int, userId string, price int, product string) {
|
|
|
go func() {
|
|
|
priceFloat := decimal.NewFromFloat(float64(price)).Div(decimal.NewFromFloat(float64(100)))
|
|
@@ -214,17 +285,19 @@ func (m *msgRemind) getVipType(vipType int) string {
|
|
|
}
|
|
|
|
|
|
func (m *msgRemind) run() {
|
|
|
- duration := TimeTaskConfig.UnpaidRemind.Duration
|
|
|
+ duration := TimeTaskConfig.UnpaidRemind.RemindDuration
|
|
|
if duration == 0 {
|
|
|
duration = 10
|
|
|
}
|
|
|
log.Println("未支付订单定时任务run after", duration, "m")
|
|
|
time.AfterFunc(time.Duration(duration)*time.Minute, func() {
|
|
|
defer util.Catch()
|
|
|
+ Unpaid_WTMCS.Reload()
|
|
|
m.unpaidOrders.Range(func(k interface{}, v interface{}) bool {
|
|
|
orderId, _ := k.(int)
|
|
|
unpaidOrder, _ := v.(*unpaidOrder)
|
|
|
if Mysql.CountBySql("select count(1) as count from dataexport_order where id=? and order_status=0 and del_status=0 and (remind_status<>2 or remind_status is null)", orderId) == 0 {
|
|
|
+ m.delete(orderId)
|
|
|
log.Println("未支付订单状态发生变化,不推送消息", unpaidOrder.userId, orderId, unpaidOrder.orderCode)
|
|
|
return true
|
|
|
}
|
|
@@ -251,9 +324,16 @@ func (m *msgRemind) run() {
|
|
|
log.Println("未支付订单,推送消息", unpaidOrder.userId, orderId, unpaidOrder.orderCode, "remind_status", remind_status, "i_ispush", isPushWx, "s_m_openid", s_m_openid, "s_jpushid", s_jpushid, "s_opushid", s_opushid, "s_appponetype", s_appponetype)
|
|
|
wxPushOk, appPushOk := false, false
|
|
|
if isPushWx == 1 && s_m_openid != "" {
|
|
|
+ wtmc := Unpaid_WTMCS.Get(MessageConfig.WxTpl_Unpaid.First.Value)
|
|
|
+ productType := unpaidOrder.productType
|
|
|
+ if productType == "VIP订阅" {
|
|
|
+ productType = "超级订阅"
|
|
|
+ } else if strings.HasPrefix(productType, "大会员") {
|
|
|
+ productType = "大会员"
|
|
|
+ }
|
|
|
tmplData := map[string]*qrpc.TmplItem{
|
|
|
"first": &qrpc.TmplItem{
|
|
|
- Value: fmt.Sprintf(MessageConfig.WxTpl_Unpaid.First.Value, unpaidOrder.orderCode),
|
|
|
+ Value: strings.ReplaceAll(wtmc.FirstData, "@订单号", unpaidOrder.orderCode),
|
|
|
Color: MessageConfig.WxTpl_Unpaid.First.Color,
|
|
|
},
|
|
|
"keyword1": &qrpc.TmplItem{
|
|
@@ -266,7 +346,7 @@ func (m *msgRemind) run() {
|
|
|
Value: fmt.Sprintf(MessageConfig.WxTpl_Unpaid.Keyword3.Value, fmt.Sprintf("%.2f", float64(unpaidOrder.orderMoney)/100)),
|
|
|
},
|
|
|
"keyword4": &qrpc.TmplItem{
|
|
|
- Value: fmt.Sprintf(MessageConfig.WxTpl_Unpaid.Keyword4.Value, m.getVipType(unpaidOrder.vipType)),
|
|
|
+ Value: fmt.Sprintf(MessageConfig.WxTpl_Unpaid.Keyword4.Value, productType+m.getVipType(unpaidOrder.vipType)),
|
|
|
},
|
|
|
}
|
|
|
if remind_status == 2 {
|
|
@@ -278,9 +358,9 @@ func (m *msgRemind) run() {
|
|
|
OpenId: s_m_openid,
|
|
|
TplId: MessageConfig.WxTpl_Unpaid.Id,
|
|
|
TmplData: tmplData,
|
|
|
- Url: Config.WebDomain + "/front/sess/" + Se_Topnet.EncodeString(s_m_openid+",uid,"+strconv.Itoa(int(time.Now().Unix()))+",msgremind") + "__" + hex.EncodeToString([]byte(fmt.Sprintf("type=unpaid&ordercode=%s", unpaidOrder.orderCode))),
|
|
|
+ Url: Config.WebDomain + "/front/sess/" + Se_Topnet.EncodeString(s_m_openid+",uid,"+strconv.Itoa(int(time.Now().Unix()))+",msgremind") + "__" + hex.EncodeToString([]byte(fmt.Sprintf("type=unpaid&ordercode=%s&advertcode=%s", unpaidOrder.orderCode, wtmc.AdvertCode))),
|
|
|
})
|
|
|
- log.Println("未支付订单,微信推送", unpaidOrder.userId, orderId, unpaidOrder.orderCode, wxPushOk)
|
|
|
+ log.Println("未支付订单,微信推送", unpaidOrder.userId, orderId, unpaidOrder.orderCode, wxPushOk, wtmc.AdvertCode, wtmc.FirstData)
|
|
|
} else if s_opushid != "" || s_jpushid != "" {
|
|
|
appPushOk = qrpc.AppPush(Config.AppPushServiceRpc, map[string]interface{}{
|
|
|
"phoneType": s_appponetype,
|
|
@@ -289,7 +369,7 @@ func (m *msgRemind) run() {
|
|
|
"url": "/jyapp/free/sess/" + Se_Topnet.EncodeString(unpaidOrder.userId+",uid,"+strconv.Itoa(int(time.Now().Unix()))+",msgremind") + "__" + hex.EncodeToString([]byte(fmt.Sprintf("type=unpaid&ordercode=%s", unpaidOrder.orderCode))),
|
|
|
"userId": unpaidOrder.userId,
|
|
|
"type": "vipNotice",
|
|
|
- "descript": fmt.Sprintf(MessageConfig.WxTpl_Unpaid.First.Value, unpaidOrder.orderCode),
|
|
|
+ "descript": fmt.Sprintf(MessageConfig.App_Unpaid, unpaidOrder.orderCode),
|
|
|
"title": "剑鱼提醒",
|
|
|
})
|
|
|
log.Println("未支付订单,app推送", unpaidOrder.userId, orderId, unpaidOrder.orderCode, appPushOk)
|
|
@@ -312,8 +392,39 @@ func (m *msgRemind) run() {
|
|
|
m.run()
|
|
|
})
|
|
|
}
|
|
|
+func (m *msgRemind) loadOrder() {
|
|
|
+ duration := TimeTaskConfig.UnpaidRemind.LoadOrderDuration
|
|
|
+ if duration == 0 {
|
|
|
+ duration = 8
|
|
|
+ }
|
|
|
+ time.AfterFunc(time.Duration(duration)*time.Minute, func() {
|
|
|
+ defer util.Catch()
|
|
|
+ log.Println("开始加载72小时内的订单到内存中。。。")
|
|
|
+ startTime := time.Unix(time.Now().Unix()-MsgRemind.getExpireTime(), 0)
|
|
|
+ startTimes := util.FormatDate(&startTime, util.Date_Full_Layout)
|
|
|
+ list := Mysql.SelectBySql("select id,order_code,order_money,user_id,prepay_time,remind_status,vip_type,product_type from dataexport_order where order_money>0 and prepay_time>=? and order_status=0 and del_status=0 and (remind_status<>2 or remind_status is null)", startTimes)
|
|
|
+ if list == nil {
|
|
|
+ log.Println("加载72小时内的订单到内存中失败")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range *list {
|
|
|
+ order_code, _ := v["order_code"].(string)
|
|
|
+ user_id, _ := v["user_id"].(string)
|
|
|
+ prepay_time, _ := v["prepay_time"].(string)
|
|
|
+ if order_code == "" || user_id == "" || prepay_time == "" {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ prepayTime, err := time.ParseInLocation(util.Date_Full_Layout, prepay_time, time.Local)
|
|
|
+ if err != nil {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ MsgRemind.add(util.IntAll(v["id"]), util.IntAll(v["order_money"]), util.IntAllDef(v["vip_type"], -1), util.IntAll(v["remind_status"]), order_code, user_id, prepayTime.Unix(), util.ObjToString(v["product_type"]))
|
|
|
+ }
|
|
|
+ log.Println("加载72小时内的订单到内存中结束。。。", len(*list))
|
|
|
+ })
|
|
|
+}
|
|
|
func (m *msgRemind) gc() {
|
|
|
- time.AfterFunc(5*time.Minute, func() {
|
|
|
+ time.AfterFunc(3*time.Minute, func() {
|
|
|
defer util.Catch()
|
|
|
m.unpaidOrders.Range(func(k interface{}, v interface{}) bool {
|
|
|
unpaidOrder, _ := v.(*unpaidOrder)
|
|
@@ -327,33 +438,8 @@ func (m *msgRemind) gc() {
|
|
|
}
|
|
|
func init() {
|
|
|
if TimeTaskConfig.IsRun {
|
|
|
- go func() {
|
|
|
- defer util.Catch()
|
|
|
- log.Println("开始加载72小时内的订单到内存中。。。")
|
|
|
- startTime := time.Unix(time.Now().Unix()-MsgRemind.getExpireTime(), 0)
|
|
|
- startTimes := util.FormatDate(&startTime, util.Date_Full_Layout)
|
|
|
- list := Mysql.SelectBySql("select id,order_code,order_money,user_id,prepay_time,remind_status,vip_type from dataexport_order where order_money>0 and prepay_time>=? and product_type='VIP订阅' and order_status=0 and del_status=0 and (remind_status<>2 or remind_status is null)", startTimes)
|
|
|
- if list == nil {
|
|
|
- log.Println("加载72小时内的订单到内存中失败")
|
|
|
- return
|
|
|
- }
|
|
|
- for _, v := range *list {
|
|
|
- order_code, _ := v["order_code"].(string)
|
|
|
- user_id, _ := v["user_id"].(string)
|
|
|
- prepay_time, _ := v["prepay_time"].(string)
|
|
|
- if order_code == "" || user_id == "" || prepay_time == "" {
|
|
|
- continue
|
|
|
- }
|
|
|
- prepayTime, err := time.ParseInLocation(util.Date_Full_Layout, prepay_time, time.Local)
|
|
|
- if err != nil {
|
|
|
- continue
|
|
|
- }
|
|
|
- orderId := util.IntAll(v["id"])
|
|
|
- MsgRemind.Add(orderId, util.IntAll(v["order_money"]), util.IntAllDef(v["vip_type"], -1), util.IntAll(v["remind_status"]), order_code, user_id, prepayTime.Unix())
|
|
|
- }
|
|
|
- log.Println("加载72小时内的订单到内存中结束。。。", len(*list))
|
|
|
- }()
|
|
|
+ MsgRemind.loadOrder()
|
|
|
+ MsgRemind.run()
|
|
|
+ MsgRemind.gc()
|
|
|
}
|
|
|
- MsgRemind.run()
|
|
|
- MsgRemind.gc()
|
|
|
}
|