everything.go 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087
  1. package main
  2. import (
  3. "app.yhyue.com/moapp/jybase/redis"
  4. "encoding/json"
  5. "fmt"
  6. "github.com/gogf/gf/util/gconv"
  7. "log"
  8. "net/url"
  9. "strings"
  10. "time"
  11. "app.yhyue.com/moapp/jybase/mail"
  12. "github.com/tealeg/xlsx"
  13. "app.yhyue.com/moapp/jybase/date"
  14. dates "app.yhyue.com/moapp/jybase/date"
  15. "app.yhyue.com/moapp/jybase/mongodb"
  16. "app.yhyue.com/moapp/jybase/common"
  17. )
  18. func everythingSync() {
  19. lastEverythingTime := cfg.LastEverythingTime
  20. nowTime := time.Now().Format(dates.Date_Full_Layout)
  21. sql := fmt.Sprintf(`select * from user_source where channel_code = "JyChCoopA" and create_time > "%s" order by create_time asc`, lastEverythingTime)
  22. log.Println("三方渠道数据定时任务开始", sql)
  23. data := ThirdParty.SelectBySql(sql)
  24. if data != nil && *data != nil && len(*data) > 0 {
  25. for _, v := range *data {
  26. user_id := common.ObjToString(v["user_id"])
  27. position_id := common.Int64All(v["position_id"])
  28. phone := common.ObjToString(v["phone"])
  29. state := common.IntAll(v["state"])
  30. user_mold, is_assign, is_transfer, last_login_time, registe_time, mailbox, source, clueId, order_type := 4, 0, 0, "", "", "", "", int64(0), ""
  31. owner, sales_lead_phone, sales_ent_name, sales_position, sales_dep, data_request, unique_id, belongTo, sales_leads_source := "", "", "", "", "", "", "", "", ""
  32. cData := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"phone": phone}, "", "")
  33. if cData != nil {
  34. is_assign = common.IntAll((*cData)["is_assign"])
  35. is_transfer = common.IntAll((*cData)["is_transfer"])
  36. clueId = common.Int64All((*cData)["id"])
  37. }
  38. //
  39. udata := TiDb.FindOne("dwd_f_userbase_baseinfo", map[string]interface{}{"userid": user_id}, "", "")
  40. if udata != nil {
  41. userSource := common.ObjToString((*udata)["source"])
  42. if userSource == "0102" {
  43. continue
  44. }
  45. }
  46. //
  47. /*cuData := TiDbData.FindOne("customer", map[string]interface{}{"phone": phone}, "", "")
  48. if cuData != nil {
  49. owner = common.ObjToString((*cuData)["owner"])
  50. unique_id = common.ObjToString((*cuData)["unique_id"])
  51. belongTo = common.ObjToString((*cuData)["belongTo"])
  52. }*/
  53. vData := TiDb.FindOne("dwd_f_userbase_visit_info", map[string]interface{}{"userid": user_id}, "", "")
  54. if vData != nil {
  55. last_login_time = common.ObjToString((*vData)["date"])
  56. }
  57. dData := Mysql.Find("dataexport_order", map[string]interface{}{"user_id": user_id}, "", "", -1, -1)
  58. if dData != nil && len(*dData) > 0 {
  59. pMap := map[string]string{}
  60. pArr := []string{}
  61. for _, v := range *dData {
  62. product_type := common.ObjToString(v["product_type"])
  63. pMap[product_type] = "1"
  64. }
  65. for k := range pMap {
  66. pArr = append(pArr, k)
  67. }
  68. if len(pArr) > 0 {
  69. order_type = strings.Join(pArr, ",")
  70. }
  71. }
  72. uData, ok := Mgo.FindOne("user", map[string]interface{}{"_id": mongodb.StringTOBsonId(user_id)})
  73. if ok && uData != nil {
  74. l_registedate := common.Int64All((*uData)["l_registedate"])
  75. registe_time = time.Unix(l_registedate, 0).Format(dates.Date_Full_Layout)
  76. }
  77. sData, oks := Mgo.Find("saleLeads", map[string]interface{}{"userid": user_id}, `{"_id":-1}`, nil, false, 0, 1)
  78. if oks && sData != nil {
  79. if len(*sData) > 0 {
  80. sDatas := (*sData)[0]
  81. sales_lead_phone = common.ObjToString(sDatas["phone"])
  82. sales_position = common.ObjToString(sDatas["position"])
  83. sales_ent_name = common.ObjToString(sDatas["company"])
  84. sales_dep = common.ObjToString(sDatas["branch"])
  85. if sales_dep == "" {
  86. sales_dep = common.ObjToString(sDatas["department"])
  87. }
  88. data_request = common.ObjToString(sDatas["data_requirement"])
  89. mailbox = common.ObjToString(sDatas["mail"])
  90. source = common.ObjToString(sDatas["interest"])
  91. }
  92. }
  93. if state == 1 {
  94. sales_leads_source = "一切都好登录"
  95. if is_assign == 1 || is_transfer == 1 || owner != "" {
  96. user_mold = 1
  97. } else {
  98. user_mold = 2
  99. }
  100. } else if state == 2 {
  101. sales_leads_source = "一切都好注册"
  102. if is_assign == 1 || is_transfer == 1 || owner != "" {
  103. user_mold = 3
  104. } else {
  105. user_mold = 4
  106. }
  107. }
  108. if owner == "" && unique_id != "" && belongTo == "市场部" {
  109. token := getToken()
  110. if token != "" {
  111. sss := url.QueryEscape("合作渠道一切都好")
  112. urls := `https://a1.7x24cc.com/commonInte?flag=1008&account=N000000029739&accessToken=` + token + `&cusObj={"unique_id":"` + unique_id + `","empNo":"8049","owner":"8049","source":"` + sss + `"}&dbType=0001`
  113. bs, err := doGet(urls)
  114. if err != nil {
  115. log.Println("调用接口失败", unique_id, err)
  116. }
  117. resMap := common.StringToMap(string(bs))
  118. if resMap["success"] != nil && resMap["success"].(bool) {
  119. /*ok := TiDbData.Update("customer", map[string]interface{}{"unique_id": unique_id}, map[string]interface{}{"empNo": "8049", "owner": "8049", "source": "合作渠道一切都好"})
  120. if ok {
  121. log.Println("更新成功", unique_id)
  122. } else {
  123. log.Println("更新失败", unique_id)
  124. }*/
  125. } else {
  126. log.Println("调用接口失败!!", unique_id)
  127. }
  128. }
  129. }
  130. if ThirdParty.Count("user_channel_info", map[string]interface{}{"user_id": user_id}) > 0 {
  131. ThirdParty.Update("user_channel_info", map[string]interface{}{"user_id": user_id}, map[string]interface{}{
  132. "user_mold": user_mold,
  133. "last_login_time": common.If(last_login_time != "", last_login_time, nil),
  134. "sales_lead_phone": sales_lead_phone,
  135. "sales_ent_name": sales_ent_name,
  136. "sales_position": sales_position,
  137. "sales_dep": sales_dep,
  138. "sales_leads_source": sales_leads_source,
  139. "mailbox": mailbox,
  140. "order_type": order_type,
  141. "data_request": data_request,
  142. "source": source,
  143. "update_time": nowTime,
  144. })
  145. } else {
  146. ThirdParty.Insert("user_channel_info", map[string]interface{}{
  147. "user_id": user_id,
  148. "registe_time": registe_time,
  149. "phone": phone,
  150. "user_mold": user_mold,
  151. "last_login_time": common.If(last_login_time != "", last_login_time, nil),
  152. "sales_lead_phone": sales_lead_phone,
  153. "sales_ent_name": sales_ent_name,
  154. "sales_position": sales_position,
  155. "sales_dep": sales_dep,
  156. "sales_leads_source": sales_leads_source,
  157. "order_type": order_type,
  158. "mailbox": mailbox,
  159. "data_request": data_request,
  160. "source": source,
  161. "update_time": nowTime,
  162. })
  163. }
  164. if clueId > 0 && is_assign != 1 && is_transfer != 1 {
  165. TiDb.Update("dwd_f_userbase_baseinfo", map[string]interface{}{"userid": user_id}, map[string]interface{}{"belong_to": "0301"})
  166. TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"phone": phone}, map[string]interface{}{"is_assign": -1})
  167. TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  168. "clue_id": clueId,
  169. "position_id": common.If(position_id > 0, position_id, -1),
  170. "change_type": "退出公海",
  171. "new_value": "通过合作渠道一切就好" + fmt.Sprint(common.If(user_mold == 1 || user_mold == 2, "登录", "注册")),
  172. "createtime": nowTime,
  173. "BCPCID": common.GetRandom(32),
  174. "operator_id": -1,
  175. })
  176. }
  177. }
  178. cfg.LastEverythingTime = common.ObjToString((*data)[len(*data)-1]["create_time"])
  179. }
  180. common.WriteSysConfig(&cfg)
  181. log.Println("三方渠道数据定时任务结束")
  182. }
  183. func saveEverything(user_id, phone, item, sourceName, sourceCode string) bool {
  184. nowTime, isOk := time.Now().Format(dates.Date_Full_Layout), false
  185. user_mold, is_assign, is_transfer, last_login_time, registe_time, mailbox, source, order_type, sales_leads_source := 4, 0, 0, "", "", "", "", "", ""
  186. owner, sales_lead_phone, sales_ent_name, sales_position, sales_dep, data_request, unique_id, belongTo, clueId, position_id := "", "", "", "", "", "", "", "", int64(0), int64(0)
  187. cData := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"phone": phone}, "", "")
  188. if cData != nil {
  189. is_assign = common.IntAll((*cData)["is_assign"])
  190. is_transfer = common.IntAll((*cData)["is_transfer"])
  191. clueId = common.Int64All((*cData)["is_transfer"])
  192. position_id = common.Int64All((*cData)["position_id"])
  193. }
  194. /*cuData := TiDbData.FindOne("customer", map[string]interface{}{"phone": phone}, "", "")
  195. if cuData != nil {
  196. unique_id = common.ObjToString((*cuData)["unique_id"])
  197. owner = common.ObjToString((*cuData)["owner"])
  198. }*/
  199. dData := Mysql.Find("dataexport_order", map[string]interface{}{"user_id": user_id}, "", "", -1, -1)
  200. if dData != nil && len(*dData) > 0 {
  201. pMap := map[string]string{}
  202. pArr := []string{}
  203. for _, v := range *dData {
  204. product_type := common.ObjToString(v["product_type"])
  205. pMap[product_type] = "1"
  206. }
  207. for k := range pMap {
  208. pArr = append(pArr, k)
  209. }
  210. if len(pArr) > 0 {
  211. order_type = strings.Join(pArr, ",")
  212. }
  213. }
  214. vData := TiDb.FindOne("dwd_f_userbase_visit_info", map[string]interface{}{"userid": user_id}, "", "")
  215. if vData != nil {
  216. last_login_time = common.ObjToString((*vData)["date"])
  217. }
  218. uData, ok := Mgo.FindOne("user", map[string]interface{}{"_id": mongodb.StringTOBsonId(user_id)})
  219. if ok && uData != nil {
  220. l_registedate := common.Int64All((*uData)["l_registedate"])
  221. registe_time = time.Unix(l_registedate, 0).Format(dates.Date_Full_Layout)
  222. }
  223. if item == "orders" {
  224. sales_leads_source = "订单未支付"
  225. } else if item == "users" || item == "xcxusers" {
  226. return false
  227. } else if item == "saleLeads" {
  228. sales_leads_source = sourceName
  229. } else {
  230. sales_leads_source = "用户留资"
  231. }
  232. query := map[string]interface{}{"userid": user_id}
  233. if sourceCode != "" {
  234. query["source"] = sourceCode
  235. }
  236. sData, oks := Mgo.Find("saleLeads", query, `{"_id":-1}`, nil, false, 0, 1)
  237. if oks && sData != nil {
  238. if len(*sData) > 0 {
  239. sDatas := (*sData)[0]
  240. sales_lead_phone = common.ObjToString(sDatas["phone"])
  241. sales_position = common.ObjToString(sDatas["position"])
  242. sales_ent_name = common.ObjToString(sDatas["company"])
  243. sales_dep = common.ObjToString(sDatas["branch"])
  244. if sales_dep == "" {
  245. sales_dep = common.ObjToString(sDatas["department"])
  246. }
  247. data_request = common.ObjToString(sDatas["data_requirement"])
  248. mailbox = common.ObjToString(sDatas["mail"])
  249. source = common.ObjToString(sDatas["interest"])
  250. }
  251. }
  252. if is_assign == 1 || is_transfer == 1 || owner != "" {
  253. user_mold = 1
  254. } else {
  255. user_mold = 2
  256. }
  257. if owner == "" && unique_id != "" && belongTo == "市场部" {
  258. token := getToken()
  259. if token != "" {
  260. sss := url.QueryEscape("合作渠道一切都好")
  261. urls := `https://a1.7x24cc.com/commonInte?flag=1008&account=N000000029739&accessToken=` + token + `&cusObj={"unique_id":"` + unique_id + `","empNo":"8049","owner":"8049","source":"` + sss + `"}&dbType=0001`
  262. bs, err := doGet(urls)
  263. if err != nil {
  264. log.Println("调用接口失败", unique_id, err)
  265. }
  266. resMap := common.StringToMap(string(bs))
  267. if resMap["success"] != nil && resMap["success"].(bool) {
  268. ok := TiDbData.Update("customer", map[string]interface{}{"unique_id": unique_id}, map[string]interface{}{"empNo": "8049", "owner": "8049", "source": "合作渠道一切都好"})
  269. if ok {
  270. log.Println("更新成功", unique_id)
  271. } else {
  272. log.Println("更新失败", unique_id)
  273. }
  274. } else {
  275. log.Println("调用接口失败!!", unique_id)
  276. }
  277. }
  278. }
  279. if ThirdParty.Count("user_channel_info", map[string]interface{}{"user_id": user_id}) > 0 {
  280. ThirdParty.Update("user_channel_info", map[string]interface{}{"user_id": user_id}, map[string]interface{}{
  281. "user_mold": user_mold,
  282. "last_login_time": common.If(last_login_time != "", last_login_time, nil),
  283. "sales_lead_phone": sales_lead_phone,
  284. "sales_ent_name": sales_ent_name,
  285. "sales_position": sales_position,
  286. "sales_dep": sales_dep,
  287. "sales_leads_source": sales_leads_source,
  288. "mailbox": mailbox,
  289. "data_request": data_request,
  290. "source": source,
  291. "order_type": order_type,
  292. "update_time": nowTime,
  293. })
  294. } else {
  295. ThirdParty.Insert("user_channel_info", map[string]interface{}{
  296. "user_id": user_id,
  297. "registe_time": registe_time,
  298. "phone": phone,
  299. "user_mold": user_mold,
  300. "last_login_time": common.If(last_login_time != "", last_login_time, nil),
  301. "sales_lead_phone": sales_lead_phone,
  302. "sales_ent_name": sales_ent_name,
  303. "sales_position": sales_position,
  304. "sales_dep": sales_dep,
  305. "sales_leads_source": sales_leads_source,
  306. "mailbox": mailbox,
  307. "data_request": data_request,
  308. "order_type": order_type,
  309. "source": source,
  310. "update_time": nowTime,
  311. })
  312. }
  313. if clueId > 0 && is_assign != 1 && is_transfer != 1 {
  314. TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"phone": phone}, map[string]interface{}{"is_assign": -1})
  315. TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  316. "clue_id": clueId,
  317. "position_id": common.If(position_id > 0, position_id, -1),
  318. "change_type": "退出公海",
  319. "new_value": "通过合作渠道一切就好登录",
  320. "createtime": nowTime,
  321. "BCPCID": common.GetRandom(32),
  322. "operator_id": -1,
  323. })
  324. } else if is_assign == 1 || is_transfer == 1 {
  325. isOk = true
  326. }
  327. return isOk
  328. }
  329. // 大客户线索-发邮件
  330. func bigCustomer() {
  331. runOk := getRunOk()
  332. if !runOk {
  333. log.Println("不是工作日,任务暂停")
  334. return
  335. }
  336. log.Println("大客户线索定时任务开始")
  337. dataArr := []map[string]interface{}{}
  338. filterArr := []string{"-pc", "-app", "-wx", "-h5"}
  339. sourceMap := map[string]string{} //根据留资维表:tidb/Jianyu_subjectdb/d_saleleads_code
  340. saleSource := TiDb.SelectBySql(`SELECT source,name FROM d_saleleads_code WHERE department LIKE '%大客户%' AND is_delete = 1`)
  341. if saleSource != nil && len(*saleSource) > 0 {
  342. for _, v := range *saleSource {
  343. source := common.ObjToString(v["source"])
  344. name := common.ObjToString(v["name"])
  345. for _, s := range filterArr {
  346. name = strings.ReplaceAll(name, s, "")
  347. }
  348. sourceMap[source] = name
  349. }
  350. }
  351. nowTime := time.Now().Format(date.Date_Full_Layout)
  352. bigSaleTime := cfg.BigSaleTime
  353. bigOrderTime := cfg.BigOrderTime
  354. if bigSaleTime == 0 {
  355. bigSaleTime = time.Now().Unix()
  356. }
  357. if bigOrderTime == "" {
  358. bigOrderTime = nowTime
  359. }
  360. abhList := []map[string]interface{}{}
  361. data := FindBatchData("dk")
  362. saleleadsData, ok := Mgo.Find("saleLeads", map[string]interface{}{"createtime": map[string]interface{}{"$gte": bigSaleTime}}, `{"phone":1,"createtime":1}`, nil, false, -1, -1)
  363. if ok && saleleadsData != nil && len(*saleleadsData) > 0 {
  364. for _, v := range *saleleadsData {
  365. log.Println("444", v)
  366. sources := common.ObjToString(v["source"])
  367. userid := common.ObjToString(v["userid"])
  368. uid := ""
  369. if !mongodb.IsObjectIdHex(userid) {
  370. userMapping := TiDb.FindOne("dwd_f_userbase_id_mapping", map[string]interface{}{"position_id": userid}, "", "")
  371. if userMapping != nil && len(*userMapping) > 0 {
  372. userid = common.ObjToString((*userMapping)["userid"])
  373. uid = common.ObjToString((*userMapping)["uid"])
  374. }
  375. }
  376. if sourceMap[sources] != "" {
  377. source := sourceMap[sources]
  378. phone := common.ObjToString(v["phone"])
  379. if IsInternal(phone) {
  380. continue
  381. }
  382. key := fmt.Sprintf("%s_%s", source, phone)
  383. if _, ok := data[key]; ok {
  384. continue
  385. }
  386. data[key] = true
  387. company := common.ObjToString(v["company"])
  388. job := common.ObjToString(v["position"])
  389. username := common.ObjToString(v["name"])
  390. email := common.ObjToString(v["mail"])
  391. interest := common.ObjToString(v["interest"])
  392. data_requirement := common.ObjToString(v["data_requirement"])
  393. belongTo, usernickname := "大客户", ""
  394. userData := TiDb.FindOne("dwd_f_userbase_baseinfo", map[string]interface{}{"uid": uid}, "", "")
  395. log.Println("555", uid, userData)
  396. if userData != nil {
  397. usernickname = common.ObjToString((*userData)["nickname"])
  398. bt := common.ObjToString((*userData)["belong_to"])
  399. if strings.HasPrefix(bt, "03") || bt == "0102" {
  400. continue
  401. }
  402. }
  403. log.Println("333", userData)
  404. s_sourceid := common.ObjToString((*userData)["s_sourceid"])
  405. if s_sourceid == db.Sourceid {
  406. log.Println("abhList", data, 2222)
  407. //安博会数据
  408. abhList = append(abhList, map[string]interface{}{
  409. "createTime": nowTime,
  410. "lastUpdateTime": nowTime,
  411. "uid": uid,
  412. "userid": userid,
  413. "username": username,
  414. "usernickname": usernickname,
  415. "company": company,
  416. "job": job,
  417. "phone": phone,
  418. "email": email,
  419. "source": source,
  420. "belongTo": belongTo,
  421. "interest": interest,
  422. "data_requirement": data_requirement,
  423. })
  424. if gconv.Int64(v["createtime"]) > bigSaleTime {
  425. bigSaleTime = gconv.Int64(v["createtime"])
  426. }
  427. continue
  428. }
  429. dataArr = append(dataArr, map[string]interface{}{
  430. "createTime": nowTime,
  431. "lastUpdateTime": nowTime,
  432. "uid": uid,
  433. "userid": userid,
  434. "username": username,
  435. "usernickname": usernickname,
  436. "company": company,
  437. "job": job,
  438. "phone": phone,
  439. "email": email,
  440. "source": source,
  441. "belongTo": belongTo,
  442. "interest": interest,
  443. "data_requirement": data_requirement,
  444. })
  445. }
  446. if gconv.Int64(v["createtime"]) > bigSaleTime {
  447. bigSaleTime = gconv.Int64(v["createtime"])
  448. }
  449. }
  450. }
  451. cfg.BigSaleTime = bigSaleTime
  452. orderData := Mysql.SelectBySql(`SELECT * FROM dataexport_order WHERE create_time > "` + bigOrderTime + `" AND (product_type = '历史数据' or product_type = '数据流量包') AND order_status IN (0,1) AND salesperson IS NULL AND is_backstage_order = 0`)
  453. if orderData != nil && len(*orderData) > 0 {
  454. for _, v := range *orderData {
  455. phone := common.ObjToString(v["user_phone"])
  456. order_status := common.IntAll(v["order_status"])
  457. product_type := common.ObjToString(v["product_type"])
  458. orderUserId := gconv.String(v["user_id"])
  459. query := map[string]interface{}{}
  460. if !mongodb.IsObjectIdHex(orderUserId) {
  461. userMapping := TiDb.FindOne("dwd_f_userbase_id_mapping", map[string]interface{}{"position_id": orderUserId}, "", "")
  462. if userMapping != nil && len(*userMapping) > 0 {
  463. uid := common.ObjToString((*userMapping)["uid"])
  464. query["uid"] = uid
  465. }
  466. } else {
  467. query["userid"] = orderUserId
  468. }
  469. userData := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
  470. username, usernickname, userid, uid, source, payorderinfo, unpayorderinfo, s_sourceid := "", "", "", "", "", "", "", ""
  471. if userData != nil {
  472. if phone == "" {
  473. phone = common.ObjToString((*userData)["phone"])
  474. }
  475. if IsInternal(phone) {
  476. continue
  477. }
  478. username = common.ObjToString((*userData)["name"])
  479. usernickname = common.ObjToString((*userData)["nickname"])
  480. uid = common.ObjToString((*userData)["uid"])
  481. userid = common.ObjToString((*userData)["userid"])
  482. s_sourceid = common.ObjToString((*userData)["s_sourceid"])
  483. bt := common.ObjToString((*userData)["belong_to"])
  484. if strings.HasPrefix(bt, "03") || bt == "0102" {
  485. continue
  486. }
  487. }
  488. if product_type == "历史数据" {
  489. if order_status == 0 {
  490. source = "线上历史数据导出未支付订单"
  491. unpayorderinfo = "历史数据"
  492. } else {
  493. source = "线上历史数据导出已支付订单"
  494. payorderinfo = "历史数据" + fmt.Sprint(common.IntAll(v["pay_money"])/100)
  495. }
  496. } else {
  497. if order_status == 0 {
  498. source = "线上数据流量包未支付订单"
  499. unpayorderinfo = "数据流量包"
  500. } else {
  501. source = "线上数据流量包已支付订单"
  502. payorderinfo = "数据流量包" + fmt.Sprint(common.IntAll(v["pay_money"])/100)
  503. }
  504. }
  505. key := fmt.Sprintf("%s_%s", source, phone)
  506. if _, ok := data[key]; ok {
  507. continue
  508. }
  509. data[key] = true
  510. if s_sourceid == db.Sourceid {
  511. abhList = append(abhList, map[string]interface{}{
  512. "createTime": nowTime,
  513. "lastUpdateTime": nowTime,
  514. "phone": phone,
  515. "username": username,
  516. "usernickname": usernickname,
  517. "uid": uid,
  518. "userid": userid,
  519. "company": v["company_name"],
  520. "email": v["user_mail"],
  521. "belongTo": "大客户",
  522. "source": source,
  523. "data_count": v["data_count"],
  524. "unpayorderinfo": unpayorderinfo,
  525. "payorderinfo": payorderinfo, //增加客户需求
  526. })
  527. bigOrderTime = gconv.Time(gconv.String(v["create_time"])).Format(date.Date_Full_Layout)
  528. continue
  529. }
  530. dataArr = append(dataArr, map[string]interface{}{
  531. "createTime": nowTime,
  532. "lastUpdateTime": nowTime,
  533. "phone": phone,
  534. "username": username,
  535. "usernickname": usernickname,
  536. "uid": uid,
  537. "userid": userid,
  538. "company": v["company_name"],
  539. "email": v["user_mail"],
  540. "belongTo": "大客户",
  541. "source": source,
  542. "data_count": v["data_count"],
  543. "unpayorderinfo": unpayorderinfo,
  544. "payorderinfo": payorderinfo, //增加客户需求
  545. })
  546. bigOrderTime = gconv.Time(gconv.String(v["create_time"])).Format(date.Date_Full_Layout)
  547. }
  548. cfg.BigOrderTime = bigOrderTime
  549. }
  550. log.Println("abhList", abhList, 11111)
  551. if len(abhList) > 0 {
  552. ABHEmail("big", abhList)
  553. }
  554. xlsxArr := []string{"用户昵称", "姓名", "公司名称", "职位", "联系人电话", "购买条数", "用户邮箱", "已支付订单信息", "未支付订单类型", "销售线索来源", "具体来源", "数据需求"}
  555. if len(dataArr) > 0 {
  556. keyContent := fmt.Sprintf("data_%s_%s", time.Now().Format("2006-01-02"), "dk")
  557. redis.Put("newother", keyContent, data, 86400)
  558. bigData := TiDb.SelectBySql("select * from dwd_f_crm_clue_big_autodraw_record")
  559. if bigData != nil && len(*bigData) > 0 {
  560. cdata := *bigData
  561. bigArr := map[string][]map[string]interface{}{}
  562. for _, v := range dataArr {
  563. mincount := common.IntAll(cdata[0]["count"])
  564. minindex := 0
  565. minemail := ""
  566. for kk, vv := range cdata {
  567. vcount := common.IntAll(vv["count"])
  568. vemail := common.ObjToString(vv["email"])
  569. if vcount <= mincount {
  570. minindex = kk
  571. mincount = vcount
  572. minemail = vemail
  573. }
  574. }
  575. bigArr[minemail] = append(bigArr[minemail], v)
  576. cdata[minindex]["count"] = mincount + 1
  577. name := common.ObjToString(cdata[minindex]["name"])
  578. TiDb.UpdateOrDeleteBySql(`update dwd_f_crm_clue_big_autodraw_record set count = count + 1 where name = ?`, name)
  579. }
  580. for k, vb := range bigArr {
  581. batch := FindBatch("dk")
  582. fileName, detailName := time.Now().Format(date.Date_Short_Layout)+"-"+batch+"大客户销售线索", ""
  583. xf := xlsx.NewFile()
  584. style := xlsx.NewStyle()
  585. style.Font.Size = 12
  586. style.Font.Bold = true
  587. style.Alignment.Vertical = "center"
  588. style.Alignment.Horizontal = "center"
  589. detailName = time.Now().Format(date.Date_Short_Layout) + "数据详情请查看附件"
  590. sh, _ := xf.AddSheet("线索数据")
  591. row1 := sh.AddRow()
  592. for _, x := range xlsxArr {
  593. cell := row1.AddCell()
  594. cell.SetString(x)
  595. cell.SetStyle(style)
  596. }
  597. for _, v := range vb {
  598. row := sh.AddRow()
  599. row.AddCell().SetString(common.ObjToString(v["usernickname"]))
  600. row.AddCell().SetString(common.ObjToString(v["username"]))
  601. row.AddCell().SetString(common.ObjToString(v["company"]))
  602. row.AddCell().SetString(common.ObjToString(v["job"]))
  603. row.AddCell().SetString(common.ObjToString(v["phone"]))
  604. row.AddCell().SetValue(common.IntAll(v["data_count"]))
  605. row.AddCell().SetString(common.ObjToString(v["email"]))
  606. row.AddCell().SetString(common.ObjToString(v["payorderinfo"]))
  607. row.AddCell().SetString(common.ObjToString(v["unpayorderinfo"]))
  608. row.AddCell().SetString(common.ObjToString(v["source"]))
  609. row.AddCell().SetString(common.ObjToString(v["interest"]))
  610. row.AddCell().SetString(common.ObjToString(v["data_requirement"]))
  611. //增加客户需求
  612. }
  613. email := k
  614. //email = "wanghao@jianyu360.com"
  615. dir := "./xlsx/dk/" + fileName + ".xlsx"
  616. err := xf.Save(dir)
  617. if err != nil {
  618. log.Println("xls error", err, dir)
  619. } else {
  620. gmail := &mail.GmailAuth{
  621. SmtpHost: "smtp.exmail.qq.com",
  622. SmtpPort: 465,
  623. User: "public03@topnet.net.cn",
  624. Pwd: "ue9Rg9Sf4CVtdm5a",
  625. }
  626. status := mail.GSendMail_q("剑鱼标讯", email, "", "", fileName, detailName, dir, fileName+".xlsx", gmail)
  627. if status {
  628. log.Println("send mail success", fileName, email)
  629. }
  630. }
  631. }
  632. }
  633. }
  634. common.WriteSysConfig(&cfg)
  635. log.Println("大客户线索定时任务结束")
  636. }
  637. func IsInternal(phone string) bool {
  638. if DataAnalysisService.Count("dwd_f_userbase_insider", map[string]interface{}{
  639. "mobile": phone,
  640. }) > 0 {
  641. return true
  642. }
  643. return false
  644. }
  645. // 咨询组线索
  646. func AdvisoryCommittee() {
  647. runOk := getRunOk()
  648. if !runOk {
  649. log.Println("不是工作日,任务暂停")
  650. return
  651. }
  652. log.Println("咨询部线索定时任务开始")
  653. dataArr := []map[string]interface{}{}
  654. filterArr := []string{"-pc", "-app", "-wx", "-h5"}
  655. sourceMap := map[string]string{} //根据留资维表:tidb/Jianyu_subjectdb/d_saleleads_code
  656. saleSource := TiDb.SelectBySql(`SELECT source,name FROM d_saleleads_code WHERE department LIKE '%咨询组%' AND is_delete = 1`)
  657. if saleSource != nil && len(*saleSource) > 0 {
  658. for _, v := range *saleSource {
  659. source := common.ObjToString(v["source"])
  660. name := common.ObjToString(v["name"])
  661. for _, s := range filterArr {
  662. name = strings.ReplaceAll(name, s, "")
  663. }
  664. sourceMap[source] = name
  665. }
  666. }
  667. nowTime := time.Now().Format(date.Date_Full_Layout)
  668. advisoryCommitteeTime := cfg.AdvisoryCommitteeTime
  669. if advisoryCommitteeTime == 0 {
  670. advisoryCommitteeTime = time.Now().Unix()
  671. }
  672. abhList := []map[string]interface{}{}
  673. saleleadsData, ok := Mgo.Find("saleLeads", map[string]interface{}{"createtime": map[string]interface{}{"$gte": advisoryCommitteeTime}}, `{"phone":1,"createtime":1}`, nil, false, -1, -1)
  674. if ok && saleleadsData != nil && len(*saleleadsData) > 0 {
  675. data := FindBatchData("zx")
  676. for _, v := range *saleleadsData {
  677. sources := common.ObjToString(v["source"])
  678. userid := common.ObjToString(v["userid"])
  679. uid := ""
  680. if !mongodb.IsObjectIdHex(userid) {
  681. userMapping := TiDb.FindOne("dwd_f_userbase_id_mapping", map[string]interface{}{"position_id": userid}, "", "")
  682. if userMapping != nil && len(*userMapping) > 0 {
  683. userid = common.ObjToString((*userMapping)["userid"])
  684. uid = common.ObjToString((*userMapping)["uid"])
  685. }
  686. }
  687. if sourceMap[sources] != "" {
  688. company := common.ObjToString(v["company"])
  689. phone := common.ObjToString(v["phone"])
  690. if IsInternal(phone) {
  691. continue
  692. }
  693. username := common.ObjToString(v["name"])
  694. email := common.ObjToString(v["mail"])
  695. interest := common.ObjToString(v["interest"])
  696. data_requirement := common.ObjToString(v["data_requirement"])
  697. source := sourceMap[sources]
  698. belongTo := "咨询组"
  699. userData := TiDb.FindOne("dwd_f_userbase_baseinfo", map[string]interface{}{"uid": uid}, "", "")
  700. if userData != nil {
  701. bt := common.ObjToString((*userData)["belong_to"])
  702. if strings.HasPrefix(bt, "03") || bt == "0102" {
  703. continue
  704. }
  705. }
  706. key := fmt.Sprintf("%s_%s_%s", source, phone, interest)
  707. if _, ok := data[key]; ok {
  708. continue
  709. }
  710. data[key] = true
  711. s_sourceid := common.ObjToString((*userData)["s_sourceid"])
  712. if s_sourceid == db.Sourceid {
  713. abhList = append(abhList, map[string]interface{}{
  714. "createTime": nowTime,
  715. "createtime": v["createtime"],
  716. "username": username,
  717. "company": company,
  718. "phone": phone,
  719. "source": source,
  720. "belongTo": belongTo,
  721. "interest": interest,
  722. "data_requirement": data_requirement,
  723. "branch": v["branch"],
  724. "email": email,
  725. })
  726. if gconv.Int64(v["createtime"]) > advisoryCommitteeTime {
  727. advisoryCommitteeTime = gconv.Int64(v["createtime"])
  728. }
  729. continue
  730. }
  731. dataArr = append(dataArr, map[string]interface{}{
  732. "createTime": nowTime,
  733. "createtime": v["createtime"],
  734. "username": username,
  735. "company": company,
  736. "phone": phone,
  737. "source": source,
  738. "belongTo": belongTo,
  739. "interest": interest,
  740. "data_requirement": data_requirement,
  741. "branch": v["branch"],
  742. "email": email,
  743. })
  744. }
  745. }
  746. keyContent := fmt.Sprintf("data_%s_%s", time.Now().Format("2006-01-02"), "zx")
  747. redis.Put("newother", keyContent, data, 86400)
  748. }
  749. if len(abhList) > 0 {
  750. //安博会发邮件高翔
  751. ABHEmail("advisory", abhList)
  752. }
  753. cfg.AdvisoryCommitteeTime = advisoryCommitteeTime
  754. xlsxArr := []string{"姓名", "联系方式", "邮箱", "公司名称", "咨询需求", "销售线索来源", "具体来源", "留资时间"}
  755. if len(dataArr) > 0 {
  756. //排序:首先按照“联系方式”排序,即同1个用户的留资放在一起,其次按照留资时间正序排序。
  757. batch := FindBatch("zx")
  758. fileName, detailName := "咨询服务销售线索 "+time.Now().Format(date.Date_Short_Layout)+"-"+batch, ""
  759. xf := xlsx.NewFile()
  760. style := xlsx.NewStyle()
  761. style.Font.Size = 12
  762. style.Font.Bold = true
  763. style.Alignment.Vertical = "center"
  764. style.Alignment.Horizontal = "center"
  765. detailName = "今日新增咨询服务销售线索,请查收附件,及时跟进。"
  766. sh, _ := xf.AddSheet("线索数据")
  767. row1 := sh.AddRow()
  768. for _, x := range xlsxArr {
  769. cell := row1.AddCell()
  770. cell.SetString(x)
  771. cell.SetStyle(style)
  772. }
  773. for _, v := range dataArr {
  774. row := sh.AddRow()
  775. row.AddCell().SetString(common.ObjToString(v["username"]))
  776. row.AddCell().SetString(common.ObjToString(v["phone"]))
  777. row.AddCell().SetString(common.ObjToString(v["email"]))
  778. row.AddCell().SetString(common.ObjToString(v["company"]))
  779. row.AddCell().SetString(common.ObjToString(v["data_requirement"]))
  780. row.AddCell().SetString(common.ObjToString(v["source"]))
  781. row.AddCell().SetString(common.ObjToString(v["interest"]))
  782. row.AddCell().SetString(gconv.Time(gconv.Int64(v["createtime"])).Format(date.Date_Full_Layout))
  783. //增加客户需求
  784. }
  785. email := db.AdvisoryCommitteeMail
  786. dir := "./xlsx/zx/" + fileName + ".xlsx"
  787. err := xf.Save(dir)
  788. if err != nil {
  789. log.Println("xls error", err, dir)
  790. } else {
  791. gmail := &mail.GmailAuth{
  792. SmtpHost: "smtp.exmail.qq.com",
  793. SmtpPort: 465,
  794. User: "public03@topnet.net.cn",
  795. Pwd: "ue9Rg9Sf4CVtdm5a",
  796. }
  797. for _, v := range email {
  798. status := mail.GSendMail_q("剑鱼标讯", v, "", "", fileName, detailName, dir, fileName+".xlsx", gmail)
  799. if status {
  800. log.Println("send mail success", fileName, v)
  801. }
  802. }
  803. }
  804. }
  805. common.WriteSysConfig(&cfg)
  806. log.Println("咨询部线索定时任务结束")
  807. }
  808. // 市场部线索
  809. func marketCustomer() {
  810. runOk := getRunOk()
  811. if !runOk {
  812. log.Println("不是工作日,任务暂停")
  813. return
  814. }
  815. log.Println("市场部线索定时任务开始")
  816. dataArr := []map[string]interface{}{}
  817. filterArr := []string{"-pc", "-app", "-wx", "-h5"}
  818. sourceMap := map[string]string{} //根据留资维表:tidb/Jianyu_subjectdb/d_saleleads_code
  819. saleSource := TiDb.SelectBySql(`SELECT source,name FROM d_saleleads_code WHERE department LIKE '%市场组%' AND is_delete = 1`)
  820. if saleSource != nil && len(*saleSource) > 0 {
  821. for _, v := range *saleSource {
  822. source := common.ObjToString(v["source"])
  823. name := common.ObjToString(v["name"])
  824. for _, s := range filterArr {
  825. name = strings.ReplaceAll(name, s, "")
  826. }
  827. sourceMap[source] = name
  828. }
  829. }
  830. nowTime := time.Now().Format(date.Date_Full_Layout)
  831. marketSaleTime := cfg.MarketSaleTime
  832. if marketSaleTime == 0 {
  833. marketSaleTime = time.Now().Unix()
  834. }
  835. abhList := []map[string]interface{}{}
  836. saleleadsData, ok := Mgo.Find("saleLeads", map[string]interface{}{"createtime": map[string]interface{}{"$gte": marketSaleTime}}, `{"phone":1,"createtime":1}`, nil, false, -1, -1)
  837. if ok && saleleadsData != nil && len(*saleleadsData) > 0 {
  838. data := FindBatchData("sc")
  839. for _, v := range *saleleadsData {
  840. sources := common.ObjToString(v["source"])
  841. userid := common.ObjToString(v["userid"])
  842. uid := ""
  843. if !mongodb.IsObjectIdHex(userid) {
  844. userMapping := TiDb.FindOne("dwd_f_userbase_id_mapping", map[string]interface{}{"position_id": userid}, "", "")
  845. if userMapping != nil && len(*userMapping) > 0 {
  846. userid = common.ObjToString((*userMapping)["userid"])
  847. uid = common.ObjToString((*userMapping)["uid"])
  848. }
  849. }
  850. if sourceMap[sources] != "" {
  851. company := common.ObjToString(v["company"])
  852. phone := common.ObjToString(v["phone"])
  853. if IsInternal(phone) {
  854. continue
  855. }
  856. job := common.ObjToString(v["position"])
  857. username := common.ObjToString(v["name"])
  858. email := common.ObjToString(v["mail"])
  859. interest := common.ObjToString(v["interest"])
  860. data_requirement := common.ObjToString(v["data_requirement"])
  861. source := sourceMap[sources]
  862. belongTo, usernickname := "市场组", ""
  863. userData := TiDb.FindOne("dwd_f_userbase_baseinfo", map[string]interface{}{"uid": uid}, "", "")
  864. if userData != nil {
  865. usernickname = common.ObjToString((*userData)["nickname"])
  866. bt := common.ObjToString((*userData)["belong_to"])
  867. if strings.HasPrefix(bt, "03") || bt == "0102" {
  868. continue
  869. }
  870. }
  871. key := fmt.Sprintf("%s_%s", source, phone)
  872. if _, ok := data[key]; ok {
  873. continue
  874. }
  875. s_sourceid := common.ObjToString((*userData)["s_sourceid"])
  876. data[key] = true
  877. if s_sourceid == db.Sourceid {
  878. abhList = append(abhList, map[string]interface{}{
  879. "createTime": nowTime,
  880. "lastUpdateTime": nowTime,
  881. "createtime": v["createtime"],
  882. "uid": uid,
  883. "userid": userid,
  884. "username": username,
  885. "usernickname": usernickname,
  886. "company": company,
  887. "job": job,
  888. "phone": phone,
  889. "email": email,
  890. "source": source,
  891. "belongTo": belongTo,
  892. "interest": interest,
  893. "data_requirement": data_requirement,
  894. "branch": v["branch"],
  895. "s_sourceid": s_sourceid,
  896. })
  897. if gconv.Int64(v["createtime"]) > marketSaleTime {
  898. marketSaleTime = gconv.Int64(v["createtime"])
  899. }
  900. continue
  901. }
  902. dataArr = append(dataArr, map[string]interface{}{
  903. "createTime": nowTime,
  904. "lastUpdateTime": nowTime,
  905. "createtime": v["createtime"],
  906. "uid": uid,
  907. "userid": userid,
  908. "username": username,
  909. "usernickname": usernickname,
  910. "company": company,
  911. "job": job,
  912. "phone": phone,
  913. "email": email,
  914. "source": source,
  915. "belongTo": belongTo,
  916. "interest": interest,
  917. "data_requirement": data_requirement,
  918. "branch": v["branch"],
  919. "s_sourceid": s_sourceid,
  920. })
  921. }
  922. if gconv.Int64(v["createtime"]) > marketSaleTime {
  923. marketSaleTime = gconv.Int64(v["createtime"])
  924. }
  925. }
  926. if len(abhList) > 0 {
  927. //安博会发邮件高翔
  928. ABHEmail("market", abhList)
  929. }
  930. keyContent := fmt.Sprintf("data_%s_%s", time.Now().Format("2006-01-02"), "sc")
  931. redis.Put("newother", keyContent, data, 86400)
  932. }
  933. cfg.MarketSaleTime = marketSaleTime
  934. xlsxArr := []string{"姓名", "联系人电话", "公司名称", "职位", "部门", "销售线索来源", "留资时间"}
  935. if len(dataArr) > 0 {
  936. //排序:首先按照“联系方式”排序,即同1个用户的留资放在一起,其次按照留资时间正序排序。
  937. batch := FindBatch("sc")
  938. fileName, detailName := "商务合作销售线索 "+time.Now().Format(date.Date_Short_Layout)+"-"+batch, ""
  939. xf := xlsx.NewFile()
  940. style := xlsx.NewStyle()
  941. style.Font.Size = 12
  942. style.Font.Bold = true
  943. style.Alignment.Vertical = "center"
  944. style.Alignment.Horizontal = "center"
  945. detailName = "今日新增商务合作销售线索,请查收附件,及时跟进。"
  946. sh, _ := xf.AddSheet("线索数据")
  947. row1 := sh.AddRow()
  948. for _, x := range xlsxArr {
  949. cell := row1.AddCell()
  950. cell.SetString(x)
  951. cell.SetStyle(style)
  952. }
  953. for _, v := range dataArr {
  954. row := sh.AddRow()
  955. row.AddCell().SetString(common.ObjToString(v["username"]))
  956. row.AddCell().SetString(common.ObjToString(v["phone"]))
  957. row.AddCell().SetString(common.ObjToString(v["company"]))
  958. row.AddCell().SetString(common.ObjToString(v["job"]))
  959. row.AddCell().SetString(common.ObjToString(v["branch"]))
  960. row.AddCell().SetString(common.ObjToString(v["source"]))
  961. row.AddCell().SetString(gconv.Time(gconv.Int64(v["createtime"])).Format(date.Date_Full_Layout))
  962. //增加客户需求
  963. }
  964. email := db.MarketSaleMail
  965. dir := "./xlsx/sc/" + fileName + ".xlsx"
  966. err := xf.Save(dir)
  967. if err != nil {
  968. log.Println("xls error", err, dir)
  969. } else {
  970. gmail := &mail.GmailAuth{
  971. SmtpHost: "smtp.exmail.qq.com",
  972. SmtpPort: 465,
  973. User: "public03@topnet.net.cn",
  974. Pwd: "ue9Rg9Sf4CVtdm5a",
  975. }
  976. status := mail.GSendMail_q("剑鱼标讯", email, "", "", fileName, detailName, dir, fileName+".xlsx", gmail)
  977. if status {
  978. log.Println("send mail success", fileName, email)
  979. }
  980. }
  981. }
  982. common.WriteSysConfig(&cfg)
  983. log.Println("大客户线索定时任务结束")
  984. }
  985. func eventReg() {
  986. lastEventRegTime := cfg.LastEventRegTime
  987. sql := fmt.Sprintf(`select * from exhibition_sign_up where is_del = 0 and update_time > "%s" order by update_time asc`, lastEventRegTime)
  988. log.Println("活动报名表定时任务开始", sql)
  989. data := Jyactivities.SelectBySql(sql)
  990. if data != nil && *data != nil && len(*data) > 0 {
  991. for _, v := range *data {
  992. ok1, ok2, _ := FormatData(v, "eventReg")
  993. if !ok1 {
  994. common.WriteSysConfig(&cfg)
  995. log.Println("线索卡点", "eventReg", v, lastEventRegTime)
  996. } else {
  997. if !ok2 {
  998. log.Println("用户分配已达上限", "eventReg", v, lastEventRegTime)
  999. common.WriteSysConfig(&cfg)
  1000. }
  1001. }
  1002. cfg.LastEventRegTime = common.ObjToString(v["update_time"])
  1003. }
  1004. }
  1005. common.WriteSysConfig(&cfg)
  1006. log.Println("活动报名表定时任务结束")
  1007. }
  1008. func saveHlyj(belong_to, item, phone, name, sourceName, cluename, position, nowTime string, isGroup, isCommerce int) {
  1009. if strings.HasPrefix(belong_to, "02") && item == "eventReg" {
  1010. saveMap := map[string]interface{}{
  1011. "unique_id": phone,
  1012. "phone": phone,
  1013. "username": name,
  1014. "source": sourceName,
  1015. "status999": "status5",
  1016. "company": cluename,
  1017. "job": position,
  1018. "belongTo": "市场部",
  1019. "createTime": nowTime,
  1020. "lastUpdateTime": nowTime,
  1021. }
  1022. token := getToken()
  1023. updateData := map[string]interface{}{
  1024. "dbType": "0001",
  1025. "customerList": []map[string]interface{}{saveMap},
  1026. }
  1027. dataByte, _ := json.Marshal(&updateData)
  1028. url := `https://a1.7x24cc.com/commonInte?flag=1007&account=N000000029739&accessToken=` + token + `&json=` + url.QueryEscape(string(dataByte))
  1029. bs, err := doGet(url)
  1030. if err != nil {
  1031. log.Println("调用接口失败")
  1032. } else {
  1033. resMap := common.StringToMap(string(bs))
  1034. if resMap["success"] != nil && resMap["success"].(bool) {
  1035. saveMap["company_nature"] = isGroup
  1036. saveMap["company_verification"] = isCommerce
  1037. TiDbData.Insert("customer", saveMap)
  1038. } else {
  1039. log.Println("新增线索失败")
  1040. }
  1041. }
  1042. }
  1043. }
  1044. func FindBatch(moudle string) string {
  1045. now := time.Now().Format("2006-01-02")
  1046. key := fmt.Sprintf("batch_%s_%s", now, moudle)
  1047. yesterday := time.Now().AddDate(0, 0, -1).Format("2006-01-02")
  1048. yesterdayKey := fmt.Sprintf("batch_%s_%s", yesterday, moudle)
  1049. if ok, _ := redis.Exists("newother", yesterdayKey); ok {
  1050. //删除之前数据
  1051. redis.Del("newother", yesterdayKey)
  1052. }
  1053. batch := redis.Incr("newother", key)
  1054. return fmt.Sprintf("%04d", batch)
  1055. }
  1056. func FindBatchData(moudle string) map[string]interface{} {
  1057. now := time.Now().Format("2006-01-02")
  1058. //数据提取
  1059. keyContent := fmt.Sprintf("data_%s_%s", now, moudle)
  1060. data := redis.Get("newother", keyContent)
  1061. if data == nil {
  1062. return make(map[string]interface{})
  1063. } else {
  1064. return gconv.Map(data)
  1065. }
  1066. }