zhangxinlei1996 1 年間 前
コミット
c4c5da74be

+ 16 - 0
api/application.api

@@ -140,6 +140,19 @@ type (
 	EntInfoReq {
 		EntName string `json:"entName"`
 	}
+
+	PushMsgReq {
+		AppId      string  `header:"appId,default=10000"`
+		BaseUserId int64   `header:"newUserId"`
+		PositionId int64   `header:"positionId,optional"`
+		EntUserId  int64   `header:"entUserId,optional"`
+		EntId      int64   `header:"entId,optional"`
+		Title      string  `json:"title"`         //标题
+		Content    string  `json:"content"`       //内容
+		PcHref     string  `json:"pcHref"`        //pc跳转地址
+		MobileHref string  `json:"mobileHref"`    //移动端跳转地址
+		User       []int64 `json:"user,optional"` //企业用户id
+	}
 )
 
 service crmApplication {
@@ -173,4 +186,7 @@ service crmApplication {
 	@doc "企业详情"
 	@handler   entinfo
 	post /crmApplication/ent/info(EntInfoReq) returns (Reply)
+	@doc "消息推送"
+	@handler pushMsg
+	post /crmApplication/info/push(PushMsgReq) returns (Reply)
 }

+ 6 - 0
api/common/initconfig.go

@@ -29,6 +29,10 @@ var logc entity.Logc
 var dbFile = flag.String("df", "etc/db.yaml", "the db file")
 var DB config.Db
 
+//
+var pushFile = flag.String("pf", "etc/push.yaml", "the push file")
+var Push config.Push
+
 var (
 	MgoBidding    mongodb.MongodbSim
 	MgoEnt        mongodb.MongodbSim
@@ -142,4 +146,6 @@ func init() {
 	UserCenterRpc = usercenter.NewUserCenter(zrpc.MustNewClient(C.UserCenterRpc))
 	FileCenterRpc = filecenter.NewFileCenter(zrpc.MustNewClient(C.FileCenterRpc))
 	BaseCenterRpc = basecenter.NewBaseCenter(zrpc.MustNewClient(C.BaseCenterRpc))
+
+	conf.MustLoad(*pushFile, &Push)
 }

+ 4 - 1
api/crmapplication.go

@@ -12,7 +12,7 @@ import (
 	. "bp.jydev.jianyu360.cn/CRM/application/api/common"
 	"bp.jydev.jianyu360.cn/CRM/application/api/internal/handler"
 	"bp.jydev.jianyu360.cn/CRM/application/api/internal/svc"
-
+	"bp.jydev.jianyu360.cn/CRM/application/api/timetask"
 	"github.com/zeromicro/go-zero/rest"
 )
 
@@ -31,6 +31,9 @@ func main() {
 	ctx := svc.NewServiceContext(C)
 	handler.RegisterHandlers(server, ctx)
 
+	//定时任务
+	go timetask.Run()
+
 	fmt.Printf("Starting server at %s:%d...\n", C.Host, C.Port)
 	server.Start()
 

+ 0 - 3
api/etc/crmapplication.yaml

@@ -24,6 +24,3 @@ BaseCenterRpc:
     - 192.168.3.206:2379
     Key: basecenter.rpc
 TimeTaskSwitch: true
-StationMailHref: https://web-qmx_admin.jydev.jianyu360.com/api/admin
-StationMailAction: /message/sendMessageApi
-TestId: 6103bb722abfa5f4d81bb1d1

+ 36 - 11
api/etc/push.yaml

@@ -1,15 +1,40 @@
 TimeTaskSwitch: true
-StationMailHref: https://web-qmx_admin.jydev.jianyu360.com/api/admin
-StationMailAction: /message/sendMessageApi
-TestId: 6103bb722abfa5f4d81bb1d1
+StationMailHref: "https://web-qmx_admin.jydev.jianyu360.com/api/admin"
+StationMailAction: "/message/sendMessageApi"
+TestId: "6103bb722abfa5f4d81bb1d1"
 SaleClue:
-  Title: 创建销售线索通知
-  Content: %s于%s创建销售线索
+  Create:
+    Title: "创建销售线索通知"
+    Content: "%s于%s创建销售线索"
+    PcHref: "/succbi/crm_system/app/crm.app/task_follow/Intermediate_part/middle_opp_project.spg?E_chance_id=%v"
+    MobileHref: "/jy_mobile/message/msgGuide"
+  Due:
+    Title: "销售线索跟进任务即将到期提醒"
+    Content: "%s即将到期,请及时跟进。"
+    PcHref: "/succbi/crm_system/app/crm.app/task_follow/Intermediate_part/middle_opp_project.spg?E_chance_id=%v"
+    MobileHref: "/jy_mobile/message/msgGuide"
 SaleChance:
-  Title: 创建销售机会通知
-  Content: %s于%s创建销售机会%s
+  Create:
+    Title: "创建销售机会通知"
+    Content: "%s于%s创建销售机会,下次跟进时间为%s"
+    PcHref: "/succbi/crm_system/app/crm.app/task_follow/Intermediate_part/middle_opp_project.spg?E_chance_id=%v"
+    MobileHref: "/jy_mobile/message/msgGuide"
+  Due:
+    Title: "销售机会跟进任务即将到期提醒"
+    Content: "%s即将到期,请及时跟进。"
+    PcHref: "/succbi/crm_system/app/crm.app/task_follow/Intermediate_part/middle_opp_project.spg?E_chance_id=%v"
+    MobileHref: "/jy_mobile/message/msgGuide"
 Custom:
-  Title: 创建客户通知
-  Content: %s于%s创建客户%s
-
-  
+  Create:
+    Title: "创建客户通知"
+    Content: "%s于%s创建客户,下次跟进时间为%s"
+    PcHref: "/succbi/crm_system/app/crm.app/task_follow/Intermediate_part/middle_opp_project.spg?E_chance_id=%v"
+    MobileHref: "/jy_mobile/message/msgGuide"
+  Due:
+    Title: "客户跟进任务即将到期提醒"
+    Content: "%s即将到期,请及时跟进。"
+    PcHref: "/succbi/crm_system/app/crm.app/task_follow/Intermediate_part/middle_opp_project.spg?E_chance_id=%v"
+    MobileHref: "/jy_mobile/message/msgGuide"
+#PushTime: "0 0 8 * * *"
+PushTime: "0 50 13 * * *"
+DueDay: 2

+ 40 - 8
api/internal/config/config.go

@@ -12,14 +12,11 @@ type Config struct {
 		ServerCode string
 		Etcd       []string
 	}
-	UserCenterRpc     zrpc.RpcClientConf
-	FileCenterRpc     zrpc.RpcClientConf
-	OssBucketName     string
-	OssUrl            string
-	BaseCenterRpc     zrpc.RpcClientConf
-	StationMailHref   string
-	StationMailAction string
-	TestId            string
+	UserCenterRpc zrpc.RpcClientConf
+	FileCenterRpc zrpc.RpcClientConf
+	OssBucketName string
+	OssUrl        string
+	BaseCenterRpc zrpc.RpcClientConf
 }
 
 type Db struct {
@@ -28,3 +25,38 @@ type Db struct {
 	Mongo entity.Mongo      `json:"mongo"`
 	Es    entity.EsStruct   `json:"es"`
 }
+
+type Push struct {
+	TimeTaskSwitch    bool
+	StationMailHref   string
+	StationMailAction string
+	TestId            string
+	SaleClue          struct {
+		Create Create
+		Due    Due
+	}
+	SaleChance struct {
+		Create Create
+		Due    Due
+	}
+	Custom struct {
+		Create Create
+		Due    Due
+	}
+	PushTime string
+	DueDay   int
+}
+
+type Create struct {
+	Title      string
+	Content    string
+	PcHref     string
+	MobileHref string
+}
+
+type Due struct {
+	Title      string
+	Content    string
+	PcHref     string
+	MobileHref string
+}

+ 28 - 0
api/internal/handler/pushmsghandler.go

@@ -0,0 +1,28 @@
+package handler
+
+import (
+	"net/http"
+
+	"bp.jydev.jianyu360.cn/CRM/application/api/internal/logic"
+	"bp.jydev.jianyu360.cn/CRM/application/api/internal/svc"
+	"bp.jydev.jianyu360.cn/CRM/application/api/internal/types"
+	"github.com/zeromicro/go-zero/rest/httpx"
+)
+
+func pushMsgHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.PushMsgReq
+		if err := httpx.Parse(r, &req); err != nil {
+			httpx.Error(w, err)
+			return
+		}
+
+		l := logic.NewPushMsgLogic(r.Context(), svcCtx)
+		resp, err := l.PushMsg(&req)
+		if err != nil {
+			httpx.Error(w, err)
+		} else {
+			httpx.OkJson(w, resp)
+		}
+	}
+}

+ 5 - 0
api/internal/handler/routes.go

@@ -62,6 +62,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 				Path:    "/crmApplication/ent/info",
 				Handler: entinfoHandler(serverCtx),
 			},
