Procházet zdrojové kódy

feat:成交订单发邮件

wangchuanjin před 11 měsíci
rodič
revize
b191aa9a53

+ 8 - 6
pushjyinside/config.json

@@ -5,12 +5,14 @@
 	"messageKey":"message.rpc",
 	"messageKey":"message.rpc",
 	"kecheng":{
 	"kecheng":{
 		"deptId":3502,
 		"deptId":3502,
+		"reTryTime":3,
+		"maxTime":30,
 		"title":"客户移交客户成功组",
 		"title":"客户移交客户成功组",
 		"mail":{
 		"mail":{
 			"content":"<style> *,body,html{margin:0px;font-family:tahoma,arial,'Hiragino Sans GB','Microsoft YaHei',宋体,ans-serif;font-size:16px;}p{margin:15px;font-size:18px;}table{background-color: rgb(244, 244, 249);padding:5px 15px;border:solid 1px #ddd;margin: 20px 0px 20px 50px;float:left;}.tit{width:120px;}td{padding: 5px;}.clear{clear: both;}</style><p>各位好,以下订单用户已经完成支付,烦请对接后续售后服务事项,谢谢!</p>%s<div class='clear'></div>",
 			"content":"<style> *,body,html{margin:0px;font-family:tahoma,arial,'Hiragino Sans GB','Microsoft YaHei',宋体,ans-serif;font-size:16px;}p{margin:15px;font-size:18px;}table{background-color: rgb(244, 244, 249);padding:5px 15px;border:solid 1px #ddd;margin: 20px 0px 20px 50px;float:left;}.tit{width:120px;}td{padding: 5px;}.clear{clear: both;}</style><p>各位好,以下订单用户已经完成支付,烦请对接后续售后服务事项,谢谢!</p>%s<div class='clear'></div>",
-			"table":"<table><tr><td class='tit'>产品名称:</td><td>%s</td></tr><tr><td class='tit'>联系方式:</td><td>%s</td></tr><tr><td class='tit'>订单编号:</td><td>%s</td></tr><tr><td class='tit'>使用起止时间:</td><td>%s</td></tr></table>"
+			"table":"<table><tr><td class='tit'>产品名称:</td><td>%s</td></tr><tr><td class='tit'>联系方式:</td><td>%s</td></tr><tr><td class='tit'>订单编号:</td><td>%s</td></tr><tr><td class='tit'>使用起止时间:</td><td>%s</td></tr><tr><td class='tit'>分配客成:</td><td>%s</td></tr></table>"
 		},
 		},
-		"message":"该订单用户已经完成支付,烦请对接后续售后服务事项,谢谢!\n产品名称:%s 联系方式:%s 订单编号:%s 使用起止时间:%s"
+		"message":"该订单用户已经完成支付,烦请对接后续售后服务事项,谢谢!\n产品名称:%s 联系方式:%s 订单编号:%s 使用起止时间:%s 分配客成:%s"
 	},
 	},
 	"mails":[
 	"mails":[
 		{
 		{
@@ -18,16 +20,16 @@
 			"port":465,
 			"port":465,
 			"pwd":"ue9Rg9Sf4CVtdm5a",
 			"pwd":"ue9Rg9Sf4CVtdm5a",
 			"user":"public03@topnet.net.cn",
 			"user":"public03@topnet.net.cn",
-			"mailPoolSize":5,
-			"mailReTry":1
+			"mailPoolSize":2,
+			"mailReTry":3
 		},
 		},
 		{
 		{
 			"addr":"smtp.exmail.qq.com",
 			"addr":"smtp.exmail.qq.com",
 			"port":465,
 			"port":465,
 			"pwd":"Mu^$i21673",
 			"pwd":"Mu^$i21673",
 			"user":"public04@topnet.net.cn",
 			"user":"public04@topnet.net.cn",
-			"mailPoolSize":4,
-			"mailReTry":1
+			"mailPoolSize":2,
+			"mailReTry":3
 		}
 		}
 	]
 	]
 }
 }

+ 7 - 4
pushjyinside/config/config.go

