everything.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  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. /*
  330. 2、线索来源:
  331. (1)留资线索
  332. 根据留资维表:tidb/Jianyu_subjectdb/d_saleleads_code
  333. 根据维表中department字段包含“大客户”的所有source
  334. Source对应的中文名称用维表中的name,name要去掉"-pc","-app","-wx","-h5"
  335. 查询sql如下:SELECT source,name FROM Jianyu_subjectdb.d_saleleads_code WHERE department LIKE '%大客户' AND is_delete = 1
  336. (2)订单线索
  337. ①线上历史数据导出未支付订单
  338. ②线上历史数据导出已支付订单
  339. 3、线索处理逻辑
  340. (1)线索每天保留最新的一条数据
  341. (2)"具体来源", "数据需求" 这两个字段要将该用户当天作为线索进入大客户线索池的内容去重汇总,并用逗号分隔
  342. 4、导出明细
  343. 购买条数据:购买产品是“历史数据”,获取对应的购买条数
  344. 已支付订单信息:产品类型-有效期-金额
  345. 未支付订单信息:产品类型
  346. 5、发送邮件
  347. (1)邮件主题:线索日期+大客户销售线索
  348. (2)收件人:
  349. "gaoxiang@jianyu360.com",
  350. "sunzhenjie@jianyu360.com",
  351. "fanzongdong@jianyu360.com",
  352. "chenzhaobiao@jianyu360.com"
  353. (3)发送内容
  354. ①当天有线索,邮件正文为:线索日期+数据详情请查看附件。附件名称同主题名称
  355. ②当天无线索,邮件正文为:线索日期+无数据。
  356. (4)发送时间
  357. 每天一次,每天早上8:20
  358. */
  359. log.Println("大客户线索定时任务开始")
  360. dataArr := []map[string]interface{}{}
  361. filterArr := []string{"-pc", "-app", "-wx", "-h5"}
  362. sourceMap := map[string]string{}
  363. saleSource := TiDb.SelectBySql(`SELECT source,name FROM d_saleleads_code WHERE department LIKE '%大客户%' AND is_delete = 1`)
  364. if saleSource != nil && len(*saleSource) > 0 {
  365. for _, v := range *saleSource {
  366. source := common.ObjToString(v["source"])
  367. name := common.ObjToString(v["name"])
  368. for _, s := range filterArr {
  369. name = strings.ReplaceAll(name, s, "")
  370. }
  371. sourceMap[source] = name
  372. }
  373. }
  374. nowTime := time.Now().Format(date.Date_Full_Layout)
  375. nowTimes := time.Now().AddDate(0, 0, -1)
  376. startTime := time.Date(nowTimes.Year(), nowTimes.Month(), nowTimes.Day(), 0, 0, 0, 0, time.Local).Unix()
  377. saleleadsData, ok := Mgo.Find("saleLeads", map[string]interface{}{"createtime": map[string]interface{}{"$gte": startTime, "$lt": startTime + 86400}}, nil, nil, false, -1, -1)
  378. if ok && saleleadsData != nil && len(*saleleadsData) > 0 {
  379. for _, v := range *saleleadsData {
  380. sources := common.ObjToString(v["source"])
  381. userid := common.ObjToString(v["userid"])
  382. uid := ""
  383. if !mongodb.IsObjectIdHex(userid) {
  384. userMapping := TiDb.FindOne("dwd_f_userbase_id_mapping", map[string]interface{}{"position_id": userid}, "", "")
  385. if userMapping != nil && len(*userMapping) > 0 {
  386. userid = common.ObjToString((*userMapping)["userid"])
  387. uid = common.ObjToString((*userMapping)["uid"])
  388. }
  389. }
  390. if sourceMap[sources] != "" {
  391. company := common.ObjToString(v["company"])
  392. phone := common.ObjToString(v["phone"])
  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. source := sourceMap[sources]
  399. belongTo, usernickname := "大客户", ""
  400. userData := TiDb.FindOne("dwd_f_userbase_baseinfo", map[string]interface{}{"uid": uid}, "", "")
  401. if userData != nil {
  402. usernickname = common.ObjToString((*userData)["nickname"])
  403. bt := common.ObjToString((*userData)["belong_to"])
  404. if strings.HasPrefix(bt, "03") {
  405. continue
  406. }
  407. }
  408. dataArr = append(dataArr, 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. }
  425. }
  426. }
  427. 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 = '历史数据' AND order_status IN (0,1) AND salesperson IS NULL AND is_backstage_order = 0`)
  428. if orderData != nil && len(*orderData) > 0 {
  429. for _, v := range *orderData {
  430. phone := common.ObjToString(v["user_phone"])
  431. order_status := common.IntAll(v["order_status"])
  432. userData := TiDb.FindOne("dwd_f_userbase_baseinfo", map[string]interface{}{"phone": phone}, "", "")
  433. username, usernickname, userid, uid, source, payorderinfo, unpayorderinfo := "", "", "", "", "", "", ""
  434. if userData != nil {
  435. username = common.ObjToString((*userData)["name"])
  436. usernickname = common.ObjToString((*userData)["nickname"])
  437. uid = common.ObjToString((*userData)["uid"])
  438. userid = common.ObjToString((*userData)["userid"])
  439. bt := common.ObjToString((*userData)["belong_to"])
  440. if strings.HasPrefix(bt, "03") {
  441. continue
  442. }
  443. }
  444. if order_status == 0 {
  445. source = "线上历史数据导出未支付订单"
  446. unpayorderinfo = "历史数据"
  447. } else {
  448. source = "线上历史数据导出已支付订单"
  449. payorderinfo = "历史数据" + fmt.Sprint(common.IntAll(v["pay_money"])/100)
  450. }
  451. dataArr = append(dataArr, map[string]interface{}{
  452. "createTime": nowTime,
  453. "lastUpdateTime": nowTime,
  454. "phone": phone,
  455. "username": username,
  456. "usernickname": usernickname,
  457. "uid": uid,
  458. "userid": userid,
  459. "company": v["company_name"],
  460. "email": v["user_mail"],
  461. "belongTo": "大客户",
  462. "source": source,
  463. "data_count": v["data_count"],
  464. "unpayorderinfo": unpayorderinfo,
  465. "payorderinfo": payorderinfo,
  466. })
  467. }
  468. }
  469. xlsxArr := []string{"用户昵称", "姓名", "公司名称", "职位", "联系人电话", "购买条数", "用户邮箱", "已支付订单信息", "未支付订单类型", "销售线索来源", "具体来源", "数据需求"}
  470. xf := xlsx.NewFile()
  471. style := xlsx.NewStyle()
  472. style.Font.Size = 12
  473. style.Font.Bold = true
  474. style.Alignment.Vertical = "center"
  475. style.Alignment.Horizontal = "center"
  476. fileName, detailName := time.Now().Format(date.Date_Short_Layout)+"大客户销售线索", ""
  477. if len(dataArr) > 0 {
  478. detailName = time.Now().Format(date.Date_Short_Layout) + "数据详情请查看附件"
  479. sh, _ := xf.AddSheet("线索数据")
  480. row1 := sh.AddRow()
  481. for _, x := range xlsxArr {
  482. cell := row1.AddCell()
  483. cell.SetString(x)
  484. cell.SetStyle(style)
  485. }
  486. for _, v := range dataArr {
  487. row := sh.AddRow()
  488. row.AddCell().SetString(common.ObjToString(v["usernickname"]))
  489. row.AddCell().SetString(common.ObjToString(v["username"]))
  490. row.AddCell().SetString(common.ObjToString(v["company"]))
  491. row.AddCell().SetString(common.ObjToString(v["job"]))
  492. row.AddCell().SetString(common.ObjToString(v["phone"]))
  493. row.AddCell().SetValue(common.IntAll(v["data_count"]))
  494. row.AddCell().SetString(common.ObjToString(v["email"]))
  495. row.AddCell().SetString(common.ObjToString(v["payorderinfo"]))
  496. row.AddCell().SetString(common.ObjToString(v["unpayorderinfo"]))
  497. row.AddCell().SetString(common.ObjToString(v["source"]))
  498. row.AddCell().SetString(common.ObjToString(v["interest"]))
  499. row.AddCell().SetString(common.ObjToString(v["data_requirement"]))
  500. }
  501. } else {
  502. detailName = time.Now().Format(date.Date_Short_Layout) + "无线索"
  503. }
  504. email := "xuzhiheng@topnet.net.cn,gaoxiang@topnet.net.cn,fanzongdong@topnet.net.cn,sunzhenjie@topnet.net.cn"
  505. // email = "xuzhiheng@jianyu360.com"
  506. dir := "./xlsx/" + fileName + ".xlsx"
  507. err := xf.Save(dir)
  508. if err != nil && len(dataArr) > 0 {
  509. log.Println("xls error", err, dir)
  510. } else if len(dataArr) == 0 {
  511. log.Println("xlsx数据量为0不发邮件")
  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. log.Println("大客户线索定时任务结束")
  525. }
  526. func eventReg() {
  527. lastEventRegTime := cfg.LastEventRegTime
  528. sql := fmt.Sprintf(`select * from exhibition_sign_up where is_del = 0 and update_time > "%s" order by update_time asc`, lastEventRegTime)
  529. log.Println("活动报名表定时任务开始", sql)
  530. data := Jyactivities.SelectBySql(sql)
  531. if data != nil && *data != nil && len(*data) > 0 {
  532. for _, v := range *data {
  533. ok1, _ := FormatData(v, "eventReg")
  534. if !ok1 {
  535. common.WriteSysConfig(&cfg)
  536. break
  537. }
  538. cfg.LastEventRegTime = common.ObjToString(v["update_time"])
  539. }
  540. }
  541. common.WriteSysConfig(&cfg)
  542. log.Println("活动报名表定时任务结束")
  543. }
  544. func saveHlyj(belong_to, item, phone, name, sourceName, cluename, position, nowTime string, isGroup, isCommerce int) {
  545. if strings.HasPrefix(belong_to, "02") && item == "eventReg" {
  546. saveMap := map[string]interface{}{
  547. "unique_id": phone,
  548. "phone": phone,
  549. "username": name,
  550. "source": sourceName,
  551. "status999": "status5",
  552. "company": cluename,
  553. "job": position,
  554. "belongTo": "市场部",
  555. "createTime": nowTime,
  556. "lastUpdateTime": nowTime,
  557. }
  558. token := getToken()
  559. updateData := map[string]interface{}{
  560. "dbType": "0001",
  561. "customerList": []map[string]interface{}{saveMap},
  562. }
  563. dataByte, _ := json.Marshal(&updateData)
  564. url := `https://a1.7x24cc.com/commonInte?flag=1007&account=N000000029739&accessToken=` + token + `&json=` + url.QueryEscape(string(dataByte))
  565. bs, err := doGet(url)
  566. if err != nil {
  567. log.Println("调用接口失败")
  568. } else {
  569. resMap := common.StringToMap(string(bs))
  570. if resMap["success"] != nil && resMap["success"].(bool) {
  571. saveMap["company_nature"] = isGroup
  572. saveMap["company_verification"] = isCommerce
  573. TiDbData.Insert("customer", saveMap)
  574. } else {
  575. log.Println("新增线索失败")
  576. }
  577. }
  578. }
  579. }