everything.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. package main
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "log"
  6. "net/url"
  7. "strings"
  8. "time"
  9. "app.yhyue.com/moapp/jybase/mail"
  10. "github.com/tealeg/xlsx"
  11. "app.yhyue.com/moapp/jybase/date"
  12. dates "app.yhyue.com/moapp/jybase/date"
  13. "app.yhyue.com/moapp/jybase/mongodb"
  14. "app.yhyue.com/moapp/jybase/common"
  15. )
  16. func everythingSync() {
  17. lastEverythingTime := cfg.LastEverythingTime
  18. nowTime := time.Now().Format(dates.Date_Full_Layout)
  19. sql := fmt.Sprintf(`select * from user_source where channel_code = "JyChCoopA" and create_time > "%s" order by create_time asc`, lastEverythingTime)
  20. log.Println("三方渠道数据定时任务开始", sql)
  21. data := ThirdParty.SelectBySql(sql)
  22. if data != nil && *data != nil && len(*data) > 0 {
  23. for _, v := range *data {
  24. user_id := common.ObjToString(v["user_id"])
  25. position_id := common.Int64All(v["position_id"])
  26. phone := common.ObjToString(v["phone"])
  27. state := common.IntAll(v["state"])
  28. user_mold, is_assign, is_transfer, last_login_time, registe_time, mailbox, source, clueId, order_type := 4, 0, 0, "", "", "", "", int64(0), ""
  29. owner, sales_lead_phone, sales_ent_name, sales_position, sales_dep, data_request, unique_id, belongTo, sales_leads_source := "", "", "", "", "", "", "", "", ""
  30. cData := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"phone": phone}, "", "")
  31. if cData != nil {
  32. is_assign = common.IntAll((*cData)["is_assign"])
  33. is_transfer = common.IntAll((*cData)["is_transfer"])
  34. clueId = common.Int64All((*cData)["id"])
  35. }
  36. //
  37. udata := TiDb.FindOne("dwd_f_userbase_baseinfo", map[string]interface{}{"userid": user_id}, "", "")
  38. if udata != nil {
  39. userSource := common.ObjToString((*udata)["source"])
  40. if userSource == "0102" {
  41. continue
  42. }
  43. }
  44. //
  45. cuData := TiDbData.FindOne("customer", map[string]interface{}{"phone": phone}, "", "")
  46. if cuData != nil {
  47. owner = common.ObjToString((*cuData)["owner"])
  48. unique_id = common.ObjToString((*cuData)["unique_id"])
  49. belongTo = common.ObjToString((*cuData)["belongTo"])
  50. }
  51. vData := TiDb.FindOne("dwd_f_userbase_visit_info", map[string]interface{}{"userid": user_id}, "", "")
  52. if vData != nil {
  53. last_login_time = common.ObjToString((*vData)["date"])
  54. }
  55. dData := Mysql.Find("dataexport_order", map[string]interface{}{"user_id": user_id}, "", "", -1, -1)
  56. if dData != nil && len(*dData) > 0 {
  57. pMap := map[string]string{}
  58. pArr := []string{}
  59. for _, v := range *dData {
  60. product_type := common.ObjToString(v["product_type"])
  61. pMap[product_type] = "1"
  62. }
  63. for k := range pMap {
  64. pArr = append(pArr, k)
  65. }
  66. if len(pArr) > 0 {
  67. order_type = strings.Join(pArr, ",")
  68. }
  69. }
  70. uData, ok := Mgo.FindOne("user", map[string]interface{}{"_id": mongodb.StringTOBsonId(user_id)})
  71. if ok && uData != nil {
  72. l_registedate := common.Int64All((*uData)["l_registedate"])
  73. registe_time = time.Unix(l_registedate, 0).Format(dates.Date_Full_Layout)
  74. }
  75. sData, oks := Mgo.Find("saleLeads", map[string]interface{}{"userid": user_id}, `{"_id":-1}`, nil, false, 0, 1)
  76. if oks && sData != nil {
  77. if len(*sData) > 0 {
  78. sDatas := (*sData)[0]
  79. sales_lead_phone = common.ObjToString(sDatas["phone"])
  80. sales_position = common.ObjToString(sDatas["position"])
  81. sales_ent_name = common.ObjToString(sDatas["company"])
  82. sales_dep = common.ObjToString(sDatas["branch"])
  83. if sales_dep == "" {
  84. sales_dep = common.ObjToString(sDatas["department"])
  85. }
  86. data_request = common.ObjToString(sDatas["data_requirement"])
  87. mailbox = common.ObjToString(sDatas["mail"])
  88. source = common.ObjToString(sDatas["interest"])
  89. }
  90. }
  91. if state == 1 {
  92. sales_leads_source = "一切都好登录"
  93. if is_assign == 1 || is_transfer == 1 || owner != "" {
  94. user_mold = 1
  95. } else {
  96. user_mold = 2
  97. }
  98. } else if state == 2 {
  99. sales_leads_source = "一切都好注册"
  100. if is_assign == 1 || is_transfer == 1 || owner != "" {
  101. user_mold = 3
  102. } else {
  103. user_mold = 4
  104. }
  105. }
  106. if owner == "" && unique_id != "" && belongTo == "市场部" {
  107. token := getToken()
  108. if token != "" {
  109. sss := url.QueryEscape("合作渠道一切都好")
  110. 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`
  111. bs, err := doGet(urls)
  112. if err != nil {
  113. log.Println("调用接口失败", unique_id, err)
  114. }
  115. resMap := common.StringToMap(string(bs))
  116. if resMap["success"] != nil && resMap["success"].(bool) {
  117. ok := TiDbData.Update("customer", map[string]interface{}{"unique_id": unique_id}, map[string]interface{}{"empNo": "8049", "owner": "8049", "source": "合作渠道一切都好"})
  118. if ok {
  119. log.Println("更新成功", unique_id)
  120. } else {
  121. log.Println("更新失败", unique_id)
  122. }
  123. } else {
  124. log.Println("调用接口失败!!", unique_id)
  125. }
  126. }
  127. }
  128. if ThirdParty.Count("user_channel_info", map[string]interface{}{"user_id": user_id}) > 0 {
  129. ThirdParty.Update("user_channel_info", map[string]interface{}{"user_id": user_id}, map[string]interface{}{
  130. "user_mold": user_mold,
  131. "last_login_time": common.If(last_login_time != "", last_login_time, nil),
  132. "sales_lead_phone": sales_lead_phone,
  133. "sales_ent_name": sales_ent_name,
  134. "sales_position": sales_position,
  135. "sales_dep": sales_dep,
  136. "sales_leads_source": sales_leads_source,
  137. "mailbox": mailbox,
  138. "order_type": order_type,
  139. "data_request": data_request,
  140. "source": source,
  141. "update_time": nowTime,
  142. })
  143. } else {
  144. ThirdParty.Insert("user_channel_info", map[string]interface{}{
  145. "user_id": user_id,
  146. "registe_time": registe_time,
  147. "phone": phone,
  148. "user_mold": user_mold,
  149. "last_login_time": common.If(last_login_time != "", last_login_time, nil),
  150. "sales_lead_phone": sales_lead_phone,
  151. "sales_ent_name": sales_ent_name,
  152. "sales_position": sales_position,
  153. "sales_dep": sales_dep,
  154. "sales_leads_source": sales_leads_source,
  155. "order_type": order_type,
  156. "mailbox": mailbox,
  157. "data_request": data_request,
  158. "source": source,
  159. "update_time": nowTime,
  160. })
  161. }
  162. if clueId > 0 && is_assign != 1 && is_transfer != 1 {
  163. TiDb.Update("dwd_f_userbase_baseinfo", map[string]interface{}{"userid": user_id}, map[string]interface{}{"belong_to": "0301"})
  164. TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"phone": phone}, map[string]interface{}{"is_assign": -1})
  165. TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  166. "clue_id": clueId,
  167. "position_id": common.If(position_id > 0, position_id, -1),
  168. "change_type": "退出公海",
  169. "new_value": "通过合作渠道一切就好" + fmt.Sprint(common.If(user_mold == 1 || user_mold == 2, "登录", "注册")),
  170. "createtime": nowTime,
  171. "BCPCID": common.GetRandom(32),
  172. "operator_id": -1,
  173. })
  174. }
  175. }
  176. cfg.LastEverythingTime = common.ObjToString((*data)[len(*data)-1]["create_time"])
  177. }
  178. common.WriteSysConfig(&cfg)
  179. log.Println("三方渠道数据定时任务结束")
  180. }
  181. func saveEverything(user_id, phone, item, sourceName, sourceCode string) bool {
  182. nowTime, isOk := time.Now().Format(dates.Date_Full_Layout), false
  183. user_mold, is_assign, is_transfer, last_login_time, registe_time, mailbox, source, order_type, sales_leads_source := 4, 0, 0, "", "", "", "", "", ""
  184. owner, sales_lead_phone, sales_ent_name, sales_position, sales_dep, data_request, unique_id, belongTo, clueId, position_id := "", "", "", "", "", "", "", "", int64(0), int64(0)
  185. cData := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"phone": phone}, "", "")
  186. if cData != nil {
  187. is_assign = common.IntAll((*cData)["is_assign"])
  188. is_transfer = common.IntAll((*cData)["is_transfer"])
  189. clueId = common.Int64All((*cData)["is_transfer"])
  190. position_id = common.Int64All((*cData)["position_id"])
  191. }
  192. cuData := TiDbData.FindOne("customer", map[string]interface{}{"phone": phone}, "", "")
  193. if cuData != nil {
  194. unique_id = common.ObjToString((*cuData)["unique_id"])
  195. owner = common.ObjToString((*cuData)["owner"])
  196. }
  197. dData := Mysql.Find("dataexport_order", map[string]interface{}{"user_id": user_id}, "", "", -1, -1)
  198. if dData != nil && len(*dData) > 0 {
  199. pMap := map[string]string{}
  200. pArr := []string{}
  201. for _, v := range *dData {
  202. product_type := common.ObjToString(v["product_type"])
  203. pMap[product_type] = "1"
  204. }
  205. for k := range pMap {
  206. pArr = append(pArr, k)
  207. }
  208. if len(pArr) > 0 {
  209. order_type = strings.Join(pArr, ",")
  210. }
  211. }
  212. vData := TiDb.FindOne("dwd_f_userbase_visit_info", map[string]interface{}{"userid": user_id}, "", "")
  213. if vData != nil {
  214. last_login_time = common.ObjToString((*vData)["date"])
  215. }
  216. uData, ok := Mgo.FindOne("user", map[string]interface{}{"_id": mongodb.StringTOBsonId(user_id)})
  217. if ok && uData != nil {
  218. l_registedate := common.Int64All((*uData)["l_registedate"])
  219. registe_time = time.Unix(l_registedate, 0).Format(dates.Date_Full_Layout)
  220. }
  221. if item == "orders" {
  222. sales_leads_source = "订单未支付"
  223. } else if item == "users" {
  224. return false
  225. } else if item == "saleLeads" {
  226. sales_leads_source = sourceName
  227. } else {
  228. sales_leads_source = "用户留资"
  229. }
  230. query := map[string]interface{}{"userid": user_id}
  231. if sourceCode != "" {
  232. query["source"] = sourceCode
  233. }
  234. sData, oks := Mgo.Find("saleLeads", query, `{"_id":-1}`, nil, false, 0, 1)
  235. if oks && sData != nil {
  236. if len(*sData) > 0 {
  237. sDatas := (*sData)[0]
  238. sales_lead_phone = common.ObjToString(sDatas["phone"])
  239. sales_position = common.ObjToString(sDatas["position"])
  240. sales_ent_name = common.ObjToString(sDatas["company"])
  241. sales_dep = common.ObjToString(sDatas["branch"])
  242. if sales_dep == "" {
  243. sales_dep = common.ObjToString(sDatas["department"])
  244. }
  245. data_request = common.ObjToString(sDatas["data_requirement"])
  246. mailbox = common.ObjToString(sDatas["mail"])
  247. source = common.ObjToString(sDatas["interest"])
  248. }
  249. }
  250. if is_assign == 1 || is_transfer == 1 || owner != "" {
  251. user_mold = 1
  252. } else {
  253. user_mold = 2
  254. }
  255. if owner == "" && unique_id != "" && belongTo == "市场部" {
  256. token := getToken()
  257. if token != "" {
  258. sss := url.QueryEscape("合作渠道一切都好")
  259. 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`
  260. bs, err := doGet(urls)
  261. if err != nil {
  262. log.Println("调用接口失败", unique_id, err)
  263. }
  264. resMap := common.StringToMap(string(bs))
  265. if resMap["success"] != nil && resMap["success"].(bool) {
  266. ok := TiDbData.Update("customer", map[string]interface{}{"unique_id": unique_id}, map[string]interface{}{"empNo": "8049", "owner": "8049", "source": "合作渠道一切都好"})
  267. if ok {
  268. log.Println("更新成功", unique_id)
  269. } else {
  270. log.Println("更新失败", unique_id)
  271. }
  272. } else {
  273. log.Println("调用接口失败!!", unique_id)
  274. }
  275. }
  276. }
  277. if ThirdParty.Count("user_channel_info", map[string]interface{}{"user_id": user_id}) > 0 {
  278. ThirdParty.Update("user_channel_info", map[string]interface{}{"user_id": user_id}, map[string]interface{}{
  279. "user_mold": user_mold,
  280. "last_login_time": common.If(last_login_time != "", last_login_time, nil),
  281. "sales_lead_phone": sales_lead_phone,
  282. "sales_ent_name": sales_ent_name,
  283. "sales_position": sales_position,
  284. "sales_dep": sales_dep,
  285. "sales_leads_source": sales_leads_source,
  286. "mailbox": mailbox,
  287. "data_request": data_request,
  288. "source": source,
  289. "order_type": order_type,
  290. "update_time": nowTime,
  291. })
  292. } else {
  293. ThirdParty.Insert("user_channel_info", map[string]interface{}{
  294. "user_id": user_id,
  295. "registe_time": registe_time,
  296. "phone": phone,
  297. "user_mold": user_mold,
  298. "last_login_time": common.If(last_login_time != "", last_login_time, nil),
  299. "sales_lead_phone": sales_lead_phone,
  300. "sales_ent_name": sales_ent_name,
  301. "sales_position": sales_position,
  302. "sales_dep": sales_dep,
  303. "sales_leads_source": sales_leads_source,
  304. "mailbox": mailbox,
  305. "data_request": data_request,
  306. "order_type": order_type,
  307. "source": source,
  308. "update_time": nowTime,
  309. })
  310. }
  311. if clueId > 0 && is_assign != 1 && is_transfer != 1 {
  312. TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"phone": phone}, map[string]interface{}{"is_assign": -1})
  313. TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
  314. "clue_id": clueId,
  315. "position_id": common.If(position_id > 0, position_id, -1),
  316. "change_type": "退出公海",
  317. "new_value": "通过合作渠道一切就好登录",
  318. "createtime": nowTime,
  319. "BCPCID": common.GetRandom(32),
  320. "operator_id": -1,
  321. })
  322. } else if is_assign == 1 || is_transfer == 1 {
  323. isOk = true
  324. }
  325. return isOk
  326. }
  327. // 大客户线索-发邮件
  328. func bigCustomer() {
  329. log.Println("大客户线索定时任务开始")
  330. dataArr := []map[string]interface{}{}
  331. filterArr := []string{"-pc", "-app", "-wx", "-h5"}
  332. sourceMap := map[string]string{} //根据留资维表:tidb/Jianyu_subjectdb/d_saleleads_code
  333. saleSource := TiDb.SelectBySql(`SELECT source,name FROM d_saleleads_code WHERE department LIKE '%大客户%' AND is_delete = 1`)
  334. if saleSource != nil && len(*saleSource) > 0 {
  335. for _, v := range *saleSource {
  336. source := common.ObjToString(v["source"])
  337. name := common.ObjToString(v["name"])
  338. for _, s := range filterArr {
  339. name = strings.ReplaceAll(name, s, "")
  340. }
  341. sourceMap[source] = name
  342. }
  343. }
  344. nowTime := time.Now().Format(date.Date_Full_Layout)
  345. nowTimes := time.Now().AddDate(0, 0, -1)
  346. startTime := time.Date(nowTimes.Year(), nowTimes.Month(), nowTimes.Day(), 0, 0, 0, 0, time.Local).Unix()
  347. saleleadsData, ok := Mgo.Find("saleLeads", map[string]interface{}{"createtime": map[string]interface{}{"$gte": startTime, "$lt": startTime + 86400}}, nil, nil, false, -1, -1)
  348. if ok && saleleadsData != nil && len(*saleleadsData) > 0 {
  349. for _, v := range *saleleadsData {
  350. sources := common.ObjToString(v["source"])
  351. userid := common.ObjToString(v["userid"])
  352. uid := ""
  353. if !mongodb.IsObjectIdHex(userid) {
  354. userMapping := TiDb.FindOne("dwd_f_userbase_id_mapping", map[string]interface{}{"position_id": userid}, "", "")
  355. if userMapping != nil && len(*userMapping) > 0 {
  356. userid = common.ObjToString((*userMapping)["userid"])
  357. uid = common.ObjToString((*userMapping)["uid"])
  358. }
  359. }
  360. if sourceMap[sources] != "" {
  361. company := common.ObjToString(v["company"])
  362. phone := common.ObjToString(v["phone"])
  363. job := common.ObjToString(v["position"])
  364. username := common.ObjToString(v["name"])
  365. email := common.ObjToString(v["mail"])
  366. interest := common.ObjToString(v["interest"])
  367. data_requirement := common.ObjToString(v["data_requirement"])
  368. source := sourceMap[sources]
  369. belongTo, usernickname := "大客户", ""
  370. userData := TiDb.FindOne("dwd_f_userbase_baseinfo", map[string]interface{}{"uid": uid}, "", "")
  371. if userData != nil {
  372. usernickname = common.ObjToString((*userData)["nickname"])
  373. bt := common.ObjToString((*userData)["belong_to"])
  374. if strings.HasPrefix(bt, "03") || bt == "0102" {
  375. continue
  376. }
  377. }
  378. dataArr = append(dataArr, map[string]interface{}{
  379. "createTime": nowTime,
  380. "lastUpdateTime": nowTime,
  381. "uid": uid,
  382. "userid": userid,
  383. "username": username,
  384. "usernickname": usernickname,
  385. "company": company,
  386. "job": job,
  387. "phone": phone,
  388. "email": email,
  389. "source": source,
  390. "belongTo": belongTo,
  391. "interest": interest,
  392. "data_requirement": data_requirement,
  393. })
  394. }
  395. }
  396. }
  397. orderData := Mysql.SelectBySql(`SELECT * FROM dataexport_order WHERE create_time >= "` + time.Now().AddDate(0, 0, -1).Format(date.Date_Short_Layout) + " 00:00:00" + `" AND create_time < "` + time.Now().Format(date.Date_Short_Layout) + " 00:00:00" + `" AND (product_type = '历史数据' or product_type = '数据流量包') AND order_status IN (0,1) AND salesperson IS NULL AND is_backstage_order = 0`)
  398. if orderData != nil && len(*orderData) > 0 {
  399. for _, v := range *orderData {
  400. phone := common.ObjToString(v["user_phone"])
  401. order_status := common.IntAll(v["order_status"])
  402. product_type := common.ObjToString(v["product_type"])
  403. userData := TiDb.FindOne("dwd_f_userbase_baseinfo", map[string]interface{}{"phone": phone}, "", "")
  404. username, usernickname, userid, uid, source, payorderinfo, unpayorderinfo := "", "", "", "", "", "", ""
  405. if userData != nil {
  406. username = common.ObjToString((*userData)["name"])
  407. usernickname = common.ObjToString((*userData)["nickname"])
  408. uid = common.ObjToString((*userData)["uid"])
  409. userid = common.ObjToString((*userData)["userid"])
  410. bt := common.ObjToString((*userData)["belong_to"])
  411. if strings.HasPrefix(bt, "03") || bt == "0102" {
  412. continue
  413. }
  414. }
  415. if product_type == "历史数据" {
  416. if order_status == 0 {
  417. source = "线上历史数据导出未支付订单"
  418. unpayorderinfo = "历史数据"
  419. } else {
  420. source = "线上历史数据导出已支付订单"
  421. payorderinfo = "历史数据" + fmt.Sprint(common.IntAll(v["pay_money"])/100)
  422. }
  423. } else {
  424. if order_status == 0 {
  425. source = "线上数据流量包未支付订单"
  426. unpayorderinfo = "数据流量包"
  427. } else {
  428. source = "线上数据流量包已支付订单"
  429. payorderinfo = "数据流量包" + fmt.Sprint(common.IntAll(v["pay_money"])/100)
  430. }
  431. }
  432. dataArr = append(dataArr, map[string]interface{}{
  433. "createTime": nowTime,
  434. "lastUpdateTime": nowTime,
  435. "phone": phone,
  436. "username": username,
  437. "usernickname": usernickname,
  438. "uid": uid,
  439. "userid": userid,
  440. "company": v["company_name"],
  441. "email": v["user_mail"],
  442. "belongTo": "大客户",
  443. "source": source,
  444. "data_count": v["data_count"],
  445. "unpayorderinfo": unpayorderinfo,
  446. "payorderinfo": payorderinfo, //增加客户需求
  447. })
  448. }
  449. }
  450. xlsxArr := []string{"用户昵称", "姓名", "公司名称", "职位", "联系人电话", "购买条数", "用户邮箱", "已支付订单信息", "未支付订单类型", "销售线索来源", "具体来源", "数据需求"}
  451. fileName, detailName := time.Now().Format(date.Date_Short_Layout)+"大客户销售线索", ""
  452. if len(dataArr) > 0 {
  453. bigData := TiDb.SelectBySql("select * from dwd_f_crm_clue_big_autodraw_record")
  454. if bigData != nil && len(*bigData) > 0 {
  455. cdata := *bigData
  456. bigArr := map[string][]map[string]interface{}{}
  457. for _, v := range dataArr {
  458. mincount := common.IntAll(cdata[0]["count"])
  459. minindex := 0
  460. minemail := ""
  461. for kk, vv := range cdata {
  462. vcount := common.IntAll(vv["count"])
  463. vemail := common.ObjToString(vv["email"])
  464. if vcount <= mincount {
  465. minindex = kk
  466. mincount = vcount
  467. minemail = vemail
  468. }
  469. }
  470. bigArr[minemail] = append(bigArr[minemail], v)
  471. cdata[minindex]["count"] = mincount + 1
  472. name := common.ObjToString(cdata[minindex]["name"])
  473. TiDb.UpdateOrDeleteBySql(`update dwd_f_crm_clue_big_autodraw_record set count = count + 1 where name = ?`, name)
  474. }
  475. for k, vb := range bigArr {
  476. xf := xlsx.NewFile()
  477. style := xlsx.NewStyle()
  478. style.Font.Size = 12
  479. style.Font.Bold = true
  480. style.Alignment.Vertical = "center"
  481. style.Alignment.Horizontal = "center"
  482. detailName = time.Now().Format(date.Date_Short_Layout) + "数据详情请查看附件"
  483. sh, _ := xf.AddSheet("线索数据")
  484. row1 := sh.AddRow()
  485. for _, x := range xlsxArr {
  486. cell := row1.AddCell()
  487. cell.SetString(x)
  488. cell.SetStyle(style)
  489. }
  490. for _, v := range vb {
  491. row := sh.AddRow()
  492. row.AddCell().SetString(common.ObjToString(v["usernickname"]))
  493. row.AddCell().SetString(common.ObjToString(v["username"]))
  494. row.AddCell().SetString(common.ObjToString(v["company"]))
  495. row.AddCell().SetString(common.ObjToString(v["job"]))
  496. row.AddCell().SetString(common.ObjToString(v["phone"]))
  497. row.AddCell().SetValue(common.IntAll(v["data_count"]))
  498. row.AddCell().SetString(common.ObjToString(v["email"]))
  499. row.AddCell().SetString(common.ObjToString(v["payorderinfo"]))
  500. row.AddCell().SetString(common.ObjToString(v["unpayorderinfo"]))
  501. row.AddCell().SetString(common.ObjToString(v["source"]))
  502. row.AddCell().SetString(common.ObjToString(v["interest"]))
  503. row.AddCell().SetString(common.ObjToString(v["data_requirement"]))
  504. //增加客户需求
  505. }
  506. email := k
  507. // email = "xuzhiheng@jianyu360.com"
  508. dir := "./xlsx/" + fileName + ".xlsx"
  509. err := xf.Save(dir)
  510. if err != nil {
  511. log.Println("xls error", err, dir)
  512. } else {
  513. gmail := &mail.GmailAuth{
  514. SmtpHost: "smtp.exmail.qq.com",
  515. SmtpPort: 465,
  516. User: "public03@topnet.net.cn",
  517. Pwd: "ue9Rg9Sf4CVtdm5a",
  518. }
  519. status := mail.GSendMail_q("剑鱼标讯", email, "", "", fileName, detailName, dir, fileName+".xlsx", gmail)
  520. if status {
  521. log.Println("send mail success", fileName, email)
  522. }
  523. }
  524. }
  525. }
  526. }
  527. log.Println("大客户线索定时任务结束")
  528. }
  529. func eventReg() {
  530. lastEventRegTime := cfg.LastEventRegTime
  531. sql := fmt.Sprintf(`select * from exhibition_sign_up where is_del = 0 and update_time > "%s" order by update_time asc`, lastEventRegTime)
  532. log.Println("活动报名表定时任务开始", sql)
  533. data := Jyactivities.SelectBySql(sql)
  534. if data != nil && *data != nil && len(*data) > 0 {
  535. for _, v := range *data {
  536. ok1, ok2 := FormatData(v, "eventReg")
  537. if !ok1 {
  538. common.WriteSysConfig(&cfg)
  539. break
  540. } else {
  541. if !ok2 {
  542. log.Println("用户分配已达上限")
  543. common.WriteSysConfig(&cfg)
  544. break
  545. }
  546. }
  547. cfg.LastEventRegTime = common.ObjToString(v["update_time"])
  548. }
  549. }
  550. common.WriteSysConfig(&cfg)
  551. log.Println("活动报名表定时任务结束")
  552. }
  553. func saveHlyj(belong_to, item, phone, name, sourceName, cluename, position, nowTime string, isGroup, isCommerce int) {
  554. if strings.HasPrefix(belong_to, "02") && item == "eventReg" {
  555. saveMap := map[string]interface{}{
  556. "unique_id": phone,
  557. "phone": phone,
  558. "username": name,
  559. "source": sourceName,
  560. "status999": "status5",
  561. "company": cluename,
  562. "job": position,
  563. "belongTo": "市场部",
  564. "createTime": nowTime,
  565. "lastUpdateTime": nowTime,
  566. }
  567. token := getToken()
  568. updateData := map[string]interface{}{
  569. "dbType": "0001",
  570. "customerList": []map[string]interface{}{saveMap},
  571. }
  572. dataByte, _ := json.Marshal(&updateData)
  573. url := `https://a1.7x24cc.com/commonInte?flag=1007&account=N000000029739&accessToken=` + token + `&json=` + url.QueryEscape(string(dataByte))
  574. bs, err := doGet(url)
  575. if err != nil {
  576. log.Println("调用接口失败")
  577. } else {
  578. resMap := common.StringToMap(string(bs))
  579. if resMap["success"] != nil && resMap["success"].(bool) {
  580. saveMap["company_nature"] = isGroup
  581. saveMap["company_verification"] = isCommerce
  582. TiDbData.Insert("customer", saveMap)
  583. } else {
  584. log.Println("新增线索失败")
  585. }
  586. }
  587. }
  588. }