@@ -2,6 +2,7 @@ package config
 
 
 import (
 import (
 	"log"
 	"log"
+	"time"
 
 
 	util "app.yhyue.com/moapp/jybase/common"
 	util "app.yhyue.com/moapp/jybase/common"
 	"app.yhyue.com/moapp/jybase/mail"
 	"app.yhyue.com/moapp/jybase/mail"
@@ -15,9 +16,11 @@ type config struct {
 	EtcdHosts  []string `json:"etcdHosts"`
 	EtcdHosts  []string `json:"etcdHosts"`
 	MessageKey string   `json:"messageKey"`
 	MessageKey string   `json:"messageKey"`
 	KeCheng    struct {
 	KeCheng    struct {
-		DeptId int64  `json:"deptId"`
-		Title  string `json:"title"`
-		Mail   struct {
+		DeptId    int64         `json:"deptId"`
+		ReTryTime time.Duration `json:"reTryTime"`
+		MaxTime   time.Duration `json:"maxTime"`
+		Title     string        `json:"title"`
+		Mail      struct {
 			Table   string `json:"table"`
 			Table   string `json:"table"`
 			Content string `json:"content"`
 			Content string `json:"content"`
 		} `json:"mail"`
 		} `json:"mail"`
@@ -36,7 +39,7 @@ type pushMail struct {
 }
 }
 
 
 type taskConfig struct {
 type taskConfig struct {
-	OrderPayTime string `json:"orderPayTime"`
+	OrderEachTime string `json:"orderEachTime"`
 }
 }
 
 
 var (
 var (

+ 14 - 1
pushjyinside/db.json

@@ -7,7 +7,7 @@
 			"replSet": ""
 			"replSet": ""
 		}
 		}
 	},
 	},
-    "mysql": {
+    "tidb": {
 	    "main": {
 	    "main": {
 	        "dbName": "jianyu",
 	        "dbName": "jianyu",
 	        "address": "192.168.3.217:4000",
 	        "address": "192.168.3.217:4000",
@@ -15,6 +15,19 @@
 	        "passWord": "=PDT49#80Z!RVv52_z",
 	        "passWord": "=PDT49#80Z!RVv52_z",
 			"maxOpenConns": 5,
 			"maxOpenConns": 5,
 			"maxIdleConns": 5
 			"maxIdleConns": 5
+	    },
+		"subjectdb": {
+	        "dbName": "jianyu_subjectdb_test",
+	        "address": "192.168.3.149:4000",
+	        "userName": "root",
+	        "passWord": "Tibi#20211222",
+			"maxOpenConns": 5,
+			"maxIdleConns": 5
 	    }
 	    }
+    },
+    "redis": {
+    	"main": {
+			"address": "pushcache_2_c=192.168.3.128:5003"
+		}
     }
     }
 }
 }

+ 40 - 15
pushjyinside/db/db.go

@@ -3,6 +3,8 @@ package db
 import (
 import (
 	"log"
 	"log"
 
 
+	"app.yhyue.com/moapp/jybase/redis"
+
 	util "app.yhyue.com/moapp/jybase/common"
 	util "app.yhyue.com/moapp/jybase/common"
 	m "app.yhyue.com/moapp/jybase/mongodb"
 	m "app.yhyue.com/moapp/jybase/mongodb"
 	"app.yhyue.com/moapp/jybase/mysql"
 	"app.yhyue.com/moapp/jybase/mysql"
@@ -10,17 +12,22 @@ import (
 )
 )
 
 
 var (
 var (
-	DbConf     *dbConf
-	Mysql_Main *mysql.Mysql
-	Mgo        *m.MongodbSim
+	DbConf         *dbConf
+	Tidb_Main      *mysql.Mysql
+	Tidb_Subjectdb *mysql.Mysql
+	Mgo            *m.MongodbSim
 )
 )
 
 
 type dbConf struct {
 type dbConf struct {
 	Mongodb struct {
 	Mongodb struct {
 		Main *MgoConf
 		Main *MgoConf
 	}
 	}
-	Mysql struct {
-		Main *MysqlConf
+	Tidb struct {
+		Main      *MysqlConf
+		Subjectdb *MysqlConf
+	}
+	Redis struct {
+		Main *RedisConf
 	}
 	}
 }
 }
 
 
@@ -40,17 +47,35 @@ func init() {
 			Mgo.InitPool()
 			Mgo.InitPool()
 		}
 		}
 		//
 		//
-		if DbConf.Mysql.Main != nil {
-			log.Println("初始化 mysql main")
-			Mysql_Main = &mysql.Mysql{
-				Address:      DbConf.Mysql.Main.Address,
-				UserName:     DbConf.Mysql.Main.UserName,
-				PassWord:     DbConf.Mysql.Main.PassWord,
-				DBName:       DbConf.Mysql.Main.DbName,
-				MaxOpenConns: DbConf.Mysql.Main.MaxOpenConns,
-				MaxIdleConns: DbConf.Mysql.Main.MaxIdleConns,
+		if DbConf.Tidb.Main != nil {
+			log.Println("初始化 tidb main")
+			Tidb_Main = &mysql.Mysql{
+				Address:      DbConf.Tidb.Main.Address,
+				UserName:     DbConf.Tidb.Main.UserName,
+				PassWord:     DbConf.Tidb.Main.PassWord,
+				DBName:       DbConf.Tidb.Main.DbName,
+				MaxOpenConns: DbConf.Tidb.Main.MaxOpenConns,
+				MaxIdleConns: DbConf.Tidb.Main.MaxIdleConns,
+			}
+			Tidb_Main.Init()
+		}
+		//
+		if DbConf.Tidb.Subjectdb != nil {
+			log.Println("初始化 tidb subjectdb")
+			Tidb_Subjectdb = &mysql.Mysql{
+				Address:      DbConf.Tidb.Subjectdb.Address,
+				UserName:     DbConf.Tidb.Subjectdb.UserName,
+				PassWord:     DbConf.Tidb.Subjectdb.PassWord,
+				DBName:       DbConf.Tidb.Subjectdb.DbName,
+				MaxOpenConns: DbConf.Tidb.Subjectdb.MaxOpenConns,
+				MaxIdleConns: DbConf.Tidb.Subjectdb.MaxIdleConns,
 			}
 			}
-			Mysql_Main.Init()
+			Tidb_Subjectdb.Init()
+		}
+		//初始化redis
+		if DbConf.Redis.Main != nil {
+			log.Println("初始化 redis")
+			redis.InitRedisBySize(DbConf.Redis.Main.Address, 30, 30, 300)
 		}
 		}
 	}
 	}
 }
 }

