Browse Source

Merge remote-tracking branch 'origin/feature/v1.5.18' into dev_v1.5.18_wh

WH01243 5 months ago
parent
commit
97ff4f51ba

+ 2 - 2
clueEs/go.mod

@@ -3,13 +3,14 @@ module clueEs
 go 1.20
 
 require (
+	app.yhyue.com/moapp/jybase v0.0.0-20240805110713-0c17face82c4
+	github.com/robfig/cron/v3 v3.0.1
 	github.com/segmentio/kafka-go v0.4.47
 	github.com/spf13/cobra v1.8.1
 	jygit.jydev.jianyu360.cn/data_processing/common_utils v0.0.0-20240202055658-e2ef72e18b40
 )
 
 require (
-	app.yhyue.com/moapp/jybase v0.0.0-20240805110713-0c17face82c4 // indirect
 	github.com/PuerkitoBio/goquery v1.8.0 // indirect
 	github.com/andybalholm/cascadia v1.3.1 // indirect
 	github.com/dchest/captcha v1.0.0 // indirect
@@ -29,7 +30,6 @@ require (
 	github.com/xdg-go/stringprep v1.0.4 // indirect
 	github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
 	go.mongodb.org/mongo-driver v1.10.1 // indirect
-	go.uber.org/multierr v1.10.0 // indirect
 	golang.org/x/crypto v0.14.0 // indirect
 	golang.org/x/net v0.17.0 // indirect
 	golang.org/x/sync v0.1.0 // indirect

+ 3 - 12
clueEs/go.sum

@@ -1,10 +1,4 @@
 app.yhyue.com/moapp/esv1 v0.0.0-20220414031211-3da4123e648d/go.mod h1:91/lSD/hS+ckMVP3WdidRzDhC60lLMdyce9QHy0cSMA=
-app.yhyue.com/moapp/jybase v0.0.0-20240626030750-115a3c0929fb h1:LstR4tQbICqo2MO0A6za4rci4Y/lw+Nf898GlImARZM=
-app.yhyue.com/moapp/jybase v0.0.0-20240626030750-115a3c0929fb/go.mod h1:XHNATN6tsJKHdCB0DbUtFdPPHXexTUFyB3RlO+lUUoM=
-app.yhyue.com/moapp/jybase v0.0.0-20240805074155-db07f61335b3 h1:Cu80hl1f3ZOOx4jFROfOzjmnsVTciRltfnY1lMgqVN4=
-app.yhyue.com/moapp/jybase v0.0.0-20240805074155-db07f61335b3/go.mod h1:XHNATN6tsJKHdCB0DbUtFdPPHXexTUFyB3RlO+lUUoM=
-app.yhyue.com/moapp/jybase v0.0.0-20240805105653-d9352550f0b6 h1:nkQCwvoH6TGpt+jKQoafgLR+u5Lkw9OSro4XCqJ2qTc=
-app.yhyue.com/moapp/jybase v0.0.0-20240805105653-d9352550f0b6/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=
 cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
@@ -190,6 +184,8 @@ github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R
 github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
 github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
 github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
+github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
+github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
 github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
 github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
 github.com/segmentio/kafka-go v0.4.47 h1:IqziR4pA3vrZq7YdRxaT3w1/5fvIH5qpCwstUanQQB0=
@@ -214,8 +210,8 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
 github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
+github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
 github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
-github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
 github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
 github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
 github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
@@ -250,16 +246,11 @@ go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
 go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
 go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
 go.uber.org/goleak v1.1.12/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
-go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
 go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
 go.uber.org/multierr v1.8.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak=
-go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
-go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
 go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo=
 go.uber.org/zap v1.21.0/go.mod h1:wjWOCqI0f2ZZrJF/UufIOkiC8ii6tm1iqIsLo76RfJw=
 go.uber.org/zap v1.22.0/go.mod h1:H4siCOZOrAolnUPJEkfaSjDqyP+BDS0DdDWzwcgt3+U=
-go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
-go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
 golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
 golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=

+ 47 - 1
clueEs/main.go

@@ -5,6 +5,7 @@ import (
 	"context"
 	"encoding/json"
 	"fmt"
+	"github.com/robfig/cron/v3"
 	"github.com/segmentio/kafka-go"
 	"github.com/spf13/cobra"
 	util "jygit.jydev.jianyu360.cn/data_processing/common_utils"
@@ -16,6 +17,8 @@ import (
 
 var (
 	Tidb *mysqldb.Mysql
+
+	Pici int64
 )
 
 func init() {
@@ -27,6 +30,7 @@ func init() {
 		PassWord: "Tibi#20211222",
 	}
 	Tidb.Init()
+
 }
 
 func main() {
@@ -38,16 +42,28 @@ func main() {
 	if err := rootCmd.Execute(); err != nil {
 		fmt.Println("rootCmd.Execute failed", err.Error())
 	}
+
+	select {}
 }
 
 func addData() *cobra.Command {
+
 	cmdClient := &cobra.Command{
 		Use:   "add",
 		Short: "Start processing add data",
 		Run: func(cmd *cobra.Command, args []string) {
-			taskAdd()
+			//taskAdd()
+
+			//taskAdd1()
+			crn := cron.New(cron.WithSeconds())
+			cronstr := "0 */5 * * * *"
+			crn.AddFunc(cronstr, func() {
+				taskAdd1()
+			})
+			crn.Start()
 		},
 	}
+	cmdClient.Flags().Int64VarP(&Pici, "pici", "c", 0, "pici time")
 	return cmdClient
 }
 
@@ -81,6 +97,36 @@ func taskAdd() {
 	}
 }
 
+func taskAdd1() {
+	sql := `SELECT id, uid, userid, position_id, seatNumber, is_assign, comeintime, createtime, updatetime, cluename FROM dwd_f_crm_clue_info WHERE updatetime >= ? ORDER BY id ASC`
+	sql1 := `SELECT count(1) FROM dwd_f_crm_clue_info WHERE updatetime >= ?`
+	log.Println("轮次开始,查询到数据量: ", Tidb.CountBySql(sql1, util.FormatDateByInt64(&Pici, util.Date_Full_Layout)))
+	info := Tidb.SelectBySql(sql, util.FormatDateByInt64(&Pici, util.Date_Full_Layout))
+	if info != nil && len(*info) > 0 {
+		for _, data := range *info {
+			save := make(map[string]interface{})
+			for _, v := range []string{"id", "uid", "userid", "position_id", "seatNumber", "is_assign", "comeintime", "createtime", "updatetime", "cluename"} {
+				if v == "id" {
+					save[v] = fmt.Sprint(data[v])
+				} else if v == "updatetime" {
+					t1, _ := data[v].(time.Time)
+					save[v] = t1.Unix()
+					if t1.Unix() > Pici {
+						Pici = t1.Unix()
+					}
+				} else if v == "comeintime" || v == "createtime" {
+					t1, _ := data[v].(time.Time)
+					save[v] = t1.Unix()
+				} else {
+					save[v] = data[v]
+				}
+			}
+			elastic.UpdateNew(esIndex, save)
+		}
+	}
+	log.Println(fmt.Sprintf("轮次结束,last time: %d", Pici))
+}
+
 func formatMsg(msg []byte) {
 	msgInfo := make(map[string]interface{})
 	err := json.Unmarshal(msg, &msgInfo)

+ 1 - 1
clueEs/task.go

@@ -14,7 +14,7 @@ var (
 	saveEs []map[string]interface{}
 
 	SaveEsLock = &sync.Mutex{}
-	esIndex    = ""
+	esIndex    = "clue_info"
 )
 
 // @Author jianghan

+ 84 - 13
clueSync/autoTask.go

@@ -1,6 +1,7 @@
 package main
 
 import (
+	"app.yhyue.com/moapp/jybase/mongodb"
 	"database/sql"
 	"fmt"
 	"github.com/gogf/gf/v2/util/gconv"
@@ -413,6 +414,7 @@ func Thaw() {
 				if TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, map[string]interface{}{
 					"is_assign":   0,
 					"position_id": 0,
+					"seatNumber":  nil,
 				}) {
 					TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
 						"clue_id":      clueId,
@@ -550,12 +552,20 @@ func LockHandle() {
 						"id": clue_id,
 					}, 3, "")
 				}
-			} else if company_nature == 0 && company_verification == 1 && position_id != "" {
+			} else if company_nature == 0 && company_verification == 1 {
 				//已锁定处理
-				if lock_status != 1 {
+				if position_id != "" {
 					go UpdateData(1, map[string]interface{}{
-						"cluename": cluename,
+						"cluename":             cluename,
+						"company_verification": 1,
+						"company_nature":       0,
 					}, 1, position_id)
+				} else {
+					go UpdateData(2, map[string]interface{}{
+						"cluename":             cluename,
+						"company_verification": 1,
+						"company_nature":       0,
+					}, 2, "")
 				}
 			} else {
 				//未锁定处理
@@ -572,15 +582,76 @@ func LockHandle() {
 }
 
 func UpdateData(lockStatus int64, query map[string]interface{}, status int, positionId string) {
-	if status != 1 {
-		TiDb.Update("dwd_f_crm_clue_info", query, map[string]interface{}{
-			"lock_status": lockStatus,
-		})
-	} else {
-		TiDb.Update("dwd_f_crm_clue_info", query, map[string]interface{}{
-			"lock_status":      lockStatus,
-			"lock_position_id": positionId,
-		})
-	}
+	TiDb.Update("dwd_f_crm_clue_info", query, map[string]interface{}{
+		"lock_status":      lockStatus,
+		"lock_position_id": positionId,
+	})
+}
 
+// 大会员子账号不作为电销线索
+func ClueToDxTask() {
+	//把所-5有的用户刷至公海
+	ok := TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"is_assign": -5}, map[string]interface{}{"is_assign": 0, "seatNumber": nil, "position_id": 0})
+	if !ok {
+		log.Println("更新dwd_f_crm_clue_info处理子账号出错")
+		return
+	}
+	//查询在客成的用户
+	res := TiDb.Query("SELECT clue_id,ent_id FROM `dwd_f_csm_customer_info` WHERE is_transfer = 0")
+	if res == nil || len(*res) <= 0 {
+		log.Println("查dwd_f_csm_customer_info 客成用户异常")
+		return
+	}
+	log.Println("客成用户量:", len(*res))
+	for _, val := range *res {
+		//log.Println("ent_id", val["ent_id"])
+		clue_id := gconv.Int(val["clue_id"])
+		childIds := []string{}
+		if gconv.String(val["ent_id"]) == "" || gconv.String(val["ent_id"]) == "0" {
+			continue
+		}
+		if mongodb.IsObjectIdHex(gconv.String(val["ent_id"])) { //mongodb  个人身份大会员
+			//查询个人大会员下的子账号
+			query := map[string]interface{}{"s_member_mainid": gconv.String(val["ent_id"])}
+			childAccount, _ := Mgo.Find("user", query, "", `"_id":1`, false, -1, -1)
+			if childAccount != nil && len(*childAccount) > 0 {
+				log.Println("个人大会员子账号数量:", gconv.String(val["ent_id"]), len(*childAccount))
+				for _, v := range *childAccount {
+					childIds = append(childIds, mongodb.BsonIdToSId(v["_id"]))
+				}
+			}
+		} else { //企业大会员
+			//根据企业id查询企业下的员工
+			if gconv.Int(val["ent_id"]) == 0 {
+				continue
+			}
+			data := TiDb.Query("SELECT userid,uid FROM dwd_f_userbase_id_mapping WHERE ent_id = ?", gconv.Int(val["ent_id"]))
+			if data != nil && len(*data) > 0 {
+				log.Println("企业下员工数:", gconv.Int(val["ent_id"]), len(*data))
+				for _, vv := range *data {
+					childIds = append(childIds, gconv.String(vv["userid"]))
+				}
+			}
+		}
+		//更新线索信息
+		if len(childIds) > 0 {
+			ids := ""
+			for k, vv := range childIds {
+				if k == 0 {
+					ids += fmt.Sprintf("'%s'", vv)
+				} else {
+					ids += fmt.Sprintf(",'%s'", vv)
+				}
+			}
+			//log.Println("线索ids:", ids)
+			sql := fmt.Sprintf("UPDATE dwd_f_crm_clue_info SET is_assign = -5 WHERE id != %d and userid IN (%s)", clue_id, ids)
+			log.Println("sql:", sql)
+			up := TiDb.UpdateOrDeleteBySql(sql)
+			if up < 0 {
+				log.Println("更新线索为-5出错", childIds)
+				return
+			}
+		}
+	}
+	log.Println("定时任务完成")
 }

+ 47 - 16
clueSync/config.go

@@ -1,9 +1,9 @@
 package main
 
 import (
-	"log"
-
 	"app.yhyue.com/moapp/jybase/common"
+	"gopkg.in/gomail.v2"
+	"log"
 )
 
 type (
@@ -31,6 +31,8 @@ type (
 		ActiveTime              string  `json:"activeTime"`
 		RebindTime              string  `json:"rebindTime"`
 		InviteTime              string  `json:"inviteTime"`
+		ActivityTime            string  `json:"activityTime"`
+		LastKcChangeTime        string  `json:"lastKcChangeTime"`
 	}
 	DB struct {
 		CornExp1      int64  `json:"cornexp1"`
@@ -176,22 +178,51 @@ type (
 			UserName string `json:"user	Name"`
 			Password string `json:"password"`
 		} `json:"es"`
-		ProductArr      []string          `json:"productArr"`
-		RedisServer     string            `json:"redisServer"`
-		AllocationCap   int64             `json:"allocationCap"`
-		WarningValue    int64             `json:"warningValue"`
-		CornMail        string            `json:"corn_mail"`
-		RegTimes        int               `json:"regTimes"`
-		NameToMail      map[string]string `json:"nameToMail"`
-		ThawDay         int64             `json:"thawDay"`
-		LoopType        int64             `json:"loopType"`
-		Sourceid        string            `json:"sourceid"`
-		AbhEmail        string            `json:"abhEmail"`
-		AfEmail         string            `json:"afEmail"`
-		NewRegistration int64             `json:"newRegistration"`
-		OperationEmail  []string          `json:"operationEmail"`
+		ProductArr       []string          `json:"productArr"`
+		RedisServer      string            `json:"redisServer"`
+		AllocationCap    int64             `json:"allocationCap"`
+		WarningValue     int64             `json:"warningValue"`
+		CornMail         string            `json:"corn_mail"`
+		RegTimes         int               `json:"regTimes"`
+		NameToMail       map[string]string `json:"nameToMail"`
+		ThawDay          int64             `json:"thawDay"`
+		LoopType         int64             `json:"loopType"`
+		Sourceid         string            `json:"sourceid"`
+		AbhEmail         string            `json:"abhEmail"`
+		AfEmail          string            `json:"afEmail"`
+		NewRegistration  int64             `json:"newRegistration"`
+		OperationEmail   []string          `json:"operationEmail"`
+		ExpirationPeriod int               `json:"expirationPeriod"` //客成到期周期
+		HandoverCycle    int64             `json:"handoverCycle"`    //移交周期
+		CustomerTime     int64             `json:"customerTime"`     //客成时间
+		KeCheng          struct {
+			DeptId int64  `json:"deptId"`
+			Title  string `json:"title"`
+			Mail   struct {
+				Table       string `json:"table"`
+				Content     string `json:"content"`
+				ServiceList string `json:"serviceList"`
+				ReturnMoney string `json:"returnMoney"`
+			} `json:"mail"`
+			Message            string `json:"message"`
+			MessageServiceList string `json:"messageServiceList"`
+			MessageReturnMoney string `json:"messageReturnMoney"`
+			Admin              string `json:"admin"`
+		} `json:"keCheng"`
+		EntId int       `json:"entId"`
+		Mail  GmailAuth `json:"mail"` //邮箱配置
+
 	}
 )
+type GmailAuth struct {
+	SmtpHost string //邮箱服务器
+	SmtpPort int    //邮箱端口
+	User     string //用户
+	Pwd      string //密码
+	PoolChan chan *gomail.Dialer
+	PoolSize int
+	ReTry    int
+}
 
 var AreaCode = map[string]string{}
 var CodeArea = map[string]string{}

+ 1 - 25
clueSync/config.json

@@ -1,25 +1 @@
-{
-  "lastOrderId": 258784,
-  "lastOrderClueId": "2024-05-25 02:23:21",
-  "lastUserId": "2024-05-20 15:40:02",
-  "lastXcxUserId": "2024-07-09 14:59:37",
-  "lastId": "66cd4d3ae83797f8bf5e7ca2",
-  "lastOrderTime": "2023-04-25 00:00:00",
-  "lastUserTime": "2024-07-09 11:54:02",
-  "lastSubscribeId": "64547124b487f52aade52c80",
-  "lastMessageTime": "2024-06-20 17:54:18",
-  "lastkcTime": "",
-  "lastEverythingTime": "",
-  "lastEventRegTime": "",
-  "lastReadClueTime": "",
-  "bigSaleTime": 1718241923,
-  "bigOrderTime": "2024-06-12 17:01:39",
-  "marketSaleTime": 1708160200,
-  "advisoryCommitteeTime": 1724136683,
-  "selectionDepartmentTime": 0,
-  "allocationTime": "2024-07-01 14:59:37",
-  "allocationRatio": 2,
-  "activeTime": "2024-07-01 14:59:37",
-  "rebindTime": "2024-08-27 16:10:27",
-  "inviteTime": "2024-11-10 10:47:16"
-}
+{"lastOrderId":260273,"lastOrderClueId":"2024-09-19 11:51:37","lastUserId":"2024-05-20 15:40:02","lastXcxUserId":"2024-07-09 14:59:37","lastId":"66cd4d3ae83797f8bf5e7ca2","lastOrderTime":"2023-04-25 00:00:00","lastUserTime":"2024-07-09 11:54:02","lastSubscribeId":"6459d89a8edef707156e9cc6","lastMessageTime":"2024-07-16 14:26:26","lastkcTime":"2025-01-08 11:18:00","lastEverythingTime":"","lastEventRegTime":"","lastReadClueTime":"","bigSaleTime":1718241923,"bigOrderTime":"2024-06-12 17:01:39","marketSaleTime":1708160200,"advisoryCommitteeTime":1724136683,"selectionDepartmentTime":0,"allocationTime":"2024-07-01 14:59:37","allocationRatio":2,"activeTime":"2024-07-01 14:59:37","rebindTime":"2024-08-27 16:10:27","inviteTime":"2024-11-20 14:42:11","lastKcChangeTime":"2025-01-22 15:22:05"}

+ 25 - 1
clueSync/db.json

@@ -161,5 +161,29 @@
   "sourceid": "88",
   "afEmail": "wanghao@topnet.net.cn",
   "abhEmail": "wanghao@topnet.net.cn",
-  "newRegistration": 1
+  "newRegistration": 1,
+  "expirationPeriod": 30,
+  "handoverCycle": 60,
+  "customerTime": 1603846400,
+  "mail": {
+    "smtpHost": "smtp.exmail.qq.com",
+    "smtpPort": 465,
+    "user": "public03@topnet.net.cn",
+    "pwd": "ue9Rg9Sf4CVtdm5a"
+  },
+  "kecheng":{
+    "deptId":59005,
+    "title":"客户移交客户成功组",
+    "mail":{
+      "content":"<style> *,body,html{margin:10px;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;vertical-align:top;display:inline-block;}.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><tr><td class='tit'>订单编号:</td><td>%s</td></tr><tr><td class='tit'>合同金额:</td><td>%.2f</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>%s</table>",
+      "serviceList":"<tr><td class='tit'>服务列表:</td><td>%s</td></tr>",
+      "returnMoney":"<tr><td class='tit'>回款金额:</td><td>%.2f</td></tr>"
+    },
+    "message":"该订单用户已经完成支付,烦请对接后续售后服务事项,谢谢!\n产品名称:%s 公司名称:%s 联系方式:%s 联系人姓名:%s 订单编号:%s 合同金额:%.2f 使用起止时间:%s 分配客成:%s 签署销售:%s%s",
+    "messageServiceList":" 服务列表:%s",
+    "messageReturnMoney":" 回款金额:%.2f",
+    "admin": "郑慧慧"
+  },
+  "entId": 25917
 }

+ 38 - 403
clueSync/everything.go

@@ -412,31 +412,32 @@ func bigCustomer() {
 					if strings.HasPrefix(bt, "03") || bt == "0102" {
 						continue
 					}
+					/*s_sourceid := common.ObjToString((*userData)["s_sourceid"])
+					if s_sourceid == db.Sourceid {
+						//安博会数据
+						abhList = append(abhList, map[string]interface{}{
+							"createTime":       nowTime,
+							"lastUpdateTime":   nowTime,
+							"uid":              uid,
+							"userid":           userid,
+							"username":         username,
+							"usernickname":     usernickname,
+							"company":          company,
+							"job":              job,
+							"phone":            phone,
+							"email":            email,
+							"source":           source,
+							"belongTo":         belongTo,
+							"interest":         interest,
+							"data_requirement": data_requirement,
+						})
+						if gconv.Int64(v["createtime"]) > bigSaleTime {
+							bigSaleTime = gconv.Int64(v["createtime"])
+						}
+						continue
+					}*/
 				}
-				s_sourceid := common.ObjToString((*userData)["s_sourceid"])
-				if s_sourceid == db.Sourceid {
-					//安博会数据
-					abhList = append(abhList, map[string]interface{}{
-						"createTime":       nowTime,
-						"lastUpdateTime":   nowTime,
-						"uid":              uid,
-						"userid":           userid,
-						"username":         username,
-						"usernickname":     usernickname,
-						"company":          company,
-						"job":              job,
-						"phone":            phone,
-						"email":            email,
-						"source":           source,
-						"belongTo":         belongTo,
-						"interest":         interest,
-						"data_requirement": data_requirement,
-					})
-					if gconv.Int64(v["createtime"]) > bigSaleTime {
-						bigSaleTime = gconv.Int64(v["createtime"])
-					}
-					continue
-				}
+
 				dataArr = append(dataArr, map[string]interface{}{
 					"createTime":       nowTime,
 					"lastUpdateTime":   nowTime,
@@ -612,13 +613,8 @@ func bigCustomer() {
 			if err != nil {
 				log.Println("xls error", err, dir)
 			} else {
-				gmail := &mail.GmailAuth{
-					SmtpHost: "smtp.exmail.qq.com",
-					SmtpPort: 465,
-					User:     "public03@topnet.net.cn",
-					Pwd:      "ue9Rg9Sf4CVtdm5a",
-				}
-				status := mail.GSendMail_q("剑鱼标讯", email, "", "", fileName, detailName, dir, fileName+".xlsx", gmail)
+
+				status := mail.GSendMail_q("剑鱼标讯", email, "", "", fileName, detailName, dir, fileName+".xlsx", &Gmail)
 				if status {
 					log.Println("send mail success", fileName, email)
 				}
@@ -638,369 +634,6 @@ func IsInternal(phone string) bool {
 	return false
 }
 
-/*
-// 咨询组线索
-
-	func AdvisoryCommittee() {
-		runOk := getRunOk()
-		if !runOk {
-			log.Println("不是工作日,任务暂停")
-			return
-		}
-		log.Println("咨询部线索定时任务开始")
-		dataArr := []map[string]interface{}{}
-		filterArr := []string{"-pc", "-app", "-wx", "-h5"}
-		sourceMap := map[string]string{} //根据留资维表:tidb/Jianyu_subjectdb/d_saleleads_code
-		saleSource := TiDb.SelectBySql(`SELECT source,name FROM d_saleleads_code WHERE department LIKE '%咨询组%' AND is_delete = 1`)
-		if saleSource != nil && len(*saleSource) > 0 {
-			for _, v := range *saleSource {
-				source := common.ObjToString(v["source"])
-				name := common.ObjToString(v["name"])
-				for _, s := range filterArr {
-					name = strings.ReplaceAll(name, s, "")
-				}
-				sourceMap[source] = name
-			}
-		}
-		nowTime := time.Now().Format(date.Date_Full_Layout)
-		advisoryCommitteeTime := cfg.AdvisoryCommitteeTime
-		if advisoryCommitteeTime == 0 {
-			advisoryCommitteeTime = time.Now().Unix()
-		}
-		abhList := []map[string]interface{}{}
-		saleleadsData, ok := Mgo.Find("saleLeads", map[string]interface{}{"createtime": map[string]interface{}{"$gte": advisoryCommitteeTime}}, `{"phone":1,"createtime":1}`, nil, false, -1, -1)
-		if ok && saleleadsData != nil && len(*saleleadsData) > 0 {
-			data := FindBatchData("zx")
-			for _, v := range *saleleadsData {
-				sources := common.ObjToString(v["source"])
-				userid := common.ObjToString(v["userid"])
-				uid := ""
-				if !mongodb.IsObjectIdHex(userid) {
-					userMapping := TiDb.FindOne("dwd_f_userbase_id_mapping", map[string]interface{}{"position_id": userid}, "", "")
-					if userMapping != nil && len(*userMapping) > 0 {
-						userid = common.ObjToString((*userMapping)["userid"])
-						uid = common.ObjToString((*userMapping)["uid"])
-					}
-				} else {
-					userMapping := TiDb.FindOne("dwd_f_userbase_id_mapping", map[string]interface{}{"userid": userid}, "", "")
-					if userMapping != nil && len(*userMapping) > 0 {
-						userid = common.ObjToString((*userMapping)["userid"])
-						uid = common.ObjToString((*userMapping)["uid"])
-					}
-				}
-				if sourceMap[sources] != "" {
-					company := common.ObjToString(v["company"])
-					phone := common.ObjToString(v["phone"])
-					if IsInternal(phone) {
-						continue
-					}
-					username := common.ObjToString(v["name"])
-					email := common.ObjToString(v["mail"])
-					interest := common.ObjToString(v["interest"])
-					data_requirement := common.ObjToString(v["data_requirement"])
-					source := sourceMap[sources]
-					belongTo := "咨询组"
-					userData := TiDb.FindOne("dwd_f_userbase_baseinfo", map[string]interface{}{"uid": uid}, "", "")
-					if userData != nil {
-						bt := common.ObjToString((*userData)["belong_to"])
-						if strings.HasPrefix(bt, "03") || bt == "0102" {
-							continue
-						}
-					}
-					key := fmt.Sprintf("%s_%s_%s", source, phone, interest)
-					if _, ok := data[key]; ok {
-						continue
-					}
-					data[key] = true
-					s_sourceid := common.ObjToString((*userData)["s_sourceid"])
-					if s_sourceid == db.Sourceid {
-						abhList = append(abhList, map[string]interface{}{
-							"createTime":       nowTime,
-							"createtime":       v["createtime"],
-							"username":         username,
-							"company":          company,
-							"phone":            phone,
-							"source":           source,
-							"belongTo":         belongTo,
-							"interest":         interest,
-							"data_requirement": data_requirement,
-							"branch":           v["branch"],
-							"email":            email,
-						})
-						if gconv.Int64(v["createtime"]) > advisoryCommitteeTime {
-							advisoryCommitteeTime = gconv.Int64(v["createtime"])
-						}
-						continue
-					}
-					dataArr = append(dataArr, map[string]interface{}{
-						"createTime":       nowTime,
-						"createtime":       v["createtime"],
-						"username":         username,
-						"company":          company,
-						"phone":            phone,
-						"source":           source,
-						"belongTo":         belongTo,
-						"interest":         interest,
-						"data_requirement": data_requirement,
-						"branch":           v["branch"],
-						"email":            email,
-					})
-
-				}
-
-			}
-			keyContent := fmt.Sprintf("data_%s_%s", time.Now().Format("2006-01-02"), "zx")
-			redis.Put("newother", keyContent, data, 86400)
-		}
-		if len(abhList) > 0 {
-			//安博会发邮件高翔
-			ABHEmail("advisory", abhList)
-		}
-		cfg.AdvisoryCommitteeTime = advisoryCommitteeTime
-		xlsxArr := []string{"姓名", "联系方式", "邮箱", "公司名称", "咨询需求", "销售线索来源", "具体来源", "留资时间"}
-		if len(dataArr) > 0 {
-			//排序:首先按照“联系方式”排序,即同1个用户的留资放在一起,其次按照留资时间正序排序。
-			batch := FindBatch("zx")
-			fileName, detailName := "咨询服务销售线索 "+time.Now().Format(date.Date_Short_Layout)+"-"+batch, ""
-			xf := xlsx.NewFile()
-			style := xlsx.NewStyle()
-			style.Font.Size = 12
-			style.Font.Bold = true
-			style.Alignment.Vertical = "center"
-			style.Alignment.Horizontal = "center"
-			detailName = "今日新增咨询服务销售线索,请查收附件,及时跟进。"
-			sh, _ := xf.AddSheet("线索数据")
-			row1 := sh.AddRow()
-			for _, x := range xlsxArr {
-				cell := row1.AddCell()
-				cell.SetString(x)
-				cell.SetStyle(style)
-			}
-			for _, v := range dataArr {
-				row := sh.AddRow()
-				row.AddCell().SetString(common.ObjToString(v["username"]))
-				row.AddCell().SetString(common.ObjToString(v["phone"]))
-				row.AddCell().SetString(common.ObjToString(v["email"]))
-				row.AddCell().SetString(common.ObjToString(v["company"]))
-				row.AddCell().SetString(common.ObjToString(v["data_requirement"]))
-				row.AddCell().SetString(common.ObjToString(v["source"]))
-				row.AddCell().SetString(common.ObjToString(v["interest"]))
-				row.AddCell().SetString(gconv.Time(gconv.Int64(v["createtime"])).Format(date.Date_Full_Layout))
-				//增加客户需求
-			}
-			email := db.AdvisoryCommitteeMail
-			dir := "./xlsx/zx/" + fileName + ".xlsx"
-			err := xf.Save(dir)
-			if err != nil {
-				log.Println("xls error", err, dir)
-			} else {
-				gmail := &mail.GmailAuth{
-					SmtpHost: "smtp.exmail.qq.com",
-					SmtpPort: 465,
-					User:     "public03@topnet.net.cn",
-					Pwd:      "ue9Rg9Sf4CVtdm5a",
-				}
-				for _, v := range email {
-					status := mail.GSendMail_q("剑鱼标讯", v, "", "", fileName, detailName, dir, fileName+".xlsx", gmail)
-					if status {
-						log.Println("send mail success", fileName, v)
-					}
-				}
-			}
-		}
-		common.WriteSysConfig(&cfg)
-		log.Println("咨询部线索定时任务结束")
-	}
-
-// 市场部线索
-
-	func marketCustomer() {
-		runOk := getRunOk()
-		if !runOk {
-			log.Println("不是工作日,任务暂停")
-			return
-		}
-		log.Println("市场部线索定时任务开始")
-		dataArr := []map[string]interface{}{}
-		filterArr := []string{"-pc", "-app", "-wx", "-h5"}
-		sourceMap := map[string]string{} //根据留资维表:tidb/Jianyu_subjectdb/d_saleleads_code
-		saleSource := TiDb.SelectBySql(`SELECT source,name FROM d_saleleads_code WHERE department LIKE '%市场组%' AND is_delete = 1`)
-		if saleSource != nil && len(*saleSource) > 0 {
-			for _, v := range *saleSource {
-				source := common.ObjToString(v["source"])
-				name := common.ObjToString(v["name"])
-				for _, s := range filterArr {
-					name = strings.ReplaceAll(name, s, "")
-				}
-				sourceMap[source] = name
-			}
-		}
-		nowTime := time.Now().Format(date.Date_Full_Layout)
-		marketSaleTime := cfg.MarketSaleTime
-		if marketSaleTime == 0 {
-			marketSaleTime = time.Now().Unix()
-		}
-		abhList := []map[string]interface{}{}
-		saleleadsData, ok := Mgo.Find("saleLeads", map[string]interface{}{"createtime": map[string]interface{}{"$gte": marketSaleTime}}, `{"phone":1,"createtime":1}`, nil, false, -1, -1)
-		if ok && saleleadsData != nil && len(*saleleadsData) > 0 {
-			data := FindBatchData("sc")
-			for _, v := range *saleleadsData {
-				sources := common.ObjToString(v["source"])
-				userid := common.ObjToString(v["userid"])
-				uid := ""
-				if !mongodb.IsObjectIdHex(userid) {
-					userMapping := TiDb.FindOne("dwd_f_userbase_id_mapping", map[string]interface{}{"position_id": userid}, "", "")
-					if userMapping != nil && len(*userMapping) > 0 {
-						userid = common.ObjToString((*userMapping)["userid"])
-						uid = common.ObjToString((*userMapping)["uid"])
-					}
-				} else {
-					userMapping := TiDb.FindOne("dwd_f_userbase_id_mapping", map[string]interface{}{"userid": userid}, "", "")
-					if userMapping != nil && len(*userMapping) > 0 {
-						userid = common.ObjToString((*userMapping)["userid"])
-						uid = common.ObjToString((*userMapping)["uid"])
-					}
-				}
-				if sourceMap[sources] != "" {
-					company := common.ObjToString(v["company"])
-					phone := common.ObjToString(v["phone"])
-					if IsInternal(phone) {
-						continue
-					}
-					job := common.ObjToString(v["position"])
-					username := common.ObjToString(v["name"])
-					email := common.ObjToString(v["mail"])
-					interest := common.ObjToString(v["interest"])
-					data_requirement := common.ObjToString(v["data_requirement"])
-					source := sourceMap[sources]
-					belongTo, usernickname := "市场组", ""
-					userData := TiDb.FindOne("dwd_f_userbase_baseinfo", map[string]interface{}{"uid": uid}, "", "")
-					if userData != nil {
-						usernickname = common.ObjToString((*userData)["nickname"])
-						bt := common.ObjToString((*userData)["belong_to"])
-						if strings.HasPrefix(bt, "03") || bt == "0102" {
-							continue
-						}
-					}
-					key := fmt.Sprintf("%s_%s", source, phone)
-					if _, ok := data[key]; ok {
-						continue
-					}
-					s_sourceid := common.ObjToString((*userData)["s_sourceid"])
-					data[key] = true
-					if s_sourceid == db.Sourceid {
-						abhList = append(abhList, map[string]interface{}{
-							"createTime":       nowTime,
-							"lastUpdateTime":   nowTime,
-							"createtime":       v["createtime"],
-							"uid":              uid,
-							"userid":           userid,
-							"username":         username,
-							"usernickname":     usernickname,
-							"company":          company,
-							"job":              job,
-							"phone":            phone,
-							"email":            email,
-							"source":           source,
-							"belongTo":         belongTo,
-							"interest":         interest,
-							"data_requirement": data_requirement,
-							"branch":           v["branch"],
-							"s_sourceid":       s_sourceid,
-						})
-						if gconv.Int64(v["createtime"]) > marketSaleTime {
-							marketSaleTime = gconv.Int64(v["createtime"])
-						}
-						continue
-					}
-					dataArr = append(dataArr, map[string]interface{}{
-						"createTime":       nowTime,
-						"lastUpdateTime":   nowTime,
-						"createtime":       v["createtime"],
-						"uid":              uid,
-						"userid":           userid,
-						"username":         username,
-						"usernickname":     usernickname,
-						"company":          company,
-						"job":              job,
-						"phone":            phone,
-						"email":            email,
-						"source":           source,
-						"belongTo":         belongTo,
-						"interest":         interest,
-						"data_requirement": data_requirement,
-						"branch":           v["branch"],
-						"s_sourceid":       s_sourceid,
-					})
-
-				}
-				if gconv.Int64(v["createtime"]) > marketSaleTime {
-					marketSaleTime = gconv.Int64(v["createtime"])
-				}
-			}
-			if len(abhList) > 0 {
-				//安博会发邮件高翔
-				ABHEmail("market", abhList)
-			}
-			keyContent := fmt.Sprintf("data_%s_%s", time.Now().Format("2006-01-02"), "sc")
-			redis.Put("newother", keyContent, data, 86400)
-
-		}
-		cfg.MarketSaleTime = marketSaleTime
-		xlsxArr := []string{"姓名", "联系人电话", "公司名称", "职位", "部门", "销售线索来源", "留资时间"}
-		if len(dataArr) > 0 {
-			//排序:首先按照“联系方式”排序,即同1个用户的留资放在一起,其次按照留资时间正序排序。
-			batch := FindBatch("sc")
-			fileName, detailName := "商务合作销售线索 "+time.Now().Format(date.Date_Short_Layout)+"-"+batch, ""
-			xf := xlsx.NewFile()
-			style := xlsx.NewStyle()
-			style.Font.Size = 12
-			style.Font.Bold = true
-			style.Alignment.Vertical = "center"
-			style.Alignment.Horizontal = "center"
-			detailName = "今日新增商务合作销售线索,请查收附件,及时跟进。"
-			sh, _ := xf.AddSheet("线索数据")
-			row1 := sh.AddRow()
-			for _, x := range xlsxArr {
-				cell := row1.AddCell()
-				cell.SetString(x)
-				cell.SetStyle(style)
-			}
-			for _, v := range dataArr {
-
-				row := sh.AddRow()
-				row.AddCell().SetString(common.ObjToString(v["username"]))
-				row.AddCell().SetString(common.ObjToString(v["phone"]))
-				row.AddCell().SetString(common.ObjToString(v["company"]))
-				row.AddCell().SetString(common.ObjToString(v["job"]))
-				row.AddCell().SetString(common.ObjToString(v["branch"]))
-				row.AddCell().SetString(common.ObjToString(v["source"]))
-				row.AddCell().SetString(gconv.Time(gconv.Int64(v["createtime"])).Format(date.Date_Full_Layout))
-				//增加客户需求
-			}
-			email := db.MarketSaleMail
-			dir := "./xlsx/sc/" + fileName + ".xlsx"
-			err := xf.Save(dir)
-			if err != nil {
-				log.Println("xls error", err, dir)
-			} else {
-				gmail := &mail.GmailAuth{
-					SmtpHost: "smtp.exmail.qq.com",
-					SmtpPort: 465,
-					User:     "public03@topnet.net.cn",
-					Pwd:      "ue9Rg9Sf4CVtdm5a",
-				}
-				status := mail.GSendMail_q("剑鱼标讯", email, "", "", fileName, detailName, dir, fileName+".xlsx", gmail)
-				if status {
-					log.Println("send mail success", fileName, email)
-				}
-			}
-
-		}
-		common.WriteSysConfig(&cfg)
-		log.Println("大客户线索定时任务结束")
-	}
-*/
 func eventReg() {
 	lastEventRegTime := cfg.LastEventRegTime
 	sql := fmt.Sprintf(`select * from exhibition_sign_up where is_del = 0 and update_time > "%s" order by update_time asc`, lastEventRegTime)
@@ -1073,6 +706,7 @@ func FindBatch(moudle string) string {
 	batch := redis.Incr("newother", key)
 	return fmt.Sprintf("%04d", batch)
 }
+
 func FindBatchData(moudle string) map[string]interface{} {
 	now := time.Now().Format("2006-01-02")
 	//数据提取
@@ -1199,11 +833,12 @@ func processLeads(batch string, committeeTime int64, sourceMap map[string]string
 			lead := map[string]interface{}{}
 			lead, endtime = processLead(v, sourceMap, nowTime, committeeTime, data)
 			if lead != nil {
-				if isABHLead(lead) {
-					abhList = append(abhList, lead)
-				} else {
-					dataArr = append(dataArr, lead)
-				}
+				/*	if isABHLead(lead) {
+						abhList = append(abhList, lead)
+					} else {
+						dataArr = append(dataArr, lead)
+					}*/
+				dataArr = append(dataArr, lead)
 			}
 		}
 		saveDataToRedis(data, batch)
@@ -1334,10 +969,10 @@ func exportToExcel(dataArr []map[string]interface{}, title, batch string) {
 // 发送邮件
 func sendEmail(fileName, detailName, dir, email string) {
 	gmail := &mail.GmailAuth{
-		SmtpHost: "smtp.exmail.qq.com",
-		SmtpPort: 465,
-		User:     "public03@topnet.net.cn",
-		Pwd:      "ue9Rg9Sf4CVtdm5a",
+		SmtpHost: db.Mail.SmtpHost,
+		SmtpPort: db.Mail.SmtpPort,
+		User:     db.Mail.User,
+		Pwd:      db.Mail.Pwd,
 	}
 	if status := mail.GSendMail_q("剑鱼标讯", email, "", "", fileName, detailName, dir, fileName+".xlsx", gmail); status {
 		log.Println("send mail success", fileName, email)

+ 1 - 1
clueSync/go.mod

@@ -13,6 +13,6 @@ require (
 	github.com/gogf/gf/v2 v2.7.0
 	github.com/lunny/csession v0.0.0-20130910075847-fe53c5de3dfd // indirect
 	github.com/robfig/cron v1.2.0
-	github.com/robfig/cron/v3 v3.0.1
 	github.com/tealeg/xlsx v1.0.5
+	gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df // indirect
 )

+ 0 - 2
clueSync/go.sum

@@ -1255,8 +1255,6 @@ github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
 github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
 github.com/robfig/cron v1.2.0 h1:ZjScXvvxeQ63Dbyxy76Fj3AT3Ut0aKsyd2/tl3DTMuQ=
 github.com/robfig/cron v1.2.0/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k=
-github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
-github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
 github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
 github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
 github.com/rogpeppe/go-internal v1.2.2/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=

+ 252 - 149
clueSync/job.go

@@ -17,7 +17,7 @@ import (
 )
 
 func FormatData(data map[string]interface{}, item string) (bool, bool, bool) {
-	userId, uId, positionId, source, cluename, phone, sourceCode, keyword, s_sourceid := common.ObjToString(data["user_id"]), "", "", "", "", "", "", []string{}, ""
+	userId, uId, positionId, source, cluename, phone, sourceCode, keyword, _ := gconv.String(data["user_id"]), "", "", "", "", "", "", []string{}, ""
 	role, industry, department, departments, position, name, top_cluetype, sub_cluetype, follow_project_area, level := "", "", "", "", "", "", "", "", "", ""
 	query, topname, subname, belong_to, sourceName, remark, sourceId := map[string]interface{}{}, "", "", "01", "", "", int64(0)
 	nowTime := time.Now().Format("2006-01-02 15:04:05")
@@ -26,35 +26,35 @@ func FormatData(data map[string]interface{}, item string) (bool, bool, bool) {
 			positionId = userId
 			userMapping := TiDb.FindOne("dwd_f_userbase_id_mapping", map[string]interface{}{"position_id": userId}, "", "")
 			if userMapping != nil && len(*userMapping) > 0 {
-				userId = common.ObjToString((*userMapping)["userid"])
+				userId = gconv.String((*userMapping)["userid"])
 			}
 		}
 		query["userid"] = userId
 		userInfo := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
 		if userInfo != nil && len(*userInfo) > 0 {
-			uId = common.ObjToString((*userInfo)["uid"])
-			source = common.ObjToString((*userInfo)["source"])       //用户来源
-			belong_to = common.ObjToString((*userInfo)["belong_to"]) //用户归属
+			uId = gconv.String((*userInfo)["uid"])
+			source = gconv.String((*userInfo)["source"])       //用户来源
+			belong_to = gconv.String((*userInfo)["belong_to"]) //用户归属
 		}
-		cluename = common.ObjToString(data["company_name"])
-		phone = common.ObjToString(data["user_phone"])
+		cluename = gconv.String(data["company_name"])
+		phone = gconv.String(data["user_phone"])
 	} else if item == "message" {
 		userMapping := TiDb.FindOne("dwd_f_userbase_id_mapping", map[string]interface{}{"base_user_id": common.Int64All(data["own_id"])}, "", "")
 		if userMapping != nil && len(*userMapping) > 0 {
-			userId = common.ObjToString((*userMapping)["userid"])
+			userId = gconv.String((*userMapping)["userid"])
 			positionId = fmt.Sprint((*userMapping)["position_id"])
 		}
 		query["userid"] = userId
 		userInfo := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
 		if userInfo != nil && len(*userInfo) > 0 {
-			uId = common.ObjToString((*userInfo)["uid"])
-			source = common.ObjToString((*userInfo)["source"])
-			belong_to = common.ObjToString((*userInfo)["belong_to"])
-			phone = common.ObjToString((*userInfo)["phone"])
+			uId = gconv.String((*userInfo)["uid"])
+			source = gconv.String((*userInfo)["source"])
+			belong_to = gconv.String((*userInfo)["belong_to"])
+			phone = gconv.String((*userInfo)["phone"])
 			if phone != "" {
 				phoneMapping := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"phone": phone}, "", "")
 				if phoneMapping != nil && len(*phoneMapping) > 0 {
-					cluename = common.ObjToString((*phoneMapping)["cluename"])
+					cluename = gconv.String((*phoneMapping)["cluename"])
 				}
 			}
 		}
@@ -66,13 +66,13 @@ func FormatData(data map[string]interface{}, item string) (bool, bool, bool) {
 		}
 		userId = mongodb.BsonIdToSId(data["userid"])
 		//新用户没有uid、source要等5分钟
-		cluename = common.ObjToString(data["company_name"])
-		phone = common.ObjToString(data["phone"])
+		cluename = gconv.String(data["company_name"])
+		phone = gconv.String(data["phone"])
 		if phone != "" {
 			contactsData := TiDb.SelectBySql("select * from dwd_f_userbase_contacts where phone = ? and is_delete = 1", phone)
 			if contactsData != nil && len(*contactsData) > 0 {
-				if common.ObjToString((*contactsData)[0]["baseinfo_id"]) != "" {
-					uId = common.ObjToString((*contactsData)[0]["baseinfo_id"])
+				if gconv.String((*contactsData)[0]["baseinfo_id"]) != "" {
+					uId = gconv.String((*contactsData)[0]["baseinfo_id"])
 					query["uid"] = uId
 				} else {
 					query["userid"] = userId
@@ -83,14 +83,14 @@ func FormatData(data map[string]interface{}, item string) (bool, bool, bool) {
 			//createtimeStr := ""
 			userInfo := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
 			if userInfo != nil && len(*userInfo) > 0 {
-				uId = common.ObjToString((*userInfo)["uid"])
-				source = common.ObjToString((*userInfo)["source"])
-				belong_to = common.ObjToString((*userInfo)["belong_to"])
-				s_sourceid = common.ObjToString((*userInfo)["s_sourceid"])
-				//createtimeStr = common.ObjToString((*userInfo)["l_registedate"])
+				uId = gconv.String((*userInfo)["uid"])
+				source = gconv.String((*userInfo)["source"])
+				belong_to = gconv.String((*userInfo)["belong_to"])
+				//s_sourceid =  gconv.String((*userInfo)["s_sourceid"])
+				//createtimeStr =  gconv.String((*userInfo)["l_registedate"])
 			}
 			if item == "xcxusers" {
-				sourceCode = common.ObjToString(data["industry"])
+				sourceCode = gconv.String(data["industry"])
 				//t, _ := time.Parse("2006-01-02 15:04:05", createtimeStr)
 				if sourceCode == "" {
 					log.Println("留资没有source", phone)
@@ -116,44 +116,44 @@ func FormatData(data map[string]interface{}, item string) (bool, bool, bool) {
 			"userid": userId,
 		}, "", "")
 		if userInfo != nil && len(*userInfo) > 0 {
-			phone = common.ObjToString((*userInfo)["phone"])
-			uId = common.ObjToString((*userInfo)["uid"])
-			source = common.ObjToString((*userInfo)["source"])
-			belong_to = common.ObjToString((*userInfo)["belong_to"])
+			phone = gconv.String((*userInfo)["phone"])
+			uId = gconv.String((*userInfo)["uid"])
+			source = gconv.String((*userInfo)["source"])
+			belong_to = gconv.String((*userInfo)["belong_to"])
 		}
 	} else if item == "saleLeads" { //留资
 		//线索名称打印
-		log.Println(1111, common.ObjToString(data["company"]))
-		userId = common.ObjToString(data["userid"])
+		log.Println(1111, gconv.String(data["company"]))
+		userId = gconv.String(data["userid"])
 		if !mongodb.IsObjectIdHex(userId) {
 			positionId = userId
 			userMapping := TiDb.FindOne("dwd_f_userbase_id_mapping", map[string]interface{}{"position_id": userId}, "", "")
 			if userMapping != nil && len(*userMapping) > 0 {
-				userId = common.ObjToString((*userMapping)["userid"])
-			}
-		}
-		cluename = common.ObjToString(data["company"])
-		phone = common.ObjToString(data["phone"])
-		role = common.ObjToString(data["companyType"])
-		industry = common.ObjToString(data["industry"])
-		department = common.ObjToString(data["branch"])
-		departments = common.ObjToString(data["department"])
-		position = common.ObjToString(data["position"])
-		name = common.ObjToString(data["name"])
-		sourceCode = common.ObjToString(data["source"])
+				userId = gconv.String((*userMapping)["userid"])
+			}
+		}
+		cluename = gconv.String(data["company"])
+		phone = gconv.String(data["phone"])
+		role = gconv.String(data["companyType"])
+		industry = gconv.String(data["industry"])
+		department = gconv.String(data["branch"])
+		departments = gconv.String(data["department"])
+		position = gconv.String(data["position"])
+		name = gconv.String(data["name"])
+		sourceCode = gconv.String(data["source"])
 		if sourceCode == "" {
 			log.Println("留资没有source", phone)
 			return true, true, true
 		}
-		remark = common.ObjToString(data["jyRemark"]) //荟聚线索备注
+		remark = gconv.String(data["jyRemark"]) //荟聚线索备注
 		keywordArr := data["keyword"]
 		if keywordArr != nil {
 			keyword = common.ObjArrToStringArr(data["keyword"].([]interface{}))
 		}
 		contactsData := TiDb.SelectBySql("select * from dwd_f_userbase_contacts where phone = ? and is_delete = 1", phone)
 		if contactsData != nil && len(*contactsData) > 0 {
-			if common.ObjToString((*contactsData)[0]["baseinfo_id"]) != "" {
-				uId = common.ObjToString((*contactsData)[0]["baseinfo_id"])
+			if gconv.String((*contactsData)[0]["baseinfo_id"]) != "" {
+				uId = gconv.String((*contactsData)[0]["baseinfo_id"])
 				query["uid"] = uId
 			} else {
 				query["userid"] = userId
@@ -164,11 +164,11 @@ func FormatData(data map[string]interface{}, item string) (bool, bool, bool) {
 		if userId != "" || uId != "" {
 			userInfo := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
 			if userInfo != nil && len(*userInfo) > 0 {
-				uId = common.ObjToString((*userInfo)["uid"])
-				source = common.ObjToString((*userInfo)["source"])
-				belong_to = common.ObjToString((*userInfo)["belong_to"])
-				userId = common.ObjToString((*userInfo)["userid"])
-				s_sourceid = common.ObjToString((*userInfo)["s_sourceid"])
+				uId = gconv.String((*userInfo)["uid"])
+				source = gconv.String((*userInfo)["source"])
+				belong_to = gconv.String((*userInfo)["belong_to"])
+				userId = gconv.String((*userInfo)["userid"])
+				//s_sourceid =  gconv.String((*userInfo)["s_sourceid"])
 			}
 		} else {
 			if sourceCode == "report_retention" || sourceCode == "marketing_retention" { //荟聚线索来源,不是剑鱼用户,需要等待用户归集
@@ -180,20 +180,20 @@ func FormatData(data map[string]interface{}, item string) (bool, bool, bool) {
 			}
 		}
 	} else if item == "eventReg" { //渠道
-		userId = common.ObjToString(data["userid"])
-		cluename = common.ObjToString(data["company"])
-		phone = common.ObjToString(data["sign_phone"])
-		role = common.ObjToString(data["company_type"])
-		department = common.ObjToString(data["branch"])
-		position = common.ObjToString(data["position"])
-		name = common.ObjToString(data["sign_name"])
-		sourceCode = common.ObjToString(data["source_code"])
-		sourceName = common.ObjToString(data["source_name"])
+		userId = gconv.String(data["userid"])
+		cluename = gconv.String(data["company"])
+		phone = gconv.String(data["sign_phone"])
+		role = gconv.String(data["company_type"])
+		department = gconv.String(data["branch"])
+		position = gconv.String(data["position"])
+		name = gconv.String(data["sign_name"])
+		sourceCode = gconv.String(data["source_code"])
+		sourceName = gconv.String(data["source_name"])
 		log.Println(sourceName)
 		contactsData := TiDb.SelectBySql("select * from dwd_f_userbase_contacts where phone = ? and is_delete = 1", phone)
 		if contactsData != nil && len(*contactsData) > 0 {
-			if common.ObjToString((*contactsData)[0]["baseinfo_id"]) != "" {
-				uId = common.ObjToString((*contactsData)[0]["baseinfo_id"])
+			if gconv.String((*contactsData)[0]["baseinfo_id"]) != "" {
+				uId = gconv.String((*contactsData)[0]["baseinfo_id"])
 				query["uid"] = uId
 			} else {
 				query["userid"] = userId
@@ -203,57 +203,72 @@ func FormatData(data map[string]interface{}, item string) (bool, bool, bool) {
 		}
 		userInfo := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
 		if userInfo != nil && len(*userInfo) > 0 {
-			uId = common.ObjToString((*userInfo)["uid"])
-			source = common.ObjToString((*userInfo)["source"])
-			belong_to = common.ObjToString((*userInfo)["belong_to"])
-			userId = common.ObjToString((*userInfo)["userid"])
+			uId = gconv.String((*userInfo)["uid"])
+			source = gconv.String((*userInfo)["source"])
+			belong_to = gconv.String((*userInfo)["belong_to"])
+			userId = gconv.String((*userInfo)["userid"])
 		}
 		if role == "集成商" || role == "设计院" {
 			role = "其他-" + role
 		}
 	} else if item == "readClue" {
-		userId = common.ObjToString(data["userId"])
+		userId = gconv.String(data["userId"])
 		query["userid"] = userId
 		userInfo := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
 		if userInfo != nil && len(*userInfo) > 0 {
-			uId = common.ObjToString((*userInfo)["uid"])
-			source = common.ObjToString((*userInfo)["source"])
-			belong_to = common.ObjToString((*userInfo)["belong_to"])
+			uId = gconv.String((*userInfo)["uid"])
+			source = gconv.String((*userInfo)["source"])
+			belong_to = gconv.String((*userInfo)["belong_to"])
 		}
-		// cluename = common.ObjToString(data["companyName"])
-		phone = common.ObjToString(data["phone"])
+		// cluename =  gconv.String(data["companyName"])
+		phone = gconv.String(data["phone"])
 		sourceId = common.Int64All(data["sourceId"])
 	} else if item == "invite" {
 		query["userid"] = userId
 		userInfo := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
 		if userInfo != nil && len(*userInfo) > 0 {
-			uId = common.ObjToString((*userInfo)["uid"])
-			source = common.ObjToString((*userInfo)["source"])       //用户来源
-			belong_to = common.ObjToString((*userInfo)["belong_to"]) //用户归属
+			uId = gconv.String((*userInfo)["uid"])
+			source = gconv.String((*userInfo)["source"])       //用户来源
+			belong_to = gconv.String((*userInfo)["belong_to"]) //用户归属
+		} else {
+			log.Println("邀请用户,用户归集没数据", data)
+			return true, true, true
+		}
+		cluename = gconv.String((*userInfo)["company_name"])
+		phone = gconv.String((*userInfo)["phone"])
+		sourceCode = gconv.String(data["sourceCode"])
+	} else if item == "activity" {
+		query["userid"] = userId
+		userInfo := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
+		if userInfo != nil && len(*userInfo) > 0 {
+			uId = gconv.String((*userInfo)["uid"])
+			source = gconv.String((*userInfo)["source"])       //用户来源
+			belong_to = gconv.String((*userInfo)["belong_to"]) //用户归属
 		} else {
 			log.Println("邀请用户,用户归集没数据", data)
 			return true, true, true
 		}
-		cluename = common.ObjToString((*userInfo)["company_name"])
-		phone = common.ObjToString((*userInfo)["phone"])
-		sourceCode = common.ObjToString(data["sourceCode"])
+		cluename = gconv.String((*userInfo)["company_name"])
+		phone = gconv.String((*userInfo)["phone"])
+		sourceCode = gconv.String(data["sourceCode"])
+		log.Println(sourceCode)
 	}
 	log.Println(222, cluename)
-	if cluename == "" && item != "message" && item != "orders" && item != "readClue" && item != "rebind" && item != "allocation" {
+	if cluename == "" && item != "message" && item != "orders" && item != "readClue" && item != "rebind" && item != "allocation" && item != "activity" {
 		cluename = phone //没有线索名,手机号代替
 	}
 	log.Println(333, cluename)
 	cluename = strings.ReplaceAll(cluename, " ", "")
-	isGroup, isCommerce := GetCompanyType(cluename)                                                                    //判断是否集团公司、工商库
+	isGroup, isCommerce := GetCompanyType(cluename, uId)                                                               //判断是否集团公司、工商库
 	if source == "0104" || strings.HasPrefix(belong_to, "02") || source == "0102" || source == "0103" || phone == "" { //参照用户来源代码表
 		//log.Println("线索分配失败,线索过滤!!", item, source, phone, userId)
 		//saveHlyj(belong_to, item, phone, name, sourceName, cluename, position, nowTime, isGroup, isCommerce)
 		return true, true, true
 	}
 	//安博会
-	if s_sourceid == db.Sourceid {
+	/*if s_sourceid == db.Sourceid {
 		return true, true, false
-	}
+	}*/
 	if uId == "" { //没有进用户归集,等待进入,结束任务,放在下次继续执行
 		if isExists, _ := redis.Exists("bidx", "bidx_userId_"+userId); isExists {
 			redisInt := redis.GetInt("bidx", "bidx_userId_"+userId)
@@ -277,12 +292,12 @@ func FormatData(data map[string]interface{}, item string) (bool, bool, bool) {
 		saleLeadsData, ok := Mgo.Find("saleLeads", map[string]interface{}{"userid": qid}, map[string]interface{}{"_id": -1}, nil, false, 0, 1)
 		if ok && saleLeadsData != nil && len(*saleLeadsData) > 0 {
 			sdata := (*saleLeadsData)[0]
-			role = common.ObjToString(sdata["companyType"])
-			industry = common.ObjToString(sdata["industry"])
-			department = common.ObjToString(sdata["branch"])
-			departments = common.ObjToString(sdata["department"])
-			position = common.ObjToString(sdata["position"])
-			name = common.ObjToString(sdata["name"])
+			role = gconv.String(sdata["companyType"])
+			industry = gconv.String(sdata["industry"])
+			department = gconv.String(sdata["branch"])
+			departments = gconv.String(sdata["department"])
+			position = gconv.String(sdata["position"])
+			name = gconv.String(sdata["name"])
 		}
 	}
 	top_cluetype, sub_cluetype, level, topname, subname = getClueType(item, data, sourceCode, sourceId) //查留资来源名字
@@ -314,7 +329,7 @@ func FormatData(data map[string]interface{}, item string) (bool, bool, bool) {
 				cluename = ""
 			}
 			//已存在,走更新
-			batch_import := common.ObjToString((*uCount)["batch_import"])
+			batch_import := gconv.String((*uCount)["batch_import"])
 			if batch_import != "" && item == "users" { //有导入批次号还是新用户,不执行
 				return true, true, true
 			}
@@ -341,14 +356,16 @@ func FormatData(data map[string]interface{}, item string) (bool, bool, bool) {
 				if item != "orders" && item != "users" { //新用户和订单之外的替换一下新的留资信息
 					BCPCID := common.GetRandom(32)
 					clueId := common.Int64All((*uCount)["id"])
-					old_name := common.ObjToString((*uCount)["name"])
-					old_position := common.ObjToString((*uCount)["position"])
-					old_department := common.ObjToString((*uCount)["department"])
-					old_follow_project_area := common.ObjToString((*uCount)["follow_project_area"])
-					old_role := common.ObjToString((*uCount)["role"])
-					old_cluename := common.ObjToString((*uCount)["cluename"])
-					old_top_cluetype := common.ObjToString((*uCount)["top_cluetype"])
-					old_sub_cluetype := common.ObjToString((*uCount)["sub_cluetype"])
+					old_name := gconv.String((*uCount)["name"])
+					old_position := gconv.String((*uCount)["position"])
+					old_department := gconv.String((*uCount)["department"])
+					old_follow_project_area := gconv.String((*uCount)["follow_project_area"])
+					old_role := gconv.String((*uCount)["role"])
+					old_cluename := gconv.String((*uCount)["cluename"])
+					old_top_cluetype := gconv.String((*uCount)["top_cluetype"])
+					old_sub_cluetype := gconv.String((*uCount)["sub_cluetype"])
+					label := gconv.Int64((*uCount)["label"])
+					trailstatusCode := gconv.String((*uCount)["trailstatus"])
 					clueUpdateData := map[string]interface{}{}
 					if old_name != name && name != "" {
 						clueUpdateData["name"] = name
@@ -356,6 +373,7 @@ func FormatData(data map[string]interface{}, item string) (bool, bool, bool) {
 							"clue_id":      clueId,
 							"change_field": "name",
 							"position_id":  0,
+							"seatNumber":   nil,
 							"change_type":  "基本信息变更",
 							"old_value":    common.If(old_name != "", old_name, "/"),
 							"new_value":    common.If(name != "", name, "/"),
@@ -433,13 +451,13 @@ func FormatData(data map[string]interface{}, item string) (bool, bool, bool) {
 					if old_top_cluetype != "" {
 						pcodeData := TiDb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"code": old_top_cluetype}, "", "")
 						if pcodeData != nil && len(*pcodeData) > 0 {
-							old_topname = common.ObjToString((*pcodeData)["name"])
+							old_topname = gconv.String((*pcodeData)["name"])
 						}
 					}
 					if old_sub_cluetype != "" {
 						pcodeData := TiDb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"code": old_sub_cluetype}, "", "")
 						if pcodeData != nil && len(*pcodeData) > 0 {
-							old_subname = common.ObjToString((*pcodeData)["name"])
+							old_subname = gconv.String((*pcodeData)["name"])
 						}
 					}
 					if old_top_cluetype != top_cluetype && top_cluetype != "" {
@@ -459,7 +477,7 @@ func FormatData(data map[string]interface{}, item string) (bool, bool, bool) {
 						clueUpdateData["sub_cluetype"] = sub_cluetype //新的线索名不为空才替换
 						TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
 							"clue_id":      clueId,
-							"change_field": "sub_cluetype",
+							"change_field": "sub_cluetype", //111
 							"position_id":  0,
 							"change_type":  "基本信息变更",
 							"old_value":    common.If(old_subname != "", old_subname, "/"),
@@ -467,6 +485,8 @@ func FormatData(data map[string]interface{}, item string) (bool, bool, bool) {
 							"createtime":   nowTime,
 							"BCPCID":       BCPCID,
 							"operator_id":  -1})
+						//标签处理
+						LabelHandel(nil, label, 2, uId, level, trailstatusCode, gconv.String(clueUpdateData["trailstatus"]), 1)
 					}
 					clueUpdateData["company_nature"] = isGroup
 					clueUpdateData["company_verification"] = isCommerce
@@ -496,7 +516,6 @@ func SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, c
 		if cluename == "" {
 			cluename = phone
 		}
-
 		clueId = TiDb.InsertByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{
 			"userid":               userId,
 			"uid":                  uId,
@@ -529,6 +548,8 @@ func SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, c
 			"remark":               remark,
 			"customer_demand":      demand,
 			"FREEZE_TIME":          nowTime,
+			"label":                1,
+			"labelChangeTime":      time.Now().Format("2006-01-02"),
 		})
 		uodateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
 			"clue_id":     clueId,
@@ -584,7 +605,7 @@ func SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, c
 		uodateId6 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
 			"clue_id":      clueId,
 			"position_id":  positionId,
-			"change_field": "sub_cluetype",
+			"change_field": "sub_cluetype", //222
 			"change_type":  "基本信息变更",
 			"old_value":    "/",
 			"new_value":    subname,
@@ -652,6 +673,8 @@ func SaveClue0(item, userId, uId, top_cluetype, sub_cluetype, topname, subname,
 			"company_verification": isCommerce,
 			"remark":               remark,
 			"FREEZE_TIME":          nowTime,
+			"label":                1,
+			"labelChangeTime":      time.Now().Format("2006-01-02"),
 		})
 		uodateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
 			"clue_id":     clueId,
@@ -708,8 +731,8 @@ func WorkUpdateClue(data map[string]interface{}, saleData []map[string]interface
 	log.Println("工单线索修改前", data)
 	nowTime := time.Now().Format("2006-01-02 15:04:05")
 	nowTimes := time.Unix(time.Now().Unix()+3600*12, 0).Format("2006-01-02 15:04:05")
-	trailstatus := common.ObjToString(data["trailstatus"]) //data都为原线索数据
-	trailstatusTime := common.ObjToString(data["trailstatus_time"])
+	trailstatus := gconv.String(data["trailstatus"]) //data都为原线索数据
+	trailstatusTime := gconv.String(data["trailstatus_time"])
 	var trailstatusTimes time.Time
 	if trailstatusTime != "" {
 		trailstatusTimes, _ = time.ParseInLocation(date.Date_Full_Layout, trailstatusTime, time.Local)
@@ -717,23 +740,24 @@ func WorkUpdateClue(data map[string]interface{}, saleData []map[string]interface
 	clueId := common.Int64All(data["id"])
 	is_assign := common.IntAll(data["is_assign"])
 	oldsaleName, oldTaskTime, taskTime, is_task, taskstatus := "", "", "", 0, 0
-	old_position_id, old_seatNumber := common.Int64All(data["position_id"]), common.ObjToString(data["seatNumber"])
-	oldTaskTime = common.ObjToString(data["tasktime"])
+	old_position_id, old_seatNumber := common.Int64All(data["position_id"]), gconv.String(data["seatNumber"])
+	oldTaskTime = gconv.String(data["tasktime"])
 	is_task = common.IntAll(data["is_task"])
 	taskstatus = common.IntAll(data["taskstatus"])
 	BCPCID := common.GetRandom(32)
-	old_name := common.ObjToString(data["name"])
-	old_position := common.ObjToString(data["position"])
-	old_department := common.ObjToString(data["department"])
-	old_follow_project_area := common.ObjToString(data["follow_project_area"])
-	old_role := common.ObjToString(data["role"])
-	old_cluename := common.ObjToString(data["cluename"])
-	old_top_cluetype := common.ObjToString(data["top_cluetype"])
-	old_sub_cluetype := common.ObjToString(data["sub_cluetype"])
+	old_name := gconv.String(data["name"])
+	old_position := gconv.String(data["position"])
+	old_department := gconv.String(data["department"])
+	old_follow_project_area := gconv.String(data["follow_project_area"])
+	old_role := gconv.String(data["role"])
+	old_cluename := gconv.String(data["cluename"])
+	old_top_cluetype := gconv.String(data["top_cluetype"])
+	old_sub_cluetype := gconv.String(data["sub_cluetype"])
+	label := gconv.Int64(data["label"])
 	old_topname, old_subname := "", ""
 	is_transfer := common.IntAll(data["is_transfer"])
 	if taskstatus == 1 || is_task == 0 {
-		taskTime = common.ObjToString(common.If(item != "users", nowTime, nowTimes)) //任务时间,正常的是当前时间,新用户是当前时间+12个小时
+		taskTime = gconv.String(common.If(item != "users", nowTime, nowTimes)) //任务时间,正常的是当前时间,新用户是当前时间+12个小时
 	} else {
 		if is_task == 1 {
 			if oldTaskTime != "" { //以最新的任务时间为主
@@ -788,12 +812,12 @@ func WorkUpdateClue(data map[string]interface{}, saleData []map[string]interface
 		"company_nature":       isGroup,
 		"company_verification": isCommerce,
 	}
-	old_remark := common.ObjToString(data["remark"])
+	old_remark := gconv.String(data["remark"])
 	if old_remark != "" {
 		remark = old_remark + ";" + remark //备注不能替换,只能往上拼接
 	}
 	clueUpdateData["remark"] = remark
-	old_demand := common.ObjToString(data["customer_demand"])
+	old_demand := gconv.String(data["customer_demand"])
 	if demand != old_demand {
 		clueUpdateData["customer_demand"] = demand
 	}
@@ -825,7 +849,7 @@ func WorkUpdateClue(data map[string]interface{}, saleData []map[string]interface
 			clueUpdateData["department"] = departments
 			department = departments
 		}
-		business_scope := common.ObjToString(data["business_scope"])
+		business_scope := gconv.String(data["business_scope"])
 		keywords := ""
 		if len(keyword) > 0 && keyword[0] != "" {
 			keywords = strings.Join(keyword, ",")
@@ -839,7 +863,7 @@ func WorkUpdateClue(data map[string]interface{}, saleData []map[string]interface
 	if old_position_id != 0 {
 		for _, v := range saleData {
 			if old_position_id == common.Int64All(v["position_id"]) {
-				oldsaleName = common.ObjToString(v["name"])
+				oldsaleName = gconv.String(v["name"])
 			}
 		}
 	}
@@ -889,7 +913,7 @@ func WorkUpdateClue(data map[string]interface{}, saleData []map[string]interface
 				eData := TiDb.Find("dwd_f_crm_clue_change_record", map[string]interface{}{"clue_id": clueId, "change_type": "加入任务车"}, "", "", -1, -1)
 				if eData != nil && len(*eData) > 0 {
 					for _, e := range *eData {
-						new_value := common.ObjToString(e["new_value"])
+						new_value := gconv.String(e["new_value"])
 						if strings.Contains(new_value, subname) {
 							is_ok = true
 						}
@@ -931,7 +955,6 @@ func WorkUpdateClue(data map[string]interface{}, saleData []map[string]interface
 		//线索
 		ok = TiDb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, clueUpdateData)
 		//变更记录
-
 		if (trailstatus == "00" || old_position_id == 0 || (pIsOk && old_cluename != cluename && cluename != "")) && is_assign == 1 {
 			if trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400 {
 			} else if old_position_id == 0 {
@@ -1100,7 +1123,7 @@ func WorkUpdateClue(data map[string]interface{}, saleData []map[string]interface
 						cdata := TiDb.FindOne("dwd_f_csm_customer_info", map[string]interface{}{"clue_id": clueId}, "", "")
 						if cdata != nil && len(*cdata) > 0 {
 							kcpositionId := common.Int64All((*cdata)["position_id"])
-							tasksource := common.ObjToString((*cdata)["tasksource"])
+							tasksource := gconv.String((*cdata)["tasksource"])
 							taskstatus := common.IntAll((*cdata)["taskstatus"])
 							updateId5 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
 								"clue_id":     clueId,
@@ -1143,17 +1166,16 @@ func WorkUpdateClue(data map[string]interface{}, saleData []map[string]interface
 				}
 			}
 		}
-
 		if old_top_cluetype != "" {
 			pcodeData := TiDb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"code": old_top_cluetype}, "", "")
 			if pcodeData != nil && len(*pcodeData) > 0 {
-				old_topname = common.ObjToString((*pcodeData)["name"])
+				old_topname = gconv.String((*pcodeData)["name"])
 			}
 		}
 		if old_sub_cluetype != "" {
 			pcodeData := TiDb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"code": old_sub_cluetype}, "", "")
 			if pcodeData != nil && len(*pcodeData) > 0 {
-				old_subname = common.ObjToString((*pcodeData)["name"])
+				old_subname = gconv.String((*pcodeData)["name"])
 			}
 		}
 		if item != "orders" {
@@ -1249,11 +1271,12 @@ func WorkUpdateClue(data map[string]interface{}, saleData []map[string]interface
 				"operator_id":  -1,
 			})
 		}
+		newPositionId := gconv.Int64(common.If(trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400, -1, common.If(trailstatus == "00" || is_assign == 0, positionId, common.If(is_assign == 1, positionId, common.If(is_assign == 1, positionId, common.Int64All(data["position_id"]))))))
 		if old_sub_cluetype != sub_cluetype {
 			updateId13 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
 				"clue_id":      clueId,
 				"position_id":  common.If(trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400, -1, common.If(trailstatus == "00" || is_assign == 0, positionId, common.If(is_assign == 1, positionId, common.If(is_assign == 1, positionId, common.Int64All(data["position_id"]))))),
-				"change_field": "sub_cluetype",
+				"change_field": "sub_cluetype", //333
 				"change_type":  "基本信息变更",
 				"old_value":    common.If(old_subname != "", old_subname, "/"),
 				"new_value":    common.If(subname != "", subname, "/"),
@@ -1261,6 +1284,16 @@ func WorkUpdateClue(data map[string]interface{}, saleData []map[string]interface
 				"BCPCID":       BCPCID,
 				"operator_id":  -1,
 			})
+			//标签处理
+			if old_position_id != positionId && newPositionId > 0 {
+				LabelHandel(tx, label, 1, uId, level, trailstatus, gconv.String(clueUpdateData["trailstatus"]), 0)
+			} else {
+				LabelHandel(tx, label, 2, uId, level, trailstatus, gconv.String(clueUpdateData["trailstatus"]), 0)
+			}
+		} else {
+			if old_position_id != positionId && newPositionId > 0 {
+				LabelHandel(tx, label, 1, uId, level, trailstatus, gconv.String(clueUpdateData["trailstatus"]), 0)
+			}
 		}
 		return ok && updateId1 > -1 && updateId2 > -1 && updateId3 > -1 && updateId4 > -1 && updateId5 > -1 && updateId6 > -1 && updateId7 > -1 && updateId8 > -1 && updateId9 > -1 && updateId10 > -1 && updateId11 > -1 && updateId12 > -1 && updateId13 > -1 && updateId14
 	}) {
@@ -1290,8 +1323,8 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 	name = strings.ReplaceAll(name, " ", "")
 	nowTime := time.Now().Format("2006-01-02 15:04:05")
 	nowTimes := time.Unix(time.Now().Unix()+3600*12, 0).Format("2006-01-02 15:04:05")
-	trailstatus := common.ObjToString(data["trailstatus"]) //data都为原线索数据
-	trailstatusTime := common.ObjToString(data["trailstatus_time"])
+	trailstatus := gconv.String(data["trailstatus"]) //data都为原线索数据
+	trailstatusTime := gconv.String(data["trailstatus_time"])
 	var trailstatusTimes time.Time
 	if trailstatusTime != "" {
 		trailstatusTimes, _ = time.ParseInLocation(date.Date_Full_Layout, trailstatusTime, time.Local)
@@ -1299,23 +1332,25 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 	clueId := common.Int64All(data["id"])
 	is_assign := common.IntAll(data["is_assign"])
 	oldsaleName, oldTaskTime, taskTime, is_task, taskstatus := "", "", "", 0, 0
-	old_position_id, old_seatNumber := common.Int64All(data["position_id"]), common.ObjToString(data["seatNumber"])
-	oldTaskTime = common.ObjToString(data["tasktime"])
+	old_position_id, old_seatNumber := common.Int64All(data["position_id"]), gconv.String(data["seatNumber"])
+	oldTaskTime = gconv.String(data["tasktime"])
 	is_task = common.IntAll(data["is_task"])
 	taskstatus = common.IntAll(data["taskstatus"])
 	BCPCID := common.GetRandom(32)
-	old_name := common.ObjToString(data["name"])
-	old_position := common.ObjToString(data["position"])
-	old_department := common.ObjToString(data["department"])
-	old_follow_project_area := common.ObjToString(data["follow_project_area"])
-	old_role := common.ObjToString(data["role"])
-	old_cluename := common.ObjToString(data["cluename"])
-	old_top_cluetype := common.ObjToString(data["top_cluetype"])
-	old_sub_cluetype := common.ObjToString(data["sub_cluetype"])
+	old_name := gconv.String(data["name"])
+	old_position := gconv.String(data["position"])
+	old_department := gconv.String(data["department"])
+	old_follow_project_area := gconv.String(data["follow_project_area"])
+	old_role := gconv.String(data["role"])
+	old_cluename := gconv.String(data["cluename"])
+	old_top_cluetype := gconv.String(data["top_cluetype"])
+	old_sub_cluetype := gconv.String(data["sub_cluetype"])
 	old_topname, old_subname := "", ""
 	is_transfer := common.IntAll(data["is_transfer"])
+	oldLabelChangeTime := gconv.String(data["labelChangeTime"])
+	label := gconv.Int64(data["label"])
 	if taskstatus == 1 || is_task == 0 {
-		taskTime = common.ObjToString(common.If(item != "users", nowTime, nowTimes)) //任务时间,正常的是当前时间,新用户是当前时间+12个小时
+		taskTime = gconv.String(common.If(item != "users", nowTime, nowTimes)) //任务时间,正常的是当前时间,新用户是当前时间+12个小时
 	} else {
 		if is_task == 1 {
 			if oldTaskTime != "" { //以最新的任务时间为主
@@ -1370,7 +1405,7 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 		"company_nature":       isGroup,
 		"company_verification": isCommerce,
 	}
-	old_remark := common.ObjToString(data["remark"])
+	old_remark := gconv.String(data["remark"])
 	if old_remark != "" {
 		remark = old_remark + ";" + remark //备注不能替换,只能往上拼接
 	}
@@ -1402,7 +1437,7 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 			clueUpdateData["department"] = departments
 			department = departments
 		}
-		business_scope := common.ObjToString(data["business_scope"])
+		business_scope := gconv.String(data["business_scope"])
 		keywords := ""
 		if len(keyword) > 0 && keyword[0] != "" {
 			keywords = strings.Join(keyword, ",")
@@ -1442,6 +1477,9 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 			Phone:                phone,
 			Source:               source,
 			PositionId:           old_position_id,
+			Level:                level,
+			LabelChangeTime:      oldLabelChangeTime,
+			Label:                label,
 		}
 		return clueInfoUpdate(clueMapEntity)
 
@@ -1464,7 +1502,7 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 			clueUpdateData["clue_level"] = nil
 			for _, v := range saleData {
 				if common.Int64All(data["position_id"]) == common.Int64All(v["position_id"]) {
-					oldsaleName = common.ObjToString(v["name"])
+					oldsaleName = gconv.String(v["name"])
 				}
 			}
 		}
@@ -1503,7 +1541,7 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 				eData := TiDb.Find("dwd_f_crm_clue_change_record", map[string]interface{}{"clue_id": clueId, "change_type": "加入任务车"}, "", "", -1, -1)
 				if eData != nil && len(*eData) > 0 {
 					for _, e := range *eData {
-						new_value := common.ObjToString(e["new_value"])
+						new_value := gconv.String(e["new_value"])
 						if strings.Contains(new_value, subname) {
 							is_ok = true
 						}
@@ -1710,7 +1748,7 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 						cdata := TiDb.FindOne("dwd_f_csm_customer_info", map[string]interface{}{"clue_id": clueId}, "", "")
 						if cdata != nil && len(*cdata) > 0 {
 							kcpositionId := common.Int64All((*cdata)["position_id"])
-							tasksource := common.ObjToString((*cdata)["tasksource"])
+							tasksource := gconv.String((*cdata)["tasksource"])
 							taskstatus := common.IntAll((*cdata)["taskstatus"])
 							updateId5 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
 								"clue_id":     clueId,
@@ -1756,13 +1794,13 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 		if old_top_cluetype != "" {
 			pcodeData := TiDb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"code": old_top_cluetype}, "", "")
 			if pcodeData != nil && len(*pcodeData) > 0 {
-				old_topname = common.ObjToString((*pcodeData)["name"])
+				old_topname = gconv.String((*pcodeData)["name"])
 			}
 		}
 		if old_sub_cluetype != "" {
 			pcodeData := TiDb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"code": old_sub_cluetype}, "", "")
 			if pcodeData != nil && len(*pcodeData) > 0 {
-				old_subname = common.ObjToString((*pcodeData)["name"])
+				old_subname = gconv.String((*pcodeData)["name"])
 			}
 		}
 		if item != "orders" {
@@ -1867,11 +1905,12 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 				"operator_id":  -1,
 			})
 		}
+		newPositionId := gconv.Int64(common.If(trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400, -1, common.If(trailstatus == "00" || is_assign == 0, positionId, common.Int64All(data["position_id"]))))
 		if old_sub_cluetype != sub_cluetype {
 			updateId13 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
 				"clue_id":      clueId,
 				"position_id":  common.If(trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400, -1, common.If(trailstatus == "00" || is_assign == 0, positionId, common.Int64All(data["position_id"]))),
-				"change_field": "sub_cluetype",
+				"change_field": "sub_cluetype", //444
 				"change_type":  "基本信息变更",
 				"old_value":    common.If(old_subname != "", old_subname, "/"),
 				"new_value":    common.If(subname != "", subname, "/"),
@@ -1879,6 +1918,15 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 				"BCPCID":       BCPCID,
 				"operator_id":  -1,
 			})
+			if old_position_id != newPositionId && newPositionId > 0 {
+				LabelHandel(tx, label, 1, uId, level, trailstatus, gconv.String(clueUpdateData["trailstatus"]), 0)
+			} else {
+				LabelHandel(tx, label, 2, uId, level, trailstatus, gconv.String(clueUpdateData["trailstatus"]), 0)
+			}
+		} else {
+			if old_position_id != newPositionId && newPositionId > 0 {
+				LabelHandel(tx, label, 1, uId, level, trailstatus, gconv.String(clueUpdateData["trailstatus"]), 0)
+			}
 		}
 		return ok && updateId1 > -1 && updateId2 > -1 && updateId3 > -1 && updateId4 > -1 && updateId5 > -1 && updateId6 > -1 && updateId7 > -1 && updateId8 > -1 && updateId9 > -1 && updateId10 > -1 && updateId11 > -1 && updateId12 > -1 && updateId13 > -1 && updateId14
 	}) {
@@ -1931,6 +1979,9 @@ type ClueMapEntity struct {
 	Phone                string
 	Source               string
 	PositionId           int64
+	Label                int64
+	LabelChangeTime      string
+	Level                string
 }
 
 // 基本信息变更
@@ -1950,13 +2001,13 @@ func clueInfoUpdate(data ClueMapEntity) bool {
 		if data.OldTopCluetype != "" {
 			pcodeData := TiDb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"code": data.OldTopCluetype}, "", "")
 			if pcodeData != nil && len(*pcodeData) > 0 {
-				old_topname = common.ObjToString((*pcodeData)["name"])
+				old_topname = gconv.String((*pcodeData)["name"])
 			}
 		}
 		if data.OldSubCluetype != "" {
 			pcodeData := TiDb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"code": data.OldSubCluetype}, "", "")
 			if pcodeData != nil && len(*pcodeData) > 0 {
-				old_subname = common.ObjToString((*pcodeData)["name"])
+				old_subname = gconv.String((*pcodeData)["name"])
 			}
 		}
 		if data.Item != "orders" {
@@ -2061,11 +2112,11 @@ func clueInfoUpdate(data ClueMapEntity) bool {
 				"operator_id":  -1,
 			})
 		}
-		if data.OldTopCluetype != data.NewTopCluetype {
+		if data.OldSubCluetype != data.OldSubCluetype {
 			updateId13 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
 				"clue_id":      data.ClueId,
 				"position_id":  data.PositionId,
-				"change_field": "sub_cluetype",
+				"change_field": "sub_cluetype", //555
 				"change_type":  "基本信息变更",
 				"old_value":    common.If(old_subname != "", old_subname, "/"),
 				"new_value":    common.If(data.Subname != "", data.Subname, "/"),
@@ -2073,6 +2124,7 @@ func clueInfoUpdate(data ClueMapEntity) bool {
 				"BCPCID":       BCPCID,
 				"operator_id":  -1,
 			})
+			LabelHandel(tx, data.Label, 1, data.UId, data.Level, data.Trailstatus, data.Trailstatus, 0)
 		}
 		return ok && updateId1 > -1 && updateId2 > -1 && updateId3 > -1 && updateId4 > -1 && updateId5 > -1 && updateId6 > -1 && updateId7 > -1 && updateId8 > -1 && updateId9 > -1 && updateId10 > -1 && updateId11 > -1 && updateId12 > -1 && updateId13 > -1
 	}) {
@@ -2094,3 +2146,54 @@ func clueInfoUpdate(data ClueMapEntity) bool {
 		return false
 	}
 }
+
+// 线索标签修改 label  labelChangeTime
+func LabelHandel(tx *sql.Tx, oldlabelType, labelType int64, uId, level, oldTrailstatusCode, trailstatusCode string, status int64) {
+	log.Println("线索标签修改:", "oldlabelType:", oldlabelType, "labelType:", labelType, "uId:", uId, "level:", level, "oldTrailstatusCode:", oldTrailstatusCode, "trailstatusCode:", trailstatusCode, "status:", status)
+	//先查询以前什么类型
+	if trailstatusCode != "01" && oldTrailstatusCode != "01" {
+		log.Println("不属于商机类型", uId)
+		return
+	}
+	if status != 0 {
+		log.Println("不属于未完成", uId)
+		return
+	}
+	updateLabelType := int64(0)
+	nowStr := time.Now().Format("2006-01-02")
+	if labelType == 1 {
+		//直接更新
+		if oldlabelType != 1 {
+			updateLabelType = labelType
+		}
+	} else if labelType == 2 {
+		if level != "A" && level != "B" && level != "C" {
+			return
+		}
+		//查询以前是什么数据
+		//同一天修改过
+		if oldlabelType != 1 {
+			updateLabelType = labelType
+		}
+	}
+	if updateLabelType > 0 {
+		ok := false
+		if tx == nil {
+			ok = TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{
+				"uid": uId,
+			}, map[string]interface{}{
+				"label":           updateLabelType,
+				"labelChangeTime": nowStr,
+			})
+		} else {
+			ok = TiDb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{
+				"uid": uId,
+			}, map[string]interface{}{
+				"label":           updateLabelType,
+				"labelChangeTime": nowStr,
+			})
+		}
+
+		log.Println("线索标签修改", ok)
+	}
+}

+ 75 - 47
clueSync/jobutil.go

@@ -77,7 +77,7 @@ func WorkDataHandle(company, phone, demand, name, product string, acceptanceData
 		cluename = phone //没有线索名,手机号代替
 	}
 	ok, data, saleData := false, map[string]interface{}{}, []map[string]interface{}{}
-	isGroup, isCommerce := GetCompanyType(cluename)
+	isGroup, isCommerce := GetCompanyType(cluename, uId)
 	uCount, _ := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, "", ""), true //查当前线索是否已存在
 	if uCount != nil && len(*uCount) > 0 {
 		isUpdate := gconv.Int64((*uCount)["is_artificially_modified"])
@@ -501,6 +501,7 @@ func orders() {
 	selectTimeStart := time.Unix(time.Now().Unix()-7200, 0).Format(date.Date_Full_Layout)
 	selectTimeEnd := time.Unix(time.Now().Unix()-3600, 0).Format(date.Date_Full_Layout)
 	sql := fmt.Sprintf(`select * from dataexport_order where create_time <= "%s" and create_time >= "%s" and id > %s`, selectTimeEnd, selectTimeStart, fmt.Sprint(lastOrderId))
+	//sql := fmt.Sprintf(`select * from dataexport_order where id=260265`)
 	data := Mysql.SelectBySql(sql)
 	if data != nil && *data != nil && len(*data) > 0 {
 		for _, v := range *data {
@@ -596,7 +597,7 @@ func users() {
 	selectXcxTimeEnd := cfg.LastXcxUserId
 	xcxSql := fmt.Sprintf(`SELECT DISTINCT
 	aa.mgo_id as  userId,
-	cc.NAME as   industry ,
+	cc.code as   industry ,
 	aa.phone,
 	IF
 			( aa.phone_time IS NULL, aa.create_time, aa.phone_time ) as  time 
@@ -770,6 +771,7 @@ func userbase() {
 		dwd_f_userbase_contacts a
 	INNER JOIN dwd_f_userbase_baseinfo b ON
 	    b.status= 1 
+	    and  (b.s_platform != 'xcx' or  b.s_platform is  NULL)
 		AND a.phone = b.phone and a.baseinfo_id= b.uid and     a.source  ="0101"
   		and  a.phone  is  not   NULL  
 		and   a.createtime   >="%s"
@@ -982,37 +984,6 @@ func getClueType(item string, data map[string]interface{}, sourceCode string, so
 			code = "618"
 			subname = "7天后到期"
 		}
-	} else if item == "xcxusers" {
-		level = "S"
-		pcode = "532"
-		code = "477"
-		topname = "其他"
-		switch sourceCode {
-		case "环境采购":
-			pcode = "532"
-			code = "696"
-			subname = `首次使用“环境”小程序`
-		case "物业":
-			pcode = "532"
-			code = "693"
-			subname = `首次使用“物业”小程序`
-		case "印务商机":
-			pcode = "532"
-			code = "697"
-			subname = `首次使用“印务”小程序`
-		case "家具":
-			pcode = "532"
-			code = "695"
-			subname = `首次使用“家具”小程序`
-		case "车辆租赁":
-			pcode = "532"
-			code = "694"
-			subname = `首次使用“车辆”小程序`
-		case "安防":
-			pcode = "532"
-			code = "701"
-			subname = `首次使用“安防”小程序`
-		}
 	} else if item == "allocation" {
 		pcode = "532"
 		code = "671"
@@ -1349,7 +1320,7 @@ func getPositionId(phone string) (positionId int64) {
 	userData, ok := Mgo.FindOne("user", map[string]interface{}{"s_phone": phone})
 	if ok && userData != nil && len(*userData) > 0 {
 		userId := common.Int64All((*userData)["base_user_id"])
-		positionData := Base.FindOne("base_position", map[string]interface{}{"type": 1, "ent_id": 25917, "user_id": userId}, "", "") //TODO ent_id
+		positionData := Base.FindOne("base_position", map[string]interface{}{"type": 1, "ent_id": db.EntId, "user_id": userId}, "", "") //TODO ent_id
 		if positionData != nil && len(*positionData) > 0 {
 			positionId = common.Int64All((*positionData)["id"])
 		}
@@ -1357,15 +1328,30 @@ func getPositionId(phone string) (positionId int64) {
 	return
 }
 
-func GetCompanyType(companyName string) (int, int) {
-	//是否是集团
+func GetCompanyType(companyName string, uId string) (int, int) {
 	isGroup, isCommerce := 0, 0
+	uCount := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, "", "")
+	if uCount != nil && len(*uCount) > 0 {
+		isUpdate := gconv.Int64((*uCount)["is_artificially_modified"])
+		if isUpdate == 1 {
+			companyName = gconv.String((*uCount)["cluename"])
+		}
+		if companyName == "" {
+			companyName = gconv.String((*uCount)["cluename"])
+		}
+	}
+	if companyName == "" {
+		return isGroup, isCommerce
+	}
+	//是否是集团
 	if c := TiDb.CountBySql(`select count(1) from group_company_name where company_name=?`, companyName); c > 0 {
 		isGroup = 1
 	}
 	//是否在工商库
-	if c := MgoQyxy.Count("qyxy_std", map[string]interface{}{"company_name": companyName, "company_type": map[string]interface{}{"$ne": "个体工商户"}}); c > 0 {
-		isCommerce = 1
+	if companyName != "" {
+		if c := MgoQyxy.Count("qyxy_std", map[string]interface{}{"company_name": companyName, "company_type": map[string]interface{}{"$ne": "个体工商户"}}); c > 0 {
+			isCommerce = 1
+		}
 	}
 	return isGroup, isCommerce
 }
@@ -1697,12 +1683,12 @@ func AFEmail(data []map[string]interface{}) {
 		log.Println("xls error", err, dir)
 	} else {
 		gmail := &mail.GmailAuth{
-			SmtpHost: "smtp.exmail.qq.com",
-			SmtpPort: 465,
-			User:     "public03@topnet.net.cn",
-			Pwd:      "ue9Rg9Sf4CVtdm5a",
+			SmtpHost: db.Mail.SmtpHost,
+			SmtpPort: db.Mail.SmtpPort,
+			User:     db.Mail.User,
+			Pwd:      db.Mail.Pwd,
 		}
-		status := mail.GSendMail_q("剑鱼标讯", email, "", "", fileName, detailName, dir, fileName+".xlsx", gmail)
+		status := mail.GSendMail_q("剑鱼标讯", email, "", "", fileName, detailName, dir, "", gmail)
 		if status {
 			log.Println("send mail success", fileName, email)
 		}
@@ -1866,16 +1852,18 @@ func sendEmailIfSuccessful(err error, fileName, detailName, dir string) {
 	}
 	email := db.AbhEmail
 	gmail := &mail.GmailAuth{
-		SmtpHost: "smtp.exmail.qq.com",
-		SmtpPort: 465,
-		User:     "public03@topnet.net.cn",
-		Pwd:      "ue9Rg9Sf4CVtdm5a",
+		SmtpHost: db.Mail.SmtpHost,
+		SmtpPort: db.Mail.SmtpPort,
+		User:     db.Mail.User,
+		Pwd:      db.Mail.Pwd,
 	}
 	status := mail.GSendMail_q("剑鱼标讯", email, "", "", fileName, detailName, dir, fileName+".xlsx", gmail)
 	if status {
 		log.Println("send mail success", fileName, email)
 	}
 }
+
+// 邀请用户处理
 func inviteUser() {
 	log.Println("邀请用户处理开始")
 	//判断节假日
@@ -1915,3 +1903,43 @@ func inviteUser() {
 	}
 	log.Println("邀请用户处理结束")
 }
+
+// 开年活动
+func nextYearActivity() {
+	log.Println("开年活动处理开始")
+	//判断节假日
+	runOk := getRunOk()
+	if !runOk {
+		log.Println("不是工作日,任务暂停")
+		return
+	}
+	activityTimeEnd := cfg.ActivityTime
+	sql := fmt.Sprintf(`SELECT
+							 a.*
+							FROM
+								jyactivities.lottery_user_account a  
+								INNER JOIN  jyactivities.lottery_prize_info b  on     a.create_time > "%s"  and  a.prize_id=b.id
+								INNER JOIN  jyactivities.prize_base_info c  on   c.name like "%s"  and b.pb_id=c.id
+							ORDER BY
+								a.create_time ASC
+`, activityTimeEnd, "%超级订阅%")
+	data := Mysql.SelectBySql(sql)
+	if data != nil && *data != nil && len(*data) > 0 {
+		for _, v := range *data {
+			activityTimeEnd = common.ObjToString(v["create_time"])
+			v["sourceCode"] = gconv.Int64(v["active_id"])
+			v["user_id"] = gconv.String(v["mgo_user_id"])
+			ok1, ok2, _ := FormatData(v, "activity")
+			if !ok1 {
+				log.Println("线索卡点", "activity", v, activityTimeEnd)
+			} else {
+				if !ok2 {
+					log.Println("开年活动分配已达上限", "activity", v, activityTimeEnd)
+				}
+			}
+		}
+		cfg.ActivityTime = activityTimeEnd
+		common.WriteSysConfig(&cfg)
+	}
+	log.Println("开年活动处理结束")
+}

File diff suppressed because it is too large
+ 807 - 264
clueSync/kc.go


+ 1 - 1
clueSync/log.go

@@ -37,7 +37,7 @@ func initLog(saveDay int) {
 	go logfile()
 	task := cron.New()
 	task.Start()
-	task.AddFunc("0 0 0/1 * * ?", func() {
+	task.AddFunc("0 0 0/2 * * ?", func() {
 		go logfile()
 		time.Sleep(50 * time.Second)
 		if saveDay > 0 {

+ 11 - 0
clueSync/main.go

@@ -3,6 +3,7 @@ package main
 import (
 	"app.yhyue.com/moapp/jybase/common"
 	elastic "app.yhyue.com/moapp/jybase/es"
+	"app.yhyue.com/moapp/jybase/mail"
 	"app.yhyue.com/moapp/jybase/mongodb"
 	"app.yhyue.com/moapp/jybase/mysql"
 	"app.yhyue.com/moapp/jybase/redis"
@@ -33,6 +34,7 @@ var (
 	MgoQyxy             *mongodb.MongodbSim
 	mode                = flag.Int("m", 1, "")
 	startTime, endTime  = "00:00", "23:59"
+	Gmail               mail.GmailAuth
 )
 
 func main() {
@@ -41,6 +43,12 @@ func main() {
 	log.Println("cfg ", cfg)
 	common.ReadConfig("./db.json", &db)
 	log.Println("db ", db)
+	Gmail = mail.GmailAuth{
+		SmtpHost: db.Mail.SmtpHost,
+		SmtpPort: db.Mail.SmtpPort,
+		User:     db.Mail.User,
+		Pwd:      db.Mail.Pwd,
+	}
 	TiDb = &mysql.Mysql{
 		Address:      db.TiDb.Host + ":" + fmt.Sprint(db.TiDb.Port),
 		UserName:     db.TiDb.User,
@@ -169,6 +177,7 @@ func main() {
 			rebind()              //取关重新关注处理
 			activeUsers()         //活跃用户处理
 			inviteUser()          //邀请用户
+			nextYearActivity()    //开年活动
 		})
 		//每天8点30
 		c := cron.New()
@@ -196,6 +205,7 @@ func main() {
 			autoExitSea()      //自动退海
 			Thaw()             //自动解冻处理
 			subscribeAddSync() //订阅增量
+			CustomerChange()
 		})
 		//5分钟一次
 		go p.VarTimeTask.RunInTimeLoop("5分钟定时任务3", "", "", db.CornExp6, true, true, nil, func() {
@@ -211,6 +221,7 @@ func main() {
 			refundAuto() //客成移交销售
 			autoTask()   //超时未跟进加入任务车
 			autoTasks()  //按照下次跟进时间提前一天加入任务车
+			ClueToDxTask()
 		})
 		g.Start()
 		log.Println("个人邮件告警查询开始")

+ 4 - 4
clueSync/sendMail.go

@@ -394,10 +394,10 @@ func sendInfo(to, cs, title, content string) {
 	log.Println("发送人:", to)
 	log.Println("抄送:", cs)
 	gmail := &mail.GmailAuth{
-		SmtpHost: "smtp.exmail.qq.com",
-		SmtpPort: 465,
-		User:     "public03@topnet.net.cn",
-		Pwd:      "ue9Rg9Sf4CVtdm5a",
+		SmtpHost: db.Mail.SmtpHost,
+		SmtpPort: db.Mail.SmtpPort,
+		User:     db.Mail.User,
+		Pwd:      db.Mail.Pwd,
 	}
 	status := mail.GSendMail_dx("剑鱼标讯", to, cs, "", title, content, "", "", gmail)
 	if status {

+ 28 - 0
clueSync/util.go

@@ -0,0 +1,28 @@
+package main
+
+import (
+	"fmt"
+	"time"
+)
+
+func TimeStrcount(start, end string) int64 {
+	timeFormat := "2006-01-02 15:04:05" // 定义时间格式
+	// 两个时间字符串
+	// 解析时间字符串为 Time 对象
+	startTime, err := time.Parse(timeFormat, start)
+	if err != nil {
+		fmt.Println("Error parsing start time:", err)
+		return 0
+	}
+	endTime, err := time.Parse(timeFormat, end)
+	if err != nil {
+		fmt.Println("Error parsing end time:", err)
+		return 0
+	}
+	// 计算时间差
+	diff := endTime.Sub(startTime)
+	// 获取相差的天数
+	days := int64(diff.Hours() / 24)
+	fmt.Printf("相差的天数: %d 天\n", days)
+	return days
+}

+ 1 - 0
doFreeClueSign/config.yaml

@@ -1,4 +1,5 @@
 lastId: 258768
+historyData: true
 mongodb:
   default: #qfw
     address: "192.168.3.149:27180"

+ 11 - 4
doFreeClueSign/job/job.go

@@ -2,6 +2,7 @@ package job
 
 import (
 	"context"
+	"doFreeClueSign/db"
 	"doFreeClueSign/public"
 	"github.com/gogf/gf/v2/encoding/gjson"
 	"github.com/gogf/gf/v2/frame/g"
@@ -126,6 +127,7 @@ func loadOrder() {
 			}
 		}
 	}
+	g.Log().Infof(ctx, "loadOrder end: %d", LastId)
 }
 
 func LoadOrderOther() {
@@ -172,17 +174,22 @@ func LoadOrderHis() {
 			}
 			userid := gconv.String(m["user_id"])
 			now := time.Now().Format(time.DateTime)
-			g.DB("bi_service").Exec(ctx, `INSERT INTO user_statistics (userId, createTime, event) SELECT ?, ?, 1 WHERE NOT EXISTS ( SELECT 1 FROM user_statistics WHERE userId = ? AND event = 1)`, userid, now, userid)
+			user, _ := db.MG.DB().FindById("user", userid, `{"i_vip_status":1, "i_member_status": 1}`)
+			if user != nil && len(*user) > 0 {
+				if gconv.Int((*user)["i_vip_status"]) <= 0 && gconv.Int((*user)["i_member_status"]) <= 0 {
+					g.DB("bi_service").Exec(ctx, `INSERT INTO user_statistics (userId, createTime, event) SELECT ?, ?, 1 WHERE NOT EXISTS ( SELECT 1 FROM user_statistics WHERE userId = ? AND event = 1)`, userid, now, userid)
+				}
+			}
 		}
 	}
-	g.Log().Infof(ctx, "LoadOrderHis end")
+	g.Log().Info(ctx, "LoadOrderHis end")
 }
 
 // @Author jianghan
 // @Description 11月9日注册成功
 // @Date 2024/11/20
 func LoadOrderHisMore() {
-	g.Log().Infof(ctx, "LoadOrderHisMore start")
+	g.Log().Info(ctx, "LoadOrderHisMore start")
 	now := time.Now().Format(time.DateTime)
 	sql := `SELECT id, filter, order_code, product_type, user_id, user_phone, vip_starttime, vip_endtime FROM dataexport_order WHERE order_status = 1 AND vip_endtime > '2024-11-16 00:00:00' AND vip_endtime < ? AND filter LIKE '%2024年新用户注册赠送7天超级订阅%' ORDER BY id DESC`
 	sql1 := `SELECT id, vip_endtime FROM jianyu.dataexport_order WHERE (product_type = 'VIP订阅' OR product_type = '大会员') AND id > ? AND user_id = ? AND order_status = 1`
@@ -197,5 +204,5 @@ func LoadOrderHisMore() {
 			}
 		}
 	}
-	g.Log().Infof(ctx, "LoadOrderHisMore end")
+	g.Log().Info(ctx, "LoadOrderHisMore end")
 }

+ 6 - 2
doFreeClueSign/main.go

@@ -1,13 +1,17 @@
 package main
 
 import (
+	"context"
 	"doFreeClueSign/job"
 	_ "github.com/gogf/gf/contrib/drivers/mysql/v2"
+	"github.com/gogf/gf/v2/frame/g"
 )
 
 func main() {
-	go job.LoadOrderHis()
-	go job.LoadOrderHisMore()
+	if g.Cfg().MustGet(context.TODO(), "historyData").Bool() {
+		go job.LoadOrderHis()
+		go job.LoadOrderHisMore()
+	}
 
 	job.InitJobManager()
 

Some files were not shown because too many files changed in this diff