Forráskód Böngészése

修改剑鱼定时

renzheng 9 éve
szülő
commit
006acec879

+ 2 - 1
common/src/qfw/util/encrypt_test.go

@@ -12,7 +12,8 @@ import (
 func TestEncrypt(t *testing.T) {
 	se := &SimpleEncrypt{Key: "topnet"}
 
-	log.Println(se.EncodeString("obEpLuH03fTYZ2e0xhJL3k7H6q48,ff,ff,swordfishaction"))
+	log.Println(se.EncodeString("oJULtwzXo6EFV1Ah-XeyRBimXGM8,ff,ff,swordfishaction"))
+	log.Println(se.DecodeString("GyUlIhEDDjcfWCAyIl4xBkgsERYiLAwZLCg9VkkSEkMWCEkHAwACCgMdBwcRDREdGwE="))
 }
 
 func Test_sim(t *testing.T) {

+ 1 - 1
core/src/timetask.json

@@ -1 +1 @@
-{"comment":{"c_rate":720,"commentrate":900},"market":{"demand":{"attr":["i_hits","i_bids","i_status"],"timepoint":"2016-01-21 14:42:23"},"service":{"attr":["i_hits","i_sales","i_comments","i_score","i_appcounts"],"timepoint":"2016-01-21 14:42:23"}},"marketisstart":true,"marketrate":300}
+{"comment":{"c_rate":720,"commentrate":900},"market":{"demand":{"attr":["i_hits","i_bids","i_status"],"timepoint":"2016-01-21 17:20:57"},"service":{"attr":["i_hits","i_sales","i_comments","i_score","i_appcounts"],"timepoint":"2016-01-21 17:20:57"}},"marketisstart":true,"marketrate":300}

+ 2 - 1
credit/src/config.json

@@ -94,5 +94,6 @@
     "saveLogDuration": 1,
     "checkGiveDuration": 30,
     "swordfish_tipBeforeDays": "3,1",
-    "swordfish_subHour": 18
+    "swordfish_subHour": 16,
+	"timerHM":"24,s,21"
 }

+ 22 - 7
credit/src/main.go

@@ -27,6 +27,8 @@ var SysConfig map[string]interface{}
 var swordfish_subHour int
 var swordfish_tipBeforeDays []int
 var swordfish_dueTitle, swordfish_due, swordfish_closeTitle, swordfish_close, swordfish_payTitle, swordfish_pay string
+var duration_hour time.Duration = 24 * time.Hour
+var minutes = 0
 
 func init() {
 	util.ReadConfig(&SysConfig)
@@ -64,6 +66,21 @@ func init() {
 
 	creditlog.Smtp = SysConfig["smtp"].(map[string]interface{})
 
+	timerHM := util.ObjToString(SysConfig["timerHM"])
+	if timerHM != "" {
+		timerHMS := strings.Split(timerHM, ",")
+		tmp, _ := strconv.Atoi(timerHMS[0])
+		switch timerHMS[1] {
+		case "h":
+			duration_hour = time.Duration(tmp) * time.Hour
+		case "m":
+			duration_hour = time.Duration(tmp) * time.Minute
+		case "s":
+			duration_hour = time.Duration(tmp) * time.Second
+		}
+		minutes, _ = strconv.Atoi(timerHMS[2])
+	}
+
 }
 
 func main() {
@@ -106,7 +123,7 @@ func quartz() {
 	//每天一次检查剑鱼积分
 	//有一张增值服务表,记录服务代码、服务起始日期、服务截止日期、服务类型按月、服务数量、是否自动扣费(扣费走rpc调用)、记录是否过期
 
-	TimerSwordFishFromUser()
+	//TimerSwordFishFromUser()
 
 	//定时任务转赠积分24后无人接收即退回,本月不做了
 	/**
@@ -147,10 +164,8 @@ func TimerSwordFishFromUser() {
 		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())
+			next := now.Add(duration_hour)
+			next = time.Date(next.Year(), next.Month(), next.Day(), swordfish_subHour, minutes, 0, 0, next.Location())
 			next64 := next.Unix()
 			t := time.NewTimer(next.Sub(now))
 			<-t.C
@@ -167,7 +182,7 @@ func TimerSwordFishFromUser() {
 					query := coll.Find(&map[string]interface{}{
 						"o_msgset." + typeName + ".l_enddate": map[string]interface{}{
 							"$gte": next64 - 600,
-							"$lte": next64 + int64(swordfish_tipBeforeDays[0]*60),
+							"$lte": next64 + int64(swordfish_tipBeforeDays[0]*24*3600) + 7200,
 						},
 						"o_msgset." + typeName + ".i_status":       1,
 						"o_msgset." + typeName + ".i_switchstatus": 1,
@@ -178,7 +193,7 @@ func TimerSwordFishFromUser() {
 						util.Try(func() {
 							tmpCode := tmp["o_msgset"].(map[string]interface{})[typeName].(map[string]interface{})
 							endDate := tmpCode["l_enddate"].(int64)
-							sub64 := (endDate - next64) / (60)
+							sub64 := (endDate - next64) / 86400
 							if sub64 == 0 {
 								//自动扣费
 								doSubCreditByUser(util.BsonIdToSId(tmp["_id"]), tmp["s_m_openid"].(string), typeName, code, &next, tmp)

+ 1 - 1
credit/src/qfw/creditlog/creditlog.go

@@ -24,7 +24,7 @@ var Smtp map[string]interface{}
 //对map的同步
 var lock sync.Mutex
 
-func AddLog(logs map[string]interface{}) {
+func AddLog_BACK(logs map[string]interface{}) {
 	lock.Lock()
 	arr = append(arr, logs)
 	lock.Unlock()

+ 30 - 24
credit/src/qfw/creditrpc/creditrpc.go

@@ -60,6 +60,8 @@ func (c *CreditRpc) InCreadit(param *qrpc.CreditData, replay *int) error {
 			}
 		}
 	}()
+	lock := GetMutex(param.Uid)
+	lock.Lock()
 	//a类为即时保存
 	//b、c、d、e为定时保存
 	log.Println("---请求", param)
@@ -91,8 +93,6 @@ func (c *CreditRpc) InCreadit(param *qrpc.CreditData, replay *int) error {
 		case "b":
 			key := param.Code + "_" + param.Uid
 			//[0/1,time,alltimes] //是否完成,次数,总次数,
-			lock := GetMutex(param.Uid)
-			lock.Lock()
 			if param.Code == "b1" { //签到
 				now := time.Now()
 				daykey := key + "_" + fmt.Sprintf("%d", now.Day())
@@ -114,8 +114,9 @@ func (c *CreditRpc) InCreadit(param *qrpc.CreditData, replay *int) error {
 							creditDoc["i_scorenow"] = i_scorenow + Score[param.Code+"_1"] + int(thist)*Score[param.Code]
 							redis.Put(consts.RedisDB, key, newobj, GetSubSecond(int(newobj[2]-thist)))
 							redis.Put(consts.RedisDB, daykey, true, GetSubSecond(1))
-							creditlog.AddLog(creditDoc)
-							*replay = creditDoc["i_score"].(int)
+							if creditlog.Save(creditDoc) {
+								*replay = creditDoc["i_score"].(int)
+							}
 						} else {
 							//不是连续签到
 							bcon = false
@@ -133,8 +134,9 @@ func (c *CreditRpc) InCreadit(param *qrpc.CreditData, replay *int) error {
 						creditDoc["i_scorenow"] = i_scorenow + Score[param.Code+"_1"]
 						redis.Put(consts.RedisDB, key, newobj, GetSubSecond(int(newobj[2])))
 						redis.Put(consts.RedisDB, daykey, true, GetSubSecond(1))
-						creditlog.AddLog(creditDoc)
-						*replay = creditDoc["i_score"].(int)
+						if creditlog.Save(creditDoc) {
+							*replay = creditDoc["i_score"].(int)
+						}
 					}
 				}
 			} else {
@@ -149,8 +151,9 @@ func (c *CreditRpc) InCreadit(param *qrpc.CreditData, replay *int) error {
 						redis.Put(consts.RedisDB, key, newobj, GetSubSecond(1))
 						creditDoc["i_score"] = Score[param.Code]
 						creditDoc["i_scorenow"] = i_scorenow + Score[param.Code]
-						creditlog.AddLog(creditDoc)
-						*replay = creditDoc["i_score"].(int)
+						if creditlog.Save(creditDoc) {
+							*replay = creditDoc["i_score"].(int)
+						}
 					}
 				} else {
 					times := Score[param.Code+"_n"]
@@ -162,15 +165,12 @@ func (c *CreditRpc) InCreadit(param *qrpc.CreditData, replay *int) error {
 					creditDoc["i_score"] = Score[param.Code]
 					creditDoc["i_scorenow"] = i_scorenow + Score[param.Code]
 					redis.Put(consts.RedisDB, key, newobj, GetSubSecond(1))
-					creditlog.AddLog(creditDoc)
-					*replay = creditDoc["i_score"].(int)
+					if creditlog.Save(creditDoc) {
+						*replay = creditDoc["i_score"].(int)
+					}
 				}
 			}
-			lock.Unlock()
-			//
 		case "c":
-			lock := GetMutex(param.Uid)
-			lock.Lock()
 			if param.Code == "c1" { //交易
 				objid := param.OtherParam["objid"]
 				if objid != nil {
@@ -189,10 +189,12 @@ func (c *CreditRpc) InCreadit(param *qrpc.CreditData, replay *int) error {
 							"i_score":     Score[param.Code],
 							"i_scorenow":  i_scorenow + Score[param.Code],
 						}
-						creditlog.AddLog(creditDoc)
-						creditlog.AddLog(newDoc)
+						//creditlog.AddLog(creditDoc)
+						//creditlog.AddLog(newDoc)
 						redis.Put(consts.RedisDB, key, true, GetSubSecond(1))
-						*replay = creditDoc["i_score"].(int)
+						if creditlog.Save(creditDoc) && creditlog.Save(newDoc) {
+							*replay = creditDoc["i_score"].(int)
+						}
 					}
 				}
 			} else if param.Code == "c2" { //评价
@@ -203,29 +205,33 @@ func (c *CreditRpc) InCreadit(param *qrpc.CreditData, replay *int) error {
 						creditDoc["i_score"] = Score[param.Code]
 						creditDoc["i_scorenow"] = i_scorenow + Score[param.Code]
 						creditDoc["o_param"] = param.OtherParam
-						creditlog.AddLog(creditDoc)
+						if creditlog.Save(creditDoc) {
+							*replay = creditDoc["i_score"].(int)
+						}
 						redis.Put(consts.RedisDB, key, true, GetSubSecond(1))
-						*replay = creditDoc["i_score"].(int)
+
 					}
 				}
 			} else {
 				creditDoc["i_score"] = Score[param.Code]
 				creditDoc["i_scorenow"] = i_scorenow + Score[param.Code]
 				creditDoc["o_param"] = param.OtherParam
-				creditlog.AddLog(creditDoc)
-				*replay = creditDoc["i_score"].(int)
+				if creditlog.Save(creditDoc) {
+					*replay = creditDoc["i_score"].(int)
+				}
 			}
-			lock.Unlock()
 		default: //定时任务
 			sc := util.If(param.Num > 0, param.Num, Score[param.Code]).(int)
 			if sc > 0 {
 				creditDoc["i_score"] = sc
 				creditDoc["i_scorenow"] = i_scorenow + sc
-				creditlog.AddLog(creditDoc)
-				*replay = creditDoc["i_score"].(int)
+				if creditlog.Save(creditDoc) {
+					*replay = creditDoc["i_score"].(int)
+				}
 			}
 		}
 	}
+	lock.Unlock()
 	return nil
 }