+ 1 - 1
pushjyinside/go.mod

@@ -4,7 +4,7 @@ go 1.18
 
 
 require (
 require (
 	app.yhyue.com/moapp/MessageCenter v0.0.0-20240823102038-aea2532a65c6
 	app.yhyue.com/moapp/MessageCenter v0.0.0-20240823102038-aea2532a65c6
-	app.yhyue.com/moapp/jybase v0.0.0-20240226084952-7e7b38ef8a66
+	app.yhyue.com/moapp/jybase v0.0.0-20240805110713-0c17face82c4
 	bp.jydev.jianyu360.cn/BaseService/pushpkg v0.0.0-20240408032230-511af2024e83
 	bp.jydev.jianyu360.cn/BaseService/pushpkg v0.0.0-20240408032230-511af2024e83
 	github.com/zeromicro/go-zero v1.5.2
 	github.com/zeromicro/go-zero v1.5.2
 )
 )

+ 2 - 2
pushjyinside/go.sum

@@ -7,8 +7,8 @@ app.yhyue.com/moapp/jybase v0.0.0-20220418104200-46c3fff161c7/go.mod h1:qNRA0sHu
 app.yhyue.com/moapp/jybase v0.0.0-20220420032112-668025915ee4/go.mod h1:qNRA0sHuYqcLoYoP8irpaWnW9YsXixe6obBIkwaXpD0=
 app.yhyue.com/moapp/jybase v0.0.0-20220420032112-668025915ee4/go.mod h1:qNRA0sHuYqcLoYoP8irpaWnW9YsXixe6obBIkwaXpD0=
 app.yhyue.com/moapp/jybase v0.0.0-20220421060131-a1001013ba46/go.mod h1:qNRA0sHuYqcLoYoP8irpaWnW9YsXixe6obBIkwaXpD0=
 app.yhyue.com/moapp/jybase v0.0.0-20220421060131-a1001013ba46/go.mod h1:qNRA0sHuYqcLoYoP8irpaWnW9YsXixe6obBIkwaXpD0=
 app.yhyue.com/moapp/jybase v0.0.0-20230901064756-2fc66b18db40/go.mod h1:Hv9U/7oHRucqH315Tr1+d03NCvS9mOKPfk8pwwlOIwQ=
 app.yhyue.com/moapp/jybase v0.0.0-20230901064756-2fc66b18db40/go.mod h1:Hv9U/7oHRucqH315Tr1+d03NCvS9mOKPfk8pwwlOIwQ=
-app.yhyue.com/moapp/jybase v0.0.0-20240226084952-7e7b38ef8a66 h1:kCRYqzclN4dtGuGC89ID2w5lGrJgqZC8bNL8mRR+tiU=
-app.yhyue.com/moapp/jybase v0.0.0-20240226084952-7e7b38ef8a66/go.mod h1:XHNATN6tsJKHdCB0DbUtFdPPHXexTUFyB3RlO+lUUoM=
+app.yhyue.com/moapp/jybase v0.0.0-20240805110713-0c17face82c4 h1:YPgzn9rGR0+eHGuJAIDXOjmGySAWSErBrdjndX3uVog=
+app.yhyue.com/moapp/jybase v0.0.0-20240805110713-0c17face82c4/go.mod h1:XHNATN6tsJKHdCB0DbUtFdPPHXexTUFyB3RlO+lUUoM=
 bp.jydev.jianyu360.cn/BP/jynsq v0.0.0-20220222052708-ebc43af90698/go.mod h1:ojo/AUH9Yr1wzarEjOaNMkj1Cet/9r8IgLyba64Z52E=
 bp.jydev.jianyu360.cn/BP/jynsq v0.0.0-20220222052708-ebc43af90698/go.mod h1:ojo/AUH9Yr1wzarEjOaNMkj1Cet/9r8IgLyba64Z52E=
 bp.jydev.jianyu360.cn/BaseService/gateway v0.0.0-20220419090715-88ddb32961be/go.mod h1:Yj4oabIGItuMoF0BXYLz2XAnF581kxgXBrvlUtIJrkI=
 bp.jydev.jianyu360.cn/BaseService/gateway v0.0.0-20220419090715-88ddb32961be/go.mod h1:Yj4oabIGItuMoF0BXYLz2XAnF581kxgXBrvlUtIJrkI=
 bp.jydev.jianyu360.cn/BaseService/gateway v1.3.4/go.mod h1:BMLd/5wb3BIEGhnEgF9y1sJN9P5/Dw9kYsoiE9V8I9g=
 bp.jydev.jianyu360.cn/BaseService/gateway v1.3.4/go.mod h1:BMLd/5wb3BIEGhnEgF9y1sJN9P5/Dw9kYsoiE9V8I9g=

