job.go 95 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263
  1. package main
  2. import (
  3. "database/sql"
  4. "fmt"
  5. "github.com/gogf/gf/v2/util/gconv"
  6. "log"
  7. "regexp"
  8. "strings"
  9. "time"
  10. "app.yhyue.com/moapp/jybase/date"
  11. "app.yhyue.com/moapp/jybase/redis"
  12. "app.yhyue.com/moapp/jybase/common"
  13. "app.yhyue.com/moapp/jybase/mongodb"
  14. )
  15. func FormatData(data map[string]interface{}, item string) (bool, bool, bool) {
  16. userId, uId, positionId, source, cluename, phone, sourceCode, keyword, _ := gconv.String(data["user_id"]), "", "", "", "", "", "", []string{}, ""
  17. role, industry, department, departments, position, name, top_cluetype, sub_cluetype, follow_project_area, level := "", "", "", "", "", "", "", "", "", ""
  18. query, topname, subname, belong_to, sourceName, remark, sourceId := map[string]interface{}{}, "", "", "01", "", "", int64(0)
  19. nowTime := time.Now().Format("2006-01-02 15:04:05")
  20. if item == "orders" { //订单
  21. if !mongodb.IsObjectIdHex(userId) {
  22. positionId = userId
  23. userMapping := TiDb.FindOne("data_service.user_system", map[string]interface{}{"position_id": userId}, "", "")
  24. if userMapping != nil && len(*userMapping) > 0 {
  25. userId = gconv.String((*userMapping)["userid"])
  26. }
  27. }
  28. query["userid"] = userId
  29. userInfo := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
  30. if userInfo != nil && len(*userInfo) > 0 {
  31. uId = gconv.String((*userInfo)["uid"])
  32. source = gconv.String((*userInfo)["source"]) //用户来源
  33. belong_to = gconv.String((*userInfo)["belong_to"]) //用户归属
  34. }
  35. cluename = gconv.String(data["company_name"])
  36. phone = gconv.String(data["user_phone"])
  37. } else if item == "message" {
  38. userMapping := TiDb.FindOne("data_service.user_system", map[string]interface{}{"base_user_id": common.Int64All(data["own_id"])}, "", "")
  39. if userMapping != nil && len(*userMapping) > 0 {
  40. userId = gconv.String((*userMapping)["userid"])
  41. positionId = fmt.Sprint((*userMapping)["position_id"])
  42. }
  43. query["userid"] = userId
  44. userInfo := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
  45. if userInfo != nil && len(*userInfo) > 0 {
  46. uId = gconv.String((*userInfo)["uid"])
  47. source = gconv.String((*userInfo)["source"])
  48. belong_to = gconv.String((*userInfo)["belong_to"])
  49. phone = gconv.String((*userInfo)["phone"])
  50. if phone != "" {
  51. phoneMapping := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"phone": phone}, "", "")
  52. if phoneMapping != nil && len(*phoneMapping) > 0 {
  53. cluename = gconv.String((*phoneMapping)["cluename"])
  54. }
  55. }
  56. }
  57. } else if item == "tag" {
  58. userMapping := TiDb.FindOne("data_service.user_system", map[string]interface{}{"base_user_id": common.Int64All(data["baseUserId"])}, "", "")
  59. if userMapping != nil && len(*userMapping) > 0 {
  60. userId = gconv.String((*userMapping)["userid"])
  61. positionId = fmt.Sprint((*userMapping)["position_id"])
  62. }
  63. query["userid"] = userId
  64. userInfo := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
  65. if userInfo != nil && len(*userInfo) > 0 {
  66. uId = gconv.String((*userInfo)["uid"])
  67. source = gconv.String((*userInfo)["source"])
  68. belong_to = gconv.String((*userInfo)["belong_to"])
  69. phone = gconv.String((*userInfo)["phone"])
  70. if phone != "" {
  71. phoneMapping := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"phone": phone}, "", "")
  72. if phoneMapping != nil && len(*phoneMapping) > 0 {
  73. cluename = gconv.String((*phoneMapping)["cluename"])
  74. }
  75. }
  76. }
  77. } else if item == "users" || item == "xcxusers" { //注册用户
  78. if Mgo.Count("user_share", map[string]interface{}{
  79. "shared_uid": userId,
  80. }) > 0 {
  81. return true, true, true
  82. }
  83. sourceCode = gconv.String(data["rsource"])
  84. userId = mongodb.BsonIdToSId(data["userid"])
  85. //新用户没有uid、source要等5分钟
  86. cluename = gconv.String(data["company_name"])
  87. phone = gconv.String(data["phone"])
  88. if phone != "" {
  89. contactsData := TiDb.SelectBySql("select * from dwd_f_userbase_contacts where phone = ? and is_delete = 1", phone)
  90. if contactsData != nil && len(*contactsData) > 0 {
  91. if gconv.String((*contactsData)[0]["baseinfo_id"]) != "" {
  92. uId = gconv.String((*contactsData)[0]["baseinfo_id"])
  93. query["uid"] = uId
  94. } else {
  95. query["userid"] = userId
  96. }
  97. } else {
  98. query["userid"] = userId
  99. }
  100. //createtimeStr := ""
  101. userInfo := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
  102. if userInfo != nil && len(*userInfo) > 0 {
  103. uId = gconv.String((*userInfo)["uid"])
  104. source = gconv.String((*userInfo)["source"])
  105. belong_to = gconv.String((*userInfo)["belong_to"])
  106. //s_sourceid = gconv.String((*userInfo)["s_sourceid"])
  107. //createtimeStr = gconv.String((*userInfo)["l_registedate"])
  108. }
  109. if item == "xcxusers" {
  110. sourceCode = gconv.String(data["industry"])
  111. //t, _ := time.Parse("2006-01-02 15:04:05", createtimeStr)
  112. if sourceCode == "" {
  113. log.Println("留资没有source", phone)
  114. return true, true, true
  115. }
  116. /* 安防代码
  117. if t.Unix() > db.NewRegistration && sourceCode == "安防" {
  118. return true, true, false
  119. }*/
  120. //线索名称查询处理
  121. clueData, _ := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, "", ""), true //查当前线索是否已存在
  122. if clueData != nil && len(*clueData) > 0 {
  123. cluename = gconv.String((*clueData)["cluename"])
  124. } else {
  125. cluename = phone
  126. }
  127. }
  128. }
  129. } else if item == "allocation" || item == "rebind" {
  130. userId = mongodb.BsonIdToSId(data["mogUserId"])
  131. userInfo := TiDb.FindOne("dwd_f_userbase_baseinfo", map[string]interface{}{
  132. "userid": userId,
  133. }, "", "")
  134. if userInfo != nil && len(*userInfo) > 0 {
  135. phone = gconv.String((*userInfo)["phone"])
  136. uId = gconv.String((*userInfo)["uid"])
  137. source = gconv.String((*userInfo)["source"])
  138. belong_to = gconv.String((*userInfo)["belong_to"])
  139. }
  140. } else if item == "saleLeads" { //留资
  141. //线索名称打印
  142. log.Println(1111, gconv.String(data["company"]))
  143. userId = gconv.String(data["userid"])
  144. if !mongodb.IsObjectIdHex(userId) {
  145. positionId = userId
  146. userMapping := TiDb.FindOne("data_service.user_system", map[string]interface{}{"position_id": userId}, "", "")
  147. if userMapping != nil && len(*userMapping) > 0 {
  148. userId = gconv.String((*userMapping)["userid"])
  149. }
  150. }
  151. cluename = gconv.String(data["company"])
  152. phone = gconv.String(data["phone"])
  153. role = gconv.String(data["companyType"])
  154. industry = gconv.String(data["industry"])
  155. department = gconv.String(data["branch"])
  156. departments = gconv.String(data["department"])
  157. position = gconv.String(data["position"])
  158. name = gconv.String(data["name"])
  159. sourceCode = gconv.String(data["source"])
  160. if sourceCode == "" {
  161. log.Println("留资没有source", phone)
  162. return true, true, true
  163. }
  164. remark = gconv.String(data["jyRemark"]) //荟聚线索备注
  165. keywordArr := data["keyword"]
  166. if keywordArr != nil {
  167. keyword = common.ObjArrToStringArr(data["keyword"].([]interface{}))
  168. }
  169. contactsData := TiDb.SelectBySql("select * from dwd_f_userbase_contacts where phone = ? and is_delete = 1", phone)
  170. if contactsData != nil && len(*contactsData) > 0 {
  171. if gconv.String((*contactsData)[0]["baseinfo_id"]) != "" {
  172. uId = gconv.String((*contactsData)[0]["baseinfo_id"])
  173. query["uid"] = uId
  174. } else {
  175. query["userid"] = userId
  176. }
  177. } else {
  178. query["userid"] = userId
  179. }
  180. if userId != "" || uId != "" {
  181. userInfo := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
  182. if userInfo != nil && len(*userInfo) > 0 {
  183. uId = gconv.String((*userInfo)["uid"])
  184. source = gconv.String((*userInfo)["source"])
  185. belong_to = gconv.String((*userInfo)["belong_to"])
  186. userId = gconv.String((*userInfo)["userid"])
  187. //s_sourceid = gconv.String((*userInfo)["s_sourceid"])
  188. }
  189. } else {
  190. if sourceCode == "report_retention" || sourceCode == "marketing_retention" { //荟聚线索来源,不是剑鱼用户,需要等待用户归集
  191. log.Println("不是剑鱼用户留资,等待用户", phone)
  192. return false, false, true
  193. } else if remark != "" {
  194. log.Println("留资source过滤", phone, sourceCode)
  195. return true, true, true
  196. }
  197. }
  198. } else if item == "eventReg" { //渠道
  199. userId = gconv.String(data["userid"])
  200. cluename = gconv.String(data["company"])
  201. phone = gconv.String(data["sign_phone"])
  202. role = gconv.String(data["company_type"])
  203. department = gconv.String(data["branch"])
  204. position = gconv.String(data["position"])
  205. name = gconv.String(data["sign_name"])
  206. sourceCode = gconv.String(data["source_code"])
  207. sourceName = gconv.String(data["source_name"])
  208. log.Println(sourceName)
  209. contactsData := TiDb.SelectBySql("select * from dwd_f_userbase_contacts where phone = ? and is_delete = 1", phone)
  210. if contactsData != nil && len(*contactsData) > 0 {
  211. if gconv.String((*contactsData)[0]["baseinfo_id"]) != "" {
  212. uId = gconv.String((*contactsData)[0]["baseinfo_id"])
  213. query["uid"] = uId
  214. } else {
  215. query["userid"] = userId
  216. }
  217. } else {
  218. query["userid"] = userId
  219. }
  220. userInfo := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
  221. if userInfo != nil && len(*userInfo) > 0 {
  222. uId = gconv.String((*userInfo)["uid"])
  223. source = gconv.String((*userInfo)["source"])
  224. belong_to = gconv.String((*userInfo)["belong_to"])
  225. userId = gconv.String((*userInfo)["userid"])
  226. }
  227. if role == "集成商" || role == "设计院" {
  228. role = "其他-" + role
  229. }
  230. } else if item == "readClue" {
  231. userId = gconv.String(data["userId"])
  232. query["userid"] = userId
  233. userInfo := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
  234. if userInfo != nil && len(*userInfo) > 0 {
  235. uId = gconv.String((*userInfo)["uid"])
  236. source = gconv.String((*userInfo)["source"])
  237. belong_to = gconv.String((*userInfo)["belong_to"])
  238. }
  239. // cluename = gconv.String(data["companyName"])
  240. phone = gconv.String(data["phone"])
  241. sourceId = common.Int64All(data["sourceId"])
  242. } else if item == "invite" {
  243. query["userid"] = userId
  244. userInfo := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
  245. if userInfo != nil && len(*userInfo) > 0 {
  246. uId = gconv.String((*userInfo)["uid"])
  247. source = gconv.String((*userInfo)["source"]) //用户来源
  248. belong_to = gconv.String((*userInfo)["belong_to"]) //用户归属
  249. } else {
  250. log.Println("邀请用户,用户归集没数据", data)
  251. return true, true, true
  252. }
  253. cluename = gconv.String((*userInfo)["company_name"])
  254. phone = gconv.String((*userInfo)["phone"])
  255. sourceCode = gconv.String(data["sourceCode"])
  256. } else if item == "activity" {
  257. query["userid"] = userId
  258. userInfo := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
  259. if userInfo != nil && len(*userInfo) > 0 {
  260. uId = gconv.String((*userInfo)["uid"])
  261. source = gconv.String((*userInfo)["source"]) //用户来源
  262. belong_to = gconv.String((*userInfo)["belong_to"]) //用户归属
  263. } else {
  264. log.Println("邀请用户,用户归集没数据", data)
  265. return true, true, true
  266. }
  267. cluename = gconv.String((*userInfo)["company_name"])
  268. phone = gconv.String((*userInfo)["phone"])
  269. sourceCode = gconv.String(data["sourceCode"])
  270. log.Println(sourceCode)
  271. }
  272. log.Println(222, cluename)
  273. if cluename == "" && item != "message" && item != "orders" && item != "readClue" &&
  274. item != "rebind" && item != "allocation" && item != "tag" &&
  275. item != "activity" {
  276. cluename = phone //没有线索名,手机号代替
  277. }
  278. log.Println(333, cluename)
  279. cluename = strings.ReplaceAll(cluename, " ", "")
  280. isGroup, isCommerce := GetCompanyType(cluename, uId) //判断是否集团公司、工商库
  281. //获取用户渠道
  282. if source == "0104" || strings.HasPrefix(belong_to, "02") || source == "0102" || source == "0103" || phone == "" { //参照用户来源代码表
  283. //log.Println("线索分配失败,线索过滤!!", item, source, phone, userId)
  284. //saveHlyj(belong_to, item, phone, name, sourceName, cluename, position, nowTime, isGroup, isCommerce)
  285. return true, true, true
  286. }
  287. if uId == "" { //没有进用户归集,等待进入,结束任务,放在下次继续执行
  288. if isExists, _ := redis.Exists("bidx", "bidx_userId_"+userId); isExists {
  289. redisInt := redis.GetInt("bidx", "bidx_userId_"+userId)
  290. if redisInt > 4 {
  291. log.Println("线索分配失败,线索缺少信息,任务已执行超过1次", item, userId, phone)
  292. return true, true, true
  293. } else {
  294. redis.Incr("bidx", "bidx_userId_"+userId)
  295. }
  296. } else {
  297. redis.Put("bidx", "bidx_userId_"+userId, 1, 3600)
  298. }
  299. log.Println("线索分配失败,线索缺少信息", item, phone, userId)
  300. return false, false, true
  301. }
  302. if item == "orders" { //订单没信息再查一遍留资
  303. qid := positionId
  304. if qid == "" {
  305. qid = userId
  306. }
  307. saleLeadsData, ok := Mgo.Find("saleLeads", map[string]interface{}{"userid": qid}, map[string]interface{}{"_id": -1}, nil, false, 0, 1)
  308. if ok && saleLeadsData != nil && len(*saleLeadsData) > 0 {
  309. sdata := (*saleLeadsData)[0]
  310. role = gconv.String(sdata["companyType"])
  311. industry = gconv.String(sdata["industry"])
  312. department = gconv.String(sdata["branch"])
  313. departments = gconv.String(sdata["department"])
  314. position = gconv.String(sdata["position"])
  315. name = gconv.String(sdata["name"])
  316. }
  317. }
  318. top_cluetype, sub_cluetype, level, topname, subname = getClueType(item, data, sourceCode, sourceId) //查留资来源名字
  319. if topname == "市场活动" && item == "saleLeads" { //市场活动的不要
  320. log.Println("市场活动留资过滤 ", userId, phone)
  321. return true, true, true
  322. }
  323. if strings.HasPrefix(belong_to, "03") { //一切都好的不进
  324. isOk := saveEverything(userId, phone, item, subname, sourceCode, belong_to)
  325. log.Println("渠道线索电销", userId, phone, item, subname, sourceCode)
  326. if !isOk {
  327. return true, true, true
  328. }
  329. }
  330. follow_project_area = getAreaCode(userId) //关注项目区域
  331. log.Println("data +++", top_cluetype, sub_cluetype, level, follow_project_area, isGroup, isCommerce)
  332. if top_cluetype == "" || sub_cluetype == "" || level == "" {
  333. log.Println("线索分配失败,线索过滤top_cluetype!!", item, uId, phone, userId)
  334. return true, true, true
  335. }
  336. log.Println("人员选择", level, cluename, phone, isGroup, isCommerce)
  337. position_id, seatNumber, saleName, saleData, pIsOk, isFreeze, noticePositionId := autoDraw(level, cluename, phone, isGroup, isCommerce) //查询当前分配次数最少的,如果当前线索有销售,此次找出的不会+1
  338. log.Println("data -------", position_id, seatNumber, saleName, pIsOk, isFreeze, noticePositionId)
  339. if position_id > 0 && seatNumber != "" {
  340. uCount, oks := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, "", ""), true //查当前线索是否已存在
  341. if uCount != nil && len(*uCount) > 0 {
  342. isUpdate := gconv.Int64((*uCount)["is_artificially_modified"])
  343. if isUpdate == 1 {
  344. cluename = ""
  345. }
  346. //已存在,走更新
  347. batch_import := gconv.String((*uCount)["batch_import"])
  348. if batch_import != "" && item == "users" { //有导入批次号还是新用户,不执行
  349. return true, true, true
  350. }
  351. 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)
  352. } else { //不存在走新增
  353. 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, "")
  354. if oks { //新增成功,销售分配次数+1
  355. TiDb.UpdateOrDeleteBySql(`update dwd_f_crm_clue_autodraw_record set count = count + 1 where position_id = ? and clue_level = ?`, position_id, level)
  356. }
  357. }
  358. if !oks {
  359. log.Println("线索分配失败!!", item, position_id, seatNumber, uId, userId, phone)
  360. return false, false, true
  361. }
  362. } else {
  363. if isFreeze {
  364. //达上限放公海处理
  365. uCount, oks := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, "", ""), true //查当前线索是否已存在
  366. if uCount == nil || len(*uCount) == 0 {
  367. 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)
  368. log.Println(oks)
  369. } else {
  370. //留资线索更新
  371. if item != "orders" && item != "users" { //新用户和订单之外的替换一下新的留资信息
  372. BCPCID := common.GetRandom(32)
  373. clueId := common.Int64All((*uCount)["id"])
  374. old_name := gconv.String((*uCount)["name"])
  375. old_position := gconv.String((*uCount)["position"])
  376. old_department := gconv.String((*uCount)["department"])
  377. old_follow_project_area := gconv.String((*uCount)["follow_project_area"])
  378. old_role := gconv.String((*uCount)["role"])
  379. old_cluename := gconv.String((*uCount)["cluename"])
  380. old_top_cluetype := gconv.String((*uCount)["top_cluetype"])
  381. old_sub_cluetype := gconv.String((*uCount)["sub_cluetype"])
  382. label := gconv.Int64((*uCount)["label"])
  383. trailstatusCode := gconv.String((*uCount)["trailstatus"])
  384. clueUpdateData := map[string]interface{}{}
  385. e_label := gconv.String((*uCount)["e_label"])
  386. Ehandle(clueId, uId, userId, cluename, trailstatusCode, e_label)
  387. if old_name != name && name != "" {
  388. clueUpdateData["name"] = name
  389. TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  390. "clue_id": clueId,
  391. "change_field": "name",
  392. "position_id": 0,
  393. "seatNumber": nil,
  394. "change_type": "基本信息变更",
  395. "old_value": common.If(old_name != "", old_name, "/"),
  396. "new_value": common.If(name != "", name, "/"),
  397. "createtime": nowTime,
  398. "BCPCID": BCPCID,
  399. "operator_id": -1})
  400. }
  401. if old_position != position && position != "" {
  402. clueUpdateData["position"] = position
  403. TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  404. "clue_id": clueId,
  405. "change_field": "position",
  406. "position_id": 0,
  407. "change_type": "基本信息变更",
  408. "old_value": common.If(old_position != "", old_position, "/"),
  409. "new_value": common.If(position != "", position, "/"),
  410. "createtime": nowTime,
  411. "BCPCID": BCPCID,
  412. "operator_id": -1})
  413. }
  414. if old_department != department && department != "" {
  415. clueUpdateData["department"] = department
  416. TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  417. "clue_id": clueId,
  418. "change_field": "department",
  419. "position_id": 0,
  420. "change_type": "基本信息变更",
  421. "old_value": common.If(old_department != "", old_department, "/"),
  422. "new_value": common.If(department != "", department, "/"),
  423. "createtime": nowTime,
  424. "BCPCID": BCPCID,
  425. "operator_id": -1})
  426. }
  427. if old_follow_project_area != follow_project_area && follow_project_area != "" {
  428. clueUpdateData["follow_project_area"] = follow_project_area
  429. TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  430. "clue_id": clueId,
  431. "change_field": "follow_project_area",
  432. "position_id": 0,
  433. "change_type": "基本信息变更",
  434. "old_value": common.If(old_follow_project_area != "", old_follow_project_area, "/"),
  435. "new_value": common.If(follow_project_area != "", follow_project_area, "/"),
  436. "createtime": nowTime,
  437. "BCPCID": BCPCID,
  438. "operator_id": -1})
  439. }
  440. if old_role != role && role != "" {
  441. TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  442. "clue_id": clueId,
  443. "change_field": "role",
  444. "change_type": "基本信息变更",
  445. "old_value": common.If(old_role != "", old_role, "/"),
  446. "new_value": common.If(role != "", role, "/"),
  447. "createtime": nowTime,
  448. "position_id": 0,
  449. "BCPCID": BCPCID,
  450. "operator_id": -1})
  451. clueUpdateData["role"] = role
  452. }
  453. if old_cluename != cluename && cluename != "" {
  454. clueUpdateData["cluename"] = cluename //新的线索名不为空才替换
  455. TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  456. "clue_id": clueId,
  457. "change_field": "cluename",
  458. "change_type": "基本信息变更",
  459. "old_value": common.If(old_cluename != "", old_cluename, "/"),
  460. "new_value": common.If(cluename != "", cluename, "/"),
  461. "createtime": nowTime,
  462. "BCPCID": BCPCID,
  463. "position_id": 0,
  464. "operator_id": -1})
  465. }
  466. old_topname := ""
  467. old_subname := ""
  468. if old_top_cluetype != "" {
  469. pcodeData := TiDb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"code": old_top_cluetype}, "", "")
  470. if pcodeData != nil && len(*pcodeData) > 0 {
  471. old_topname = gconv.String((*pcodeData)["name"])
  472. }
  473. }
  474. if old_sub_cluetype != "" {
  475. pcodeData := TiDb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"code": old_sub_cluetype}, "", "")
  476. if pcodeData != nil && len(*pcodeData) > 0 {
  477. old_subname = gconv.String((*pcodeData)["name"])
  478. }
  479. }
  480. if old_top_cluetype != top_cluetype && top_cluetype != "" {
  481. clueUpdateData["top_cluetype"] = top_cluetype //新的线索名不为空才替换
  482. TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  483. "clue_id": clueId,
  484. "change_field": "top_cluetype",
  485. "position_id": 0,
  486. "change_type": "基本信息变更",
  487. "old_value": common.If(old_topname != "", old_topname, "/"),
  488. "new_value": common.If(topname != "", topname, "/"),
  489. "createtime": nowTime,
  490. "BCPCID": BCPCID,
  491. "operator_id": -1})
  492. }
  493. if old_sub_cluetype != sub_cluetype && sub_cluetype != "" {
  494. clueUpdateData["sub_cluetype"] = sub_cluetype //新的线索名不为空才替换
  495. TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  496. "clue_id": clueId,
  497. "change_field": "sub_cluetype", //111
  498. "position_id": 0,
  499. "change_type": "基本信息变更",
  500. "old_value": common.If(old_subname != "", old_subname, "/"),
  501. "new_value": common.If(subname != "", subname, "/"),
  502. "createtime": nowTime,
  503. "BCPCID": BCPCID,
  504. "operator_id": -1})
  505. //标签处理
  506. LabelHandel(nil, label, 2, uId, level, trailstatusCode, gconv.String(clueUpdateData["trailstatus"]), 1)
  507. }
  508. clueUpdateData["company_nature"] = isGroup
  509. clueUpdateData["company_verification"] = isCommerce
  510. TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, clueUpdateData)
  511. }
  512. }
  513. AssFail(noticePositionId, cluename, phone)
  514. return true, true, true
  515. }
  516. return true, false, true
  517. }
  518. return true, true, true
  519. }
  520. 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 {
  521. 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)
  522. nowTime := time.Now().Format("2006-01-02 15:04:05")
  523. nowTimes := time.Unix(time.Now().Unix()+3600*12, 0).Format("2006-01-02 15:04:05")
  524. clueId, uodateId1, uodateId2, uodateId3, uodateId4, uodateId5, uodateId6 := int64(0), int64(0), int64(0), int64(0), int64(0), int64(0), int64(0)
  525. if TiDb.ExecTx("保存线索", func(tx *sql.Tx) bool {
  526. keywords := ""
  527. if sourceCode == "app_xzcyh" {
  528. if len(keyword) > 0 && keyword[0] != "" {
  529. keywords = strings.Join(keyword, ",")
  530. }
  531. }
  532. if cluename == "" {
  533. cluename = phone
  534. }
  535. clueId = TiDb.InsertByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{
  536. "userid": userId,
  537. "uid": uId,
  538. "seatNumber": seatNumber,
  539. "position_id": positionId,
  540. "is_assign": common.If(isFreeze, -3, 1),
  541. "comeintime": nowTime,
  542. "createtime": nowTime,
  543. "updatetime": nowTime,
  544. "cluename": cluename,
  545. "top_cluetype": top_cluetype,
  546. "sub_cluetype": sub_cluetype,
  547. "trailstatus": "01",
  548. "name": name,
  549. "phone": phone,
  550. "position": position,
  551. "department": common.If(sourceCode == "app_xzcyh", departments, department),
  552. "industry": industry,
  553. "follow_project_area": follow_project_area,
  554. "role": role,
  555. "comeinsource_private": 2,
  556. "is_task": 1,
  557. "task_time": nowTime,
  558. "tasktime": common.If(item == "users", nowTimes, nowTime),
  559. "taskstatus": 0,
  560. "tasksource": "线索自动分配" + "-" + topname + "-" + subname,
  561. "business_scope": common.If(sourceCode == "app_xzcyh", keywords, nil),
  562. "company_nature": isGroup,
  563. "company_verification": isCommerce,
  564. "remark": remark,
  565. "customer_demand": demand,
  566. "FREEZE_TIME": nowTime,
  567. "label": 1,
  568. "labelChangeTime": time.Now().Format("2006-01-02"),
  569. })
  570. Ehandle(clueId, uId, userId, cluename, "01", "E")
  571. uodateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  572. "clue_id": clueId,
  573. "position_id": positionId,
  574. "change_type": "创建线索",
  575. "new_value": "系统自动创建",
  576. "createtime": nowTime,
  577. "BCPCID": common.GetRandom(32),
  578. "operator_id": -1,
  579. })
  580. uodateId2 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  581. "clue_id": clueId,
  582. "position_id": positionId,
  583. "change_field": "position_id",
  584. "change_type": "所属人变更",
  585. "old_value": "/",
  586. "new_value": saleName,
  587. "createtime": nowTime,
  588. "BCPCID": common.GetRandom(32),
  589. "operator_id": -1,
  590. })
  591. uodateId3 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  592. "clue_id": clueId,
  593. "position_id": positionId,
  594. "change_field": "trailstatus",
  595. "change_type": "基本信息变更",
  596. "old_value": "商机线索",
  597. "new_value": "新增",
  598. "createtime": nowTime,
  599. "BCPCID": common.GetRandom(32),
  600. "operator_id": -1,
  601. })
  602. uodateId4 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  603. "clue_id": clueId,
  604. "position_id": positionId,
  605. "change_type": "加入任务车",
  606. "new_value": "线索自动分配" + "-" + topname + "-" + subname,
  607. "createtime": nowTime,
  608. "BCPCID": common.GetRandom(32),
  609. "operator_id": -1,
  610. })
  611. uodateId5 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  612. "clue_id": clueId,
  613. "position_id": positionId,
  614. "change_field": "top_cluetype",
  615. "change_type": "基本信息变更",
  616. "old_value": "/",
  617. "new_value": topname,
  618. "createtime": nowTime,
  619. "BCPCID": common.GetRandom(32),
  620. "operator_id": -1,
  621. })
  622. uodateId6 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  623. "clue_id": clueId,
  624. "position_id": positionId,
  625. "change_field": "sub_cluetype", //222
  626. "change_type": "基本信息变更",
  627. "old_value": "/",
  628. "new_value": subname,
  629. "createtime": nowTime,
  630. "BCPCID": common.GetRandom(32),
  631. "operator_id": -1,
  632. })
  633. //冻结处理
  634. return clueId > -1 && uodateId1 > -1 && uodateId2 > -1 && uodateId3 > -1 && uodateId4 > -1 && uodateId5 > -1 && uodateId6 > -1
  635. }) {
  636. log.Println("线索分配成功")
  637. if TiDb.Count("dwd_f_userbase_contacts", map[string]interface{}{"phone": phone}) == 0 {
  638. TiDb.Insert("dwd_f_userbase_contacts", map[string]interface{}{
  639. "status": 1,
  640. "is_delete": 1,
  641. "createtime": nowTime,
  642. "updatetime": nowTime,
  643. "phone": phone,
  644. "baseinfo_id": uId,
  645. "SOURCE": source,
  646. })
  647. }
  648. return true
  649. } else {
  650. log.Println("线索分配失败!!!", clueId, uodateId1, uodateId2, uodateId3, uodateId4, uodateId5, uodateId6, " 用户信息 ", item, position, seatNumber, uId, userId, phone)
  651. return false
  652. }
  653. }
  654. 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 {
  655. nowTime := time.Now().Format("2006-01-02 15:04:05")
  656. clueId, uodateId1, uodateId2, uodateId3 := int64(0), int64(0), int64(0), int64(0)
  657. if TiDb.ExecTx("保存线索", func(tx *sql.Tx) bool {
  658. keywords := ""
  659. if sourceCode == "app_xzcyh" {
  660. if len(keyword) > 0 && keyword[0] != "" {
  661. keywords = strings.Join(keyword, ",")
  662. }
  663. }
  664. if cluename == "" {
  665. cluename = phone
  666. }
  667. clueId = TiDb.InsertByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{
  668. "userid": userId,
  669. "uid": uId,
  670. "seatNumber": "",
  671. "position_id": 0,
  672. "is_assign": 0,
  673. "comeintime": nowTime,
  674. "createtime": nowTime,
  675. "updatetime": nowTime,
  676. "cluename": cluename,
  677. "top_cluetype": top_cluetype,
  678. "sub_cluetype": sub_cluetype,
  679. "trailstatus": "01",
  680. "name": name,
  681. "phone": phone,
  682. "position": position,
  683. "department": common.If(sourceCode == "app_xzcyh", departments, department),
  684. "industry": industry,
  685. "follow_project_area": follow_project_area,
  686. "role": role,
  687. "comeinsource_private": 2,
  688. "business_scope": common.If(sourceCode == "app_xzcyh", keywords, nil),
  689. "company_nature": isGroup,
  690. "company_verification": isCommerce,
  691. "remark": remark,
  692. "FREEZE_TIME": nowTime,
  693. "label": 1,
  694. "labelChangeTime": time.Now().Format("2006-01-02"),
  695. })
  696. Ehandle(clueId, uId, userId, cluename, "01", "E")
  697. uodateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  698. "clue_id": clueId,
  699. "position_id": positionId,
  700. "change_type": "创建线索",
  701. "new_value": "系统自动创建",
  702. "createtime": nowTime,
  703. "BCPCID": common.GetRandom(32),
  704. "operator_id": -1,
  705. })
  706. uodateId2 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  707. "clue_id": clueId,
  708. "position_id": positionId,
  709. "change_field": "position_id",
  710. "change_type": "所属人变更",
  711. "old_value": "",
  712. "new_value": "/",
  713. "createtime": nowTime,
  714. "BCPCID": common.GetRandom(32),
  715. "operator_id": -1,
  716. })
  717. uodateId3 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  718. "clue_id": clueId,
  719. "position_id": positionId,
  720. "change_field": "trailstatus",
  721. "change_type": "基本信息变更",
  722. "old_value": "商机线索",
  723. "new_value": "新增",
  724. "createtime": nowTime,
  725. "BCPCID": common.GetRandom(32),
  726. "operator_id": -1,
  727. })
  728. return clueId > -1 && uodateId1 > -1 && uodateId2 > -1 && uodateId3 > -1
  729. }) {
  730. log.Println("线索分配成功")
  731. if TiDb.Count("dwd_f_userbase_contacts", map[string]interface{}{"phone": phone}) == 0 {
  732. TiDb.Insert("dwd_f_userbase_contacts", map[string]interface{}{
  733. "status": 1,
  734. "is_delete": 1,
  735. "createtime": nowTime,
  736. "updatetime": nowTime,
  737. "phone": phone,
  738. "baseinfo_id": uId,
  739. "SOURCE": source,
  740. })
  741. }
  742. return true
  743. } else {
  744. log.Println("线索分配失败!!!", clueId, uodateId1, uodateId2, uodateId3, " 用户信息 ", item, position, seatNumber, uId, userId, phone)
  745. return false
  746. }
  747. }
  748. 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 {
  749. log.Println("工单线索修改前", data)
  750. nowTime := time.Now().Format("2006-01-02 15:04:05")
  751. nowTimes := time.Unix(time.Now().Unix()+3600*12, 0).Format("2006-01-02 15:04:05")
  752. trailstatus := gconv.String(data["trailstatus"]) //data都为原线索数据
  753. trailstatusTime := gconv.String(data["trailstatus_time"])
  754. var trailstatusTimes time.Time
  755. if trailstatusTime != "" {
  756. trailstatusTimes, _ = time.ParseInLocation(date.Date_Full_Layout, trailstatusTime, time.Local)
  757. }
  758. clueId := common.Int64All(data["id"])
  759. is_assign := common.IntAll(data["is_assign"])
  760. oldsaleName, oldTaskTime, taskTime, is_task, taskstatus := "", "", "", 0, 0
  761. old_position_id, old_seatNumber := common.Int64All(data["position_id"]), gconv.String(data["seatNumber"])
  762. oldTaskTime = gconv.String(data["tasktime"])
  763. is_task = common.IntAll(data["is_task"])
  764. taskstatus = common.IntAll(data["taskstatus"])
  765. BCPCID := common.GetRandom(32)
  766. old_name := gconv.String(data["name"])
  767. old_position := gconv.String(data["position"])
  768. old_department := gconv.String(data["department"])
  769. old_follow_project_area := gconv.String(data["follow_project_area"])
  770. old_role := gconv.String(data["role"])
  771. old_cluename := gconv.String(data["cluename"])
  772. old_top_cluetype := gconv.String(data["top_cluetype"])
  773. old_sub_cluetype := gconv.String(data["sub_cluetype"])
  774. label := gconv.Int64(data["label"])
  775. e_label := gconv.String(data["e_label"])
  776. old_topname, old_subname := "", ""
  777. Ehandle(clueId, uId, userId, cluename, trailstatus, e_label)
  778. is_transfer := common.IntAll(data["is_transfer"])
  779. if taskstatus == 1 || is_task == 0 {
  780. taskTime = gconv.String(common.If(item != "users", nowTime, nowTimes)) //任务时间,正常的是当前时间,新用户是当前时间+12个小时
  781. } else {
  782. if is_task == 1 {
  783. if oldTaskTime != "" { //以最新的任务时间为主
  784. t1, err := time.Parse("2006-01-02 15:04:05", oldTaskTime)
  785. if err == nil && time.Now().Before(t1) {
  786. taskTime = nowTime
  787. } else {
  788. taskTime = oldTaskTime
  789. }
  790. }
  791. }
  792. }
  793. count, counts, t := 0, 0, time.Now() //加入任务车判断节假日
  794. for {
  795. count++
  796. currentTime := t.AddDate(0, 0, -count)
  797. if currentTime.Weekday() == time.Sunday || currentTime.Weekday() == time.Saturday {
  798. isok := false
  799. for k, v := range DateMap {
  800. if currentTime.Format(date.Date_Short_Layout) == k && v == 2 {
  801. isok = true
  802. }
  803. }
  804. if isok {
  805. counts++
  806. }
  807. } else {
  808. isok := true
  809. for k, v := range DateMap {
  810. if currentTime.Format(date.Date_Short_Layout) == k && v == 1 {
  811. isok = false
  812. }
  813. }
  814. if isok {
  815. counts++
  816. }
  817. }
  818. if counts >= 2 {
  819. break
  820. }
  821. }
  822. //两天之前不包含节假日,有没有跟进记录
  823. 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))
  824. //
  825. clueUpdateData := map[string]interface{}{
  826. "updatetime": nowTime,
  827. "top_cluetype": top_cluetype,
  828. "sub_cluetype": sub_cluetype,
  829. "userid": userId,
  830. "comeinsource_private": 2,
  831. "tasksource": gconv.String(common.If(gconv.Int64(data["position_id"]) == 0, "线索自动分配", "线索来源自动更新")) + "-" + topname + "-" + subname,
  832. "company_nature": isGroup,
  833. "company_verification": isCommerce,
  834. }
  835. old_remark := gconv.String(data["remark"])
  836. if old_remark != "" {
  837. remark = old_remark + ";" + remark //备注不能替换,只能往上拼接
  838. }
  839. clueUpdateData["remark"] = remark
  840. old_demand := gconv.String(data["customer_demand"])
  841. if demand != old_demand {
  842. clueUpdateData["customer_demand"] = demand
  843. }
  844. if cluename != "" {
  845. clueUpdateData["cluename"] = cluename //新的线索名不为空才替换
  846. }
  847. if item != "orders" && item != "users" { //新用户和订单之外的替换一下新的留资信息
  848. if name != "" {
  849. clueUpdateData["name"] = name
  850. }
  851. if position != "" {
  852. clueUpdateData["position"] = position
  853. }
  854. if department != "" {
  855. clueUpdateData["department"] = department
  856. }
  857. if follow_project_area != "" {
  858. clueUpdateData["follow_project_area"] = follow_project_area
  859. }
  860. if role != "" {
  861. clueUpdateData["role"] = role
  862. }
  863. // clueUpdateData["industry"] = industry
  864. }
  865. if sourceCode == "app_xzcyh" { //这个留资单独处理一下
  866. if departments != "" {
  867. clueUpdateData["department"] = departments
  868. department = departments
  869. }
  870. business_scope := gconv.String(data["business_scope"])
  871. keywords := ""
  872. if len(keyword) > 0 && keyword[0] != "" {
  873. keywords = strings.Join(keyword, ",")
  874. if business_scope != "" {
  875. clueUpdateData["business_scope"] = business_scope + "," + keywords
  876. } else {
  877. clueUpdateData["business_scope"] = keywords
  878. }
  879. }
  880. }
  881. if old_position_id != 0 {
  882. for _, v := range saleData {
  883. if old_position_id == common.Int64All(v["position_id"]) {
  884. oldsaleName = gconv.String(v["name"])
  885. }
  886. }
  887. }
  888. if trailstatus == "00" || old_position_id == 0 || is_assign != 1 || (pIsOk && old_cluename != cluename && cluename != "") {
  889. if trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400 {
  890. } else {
  891. clueUpdateData["seatNumber"] = seatNumber
  892. clueUpdateData["position_id"] = positionId
  893. clueUpdateData["comeintime"] = nowTime
  894. clueUpdateData["is_assign"] = 1
  895. clueUpdateData["comeinsource_open"] = nil
  896. clueUpdateData["level_open"] = nil
  897. clueUpdateData["clue_level"] = nil
  898. }
  899. } else if is_assign == 1 && positionId != old_position_id {
  900. clueUpdateData["seatNumber"] = seatNumber
  901. clueUpdateData["position_id"] = positionId
  902. clueUpdateData["comeintime"] = nowTime
  903. clueUpdateData["is_assign"] = 1
  904. clueUpdateData["comeinsource_open"] = nil
  905. clueUpdateData["level_open"] = nil
  906. clueUpdateData["clue_level"] = nil
  907. } else { //不属于上边情况就还是属于原来的销售,不更换销售
  908. clueUpdateData["seatNumber"] = old_seatNumber
  909. clueUpdateData["position_id"] = old_position_id
  910. clueUpdateData["is_assign"] = 1
  911. clueUpdateData["comeinsource_open"] = nil
  912. clueUpdateData["level_open"] = nil
  913. clueUpdateData["clue_level"] = nil
  914. }
  915. if is_assign == 0 { //在公海的成交客户
  916. if trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400 {
  917. } else {
  918. clueUpdateData["trailstatus"] = "01"
  919. clueUpdateData["trailstatus_time"] = nowTime
  920. }
  921. }
  922. if trailstatus == "02" { //在公海的成交客户
  923. clueUpdateData["trailstatus"] = "01"
  924. clueUpdateData["trailstatus_time"] = nowTime
  925. }
  926. is_ok := false
  927. if recordCount <= 0 || is_assign == 0 {
  928. if trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400 {
  929. } else {
  930. if item == "eventReg" {
  931. eData := TiDb.Find("dwd_f_crm_clue_change_record", map[string]interface{}{"clue_id": clueId, "change_type": "加入任务车"}, "", "", -1, -1)
  932. if eData != nil && len(*eData) > 0 {
  933. for _, e := range *eData {
  934. new_value := gconv.String(e["new_value"])
  935. if strings.Contains(new_value, subname) {
  936. is_ok = true
  937. }
  938. }
  939. }
  940. if !is_ok {
  941. if old_sub_cluetype != sub_cluetype || is_assign == 0 {
  942. if taskTime == "" {
  943. taskTime = nowTime
  944. }
  945. clueUpdateData["task_time"] = nowTime
  946. clueUpdateData["tasktime"] = taskTime
  947. clueUpdateData["taskstatus"] = 0
  948. }
  949. if is_transfer != 1 {
  950. clueUpdateData["is_task"] = 1
  951. }
  952. }
  953. } else {
  954. if old_sub_cluetype != sub_cluetype || is_assign == 0 {
  955. if taskTime == "" {
  956. taskTime = nowTime
  957. }
  958. clueUpdateData["task_time"] = nowTime
  959. clueUpdateData["tasktime"] = taskTime
  960. clueUpdateData["taskstatus"] = 0
  961. }
  962. if is_transfer != 1 {
  963. clueUpdateData["is_task"] = 1
  964. }
  965. }
  966. }
  967. }
  968. ok, updateId14 := true, true
  969. updateId1, updateId2, updateId3, updateId4, updateId5 := int64(0), int64(0), int64(0), int64(0), int64(0)
  970. updateId6, updateId7, updateId8, updateId9, updateId10 := int64(0), int64(0), int64(0), int64(0), int64(0)
  971. updateId11, updateId12, updateId13 := int64(0), int64(0), int64(0)
  972. if TiDb.ExecTx("更新线索", func(tx *sql.Tx) bool {
  973. //线索
  974. ok = TiDb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, clueUpdateData)
  975. //变更记录
  976. if (trailstatus == "00" || old_position_id == 0 || (pIsOk && old_cluename != cluename && cluename != "")) && is_assign == 1 {
  977. if trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400 {
  978. } else if old_position_id == 0 {
  979. updateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  980. "clue_id": clueId,
  981. "position_id": positionId,
  982. "change_field": "position_id",
  983. "change_type": "所属人变更",
  984. "old_value": common.If(oldsaleName != "", oldsaleName, "/"),
  985. "new_value": common.If(saleName != "", saleName, "/"),
  986. "createtime": nowTime,
  987. "BCPCID": common.GetRandom(32),
  988. "operator_id": -1,
  989. })
  990. updateId3 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  991. "clue_id": clueId,
  992. "position_id": positionId,
  993. "change_field": "trailstatus",
  994. "change_type": "基本信息变更",
  995. "old_value": CodeTrail[trailstatus],
  996. "new_value": "新增",
  997. "createtime": nowTime,
  998. "BCPCID": common.GetRandom(32),
  999. "operator_id": -1,
  1000. })
  1001. } else {
  1002. if pIsOk && old_cluename != cluename && cluename != "" {
  1003. updateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  1004. "clue_id": clueId,
  1005. "position_id": positionId,
  1006. "change_field": "position_id",
  1007. "change_type": "所属人变更",
  1008. "old_value": common.If(oldsaleName != "", oldsaleName, "/"),
  1009. "new_value": common.If(saleName != "", saleName, "/"),
  1010. "createtime": nowTime,
  1011. "BCPCID": common.GetRandom(32),
  1012. "operator_id": -1,
  1013. })
  1014. } else {
  1015. updateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  1016. "clue_id": clueId,
  1017. "position_id": positionId,
  1018. "change_field": "position_id",
  1019. "change_type": "所属人变更",
  1020. "old_value": common.If(oldsaleName != "", oldsaleName, "/"),
  1021. "new_value": common.If(saleName != "", saleName, "/"),
  1022. "createtime": nowTime,
  1023. "BCPCID": common.GetRandom(32),
  1024. "operator_id": -1,
  1025. })
  1026. updateId2 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  1027. "clue_id": clueId,
  1028. "position_id": common.Int64All(data["position_id"]),
  1029. "change_field": "trailstatus",
  1030. "change_type": "基本信息变更",
  1031. "old_value": "无意向客户",
  1032. "new_value": "流失",
  1033. "createtime": nowTime,
  1034. "BCPCID": common.GetRandom(32),
  1035. "operator_id": -1,
  1036. })
  1037. updateId3 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  1038. "clue_id": clueId,
  1039. "position_id": positionId,
  1040. "change_field": "trailstatus",
  1041. "change_type": "基本信息变更",
  1042. "old_value": "商机线索",
  1043. "new_value": "新增",
  1044. "createtime": nowTime,
  1045. "BCPCID": common.GetRandom(32),
  1046. "operator_id": -1,
  1047. })
  1048. updateId4 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  1049. "clue_id": clueId,
  1050. "position_id": positionId,
  1051. "change_field": "trailstatus",
  1052. "change_type": "基本信息变更",
  1053. "old_value": "无意向客户",
  1054. "new_value": "商机线索",
  1055. "createtime": nowTime,
  1056. "BCPCID": common.GetRandom(32),
  1057. "operator_id": -1,
  1058. })
  1059. }
  1060. }
  1061. } else if is_assign == 0 {
  1062. if trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400 {
  1063. } else {
  1064. updateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  1065. "clue_id": clueId,
  1066. "position_id": positionId,
  1067. "change_field": "position_id",
  1068. "change_type": "所属人变更",
  1069. "old_value": common.If(oldsaleName != "", oldsaleName, "/"),
  1070. "new_value": common.If(saleName != "", saleName, "/"),
  1071. "createtime": nowTime,
  1072. "BCPCID": common.GetRandom(32),
  1073. "operator_id": -1,
  1074. })
  1075. if trailstatus != "01" {
  1076. updateId4 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  1077. "clue_id": clueId,
  1078. "position_id": positionId,
  1079. "change_field": "trailstatus",
  1080. "change_type": "基本信息变更",
  1081. "old_value": CodeTrail[trailstatus],
  1082. "new_value": "商机线索",
  1083. "createtime": nowTime,
  1084. "BCPCID": common.GetRandom(32),
  1085. "operator_id": -1,
  1086. })
  1087. }
  1088. updateId3 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  1089. "clue_id": clueId,
  1090. "position_id": positionId,
  1091. "change_field": "trailstatus",
  1092. "change_type": "基本信息变更",
  1093. "old_value": "商机线索",
  1094. "new_value": "新增",
  1095. "createtime": nowTime,
  1096. "BCPCID": common.GetRandom(32),
  1097. "operator_id": -1,
  1098. })
  1099. }
  1100. } else if is_assign == -1 {
  1101. updateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  1102. "clue_id": clueId,
  1103. "position_id": positionId,
  1104. "change_field": "position_id",
  1105. "change_type": "所属人变更",
  1106. "old_value": common.If(oldsaleName != "", oldsaleName, "/"),
  1107. "new_value": common.If(saleName != "", saleName, "/"),
  1108. "createtime": nowTime,
  1109. "BCPCID": common.GetRandom(32),
  1110. "operator_id": -1,
  1111. })
  1112. updateId4 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  1113. "clue_id": clueId,
  1114. "position_id": positionId,
  1115. "change_field": "trailstatus",
  1116. "change_type": "基本信息变更",
  1117. "old_value": CodeTrail[trailstatus],
  1118. "new_value": "商机线索",
  1119. "createtime": nowTime,
  1120. "BCPCID": common.GetRandom(32),
  1121. "operator_id": -1,
  1122. })
  1123. } else if (pIsOk && old_cluename == cluename && cluename != "") && is_assign == 1 && positionId != old_position_id {
  1124. updateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  1125. "clue_id": clueId,
  1126. "position_id": positionId,
  1127. "change_field": "position_id",
  1128. "change_type": "所属人变更",
  1129. "old_value": common.If(oldsaleName != "", oldsaleName, "/"),
  1130. "new_value": common.If(saleName != "", saleName, "/"),
  1131. "createtime": nowTime,
  1132. "BCPCID": common.GetRandom(32),
  1133. "operator_id": -1,
  1134. })
  1135. }
  1136. if recordCount <= 0 || is_assign == 0 {
  1137. if trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400 {
  1138. } else {
  1139. if is_transfer == 1 {
  1140. if old_sub_cluetype != sub_cluetype && !is_ok {
  1141. cdata := TiDb.FindOne("dwd_f_csm_customer_info", map[string]interface{}{"clue_id": clueId}, "", "")
  1142. if cdata != nil && len(*cdata) > 0 {
  1143. kcpositionId := common.Int64All((*cdata)["position_id"])
  1144. tasksource := gconv.String((*cdata)["tasksource"])
  1145. taskstatus := common.IntAll((*cdata)["taskstatus"])
  1146. updateId5 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  1147. "clue_id": clueId,
  1148. "position_id": kcpositionId,
  1149. "change_type": "加入任务车",
  1150. "new_value": "线上主动留资",
  1151. "createtime": nowTime,
  1152. "BCPCID": common.GetRandom(32),
  1153. "operator_id": -1,
  1154. })
  1155. if taskstatus == 1 {
  1156. tasksource = "10"
  1157. } else {
  1158. if tasksource != "" && !strings.Contains(tasksource, "10") {
  1159. if !strings.Contains(tasksource, "10") {
  1160. tasksource += ",10"
  1161. }
  1162. } else {
  1163. tasksource = "10"
  1164. }
  1165. }
  1166. updateId14 = TiDb.UpdateByTx(tx, "dwd_f_csm_customer_info", map[string]interface{}{"clue_id": clueId}, map[string]interface{}{
  1167. "tasksource": tasksource,
  1168. "tasktime": nowTime,
  1169. "is_task": 1,
  1170. "taskstatus": 0,
  1171. })
  1172. }
  1173. }
  1174. } else if !is_ok {
  1175. updateId5 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  1176. "clue_id": clueId,
  1177. "position_id": common.If(trailstatus == "00" || is_assign == 0 || is_assign == -1, positionId, common.Int64All(data["position_id"])),
  1178. "change_type": "加入任务车",
  1179. "new_value": gconv.String(common.If(gconv.Int64(data["position_id"]) == 0, "线索自动分配", "线索来源自动更新")) + "-" + topname + "-" + subname,
  1180. "createtime": nowTime,
  1181. "BCPCID": common.GetRandom(32),
  1182. "operator_id": -1,
  1183. })
  1184. }
  1185. }
  1186. }
  1187. if old_top_cluetype != "" {
  1188. pcodeData := TiDb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"code": old_top_cluetype}, "", "")
  1189. if pcodeData != nil && len(*pcodeData) > 0 {
  1190. old_topname = gconv.String((*pcodeData)["name"])
  1191. }
  1192. }
  1193. if old_sub_cluetype != "" {
  1194. pcodeData := TiDb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"code": old_sub_cluetype}, "", "")
  1195. if pcodeData != nil && len(*pcodeData) > 0 {
  1196. old_subname = gconv.String((*pcodeData)["name"])
  1197. }
  1198. }
  1199. if item != "orders" {
  1200. if old_name != name && name != "" {
  1201. updateId6 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  1202. "clue_id": clueId,
  1203. "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"])))),
  1204. "change_field": "name",
  1205. "change_type": "基本信息变更",
  1206. "old_value": common.If(old_name != "", old_name, "/"),
  1207. "new_value": common.If(name != "", name, "/"),
  1208. "createtime": nowTime,
  1209. "BCPCID": BCPCID,
  1210. "operator_id": -1,
  1211. })
  1212. }
  1213. if old_position != position && position != "" {
  1214. updateId7 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  1215. "clue_id": clueId,
  1216. "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"])))),
  1217. "change_field": "position",
  1218. "change_type": "基本信息变更",
  1219. "old_value": common.If(old_position != "", old_position, "/"),
  1220. "new_value": common.If(position != "", position, "/"),
  1221. "createtime": nowTime,
  1222. "BCPCID": BCPCID,
  1223. "operator_id": -1,
  1224. })
  1225. }
  1226. if old_department != department && department != "" {
  1227. updateId8 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  1228. "clue_id": clueId,
  1229. "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"])))),
  1230. "change_field": "department",
  1231. "change_type": "基本信息变更",
  1232. "old_value": common.If(old_department != "", old_department, "/"),
  1233. "new_value": common.If(department != "", department, "/"),
  1234. "createtime": nowTime,
  1235. "BCPCID": BCPCID,
  1236. "operator_id": -1,
  1237. })
  1238. }
  1239. if old_role != role && role != "" {
  1240. 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})
  1241. }
  1242. if old_follow_project_area != follow_project_area && follow_project_area != "" {
  1243. old_area, old_area_arr := "", []string{}
  1244. new_area, new_area_arr := "", []string{}
  1245. for _, v := range strings.Split(old_follow_project_area, ",") {
  1246. old_area_arr = append(old_area_arr, CodeArea[v])
  1247. }
  1248. for _, v := range strings.Split(follow_project_area, ",") {
  1249. new_area_arr = append(new_area_arr, CodeArea[v])
  1250. }
  1251. old_area = strings.Join(old_area_arr, ",")
  1252. new_area = strings.Join(new_area_arr, ",")
  1253. updateId10 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  1254. "clue_id": clueId,
  1255. "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"])))),
  1256. "change_field": "follow_project_area",
  1257. "change_type": "基本信息变更",
  1258. "old_value": common.If(old_area != "", old_area, "/"),
  1259. "new_value": common.If(new_area != "", new_area, "/"),
  1260. "createtime": nowTime,
  1261. "BCPCID": BCPCID,
  1262. "operator_id": -1,
  1263. })
  1264. }
  1265. if old_cluename != cluename && cluename != "" {
  1266. updateId11 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  1267. "clue_id": clueId,
  1268. "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"])))),
  1269. "change_field": "cluename",
  1270. "change_type": "基本信息变更",
  1271. "old_value": common.If(old_cluename != "", old_cluename, "/"),
  1272. "new_value": common.If(cluename != "", cluename, "/"),
  1273. "createtime": nowTime,
  1274. "BCPCID": BCPCID,
  1275. "operator_id": -1,
  1276. })
  1277. }
  1278. }
  1279. if old_top_cluetype != top_cluetype {
  1280. updateId12 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  1281. "clue_id": clueId,
  1282. "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"])))),
  1283. "change_field": "top_cluetype",
  1284. "change_type": "基本信息变更",
  1285. "old_value": common.If(old_topname != "", old_topname, "/"),
  1286. "new_value": common.If(topname != "", topname, "/"),
  1287. "createtime": nowTime,
  1288. "BCPCID": BCPCID,
  1289. "operator_id": -1,
  1290. })
  1291. }
  1292. 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"]))))))
  1293. if old_sub_cluetype != sub_cluetype {
  1294. updateId13 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  1295. "clue_id": clueId,
  1296. "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"]))))),
  1297. "change_field": "sub_cluetype", //333
  1298. "change_type": "基本信息变更",
  1299. "old_value": common.If(old_subname != "", old_subname, "/"),
  1300. "new_value": common.If(subname != "", subname, "/"),
  1301. "createtime": nowTime,
  1302. "BCPCID": BCPCID,
  1303. "operator_id": -1,
  1304. })
  1305. //标签处理
  1306. if old_position_id != positionId && newPositionId > 0 {
  1307. LabelHandel(tx, label, 1, uId, level, trailstatus, gconv.String(clueUpdateData["trailstatus"]), 0)
  1308. } else {
  1309. LabelHandel(tx, label, 2, uId, level, trailstatus, gconv.String(clueUpdateData["trailstatus"]), 0)
  1310. }
  1311. } else {
  1312. if old_position_id != positionId && newPositionId > 0 {
  1313. LabelHandel(tx, label, 1, uId, level, trailstatus, gconv.String(clueUpdateData["trailstatus"]), 0)
  1314. }
  1315. }
  1316. 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
  1317. }) {
  1318. log.Println("线索更新成功")
  1319. if TiDb.Count("dwd_f_userbase_contacts", map[string]interface{}{"phone": phone}) == 0 {
  1320. TiDb.Insert("dwd_f_userbase_contacts", map[string]interface{}{
  1321. "status": 1,
  1322. "is_delete": 1,
  1323. "createtime": nowTime,
  1324. "updatetime": nowTime,
  1325. "phone": phone,
  1326. "baseinfo_id": uId,
  1327. "SOURCE": source,
  1328. })
  1329. }
  1330. if old_position_id == 0 {
  1331. TiDb.UpdateOrDeleteBySql(`update dwd_f_crm_clue_autodraw_record set count = count + 1 where position_id = ? and clue_level = ?`, positionId, level)
  1332. }
  1333. return true
  1334. } else {
  1335. log.Println("线索更新失败!!!", ok, updateId1, updateId2, updateId3, updateId4, updateId5, updateId6, updateId7, updateId8, updateId9, updateId10, updateId11, updateId12, updateId13, updateId14, " 用户信息 ", item, position, seatNumber, uId, userId, phone)
  1336. return false
  1337. }
  1338. }
  1339. 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 {
  1340. 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)
  1341. name = strings.ReplaceAll(name, " ", "")
  1342. nowTime := time.Now().Format("2006-01-02 15:04:05")
  1343. nowTimes := time.Unix(time.Now().Unix()+3600*12, 0).Format("2006-01-02 15:04:05")
  1344. trailstatus := gconv.String(data["trailstatus"]) //data都为原线索数据
  1345. trailstatusTime := gconv.String(data["trailstatus_time"])
  1346. var trailstatusTimes time.Time
  1347. if trailstatusTime != "" {
  1348. trailstatusTimes, _ = time.ParseInLocation(date.Date_Full_Layout, trailstatusTime, time.Local)
  1349. }
  1350. clueId := common.Int64All(data["id"])
  1351. is_assign := common.IntAll(data["is_assign"])
  1352. oldsaleName, oldTaskTime, taskTime, is_task, taskstatus := "", "", "", 0, 0
  1353. old_position_id, old_seatNumber := common.Int64All(data["position_id"]), gconv.String(data["seatNumber"])
  1354. oldTaskTime = gconv.String(data["tasktime"])
  1355. is_task = common.IntAll(data["is_task"])
  1356. taskstatus = common.IntAll(data["taskstatus"])
  1357. BCPCID := common.GetRandom(32)
  1358. old_name := gconv.String(data["name"])
  1359. old_position := gconv.String(data["position"])
  1360. old_department := gconv.String(data["department"])
  1361. old_follow_project_area := gconv.String(data["follow_project_area"])
  1362. old_role := gconv.String(data["role"])
  1363. old_cluename := gconv.String(data["cluename"])
  1364. old_top_cluetype := gconv.String(data["top_cluetype"])
  1365. old_sub_cluetype := gconv.String(data["sub_cluetype"])
  1366. old_topname, old_subname := "", ""
  1367. is_transfer := common.IntAll(data["is_transfer"])
  1368. oldLabelChangeTime := gconv.String(data["labelChangeTime"])
  1369. label := gconv.Int64(data["label"])
  1370. e_label := gconv.String(data["e_label"])
  1371. Ehandle(clueId, uId, userId, cluename, trailstatus, e_label)
  1372. if taskstatus == 1 || is_task == 0 {
  1373. taskTime = gconv.String(common.If(item != "users", nowTime, nowTimes)) //任务时间,正常的是当前时间,新用户是当前时间+12个小时
  1374. } else {
  1375. if is_task == 1 {
  1376. if oldTaskTime != "" { //以最新的任务时间为主
  1377. t1, err := time.Parse("2006-01-02 15:04:05", oldTaskTime)
  1378. if err == nil && time.Now().Before(t1) {
  1379. taskTime = nowTime
  1380. } else {
  1381. taskTime = oldTaskTime
  1382. }
  1383. }
  1384. }
  1385. }
  1386. count, counts, t := 0, 0, time.Now() //加入任务车判断节假日
  1387. for {
  1388. count++
  1389. currentTime := t.AddDate(0, 0, -count)
  1390. if currentTime.Weekday() == time.Sunday || currentTime.Weekday() == time.Saturday {
  1391. isok := false
  1392. for k, v := range DateMap {
  1393. if currentTime.Format(date.Date_Short_Layout) == k && v == 2 {
  1394. isok = true
  1395. }
  1396. }
  1397. if isok {
  1398. counts++
  1399. }
  1400. } else {
  1401. isok := true
  1402. for k, v := range DateMap {
  1403. if currentTime.Format(date.Date_Short_Layout) == k && v == 1 {
  1404. isok = false
  1405. }
  1406. }
  1407. if isok {
  1408. counts++
  1409. }
  1410. }
  1411. if counts >= 2 {
  1412. break
  1413. }
  1414. }
  1415. //两天之前不包含节假日,有没有跟进记录
  1416. 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))
  1417. //
  1418. clueUpdateData := map[string]interface{}{
  1419. "updatetime": nowTime,
  1420. "top_cluetype": top_cluetype,
  1421. "sub_cluetype": sub_cluetype,
  1422. "userid": userId,
  1423. "comeinsource_private": 2,
  1424. "tasksource": "线索来源自动更新" + "-" + topname + "-" + subname,
  1425. "company_nature": isGroup,
  1426. "company_verification": isCommerce,
  1427. }
  1428. old_remark := gconv.String(data["remark"])
  1429. if old_remark != "" {
  1430. remark = old_remark + ";" + remark //备注不能替换,只能往上拼接
  1431. }
  1432. clueUpdateData["remark"] = remark
  1433. if cluename != "" {
  1434. clueUpdateData["cluename"] = cluename //新的线索名不为空才替换
  1435. }
  1436. if item != "orders" && item != "users" { //新用户和订单之外的替换一下新的留资信息
  1437. if name != "" {
  1438. clueUpdateData["name"] = name
  1439. }
  1440. if position != "" {
  1441. clueUpdateData["position"] = position
  1442. }
  1443. if department != "" {
  1444. clueUpdateData["department"] = department
  1445. }
  1446. if follow_project_area != "" {
  1447. clueUpdateData["follow_project_area"] = follow_project_area
  1448. }
  1449. if role != "" {
  1450. clueUpdateData["role"] = role
  1451. }
  1452. // clueUpdateData["industry"] = industry
  1453. }
  1454. if sourceCode == "app_xzcyh" { //这个留资单独处理一下
  1455. if departments != "" {
  1456. clueUpdateData["department"] = departments
  1457. department = departments
  1458. }
  1459. business_scope := gconv.String(data["business_scope"])
  1460. keywords := ""
  1461. if len(keyword) > 0 && keyword[0] != "" {
  1462. keywords = strings.Join(keyword, ",")
  1463. if business_scope != "" {
  1464. clueUpdateData["business_scope"] = business_scope + "," + keywords
  1465. } else {
  1466. clueUpdateData["business_scope"] = keywords
  1467. }
  1468. }
  1469. }
  1470. //只更新线索不更新人员信息
  1471. if is_assign != 1 && is_assign != 0 && is_assign != -1 {
  1472. clueUpdateData["comeintime"] = nowTime
  1473. clueMapEntity := ClueMapEntity{
  1474. UId: uId,
  1475. OldTopCluetype: old_top_cluetype,
  1476. OldSubCluetype: old_sub_cluetype,
  1477. NewTopCluetype: top_cluetype,
  1478. NewSubCluetype: sub_cluetype,
  1479. Item: item,
  1480. OldName: old_name,
  1481. NewName: name,
  1482. ClueUpdateData: clueUpdateData,
  1483. ClueId: clueId,
  1484. OldPosition: old_position,
  1485. NewPosition: position,
  1486. OldDepartment: old_department,
  1487. NewDepartment: department,
  1488. OldRole: old_role,
  1489. NewRole: role,
  1490. OldFollowProjectArea: old_follow_project_area,
  1491. NewFollowProjectArea: follow_project_area,
  1492. NewCluename: cluename,
  1493. OldCluename: old_cluename,
  1494. Subname: subname,
  1495. Topname: topname,
  1496. Phone: phone,
  1497. Source: source,
  1498. PositionId: old_position_id,
  1499. Level: level,
  1500. LabelChangeTime: oldLabelChangeTime,
  1501. Label: label,
  1502. }
  1503. return clueInfoUpdate(clueMapEntity)
  1504. }
  1505. if trailstatus == "00" || trailstatus == "09" || old_position_id == 0 || is_assign != 1 || (pIsOk && old_cluename != cluename && cluename != "") {
  1506. if trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400 {
  1507. //无意向几天以内不参与分配
  1508. } else if trailstatus == "09" && (topname != "付费产品落地页主动留资" && topname != "受理系统") {
  1509. //线索状态为“拒绝沟通客户”,则仅针对线索来源一级分类为“付费产品落地页主动留资”和“受理系统”产生的线索进行线索分配,其他类线上线索只做线索更新但不再自动分配。
  1510. positionId = 0
  1511. seatNumber = ""
  1512. } else {
  1513. clueUpdateData["seatNumber"] = seatNumber
  1514. clueUpdateData["position_id"] = positionId
  1515. clueUpdateData["comeintime"] = nowTime
  1516. clueUpdateData["is_assign"] = 1
  1517. clueUpdateData["is_assign"] = 1
  1518. clueUpdateData["comeinsource_open"] = nil
  1519. clueUpdateData["level_open"] = nil
  1520. clueUpdateData["clue_level"] = nil
  1521. for _, v := range saleData {
  1522. if common.Int64All(data["position_id"]) == common.Int64All(v["position_id"]) {
  1523. oldsaleName = gconv.String(v["name"])
  1524. }
  1525. }
  1526. }
  1527. } else { //不属于上边情况就还是属于原来的销售,不更换销售
  1528. clueUpdateData["seatNumber"] = old_seatNumber
  1529. clueUpdateData["position_id"] = old_position_id
  1530. //clueUpdateData["is_assign"] = 1
  1531. clueUpdateData["comeinsource_open"] = nil
  1532. clueUpdateData["level_open"] = nil
  1533. clueUpdateData["clue_level"] = nil
  1534. }
  1535. if is_assign == 0 { //在公海的成交客户
  1536. if trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400 {
  1537. } else if trailstatus == "09" && (topname != "付费产品落地页主动留资" && topname != "受理系统") {
  1538. //线索状态为“拒绝沟通客户”,则仅针对线索来源一级分类为“付费产品落地页主动留资”和“受理系统”产生的线索进行线索分配,其他类线上线索只做线索更新但不再自动分配。
  1539. positionId = 0
  1540. seatNumber = ""
  1541. } else {
  1542. clueUpdateData["trailstatus"] = "01"
  1543. clueUpdateData["trailstatus_time"] = nowTime
  1544. }
  1545. }
  1546. if trailstatus == "02" { //在公海的成交客户
  1547. clueUpdateData["trailstatus"] = "01"
  1548. clueUpdateData["trailstatus_time"] = nowTime
  1549. }
  1550. is_ok := false
  1551. if recordCount <= 0 || is_assign == 0 {
  1552. if trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400 {
  1553. } else if trailstatus == "09" && (topname != "付费产品落地页主动留资" && topname != "受理系统") {
  1554. //线索状态为“拒绝沟通客户”,则仅针对线索来源一级分类为“付费产品落地页主动留资”和“受理系统”产生的线索进行线索分配,其他类线上线索只做线索更新但不再自动分配。
  1555. positionId = 0
  1556. seatNumber = ""
  1557. } else {
  1558. if item == "eventReg" {
  1559. eData := TiDb.Find("dwd_f_crm_clue_change_record", map[string]interface{}{"clue_id": clueId, "change_type": "加入任务车"}, "", "", -1, -1)
  1560. if eData != nil && len(*eData) > 0 {
  1561. for _, e := range *eData {
  1562. new_value := gconv.String(e["new_value"])
  1563. if strings.Contains(new_value, subname) {
  1564. is_ok = true
  1565. }
  1566. }
  1567. }
  1568. if !is_ok {
  1569. if old_sub_cluetype != sub_cluetype || is_assign == 0 {
  1570. if taskTime == "" {
  1571. taskTime = nowTime
  1572. }
  1573. clueUpdateData["task_time"] = nowTime
  1574. clueUpdateData["tasktime"] = taskTime
  1575. clueUpdateData["taskstatus"] = 0
  1576. }
  1577. if is_transfer != 1 {
  1578. clueUpdateData["is_task"] = 1
  1579. }
  1580. }
  1581. } else {
  1582. if old_sub_cluetype != sub_cluetype || is_assign == 0 {
  1583. if taskTime == "" {
  1584. taskTime = nowTime
  1585. }
  1586. clueUpdateData["task_time"] = nowTime
  1587. clueUpdateData["tasktime"] = taskTime
  1588. clueUpdateData["taskstatus"] = 0
  1589. }
  1590. if is_transfer != 1 {
  1591. clueUpdateData["is_task"] = 1
  1592. }
  1593. }
  1594. }
  1595. }
  1596. ok, updateId14 := true, true
  1597. updateId1, updateId2, updateId3, updateId4, updateId5 := int64(0), int64(0), int64(0), int64(0), int64(0)
  1598. updateId6, updateId7, updateId8, updateId9, updateId10 := int64(0), int64(0), int64(0), int64(0), int64(0)
  1599. updateId11, updateId12, updateId13 := int64(0), int64(0), int64(0)
  1600. if TiDb.ExecTx("更新线索", func(tx *sql.Tx) bool {
  1601. //线索
  1602. ok = TiDb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, clueUpdateData)
  1603. //变更记录
  1604. if (trailstatus == "00" || old_position_id == 0 || (pIsOk && old_cluename != cluename && cluename != "")) && is_assign == 1 {
  1605. if trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400 {
  1606. } else if trailstatus == "09" && (topname != "付费产品落地页主动留资" && topname != "受理系统") {
  1607. positionId = 0
  1608. seatNumber = ""
  1609. } else if old_position_id == 0 {
  1610. updateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  1611. "clue_id": clueId,
  1612. "position_id": positionId,
  1613. "change_field": "position_id",
  1614. "change_type": "所属人变更",
  1615. "old_value": common.If(oldsaleName != "", oldsaleName, "/"),
  1616. "new_value": common.If(saleName != "", saleName, "/"),
  1617. "createtime": nowTime,
  1618. "BCPCID": common.GetRandom(32),
  1619. "operator_id": -1,
  1620. })
  1621. updateId3 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  1622. "clue_id": clueId,
  1623. "position_id": positionId,
  1624. "change_field": "trailstatus",
  1625. "change_type": "基本信息变更",
  1626. "old_value": CodeTrail[trailstatus],
  1627. "new_value": "新增",
  1628. "createtime": nowTime,
  1629. "BCPCID": common.GetRandom(32),
  1630. "operator_id": -1,
  1631. })
  1632. } else {
  1633. if pIsOk && old_cluename != cluename && cluename != "" {
  1634. updateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  1635. "clue_id": clueId,
  1636. "position_id": positionId,
  1637. "change_field": "position_id",
  1638. "change_type": "所属人变更",
  1639. "old_value": common.If(oldsaleName != "", oldsaleName, "/"),
  1640. "new_value": common.If(saleName != "", saleName, "/"),
  1641. "createtime": nowTime,
  1642. "BCPCID": common.GetRandom(32),
  1643. "operator_id": -1,
  1644. })
  1645. } else {
  1646. updateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  1647. "clue_id": clueId,
  1648. "position_id": positionId,
  1649. "change_field": "position_id",
  1650. "change_type": "所属人变更",
  1651. "old_value": common.If(oldsaleName != "", oldsaleName, "/"),
  1652. "new_value": common.If(saleName != "", saleName, "/"),
  1653. "createtime": nowTime,
  1654. "BCPCID": common.GetRandom(32),
  1655. "operator_id": -1,
  1656. })
  1657. updateId2 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  1658. "clue_id": clueId,
  1659. "position_id": common.Int64All(data["position_id"]),
  1660. "change_field": "trailstatus",
  1661. "change_type": "基本信息变更",
  1662. "old_value": "无意向客户",
  1663. "new_value": "流失",
  1664. "createtime": nowTime,
  1665. "BCPCID": common.GetRandom(32),
  1666. "operator_id": -1,
  1667. })
  1668. updateId3 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  1669. "clue_id": clueId,
  1670. "position_id": positionId,
  1671. "change_field": "trailstatus",
  1672. "change_type": "基本信息变更",
  1673. "old_value": "商机线索",
  1674. "new_value": "新增",
  1675. "createtime": nowTime,
  1676. "BCPCID": common.GetRandom(32),
  1677. "operator_id": -1,
  1678. })
  1679. updateId4 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  1680. "clue_id": clueId,
  1681. "position_id": positionId,
  1682. "change_field": "trailstatus",
  1683. "change_type": "基本信息变更",
  1684. "old_value": "无意向客户",
  1685. "new_value": "商机线索",
  1686. "createtime": nowTime,
  1687. "BCPCID": common.GetRandom(32),
  1688. "operator_id": -1,
  1689. })
  1690. }
  1691. }
  1692. } else if is_assign == 0 {
  1693. if trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400 {
  1694. } else if trailstatus == "09" && (topname != "付费产品落地页主动留资" && topname != "受理系统") {
  1695. positionId = 0
  1696. seatNumber = ""
  1697. } else {
  1698. updateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  1699. "clue_id": clueId,
  1700. "position_id": positionId,
  1701. "change_field": "position_id",
  1702. "change_type": "所属人变更",
  1703. "old_value": common.If(oldsaleName != "", oldsaleName, "/"),
  1704. "new_value": common.If(saleName != "", saleName, "/"),
  1705. "createtime": nowTime,
  1706. "BCPCID": common.GetRandom(32),
  1707. "operator_id": -1,
  1708. })
  1709. if trailstatus != "01" {
  1710. updateId4 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  1711. "clue_id": clueId,
  1712. "position_id": positionId,
  1713. "change_field": "trailstatus",
  1714. "change_type": "基本信息变更",
  1715. "old_value": CodeTrail[trailstatus],
  1716. "new_value": "商机线索",
  1717. "createtime": nowTime,
  1718. "BCPCID": common.GetRandom(32),
  1719. "operator_id": -1,
  1720. })
  1721. }
  1722. updateId3 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  1723. "clue_id": clueId,
  1724. "position_id": positionId,
  1725. "change_field": "trailstatus",
  1726. "change_type": "基本信息变更",
  1727. "old_value": "商机线索",
  1728. "new_value": "新增",
  1729. "createtime": nowTime,
  1730. "BCPCID": common.GetRandom(32),
  1731. "operator_id": -1,
  1732. })
  1733. }
  1734. } else if is_assign == -1 {
  1735. updateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  1736. "clue_id": clueId,
  1737. "position_id": positionId,
  1738. "change_field": "position_id",
  1739. "change_type": "所属人变更",
  1740. "old_value": common.If(oldsaleName != "", oldsaleName, "/"),
  1741. "new_value": common.If(saleName != "", saleName, "/"),
  1742. "createtime": nowTime,
  1743. "BCPCID": common.GetRandom(32),
  1744. "operator_id": -1,
  1745. })
  1746. updateId4 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  1747. "clue_id": clueId,
  1748. "position_id": positionId,
  1749. "change_field": "trailstatus",
  1750. "change_type": "基本信息变更",
  1751. "old_value": CodeTrail[trailstatus],
  1752. "new_value": "商机线索",
  1753. "createtime": nowTime,
  1754. "BCPCID": common.GetRandom(32),
  1755. "operator_id": -1,
  1756. })
  1757. }
  1758. if recordCount <= 0 || is_assign == 0 {
  1759. if trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400 {
  1760. } else if trailstatus == "09" && (topname != "付费产品落地页主动留资" && topname != "受理系统") {
  1761. positionId = 0
  1762. seatNumber = ""
  1763. } else {
  1764. if is_transfer == 1 {
  1765. if old_sub_cluetype != sub_cluetype && !is_ok {
  1766. cdata := TiDb.FindOne("dwd_f_csm_customer_info", map[string]interface{}{"clue_id": clueId}, "", "")
  1767. if cdata != nil && len(*cdata) > 0 {
  1768. kcpositionId := common.Int64All((*cdata)["position_id"])
  1769. tasksource := gconv.String((*cdata)["tasksource"])
  1770. taskstatus := common.IntAll((*cdata)["taskstatus"])
  1771. updateId5 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  1772. "clue_id": clueId,
  1773. "position_id": kcpositionId,
  1774. "change_type": "加入任务车",
  1775. "new_value": "线上主动留资",
  1776. "createtime": nowTime,
  1777. "BCPCID": common.GetRandom(32),
  1778. "operator_id": -1,
  1779. })
  1780. if taskstatus == 1 {
  1781. tasksource = "10"
  1782. } else {
  1783. if tasksource != "" && !strings.Contains(tasksource, "10") {
  1784. if !strings.Contains(tasksource, "10") {
  1785. tasksource += ",10"
  1786. }
  1787. } else {
  1788. tasksource = "10"
  1789. }
  1790. }
  1791. updateId14 = TiDb.UpdateByTx(tx, "dwd_f_csm_customer_info", map[string]interface{}{"clue_id": clueId}, map[string]interface{}{
  1792. "tasksource": tasksource,
  1793. "tasktime": nowTime,
  1794. "is_task": 1,
  1795. "taskstatus": 0,
  1796. })
  1797. }
  1798. }
  1799. } else if !is_ok {
  1800. updateId5 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  1801. "clue_id": clueId,
  1802. "position_id": common.If(trailstatus == "00" || is_assign == 0 || is_assign == -1, positionId, common.Int64All(data["position_id"])),
  1803. "change_type": "加入任务车",
  1804. "new_value": gconv.String(common.If(gconv.Int64(data["position_id"]) == 0, "线索自动分配", "线索来源自动更新")) + "-" + topname + "-" + subname,
  1805. "createtime": nowTime,
  1806. "BCPCID": common.GetRandom(32),
  1807. "operator_id": -1,
  1808. })
  1809. }
  1810. }
  1811. }
  1812. if old_top_cluetype != "" {
  1813. pcodeData := TiDb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"code": old_top_cluetype}, "", "")
  1814. if pcodeData != nil && len(*pcodeData) > 0 {
  1815. old_topname = gconv.String((*pcodeData)["name"])
  1816. }
  1817. }
  1818. if old_sub_cluetype != "" {
  1819. pcodeData := TiDb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"code": old_sub_cluetype}, "", "")
  1820. if pcodeData != nil && len(*pcodeData) > 0 {
  1821. old_subname = gconv.String((*pcodeData)["name"])
  1822. }
  1823. }
  1824. if item != "orders" {
  1825. if old_name != name && name != "" {
  1826. updateId6 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  1827. "clue_id": clueId,
  1828. "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"]))),
  1829. "change_field": "name",
  1830. "change_type": "基本信息变更",
  1831. "old_value": common.If(old_name != "", old_name, "/"),
  1832. "new_value": common.If(name != "", name, "/"),
  1833. "createtime": nowTime,
  1834. "BCPCID": BCPCID,
  1835. "operator_id": -1,
  1836. })
  1837. }
  1838. if old_position != position && position != "" {
  1839. updateId7 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  1840. "clue_id": clueId,
  1841. "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"]))),
  1842. "change_field": "position",
  1843. "change_type": "基本信息变更",
  1844. "old_value": common.If(old_position != "", old_position, "/"),
  1845. "new_value": common.If(position != "", position, "/"),
  1846. "createtime": nowTime,
  1847. "BCPCID": BCPCID,
  1848. "operator_id": -1,
  1849. })
  1850. }
  1851. if old_department != department && department != "" {
  1852. updateId8 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  1853. "clue_id": clueId,
  1854. "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"]))),
  1855. "change_field": "department",
  1856. "change_type": "基本信息变更",
  1857. "old_value": common.If(old_department != "", old_department, "/"),
  1858. "new_value": common.If(department != "", department, "/"),
  1859. "createtime": nowTime,
  1860. "BCPCID": BCPCID,
  1861. "operator_id": -1,
  1862. })
  1863. }
  1864. if old_role != role && role != "" {
  1865. updateId9 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  1866. "clue_id": clueId,
  1867. "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"]))),
  1868. "change_field": "role",
  1869. "change_type": "基本信息变更",
  1870. "old_value": common.If(old_role != "", old_role, "/"),
  1871. "new_value": common.If(role != "", role, "/"),
  1872. "createtime": nowTime,
  1873. "BCPCID": BCPCID,
  1874. "operator_id": -1})
  1875. }
  1876. if old_follow_project_area != follow_project_area && follow_project_area != "" {
  1877. old_area, old_area_arr := "", []string{}
  1878. new_area, new_area_arr := "", []string{}
  1879. for _, v := range strings.Split(old_follow_project_area, ",") {
  1880. old_area_arr = append(old_area_arr, CodeArea[v])
  1881. }
  1882. for _, v := range strings.Split(follow_project_area, ",") {
  1883. new_area_arr = append(new_area_arr, CodeArea[v])
  1884. }
  1885. old_area = strings.Join(old_area_arr, ",")
  1886. new_area = strings.Join(new_area_arr, ",")
  1887. updateId10 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  1888. "clue_id": clueId,
  1889. "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"]))),
  1890. "change_field": "follow_project_area",
  1891. "change_type": "基本信息变更",
  1892. "old_value": common.If(old_area != "", old_area, "/"),
  1893. "new_value": common.If(new_area != "", new_area, "/"),
  1894. "createtime": nowTime,
  1895. "BCPCID": BCPCID,
  1896. "operator_id": -1,
  1897. })
  1898. }
  1899. if old_cluename != cluename && cluename != "" {
  1900. updateId11 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  1901. "clue_id": clueId,
  1902. "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"]))),
  1903. "change_field": "cluename",
  1904. "change_type": "基本信息变更",
  1905. "old_value": common.If(old_cluename != "", old_cluename, "/"),
  1906. "new_value": common.If(cluename != "", cluename, "/"),
  1907. "createtime": nowTime,
  1908. "BCPCID": BCPCID,
  1909. "operator_id": -1,
  1910. })
  1911. }
  1912. }
  1913. if old_top_cluetype != top_cluetype {
  1914. updateId12 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  1915. "clue_id": clueId,
  1916. "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"]))),
  1917. "change_field": "top_cluetype",
  1918. "change_type": "基本信息变更",
  1919. "old_value": common.If(old_topname != "", old_topname, "/"),
  1920. "new_value": common.If(topname != "", topname, "/"),
  1921. "createtime": nowTime,
  1922. "BCPCID": BCPCID,
  1923. "operator_id": -1,
  1924. })
  1925. }
  1926. 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"]))))
  1927. if old_sub_cluetype != sub_cluetype {
  1928. updateId13 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  1929. "clue_id": clueId,
  1930. "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"]))),
  1931. "change_field": "sub_cluetype", //444
  1932. "change_type": "基本信息变更",
  1933. "old_value": common.If(old_subname != "", old_subname, "/"),
  1934. "new_value": common.If(subname != "", subname, "/"),
  1935. "createtime": nowTime,
  1936. "BCPCID": BCPCID,
  1937. "operator_id": -1,
  1938. })
  1939. if old_position_id != newPositionId && newPositionId > 0 {
  1940. LabelHandel(tx, label, 1, uId, level, trailstatus, gconv.String(clueUpdateData["trailstatus"]), 0)
  1941. } else {
  1942. LabelHandel(tx, label, 2, uId, level, trailstatus, gconv.String(clueUpdateData["trailstatus"]), 0)
  1943. }
  1944. } else {
  1945. if old_position_id != newPositionId && newPositionId > 0 {
  1946. LabelHandel(tx, label, 1, uId, level, trailstatus, gconv.String(clueUpdateData["trailstatus"]), 0)
  1947. }
  1948. }
  1949. 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
  1950. }) {
  1951. log.Println("线索更新成功")
  1952. if TiDb.Count("dwd_f_userbase_contacts", map[string]interface{}{"phone": phone}) == 0 {
  1953. TiDb.Insert("dwd_f_userbase_contacts", map[string]interface{}{
  1954. "status": 1,
  1955. "is_delete": 1,
  1956. "createtime": nowTime,
  1957. "updatetime": nowTime,
  1958. "phone": phone,
  1959. "baseinfo_id": uId,
  1960. "SOURCE": source,
  1961. })
  1962. }
  1963. if old_position_id == 0 {
  1964. TiDb.UpdateOrDeleteBySql(`update dwd_f_crm_clue_autodraw_record set count = count + 1 where position_id = ? and clue_level = ?`, positionId, level)
  1965. }
  1966. return true
  1967. } else {
  1968. log.Println("线索更新失败!!!", ok, updateId1, updateId2, updateId3, updateId4, updateId5, updateId6, updateId7, updateId8, updateId9, updateId10, updateId11, updateId12, updateId13, updateId14, " 用户信息 ", item, position, seatNumber, uId, userId, phone)
  1969. return false
  1970. }
  1971. }
  1972. type ClueMapEntity struct {
  1973. UId string
  1974. OldTopCluetype string
  1975. OldSubCluetype string
  1976. NewTopCluetype string
  1977. NewSubCluetype string
  1978. Item string
  1979. OldName string
  1980. NewName string
  1981. ClueUpdateData map[string]interface{}
  1982. ClueId int64
  1983. Trailstatus string
  1984. OldPosition string
  1985. NewPosition string
  1986. OldDepartment string
  1987. NewDepartment string
  1988. OldRole string
  1989. NewRole string
  1990. OldFollowProjectArea string
  1991. NewFollowProjectArea string
  1992. NewCluename string
  1993. OldCluename string
  1994. Subname string
  1995. Topname string
  1996. Phone string
  1997. Source string
  1998. PositionId int64
  1999. Label int64
  2000. LabelChangeTime string
  2001. Level string
  2002. }
  2003. // 基本信息变更
  2004. func clueInfoUpdate(data ClueMapEntity) bool {
  2005. ok := false
  2006. updateId1, updateId2, updateId3, updateId4, updateId5 := int64(0), int64(0), int64(0), int64(0), int64(0)
  2007. updateId6, updateId7, updateId8, updateId9, updateId10 := int64(0), int64(0), int64(0), int64(0), int64(0)
  2008. updateId11, updateId12, updateId13 := int64(0), int64(0), int64(0)
  2009. nowTime := time.Now().Format("2006-01-02 15:04:05")
  2010. if TiDb.ExecTx("更新线索", func(tx *sql.Tx) bool {
  2011. log.Println("修改线索", data)
  2012. BCPCID := common.GetRandom(32)
  2013. old_topname, old_subname := "", ""
  2014. //线索
  2015. ok = TiDb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"uid": data.UId}, data.ClueUpdateData)
  2016. //变更记录
  2017. if data.OldTopCluetype != "" {
  2018. pcodeData := TiDb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"code": data.OldTopCluetype}, "", "")
  2019. if pcodeData != nil && len(*pcodeData) > 0 {
  2020. old_topname = gconv.String((*pcodeData)["name"])
  2021. }
  2022. }
  2023. if data.OldSubCluetype != "" {
  2024. pcodeData := TiDb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"code": data.OldSubCluetype}, "", "")
  2025. if pcodeData != nil && len(*pcodeData) > 0 {
  2026. old_subname = gconv.String((*pcodeData)["name"])
  2027. }
  2028. }
  2029. if data.Item != "orders" {
  2030. if data.OldName != data.NewName && data.NewName != "" {
  2031. updateId6 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  2032. "clue_id": data.ClueId,
  2033. "position_id": data.PositionId,
  2034. "change_field": "name",
  2035. "change_type": "基本信息变更",
  2036. "old_value": common.If(data.OldName != "", data.OldName, "/"),
  2037. "new_value": common.If(data.NewName != "", data.NewName, "/"),
  2038. "createtime": nowTime,
  2039. "BCPCID": BCPCID,
  2040. "operator_id": -1,
  2041. })
  2042. }
  2043. if data.OldPosition != data.NewPosition && data.NewPosition != "" {
  2044. updateId7 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  2045. "clue_id": data.ClueId,
  2046. "position_id": data.PositionId,
  2047. "change_field": "position",
  2048. "change_type": "基本信息变更",
  2049. "old_value": common.If(data.OldPosition != "", data.OldPosition, "/"),
  2050. "new_value": common.If(data.NewPosition != "", data.NewPosition, "/"),
  2051. "createtime": nowTime,
  2052. "BCPCID": BCPCID,
  2053. "operator_id": -1,
  2054. })
  2055. }
  2056. if data.OldDepartment != data.NewDepartment && data.NewDepartment != "" {
  2057. updateId8 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  2058. "clue_id": data.ClueId,
  2059. "position_id": data.PositionId,
  2060. "change_field": "department",
  2061. "change_type": "基本信息变更",
  2062. "old_value": common.If(data.OldDepartment != "", data.OldDepartment, "/"),
  2063. "new_value": common.If(data.NewDepartment != "", data.NewDepartment, "/"),
  2064. "createtime": nowTime,
  2065. "BCPCID": BCPCID,
  2066. "operator_id": -1,
  2067. })
  2068. }
  2069. if data.OldRole != data.NewRole && data.NewRole != "" {
  2070. updateId9 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  2071. "clue_id": data.ClueId,
  2072. "position_id": data.PositionId,
  2073. "change_field": "role",
  2074. "change_type": "基本信息变更",
  2075. "old_value": common.If(data.OldRole != "", data.OldRole, "/"),
  2076. "new_value": common.If(data.NewRole != "", data.NewRole, "/"),
  2077. "createtime": nowTime,
  2078. "BCPCID": BCPCID,
  2079. "operator_id": -1})
  2080. }
  2081. if data.OldFollowProjectArea != data.NewFollowProjectArea && data.NewFollowProjectArea != "" {
  2082. old_area, old_area_arr := "", []string{}
  2083. new_area, new_area_arr := "", []string{}
  2084. for _, v := range strings.Split(data.OldFollowProjectArea, ",") {
  2085. old_area_arr = append(old_area_arr, CodeArea[v])
  2086. }
  2087. for _, v := range strings.Split(data.NewFollowProjectArea, ",") {
  2088. new_area_arr = append(new_area_arr, CodeArea[v])
  2089. }
  2090. old_area = strings.Join(old_area_arr, ",")
  2091. new_area = strings.Join(new_area_arr, ",")
  2092. updateId10 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  2093. "clue_id": data.ClueId,
  2094. "position_id": data.PositionId,
  2095. "change_field": "follow_project_area",
  2096. "change_type": "基本信息变更",
  2097. "old_value": common.If(old_area != "", old_area, "/"),
  2098. "new_value": common.If(new_area != "", new_area, "/"),
  2099. "createtime": nowTime,
  2100. "BCPCID": BCPCID,
  2101. "operator_id": -1,
  2102. })
  2103. }
  2104. if data.OldCluename != data.NewCluename && data.NewCluename != "" {
  2105. updateId11 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  2106. "clue_id": data.ClueId,
  2107. "position_id": data.PositionId,
  2108. "change_field": "cluename",
  2109. "change_type": "基本信息变更",
  2110. "old_value": common.If(data.OldCluename != "", data.OldCluename, "/"),
  2111. "new_value": common.If(data.NewCluename != "", data.NewCluename, "/"),
  2112. "createtime": nowTime,
  2113. "BCPCID": BCPCID,
  2114. "operator_id": -1,
  2115. })
  2116. }
  2117. }
  2118. if data.OldTopCluetype != data.NewTopCluetype {
  2119. updateId12 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  2120. "clue_id": data.ClueId,
  2121. "position_id": data.PositionId,
  2122. "change_field": "top_cluetype",
  2123. "change_type": "基本信息变更",
  2124. "old_value": common.If(old_topname != "", old_topname, "/"),
  2125. "new_value": common.If(data.Topname != "", data.Topname, "/"),
  2126. "createtime": nowTime,
  2127. "BCPCID": BCPCID,
  2128. "operator_id": -1,
  2129. })
  2130. }
  2131. if data.OldSubCluetype != data.OldSubCluetype {
  2132. updateId13 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
  2133. "clue_id": data.ClueId,
  2134. "position_id": data.PositionId,
  2135. "change_field": "sub_cluetype", //555
  2136. "change_type": "基本信息变更",
  2137. "old_value": common.If(old_subname != "", old_subname, "/"),
  2138. "new_value": common.If(data.Subname != "", data.Subname, "/"),
  2139. "createtime": nowTime,
  2140. "BCPCID": BCPCID,
  2141. "operator_id": -1,
  2142. })
  2143. LabelHandel(tx, data.Label, 1, data.UId, data.Level, data.Trailstatus, data.Trailstatus, 0)
  2144. }
  2145. 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
  2146. }) {
  2147. log.Println("线索更新成功")
  2148. if TiDb.Count("dwd_f_userbase_contacts", map[string]interface{}{"phone": data.Phone}) == 0 {
  2149. TiDb.Insert("dwd_f_userbase_contacts", map[string]interface{}{
  2150. "status": 1,
  2151. "is_delete": 1,
  2152. "createtime": nowTime,
  2153. "updatetime": nowTime,
  2154. "phone": data.Phone,
  2155. "baseinfo_id": data.UId,
  2156. "SOURCE": data.Source,
  2157. })
  2158. }
  2159. return true
  2160. } else {
  2161. log.Println("线索更新失败!!!", ok, updateId1, updateId2, updateId3, updateId4, updateId5, updateId6, updateId7, updateId8, updateId9, updateId10, updateId11, updateId12, updateId13)
  2162. return false
  2163. }
  2164. }
  2165. // 线索标签修改 label labelChangeTime
  2166. func LabelHandel(tx *sql.Tx, oldlabelType, labelType int64, uId, level, oldTrailstatusCode, trailstatusCode string, status int64) {
  2167. log.Println("线索标签修改:", "oldlabelType:", oldlabelType, "labelType:", labelType, "uId:", uId, "level:", level, "oldTrailstatusCode:", oldTrailstatusCode, "trailstatusCode:", trailstatusCode, "status:", status)
  2168. //先查询以前什么类型
  2169. if trailstatusCode != "01" && oldTrailstatusCode != "01" {
  2170. log.Println("不属于商机类型", uId)
  2171. return
  2172. }
  2173. if status != 0 {
  2174. log.Println("不属于未完成", uId)
  2175. return
  2176. }
  2177. updateLabelType := int64(0)
  2178. nowStr := time.Now().Format("2006-01-02")
  2179. if labelType == 1 {
  2180. //直接更新
  2181. if oldlabelType != 1 {
  2182. updateLabelType = labelType
  2183. }
  2184. } else if labelType == 2 {
  2185. if level != "A" && level != "B" && level != "C" {
  2186. return
  2187. }
  2188. //查询以前是什么数据
  2189. //同一天修改过
  2190. if oldlabelType != 1 {
  2191. updateLabelType = labelType
  2192. }
  2193. }
  2194. if updateLabelType > 0 {
  2195. ok := false
  2196. if tx == nil {
  2197. ok = TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{
  2198. "uid": uId,
  2199. }, map[string]interface{}{
  2200. "label": updateLabelType,
  2201. "labelChangeTime": nowStr,
  2202. })
  2203. } else {
  2204. ok = TiDb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{
  2205. "uid": uId,
  2206. }, map[string]interface{}{
  2207. "label": updateLabelType,
  2208. "labelChangeTime": nowStr,
  2209. })
  2210. }
  2211. log.Println("线索标签修改", ok)
  2212. }
  2213. }
  2214. func Ehandle(clueId int64, uid, userId, clueName, trailstatus, e_label string) {
  2215. if e_label != "" {
  2216. return
  2217. }
  2218. // 最近访问时间:最近1天内
  2219. beforeTime := time.Now().AddDate(0, 0, -1).Format("2006-01-02 15:04:05")
  2220. if TiDb.CountBySql("select count(1) as count from dwd_f_userbase_visit_info where userid=? and date>=? and number>0 ", userId, beforeTime) <= 0 {
  2221. return
  2222. }
  2223. // 最近接通时间:近20天内未被接通
  2224. if TiDb.CountBySql("select count(1) as count from dwd_f_crm_attribute_label where uid=? and noanswer_count>0 ", uid) > 0 {
  2225. return
  2226. }
  2227. // 排除条件:空号停机、拒绝沟通客户
  2228. if trailstatus == "02" || trailstatus == "09" {
  2229. return
  2230. }
  2231. // 线索名称:有企业名称的
  2232. if ValidatePhone(clueName) {
  2233. return
  2234. }
  2235. TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{
  2236. "id": clueId,
  2237. }, map[string]interface{}{
  2238. "e_label": "E001",
  2239. })
  2240. }
  2241. // 预编译正则表达式提升性能
  2242. var phoneRegex = regexp.MustCompile(`^1[3-9]\d{9}$`)
  2243. // ValidatePhone 验证手机号格式是否合法
  2244. func ValidatePhone(phone string) bool {
  2245. return phoneRegex.MatchString(phone)
  2246. }