123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- package service
- import (
- "app.yhyue.com/moapp/jybase/common"
- "bp.jydev.jianyu360.cn/BaseService/biService/entity"
- "database/sql"
- "errors"
- "go.mongodb.org/mongo-driver/bson"
- "time"
- )
- func RelatedCompanyIsCustom(companyName string) bool {
- if companyName == "" {
- return false
- }
- return entity.JyBiTidb.CountBySql("SELECT count(1) FROM dwd_f_csm_customer_info WHERE company_name = ? and account_type= 1 and is_transfer = 0", companyName) > 0
- }
- // 电销系统修改线索名称移交客成
- func ClueTransfer(clueId int64, clueName string) (status int, err error) {
- //clueData := entity.JyBiTidb.FindOne("dwd_f_crm_clue_info", bson.M{"id": clueId}, "cluename", "")
- //if clueData == nil || len(*clueData) == 0 {
- // return -1, errors.New("未查询到线索信息")
- //}
- //clueName := common.InterfaceToStr((*clueData)["cluename"])
- //查询关联客户客成信息
- relatedData := entity.JyBiTidb.FindOne("dwd_f_csm_customer_info", bson.M{"company_name": clueName, "account_type": 1, "is_transfer": 0}, "id,position_id,name,ent_id,company_name", "")
- if relatedData == nil || len(*relatedData) == 0 {
- return -1, errors.New("未查询到关联客户信息")
- }
- positionId := common.Int64All((*relatedData)["position_id"])
- name := common.InterfaceToStr((*relatedData)["name"]) //客成经理名称
- entId := common.Int64All((*relatedData)["ent_id"])
- cusId := common.Int64All((*relatedData)["id"])
- nowTime := time.Now().Format("2006-01-02 15:04:05")
- //判断之前该线索是否移交过客成
- cusData := entity.JyBiTidb.FindOne("dwd_f_csm_customer_info", bson.M{"clue_id": clueId}, "is_transfer", "")
- if cusData != nil && len(*cusData) > 0 { //该线索曾经移交过客成
- if common.IntAll((*cusData)["is_transfer"]) == 0 {
- return 1, nil
- } else {
- up1 := entity.JyBiTidb.Update("dwd_f_csm_customer_info", map[string]interface{}{"clue_id": clueId}, bson.M{
- "is_transfer": 0,
- "is_renewal_protection": 0,
- "transfertime": nowTime,
- "ent_id": entId,
- "company_name": clueName,
- "position_id": positionId,
- "name": name,
- "is_admin": 0,
- "primary_id": cusId,
- "account_type": 4,
- })
- in := entity.JyBiTidb.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,
- "change_reason": "与主账号线索名称保持一致",
- })
- up2 := entity.JyBiTidb.Update("dwd_f_crm_clue_info", bson.M{"id": clueId}, map[string]interface{}{"is_transfer": 1, "updatetime": nowTime})
- if up1 && up2 && in > 0 {
- return 1, nil
- }
- return -1, errors.New("更新客成信息出错")
- }
- } else {
- saveMap := map[string]interface{}{
- "clue_id": clueId,
- "transfertime": nowTime,
- "position_id": positionId,
- "name": name,
- "ent_id": entId,
- "is_task": 1,
- "tasktime": nowTime,
- "taskstatus": 0,
- "tasksource": "1",
- "is_admin": 0,
- "relationship_building_way": 1,
- "inventory_way": 1,
- "training_way": 1,
- "is_pre_sales_training": 0,
- "service_stage": 1,
- "company_name": clueName,
- "primary_id": cusId,
- "account_type": 4,
- }
- cId, ok, updateId1 := int64(-1), false, int64(-1)
- if entity.JyBiTidb.ExecTx("保存客户", func(tx *sql.Tx) bool {
- cId = entity.JyBiTidb.InsertByTx(tx, "dwd_f_csm_customer_info", saveMap)
- ok = entity.JyBiTidb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, map[string]interface{}{"is_transfer": 1, "updatetime": nowTime})
- updateId1 = entity.JyBiTidb.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,
- "change_reason": "与主账号线索名称保持一致",
- })
- return cId > -1 && ok && updateId1 > -1
- }) {
- return 1, nil
- }
- return -1, errors.New("移交客成失败")
- }
- }
|