+ 132 - 72
pushjyinside/job/pushkcjob.go

@@ -5,9 +5,12 @@ import (
 	"context"
 	"context"
 	"encoding/json"
 	"encoding/json"
 	"fmt"
 	"fmt"
+	"log"
 	. "pushjyinside/config"
 	. "pushjyinside/config"
 	. "pushjyinside/db"
 	. "pushjyinside/db"
+	. "pushjyinside/util"
 	"strings"
 	"strings"
+	"time"
 
 
 	"app.yhyue.com/moapp/MessageCenter/rpc/messageclient"
 	"app.yhyue.com/moapp/MessageCenter/rpc/messageclient"
 	"app.yhyue.com/moapp/MessageCenter/rpc/type/message"
 	"app.yhyue.com/moapp/MessageCenter/rpc/type/message"
@@ -16,6 +19,7 @@ import (
 	"app.yhyue.com/moapp/jybase/logger"
 	"app.yhyue.com/moapp/jybase/logger"
 	. "app.yhyue.com/moapp/jybase/mail"
 	. "app.yhyue.com/moapp/jybase/mail"
 	. "app.yhyue.com/moapp/jybase/mongodb"
 	. "app.yhyue.com/moapp/jybase/mongodb"
+	"app.yhyue.com/moapp/jybase/redis"
 )
 )
 
 
 //有成单给客成发邮件,部门id:59005
 //有成单给客成发邮件,部门id:59005
