1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102 |
- package main
- import (
- "app.yhyue.com/moapp/jybase/redis"
- "encoding/json"
- "fmt"
- "github.com/gogf/gf/util/gconv"
- "log"
- "net/url"
- "strings"
- "time"
- "app.yhyue.com/moapp/jybase/mail"
- "github.com/tealeg/xlsx"
- "app.yhyue.com/moapp/jybase/date"
- dates "app.yhyue.com/moapp/jybase/date"
- "app.yhyue.com/moapp/jybase/mongodb"
- "app.yhyue.com/moapp/jybase/common"
- )
- func everythingSync() {
- lastEverythingTime := cfg.LastEverythingTime
- nowTime := time.Now().Format(dates.Date_Full_Layout)
- sql := fmt.Sprintf(`select * from user_source where channel_code = "JyChCoopA" and create_time > "%s" order by create_time asc`, lastEverythingTime)
- log.Println("三方渠道数据定时任务开始", sql)
- data := ThirdParty.SelectBySql(sql)
- if data != nil && *data != nil && len(*data) > 0 {
- for _, v := range *data {
- user_id := common.ObjToString(v["user_id"])
- position_id := common.Int64All(v["position_id"])
- phone := common.ObjToString(v["phone"])
- state := common.IntAll(v["state"])
- user_mold, is_assign, is_transfer, last_login_time, registe_time, mailbox, source, clueId, order_type := 4, 0, 0, "", "", "", "", int64(0), ""
- owner, sales_lead_phone, sales_ent_name, sales_position, sales_dep, data_request, unique_id, belongTo, sales_leads_source := "", "", "", "", "", "", "", "", ""
- cData := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"phone": phone}, "", "")
- if cData != nil {
- is_assign = common.IntAll((*cData)["is_assign"])
- is_transfer = common.IntAll((*cData)["is_transfer"])
- clueId = common.Int64All((*cData)["id"])
- }
- //
- udata := TiDb.FindOne("dwd_f_userbase_baseinfo", map[string]interface{}{"userid": user_id}, "", "")
- if udata != nil {
- userSource := common.ObjToString((*udata)["source"])
- if userSource == "0102" {
- continue
- }
- }
- //
- /*cuData := TiDbData.FindOne("customer", map[string]interface{}{"phone": phone}, "", "")
- if cuData != nil {
- owner = common.ObjToString((*cuData)["owner"])
- unique_id = common.ObjToString((*cuData)["unique_id"])
- belongTo = common.ObjToString((*cuData)["belongTo"])
- }*/
- vData := TiDb.FindOne("dwd_f_userbase_visit_info", map[string]interface{}{"userid": user_id}, "", "")
- if vData != nil {
- last_login_time = common.ObjToString((*vData)["date"])
- }
- dData := Mysql.Find("dataexport_order", map[string]interface{}{"user_id": user_id}, "", "", -1, -1)
- if dData != nil && len(*dData) > 0 {
- pMap := map[string]string{}
- pArr := []string{}
- for _, v := range *dData {
- product_type := common.ObjToString(v["product_type"])
- pMap[product_type] = "1"
- }
- for k := range pMap {
- pArr = append(pArr, k)
- }
- if len(pArr) > 0 {
- order_type = strings.Join(pArr, ",")
- }
- }
- uData, ok := Mgo.FindOne("user", map[string]interface{}{"_id": mongodb.StringTOBsonId(user_id)})
- if ok && uData != nil {
- l_registedate := common.Int64All((*uData)["l_registedate"])
- registe_time = time.Unix(l_registedate, 0).Format(dates.Date_Full_Layout)
- }
- sData, oks := Mgo.Find("saleLeads", map[string]interface{}{"userid": user_id}, `{"_id":-1}`, nil, false, 0, 1)
- if oks && sData != nil {
- if len(*sData) > 0 {
- sDatas := (*sData)[0]
- sales_lead_phone = common.ObjToString(sDatas["phone"])
- sales_position = common.ObjToString(sDatas["position"])
- sales_ent_name = common.ObjToString(sDatas["company"])
- sales_dep = common.ObjToString(sDatas["branch"])
- if sales_dep == "" {
- sales_dep = common.ObjToString(sDatas["department"])
- }
- data_request = common.ObjToString(sDatas["data_requirement"])
- mailbox = common.ObjToString(sDatas["mail"])
- source = common.ObjToString(sDatas["interest"])
- }
- }
- if state == 1 {
- sales_leads_source = "一切都好登录"
- if is_assign == 1 || is_transfer == 1 || owner != "" {
- user_mold = 1
- } else {
- user_mold = 2
- }
- } else if state == 2 {
- sales_leads_source = "一切都好注册"
- if is_assign == 1 || is_transfer == 1 || owner != "" {
- user_mold = 3
- } else {
- user_mold = 4
- }
- }
- if owner == "" && unique_id != "" && belongTo == "市场部" {
- token := getToken()
- if token != "" {
- sss := url.QueryEscape("合作渠道一切都好")
- 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`
- bs, err := doGet(urls)
- if err != nil {
- log.Println("调用接口失败", unique_id, err)
- }
- resMap := common.StringToMap(string(bs))
- if resMap["success"] != nil && resMap["success"].(bool) {
- /*ok := TiDbData.Update("customer", map[string]interface{}{"unique_id": unique_id}, map[string]interface{}{"empNo": "8049", "owner": "8049", "source": "合作渠道一切都好"})
- if ok {
- log.Println("更新成功", unique_id)
- } else {
- log.Println("更新失败", unique_id)
- }*/
- } else {
- log.Println("调用接口失败!!", unique_id)
- }
- }
- }
- if ThirdParty.Count("user_channel_info", map[string]interface{}{"user_id": user_id}) > 0 {
- ThirdParty.Update("user_channel_info", map[string]interface{}{"user_id": user_id}, map[string]interface{}{
- "user_mold": user_mold,
- "last_login_time": common.If(last_login_time != "", last_login_time, nil),
- "sales_lead_phone": sales_lead_phone,
- "sales_ent_name": sales_ent_name,
- "sales_position": sales_position,
- "sales_dep": sales_dep,
- "sales_leads_source": sales_leads_source,
- "mailbox": mailbox,
- "order_type": order_type,
- "data_request": data_request,
- "source": source,
- "update_time": nowTime,
- })
- } else {
- ThirdParty.Insert("user_channel_info", map[string]interface{}{
- "user_id": user_id,
- "registe_time": registe_time,
- "phone": phone,
- "user_mold": user_mold,
- "last_login_time": common.If(last_login_time != "", last_login_time, nil),
- "sales_lead_phone": sales_lead_phone,
- "sales_ent_name": sales_ent_name,
- "sales_position": sales_position,
- "sales_dep": sales_dep,
- "sales_leads_source": sales_leads_source,
- "order_type": order_type,
- "mailbox": mailbox,
- "data_request": data_request,
- "source": source,
- "update_time": nowTime,
- })
- }
- if clueId > 0 && is_assign != 1 && is_transfer != 1 {
- TiDb.Update("dwd_f_userbase_baseinfo", map[string]interface{}{"userid": user_id}, map[string]interface{}{"belong_to": "0301"})
- TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"phone": phone}, map[string]interface{}{"is_assign": -1})
- TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": common.If(position_id > 0, position_id, -1),
- "change_type": "退出公海",
- "new_value": "通过合作渠道一切就好" + fmt.Sprint(common.If(user_mold == 1 || user_mold == 2, "登录", "注册")),
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": -1,
- })
- }
- }
- cfg.LastEverythingTime = common.ObjToString((*data)[len(*data)-1]["create_time"])
- }
- common.WriteSysConfig(&cfg)
- log.Println("三方渠道数据定时任务结束")
- }
- func saveEverything(user_id, phone, item, sourceName, sourceCode string) bool {
- nowTime, isOk := time.Now().Format(dates.Date_Full_Layout), false
- user_mold, is_assign, is_transfer, last_login_time, registe_time, mailbox, source, order_type, sales_leads_source := 4, 0, 0, "", "", "", "", "", ""
- owner, sales_lead_phone, sales_ent_name, sales_position, sales_dep, data_request, unique_id, belongTo, clueId, position_id := "", "", "", "", "", "", "", "", int64(0), int64(0)
- cData := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"phone": phone}, "", "")
- if cData != nil {
- is_assign = common.IntAll((*cData)["is_assign"])
- is_transfer = common.IntAll((*cData)["is_transfer"])
- clueId = common.Int64All((*cData)["is_transfer"])
- position_id = common.Int64All((*cData)["position_id"])
- }
- /*cuData := TiDbData.FindOne("customer", map[string]interface{}{"phone": phone}, "", "")
- if cuData != nil {
- unique_id = common.ObjToString((*cuData)["unique_id"])
- owner = common.ObjToString((*cuData)["owner"])
- }*/
- dData := Mysql.Find("dataexport_order", map[string]interface{}{"user_id": user_id}, "", "", -1, -1)
- if dData != nil && len(*dData) > 0 {
- pMap := map[string]string{}
- pArr := []string{}
- for _, v := range *dData {
- product_type := common.ObjToString(v["product_type"])
- pMap[product_type] = "1"
- }
- for k := range pMap {
- pArr = append(pArr, k)
- }
- if len(pArr) > 0 {
- order_type = strings.Join(pArr, ",")
- }
- }
- vData := TiDb.FindOne("dwd_f_userbase_visit_info", map[string]interface{}{"userid": user_id}, "", "")
- if vData != nil {
- last_login_time = common.ObjToString((*vData)["date"])
- }
- uData, ok := Mgo.FindOne("user", map[string]interface{}{"_id": mongodb.StringTOBsonId(user_id)})
- if ok && uData != nil {
- l_registedate := common.Int64All((*uData)["l_registedate"])
- registe_time = time.Unix(l_registedate, 0).Format(dates.Date_Full_Layout)
- }
- if item == "orders" {
- sales_leads_source = "订单未支付"
- } else if item == "users" || item == "xcxusers" {
- return false
- } else if item == "saleLeads" {
- sales_leads_source = sourceName
- } else {
- sales_leads_source = "用户留资"
- }
- query := map[string]interface{}{"userid": user_id}
- if sourceCode != "" {
- query["source"] = sourceCode
- }
- sData, oks := Mgo.Find("saleLeads", query, `{"_id":-1}`, nil, false, 0, 1)
- if oks && sData != nil {
- if len(*sData) > 0 {
- sDatas := (*sData)[0]
- sales_lead_phone = common.ObjToString(sDatas["phone"])
- sales_position = common.ObjToString(sDatas["position"])
- sales_ent_name = common.ObjToString(sDatas["company"])
- sales_dep = common.ObjToString(sDatas["branch"])
- if sales_dep == "" {
- sales_dep = common.ObjToString(sDatas["department"])
- }
- data_request = common.ObjToString(sDatas["data_requirement"])
- mailbox = common.ObjToString(sDatas["mail"])
- source = common.ObjToString(sDatas["interest"])
- }
- }
- if is_assign == 1 || is_transfer == 1 || owner != "" {
- user_mold = 1
- } else {
- user_mold = 2
- }
- if owner == "" && unique_id != "" && belongTo == "市场部" {
- token := getToken()
- if token != "" {
- sss := url.QueryEscape("合作渠道一切都好")
- 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`
- bs, err := doGet(urls)
- if err != nil {
- log.Println("调用接口失败", unique_id, err)
- }
- resMap := common.StringToMap(string(bs))
- if resMap["success"] != nil && resMap["success"].(bool) {
- ok := TiDbData.Update("customer", map[string]interface{}{"unique_id": unique_id}, map[string]interface{}{"empNo": "8049", "owner": "8049", "source": "合作渠道一切都好"})
- if ok {
- log.Println("更新成功", unique_id)
- } else {
- log.Println("更新失败", unique_id)
- }
- } else {
- log.Println("调用接口失败!!", unique_id)
- }
- }
- }
- if ThirdParty.Count("user_channel_info", map[string]interface{}{"user_id": user_id}) > 0 {
- ThirdParty.Update("user_channel_info", map[string]interface{}{"user_id": user_id}, map[string]interface{}{
- "user_mold": user_mold,
- "last_login_time": common.If(last_login_time != "", last_login_time, nil),
- "sales_lead_phone": sales_lead_phone,
- "sales_ent_name": sales_ent_name,
- "sales_position": sales_position,
- "sales_dep": sales_dep,
- "sales_leads_source": sales_leads_source,
- "mailbox": mailbox,
- "data_request": data_request,
- "source": source,
- "order_type": order_type,
- "update_time": nowTime,
- })
- } else {
- ThirdParty.Insert("user_channel_info", map[string]interface{}{
- "user_id": user_id,
- "registe_time": registe_time,
- "phone": phone,
- "user_mold": user_mold,
- "last_login_time": common.If(last_login_time != "", last_login_time, nil),
- "sales_lead_phone": sales_lead_phone,
- "sales_ent_name": sales_ent_name,
- "sales_position": sales_position,
- "sales_dep": sales_dep,
- "sales_leads_source": sales_leads_source,
- "mailbox": mailbox,
- "data_request": data_request,
- "order_type": order_type,
- "source": source,
- "update_time": nowTime,
- })
- }
- if clueId > 0 && is_assign != 1 && is_transfer != 1 {
- TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"phone": phone}, map[string]interface{}{"is_assign": -1})
- TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
- "clue_id": clueId,
- "position_id": common.If(position_id > 0, position_id, -1),
- "change_type": "退出公海",
- "new_value": "通过合作渠道一切就好登录",
- "createtime": nowTime,
- "BCPCID": common.GetRandom(32),
- "operator_id": -1,
- })
- } else if is_assign == 1 || is_transfer == 1 {
- isOk = true
- }
- return isOk
- }
- // 大客户线索-发邮件
- func bigCustomer() {
- runOk := getRunOk()
- if !runOk {
- log.Println("不是工作日,任务暂停")
- return
- }
- log.Println("大客户线索定时任务开始")
- dataArr := []map[string]interface{}{}
- filterArr := []string{"-pc", "-app", "-wx", "-h5"}
- sourceMap := map[string]string{} //根据留资维表:tidb/Jianyu_subjectdb/d_saleleads_code
- saleSource := TiDb.SelectBySql(`SELECT source,name FROM d_saleleads_code WHERE department LIKE '%大客户%' AND is_delete = 1`)
- if saleSource != nil && len(*saleSource) > 0 {
- for _, v := range *saleSource {
- source := common.ObjToString(v["source"])
- name := common.ObjToString(v["name"])
- for _, s := range filterArr {
- name = strings.ReplaceAll(name, s, "")
- }
- sourceMap[source] = name
- }
- }
- nowTime := time.Now().Format(date.Date_Full_Layout)
- bigSaleTime := cfg.BigSaleTime
- bigOrderTime := cfg.BigOrderTime
- if bigSaleTime == 0 {
- bigSaleTime = time.Now().Unix()
- }
- if bigOrderTime == "" {
- bigOrderTime = nowTime
- }
- abhList := []map[string]interface{}{}
- data := FindBatchData("dk")
- saleleadsData, ok := Mgo.Find("saleLeads", map[string]interface{}{"createtime": map[string]interface{}{"$gte": bigSaleTime}}, `{"phone":1,"createtime":1}`, nil, false, -1, -1)
- if ok && saleleadsData != nil && len(*saleleadsData) > 0 {
- for _, v := range *saleleadsData {
- sources := common.ObjToString(v["source"])
- userid := common.ObjToString(v["userid"])
- uid := ""
- if !mongodb.IsObjectIdHex(userid) {
- userMapping := TiDb.FindOne("dwd_f_userbase_id_mapping", map[string]interface{}{"position_id": userid}, "", "")
- if userMapping != nil && len(*userMapping) > 0 {
- userid = common.ObjToString((*userMapping)["userid"])
- uid = common.ObjToString((*userMapping)["uid"])
- }
- } else {
- userMapping := TiDb.FindOne("dwd_f_userbase_id_mapping", map[string]interface{}{"userid": userid}, "", "")
- if userMapping != nil && len(*userMapping) > 0 {
- userid = common.ObjToString((*userMapping)["userid"])
- uid = common.ObjToString((*userMapping)["uid"])
- }
- }
- if sourceMap[sources] != "" {
- source := sourceMap[sources]
- phone := common.ObjToString(v["phone"])
- if IsInternal(phone) {
- continue
- }
- key := fmt.Sprintf("%s_%s", source, phone)
- if _, ok := data[key]; ok {
- continue
- }
- data[key] = true
- company := common.ObjToString(v["company"])
- job := common.ObjToString(v["position"])
- username := common.ObjToString(v["name"])
- email := common.ObjToString(v["mail"])
- interest := common.ObjToString(v["interest"])
- data_requirement := common.ObjToString(v["data_requirement"])
- belongTo, usernickname := "大客户", ""
- userData := TiDb.FindOne("dwd_f_userbase_baseinfo", map[string]interface{}{"uid": uid}, "", "")
- if userData != nil {
- usernickname = common.ObjToString((*userData)["nickname"])
- bt := common.ObjToString((*userData)["belong_to"])
- if strings.HasPrefix(bt, "03") || bt == "0102" {
- continue
- }
- }
- s_sourceid := common.ObjToString((*userData)["s_sourceid"])
- if s_sourceid == db.Sourceid {
- //安博会数据
- abhList = append(abhList, map[string]interface{}{
- "createTime": nowTime,
- "lastUpdateTime": nowTime,
- "uid": uid,
- "userid": userid,
- "username": username,
- "usernickname": usernickname,
- "company": company,
- "job": job,
- "phone": phone,
- "email": email,
- "source": source,
- "belongTo": belongTo,
- "interest": interest,
- "data_requirement": data_requirement,
- })
- if gconv.Int64(v["createtime"]) > bigSaleTime {
- bigSaleTime = gconv.Int64(v["createtime"])
- }
- continue
- }
- dataArr = append(dataArr, map[string]interface{}{
- "createTime": nowTime,
- "lastUpdateTime": nowTime,
- "uid": uid,
- "userid": userid,
- "username": username,
- "usernickname": usernickname,
- "company": company,
- "job": job,
- "phone": phone,
- "email": email,
- "source": source,
- "belongTo": belongTo,
- "interest": interest,
- "data_requirement": data_requirement,
- })
- }
- if gconv.Int64(v["createtime"]) > bigSaleTime {
- bigSaleTime = gconv.Int64(v["createtime"])
- }
- }
- }
- cfg.BigSaleTime = bigSaleTime
- 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`)
- if orderData != nil && len(*orderData) > 0 {
- for _, v := range *orderData {
- phone := common.ObjToString(v["user_phone"])
- order_status := common.IntAll(v["order_status"])
- product_type := common.ObjToString(v["product_type"])
- orderUserId := gconv.String(v["user_id"])
- query := map[string]interface{}{}
- if !mongodb.IsObjectIdHex(orderUserId) {
- userMapping := TiDb.FindOne("dwd_f_userbase_id_mapping", map[string]interface{}{"position_id": orderUserId}, "", "")
- if userMapping != nil && len(*userMapping) > 0 {
- uid := common.ObjToString((*userMapping)["uid"])
- query["uid"] = uid
- }
- } else {
- query["userid"] = orderUserId
- }
- userData := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
- username, usernickname, userid, uid, source, payorderinfo, unpayorderinfo, s_sourceid := "", "", "", "", "", "", "", ""
- if userData != nil {
- if phone == "" {
- phone = common.ObjToString((*userData)["phone"])
- }
- if IsInternal(phone) {
- continue
- }
- username = common.ObjToString((*userData)["name"])
- usernickname = common.ObjToString((*userData)["nickname"])
- uid = common.ObjToString((*userData)["uid"])
- userid = common.ObjToString((*userData)["userid"])
- s_sourceid = common.ObjToString((*userData)["s_sourceid"])
- bt := common.ObjToString((*userData)["belong_to"])
- if strings.HasPrefix(bt, "03") || bt == "0102" {
- continue
- }
- }
- if product_type == "历史数据" {
- if order_status == 0 {
- source = "线上历史数据导出未支付订单"
- unpayorderinfo = "历史数据"
- } else {
- source = "线上历史数据导出已支付订单"
- payorderinfo = "历史数据" + fmt.Sprint(common.IntAll(v["pay_money"])/100)
- }
- } else {
- if order_status == 0 {
- source = "线上数据流量包未支付订单"
- unpayorderinfo = "数据流量包"
- } else {
- source = "线上数据流量包已支付订单"
- payorderinfo = "数据流量包" + fmt.Sprint(common.IntAll(v["pay_money"])/100)
- }
- }
- key := fmt.Sprintf("%s_%s", source, phone)
- if _, ok := data[key]; ok {
- continue
- }
- data[key] = true
- if s_sourceid == db.Sourceid {
- abhList = append(abhList, map[string]interface{}{
- "createTime": nowTime,
- "lastUpdateTime": nowTime,
- "phone": phone,
- "username": username,
- "usernickname": usernickname,
- "uid": uid,
- "userid": userid,
- "company": v["company_name"],
- "email": v["user_mail"],
- "belongTo": "大客户",
- "source": source,
- "data_count": v["data_count"],
- "unpayorderinfo": unpayorderinfo,
- "payorderinfo": payorderinfo, //增加客户需求
- })
- bigOrderTime = gconv.Time(gconv.String(v["create_time"])).Format(date.Date_Full_Layout)
- continue
- }
- dataArr = append(dataArr, map[string]interface{}{
- "createTime": nowTime,
- "lastUpdateTime": nowTime,
- "phone": phone,
- "username": username,
- "usernickname": usernickname,
- "uid": uid,
- "userid": userid,
- "company": v["company_name"],
- "email": v["user_mail"],
- "belongTo": "大客户",
- "source": source,
- "data_count": v["data_count"],
- "unpayorderinfo": unpayorderinfo,
- "payorderinfo": payorderinfo, //增加客户需求
- })
- bigOrderTime = gconv.Time(gconv.String(v["create_time"])).Format(date.Date_Full_Layout)
- }
- cfg.BigOrderTime = bigOrderTime
- }
- if len(abhList) > 0 {
- ABHEmail("big", abhList)
- }
- if len(abhList) > 0 || len(dataArr) > 0 {
- keyContent := fmt.Sprintf("data_%s_%s", time.Now().Format("2006-01-02"), "dk")
- redis.Put("newother", keyContent, data, 86400)
- }
- xlsxArr := []string{"用户昵称", "姓名", "公司名称", "职位", "联系人电话", "购买条数", "用户邮箱", "已支付订单信息", "未支付订单类型", "销售线索来源", "具体来源", "数据需求"}
- if len(dataArr) > 0 {
- bigData := TiDb.SelectBySql("select * from dwd_f_crm_clue_big_autodraw_record")
- if bigData != nil && len(*bigData) > 0 {
- cdata := *bigData
- bigArr := map[string][]map[string]interface{}{}
- for _, v := range dataArr {
- mincount := common.IntAll(cdata[0]["count"])
- minindex := 0
- minemail := ""
- for kk, vv := range cdata {
- vcount := common.IntAll(vv["count"])
- vemail := common.ObjToString(vv["email"])
- if vcount <= mincount {
- minindex = kk
- mincount = vcount
- minemail = vemail
- }
- }
- bigArr[minemail] = append(bigArr[minemail], v)
- cdata[minindex]["count"] = mincount + 1
- name := common.ObjToString(cdata[minindex]["name"])
- TiDb.UpdateOrDeleteBySql(`update dwd_f_crm_clue_big_autodraw_record set count = count + 1 where name = ?`, name)
- }
- for k, vb := range bigArr {
- batch := FindBatch("dk")
- fileName, detailName := time.Now().Format(date.Date_Short_Layout)+"-"+batch+"大客户销售线索", ""
- xf := xlsx.NewFile()
- style := xlsx.NewStyle()
- style.Font.Size = 12
- style.Font.Bold = true
- style.Alignment.Vertical = "center"
- style.Alignment.Horizontal = "center"
- detailName = time.Now().Format(date.Date_Short_Layout) + "数据详情请查看附件"
- sh, _ := xf.AddSheet("线索数据")
- row1 := sh.AddRow()
- for _, x := range xlsxArr {
- cell := row1.AddCell()
- cell.SetString(x)
- cell.SetStyle(style)
- }
- for _, v := range vb {
- row := sh.AddRow()
- row.AddCell().SetString(common.ObjToString(v["usernickname"]))
- row.AddCell().SetString(common.ObjToString(v["username"]))
- row.AddCell().SetString(common.ObjToString(v["company"]))
- row.AddCell().SetString(common.ObjToString(v["job"]))
- row.AddCell().SetString(common.ObjToString(v["phone"]))
- row.AddCell().SetValue(common.IntAll(v["data_count"]))
- row.AddCell().SetString(common.ObjToString(v["email"]))
- row.AddCell().SetString(common.ObjToString(v["payorderinfo"]))
- row.AddCell().SetString(common.ObjToString(v["unpayorderinfo"]))
- row.AddCell().SetString(common.ObjToString(v["source"]))
- row.AddCell().SetString(common.ObjToString(v["interest"]))
- row.AddCell().SetString(common.ObjToString(v["data_requirement"]))
- //增加客户需求
- }
- email := k
- //email = "wanghao@jianyu360.com"
- dir := "./xlsx/dk/" + fileName + ".xlsx"
- err := xf.Save(dir)
- if err != nil {
- log.Println("xls error", err, dir)
- } else {
- gmail := &mail.GmailAuth{
- SmtpHost: "smtp.exmail.qq.com",
- SmtpPort: 465,
- User: "public03@topnet.net.cn",
- Pwd: "ue9Rg9Sf4CVtdm5a",
- }
- status := mail.GSendMail_q("剑鱼标讯", email, "", "", fileName, detailName, dir, fileName+".xlsx", gmail)
- if status {
- log.Println("send mail success", fileName, email)
- }
- }
- }
- }
- }
- common.WriteSysConfig(&cfg)
- log.Println("大客户线索定时任务结束")
- }
- func IsInternal(phone string) bool {
- if DataAnalysisService.Count("dwd_f_userbase_insider", map[string]interface{}{
- "mobile": phone,
- }) > 0 {
- return true
- }
- return false
- }
- // 咨询组线索
- func AdvisoryCommittee() {
- runOk := getRunOk()
- if !runOk {
- log.Println("不是工作日,任务暂停")
- return
- }
- log.Println("咨询部线索定时任务开始")
- dataArr := []map[string]interface{}{}
- filterArr := []string{"-pc", "-app", "-wx", "-h5"}
- sourceMap := map[string]string{} //根据留资维表:tidb/Jianyu_subjectdb/d_saleleads_code
- saleSource := TiDb.SelectBySql(`SELECT source,name FROM d_saleleads_code WHERE department LIKE '%咨询组%' AND is_delete = 1`)
- if saleSource != nil && len(*saleSource) > 0 {
- for _, v := range *saleSource {
- source := common.ObjToString(v["source"])
- name := common.ObjToString(v["name"])
- for _, s := range filterArr {
- name = strings.ReplaceAll(name, s, "")
- }
- sourceMap[source] = name
- }
- }
- nowTime := time.Now().Format(date.Date_Full_Layout)
- advisoryCommitteeTime := cfg.AdvisoryCommitteeTime
- if advisoryCommitteeTime == 0 {
- advisoryCommitteeTime = time.Now().Unix()
- }
- abhList := []map[string]interface{}{}
- saleleadsData, ok := Mgo.Find("saleLeads", map[string]interface{}{"createtime": map[string]interface{}{"$gte": advisoryCommitteeTime}}, `{"phone":1,"createtime":1}`, nil, false, -1, -1)
- if ok && saleleadsData != nil && len(*saleleadsData) > 0 {
- data := FindBatchData("zx")
- for _, v := range *saleleadsData {
- sources := common.ObjToString(v["source"])
- userid := common.ObjToString(v["userid"])
- uid := ""
- if !mongodb.IsObjectIdHex(userid) {
- userMapping := TiDb.FindOne("dwd_f_userbase_id_mapping", map[string]interface{}{"position_id": userid}, "", "")
- if userMapping != nil && len(*userMapping) > 0 {
- userid = common.ObjToString((*userMapping)["userid"])
- uid = common.ObjToString((*userMapping)["uid"])
- }
- } else {
- userMapping := TiDb.FindOne("dwd_f_userbase_id_mapping", map[string]interface{}{"userid": userid}, "", "")
- if userMapping != nil && len(*userMapping) > 0 {
- userid = common.ObjToString((*userMapping)["userid"])
- uid = common.ObjToString((*userMapping)["uid"])
- }
- }
- if sourceMap[sources] != "" {
- company := common.ObjToString(v["company"])
- phone := common.ObjToString(v["phone"])
- if IsInternal(phone) {
- continue
- }
- username := common.ObjToString(v["name"])
- email := common.ObjToString(v["mail"])
- interest := common.ObjToString(v["interest"])
- data_requirement := common.ObjToString(v["data_requirement"])
- source := sourceMap[sources]
- belongTo := "咨询组"
- userData := TiDb.FindOne("dwd_f_userbase_baseinfo", map[string]interface{}{"uid": uid}, "", "")
- if userData != nil {
- bt := common.ObjToString((*userData)["belong_to"])
- if strings.HasPrefix(bt, "03") || bt == "0102" {
- continue
- }
- }
- key := fmt.Sprintf("%s_%s_%s", source, phone, interest)
- if _, ok := data[key]; ok {
- continue
- }
- data[key] = true
- s_sourceid := common.ObjToString((*userData)["s_sourceid"])
- if s_sourceid == db.Sourceid {
- abhList = append(abhList, map[string]interface{}{
- "createTime": nowTime,
- "createtime": v["createtime"],
- "username": username,
- "company": company,
- "phone": phone,
- "source": source,
- "belongTo": belongTo,
- "interest": interest,
- "data_requirement": data_requirement,
- "branch": v["branch"],
- "email": email,
- })
- if gconv.Int64(v["createtime"]) > advisoryCommitteeTime {
- advisoryCommitteeTime = gconv.Int64(v["createtime"])
- }
- continue
- }
- dataArr = append(dataArr, map[string]interface{}{
- "createTime": nowTime,
- "createtime": v["createtime"],
- "username": username,
- "company": company,
- "phone": phone,
- "source": source,
- "belongTo": belongTo,
- "interest": interest,
- "data_requirement": data_requirement,
- "branch": v["branch"],
- "email": email,
- })
- }
- }
- keyContent := fmt.Sprintf("data_%s_%s", time.Now().Format("2006-01-02"), "zx")
- redis.Put("newother", keyContent, data, 86400)
- }
- if len(abhList) > 0 {
- //安博会发邮件高翔
- ABHEmail("advisory", abhList)
- }
- cfg.AdvisoryCommitteeTime = advisoryCommitteeTime
- xlsxArr := []string{"姓名", "联系方式", "邮箱", "公司名称", "咨询需求", "销售线索来源", "具体来源", "留资时间"}
- if len(dataArr) > 0 {
- //排序:首先按照“联系方式”排序,即同1个用户的留资放在一起,其次按照留资时间正序排序。
- batch := FindBatch("zx")
- fileName, detailName := "咨询服务销售线索 "+time.Now().Format(date.Date_Short_Layout)+"-"+batch, ""
- xf := xlsx.NewFile()
- style := xlsx.NewStyle()
- style.Font.Size = 12
- style.Font.Bold = true
- style.Alignment.Vertical = "center"
- style.Alignment.Horizontal = "center"
- detailName = "今日新增咨询服务销售线索,请查收附件,及时跟进。"
- sh, _ := xf.AddSheet("线索数据")
- row1 := sh.AddRow()
- for _, x := range xlsxArr {
- cell := row1.AddCell()
- cell.SetString(x)
- cell.SetStyle(style)
- }
- for _, v := range dataArr {
- row := sh.AddRow()
- row.AddCell().SetString(common.ObjToString(v["username"]))
- row.AddCell().SetString(common.ObjToString(v["phone"]))
- row.AddCell().SetString(common.ObjToString(v["email"]))
- row.AddCell().SetString(common.ObjToString(v["company"]))
- row.AddCell().SetString(common.ObjToString(v["data_requirement"]))
- row.AddCell().SetString(common.ObjToString(v["source"]))
- row.AddCell().SetString(common.ObjToString(v["interest"]))
- row.AddCell().SetString(gconv.Time(gconv.Int64(v["createtime"])).Format(date.Date_Full_Layout))
- //增加客户需求
- }
- email := db.AdvisoryCommitteeMail
- dir := "./xlsx/zx/" + fileName + ".xlsx"
- err := xf.Save(dir)
- if err != nil {
- log.Println("xls error", err, dir)
- } else {
- gmail := &mail.GmailAuth{
- SmtpHost: "smtp.exmail.qq.com",
- SmtpPort: 465,
- User: "public03@topnet.net.cn",
- Pwd: "ue9Rg9Sf4CVtdm5a",
- }
- for _, v := range email {
- status := mail.GSendMail_q("剑鱼标讯", v, "", "", fileName, detailName, dir, fileName+".xlsx", gmail)
- if status {
- log.Println("send mail success", fileName, v)
- }
- }
- }
- }
- common.WriteSysConfig(&cfg)
- log.Println("咨询部线索定时任务结束")
- }
- // 市场部线索
- func marketCustomer() {
- runOk := getRunOk()
- if !runOk {
- log.Println("不是工作日,任务暂停")
- return
- }
- log.Println("市场部线索定时任务开始")
- dataArr := []map[string]interface{}{}
- filterArr := []string{"-pc", "-app", "-wx", "-h5"}
- sourceMap := map[string]string{} //根据留资维表:tidb/Jianyu_subjectdb/d_saleleads_code
- saleSource := TiDb.SelectBySql(`SELECT source,name FROM d_saleleads_code WHERE department LIKE '%市场组%' AND is_delete = 1`)
- if saleSource != nil && len(*saleSource) > 0 {
- for _, v := range *saleSource {
- source := common.ObjToString(v["source"])
- name := common.ObjToString(v["name"])
- for _, s := range filterArr {
- name = strings.ReplaceAll(name, s, "")
- }
- sourceMap[source] = name
- }
- }
- nowTime := time.Now().Format(date.Date_Full_Layout)
- marketSaleTime := cfg.MarketSaleTime
- if marketSaleTime == 0 {
- marketSaleTime = time.Now().Unix()
- }
- abhList := []map[string]interface{}{}
- saleleadsData, ok := Mgo.Find("saleLeads", map[string]interface{}{"createtime": map[string]interface{}{"$gte": marketSaleTime}}, `{"phone":1,"createtime":1}`, nil, false, -1, -1)
- if ok && saleleadsData != nil && len(*saleleadsData) > 0 {
- data := FindBatchData("sc")
- for _, v := range *saleleadsData {
- sources := common.ObjToString(v["source"])
- userid := common.ObjToString(v["userid"])
- uid := ""
- if !mongodb.IsObjectIdHex(userid) {
- userMapping := TiDb.FindOne("dwd_f_userbase_id_mapping", map[string]interface{}{"position_id": userid}, "", "")
- if userMapping != nil && len(*userMapping) > 0 {
- userid = common.ObjToString((*userMapping)["userid"])
- uid = common.ObjToString((*userMapping)["uid"])
- }
- } else {
- userMapping := TiDb.FindOne("dwd_f_userbase_id_mapping", map[string]interface{}{"userid": userid}, "", "")
- if userMapping != nil && len(*userMapping) > 0 {
- userid = common.ObjToString((*userMapping)["userid"])
- uid = common.ObjToString((*userMapping)["uid"])
- }
- }
- if sourceMap[sources] != "" {
- company := common.ObjToString(v["company"])
- phone := common.ObjToString(v["phone"])
- if IsInternal(phone) {
- continue
- }
- job := common.ObjToString(v["position"])
- username := common.ObjToString(v["name"])
- email := common.ObjToString(v["mail"])
- interest := common.ObjToString(v["interest"])
- data_requirement := common.ObjToString(v["data_requirement"])
- source := sourceMap[sources]
- belongTo, usernickname := "市场组", ""
- userData := TiDb.FindOne("dwd_f_userbase_baseinfo", map[string]interface{}{"uid": uid}, "", "")
- if userData != nil {
- usernickname = common.ObjToString((*userData)["nickname"])
- bt := common.ObjToString((*userData)["belong_to"])
- if strings.HasPrefix(bt, "03") || bt == "0102" {
- continue
- }
- }
- key := fmt.Sprintf("%s_%s", source, phone)
- if _, ok := data[key]; ok {
- continue
- }
- s_sourceid := common.ObjToString((*userData)["s_sourceid"])
- data[key] = true
- if s_sourceid == db.Sourceid {
- abhList = append(abhList, map[string]interface{}{
- "createTime": nowTime,
- "lastUpdateTime": nowTime,
- "createtime": v["createtime"],
- "uid": uid,
- "userid": userid,
- "username": username,
- "usernickname": usernickname,
- "company": company,
- "job": job,
- "phone": phone,
- "email": email,
- "source": source,
- "belongTo": belongTo,
- "interest": interest,
- "data_requirement": data_requirement,
- "branch": v["branch"],
- "s_sourceid": s_sourceid,
- })
- if gconv.Int64(v["createtime"]) > marketSaleTime {
- marketSaleTime = gconv.Int64(v["createtime"])
- }
- continue
- }
- dataArr = append(dataArr, map[string]interface{}{
- "createTime": nowTime,
- "lastUpdateTime": nowTime,
- "createtime": v["createtime"],
- "uid": uid,
- "userid": userid,
- "username": username,
- "usernickname": usernickname,
- "company": company,
- "job": job,
- "phone": phone,
- "email": email,
- "source": source,
- "belongTo": belongTo,
- "interest": interest,
- "data_requirement": data_requirement,
- "branch": v["branch"],
- "s_sourceid": s_sourceid,
- })
- }
- if gconv.Int64(v["createtime"]) > marketSaleTime {
- marketSaleTime = gconv.Int64(v["createtime"])
- }
- }
- if len(abhList) > 0 {
- //安博会发邮件高翔
- ABHEmail("market", abhList)
- }
- keyContent := fmt.Sprintf("data_%s_%s", time.Now().Format("2006-01-02"), "sc")
- redis.Put("newother", keyContent, data, 86400)
- }
- cfg.MarketSaleTime = marketSaleTime
- xlsxArr := []string{"姓名", "联系人电话", "公司名称", "职位", "部门", "销售线索来源", "留资时间"}
- if len(dataArr) > 0 {
- //排序:首先按照“联系方式”排序,即同1个用户的留资放在一起,其次按照留资时间正序排序。
- batch := FindBatch("sc")
- fileName, detailName := "商务合作销售线索 "+time.Now().Format(date.Date_Short_Layout)+"-"+batch, ""
- xf := xlsx.NewFile()
- style := xlsx.NewStyle()
- style.Font.Size = 12
- style.Font.Bold = true
- style.Alignment.Vertical = "center"
- style.Alignment.Horizontal = "center"
- detailName = "今日新增商务合作销售线索,请查收附件,及时跟进。"
- sh, _ := xf.AddSheet("线索数据")
- row1 := sh.AddRow()
- for _, x := range xlsxArr {
- cell := row1.AddCell()
- cell.SetString(x)
- cell.SetStyle(style)
- }
- for _, v := range dataArr {
- row := sh.AddRow()
- row.AddCell().SetString(common.ObjToString(v["username"]))
- row.AddCell().SetString(common.ObjToString(v["phone"]))
- row.AddCell().SetString(common.ObjToString(v["company"]))
- row.AddCell().SetString(common.ObjToString(v["job"]))
- row.AddCell().SetString(common.ObjToString(v["branch"]))
- row.AddCell().SetString(common.ObjToString(v["source"]))
- row.AddCell().SetString(gconv.Time(gconv.Int64(v["createtime"])).Format(date.Date_Full_Layout))
- //增加客户需求
- }
- email := db.MarketSaleMail
- dir := "./xlsx/sc/" + fileName + ".xlsx"
- err := xf.Save(dir)
- if err != nil {
- log.Println("xls error", err, dir)
- } else {
- gmail := &mail.GmailAuth{
- SmtpHost: "smtp.exmail.qq.com",
- SmtpPort: 465,
- User: "public03@topnet.net.cn",
- Pwd: "ue9Rg9Sf4CVtdm5a",
- }
- status := mail.GSendMail_q("剑鱼标讯", email, "", "", fileName, detailName, dir, fileName+".xlsx", gmail)
- if status {
- log.Println("send mail success", fileName, email)
- }
- }
- }
- common.WriteSysConfig(&cfg)
- log.Println("大客户线索定时任务结束")
- }
- func eventReg() {
- lastEventRegTime := cfg.LastEventRegTime
- sql := fmt.Sprintf(`select * from exhibition_sign_up where is_del = 0 and update_time > "%s" order by update_time asc`, lastEventRegTime)
- log.Println("活动报名表定时任务开始", sql)
- data := Jyactivities.SelectBySql(sql)
- if data != nil && *data != nil && len(*data) > 0 {
- for _, v := range *data {
- ok1, ok2, _ := FormatData(v, "eventReg")
- if !ok1 {
- common.WriteSysConfig(&cfg)
- log.Println("线索卡点", "eventReg", v, lastEventRegTime)
- } else {
- if !ok2 {
- log.Println("用户分配已达上限", "eventReg", v, lastEventRegTime)
- common.WriteSysConfig(&cfg)
- }
- }
- cfg.LastEventRegTime = common.ObjToString(v["update_time"])
- }
- }
- common.WriteSysConfig(&cfg)
- log.Println("活动报名表定时任务结束")
- }
- func saveHlyj(belong_to, item, phone, name, sourceName, cluename, position, nowTime string, isGroup, isCommerce int) {
- if strings.HasPrefix(belong_to, "02") && item == "eventReg" {
- saveMap := map[string]interface{}{
- "unique_id": phone,
- "phone": phone,
- "username": name,
- "source": sourceName,
- "status999": "status5",
- "company": cluename,
- "job": position,
- "belongTo": "市场部",
- "createTime": nowTime,
- "lastUpdateTime": nowTime,
- }
- token := getToken()
- updateData := map[string]interface{}{
- "dbType": "0001",
- "customerList": []map[string]interface{}{saveMap},
- }
- dataByte, _ := json.Marshal(&updateData)
- url := `https://a1.7x24cc.com/commonInte?flag=1007&account=N000000029739&accessToken=` + token + `&json=` + url.QueryEscape(string(dataByte))
- bs, err := doGet(url)
- if err != nil {
- log.Println("调用接口失败")
- } else {
- resMap := common.StringToMap(string(bs))
- if resMap["success"] != nil && resMap["success"].(bool) {
- saveMap["company_nature"] = isGroup
- saveMap["company_verification"] = isCommerce
- TiDbData.Insert("customer", saveMap)
- } else {
- log.Println("新增线索失败")
- }
- }
- }
- }
- func FindBatch(moudle string) string {
- now := time.Now().Format("2006-01-02")
- key := fmt.Sprintf("batch_%s_%s", now, moudle)
- yesterday := time.Now().AddDate(0, 0, -1).Format("2006-01-02")
- yesterdayKey := fmt.Sprintf("batch_%s_%s", yesterday, moudle)
- if ok, _ := redis.Exists("newother", yesterdayKey); ok {
- //删除之前数据
- redis.Del("newother", yesterdayKey)
- }
- batch := redis.Incr("newother", key)
- return fmt.Sprintf("%04d", batch)
- }
- func FindBatchData(moudle string) map[string]interface{} {
- now := time.Now().Format("2006-01-02")
- //数据提取
- keyContent := fmt.Sprintf("data_%s_%s", now, moudle)
- data := redis.Get("newother", keyContent)
- if data == nil {
- return make(map[string]interface{})
- } else {
- return gconv.Map(data)
- }
- }
|