|
@@ -1,16 +1,19 @@
|
|
package entity
|
|
package entity
|
|
|
|
|
|
import (
|
|
import (
|
|
- "app.yhyue.com/moapp/jybase/date"
|
|
|
|
- "app.yhyue.com/moapp/jybase/mongodb"
|
|
|
|
- "github.com/gogf/gf/v2/frame/g"
|
|
|
|
- "github.com/gogf/gf/v2/util/gconv"
|
|
|
|
|
|
+ "fmt"
|
|
"log"
|
|
"log"
|
|
"strings"
|
|
"strings"
|
|
"sync"
|
|
"sync"
|
|
"telemarketingEtl/config"
|
|
"telemarketingEtl/config"
|
|
"telemarketingEtl/util"
|
|
"telemarketingEtl/util"
|
|
"time"
|
|
"time"
|
|
|
|
+
|
|
|
|
+ "app.yhyue.com/moapp/jybase/date"
|
|
|
|
+ "app.yhyue.com/moapp/jybase/mongodb"
|
|
|
|
+ "github.com/gogf/gf/v2/frame/g"
|
|
|
|
+ "github.com/gogf/gf/v2/os/gctx"
|
|
|
|
+ "github.com/gogf/gf/v2/util/gconv"
|
|
)
|
|
)
|
|
|
|
|
|
/*
|
|
/*
|
|
@@ -51,11 +54,13 @@ var (
|
|
)
|
|
)
|
|
|
|
|
|
func init() {
|
|
func init() {
|
|
|
|
+ ctx := gctx.New()
|
|
poolSize := g.Cfg().MustGet(ctx, "poolSize").Int()
|
|
poolSize := g.Cfg().MustGet(ctx, "poolSize").Int()
|
|
oPool = make(chan bool, poolSize)
|
|
oPool = make(chan bool, poolSize)
|
|
}
|
|
}
|
|
|
|
|
|
func GetOpenSea() {
|
|
func GetOpenSea() {
|
|
|
|
+ ctx := gctx.New()
|
|
//
|
|
//
|
|
session := config.MgoLog.GetMgoConn()
|
|
session := config.MgoLog.GetMgoConn()
|
|
defer config.MgoLog.DestoryMongoConn(session)
|
|
defer config.MgoLog.DestoryMongoConn(session)
|
|
@@ -120,8 +125,10 @@ func GetOpenSea() {
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
+ log.Println("queryOneClassPc:", queryOneClassPc)
|
|
iter := session.DB("qfw").C("jy_logs").Find(queryOneClassPc).Iter()
|
|
iter := session.DB("qfw").C("jy_logs").Find(queryOneClassPc).Iter()
|
|
count := 0
|
|
count := 0
|
|
|
|
+ log.Println("一级公海开始.")
|
|
//一级公海
|
|
//一级公海
|
|
for thisData := map[string]interface{}{}; iter.Next(&thisData); {
|
|
for thisData := map[string]interface{}{}; iter.Next(&thisData); {
|
|
oPool <- true
|
|
oPool <- true
|
|
@@ -152,13 +159,13 @@ func GetOpenSea() {
|
|
oneClassA[uuid] = true
|
|
oneClassA[uuid] = true
|
|
}(thisData)
|
|
}(thisData)
|
|
count++
|
|
count++
|
|
- if count%100000 == 0 {
|
|
|
|
|
|
+ if count%10 == 0 {
|
|
log.Printf("已完成%d条数据\n", count)
|
|
log.Printf("已完成%d条数据\n", count)
|
|
}
|
|
}
|
|
thisData = map[string]interface{}{}
|
|
thisData = map[string]interface{}{}
|
|
}
|
|
}
|
|
oWait.Wait()
|
|
oWait.Wait()
|
|
-
|
|
|
|
|
|
+ log.Println("一级公海 pc 结束")
|
|
queryOneClassApp := map[string]interface{}{
|
|
queryOneClassApp := map[string]interface{}{
|
|
"date": map[string]interface{}{
|
|
"date": map[string]interface{}{
|
|
"$gte": start,
|
|
"$gte": start,
|
|
@@ -214,7 +221,7 @@ func GetOpenSea() {
|
|
oneClassA[uuid] = true
|
|
oneClassA[uuid] = true
|
|
}(thisData)
|
|
}(thisData)
|
|
count++
|
|
count++
|
|
- if count%100000 == 0 {
|
|
|
|
|
|
+ if count%10 == 0 {
|
|
log.Printf("已完成%d条数据\n", count)
|
|
log.Printf("已完成%d条数据\n", count)
|
|
}
|
|
}
|
|
thisData = map[string]interface{}{}
|
|
thisData = map[string]interface{}{}
|
|
@@ -222,6 +229,7 @@ func GetOpenSea() {
|
|
oWait.Wait()
|
|
oWait.Wait()
|
|
//更新公海
|
|
//更新公海
|
|
AddOpenSea(oneClassA, 1, "A")
|
|
AddOpenSea(oneClassA, 1, "A")
|
|
|
|
+ log.Println("一级公海 更新结束。")
|
|
//
|
|
//
|
|
oneClassB := map[string]bool{}
|
|
oneClassB := map[string]bool{}
|
|
classB, ok := config.Mgo.Find("user", map[string]interface{}{
|
|
classB, ok := config.Mgo.Find("user", map[string]interface{}{
|
|
@@ -244,8 +252,9 @@ func GetOpenSea() {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
AddOpenSea(oneClassB, 1, "B")
|
|
AddOpenSea(oneClassB, 1, "B")
|
|
- //TODO 一级公海c
|
|
|
|
- oneClassC := map[string]bool{}
|
|
|
|
|
|
+ oneClassC := GetOneSeaC()
|
|
|
|
+ AddOpenSea(oneClassC, 1, "C")
|
|
|
|
+ //
|
|
twoA, twoB, twoC, twoD := TwoOpenSea(oneClassA, oneClassB, oneClassC)
|
|
twoA, twoB, twoC, twoD := TwoOpenSea(oneClassA, oneClassB, oneClassC)
|
|
AddOpenSea(twoA, 2, "A")
|
|
AddOpenSea(twoA, 2, "A")
|
|
AddOpenSea(twoB, 2, "B")
|
|
AddOpenSea(twoB, 2, "B")
|
|
@@ -265,9 +274,13 @@ func GetOpenSea() {
|
|
D.1天≤最近30天内活跃天数<5天的客户;
|
|
D.1天≤最近30天内活跃天数<5天的客户;
|
|
*/
|
|
*/
|
|
func TwoOpenSea(oneClassA, oneClassB, oneClassC map[string]bool) (aMap, bMap, cMap, dMap map[string]bool) {
|
|
func TwoOpenSea(oneClassA, oneClassB, oneClassC map[string]bool) (aMap, bMap, cMap, dMap map[string]bool) {
|
|
- q := "SELECT userid,COUNT(1) as count FROM dwd_f_userbase_visit_info WHERE createtime > %s AND contentnum >%v GROUP BY userid "
|
|
|
|
|
|
+ i_day := g.Cfg().MustGet(ctx, "classTwoHighSeaslastDay").Int()
|
|
|
|
+ day := time.Now().AddDate(0, 0, -i_day).Format(date.Date_Full_Layout)
|
|
|
|
+ q := fmt.Sprintf("SELECT userid,COUNT(1) as count FROM dwd_f_userbase_visit_info WHERE createtime > '%s' AND contentnum >0 GROUP BY userid ", day)
|
|
//
|
|
//
|
|
|
|
+ log.Println(q)
|
|
stmtOut, err := config.JianyuSubjectdb.DB.Prepare(q)
|
|
stmtOut, err := config.JianyuSubjectdb.DB.Prepare(q)
|
|
|
|
+ log.Println("stmtOut.err:", err)
|
|
defer func() {
|
|
defer func() {
|
|
log.Println("stmtOut.Close start")
|
|
log.Println("stmtOut.Close start")
|
|
stmtOut.Close()
|
|
stmtOut.Close()
|
|
@@ -276,7 +289,7 @@ func TwoOpenSea(oneClassA, oneClassB, oneClassC map[string]bool) (aMap, bMap, cM
|
|
|
|
|
|
rows, err := stmtOut.Query()
|
|
rows, err := stmtOut.Query()
|
|
if err != nil {
|
|
if err != nil {
|
|
- log.Println(err)
|
|
|
|
|
|
+ log.Println("er:", err)
|
|
}
|
|
}
|
|
defer func() {
|
|
defer func() {
|
|
log.Println("rows.Close start")
|
|
log.Println("rows.Close start")
|
|
@@ -322,6 +335,7 @@ func TwoOpenSea(oneClassA, oneClassB, oneClassC map[string]bool) (aMap, bMap, cM
|
|
// 三级公海:
|
|
// 三级公海:
|
|
// 最近30天内活跃天数=0天的客户。
|
|
// 最近30天内活跃天数=0天的客户。
|
|
func ThreeOpenSea() {
|
|
func ThreeOpenSea() {
|
|
|
|
+ ctx := gctx.New()
|
|
t := time.Now()
|
|
t := time.Now()
|
|
t = time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, time.Local)
|
|
t = time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, time.Local)
|
|
day := g.Cfg().MustGet(ctx, "classThreeHighSeaslastDay").Int()
|
|
day := g.Cfg().MustGet(ctx, "classThreeHighSeaslastDay").Int()
|
|
@@ -338,16 +352,17 @@ func ThreeOpenSea() {
|
|
"$gte": start,
|
|
"$gte": start,
|
|
},
|
|
},
|
|
}
|
|
}
|
|
- uuid := gconv.String(v["uid"])
|
|
|
|
|
|
+ // uuid := gconv.String(v["uid"])
|
|
|
|
+ id := gconv.Int64(v["id"])
|
|
if r, ok := config.MgoLog.Find("subscribepay_logs", query, nil, `{"_id":1}`, false, 0, 1); ok && r != nil && len(*r) == 0 {
|
|
if r, ok := config.MgoLog.Find("subscribepay_logs", query, nil, `{"_id":1}`, false, 0, 1); ok && r != nil && len(*r) == 0 {
|
|
- config.JianyuSubjectdb.ExecBySql(`INSERT INTO dwd_f_crm_open_seax (comeintime,comeinsource,LEVEL,clue_level,clue_id)
|
|
|
|
|
|
+ config.JianyuSubjectdb.ExecBySql(`INSERT INTO dwd_f_crm_open_sea (comeintime,comeinsource,LEVEL,clue_level,clue_id)
|
|
VALUES(?,?,?,?,?)
|
|
VALUES(?,?,?,?,?)
|
|
- ON DUPLICATE KEY UPDATE comeintime=?,comeinsource=?,LEVEL=?,clue_level=?`, createtime, 1, 3, "D", uuid, createtime, 1, 3, "D")
|
|
|
|
|
|
+ ON DUPLICATE KEY UPDATE comeintime=?,comeinsource=?,LEVEL=?,clue_level=?`, createtime, 1, 3, "D", id, createtime, 1, 3, "D")
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return true
|
|
return true
|
|
- }, `select userid,uid from dwd_f_crm_clue_info where is_assign !=1`)
|
|
|
|
|
|
+ }, `select userid,uid,id from dwd_f_crm_clue_info where is_assign !=1`)
|
|
}
|
|
}
|
|
|
|
|
|
// 根据mongodb userid 获取 线索id
|
|
// 根据mongodb userid 获取 线索id
|
|
@@ -369,7 +384,7 @@ func AddOpenSea(m map[string]bool, level int, clue_level string) {
|
|
createtime := time.Now().Format(date.Date_Full_Layout)
|
|
createtime := time.Now().Format(date.Date_Full_Layout)
|
|
if len(m) > 0 {
|
|
if len(m) > 0 {
|
|
for _, v := range m {
|
|
for _, v := range m {
|
|
- config.JianyuSubjectdb.ExecBySql(`INSERT INTO dwd_f_crm_open_seax (comeintime,comeinsource,LEVEL,clue_level,clue_id)
|
|
|
|
|
|
+ config.JianyuSubjectdb.ExecBySql(`INSERT INTO dwd_f_crm_open_sea (comeintime,comeinsource,LEVEL,clue_level,clue_id)
|
|
VALUES(?,?,?,?,?)
|
|
VALUES(?,?,?,?,?)
|
|
ON DUPLICATE KEY UPDATE comeintime=?,comeinsource=?,LEVEL=?,clue_level=?`, createtime, 1, level, clue_level, v, createtime, 1, level, clue_level)
|
|
ON DUPLICATE KEY UPDATE comeintime=?,comeinsource=?,LEVEL=?,clue_level=?`, createtime, 1, level, clue_level, v, createtime, 1, level, clue_level)
|
|
}
|
|
}
|
|
@@ -395,7 +410,7 @@ func DeleteOpenSea() {
|
|
return true
|
|
return true
|
|
}
|
|
}
|
|
return true
|
|
return true
|
|
- }, `select id from dwd_f_crm_clue_info where trailstatus == ?`, "00")
|
|
|
|
|
|
+ }, `select id from dwd_f_crm_clue_info where trailstatus = ?`, "00")
|
|
}
|
|
}
|
|
|
|
|
|
//自动退回公海
|
|
//自动退回公海
|
|
@@ -409,6 +424,7 @@ func DeleteOpenSea() {
|
|
7.“无意向客户”自动退回公海;
|
|
7.“无意向客户”自动退回公海;
|
|
*/
|
|
*/
|
|
func ReturnOpenSea() {
|
|
func ReturnOpenSea() {
|
|
|
|
+ ctx := gctx.New()
|
|
t := time.Now()
|
|
t := time.Now()
|
|
t = time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, time.Local)
|
|
t = time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, time.Local)
|
|
//高意向客户
|
|
//高意向客户
|
|
@@ -433,13 +449,15 @@ func ReturnOpenSea() {
|
|
"08": t.AddDate(0, 0, -noIdeaCustomer),
|
|
"08": t.AddDate(0, 0, -noIdeaCustomer),
|
|
} {
|
|
} {
|
|
config.JianyuSubjectdb.SelectByBath(500, func(l *[]map[string]interface{}) bool {
|
|
config.JianyuSubjectdb.SelectByBath(500, func(l *[]map[string]interface{}) bool {
|
|
|
|
+ //1新增 2私海手动退回 3私海高意向客户自动退回 4私海意向客户退回 5私海潜在客户退回 6私海沉睡客户退回 7私海商机线索退回 8私海无意向客户退回
|
|
|
|
+ comeinsource := GetComeSource()[trailstatus]
|
|
ids := []interface{}{}
|
|
ids := []interface{}{}
|
|
args := []interface{}{}
|
|
args := []interface{}{}
|
|
for _, v := range *l {
|
|
for _, v := range *l {
|
|
id := v["id"]
|
|
id := v["id"]
|
|
ids = append(ids, id)
|
|
ids = append(ids, id)
|
|
//
|
|
//
|
|
- args = append(args, id, time.Now().Format(date.Date_Full_Layout), 2)
|
|
|
|
|
|
+ args = append(args, id, time.Now().Format(date.Date_Full_Layout), comeinsource)
|
|
}
|
|
}
|
|
whs := []string{}
|
|
whs := []string{}
|
|
for i := 0; i < len(ids); i++ {
|
|
for i := 0; i < len(ids); i++ {
|
|
@@ -460,4 +478,24 @@ func ReturnOpenSea() {
|
|
LEFT JOIN dwd_f_crm_trail_content c ON b.id =c.clue_id
|
|
LEFT JOIN dwd_f_crm_trail_content c ON b.id =c.clue_id
|
|
WHERE b.trailstatus =? AND c.next_time >? GROUP BY b.id`, trailstatus, nexttime)
|
|
WHERE b.trailstatus =? AND c.next_time >? GROUP BY b.id`, trailstatus, nexttime)
|
|
}
|
|
}
|
|
|
|
+ log.Println("return sea end")
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func GetComeSource() map[string]int {
|
|
|
|
+ return map[string]int{
|
|
|
|
+ "04": 2,
|
|
|
|
+ "05": 4,
|
|
|
|
+ "06": 3,
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func GetOneSeaC() map[string]bool {
|
|
|
|
+ m := map[string]bool{}
|
|
|
|
+ config.JianyuSubjectdb.SelectByBath(500, func(l *[]map[string]interface{}) bool {
|
|
|
|
+ for _, v := range *l {
|
|
|
|
+ m[gconv.String(v["clue_id"])] = true
|
|
|
|
+ }
|
|
|
|
+ return true
|
|
|
|
+ }, `select clue_id from dwd_f_crm_open_sea where comeinsource in(2,3,4)`)
|
|
|
|
+ return m
|
|
}
|
|
}
|