@@ -26,103 +30,159 @@ type PushKcJob struct {
 func (p *PushKcJob) Execute() {
 func (p *PushKcJob) Execute() {
 	defer util.Catch()
 	defer util.Catch()
 	nowFormat := NowFormat(Date_Full_Layout)
 	nowFormat := NowFormat(Date_Full_Layout)
-	logger.Info(p.TaskName, "开始。。。", TaskConfig.OrderPayTime, nowFormat)
-	table := ""
+	logger.Info(p.TaskName, "开始。。。", TaskConfig.OrderEachTime, nowFormat)
 	count := 0
 	count := 0
 	orderCodes := []string{}
 	orderCodes := []string{}
 	messageConents := []string{}
 	messageConents := []string{}
 	combo := map[int64]string{}
 	combo := map[int64]string{}
-	Mysql_Main.SelectByBath(1, func(l *[]map[string]interface{}) bool {
+	Tidb_Main.SelectByBath(1, func(l *[]map[string]interface{}) bool {
 		combo[util.Int64All((*l)[0]["id"])] = util.ObjToString((*l)[0]["s_name"])
 		combo[util.Int64All((*l)[0]["id"])] = util.ObjToString((*l)[0]["s_name"])
 		return true
 		return true
-	}, `select id,s_name from bigmember_combo`)
-	Mysql_Main.SelectByBath(1, func(l *[]map[string]interface{}) bool {
-		product_type := util.ObjToString((*l)[0]["product_type"])
-		if product_type != "大会员" && product_type != "大会员-子账号" {
+	}, `select id,s_name from jianyu.bigmember_combo`)
+	orderInfos := []*OrderInfo{}
+	userIds := []string{}
+	Tidb_Main.SelectByBath(1, func(l *[]map[string]interface{}) bool {
+		order_code := util.ObjToString((*l)[0]["order_code"])
+		id := util.Int64All((*l)[0]["id"])
+		if exists, err := redis.Exists(RedisCode, fmt.Sprintf(RedisKcOrderTip, id)); exists {
+			logger.Info(p.TaskName, "redis判重已经提醒过", id, order_code)
+			return true
+		} else if err != nil {
+			logger.Error(p.TaskName, err)
+			return true
+		}
+		user_id := util.ObjToString((*l)[0]["user_id"])
+		if user_id == "" {
 			return true
 			return true
 		}
 		}
 		count++
 		count++
+		product_type := util.ObjToString((*l)[0]["product_type"])
 		if filter := util.ObjToString((*l)[0]["filter"]); filter != "" {
 		if filter := util.ObjToString((*l)[0]["filter"]); filter != "" {
 			filterMap := map[string]interface{}{}
 			filterMap := map[string]interface{}{}
 			json.Unmarshal([]byte(filter), &filterMap)
 			json.Unmarshal([]byte(filter), &filterMap)
 			product_type += combo[util.Int64All(filterMap["comboId"])]
 			product_type += combo[util.Int64All(filterMap["comboId"])]
 		}
 		}
-		order_code := util.ObjToString((*l)[0]["order_code"])
-		user_phone := util.ObjToString((*l)[0]["user_phone"])
-		startEnd := fmt.Sprintf("%s--%s", strings.Split(util.ObjToString((*l)[0]["vip_starttime"]), " ")[0], strings.Split(util.ObjToString((*l)[0]["vip_endtime"]), " ")[0])
+		if entId := util.Int64All((*l)[0]["ent_id"]); entId > 0 {
+			user_id = fmt.Sprint(entId)
+		}
+		userIds = append(userIds, user_id)
 		orderCodes = append(orderCodes, order_code)
 		orderCodes = append(orderCodes, order_code)
-		table += fmt.Sprintf(Config.KeCheng.Mail.Table, product_type, user_phone, order_code, startEnd)
-		messageConents = append(messageConents, fmt.Sprintf(Config.KeCheng.Message, product_type, user_phone, order_code, startEnd))
+		orderInfos = append(orderInfos, &OrderInfo{
+			Id:          id,
+			UserId:      user_id,
+			ProductType: product_type,
+			OrderCode:   order_code,
+			UserPhone:   util.ObjToString((*l)[0]["user_phone"]),
+			StartEnd:    fmt.Sprintf("%s--%s", strings.Split(util.ObjToString((*l)[0]["vip_starttime"]), " ")[0], strings.Split(util.ObjToString((*l)[0]["vip_endtime"]), " ")[0]),
+		})
 		return true
 		return true
-	}, `select order_code,user_phone,vip_starttime,vip_endtime,product_type,filter from jianyu.dataexport_order where pay_time>=? and pay_time<?`, TaskConfig.OrderPayTime, nowFormat)
+	}, `select id,order_code,user_phone,vip_starttime,vip_endtime,product_type,filter,user_id,ent_id from jianyu.dataexport_order where autoUpdate>=? and autoUpdate<? and order_status=1 and (product_type='大会员' or product_type='大会员-子账号') order by autoUpdate`, TaskConfig.OrderEachTime, nowFormat)
 	logger.Info(p.TaskName, count, "个订单需要发送提醒", orderCodes)
 	logger.Info(p.TaskName, count, "个订单需要发送提醒", orderCodes)
-	phones := []string{}
-	if table != "" {
-		Mysql_Main.SelectByBath(1, func(l *[]map[string]interface{}) bool {
-			name, phone, mail := util.ObjToString((*l)[0]["name"]), util.ObjToString((*l)[0]["phone"]), util.ObjToString((*l)[0]["mail"])
-			phones = append(phones, phone)
-			logger.Info(p.TaskName, "开始邮箱推送", name, phone, mail)
-			isPushOk := false
-			//发送邮件
-			if mail != "" {
-				isPushOk = PollingMail(mail, Gmails, func(gmail *GmailAuth) bool {
-					return GSendMail(Config.MailFrom, mail, "", "", Config.KeCheng.Title, fmt.Sprintf(Config.KeCheng.Mail.Content, table), "", "", gmail)
-				})
+	if len(orderCodes) > 0 {
+		table := ""
+		startTime := time.Now()
+		whs, args := util.WhArgs(userIds)
+	L:
+		for {
+			customerInfo := map[string]string{}
+			Tidb_Subjectdb.SelectByBath(1, func(l *[]map[string]interface{}) bool {
+				customerInfo[util.ObjToString((*l)[0]["ent_id"])] = util.ObjToString((*l)[0]["name"])
+				return true
+			}, `select ent_id,name from dwd_f_csm_customer_info where ent_id in (`+whs+`) and is_transfer=0`, args...)
+			log.Println(customerInfo, args)
+			for k, v := range orderInfos {
+				if _, ok := customerInfo[v.UserId]; !ok {
+					continue
+				}
+				v.DisKcName = customerInfo[v.UserId]
+				if k == len(orderInfos)-1 {
+					break L
+				}
 			}
 			}
-			logger.Info(p.TaskName, "邮箱推送结束", isPushOk, name, phone, mail)
-			return true
-		}, `select b.name,b.phone,b.mail from jianyu.entniche_department_user a inner join jianyu.entniche_user b on (a.dept_id=? and a.user_id=b.id)`, Config.KeCheng.DeptId)
-		//发送站内信
-		if len(phones) > 0 {
-			logger.Info(p.TaskName, "开始站内信推送", phones)
-			users, ok := Mgo.Find("user", map[string]interface{}{
-				"$or": []map[string]interface{}{
-					map[string]interface{}{
-						"s_phone": map[string]interface{}{
-							"$in": phones,
+			if time.Now().Sub(startTime) > Config.KeCheng.MaxTime*time.Minute {
+				logger.Info(p.TaskName, "查找移交客成人员信息,超过", Config.KeCheng.MaxTime, "分钟终止")
+				break
+			} else {
+				logger.Info(p.TaskName, "查找移交客成人员信息,休眠", Config.KeCheng.ReTryTime, "分钟")
+				time.Sleep(Config.KeCheng.ReTryTime * time.Minute)
+			}
+		}
+		for _, v := range orderInfos {
+			table += fmt.Sprintf(Config.KeCheng.Mail.Table, v.ProductType, v.UserPhone, v.OrderCode, v.StartEnd, v.DisKcName)
+			messageConents = append(messageConents, fmt.Sprintf(Config.KeCheng.Message, v.ProductType, v.UserPhone, v.OrderCode, v.StartEnd, v.DisKcName))
+			redis.Put(RedisCode, fmt.Sprintf(RedisKcOrderTip, v.Id), 1, Day30Sec)
+		}
+		if table != "" {
+			mails, phones := []string{}, []string{}
+			Tidb_Main.SelectByBath(1, func(l *[]map[string]interface{}) bool {
+				mails = append(mails, util.ObjToString((*l)[0]["mail"]))
+				phones = append(phones, util.ObjToString((*l)[0]["phone"]))
+				return true
+			}, `select b.name,b.phone,b.mail from jianyu.entniche_department_user a inner join jianyu.entniche_user b on (a.dept_id=? and a.user_id=b.id)`, Config.KeCheng.DeptId)
+			//发送邮件
+			if len(mails) == 0 && len(phones) == 0 {
+				logger.Info(p.TaskName, "没有找到客成部门下要推送的人", Config.KeCheng.DeptId)
+			} else if len(mails) > 0 {
+				for _, v := range mails {
+					logger.Info(p.TaskName, "开始邮箱推送", v)
+					isPushOk := false
+					//发送邮件
+					if v != "" {
+						isPushOk = PollingMail(v, Gmails, func(gmail *GmailAuth) bool {
+							return GSendMail(Config.MailFrom, v, "", "", Config.KeCheng.Title, fmt.Sprintf(Config.KeCheng.Mail.Content, table), "", "", gmail)
+						})
+					}
+					logger.Info(p.TaskName, "邮箱推送结束", isPushOk, v)
+				}
+			} else if len(phones) > 0 { //发送站内信
+				logger.Info(p.TaskName, "开始站内信推送", phones)
+				users, ok := Mgo.Find("user", map[string]interface{}{
+					"$or": []map[string]interface{}{
+						map[string]interface{}{
+							"s_phone": map[string]interface{}{
+								"$in": phones,
+							},
 						},
 						},
-					},
-					map[string]interface{}{
-						"s_m_phone": map[string]interface{}{
-							"$in": phones,
+						map[string]interface{}{
+							"s_m_phone": map[string]interface{}{
+								"$in": phones,
+							},
 						},
 						},
 					},
 					},
-				},
-			}, nil, `{"_id":1}`, false, -1, -1)
-			userIds := []string{}
-			if ok && len(*users) > 0 {
-				for _, v := range *users {
-					userIds = append(userIds, BsonIdToSId(v["_id"]))
-				}
-			}
-			if len(userIds) > 0 && len(messageConents) > 0 {
-				for _, v := range messageConents {
-					req := &message.MultipleSaveMsgReq{
-						UserIds:    strings.Join(userIds, ","),
-						Title:      Config.KeCheng.Title,
-						Content:    v,
-						MsgType:    11,
-						Link:       "",
-						Appid:      "10000",
-						AppPushUrl: "",
-						WxPushUrl:  "",
-						IosPushUrl: "",
+				}, nil, `{"_id":1}`, false, -1, -1)
+				userIds := []string{}
+				if ok && len(*users) > 0 {
+					for _, v := range *users {
+						userIds = append(userIds, BsonIdToSId(v["_id"]))
 					}
 					}
-					resp, err := messageclient.NewMessage(MessageClient).MultipleSaveMsg(context.Background(), req)
-					if err != nil {
-						logger.Error(fmt.Sprintf("%+v", req), "发站内信出错", err)
-					} else if resp.Code == 1 {
-						logger.Error(fmt.Sprintf("%+v", req), "发送站内信成功")
-					} else {
-						logger.Error(fmt.Sprintf("%+v", req), "发送站内信失败")
+				}
+				if len(userIds) > 0 && len(messageConents) > 0 {
+					for _, v := range messageConents {
+						req := &message.MultipleSaveMsgReq{
+							UserIds:    strings.Join(userIds, ","),
+							Title:      Config.KeCheng.Title,
+							Content:    v,
+							MsgType:    11,
+							Link:       "",
+							Appid:      "10000",
+							AppPushUrl: "",
+							WxPushUrl:  "",
+							IosPushUrl: "",
+						}
+						resp, err := messageclient.NewMessage(MessageClient).MultipleSaveMsg(context.Background(), req)
+						if err != nil {
+							logger.Error(fmt.Sprintf("%+v", req), "发站内信出错", err)
+						} else if resp.Code == 1 {
+							logger.Error(fmt.Sprintf("%+v", req), "发送站内信成功")
+						} else {
+							logger.Error(fmt.Sprintf("%+v", req), "发送站内信失败")
+						}
 					}
 					}
 				}
 				}
+				logger.Info(p.TaskName, "站内信推送结束", phones, userIds)
 			}
 			}
-			logger.Info(p.TaskName, "站内信推送结束", phones, userIds)
-		} else {
-			logger.Info(p.TaskName, "没有找到客成部门下要推送的人", Config.KeCheng.DeptId)
 		}
 		}
 	}
 	}
-	TaskConfig.OrderPayTime = nowFormat
-	logger.Info(p.TaskName, "结束。。。", TaskConfig.OrderPayTime, nowFormat)
+	TaskConfig.OrderEachTime = nowFormat
+	logger.Info(p.TaskName, "结束。。。", TaskConfig.OrderEachTime, nowFormat)
 }
 }

+ 1 - 1
pushjyinside/job/timetask.go

@@ -10,7 +10,7 @@ import (
 type TimeTask struct{}
 type TimeTask struct{}
 
 
 func (t *TimeTask) Run() {
 func (t *TimeTask) Run() {
-	go VarTimeTask.RunInTimeLoop("push kc job", "", "", Config.Duration, true, true, nil, func() {
+	go VarTimeTask.RunInTimeLoop("push kecheng job", "", "", Config.Duration, true, true, nil, func() {
 		Jobs.PushKcJob.Execute()
 		Jobs.PushKcJob.Execute()
 		util.WriteSysConfig("./task.json", &TaskConfig)
 		util.WriteSysConfig("./task.json", &TaskConfig)
 	})
 	})

+ 1 - 1
pushjyinside/task.json

@@ -1 +1 @@
-{"orderPayTime":"2024-08-20 00:00:00"}
+{"orderEachTime":"2024-09-02 00:00:00"}

+ 7 - 0
pushjyinside/util/constant.go

@@ -0,0 +1,7 @@
+package util
+
+const (
+	RedisKcOrderTip = "kechengOrderTip_%d"
+	RedisCode       = "pushcache_2_c"
+	Day30Sec        = 2592000
+)

+ 8 - 73
pushjyinside/util/entity.go

@@ -1,76 +1,11 @@
 package util
 package util
 
 
-import (
-	"fmt"
-	. "pushsubscribe/push/config"
-	. "pushsubscribe/push/db"
-
-	"app.yhyue.com/moapp/jybase/encrypt"
-	"app.yhyue.com/moapp/jybase/redis"
-	. "bp.jydev.jianyu360.cn/BaseService/pushpkg/p"
-)
-
-func NewPushParam(dayCount int, mailPush bool, u *UserInfo, sl *SortList) *PushParam {
-	mailContent := ""
-	jpushTitle := ""
-	lastInfoDate := int64(0)
-	titleArray := []string{}
-	infos := &SortList{}
-	infosLength := 0
-	for _, ks := range *sl {
-		info := NewBiddingInfo(ks.Info, ks.Keys)
-		if u.SubPushInactive == -2 {
-			if exists, _ := redis.Exists(Pushcache_2_c, fmt.Sprintf("inactiveChange_%s_%s", u.Id, info.Id)); exists {
-				continue
-			}
-		}
-		infosLength++
-		dayCount++
-		*infos = append(*infos, ks)
-		titleArray = append(titleArray, info.AreaTitle)
-		if infosLength == 1 {
-			jpushTitle = info.ClearTitle
-			lastInfoDate = info.Publishtime
-		}
-		if mailPush && infosLength <= u.SubSet.MaxMailSize { //关于邮件的处理
-			url := fmt.Sprintf("%s/article/mailprivate/%s.html", Config.JianyuDomain, encrypt.CommonEncodeArticle("mailprivate", info.Id))
-			industryClassName := ""
-			industry := ""
-			if info.Subscopeclass != "" {
-				industryClassName = "subscopeclass"
-				industry = info.Subscopeclass
-			}
-			acountClassName := "none_a"
-			if info.Acount != "" {
-				acountClassName = "acount"
-			}
-			areaClassName := ""
-			if info.Area != "" {
-				areaClassName = "area"
-			}
-			typeClassName := ""
-			if info.Infotype != "" {
-				typeClassName = "type"
-			}
-			mailContent += fmt.Sprintf(Config.Mail.Content, infosLength, url, info.HighlightTitle, areaClassName, info.Area, typeClassName, info.Infotype, industryClassName, industry, acountClassName, info.Acount, info.PublishtimeYMD)
-		}
-		if infosLength >= u.SubSet.MaxPushSize {
-			break
-		}
-	}
-	if u.SubPushInactive == -2 {
-		Mgo.UpdateById(Mgo_User, u.Id, map[string]interface{}{
-			"$set": map[string]interface{}{
-				"subpush_inactive": -3,
-			},
-		})
-	}
-	return &PushParam{
-		JpushTitle:   jpushTitle,
-		LastInfoDate: lastInfoDate,
-		TitleArray:   titleArray,
-		Infos:        infos,
-		InfosLength:  infosLength,
-		MailHtml:     fmt.Sprintf(Config.Mail.Html, Config.JianyuDomain, Config.Mail.According, mailContent, Config.JianyuDomain, Config.JianyuDomain, Config.JianyuDomain, Config.JianyuDomain, Config.JianyuDomain, Config.JianyuDomain),
-	}
+type OrderInfo struct {
+	Id          int64
+	UserId      string
+	ProductType string
+	OrderCode   string
+	UserPhone   string
+	StartEnd    string
+	DisKcName   string
 }
 }

+ 0 - 49
pushjyinside/util/rpccall.go

@@ -1,49 +0,0 @@
-package util
-
-import (
-	. "pushsubscribe/push/config"
-	. "pushsubscribe/push/db"
-	"time"
-
-	util "app.yhyue.com/moapp/jybase/common"
-	qrpc "app.yhyue.com/moapp/jybase/rpc"
-	. "bp.jydev.jianyu360.cn/BaseService/pushpkg/p"
-)
-
-var (
-	wxPushPool  = make(chan bool, Config.WxPoolSize)
-	appPushPool = make(chan bool, Config.AppPoolSize)
-)
-
-//微信远程调用,实现模板发送消息
-func SendWeixin(k *UserInfo, wxTmplMsg *qrpc.WxTmplMsg) bool {
-	wxPushPool <- true
-	defer func() {
-		<-wxPushPool
-	}()
-	if Config.WxSleep > 0 {
-		time.Sleep(time.Duration(Config.WxSleep) * time.Millisecond)
-	}
-	ok, err := qrpc.WxSendTmplMsg(Config.WeixinRpcServer, wxTmplMsg)
-	UpdateUserIsPush(Mgo, k.Id, err)
-	return ok
-}
-func SendApp(m map[string]interface{}) bool {
-	appPushPool <- true
-	defer func() {
-		<-appPushPool
-	}()
-	if Config.AppSleep > 0 {
-		time.Sleep(time.Duration(Config.AppSleep) * time.Millisecond)
-	}
-	return qrpc.AppPush(Config.AppPushServiceRpc, m)
-}
-
-//
-func SendPH(m map[string]interface{}) bool {
-	defer util.Catch()
-	if Config.PcHelperSleep > 0 {
-		time.Sleep(time.Duration(Config.PcHelperSleep) * time.Millisecond)
-	}
-	return SendPcHelper(Config.PcHelper, m)
-}

+ 0 - 47
pushjyinside/util/util.go

@@ -1,47 +0,0 @@
-package util
-
-import (
-	"encoding/json"
-	. "pushsubscribe/push/config"
-
-	util "app.yhyue.com/moapp/jybase/common"
-	. "bp.jydev.jianyu360.cn/BaseService/pushpkg/p"
-)
-
-//根据pushspace表中的数据,生成UserInfo
-func NewUserInfoByPushSpaceColl(user map[string]interface{}) *UserInfo {
-	var wxTplMsg *WxTplMsg
-	wxtplmsg, _ := json.Marshal(user["wxtplmsg"])
-	json.Unmarshal(wxtplmsg, &wxTplMsg)
-	ui := &UserInfo{
-		Id:         util.ObjToString(user["userid"]),
-		BaseUserId: util.Int64All(user["baseuserid"]),
-		SubSet: &SubSet{
-			MaxPushSize: util.IntAll(user["maxpushsize"]),
-			MaxMailSize: util.IntAll(user["maxmailsize"]),
-		},
-		PushSet: &PushSet{
-			Email: util.ObjToString(user["email"]),
-			SubSet: &PushSetChild{
-				WxPush:   util.IntAll(user["wxpush"]),
-				AppPush:  util.IntAll(user["apppush"]),
-				MailPush: util.IntAll(user["mailpush"]),
-				RateMode: util.IntAll(user["ratemode"]),
-			},
-		},
-		S_m_openid:      util.ObjToString(user["s_m_openid"]),
-		Phone:           util.ObjToString(user["phone"]),
-		Jpushid:         util.ObjToString(user["jpushid"]),
-		Opushid:         util.ObjToString(user["opushid"]),
-		AppPhoneType:    util.ObjToString(user["appphonetype"]),
-		SubPushInactive: util.IntAll(user["subpushinactive"]),
-		WxTplMsg:        wxTplMsg,
-	}
-	if ui.SubSet.MaxPushSize <= 0 {
-		ui.SubSet.MaxPushSize = Config.MaxPushSize
-	}
-	if ui.SubSet.MaxMailSize <= 0 {
-		ui.SubSet.MaxMailSize = Config.Mail.MaxPushSize
-	}
-	return ui
-}