|
@@ -0,0 +1,88 @@
|
|
|
+package main
|
|
|
+
|
|
|
+import (
|
|
|
+ "log"
|
|
|
+ "regexp"
|
|
|
+
|
|
|
+ "strings"
|
|
|
+
|
|
|
+ "app.yhyue.com/moapp/jybase/common"
|
|
|
+ "github.com/tealeg/xlsx"
|
|
|
+)
|
|
|
+
|
|
|
+func trail() {
|
|
|
+ log.Println("合力亿捷跟进历史任务开始")
|
|
|
+ nameReg := regexp.MustCompile("【.*?】")
|
|
|
+ filePath := "./xlsx/跟进历史" + cfg.XlsxNum + ".xlsx"
|
|
|
+ log.Println("文件名 ", filePath)
|
|
|
+ xlFile, _ := xlsx.OpenFile(filePath)
|
|
|
+ //获取行数
|
|
|
+ length := len(xlFile.Sheets[0].Rows)
|
|
|
+ log.Println("获取行数 ", length)
|
|
|
+ //遍历sheet
|
|
|
+ for _, sheet := range xlFile.Sheets {
|
|
|
+ //遍历每一行
|
|
|
+ for rowIndex, row := range sheet.Rows {
|
|
|
+ //跳过第一行表头信息
|
|
|
+ if rowIndex == 0 {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ createtime := row.Cells[0].Value
|
|
|
+ name := row.Cells[1].Value
|
|
|
+ nexttype := row.Cells[2].Value
|
|
|
+ content := row.Cells[3].Value
|
|
|
+ phone := row.Cells[6].Value
|
|
|
+ positionId, clueId := getSale(name, phone)
|
|
|
+ log.Println("positionId,clueId ", positionId, clueId)
|
|
|
+ if clueId > 0 {
|
|
|
+ if nexttype == "无类型" {
|
|
|
+ TiDb.Insert("dwd_f_crm_trail_content", map[string]interface{}{
|
|
|
+ "clue_id": clueId,
|
|
|
+ "position_id": positionId,
|
|
|
+ "createtime": createtime,
|
|
|
+ "content": content,
|
|
|
+ "operator_id": positionId,
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ old_value := strings.ReplaceAll(strings.ReplaceAll(nameReg.FindAllString(content, -1)[0], "【", ""), "】", "")
|
|
|
+ new_value := strings.ReplaceAll(strings.ReplaceAll(nameReg.FindAllString(content, -1)[1], "【", ""), "】", "")
|
|
|
+ TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
+ "clue_id": clueId,
|
|
|
+ "position_id": positionId,
|
|
|
+ "createtime": createtime,
|
|
|
+ "change_field": common.If(nexttype == "所属人变更", "position_id", "trailstatus"),
|
|
|
+ "change_type": common.If(nexttype == "所属人变更", nexttype, "基本信息变更"),
|
|
|
+ "old_value": common.If(old_value == "销售线索", "商机线索", old_value),
|
|
|
+ "new_value": common.If(new_value == "销售线索", "商机线索", new_value),
|
|
|
+ "operator_id": positionId,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func getSale(name, phone string) (positionId, clueId int64) {
|
|
|
+ saleData := TiDb.FindOne("jy_salesperson_info", map[string]interface{}{"name": name, "status": 0}, "", "")
|
|
|
+ if saleData != nil && len(*saleData) > 0 {
|
|
|
+ salePhone := common.ObjToString((*saleData)["phone"])
|
|
|
+ userInfo := TiDb.FindOne("dwd_f_userbase_baseinfo", map[string]interface{}{"phone": salePhone}, "", "")
|
|
|
+ if userInfo != nil && len(*userInfo) > 0 {
|
|
|
+ base_user_id := common.Int64All((*userInfo)["base_user_id"])
|
|
|
+ positionData := Base.FindOne("base_position", map[string]interface{}{"type": 1, "user_id": base_user_id, "ent_id": 25917}, "", "")
|
|
|
+ if positionData != nil && len(*positionData) > 0 {
|
|
|
+ positionId = common.Int64All((*positionData)["id"])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ positionId = -1
|
|
|
+ }
|
|
|
+ if positionId == 0 {
|
|
|
+ positionId = -1
|
|
|
+ }
|
|
|
+ clueInfo := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"phone": phone}, "", "")
|
|
|
+ if clueInfo != nil && len(*clueInfo) > 0 {
|
|
|
+ clueId = common.Int64All((*clueInfo)["id"])
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|