Sfoglia il codice sorgente

Merge branch 'comein'

zwxi 11 mesi fa
parent
commit
980d4dceae
2 ha cambiato i file con 51 aggiunte e 35 eliminazioni
  1. 7 4
      models/comein_white_user.go
  2. 44 31
      services/comein/comein.go

+ 7 - 4
models/comein_white_user.go

@@ -34,9 +34,12 @@ func DelComeinWhiteUserMulti(delIds []int) (err error) {
 	return
 }
 
-func GetComeinWhiteUser(mobiles,emails []string) (items []*ComeinWhiteUser, err error) {
-	sql:=`SELECT * fromBy comein_white_user WHERE mobile IN (` + utils.GetOrmInReplace(len(mobiles)) + `) OR email IN (` + utils.GetOrmInReplace(len(emails)) + `)`
-	o:=orm.NewOrm()
-	_, err=o.Raw(sql,mobiles,emails).QueryRows(&items)
+func GetComeinWhiteUser(mobiles,emails string) (items []*ComeinWhiteUser, err error) {
+	sql:=`SELECT * from comein_white_user WHERE mobile IN (` + mobiles + `)  `
+	if len(emails) > 0 {
+		sql+= ` OR email IN (` + emails + `) `
+	}
+		o:=orm.NewOrm()
+	_, err=o.Raw(sql).QueryRows(&items)
 	return
 }

+ 44 - 31
services/comein/comein.go

@@ -14,6 +14,7 @@ import (
 	"net/url"
 	"sort"
 	"strconv"
+	"strings"
 	"time"
 )
 
@@ -477,8 +478,8 @@ func SyncWhiteList(cont context.Context) (err error) {
 		fmt.Println("GetUserMobileFormal Err:", err.Error())
 		return
 	}
-	addMobiles := make([]string, 0)
-	addemails := make([]string, 0)
+	addMobiles := ""
+	addemails := ""
 	addList := make([]*models.ComeinWhiteUser, 0)
 	for _, v := range needAddList {
 		if _, ok := syncedMap[v.Mobile+v.Email]; !ok {
@@ -492,35 +493,43 @@ func SyncWhiteList(cont context.Context) (err error) {
 
 
 			if v.Mobile != "" {
-				addMobiles = append(addMobiles,"'"+ v.Mobile+"'")
+				//addMobiles = append(addMobiles,"'"+ v.Mobile+"'")
+				addMobiles += "'"+ v.Mobile+"'"+","
 			} else if v.Email != "" {
-				addemails = append(addemails,"'"+ v.Email+"'")
+				//addemails = append(addemails,"'"+ v.Email+"'")
+				addemails += "'"+ v.Email+"'"+","
 			}
 		}
 	}
-	err = models.AddComeinWhiteUserMulti(addList)
-	if err != nil {
-		fmt.Println("新增白名单失败,AddComeinWhiteUserMulti", err.Error())
-		return
-	}
-	err = syncWhiteList(addMobiles,addemails, 1)
-	if err != nil {
-		fmt.Println("新增白名单失败", err.Error())
-		return
+	addMobiles = strings.TrimSuffix(addMobiles, ",")
+	addemails = strings.TrimSuffix(addemails, ",")
+	if len(addList) > 0 {
+		err = models.AddComeinWhiteUserMulti(addList)
+		if err != nil {
+			fmt.Println("新增白名单失败,AddComeinWhiteUserMulti", err.Error())
+			return
+		}
+		err = syncWhiteList(addMobiles,addemails, 1)
+		if err != nil {
+			fmt.Println("新增白名单失败", err.Error())
+			return
+		}
 	}
 
+
 	//拿联系人表,需要删除的
 	needDelList, err := models.GetUserMobileNotFormal()
 	if err != nil {
 		fmt.Println("GetUserMobileFormal Err:", err.Error())
 		return
 	}
-	delMobiles := make([]string, 0)
-	delEmials := make([]string, 0)
+	delMobiles := ""
+	delEmials := ""
 	delList := make([]*models.ComeinWhiteUser, 0)
 	for _, v := range needDelList {
 		if _, ok := syncedMap[v.Mobile+v.Email]; ok {
 			user := models.ComeinWhiteUser{
+				UserId: v.UserId,
 				Mobile:      v.Mobile,
 				CountryCode: "+"+v.CountryCode,
 				Email:       v.Email,
@@ -529,31 +538,35 @@ func SyncWhiteList(cont context.Context) (err error) {
 			delList = append(delList, &user)
 
 			if v.Mobile != "" {
-				delMobiles = append(delMobiles, "'"+v.Mobile+"'")
+				//delMobiles = append(delMobiles, "'"+v.Mobile+"'")
+				delMobiles += "'"+v.Mobile+"'"+","
 			} else if v.Email != "" {
-				delEmials = append(delEmials, "'"+v.Email+"'")
+				//delEmials = append(delEmials, "'"+v.Email+"'")
+				delEmials += "'"+v.Email+"'"+","
 			}
 		}
 	}
-	err = syncWhiteList(delMobiles, delEmials, 2)
-	if err != nil {
-		fmt.Println("删除白名单失败", err.Error())
-		return
-	}
-	delIds := make([]int, 0)
-	for _, v := range delList {
-		delIds = append(delIds, v.UserId)
-	}
-	err = models.DelComeinWhiteUserMulti(delIds)
-	if err != nil {
-		fmt.Println("删除白名单失败,DelComeinWhiteUserMulti", err.Error())
-		return
+	if len(delList) > 0 {
+		err = syncWhiteList(delMobiles, delEmials, 2)
+		if err != nil {
+			fmt.Println("删除白名单失败", err.Error())
+			return
+		}
+		delIds := make([]int, 0)
+		for _, v := range delList {
+			delIds = append(delIds, v.UserId)
+		}
+		err = models.DelComeinWhiteUserMulti(delIds)
+		if err != nil {
+			fmt.Println("删除白名单失败,DelComeinWhiteUserMulti", err.Error())
+			return
+		}
 	}
 
 	return
 }
 
-func syncWhiteList(mobiles, emails []string, opt int) (err error) {
+func syncWhiteList(mobiles, emails string, opt int) (err error) {
 	postUrl := utils.COMEIN_URL
 
 	timestamp := fmt.Sprintf("%d", time.Now().UnixNano()/1e6)