+			{
+				Method:  http.MethodPost,
+				Path:    "/crmApplication/info/push",
+				Handler: pushMsgHandler(serverCtx),
+			},
 		},
 	)
 }

+ 1 - 0
api/internal/logic/clueaddlogic.go

@@ -39,6 +39,7 @@ func (l *ClueAddLogic) ClueAdd(req *types.ClueAddReq) (resp *types.Reply, err er
 		User:         req.User,
 		FollowUpTime: req.FollowUpTime,
 		CreateName:   req.CreateName,
+		BaseUserId:   req.BaseUserId,
 	}
 	status := clue.Add(l.ctx)
 

+ 2 - 1
api/internal/logic/entinfologic.go

@@ -1,9 +1,10 @@
 package logic
 
 import (
-	"bp.jydev.jianyu360.cn/CRM/application/service"
 	"context"
 
+	"bp.jydev.jianyu360.cn/CRM/application/service"
+
 	"bp.jydev.jianyu360.cn/CRM/application/api/internal/svc"
 	"bp.jydev.jianyu360.cn/CRM/application/api/internal/types"
 

+ 69 - 0
api/internal/logic/pushmsglogic.go

@@ -0,0 +1,69 @@
+package logic
+
+import (
+	"context"
+	"log"
+	"strings"
+
+	"bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/pb"
+	cm "bp.jydev.jianyu360.cn/CRM/application/api/common"
+	"bp.jydev.jianyu360.cn/CRM/application/api/internal/svc"
+	"bp.jydev.jianyu360.cn/CRM/application/api/internal/types"
+	"bp.jydev.jianyu360.cn/CRM/application/service"
+	"github.com/gogf/gf/v2/util/gconv"
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type PushMsgLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewPushMsgLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PushMsgLogic {
+	return &PushMsgLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx,
+	}
+}
+
+func (l *PushMsgLogic) PushMsg(req *types.PushMsgReq) (resp *types.Reply, err error) {
+	resp = &types.Reply{}
+	status := -1
+	baseUserIdArr := []int64{}
+	for _, v := range req.User {
+		resp, err := cm.UserCenterRpc.IdentityByEntUserId(l.ctx, &pb.IdentityReq{
+			Id: v,
+		})
+		if err != nil {
+			log.Println("获取用户职位id信息出错", v, "的信息出错", err)
+			continue
+		} else if resp == nil {
+			log.Println("entuser用户", v, "没有找到职位信息")
+			continue
+		}
+		baseUserIdArr = append(baseUserIdArr, resp.UserId)
+		//查询mgo
+	}
+	u := &service.User{
+		BaseUserIds: baseUserIdArr,
+	}
+	m := u.GetUserId(req.EntId)
+	var kb strings.Builder
+	var vb strings.Builder
+	for k, v := range m {
+		kb.WriteString(k + ",")
+		vb.WriteString(gconv.String(v) + ",")
+		userId := strings.TrimRight(kb.String(), ",")
+		positionId := strings.TrimRight(vb.String(), ",")
+		ok := service.StationMailPush(userId, positionId, req.Title, strings.Replace(req.Content, " ", "%20", -1), req.PcHref, req.MobileHref)
+		if ok {
+			status = 1
+		}
+	}
+	resp.Data = map[string]interface{}{
+		"status": status,
+	}
+	return
+}

+ 13 - 0
api/internal/types/types.go

@@ -143,3 +143,16 @@ type DistributePerson struct {
 type EntInfoReq struct {
 	EntName string `json:"entName"`
 }
+
+type PushMsgReq struct {
+	AppId      string  `header:"appId,default=10000"`
+	BaseUserId int64   `header:"newUserId"`
+	PositionId int64   `header:"positionId,optional"`
+	EntUserId  int64   `header:"entUserId,optional"`
+	EntId      int64   `header:"entId,optional"`
+	Title      string  `json:"title"`         //标题
+	Content    string  `json:"content"`       //内容
+	PcHref     string  `json:"pcHref"`        //pc跳转地址
+	MobileHref string  `json:"mobileHref"`    //移动端跳转地址
+	User       []int64 `json:"user,optional"` //企业用户id
+}

+ 89 - 0
api/timetask/timetask.go

@@ -0,0 +1,89 @@
+package timetask
+
+import (
+	"context"
+	"fmt"
+	"log"
+	"strings"
+	"time"
+
+	"app.yhyue.com/moapp/jybase/date"
+	cm "bp.jydev.jianyu360.cn/CRM/application/api/common"
+	"bp.jydev.jianyu360.cn/CRM/application/service"
+	"github.com/gogf/gf/v2/os/gcron"
+	"github.com/gogf/gf/v2/os/gctx"
+	"github.com/gogf/gf/v2/util/gconv"
+)
+
+func Run() {
+	if cm.Push.TimeTaskSwitch {
+		sendMess()
+	}
+}
+
+func getTime() (string, string) {
+	today := time.Now()
+
+	// 计算两天前的时间
+	twoDaysAgo := today.AddDate(0, 0, -cm.Push.DueDay)
+
+	// 设置时间为 0 点
+	startTime := time.Date(twoDaysAgo.Year(), twoDaysAgo.Month(), twoDaysAgo.Day(), 0, 0, 0, 0, twoDaysAgo.Location())
+
+	// 设置时间为 24 点
+	endTime := startTime.Add(24 * time.Hour)
+	return startTime.Format(date.Date_Full_Layout), endTime.Format(date.Date_Full_Layout)
+}
+
+//发送推送 站内信和微信
+func sendMess() {
+	ctx := gctx.New()
+	_, err := gcron.Add(ctx, cm.Push.PushTime, func(ctx context.Context) {
+		log.Println("start cron")
+		//获取倒计时时间
+		st, et := getTime()
+		cm.CrmMysql.SelectByBath(500, func(l *[]map[string]interface{}) bool {
+			for _, v := range *l {
+				name := gconv.String(v["name"])
+				positionId := gconv.Int64(v["position_id"])
+				source := gconv.Int(v["source"]) //1:线索 2:机会 3:客户
+				sourceId := gconv.Int(v["source_id"])
+				title := cm.Push.SaleClue.Due.Title
+				content := cm.Push.SaleClue.Due.Content
+				pcHref := cm.Push.SaleClue.Due.PcHref
+				mobileHref := cm.Push.SaleClue.Due.MobileHref
+				if source == 2 {
+					title = cm.Push.SaleChance.Due.Title
+					content = cm.Push.SaleChance.Due.Content
+					pcHref = cm.Push.SaleChance.Due.PcHref
+					mobileHref = cm.Push.SaleChance.Due.MobileHref
+				} else if source == 3 {
+					title = cm.Push.Custom.Due.Title
+					content = cm.Push.Custom.Due.Content
+					pcHref = cm.Push.Custom.Due.PcHref
+					mobileHref = cm.Push.Custom.Due.MobileHref
+				}
+				u := &service.User{}
+				resp := u.IdentityByPositionId(positionId)
+				if resp == nil {
+					continue
+				}
+				user := &service.User{
+					BaseUserIds: []int64{resp.UserId},
+				}
+				m := user.GetUserId(resp.EntId)
+				for k, v := range m {
+					service.StationMailPush(k, gconv.String(v), strings.Replace(title, " ", "%20", -1), strings.Replace(fmt.Sprintf(content, name), " ", "%20", -1), fmt.Sprintf(pcHref, sourceId), mobileHref)
+				}
+			}
+			return true
+		}, `select a.name,b.position_id,a.source,a.source_id from task a left join task_team b on (a.id =b.task_id and b.role=1)
+			where a.status!=3 and a.next_follow_time >= ? and a.next_follow_time < ?`, st, et)
+
+		log.Println("end cron")
+	}, "sendMsg")
+	if err != nil {
+		log.Println("cron err:", err)
+	}
+
+}

+ 31 - 9
service/custom.go

@@ -5,6 +5,7 @@ import (
 	"database/sql"
 	"fmt"
 	"log"
+	"strings"
 	"time"
 
 	qu "app.yhyue.com/moapp/jybase/common"
@@ -13,6 +14,7 @@ import (
 	cm "bp.jydev.jianyu360.cn/CRM/application/api/common"
 	"bp.jydev.jianyu360.cn/CRM/application/entity"
 	baseC "bp.jydev.jianyu360.cn/CRM/baseCenter/rpc/pb"
+	"github.com/gogf/gf/v2/util/gconv"
 )
 
 //客户相关
@@ -51,6 +53,9 @@ func (this *CustomService) Add(ctx context.Context) int64 {
 	argsTaskTeam := []interface{}{}
 	//判断处理方式
 	//转办
+	baseUserIdArr := []int64{}
+	customId := int64(-1)
+
 	if this.Types == 2 {
 		transferArr := []int64{}
 		for _, v := range this.User {
@@ -60,12 +65,13 @@ func (this *CustomService) Add(ctx context.Context) int64 {
 			})
 			if err != nil {
 				log.Println("获取用户职位id信息出错", i_entuserid, "的信息出错", err)
-				return 0
+				return -1
 			} else if resp == nil {
 				log.Println("entuser用户", i_entuserid, "没有找到职位信息")
-				return 0
+				return -1
 			}
 			transferArr = append(transferArr, resp.PositionId)
+			baseUserIdArr = append(baseUserIdArr, resp.UserId)
 		}
 
 		//客户
@@ -73,8 +79,9 @@ func (this *CustomService) Add(ctx context.Context) int64 {
 		//任务
 		argsTask = append(argsTask, this.EntId, this.CustomAllName+"的跟进任务", 3, this.PositionId, 1, nowtime, 1, qu.If(this.NextfollowUpTime == 0, nil, nextFollowTime))
 
-		if !SaveCustom(ctx, args, argsTask, argsTaskTeam, this.EmployInfoId, this.EmployCustomId, this.PositionId, this.CreateName, transferArr) {
-			return 0
+		customId = SaveCustom(ctx, args, argsTask, argsTaskTeam, this.EmployInfoId, this.EmployCustomId, this.PositionId, this.CreateName, transferArr)
+		if customId < 0 {
+			return -1
 		}
 	} else if this.Types == 1 {
 		//客户
@@ -84,9 +91,22 @@ func (this *CustomService) Add(ctx context.Context) int64 {
 		//任务团队
 		argsTaskTeam = append(argsTaskTeam, this.PositionId, this.EntUserId, this.CreateName, 1, nowtime)
 		//存库
-		if !SaveCustom(ctx, args, argsTask, argsTaskTeam, this.EmployInfoId, this.EmployCustomId, this.PositionId, this.CreateName, []int64{}) {
-			return 0
+		customId = SaveCustom(ctx, args, argsTask, argsTaskTeam, this.EmployInfoId, this.EmployCustomId, this.PositionId, this.CreateName, []int64{})
+		if customId < 0 {
+			return -1
 		}
+		baseUserIdArr = append(baseUserIdArr, this.BaseUserId)
+	}
+	u := &User{BaseUserIds: baseUserIdArr}
+
+	var kb strings.Builder
+	var vb strings.Builder
+	for k, v := range u.GetUserId(this.EntId) {
+		kb.WriteString(k + ",")
+		vb.WriteString(gconv.String(v) + ",")
+		userId := strings.TrimRight(kb.String(), ",")
+		positionId := strings.TrimRight(vb.String(), ",")
+		StationMailPush(userId, positionId, cm.Push.Custom.Create.Title, fmt.Sprintf(cm.Push.Custom.Create.Content, this.CreateName, strings.Replace(date.NowFormat(YYYYMMDDHHMM), " ", "%20", -1), strings.Replace(time.Unix(this.NextfollowUpTime, 0).Format(YYYYMMDDHHMM), " ", "%20", -1)), fmt.Sprintf(cm.Push.Custom.Create.PcHref, customId), cm.Push.Custom.Create.MobileHref)
 	}
 
 	return 1
@@ -116,11 +136,12 @@ func EmployUpdate(tx *sql.Tx, employ_info_id, employ_custom_id, positionId int64
 	return cm.CrmMysql.UpdateByTx(tx, tablename, map[string]interface{}{"id": id, "position_id": positionId}, map[string]interface{}{key: 1})
 }
 
-func SaveCustom(ctx context.Context, argsCustom, argsTask, argsTaskTeam []interface{}, employ_info_id, employ_custom_id, positionId int64, createPerson string, transferArr []int64) bool {
+func SaveCustom(ctx context.Context, argsCustom, argsTask, argsTaskTeam []interface{}, employ_info_id, employ_custom_id, positionId int64, createPerson string, transferArr []int64) int64 {
+	customId := int64(-1)
 	//存库
-	return cm.CrmMysql.ExecTx("创建客户", func(tx *sql.Tx) bool {
+	cm.CrmMysql.ExecTx("创建客户", func(tx *sql.Tx) bool {
 		//插入客户
-		customId := SaleCustomAdd(tx, argsCustom)
+		customId = SaleCustomAdd(tx, argsCustom)
 		//传过来的argTask没有来源id,需要append
 		argsTask = append(argsTask, customId)
 		//任务车存储
@@ -134,6 +155,7 @@ func SaveCustom(ctx context.Context, argsCustom, argsTask, argsTaskTeam []interf
 		log.Println("SaveCustom err:", customId, taskId, ok)
 		return false
 	})
+	return customId
 }
 
 //SaveLedger 操作台帐相关

+ 30 - 6
service/sale_chance.go

@@ -5,9 +5,10 @@ import (
 	"database/sql"
 	"fmt"
 	"log"
-	"strings"
 	"time"
 
+	"strings"
+
 	qu "app.yhyue.com/moapp/jybase/common"
 	"app.yhyue.com/moapp/jybase/date"
 	"bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/pb"
@@ -50,6 +51,8 @@ func (this *SaleChanceService) Add(ctx context.Context) int64 {
 	//下次跟进时间
 	nextFollowTime := time.Unix(this.NextfollowUpTime, 0).Format(date.Date_Full_Layout)
 
+	baseUserIdArr := []int64{}
+	chanceId := int64(-1)
 	//判断处理方式
 	//转办
 	if this.Types == 2 {
@@ -67,13 +70,16 @@ func (this *SaleChanceService) Add(ctx context.Context) int64 {
 				return -1
 			}
 			transferArr = append(transferArr, resp.PositionId)
+			baseUserIdArr = append(baseUserIdArr, resp.UserId)
 		}
 
 		args = append(args, this.PositionId, this.EntId, this.EntUserId, this.EmployInfoId, this.CustomId, this.BusinessType, this.ChanceName, this.Summary, this.ChanceClassify, qu.If(this.ExpectedOrderTime == 0, nil, expect_deal_time), qu.If(this.ExpectedMoney == 0, nil, this.ExpectedMoney), qu.If(this.Remarks == "", nil, this.Remarks), nowtime, this.CreateName)
 		//任务
 		argsTask = append(argsTask, this.EntId, this.ChanceName+"的跟进任务", 2, this.PositionId, 1, nowtime, 1, qu.If(this.NextfollowUpTime == 0, nil, nextFollowTime))
 
-		if !SaveChange(ctx, args, argsTask, argsTaskTeam, this.EmployInfoId, this.CustomId, this.PositionId, this.BusinessType, this.CreateName, transferArr) {
+		chanceId = SaveChange(ctx, args, argsTask, argsTaskTeam, this.EmployInfoId, this.CustomId, this.PositionId, this.BusinessType, this.CreateName, transferArr)
+
+		if chanceId < 0 {
 			return -1
 		}
 	} else if this.Types == 1 {
@@ -84,9 +90,24 @@ func (this *SaleChanceService) Add(ctx context.Context) int64 {
 		//任务团队
 		argsTaskTeam = append(argsTaskTeam, this.PositionId, this.EntUserId, this.CreateName, 1, nowtime)
 		//存库
-		if !SaveChange(ctx, args, argsTask, argsTaskTeam, this.EmployInfoId, this.CustomId, this.PositionId, this.BusinessType, this.CreateName, []int64{}) {
+		chanceId = SaveChange(ctx, args, argsTask, argsTaskTeam, this.EmployInfoId, this.CustomId, this.PositionId, this.BusinessType, this.CreateName, []int64{})
+		if chanceId < 0 {
 			return -1
 		}
+		baseUserIdArr = append(baseUserIdArr, this.BaseUserId)
+	}
+
+	u := &User{BaseUserIds: baseUserIdArr}
+
+	var kb strings.Builder
+	var vb strings.Builder
+	for k, v := range u.GetUserId(this.EntId) {
+		kb.WriteString(k + ",")
+		vb.WriteString(gconv.String(v) + ",")
+		userId := strings.TrimRight(kb.String(), ",")
+		positionId := strings.TrimRight(vb.String(), ",")
+		StationMailPush(userId, positionId, cm.Push.SaleChance.Create.Title, fmt.Sprintf(cm.Push.SaleChance.Create.Content, this.CreateName, strings.Replace(date.NowFormat(YYYYMMDDHHMM), " ", "%20", -1), strings.Replace(time.Unix(this.NextfollowUpTime, 0).Format(YYYYMMDDHHMM), " ", "%20", -1)), fmt.Sprintf(cm.Push.SaleChance.Create.PcHref, chanceId), cm.Push.SaleChance.Create.MobileHref)
+
 	}
 
 	return 1
@@ -101,11 +122,12 @@ func SaleChangeAdd(tx *sql.Tx, args []interface{}) int64 {
 }
 
 // Save 存库
-func SaveChange(ctx context.Context, argsChange, argsTask, argsTaskTeam []interface{}, employ_info_id, employ_custom_id, positionId, tplId int64, createName string, transferArr []int64) bool {
+func SaveChange(ctx context.Context, argsChange, argsTask, argsTaskTeam []interface{}, employ_info_id, employ_custom_id, positionId, tplId int64, createName string, transferArr []int64) int64 {
 	//存库
-	return cm.CrmMysql.ExecTx("创建机会", func(tx *sql.Tx) bool {
+	changeId := int64(-1)
+	cm.CrmMysql.ExecTx("创建机会", func(tx *sql.Tx) bool {
 		//插入机会
-		changeId := SaleChangeAdd(tx, argsChange)
+		changeId = SaleChangeAdd(tx, argsChange)
 		//传过来的argTask没有来源id,需要append
 		argsTask = append(argsTask, changeId)
 		//任务车存储
@@ -123,6 +145,8 @@ func SaveChange(ctx context.Context, argsChange, argsTask, argsTaskTeam []interf
 		log.Println("save change err: ", changeId, taskId, ok1, ok2, planId)
 		return false
 	})
+
+	return changeId
 }
 
 // TaskExecutePlanAdd 任务执行计划存储

+ 32 - 12
service/sale_clue.go

@@ -5,20 +5,27 @@ import (
 	"database/sql"
 	"fmt"
 	"log"
+	"strings"
 	"time"
 
 	qu "app.yhyue.com/moapp/jybase/common"
 	"app.yhyue.com/moapp/jybase/date"
+	"app.yhyue.com/moapp/jybase/encrypt"
 	"bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/pb"
 	cm "bp.jydev.jianyu360.cn/CRM/application/api/common"
 	"bp.jydev.jianyu360.cn/CRM/application/entity"
+	"github.com/gogf/gf/v2/util/gconv"
 )
 
+var Se = encrypt.SimpleEncrypt{Key: "topnet"}
+var YYYYMMDDHHMM = "2006-01-02 15:04" //%20用于转义
+
 //线索相关
 type SaleClueService struct {
 	PositionId   int64
 	EntId        int64
 	EntUserId    int64
+	BaseUserId   int64
 	ClueName     string
 	CluesSource  string
 	Summary      string
@@ -36,12 +43,12 @@ func (this *SaleClueService) Add(ctx context.Context) int64 {
 	args := []interface{}{}
 	argsTask := []interface{}{}
 	argsTaskTeam := []interface{}{}
-	// userIds, positionIds := "", ""
+	baseUserIdArr := []int64{}
+	clueId := int64(-1)
 	//判断处理方式
 	//转办
 	if this.Types == 2 {
 		transferArr := []int64{}
-		baseUserIdArr := []int64{}
 		for _, v := range this.User {
 			i_entuserid := v
 			resp, err := cm.UserCenterRpc.IdentityByEntUserId(ctx, &pb.IdentityReq{
@@ -58,15 +65,13 @@ func (this *SaleClueService) Add(ctx context.Context) int64 {
 			baseUserIdArr = append(baseUserIdArr, resp.UserId)
 			//查询mgo
 		}
-		// &User{
-		// 	baseUserIds
-		// }
+
 		//线索
 		args = append(args, this.PositionId, this.EntId, this.EntUserId, this.ClueName, this.CluesSource, this.Summary, this.EmployInfoId, 0, nowtime, this.CreateName)
 		//任务
 		argsTask = append(argsTask, this.EntId, this.ClueName+"的跟进任务", 1, this.PositionId, 1, nowtime, 1, qu.If(this.FollowUpTime == 0, nil, nextFollowTime))
-
-		if !Save(ctx, args, argsTask, argsTaskTeam, this.EmployInfoId, 0, this.PositionId, this.CreateName, transferArr) {
+		clueId = Save(ctx, args, argsTask, argsTaskTeam, this.EmployInfoId, 0, this.PositionId, this.CreateName, transferArr)
+		if clueId < 0 {
 			return -1
 		}
 	} else if this.Types == 1 {
@@ -77,12 +82,25 @@ func (this *SaleClueService) Add(ctx context.Context) int64 {
 		//任务团队
 		argsTaskTeam = append(argsTaskTeam, this.PositionId, this.EntUserId, this.CreateName, 1, nowtime)
 		//存库
-		if !Save(ctx, args, argsTask, argsTaskTeam, this.EmployInfoId, 0, this.PositionId, this.CreateName, []int64{}) {
+		clueId = Save(ctx, args, argsTask, argsTaskTeam, this.EmployInfoId, 0, this.PositionId, this.CreateName, []int64{})
+		if clueId < 0 {
 			return -1
 		}
+		baseUserIdArr = append(baseUserIdArr, this.BaseUserId)
+	}
+	u := &User{BaseUserIds: baseUserIdArr}
+
+	var kb strings.Builder
+	var vb strings.Builder
+	for k, v := range u.GetUserId(this.EntId) {
+		kb.WriteString(k + ",")
+		vb.WriteString(gconv.String(v) + ",")
+		userId := strings.TrimRight(kb.String(), ",")
+		positionId := strings.TrimRight(vb.String(), ",")
+		StationMailPush(userId, positionId, cm.Push.SaleClue.Create.Title, fmt.Sprintf(cm.Push.SaleClue.Create.Content, this.CreateName, strings.Replace(date.NowFormat(YYYYMMDDHHMM), " ", "%20", -1)), fmt.Sprintf(cm.Push.SaleClue.Create.PcHref, clueId), cm.Push.SaleClue.Create.MobileHref)
 	}
-	// StationMailPush
 	return 1
+
 }
 
 //SaleClueAdd 线索存储
@@ -123,11 +141,12 @@ func TaskAdd(tx *sql.Tx, args, taskTeamArgs []interface{}, transferArr []int64,
 }
 
 //Save 存库
-func Save(ctx context.Context, argsClue, argsTask, argsTaskTeam []interface{}, employ_info_id, employ_custom_id, positionId int64, createName string, transferArr []int64) bool {
+func Save(ctx context.Context, argsClue, argsTask, argsTaskTeam []interface{}, employ_info_id, employ_custom_id, positionId int64, createName string, transferArr []int64) int64 {
+	clueId := int64(-1)
 	//存库
-	return cm.CrmMysql.ExecTx("创建线索", func(tx *sql.Tx) bool {
+	cm.CrmMysql.ExecTx("创建线索", func(tx *sql.Tx) bool {
 		//插入线索
-		clueId := SaleClueAdd(tx, argsClue)
+		clueId = SaleClueAdd(tx, argsClue)
 		//传过来的argTask没有来源id,需要append
 		argsTask = append(argsTask, clueId)
 		//任务车存储
@@ -142,4 +161,5 @@ func Save(ctx context.Context, argsClue, argsTask, argsTaskTeam []interface{}, e
 		log.Println("save clue err: ", clueId, taskId, ok1, ok2)
 		return false
 	})
+	return clueId
 }

+ 11 - 8
service/sendMsg.go

@@ -5,6 +5,8 @@ import (
 	"encoding/json"
 	"fmt"
 	"log"
+	"strconv"
+	"time"
 
 	qu "app.yhyue.com/moapp/jybase/common"
 	"app.yhyue.com/moapp/jybase/date"
@@ -25,33 +27,34 @@ func FormatUserId(useridArr []string) (userids string) {
 }
 
 //站内信推送
-func StationMailPush(userIds, positionIds, title, content, pcLandingPage, appLandingPage, wxLandingPage string) {
+func StationMailPush(userId, positionId, title, content, pcHref, mobileHref string) bool {
+	pcLandingPage := "/front/sess/" + Se.EncodeString(positionId+",positionId,"+strconv.Itoa(int(time.Now().Unix()))+",") + "__" + Se.EncodeString(pcHref)
+	wxAppLandingPage := "/front/sess/" + Se.EncodeString(positionId+",positionId,"+strconv.Itoa(int(time.Now().Unix()))+",") + "__" + Se.EncodeString(mobileHref)
 	href := fmt.Sprintf("%s?_action=%s&userIds=%s&msgType=11&title=%s&content=%s&link=%s&sendMode=2&sendTime=%s&androidUrl=%s&iosUrl=%s&weChatUrl=%s&_token=12311&reqSource=1&callPlatform=crm&menuname=message&positionIds=%s",
-		cm.C.StationMailHref, cm.C.StationMailAction, userIds, title, content, pcLandingPage, date.NowFormat(date.Date_Short_Layout), appLandingPage, appLandingPage, wxLandingPage, positionIds)
+		cm.Push.StationMailHref, cm.Push.StationMailAction, userId, title, content, pcLandingPage, date.NowFormat(date.Date_Short_Layout), wxAppLandingPage, wxAppLandingPage, wxAppLandingPage, positionId)
 	log.Println(href)
 	resp := Get(href, nil)
-	log.Println(resp)
+	log.Println("resp:", resp)
 	ret := map[string]interface{}{}
 	err := json.Unmarshal([]byte(resp), &ret)
 	if err != nil {
-		log.Println(err)
-		return
+		return false
 	}
 	if ret != nil && len(ret) > 0 {
 		if data := qu.ObjToMap(ret["data"]); data != nil && len(*data) > 0 {
 			if qu.Int64All((*data)["status"]) != 1 {
-				log.Println("推送失败")
+				return false
 			}
 		}
 	}
-	return
+	return true
 }
 
 //公共get方法
 func Get(url string, param map[string]interface{}) (str string) {
 	ctx := context.Background()
 	if r, err := g.Client().Get(ctx, url, param); err != nil {
-		g.Log().Error(ctx, err)
+		log.Println("get err:", err)
 	} else {
 		defer r.Close()
 		str = r.ReadAllString()

+ 24 - 2
service/user.go

@@ -1,8 +1,12 @@
 package service
 
 import (
+	"log"
+
 	"app.yhyue.com/moapp/jybase/mongodb"
+	"bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/pb"
 	cm "bp.jydev.jianyu360.cn/CRM/application/api/common"
+	"github.com/gogf/gf/v2/os/gctx"
 	"github.com/gogf/gf/v2/util/gconv"
 )
 
@@ -10,7 +14,7 @@ type User struct {
 	BaseUserIds []int64
 }
 
-func (this *User) GetUserId([]int64) map[string]int64 {
+func (this *User) GetUserId(entId int64) map[string]int64 {
 	m := map[string]int64{}
 	data, ok := cm.Mgo.Find("user", map[string]interface{}{
 		"base_user_id": map[string]interface{}{
@@ -19,8 +23,26 @@ func (this *User) GetUserId([]int64) map[string]int64 {
 	}, nil, `{"_id":1,"base_user_id":1}`, false, -1, -1)
 	if ok && data != nil && len(*data) > 0 {
 		for _, v := range *data {
-			m[mongodb.BsonIdToSId(v["_id"])] = gconv.Int64(v["base_user_id"])
+			mdata := cm.BaseMysql.SelectBySql(`SELECT id FROM base_position WHERE user_id =? AND ent_id =? LIMIT 1`, gconv.Int64(v["base_user_id"]), entId)
+			if mdata != nil && len(*mdata) > 0 {
+				m[mongodb.BsonIdToSId(v["_id"])] = gconv.Int64((*mdata)[0]["id"])
+			}
 		}
 	}
 	return m
 }
+
+func (this *User) IdentityByPositionId(positionId int64) *pb.Identity {
+	resp, err := cm.UserCenterRpc.IdentityByPositionId(gctx.New(), &pb.IdentityReq{
+		Id: positionId,
+	})
+	if err != nil {
+		log.Println("获取用户职位id信息出错", positionId, "的信息出错", err)
+		return nil
+	} else if resp == nil {
+		log.Println("positionId用户", positionId, "没有找到职位信息")
+		return nil
+	}
+
+	return resp
+}