everything.go 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102
  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. sources := common.ObjToString(v["source"])
  366. userid := common.ObjToString(v["userid"])
  367. uid := ""
  368. if !mongodb.IsObjectIdHex(userid) {
  369. userMapping := TiDb.FindOne("dwd_f_userbase_id_mapping", map[string]interface{}{"position_id": userid}, "", "")
  370. if userMapping != nil && len(*userMapping) > 0 {
  371. userid = common.ObjToString((*userMapping)["userid"])
  372. uid = common.ObjToString((*userMapping)["uid"])
  373. }
  374. } else {
  375. userMapping := TiDb.FindOne("dwd_f_userbase_id_mapping", map[string]interface{}{"userid": userid}, "", "")
  376. if userMapping != nil && len(*userMapping) > 0 {
  377. userid = common.ObjToString((*userMapping)["userid"])
  378. uid = common.ObjToString((*userMapping)["uid"])
  379. }
  380. }
  381. if sourceMap[sources] != "" {
  382. source := sourceMap[sources]
  383. phone := common.ObjToString(v["phone"])
  384. if IsInternal(phone) {
  385. continue
  386. }
  387. key := fmt.Sprintf("%s_%s", source, phone)
  388. if _, ok := data[key]; ok {
  389. continue
  390. }
  391. data[key] = true
  392. company := common.ObjToString(v["company"])
  393. job := common.ObjToString(v["position"])
  394. username := common.ObjToString(v["name"])
  395. email := common.ObjToString(v["mail"])
  396. interest := common.ObjToString(v["interest"])
  397. data_requirement := common.ObjToString(v["data_requirement"])
  398. belongTo, usernickname := "大客户", ""
  399. userData := TiDb.FindOne("dwd_f_userbase_baseinfo", map[string]interface{}{"uid": uid}, "", "")
  400. if userData != nil {
  401. usernickname = common.ObjToString((*userData)["nickname"])
  402. bt := common.ObjToString((*userData)["belong_to"])
  403. if strings.HasPrefix(bt, "03") || bt == "0102" {
  404. continue
  405. }
  406. }
  407. s_sourceid := common.ObjToString((*userData)["s_sourceid"])
  408. if s_sourceid == db.Sourceid {
  409. //安博会数据
  410. abhList = append(abhList, map[string]interface{}{
  411. "createTime": nowTime,
  412. "lastUpdateTime": nowTime,
  413. "uid": uid,
  414. "userid": userid,
  415. "username": username,
  416. "usernickname": usernickname,
  417. "company": company,
  418. "job": job,
  419. "phone": phone,
  420. "email": email,
  421. "source": source,
  422. "belongTo": belongTo,
  423. "interest": interest,
  424. "data_requirement": data_requirement,
  425. })
  426. if gconv.Int64(v["createtime"]) > bigSaleTime {
  427. bigSaleTime = gconv.Int64(v["createtime"])
  428. }
  429. continue
  430. }
  431. dataArr = append(dataArr, map[string]interface{}{
  432. "createTime": nowTime,
  433. "lastUpdateTime": nowTime,
  434. "uid": uid,
  435. "userid": userid,
  436. "username": username,
  437. "usernickname": usernickname,
  438. "company": company,
  439. "job": job,
  440. "phone": phone,
  441. "email": email,
  442. "source": source,
  443. "belongTo": belongTo,
  444. "interest": interest,
  445. "data_requirement": data_requirement,
  446. })
  447. }
  448. if gconv.Int64(v["createtime"]) > bigSaleTime {
  449. bigSaleTime = gconv.Int64(v["createtime"])
  450. }
  451. }
  452. }
  453. cfg.BigSaleTime = bigSaleTime
  454. 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`)
  455. if orderData != nil && len(*orderData) > 0 {
  456. for _, v := range *orderData {
  457. phone := common.ObjToString(v["user_phone"])
  458. order_status := common.IntAll(v["order_status"])
  459. product_type := common.ObjToString(v["product_type"])
  460. orderUserId := gconv.String(v["user_id"])
  461. query := map[string]interface{}{}
  462. if !mongodb.IsObjectIdHex(orderUserId) {
  463. userMapping := TiDb.FindOne("dwd_f_userbase_id_mapping", map[string]interface{}{"position_id": orderUserId}, "", "")
  464. if userMapping != nil && len(*userMapping) > 0 {
  465. uid := common.ObjToString((*userMapping)["uid"])
  466. query["uid"] = uid
  467. }
  468. } else {
  469. query["userid"] = orderUserId
  470. }
  471. userData := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
  472. username, usernickname, userid, uid, source, payorderinfo, unpayorderinfo, s_sourceid := "", "", "", "", "", "", "", ""
  473. if userData != nil {
  474. if phone == "" {
  475. phone = common.ObjToString((*userData)["phone"])
  476. }
  477. if IsInternal(phone) {
  478. continue
  479. }
  480. username = common.ObjToString((*userData)["name"])
  481. usernickname = common.ObjToString((*userData)["nickname"])
  482. uid = common.ObjToString((*userData)["uid"])
  483. userid = common.ObjToString((*userData)["userid"])
  484. s_sourceid = common.ObjToString((*userData)["s_sourceid"])
  485. bt := common.ObjToString((*userData)["belong_to"])
  486. if strings.HasPrefix(bt, "03") || bt == "0102" {
  487. continue
  488. }
  489. }
  490. if product_type == "历史数据" {
  491. if order_status == 0 {
  492. source = "线上历史数据导出未支付订单"
  493. unpayorderinfo = "历史数据"
  494. } else {
  495. source = "线上历史数据导出已支付订单"
  496. payorderinfo = "历史数据" + fmt.Sprint(common.IntAll(v["pay_money"])/100)
  497. }
  498. } else {
  499. if order_status == 0 {
  500. source = "线上数据流量包未支付订单"
  501. unpayorderinfo = "数据流量包"
  502. } else {
  503. source = "线上数据流量包已支付订单"
  504. payorderinfo = "数据流量包" + fmt.Sprint(common.IntAll(v["pay_money"])/100)
  505. }
  506. }
  507. key := fmt.Sprintf("%s_%s", source, phone)
  508. if _, ok := data[key]; ok {
  509. continue
  510. }
  511. data[key] = true
  512. if s_sourceid == db.Sourceid {
  513. abhList = append(abhList, map[string]interface{}{
  514. "createTime": nowTime,
  515. "lastUpdateTime": nowTime,
  516. "phone": phone,
  517. "username": username,
  518. "usernickname": usernickname,
  519. "uid": uid,
  520. "userid": userid,
  521. "company": v["company_name"],
  522. "email": v["user_mail"],
  523. "belongTo": "大客户",
  524. "source": source,
  525. "data_count": v["data_count"],
  526. "unpayorderinfo": unpayorderinfo,
  527. "payorderinfo": payorderinfo, //增加客户需求
  528. })
  529. bigOrderTime = gconv.Time(gconv.String(v["create_time"])).Format(date.Date_Full_Layout)
  530. continue
  531. }
  532. dataArr = append(dataArr, map[string]interface{}{
  533. "createTime": nowTime,
  534. "lastUpdateTime": nowTime,
  535. "phone": phone,
  536. "username": username,
  537. "usernickname": usernickname,
  538. "uid": uid,
  539. "userid": userid,
  540. "company": v["company_name"],
  541. "email": v["user_mail"],
  542. "belongTo": "大客户",
  543. "source": source,
  544. "data_count": v["data_count"],
  545. "unpayorderinfo": unpayorderinfo,
  546. "payorderinfo": payorderinfo, //增加客户需求
  547. })
  548. bigOrderTime = gconv.Time(gconv.String(v["create_time"])).Format(date.Date_Full_Layout)
  549. }
  550. cfg.BigOrderTime = bigOrderTime
  551. }
  552. if len(abhList) > 0 {
  553. ABHEmail("big", abhList)
  554. }
  555. if len(abhList) > 0 || 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. }
  559. xlsxArr := []string{"用户昵称", "姓名", "公司名称", "职位", "联系人电话", "购买条数", "用户邮箱", "已支付订单信息", "未支付订单类型", "销售线索来源", "具体来源", "数据需求"}
  560. if len(dataArr) > 0 {
  561. bigData := TiDb.SelectBySql("select * from dwd_f_crm_clue_big_autodraw_record")
  562. if bigData != nil && len(*bigData) > 0 {
  563. cdata := *bigData
  564. bigArr := map[string][]map[string]interface{}{}
  565. for _, v := range dataArr {
  566. mincount := common.IntAll(cdata[0]["count"])
  567. minindex := 0
  568. minemail := ""
  569. for kk, vv := range cdata {
  570. vcount := common.IntAll(vv["count"])
  571. vemail := common.ObjToString(vv["email"])
  572. if vcount <= mincount {
  573. minindex = kk
  574. mincount = vcount
  575. minemail = vemail
  576. }
  577. }
  578. bigArr[minemail] = append(bigArr[minemail], v)
  579. cdata[minindex]["count"] = mincount + 1
  580. name := common.ObjToString(cdata[minindex]["name"])
  581. TiDb.UpdateOrDeleteBySql(`update dwd_f_crm_clue_big_autodraw_record set count = count + 1 where name = ?`, name)
  582. }
  583. for k, vb := range bigArr {
  584. batch := FindBatch("dk")
  585. fileName, detailName := time.Now().Format(date.Date_Short_Layout)+"-"+batch+"大客户销售线索", ""
  586. xf := xlsx.NewFile()
  587. style := xlsx.NewStyle()
  588. style.Font.Size = 12
  589. style.Font.Bold = true
  590. style.Alignment.Vertical = "center"
  591. style.Alignment.Horizontal = "center"
  592. detailName = time.Now().Format(date.Date_Short_Layout) + "数据详情请查看附件"
  593. sh, _ := xf.AddSheet("线索数据")
  594. row1 := sh.AddRow()
  595. for _, x := range xlsxArr {
  596. cell := row1.AddCell()
  597. cell.SetString(x)
  598. cell.SetStyle(style)
  599. }
  600. for _, v := range vb {
  601. row := sh.AddRow()
  602. row.AddCell().SetString(common.ObjToString(v["usernickname"]))
  603. row.AddCell().SetString(common.ObjToString(v["username"]))
  604. row.AddCell().SetString(common.ObjToString(v["company"]))
  605. row.AddCell().SetString(common.ObjToString(v["job"]))
  606. row.AddCell().SetString(common.ObjToString(v["phone"]))
  607. row.AddCell().SetValue(common.IntAll(v["data_count"]))
  608. row.AddCell().SetString(common.ObjToString(v["email"]))
  609. row.AddCell().SetString(common.ObjToString(v["payorderinfo"]))
  610. row.AddCell().SetString(common.ObjToString(v["unpayorderinfo"]))
  611. row.AddCell().SetString(common.ObjToString(v["source"]))
  612. row.AddCell().SetString(common.ObjToString(v["interest"]))
  613. row.AddCell().SetString(common.ObjToString(v["data_requirement"]))
  614. //增加客户需求
  615. }
  616. email := k
  617. //email = "wanghao@jianyu360.com"
  618. dir := "./xlsx/dk/" + fileName + ".xlsx"
  619. err := xf.Save(dir)
  620. if err != nil {
  621. log.Println("xls error", err, dir)
  622. } else {
  623. gmail := &mail.GmailAuth{
  624. SmtpHost: "smtp.exmail.qq.com",
  625. SmtpPort: 465,
  626. User: "public03@topnet.net.cn",
  627. Pwd: "ue9Rg9Sf4CVtdm5a",
  628. }
  629. status := mail.GSendMail_q("剑鱼标讯", email, "", "", fileName, detailName, dir, fileName+".xlsx", gmail)
  630. if status {
  631. log.Println("send mail success", fileName, email)
  632. }
  633. }
  634. }
  635. }
  636. }
  637. common.WriteSysConfig(&cfg)
  638. log.Println("大客户线索定时任务结束")
  639. }
  640. func IsInternal(phone string) bool {
  641. if DataAnalysisService.Count("dwd_f_userbase_insider", map[string]interface{}{
  642. "mobile": phone,
  643. }) > 0 {
  644. return true
  645. }
  646. return false
  647. }
  648. // 咨询组线索
  649. func AdvisoryCommittee() {
  650. runOk := getRunOk()
  651. if !runOk {
  652. log.Println("不是工作日,任务暂停")
  653. return
  654. }
  655. log.Println("咨询部线索定时任务开始")
  656. dataArr := []map[string]interface{}{}
  657. filterArr := []string{"-pc", "-app", "-wx", "-h5"}
  658. sourceMap := map[string]string{} //根据留资维表:tidb/Jianyu_subjectdb/d_saleleads_code
  659. saleSource := TiDb.SelectBySql(`SELECT source,name FROM d_saleleads_code WHERE department LIKE '%咨询组%' AND is_delete = 1`)
  660. if saleSource != nil && len(*saleSource) > 0 {
  661. for _, v := range *saleSource {
  662. source := common.ObjToString(v["source"])
  663. name := common.ObjToString(v["name"])
  664. for _, s := range filterArr {
  665. name = strings.ReplaceAll(name, s, "")
  666. }
  667. sourceMap[source] = name
  668. }
  669. }
  670. nowTime := time.Now().Format(date.Date_Full_Layout)
  671. advisoryCommitteeTime := cfg.AdvisoryCommitteeTime
  672. if advisoryCommitteeTime == 0 {
  673. advisoryCommitteeTime = time.Now().Unix()
  674. }
  675. abhList := []map[string]interface{}{}
  676. saleleadsData, ok := Mgo.Find("saleLeads", map[string]interface{}{"createtime": map[string]interface{}{"$gte": advisoryCommitteeTime}}, `{"phone":1,"createtime":1}`, nil, false, -1, -1)
  677. if ok && saleleadsData != nil && len(*saleleadsData) > 0 {
  678. data := FindBatchData("zx")
  679. for _, v := range *saleleadsData {
  680. sources := common.ObjToString(v["source"])
  681. userid := common.ObjToString(v["userid"])
  682. uid := ""
  683. if !mongodb.IsObjectIdHex(userid) {
  684. userMapping := TiDb.FindOne("dwd_f_userbase_id_mapping", map[string]interface{}{"position_id": userid}, "", "")
  685. if userMapping != nil && len(*userMapping) > 0 {
  686. userid = common.ObjToString((*userMapping)["userid"])
  687. uid = common.ObjToString((*userMapping)["uid"])
  688. }
  689. } else {
  690. userMapping := TiDb.FindOne("dwd_f_userbase_id_mapping", map[string]interface{}{"userid": userid}, "", "")
  691. if userMapping != nil && len(*userMapping) > 0 {
  692. userid = common.ObjToString((*userMapping)["userid"])
  693. uid = common.ObjToString((*userMapping)["uid"])
  694. }
  695. }
  696. if sourceMap[sources] != "" {
  697. company := common.ObjToString(v["company"])
  698. phone := common.ObjToString(v["phone"])
  699. if IsInternal(phone) {
  700. continue
  701. }
  702. username := common.ObjToString(v["name"])
  703. email := common.ObjToString(v["mail"])
  704. interest := common.ObjToString(v["interest"])
  705. data_requirement := common.ObjToString(v["data_requirement"])
  706. source := sourceMap[sources]
  707. belongTo := "咨询组"
  708. userData := TiDb.FindOne("dwd_f_userbase_baseinfo", map[string]interface{}{"uid": uid}, "", "")
  709. if userData != nil {
  710. bt := common.ObjToString((*userData)["belong_to"])
  711. if strings.HasPrefix(bt, "03") || bt == "0102" {
  712. continue
  713. }
  714. }
  715. key := fmt.Sprintf("%s_%s_%s", source, phone, interest)
  716. if _, ok := data[key]; ok {
  717. continue
  718. }
  719. data[key] = true
  720. s_sourceid := common.ObjToString((*userData)["s_sourceid"])
  721. if s_sourceid == db.Sourceid {
  722. abhList = append(abhList, map[string]interface{}{
  723. "createTime": nowTime,
  724. "createtime": v["createtime"],
  725. "username": username,
  726. "company": company,
  727. "phone": phone,
  728. "source": source,
  729. "belongTo": belongTo,
  730. "interest": interest,
  731. "data_requirement": data_requirement,
  732. "branch": v["branch"],
  733. "email": email,
  734. })
  735. if gconv.Int64(v["createtime"]) > advisoryCommitteeTime {
  736. advisoryCommitteeTime = gconv.Int64(v["createtime"])
  737. }
  738. continue
  739. }
  740. dataArr = append(dataArr, map[string]interface{}{
  741. "createTime": nowTime,
  742. "createtime": v["createtime"],
  743. "username": username,
  744. "company": company,
  745. "phone": phone,
  746. "source": source,
  747. "belongTo": belongTo,
  748. "interest": interest,
  749. "data_requirement": data_requirement,
  750. "branch": v["branch"],
  751. "email": email,
  752. })
  753. }
  754. }
  755. keyContent := fmt.Sprintf("data_%s_%s", time.Now().Format("2006-01-02"), "zx")
  756. redis.Put("newother", keyContent, data, 86400)
  757. }
  758. if len(abhList) > 0 {
  759. //安博会发邮件高翔
  760. ABHEmail("advisory", abhList)
  761. }
  762. cfg.AdvisoryCommitteeTime = advisoryCommitteeTime
  763. xlsxArr := []string{"姓名", "联系方式", "邮箱", "公司名称", "咨询需求", "销售线索来源", "具体来源", "留资时间"}
  764. if len(dataArr) > 0 {
  765. //排序:首先按照“联系方式”排序,即同1个用户的留资放在一起,其次按照留资时间正序排序。
  766. batch := FindBatch("zx")
  767. fileName, detailName := "咨询服务销售线索 "+time.Now().Format(date.Date_Short_Layout)+"-"+batch, ""
  768. xf := xlsx.NewFile()
  769. style := xlsx.NewStyle()
  770. style.Font.Size = 12
  771. style.Font.Bold = true
  772. style.Alignment.Vertical = "center"
  773. style.Alignment.Horizontal = "center"
  774. detailName = "今日新增咨询服务销售线索,请查收附件,及时跟进。"
  775. sh, _ := xf.AddSheet("线索数据")
  776. row1 := sh.AddRow()
  777. for _, x := range xlsxArr {
  778. cell := row1.AddCell()
  779. cell.SetString(x)
  780. cell.SetStyle(style)
  781. }
  782. for _, v := range dataArr {
  783. row := sh.AddRow()
  784. row.AddCell().SetString(common.ObjToString(v["username"]))
  785. row.AddCell().SetString(common.ObjToString(v["phone"]))
  786. row.AddCell().SetString(common.ObjToString(v["email"]))
  787. row.AddCell().SetString(common.ObjToString(v["company"]))
  788. row.AddCell().SetString(common.ObjToString(v["data_requirement"]))
  789. row.AddCell().SetString(common.ObjToString(v["source"]))
  790. row.AddCell().SetString(common.ObjToString(v["interest"]))
  791. row.AddCell().SetString(gconv.Time(gconv.Int64(v["createtime"])).Format(date.Date_Full_Layout))
  792. //增加客户需求
  793. }
  794. email := db.AdvisoryCommitteeMail
  795. dir := "./xlsx/zx/" + fileName + ".xlsx"
  796. err := xf.Save(dir)
  797. if err != nil {
  798. log.Println("xls error", err, dir)
  799. } else {
  800. gmail := &mail.GmailAuth{
  801. SmtpHost: "smtp.exmail.qq.com",
  802. SmtpPort: 465,
  803. User: "public03@topnet.net.cn",
  804. Pwd: "ue9Rg9Sf4CVtdm5a",
  805. }
  806. for _, v := range email {
  807. status := mail.GSendMail_q("剑鱼标讯", v, "", "", fileName, detailName, dir, fileName+".xlsx", gmail)
  808. if status {
  809. log.Println("send mail success", fileName, v)
  810. }
  811. }
  812. }
  813. }
  814. common.WriteSysConfig(&cfg)
  815. log.Println("咨询部线索定时任务结束")
  816. }
  817. // 市场部线索
  818. func marketCustomer() {
  819. runOk := getRunOk()
  820. if !runOk {
  821. log.Println("不是工作日,任务暂停")
  822. return
  823. }
  824. log.Println("市场部线索定时任务开始")
  825. dataArr := []map[string]interface{}{}
  826. filterArr := []string{"-pc", "-app", "-wx", "-h5"}
  827. sourceMap := map[string]string{} //根据留资维表:tidb/Jianyu_subjectdb/d_saleleads_code
  828. saleSource := TiDb.SelectBySql(`SELECT source,name FROM d_saleleads_code WHERE department LIKE '%市场组%' AND is_delete = 1`)
  829. if saleSource != nil && len(*saleSource) > 0 {
  830. for _, v := range *saleSource {
  831. source := common.ObjToString(v["source"])
  832. name := common.ObjToString(v["name"])
  833. for _, s := range filterArr {
  834. name = strings.ReplaceAll(name, s, "")
  835. }
  836. sourceMap[source] = name
  837. }
  838. }
  839. nowTime := time.Now().Format(date.Date_Full_Layout)
  840. marketSaleTime := cfg.MarketSaleTime
  841. if marketSaleTime == 0 {
  842. marketSaleTime = time.Now().Unix()
  843. }
  844. abhList := []map[string]interface{}{}
  845. saleleadsData, ok := Mgo.Find("saleLeads", map[string]interface{}{"createtime": map[string]interface{}{"$gte": marketSaleTime}}, `{"phone":1,"createtime":1}`, nil, false, -1, -1)
  846. if ok && saleleadsData != nil && len(*saleleadsData) > 0 {
  847. data := FindBatchData("sc")
  848. for _, v := range *saleleadsData {
  849. sources := common.ObjToString(v["source"])
  850. userid := common.ObjToString(v["userid"])
  851. uid := ""
  852. if !mongodb.IsObjectIdHex(userid) {
  853. userMapping := TiDb.FindOne("dwd_f_userbase_id_mapping", map[string]interface{}{"position_id": userid}, "", "")
  854. if userMapping != nil && len(*userMapping) > 0 {
  855. userid = common.ObjToString((*userMapping)["userid"])
  856. uid = common.ObjToString((*userMapping)["uid"])
  857. }
  858. } else {
  859. userMapping := TiDb.FindOne("dwd_f_userbase_id_mapping", map[string]interface{}{"userid": userid}, "", "")
  860. if userMapping != nil && len(*userMapping) > 0 {
  861. userid = common.ObjToString((*userMapping)["userid"])
  862. uid = common.ObjToString((*userMapping)["uid"])
  863. }
  864. }
  865. if sourceMap[sources] != "" {
  866. company := common.ObjToString(v["company"])
  867. phone := common.ObjToString(v["phone"])
  868. if IsInternal(phone) {
  869. continue
  870. }
  871. job := common.ObjToString(v["position"])
  872. username := common.ObjToString(v["name"])
  873. email := common.ObjToString(v["mail"])
  874. interest := common.ObjToString(v["interest"])
  875. data_requirement := common.ObjToString(v["data_requirement"])
  876. source := sourceMap[sources]
  877. belongTo, usernickname := "市场组", ""
  878. userData := TiDb.FindOne("dwd_f_userbase_baseinfo", map[string]interface{}{"uid": uid}, "", "")
  879. if userData != nil {
  880. usernickname = common.ObjToString((*userData)["nickname"])
  881. bt := common.ObjToString((*userData)["belong_to"])
  882. if strings.HasPrefix(bt, "03") || bt == "0102" {
  883. continue
  884. }
  885. }
  886. key := fmt.Sprintf("%s_%s", source, phone)
  887. if _, ok := data[key]; ok {
  888. continue
  889. }
  890. s_sourceid := common.ObjToString((*userData)["s_sourceid"])
  891. data[key] = true
  892. if s_sourceid == db.Sourceid {
  893. abhList = append(abhList, map[string]interface{}{
  894. "createTime": nowTime,
  895. "lastUpdateTime": nowTime,
  896. "createtime": v["createtime"],
  897. "uid": uid,
  898. "userid": userid,
  899. "username": username,
  900. "usernickname": usernickname,
  901. "company": company,
  902. "job": job,
  903. "phone": phone,
  904. "email": email,
  905. "source": source,
  906. "belongTo": belongTo,
  907. "interest": interest,
  908. "data_requirement": data_requirement,
  909. "branch": v["branch"],
  910. "s_sourceid": s_sourceid,
  911. })
  912. if gconv.Int64(v["createtime"]) > marketSaleTime {
  913. marketSaleTime = gconv.Int64(v["createtime"])
  914. }
  915. continue
  916. }
  917. dataArr = append(dataArr, map[string]interface{}{
  918. "createTime": nowTime,
  919. "lastUpdateTime": nowTime,
  920. "createtime": v["createtime"],
  921. "uid": uid,
  922. "userid": userid,
  923. "username": username,
  924. "usernickname": usernickname,
  925. "company": company,
  926. "job": job,
  927. "phone": phone,
  928. "email": email,
  929. "source": source,
  930. "belongTo": belongTo,
  931. "interest": interest,
  932. "data_requirement": data_requirement,
  933. "branch": v["branch"],
  934. "s_sourceid": s_sourceid,
  935. })
  936. }
  937. if gconv.Int64(v["createtime"]) > marketSaleTime {
  938. marketSaleTime = gconv.Int64(v["createtime"])
  939. }
  940. }
  941. if len(abhList) > 0 {
  942. //安博会发邮件高翔
  943. ABHEmail("market", abhList)
  944. }
  945. keyContent := fmt.Sprintf("data_%s_%s", time.Now().Format("2006-01-02"), "sc")
  946. redis.Put("newother", keyContent, data, 86400)
  947. }
  948. cfg.MarketSaleTime = marketSaleTime
  949. xlsxArr := []string{"姓名", "联系人电话", "公司名称", "职位", "部门", "销售线索来源", "留资时间"}
  950. if len(dataArr) > 0 {
  951. //排序:首先按照“联系方式”排序,即同1个用户的留资放在一起,其次按照留资时间正序排序。
  952. batch := FindBatch("sc")
  953. fileName, detailName := "商务合作销售线索 "+time.Now().Format(date.Date_Short_Layout)+"-"+batch, ""
  954. xf := xlsx.NewFile()
  955. style := xlsx.NewStyle()
  956. style.Font.Size = 12
  957. style.Font.Bold = true
  958. style.Alignment.Vertical = "center"
  959. style.Alignment.Horizontal = "center"
  960. detailName = "今日新增商务合作销售线索,请查收附件,及时跟进。"
  961. sh, _ := xf.AddSheet("线索数据")
  962. row1 := sh.AddRow()
  963. for _, x := range xlsxArr {
  964. cell := row1.AddCell()
  965. cell.SetString(x)
  966. cell.SetStyle(style)
  967. }
  968. for _, v := range dataArr {
  969. row := sh.AddRow()
  970. row.AddCell().SetString(common.ObjToString(v["username"]))
  971. row.AddCell().SetString(common.ObjToString(v["phone"]))
  972. row.AddCell().SetString(common.ObjToString(v["company"]))
  973. row.AddCell().SetString(common.ObjToString(v["job"]))
  974. row.AddCell().SetString(common.ObjToString(v["branch"]))
  975. row.AddCell().SetString(common.ObjToString(v["source"]))
  976. row.AddCell().SetString(gconv.Time(gconv.Int64(v["createtime"])).Format(date.Date_Full_Layout))
  977. //增加客户需求
  978. }
  979. email := db.MarketSaleMail
  980. dir := "./xlsx/sc/" + fileName + ".xlsx"
  981. err := xf.Save(dir)
  982. if err != nil {
  983. log.Println("xls error", err, dir)
  984. } else {
  985. gmail := &mail.GmailAuth{
  986. SmtpHost: "smtp.exmail.qq.com",
  987. SmtpPort: 465,
  988. User: "public03@topnet.net.cn",
  989. Pwd: "ue9Rg9Sf4CVtdm5a",
  990. }
  991. status := mail.GSendMail_q("剑鱼标讯", email, "", "", fileName, detailName, dir, fileName+".xlsx", gmail)
  992. if status {
  993. log.Println("send mail success", fileName, email)
  994. }
  995. }
  996. }
  997. common.WriteSysConfig(&cfg)
  998. log.Println("大客户线索定时任务结束")
  999. }
  1000. func eventReg() {
  1001. lastEventRegTime := cfg.LastEventRegTime
  1002. sql := fmt.Sprintf(`select * from exhibition_sign_up where is_del = 0 and update_time > "%s" order by update_time asc`, lastEventRegTime)
  1003. log.Println("活动报名表定时任务开始", sql)
  1004. data := Jyactivities.SelectBySql(sql)
  1005. if data != nil && *data != nil && len(*data) > 0 {
  1006. for _, v := range *data {
  1007. ok1, ok2, _ := FormatData(v, "eventReg")
  1008. if !ok1 {
  1009. common.WriteSysConfig(&cfg)
  1010. log.Println("线索卡点", "eventReg", v, lastEventRegTime)
  1011. } else {
  1012. if !ok2 {
  1013. log.Println("用户分配已达上限", "eventReg", v, lastEventRegTime)
  1014. common.WriteSysConfig(&cfg)
  1015. }
  1016. }
  1017. cfg.LastEventRegTime = common.ObjToString(v["update_time"])
  1018. }
  1019. }
  1020. common.WriteSysConfig(&cfg)
  1021. log.Println("活动报名表定时任务结束")
  1022. }
  1023. func saveHlyj(belong_to, item, phone, name, sourceName, cluename, position, nowTime string, isGroup, isCommerce int) {
  1024. if strings.HasPrefix(belong_to, "02") && item == "eventReg" {
  1025. saveMap := map[string]interface{}{
  1026. "unique_id": phone,
  1027. "phone": phone,
  1028. "username": name,
  1029. "source": sourceName,
  1030. "status999": "status5",
  1031. "company": cluename,
  1032. "job": position,
  1033. "belongTo": "市场部",
  1034. "createTime": nowTime,
  1035. "lastUpdateTime": nowTime,
  1036. }
  1037. token := getToken()
  1038. updateData := map[string]interface{}{
  1039. "dbType": "0001",
  1040. "customerList": []map[string]interface{}{saveMap},
  1041. }
  1042. dataByte, _ := json.Marshal(&updateData)
  1043. url := `https://a1.7x24cc.com/commonInte?flag=1007&account=N000000029739&accessToken=` + token + `&json=` + url.QueryEscape(string(dataByte))
  1044. bs, err := doGet(url)
  1045. if err != nil {
  1046. log.Println("调用接口失败")
  1047. } else {
  1048. resMap := common.StringToMap(string(bs))
  1049. if resMap["success"] != nil && resMap["success"].(bool) {
  1050. saveMap["company_nature"] = isGroup
  1051. saveMap["company_verification"] = isCommerce
  1052. TiDbData.Insert("customer", saveMap)
  1053. } else {
  1054. log.Println("新增线索失败")
  1055. }
  1056. }
  1057. }
  1058. }
  1059. func FindBatch(moudle string) string {
  1060. now := time.Now().Format("2006-01-02")
  1061. key := fmt.Sprintf("batch_%s_%s", now, moudle)
  1062. yesterday := time.Now().AddDate(0, 0, -1).Format("2006-01-02")
  1063. yesterdayKey := fmt.Sprintf("batch_%s_%s", yesterday, moudle)
  1064. if ok, _ := redis.Exists("newother", yesterdayKey); ok {
  1065. //删除之前数据
  1066. redis.Del("newother", yesterdayKey)
  1067. }
  1068. batch := redis.Incr("newother", key)
  1069. return fmt.Sprintf("%04d", batch)
  1070. }
  1071. func FindBatchData(moudle string) map[string]interface{} {
  1072. now := time.Now().Format("2006-01-02")
  1073. //数据提取
  1074. keyContent := fmt.Sprintf("data_%s_%s", now, moudle)
  1075. data := redis.Get("newother", keyContent)
  1076. if data == nil {
  1077. return make(map[string]interface{})
  1078. } else {
  1079. return gconv.Map(data)
  1080. }
  1081. }