Kaynağa Gözat

修改credit

renzheng 9 yıl önce
ebeveyn
işleme
c78f6ce509

+ 1 - 2
core/src/timetask.json

@@ -1,2 +1 @@
-{"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}
-
+{"comment":{"c_rate":720,"commentrate":900},"market":{"demand":{"attr":["i_hits","i_bids","i_status"],"timepoint":"2016-01-22 13:30:43"},"service":{"attr":["i_hits","i_sales","i_comments","i_score","i_appcounts"],"timepoint":"2016-01-22 13:30:43"}},"marketisstart":true,"marketrate":300}

+ 1 - 1
core/src/web/staticres/wxswordfish/main.js

@@ -69,7 +69,7 @@ KeyWordDialog.SetContentHeight = function(dialogObj){
 KeyWordDialog.AppendNode = function(dialogObj,value){
 	var getHtml = function(index,value){
 		return '<div class="keyWordGroup">'
-					+'<lable>关键词<font>'+index+'</font></lable>'
+					+'<lable style="white-space:nowrap;">关键词<font>'+index+'</font></lable>'
 					+'<div><input type="text" value="'+(value?value:"")+'" placeholder="示例:综合布线 电话线 网线" maxlength="100"></div>'
 					+'<div>'+(index==1?'':'<img src="/wxswordfish/images/delete.png" class="delete">')+'</div>'
 				+'</div>';

+ 1 - 1
credit/src/config.json

@@ -95,5 +95,5 @@
     "checkGiveDuration": 30,
     "swordfish_tipBeforeDays": "3,1",
     "swordfish_subHour": 16,
-	"timerHM":"24,s,21"
+	"timerHM":"40,s,21"
 }

+ 70 - 45
credit/src/main.go

@@ -79,10 +79,26 @@ func init() {
 			duration_hour = time.Duration(tmp) * time.Second
 		}
 		minutes, _ = strconv.Atoi(timerHMS[2])
+
+		http.HandleFunc("/m", saveHandlerFunc)
+		http.ListenAndServe(":8878", nil)
+
 	}
 
 }
 
+var TesB = make(chan bool, 1)
+
+func saveHandlerFunc(res http.ResponseWriter, req *http.Request) {
+	req.ParseForm()
+	form := req.Form
+	t := form.Get("t")
+	ts := strings.Split(t, ".")
+	swordfish_subHour, _ = strconv.Atoi(ts[0])
+	minutes, _ = strconv.Atoi(ts[1])
+	TesB <- true
+}
+
 func main() {
 	crpc := new(creditrpc.CreditRpc)
 	rpc.Register(crpc)
@@ -92,6 +108,7 @@ func main() {
 	go http.Serve(l, nil)
 	quartz()
 	log.Println("启动积分系统", port)
+
 	flag := make(chan bool)
 	<-flag
 }
@@ -123,7 +140,7 @@ func quartz() {
 	//每天一次检查剑鱼积分
 	//有一张增值服务表,记录服务代码、服务起始日期、服务截止日期、服务类型按月、服务数量、是否自动扣费(扣费走rpc调用)、记录是否过期
 
-	//TimerSwordFishFromUser()
+	TimerSwordFishFromUser()
 
 	//定时任务转赠积分24后无人接收即退回,本月不做了
 	/**
@@ -165,55 +182,63 @@ func TimerSwordFishFromUser() {
 			now := time.Now()
 			// 计算下一个零点
 			next := now.Add(duration_hour)
-			next = time.Date(next.Year(), next.Month(), next.Day(), swordfish_subHour, minutes, 0, 0, next.Location())
+			next = time.Date(next.Year(), next.Month(), next.Day(), swordfish_subHour, minutes, 10, 0, next.Location())
 			next64 := next.Unix()
+			if int64(next.Sub(now)) < 0 {
+				continue
+			}
 			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]*24*3600) + 7200,
-						},
-						"o_msgset." + typeName + ".i_status":       1,
-						"o_msgset." + typeName + ".i_switchstatus": 1,
-					}).Iter()
+			select {
+			case <-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]*24*3600) + 7200,
+							},
+							"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) / 86400
-							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))
+						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) / 86400
+								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{}) {})
+							tmp = make(map[string]interface{})
+						}
 					}
-				}
-			}, func(e interface{}) {
-				log.Println("定时任务,扣剑鱼积分时报错", e)
-			})
-			TimerSwordFishFromUser()
-			break
+				}, func(e interface{}) {
+					log.Println("定时任务,扣剑鱼积分时报错", e)
+				})
+				//TimerSwordFishFromUser()
+				break
+			case <-TesB:
+				//TimerSwordFishFromUser()
+				break
+			}
 		}
 	}()
 }
@@ -230,7 +255,7 @@ func doSubCreditByUser(userId, umid, typeName, code string, next *time.Time, use
 			bsub = true
 		}
 		if bsub { //扣分操作
-			newDate := next.AddDate(0, 1, 0)
+			newDate := next.AddDate(0, 1, -1)
 			creditDoc := map[string]interface{}{
 				"s_uid":     userId,
 				"s_umid":    umid,

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

@@ -269,7 +269,7 @@ func (c *CreditRpc) OutCreadit(param *qrpc.CreditData, replay *int) error {
 		var newDate time.Time
 		switch first {
 		case "A":
-			newDate = GetTimeByNow(now, Hour).AddDate(0, 1, 0)
+			newDate = GetTimeByNow(now, Hour).AddDate(0, 1, -1)
 			creditDoc["l_enddate"] = newDate.Unix()
 			creditDoc["i_valid"] = 1
 			if param.OtherParam != nil {