1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263 |
- package main
- import (
- "database/sql"
- "fmt"
- "github.com/gogf/gf/v2/util/gconv"
- "log"
- "regexp"
- "strings"
- "time"
- "app.yhyue.com/moapp/jybase/date"
- "app.yhyue.com/moapp/jybase/redis"
- "app.yhyue.com/moapp/jybase/common"
- "app.yhyue.com/moapp/jybase/mongodb"
- )
- func FormatData(data map[string]interface{}, item string) (bool, bool, bool) {
- 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")
- if item == "orders" { //订单
- if !mongodb.IsObjectIdHex(userId) {
- positionId = userId
- userMapping := TiDb.FindOne("data_service.user_system", map[string]interface{}{"position_id": userId}, "", "")
- if userMapping != nil && len(*userMapping) > 0 {
- userId = gconv.String((*userMapping)["userid"])
- }
- }
- 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"]) //用户归属
- }
- cluename = gconv.String(data["company_name"])
- phone = gconv.String(data["user_phone"])
- } else if item == "message" {
- userMapping := TiDb.FindOne("data_service.user_system", map[string]interface{}{"base_user_id": common.Int64All(data["own_id"])}, "", "")
- if userMapping != nil && len(*userMapping) > 0 {
- 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 = 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 = gconv.String((*phoneMapping)["cluename"])
- }
- }
- }
- } else if item == "tag" {
- userMapping := TiDb.FindOne("data_service.user_system", map[string]interface{}{"base_user_id": common.Int64All(data["baseUserId"])}, "", "")
- if userMapping != nil && len(*userMapping) > 0 {
- 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 = 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 = gconv.String((*phoneMapping)["cluename"])
- }
- }
- }
- } else if item == "users" || item == "xcxusers" { //注册用户
- if Mgo.Count("user_share", map[string]interface{}{
- "shared_uid": userId,
- }) > 0 {
- return true, true, true
- }
- sourceCode = gconv.String(data["rsource"])
- userId = mongodb.BsonIdToSId(data["userid"])
- //新用户没有uid、source要等5分钟
- 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 gconv.String((*contactsData)[0]["baseinfo_id"]) != "" {
- uId = gconv.String((*contactsData)[0]["baseinfo_id"])
- query["uid"] = uId
- } else {
- query["userid"] = userId
- }
- } else {
- query["userid"] = userId
- }
- //createtimeStr := ""
- 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"])
- //s_sourceid = gconv.String((*userInfo)["s_sourceid"])
- //createtimeStr = gconv.String((*userInfo)["l_registedate"])
- }
- if item == "xcxusers" {
- sourceCode = gconv.String(data["industry"])
- //t, _ := time.Parse("2006-01-02 15:04:05", createtimeStr)
- if sourceCode == "" {
- log.Println("留资没有source", phone)
- return true, true, true
- }
- /* 安防代码
- if t.Unix() > db.NewRegistration && sourceCode == "安防" {
- return true, true, false
- }*/
- //线索名称查询处理
- clueData, _ := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, "", ""), true //查当前线索是否已存在
- if clueData != nil && len(*clueData) > 0 {
- cluename = gconv.String((*clueData)["cluename"])
- } else {
- cluename = phone
- }
- }
- }
- } else if item == "allocation" || item == "rebind" {
- userId = mongodb.BsonIdToSId(data["mogUserId"])
- userInfo := TiDb.FindOne("dwd_f_userbase_baseinfo", map[string]interface{}{
- "userid": userId,
- }, "", "")
- if userInfo != nil && len(*userInfo) > 0 {
- 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, gconv.String(data["company"]))
- userId = gconv.String(data["userid"])
- if !mongodb.IsObjectIdHex(userId) {
- positionId = userId
- userMapping := TiDb.FindOne("data_service.user_system", map[string]interface{}{"position_id": userId}, "", "")
- if userMapping != nil && len(*userMapping) > 0 {
- 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 = 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 gconv.String((*contactsData)[0]["baseinfo_id"]) != "" {
- uId = gconv.String((*contactsData)[0]["baseinfo_id"])
- query["uid"] = uId
- } else {
- query["userid"] = userId
- }
- } else {
- query["userid"] = userId
- }
- if userId != "" || uId != "" {
- 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"])
- userId = gconv.String((*userInfo)["userid"])
- //s_sourceid = gconv.String((*userInfo)["s_sourceid"])
- }
- } else {
- if sourceCode == "report_retention" || sourceCode == "marketing_retention" { //荟聚线索来源,不是剑鱼用户,需要等待用户归集
- log.Println("不是剑鱼用户留资,等待用户", phone)
- return false, false, true
- } else if remark != "" {
- log.Println("留资source过滤", phone, sourceCode)
- return true, true, true
- }
- }
- } else if item == "eventReg" { //渠道
- 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 gconv.String((*contactsData)[0]["baseinfo_id"]) != "" {
- uId = gconv.String((*contactsData)[0]["baseinfo_id"])
- query["uid"] = uId
- } else {
- query["userid"] = userId
- }
- } else {
- 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"])
- userId = gconv.String((*userInfo)["userid"])
- }
- if role == "集成商" || role == "设计院" {
- role = "其他-" + role
- }
- } else if item == "readClue" {
- userId = gconv.String(data["userId"])
- 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"])
- }
- // 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 = 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 = 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" && item != "tag" &&
- item != "activity" {
- cluename = phone //没有线索名,手机号代替
- }
- log.Println(333, cluename)
- cluename = strings.ReplaceAll(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 uId == "" { //没有进用户归集,等待进入,结束任务,放在下次继续执行
- if isExists, _ := redis.Exists("bidx", "bidx_userId_"+userId); isExists {
- redisInt := redis.GetInt("bidx", "bidx_userId_"+userId)
- if redisInt > 4 {
- log.Println("线索分配失败,线索缺少信息,任务已执行超过1次", item, userId, phone)
- return true, true, true
- } else {
- redis.Incr("bidx", "bidx_userId_"+userId)
- }
- } else {
- redis.Put("bidx", "bidx_userId_"+userId, 1, 3600)
- }
- log.Println("线索分配失败,线索缺少信息", item, phone, userId)
- return false, false, true
- }
- if item == "orders" { //订单没信息再查一遍留资
- qid := positionId
- if qid == "" {
- qid = userId
- }
- 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 = 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) //查留资来源名字
- if topname == "市场活动" && item == "saleLeads" { //市场活动的不要
- log.Println("市场活动留资过滤 ", userId, phone)
- return true, true, true
- }
- if strings.HasPrefix(belong_to, "03") { //一切都好的不进
- isOk := saveEverything(userId, phone, item, subname, sourceCode, belong_to)
- log.Println("渠道线索电销", userId, phone, item, subname, sourceCode)
- if !isOk {
- return true, true, true
- }
- }
- follow_project_area = getAreaCode(userId) //关注项目区域
- log.Println("data +++", top_cluetype, sub_cluetype, level, follow_project_area, isGroup, isCommerce)
- if top_cluetype == "" || sub_cluetype == "" || level == "" {
- log.Println("线索分配失败,线索过滤top_cluetype!!", item, uId, phone, userId)
- return true, true, true
- }
- log.Println("人员选择", level, cluename, phone, isGroup, isCommerce)
- position_id, seatNumber, saleName, saleData, pIsOk, isFreeze, noticePositionId := autoDraw(level, cluename, phone, isGroup, isCommerce) //查询当前分配次数最少的,如果当前线索有销售,此次找出的不会+1
- log.Println("data -------", position_id, seatNumber, saleName, pIsOk, isFreeze, noticePositionId)
- if position_id > 0 && seatNumber != "" {
- uCount, oks := 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"])
- if isUpdate == 1 {
- cluename = ""
- }
- //已存在,走更新
- batch_import := gconv.String((*uCount)["batch_import"])
- if batch_import != "" && item == "users" { //有导入批次号还是新用户,不执行
- return true, true, true
- }
- oks = UpdateClue(*uCount, saleData, item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, departments, industry, follow_project_area, role, seatNumber, level, position_id, source, sourceCode, remark, keyword, belong_to, isGroup, isCommerce, pIsOk)
- } else { //不存在走新增
- oks = SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, departments, industry, follow_project_area, role, seatNumber, position_id, source, sourceCode, remark, keyword, belong_to, isGroup, isCommerce, isFreeze, "")
- if oks { //新增成功,销售分配次数+1
- TiDb.UpdateOrDeleteBySql(`update dwd_f_crm_clue_autodraw_record set count = count + 1 where position_id = ? and clue_level = ?`, position_id, level)
- }
- }
- if !oks {
- log.Println("线索分配失败!!", item, position_id, seatNumber, uId, userId, phone)
- return false, false, true
- }
- } else {
- if isFreeze {
- //达上限放公海处理
- uCount, oks := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, "", ""), true //查当前线索是否已存在
- if uCount == nil || len(*uCount) == 0 {
- oks = SaveClue0(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, departments, industry, follow_project_area, role, seatNumber, position_id, source, sourceCode, remark, keyword, belong_to, isGroup, isCommerce, isFreeze)
- log.Println(oks)
- } else {
- //留资线索更新
- if item != "orders" && item != "users" { //新用户和订单之外的替换一下新的留资信息
- BCPCID := common.GetRandom(32)
- clueId := common.Int64All((*uCount)["id"])
- 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{}{}
- e_label := gconv.String((*uCount)["e_label"])
- Ehandle(clueId, uId, userId, cluename, trailstatusCode, e_label)
- if old_name != name && name != "" {
- clueUpdateData["name"] = name
- TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
- "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, "/"),
- "createtime": nowTime,
- "BCPCID": BCPCID,
- "operator_id": -1})
- }
- if old_position != position && position != "" {
- clueUpdateData["position"] = position
- TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "change_field": "position",
- "position_id": 0,
- "change_type": "基本信息变更",
- "old_value": common.If(old_position != "", old_position, "/"),
- "new_value": common.If(position != "", position, "/"),
- "createtime": nowTime,
- "BCPCID": BCPCID,
- "operator_id": -1})
- }
- if old_department != department && department != "" {
- clueUpdateData["department"] = department
- TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "change_field": "department",
- "position_id": 0,
- "change_type": "基本信息变更",
- "old_value": common.If(old_department != "", old_department, "/"),
- "new_value": common.If(department != "", department, "/"),
- "createtime": nowTime,
- "BCPCID": BCPCID,
- "operator_id": -1})
- }
- if old_follow_project_area != follow_project_area && follow_project_area != "" {
- clueUpdateData["follow_project_area"] = follow_project_area
- TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "change_field": "follow_project_area",
- "position_id": 0,
- "change_type": "基本信息变更",
- "old_value": common.If(old_follow_project_area != "", old_follow_project_area, "/"),
- "new_value": common.If(follow_project_area != "", follow_project_area, "/"),
- "createtime": nowTime,
- "BCPCID": BCPCID,
- "operator_id": -1})
- }
- if old_role != role && role != "" {
- TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "change_field": "role",
- "change_type": "基本信息变更",
- "old_value": common.If(old_role != "", old_role, "/"),
- "new_value": common.If(role != "", role, "/"),
- "createtime": nowTime,
- "position_id": 0,
- "BCPCID": BCPCID,
- "operator_id": -1})
- clueUpdateData["role"] = role
- }
- if old_cluename != cluename && cluename != "" {
- clueUpdateData["cluename"] = cluename //新的线索名不为空才替换
- TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "change_field": "cluename",
- "change_type": "基本信息变更",
- "old_value": common.If(old_cluename != "", old_cluename, "/"),
- "new_value": common.If(cluename != "", cluename, "/"),
- "createtime": nowTime,
- "BCPCID": BCPCID,
- "position_id": 0,
- "operator_id": -1})
- }
- old_topname := ""
- old_subname := ""
- 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 = 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 = gconv.String((*pcodeData)["name"])
- }
- }
- if old_top_cluetype != top_cluetype && top_cluetype != "" {
- clueUpdateData["top_cluetype"] = top_cluetype //新的线索名不为空才替换
- TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "change_field": "top_cluetype",
- "position_id": 0,
- "change_type": "基本信息变更",
- "old_value": common.If(old_topname != "", old_topname, "/"),
- "new_value": common.If(topname != "", topname, "/"),
- "createtime": nowTime,
- "BCPCID": BCPCID,
- "operator_id": -1})
- }
- if old_sub_cluetype != sub_cluetype && sub_cluetype != "" {
- clueUpdateData["sub_cluetype"] = sub_cluetype //新的线索名不为空才替换
- TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "change_field": "sub_cluetype", //111
- "position_id": 0,
- "change_type": "基本信息变更",
- "old_value": common.If(old_subname != "", old_subname, "/"),
- "new_value": common.If(subname != "", subname, "/"),
- "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
- TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, clueUpdateData)
- }
- }
- AssFail(noticePositionId, cluename, phone)
- return true, true, true
- }
- return true, false, true
- }
- return true, true, true
- }
- func SaveClue(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, departments, industry, follow_project_area, role, seatNumber string, positionId int64, source, sourceCode, remark string, keyword []string, belong_to string, isGroup, isCommerce int, isFreeze bool, demand string) bool {
- log.Println("线索修改前", item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, departments, industry, follow_project_area, role, seatNumber, positionId, source, sourceCode, remark)
- 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")
- clueId, uodateId1, uodateId2, uodateId3, uodateId4, uodateId5, uodateId6 := int64(0), int64(0), int64(0), int64(0), int64(0), int64(0), int64(0)
- if TiDb.ExecTx("保存线索", func(tx *sql.Tx) bool {
- keywords := ""
- if sourceCode == "app_xzcyh" {
- if len(keyword) > 0 && keyword[0] != "" {
- keywords = strings.Join(keyword, ",")
- }
- }
- if cluename == "" {
- cluename = phone
- }
- clueId = TiDb.InsertByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{
- "userid": userId,
- "uid": uId,
- "seatNumber": seatNumber,
- "position_id": positionId,
- "is_assign": common.If(isFreeze, -3, 1),
- "comeintime": nowTime,
- "createtime": nowTime,
- "updatetime": nowTime,
- "cluename": cluename,
- "top_cluetype": top_cluetype,
- "sub_cluetype": sub_cluetype,
- "trailstatus": "01",
- "name": name,
- "phone": phone,
- "position": position,
- "department": common.If(sourceCode == "app_xzcyh", departments, department),
- "industry": industry,
- "follow_project_area": follow_project_area,
- "role": role,
- "comeinsource_private": 2,
- "is_task": 1,
- "task_time": nowTime,
- "tasktime": common.If(item == "users", nowTimes, nowTime),
- "taskstatus": 0,
- "tasksource": "线索自动分配" + "-" + topname + "-" + subname,
- "business_scope": common.If(sourceCode == "app_xzcyh", keywords, nil),
- "company_nature": isGroup,
- "company_verification": isCommerce,
- "remark": remark,
- "customer_demand": demand,
- "FREEZE_TIME": nowTime,
- "label": 1,
- "labelChangeTime": time.Now().Format("2006-01-02"),
- })
- Ehandle(clueId, uId, userId, cluename, "01", "E")
- uodateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_type": "创建线索",
- "new_value": "系统自动创建",
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": -1,
- })
- uodateId2 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_field": "position_id",
- "change_type": "所属人变更",
- "old_value": "/",
- "new_value": saleName,
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": -1,
- })
- uodateId3 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_field": "trailstatus",
- "change_type": "基本信息变更",
- "old_value": "商机线索",
- "new_value": "新增",
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": -1,
- })
- uodateId4 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_type": "加入任务车",
- "new_value": "线索自动分配" + "-" + topname + "-" + subname,
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": -1,
- })
- uodateId5 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_field": "top_cluetype",
- "change_type": "基本信息变更",
- "old_value": "/",
- "new_value": topname,
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": -1,
- })
- uodateId6 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_field": "sub_cluetype", //222
- "change_type": "基本信息变更",
- "old_value": "/",
- "new_value": subname,
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": -1,
- })
- //冻结处理
- return clueId > -1 && uodateId1 > -1 && uodateId2 > -1 && uodateId3 > -1 && uodateId4 > -1 && uodateId5 > -1 && uodateId6 > -1
- }) {
- log.Println("线索分配成功")
- if TiDb.Count("dwd_f_userbase_contacts", map[string]interface{}{"phone": phone}) == 0 {
- TiDb.Insert("dwd_f_userbase_contacts", map[string]interface{}{
- "status": 1,
- "is_delete": 1,
- "createtime": nowTime,
- "updatetime": nowTime,
- "phone": phone,
- "baseinfo_id": uId,
- "SOURCE": source,
- })
- }
- return true
- } else {
- log.Println("线索分配失败!!!", clueId, uodateId1, uodateId2, uodateId3, uodateId4, uodateId5, uodateId6, " 用户信息 ", item, position, seatNumber, uId, userId, phone)
- return false
- }
- }
- func SaveClue0(item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, departments, industry, follow_project_area, role, seatNumber string, positionId int64, source, sourceCode, remark string, keyword []string, belong_to string, isGroup, isCommerce int, isFreeze bool) bool {
- nowTime := time.Now().Format("2006-01-02 15:04:05")
- clueId, uodateId1, uodateId2, uodateId3 := int64(0), int64(0), int64(0), int64(0)
- if TiDb.ExecTx("保存线索", func(tx *sql.Tx) bool {
- keywords := ""
- if sourceCode == "app_xzcyh" {
- if len(keyword) > 0 && keyword[0] != "" {
- keywords = strings.Join(keyword, ",")
- }
- }
- if cluename == "" {
- cluename = phone
- }
- clueId = TiDb.InsertByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{
- "userid": userId,
- "uid": uId,
- "seatNumber": "",
- "position_id": 0,
- "is_assign": 0,
- "comeintime": nowTime,
- "createtime": nowTime,
- "updatetime": nowTime,
- "cluename": cluename,
- "top_cluetype": top_cluetype,
- "sub_cluetype": sub_cluetype,
- "trailstatus": "01",
- "name": name,
- "phone": phone,
- "position": position,
- "department": common.If(sourceCode == "app_xzcyh", departments, department),
- "industry": industry,
- "follow_project_area": follow_project_area,
- "role": role,
- "comeinsource_private": 2,
- "business_scope": common.If(sourceCode == "app_xzcyh", keywords, nil),
- "company_nature": isGroup,
- "company_verification": isCommerce,
- "remark": remark,
- "FREEZE_TIME": nowTime,
- "label": 1,
- "labelChangeTime": time.Now().Format("2006-01-02"),
- })
- Ehandle(clueId, uId, userId, cluename, "01", "E")
- uodateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_type": "创建线索",
- "new_value": "系统自动创建",
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": -1,
- })
- uodateId2 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_field": "position_id",
- "change_type": "所属人变更",
- "old_value": "",
- "new_value": "/",
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": -1,
- })
- uodateId3 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_field": "trailstatus",
- "change_type": "基本信息变更",
- "old_value": "商机线索",
- "new_value": "新增",
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": -1,
- })
- return clueId > -1 && uodateId1 > -1 && uodateId2 > -1 && uodateId3 > -1
- }) {
- log.Println("线索分配成功")
- if TiDb.Count("dwd_f_userbase_contacts", map[string]interface{}{"phone": phone}) == 0 {
- TiDb.Insert("dwd_f_userbase_contacts", map[string]interface{}{
- "status": 1,
- "is_delete": 1,
- "createtime": nowTime,
- "updatetime": nowTime,
- "phone": phone,
- "baseinfo_id": uId,
- "SOURCE": source,
- })
- }
- return true
- } else {
- log.Println("线索分配失败!!!", clueId, uodateId1, uodateId2, uodateId3, " 用户信息 ", item, position, seatNumber, uId, userId, phone)
- return false
- }
- }
- func WorkUpdateClue(data map[string]interface{}, saleData []map[string]interface{}, item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, departments, industry, follow_project_area, role, seatNumber, level string, positionId int64, source, sourceCode, remark string, keyword []string, belong_to string, isGroup, isCommerce int, pIsOk bool, demand string) bool {
- 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 := 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)
- }
- 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"]), 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 := 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"])
- e_label := gconv.String(data["e_label"])
- old_topname, old_subname := "", ""
- Ehandle(clueId, uId, userId, cluename, trailstatus, e_label)
- is_transfer := common.IntAll(data["is_transfer"])
- if taskstatus == 1 || is_task == 0 {
- taskTime = gconv.String(common.If(item != "users", nowTime, nowTimes)) //任务时间,正常的是当前时间,新用户是当前时间+12个小时
- } else {
- if is_task == 1 {
- if oldTaskTime != "" { //以最新的任务时间为主
- t1, err := time.Parse("2006-01-02 15:04:05", oldTaskTime)
- if err == nil && time.Now().Before(t1) {
- taskTime = nowTime
- } else {
- taskTime = oldTaskTime
- }
- }
- }
- }
- count, counts, t := 0, 0, time.Now() //加入任务车判断节假日
- for {
- count++
- currentTime := t.AddDate(0, 0, -count)
- if currentTime.Weekday() == time.Sunday || currentTime.Weekday() == time.Saturday {
- isok := false
- for k, v := range DateMap {
- if currentTime.Format(date.Date_Short_Layout) == k && v == 2 {
- isok = true
- }
- }
- if isok {
- counts++
- }
- } else {
- isok := true
- for k, v := range DateMap {
- if currentTime.Format(date.Date_Short_Layout) == k && v == 1 {
- isok = false
- }
- }
- if isok {
- counts++
- }
- }
- if counts >= 2 {
- break
- }
- }
- //两天之前不包含节假日,有没有跟进记录
- recordCount := TiDb.CountBySql(`select count(1) from dwd_f_crm_trail_content where clue_id = ? and createtime > ?`, clueId, t.AddDate(0, 0, -count).Format(date.Date_Full_Layout))
- //
- clueUpdateData := map[string]interface{}{
- "updatetime": nowTime,
- "top_cluetype": top_cluetype,
- "sub_cluetype": sub_cluetype,
- "userid": userId,
- "comeinsource_private": 2,
- "tasksource": gconv.String(common.If(gconv.Int64(data["position_id"]) == 0, "线索自动分配", "线索来源自动更新")) + "-" + topname + "-" + subname,
- "company_nature": isGroup,
- "company_verification": isCommerce,
- }
- old_remark := gconv.String(data["remark"])
- if old_remark != "" {
- remark = old_remark + ";" + remark //备注不能替换,只能往上拼接
- }
- clueUpdateData["remark"] = remark
- old_demand := gconv.String(data["customer_demand"])
- if demand != old_demand {
- clueUpdateData["customer_demand"] = demand
- }
- if cluename != "" {
- clueUpdateData["cluename"] = cluename //新的线索名不为空才替换
- }
- if item != "orders" && item != "users" { //新用户和订单之外的替换一下新的留资信息
- if name != "" {
- clueUpdateData["name"] = name
- }
- if position != "" {
- clueUpdateData["position"] = position
- }
- if department != "" {
- clueUpdateData["department"] = department
- }
- if follow_project_area != "" {
- clueUpdateData["follow_project_area"] = follow_project_area
- }
- if role != "" {
- clueUpdateData["role"] = role
- }
- // clueUpdateData["industry"] = industry
- }
- if sourceCode == "app_xzcyh" { //这个留资单独处理一下
- if departments != "" {
- clueUpdateData["department"] = departments
- department = departments
- }
- business_scope := gconv.String(data["business_scope"])
- keywords := ""
- if len(keyword) > 0 && keyword[0] != "" {
- keywords = strings.Join(keyword, ",")
- if business_scope != "" {
- clueUpdateData["business_scope"] = business_scope + "," + keywords
- } else {
- clueUpdateData["business_scope"] = keywords
- }
- }
- }
- if old_position_id != 0 {
- for _, v := range saleData {
- if old_position_id == common.Int64All(v["position_id"]) {
- oldsaleName = gconv.String(v["name"])
- }
- }
- }
- if trailstatus == "00" || old_position_id == 0 || is_assign != 1 || (pIsOk && old_cluename != cluename && cluename != "") {
- if trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400 {
- } else {
- clueUpdateData["seatNumber"] = seatNumber
- clueUpdateData["position_id"] = positionId
- clueUpdateData["comeintime"] = nowTime
- clueUpdateData["is_assign"] = 1
- clueUpdateData["comeinsource_open"] = nil
- clueUpdateData["level_open"] = nil
- clueUpdateData["clue_level"] = nil
- }
- } else if is_assign == 1 && positionId != old_position_id {
- clueUpdateData["seatNumber"] = seatNumber
- clueUpdateData["position_id"] = positionId
- clueUpdateData["comeintime"] = nowTime
- clueUpdateData["is_assign"] = 1
- clueUpdateData["comeinsource_open"] = nil
- clueUpdateData["level_open"] = nil
- clueUpdateData["clue_level"] = nil
- } else { //不属于上边情况就还是属于原来的销售,不更换销售
- clueUpdateData["seatNumber"] = old_seatNumber
- clueUpdateData["position_id"] = old_position_id
- clueUpdateData["is_assign"] = 1
- clueUpdateData["comeinsource_open"] = nil
- clueUpdateData["level_open"] = nil
- clueUpdateData["clue_level"] = nil
- }
- if is_assign == 0 { //在公海的成交客户
- if trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400 {
- } else {
- clueUpdateData["trailstatus"] = "01"
- clueUpdateData["trailstatus_time"] = nowTime
- }
- }
- if trailstatus == "02" { //在公海的成交客户
- clueUpdateData["trailstatus"] = "01"
- clueUpdateData["trailstatus_time"] = nowTime
- }
- is_ok := false
- if recordCount <= 0 || is_assign == 0 {
- if trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400 {
- } else {
- if item == "eventReg" {
- 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 := gconv.String(e["new_value"])
- if strings.Contains(new_value, subname) {
- is_ok = true
- }
- }
- }
- if !is_ok {
- if old_sub_cluetype != sub_cluetype || is_assign == 0 {
- if taskTime == "" {
- taskTime = nowTime
- }
- clueUpdateData["task_time"] = nowTime
- clueUpdateData["tasktime"] = taskTime
- clueUpdateData["taskstatus"] = 0
- }
- if is_transfer != 1 {
- clueUpdateData["is_task"] = 1
- }
- }
- } else {
- if old_sub_cluetype != sub_cluetype || is_assign == 0 {
- if taskTime == "" {
- taskTime = nowTime
- }
- clueUpdateData["task_time"] = nowTime
- clueUpdateData["tasktime"] = taskTime
- clueUpdateData["taskstatus"] = 0
- }
- if is_transfer != 1 {
- clueUpdateData["is_task"] = 1
- }
- }
- }
- }
- ok, updateId14 := true, true
- 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)
- if TiDb.ExecTx("更新线索", func(tx *sql.Tx) bool {
- //线索
- 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 {
- updateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_field": "position_id",
- "change_type": "所属人变更",
- "old_value": common.If(oldsaleName != "", oldsaleName, "/"),
- "new_value": common.If(saleName != "", saleName, "/"),
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": -1,
- })
- updateId3 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_field": "trailstatus",
- "change_type": "基本信息变更",
- "old_value": CodeTrail[trailstatus],
- "new_value": "新增",
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": -1,
- })
- } else {
- if pIsOk && old_cluename != cluename && cluename != "" {
- updateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_field": "position_id",
- "change_type": "所属人变更",
- "old_value": common.If(oldsaleName != "", oldsaleName, "/"),
- "new_value": common.If(saleName != "", saleName, "/"),
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": -1,
- })
- } else {
- updateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_field": "position_id",
- "change_type": "所属人变更",
- "old_value": common.If(oldsaleName != "", oldsaleName, "/"),
- "new_value": common.If(saleName != "", saleName, "/"),
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": -1,
- })
- updateId2 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": common.Int64All(data["position_id"]),
- "change_field": "trailstatus",
- "change_type": "基本信息变更",
- "old_value": "无意向客户",
- "new_value": "流失",
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": -1,
- })
- updateId3 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_field": "trailstatus",
- "change_type": "基本信息变更",
- "old_value": "商机线索",
- "new_value": "新增",
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": -1,
- })
- updateId4 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_field": "trailstatus",
- "change_type": "基本信息变更",
- "old_value": "无意向客户",
- "new_value": "商机线索",
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": -1,
- })
- }
- }
- } else if is_assign == 0 {
- if trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400 {
- } else {
- updateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_field": "position_id",
- "change_type": "所属人变更",
- "old_value": common.If(oldsaleName != "", oldsaleName, "/"),
- "new_value": common.If(saleName != "", saleName, "/"),
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": -1,
- })
- if trailstatus != "01" {
- updateId4 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_field": "trailstatus",
- "change_type": "基本信息变更",
- "old_value": CodeTrail[trailstatus],
- "new_value": "商机线索",
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": -1,
- })
- }
- updateId3 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_field": "trailstatus",
- "change_type": "基本信息变更",
- "old_value": "商机线索",
- "new_value": "新增",
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": -1,
- })
- }
- } else if is_assign == -1 {
- updateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_field": "position_id",
- "change_type": "所属人变更",
- "old_value": common.If(oldsaleName != "", oldsaleName, "/"),
- "new_value": common.If(saleName != "", saleName, "/"),
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": -1,
- })
- updateId4 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_field": "trailstatus",
- "change_type": "基本信息变更",
- "old_value": CodeTrail[trailstatus],
- "new_value": "商机线索",
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": -1,
- })
- } else if (pIsOk && old_cluename == cluename && cluename != "") && is_assign == 1 && positionId != old_position_id {
- updateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_field": "position_id",
- "change_type": "所属人变更",
- "old_value": common.If(oldsaleName != "", oldsaleName, "/"),
- "new_value": common.If(saleName != "", saleName, "/"),
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": -1,
- })
- }
- if recordCount <= 0 || is_assign == 0 {
- if trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400 {
- } else {
- if is_transfer == 1 {
- if old_sub_cluetype != sub_cluetype && !is_ok {
- 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 := 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,
- "position_id": kcpositionId,
- "change_type": "加入任务车",
- "new_value": "线上主动留资",
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": -1,
- })
- if taskstatus == 1 {
- tasksource = "10"
- } else {
- if tasksource != "" && !strings.Contains(tasksource, "10") {
- if !strings.Contains(tasksource, "10") {
- tasksource += ",10"
- }
- } else {
- tasksource = "10"
- }
- }
- updateId14 = TiDb.UpdateByTx(tx, "dwd_f_csm_customer_info", map[string]interface{}{"clue_id": clueId}, map[string]interface{}{
- "tasksource": tasksource,
- "tasktime": nowTime,
- "is_task": 1,
- "taskstatus": 0,
- })
- }
- }
- } else if !is_ok {
- updateId5 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": common.If(trailstatus == "00" || is_assign == 0 || is_assign == -1, positionId, common.Int64All(data["position_id"])),
- "change_type": "加入任务车",
- "new_value": gconv.String(common.If(gconv.Int64(data["position_id"]) == 0, "线索自动分配", "线索来源自动更新")) + "-" + topname + "-" + subname,
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": -1,
- })
- }
- }
- }
- 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 = 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 = gconv.String((*pcodeData)["name"])
- }
- }
- if item != "orders" {
- if old_name != name && name != "" {
- updateId6 = 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.Int64All(data["position_id"])))),
- "change_field": "name",
- "change_type": "基本信息变更",
- "old_value": common.If(old_name != "", old_name, "/"),
- "new_value": common.If(name != "", name, "/"),
- "createtime": nowTime,
- "BCPCID": BCPCID,
- "operator_id": -1,
- })
- }
- if old_position != position && position != "" {
- updateId7 = 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.Int64All(data["position_id"])))),
- "change_field": "position",
- "change_type": "基本信息变更",
- "old_value": common.If(old_position != "", old_position, "/"),
- "new_value": common.If(position != "", position, "/"),
- "createtime": nowTime,
- "BCPCID": BCPCID,
- "operator_id": -1,
- })
- }
- if old_department != department && department != "" {
- updateId8 = 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.Int64All(data["position_id"])))),
- "change_field": "department",
- "change_type": "基本信息变更",
- "old_value": common.If(old_department != "", old_department, "/"),
- "new_value": common.If(department != "", department, "/"),
- "createtime": nowTime,
- "BCPCID": BCPCID,
- "operator_id": -1,
- })
- }
- if old_role != role && role != "" {
- updateId9 = 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.Int64All(data["position_id"])))), "change_field": "role", "change_type": "基本信息变更", "old_value": common.If(old_role != "", old_role, "/"), "new_value": common.If(role != "", role, "/"), "createtime": nowTime, "BCPCID": BCPCID, "operator_id": -1})
- }
- if old_follow_project_area != follow_project_area && follow_project_area != "" {
- old_area, old_area_arr := "", []string{}
- new_area, new_area_arr := "", []string{}
- for _, v := range strings.Split(old_follow_project_area, ",") {
- old_area_arr = append(old_area_arr, CodeArea[v])
- }
- for _, v := range strings.Split(follow_project_area, ",") {
- 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": 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.Int64All(data["position_id"])))),
- "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 old_cluename != cluename && cluename != "" {
- updateId11 = 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.Int64All(data["position_id"])))),
- "change_field": "cluename",
- "change_type": "基本信息变更",
- "old_value": common.If(old_cluename != "", old_cluename, "/"),
- "new_value": common.If(cluename != "", cluename, "/"),
- "createtime": nowTime,
- "BCPCID": BCPCID,
- "operator_id": -1,
- })
- }
- }
- if old_top_cluetype != top_cluetype {
- updateId12 = 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.Int64All(data["position_id"])))),
- "change_field": "top_cluetype",
- "change_type": "基本信息变更",
- "old_value": common.If(old_topname != "", old_topname, "/"),
- "new_value": common.If(topname != "", topname, "/"),
- "createtime": nowTime,
- "BCPCID": BCPCID,
- "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", //333
- "change_type": "基本信息变更",
- "old_value": common.If(old_subname != "", old_subname, "/"),
- "new_value": common.If(subname != "", subname, "/"),
- "createtime": nowTime,
- "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
- }) {
- log.Println("线索更新成功")
- if TiDb.Count("dwd_f_userbase_contacts", map[string]interface{}{"phone": phone}) == 0 {
- TiDb.Insert("dwd_f_userbase_contacts", map[string]interface{}{
- "status": 1,
- "is_delete": 1,
- "createtime": nowTime,
- "updatetime": nowTime,
- "phone": phone,
- "baseinfo_id": uId,
- "SOURCE": source,
- })
- }
- if old_position_id == 0 {
- TiDb.UpdateOrDeleteBySql(`update dwd_f_crm_clue_autodraw_record set count = count + 1 where position_id = ? and clue_level = ?`, positionId, level)
- }
- return true
- } else {
- log.Println("线索更新失败!!!", ok, updateId1, updateId2, updateId3, updateId4, updateId5, updateId6, updateId7, updateId8, updateId9, updateId10, updateId11, updateId12, updateId13, updateId14, " 用户信息 ", item, position, seatNumber, uId, userId, phone)
- return false
- }
- }
- func UpdateClue(data map[string]interface{}, saleData []map[string]interface{}, item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, departments, industry, follow_project_area, role, seatNumber, level string, positionId int64, source, sourceCode, remark string, keyword []string, belong_to string, isGroup, isCommerce int, pIsOk bool) bool {
- log.Println("线索修改前", data, item, userId, uId, top_cluetype, sub_cluetype, topname, subname, cluename, name, saleName, phone, position, department, departments, industry, follow_project_area, role, seatNumber, level, positionId, source, sourceCode, remark)
- 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 := 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)
- }
- 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"]), 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 := 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"])
- e_label := gconv.String(data["e_label"])
- Ehandle(clueId, uId, userId, cluename, trailstatus, e_label)
- if taskstatus == 1 || is_task == 0 {
- taskTime = gconv.String(common.If(item != "users", nowTime, nowTimes)) //任务时间,正常的是当前时间,新用户是当前时间+12个小时
- } else {
- if is_task == 1 {
- if oldTaskTime != "" { //以最新的任务时间为主
- t1, err := time.Parse("2006-01-02 15:04:05", oldTaskTime)
- if err == nil && time.Now().Before(t1) {
- taskTime = nowTime
- } else {
- taskTime = oldTaskTime
- }
- }
- }
- }
- count, counts, t := 0, 0, time.Now() //加入任务车判断节假日
- for {
- count++
- currentTime := t.AddDate(0, 0, -count)
- if currentTime.Weekday() == time.Sunday || currentTime.Weekday() == time.Saturday {
- isok := false
- for k, v := range DateMap {
- if currentTime.Format(date.Date_Short_Layout) == k && v == 2 {
- isok = true
- }
- }
- if isok {
- counts++
- }
- } else {
- isok := true
- for k, v := range DateMap {
- if currentTime.Format(date.Date_Short_Layout) == k && v == 1 {
- isok = false
- }
- }
- if isok {
- counts++
- }
- }
- if counts >= 2 {
- break
- }
- }
- //两天之前不包含节假日,有没有跟进记录
- recordCount := TiDb.CountBySql(`select count(1) from dwd_f_crm_trail_content where clue_id = ? and createtime > ?`, clueId, t.AddDate(0, 0, -count).Format(date.Date_Full_Layout))
- //
- clueUpdateData := map[string]interface{}{
- "updatetime": nowTime,
- "top_cluetype": top_cluetype,
- "sub_cluetype": sub_cluetype,
- "userid": userId,
- "comeinsource_private": 2,
- "tasksource": "线索来源自动更新" + "-" + topname + "-" + subname,
- "company_nature": isGroup,
- "company_verification": isCommerce,
- }
- old_remark := gconv.String(data["remark"])
- if old_remark != "" {
- remark = old_remark + ";" + remark //备注不能替换,只能往上拼接
- }
- clueUpdateData["remark"] = remark
- if cluename != "" {
- clueUpdateData["cluename"] = cluename //新的线索名不为空才替换
- }
- if item != "orders" && item != "users" { //新用户和订单之外的替换一下新的留资信息
- if name != "" {
- clueUpdateData["name"] = name
- }
- if position != "" {
- clueUpdateData["position"] = position
- }
- if department != "" {
- clueUpdateData["department"] = department
- }
- if follow_project_area != "" {
- clueUpdateData["follow_project_area"] = follow_project_area
- }
- if role != "" {
- clueUpdateData["role"] = role
- }
- // clueUpdateData["industry"] = industry
- }
- if sourceCode == "app_xzcyh" { //这个留资单独处理一下
- if departments != "" {
- clueUpdateData["department"] = departments
- department = departments
- }
- business_scope := gconv.String(data["business_scope"])
- keywords := ""
- if len(keyword) > 0 && keyword[0] != "" {
- keywords = strings.Join(keyword, ",")
- if business_scope != "" {
- clueUpdateData["business_scope"] = business_scope + "," + keywords
- } else {
- clueUpdateData["business_scope"] = keywords
- }
- }
- }
- //只更新线索不更新人员信息
- 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,
- Level: level,
- LabelChangeTime: oldLabelChangeTime,
- Label: label,
- }
- 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 {
- //无意向几天以内不参与分配
- } else if trailstatus == "09" && (topname != "付费产品落地页主动留资" && topname != "受理系统") {
- //线索状态为“拒绝沟通客户”,则仅针对线索来源一级分类为“付费产品落地页主动留资”和“受理系统”产生的线索进行线索分配,其他类线上线索只做线索更新但不再自动分配。
- positionId = 0
- seatNumber = ""
- } else {
- clueUpdateData["seatNumber"] = seatNumber
- clueUpdateData["position_id"] = positionId
- clueUpdateData["comeintime"] = nowTime
- clueUpdateData["is_assign"] = 1
- clueUpdateData["is_assign"] = 1
- clueUpdateData["comeinsource_open"] = nil
- clueUpdateData["level_open"] = nil
- clueUpdateData["clue_level"] = nil
- for _, v := range saleData {
- if common.Int64All(data["position_id"]) == common.Int64All(v["position_id"]) {
- oldsaleName = gconv.String(v["name"])
- }
- }
- }
- } else { //不属于上边情况就还是属于原来的销售,不更换销售
- clueUpdateData["seatNumber"] = old_seatNumber
- clueUpdateData["position_id"] = old_position_id
- //clueUpdateData["is_assign"] = 1
- clueUpdateData["comeinsource_open"] = nil
- clueUpdateData["level_open"] = nil
- clueUpdateData["clue_level"] = nil
- }
- if is_assign == 0 { //在公海的成交客户
- if trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400 {
- } else if trailstatus == "09" && (topname != "付费产品落地页主动留资" && topname != "受理系统") {
- //线索状态为“拒绝沟通客户”,则仅针对线索来源一级分类为“付费产品落地页主动留资”和“受理系统”产生的线索进行线索分配,其他类线上线索只做线索更新但不再自动分配。
- positionId = 0
- seatNumber = ""
- } else {
- clueUpdateData["trailstatus"] = "01"
- clueUpdateData["trailstatus_time"] = nowTime
- }
- }
- if trailstatus == "02" { //在公海的成交客户
- clueUpdateData["trailstatus"] = "01"
- clueUpdateData["trailstatus_time"] = nowTime
- }
- is_ok := false
- if recordCount <= 0 || is_assign == 0 {
- if trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400 {
- } else if trailstatus == "09" && (topname != "付费产品落地页主动留资" && topname != "受理系统") {
- //线索状态为“拒绝沟通客户”,则仅针对线索来源一级分类为“付费产品落地页主动留资”和“受理系统”产生的线索进行线索分配,其他类线上线索只做线索更新但不再自动分配。
- positionId = 0
- seatNumber = ""
- } else {
- if item == "eventReg" {
- 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 := gconv.String(e["new_value"])
- if strings.Contains(new_value, subname) {
- is_ok = true
- }
- }
- }
- if !is_ok {
- if old_sub_cluetype != sub_cluetype || is_assign == 0 {
- if taskTime == "" {
- taskTime = nowTime
- }
- clueUpdateData["task_time"] = nowTime
- clueUpdateData["tasktime"] = taskTime
- clueUpdateData["taskstatus"] = 0
- }
- if is_transfer != 1 {
- clueUpdateData["is_task"] = 1
- }
- }
- } else {
- if old_sub_cluetype != sub_cluetype || is_assign == 0 {
- if taskTime == "" {
- taskTime = nowTime
- }
- clueUpdateData["task_time"] = nowTime
- clueUpdateData["tasktime"] = taskTime
- clueUpdateData["taskstatus"] = 0
- }
- if is_transfer != 1 {
- clueUpdateData["is_task"] = 1
- }
- }
- }
- }
- ok, updateId14 := true, true
- 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)
- if TiDb.ExecTx("更新线索", func(tx *sql.Tx) bool {
- //线索
- 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 trailstatus == "09" && (topname != "付费产品落地页主动留资" && topname != "受理系统") {
- positionId = 0
- seatNumber = ""
- } else if old_position_id == 0 {
- updateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_field": "position_id",
- "change_type": "所属人变更",
- "old_value": common.If(oldsaleName != "", oldsaleName, "/"),
- "new_value": common.If(saleName != "", saleName, "/"),
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": -1,
- })
- updateId3 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_field": "trailstatus",
- "change_type": "基本信息变更",
- "old_value": CodeTrail[trailstatus],
- "new_value": "新增",
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": -1,
- })
- } else {
- if pIsOk && old_cluename != cluename && cluename != "" {
- updateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_field": "position_id",
- "change_type": "所属人变更",
- "old_value": common.If(oldsaleName != "", oldsaleName, "/"),
- "new_value": common.If(saleName != "", saleName, "/"),
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": -1,
- })
- } else {
- updateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_field": "position_id",
- "change_type": "所属人变更",
- "old_value": common.If(oldsaleName != "", oldsaleName, "/"),
- "new_value": common.If(saleName != "", saleName, "/"),
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": -1,
- })
- updateId2 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": common.Int64All(data["position_id"]),
- "change_field": "trailstatus",
- "change_type": "基本信息变更",
- "old_value": "无意向客户",
- "new_value": "流失",
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": -1,
- })
- updateId3 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_field": "trailstatus",
- "change_type": "基本信息变更",
- "old_value": "商机线索",
- "new_value": "新增",
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": -1,
- })
- updateId4 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_field": "trailstatus",
- "change_type": "基本信息变更",
- "old_value": "无意向客户",
- "new_value": "商机线索",
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": -1,
- })
- }
- }
- } else if is_assign == 0 {
- if trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400 {
- } else if trailstatus == "09" && (topname != "付费产品落地页主动留资" && topname != "受理系统") {
- positionId = 0
- seatNumber = ""
- } else {
- updateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_field": "position_id",
- "change_type": "所属人变更",
- "old_value": common.If(oldsaleName != "", oldsaleName, "/"),
- "new_value": common.If(saleName != "", saleName, "/"),
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": -1,
- })
- if trailstatus != "01" {
- updateId4 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_field": "trailstatus",
- "change_type": "基本信息变更",
- "old_value": CodeTrail[trailstatus],
- "new_value": "商机线索",
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": -1,
- })
- }
- updateId3 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_field": "trailstatus",
- "change_type": "基本信息变更",
- "old_value": "商机线索",
- "new_value": "新增",
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": -1,
- })
- }
- } else if is_assign == -1 {
- updateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_field": "position_id",
- "change_type": "所属人变更",
- "old_value": common.If(oldsaleName != "", oldsaleName, "/"),
- "new_value": common.If(saleName != "", saleName, "/"),
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": -1,
- })
- updateId4 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": positionId,
- "change_field": "trailstatus",
- "change_type": "基本信息变更",
- "old_value": CodeTrail[trailstatus],
- "new_value": "商机线索",
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": -1,
- })
- }
- if recordCount <= 0 || is_assign == 0 {
- if trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400 {
- } else if trailstatus == "09" && (topname != "付费产品落地页主动留资" && topname != "受理系统") {
- positionId = 0
- seatNumber = ""
- } else {
- if is_transfer == 1 {
- if old_sub_cluetype != sub_cluetype && !is_ok {
- 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 := 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,
- "position_id": kcpositionId,
- "change_type": "加入任务车",
- "new_value": "线上主动留资",
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": -1,
- })
- if taskstatus == 1 {
- tasksource = "10"
- } else {
- if tasksource != "" && !strings.Contains(tasksource, "10") {
- if !strings.Contains(tasksource, "10") {
- tasksource += ",10"
- }
- } else {
- tasksource = "10"
- }
- }
- updateId14 = TiDb.UpdateByTx(tx, "dwd_f_csm_customer_info", map[string]interface{}{"clue_id": clueId}, map[string]interface{}{
- "tasksource": tasksource,
- "tasktime": nowTime,
- "is_task": 1,
- "taskstatus": 0,
- })
- }
- }
- } else if !is_ok {
- updateId5 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": common.If(trailstatus == "00" || is_assign == 0 || is_assign == -1, positionId, common.Int64All(data["position_id"])),
- "change_type": "加入任务车",
- "new_value": gconv.String(common.If(gconv.Int64(data["position_id"]) == 0, "线索自动分配", "线索来源自动更新")) + "-" + topname + "-" + subname,
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": -1,
- })
- }
- }
- }
- 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 = 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 = gconv.String((*pcodeData)["name"])
- }
- }
- if item != "orders" {
- if old_name != name && name != "" {
- updateId6 = 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": "name",
- "change_type": "基本信息变更",
- "old_value": common.If(old_name != "", old_name, "/"),
- "new_value": common.If(name != "", name, "/"),
- "createtime": nowTime,
- "BCPCID": BCPCID,
- "operator_id": -1,
- })
- }
- if old_position != position && position != "" {
- updateId7 = 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": "position",
- "change_type": "基本信息变更",
- "old_value": common.If(old_position != "", old_position, "/"),
- "new_value": common.If(position != "", position, "/"),
- "createtime": nowTime,
- "BCPCID": BCPCID,
- "operator_id": -1,
- })
- }
- if old_department != department && department != "" {
- updateId8 = 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": "department",
- "change_type": "基本信息变更",
- "old_value": common.If(old_department != "", old_department, "/"),
- "new_value": common.If(department != "", department, "/"),
- "createtime": nowTime,
- "BCPCID": BCPCID,
- "operator_id": -1,
- })
- }
- if old_role != role && role != "" {
- updateId9 = 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": "role",
- "change_type": "基本信息变更",
- "old_value": common.If(old_role != "", old_role, "/"),
- "new_value": common.If(role != "", role, "/"),
- "createtime": nowTime,
- "BCPCID": BCPCID,
- "operator_id": -1})
- }
- if old_follow_project_area != follow_project_area && follow_project_area != "" {
- old_area, old_area_arr := "", []string{}
- new_area, new_area_arr := "", []string{}
- for _, v := range strings.Split(old_follow_project_area, ",") {
- old_area_arr = append(old_area_arr, CodeArea[v])
- }
- for _, v := range strings.Split(follow_project_area, ",") {
- 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": 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": "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 old_cluename != cluename && cluename != "" {
- updateId11 = 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": "cluename",
- "change_type": "基本信息变更",
- "old_value": common.If(old_cluename != "", old_cluename, "/"),
- "new_value": common.If(cluename != "", cluename, "/"),
- "createtime": nowTime,
- "BCPCID": BCPCID,
- "operator_id": -1,
- })
- }
- }
- if old_top_cluetype != top_cluetype {
- updateId12 = 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": "top_cluetype",
- "change_type": "基本信息变更",
- "old_value": common.If(old_topname != "", old_topname, "/"),
- "new_value": common.If(topname != "", topname, "/"),
- "createtime": nowTime,
- "BCPCID": BCPCID,
- "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", //444
- "change_type": "基本信息变更",
- "old_value": common.If(old_subname != "", old_subname, "/"),
- "new_value": common.If(subname != "", subname, "/"),
- "createtime": nowTime,
- "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
- }) {
- log.Println("线索更新成功")
- if TiDb.Count("dwd_f_userbase_contacts", map[string]interface{}{"phone": phone}) == 0 {
- TiDb.Insert("dwd_f_userbase_contacts", map[string]interface{}{
- "status": 1,
- "is_delete": 1,
- "createtime": nowTime,
- "updatetime": nowTime,
- "phone": phone,
- "baseinfo_id": uId,
- "SOURCE": source,
- })
- }
- if old_position_id == 0 {
- TiDb.UpdateOrDeleteBySql(`update dwd_f_crm_clue_autodraw_record set count = count + 1 where position_id = ? and clue_level = ?`, positionId, level)
- }
- return true
- } else {
- log.Println("线索更新失败!!!", ok, updateId1, updateId2, updateId3, updateId4, updateId5, updateId6, updateId7, updateId8, updateId9, updateId10, updateId11, updateId12, updateId13, updateId14, " 用户信息 ", item, position, seatNumber, uId, userId, phone)
- 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
- Label int64
- LabelChangeTime string
- Level string
- }
- // 基本信息变更
- 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 = 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 = gconv.String((*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.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", //555
- "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,
- })
- 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
- }) {
- 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
- }
- }
- // 线索标签修改 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)
- }
- }
- func Ehandle(clueId int64, uid, userId, clueName, trailstatus, e_label string) {
- if e_label != "" {
- return
- }
- // 最近访问时间:最近1天内
- beforeTime := time.Now().AddDate(0, 0, -1).Format("2006-01-02 15:04:05")
- if TiDb.CountBySql("select count(1) as count from dwd_f_userbase_visit_info where userid=? and date>=? and number>0 ", userId, beforeTime) <= 0 {
- return
- }
- // 最近接通时间:近20天内未被接通
- if TiDb.CountBySql("select count(1) as count from dwd_f_crm_attribute_label where uid=? and noanswer_count>0 ", uid) > 0 {
- return
- }
- // 排除条件:空号停机、拒绝沟通客户
- if trailstatus == "02" || trailstatus == "09" {
- return
- }
- // 线索名称:有企业名称的
- if ValidatePhone(clueName) {
- return
- }
- TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{
- "id": clueId,
- }, map[string]interface{}{
- "e_label": "E001",
- })
- }
- // 预编译正则表达式提升性能
- var phoneRegex = regexp.MustCompile(`^1[3-9]\d{9}$`)
- // ValidatePhone 验证手机号格式是否合法
- func ValidatePhone(phone string) bool {
- return phoneRegex.MatchString(phone)
- }
|