Bläddra i källkod

Merge branch 'dev_v1.5.21_wh' of jianyu/datatools into feature/v1.5.21

王浩 8 månader sedan
förälder
incheckning
e7ddccce20
3 ändrade filer med 227 tillägg och 5 borttagningar
  1. 225 1
      clueSync/job.go
  2. 1 1
      clueSync/log.go
  3. 1 3
      clueSync/main.go

+ 225 - 1
clueSync/job.go

@@ -1413,6 +1413,39 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 			}
 		}
 	}
+	//只更新线索不更新人员信息
+	if is_assign != 1 && is_assign != 0 && is_assign != -1 {
+		clueUpdateData["comeintime"] = nowTime
+		clueMapEntity := ClueMapEntity{
+			UId:                  uId,
+			OldTopCluetype:       old_top_cluetype,
+			OldSubCluetype:       old_sub_cluetype,
+			NewTopCluetype:       top_cluetype,
+			NewSubCluetype:       sub_cluetype,
+			Item:                 item,
+			OldName:              old_name,
+			NewName:              name,
+			ClueUpdateData:       clueUpdateData,
+			ClueId:               clueId,
+			OldPosition:          old_position,
+			NewPosition:          position,
+			OldDepartment:        old_department,
+			NewDepartment:        department,
+			OldRole:              old_role,
+			NewRole:              role,
+			OldFollowProjectArea: old_follow_project_area,
+			NewFollowProjectArea: follow_project_area,
+			NewCluename:          cluename,
+			OldCluename:          old_cluename,
+			Subname:              subname,
+			Topname:              topname,
+			Phone:                phone,
+			Source:               source,
+			PositionId:           old_position_id,
+		}
+		return clueInfoUpdate(clueMapEntity)
+
+	}
 	if trailstatus == "00" || trailstatus == "09" || old_position_id == 0 || is_assign != 1 || (pIsOk && old_cluename != cluename && cluename != "") {
 		if trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400 {
 			//无意向几天以内不参与分配
@@ -1438,7 +1471,7 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 	} else { //不属于上边情况就还是属于原来的销售,不更换销售
 		clueUpdateData["seatNumber"] = old_seatNumber
 		clueUpdateData["position_id"] = old_position_id
-		clueUpdateData["is_assign"] = 1
+		//clueUpdateData["is_assign"] = 1
 		clueUpdateData["comeinsource_open"] = nil
 		clueUpdateData["level_open"] = nil
 		clueUpdateData["clue_level"] = nil
@@ -1870,3 +1903,194 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 		return false
 	}
 }
