Explorar o código

Merge branch 'develop' of 192.168.3.17:zhanghongbo/qfw into develop

zhangjinkun@topnet.net.cn %!s(int64=9) %!d(string=hai) anos
pai
achega
b508e4bc1e

+ 3 - 1
credit/src/config.json

@@ -69,5 +69,7 @@
         "pwd": "qy123456",
         "fromuser": "企明星",
 		"touser":"renzheng@topnet.net.cn,zhanghongbo@topnet.net.cn"
-    }
+    },
+	"saveLogDuration":1,
+	"checkGiveDuration":30
 }

+ 50 - 2
credit/src/main.go

@@ -59,14 +59,62 @@ func quartz() {
 	go func() {
 		for {
 			select {
-			case <-timingwheel.TW.After(5 * time.Second):
+			case <-timingwheel.TW.After(time.Duration(util.IntAllDef(SysConfig["saveLogDuration"], 5)) * time.Minute):
 				creditlog.SaveLog()
 			}
 		}
 	}()
 
-	//每天晚上12点左右清除redis缓存
+	//每天晚上12点左右清除redis缓存,已经不用
 
 	//每天一次检查剑鱼积分
+	//有一张增值服务表,记录服务代码、服务起始日期、服务截止日期、服务类型按月、服务数量、是否自动扣费(扣费走rpc调用)、记录是否过期
 
+	TimerSwordFish()
+
+	//定时任务转赠积分24后无人接收即退回,本月不做了
+	/**
+	go func() {
+		for {
+			select {
+			case <-timingwheel.TW.After(time.Duration(util.IntAllDef(SysConfig["checkGiveDuration"], 30)) * time.Second):
+				util.Try(func() {
+					session := mongodb.GetMgoConn()
+					defer mongodb.DestoryMongoConn(session)
+					query := session.DB("qfw").C(creditlog.TB).Find(&map[string]interface{}{
+						"s_code": "B1",
+						"l_date": map[string]interface{}{
+							"$lt": time.Now().Unix() - 24*3600,
+						},
+						"i_givestatus": 0,
+					}).Iter()
+					for tmp := new(map[string]interface{}); query.Next(tmp); {
+						//进行退回操作---待续
+
+						tmp = new(map[string]interface{})
+					}
+				}, func(e interface{}) {
+					log.Println("定时任务转赠无人接收收回报错", e)
+				})
+			}
+		}
+	}()
+	**/
+}
+
+func TimerSwordFish() {
+	go func() {
+		for {
+			now := time.Now()
+			// 计算下一个零点
+			next := now.Add(24 * time.Hour)
+			next = time.Date(next.Year(), next.Month(), next.Day(), 0, 0, 0, 0, next.Location())
+			t := time.NewTimer(next.Sub(now))
+			<-t.C
+			/*执行逻辑*/
+
+			TimerSwordFish()
+			break
+		}
+	}()
 }

+ 34 - 2
credit/src/qfw/creditrpc/creditrpc.go

@@ -54,7 +54,7 @@ func (c *CreditRpc) InCreadit(param *rpc.CreditData, replay *int) error {
 			}
 		case "b":
 			key := param.Code + "_" + param.Uid
-			//[0/1,time] //是否完成,次数
+			//[0/1,time,alltimes] //是否完成,次数,总次数
 			lock := GetMutex(param.Uid)
 			lock.Lock()
 			obj := redis.Get(consts.RedisDB, key)
@@ -94,11 +94,43 @@ func (c *CreditRpc) InCreadit(param *rpc.CreditData, replay *int) error {
 	return nil
 }
 
-//消费积分
+//消费积分,增加扣费方式、手动还是自动
 func (c *CreditRpc) OutCreadit(param *rpc.CreditData, replay *int) error {
+	*replay = 0
+	lock := GetMutex(param.Uid)
+	lock.Lock()
+	if len(param.Code) > 1 && Message[("txt_"+param.Code)] != "" {
+		first := param.Code[:1]
+		creditDoc := map[string]interface{}{
+			"s_uid":   param.Uid,
+			"s_code":  param.Code,
+			"i_type":  0,
+			"l_date":  time.Now().Unix(),
+			"i_score": param.Num,
+		}
+		if param.OtherParam != nil && param.OtherParam["i_way"] != nil {
+			creditDoc["i_way"] = param.OtherParam["i_way"]
+		}
+		switch first {
+		case "B":
+			creditDoc["i_givestatus"] = 0
+		}
+		if creditlog.Save(creditDoc) {
+			*replay = 1
+			//发送微信通知扣积分成功
+			go SendWeixin(param.Num, param.Uid, "")
+		}
+	}
+	lock.Unlock()
 	return nil
 }
 
+//发送微信积分变动通知
+func SendWeixin(num int, uid, info string) {
+
+}
+
+//获取离明天的秒差
 func GetSubSecond() int {
 	now := time.Now()
 	tom := time.Date(now.Year(), now.Month(), now.Day()+1, 0, 0, 0, 0, time.Local)

+ 2 - 1
credit/src/qfw/timewheel/timingwheel.go

@@ -5,7 +5,8 @@ import (
 	"time"
 )
 
-var TW *TimingWheel = NewTimingWheel(1*time.Second, 600)
+var TW *TimingWheel = NewTimingWheel(1*time.Minute, 150)
+var TWD *TimingWheel = NewTimingWheel(24*time.Second, 1)
 
 type TimingWheel struct {
 	sync.Mutex