|
@@ -106,7 +106,7 @@ func quartz() {
|
|
|
//每天一次检查剑鱼积分
|
|
|
//有一张增值服务表,记录服务代码、服务起始日期、服务截止日期、服务类型按月、服务数量、是否自动扣费(扣费走rpc调用)、记录是否过期
|
|
|
|
|
|
- TimerSwordFish()
|
|
|
+ TimerSwordFishFromUser()
|
|
|
|
|
|
//定时任务转赠积分24后无人接收即退回,本月不做了
|
|
|
/**
|
|
@@ -138,7 +138,115 @@ func quartz() {
|
|
|
**/
|
|
|
}
|
|
|
|
|
|
+//剑鱼定时扣分逻辑
|
|
|
+/**
|
|
|
+** 根据user表来处理
|
|
|
+**/
|
|
|
+func TimerSwordFishFromUser() {
|
|
|
+ go func() {
|
|
|
+ for {
|
|
|
+ now := time.Now()
|
|
|
+ // 计算下一个零点
|
|
|
+ //next := now.Add(24 * time.Hour)
|
|
|
+ //next = time.Date(next.Year(), next.Month(), next.Day(), swordfish_subHour, 0, 0, 0, next.Location())
|
|
|
+ next := now.Add(30 * time.Second)
|
|
|
+ //next = time.Date(next.Year(), next.Month(), next.Day(), swordfish_subHour, 0, 0, 0, next.Location())
|
|
|
+ next64 := next.Unix()
|
|
|
+ t := time.NewTimer(next.Sub(now))
|
|
|
+ <-t.C
|
|
|
+ /*执行逻辑*/
|
|
|
+ log.Println("执行定时任务...")
|
|
|
+ util.Try(func() {
|
|
|
+ session := mongodb.GetMgoConn()
|
|
|
+ defer mongodb.DestoryMongoConn(session)
|
|
|
+ coll := session.DB("qfw").C("user")
|
|
|
+ for code, typeName := range map[string]string{
|
|
|
+ "A1": "tender",
|
|
|
+ "A2": "bid",
|
|
|
+ } {
|
|
|
+ query := coll.Find(&map[string]interface{}{
|
|
|
+ "o_msgset." + typeName + ".l_enddate": map[string]interface{}{
|
|
|
+ "$gte": next64 - 600,
|
|
|
+ "$lte": next64 + int64(swordfish_tipBeforeDays[0]*60),
|
|
|
+ },
|
|
|
+ "o_msgset." + typeName + ".i_status": 1,
|
|
|
+ "o_msgset." + typeName + ".i_switchstatus": 1,
|
|
|
+ }).Iter()
|
|
|
+
|
|
|
+ for tmp := make(map[string]interface{}); query.Next(tmp); {
|
|
|
+ log.Println(tmp)
|
|
|
+ util.Try(func() {
|
|
|
+ tmpCode := tmp["o_msgset"].(map[string]interface{})[typeName].(map[string]interface{})
|
|
|
+ endDate := tmpCode["l_enddate"].(int64)
|
|
|
+ sub64 := (endDate - next64) / (60)
|
|
|
+ if sub64 == 0 {
|
|
|
+ //自动扣费
|
|
|
+ doSubCreditByUser(util.BsonIdToSId(tmp["_id"]), tmp["s_m_openid"].(string), typeName, code, &next, tmp)
|
|
|
+ } else {
|
|
|
+ //提示
|
|
|
+ for _, v := range swordfish_tipBeforeDays {
|
|
|
+ if int64(v) == sub64 {
|
|
|
+ creditrpc.SendMsgWebAndWx(swordfish_dueTitle, fmt.Sprintf(swordfish_due, v), util.BsonIdToSId(tmp["_id"]), tmp["s_m_openid"].(string))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, func(e interface{}) {})
|
|
|
+ tmp = make(map[string]interface{})
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, func(e interface{}) {
|
|
|
+ log.Println("定时任务,扣剑鱼积分时报错", e)
|
|
|
+ })
|
|
|
+ TimerSwordFishFromUser()
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }()
|
|
|
+}
|
|
|
+
|
|
|
+//自动扣费
|
|
|
+func doSubCreditByUser(userId, umid, typeName, code string, next *time.Time, user map[string]interface{}) {
|
|
|
+ //是否生效和是否启用
|
|
|
+ util.Try(func() {
|
|
|
+ i_credit := util.IntAllDef(user["i_credit"], 0)
|
|
|
+ bsub := false
|
|
|
+ codeNum := creditrpc.Score[code]
|
|
|
+ restNum := i_credit + codeNum
|
|
|
+ if i_credit > 0 && restNum > -1 {
|
|
|
+ bsub = true
|
|
|
+ }
|
|
|
+ if bsub { //扣分操作
|
|
|
+ newDate := next.AddDate(0, 1, 0)
|
|
|
+ creditDoc := map[string]interface{}{
|
|
|
+ "s_uid": userId,
|
|
|
+ "s_umid": umid,
|
|
|
+ "s_code": code,
|
|
|
+ "i_type": 0, //是扣
|
|
|
+ "l_date": next.Unix(),
|
|
|
+ "l_enddate": newDate.Unix(),
|
|
|
+ "i_score": codeNum,
|
|
|
+ "s_type": typeName,
|
|
|
+ }
|
|
|
+ if creditlog.Save(creditDoc) {
|
|
|
+ //发送微信通知扣积分成功
|
|
|
+ creditrpc.SendMsgWebAndWx(swordfish_payTitle, fmt.Sprintf(swordfish_pay, -codeNum, restNum, util.FormatDate(&newDate, util.Date_Full_Layout)), userId, umid)
|
|
|
+ }
|
|
|
+ } else { //暂停操作
|
|
|
+ //更新操作
|
|
|
+ if mongodb.Update("user", `{"_id":"`+userId+`"}`, `{"$set":{"o_msgset.`+typeName+`.i_status":0}}`, false, false) {
|
|
|
+ //暂停通知,因积分不够
|
|
|
+ creditrpc.SendMsgWebAndWx(swordfish_closeTitle, swordfish_close, userId, umid)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, func(e interface{}) {
|
|
|
+ log.Println("查询用户剑鱼状态出错,", e)
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
//剑鱼定时扣分逻辑,提前三天提示积分不够、扣积分发通知,下午18点执行
|
|
|
+/**
|
|
|
+** 根据creditlog表来处理
|
|
|
+**/
|
|
|
+/**
|
|
|
func TimerSwordFish() {
|
|
|
go func() {
|
|
|
for {
|
|
@@ -149,7 +257,7 @@ func TimerSwordFish() {
|
|
|
next64 := next.Unix()
|
|
|
t := time.NewTimer(next.Sub(now))
|
|
|
<-t.C
|
|
|
- /*执行逻辑*/
|
|
|
+ //执行逻辑
|
|
|
util.Try(func() {
|
|
|
session := mongodb.GetMgoConn()
|
|
|
defer mongodb.DestoryMongoConn(session)
|
|
@@ -249,3 +357,5 @@ func doSubCredit(userId, umid, typeName, code string, next *time.Time) {
|
|
|
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+**/
|