|
@@ -1,6 +1,7 @@
|
|
|
package main
|
|
|
|
|
|
import (
|
|
|
+ "app.yhyue.com/moapp/jybase/mail"
|
|
|
"database/sql"
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
@@ -13,21 +14,20 @@ import (
|
|
|
"app.yhyue.com/moapp/jybase/common"
|
|
|
"app.yhyue.com/moapp/jybase/date"
|
|
|
"app.yhyue.com/moapp/jybase/mongodb"
|
|
|
- "app.yhyue.com/moapp/jybase/redis"
|
|
|
)
|
|
|
|
|
|
func kcSync() {
|
|
|
log.Println("客户成功系统移交定时任务开始")
|
|
|
- sql := `select * from dwd_f_userbase_order_info where vip_endtime > "` + time.Now().Format(date.Date_Full_Layout) + `" and autoUpdate > "` + cfg.LastkcTime +
|
|
|
- ` and order_status =1 and refund_status!=1 and data_spec!="dhy4" and (payable_money > 0 or (payable_money=0 and (filter LIKE "%分期付款补充权益%" or filter LIKE "%原订单不支持开通多项权益" or filter LIKE "%权益码兑换%") ) ) and product_type in ("大会员","企业商机管理") " order by autoUpdate asc`
|
|
|
+ sql := `select * from dwd_f_userbase_order_info where payable_money > 0 and vip_endtime > "` + time.Now().Format(date.Date_Full_Layout) + `" and autoUpdate > "` + cfg.LastkcTime + `" order by autoUpdate asc`
|
|
|
data := TiDb.SelectBySql(sql)
|
|
|
if data != nil && *data != nil && len(*data) > 0 {
|
|
|
for _, v := range *data {
|
|
|
+ product_type := common.ObjToString(v["product_type"])
|
|
|
+ data_spec := common.ObjToString(v["data_spec"])
|
|
|
starttime := common.ObjToString(v["vip_starttime"])
|
|
|
- order_change := common.IntAll(v["order_change"])
|
|
|
- endTime := common.ObjToString(v["vip_endtime"])
|
|
|
- timecount := TimeStrcount(starttime, endTime)
|
|
|
- if !strings.HasPrefix(starttime, "2099") && (order_change != 1 || timecount > 93) {
|
|
|
+ order_status := common.IntAll(v["order_status"])
|
|
|
+ refund_status := common.IntAll(v["refund_status"])
|
|
|
+ if (product_type == "大会员" || product_type == "企业商机管理") && order_status == 1 && data_spec != "dhy4" && !strings.HasPrefix(starttime, "2099") && refund_status != 1 {
|
|
|
status := kcJob(v)
|
|
|
if status == 0 {
|
|
|
break
|
|
@@ -44,38 +44,81 @@ func kcJob(data map[string]interface{}) int {
|
|
|
nowTime := time.Now().Format(date.Date_Full_Layout)
|
|
|
uId, entId, clueId, saveMap, name, positionId, status := common.ObjToString(data["uid"]), fmt.Sprint(data["ent_id"]), int64(0), map[string]interface{}{}, "", int64(0), 1
|
|
|
clueData := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, "", "")
|
|
|
+ orderCode := gconv.String(data["order_code"])
|
|
|
+ saleDep, orderPositionId, salesperson := FindSaleRecord(orderCode)
|
|
|
if clueData == nil || len(*clueData) == 0 {
|
|
|
- //查询是否是客成的单子
|
|
|
- saleDep, _, salesperson := FindSaleRecord(gconv.String(data["order_code"]))
|
|
|
+ role, industry, department, departments, position, name, top_cluetype, sub_cluetype, follow_project_area := "", "", "", "", "", "", "", "", ""
|
|
|
+ query, topname, subname, belong_to, remark, sourceId := map[string]interface{}{}, "", "", "01", "", int64(0)
|
|
|
+ //创建线索
|
|
|
+ //原始订单获取
|
|
|
+ orderData := Mysql.FindOne("dataexport_order", map[string]interface{}{
|
|
|
+ "order_code": orderCode,
|
|
|
+ }, "", "")
|
|
|
+ if orderData == nil {
|
|
|
+ log.Println("原始订单查询不到:", orderCode)
|
|
|
+ }
|
|
|
+ userId, uId, source, cluename, phone, sourceCode, keyword, _, positionId := common.ObjToString((*orderData)["user_id"]), "", "", "", "", "", []string{}, "", ""
|
|
|
+ seatNumber := ""
|
|
|
if saleDep == "客户成功组" {
|
|
|
- //查询是否是管理员
|
|
|
- //添加线索
|
|
|
+ //新增线索
|
|
|
+ orderPositionId = 0
|
|
|
} else {
|
|
|
- log.Println("客户未查到线索!!!", uId)
|
|
|
- if isExists, _ := redis.Exists("bidx", "bidx_uId_"+uId); isExists {
|
|
|
- redisInt := redis.GetInt("bidx", "bidx_uId_"+uId)
|
|
|
- if redisInt > 2 {
|
|
|
- return 1
|
|
|
- } else {
|
|
|
- redis.Incr("bidx", "bidx_uId_"+uId)
|
|
|
- return 0
|
|
|
- }
|
|
|
- } else {
|
|
|
- redis.Put("bidx", "bidx_uId_"+uId, 1, 3600)
|
|
|
- return 0
|
|
|
+ //其他信息
|
|
|
+ seatNumber = "0000"
|
|
|
+ }
|
|
|
+ if !mongodb.IsObjectIdHex(userId) {
|
|
|
+ positionId = 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"])
|
|
|
}
|
|
|
}
|
|
|
+ query["userid"] = userId
|
|
|
+ userInfo := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
|
|
|
+ if userInfo != nil && len(*userInfo) > 0 {
|
|
|
+ uId = common.ObjToString((*userInfo)["uid"])
|
|
|
+ source = common.ObjToString((*userInfo)["source"]) //用户来源
|
|
|
+ belong_to = common.ObjToString((*userInfo)["belong_to"]) //用户归属
|
|
|
+ }
|
|
|
+ cluename = common.ObjToString(data["company_name"])
|
|
|
+ phone = common.ObjToString(data["user_phone"])
|
|
|
+ //线索信息处理
|
|
|
+ isGroup, isCommerce := GetCompanyType(cluename, uId)
|
|
|
+ if source == "0104" || strings.HasPrefix(belong_to, "02") || source == "0102" || source == "0103" || phone == "" { //参照用户来源代码表
|
|
|
+ return 0
|
|
|
+ }
|
|
|
+ qid := positionId
|
|
|
+ if qid == "" {
|
|
|
+ qid = userId
|
|
|
+ }
|
|
|
+ saleLeadsData, ok := Mgo.Find("saleLeads", map[string]interface{}{"userid": qid}, map[string]interface{}{"_id": -1}, nil, false, 0, 1)
|
|
|
+ if ok && saleLeadsData != nil && len(*saleLeadsData) > 0 {
|
|
|
+ sdata := (*saleLeadsData)[0]
|
|
|
+ role = common.ObjToString(sdata["companyType"])
|
|
|
+ industry = common.ObjToString(sdata["industry"])
|
|
|
+ department = common.ObjToString(sdata["branch"])
|
|
|
+ departments = common.ObjToString(sdata["department"])
|
|
|
+ position = common.ObjToString(sdata["position"])
|
|
|
+ name = common.ObjToString(sdata["name"])
|
|
|
+ }
|
|
|
+ top_cluetype, sub_cluetype, _, topname, subname = getClueType("order", data, sourceCode, sourceId) //查留资来源名字
|
|
|
+ kcClue(userId, uId, seatNumber, cluename, top_cluetype, sub_cluetype,
|
|
|
+ name, phone, position, sourceCode, industry, follow_project_area,
|
|
|
+ role, "order", subname, topname, remark, "", department, departments, salesperson, source,
|
|
|
+ orderPositionId, isGroup, isCommerce,
|
|
|
+ keyword)
|
|
|
+ clueData = TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, "", "")
|
|
|
+ if clueData == nil || len(*clueData) == 0 {
|
|
|
+ return 0
|
|
|
+ }
|
|
|
}
|
|
|
clueId = common.Int64All((*clueData)["id"])
|
|
|
starttime := common.ObjToString(data["vip_starttime"])
|
|
|
endtime := common.ObjToString(data["vip_endtime"])
|
|
|
- //
|
|
|
- // user_role := common.IntAll(data["user_role"])
|
|
|
buy_subject := common.IntAll(data["buy_subject"])
|
|
|
product_type := common.ObjToString(data["product_type"])
|
|
|
data_spec := common.ObjToString(data["data_spec"])
|
|
|
userName := common.ObjToString((*clueData)["name"])
|
|
|
- //phone := common.ObjToString((*clueData)["phone"])
|
|
|
product, company_name := 0, common.ObjToString(data["company_name"])
|
|
|
productMap := map[string]int{
|
|
|
"dhy6": 1,
|
|
@@ -116,81 +159,7 @@ func kcJob(data map[string]interface{}) int {
|
|
|
}
|
|
|
}
|
|
|
//同一公司名称(以客户详情-组织机构-公司名称)下的线索需分配给同1人
|
|
|
- //合力亿捷线索同步
|
|
|
- /*customerData := TiDbData.FindOne("customer", map[string]interface{}{"phone": phone}, "", "")
|
|
|
- if customerData != nil {
|
|
|
- log.Println("移交客成查询到合力亿捷")
|
|
|
- status999 := common.ObjToString((*customerData)["status999"]) //线索状态
|
|
|
- source := common.ObjToString((*customerData)["source"]) //销售来源
|
|
|
- customerNeeds := common.ObjToString((*customerData)["customerNeeds"]) //客户需求
|
|
|
- wantGoods := common.ObjToString((*customerData)["wantGoods"]) //意向产品
|
|
|
- job := common.ObjToString((*customerData)["job"]) //职位
|
|
|
- createTime := common.ObjToString((*customerData)["createTime"]) //创建时间
|
|
|
- lastUpdateTime := common.ObjToString((*customerData)["lastUpdateTime"]) //更新时间
|
|
|
- area := common.ObjToString((*customerData)["area"]) //关注区域
|
|
|
- customerBudget := common.ObjToString((*customerData)["customerBudget"]) //客户预算
|
|
|
- isPolicymaker := common.ObjToString((*customerData)["customerBudget"]) //是否为决策人
|
|
|
- belongToIndustry := common.ObjToString((*customerData)["belongToIndustry"]) //所属行业
|
|
|
- seatNumber := common.ObjToString((*customerData)["empNo"]) //坐席号
|
|
|
- statusMap := map[string]string{
|
|
|
- "status0": "08",
|
|
|
- "status1": "07",
|
|
|
- "status2": "06",
|
|
|
- "status3": "05",
|
|
|
- "status4": "04",
|
|
|
- "status6": "00",
|
|
|
- "status5": "01",
|
|
|
- "spaceNumber": "02",
|
|
|
- "phoneDown": "02",
|
|
|
- }
|
|
|
- if status999 != "" {
|
|
|
- status999 = statusMap[status999]
|
|
|
- } else {
|
|
|
- status999 = "01"
|
|
|
- }
|
|
|
- top_cluetype := "172"
|
|
|
- sub_cluetype := ""
|
|
|
- cluetypeData := TiDb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"name": "其他-" + source}, "", "")
|
|
|
- if cluetypeData != nil {
|
|
|
- sub_cluetype = common.ObjToString((*cluetypeData)["code"])
|
|
|
- }
|
|
|
- wantGoods = strings.ReplaceAll(wantGoods, "剑鱼大会员", "大会员")
|
|
|
- wantGoods = strings.ReplaceAll(wantGoods, "数据导出", "数据流量包")
|
|
|
- if isPolicymaker == "是" {
|
|
|
- isPolicymaker = "决策人"
|
|
|
- } else {
|
|
|
- isPolicymaker = "使用人"
|
|
|
- }
|
|
|
- areaCodeArr := []string{}
|
|
|
- areaCode := ""
|
|
|
- for _, v := range strings.Split(area, ",") {
|
|
|
- areaCodeArr = append(areaCodeArr, AreaCode[v])
|
|
|
- }
|
|
|
- if len(areaCodeArr) > 0 {
|
|
|
- areaCode = strings.Join(areaCodeArr, ",")
|
|
|
- }
|
|
|
- SalePositionId := getSeatNumberPositionId(seatNumber)
|
|
|
- TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, map[string]interface{}{
|
|
|
- "position_id": SalePositionId,
|
|
|
- "seatNumber": seatNumber,
|
|
|
- "is_assign": -2,
|
|
|
- "createtime": createTime,
|
|
|
- "updatetime": lastUpdateTime,
|
|
|
- "top_cluetype": top_cluetype,
|
|
|
- "sub_cluetype": sub_cluetype,
|
|
|
- "customer_demand": customerNeeds,
|
|
|
- "intended_products": wantGoods,
|
|
|
- "customer_budget": customerBudget,
|
|
|
- "contact_type": isPolicymaker,
|
|
|
- "position": job,
|
|
|
- "industry": belongToIndustry,
|
|
|
- "follow_project_area": areaCode,
|
|
|
- })
|
|
|
- }*/
|
|
|
- //
|
|
|
- entIds := common.IntAll(data["ent_id"])
|
|
|
- positionId, name = cAutoDraw(entIds)
|
|
|
- log.Println("移交客成positionId", positionId, name)
|
|
|
+ log.Println("移交客成positionId", positionId, name, saleDep, orderPositionId, salesperson)
|
|
|
saveMap = map[string]interface{}{
|
|
|
"clue_id": clueId,
|
|
|
"transfertime": nowTime,
|
|
@@ -216,6 +185,8 @@ func kcJob(data map[string]interface{}) int {
|
|
|
if TiDb.Count("dwd_f_csm_customer_info", map[string]interface{}{"clue_id": clueId}) > 0 {
|
|
|
csmdata := TiDb.FindOne("dwd_f_csm_customer_info", map[string]interface{}{"clue_id": clueId}, "", "")
|
|
|
if csmdata != nil && len(*csmdata) > 0 {
|
|
|
+ positionId = int64(gconv.Int((*csmdata)["position_id"]))
|
|
|
+ name = gconv.String((*csmdata)["(*csmdata)[\"name\"]"])
|
|
|
TiDb.Update("dwd_f_csm_customer_info", map[string]interface{}{"clue_id": clueId}, map[string]interface{}{
|
|
|
"is_transfer": 0,
|
|
|
"is_renewal_protection": 0,
|
|
@@ -229,40 +200,68 @@ func kcJob(data map[string]interface{}) int {
|
|
|
})
|
|
|
TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
"clue_id": clueId,
|
|
|
- "position_id": (*csmdata)["position_id"],
|
|
|
+ "position_id": positionId,
|
|
|
"change_type": "成交客户移交",
|
|
|
"new_value": "移交至客户成功组",
|
|
|
"createtime": nowTime,
|
|
|
"BCPCID": common.GetRandom(32),
|
|
|
"operator_id": -1,
|
|
|
})
|
|
|
- TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
- "clue_id": clueId,
|
|
|
- "position_id": (*csmdata)["position_id"],
|
|
|
- "change_field": "position_id",
|
|
|
- "change_type": "客户成功经理",
|
|
|
- "old_value": "/",
|
|
|
- "new_value": (*csmdata)["name"],
|
|
|
- "createtime": nowTime,
|
|
|
- "BCPCID": common.GetRandom(32),
|
|
|
- "operator_id": -1,
|
|
|
- })
|
|
|
+ if positionId > 0 {
|
|
|
+ TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
+ "clue_id": clueId,
|
|
|
+ "position_id": positionId,
|
|
|
+ "change_field": "position_id",
|
|
|
+ "change_type": "客户成功经理",
|
|
|
+ "old_value": "/",
|
|
|
+ "new_value": name,
|
|
|
+ "createtime": nowTime,
|
|
|
+ "BCPCID": common.GetRandom(32),
|
|
|
+ "operator_id": -1,
|
|
|
+ })
|
|
|
+ KcSend(orderCode, name)
|
|
|
+ }
|
|
|
+
|
|
|
TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, map[string]interface{}{"is_transfer": 1, "updatetime": nowTime, "name": userName})
|
|
|
}
|
|
|
} else {
|
|
|
+ entIds := common.IntAll(data["ent_id"])
|
|
|
+ if saleDep == "客户成功组" {
|
|
|
+ if orderPositionId == 0 {
|
|
|
+ positionId, name = orderPositionId, salesperson
|
|
|
+ } else {
|
|
|
+ positionId, name = cAutoDraw(entIds)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ positionId, name = cAutoDraw(entIds)
|
|
|
+ }
|
|
|
cId, ok, updateId1, updateId2, updateId3 := int64(-1), false, int64(-1), int64(-1), int64(-1)
|
|
|
if TiDb.ExecTx("保存客户", func(tx *sql.Tx) bool {
|
|
|
cId = TiDb.InsertByTx(tx, "dwd_f_csm_customer_info", saveMap)
|
|
|
ok = TiDb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, map[string]interface{}{"is_transfer": 1, "updatetime": nowTime, "name": userName})
|
|
|
- updateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
- "clue_id": clueId,
|
|
|
- "position_id": positionId,
|
|
|
- "change_type": "加入任务车",
|
|
|
- "new_value": "未建联",
|
|
|
- "createtime": nowTime,
|
|
|
- "BCPCID": common.GetRandom(32),
|
|
|
- "operator_id": -1,
|
|
|
- })
|
|
|
+ if positionId > 0 {
|
|
|
+ updateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
+ "clue_id": clueId,
|
|
|
+ "position_id": positionId,
|
|
|
+ "change_type": "加入任务车",
|
|
|
+ "new_value": "未建联",
|
|
|
+ "createtime": nowTime,
|
|
|
+ "BCPCID": common.GetRandom(32),
|
|
|
+ "operator_id": -1,
|
|
|
+ })
|
|
|
+ updateId3 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
+ "clue_id": clueId,
|
|
|
+ "position_id": positionId,
|
|
|
+ "change_field": "position_id",
|
|
|
+ "change_type": "客户成功经理",
|
|
|
+ "old_value": "/",
|
|
|
+ "new_value": name,
|
|
|
+ "createtime": nowTime,
|
|
|
+ "BCPCID": common.GetRandom(32),
|
|
|
+ "operator_id": -1,
|
|
|
+ })
|
|
|
+ KcSend(orderCode, name)
|
|
|
+ }
|
|
|
updateId2 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
"clue_id": clueId,
|
|
|
"position_id": positionId,
|
|
@@ -272,20 +271,9 @@ func kcJob(data map[string]interface{}) int {
|
|
|
"BCPCID": common.GetRandom(32),
|
|
|
"operator_id": -1,
|
|
|
})
|
|
|
- updateId3 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
- "clue_id": clueId,
|
|
|
- "position_id": positionId,
|
|
|
- "change_field": "position_id",
|
|
|
- "change_type": "客户成功经理",
|
|
|
- "old_value": "/",
|
|
|
- "new_value": name,
|
|
|
- "createtime": nowTime,
|
|
|
- "BCPCID": common.GetRandom(32),
|
|
|
- "operator_id": -1,
|
|
|
- })
|
|
|
return cId > -1 && ok && updateId1 > -1 && updateId2 > -1 && updateId3 > -1
|
|
|
}) {
|
|
|
- TiDb.UpdateOrDeleteBySql(`update dwd_f_csm_customer_autodraw_record set count = count + 1 where name = ?`, name)
|
|
|
+ //TiDb.UpdateOrDeleteBySql(`update dwd_f_csm_customer_autodraw_record set count = count + 1 where name = ?`, name)
|
|
|
log.Println("保存客户成功")
|
|
|
} else {
|
|
|
log.Println("保存客户失败!!!", clueId, cId, ok, updateId1, updateId2, updateId3, " 用户信息 ", name, positionId, uId)
|
|
@@ -306,7 +294,7 @@ func cAutoDraw(entId int) (positionId int64, name string) {
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
- sql := `select a.name,a.count from dwd_f_csm_customer_autodraw_record a INNER JOIN dwd_d_crm_department_level_succbi b on (a.name = b.name) where b.resign = 0`
|
|
|
+ /*sql := `select a.name,a.count from dwd_f_csm_customer_autodraw_record a INNER JOIN dwd_d_crm_department_level_succbi b on (a.name = b.name) where b.resign = 0`
|
|
|
countData := TiDb.SelectBySql(sql)
|
|
|
if countData != nil && len(*countData) > 0 {
|
|
|
for _, v := range *data {
|
|
@@ -342,12 +330,12 @@ func cAutoDraw(entId int) (positionId int64, name string) {
|
|
|
}
|
|
|
countres++
|
|
|
}
|
|
|
- }
|
|
|
- for _, v := range *data {
|
|
|
+ }*/
|
|
|
+ /*for _, v := range *data {
|
|
|
if name == common.ObjToString(v["name"]) {
|
|
|
positionId = common.Int64All(v["position_id"])
|
|
|
}
|
|
|
- }
|
|
|
+ }*/
|
|
|
}
|
|
|
return
|
|
|
}
|
|
@@ -584,22 +572,40 @@ func refundAuto() {
|
|
|
log.Println("自动移交销售定时任务开始")
|
|
|
findNowTime := time.Now().AddDate(0, 0, -db.ExpirationPeriod).Format(date.Date_Full_Layout)
|
|
|
nowTime := time.Now().Format(date.Date_Full_Layout)
|
|
|
+ mailData := map[string][]map[string]interface{}{}
|
|
|
TiDb.SelectByBath(100, func(l *[]map[string]interface{}) bool {
|
|
|
for _, v := range *l {
|
|
|
- saleId, cluename, company_nature, company_verification, uid, phone := int64(0), "", 0, 0, "", ""
|
|
|
+ saleId, cluename, company_nature, company_verification, uid, phone, userName := int64(0), "", 0, 0, "", "", ""
|
|
|
clueId := common.Int64All(v["clue_id"])
|
|
|
+ company_name := gconv.String(v["company_name"])
|
|
|
name := common.ObjToString(v["name"])
|
|
|
kcposition_id := common.Int64All(v["position_id"])
|
|
|
isRenewalProtection := common.IntAll(v["is_renewal_protection"])
|
|
|
- clueData := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, "phone,company_nature,company_verification,cluename,userid,position_id,uid", "")
|
|
|
+ clueData := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, "name,phone,company_nature,company_verification,cluename,userid,position_id,uid", "")
|
|
|
if clueData != nil && len(*clueData) > 0 {
|
|
|
saleId = common.Int64All((*clueData)["position_id"])
|
|
|
cluename = common.ObjToString((*clueData)["cluename"])
|
|
|
+ userName = gconv.String((*clueData)["name"])
|
|
|
company_nature = common.IntAll((*clueData)["company_nature"])
|
|
|
company_verification = common.IntAll((*clueData)["company_verification"])
|
|
|
uid = common.ObjToString((*clueData)["uid"])
|
|
|
phone = common.ObjToString((*clueData)["phone"])
|
|
|
}
|
|
|
+ //查询即将到期数据
|
|
|
+ if isRenewalProtection == 0 {
|
|
|
+ aaa := TiDb.CountBySql(`select count(1) from dwd_f_userbase_order_info where uid=? and (product_type = "企业商机管理" or product_type = "大会员") and order_status = 1 and refund_status!=1 and vip_endtime < ? and vip_endtime > ? `, uid, time.Now().AddDate(0, 0, -db.ExpirationPeriod+1).Format(date.Date_Short_Layout), time.Now().AddDate(0, 0, -db.ExpirationPeriod).Format(date.Date_Short_Layout))
|
|
|
+ log.Println(aaa)
|
|
|
+ if TiDb.CountBySql(`select count(1) from dwd_f_userbase_order_info where uid=? and (product_type = "企业商机管理" or product_type = "大会员") and order_status = 1 and refund_status!=1 and vip_endtime < ? and vip_endtime < ? `, uid, time.Now().AddDate(0, 0, -db.ExpirationPeriod+1).Format(date.Date_Short_Layout), time.Now().AddDate(0, 0, -db.ExpirationPeriod).Format(date.Date_Short_Layout)) > 0 {
|
|
|
+ //即将到期
|
|
|
+ mailData[name] = append(mailData[name], map[string]interface{}{
|
|
|
+ "company_name": company_name,
|
|
|
+ "phone": phone,
|
|
|
+ "userName": userName,
|
|
|
+ "remrk": "1天后即将移交",
|
|
|
+ "reason": "成交客户续费失败",
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
isFull := FindUpperLimit(gconv.String(saleId), "", false)
|
|
|
isAllRefund := false
|
|
|
myOrders := TiDb.SelectBySql(`select refund_status from dwd_f_userbase_order_info where uid=? and (product_type = "企业商机管理" or product_type = "大会员") and order_status = 1 and vip_endtime < ?`, uid, findNowTime)
|
|
@@ -657,6 +663,13 @@ func refundAuto() {
|
|
|
"BCPCID": common.GetRandom(32),
|
|
|
"operator_id": -1,
|
|
|
})
|
|
|
+ mailData[name] = append(mailData[name], map[string]interface{}{
|
|
|
+ "company_name": company_name,
|
|
|
+ "phone": phone,
|
|
|
+ "userName": userName,
|
|
|
+ "remrk": "已移交",
|
|
|
+ "reason": "成交客户申请退款",
|
|
|
+ })
|
|
|
TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_csm_customer_info SET is_transfer=1 WHERE clue_id = ?`, clueId)
|
|
|
} else {
|
|
|
order1 := TiDb.SelectBySql(`select id from dwd_f_userbase_order_info where uid=? and (product_type = "企业商机管理" or product_type = "大会员") and vip_endtime > ? and order_status = 1 `, uid, findNowTime)
|
|
@@ -667,12 +680,12 @@ func refundAuto() {
|
|
|
for _, vv := range *order3 {
|
|
|
if isRenewalProtection == 1 {
|
|
|
vip_endtime := common.ObjToString(vv["vip_endtime"])
|
|
|
- vip_endtimes, _ := time.ParseInLocation(date.Date_Full_Layout, vip_endtime, time.Local)
|
|
|
+ vip_endtimes, _ := time.ParseInLocation(date.Date_Short_Layout, vip_endtime, time.Local)
|
|
|
//查询申请保护时间
|
|
|
renewalTime := time.Time{}
|
|
|
timeData := TiDb.SelectBySql(`select max(createtime) as createtime from dwd_f_crm_clue_change_record where clue_id = ? and change_type="申请续费保护"`, clueId)
|
|
|
if timeData != nil && len(*timeData) > 0 {
|
|
|
- renewalTime, _ = time.ParseInLocation(date.Date_Full_Layout, gconv.String((*timeData)[0]["createtime"]), time.Local)
|
|
|
+ renewalTime, _ = time.ParseInLocation(date.Date_Short_Layout, gconv.String((*timeData)[0]["createtime"]), time.Local)
|
|
|
}
|
|
|
renewalInt := renewalTime.Unix()
|
|
|
log.Println("申请保护期时间", clueId, renewalInt)
|
|
@@ -682,11 +695,17 @@ func refundAuto() {
|
|
|
if time.Now().Unix()-vip_endtimes.Unix() < 3*30*86400 {
|
|
|
isOk = true
|
|
|
}
|
|
|
- } else {
|
|
|
- //一个月
|
|
|
- if time.Now().Unix()-vip_endtimes.Unix() < db.HandoverCycle*86400 {
|
|
|
- isOk = true
|
|
|
- }
|
|
|
+ } else if time.Now().Unix()-vip_endtimes.Unix() < (db.HandoverCycle-1)*86400 {
|
|
|
+ //提前一天提示
|
|
|
+ mailData[name] = append(mailData[name], map[string]interface{}{
|
|
|
+ "company_name": company_name,
|
|
|
+ "phone": phone,
|
|
|
+ "userName": userName,
|
|
|
+ "remrk": "1天后即将移交",
|
|
|
+ "reason": "成交客户续费失败",
|
|
|
+ })
|
|
|
+ } else if time.Now().Unix()-vip_endtimes.Unix() < db.HandoverCycle*86400 {
|
|
|
+ isOk = true
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -747,6 +766,13 @@ func refundAuto() {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ mailData[name] = append(mailData[name], map[string]interface{}{
|
|
|
+ "company_name": company_name,
|
|
|
+ "phone": phone,
|
|
|
+ "userName": userName,
|
|
|
+ "remrk": "已移交",
|
|
|
+ "reason": "成交客户续费失败",
|
|
|
+ })
|
|
|
} else {
|
|
|
if isFull {
|
|
|
TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_clue_info SET is_unfollow=0,updatetime=?,trailstatus="01",top_cluetype="532",sub_cluetype="537",is_transfer=0,is_assign=-3,FREEZE_TIME=? WHERE id = ?`, nowTime, nowTime, clueId)
|
|
@@ -829,7 +855,14 @@ func refundAuto() {
|
|
|
}
|
|
|
}
|
|
|
return true
|
|
|
- }, `select ent_id,clue_id,position_id,name,is_renewal_protection from dwd_f_csm_customer_info where is_transfer = 0`)
|
|
|
+ //}, `select ent_id,clue_id,position_id,name,is_renewal_protection from dwd_f_csm_customer_info where is_transfer = 0`)
|
|
|
+ }, `select ent_id,clue_id,position_id,name,is_renewal_protection from dwd_f_csm_customer_info where id =150022`)
|
|
|
+ //移交电销提醒
|
|
|
+ for i, v := range mailData {
|
|
|
+ if i != "" {
|
|
|
+ ExitKcSend(i, v)
|
|
|
+ }
|
|
|
+ }
|
|
|
log.Println("自动移交销售定时任务结束")
|
|
|
}
|
|
|
|
|
@@ -871,7 +904,7 @@ func FindSaleRecord(orderCode string) (dept string, positionId int64, position s
|
|
|
saler_dept = "销售部"
|
|
|
} else if strings.Contains(saler_dept, "市场") {
|
|
|
saler_dept = "市场部"
|
|
|
- } else if strings.Contains(saler_dept, "市场") {
|
|
|
+ } else if strings.Contains(saler_dept, "客户成功组") {
|
|
|
saler_dept = "客户成功组"
|
|
|
} else {
|
|
|
saler_dept = ""
|
|
@@ -880,3 +913,246 @@ func FindSaleRecord(orderCode string) (dept string, positionId int64, position s
|
|
|
}
|
|
|
return "", int64(0), ""
|
|
|
}
|
|
|
+func kcClue(userId, uId, seatNumber, cluename, top_cluetype, sub_cluetype,
|
|
|
+ name, phone, position, sourceCode, industry, follow_project_area,
|
|
|
+ role, item, subname, topname, remark, demand, department, departments, saleName, source string,
|
|
|
+ positionId int64, isGroup, isCommerce int,
|
|
|
+ keywords []string) bool {
|
|
|
+ clueId, uodateId1, uodateId2, uodateId3, uodateId4, uodateId5 := int64(0), int64(0), int64(0), int64(0), int64(0), int64(0)
|
|
|
+ nowTime := time.Now().Format("2006-01-02 15:04:05")
|
|
|
+ nowTimes := time.Unix(time.Now().Unix()+3600*12, 0).Format("2006-01-02 15:04:05")
|
|
|
+ if TiDb.ExecTx("保存线索", func(tx *sql.Tx) bool {
|
|
|
+ clueId = TiDb.InsertByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{
|
|
|
+ "userid": userId,
|
|
|
+ "uid": uId,
|
|
|
+ "seatNumber": seatNumber,
|
|
|
+ "position_id": positionId,
|
|
|
+ "is_assign": common.If(positionId > 0, 1, 0),
|
|
|
+ "comeintime": nowTime,
|
|
|
+ "createtime": nowTime,
|
|
|
+ "updatetime": nowTime,
|
|
|
+ "cluename": cluename,
|
|
|
+ "top_cluetype": top_cluetype,
|
|
|
+ "sub_cluetype": sub_cluetype,
|
|
|
+ "trailstatus": "01",
|
|
|
+ "name": name,
|
|
|
+ "phone": phone,
|
|
|
+ "position": position,
|
|
|
+ "department": common.If(sourceCode == "app_xzcyh", departments, department),
|
|
|
+ "industry": industry,
|
|
|
+ "follow_project_area": follow_project_area,
|
|
|
+ "role": role,
|
|
|
+ "comeinsource_private": 2,
|
|
|
+ "is_task": 1,
|
|
|
+ "task_time": nowTime,
|
|
|
+ "tasktime": common.If(item == "users", nowTimes, nowTime),
|
|
|
+ "taskstatus": 0,
|
|
|
+ "tasksource": "线索自动分配" + "-" + topname + "-" + subname,
|
|
|
+ "business_scope": common.If(sourceCode == "app_xzcyh", keywords, nil),
|
|
|
+ "company_nature": isGroup,
|
|
|
+ "company_verification": isCommerce,
|
|
|
+ "remark": remark,
|
|
|
+ "customer_demand": demand,
|
|
|
+ "FREEZE_TIME": nowTime,
|
|
|
+ "label": 1,
|
|
|
+ "labelChangeTime": time.Now().Format("2006-01-02"),
|
|
|
+ })
|
|
|
+ uodateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
+ "clue_id": clueId,
|
|
|
+ "position_id": positionId,
|
|
|
+ "change_type": "创建线索",
|
|
|
+ "new_value": "系统自动创建",
|
|
|
+ "createtime": nowTime,
|
|
|
+ "BCPCID": common.GetRandom(32),
|
|
|
+ "operator_id": -1,
|
|
|
+ })
|
|
|
+ uodateId2 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
+ "clue_id": clueId,
|
|
|
+ "position_id": positionId,
|
|
|
+ "change_field": "position_id",
|
|
|
+ "change_type": "所属人变更",
|
|
|
+ "old_value": "/",
|
|
|
+ "new_value": saleName,
|
|
|
+ "createtime": nowTime,
|
|
|
+ "BCPCID": common.GetRandom(32),
|
|
|
+ "operator_id": -1,
|
|
|
+ })
|
|
|
+ uodateId3 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
+ "clue_id": clueId,
|
|
|
+ "position_id": positionId,
|
|
|
+ "change_field": "trailstatus",
|
|
|
+ "change_type": "基本信息变更",
|
|
|
+ "old_value": "商机线索",
|
|
|
+ "new_value": "新增",
|
|
|
+ "createtime": nowTime,
|
|
|
+ "BCPCID": common.GetRandom(32),
|
|
|
+ "operator_id": -1,
|
|
|
+ })
|
|
|
+ uodateId5 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
+ "clue_id": clueId,
|
|
|
+ "position_id": positionId,
|
|
|
+ "change_field": "top_cluetype",
|
|
|
+ "change_type": "基本信息变更",
|
|
|
+ "old_value": "/",
|
|
|
+ "new_value": topname,
|
|
|
+ "createtime": nowTime,
|
|
|
+ "BCPCID": common.GetRandom(32),
|
|
|
+ "operator_id": -1,
|
|
|
+ })
|
|
|
+ uodateId5 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
+ "clue_id": clueId,
|
|
|
+ "position_id": positionId,
|
|
|
+ "change_field": "sub_cluetype", //222
|
|
|
+ "change_type": "基本信息变更",
|
|
|
+ "old_value": "/",
|
|
|
+ "new_value": subname,
|
|
|
+ "createtime": nowTime,
|
|
|
+ "BCPCID": common.GetRandom(32),
|
|
|
+ "operator_id": -1,
|
|
|
+ })
|
|
|
+ return clueId > -1 && uodateId1 > -1 && uodateId2 > -1 && uodateId3 > -1 && uodateId4 > -1 && uodateId5 > -1
|
|
|
+ }) {
|
|
|
+ log.Println("线索分配成功")
|
|
|
+ if TiDb.Count("dwd_f_userbase_contacts", map[string]interface{}{"phone": phone}) == 0 {
|
|
|
+ TiDb.Insert("dwd_f_userbase_contacts", map[string]interface{}{
|
|
|
+ "status": 1,
|
|
|
+ "is_delete": 1,
|
|
|
+ "createtime": nowTime,
|
|
|
+ "updatetime": nowTime,
|
|
|
+ "phone": phone,
|
|
|
+ "baseinfo_id": uId,
|
|
|
+ "SOURCE": source,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ return false
|
|
|
+}
|
|
|
+
|
|
|
+type OrderInfo struct {
|
|
|
+ Id int64
|
|
|
+ UserId string
|
|
|
+ CompanyName string
|
|
|
+ ProductType string
|
|
|
+ OrderCode string
|
|
|
+ PayMoney float64
|
|
|
+ ReturnMoney float64
|
|
|
+ UserPhone string
|
|
|
+ StartEnd string
|
|
|
+ DisKcName string
|
|
|
+ UserName string
|
|
|
+ SeriveList []string
|
|
|
+ SaleName string
|
|
|
+}
|
|
|
+
|
|
|
+// 客成发送邮箱
|
|
|
+func KcSend(orderCode, personName string) {
|
|
|
+ bigmemberService := map[int64]string{}
|
|
|
+ combo := map[int64]string{}
|
|
|
+ Mysql.SelectByBath(1, func(l *[]map[string]interface{}) bool {
|
|
|
+ bigmemberService[common.Int64All((*l)[0]["id"])] = common.ObjToString((*l)[0]["s_name"])
|
|
|
+ return true
|
|
|
+ }, `select id,s_name from jianyu.bigmember_service`)
|
|
|
+ Mysql.SelectByBath(1, func(l *[]map[string]interface{}) bool {
|
|
|
+ combo[common.Int64All((*l)[0]["id"])] = common.ObjToString((*l)[0]["s_name"])
|
|
|
+ return true
|
|
|
+ }, `select id,s_name from jianyu.bigmember_combo`)
|
|
|
+ orderInfo := KcOrderFormat(orderCode, bigmemberService, combo)
|
|
|
+ if orderInfo != nil {
|
|
|
+ tableAppend := ""
|
|
|
+ if len(orderInfo.SeriveList) > 0 {
|
|
|
+ tableAppend = fmt.Sprintf(db.KeCheng.Mail.ServiceList, strings.Join(orderInfo.SeriveList, ","))
|
|
|
+ }
|
|
|
+ if orderInfo.ReturnMoney > 0 {
|
|
|
+ tableAppend += fmt.Sprintf(db.KeCheng.Mail.ReturnMoney, orderInfo.ReturnMoney)
|
|
|
+ }
|
|
|
+ table := ""
|
|
|
+ deptData := Mysql.SelectBySql("select b.mail from jianyu.entniche_department_user a inner join jianyu.entniche_user b on a.dept_id=? and a.user_id=b.id and b.name=? ", db.KeCheng.DeptId, personName)
|
|
|
+ table += fmt.Sprintf(db.KeCheng.Mail.Table, orderInfo.ProductType, orderInfo.CompanyName, orderInfo.UserPhone, orderInfo.UserName, orderInfo.OrderCode, orderInfo.PayMoney, orderInfo.StartEnd, orderInfo.DisKcName, orderInfo.SaleName, tableAppend)
|
|
|
+ //发送邮件
|
|
|
+ if deptData != nil && len(*deptData) > 0 && table != "" {
|
|
|
+ mailStr := gconv.String((*deptData)[0]["mail"])
|
|
|
+ if mailStr != "" {
|
|
|
+ gmail := &mail.GmailAuth{
|
|
|
+ SmtpHost: db.Mail.SmtpHost,
|
|
|
+ SmtpPort: db.Mail.SmtpPort,
|
|
|
+ User: db.Mail.User,
|
|
|
+ Pwd: db.Mail.Pwd,
|
|
|
+ }
|
|
|
+ status := mail.GSendMail_q("剑鱼标讯", mailStr, "", "", db.KeCheng.Title, fmt.Sprintf(db.KeCheng.Mail.Content, table), "", "", gmail)
|
|
|
+ if status {
|
|
|
+ log.Println("客成发邮件 send mail success", table, mailStr)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+func ExitKcSend(personName string, infoList []map[string]interface{}) {
|
|
|
+ //退出客成 即将退出客成信息
|
|
|
+ deptData := Mysql.SelectBySql("select b.mail from jianyu.entniche_department_user a inner join jianyu.entniche_user b on a.dept_id=? and a.user_id=b.id and b.name=? ", db.KeCheng.DeptId, personName)
|
|
|
+ if deptData != nil && len(*deptData) > 0 {
|
|
|
+ mailStr := gconv.String((*deptData)[0]["mail"])
|
|
|
+ if mailStr != "" {
|
|
|
+ gmail := &mail.GmailAuth{
|
|
|
+ SmtpHost: db.Mail.SmtpHost,
|
|
|
+ SmtpPort: db.Mail.SmtpPort,
|
|
|
+ User: db.Mail.User,
|
|
|
+ Pwd: db.Mail.Pwd,
|
|
|
+ }
|
|
|
+ //正文拼接
|
|
|
+ startStr := `<html lang="zh-CN"><head><meta charset="UTF-8"><meta name="viewport"content="width=device-width, initial-scale=1.0"><style>table{width:100%;border-collapse:collapse}th,td{border:1px solid#000;padding:8px;text-align:left}th{background-color:#f2f2f2}</style></head><body><table><thead><tr><th>序号</th><th>公司名称</th><th>联系人</th><th>姓名</th><th>移交状态</th><th>移交销售原因</th></tr></thead><tbody>`
|
|
|
+ for i, v := range infoList {
|
|
|
+ startStr += fmt.Sprintf(`<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>`, i+1, gconv.String(v["company_name"]), gconv.String(v["phone"]), gconv.String(v["name"]), gconv.String(v["remrk"]), gconv.String(v["reason"]))
|
|
|
+ }
|
|
|
+ endStr := `</tbody></table><p></body></html>`
|
|
|
+ startStr += endStr
|
|
|
+ status := mail.GSendMail_q("剑鱼标讯", mailStr, "", "", "客户退出客成系统通知", startStr, "", "", gmail)
|
|
|
+ if status {
|
|
|
+ log.Println("客成发邮件 send mail success", startStr, mailStr)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+func KcOrderFormat(orderCode string, bigmemberService, combo map[int64]string) *OrderInfo {
|
|
|
+ orderData := Mysql.SelectBySql(`SELECT a.id,a.order_code,a.pay_money,a.user_phone,a.vip_starttime,a.vip_endtime,a.product_type,a.filter,a.user_id,a.ent_id,a.company_name,a.create_person,SUM(b.return_money) AS return_money
|
|
|
+ FROM jianyu.dataexport_order a
|
|
|
+ LEFT JOIN return_money_record b ON (a.order_code=b.order_code)
|
|
|
+ WHERE a.order_code=? AND a.order_status=1 AND (a.product_type='大会员' OR a.product_type='大会员-子账号')
|
|
|
+ GROUP BY a.id ORDER BY a.autoUpdate`, orderCode)
|
|
|
+ data := &OrderInfo{}
|
|
|
+ if orderData != nil && len(*orderData) > 0 {
|
|
|
+ id := common.Int64All((*orderData)[0]["id"])
|
|
|
+ user_phone := common.ObjToString((*orderData)[0]["user_phone"])
|
|
|
+ user_id := common.ObjToString((*orderData)[0]["user_id"])
|
|
|
+ product_type := common.ObjToString((*orderData)[0]["product_type"])
|
|
|
+ serviceList := []string{}
|
|
|
+ if filter := common.ObjToString((*orderData)[0]["filter"]); filter != "" {
|
|
|
+ filterMap := map[string]interface{}{}
|
|
|
+ json.Unmarshal([]byte(filter), &filterMap)
|
|
|
+ if level := common.Int64All(filterMap["level"]); level == 5 {
|
|
|
+ product_type += "自定义版"
|
|
|
+ for _, serversId := range strings.Split(common.ObjToString(filterMap["serversId"]), ",") {
|
|
|
+ if serviceName := bigmemberService[common.Int64All(serversId)]; serviceName != "" {
|
|
|
+ serviceList = append(serviceList, serviceName)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ product_type += combo[common.Int64All(filterMap["comboId"])]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ data = &OrderInfo{
|
|
|
+ Id: id,
|
|
|
+ CompanyName: common.ObjToString((*orderData)[0]["company_name"]),
|
|
|
+ UserId: user_id,
|
|
|
+ ProductType: product_type,
|
|
|
+ OrderCode: orderCode,
|
|
|
+ PayMoney: common.Float64All((*orderData)[0]["pay_money"]) / 100,
|
|
|
+ ReturnMoney: common.Float64All((*orderData)[0]["return_money"]) / 100,
|
|
|
+ UserPhone: user_phone,
|
|
|
+ StartEnd: fmt.Sprintf("%s--%s", strings.Split(common.ObjToString((*orderData)[0]["vip_starttime"]), " ")[0], strings.Split(common.ObjToString((*orderData)[0]["vip_endtime"]), " ")[0]),
|
|
|
+ SeriveList: serviceList,
|
|
|
+ SaleName: common.ObjToString((*orderData)[0]["create_person"]),
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return data
|
|
|
+}
|