|
@@ -1,1006 +1,989 @@
|
|
|
package timetask
|
|
|
|
|
|
import (
|
|
|
- "bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/pb"
|
|
|
- "encoding/hex"
|
|
|
- "fmt"
|
|
|
- "jy/src/jfw/modules/subscribepay/src/config"
|
|
|
- . "jy/src/jfw/modules/subscribepay/src/config"
|
|
|
- "jy/src/jfw/modules/subscribepay/src/pay"
|
|
|
- "jy/src/jfw/modules/subscribepay/src/util"
|
|
|
- "log"
|
|
|
- "strconv"
|
|
|
- "strings"
|
|
|
- "time"
|
|
|
+ "encoding/hex"
|
|
|
+ "fmt"
|
|
|
+ "jy/src/jfw/modules/subscribepay/src/config"
|
|
|
+ . "jy/src/jfw/modules/subscribepay/src/config"
|
|
|
+ "jy/src/jfw/modules/subscribepay/src/pay"
|
|
|
+ "jy/src/jfw/modules/subscribepay/src/util"
|
|
|
+ "log"
|
|
|
+ "strconv"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
|
|
|
- qutil "app.yhyue.com/moapp/jybase/common"
|
|
|
- . "app.yhyue.com/moapp/jybase/date"
|
|
|
- . "app.yhyue.com/moapp/jybase/mongodb"
|
|
|
- "app.yhyue.com/moapp/jybase/redis"
|
|
|
- qrpc "app.yhyue.com/moapp/jybase/rpc"
|
|
|
- "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
|
|
|
- p "bp.jydev.jianyu360.cn/BaseService/pushpkg/p"
|
|
|
+ "bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/pb"
|
|
|
+
|
|
|
+ qutil "app.yhyue.com/moapp/jybase/common"
|
|
|
+ . "app.yhyue.com/moapp/jybase/date"
|
|
|
+ . "app.yhyue.com/moapp/jybase/mongodb"
|
|
|
+ "app.yhyue.com/moapp/jybase/redis"
|
|
|
+ qrpc "app.yhyue.com/moapp/jybase/rpc"
|
|
|
+ "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
|
|
|
+ p "bp.jydev.jianyu360.cn/BaseService/pushpkg/p"
|
|
|
)
|
|
|
|
|
|
const (
|
|
|
- threeday = 259200
|
|
|
+ threeday = 259200
|
|
|
)
|
|
|
|
|
|
func Run() {
|
|
|
- if TimeTaskConfig.IsRun {
|
|
|
- for _, v := range []Identity{&Personal{}, &Ent{}} {
|
|
|
- go checkIsExpire(v)
|
|
|
- go checkMemberIsExpire(v)
|
|
|
- go updateProvincePackageStatus(v) //省份流量包
|
|
|
- }
|
|
|
- go bigMemberExpireRemind()
|
|
|
- go syncVipUpgrade()
|
|
|
- go updateDataExportStatus()
|
|
|
- go SendDataExportMailForPayed()
|
|
|
- go courseTask()
|
|
|
- go expireRemind()
|
|
|
- go checkMemberIsStart()
|
|
|
- go checkMemberServiceIsExpire()
|
|
|
- go updateTimeLimitActitityOrderStatus() //修改限时活动的订单状态
|
|
|
- }
|
|
|
+ if TimeTaskConfig.IsRun {
|
|
|
+ for _, v := range []Identity{&Personal{}, &Ent{}} {
|
|
|
+ go checkIsExpire(v)
|
|
|
+ go checkMemberIsExpire(v)
|
|
|
+ go updateProvincePackageStatus(v) //省份流量包
|
|
|
+ }
|
|
|
+ go bigMemberExpireRemind()
|
|
|
+ go syncVipUpgrade()
|
|
|
+ go updateDataExportStatus()
|
|
|
+ go SendDataExportMailForPayed()
|
|
|
+ go courseTask()
|
|
|
+ go expireRemind()
|
|
|
+ go checkMemberIsStart()
|
|
|
+ go checkMemberServiceIsExpire()
|
|
|
+ go updateTimeLimitActitityOrderStatus() //修改限时活动的订单状态
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//省份流量包到期时间 定时任务
|
|
|
func updateProvincePackageStatus(i Identity) {
|
|
|
- crontab(true, TimeTaskConfig.ProvinceExpire, func() {
|
|
|
- defer qutil.Catch()
|
|
|
- log.Println("定时任务,开始更新省份订阅包状态开始")
|
|
|
- now_unix := time.Now().Unix()
|
|
|
- sess := util.MQFW.GetMgoConn()
|
|
|
- for {
|
|
|
- if sess != nil {
|
|
|
- defer util.MQFW.DestoryMongoConn(sess)
|
|
|
- break
|
|
|
- }
|
|
|
- time.Sleep(time.Minute)
|
|
|
- sess = util.MQFW.GetMgoConn()
|
|
|
- }
|
|
|
- query := i.SubsetQuery(2)
|
|
|
- query["o_jy.i_ppstatus"] = map[string]interface{}{
|
|
|
- "$gt": -1,
|
|
|
- }
|
|
|
- query["o_jy.l_areaEnd_p"] = map[string]interface{}{
|
|
|
- "$lte": now_unix,
|
|
|
- }
|
|
|
- it := sess.DB("qfw").C(i.SubsetColl()).Find(query).Select(map[string]interface{}{"o_jy.i_ppstatus": 1, "o_jy.l_areaEnd_p": 1}).Iter()
|
|
|
- for m := make(map[string]interface{}); it.Next(&m); {
|
|
|
- _id := BsonIdToSId(m["_id"])
|
|
|
- if util.MQFW.UpdateById(i.SubsetColl(), _id, map[string]interface{}{
|
|
|
- "$set": map[string]interface{}{
|
|
|
- "o_jy.i_ppstatus": -1,
|
|
|
- "o_jy.i_areapackTip": 1,
|
|
|
- },
|
|
|
- }) {
|
|
|
- positionId := util.MongoIdToPositionId(_id)
|
|
|
- ok := jy.ClearBigVipUserPower(positionId)
|
|
|
- config.Middleground.UserCenter.WorkDesktopClearUserInfo(pb.WorkDesktopClearUserInfoReq{
|
|
|
- PositionId: positionId,
|
|
|
- AppId: "10000",
|
|
|
- })
|
|
|
- config.Middleground.PowerCheckCenter.DelCheckRedis("10000", qutil.Int64All(positionId))
|
|
|
- if !ok {
|
|
|
- log.Println("清除 redis省份订阅包服务详情 缓存失败:", _id)
|
|
|
- }
|
|
|
- } else {
|
|
|
- log.Println("更新user表 省份订阅包状态失败:", _id)
|
|
|
- }
|
|
|
- m = make(map[string]interface{})
|
|
|
- }
|
|
|
- log.Println("定时任务,更新省份订阅包状态结束")
|
|
|
- })
|
|
|
+ crontab(true, TimeTaskConfig.ProvinceExpire, func() {
|
|
|
+ defer qutil.Catch()
|
|
|
+ log.Println("定时任务,开始更新省份订阅包状态开始")
|
|
|
+ now_unix := time.Now().Unix()
|
|
|
+ sess := util.MQFW.GetMgoConn()
|
|
|
+ for {
|
|
|
+ if sess != nil {
|
|
|
+ defer util.MQFW.DestoryMongoConn(sess)
|
|
|
+ break
|
|
|
+ }
|
|
|
+ time.Sleep(time.Minute)
|
|
|
+ sess = util.MQFW.GetMgoConn()
|
|
|
+ }
|
|
|
+ query := i.SubsetQuery(2)
|
|
|
+ query["o_jy.i_ppstatus"] = map[string]interface{}{
|
|
|
+ "$gt": -1,
|
|
|
+ }
|
|
|
+ query["o_jy.l_areaEnd_p"] = map[string]interface{}{
|
|
|
+ "$lte": now_unix,
|
|
|
+ }
|
|
|
+ it := sess.DB("qfw").C(i.SubsetColl()).Find(query).Select(map[string]interface{}{"o_jy.i_ppstatus": 1, "o_jy.l_areaEnd_p": 1}).Iter()
|
|
|
+ for m := make(map[string]interface{}); it.Next(&m); {
|
|
|
+ _id := BsonIdToSId(m["_id"])
|
|
|
+ if util.MQFW.UpdateById(i.SubsetColl(), _id, map[string]interface{}{
|
|
|
+ "$set": map[string]interface{}{
|
|
|
+ "o_jy.i_ppstatus": -1,
|
|
|
+ "o_jy.i_areapackTip": 1,
|
|
|
+ },
|
|
|
+ }) {
|
|
|
+ positionId := util.MongoIdToPositionId(_id)
|
|
|
+ ok := jy.ClearBigVipUserPower(positionId)
|
|
|
+ config.Middleground.UserCenter.WorkDesktopClearUserInfo(pb.WorkDesktopClearUserInfoReq{
|
|
|
+ PositionId: positionId,
|
|
|
+ AppId: "10000",
|
|
|
+ })
|
|
|
+ config.Middleground.PowerCheckCenter.DelCheckRedis("10000", qutil.Int64All(positionId))
|
|
|
+ if !ok {
|
|
|
+ log.Println("清除 redis省份订阅包服务详情 缓存失败:", _id)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.Println("更新user表 省份订阅包状态失败:", _id)
|
|
|
+ }
|
|
|
+ m = make(map[string]interface{})
|
|
|
+ }
|
|
|
+ log.Println("定时任务,更新省份订阅包状态结束")
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
//定时更新超过72小时订单
|
|
|
func updateDataExportStatus() {
|
|
|
- crontabByTicker(true, TimeTaskConfig.UpdateDEStatus, func() {
|
|
|
- log.Println("定时任务,开始更新超时订单状态")
|
|
|
- create_time := time.Now()
|
|
|
- create_time_stamp := create_time.Unix()
|
|
|
- start_time_stamp := create_time.Unix()
|
|
|
- order_countdown := Config.OrderCountdown //配置文件读取
|
|
|
- if strings.Contains(qutil.ObjToString(order_countdown), "h") {
|
|
|
- onehour, _ := time.ParseDuration(qutil.ObjToString(order_countdown))
|
|
|
- create_time_stamp = create_time.Add(-onehour).Unix()
|
|
|
- start_time_stamp = create_time.Add(-onehour).AddDate(0, 0, -1).Unix()
|
|
|
- } else {
|
|
|
- i_countdown := qutil.IntAll(order_countdown)
|
|
|
- create_time_stamp = create_time.AddDate(0, 0, -i_countdown).Unix()
|
|
|
- start_time_stamp = create_time.AddDate(0, 0, -i_countdown).AddDate(0, 0, -1).Unix()
|
|
|
- }
|
|
|
- over_time := FormatDateByInt64(&create_time_stamp, Date_Full_Layout)
|
|
|
- start_time := FormatDateByInt64(&start_time_stamp, Date_Full_Layout)
|
|
|
- log.Println("over_time:", over_time, "start_time:", start_time)
|
|
|
- //查询未支付超时订单(仅用户自主下单、销售代用户下单的订单)
|
|
|
- wooList := util.Mysql.SelectBySql(`SELECT * FROM dataexport_order WHERE order_status = 0 AND create_time < ? AND create_time > ? AND (is_backstage_order = 0 or (is_backstage_order=1 AND order_channel ='xdqd04'))`, over_time, start_time)
|
|
|
- if wooList != nil && len(*wooList) != 0 {
|
|
|
- for _, v := range *wooList {
|
|
|
- if v["order_code"] != nil {
|
|
|
- //订单编号
|
|
|
- order_code, _ := v["order_code"].(string)
|
|
|
- productType := 0 //取消卡券的时候 需要这个参数 商品类型0普通的1线上课程
|
|
|
- if product_type, _ := v["product_type"].(string); product_type != "中标必听课" {
|
|
|
- productType = 1
|
|
|
- }
|
|
|
- flag := false
|
|
|
- //仅用户自主下单、销售代用户下单的订单 可以取消
|
|
|
- cancelOrder := qutil.IntAll(v["is_backstage_order"]) == 0 || (qutil.IntAll(v["is_backstage_order"]) == 1 && qutil.ObjToString(v["order_channel"]) == "xdqd04")
|
|
|
- if qutil.IntAll(v["order_status"]) == 0 && cancelOrder && qutil.ObjToString(v["pay_way"]) != "transferAccounts" { //未支付状态下 删除订单需要先关闭订单
|
|
|
- flag = pay.CloseDataExportOrder(qutil.ObjToString(v["pay_way"]), qutil.ObjToString(v["out_trade_no"]), qutil.ObjToString(v["prepay_time"]))
|
|
|
- }
|
|
|
- if flag || (!(qutil.IntAll(v["course_status"]) == 2 || qutil.IntAll(v["course_status"]) == 4)) && qutil.ObjToString(v["pay_way"]) == "transferAccounts" && cancelOrder { //对公转账非审核中 和 转账成功 状态下超时取消订单
|
|
|
- queryMap := map[string]interface{}{
|
|
|
- "order_code": order_code,
|
|
|
- }
|
|
|
- flag = util.Mysql.Update("dataexport_order", queryMap, map[string]interface{}{"order_status": -2})
|
|
|
- }
|
|
|
- // discountId := ""
|
|
|
- // var filter map[string]interface{}
|
|
|
- // //关闭未支付订单
|
|
|
- // if err := json.Unmarshal([]byte(qutil.ObjToString(v["filter"])), &filter); err != nil {
|
|
|
- // log.Println("filter.json.Unmarshal出错", err)
|
|
|
- // } else {
|
|
|
- // if filter["discountId"] != nil {
|
|
|
- // discountId = strconv.Itoa(qutil.IntAll(filter["discountId"]))
|
|
|
- // }
|
|
|
- // }
|
|
|
- if !flag {
|
|
|
- log.Println("mysql 订单更新失败", order_code)
|
|
|
- } else {
|
|
|
- //解除卡卷绑定
|
|
|
- //用户领取卡卷的记录id
|
|
|
- userLotteryId, _ := v["d_relation_id"].(string)
|
|
|
- if userLotteryId != "" {
|
|
|
- //用户id
|
|
|
- userId, _ := v["user_id"].(string)
|
|
|
- go func(userId, userLotteryId, order_code string) {
|
|
|
- if !util.UpdateCouponState(userId, userLotteryId, "", "", order_code, qutil.ObjToString(v["product_type"]), "0", 0, productType) {
|
|
|
- log.Println(fmt.Sprintf("单号%s-解绑失败-卡卷%s", order_code, userLotteryId))
|
|
|
- }
|
|
|
- }(userId, userLotteryId, order_code)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- log.Println("定时任务,更新超时订单状态结束")
|
|
|
- })
|
|
|
+ crontabByTicker(true, TimeTaskConfig.UpdateDEStatus, func() {
|
|
|
+ log.Println("定时任务,开始更新超时订单状态")
|
|
|
+ create_time := time.Now()
|
|
|
+ create_time_stamp := create_time.Unix()
|
|
|
+ start_time_stamp := create_time.Unix()
|
|
|
+ order_countdown := Config.OrderCountdown //配置文件读取
|
|
|
+ if strings.Contains(qutil.ObjToString(order_countdown), "h") {
|
|
|
+ onehour, _ := time.ParseDuration(qutil.ObjToString(order_countdown))
|
|
|
+ create_time_stamp = create_time.Add(-onehour).Unix()
|
|
|
+ start_time_stamp = create_time.Add(-onehour).AddDate(0, 0, -1).Unix()
|
|
|
+ } else {
|
|
|
+ i_countdown := qutil.IntAll(order_countdown)
|
|
|
+ create_time_stamp = create_time.AddDate(0, 0, -i_countdown).Unix()
|
|
|
+ start_time_stamp = create_time.AddDate(0, 0, -i_countdown).AddDate(0, 0, -1).Unix()
|
|
|
+ }
|
|
|
+ over_time := FormatDateByInt64(&create_time_stamp, Date_Full_Layout)
|
|
|
+ start_time := FormatDateByInt64(&start_time_stamp, Date_Full_Layout)
|
|
|
+ log.Println("over_time:", over_time, "start_time:", start_time)
|
|
|
+ //查询未支付超时订单(仅用户自主下单、销售代用户下单的订单)
|
|
|
+ wooList := util.Mysql.SelectBySql(`SELECT * FROM dataexport_order WHERE order_status = 0 AND create_time < ? AND create_time > ? AND (is_backstage_order = 0 or (is_backstage_order=1 AND order_channel ='xdqd04'))`, over_time, start_time)
|
|
|
+ if wooList != nil && len(*wooList) != 0 {
|
|
|
+ for _, v := range *wooList {
|
|
|
+ if v["order_code"] != nil {
|
|
|
+ //订单编号
|
|
|
+ order_code, _ := v["order_code"].(string)
|
|
|
+ productType := 0 //取消卡券的时候 需要这个参数 商品类型0普通的1线上课程
|
|
|
+ if product_type, _ := v["product_type"].(string); product_type != "中标必听课" {
|
|
|
+ productType = 1
|
|
|
+ }
|
|
|
+ flag := false
|
|
|
+ //仅用户自主下单、销售代用户下单的订单 可以取消
|
|
|
+ cancelOrder := qutil.IntAll(v["is_backstage_order"]) == 0 || (qutil.IntAll(v["is_backstage_order"]) == 1 && qutil.ObjToString(v["order_channel"]) == "xdqd04")
|
|
|
+ if qutil.IntAll(v["order_status"]) == 0 && cancelOrder && qutil.ObjToString(v["pay_way"]) != "transferAccounts" { //未支付状态下 删除订单需要先关闭订单
|
|
|
+ flag = pay.CloseDataExportOrder(qutil.ObjToString(v["pay_way"]), qutil.ObjToString(v["out_trade_no"]), qutil.ObjToString(v["prepay_time"]))
|
|
|
+ }
|
|
|
+ if flag || (!(qutil.IntAll(v["course_status"]) == 2 || qutil.IntAll(v["course_status"]) == 4)) && qutil.ObjToString(v["pay_way"]) == "transferAccounts" && cancelOrder { //对公转账非审核中 和 转账成功 状态下超时取消订单
|
|
|
+ queryMap := map[string]interface{}{
|
|
|
+ "order_code": order_code,
|
|
|
+ }
|
|
|
+ flag = util.Mysql.Update("dataexport_order", queryMap, map[string]interface{}{"order_status": -2})
|
|
|
+ }
|
|
|
+ // discountId := ""
|
|
|
+ // var filter map[string]interface{}
|
|
|
+ // //关闭未支付订单
|
|
|
+ // if err := json.Unmarshal([]byte(qutil.ObjToString(v["filter"])), &filter); err != nil {
|
|
|
+ // log.Println("filter.json.Unmarshal出错", err)
|
|
|
+ // } else {
|
|
|
+ // if filter["discountId"] != nil {
|
|
|
+ // discountId = strconv.Itoa(qutil.IntAll(filter["discountId"]))
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ if !flag {
|
|
|
+ log.Println("mysql 订单更新失败", order_code)
|
|
|
+ } else {
|
|
|
+ //解除卡卷绑定
|
|
|
+ //用户领取卡卷的记录id
|
|
|
+ userLotteryId, _ := v["d_relation_id"].(string)
|
|
|
+ if userLotteryId != "" {
|
|
|
+ //用户id
|
|
|
+ userId, _ := v["user_id"].(string)
|
|
|
+ go func(userId, userLotteryId, order_code string) {
|
|
|
+ if !util.UpdateCouponState(userId, userLotteryId, "", "", order_code, qutil.ObjToString(v["product_type"]), "0", 0, productType) {
|
|
|
+ log.Println(fmt.Sprintf("单号%s-解绑失败-卡卷%s", order_code, userLotteryId))
|
|
|
+ }
|
|
|
+ }(userId, userLotteryId, order_code)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.Println("定时任务,更新超时订单状态结束")
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
//每天夜里12点 根据课程结束时间 更新课程状态 并 更新mysql预定此课程订单的状态为已取消
|
|
|
func courseTask() {
|
|
|
- crontab(true, TimeTaskConfig.CourseTask, func() {
|
|
|
- log.Println("定时任务,开始更新课程状态")
|
|
|
- now_unix := time.Now().Unix()
|
|
|
- sess := util.MQFW.GetMgoConn()
|
|
|
- defer util.MQFW.DestoryMongoConn(sess)
|
|
|
- //i_status : 0是保存未发布 1是已发布 -1是已下线
|
|
|
- it := sess.DB("qfw").C("jy_course").Find(map[string]interface{}{
|
|
|
- "i_status": 1,
|
|
|
- "l_starttime": map[string]interface{}{
|
|
|
- "$lte": now_unix,
|
|
|
- },
|
|
|
- }).Select(map[string]interface{}{"i_status": 1, "l_endtime": 1}).Iter()
|
|
|
- for m := make(map[string]interface{}); it.Next(&m); {
|
|
|
- _id := BsonIdToSId(m["_id"])
|
|
|
- util.MQFW.UpdateById("jy_course", _id, map[string]interface{}{
|
|
|
- "$set": map[string]interface{}{
|
|
|
- "i_status": -1,
|
|
|
- },
|
|
|
- })
|
|
|
- go func(id string) { //更新已预订此课程订单的状态为已取消
|
|
|
- var updateSql = `UPDATE dataexport_order SET order_status = -2 WHERE order_status = 0 AND product_type = '招投标课程' AND filter_id = '` + id + `'`
|
|
|
- i := util.Mysql.UpdateOrDeleteBySql(updateSql)
|
|
|
- if i < 0 {
|
|
|
- log.Println("mysql 订单更新失败", id)
|
|
|
- }
|
|
|
- }(_id)
|
|
|
- m = make(map[string]interface{})
|
|
|
- }
|
|
|
- log.Println("定时任务,更新课程状态结束")
|
|
|
- })
|
|
|
+ crontab(true, TimeTaskConfig.CourseTask, func() {
|
|
|
+ log.Println("定时任务,开始更新课程状态")
|
|
|
+ now_unix := time.Now().Unix()
|
|
|
+ sess := util.MQFW.GetMgoConn()
|
|
|
+ defer util.MQFW.DestoryMongoConn(sess)
|
|
|
+ //i_status : 0是保存未发布 1是已发布 -1是已下线
|
|
|
+ it := sess.DB("qfw").C("jy_course").Find(map[string]interface{}{
|
|
|
+ "i_status": 1,
|
|
|
+ "l_starttime": map[string]interface{}{
|
|
|
+ "$lte": now_unix,
|
|
|
+ },
|
|
|
+ }).Select(map[string]interface{}{"i_status": 1, "l_endtime": 1}).Iter()
|
|
|
+ for m := make(map[string]interface{}); it.Next(&m); {
|
|
|
+ _id := BsonIdToSId(m["_id"])
|
|
|
+ util.MQFW.UpdateById("jy_course", _id, map[string]interface{}{
|
|
|
+ "$set": map[string]interface{}{
|
|
|
+ "i_status": -1,
|
|
|
+ },
|
|
|
+ })
|
|
|
+ go func(id string) { //更新已预订此课程订单的状态为已取消
|
|
|
+ var updateSql = `UPDATE dataexport_order SET order_status = -2 WHERE order_status = 0 AND product_type = '招投标课程' AND filter_id = '` + id + `'`
|
|
|
+ i := util.Mysql.UpdateOrDeleteBySql(updateSql)
|
|
|
+ if i < 0 {
|
|
|
+ log.Println("mysql 订单更新失败", id)
|
|
|
+ }
|
|
|
+ }(_id)
|
|
|
+ m = make(map[string]interface{})
|
|
|
+ }
|
|
|
+ log.Println("定时任务,更新课程状态结束")
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
//vip升级 下个月生效 同步
|
|
|
func syncVipUpgrade() {
|
|
|
- crontab(true, TimeTaskConfig.SyncVipUpgrade, func() {
|
|
|
- defer qutil.Catch()
|
|
|
- log.Println("定时任务,开始同步vip升级数据")
|
|
|
- sess := util.MQFW.GetMgoConn()
|
|
|
- for {
|
|
|
- if sess != nil {
|
|
|
- defer util.MQFW.DestoryMongoConn(sess)
|
|
|
- break
|
|
|
- }
|
|
|
- time.Sleep(time.Minute)
|
|
|
- sess = util.MQFW.GetMgoConn()
|
|
|
- }
|
|
|
- it := sess.DB("qfw").C("vip_upgrade").Find(map[string]interface{}{
|
|
|
- "l_validtime": map[string]interface{}{
|
|
|
- "$lte": time.Now().Unix(),
|
|
|
- },
|
|
|
- "i_isvalid": map[string]interface{}{
|
|
|
- "$ne": 1,
|
|
|
- },
|
|
|
- }).Select(map[string]interface{}{"s_userid": 1, "o_area": 1, "a_buyerclass": 1, "o_buyset": 1}).Iter()
|
|
|
- for m := make(map[string]interface{}); it.Next(&m); {
|
|
|
- _id := BsonIdToSId(m["_id"])
|
|
|
- s_userid := qutil.ObjToString(m["s_userid"])
|
|
|
- if s_userid == "" {
|
|
|
- log.Println("定时任务,同步vip升级数据有问题,userid是空", _id)
|
|
|
- continue
|
|
|
- }
|
|
|
- o_area, _ := m["o_area"].(map[string]interface{})
|
|
|
- o_buyset, _ := m["o_buyset"].(map[string]interface{})
|
|
|
- a_buyerclass, _ := m["a_buyerclass"].([]interface{})
|
|
|
- updateOk := false
|
|
|
- if IsObjectIdHex(s_userid) {
|
|
|
- updateOk = util.Compatible.Update(s_userid, map[string]interface{}{
|
|
|
- "$set": map[string]interface{}{
|
|
|
- "o_vipjy.o_area": o_area,
|
|
|
- "o_vipjy.a_buyerclass": a_buyerclass,
|
|
|
- "o_vipjy.o_buyset": o_buyset,
|
|
|
- },
|
|
|
- })
|
|
|
- } else {
|
|
|
- updateOk = util.MQFW.Update("entniche_user", map[string]interface{}{
|
|
|
- "i_type": 2,
|
|
|
- "i_userid": qutil.IntAll(s_userid),
|
|
|
- }, map[string]interface{}{
|
|
|
- "$set": map[string]interface{}{
|
|
|
- "o_vipjy.o_area": o_area,
|
|
|
- "o_vipjy.a_buyerclass": a_buyerclass,
|
|
|
- "o_vipjy.o_buyset": o_buyset,
|
|
|
- },
|
|
|
- }, false, false)
|
|
|
- }
|
|
|
- if updateOk {
|
|
|
- util.MQFW.UpdateById("vip_upgrade", _id, map[string]interface{}{
|
|
|
- "$set": map[string]interface{}{
|
|
|
- "l_synctime": time.Now().Unix(),
|
|
|
- "i_isvalid": 1,
|
|
|
- },
|
|
|
- })
|
|
|
- log.Println("定时任务,同步vip升级数据成功", _id)
|
|
|
- positionId := util.MongoIdToPositionId(_id)
|
|
|
- go jy.ClearBigVipUserPower(positionId)
|
|
|
- go config.Middleground.UserCenter.WorkDesktopClearUserInfo(pb.WorkDesktopClearUserInfoReq{
|
|
|
- PositionId: positionId,
|
|
|
- AppId: "10000",
|
|
|
- })
|
|
|
- go config.Middleground.PowerCheckCenter.DelCheckRedis("10000", qutil.Int64All(positionId))
|
|
|
- } else {
|
|
|
- log.Println("定时任务,同步vip升级数据更新用户表失败", _id)
|
|
|
- }
|
|
|
- m = make(map[string]interface{})
|
|
|
- }
|
|
|
- log.Println("定时任务,同步vip升级数据结束")
|
|
|
- })
|
|
|
+ crontab(true, TimeTaskConfig.SyncVipUpgrade, func() {
|
|
|
+ defer qutil.Catch()
|
|
|
+ log.Println("定时任务,开始同步vip升级数据")
|
|
|
+ sess := util.MQFW.GetMgoConn()
|
|
|
+ for {
|
|
|
+ if sess != nil {
|
|
|
+ defer util.MQFW.DestoryMongoConn(sess)
|
|
|
+ break
|
|
|
+ }
|
|
|
+ time.Sleep(time.Minute)
|
|
|
+ sess = util.MQFW.GetMgoConn()
|
|
|
+ }
|
|
|
+ it := sess.DB("qfw").C("vip_upgrade").Find(map[string]interface{}{
|
|
|
+ "l_validtime": map[string]interface{}{
|
|
|
+ "$lte": time.Now().Unix(),
|
|
|
+ },
|
|
|
+ "i_isvalid": map[string]interface{}{
|
|
|
+ "$ne": 1,
|
|
|
+ },
|
|
|
+ }).Select(map[string]interface{}{"s_userid": 1, "o_area": 1, "a_buyerclass": 1, "o_buyset": 1}).Iter()
|
|
|
+ for m := make(map[string]interface{}); it.Next(&m); {
|
|
|
+ _id := BsonIdToSId(m["_id"])
|
|
|
+ s_userid := qutil.ObjToString(m["s_userid"])
|
|
|
+ if s_userid == "" {
|
|
|
+ log.Println("定时任务,同步vip升级数据有问题,userid是空", _id)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ o_area, _ := m["o_area"].(map[string]interface{})
|
|
|
+ o_buyset, _ := m["o_buyset"].(map[string]interface{})
|
|
|
+ a_buyerclass, _ := m["a_buyerclass"].([]interface{})
|
|
|
+ updateOk := false
|
|
|
+ if IsObjectIdHex(s_userid) {
|
|
|
+ updateOk = util.Compatible.Update(s_userid, map[string]interface{}{
|
|
|
+ "$set": map[string]interface{}{
|
|
|
+ "o_vipjy.o_area": o_area,
|
|
|
+ "o_vipjy.a_buyerclass": a_buyerclass,
|
|
|
+ "o_vipjy.o_buyset": o_buyset,
|
|
|
+ },
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ updateOk = util.MQFW.Update("entniche_user", map[string]interface{}{
|
|
|
+ "i_type": 2,
|
|
|
+ "i_userid": qutil.IntAll(s_userid),
|
|
|
+ }, map[string]interface{}{
|
|
|
+ "$set": map[string]interface{}{
|
|
|
+ "o_vipjy.o_area": o_area,
|
|
|
+ "o_vipjy.a_buyerclass": a_buyerclass,
|
|
|
+ "o_vipjy.o_buyset": o_buyset,
|
|
|
+ },
|
|
|
+ }, false, false)
|
|
|
+ }
|
|
|
+ if updateOk {
|
|
|
+ util.MQFW.UpdateById("vip_upgrade", _id, map[string]interface{}{
|
|
|
+ "$set": map[string]interface{}{
|
|
|
+ "l_synctime": time.Now().Unix(),
|
|
|
+ "i_isvalid": 1,
|
|
|
+ },
|
|
|
+ })
|
|
|
+ log.Println("定时任务,同步vip升级数据成功", _id)
|
|
|
+ positionId := util.MongoIdToPositionId(_id)
|
|
|
+ go jy.ClearBigVipUserPower(positionId)
|
|
|
+ go config.Middleground.UserCenter.WorkDesktopClearUserInfo(pb.WorkDesktopClearUserInfoReq{
|
|
|
+ PositionId: positionId,
|
|
|
+ AppId: "10000",
|
|
|
+ })
|
|
|
+ go config.Middleground.PowerCheckCenter.DelCheckRedis("10000", qutil.Int64All(positionId))
|
|
|
+ } else {
|
|
|
+ log.Println("定时任务,同步vip升级数据更新用户表失败", _id)
|
|
|
+ }
|
|
|
+ m = make(map[string]interface{})
|
|
|
+ }
|
|
|
+ log.Println("定时任务,同步vip升级数据结束")
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
//每天0点 检查试用、vip服务是否到期
|
|
|
func checkIsExpire(iy Identity) {
|
|
|
- crontab(true, TimeTaskConfig.CheckIsExpire, func() {
|
|
|
- defer qutil.Catch()
|
|
|
- log.Println("定时任务,开始更新vip状态")
|
|
|
- now_unix := time.Now().Unix()
|
|
|
- sess := util.MQFW.GetMgoConn()
|
|
|
- for {
|
|
|
- if sess != nil {
|
|
|
- defer util.MQFW.DestoryMongoConn(sess)
|
|
|
- break
|
|
|
- }
|
|
|
- time.Sleep(time.Minute)
|
|
|
- sess = util.MQFW.GetMgoConn()
|
|
|
- }
|
|
|
- query := iy.UserQuery()
|
|
|
- query["i_vip_status"] = map[string]interface{}{
|
|
|
- "$gt": 0,
|
|
|
- }
|
|
|
- query["l_vip_endtime"] = map[string]interface{}{
|
|
|
- "$lte": now_unix + threeday,
|
|
|
- }
|
|
|
- count, err := sess.DB("qfw").C(iy.UserColl()).Find(query).Count()
|
|
|
- log.Println("当前时间:", FormatDateByInt64(&now_unix, Date_Full_Layout), "数据总量:", count, "--err:", err)
|
|
|
- var i int64 = 0
|
|
|
- it := sess.DB("qfw").C(iy.UserColl()).Find(query).Select(iy.UserField(map[string]interface{}{"i_vip_status": 1, "l_vip_endtime": 1, "i_vip_expire_tip": 1})).Iter()
|
|
|
- for m := make(map[string]interface{}); it.Next(&m); {
|
|
|
- i++
|
|
|
- _id := BsonIdToSId(m["_id"])
|
|
|
- l_vip_endtime := qutil.Int64All(m["l_vip_endtime"])
|
|
|
- i_vip_status := qutil.IntAll(m["i_vip_status"])
|
|
|
- i_vip_expire_tip := qutil.IntAll(m["i_vip_expire_tip"])
|
|
|
- if l_vip_endtime <= now_unix {
|
|
|
- ok := util.MQFW.UpdateById(iy.UserColl(), _id, map[string]interface{}{
|
|
|
- "$set": map[string]interface{}{
|
|
|
- "i_vip_status": -i_vip_status,
|
|
|
- "i_vip_expire_tip": 2,
|
|
|
- "i_vip_subtips": 0,
|
|
|
- "i_vip_fastimport": 0,
|
|
|
- },
|
|
|
- "$unset": map[string]interface{}{
|
|
|
- "i_vip_expire_tip_retry": "",
|
|
|
- },
|
|
|
- })
|
|
|
- if !ok {
|
|
|
- log.Println("用户:", _id, " 更新vip状态异常")
|
|
|
- }
|
|
|
- go iy.DelVipSubPush(m)
|
|
|
- positionId := util.MongoIdToPositionId(_id)
|
|
|
- go jy.ClearBigVipUserPower(positionId)
|
|
|
- go config.Middleground.UserCenter.WorkDesktopClearUserInfo(pb.WorkDesktopClearUserInfoReq{
|
|
|
- PositionId: positionId,
|
|
|
- AppId: "10000",
|
|
|
- })
|
|
|
- go config.Middleground.PowerCheckCenter.DelCheckRedis("10000", qutil.Int64All(positionId))
|
|
|
- log.Println("用户", _id, i_vip_status, l_vip_endtime, "修改已到期状态")
|
|
|
- redis.Del("other", "p1_indexMessage_"+_id) //清除redis中vip状态
|
|
|
- filePackKey := fmt.Sprintf(jy.FilePackNumKey, _id, fmt.Sprint(time.Now().Month()))
|
|
|
- redis.Del(jy.PowerCacheDb, filePackKey) //清除redis中附件下载包次数
|
|
|
- vipFileUploadNumKey := fmt.Sprintf(jy.VipFileUploadNumKey, _id, fmt.Sprint(time.Now().Month()))
|
|
|
- redis.Del(jy.PowerCacheDb, vipFileUploadNumKey) //清除redis中vip使用次数
|
|
|
- } else if l_vip_endtime-now_unix <= threeday && i_vip_expire_tip != 1 {
|
|
|
- updateOk := util.MQFW.UpdateById(iy.UserColl(), _id, map[string]interface{}{
|
|
|
- "$set": map[string]interface{}{
|
|
|
- "i_vip_expire_tip": 1,
|
|
|
- },
|
|
|
- "$unset": map[string]interface{}{
|
|
|
- "i_vip_expire_tip_retry": "",
|
|
|
- },
|
|
|
- })
|
|
|
- log.Println("用户", _id, i_vip_status, l_vip_endtime, "修改即将到期状态", updateOk)
|
|
|
- }
|
|
|
- m = make(map[string]interface{})
|
|
|
- }
|
|
|
- if i != count {
|
|
|
- log.Println("更新vip状态有异常,已处理:", i, "总量:", count)
|
|
|
- }
|
|
|
- log.Println("已处理:", i, "总量:", count)
|
|
|
- log.Println("定时任务,更新vip状态结束")
|
|
|
- })
|
|
|
+ crontab(true, TimeTaskConfig.CheckIsExpire, func() {
|
|
|
+ defer qutil.Catch()
|
|
|
+ log.Println("定时任务,开始更新vip状态")
|
|
|
+ now_unix := time.Now().Unix()
|
|
|
+ sess := util.MQFW.GetMgoConn()
|
|
|
+ for {
|
|
|
+ if sess != nil {
|
|
|
+ defer util.MQFW.DestoryMongoConn(sess)
|
|
|
+ break
|
|
|
+ }
|
|
|
+ time.Sleep(time.Minute)
|
|
|
+ sess = util.MQFW.GetMgoConn()
|
|
|
+ }
|
|
|
+ query := iy.UserQuery()
|
|
|
+ query["i_vip_status"] = map[string]interface{}{
|
|
|
+ "$gt": 0,
|
|
|
+ }
|
|
|
+ query["l_vip_endtime"] = map[string]interface{}{
|
|
|
+ "$lte": now_unix + threeday,
|
|
|
+ }
|
|
|
+ count, err := sess.DB("qfw").C(iy.UserColl()).Find(query).Count()
|
|
|
+ log.Println("当前时间:", FormatDateByInt64(&now_unix, Date_Full_Layout), "数据总量:", count, "--err:", err)
|
|
|
+ var i int64 = 0
|
|
|
+ it := sess.DB("qfw").C(iy.UserColl()).Find(query).Select(iy.UserField(map[string]interface{}{"i_vip_status": 1, "l_vip_endtime": 1, "i_vip_expire_tip": 1})).Iter()
|
|
|
+ for m := make(map[string]interface{}); it.Next(&m); {
|
|
|
+ i++
|
|
|
+ _id := BsonIdToSId(m["_id"])
|
|
|
+ l_vip_endtime := qutil.Int64All(m["l_vip_endtime"])
|
|
|
+ i_vip_status := qutil.IntAll(m["i_vip_status"])
|
|
|
+ i_vip_expire_tip := qutil.IntAll(m["i_vip_expire_tip"])
|
|
|
+ if l_vip_endtime <= now_unix {
|
|
|
+ ok := util.MQFW.UpdateById(iy.UserColl(), _id, map[string]interface{}{
|
|
|
+ "$set": map[string]interface{}{
|
|
|
+ "i_vip_status": -i_vip_status,
|
|
|
+ "i_vip_expire_tip": 2,
|
|
|
+ "i_vip_subtips": 0,
|
|
|
+ "i_vip_fastimport": 0,
|
|
|
+ },
|
|
|
+ "$unset": map[string]interface{}{
|
|
|
+ "i_vip_expire_tip_retry": "",
|
|
|
+ },
|
|
|
+ })
|
|
|
+ if !ok {
|
|
|
+ log.Println("用户:", _id, " 更新vip状态异常")
|
|
|
+ }
|
|
|
+ go iy.DelVipSubPush(m)
|
|
|
+ positionId := util.MongoIdToPositionId(_id)
|
|
|
+ go jy.ClearBigVipUserPower(positionId)
|
|
|
+ go config.Middleground.UserCenter.WorkDesktopClearUserInfo(pb.WorkDesktopClearUserInfoReq{
|
|
|
+ PositionId: positionId,
|
|
|
+ AppId: "10000",
|
|
|
+ })
|
|
|
+ go config.Middleground.PowerCheckCenter.DelCheckRedis("10000", qutil.Int64All(positionId))
|
|
|
+ log.Println("用户", _id, i_vip_status, l_vip_endtime, "修改已到期状态")
|
|
|
+ redis.Del("other", "p1_indexMessage_"+_id) //清除redis中vip状态
|
|
|
+ filePackKey := fmt.Sprintf(jy.FilePackNumKey, _id, fmt.Sprint(time.Now().Month()))
|
|
|
+ redis.Del(jy.PowerCacheDb, filePackKey) //清除redis中附件下载包次数
|
|
|
+ vipFileUploadNumKey := fmt.Sprintf(jy.VipFileUploadNumKey, _id, fmt.Sprint(time.Now().Month()))
|
|
|
+ redis.Del(jy.PowerCacheDb, vipFileUploadNumKey) //清除redis中vip使用次数
|
|
|
+ } else if l_vip_endtime-now_unix <= threeday && i_vip_expire_tip != 1 {
|
|
|
+ updateOk := util.MQFW.UpdateById(iy.UserColl(), _id, map[string]interface{}{
|
|
|
+ "$set": map[string]interface{}{
|
|
|
+ "i_vip_expire_tip": 1,
|
|
|
+ },
|
|
|
+ "$unset": map[string]interface{}{
|
|
|
+ "i_vip_expire_tip_retry": "",
|
|
|
+ },
|
|
|
+ })
|
|
|
+ log.Println("用户", _id, i_vip_status, l_vip_endtime, "修改即将到期状态", updateOk)
|
|
|
+ }
|
|
|
+ m = make(map[string]interface{})
|
|
|
+ }
|
|
|
+ if i != count {
|
|
|
+ log.Println("更新vip状态有异常,已处理:", i, "总量:", count)
|
|
|
+ }
|
|
|
+ log.Println("已处理:", i, "总量:", count)
|
|
|
+ log.Println("定时任务,更新vip状态结束")
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
//即将到期或者已到期发推送消息
|
|
|
func expireRemind() {
|
|
|
- crontab(false, TimeTaskConfig.ExpireRemind, func() {
|
|
|
- defer qutil.Catch()
|
|
|
- log.Println("定时任务,到期提醒,开始推送消息")
|
|
|
- now_unix := time.Now().Unix()
|
|
|
- util.OnTrial_WTMCS.Reload()
|
|
|
- util.Formal_WTMCS.Reload()
|
|
|
- doFunc := func(m map[string]interface{}) {
|
|
|
- i_vip_expire_tip := qutil.IntAll(m["i_vip_expire_tip"])
|
|
|
- if i_vip_expire_tip != 1 && i_vip_expire_tip != 2 {
|
|
|
- return
|
|
|
- }
|
|
|
- _id := qutil.ObjToString(m["_id"])
|
|
|
- l_vip_endtime := qutil.Int64All(m["l_vip_endtime"])
|
|
|
- if l_vip_endtime-now_unix > threeday && i_vip_expire_tip == 1 {
|
|
|
- log.Println("即将到期提醒,结束时间大于三天,过滤掉", _id, l_vip_endtime)
|
|
|
- return
|
|
|
- }
|
|
|
- i_vip_status := qutil.IntAll(m["i_vip_status"])
|
|
|
- wxPushOk, appPushOk := false, false
|
|
|
- l_vip_starttime := qutil.Int64All(m["l_vip_starttime"])
|
|
|
- s_m_openid := qutil.ObjToString(m["s_m_openid"])
|
|
|
- isPushWx := qutil.IntAllDef(m["i_ispush"], 1)
|
|
|
- s_jpushid := qutil.ObjToString(m["s_jpushid"])
|
|
|
- s_opushid := qutil.ObjToString(m["s_opushid"])
|
|
|
- s_appponetype := qutil.ObjToString(m["s_appponetype"])
|
|
|
- log.Println("到期提醒,推送消息", _id, "i_vip_status", i_vip_status, "l_vip_starttime", l_vip_starttime, "l_vip_endtime", l_vip_endtime, "i_vip_expire_tip", i_vip_expire_tip, "s_m_openid", s_m_openid, "isPushWx", isPushWx, "s_appponetype", s_appponetype, "s_jpushid", s_jpushid, "s_opushid", s_opushid)
|
|
|
- if isPushWx == 1 && s_m_openid != "" { //微信推送
|
|
|
- tp := ""
|
|
|
- tplId, first_color, keyword1_value, keyword2_value, keyword3_value, keyword4_value, remark := "", "", "", "", "", "", ""
|
|
|
- var wtmc *p.WxTplMsgCustom
|
|
|
- switch i_vip_status {
|
|
|
- case 1, -1:
|
|
|
- if i_vip_expire_tip == 1 {
|
|
|
- tp = "ontrial_soonexprie"
|
|
|
- tplId = MessageConfig.WxTpl_OnTrial_SoonExpire.Id
|
|
|
- wtmc = util.OnTrial_WTMCS.Get(MessageConfig.WxTpl_OnTrial_SoonExpire.First.Value)
|
|
|
- first_color = MessageConfig.WxTpl_OnTrial_SoonExpire.First.Color
|
|
|
- remark = MessageConfig.WxTpl_OnTrial_SoonExpire.Remark.Value
|
|
|
- } else if i_vip_expire_tip == 2 {
|
|
|
- tp = "ontrial_expried"
|
|
|
- tplId = MessageConfig.WxTpl_OnTrial_Expired.Id
|
|
|
- wtmc = util.OnTrial_WTMCS.Get(MessageConfig.WxTpl_OnTrial_Expired.First.Value)
|
|
|
- first_color = MessageConfig.WxTpl_OnTrial_Expired.First.Color
|
|
|
- remark = MessageConfig.WxTpl_OnTrial_Expired.Remark.Value
|
|
|
- }
|
|
|
- keyword1_value = qutil.ObjToString(m["s_nickname"])
|
|
|
- keyword2_value = FormatDateByInt64(&l_vip_endtime, Date_Short_Layout)
|
|
|
- return
|
|
|
- case 2, -2:
|
|
|
- if i_vip_expire_tip == 1 {
|
|
|
- tp = "soonexprie"
|
|
|
- tplId = MessageConfig.WxTpl_SoonExpire.Id
|
|
|
- wtmc = util.Formal_WTMCS.Get(MessageConfig.WxTpl_SoonExpire.First.Value)
|
|
|
- first_color = MessageConfig.WxTpl_SoonExpire.First.Color
|
|
|
- keyword2_value = MessageConfig.WxTpl_SoonExpire.Keyword2.Value
|
|
|
- keyword3_value = MessageConfig.WxTpl_SoonExpire.Keyword3.Value
|
|
|
- remark = MessageConfig.WxTpl_SoonExpire.Remark.Value
|
|
|
- } else if i_vip_expire_tip == 2 {
|
|
|
- tp = "expried"
|
|
|
- tplId = MessageConfig.WxTpl_Expired.Id
|
|
|
- wtmc = util.Formal_WTMCS.Get(MessageConfig.WxTpl_Expired.First.Value)
|
|
|
- first_color = MessageConfig.WxTpl_Expired.First.Color
|
|
|
- keyword2_value = MessageConfig.WxTpl_Expired.Keyword2.Value
|
|
|
- keyword3_value = MessageConfig.WxTpl_Expired.Keyword3.Value
|
|
|
- remark = MessageConfig.WxTpl_Expired.Remark.Value
|
|
|
- }
|
|
|
- keyword1_value = qutil.ObjToString(m["s_nickname"])
|
|
|
- keyword4_value = FormatDateByInt64(&l_vip_endtime, Date_Short_Layout)
|
|
|
- return
|
|
|
- default:
|
|
|
- return
|
|
|
- }
|
|
|
- if wtmc != nil {
|
|
|
- tmplData := map[string]*qrpc.TmplItem{
|
|
|
- "first": &qrpc.TmplItem{
|
|
|
- Value: wtmc.FirstData,
|
|
|
- Color: first_color,
|
|
|
- },
|
|
|
- "keyword1": &qrpc.TmplItem{
|
|
|
- Value: keyword1_value,
|
|
|
- },
|
|
|
- "keyword2": &qrpc.TmplItem{
|
|
|
- Value: keyword2_value,
|
|
|
- },
|
|
|
- "keyword3": &qrpc.TmplItem{
|
|
|
- Value: keyword3_value,
|
|
|
- },
|
|
|
- "keyword4": &qrpc.TmplItem{
|
|
|
- Value: keyword4_value,
|
|
|
- },
|
|
|
- "remark": &qrpc.TmplItem{
|
|
|
- Value: remark,
|
|
|
- },
|
|
|
- }
|
|
|
- wxPushOk, _ = qrpc.WxSendTmplMsg(Config.Weixinrpc, &qrpc.WxTmplMsg{
|
|
|
- OpenId: s_m_openid,
|
|
|
- TplId: tplId,
|
|
|
- TmplData: tmplData,
|
|
|
- Url: Config.WebDomain + "/front/sess/" + util.Se_Topnet.EncodeString(_id+qutil.If(IsObjectIdHex(_id), ",_id,", ",entUserId,").(string)+strconv.Itoa(int(time.Now().Unix()))+",msgremind") + "__" + hex.EncodeToString([]byte(fmt.Sprintf("type=%s&advertcode=%s", tp, wtmc.AdvertCode))),
|
|
|
- })
|
|
|
- log.Println("到期提醒,微信推送", _id, wxPushOk, wtmc.AdvertCode, wtmc.FirstData)
|
|
|
- }
|
|
|
- }
|
|
|
- if !wxPushOk && (m["s_opushid"] != nil || m["s_jpushid"] != nil) { //app推送
|
|
|
- tp, app_descript := "", ""
|
|
|
- switch i_vip_status {
|
|
|
- case 1, -1:
|
|
|
- if i_vip_expire_tip == 1 {
|
|
|
- tp = "ontrial_soonexprie"
|
|
|
- app_descript = MessageConfig.App_OnTrial_SoonExpire
|
|
|
- } else if i_vip_expire_tip == 2 {
|
|
|
- tp = "ontrial_expried"
|
|
|
- app_descript = MessageConfig.App_OnTrial_Expired
|
|
|
- }
|
|
|
- return
|
|
|
- case 2, -2:
|
|
|
- if i_vip_expire_tip == 1 {
|
|
|
- tp = "soonexprie"
|
|
|
- app_descript = MessageConfig.App_SoonExpire
|
|
|
- } else if i_vip_expire_tip == 2 {
|
|
|
- tp = "expried"
|
|
|
- app_descript = MessageConfig.App_Expired
|
|
|
- }
|
|
|
- return
|
|
|
- default:
|
|
|
- return
|
|
|
- }
|
|
|
- appPushOk = qrpc.AppPush(Config.AppPushServiceRpc, map[string]interface{}{
|
|
|
- "phoneType": m["s_appponetype"],
|
|
|
- "otherPushId": m["s_opushid"],
|
|
|
- "jgPushId": m["s_jpushid"],
|
|
|
- "url": "/jyapp/free/sess/" + util.Se_Topnet.EncodeString(_id+qutil.If(IsObjectIdHex(_id), ",_id,", ",entUserId,").(string)+strconv.Itoa(int(time.Now().Unix()))+",msgremind") + "__" + hex.EncodeToString([]byte(fmt.Sprintf("type=%s", tp))),
|
|
|
- "userId": _id,
|
|
|
- "type": "vipNotice",
|
|
|
- "descript": app_descript,
|
|
|
- "title": "剑鱼提醒",
|
|
|
- })
|
|
|
- log.Println("到期提醒,app推送", _id, appPushOk)
|
|
|
- }
|
|
|
- if wxPushOk || appPushOk || qutil.IntAll(m["i_vip_expire_tip_retry"]) >= 2 {
|
|
|
- util.Compatible.UpdateByEntUserId(_id, map[string]interface{}{
|
|
|
- "$set": map[string]interface{}{
|
|
|
- "i_vip_expire_tip": 0,
|
|
|
- },
|
|
|
- })
|
|
|
- } else if i_vip_expire_tip == 2 {
|
|
|
- util.Compatible.UpdateByEntUserId(_id, map[string]interface{}{
|
|
|
- "$set": map[string]interface{}{
|
|
|
- "i_vip_expire_tip_retry": 1,
|
|
|
- },
|
|
|
- })
|
|
|
- }
|
|
|
- }
|
|
|
- field := map[string]interface{}{
|
|
|
- "s_m_openid": 1,
|
|
|
- "s_jpushid": 1,
|
|
|
- "s_opushid": 1,
|
|
|
- "s_appponetype": 1,
|
|
|
- "s_nickname": 1,
|
|
|
- "i_ispush": 1,
|
|
|
- "i_vip_status": 1,
|
|
|
- "l_vip_starttime": 1,
|
|
|
- "l_vip_endtime": 1,
|
|
|
- "i_vip_expire_tip": 1,
|
|
|
- "i_vip_expire_tip_retry": 1,
|
|
|
- }
|
|
|
- (&Personal{}).LoadVipUsers(field, doFunc)
|
|
|
- (&Ent{}).LoadVipUsers(field, doFunc)
|
|
|
- log.Println("定时任务,到期提醒,推送消息结束")
|
|
|
- })
|
|
|
+ crontab(false, TimeTaskConfig.ExpireRemind, func() {
|
|
|
+ defer qutil.Catch()
|
|
|
+ log.Println("定时任务,到期提醒,开始推送消息")
|
|
|
+ now_unix := time.Now().Unix()
|
|
|
+ util.OnTrial_WTMCS.Reload()
|
|
|
+ util.Formal_WTMCS.Reload()
|
|
|
+ doFunc := func(m map[string]interface{}) {
|
|
|
+ i_vip_expire_tip := qutil.IntAll(m["i_vip_expire_tip"])
|
|
|
+ if i_vip_expire_tip != 1 && i_vip_expire_tip != 2 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ _id := qutil.ObjToString(m["_id"])
|
|
|
+ l_vip_endtime := qutil.Int64All(m["l_vip_endtime"])
|
|
|
+ if l_vip_endtime-now_unix > threeday && i_vip_expire_tip == 1 {
|
|
|
+ log.Println("即将到期提醒,结束时间大于三天,过滤掉", _id, l_vip_endtime)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ i_vip_status := qutil.IntAll(m["i_vip_status"])
|
|
|
+ wxPushOk, appPushOk := false, false
|
|
|
+ l_vip_starttime := qutil.Int64All(m["l_vip_starttime"])
|
|
|
+ s_m_openid := qutil.ObjToString(m["s_m_openid"])
|
|
|
+ isPushWx := qutil.IntAllDef(m["i_ispush"], 1)
|
|
|
+ s_jpushid := qutil.ObjToString(m["s_jpushid"])
|
|
|
+ s_opushid := qutil.ObjToString(m["s_opushid"])
|
|
|
+ s_appponetype := qutil.ObjToString(m["s_appponetype"])
|
|
|
+ log.Println("到期提醒,推送消息", _id, "i_vip_status", i_vip_status, "l_vip_starttime", l_vip_starttime, "l_vip_endtime", l_vip_endtime, "i_vip_expire_tip", i_vip_expire_tip, "s_m_openid", s_m_openid, "isPushWx", isPushWx, "s_appponetype", s_appponetype, "s_jpushid", s_jpushid, "s_opushid", s_opushid)
|
|
|
+ if isPushWx == 1 && s_m_openid != "" { //微信推送
|
|
|
+ tp := ""
|
|
|
+ tplId, first_color, keyword1_value, keyword2_value, keyword3_value, keyword4_value := "", "", "", "", "", ""
|
|
|
+ var wtmc *p.WxTplMsgCustom
|
|
|
+ switch i_vip_status {
|
|
|
+ case 1, -1:
|
|
|
+ if i_vip_expire_tip == 1 {
|
|
|
+ tp = "ontrial_soonexprie"
|
|
|
+ tplId = MessageConfig.WxTpl_OnTrial_SoonExpire.Id
|
|
|
+ wtmc = util.OnTrial_WTMCS.Get(MessageConfig.WxTpl_OnTrial_SoonExpire.First.Value)
|
|
|
+ first_color = MessageConfig.WxTpl_OnTrial_SoonExpire.First.Color
|
|
|
+ } else if i_vip_expire_tip == 2 {
|
|
|
+ tp = "ontrial_expried"
|
|
|
+ tplId = MessageConfig.WxTpl_OnTrial_Expired.Id
|
|
|
+ wtmc = util.OnTrial_WTMCS.Get(MessageConfig.WxTpl_OnTrial_Expired.First.Value)
|
|
|
+ first_color = MessageConfig.WxTpl_OnTrial_Expired.First.Color
|
|
|
+ }
|
|
|
+ keyword1_value = qutil.ObjToString(m["s_nickname"])
|
|
|
+ keyword2_value = FormatDateByInt64(&l_vip_endtime, Date_Short_Layout)
|
|
|
+ case 2, -2:
|
|
|
+ if i_vip_expire_tip == 1 {
|
|
|
+ tp = "soonexprie"
|
|
|
+ tplId = MessageConfig.WxTpl_SoonExpire.Id
|
|
|
+ wtmc = util.Formal_WTMCS.Get(MessageConfig.WxTpl_SoonExpire.First.Value)
|
|
|
+ first_color = MessageConfig.WxTpl_SoonExpire.First.Color
|
|
|
+ keyword2_value = MessageConfig.WxTpl_SoonExpire.Keyword2.Value
|
|
|
+ keyword3_value = MessageConfig.WxTpl_SoonExpire.Keyword3.Value
|
|
|
+ } else if i_vip_expire_tip == 2 {
|
|
|
+ tp = "expried"
|
|
|
+ tplId = MessageConfig.WxTpl_Expired.Id
|
|
|
+ wtmc = util.Formal_WTMCS.Get(MessageConfig.WxTpl_Expired.First.Value)
|
|
|
+ first_color = MessageConfig.WxTpl_Expired.First.Color
|
|
|
+ keyword2_value = MessageConfig.WxTpl_Expired.Keyword2.Value
|
|
|
+ keyword3_value = MessageConfig.WxTpl_Expired.Keyword3.Value
|
|
|
+ }
|
|
|
+ keyword1_value = qutil.ObjToString(m["s_nickname"])
|
|
|
+ keyword4_value = FormatDateByInt64(&l_vip_endtime, Date_Short_Layout)
|
|
|
+ default:
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if wtmc != nil {
|
|
|
+ tmplData := map[string]*qrpc.TmplItem{
|
|
|
+ "first": &qrpc.TmplItem{
|
|
|
+ Value: wtmc.FirstData,
|
|
|
+ Color: first_color,
|
|
|
+ },
|
|
|
+ "keyword1": &qrpc.TmplItem{
|
|
|
+ Value: keyword1_value,
|
|
|
+ },
|
|
|
+ "keyword2": &qrpc.TmplItem{
|
|
|
+ Value: keyword2_value,
|
|
|
+ },
|
|
|
+ "keyword3": &qrpc.TmplItem{
|
|
|
+ Value: keyword3_value,
|
|
|
+ },
|
|
|
+ "keyword4": &qrpc.TmplItem{
|
|
|
+ Value: keyword4_value,
|
|
|
+ },
|
|
|
+ }
|
|
|
+ wxPushOk, _ = qrpc.WxSendTmplMsg(Config.Weixinrpc, &qrpc.WxTmplMsg{
|
|
|
+ OpenId: s_m_openid,
|
|
|
+ TplId: tplId,
|
|
|
+ TmplData: tmplData,
|
|
|
+ Url: Config.WebDomain + "/front/sess/" + util.Se_Topnet.EncodeString(_id+qutil.If(IsObjectIdHex(_id), ",_id,", ",entUserId,").(string)+strconv.Itoa(int(time.Now().Unix()))+",msgremind") + "__" + hex.EncodeToString([]byte(fmt.Sprintf("type=%s&advertcode=%s", tp, wtmc.AdvertCode))),
|
|
|
+ })
|
|
|
+ log.Println("到期提醒,微信推送", _id, wxPushOk, wtmc.AdvertCode, wtmc.FirstData)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if !wxPushOk && (m["s_opushid"] != nil || m["s_jpushid"] != nil) { //app推送
|
|
|
+ tp, app_descript := "", ""
|
|
|
+ switch i_vip_status {
|
|
|
+ case 1, -1:
|
|
|
+ if i_vip_expire_tip == 1 {
|
|
|
+ tp = "ontrial_soonexprie"
|
|
|
+ app_descript = MessageConfig.App_OnTrial_SoonExpire
|
|
|
+ } else if i_vip_expire_tip == 2 {
|
|
|
+ tp = "ontrial_expried"
|
|
|
+ app_descript = MessageConfig.App_OnTrial_Expired
|
|
|
+ }
|
|
|
+ case 2, -2:
|
|
|
+ if i_vip_expire_tip == 1 {
|
|
|
+ tp = "soonexprie"
|
|
|
+ app_descript = MessageConfig.App_SoonExpire
|
|
|
+ } else if i_vip_expire_tip == 2 {
|
|
|
+ tp = "expried"
|
|
|
+ app_descript = MessageConfig.App_Expired
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ return
|
|
|
+ }
|
|
|
+ appPushOk = qrpc.AppPush(Config.AppPushServiceRpc, map[string]interface{}{
|
|
|
+ "phoneType": m["s_appponetype"],
|
|
|
+ "otherPushId": m["s_opushid"],
|
|
|
+ "jgPushId": m["s_jpushid"],
|
|
|
+ "url": "/jyapp/free/sess/" + util.Se_Topnet.EncodeString(_id+qutil.If(IsObjectIdHex(_id), ",_id,", ",entUserId,").(string)+strconv.Itoa(int(time.Now().Unix()))+",msgremind") + "__" + hex.EncodeToString([]byte(fmt.Sprintf("type=%s", tp))),
|
|
|
+ "userId": _id,
|
|
|
+ "type": "vipNotice",
|
|
|
+ "descript": app_descript,
|
|
|
+ "title": "剑鱼提醒",
|
|
|
+ })
|
|
|
+ log.Println("到期提醒,app推送", _id, appPushOk)
|
|
|
+ }
|
|
|
+ if wxPushOk || appPushOk || qutil.IntAll(m["i_vip_expire_tip_retry"]) >= 2 {
|
|
|
+ util.Compatible.UpdateByEntUserId(_id, map[string]interface{}{
|
|
|
+ "$set": map[string]interface{}{
|
|
|
+ "i_vip_expire_tip": 0,
|
|
|
+ },
|
|
|
+ })
|
|
|
+ } else if i_vip_expire_tip == 2 {
|
|
|
+ util.Compatible.UpdateByEntUserId(_id, map[string]interface{}{
|
|
|
+ "$set": map[string]interface{}{
|
|
|
+ "i_vip_expire_tip_retry": 1,
|
|
|
+ },
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ field := map[string]interface{}{
|
|
|
+ "s_m_openid": 1,
|
|
|
+ "s_jpushid": 1,
|
|
|
+ "s_opushid": 1,
|
|
|
+ "s_appponetype": 1,
|
|
|
+ "s_nickname": 1,
|
|
|
+ "i_ispush": 1,
|
|
|
+ "i_vip_status": 1,
|
|
|
+ "l_vip_starttime": 1,
|
|
|
+ "l_vip_endtime": 1,
|
|
|
+ "i_vip_expire_tip": 1,
|
|
|
+ "i_vip_expire_tip_retry": 1,
|
|
|
+ }
|
|
|
+ (&Personal{}).LoadVipUsers(field, doFunc)
|
|
|
+ (&Ent{}).LoadVipUsers(field, doFunc)
|
|
|
+ log.Println("定时任务,到期提醒,推送消息结束")
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
//检测大会员到期时间 定时任务
|
|
|
func checkMemberIsExpire(i Identity) {
|
|
|
- crontab(true, TimeTaskConfig.MemberExpire, func() {
|
|
|
- defer qutil.Catch()
|
|
|
- log.Println("定时任务,开始更新大会员状态")
|
|
|
- now_unix := time.Now().Unix()
|
|
|
- now_time := FormatDateByInt64(&now_unix, Date_Full_Layout)
|
|
|
- sess := util.MQFW.GetMgoConn()
|
|
|
- for {
|
|
|
- if sess != nil {
|
|
|
- defer util.MQFW.DestoryMongoConn(sess)
|
|
|
- break
|
|
|
- }
|
|
|
- time.Sleep(time.Minute)
|
|
|
- sess = util.MQFW.GetMgoConn()
|
|
|
- }
|
|
|
- query := i.UserQuery()
|
|
|
- query["i_member_status"] = map[string]interface{}{
|
|
|
- "$gt": 0,
|
|
|
- }
|
|
|
- query["i_member_endtime"] = map[string]interface{}{
|
|
|
- "$lte": now_unix + threeday,
|
|
|
- }
|
|
|
- it := sess.DB("qfw").C(i.UserColl()).Find(query).Select(i.UserField(map[string]interface{}{"i_member_status": 1, "i_member_endtime": 1, "i_member_expire_tip": 1})).Iter()
|
|
|
- for m := make(map[string]interface{}); it.Next(&m); {
|
|
|
- _id := BsonIdToSId(m["_id"])
|
|
|
- i_member_endtime := qutil.Int64All(m["i_member_endtime"])
|
|
|
- i_member_status := qutil.IntAll(m["i_member_status"])
|
|
|
- i_member_expire_tip := qutil.IntAll(m["i_member_expire_tip"])
|
|
|
- if i_member_endtime <= now_unix {
|
|
|
- util.MQFW.UpdateById(i.UserColl(), _id, map[string]interface{}{
|
|
|
- "$set": map[string]interface{}{
|
|
|
- "i_member_status": -i_member_status,
|
|
|
- "i_member_expire_tip": 2,
|
|
|
- },
|
|
|
- "$unset": map[string]interface{}{
|
|
|
- "i_member_expire_tip_retry": "",
|
|
|
- "i_mainaccount": "",
|
|
|
- "i_pay_sub_num": "",
|
|
|
- "i_free_sub_num": "",
|
|
|
- "i_member_sub_status": "",
|
|
|
- "s_member_mainid": "",
|
|
|
- },
|
|
|
- })
|
|
|
- go i.DelBigMemberSubPush(m)
|
|
|
- //大会员用户服务表
|
|
|
- if util.Mysql.UpdateOrDeleteBySql(`UPDATE `+jy.BigmemberUserPowerTable+` a SET a.i_frequency = 0 , a.i_status = -1, a.l_updatetime=? WHERE a.s_userid = ?`, now_time, _id) < 0 {
|
|
|
- log.Println(_id, "更新到期用户服务表出错")
|
|
|
- } else {
|
|
|
- positionId := util.MongoIdToPositionId(_id)
|
|
|
- ok := jy.ClearBigVipUserPower(positionId)
|
|
|
- config.Middleground.UserCenter.WorkDesktopClearUserInfo(pb.WorkDesktopClearUserInfoReq{
|
|
|
- PositionId: positionId,
|
|
|
- AppId: "10000",
|
|
|
- })
|
|
|
- go config.Middleground.PowerCheckCenter.DelCheckRedis("10000", qutil.Int64All(positionId))
|
|
|
- if !ok {
|
|
|
- log.Println("清除 redis 大会员服务详情 缓存失败:", _id)
|
|
|
- }
|
|
|
- }
|
|
|
- } else if i_member_endtime-now_unix <= threeday && i_member_expire_tip != 1 {
|
|
|
- updateOk := util.MQFW.UpdateById(i.UserColl(), _id, map[string]interface{}{
|
|
|
- "$set": map[string]interface{}{
|
|
|
- "i_member_expire_tip": 1,
|
|
|
- },
|
|
|
- "$unset": map[string]interface{}{
|
|
|
- "i_member_expire_tip_retry": "",
|
|
|
- },
|
|
|
- })
|
|
|
- log.Println("用户", _id, i_member_status, i_member_endtime, "修改大会员即将到期状态", updateOk)
|
|
|
- }
|
|
|
- m = make(map[string]interface{})
|
|
|
- }
|
|
|
- log.Println("定时任务,更新大会员状态结束")
|
|
|
- })
|
|
|
+ crontab(true, TimeTaskConfig.MemberExpire, func() {
|
|
|
+ defer qutil.Catch()
|
|
|
+ log.Println("定时任务,开始更新大会员状态")
|
|
|
+ now_unix := time.Now().Unix()
|
|
|
+ now_time := FormatDateByInt64(&now_unix, Date_Full_Layout)
|
|
|
+ sess := util.MQFW.GetMgoConn()
|
|
|
+ for {
|
|
|
+ if sess != nil {
|
|
|
+ defer util.MQFW.DestoryMongoConn(sess)
|
|
|
+ break
|
|
|
+ }
|
|
|
+ time.Sleep(time.Minute)
|
|
|
+ sess = util.MQFW.GetMgoConn()
|
|
|
+ }
|
|
|
+ query := i.UserQuery()
|
|
|
+ query["i_member_status"] = map[string]interface{}{
|
|
|
+ "$gt": 0,
|
|
|
+ }
|
|
|
+ query["i_member_endtime"] = map[string]interface{}{
|
|
|
+ "$lte": now_unix + threeday,
|
|
|
+ }
|
|
|
+ it := sess.DB("qfw").C(i.UserColl()).Find(query).Select(i.UserField(map[string]interface{}{"i_member_status": 1, "i_member_endtime": 1, "i_member_expire_tip": 1})).Iter()
|
|
|
+ for m := make(map[string]interface{}); it.Next(&m); {
|
|
|
+ _id := BsonIdToSId(m["_id"])
|
|
|
+ i_member_endtime := qutil.Int64All(m["i_member_endtime"])
|
|
|
+ i_member_status := qutil.IntAll(m["i_member_status"])
|
|
|
+ i_member_expire_tip := qutil.IntAll(m["i_member_expire_tip"])
|
|
|
+ if i_member_endtime <= now_unix {
|
|
|
+ util.MQFW.UpdateById(i.UserColl(), _id, map[string]interface{}{
|
|
|
+ "$set": map[string]interface{}{
|
|
|
+ "i_member_status": -i_member_status,
|
|
|
+ "i_member_expire_tip": 2,
|
|
|
+ },
|
|
|
+ "$unset": map[string]interface{}{
|
|
|
+ "i_member_expire_tip_retry": "",
|
|
|
+ "i_mainaccount": "",
|
|
|
+ "i_pay_sub_num": "",
|
|
|
+ "i_free_sub_num": "",
|
|
|
+ "i_member_sub_status": "",
|
|
|
+ "s_member_mainid": "",
|
|
|
+ },
|
|
|
+ })
|
|
|
+ go i.DelBigMemberSubPush(m)
|
|
|
+ //大会员用户服务表
|
|
|
+ if util.Mysql.UpdateOrDeleteBySql(`UPDATE `+jy.BigmemberUserPowerTable+` a SET a.i_frequency = 0 , a.i_status = -1, a.l_updatetime=? WHERE a.s_userid = ?`, now_time, _id) < 0 {
|
|
|
+ log.Println(_id, "更新到期用户服务表出错")
|
|
|
+ } else {
|
|
|
+ positionId := util.MongoIdToPositionId(_id)
|
|
|
+ ok := jy.ClearBigVipUserPower(positionId)
|
|
|
+ config.Middleground.UserCenter.WorkDesktopClearUserInfo(pb.WorkDesktopClearUserInfoReq{
|
|
|
+ PositionId: positionId,
|
|
|
+ AppId: "10000",
|
|
|
+ })
|
|
|
+ go config.Middleground.PowerCheckCenter.DelCheckRedis("10000", qutil.Int64All(positionId))
|
|
|
+ if !ok {
|
|
|
+ log.Println("清除 redis 大会员服务详情 缓存失败:", _id)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if i_member_endtime-now_unix <= threeday && i_member_expire_tip != 1 {
|
|
|
+ updateOk := util.MQFW.UpdateById(i.UserColl(), _id, map[string]interface{}{
|
|
|
+ "$set": map[string]interface{}{
|
|
|
+ "i_member_expire_tip": 1,
|
|
|
+ },
|
|
|
+ "$unset": map[string]interface{}{
|
|
|
+ "i_member_expire_tip_retry": "",
|
|
|
+ },
|
|
|
+ })
|
|
|
+ log.Println("用户", _id, i_member_status, i_member_endtime, "修改大会员即将到期状态", updateOk)
|
|
|
+ }
|
|
|
+ m = make(map[string]interface{})
|
|
|
+ }
|
|
|
+ log.Println("定时任务,更新大会员状态结束")
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
//大会员即将到期或者已到期发推送消息
|
|
|
func bigMemberExpireRemind() {
|
|
|
- crontab(false, TimeTaskConfig.ExpireRemind, func() {
|
|
|
- defer qutil.Catch()
|
|
|
- log.Println("定时任务,大会员到期提醒,开始推送消息")
|
|
|
- now_unix := time.Now().Unix()
|
|
|
- util.Formal_WTMCS.Reload()
|
|
|
- doFunc := func(m map[string]interface{}) {
|
|
|
- i_member_expire_tip := qutil.IntAll(m["i_member_expire_tip"])
|
|
|
- if i_member_expire_tip != 1 && i_member_expire_tip != 2 {
|
|
|
- return
|
|
|
- }
|
|
|
- _id := qutil.ObjToString(m["_id"])
|
|
|
- i_member_endtime := qutil.Int64All(m["i_member_endtime"])
|
|
|
- if i_member_endtime-now_unix > threeday && i_member_endtime == 1 {
|
|
|
- log.Println("大会员即将到期提醒,结束时间大于三天,过滤掉", _id, i_member_endtime)
|
|
|
- return
|
|
|
- }
|
|
|
- i_member_status := qutil.IntAll(m["i_member_status"])
|
|
|
- wxPushOk, appPushOk := false, false
|
|
|
- i_member_starttime := qutil.Int64All(m["i_member_starttime"])
|
|
|
- s_m_openid := qutil.ObjToString(m["s_m_openid"])
|
|
|
- isPushWx := qutil.IntAllDef(m["i_ispush"], 1)
|
|
|
- s_jpushid := qutil.ObjToString(m["s_jpushid"])
|
|
|
- s_opushid := qutil.ObjToString(m["s_opushid"])
|
|
|
- s_appponetype := qutil.ObjToString(m["s_appponetype"])
|
|
|
- log.Println("大会员到期提醒,推送消息", _id, "i_member_status", i_member_status, "i_member_starttime", i_member_starttime, "i_member_endtime", i_member_endtime, "i_member_expire_tip", i_member_expire_tip, "s_m_openid", s_m_openid, "isPushWx", isPushWx, "s_appponetype", s_appponetype, "s_jpushid", s_jpushid, "s_opushid", s_opushid)
|
|
|
- if isPushWx == 1 && s_m_openid != "" { //微信推送
|
|
|
- //tp := ""
|
|
|
- tplId, first_color, keyword1_value, keyword2_value, keyword3_value, keyword4_value, remark := "", "", "", "", "", "", ""
|
|
|
- var wtmc *p.WxTplMsgCustom
|
|
|
- if i_member_status > 0 {
|
|
|
- //tp = "bigmember_soonexprie"
|
|
|
- tplId = MessageConfig.WxTpl_BigMember_SoonExpire.Id
|
|
|
- wtmc = util.Formal_WTMCS.Get(MessageConfig.WxTpl_BigMember_SoonExpire.First.Value)
|
|
|
- first_color = MessageConfig.WxTpl_BigMember_SoonExpire.First.Color
|
|
|
- keyword2_value = MessageConfig.WxTpl_BigMember_SoonExpire.Keyword2.Value
|
|
|
- keyword3_value = MessageConfig.WxTpl_BigMember_SoonExpire.Keyword3.Value
|
|
|
- remark = MessageConfig.WxTpl_BigMember_SoonExpire.Remark.Value
|
|
|
- } else if i_member_status < 0 {
|
|
|
- //tp = "bigmember_expried"
|
|
|
- tplId = MessageConfig.WxTpl_BigMember_Expired.Id
|
|
|
- wtmc = util.Formal_WTMCS.Get(MessageConfig.WxTpl_BigMember_Expired.First.Value)
|
|
|
- first_color = MessageConfig.WxTpl_BigMember_Expired.First.Color
|
|
|
- keyword2_value = MessageConfig.WxTpl_BigMember_Expired.Keyword2.Value
|
|
|
- keyword3_value = MessageConfig.WxTpl_BigMember_Expired.Keyword3.Value
|
|
|
- remark = MessageConfig.WxTpl_BigMember_Expired.Remark.Value
|
|
|
- } else {
|
|
|
- return
|
|
|
- }
|
|
|
- if wtmc != nil {
|
|
|
- keyword1_value = qutil.ObjToString(m["s_nickname"])
|
|
|
- keyword4_value = FormatDateByInt64(&i_member_endtime, Date_Short_Layout)
|
|
|
- tmplData := map[string]*qrpc.TmplItem{
|
|
|
- "first": &qrpc.TmplItem{
|
|
|
- Value: wtmc.FirstData,
|
|
|
- Color: first_color,
|
|
|
- },
|
|
|
- "keyword1": &qrpc.TmplItem{
|
|
|
- Value: keyword1_value,
|
|
|
- },
|
|
|
- "keyword2": &qrpc.TmplItem{
|
|
|
- Value: keyword2_value,
|
|
|
- },
|
|
|
- "keyword3": &qrpc.TmplItem{
|
|
|
- Value: keyword3_value,
|
|
|
- },
|
|
|
- "keyword4": &qrpc.TmplItem{
|
|
|
- Value: keyword4_value,
|
|
|
- },
|
|
|
- "remark": &qrpc.TmplItem{
|
|
|
- Value: remark,
|
|
|
- },
|
|
|
- }
|
|
|
- wxPushOk, _ = qrpc.WxSendTmplMsg(Config.Weixinrpc, &qrpc.WxTmplMsg{
|
|
|
- OpenId: s_m_openid,
|
|
|
- TplId: tplId,
|
|
|
- TmplData: tmplData,
|
|
|
- //Url: Config.WebDomain + "/front/sess/" + util.Se_Topnet.EncodeString(s_m_openid+",uid,"+strconv.Itoa(int(time.Now().Unix()))+",msgremind") + "__" + hex.EncodeToString([]byte(fmt.Sprintf("type=%s&advertcode=%s", tp, wtmc.AdvertCode))),
|
|
|
- })
|
|
|
- log.Println("大会员到期提醒,微信推送", _id, wxPushOk, wtmc.AdvertCode, wtmc.FirstData)
|
|
|
- }
|
|
|
- }
|
|
|
- if !wxPushOk && (m["s_opushid"] != nil || m["s_jpushid"] != nil) { //app推送
|
|
|
- tp, app_descript := "", ""
|
|
|
- if i_member_status > 0 {
|
|
|
- tp = "bigmember_soonexprie"
|
|
|
- app_descript = MessageConfig.App_BigMember_SoonExpire
|
|
|
- } else if i_member_status < 0 {
|
|
|
- tp = "bigmember_expried"
|
|
|
- app_descript = MessageConfig.App_BigMember_Expired
|
|
|
- } else {
|
|
|
- return
|
|
|
- }
|
|
|
- appPushOk = qrpc.AppPush(Config.AppPushServiceRpc, map[string]interface{}{
|
|
|
- "phoneType": m["s_appponetype"],
|
|
|
- "otherPushId": m["s_opushid"],
|
|
|
- "jgPushId": m["s_jpushid"],
|
|
|
- "url": "/jyapp/free/sess/" + util.Se_Topnet.EncodeString(_id+qutil.If(IsObjectIdHex(_id), ",_id,", ",entUserId,").(string)+strconv.Itoa(int(time.Now().Unix()))+",msgremind") + "__" + hex.EncodeToString([]byte(fmt.Sprintf("type=%s", tp))),
|
|
|
- "userId": _id,
|
|
|
- "type": "vipNotice",
|
|
|
- "descript": app_descript,
|
|
|
- "title": "剑鱼提醒",
|
|
|
- })
|
|
|
- log.Println("大会员到期提醒,app推送", _id, appPushOk)
|
|
|
- }
|
|
|
- if wxPushOk || appPushOk || qutil.IntAll(m["i_member_expire_tip_retry"]) >= 2 {
|
|
|
- util.Compatible.Update(_id, map[string]interface{}{
|
|
|
- "$set": map[string]interface{}{
|
|
|
- "i_member_expire_tip": 0,
|
|
|
- },
|
|
|
- })
|
|
|
- } else {
|
|
|
- util.Compatible.Update(_id, map[string]interface{}{
|
|
|
- "$inc": map[string]interface{}{
|
|
|
- "i_member_expire_tip_retry": 1,
|
|
|
- },
|
|
|
- })
|
|
|
- }
|
|
|
- }
|
|
|
- field := map[string]interface{}{
|
|
|
- "s_m_openid": 1,
|
|
|
- "s_jpushid": 1,
|
|
|
- "s_opushid": 1,
|
|
|
- "s_appponetype": 1,
|
|
|
- "s_nickname": 1,
|
|
|
- "i_ispush": 1,
|
|
|
- "i_member_status": 1,
|
|
|
- "i_member_starttime": 1,
|
|
|
- "i_member_endtime": 1,
|
|
|
- "i_member_expire_tip": 1,
|
|
|
- "i_member_expire_tip_retry": 1,
|
|
|
- }
|
|
|
- (&Personal{}).LoadBigMemberUsers(field, doFunc)
|
|
|
- (&Ent{}).LoadBigMemberUsers(field, doFunc)
|
|
|
- log.Println("定时任务,大会员到期提醒,推送消息结束")
|
|
|
- })
|
|
|
+ crontab(false, TimeTaskConfig.ExpireRemind, func() {
|
|
|
+ defer qutil.Catch()
|
|
|
+ log.Println("定时任务,大会员到期提醒,开始推送消息")
|
|
|
+ now_unix := time.Now().Unix()
|
|
|
+ util.Formal_WTMCS.Reload()
|
|
|
+ doFunc := func(m map[string]interface{}) {
|
|
|
+ i_member_expire_tip := qutil.IntAll(m["i_member_expire_tip"])
|
|
|
+ if i_member_expire_tip != 1 && i_member_expire_tip != 2 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ _id := qutil.ObjToString(m["_id"])
|
|
|
+ i_member_endtime := qutil.Int64All(m["i_member_endtime"])
|
|
|
+ if i_member_endtime-now_unix > threeday && i_member_endtime == 1 {
|
|
|
+ log.Println("大会员即将到期提醒,结束时间大于三天,过滤掉", _id, i_member_endtime)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ i_member_status := qutil.IntAll(m["i_member_status"])
|
|
|
+ wxPushOk, appPushOk := false, false
|
|
|
+ i_member_starttime := qutil.Int64All(m["i_member_starttime"])
|
|
|
+ s_m_openid := qutil.ObjToString(m["s_m_openid"])
|
|
|
+ isPushWx := qutil.IntAllDef(m["i_ispush"], 1)
|
|
|
+ s_jpushid := qutil.ObjToString(m["s_jpushid"])
|
|
|
+ s_opushid := qutil.ObjToString(m["s_opushid"])
|
|
|
+ s_appponetype := qutil.ObjToString(m["s_appponetype"])
|
|
|
+ log.Println("大会员到期提醒,推送消息", _id, "i_member_status", i_member_status, "i_member_starttime", i_member_starttime, "i_member_endtime", i_member_endtime, "i_member_expire_tip", i_member_expire_tip, "s_m_openid", s_m_openid, "isPushWx", isPushWx, "s_appponetype", s_appponetype, "s_jpushid", s_jpushid, "s_opushid", s_opushid)
|
|
|
+ if isPushWx == 1 && s_m_openid != "" { //微信推送
|
|
|
+ //tp := ""
|
|
|
+ tplId, first_color, keyword1_value, keyword2_value, keyword3_value, keyword4_value := "", "", "", "", "", ""
|
|
|
+ var wtmc *p.WxTplMsgCustom
|
|
|
+ if i_member_status > 0 {
|
|
|
+ //tp = "bigmember_soonexprie"
|
|
|
+ tplId = MessageConfig.WxTpl_BigMember_SoonExpire.Id
|
|
|
+ wtmc = util.Formal_WTMCS.Get(MessageConfig.WxTpl_BigMember_SoonExpire.First.Value)
|
|
|
+ first_color = MessageConfig.WxTpl_BigMember_SoonExpire.First.Color
|
|
|
+ keyword2_value = MessageConfig.WxTpl_BigMember_SoonExpire.Keyword2.Value
|
|
|
+ keyword3_value = MessageConfig.WxTpl_BigMember_SoonExpire.Keyword3.Value
|
|
|
+ } else if i_member_status < 0 {
|
|
|
+ //tp = "bigmember_expried"
|
|
|
+ tplId = MessageConfig.WxTpl_BigMember_Expired.Id
|
|
|
+ wtmc = util.Formal_WTMCS.Get(MessageConfig.WxTpl_BigMember_Expired.First.Value)
|
|
|
+ first_color = MessageConfig.WxTpl_BigMember_Expired.First.Color
|
|
|
+ keyword2_value = MessageConfig.WxTpl_BigMember_Expired.Keyword2.Value
|
|
|
+ keyword3_value = MessageConfig.WxTpl_BigMember_Expired.Keyword3.Value
|
|
|
+ } else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if wtmc != nil {
|
|
|
+ keyword1_value = qutil.ObjToString(m["s_nickname"])
|
|
|
+ keyword4_value = FormatDateByInt64(&i_member_endtime, Date_Short_Layout)
|
|
|
+ tmplData := map[string]*qrpc.TmplItem{
|
|
|
+ "first": &qrpc.TmplItem{
|
|
|
+ Value: wtmc.FirstData,
|
|
|
+ Color: first_color,
|
|
|
+ },
|
|
|
+ "keyword1": &qrpc.TmplItem{
|
|
|
+ Value: keyword1_value,
|
|
|
+ },
|
|
|
+ "keyword2": &qrpc.TmplItem{
|
|
|
+ Value: keyword2_value,
|
|
|
+ },
|
|
|
+ "keyword3": &qrpc.TmplItem{
|
|
|
+ Value: keyword3_value,
|
|
|
+ },
|
|
|
+ "keyword4": &qrpc.TmplItem{
|
|
|
+ Value: keyword4_value,
|
|
|
+ },
|
|
|
+ }
|
|
|
+ wxPushOk, _ = qrpc.WxSendTmplMsg(Config.Weixinrpc, &qrpc.WxTmplMsg{
|
|
|
+ OpenId: s_m_openid,
|
|
|
+ TplId: tplId,
|
|
|
+ TmplData: tmplData,
|
|
|
+ //Url: Config.WebDomain + "/front/sess/" + util.Se_Topnet.EncodeString(s_m_openid+",uid,"+strconv.Itoa(int(time.Now().Unix()))+",msgremind") + "__" + hex.EncodeToString([]byte(fmt.Sprintf("type=%s&advertcode=%s", tp, wtmc.AdvertCode))),
|
|
|
+ })
|
|
|
+ log.Println("大会员到期提醒,微信推送", _id, wxPushOk, wtmc.AdvertCode, wtmc.FirstData)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if !wxPushOk && (m["s_opushid"] != nil || m["s_jpushid"] != nil) { //app推送
|
|
|
+ tp, app_descript := "", ""
|
|
|
+ if i_member_status > 0 {
|
|
|
+ tp = "bigmember_soonexprie"
|
|
|
+ app_descript = MessageConfig.App_BigMember_SoonExpire
|
|
|
+ } else if i_member_status < 0 {
|
|
|
+ tp = "bigmember_expried"
|
|
|
+ app_descript = MessageConfig.App_BigMember_Expired
|
|
|
+ } else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ appPushOk = qrpc.AppPush(Config.AppPushServiceRpc, map[string]interface{}{
|
|
|
+ "phoneType": m["s_appponetype"],
|
|
|
+ "otherPushId": m["s_opushid"],
|
|
|
+ "jgPushId": m["s_jpushid"],
|
|
|
+ "url": "/jyapp/free/sess/" + util.Se_Topnet.EncodeString(_id+qutil.If(IsObjectIdHex(_id), ",_id,", ",entUserId,").(string)+strconv.Itoa(int(time.Now().Unix()))+",msgremind") + "__" + hex.EncodeToString([]byte(fmt.Sprintf("type=%s", tp))),
|
|
|
+ "userId": _id,
|
|
|
+ "type": "vipNotice",
|
|
|
+ "descript": app_descript,
|
|
|
+ "title": "剑鱼提醒",
|
|
|
+ })
|
|
|
+ log.Println("大会员到期提醒,app推送", _id, appPushOk)
|
|
|
+ }
|
|
|
+ if wxPushOk || appPushOk || qutil.IntAll(m["i_member_expire_tip_retry"]) >= 2 {
|
|
|
+ util.Compatible.Update(_id, map[string]interface{}{
|
|
|
+ "$set": map[string]interface{}{
|
|
|
+ "i_member_expire_tip": 0,
|
|
|
+ },
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ util.Compatible.Update(_id, map[string]interface{}{
|
|
|
+ "$inc": map[string]interface{}{
|
|
|
+ "i_member_expire_tip_retry": 1,
|
|
|
+ },
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ field := map[string]interface{}{
|
|
|
+ "s_m_openid": 1,
|
|
|
+ "s_jpushid": 1,
|
|
|
+ "s_opushid": 1,
|
|
|
+ "s_appponetype": 1,
|
|
|
+ "s_nickname": 1,
|
|
|
+ "i_ispush": 1,
|
|
|
+ "i_member_status": 1,
|
|
|
+ "i_member_starttime": 1,
|
|
|
+ "i_member_endtime": 1,
|
|
|
+ "i_member_expire_tip": 1,
|
|
|
+ "i_member_expire_tip_retry": 1,
|
|
|
+ }
|
|
|
+ (&Personal{}).LoadBigMemberUsers(field, doFunc)
|
|
|
+ (&Ent{}).LoadBigMemberUsers(field, doFunc)
|
|
|
+ log.Println("定时任务,大会员到期提醒,推送消息结束")
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
//查看是否有大会员用户定时开启会员
|
|
|
func checkMemberIsStart() {
|
|
|
- crontab(true, TimeTaskConfig.MemberIsStart, func() {
|
|
|
- defer qutil.Catch()
|
|
|
- log.Println("定时任务,开始更新大会员状态-定时开启会员状态")
|
|
|
- now_unix := time.Now().Unix()
|
|
|
- sess := util.MQFW.GetMgoConn()
|
|
|
- for {
|
|
|
- if sess != nil {
|
|
|
- defer util.MQFW.DestoryMongoConn(sess)
|
|
|
- break
|
|
|
- }
|
|
|
- time.Sleep(time.Minute)
|
|
|
- sess = util.MQFW.GetMgoConn()
|
|
|
- }
|
|
|
- //定时开启大会员 i_member_status<0 && i_member_endtime 结束时间大于当前时间 && i_member_starttime 开始时间小于当前时间
|
|
|
- it := sess.DB("qfw").C("user").Find(map[string]interface{}{
|
|
|
- "i_appid": 2,
|
|
|
- "i_member_status": map[string]interface{}{
|
|
|
- "$lt": 0,
|
|
|
- },
|
|
|
- "$and": []map[string]interface{}{
|
|
|
- map[string]interface{}{
|
|
|
- "i_member_endtime": map[string]interface{}{
|
|
|
- "$gte": now_unix,
|
|
|
- },
|
|
|
- },
|
|
|
- map[string]interface{}{
|
|
|
- "i_member_starttime": map[string]interface{}{
|
|
|
- "$lte": now_unix,
|
|
|
- },
|
|
|
- },
|
|
|
- },
|
|
|
- }).Select(map[string]interface{}{"i_member_status": 1, "i_member_endtime": 1, "i_member_starttime": 1}).Iter()
|
|
|
- for m := make(map[string]interface{}); it.Next(&m); {
|
|
|
- _id := BsonIdToSId(m["_id"])
|
|
|
- i_member_endtime := qutil.Int64All(m["i_member_endtime"])
|
|
|
- i_member_starttime := qutil.Int64All(m["i_member_starttime"])
|
|
|
- i_member_status := qutil.IntAll(m["i_member_status"])
|
|
|
- if i_member_endtime > now_unix && i_member_starttime < now_unix {
|
|
|
- util.Compatible.Update(_id, map[string]interface{}{
|
|
|
- "$set": map[string]interface{}{
|
|
|
- "i_member_status": -i_member_status,
|
|
|
- },
|
|
|
- })
|
|
|
- //大会员用户服务表更新
|
|
|
- updateBigMemberService(_id, now_unix)
|
|
|
- positionId := util.MongoIdToPositionId(_id)
|
|
|
- ok := jy.ClearBigVipUserPower(positionId)
|
|
|
- config.Middleground.UserCenter.WorkDesktopClearUserInfo(pb.WorkDesktopClearUserInfoReq{
|
|
|
- PositionId: positionId,
|
|
|
- AppId: "10000",
|
|
|
- })
|
|
|
- config.Middleground.PowerCheckCenter.DelCheckRedis("10000", qutil.Int64All(positionId))
|
|
|
- if !ok {
|
|
|
- log.Println("清除 redis 大会员服务详情 缓存失败:", _id)
|
|
|
- }
|
|
|
- }
|
|
|
- m = make(map[string]interface{})
|
|
|
- }
|
|
|
- log.Println("定时任务,更新大会员状态结束-定时开启会员状态")
|
|
|
- })
|
|
|
+ crontab(true, TimeTaskConfig.MemberIsStart, func() {
|
|
|
+ defer qutil.Catch()
|
|
|
+ log.Println("定时任务,开始更新大会员状态-定时开启会员状态")
|
|
|
+ now_unix := time.Now().Unix()
|
|
|
+ sess := util.MQFW.GetMgoConn()
|
|
|
+ for {
|
|
|
+ if sess != nil {
|
|
|
+ defer util.MQFW.DestoryMongoConn(sess)
|
|
|
+ break
|
|
|
+ }
|
|
|
+ time.Sleep(time.Minute)
|
|
|
+ sess = util.MQFW.GetMgoConn()
|
|
|
+ }
|
|
|
+ //定时开启大会员 i_member_status<0 && i_member_endtime 结束时间大于当前时间 && i_member_starttime 开始时间小于当前时间
|
|
|
+ it := sess.DB("qfw").C("user").Find(map[string]interface{}{
|
|
|
+ "i_appid": 2,
|
|
|
+ "i_member_status": map[string]interface{}{
|
|
|
+ "$lt": 0,
|
|
|
+ },
|
|
|
+ "$and": []map[string]interface{}{
|
|
|
+ map[string]interface{}{
|
|
|
+ "i_member_endtime": map[string]interface{}{
|
|
|
+ "$gte": now_unix,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ map[string]interface{}{
|
|
|
+ "i_member_starttime": map[string]interface{}{
|
|
|
+ "$lte": now_unix,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }).Select(map[string]interface{}{"i_member_status": 1, "i_member_endtime": 1, "i_member_starttime": 1}).Iter()
|
|
|
+ for m := make(map[string]interface{}); it.Next(&m); {
|
|
|
+ _id := BsonIdToSId(m["_id"])
|
|
|
+ i_member_endtime := qutil.Int64All(m["i_member_endtime"])
|
|
|
+ i_member_starttime := qutil.Int64All(m["i_member_starttime"])
|
|
|
+ i_member_status := qutil.IntAll(m["i_member_status"])
|
|
|
+ if i_member_endtime > now_unix && i_member_starttime < now_unix {
|
|
|
+ util.Compatible.Update(_id, map[string]interface{}{
|
|
|
+ "$set": map[string]interface{}{
|
|
|
+ "i_member_status": -i_member_status,
|
|
|
+ },
|
|
|
+ })
|
|
|
+ //大会员用户服务表更新
|
|
|
+ updateBigMemberService(_id, now_unix)
|
|
|
+ positionId := util.MongoIdToPositionId(_id)
|
|
|
+ ok := jy.ClearBigVipUserPower(positionId)
|
|
|
+ config.Middleground.UserCenter.WorkDesktopClearUserInfo(pb.WorkDesktopClearUserInfoReq{
|
|
|
+ PositionId: positionId,
|
|
|
+ AppId: "10000",
|
|
|
+ })
|
|
|
+ config.Middleground.PowerCheckCenter.DelCheckRedis("10000", qutil.Int64All(positionId))
|
|
|
+ if !ok {
|
|
|
+ log.Println("清除 redis 大会员服务详情 缓存失败:", _id)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ m = make(map[string]interface{})
|
|
|
+ }
|
|
|
+ log.Println("定时任务,更新大会员状态结束-定时开启会员状态")
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
//大会员更新用户服务表
|
|
|
func updateBigMemberService(userId string, now_unix int64) {
|
|
|
- now_time := FormatDateByInt64(&now_unix, Date_Full_Layout)
|
|
|
- userServiceList := util.Mysql.SelectBySql(`select * from `+jy.BigmemberUserPowerTable+` where s_userid=? AND i_status = 1 AND l_starttime < ? AND l_endtime > ?`, userId, now_time, now_time)
|
|
|
- if len(*userServiceList) > 0 {
|
|
|
- for _, v := range *userServiceList {
|
|
|
- var serviceid = v["s_serviceid"]
|
|
|
- if util.Mysql.UpdateOrDeleteBySql(`UPDATE `+jy.BigmemberUserPowerTable+` a SET a.i_status = 0 , a.l_updatetime=? WHERE a.s_userid = ? AND a.s_serviceid = ? `, now_time, userId, serviceid) < 0 {
|
|
|
- log.Println(userId, "开启大会员用户服务表出错")
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ now_time := FormatDateByInt64(&now_unix, Date_Full_Layout)
|
|
|
+ userServiceList := util.Mysql.SelectBySql(`select * from `+jy.BigmemberUserPowerTable+` where s_userid=? AND i_status = 1 AND l_starttime < ? AND l_endtime > ?`, userId, now_time, now_time)
|
|
|
+ if len(*userServiceList) > 0 {
|
|
|
+ for _, v := range *userServiceList {
|
|
|
+ var serviceid = v["s_serviceid"]
|
|
|
+ if util.Mysql.UpdateOrDeleteBySql(`UPDATE `+jy.BigmemberUserPowerTable+` a SET a.i_status = 0 , a.l_updatetime=? WHERE a.s_userid = ? AND a.s_serviceid = ? `, now_time, userId, serviceid) < 0 {
|
|
|
+ log.Println(userId, "开启大会员用户服务表出错")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//大会员用户服务表 用户服务是否需要开启或关闭
|
|
|
func checkMemberServiceIsExpire() {
|
|
|
- crontab(false, TimeTaskConfig.MemberServiceIsExpire, func() {
|
|
|
- defer qutil.Catch()
|
|
|
- log.Println("定时任务,更新大会员服务表状态开始")
|
|
|
- now_unix := time.Now().Unix()
|
|
|
- now_time := FormatDateByInt64(&now_unix, Date_Full_Layout)
|
|
|
- //待使用服务更新状态 wait & 服务到期更新状态 overdue
|
|
|
- wooList := util.Mysql.SelectBySql(`SELECT * FROM `+jy.BigmemberUserPowerTable+` a WHERE (a.i_status = 1 AND a.l_starttime < ? AND a.l_endtime > ?) OR (a.i_status = 0 AND a.l_endtime < ?)`, now_time, now_time, now_time)
|
|
|
- if len(*wooList) > 0 {
|
|
|
- // log.Println(len(*wooList), "-----:", wooList)
|
|
|
- var useridMap = map[string]bool{}
|
|
|
- for _, v := range *wooList {
|
|
|
- var starttime int64 = -1
|
|
|
- var endtime int64 = -1
|
|
|
- var serviceid = v["s_serviceid"]
|
|
|
- var userid = v["s_userid"]
|
|
|
- if !useridMap[userid.(string)] {
|
|
|
- useridMap[userid.(string)] = true
|
|
|
- }
|
|
|
- if thisTime, err := time.ParseInLocation(Date_Full_Layout, v["l_starttime"].(string), time.Local); err == nil {
|
|
|
- starttime = thisTime.Unix()
|
|
|
- }
|
|
|
- if thisTime, err := time.ParseInLocation(Date_Full_Layout, v["l_endtime"].(string), time.Local); err == nil {
|
|
|
- endtime = thisTime.Unix()
|
|
|
- }
|
|
|
- if starttime < now_unix && endtime > now_unix {
|
|
|
- if util.Mysql.UpdateOrDeleteBySql(`UPDATE `+jy.BigmemberUserPowerTable+` a SET a.i_status = 0, a.l_updatetime=? WHERE a.s_userid = ? AND a.s_serviceid = ? `, now_time, userid, serviceid) < 0 {
|
|
|
- log.Println(userid, "开启大会员用户服务表出错")
|
|
|
- }
|
|
|
- } else if endtime < now_unix {
|
|
|
- if util.Mysql.UpdateOrDeleteBySql(`UPDATE `+jy.BigmemberUserPowerTable+` a SET a.i_frequency = 0 , a.i_status = -1, a.l_updatetime=? WHERE a.s_userid = ? AND a.s_serviceid = ?`, now_time, userid, serviceid) < 0 {
|
|
|
- log.Println(userid, "关闭大会员用户服务表出错")
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- // log.Println("useridMap:", useridMap)
|
|
|
- if useridMap != nil && len(useridMap) > 0 {
|
|
|
- for k, _ := range useridMap {
|
|
|
- positionId := util.MongoIdToPositionId(k)
|
|
|
- ok := jy.ClearBigVipUserPower(positionId)
|
|
|
- config.Middleground.UserCenter.WorkDesktopClearUserInfo(pb.WorkDesktopClearUserInfoReq{
|
|
|
- PositionId: positionId,
|
|
|
- AppId: "10000",
|
|
|
- })
|
|
|
- config.Middleground.PowerCheckCenter.DelCheckRedis("10000", qutil.Int64All(positionId))
|
|
|
- if !ok {
|
|
|
- log.Println("清除 redis 大会员服务详情 缓存失败:", k)
|
|
|
- }
|
|
|
+ crontab(false, TimeTaskConfig.MemberServiceIsExpire, func() {
|
|
|
+ defer qutil.Catch()
|
|
|
+ log.Println("定时任务,更新大会员服务表状态开始")
|
|
|
+ now_unix := time.Now().Unix()
|
|
|
+ now_time := FormatDateByInt64(&now_unix, Date_Full_Layout)
|
|
|
+ //待使用服务更新状态 wait & 服务到期更新状态 overdue
|
|
|
+ wooList := util.Mysql.SelectBySql(`SELECT * FROM `+jy.BigmemberUserPowerTable+` a WHERE (a.i_status = 1 AND a.l_starttime < ? AND a.l_endtime > ?) OR (a.i_status = 0 AND a.l_endtime < ?)`, now_time, now_time, now_time)
|
|
|
+ if len(*wooList) > 0 {
|
|
|
+ // log.Println(len(*wooList), "-----:", wooList)
|
|
|
+ var useridMap = map[string]bool{}
|
|
|
+ for _, v := range *wooList {
|
|
|
+ var starttime int64 = -1
|
|
|
+ var endtime int64 = -1
|
|
|
+ var serviceid = v["s_serviceid"]
|
|
|
+ var userid = v["s_userid"]
|
|
|
+ if !useridMap[userid.(string)] {
|
|
|
+ useridMap[userid.(string)] = true
|
|
|
+ }
|
|
|
+ if thisTime, err := time.ParseInLocation(Date_Full_Layout, v["l_starttime"].(string), time.Local); err == nil {
|
|
|
+ starttime = thisTime.Unix()
|
|
|
+ }
|
|
|
+ if thisTime, err := time.ParseInLocation(Date_Full_Layout, v["l_endtime"].(string), time.Local); err == nil {
|
|
|
+ endtime = thisTime.Unix()
|
|
|
+ }
|
|
|
+ if starttime < now_unix && endtime > now_unix {
|
|
|
+ if util.Mysql.UpdateOrDeleteBySql(`UPDATE `+jy.BigmemberUserPowerTable+` a SET a.i_status = 0, a.l_updatetime=? WHERE a.s_userid = ? AND a.s_serviceid = ? `, now_time, userid, serviceid) < 0 {
|
|
|
+ log.Println(userid, "开启大会员用户服务表出错")
|
|
|
+ }
|
|
|
+ } else if endtime < now_unix {
|
|
|
+ if util.Mysql.UpdateOrDeleteBySql(`UPDATE `+jy.BigmemberUserPowerTable+` a SET a.i_frequency = 0 , a.i_status = -1, a.l_updatetime=? WHERE a.s_userid = ? AND a.s_serviceid = ?`, now_time, userid, serviceid) < 0 {
|
|
|
+ log.Println(userid, "关闭大会员用户服务表出错")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // log.Println("useridMap:", useridMap)
|
|
|
+ if useridMap != nil && len(useridMap) > 0 {
|
|
|
+ for k, _ := range useridMap {
|
|
|
+ positionId := util.MongoIdToPositionId(k)
|
|
|
+ ok := jy.ClearBigVipUserPower(positionId)
|
|
|
+ config.Middleground.UserCenter.WorkDesktopClearUserInfo(pb.WorkDesktopClearUserInfoReq{
|
|
|
+ PositionId: positionId,
|
|
|
+ AppId: "10000",
|
|
|
+ })
|
|
|
+ config.Middleground.PowerCheckCenter.DelCheckRedis("10000", qutil.Int64All(positionId))
|
|
|
+ if !ok {
|
|
|
+ log.Println("清除 redis 大会员服务详情 缓存失败:", k)
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- log.Println("定时任务,更新大会员服务表状态结束")
|
|
|
- })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.Println("定时任务,更新大会员服务表状态结束")
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
func updateTimeLimitActitityOrderStatus() { //修改限时活动的订单状态
|
|
|
- crontabByTicker(true, TimeTaskConfig.UpdateTimeLimitActivityOrderStatus, func() {
|
|
|
- defer qutil.Catch()
|
|
|
- log.Println("定时任务,更新限时活动订单状态开始")
|
|
|
- now := time.Now().Add(-time.Duration(config.Config.ActivityOrderCountdown) * time.Minute)
|
|
|
- //获取倒计时时间
|
|
|
- starttime := now.Format(Date_Full_Layout)
|
|
|
- limitTime := 20 //默认二十秒
|
|
|
- if strings.Contains(TimeTaskConfig.UpdateTimeLimitActivityOrderStatus, "s") {
|
|
|
- cStr := strings.Split(TimeTaskConfig.UpdateTimeLimitActivityOrderStatus, "s")[0]
|
|
|
- limitTime, _ = strconv.Atoi(cStr)
|
|
|
- }
|
|
|
- endtime := now.Add(-time.Duration(limitTime) * time.Second).Format(Date_Full_Layout)
|
|
|
- data := util.Mysql.SelectBySql(`select * from dataexport_order where order_status =0 and expiration_time>=? and expiration_time<? and is_backstage_order = 0`, starttime, endtime)
|
|
|
- log.Println(fmt.Sprintf(`select * from dataexport_order where order_status =0 and expiration_time<%s and expiration_time>=%s`, starttime, endtime))
|
|
|
- if data != nil && len(*data) > 0 {
|
|
|
- for _, v := range *data {
|
|
|
- //订单编号
|
|
|
- order_code, _ := v["order_code"].(string)
|
|
|
- productType := 0 //取消卡券的时候 需要这个参数 商品类型0普通的1线上课程
|
|
|
- if product_type, _ := v["product_type"].(string); product_type != "中标必听课" {
|
|
|
- productType = 1
|
|
|
- }
|
|
|
- flag := false
|
|
|
- if qutil.IntAll(v["order_status"]) == 0 && qutil.IntAll(v["is_backstage_order"]) == 0 && qutil.ObjToString(v["pay_way"]) != "transferAccounts" { //未支付状态下 删除订单需要先关闭订单
|
|
|
- flag = pay.CloseDataExportOrder(qutil.ObjToString(v["pay_way"]), qutil.ObjToString(v["out_trade_no"]), qutil.ObjToString(v["prepay_time"]))
|
|
|
- }
|
|
|
- if flag || (!(qutil.IntAll(v["course_status"]) == 2 || qutil.IntAll(v["course_status"]) == 4)) && qutil.ObjToString(v["pay_way"]) == "transferAccounts" && qutil.IntAll(v["is_backstage_order"]) == 0 { //对公转账非审核中 和 转账成功 状态下超时取消订单
|
|
|
- queryMap := map[string]interface{}{
|
|
|
- "order_code": order_code,
|
|
|
- }
|
|
|
- flag = util.Mysql.Update("dataexport_order", queryMap, map[string]interface{}{"order_status": -2})
|
|
|
- }
|
|
|
+ crontabByTicker(true, TimeTaskConfig.UpdateTimeLimitActivityOrderStatus, func() {
|
|
|
+ defer qutil.Catch()
|
|
|
+ log.Println("定时任务,更新限时活动订单状态开始")
|
|
|
+ now := time.Now().Add(-time.Duration(config.Config.ActivityOrderCountdown) * time.Minute)
|
|
|
+ //获取倒计时时间
|
|
|
+ starttime := now.Format(Date_Full_Layout)
|
|
|
+ limitTime := 20 //默认二十秒
|
|
|
+ if strings.Contains(TimeTaskConfig.UpdateTimeLimitActivityOrderStatus, "s") {
|
|
|
+ cStr := strings.Split(TimeTaskConfig.UpdateTimeLimitActivityOrderStatus, "s")[0]
|
|
|
+ limitTime, _ = strconv.Atoi(cStr)
|
|
|
+ }
|
|
|
+ endtime := now.Add(-time.Duration(limitTime) * time.Second).Format(Date_Full_Layout)
|
|
|
+ data := util.Mysql.SelectBySql(`select * from dataexport_order where order_status =0 and expiration_time>=? and expiration_time<? and is_backstage_order = 0`, starttime, endtime)
|
|
|
+ log.Println(fmt.Sprintf(`select * from dataexport_order where order_status =0 and expiration_time<%s and expiration_time>=%s`, starttime, endtime))
|
|
|
+ if data != nil && len(*data) > 0 {
|
|
|
+ for _, v := range *data {
|
|
|
+ //订单编号
|
|
|
+ order_code, _ := v["order_code"].(string)
|
|
|
+ productType := 0 //取消卡券的时候 需要这个参数 商品类型0普通的1线上课程
|
|
|
+ if product_type, _ := v["product_type"].(string); product_type != "中标必听课" {
|
|
|
+ productType = 1
|
|
|
+ }
|
|
|
+ flag := false
|
|
|
+ if qutil.IntAll(v["order_status"]) == 0 && qutil.IntAll(v["is_backstage_order"]) == 0 && qutil.ObjToString(v["pay_way"]) != "transferAccounts" { //未支付状态下 删除订单需要先关闭订单
|
|
|
+ flag = pay.CloseDataExportOrder(qutil.ObjToString(v["pay_way"]), qutil.ObjToString(v["out_trade_no"]), qutil.ObjToString(v["prepay_time"]))
|
|
|
+ }
|
|
|
+ if flag || (!(qutil.IntAll(v["course_status"]) == 2 || qutil.IntAll(v["course_status"]) == 4)) && qutil.ObjToString(v["pay_way"]) == "transferAccounts" && qutil.IntAll(v["is_backstage_order"]) == 0 { //对公转账非审核中 和 转账成功 状态下超时取消订单
|
|
|
+ queryMap := map[string]interface{}{
|
|
|
+ "order_code": order_code,
|
|
|
+ }
|
|
|
+ flag = util.Mysql.Update("dataexport_order", queryMap, map[string]interface{}{"order_status": -2})
|
|
|
+ }
|
|
|
|
|
|
- if !flag {
|
|
|
- log.Println("mysql 订单更新失败", order_code)
|
|
|
- } else {
|
|
|
- //解除卡卷绑定
|
|
|
- //用户领取卡卷的记录id
|
|
|
- userLotteryId, _ := v["d_relation_id"].(string)
|
|
|
- if userLotteryId != "" {
|
|
|
- //用户id
|
|
|
- userId, _ := v["user_id"].(string)
|
|
|
- go func(userId, userLotteryId, order_code string) {
|
|
|
- if !util.UpdateCouponState(userId, userLotteryId, "", "", order_code, qutil.ObjToString(v["product_type"]), "0", 0, productType) {
|
|
|
- log.Println(fmt.Sprintf("单号%s-解绑失败-卡卷%s", order_code, userLotteryId))
|
|
|
- }
|
|
|
- }(userId, userLotteryId, order_code)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- log.Println("定时任务,更新限时活动订单结束")
|
|
|
- })
|
|
|
+ if !flag {
|
|
|
+ log.Println("mysql 订单更新失败", order_code)
|
|
|
+ } else {
|
|
|
+ //解除卡卷绑定
|
|
|
+ //用户领取卡卷的记录id
|
|
|
+ userLotteryId, _ := v["d_relation_id"].(string)
|
|
|
+ if userLotteryId != "" {
|
|
|
+ //用户id
|
|
|
+ userId, _ := v["user_id"].(string)
|
|
|
+ go func(userId, userLotteryId, order_code string) {
|
|
|
+ if !util.UpdateCouponState(userId, userLotteryId, "", "", order_code, qutil.ObjToString(v["product_type"]), "0", 0, productType) {
|
|
|
+ log.Println(fmt.Sprintf("单号%s-解绑失败-卡卷%s", order_code, userLotteryId))
|
|
|
+ }
|
|
|
+ }(userId, userLotteryId, order_code)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.Println("定时任务,更新限时活动订单结束")
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
//
|
|
|
func crontab(flag bool, c string, f func()) {
|
|
|
- array := strings.Split(c, ":")
|
|
|
- if len(array) != 2 {
|
|
|
- log.Fatalln("定时任务参数错误!", c)
|
|
|
- }
|
|
|
- if flag {
|
|
|
- go f()
|
|
|
- }
|
|
|
- now := time.Now()
|
|
|
- t := time.Date(now.Year(), now.Month(), now.Day(), qutil.IntAll(array[0]), qutil.IntAll(array[1]), 0, 0, time.Local)
|
|
|
- if t.Before(now) {
|
|
|
- t = t.AddDate(0, 0, 1)
|
|
|
- }
|
|
|
- timer := time.NewTimer(t.Sub(now))
|
|
|
- for {
|
|
|
- select {
|
|
|
- case <-timer.C:
|
|
|
- go f()
|
|
|
- timer.Reset(24 * time.Hour)
|
|
|
- }
|
|
|
- }
|
|
|
+ array := strings.Split(c, ":")
|
|
|
+ if len(array) != 2 {
|
|
|
+ log.Fatalln("定时任务参数错误!", c)
|
|
|
+ }
|
|
|
+ if flag {
|
|
|
+ go f()
|
|
|
+ }
|
|
|
+ now := time.Now()
|
|
|
+ t := time.Date(now.Year(), now.Month(), now.Day(), qutil.IntAll(array[0]), qutil.IntAll(array[1]), 0, 0, time.Local)
|
|
|
+ if t.Before(now) {
|
|
|
+ t = t.AddDate(0, 0, 1)
|
|
|
+ }
|
|
|
+ timer := time.NewTimer(t.Sub(now))
|
|
|
+ for {
|
|
|
+ select {
|
|
|
+ case <-timer.C:
|
|
|
+ go f()
|
|
|
+ timer.Reset(24 * time.Hour)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//
|
|
|
func crontabByTicker(flag bool, c string, f func()) {
|
|
|
- if c == "0" {
|
|
|
- log.Println("定时任务参数有误:", c)
|
|
|
- return
|
|
|
- }
|
|
|
- countdown := 5 * 60
|
|
|
- if strings.Contains(c, "h") {
|
|
|
- cStr := strings.Split(c, "h")[0]
|
|
|
- countdown, _ = strconv.Atoi(cStr)
|
|
|
- countdown = countdown * 60 * 60
|
|
|
- } else if strings.Contains(c, "s") {
|
|
|
- cStr := strings.Split(c, "s")[0]
|
|
|
- countdown, _ = strconv.Atoi(cStr)
|
|
|
- countdown = countdown
|
|
|
- } else {
|
|
|
- countdown, _ = strconv.Atoi(c)
|
|
|
- countdown = countdown * 60
|
|
|
- }
|
|
|
- if flag {
|
|
|
- go f()
|
|
|
- }
|
|
|
- ticker := time.NewTicker(time.Duration(countdown) * time.Second)
|
|
|
- go func(t *time.Ticker) {
|
|
|
- for {
|
|
|
- select {
|
|
|
- case <-t.C:
|
|
|
- go f()
|
|
|
- fmt.Println("get ticker", time.Now().Format("2006-01-02 15:04:05"))
|
|
|
- }
|
|
|
- }
|
|
|
- }(ticker)
|
|
|
+ if c == "0" {
|
|
|
+ log.Println("定时任务参数有误:", c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ countdown := 5 * 60
|
|
|
+ if strings.Contains(c, "h") {
|
|
|
+ cStr := strings.Split(c, "h")[0]
|
|
|
+ countdown, _ = strconv.Atoi(cStr)
|
|
|
+ countdown = countdown * 60 * 60
|
|
|
+ } else if strings.Contains(c, "s") {
|
|
|
+ cStr := strings.Split(c, "s")[0]
|
|
|
+ countdown, _ = strconv.Atoi(cStr)
|
|
|
+ countdown = countdown
|
|
|
+ } else {
|
|
|
+ countdown, _ = strconv.Atoi(c)
|
|
|
+ countdown = countdown * 60
|
|
|
+ }
|
|
|
+ if flag {
|
|
|
+ go f()
|
|
|
+ }
|
|
|
+ ticker := time.NewTicker(time.Duration(countdown) * time.Second)
|
|
|
+ go func(t *time.Ticker) {
|
|
|
+ for {
|
|
|
+ select {
|
|
|
+ case <-t.C:
|
|
|
+ go f()
|
|
|
+ fmt.Println("get ticker", time.Now().Format("2006-01-02 15:04:05"))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }(ticker)
|
|
|
}
|