xingzai 1 vuosi sitten
vanhempi
commit
fa5a843878
3 muutettua tiedostoa jossa 50 lisäystä ja 18 poistoa
  1. 9 8
      models/user.go
  2. 11 1
      models/wx_user_white.go
  3. 30 9
      services/user.go

+ 9 - 8
models/user.go

@@ -355,14 +355,15 @@ func ChangeUserOutboundMobileByMobile(userId int) (err error) {
 }
 
 type UserWhiteList struct {
-	Mobile      string `description:"手机号码"`
-	RealName    string `description:"用户实际名称"`
-	CompanyName string `description:"公司名称"`
-	Permission  string `description:"拥有权限分类,多个用英文逗号分隔"`
-	CountryCode string `description:"区号"`
-	SellerName  string `description:"销售姓名"`
-	CreatedTime time.Time
-	Status      string `description:"客户状态'试用','永续','冻结','流失','正式','潜在'"`
+	Mobile         string `description:"手机号码"`
+	OutboundMobile string `description:"外呼手机号"`
+	RealName       string `description:"用户实际名称"`
+	CompanyName    string `description:"公司名称"`
+	Permission     string `description:"拥有权限分类,多个用英文逗号分隔"`
+	CountryCode    string `description:"区号"`
+	SellerName     string `description:"销售姓名"`
+	CreatedTime    time.Time
+	Status         string `description:"客户状态'试用','永续','冻结','流失','正式','潜在'"`
 }
 
 type UserWhiteListRep struct {

+ 11 - 1
models/wx_user_white.go

@@ -27,6 +27,16 @@ func AddWxUserWhite(item *WxUserWhite) (lastId int64, err error) {
 	return
 }
 
+// 批量添加
+func AddAddWxUserWhiteMulti(items []*WxUserWhite) (err error) {
+	o := orm.NewOrmUsingDB("weekly_report")
+	if len(items) > 0 {
+		//批量添加新的关注记录
+		_, err = o.InsertMulti(len(items), items)
+	}
+	return
+}
+
 // 获取用户手机号白名单
 func GetWxUserWhiteMobile() (mobileStr string, err error) {
 	sql := ` SELECT
@@ -132,7 +142,7 @@ func DeleteWxUserWhite(item *WxUserWhite) (err error) {
 	if item.Mobile != "" {
 		sql := ` DELETE FROM wx_user_white WHERE mobile = ?`
 		_, err = o.Raw(sql, item.Mobile).Exec()
-	} else {
+	} else if item.OutboundMobile != "" {
 		sql := ` DELETE FROM wx_user_white WHERE outbound_mobile = ?`
 		_, err = o.Raw(sql, item.OutboundMobile).Exec()
 	}

+ 30 - 9
services/user.go

@@ -437,6 +437,7 @@ func SendEmailUserWhiteListChange(cont context.Context) (err error) {
 	//手机号新增
 	fieldStr = ` u.mobile,u.country_code,u.real_name,c.company_name,u.company_id,cp.seller_name,cp.status,`
 	condition = `  AND cp.status IN ( '正式', '试用' ) AND u.mobile IN (` + mobileStr + `) `
+	condition += ` AND  u.mobile !=''  AND DATE_SUB(CURDATE(), INTERVAL 2 DAY) <= DATE(u.created_time )`
 	listMobile, err := models.GetFormalUserWhiteList(fieldStr, condition)
 	if err != nil {
 		msg = "获取失败,Err:" + err.Error()
@@ -450,11 +451,13 @@ func SendEmailUserWhiteListChange(cont context.Context) (err error) {
 	outboundMobileStr = strings.Replace(outboundMobileStr, " ", "", -1)
 	fieldStr = ` u.outbound_mobile as mobile,u.outbound_country_code as country_code,u.real_name,c.company_name,u.company_id,cp.status,`
 	condition = `  AND cp.status IN ( '正式', '试用' ) AND u.outbound_mobile IN (` + outboundMobileStr + `) `
+	condition += `  AND DATE_SUB(CURDATE(), INTERVAL 2 DAY) <= DATE(u.created_time )`
 	listOutboundMobile, err := models.GetFormalUserWhiteList(fieldStr, condition)
 	if err != nil {
 		msg = "获取失败,Err:" + err.Error()
 		return
 	}
+
 	var rep models.UserWhiteListRep
 	var repList []*models.UserWhiteList
 	repList = listMobile
@@ -463,7 +466,16 @@ func SendEmailUserWhiteListChange(cont context.Context) (err error) {
 			repList = append(listMobile, v)
 		}
 	}
-	rep.List = repList
+
+	//新增用户,过滤手机号为空的
+	for _, v := range repList {
+		if v.Mobile == "" {
+			continue
+		}
+		rep.List = append(rep.List, v)
+	}
+
+	//rep.List = repList
 	//创建excel
 	dir, errFile := os.Executable()
 	exPath := filepath.Dir(dir)
@@ -640,17 +652,26 @@ func SendEmailUserWhiteListChange(cont context.Context) (err error) {
 	//手机号冻结
 	listFrozen, err := models.GetFrozenUserWhiteList()                 //手机号用户修改
 	listFrozenOutbound, err := models.GetFrozenUserWhiteListOutbound() //外呼手机号用户修改
+	if err != nil {
+		msg = "获取失败,Err:" + err.Error()
+		return
+	}
 	if len(listFrozenOutbound) > 0 {
 		for _, v := range listFrozenOutbound {
 			listFrozen = append(listFrozen, v)
 		}
 	}
-	if err != nil {
-		msg = "获取失败,Err:" + err.Error()
-		return
+
+	var listFrozenUser []*models.WxUserWhite
+	for _, v := range listFrozen {
+		if v.Mobile == "" {
+			continue
+		}
+		listFrozenUser = append(listFrozenUser, v)
 	}
-	if len(listFrozen) > 0 {
-		for _, item := range listFrozen {
+
+	if len(listFrozenUser) > 0 {
+		for _, item := range listFrozenUser {
 			row := sheet.AddRow()
 			cellA := row.AddCell()
 			cellA.Value = item.RealName
@@ -696,11 +717,10 @@ func SendEmailUserWhiteListChange(cont context.Context) (err error) {
 	content = time.Now().Format("2006-01-02") + "删除白名单用户"
 	fileName = downLoadnFilePaths
 	var sendResult2 bool
-	if len(listFrozen) > 0 {
+	if len(listFrozenOutbound) > 0 {
 		sendResult2 = utils.SendEmailByHongze(title, content, utils.EmaiWhiteUserList, fileName, title+".xlsx")
 	}
-	fmt.Println(sendResult2)
-	fmt.Println(sendResult)
+
 	os.Remove(downLoadnFilePaths)
 	//更新名单表
 	if sendResult {
@@ -726,6 +746,7 @@ func SendEmailUserWhiteListChange(cont context.Context) (err error) {
 		if len(listOutboundMobile) > 0 {
 			for _, v := range listOutboundMobile {
 				item := new(models.WxUserWhite)
+				item.Mobile = v.Mobile
 				item.OutboundMobile = v.Mobile
 				item.OutboundCountryCode = v.CountryCode
 				item.CreatedTime = time.Now()