|
@@ -19,22 +19,45 @@ 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.filter as productFilter
|
|
|
|
+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 ( zero_type = "分期付款补充权益" OR zero_type = "原订单不支持开通多项权益" OR zero_type = "权益码兑换" )))
|
|
|
|
+
|
|
|
|
+ AND a.user_phone NOT LIKE "9%"
|
|
|
|
+ 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 a.autoUpdate > %s
|
|
|
|
+ORDER BY
|
|
|
|
+ a.autoUpdate ASC,
|
|
|
|
+ a.order_code ASC,
|
|
|
|
+ b.final_price DESC `
|
|
|
|
+ sql = fmt.Sprintf(sql, strings.Join(productArr, ","), cfg.LastkcTime)
|
|
|
|
+ data := Mysql.SelectBySql(sql)
|
|
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"])
|
|
|
|
|
|
+ orderCode := gconv.String(v["order_code"])
|
|
|
|
+ product_type := gconv.String(v["product_type"])
|
|
|
|
+ vip_starttime := gconv.String(v["service_starttime"])
|
|
|
|
+ vip_endtime := gconv.String(v["service_endtime"])
|
|
order_change := gconv.Int64(v["order_change"])
|
|
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)
|
|
|
|
|
|
+ if (order_change != 0) || (order_change == 0 && TimeStrcount(vip_starttime, vip_endtime) > 95) {
|
|
isExit := false
|
|
isExit := false
|
|
for _, v := range customList {
|
|
for _, v := range customList {
|
|
if v == orderCode {
|
|
if v == orderCode {
|
|
@@ -45,25 +68,62 @@ func kcSync() {
|
|
if isExit {
|
|
if isExit {
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
|
|
+ //判断一下服务周期
|
|
|
|
+ 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 {
|
|
|
|
+ //需要更换
|
|
|
|
+ v["difference"] = difference
|
|
|
|
+ v["product"] = productInt64
|
|
|
|
+ v["service_endtime"] = vip_endtime
|
|
|
|
+ v["service_starttime"] = vip_starttime
|
|
|
|
+ orderMap[orderCode] = v
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ v["difference"] = difference
|
|
|
|
+ v["product"] = productInt64
|
|
|
|
+ orderMap[orderCode] = v
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ cfg.LastkcTime = gconv.String(v["autoUpdate"])
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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
|
|
}
|
|
}
|
|
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.Int(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"]), "")
|
|
|
|
+ if uId == "" {
|
|
|
|
+ log.Println("移交客成缺少基本信息,缺少用户信息", uId)
|
|
|
|
+ return 0
|
|
|
|
+ }
|
|
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,16 +133,8 @@ 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 == "客户成功组" {
|
|
//新增线索
|
|
//新增线索
|
|
@@ -95,8 +147,7 @@ func kcJob(data map[string]interface{}) int {
|
|
//其他信息
|
|
//其他信息
|
|
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 +193,23 @@ 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"])
|
|
|
|
|
|
+ starttime := gconv.String(data["service_starttime"])
|
|
|
|
+ endtime := gconv.String(data["service_endtime"])
|
|
buy_subject := common.IntAll(data["buy_subject"])
|
|
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]
|
|
|
|
|
|
+ product_type := gconv.String(data["product_type"])
|
|
|
|
+ userName := gconv.String((*clueData)["name"])
|
|
|
|
+ product, company_name := gconv.String(data["product"]), gconv.String(data["company_name"])
|
|
|
|
+ if product_type != "大会员" {
|
|
powerData := TiDb.FindOne("dwd_f_data_equity_info", map[string]interface{}{"uid": uId, "product_type": "商机管理"}, "", "comeintime desc")
|
|
powerData := TiDb.FindOne("dwd_f_data_equity_info", map[string]interface{}{"uid": uId, "product_type": "商机管理"}, "", "comeintime desc")
|
|
if powerData != nil {
|
|
if powerData != nil {
|
|
- starttime = common.ObjToString((*powerData)["starttime"])
|
|
|
|
- endtime = common.ObjToString((*powerData)["endtime"])
|
|
|
|
|
|
+ starttime = gconv.String((*powerData)["starttime"])
|
|
|
|
+ endtime = gconv.String((*powerData)["endtime"])
|
|
} else {
|
|
} else {
|
|
log.Println("客成移交权限未查到--", uId)
|
|
log.Println("客成移交权限未查到--", uId)
|
|
return 0
|
|
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]
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
//同一公司名称(以客户详情-组织机构-公司名称)下的线索需分配给同1人
|
|
//同一公司名称(以客户详情-组织机构-公司名称)下的线索需分配给同1人
|
|
-
|
|
|
|
saveMap = map[string]interface{}{
|
|
saveMap = map[string]interface{}{
|
|
"clue_id": clueId,
|
|
"clue_id": clueId,
|
|
"transfertime": nowTime,
|
|
"transfertime": nowTime,
|
|
@@ -285,8 +306,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(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 +348,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 {
|
|
@@ -365,7 +384,7 @@ 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
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -384,12 +403,12 @@ 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
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -417,7 +436,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 +447,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 +467,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 +496,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"
|
|
@@ -537,11 +556,11 @@ func ordersClue() {
|
|
pay_money := common.IntAll(v["pay_money"])
|
|
pay_money := 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)
|
|
|
|
|
|
+ user_phone := 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)
|
|
product_type_str2 := `"大会员","企业商机管理","VIP订阅"`
|
|
product_type_str2 := `"大会员","企业商机管理","VIP订阅"`
|
|
- product_type := common.ObjToString(v["product_type"])
|
|
|
|
|
|
+ product_type := gconv.String(v["product_type"])
|
|
if order_status == 1 && is_backstage_order == 1 && saleDep != "" && !strings.HasPrefix(user_phone, "9") && strings.Contains(product_type_str2, product_type) {
|
|
if order_status == 1 && is_backstage_order == 1 && saleDep != "" && !strings.HasPrefix(user_phone, "9") && strings.Contains(product_type_str2, product_type) {
|
|
//销售部
|
|
//销售部
|
|
query := map[string]interface{}{}
|
|
query := map[string]interface{}{}
|
|
@@ -550,9 +569,9 @@ func ordersClue() {
|
|
query["phone"] = user_phone
|
|
query["phone"] = user_phone
|
|
userInfo := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
|
|
userInfo := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
|
|
if userInfo != nil && len(*userInfo) > 0 {
|
|
if userInfo != nil && len(*userInfo) > 0 {
|
|
- uId = common.ObjToString((*userInfo)["uid"])
|
|
|
|
- userId = common.ObjToString((*userInfo)["userid"])
|
|
|
|
- source = common.ObjToString((*userInfo)["source"])
|
|
|
|
|
|
+ uId = gconv.String((*userInfo)["uid"])
|
|
|
|
+ userId = gconv.String((*userInfo)["userid"])
|
|
|
|
+ source = gconv.String((*userInfo)["source"])
|
|
} else {
|
|
} else {
|
|
log.Println("后台订单--未查询到 ", user_phone)
|
|
log.Println("后台订单--未查询到 ", user_phone)
|
|
break
|
|
break
|
|
@@ -561,7 +580,7 @@ func ordersClue() {
|
|
if !mongodb.IsObjectIdHex(userId) {
|
|
if !mongodb.IsObjectIdHex(userId) {
|
|
userMapping := TiDb.FindOne("dwd_f_userbase_id_mapping", map[string]interface{}{"position_id": userId}, "", "")
|
|
userMapping := TiDb.FindOne("dwd_f_userbase_id_mapping", map[string]interface{}{"position_id": userId}, "", "")
|
|
if userMapping != nil && len(*userMapping) > 0 {
|
|
if userMapping != nil && len(*userMapping) > 0 {
|
|
- userId = common.ObjToString((*userMapping)["userid"])
|
|
|
|
|
|
+ userId = gconv.String((*userMapping)["userid"])
|
|
} else {
|
|
} else {
|
|
log.Println("后台订单--未查询到 ", user_phone)
|
|
log.Println("后台订单--未查询到 ", user_phone)
|
|
break
|
|
break
|
|
@@ -570,8 +589,8 @@ func ordersClue() {
|
|
query["userid"] = userId
|
|
query["userid"] = userId
|
|
userInfo := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
|
|
userInfo := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
|
|
if userInfo != nil && len(*userInfo) > 0 {
|
|
if userInfo != nil && len(*userInfo) > 0 {
|
|
- uId = common.ObjToString((*userInfo)["uid"])
|
|
|
|
- source = common.ObjToString((*userInfo)["source"])
|
|
|
|
|
|
+ uId = gconv.String((*userInfo)["uid"])
|
|
|
|
+ source = gconv.String((*userInfo)["source"])
|
|
} else {
|
|
} else {
|
|
log.Println("后台订单--未查询到 ", query, user_phone)
|
|
log.Println("后台订单--未查询到 ", query, user_phone)
|
|
break
|
|
break
|
|
@@ -579,7 +598,7 @@ func ordersClue() {
|
|
}
|
|
}
|
|
is_assign := 1
|
|
is_assign := 1
|
|
mailContent := ""
|
|
mailContent := ""
|
|
- cluename = common.ObjToString(v["company_name"])
|
|
|
|
|
|
+ cluename = gconv.String(v["company_name"])
|
|
mailContent = fmt.Sprintf("%s(%s)", cluename, user_phone)
|
|
mailContent = fmt.Sprintf("%s(%s)", cluename, user_phone)
|
|
if cluename == "" {
|
|
if cluename == "" {
|
|
cluename = user_phone
|
|
cluename = user_phone
|
|
@@ -606,7 +625,7 @@ 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, pay_money, gconv.String(positionId), trailstatus) {
|
|
@@ -686,7 +705,7 @@ func ordersClue() {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- cfg.LastOrderClueId = common.ObjToString(v["autoUpdate"])
|
|
|
|
|
|
+ cfg.LastOrderClueId = gconv.String(v["autoUpdate"])
|
|
}
|
|
}
|
|
}
|
|
}
|
|
common.WriteSysConfig(&cfg)
|
|
common.WriteSysConfig(&cfg)
|
|
@@ -705,31 +724,39 @@ 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"])
|
|
|
|
|
|
+ uid = gconv.String((*clueData)["uid"])
|
|
|
|
+ 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 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 {
|
|
@@ -748,15 +775,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 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
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -812,15 +840,15 @@ 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)
|
|
|
|
- if order1 == nil || len(*order1) == 0 {
|
|
|
|
|
|
+ order1Sql := fmt.Sprintf(`select refund_status 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 vip_endtime>%s ORDER BY b.service_endtime desc `, strings.Join(personArr, ","), strings.Join(productArr, ","), findNowTime)
|
|
|
|
+ order1, _ := getOrderData(order1Sql)
|
|
|
|
+ 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 refund_status 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 vip_endtime<%s ORDER BY b.service_endtime desc `, strings.Join(personArr, ","), strings.Join(productArr, ","), findNowTime)
|
|
|
|
+ _, 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()
|
|
@@ -867,7 +895,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
|
|
@@ -883,7 +911,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"])
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -905,8 +933,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"])
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1387,10 +1415,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,
|
|
@@ -1411,32 +1440,55 @@ 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) {
|
|
|
|
+ /*querySql := `
|
|
|
|
+ SELECT
|
|
|
|
+ e.username as salesperson ,c.position_id,f.dept_name,c.seat_number
|
|
|
|
+ FROM
|
|
|
|
+ dwd_f_crm_clue_info a
|
|
|
|
+ INNER JOIN dwd_f_userbase_order_info b ON a.id = ?
|
|
|
|
+ AND a.uid = b.uid
|
|
|
|
+ AND (
|
|
|
|
+ b.payable_money > 0
|
|
|
|
+ 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 ) )
|
|
|
|
+ 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 dwd_d_crm_department_level_succbi f on c.position_id=f.position_id
|
|
|
|
+ ORDER BY
|
|
|
|
+ b.vip_endtime desc ,b.payable_money DESC `*/
|
|
|
|
+ personArr := getUserIdToUid(uid)
|
|
|
|
+ productArr, _ := KcProduct()
|
|
|
|
+ querySql := fmt.Sprintf(` SELECT
|
|
|
|
+ e.username as salesperson ,c.position_id,f.dept_name,c.seat_number,b.product_type,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 "9%"
|
|
|
|
+ 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 DATEDIFF( 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 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 dwd_f_crm_personnel_management c on c.ent_id =? and e.username=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, ","), strings.Join(productArr, ","))
|
|
|
|
+ clueData := TiDb.SelectBySql(querySql, db.EntId)
|
|
if clueData == nil || len(*clueData) == 0 {
|
|
if clueData == nil || len(*clueData) == 0 {
|
|
return 0, "", ""
|
|
return 0, "", ""
|
|
}
|
|
}
|
|
@@ -1452,7 +1504,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 {
|
|
@@ -1661,11 +1713,11 @@ func KcSend(orderCode, personName string) {
|
|
bigmemberService := map[int64]string{}
|
|
bigmemberService := map[int64]string{}
|
|
combo := map[int64]string{}
|
|
combo := map[int64]string{}
|
|
Mysql.SelectByBath(1, func(l *[]map[string]interface{}) bool {
|
|
Mysql.SelectByBath(1, func(l *[]map[string]interface{}) bool {
|
|
- bigmemberService[common.Int64All((*l)[0]["id"])] = common.ObjToString((*l)[0]["s_name"])
|
|
|
|
|
|
+ bigmemberService[common.Int64All((*l)[0]["id"])] = gconv.String((*l)[0]["s_name"])
|
|
return true
|
|
return true
|
|
}, `select id,s_name from jianyu.bigmember_service`)
|
|
}, `select id,s_name from jianyu.bigmember_service`)
|
|
Mysql.SelectByBath(1, func(l *[]map[string]interface{}) bool {
|
|
Mysql.SelectByBath(1, func(l *[]map[string]interface{}) bool {
|
|
- combo[common.Int64All((*l)[0]["id"])] = common.ObjToString((*l)[0]["s_name"])
|
|
|
|
|
|
+ combo[common.Int64All((*l)[0]["id"])] = gconv.String((*l)[0]["s_name"])
|
|
return true
|
|
return true
|
|
}, `select id,s_name from jianyu.bigmember_combo`)
|
|
}, `select id,s_name from jianyu.bigmember_combo`)
|
|
orderInfo := KcOrderFormat(orderCode, bigmemberService, combo)
|
|
orderInfo := KcOrderFormat(orderCode, bigmemberService, combo)
|
|
@@ -1808,16 +1860,16 @@ func KcOrderFormat(orderCode string, bigmemberService, combo map[int64]string) *
|
|
data := &OrderInfo{}
|
|
data := &OrderInfo{}
|
|
if orderData != nil && len(*orderData) > 0 {
|
|
if orderData != nil && len(*orderData) > 0 {
|
|
id := common.Int64All((*orderData)[0]["id"])
|
|
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"])
|
|
|
|
|
|
+ user_phone := gconv.String((*orderData)[0]["user_phone"])
|
|
|
|
+ user_id := gconv.String((*orderData)[0]["user_id"])
|
|
|
|
+ product_type := gconv.String((*orderData)[0]["product_type"])
|
|
serviceList := []string{}
|
|
serviceList := []string{}
|
|
- if filter := common.ObjToString((*orderData)[0]["filter"]); filter != "" {
|
|
|
|
|
|
+ if filter := gconv.String((*orderData)[0]["filter"]); filter != "" {
|
|
filterMap := map[string]interface{}{}
|
|
filterMap := map[string]interface{}{}
|
|
json.Unmarshal([]byte(filter), &filterMap)
|
|
json.Unmarshal([]byte(filter), &filterMap)
|
|
if level := common.Int64All(filterMap["level"]); level == 5 {
|
|
if level := common.Int64All(filterMap["level"]); level == 5 {
|
|
product_type += "自定义版"
|
|
product_type += "自定义版"
|
|
- for _, serversId := range strings.Split(common.ObjToString(filterMap["serversId"]), ",") {
|
|
|
|
|
|
+ for _, serversId := range strings.Split(gconv.String(filterMap["serversId"]), ",") {
|
|
if serviceName := bigmemberService[common.Int64All(serversId)]; serviceName != "" {
|
|
if serviceName := bigmemberService[common.Int64All(serversId)]; serviceName != "" {
|
|
serviceList = append(serviceList, serviceName)
|
|
serviceList = append(serviceList, serviceName)
|
|
}
|
|
}
|
|
@@ -1843,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)[0]["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,
|
|
PayMoney: common.Float64All((*orderData)[0]["pay_money"]) / 100,
|
|
ReturnMoney: common.Float64All((*orderData)[0]["return_money"]) / 100,
|
|
ReturnMoney: common.Float64All((*orderData)[0]["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)[0]["vip_starttime"]), " ")[0], strings.Split(gconv.String((*orderData)[0]["vip_endtime"]), " ")[0]),
|
|
SeriveList: serviceList,
|
|
SeriveList: serviceList,
|
|
- SaleName: common.ObjToString((*orderData)[0]["create_person"]),
|
|
|
|
|
|
+ SaleName: gconv.String((*orderData)[0]["create_person"]),
|
|
UserName: userName,
|
|
UserName: userName,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1919,3 +1971,118 @@ func FindPersonOne(positionId int64) map[string]interface{} {
|
|
}
|
|
}
|
|
return (*personData)[0]
|
|
return (*personData)[0]
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// 进客成商品查询
|
|
|
|
+func KcProduct() ([]string, map[string]bool) {
|
|
|
|
+ var strArr []string
|
|
|
|
+ var strMap map[string]bool
|
|
|
|
+ productData := Mysql.SelectBySql(`SELECT
|
|
|
|
+ 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) int64 {
|
|
|
|
+ fileJson := gconv.Map(file)
|
|
|
|
+ if fileJson == nil || len(fileJson) == 0 {
|
|
|
|
+ return 0
|
|
|
|
+ }
|
|
|
|
+ productName := ""
|
|
|
|
+ switch productType {
|
|
|
|
+ case "大会员":
|
|
|
|
+ comboId := gconv.Int(fileJson["comboId"])
|
|
|
|
+ // {1: "专家版", 2: "智慧版", 3: "商机版", 4: "试用版", 5: "定制版", 6: "商机版2.0", 7: "专家版2.0"}
|
|
|
|
+ switch comboId {
|
|
|
|
+ case 1:
|
|
|
|
+ productName = "大会员专家版"
|
|
|
|
+ case 2:
|
|
|
|
+ productName = "大会员智慧版"
|
|
|
|
+ case 3:
|
|
|
|
+ productName = "大会员商家版"
|
|
|
|
+ case 5:
|
|
|
|
+ productName = "大会员自定义"
|
|
|
|
+ case 6:
|
|
|
|
+ areaCount := common.IntAll(fileJson["areaCount"])
|
|
|
|
+ if areaCount == 1 {
|
|
|
|
+ productName = "大会员商机版2.0(单省版)"
|
|
|
|
+ } else {
|
|
|
|
+ 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 0
|
|
|
|
+ }
|
|
|
|
+ return gconv.Int64((*productData)["code"])
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+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
|
|
|
|
+}
|