|
@@ -4,7 +4,6 @@ import (
|
|
"app.yhyue.com/moapp/jybase/mail"
|
|
"app.yhyue.com/moapp/jybase/mail"
|
|
"app.yhyue.com/moapp/jybase/redis"
|
|
"app.yhyue.com/moapp/jybase/redis"
|
|
"database/sql"
|
|
"database/sql"
|
|
- "encoding/json"
|
|
|
|
"fmt"
|
|
"fmt"
|
|
"log"
|
|
"log"
|
|
"strings"
|
|
"strings"
|
|
@@ -19,22 +18,49 @@ import (
|
|
|
|
|
|
func kcSync() {
|
|
func kcSync() {
|
|
log.Println("客户成功系统移交定时任务开始")
|
|
log.Println("客户成功系统移交定时任务开始")
|
|
- sql := `select * from dwd_f_userbase_order_info where (payable_money > 0 or (payable_money=0 and ( filter like "%分期付款补充权益%" or filter like "%原订单不支持开通多项权益%" or filter like "%权益码兑换%")))
|
|
|
|
- and data_spec!="dhy4" and phone not like "9%" and order_status=1 and (refund_status!=1 or refund_status is null ) and vip_starttime<"2099-01-01"
|
|
|
|
- and vip_endtime > "` + time.Now().Format(date.Date_Full_Layout) + `" and autoUpdate > "` + cfg.LastkcTime + `" order by autoUpdate asc`
|
|
|
|
- //sql := `select * from dwd_f_userbase_order_info where order_code="173943424276" `
|
|
|
|
- data := TiDb.SelectBySql(sql)
|
|
|
|
|
|
+ //商品查询
|
|
|
|
+ productArr, _ := KcProduct()
|
|
|
|
+ if len(productArr) == 0 {
|
|
|
|
+ log.Println("查询不到进客成商品类型")
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ sql := `SELECT
|
|
|
|
+ a.*,b.product_type,b.service_starttime,b.service_endtime,b.service_type,b.filter as productFilter,TIMESTAMPDIFF(DAY, b.service_starttime, b.service_endtime) as difference,b.update_time
|
|
|
|
+FROM
|
|
|
|
+ dataexport_order a
|
|
|
|
+ INNER JOIN jy_order_detail b ON a.order_code = b.order_code
|
|
|
|
+ and b.product_type in (%s)
|
|
|
|
+ AND (
|
|
|
|
+ a.pay_money > 0
|
|
|
|
+ OR (
|
|
|
|
+ a.pay_money = 0
|
|
|
|
+ AND ( a.zero_type = "分期付款权益补充" OR a.zero_type = "原订单不支持开通多项权益" OR a.zero_type = "权益码兑换" )))
|
|
|
|
+ AND a.user_phone NOT LIKE "%s"
|
|
|
|
+ and a.user_id !=""
|
|
|
|
+ AND a.order_status = 1
|
|
|
|
+ AND ( a.refund_status != 1 OR a.refund_status IS NULL )
|
|
|
|
+ AND b.service_starttime < "2099-01-01" AND b.service_endtime > now()
|
|
|
|
+ AND b.update_time > "%s"
|
|
|
|
+
|
|
|
|
+ORDER BY
|
|
|
|
+ a.order_code ASC,
|
|
|
|
+ difference desc ,
|
|
|
|
+ b.final_price DESC `
|
|
|
|
+ sql = fmt.Sprintf(sql, strings.Join(productArr, ","), "9%", cfg.LastkcTime)
|
|
|
|
+ //sql = fmt.Sprintf(sql, strings.Join(productArr, ","), "9%", "2025-01-02", "103557341197")
|
|
|
|
+ data := Mysql.SelectBySql(sql)
|
|
|
|
+ fmt.Println("客成查询到的数量:", len(*data))
|
|
customList := gconv.Strings(redis.Get("newother", "customList"))
|
|
customList := gconv.Strings(redis.Get("newother", "customList"))
|
|
if data != nil && *data != nil && len(*data) > 0 {
|
|
if data != nil && *data != nil && len(*data) > 0 {
|
|
- arr := []string{}
|
|
|
|
|
|
+ orderMap := map[string]map[string]interface{}{}
|
|
for _, v := range *data {
|
|
for _, v := range *data {
|
|
- product_type := common.ObjToString(v["product_type"])
|
|
|
|
- vip_starttime := common.ObjToString(v["vip_starttime"])
|
|
|
|
- vip_endtime := common.ObjToString(v["vip_endtime"])
|
|
|
|
- order_change := gconv.Int64(v["order_change"])
|
|
|
|
- if (product_type == "大会员" || product_type == "企业商机管理") && ((order_change != 0) || (order_change == 0 && TimeStrcount(vip_starttime, vip_endtime) > 95)) {
|
|
|
|
- orderCode := gconv.String(v["order_code"])
|
|
|
|
- arr = append(arr, orderCode)
|
|
|
|
|
|
+ orderCode := gconv.String(v["order_code"])
|
|
|
|
+ productType := gconv.String(v["product_type"])
|
|
|
|
+ vipStarttime := gconv.String(v["service_starttime"])
|
|
|
|
+ vipEndtime := gconv.String(v["service_endtime"])
|
|
|
|
+ service_type := gconv.Int64(v["service_type"])
|
|
|
|
+ difference := gconv.Int(v["difference"])
|
|
|
|
+ if (service_type != 4) || (service_type == 4 && difference > 95) {
|
|
isExit := false
|
|
isExit := false
|
|
for _, v := range customList {
|
|
for _, v := range customList {
|
|
if v == orderCode {
|
|
if v == orderCode {
|
|
@@ -45,25 +71,66 @@ func kcSync() {
|
|
if isExit {
|
|
if isExit {
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
|
|
+ //判断一下服务周期
|
|
|
|
+ _, productInt64, _ := GetOrderProduct(productType, gconv.String(v["productFilter"]))
|
|
|
|
+ if productInt64 == 0 {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ if _, exists := orderMap[orderCode]; exists {
|
|
|
|
+ //判断服务周期
|
|
|
|
+ data := orderMap[orderCode]
|
|
|
|
+ //商品类型获取
|
|
|
|
+ oldDifference := gconv.Int(data["difference"])
|
|
|
|
+ if oldDifference < difference {
|
|
|
|
+ //需要更换
|
|
|
|
+ v["difference"] = difference
|
|
|
|
+ v["product"] = productInt64
|
|
|
|
+ v["service_endtime"] = vipEndtime
|
|
|
|
+ v["service_starttime"] = vipStarttime
|
|
|
|
+ orderMap[orderCode] = v
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ v["difference"] = difference
|
|
|
|
+ v["product"] = productInt64
|
|
|
|
+ orderMap[orderCode] = v
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ for _, v := range *data {
|
|
|
|
+ orderCode := gconv.String(v["order_code"])
|
|
|
|
+ if _, exists := orderMap[orderCode]; exists {
|
|
status := kcJob(v)
|
|
status := kcJob(v)
|
|
log.Println("订单进客成打印", orderCode, status)
|
|
log.Println("订单进客成打印", orderCode, status)
|
|
if status == 0 {
|
|
if status == 0 {
|
|
break
|
|
break
|
|
}
|
|
}
|
|
|
|
+ cfg.LastkcTime = gconv.String(v["update_time"])
|
|
customList = append(customList, orderCode)
|
|
customList = append(customList, orderCode)
|
|
|
|
+ delete(orderMap, orderCode)
|
|
}
|
|
}
|
|
- cfg.LastkcTime = common.ObjToString(v["autoUpdate"])
|
|
|
|
}
|
|
}
|
|
- redis.Put("newother", "customList", customList, 0)
|
|
|
|
- log.Println(strings.Join(arr, "`,`"))
|
|
|
|
}
|
|
}
|
|
|
|
+ redis.Put("newother", "customList", customList, 0)
|
|
common.WriteSysConfig(&cfg)
|
|
common.WriteSysConfig(&cfg)
|
|
log.Println("客户成功系统移交定时任务结束")
|
|
log.Println("客户成功系统移交定时任务结束")
|
|
}
|
|
}
|
|
|
|
|
|
func kcJob(data map[string]interface{}) int {
|
|
func kcJob(data map[string]interface{}) int {
|
|
nowTime := time.Now().Format(date.Date_Full_Layout)
|
|
nowTime := time.Now().Format(date.Date_Full_Layout)
|
|
- uId, entId, clueId, saveMap, status := common.ObjToString(data["uid"]), fmt.Sprint(data["ent_id"]), int64(0), map[string]interface{}{}, 1
|
|
|
|
|
|
+ uId, entId, clueId, saveMap, status := "", gconv.String(data["ent_id"]), int64(0), map[string]interface{}{}, 1
|
|
|
|
+ userId, cluename, phone := "", "", ""
|
|
|
|
+ phone = gconv.String(data["user_phone"])
|
|
|
|
+ uId, userId = GetUidToUserId(gconv.String(data["user_id"]), "")
|
|
|
|
+ log.Println("用户信息获取", data["user_id"], uId, userId)
|
|
|
|
+ if uId == "" {
|
|
|
|
+ log.Println("移交客成缺少基本信息,缺少用户信息", uId)
|
|
|
|
+ return 0
|
|
|
|
+ }
|
|
|
|
+ buy_subject := common.IntAll(data["buy_subject"])
|
|
|
|
+ if buy_subject == 1 || buy_subject == 0 {
|
|
|
|
+ entId = gconv.String(data["user_id"])
|
|
|
|
+ }
|
|
clueData := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, "", "")
|
|
clueData := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, "", "")
|
|
orderCode := gconv.String(data["order_code"])
|
|
orderCode := gconv.String(data["order_code"])
|
|
saleDep, orderPositionId, salesperson := FindSaleRecord(orderCode)
|
|
saleDep, orderPositionId, salesperson := FindSaleRecord(orderCode)
|
|
@@ -73,30 +140,18 @@ func kcJob(data map[string]interface{}) int {
|
|
log.Println("移交客成缺少基本信息", uId)
|
|
log.Println("移交客成缺少基本信息", uId)
|
|
return 0
|
|
return 0
|
|
}
|
|
}
|
|
- //创建线索
|
|
|
|
//原始订单获取
|
|
//原始订单获取
|
|
position_id := int64(0)
|
|
position_id := int64(0)
|
|
- orderData := Mysql.FindOne("dataexport_order", map[string]interface{}{
|
|
|
|
- "order_code": orderCode,
|
|
|
|
- }, "", "")
|
|
|
|
- if orderData == nil {
|
|
|
|
- log.Println("原始订单查询不到:", orderCode)
|
|
|
|
- }
|
|
|
|
- userId, cluename, phone := common.ObjToString((*orderData)["user_id"]), "", ""
|
|
|
|
seatNumber := ""
|
|
seatNumber := ""
|
|
- if saleDep == "客户成功组" {
|
|
|
|
|
|
+ if saleDep == "客户成功部" {
|
|
//新增线索
|
|
//新增线索
|
|
position_id = 0
|
|
position_id = 0
|
|
- } else if saleDep == "销售部" {
|
|
|
|
- log.Println("该订单数据销售部业绩,不会创建线索")
|
|
|
|
- return 0
|
|
|
|
} else {
|
|
} else {
|
|
position_id = orderPositionId
|
|
position_id = orderPositionId
|
|
//其他信息
|
|
//其他信息
|
|
seatNumber = "0000"
|
|
seatNumber = "0000"
|
|
}
|
|
}
|
|
- cluename = common.ObjToString(data["company_name"])
|
|
|
|
- phone = common.ObjToString(data["phone"])
|
|
|
|
|
|
+ cluename = gconv.String(data["company_name"])
|
|
if cluename == "" {
|
|
if cluename == "" {
|
|
cluename = phone
|
|
cluename = phone
|
|
}
|
|
}
|
|
@@ -142,53 +197,12 @@ func kcJob(data map[string]interface{}) int {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
clueId = common.Int64All((*clueData)["id"])
|
|
clueId = common.Int64All((*clueData)["id"])
|
|
- starttime := common.ObjToString(data["vip_starttime"])
|
|
|
|
- endtime := common.ObjToString(data["vip_endtime"])
|
|
|
|
- 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"])
|
|
|
|
- product, company_name := 0, common.ObjToString(data["company_name"])
|
|
|
|
- productMap := map[string]int{
|
|
|
|
- "dhy6": 1,
|
|
|
|
- "dhy7": 2,
|
|
|
|
- "dhy3": 4,
|
|
|
|
- "dhy1": 5,
|
|
|
|
- "dhy2": 6,
|
|
|
|
- "dhy5": 7,
|
|
|
|
- "企业商机管理": 8,
|
|
|
|
- }
|
|
|
|
- if buy_subject == 1 || buy_subject == 0 {
|
|
|
|
- entId = common.ObjToString(data["userid"])
|
|
|
|
- }
|
|
|
|
- if product_type == "企业商机管理" {
|
|
|
|
- product = productMap[product_type]
|
|
|
|
- powerData := TiDb.FindOne("dwd_f_data_equity_info", map[string]interface{}{"uid": uId, "product_type": "商机管理"}, "", "comeintime desc")
|
|
|
|
- if powerData != nil {
|
|
|
|
- starttime = common.ObjToString((*powerData)["starttime"])
|
|
|
|
- endtime = common.ObjToString((*powerData)["endtime"])
|
|
|
|
- } else {
|
|
|
|
- log.Println("客成移交权限未查到--", uId)
|
|
|
|
- return 0
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- if data_spec == "dhy6" {
|
|
|
|
- product = 1
|
|
|
|
- filter := common.ObjToString(data["filter"])
|
|
|
|
- filterMap := map[string]interface{}{}
|
|
|
|
- json.Unmarshal([]byte(filter), &filterMap)
|
|
|
|
- if len(filterMap) > 0 {
|
|
|
|
- areaCount := common.IntAll(filterMap["areaCount"])
|
|
|
|
- if areaCount == 1 {
|
|
|
|
- product = 3
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- product = productMap[data_spec]
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ starttime := gconv.String(data["service_starttime"])
|
|
|
|
+ endtime := gconv.String(data["service_endtime"])
|
|
|
|
+ //product_type := gconv.String(data["product_type"])
|
|
|
|
+ userName := gconv.String((*clueData)["name"])
|
|
|
|
+ product, company_name := gconv.String(data["product"]), gconv.String(data["company_name"])
|
|
//同一公司名称(以客户详情-组织机构-公司名称)下的线索需分配给同1人
|
|
//同一公司名称(以客户详情-组织机构-公司名称)下的线索需分配给同1人
|
|
-
|
|
|
|
saveMap = map[string]interface{}{
|
|
saveMap = map[string]interface{}{
|
|
"clue_id": clueId,
|
|
"clue_id": clueId,
|
|
"transfertime": nowTime,
|
|
"transfertime": nowTime,
|
|
@@ -285,8 +299,7 @@ func kcJob(data map[string]interface{}) int {
|
|
TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, map[string]interface{}{"is_transfer": 1, "updatetime": nowTime, "name": userName})
|
|
TiDb.Update("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, map[string]interface{}{"is_transfer": 1, "updatetime": nowTime, "name": userName})
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- entIds := common.IntAll(data["ent_id"])
|
|
|
|
- customerPositionId, customerName := cAutoDraw(entIds, orderPositionId, salesperson, saleDep, false, nil)
|
|
|
|
|
|
+ customerPositionId, customerName := cAutoDraw(gconv.Int(entId), orderPositionId, salesperson, saleDep, false, nil)
|
|
log.Println("移交客成positionId", customerPositionId, customerName, saleDep, orderPositionId, salesperson, false)
|
|
log.Println("移交客成positionId", customerPositionId, customerName, saleDep, orderPositionId, salesperson, false)
|
|
cId, ok, updateId1, updateId2, updateId3 := int64(0), false, int64(0), int64(0), int64(0)
|
|
cId, ok, updateId1, updateId2, updateId3 := int64(0), false, int64(0), int64(0), int64(0)
|
|
if TiDb.ExecTx("保存客户", func(tx *sql.Tx) bool {
|
|
if TiDb.ExecTx("保存客户", func(tx *sql.Tx) bool {
|
|
@@ -328,7 +341,6 @@ func kcJob(data map[string]interface{}) int {
|
|
})
|
|
})
|
|
return cId > -1 && ok && updateId1 > -1 && updateId2 > -1 && updateId3 > -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)
|
|
|
|
if customerName == db.KeCheng.Admin {
|
|
if customerName == db.KeCheng.Admin {
|
|
TiDb.UpdateOrDeleteBySql(`update dwd_f_csm_customer_autodraw_record set count = count + 2 where name = ?`, customerName)
|
|
TiDb.UpdateOrDeleteBySql(`update dwd_f_csm_customer_autodraw_record set count = count + 2 where name = ?`, customerName)
|
|
} else {
|
|
} else {
|
|
@@ -343,7 +355,7 @@ func kcJob(data map[string]interface{}) int {
|
|
}
|
|
}
|
|
|
|
|
|
func cAutoDraw(entId int, orderPositionId int64, salesperson, saleDep string, isExist bool, csmdata *map[string]interface{}) (positionId int64, name string) {
|
|
func cAutoDraw(entId int, orderPositionId int64, salesperson, saleDep string, isExist bool, csmdata *map[string]interface{}) (positionId int64, name string) {
|
|
- query := `SELECT name,position_id FROM dwd_d_crm_department_level_succbi WHERE bi_pcode = (SELECT bi_code FROM dwd_d_crm_department_level_succbi WHERE name = "客户成功部" and resign=0 and ent_id=?) and resign = 0 `
|
|
|
|
|
|
+ query := `SELECT name,position_id FROM dwd_d_crm_department_level_succbi WHERE bi_pcode = (SELECT bi_code FROM dwd_d_crm_department_level_succbi WHERE name = "客户成功部" and resign=0 and ent_id=?) and resign = 0 and position_id is not null `
|
|
data := TiDb.SelectBySql(query, db.EntId)
|
|
data := TiDb.SelectBySql(query, db.EntId)
|
|
if data == nil || len(*data) == 0 {
|
|
if data == nil || len(*data) == 0 {
|
|
return
|
|
return
|
|
@@ -365,13 +377,13 @@ func findKcOldPerson(entId int, orderPositionId int64, salesperson, saleDep stri
|
|
deptPositionId := gconv.Int64(v["position_id"])
|
|
deptPositionId := gconv.Int64(v["position_id"])
|
|
if deptPositionId == positionid {
|
|
if deptPositionId == positionid {
|
|
positionId = positionid
|
|
positionId = positionid
|
|
- name = common.ObjToString((*csmdata)["name"])
|
|
|
|
|
|
+ name = gconv.String((*csmdata)["name"])
|
|
return
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//原始用户已离职 查看订单是否有合适的订单
|
|
//原始用户已离职 查看订单是否有合适的订单
|
|
- if saleDep == "客户成功组" {
|
|
|
|
|
|
+ if saleDep == "客户成功部" {
|
|
positionId = orderPositionId
|
|
positionId = orderPositionId
|
|
name = salesperson
|
|
name = salesperson
|
|
return
|
|
return
|
|
@@ -384,19 +396,19 @@ func findKcOldPerson(entId int, orderPositionId int64, salesperson, saleDep stri
|
|
if entdata != nil && len(*entdata) > 0 {
|
|
if entdata != nil && len(*entdata) > 0 {
|
|
for _, v := range *entdata {
|
|
for _, v := range *entdata {
|
|
positionid := common.Int64All(v["position_id"])
|
|
positionid := common.Int64All(v["position_id"])
|
|
- name = common.ObjToString(v["name"])
|
|
|
|
|
|
+ name = gconv.String(v["name"])
|
|
for _, v := range *data {
|
|
for _, v := range *data {
|
|
deptPositionId := gconv.Int64(v["position_id"])
|
|
deptPositionId := gconv.Int64(v["position_id"])
|
|
if deptPositionId == positionId {
|
|
if deptPositionId == positionId {
|
|
positionId = positionid
|
|
positionId = positionid
|
|
- name = common.ObjToString((*csmdata)["name"])
|
|
|
|
|
|
+ name = gconv.String((*csmdata)["name"])
|
|
return
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//原始用户已离职 或者没有查找相关企业客成信息 以订单信息为主
|
|
//原始用户已离职 或者没有查找相关企业客成信息 以订单信息为主
|
|
- if saleDep == "客户成功组" {
|
|
|
|
|
|
+ if saleDep == "客户成功部" {
|
|
positionId = orderPositionId
|
|
positionId = orderPositionId
|
|
name = salesperson
|
|
name = salesperson
|
|
}
|
|
}
|
|
@@ -404,7 +416,7 @@ func findKcOldPerson(entId int, orderPositionId int64, salesperson, saleDep stri
|
|
//没有相同企业的客成信息
|
|
//没有相同企业的客成信息
|
|
} else {
|
|
} else {
|
|
//没有人 分配给自己
|
|
//没有人 分配给自己
|
|
- if saleDep == "客户成功组" {
|
|
|
|
|
|
+ if saleDep == "客户成功部" {
|
|
positionId = orderPositionId
|
|
positionId = orderPositionId
|
|
name = salesperson
|
|
name = salesperson
|
|
return
|
|
return
|
|
@@ -417,7 +429,7 @@ func findKcNewPerson(entId int, data *[]map[string]interface{}) (positionId int6
|
|
entdata := TiDb.FindOne("dwd_f_csm_customer_info", map[string]interface{}{"ent_id": entId}, "", "")
|
|
entdata := TiDb.FindOne("dwd_f_csm_customer_info", map[string]interface{}{"ent_id": entId}, "", "")
|
|
if entdata != nil && len(*entdata) > 0 {
|
|
if entdata != nil && len(*entdata) > 0 {
|
|
positionId = common.Int64All((*entdata)["position_id"])
|
|
positionId = common.Int64All((*entdata)["position_id"])
|
|
- name = common.ObjToString((*entdata)["name"])
|
|
|
|
|
|
+ name = gconv.String((*entdata)["name"])
|
|
return
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -428,13 +440,13 @@ func findKcNewPerson(entId int, data *[]map[string]interface{}) (positionId int6
|
|
//判断是否有新员工
|
|
//判断是否有新员工
|
|
isOk := false
|
|
isOk := false
|
|
for _, vv := range *countData {
|
|
for _, vv := range *countData {
|
|
- if common.ObjToString(v["name"]) == common.ObjToString(vv["name"]) {
|
|
|
|
|
|
+ if gconv.String(v["name"]) == gconv.String(vv["name"]) {
|
|
isOk = true
|
|
isOk = true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//有新员工直接分给新员工
|
|
//有新员工直接分给新员工
|
|
if !isOk {
|
|
if !isOk {
|
|
- name = common.ObjToString(v["name"])
|
|
|
|
|
|
+ name = gconv.String(v["name"])
|
|
rData := TiDb.FindOne("dwd_f_csm_customer_autodraw_record", map[string]interface{}{}, "", "count desc")
|
|
rData := TiDb.FindOne("dwd_f_csm_customer_autodraw_record", map[string]interface{}{}, "", "count desc")
|
|
TiDb.Insert("dwd_f_csm_customer_autodraw_record", map[string]interface{}{
|
|
TiDb.Insert("dwd_f_csm_customer_autodraw_record", map[string]interface{}{
|
|
"name": name,
|
|
"name": name,
|
|
@@ -448,18 +460,18 @@ func findKcNewPerson(entId int, data *[]map[string]interface{}) (positionId int6
|
|
for _, v := range *countData {
|
|
for _, v := range *countData {
|
|
if countres == 0 {
|
|
if countres == 0 {
|
|
res = common.Int64All(v["count"])
|
|
res = common.Int64All(v["count"])
|
|
- name = common.ObjToString(v["name"])
|
|
|
|
|
|
+ name = gconv.String(v["name"])
|
|
} else {
|
|
} else {
|
|
if common.Int64All(v["count"]) <= res {
|
|
if common.Int64All(v["count"]) <= res {
|
|
res = common.Int64All(v["count"])
|
|
res = common.Int64All(v["count"])
|
|
- name = common.ObjToString(v["name"])
|
|
|
|
|
|
+ name = gconv.String(v["name"])
|
|
}
|
|
}
|
|
}
|
|
}
|
|
countres++
|
|
countres++
|
|
}
|
|
}
|
|
}
|
|
}
|
|
for _, v := range *data {
|
|
for _, v := range *data {
|
|
- if name == common.ObjToString(v["name"]) {
|
|
|
|
|
|
+ if name == gconv.String(v["name"]) {
|
|
positionId = common.Int64All(v["position_id"])
|
|
positionId = common.Int64All(v["position_id"])
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -477,7 +489,7 @@ func kcAuto() {
|
|
training_way := common.IntAll(v["training_way"])
|
|
training_way := common.IntAll(v["training_way"])
|
|
positionId := common.Int64All(v["position_id"])
|
|
positionId := common.Int64All(v["position_id"])
|
|
clueId := common.Int64All(v["clue_id"])
|
|
clueId := common.Int64All(v["clue_id"])
|
|
- tasksource, tasksources := common.ObjToString(v["tasksource"]), ""
|
|
|
|
|
|
+ tasksource, tasksources := gconv.String(v["tasksource"]), ""
|
|
taskstatus := common.IntAll(v["taskstatus"])
|
|
taskstatus := common.IntAll(v["taskstatus"])
|
|
if relationship_building_way != 1 && inventory_way == 1 {
|
|
if relationship_building_way != 1 && inventory_way == 1 {
|
|
tasksources = "2"
|
|
tasksources = "2"
|
|
@@ -527,66 +539,60 @@ func kcAuto() {
|
|
func ordersClue() {
|
|
func ordersClue() {
|
|
lastOrderClueId := cfg.LastOrderClueId
|
|
lastOrderClueId := cfg.LastOrderClueId
|
|
nowTime := time.Now().Format(date.Date_Full_Layout)
|
|
nowTime := time.Now().Format(date.Date_Full_Layout)
|
|
|
|
+<<<<<<< HEAD
|
|
sql := fmt.Sprintf(`select order_code,order_status,is_backstage_order,pay_money,saleDep,salesperson,user_phone,create_person,saleMoney,user_id,product_type,company_name,autoUpdate from dataexport_order where autoUpdate >= "%s" order by autoUpdate asc`, lastOrderClueId)
|
|
sql := fmt.Sprintf(`select order_code,order_status,is_backstage_order,pay_money,saleDep,salesperson,user_phone,create_person,saleMoney,user_id,product_type,company_name,autoUpdate from dataexport_order where autoUpdate >= "%s" order by autoUpdate asc`, lastOrderClueId)
|
|
log.Println("后台订单线索定时任务开始:", sql)
|
|
log.Println("后台订单线索定时任务开始:", sql)
|
|
data := Mysql.SelectBySql(sql)
|
|
data := Mysql.SelectBySql(sql)
|
|
log.Println("后台订单线索定时任务开始:", len(*data))
|
|
log.Println("后台订单线索定时任务开始:", len(*data))
|
|
|
|
+=======
|
|
|
|
+ product_type_str2 := `"大会员","企业商机管理","VIP订阅"`
|
|
|
|
+ sql := fmt.Sprintf(`select a.*,b.product_type as productType ,b.service_starttime,b.service_endtime,b.filter AS productFilter,b.update_time from dataexport_order a
|
|
|
|
+ INNER JOIN jy_order_detail b on a.order_code=b.order_code
|
|
|
|
+ and b.update_time>="%s" AND a.user_phone NOT LIKE "%s" and a.user_id !=""
|
|
|
|
+ and b.product_type in (%s) and a.order_status = 1 and a.is_backstage_order = 1 order by b.update_time asc`, lastOrderClueId, "9%", product_type_str2)
|
|
|
|
+ log.Println("后台订单线索定时任务", sql)
|
|
|
|
+ data := Mysql.SelectBySql(sql)
|
|
|
|
+ log.Println("后台订单线索定时任务", len(*data))
|
|
|
|
+>>>>>>> master
|
|
if data != nil && *data != nil && len(*data) > 0 {
|
|
if data != nil && *data != nil && len(*data) > 0 {
|
|
for _, v := range *data {
|
|
for _, v := range *data {
|
|
- order_status := common.IntAll(v["order_status"])
|
|
|
|
- is_backstage_order := common.IntAll(v["is_backstage_order"])
|
|
|
|
- pay_money := common.IntAll(v["pay_money"])
|
|
|
|
|
|
+ payMoney := common.IntAll(v["pay_money"])
|
|
orderCode := gconv.String(v["order_code"])
|
|
orderCode := gconv.String(v["order_code"])
|
|
saleDep, _, salesperson := FindSaleRecord(orderCode)
|
|
saleDep, _, salesperson := FindSaleRecord(orderCode)
|
|
- user_phone := common.ObjToString(v["user_phone"])
|
|
|
|
- createperson := common.ObjToString(v["create_person"])
|
|
|
|
- userId, uId, cluename, seatNumber, positionId, trailstatus, clueId := common.ObjToString(v["user_id"]), "", "", "", int64(0), "", int64(0)
|
|
|
|
- product_type_str2 := `"大会员","企业商机管理","VIP订阅"`
|
|
|
|
- product_type := common.ObjToString(v["product_type"])
|
|
|
|
- if order_status == 1 && is_backstage_order == 1 && saleDep != "" && !strings.HasPrefix(user_phone, "9") && strings.Contains(product_type_str2, product_type) {
|
|
|
|
|
|
+ userPhone := gconv.String(v["user_phone"])
|
|
|
|
+ createperson := gconv.String(v["create_person"])
|
|
|
|
+ userId, uId, cluename, seatNumber, positionId, trailstatus, clueId := gconv.String(v["user_id"]), "", "", "", int64(0), "", int64(0)
|
|
|
|
+ if saleDep != "" {
|
|
//销售部
|
|
//销售部
|
|
query := map[string]interface{}{}
|
|
query := map[string]interface{}{}
|
|
source := ""
|
|
source := ""
|
|
- if product_type == "企业商机管理" {
|
|
|
|
- query["phone"] = user_phone
|
|
|
|
- userInfo := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
|
|
|
|
- if userInfo != nil && len(*userInfo) > 0 {
|
|
|
|
- uId = common.ObjToString((*userInfo)["uid"])
|
|
|
|
- userId = common.ObjToString((*userInfo)["userid"])
|
|
|
|
- source = common.ObjToString((*userInfo)["source"])
|
|
|
|
|
|
+ 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 = gconv.String((*userMapping)["userid"])
|
|
} else {
|
|
} else {
|
|
- log.Println("后台订单--未查询到 ", user_phone)
|
|
|
|
|
|
+ log.Println("后台订单--未查询到 ", userPhone)
|
|
break
|
|
break
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
+ query["userid"] = userId
|
|
|
|
+ userInfo := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
|
|
|
|
+ if userInfo != nil && len(*userInfo) > 0 {
|
|
|
|
+ uId = gconv.String((*userInfo)["uid"])
|
|
|
|
+ source = gconv.String((*userInfo)["source"])
|
|
} else {
|
|
} else {
|
|
- 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"])
|
|
|
|
- } else {
|
|
|
|
- log.Println("后台订单--未查询到 ", user_phone)
|
|
|
|
- break
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- 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"])
|
|
|
|
- } else {
|
|
|
|
- log.Println("后台订单--未查询到 ", query, user_phone)
|
|
|
|
- break
|
|
|
|
- }
|
|
|
|
|
|
+ log.Println("后台订单--未查询到 ", query, userPhone)
|
|
|
|
+ break
|
|
}
|
|
}
|
|
is_assign := 1
|
|
is_assign := 1
|
|
mailContent := ""
|
|
mailContent := ""
|
|
- cluename = common.ObjToString(v["company_name"])
|
|
|
|
- mailContent = fmt.Sprintf("%s(%s)", cluename, user_phone)
|
|
|
|
|
|
+ cluename = gconv.String(v["company_name"])
|
|
|
|
+ mailContent = fmt.Sprintf("%s(%s)", cluename, userPhone)
|
|
if cluename == "" {
|
|
if cluename == "" {
|
|
- cluename = user_phone
|
|
|
|
- mailContent = user_phone
|
|
|
|
|
|
+ cluename = userPhone
|
|
|
|
+ mailContent = userPhone
|
|
}
|
|
}
|
|
- if pay_money > 0 {
|
|
|
|
|
|
+ if payMoney > 0 {
|
|
trailstatus = "08"
|
|
trailstatus = "08"
|
|
} else {
|
|
} else {
|
|
trailstatus = "01"
|
|
trailstatus = "01"
|
|
@@ -607,10 +613,10 @@ func ordersClue() {
|
|
log.Println("销售部订单salesperson", salesperson)
|
|
log.Println("销售部订单salesperson", salesperson)
|
|
saleData := TiDb.FindOne("dwd_f_crm_personnel_management", map[string]interface{}{"name": salesperson}, "", "")
|
|
saleData := TiDb.FindOne("dwd_f_crm_personnel_management", map[string]interface{}{"name": salesperson}, "", "")
|
|
if saleData != nil {
|
|
if saleData != nil {
|
|
- seatNumber = common.ObjToString((*saleData)["seat_number"])
|
|
|
|
|
|
+ seatNumber = gconv.String((*saleData)["seat_number"])
|
|
positionId = common.Int64All((*saleData)["position_id"])
|
|
positionId = common.Int64All((*saleData)["position_id"])
|
|
}
|
|
}
|
|
- if IsFreeze(source, pay_money, gconv.String(positionId), trailstatus) {
|
|
|
|
|
|
+ if IsFreeze(source, payMoney, gconv.String(positionId), trailstatus) {
|
|
//线索需要冻结
|
|
//线索需要冻结
|
|
is_assign = -3
|
|
is_assign = -3
|
|
}
|
|
}
|
|
@@ -627,8 +633,8 @@ func ordersClue() {
|
|
"top_cluetype": "4",
|
|
"top_cluetype": "4",
|
|
"sub_cluetype": "154",
|
|
"sub_cluetype": "154",
|
|
"trailstatus": trailstatus,
|
|
"trailstatus": trailstatus,
|
|
- "name": user_phone,
|
|
|
|
- "phone": user_phone,
|
|
|
|
|
|
+ "name": userPhone,
|
|
|
|
+ "phone": userPhone,
|
|
"comeinsource_private": 2,
|
|
"comeinsource_private": 2,
|
|
"is_task": 0,
|
|
"is_task": 0,
|
|
"taskstatus": 0,
|
|
"taskstatus": 0,
|
|
@@ -648,8 +654,8 @@ func ordersClue() {
|
|
"top_cluetype": "4",
|
|
"top_cluetype": "4",
|
|
"sub_cluetype": "154",
|
|
"sub_cluetype": "154",
|
|
"trailstatus": trailstatus,
|
|
"trailstatus": trailstatus,
|
|
- "name": user_phone,
|
|
|
|
- "phone": user_phone,
|
|
|
|
|
|
+ "name": userPhone,
|
|
|
|
+ "phone": userPhone,
|
|
"is_task": 0,
|
|
"is_task": 0,
|
|
"taskstatus": 0,
|
|
"taskstatus": 0,
|
|
"company_nature": isGroup,
|
|
"company_nature": isGroup,
|
|
@@ -679,7 +685,7 @@ func ordersClue() {
|
|
"operator_id": -1,
|
|
"operator_id": -1,
|
|
})
|
|
})
|
|
//移交失败发送消息
|
|
//移交失败发送消息
|
|
- if IsFreeze(source, pay_money, gconv.String(positionId), trailstatus) {
|
|
|
|
|
|
+ if IsFreeze(source, payMoney, gconv.String(positionId), trailstatus) {
|
|
//发送邮件信息
|
|
//发送邮件信息
|
|
OrderCreateFail(positionId, mailContent)
|
|
OrderCreateFail(positionId, mailContent)
|
|
}
|
|
}
|
|
@@ -687,7 +693,7 @@ func ordersClue() {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- cfg.LastOrderClueId = common.ObjToString(v["autoUpdate"])
|
|
|
|
|
|
+ cfg.LastOrderClueId = gconv.String(v["update_time"])
|
|
}
|
|
}
|
|
}
|
|
}
|
|
common.WriteSysConfig(&cfg)
|
|
common.WriteSysConfig(&cfg)
|
|
@@ -706,31 +712,38 @@ func refundAuto() {
|
|
saleId, newSeatNumber, newPerson := int64(0), "", ""
|
|
saleId, newSeatNumber, newPerson := int64(0), "", ""
|
|
clueId := common.Int64All(v["clue_id"])
|
|
clueId := common.Int64All(v["clue_id"])
|
|
company_name := gconv.String(v["company_name"])
|
|
company_name := gconv.String(v["company_name"])
|
|
- name := common.ObjToString(v["name"])
|
|
|
|
|
|
+ name := gconv.String(v["name"])
|
|
kcposition_id := common.Int64All(v["position_id"])
|
|
kcposition_id := common.Int64All(v["position_id"])
|
|
isRenewalProtection := common.IntAll(v["is_renewal_protection"])
|
|
isRenewalProtection := common.IntAll(v["is_renewal_protection"])
|
|
clueData := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, "name,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 {
|
|
if clueData != nil && len(*clueData) > 0 {
|
|
- saleId, newPerson, newSeatNumber = FindPositionIdClueId(clueId)
|
|
|
|
|
|
+ uid = gconv.String((*clueData)["uid"])
|
|
|
|
+ saleId, newPerson, newSeatNumber = FindPositionIdClueId(uid)
|
|
oldSaleId = common.Int64All((*clueData)["position_id"])
|
|
oldSaleId = common.Int64All((*clueData)["position_id"])
|
|
oldPersonData := FindPersonOne(oldSaleId)
|
|
oldPersonData := FindPersonOne(oldSaleId)
|
|
if oldSaleId != 0 {
|
|
if oldSaleId != 0 {
|
|
oldsaleName = gconv.String(oldPersonData["name"])
|
|
oldsaleName = gconv.String(oldPersonData["name"])
|
|
}
|
|
}
|
|
- cluename = common.ObjToString((*clueData)["cluename"])
|
|
|
|
|
|
+ cluename = gconv.String((*clueData)["cluename"])
|
|
userName = gconv.String((*clueData)["name"])
|
|
userName = gconv.String((*clueData)["name"])
|
|
company_nature = common.IntAll((*clueData)["company_nature"])
|
|
company_nature = common.IntAll((*clueData)["company_nature"])
|
|
company_verification = common.IntAll((*clueData)["company_verification"])
|
|
company_verification = common.IntAll((*clueData)["company_verification"])
|
|
- uid = common.ObjToString((*clueData)["uid"])
|
|
|
|
- phone = common.ObjToString((*clueData)["phone"])
|
|
|
|
|
|
+ phone = gconv.String((*clueData)["phone"])
|
|
|
|
+ }
|
|
|
|
+ personArr := getUserIdToUid(uid)
|
|
|
|
+ productArr, _ := KcProduct()
|
|
|
|
+ if len(productArr) == 0 || len(personArr) == 0 {
|
|
|
|
+ log.Println("查询不到进客成商品类型或查询不到用户信息")
|
|
|
|
+ continue
|
|
}
|
|
}
|
|
//查询即将到期数据
|
|
//查询即将到期数据
|
|
if isRenewalProtection == 0 {
|
|
if isRenewalProtection == 0 {
|
|
- orderData := TiDb.SelectBySql(`select * from dwd_f_userbase_order_info where uid=? and (product_type = "企业商机管理" or product_type = "大会员") and order_status = 1 and refund_status!=1 ORDER BY vip_endtime desc `, uid)
|
|
|
|
- if orderData != nil && len(*orderData) > 0 {
|
|
|
|
|
|
+ sqlStr := fmt.Sprintf(`select a.*,b.product_type as productType,b.service_starttime,b.service_endtime,b.filter AS productFilter from dataexport_order a INNER JOIN jy_order_detail b on a.order_code=b.order_code and a.user_id in (%s) and b.product_type in (%s) ORDER BY b.service_endtime desc `, strings.Join(personArr, ","), strings.Join(productArr, ","))
|
|
|
|
+ _, vipEndDateStr := getOrderData(sqlStr)
|
|
|
|
+ if vipEndDateStr != "" {
|
|
endDate := time.Now().AddDate(0, 0, -db.ExpirationPeriod+3).Unix()
|
|
endDate := time.Now().AddDate(0, 0, -db.ExpirationPeriod+3).Unix()
|
|
startDate := time.Now().AddDate(0, 0, -db.ExpirationPeriod+2).Unix()
|
|
startDate := time.Now().AddDate(0, 0, -db.ExpirationPeriod+2).Unix()
|
|
- vipEndDate, _ := time.ParseInLocation(time.DateTime, gconv.String((*orderData)[0]["vip_endtime"]), time.Local)
|
|
|
|
|
|
+ vipEndDate, _ := time.ParseInLocation(time.DateTime, vipEndDateStr, time.Local)
|
|
log.Println(vipEndDate.Unix() > startDate, vipEndDate.Unix() < endDate)
|
|
log.Println(vipEndDate.Unix() > startDate, vipEndDate.Unix() < endDate)
|
|
log.Println(vipEndDate.Unix(), startDate, endDate)
|
|
log.Println(vipEndDate.Unix(), startDate, endDate)
|
|
if vipEndDate.Unix() > startDate && vipEndDate.Unix() < endDate {
|
|
if vipEndDate.Unix() > startDate && vipEndDate.Unix() < endDate {
|
|
@@ -749,15 +762,16 @@ func refundAuto() {
|
|
}
|
|
}
|
|
isFull := false
|
|
isFull := false
|
|
isAllRefund := 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 `, uid)
|
|
|
|
- if myOrders != nil {
|
|
|
|
|
|
+ orderSql := fmt.Sprintf(` select a.*,b.product_type as productType,b.service_starttime,b.service_endtime,b.filter AS productFilter from dataexport_order a INNER JOIN jy_order_detail b on a.order_code=b.order_code and a.user_id in (%s) and b.product_type in (%s) and order_status = 1 ORDER BY b.service_endtime desc `, strings.Join(personArr, ","), strings.Join(productArr, ","))
|
|
|
|
+ myOrders, _ := getOrderData(orderSql)
|
|
|
|
+ if myOrders != nil || len(myOrders) > 0 {
|
|
refundCount := 0
|
|
refundCount := 0
|
|
- for _, v := range *myOrders {
|
|
|
|
|
|
+ for _, v := range myOrders {
|
|
if common.IntAll(v["refund_status"]) == 1 {
|
|
if common.IntAll(v["refund_status"]) == 1 {
|
|
refundCount++
|
|
refundCount++
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if len(*myOrders) > 0 && len(*myOrders) == refundCount {
|
|
|
|
|
|
+ if len(myOrders) > 0 && len(myOrders) == refundCount {
|
|
isAllRefund = true
|
|
isAllRefund = true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -813,15 +827,22 @@ func refundAuto() {
|
|
})
|
|
})
|
|
TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_csm_customer_info SET is_transfer=1 WHERE clue_id = ?`, clueId)
|
|
TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_csm_customer_info SET is_transfer=1 WHERE clue_id = ?`, clueId)
|
|
} else {
|
|
} 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)
|
|
|
|
|
|
+ log.Println("客成到期处理")
|
|
|
|
+ order1Sql := fmt.Sprintf(`select a.id from dataexport_order a INNER JOIN jy_order_detail b on a.order_code=b.order_code and a.user_id in (%s) and b.product_type in (%s) and order_status = 1 and b.service_endtime>"%s" ORDER BY b.service_endtime desc `, strings.Join(personArr, ","), strings.Join(productArr, ","), findNowTime)
|
|
|
|
+ log.Println("有效订单查询", order1Sql)
|
|
|
|
+ order1 := Mysql.SelectBySql(order1Sql)
|
|
if order1 == nil || len(*order1) == 0 {
|
|
if order1 == nil || len(*order1) == 0 {
|
|
isOk := false
|
|
isOk := false
|
|
- order3 := TiDb.SelectBySql(`select vip_endtime from dwd_f_userbase_order_info where uid=? and (product_type = "企业商机管理" or product_type = "大会员") and vip_endtime < ? and order_status = 1 ORDER BY vip_endtime desc limit 1 `, uid, findNowTime)
|
|
|
|
- if order3 != nil && len(*order3) > 0 {
|
|
|
|
|
|
+ order3Sql := fmt.Sprintf(`select a.* , b.product_type AS productType,b.service_starttime,b.service_endtime ,b.filter AS productFilter
|
|
|
|
+ from dataexport_order a INNER JOIN jy_order_detail b
|
|
|
|
+ on a.order_code=b.order_code and a.user_id in (%s) and b.product_type in (%s)
|
|
|
|
+ and order_status = 1 and b.service_endtime<"%s" ORDER BY b.service_endtime desc `,
|
|
|
|
+ strings.Join(personArr, ","), strings.Join(productArr, ","), findNowTime)
|
|
|
|
+ log.Println("有效订单查询1", order3Sql)
|
|
|
|
+ _, vip_endtime := getOrderData(order3Sql)
|
|
|
|
+ if vip_endtime != "" {
|
|
//获取最后一个订单信息
|
|
//获取最后一个订单信息
|
|
- vv := (*order3)[0]
|
|
|
|
if isRenewalProtection == 1 {
|
|
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_Full_Layout, vip_endtime, time.Local)
|
|
//查询申请保护时间
|
|
//查询申请保护时间
|
|
renewalTime := time.Now()
|
|
renewalTime := time.Now()
|
|
@@ -868,7 +889,7 @@ func refundAuto() {
|
|
isOks := false
|
|
isOks := false
|
|
for _, vv := range *adata {
|
|
for _, vv := range *adata {
|
|
position_ids := common.Int64All(vv["position_id"])
|
|
position_ids := common.Int64All(vv["position_id"])
|
|
- newSeatNumber = common.ObjToString(vv["seatNumber"])
|
|
|
|
|
|
+ newSeatNumber = gconv.String(vv["seatNumber"])
|
|
saleDatas := TiDb.FindOne("dwd_f_crm_personnel_management", map[string]interface{}{"position_id": position_ids, "resign": 0}, "", "")
|
|
saleDatas := TiDb.FindOne("dwd_f_crm_personnel_management", map[string]interface{}{"position_id": position_ids, "resign": 0}, "", "")
|
|
if saleDatas != nil && len(*saleDatas) > 0 {
|
|
if saleDatas != nil && len(*saleDatas) > 0 {
|
|
saleId = position_ids
|
|
saleId = position_ids
|
|
@@ -884,7 +905,7 @@ func refundAuto() {
|
|
}
|
|
}
|
|
if sdata != nil && len(*sdata) > 0 {
|
|
if sdata != nil && len(*sdata) > 0 {
|
|
saleId = common.Int64All((*sdata)[0]["position_id"])
|
|
saleId = common.Int64All((*sdata)[0]["position_id"])
|
|
- newSeatNumber = common.ObjToString((*sdata)[0]["seat_number"])
|
|
|
|
|
|
+ newSeatNumber = gconv.String((*sdata)[0]["seat_number"])
|
|
newPerson = gconv.String((*sdata)[0]["name"])
|
|
newPerson = gconv.String((*sdata)[0]["name"])
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -906,8 +927,8 @@ func refundAuto() {
|
|
}
|
|
}
|
|
if sdata != nil && len(*sdata) > 0 {
|
|
if sdata != nil && len(*sdata) > 0 {
|
|
saleId = common.Int64All((*sdata)[0]["position_id"])
|
|
saleId = common.Int64All((*sdata)[0]["position_id"])
|
|
- newSeatNumber = common.ObjToString((*sdata)[0]["seat_number"])
|
|
|
|
- newPerson = common.ObjToString((*sdata)[0]["name"])
|
|
|
|
|
|
+ newSeatNumber = gconv.String((*sdata)[0]["seat_number"])
|
|
|
|
+ newPerson = gconv.String((*sdata)[0]["name"])
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1053,7 +1074,7 @@ func refundAuto() {
|
|
}
|
|
}
|
|
return true
|
|
return true
|
|
}, `select ent_id,clue_id,position_id,name,is_renewal_protection,company_name from dwd_f_csm_customer_info where is_transfer = 0`)
|
|
}, `select ent_id,clue_id,position_id,name,is_renewal_protection,company_name from dwd_f_csm_customer_info where is_transfer = 0`)
|
|
- //}, `select ent_id,clue_id,position_id,name,is_renewal_protection,company_name from dwd_f_csm_customer_info where clue_id =1189082`)
|
|
|
|
|
|
+ //}, `select ent_id,clue_id,position_id,name,is_renewal_protection,company_name from dwd_f_csm_customer_info where clue_id =1892234`)
|
|
|
|
|
|
//移交电销提醒
|
|
//移交电销提醒
|
|
for i, v := range mailData {
|
|
for i, v := range mailData {
|
|
@@ -1287,7 +1308,7 @@ func CustomerChange() {
|
|
}
|
|
}
|
|
return true
|
|
return true
|
|
}, `select operator_id, clue_id,position_id,old_value,new_value,createtime from dwd_f_crm_clue_change_record where createtime>? and change_type="客户成功经理" order by createtime`, startTime)
|
|
}, `select operator_id, clue_id,position_id,old_value,new_value,createtime from dwd_f_crm_clue_change_record where createtime>? and change_type="客户成功经理" order by createtime`, startTime)
|
|
- //}, `select operator_id, clue_id,position_id,old_value,new_value,createtime from dwd_f_crm_clue_change_record where id=? order by createtime`, 57876741)
|
|
|
|
|
|
+ //}, `select operator_id, clue_id,position_id,old_value,new_value,createtime from dwd_f_crm_clue_change_record where id=? order by createtime`, 22170775)
|
|
if len(customMap1) > 0 {
|
|
if len(customMap1) > 0 {
|
|
ChangeSendKc(customMap1, 1)
|
|
ChangeSendKc(customMap1, 1)
|
|
}
|
|
}
|
|
@@ -1388,10 +1409,11 @@ func CustomerChangeHandle(data map[string]interface{}) map[string]interface{} {
|
|
if clueData == nil || len(*clueData) == 0 {
|
|
if clueData == nil || len(*clueData) == 0 {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
- phone = common.ObjToString((*clueData)["phone"])
|
|
|
|
|
|
+ uid := gconv.String((*clueData)["uid"])
|
|
|
|
+ phone = gconv.String((*clueData)["phone"])
|
|
userName = gconv.String((*clueData)["name"])
|
|
userName = gconv.String((*clueData)["name"])
|
|
//positionId := gconv.Int64((*clueData)["position_id"])
|
|
//positionId := gconv.Int64((*clueData)["position_id"])
|
|
- positionId, _, _ := FindPositionIdClueId(clueId)
|
|
|
|
|
|
+ positionId, _, _ := FindPositionIdClueId(uid)
|
|
clueName = gconv.String((*clueData)["cluename"])
|
|
clueName = gconv.String((*clueData)["cluename"])
|
|
customData := TiDb.FindOne("dwd_f_csm_customer_info", map[string]interface{}{
|
|
customData := TiDb.FindOne("dwd_f_csm_customer_info", map[string]interface{}{
|
|
"clue_id": clueId,
|
|
"clue_id": clueId,
|
|
@@ -1412,36 +1434,43 @@ func CustomerChangeHandle(data map[string]interface{}) map[string]interface{} {
|
|
}
|
|
}
|
|
|
|
|
|
// 查找订单实际业绩归属
|
|
// 查找订单实际业绩归属
|
|
-func FindPositionIdClueId(clueId int64) (int64, string, string) {
|
|
|
|
- querySql := `
|
|
|
|
- SELECT
|
|
|
|
- e.username as salesperson ,c.position_id,f.dept_name,c.seat_number
|
|
|
|
|
|
+func FindPositionIdClueId(uid string) (int64, string, string) {
|
|
|
|
+ personArr := getUserIdToUid(uid)
|
|
|
|
+ productArr, _ := KcProduct()
|
|
|
|
+ querySql := fmt.Sprintf(` SELECT
|
|
|
|
+ d.saler_name as salesperson ,c.position_id,f.dept_name,c.seat_number,b.product_type as productType,b.filter
|
|
FROM
|
|
FROM
|
|
- dwd_f_crm_clue_info a
|
|
|
|
-INNER JOIN dwd_f_userbase_order_info b ON a.id = ?
|
|
|
|
- AND a.uid = b.uid
|
|
|
|
|
|
+ jianyu.dataexport_order a INNER JOIN jianyu.jy_order_detail b on
|
|
|
|
+ a.order_code=b.order_code and a.user_id in (%s)
|
|
AND (
|
|
AND (
|
|
- b.payable_money > 0
|
|
|
|
|
|
+ b.final_price > 0
|
|
OR (
|
|
OR (
|
|
- b.payable_money = 0
|
|
|
|
- AND ( b.filter LIKE "%分期付款补充权益%" OR b.filter LIKE "%原订单不支持开通多项权益%" OR b.filter LIKE "%权益码兑换%" )))
|
|
|
|
- AND b.data_spec != "dhy4"
|
|
|
|
- AND b.order_status = 1 and b.phone not like "9%"
|
|
|
|
- AND ( b.refund_status != 1 OR b.refund_status IS NULL )
|
|
|
|
- AND b.vip_starttime < "2099-01-01"
|
|
|
|
- AND b.product_type IN ( "大会员", "企业商机管理" )
|
|
|
|
- AND ( b.order_change != 0 or b.order_change is NULL OR ( b.order_change = 0 AND DATEDIFF( b.vip_endtime, b.vip_starttime )> 90 ) )
|
|
|
|
|
|
+ b.final_price = 0
|
|
|
|
+ AND ( a.zero_type= "分期付款权益补充" OR a.zero_type= "原订单不支持开通多项权益" OR a.zero_type= "权益码兑换" )))
|
|
|
|
+ AND a.order_status = 1 and a.user_phone not like "%s"
|
|
|
|
+ AND ( a.refund_status != 1 OR a.refund_status IS NULL )
|
|
|
|
+ AND b.service_starttime < "2099-01-01"
|
|
|
|
+ AND b.product_type IN (%s )
|
|
|
|
+ AND ( b.service_type != 4 or b.service_type is NULL OR ( b.service_type = 4 AND TIMESTAMPDIFF(DAY, b.service_starttime, b.service_endtime )> 90 ) )
|
|
inner JOIN jianyu.order_sale_record d on b.order_code=d.ordercode and d.state=1
|
|
inner JOIN jianyu.order_sale_record d on b.order_code=d.ordercode and d.state=1
|
|
- INNER JOIN cadmin.admin_user e on d.saler_Id = e.id
|
|
|
|
- INNER JOIN dwd_f_crm_personnel_management c on c.ent_id =? and e.username=c.name
|
|
|
|
|
|
+ INNER JOIN jianyu.entniche_user e on d.ent_userId = e.id
|
|
|
|
+ INNER JOIN dwd_f_crm_personnel_management c on c.ent_id =? and e.name=c.name
|
|
inner join dwd_d_crm_department_level_succbi f on c.position_id=f.position_id
|
|
inner join dwd_d_crm_department_level_succbi f on c.position_id=f.position_id
|
|
ORDER BY
|
|
ORDER BY
|
|
- b.vip_endtime desc ,b.payable_money DESC `
|
|
|
|
- clueData := TiDb.SelectBySql(querySql, clueId, db.EntId)
|
|
|
|
|
|
+ b.service_endtime desc ,b.final_price DESC `, strings.Join(personArr, ","), "9%", strings.Join(productArr, ","))
|
|
|
|
+ log.Println("业绩归属查询:", querySql)
|
|
|
|
+ clueData := TiDb.SelectBySql(querySql, db.EntId)
|
|
if clueData == nil || len(*clueData) == 0 {
|
|
if clueData == nil || len(*clueData) == 0 {
|
|
return 0, "", ""
|
|
return 0, "", ""
|
|
}
|
|
}
|
|
for _, m := range *clueData {
|
|
for _, m := range *clueData {
|
|
|
|
+ productType := gconv.String(m["productType"])
|
|
|
|
+ if productType == "大会员" {
|
|
|
|
+ level := gconv.Int(m["service_type"])
|
|
|
|
+ if level == 4 {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ }
|
|
deptName := gconv.String(m["dept_name"])
|
|
deptName := gconv.String(m["dept_name"])
|
|
if strings.Contains(deptName, "一部") || strings.Contains(deptName, "三部") {
|
|
if strings.Contains(deptName, "一部") || strings.Contains(deptName, "三部") {
|
|
return gconv.Int64(m["position_id"]), gconv.String(m["salesperson"]), gconv.String(m["seat_number"])
|
|
return gconv.Int64(m["position_id"]), gconv.String(m["salesperson"]), gconv.String(m["seat_number"])
|
|
@@ -1453,7 +1482,7 @@ func refundAutoHistory() {
|
|
data := TiDb.Find("dwd_f_crm_clue_autodraw_record", nil, "", "", -1, -1)
|
|
data := TiDb.Find("dwd_f_crm_clue_autodraw_record", nil, "", "", -1, -1)
|
|
if data != nil {
|
|
if data != nil {
|
|
for _, v := range *data {
|
|
for _, v := range *data {
|
|
- seatNumber := common.ObjToString(v["seatNumber"])
|
|
|
|
|
|
+ seatNumber := gconv.String(v["seatNumber"])
|
|
adata := TiDb.Find("dwd_f_crm_personnel_management", map[string]interface{}{"seat_number": seatNumber}, "", "", -1, -1)
|
|
adata := TiDb.Find("dwd_f_crm_personnel_management", map[string]interface{}{"seat_number": seatNumber}, "", "", -1, -1)
|
|
if adata != nil {
|
|
if adata != nil {
|
|
for _, vv := range *adata {
|
|
for _, vv := range *adata {
|
|
@@ -1479,20 +1508,22 @@ func IsFreeze(source string, pay_money int, positionId, trailstatus string) bool
|
|
}
|
|
}
|
|
return false
|
|
return false
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// 业绩归属查询
|
|
func FindSaleRecord(orderCode string) (dept string, positionId int64, position string) {
|
|
func FindSaleRecord(orderCode string) (dept string, positionId int64, position string) {
|
|
recordList := Mysql.SelectBySql(`
|
|
recordList := Mysql.SelectBySql(`
|
|
- SELECT
|
|
|
|
|
|
+ SELECT DISTINCT
|
|
a.saler_dept,
|
|
a.saler_dept,
|
|
a.saler_name,
|
|
a.saler_name,
|
|
- b.phone
|
|
|
|
|
|
+ b.phone
|
|
FROM
|
|
FROM
|
|
order_sale_record a
|
|
order_sale_record a
|
|
- INNER JOIN cadmin.admin_user b
|
|
|
|
|
|
+ INNER JOIN entniche_user b
|
|
on
|
|
on
|
|
- a.ordercode = ? and a.saler_Id = b.id
|
|
|
|
|
|
+ a.ordercode = ? and a.ent_userId = b.id
|
|
ORDER BY
|
|
ORDER BY
|
|
a.state,
|
|
a.state,
|
|
- a.money
|
|
|
|
|
|
+ a.money desc
|
|
`, orderCode)
|
|
`, orderCode)
|
|
if recordList != nil && len(*recordList) > 0 {
|
|
if recordList != nil && len(*recordList) > 0 {
|
|
saler_dept := gconv.String((*recordList)[0]["saler_dept"])
|
|
saler_dept := gconv.String((*recordList)[0]["saler_dept"])
|
|
@@ -1500,8 +1531,8 @@ func FindSaleRecord(orderCode string) (dept string, positionId int64, position s
|
|
saler_dept = "销售部"
|
|
saler_dept = "销售部"
|
|
} else if strings.Contains(saler_dept, "市场") {
|
|
} else if strings.Contains(saler_dept, "市场") {
|
|
saler_dept = "市场部"
|
|
saler_dept = "市场部"
|
|
- } else if strings.Contains(saler_dept, "客户成功") {
|
|
|
|
- saler_dept = "客户成功组"
|
|
|
|
|
|
+ } else if strings.Contains(saler_dept, "客户成功") && !strings.Contains(saler_dept, "客服") {
|
|
|
|
+ saler_dept = "客户成功部"
|
|
} else {
|
|
} else {
|
|
saler_dept = ""
|
|
saler_dept = ""
|
|
}
|
|
}
|
|
@@ -1659,17 +1690,7 @@ type OrderInfo struct {
|
|
// 客成发送邮箱
|
|
// 客成发送邮箱
|
|
func KcSend(orderCode, personName string) {
|
|
func KcSend(orderCode, personName string) {
|
|
log.Println("客成发邮件", orderCode)
|
|
log.Println("客成发邮件", orderCode)
|
|
- 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)
|
|
|
|
|
|
+ orderInfo := KcOrderFormat(orderCode)
|
|
if orderInfo != nil {
|
|
if orderInfo != nil {
|
|
tableAppend := ""
|
|
tableAppend := ""
|
|
if len(orderInfo.SeriveList) > 0 {
|
|
if len(orderInfo.SeriveList) > 0 {
|
|
@@ -1800,31 +1821,61 @@ func ExitKcSend(personName string, infoList []map[string]interface{}) {
|
|
}
|
|
}
|
|
|
|
|
|
// 客成邮件 订单信息初始化
|
|
// 客成邮件 订单信息初始化
|
|
-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='大会员-子账号' or a.product_type = "企业商机管理")
|
|
|
|
- GROUP BY a.id ORDER BY a.autoUpdate`, orderCode)
|
|
|
|
|
|
+func KcOrderFormat(orderCode string) *OrderInfo {
|
|
|
|
+ productArr, _ := KcProduct()
|
|
|
|
+ bigmemberService := map[int64]string{}
|
|
|
|
+ Mysql.SelectByBath(1, func(l *[]map[string]interface{}) bool {
|
|
|
|
+ bigmemberService[common.Int64All((*l)[0]["id"])] = gconv.String((*l)[0]["s_name"])
|
|
|
|
+ return true
|
|
|
|
+ }, `select id,s_name from jianyu.bigmember_service`)
|
|
|
|
+ orderData := Mysql.SelectBySql(fmt.Sprintf(`
|
|
|
|
+ SELECT
|
|
|
|
+ d.*,
|
|
|
|
+ SUM( c.return_money ) AS return_money
|
|
|
|
+FROM
|
|
|
|
+ (
|
|
|
|
+ SELECT
|
|
|
|
+ a.order_code,
|
|
|
|
+ a.pay_money,
|
|
|
|
+ a.user_phone,
|
|
|
|
+ b.service_starttime,
|
|
|
|
+ b.service_endtime,
|
|
|
|
+ b.product_type,
|
|
|
|
+ a.filter,
|
|
|
|
+ a.user_id,
|
|
|
|
+ a.ent_id,
|
|
|
|
+ a.company_name,
|
|
|
|
+ a.create_person,
|
|
|
|
+ b.filter AS productFilter,
|
|
|
|
+ TIMESTAMPDIFF( DAY, b.service_starttime, b.service_endtime ) AS difference
|
|
|
|
+ FROM
|
|
|
|
+ jianyu.dataexport_order a
|
|
|
|
+ INNER JOIN jy_order_detail b ON a.order_code = "%s"
|
|
|
|
+ AND a.order_code = b.order_code
|
|
|
|
+ AND a.order_status = 1
|
|
|
|
+ AND b.product_type IN ( %s )
|
|
|
|
+ ORDER BY
|
|
|
|
+ difference DESC LIMIT 1
|
|
|
|
+ ) d
|
|
|
|
+ LEFT JOIN return_money_record c ON d.order_code = c.order_code
|
|
|
|
+ `, orderCode, strings.Join(productArr, ",")))
|
|
data := &OrderInfo{}
|
|
data := &OrderInfo{}
|
|
if orderData != nil && len(*orderData) > 0 {
|
|
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"])
|
|
|
|
|
|
+ orderData := (*orderData)[0]
|
|
|
|
+ id := common.Int64All(orderData["id"])
|
|
|
|
+ user_phone := gconv.String(orderData["user_phone"])
|
|
|
|
+ user_id := gconv.String(orderData["user_id"])
|
|
|
|
+ product_type := gconv.String(orderData["product_type"])
|
|
serviceList := []string{}
|
|
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 product_type == "大会员" {
|
|
|
|
+ product_type_name, _, level := GetOrderProduct(product_type, gconv.String(orderData["productFilter"]))
|
|
|
|
+ product_type = product_type_name
|
|
|
|
+ if level == 0 {
|
|
|
|
+ for _, serversId := range strings.Split(gconv.String(gconv.Map(orderData["serversId"])), ",") {
|
|
if serviceName := bigmemberService[common.Int64All(serversId)]; serviceName != "" {
|
|
if serviceName := bigmemberService[common.Int64All(serversId)]; serviceName != "" {
|
|
serviceList = append(serviceList, serviceName)
|
|
serviceList = append(serviceList, serviceName)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- } else {
|
|
|
|
- product_type += combo[common.Int64All(filterMap["comboId"])]
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//联系人姓名
|
|
//联系人姓名
|
|
@@ -1844,16 +1895,16 @@ func KcOrderFormat(orderCode string, bigmemberService, combo map[int64]string) *
|
|
}
|
|
}
|
|
data = &OrderInfo{
|
|
data = &OrderInfo{
|
|
Id: id,
|
|
Id: id,
|
|
- CompanyName: common.ObjToString((*orderData)[0]["company_name"]),
|
|
|
|
|
|
+ CompanyName: gconv.String(orderData["company_name"]),
|
|
UserId: user_id,
|
|
UserId: user_id,
|
|
ProductType: product_type,
|
|
ProductType: product_type,
|
|
OrderCode: orderCode,
|
|
OrderCode: orderCode,
|
|
- PayMoney: common.Float64All((*orderData)[0]["pay_money"]) / 100,
|
|
|
|
- ReturnMoney: common.Float64All((*orderData)[0]["return_money"]) / 100,
|
|
|
|
|
|
+ PayMoney: common.Float64All(orderData["pay_money"]) / 100,
|
|
|
|
+ ReturnMoney: common.Float64All(orderData["return_money"]) / 100,
|
|
UserPhone: user_phone,
|
|
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]),
|
|
|
|
|
|
+ StartEnd: fmt.Sprintf("%s--%s", strings.Split(gconv.String(orderData["service_starttime"]), " ")[0], strings.Split(gconv.String(orderData["service_endtime"]), " ")[0]),
|
|
SeriveList: serviceList,
|
|
SeriveList: serviceList,
|
|
- SaleName: common.ObjToString((*orderData)[0]["create_person"]),
|
|
|
|
|
|
+ SaleName: gconv.String(orderData["create_person"]),
|
|
UserName: userName,
|
|
UserName: userName,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1920,3 +1971,112 @@ func FindPersonOne(positionId int64) map[string]interface{} {
|
|
}
|
|
}
|
|
return (*personData)[0]
|
|
return (*personData)[0]
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// 进客成商品查询
|
|
|
|
+func KcProduct() ([]string, map[string]bool) {
|
|
|
|
+ var strArr []string
|
|
|
|
+ strMap := map[string]bool{}
|
|
|
|
+ productData := Mysql.SelectBySql(`SELECT id ,
|
|
|
|
+ CONCAT( '"', class_name,'"' ) as product
|
|
|
|
+FROM
|
|
|
|
+ jy_product_class
|
|
|
|
+WHERE
|
|
|
|
+ s_service = 1`)
|
|
|
|
+ if productData == nil && len(*productData) == 0 {
|
|
|
|
+ return strArr, strMap
|
|
|
|
+ }
|
|
|
|
+ for _, m := range *productData {
|
|
|
|
+ strMap[gconv.String(m["product"])] = true
|
|
|
|
+ strArr = append(strArr, gconv.String(m["product"]))
|
|
|
|
+ }
|
|
|
|
+ return strArr, strMap
|
|
|
|
+}
|
|
|
|
+func GetOrderProduct(productType string, file string) (string, int64, int64) {
|
|
|
|
+ fileJson := gconv.Map(file)
|
|
|
|
+ if fileJson == nil || len(fileJson) == 0 {
|
|
|
|
+ return "", 0, 0
|
|
|
|
+ }
|
|
|
|
+ productName := ""
|
|
|
|
+ level := int64(0)
|
|
|
|
+ switch productType {
|
|
|
|
+ case "大会员":
|
|
|
|
+ level = gconv.Int64(fileJson["comboId"])
|
|
|
|
+ if level == 0 {
|
|
|
|
+ level = gconv.Int64(fileJson["level"])
|
|
|
|
+ }
|
|
|
|
+ switch level {
|
|
|
|
+ case 0:
|
|
|
|
+ productName = "大会员自定义"
|
|
|
|
+ case 30190:
|
|
|
|
+ productName = "大会员商机版2.0(单省版)"
|
|
|
|
+ case 6:
|
|
|
|
+ productName = "大会员商机版2.0"
|
|
|
|
+ case 7:
|
|
|
|
+ productName = "大会员专家版2.0"
|
|
|
|
+ }
|
|
|
|
+ default:
|
|
|
|
+ productName = productType
|
|
|
|
+ }
|
|
|
|
+ productData := TiDb.FindOne("dwd_d_csm_product_access_code", map[string]interface{}{
|
|
|
|
+ "name": productName,
|
|
|
|
+ }, "", "")
|
|
|
|
+ if productData == nil || len(*productData) == 0 {
|
|
|
|
+ return productName, 0, level
|
|
|
|
+ }
|
|
|
|
+ return productName, gconv.Int64((*productData)["code"]), level
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func GetTimeDifference(timeStr1, timeStr2 string) int {
|
|
|
|
+ // 解析时间字符串
|
|
|
|
+ t1, err1 := time.Parse(time.DateTime, timeStr1)
|
|
|
|
+ t2, err2 := time.Parse(time.DateTime, timeStr2)
|
|
|
|
+ if err1 != nil || err2 != nil {
|
|
|
|
+ fmt.Println("时间格式错误:", err1, err2)
|
|
|
|
+ return 0
|
|
|
|
+ }
|
|
|
|
+ // 计算时间差
|
|
|
|
+ daysDiff := gconv.Int(t2.Sub(t1).Hours() / 24)
|
|
|
|
+ fmt.Printf("两个时间相差 %.0f 天\n", daysDiff)
|
|
|
|
+ return daysDiff
|
|
|
|
+}
|
|
|
|
+func getOrderData(sql string) (map[string]map[string]interface{}, string) {
|
|
|
|
+ data := Mysql.SelectBySql(sql)
|
|
|
|
+ orderMap := map[string]map[string]interface{}{}
|
|
|
|
+ lastEndTime := ""
|
|
|
|
+ for _, v := range *data {
|
|
|
|
+ orderCode := gconv.String(v["order_code"])
|
|
|
|
+ product_type := gconv.String(v["productType"])
|
|
|
|
+ vip_starttime := gconv.String(v["service_starttime"])
|
|
|
|
+ vip_endtime := gconv.String(v["service_endtime"])
|
|
|
|
+ //判断一下服务周期
|
|
|
|
+ difference := GetTimeDifference(vip_starttime, vip_endtime)
|
|
|
|
+ _, productInt64, _ := GetOrderProduct(product_type, gconv.String(v["productFilter"]))
|
|
|
|
+ if productInt64 == 0 {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ if _, exists := orderMap[orderCode]; exists {
|
|
|
|
+ //判断服务周期
|
|
|
|
+ data := orderMap[orderCode]
|
|
|
|
+ //商品类型获取
|
|
|
|
+ oldDifference := gconv.Int(data["difference"])
|
|
|
|
+ if oldDifference >= difference {
|
|
|
|
+ //需要更换
|
|
|
|
+ lastEndTime = vip_endtime
|
|
|
|
+ v["difference"] = difference
|
|
|
|
+ v["product"] = productInt64
|
|
|
|
+ v["service_endtime"] = vip_endtime
|
|
|
|
+ v["service_starttime"] = vip_starttime
|
|
|
|
+ v["product_type"] = product_type
|
|
|
|
+ orderMap[orderCode] = v
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ lastEndTime = vip_endtime
|
|
|
|
+ v["difference"] = difference
|
|
|
|
+ v["product"] = productInt64
|
|
|
|
+ v["product_type"] = product_type
|
|
|
|
+ orderMap[orderCode] = v
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return orderMap, lastEndTime
|
|
|
|
+}
|