|
@@ -17,6 +17,13 @@ import (
|
|
|
"app.yhyue.com/moapp/jybase/mongodb"
|
|
|
)
|
|
|
|
|
|
+var (
|
|
|
+ CodeLock = map[int64]interface{}{
|
|
|
+ 1: "无需锁定",
|
|
|
+ 0: "/",
|
|
|
+ }
|
|
|
+)
|
|
|
+
|
|
|
func kcSync() {
|
|
|
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 "%权益码兑换%")))
|
|
@@ -122,15 +129,7 @@ func kcJob(data map[string]interface{}) int {
|
|
|
"label": common.If(position_id > 0, 1, nil),
|
|
|
})
|
|
|
if clueId > 0 {
|
|
|
- TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
- "clue_id": clueId,
|
|
|
- "position_id": common.If(position_id > 0, position_id, -1),
|
|
|
- "change_type": "创建线索",
|
|
|
- "new_value": "系统自动创建",
|
|
|
- "createtime": nowTime,
|
|
|
- "BCPCID": common.GetRandom(32),
|
|
|
- "operator_id": -1,
|
|
|
- })
|
|
|
+ AddChangeRecord(nil, clueId, gconv.Int64(common.If(position_id > 0, position_id, -1)), "", "创建线索", "系统自动创建", "", nowTime, "", -1)
|
|
|
clueData = TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"uid": uId}, "", "")
|
|
|
if clueData == nil || len(*clueData) == 0 {
|
|
|
return 0
|
|
@@ -241,36 +240,10 @@ func kcJob(data map[string]interface{}) int {
|
|
|
updateMap["is_task"] = 1
|
|
|
}
|
|
|
TiDb.Update("dwd_f_csm_customer_info", map[string]interface{}{"clue_id": clueId}, updateMap)
|
|
|
- TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
- "clue_id": clueId,
|
|
|
- "position_id": customerPositionId,
|
|
|
- "change_type": "成交客户移交",
|
|
|
- "new_value": "移交至客户成功组",
|
|
|
- "createtime": nowTime,
|
|
|
- "BCPCID": common.GetRandom(32),
|
|
|
- "operator_id": -1,
|
|
|
- })
|
|
|
+ AddChangeRecord(nil, clueId, customerPositionId, "", "成交客户移交", "移交至客户成功组", "", nowTime, "", -1)
|
|
|
if customerPositionId > 0 && (is_transfer == 1 || customerPositionId != gconv.Int64((*csmdata)["position_id"])) {
|
|
|
- TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
- "clue_id": clueId,
|
|
|
- "position_id": customerPositionId,
|
|
|
- "change_field": "position_id",
|
|
|
- "change_type": "客户成功经理",
|
|
|
- "old_value": common.If(oldName != customerName, oldName, common.If(oldName == "", "/", oldName)),
|
|
|
- "new_value": customerName,
|
|
|
- "createtime": nowTime,
|
|
|
- "BCPCID": common.GetRandom(32),
|
|
|
- "operator_id": -1,
|
|
|
- })
|
|
|
- TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
- "clue_id": clueId,
|
|
|
- "position_id": customerPositionId,
|
|
|
- "change_type": "加入任务车",
|
|
|
- "new_value": "未建联",
|
|
|
- "createtime": nowTime,
|
|
|
- "BCPCID": common.GetRandom(32),
|
|
|
- "operator_id": -1,
|
|
|
- })
|
|
|
+ AddChangeRecord(nil, clueId, customerPositionId, "position_id", "客户成功经理", customerName, gconv.String(common.If(oldName != customerName, oldName, common.If(oldName == "", "/", oldName))), nowTime, "", -1)
|
|
|
+ AddChangeRecord(nil, clueId, customerPositionId, "", "加入任务车", "未建联", "", nowTime, "", -1)
|
|
|
}
|
|
|
if is_transfer == 1 || customerPositionId != gconv.Int64((*csmdata)["position_id"]) {
|
|
|
if customerName == db.KeCheng.Admin {
|
|
@@ -293,37 +266,11 @@ func kcJob(data map[string]interface{}) int {
|
|
|
cId = TiDb.InsertByTx(tx, "dwd_f_csm_customer_info", saveMap)
|
|
|
ok = TiDb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, map[string]interface{}{"is_transfer": 1, "updatetime": nowTime, "name": userName})
|
|
|
if customerPositionId > 0 {
|
|
|
- updateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
- "clue_id": clueId,
|
|
|
- "position_id": customerPositionId,
|
|
|
- "change_type": "加入任务车",
|
|
|
- "new_value": "未建联",
|
|
|
- "createtime": nowTime,
|
|
|
- "BCPCID": common.GetRandom(32),
|
|
|
- "operator_id": -1,
|
|
|
- })
|
|
|
- updateId3 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
- "clue_id": clueId,
|
|
|
- "position_id": customerPositionId,
|
|
|
- "change_field": "position_id",
|
|
|
- "change_type": "客户成功经理",
|
|
|
- "old_value": "/",
|
|
|
- "new_value": customerName,
|
|
|
- "createtime": nowTime,
|
|
|
- "BCPCID": common.GetRandom(32),
|
|
|
- "operator_id": -1,
|
|
|
- })
|
|
|
+ updateId1 = AddChangeRecord(tx, clueId, customerPositionId, "", "加入任务车", "未建联", "", nowTime, "", -1)
|
|
|
+ updateId3 = AddChangeRecord(tx, clueId, customerPositionId, "position_id", "客户成功经理", customerName, "/", nowTime, "", -1)
|
|
|
}
|
|
|
KcSend(orderCode, customerName)
|
|
|
- updateId2 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
- "clue_id": clueId,
|
|
|
- "position_id": customerPositionId,
|
|
|
- "change_type": "成交客户移交",
|
|
|
- "new_value": "移交至客户成功组",
|
|
|
- "createtime": nowTime,
|
|
|
- "BCPCID": common.GetRandom(32),
|
|
|
- "operator_id": -1,
|
|
|
- })
|
|
|
+ updateId2 := AddChangeRecord(tx, clueId, customerPositionId, "", "成交客户移交", "移交至客户成功组", "", nowTime, "", -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)
|
|
@@ -479,26 +426,11 @@ func kcAuto() {
|
|
|
taskstatus := common.IntAll(v["taskstatus"])
|
|
|
if relationship_building_way != 1 && inventory_way == 1 {
|
|
|
tasksources = "2"
|
|
|
- TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
- "clue_id": clueId,
|
|
|
- "position_id": positionId,
|
|
|
- "change_type": "加入任务车",
|
|
|
- "new_value": "未盘点",
|
|
|
- "createtime": nowTime,
|
|
|
- "BCPCID": common.GetRandom(32),
|
|
|
- "operator_id": -1,
|
|
|
- })
|
|
|
+ AddChangeRecord(nil, clueId, positionId, "", "加入任务车", "未盘点", "", nowTime, "", -1)
|
|
|
+
|
|
|
} else if inventory_way != 1 && training_way == 1 {
|
|
|
tasksources = "3"
|
|
|
- TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
- "clue_id": clueId,
|
|
|
- "position_id": positionId,
|
|
|
- "change_type": "加入任务车",
|
|
|
- "new_value": "未培训",
|
|
|
- "createtime": nowTime,
|
|
|
- "BCPCID": common.GetRandom(32),
|
|
|
- "operator_id": -1,
|
|
|
- })
|
|
|
+ AddChangeRecord(nil, clueId, positionId, "", "加入任务车", "未培训", "", nowTime, "", -1)
|
|
|
}
|
|
|
if taskstatus == 1 {
|
|
|
tasksource = tasksources
|
|
@@ -655,26 +587,11 @@ func ordersClue() {
|
|
|
})
|
|
|
}
|
|
|
if clueId > 0 {
|
|
|
- TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
- "clue_id": clueId,
|
|
|
- "position_id": common.If(positionId > 0, positionId, -1),
|
|
|
- "change_type": "创建线索",
|
|
|
- "new_value": "系统自动创建",
|
|
|
- "createtime": nowTime,
|
|
|
- "BCPCID": common.GetRandom(32),
|
|
|
- "operator_id": -1,
|
|
|
- })
|
|
|
+ AddChangeRecord(nil, clueId, gconv.Int64(common.If(positionId > 0, positionId, -1)), "", "创建线索", "系统自动创建", "", nowTime, "", -1)
|
|
|
if is_assign == -3 {
|
|
|
//新增冻结记录
|
|
|
- TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
- "clue_id": clueId,
|
|
|
- "position_id": positionId,
|
|
|
- "change_type": "线索冻结",
|
|
|
- "new_value": "销售人员私海已达上限",
|
|
|
- "createtime": nowTime,
|
|
|
- "BCPCID": common.GetRandom(32),
|
|
|
- "operator_id": -1,
|
|
|
- })
|
|
|
+ AddChangeRecord(nil, clueId, positionId, "", "线索冻结", "销售人员私海已达上限", "", nowTime, "", -1)
|
|
|
+
|
|
|
//移交失败发送消息
|
|
|
if IsFreeze(source, pay_money, gconv.String(positionId), trailstatus) {
|
|
|
//发送邮件信息
|
|
@@ -763,46 +680,10 @@ func refundAuto() {
|
|
|
if isAllRefund {
|
|
|
//全退款了
|
|
|
TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_clue_info SET is_unfollow=0,is_assign=0,trailstatus="01",position_id=null,seatNumber=null,updatetime=?,comeintime_open=?,comeinsource_open=1,level_open=3,next_trail_time=null,is_task=null,tasktime=null,taskstatus=null,comeinsource_private=null,tasksource=null,is_transfer=0 WHERE id = ?`, nowTime, nowTime, clueId)
|
|
|
- TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
- "clue_id": clueId,
|
|
|
- "position_id": common.If(kcposition_id > 0, kcposition_id, -1),
|
|
|
- "change_type": "退回公海",
|
|
|
- "new_value": "成交客户申请退款",
|
|
|
- "createtime": nowTime,
|
|
|
- "BCPCID": common.GetRandom(32),
|
|
|
- "operator_id": -1,
|
|
|
- })
|
|
|
- TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
- "clue_id": clueId,
|
|
|
- "position_id": common.If(kcposition_id > 0, kcposition_id, -1),
|
|
|
- "change_field": "trailstatus",
|
|
|
- "change_type": "基本信息变更",
|
|
|
- "old_value": "成交客户",
|
|
|
- "new_value": "商机线索",
|
|
|
- "createtime": nowTime,
|
|
|
- "BCPCID": common.GetRandom(32),
|
|
|
- "operator_id": -1,
|
|
|
- })
|
|
|
- TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
- "clue_id": clueId,
|
|
|
- "position_id": common.If(kcposition_id > 0, kcposition_id, -1),
|
|
|
- "change_type": "客户成功经理",
|
|
|
- "change_field": "position_id",
|
|
|
- "old_value": name,
|
|
|
- "new_value": "/",
|
|
|
- "createtime": nowTime,
|
|
|
- "BCPCID": common.GetRandom(32),
|
|
|
- "operator_id": -1,
|
|
|
- })
|
|
|
- TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
- "clue_id": clueId,
|
|
|
- "position_id": common.If(kcposition_id > 0, kcposition_id, -1),
|
|
|
- "change_type": "移交销售",
|
|
|
- "new_value": "成交客户申请退款",
|
|
|
- "createtime": nowTime,
|
|
|
- "BCPCID": common.GetRandom(32),
|
|
|
- "operator_id": -1,
|
|
|
- })
|
|
|
+ AddChangeRecord(nil, clueId, gconv.Int64(common.If(kcposition_id > 0, kcposition_id, -1)), "", "退回公海", "成交客户申请退款", "", nowTime, "", -1)
|
|
|
+ AddChangeRecord(nil, clueId, gconv.Int64(common.If(kcposition_id > 0, kcposition_id, -1)), "trailstatus", "基本信息变更", "商机线索", "成交客户", nowTime, "", -1)
|
|
|
+ AddChangeRecord(nil, clueId, gconv.Int64(common.If(kcposition_id > 0, kcposition_id, -1)), "position_id", "客户成功经理", "/", name, nowTime, "", -1)
|
|
|
+ AddChangeRecord(nil, clueId, gconv.Int64(common.If(kcposition_id > 0, kcposition_id, -1)), "", "移交销售", "成交客户申请退款", "", nowTime, "", -1)
|
|
|
mailData[name] = append(mailData[name], map[string]interface{}{
|
|
|
"company_name": company_name,
|
|
|
"phone": phone,
|
|
@@ -936,58 +817,14 @@ func refundAuto() {
|
|
|
"cluename": cluename,
|
|
|
})
|
|
|
}
|
|
|
- TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
- "clue_id": clueId,
|
|
|
- "position_id": common.If(kcposition_id > 0, kcposition_id, -1),
|
|
|
- "change_type": "基本信息变更",
|
|
|
- "old_value": "成交客户",
|
|
|
- "change_field": "trailstatus",
|
|
|
- "new_value": "商机线索",
|
|
|
- "createtime": nowTime,
|
|
|
- "BCPCID": common.GetRandom(32),
|
|
|
- "operator_id": -1,
|
|
|
- })
|
|
|
- TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
- "clue_id": clueId,
|
|
|
- "position_id": saleId,
|
|
|
- "change_type": "加入任务车",
|
|
|
- "new_value": "线索自动分配-其他-成交客户续约失败",
|
|
|
- "createtime": nowTime,
|
|
|
- "BCPCID": common.GetRandom(32),
|
|
|
- "operator_id": -1,
|
|
|
- })
|
|
|
- TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
- "clue_id": clueId,
|
|
|
- "position_id": common.If(kcposition_id > 0, kcposition_id, -1),
|
|
|
- "change_type": "客户成功经理",
|
|
|
- "change_field": "position_id",
|
|
|
- "old_value": name,
|
|
|
- "new_value": "/",
|
|
|
- "createtime": nowTime,
|
|
|
- "BCPCID": common.GetRandom(32),
|
|
|
- "operator_id": -1,
|
|
|
- })
|
|
|
- TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
- "clue_id": clueId,
|
|
|
- "position_id": saleId,
|
|
|
- "change_type": "移交销售",
|
|
|
- "new_value": "成交客户续费失败,到期自动移交",
|
|
|
- "createtime": nowTime,
|
|
|
- "BCPCID": common.GetRandom(32),
|
|
|
- "operator_id": -1,
|
|
|
- })
|
|
|
+ AddChangeRecord(nil, clueId, gconv.Int64(common.If(kcposition_id > 0, kcposition_id, -1)), "trailstatus", "基本信息变更", "商机线索", "", nowTime, "", -1)
|
|
|
+ AddChangeRecord(nil, clueId, saleId, "trailstatus", "加入任务车", "线索自动分配-其他-成交客户续约失败", "", nowTime, "", -1)
|
|
|
+ AddChangeRecord(nil, clueId, gconv.Int64(common.If(kcposition_id > 0, kcposition_id, -1)), "position_id", "客户成功经理", "/", name, nowTime, "", -1)
|
|
|
+ AddChangeRecord(nil, clueId, saleId, "", "移交销售", "成交客户续费失败,到期自动移交", "", nowTime, "", -1)
|
|
|
TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_csm_customer_info SET is_transfer=1 WHERE clue_id = ?`, clueId)
|
|
|
if isFull {
|
|
|
//新增冻结记录
|
|
|
- TiDb.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
- "clue_id": clueId,
|
|
|
- "position_id": saleId,
|
|
|
- "change_type": "线索冻结",
|
|
|
- "new_value": "销售人员私海已达上限",
|
|
|
- "createtime": nowTime,
|
|
|
- "BCPCID": common.GetRandom(32),
|
|
|
- "operator_id": -1,
|
|
|
- })
|
|
|
+ AddChangeRecord(nil, clueId, saleId, "", "线索冻结", "销售人员私海已达上限", "", nowTime, "", -1)
|
|
|
//发送邮件
|
|
|
mailContent := ""
|
|
|
if cluename != "" {
|
|
@@ -1486,59 +1323,11 @@ func kcClue(userId, uId, seatNumber, cluename, top_cluetype, sub_cluetype,
|
|
|
"label": 1,
|
|
|
"labelChangeTime": time.Now().Format("2006-01-02"),
|
|
|
})
|
|
|
- uodateId1 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
- "clue_id": clueId,
|
|
|
- "position_id": positionId,
|
|
|
- "change_type": "创建线索",
|
|
|
- "new_value": "系统自动创建",
|
|
|
- "createtime": nowTime,
|
|
|
- "BCPCID": common.GetRandom(32),
|
|
|
- "operator_id": -1,
|
|
|
- })
|
|
|
- uodateId2 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
- "clue_id": clueId,
|
|
|
- "position_id": positionId,
|
|
|
- "change_field": "position_id",
|
|
|
- "change_type": "所属人变更",
|
|
|
- "old_value": "/",
|
|
|
- "new_value": saleName,
|
|
|
- "createtime": nowTime,
|
|
|
- "BCPCID": common.GetRandom(32),
|
|
|
- "operator_id": -1,
|
|
|
- })
|
|
|
- uodateId3 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
- "clue_id": clueId,
|
|
|
- "position_id": positionId,
|
|
|
- "change_field": "trailstatus",
|
|
|
- "change_type": "基本信息变更",
|
|
|
- "old_value": "商机线索",
|
|
|
- "new_value": "新增",
|
|
|
- "createtime": nowTime,
|
|
|
- "BCPCID": common.GetRandom(32),
|
|
|
- "operator_id": -1,
|
|
|
- })
|
|
|
- uodateId5 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
- "clue_id": clueId,
|
|
|
- "position_id": positionId,
|
|
|
- "change_field": "top_cluetype",
|
|
|
- "change_type": "基本信息变更",
|
|
|
- "old_value": "/",
|
|
|
- "new_value": topname,
|
|
|
- "createtime": nowTime,
|
|
|
- "BCPCID": common.GetRandom(32),
|
|
|
- "operator_id": -1,
|
|
|
- })
|
|
|
- uodateId5 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
- "clue_id": clueId,
|
|
|
- "position_id": positionId,
|
|
|
- "change_field": "sub_cluetype", //222
|
|
|
- "change_type": "基本信息变更",
|
|
|
- "old_value": "/",
|
|
|
- "new_value": subname,
|
|
|
- "createtime": nowTime,
|
|
|
- "BCPCID": common.GetRandom(32),
|
|
|
- "operator_id": -1,
|
|
|
- })
|
|
|
+ uodateId1 = AddChangeRecord(tx, clueId, positionId, "", "创建线索", "系统自动创建", "", nowTime, "", -1)
|
|
|
+ uodateId2 = AddChangeRecord(tx, clueId, positionId, "position_id", "所属人变更", saleName, "/", nowTime, "", -1)
|
|
|
+ uodateId3 = AddChangeRecord(tx, clueId, positionId, "trailstatus", "基本信息变更", "新增", "商机线索", nowTime, "", -1)
|
|
|
+ uodateId4 = AddChangeRecord(tx, clueId, positionId, "top_cluetype", "基本信息变更", topname, "/", nowTime, "", -1)
|
|
|
+ uodateId5 = AddChangeRecord(tx, clueId, positionId, "sub_cluetype", "基本信息变更", subname, "/", nowTime, "", -1)
|
|
|
return clueId > -1 && uodateId1 > -1 && uodateId2 > -1 && uodateId3 > -1 && uodateId4 > -1 && uodateId5 > -1
|
|
|
}) {
|
|
|
log.Println("线索分配成功")
|