+
+type ClueMapEntity struct {
+	UId                  string
+	OldTopCluetype       string
+	OldSubCluetype       string
+	NewTopCluetype       string
+	NewSubCluetype       string
+	Item                 string
+	OldName              string
+	NewName              string
+	ClueUpdateData       map[string]interface{}
+	ClueId               int64
+	Trailstatus          string
+	OldPosition          string
+	NewPosition          string
+	OldDepartment        string
+	NewDepartment        string
+	OldRole              string
+	NewRole              string
+	OldFollowProjectArea string
+	NewFollowProjectArea string
+	NewCluename          string
+	OldCluename          string
+	Subname              string
+	Topname              string
+	Phone                string
+	Source               string
+	PositionId           int64
+}
+
+// 基本信息变更
+func clueInfoUpdate(data ClueMapEntity) bool {
+	ok := false
+	updateId1, updateId2, updateId3, updateId4, updateId5 := int64(0), int64(0), int64(0), int64(0), int64(0)
+	updateId6, updateId7, updateId8, updateId9, updateId10 := int64(0), int64(0), int64(0), int64(0), int64(0)
+	updateId11, updateId12, updateId13 := int64(0), int64(0), int64(0)
+	nowTime := time.Now().Format("2006-01-02 15:04:05")
+	if TiDb.ExecTx("更新线索", func(tx *sql.Tx) bool {
+		log.Println("修改线索", data)
+		BCPCID := common.GetRandom(32)
+		old_topname, old_subname := "", ""
+		//线索
+		ok = TiDb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"uid": data.UId}, data.ClueUpdateData)
+		//变更记录
+		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"])
+			}
+		}
+		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"])
+			}
+		}
+		if data.Item != "orders" {
+			if data.OldName != data.NewName && data.NewName != "" {
+				updateId6 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+					"clue_id":      data.ClueId,
+					"position_id":  data.PositionId,
+					"change_field": "name",
+					"change_type":  "基本信息变更",
+					"old_value":    common.If(data.OldName != "", data.OldName, "/"),
+					"new_value":    common.If(data.NewName != "", data.NewName, "/"),
+					"createtime":   nowTime,
+					"BCPCID":       BCPCID,
+					"operator_id":  -1,
+				})
+			}
+			if data.OldPosition != data.NewPosition && data.NewPosition != "" {
+				updateId7 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+					"clue_id":      data.ClueId,
+					"position_id":  data.PositionId,
+					"change_field": "position",
+					"change_type":  "基本信息变更",
+					"old_value":    common.If(data.OldPosition != "", data.OldPosition, "/"),
+					"new_value":    common.If(data.NewPosition != "", data.NewPosition, "/"),
+					"createtime":   nowTime,
+					"BCPCID":       BCPCID,
+					"operator_id":  -1,
+				})
+			}
+			if data.OldDepartment != data.NewDepartment && data.NewDepartment != "" {
+				updateId8 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+					"clue_id":      data.ClueId,
+					"position_id":  data.PositionId,
+					"change_field": "department",
+					"change_type":  "基本信息变更",
+					"old_value":    common.If(data.OldDepartment != "", data.OldDepartment, "/"),
+					"new_value":    common.If(data.NewDepartment != "", data.NewDepartment, "/"),
+					"createtime":   nowTime,
+					"BCPCID":       BCPCID,
+					"operator_id":  -1,
+				})
+			}
+			if data.OldRole != data.NewRole && data.NewRole != "" {
+				updateId9 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+					"clue_id":      data.ClueId,
+					"position_id":  data.PositionId,
+					"change_field": "role",
+					"change_type":  "基本信息变更",
+					"old_value":    common.If(data.OldRole != "", data.OldRole, "/"),
+					"new_value":    common.If(data.NewRole != "", data.NewRole, "/"),
+					"createtime":   nowTime,
+					"BCPCID":       BCPCID,
+					"operator_id":  -1})
+			}
+			if data.OldFollowProjectArea != data.NewFollowProjectArea && data.NewFollowProjectArea != "" {
+				old_area, old_area_arr := "", []string{}
+				new_area, new_area_arr := "", []string{}
+				for _, v := range strings.Split(data.OldFollowProjectArea, ",") {
+					old_area_arr = append(old_area_arr, CodeArea[v])
+				}
+				for _, v := range strings.Split(data.NewFollowProjectArea, ",") {
+					new_area_arr = append(new_area_arr, CodeArea[v])
+				}
+				old_area = strings.Join(old_area_arr, ",")
+				new_area = strings.Join(new_area_arr, ",")
+				updateId10 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+					"clue_id":      data.ClueId,
+					"position_id":  data.PositionId,
+					"change_field": "follow_project_area",
+					"change_type":  "基本信息变更",
+					"old_value":    common.If(old_area != "", old_area, "/"),
+					"new_value":    common.If(new_area != "", new_area, "/"),
+					"createtime":   nowTime,
+					"BCPCID":       BCPCID,
+					"operator_id":  -1,
+				})
+			}
+			if data.OldCluename != data.NewCluename && data.NewCluename != "" {
+				updateId11 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+					"clue_id":      data.ClueId,
+					"position_id":  data.PositionId,
+					"change_field": "cluename",
+					"change_type":  "基本信息变更",
+					"old_value":    common.If(data.OldCluename != "", data.OldCluename, "/"),
+					"new_value":    common.If(data.NewCluename != "", data.NewCluename, "/"),
+					"createtime":   nowTime,
+					"BCPCID":       BCPCID,
+					"operator_id":  -1,
+				})
+			}
+		}
+		if data.OldTopCluetype != data.NewTopCluetype {
+			updateId12 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+				"clue_id":      data.ClueId,
+				"position_id":  data.PositionId,
+				"change_field": "top_cluetype",
+				"change_type":  "基本信息变更",
+				"old_value":    common.If(old_topname != "", old_topname, "/"),
+				"new_value":    common.If(data.Topname != "", data.Topname, "/"),
+				"createtime":   nowTime,
+				"BCPCID":       BCPCID,
+				"operator_id":  -1,
+			})
+		}
+		if data.OldTopCluetype != data.NewTopCluetype {
+			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_type":  "基本信息变更",
+				"old_value":    common.If(old_subname != "", old_subname, "/"),
+				"new_value":    common.If(data.Subname != "", data.Subname, "/"),
+				"createtime":   nowTime,
+				"BCPCID":       BCPCID,
+				"operator_id":  -1,
+			})
+		}
+		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
+	}) {
+		log.Println("线索更新成功")
+		if TiDb.Count("dwd_f_userbase_contacts", map[string]interface{}{"phone": data.Phone}) == 0 {
+			TiDb.Insert("dwd_f_userbase_contacts", map[string]interface{}{
+				"status":      1,
+				"is_delete":   1,
+				"createtime":  nowTime,
+				"updatetime":  nowTime,
+				"phone":       data.Phone,
+				"baseinfo_id": data.UId,
+				"SOURCE":      data.Source,
+			})
+		}
+		return true
+	} else {
+		log.Println("线索更新失败!!!", ok, updateId1, updateId2, updateId3, updateId4, updateId5, updateId6, updateId7, updateId8, updateId9, updateId10, updateId11, updateId12, updateId13)
+		return false
+	}
+}

+ 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 * * ?", func() {
+	task.AddFunc("0 0 0/1 * * ?", func() {
 		go logfile()
 		time.Sleep(50 * time.Second)
 		if saveDay > 0 {

+ 1 - 3
clueSync/main.go

@@ -6,10 +6,8 @@ import (
 	"app.yhyue.com/moapp/jybase/mongodb"
 	"app.yhyue.com/moapp/jybase/mysql"
 	"app.yhyue.com/moapp/jybase/redis"
-	"bp.jydev.jianyu360.cn/BaseService/pushpkg/p"
 	"flag"
 	"fmt"
-	"github.com/robfig/cron"
 	"log"
 )
 
@@ -146,6 +144,7 @@ func main() {
 	InitArea()
 	InitProduct(db.ProductArr)
 	if *mode == 1 {
+		go ordersClue() //后台订单进线索
 		//一秒钟一次
 		go p.VarTimeTask.RunInSecondTimeLoop("1秒钟定时任务", "", "", db.CornExp8, true, true, nil, func() {
 			LockHandle() //绑定状态处理
@@ -186,7 +185,6 @@ func main() {
 		})
 		d.Start()
 		// 5分钟一次
-		go ordersClue() //后台订单进线索
 		go p.VarTimeTask.RunInTimeLoop("5分钟定时任务2", "", "", db.CornExp5, true, true, nil, func() {
 			//go p.VarTimeTask.RunInTimeSection("5分钟定时任务2", startTime, endTime, db.CornExp5, func(dayFirst bool) {
 			everythingSync()   //渠道