everything.go 22 KB

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