Parcourir la source

修复邮件发送重复扣费的错误

il y a 5 ans
Parent
commit
fa87a40947
4 fichiers modifiés avec 33 ajouts et 8 suppressions
  1. BIN
      api_test/api_test.rar
  2. 6 0
      api_test/config.json
  3. 16 7
      api_test/main.go
  4. 11 1
      jyservice/src/usermanager/sendmail.go

BIN
api_test/api_test.rar


+ 6 - 0
api_test/config.json

@@ -0,0 +1,6 @@
+{
+    "appid": "jyPz5XQgMABgVeTkdOMTBx",
+    "key": "349300qe",
+    "day": "0",
+    "apiurl": "https://api.jianyu360.com"
+}

+ 16 - 7
api_test/main.go

@@ -8,20 +8,28 @@ import (
 	"io/ioutil"
 	"log"
 	"net/http"
+	"qfw/util"
 	"strings"
 	"time"
 )
 
 var (
+	config map[string]string
 	//	appid  = "jyNjdXQgUDAwdaTklMPz5i"
 	//	key    = "404M0v2j"
 	//	apiurl = "http://127.0.0.1:8801"
-	appid  = "jyOh1XQgUJBQ5bTUlKCyZ1"
-	key    = "56IrWR74"
-	apiurl = "https://testapi.jianyu360.com"
+	//	appid  = "jyMi1XQgMABQNcSkBMIhBq"
+	//	key    = "6PzV0CUa"
+	//	apiurl = "https://testapi.jianyu360.com"
+	appid, key, apiurl, day string
 )
 
 func main() {
+	util.ReadConfig(&config)
+	appid = config["appid"]
+	key = config["key"]
+	apiurl = config["apiurl"]
+	day = config["day"]
 	getData()
 }
 
@@ -30,8 +38,8 @@ func getToken() (token string) {
 	res := post(apiurl+"/user/access_token", map[string]string{
 		"appid":     appid,
 		"timestamp": tm,
-		//"key":       "6PzV0CUa",
 		"signature": MD5(appid + tm + key),
+		//"key":       "6PzV0CUa",
 	})
 	log.Println(tm, MD5(appid+tm+key), res)
 	if res != nil && res["access_token"] != "" {
@@ -44,11 +52,12 @@ func getData() {
 	token := getToken()
 	data := post(apiurl+"/data/getalldata", map[string]string{
 		"access_token": token,
-		//"day":          "-3",
-		"next": "0",
+		"day":          day,
+		"next":         "0",
 	})
 	//s, _ := json.Marshal(data["data"])
-	log.Println(data)
+	//delete(data, "data")
+	log.Println(token, data)
 }
 
 func MD5(str string) string {

+ 11 - 1
jyservice/src/usermanager/sendmail.go

@@ -220,6 +220,7 @@ func sendmail(appid string, days int, force int, fn string, bcron bool) {
 					}
 				}
 				fields2["item"] = 1
+				fields2["bget"] = 1 //2020/3/11 没加这个字段重复发送会扣除
 				log.Info(fields2, dataQuery)
 				data, bdata := Mgo.Find("usermail", dataQuery, `{"_id":1}`, fields2, false, -1, -1)
 				firstId, lastId := "", ""
@@ -241,6 +242,10 @@ func sendmail(appid string, days int, force int, fn string, bcron bool) {
 									},
 								},
 							})
+							if len(updateMap) > 500 {
+								Mgo.UpdateBulk("usermail", updateMap...)
+								updateMap = [][]map[string]interface{}{}
+							}
 						}
 						if index == 0 {
 							firstId = qu.BsonIdToSId(v1["_id"])
@@ -277,7 +282,10 @@ func sendmail(appid string, days int, force int, fn string, bcron bool) {
 					//处理总条数,有重复获取的信息条不计数,*******************
 					if newGetLen > 0 {
 						redis.Decrby(REDISDB, "limitnum_"+appid, newGetLen)
-						go Mgo.UpdateBulk("usermail", updateMap...)
+						//数据量特别大的时候
+						if len(updateMap) > 0 {
+							Mgo.UpdateBulk("usermail", updateMap...)
+						}
 					}
 					d := map[string]interface{}{}
 					d["size"] = len(infos)
@@ -297,6 +305,8 @@ func sendmail(appid string, days int, force int, fn string, bcron bool) {
 							log.Println(saveData)
 						}
 					}()
+					//去掉bget
+					delete(fields2, "bget")
 					GetBidInfoXlsx(appid, fn, mails, fields2, allUserData)
 				}
 			}