xuzhiheng 2 years ago
parent
commit
1a87216ca8
2 changed files with 61 additions and 65 deletions
  1. 1 1
      rpc/internal/logic/drawcluelogic.go
  2. 60 64
      service/clue.go

+ 1 - 1
rpc/internal/logic/drawcluelogic.go

@@ -5,7 +5,7 @@ import (
 
 	"bp.jydev.jianyu360.cn/BaseService/biService/rpc/internal/svc"
 	"bp.jydev.jianyu360.cn/BaseService/biService/rpc/pb"
-
+	"bp.jydev.jianyu360.cn/BaseService/biService/service"
 	"github.com/zeromicro/go-zero/core/logx"
 )
 

+ 60 - 64
service/clue.go

@@ -1,6 +1,7 @@
 package service
 
 import (
+	"database/sql"
 	"math"
 	"time"
 
@@ -12,7 +13,7 @@ import (
 func DrawClue(this *biservice.DrawClueReq) *biservice.AddProjectResp {
 	count1 := JyBiTidb.Count("dwd_f_crm_open_sea", map[string]interface{}{"level": 1})
 	count2 := JyBiTidb.Count("dwd_f_crm_open_sea", map[string]interface{}{"level": 2})
-	count3 := JyBiTidb.Count("dwd_f_crm_open_sea", map[string]interface{}{"level": 3})
+	// count3 := JyBiTidb.Count("dwd_f_crm_open_sea", map[string]interface{}{"level": 3})
 	counts1 := int64(math.Floor(float64(this.Count) / float64(10) * 2))
 	counts2 := int64(math.Floor(float64(this.Count) / float64(10) * 4))
 	counts3 := this.Count - counts1 - counts2
@@ -32,19 +33,19 @@ func DrawClue(this *biservice.DrawClueReq) *biservice.AddProjectResp {
 }
 
 func DrawClues(positionId, count1, count2, count3 int64) {
-	data1 := JyBiTidb.Find("dwd_f_crm_open_sea", map[string]interface{}{"level": 1}, "", "", 0, count1)
-	data2 := JyBiTidb.Find("dwd_f_crm_open_sea", map[string]interface{}{"level": 2}, "", "", 0, count2)
-	data3 := JyBiTidb.Find("dwd_f_crm_open_sea", map[string]interface{}{"level": 3}, "", "", 0, count3)
+	data1 := JyBiTidb.Find("dwd_f_crm_open_sea", map[string]interface{}{"level": 1}, "", "", 0, int(count1))
+	data2 := JyBiTidb.Find("dwd_f_crm_open_sea", map[string]interface{}{"level": 2}, "", "", 0, int(count2))
+	data3 := JyBiTidb.Find("dwd_f_crm_open_sea", map[string]interface{}{"level": 3}, "", "", 0, int(count3))
+	nowTime := time.Now().Format("2006-01-02 15:04:05")
+	seatNumber, name := getSeatNumber(positionId)
 	if data1 != nil && len(*data1) > 0 {
 		for _, v := range *data1 {
 			//update postionid and update record
 			clueId := common.Int64All(v["clue_id"])
-			nowTime := time.Now().Format("2006-01-02 15:04:05")
-			seatNumber, name := getSeatNumber(positionId)
 			JyBiMysql.ExecTx("领取线索等", func(tx *sql.Tx) bool {
-				JyBiTidb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"id": clue_id}, map[string]interface{}{"position_id": positionId, "seatNumber": seatNumber})
-				JyBiTidb.DeleteByTx(tx, "dwd_f_crm_open_sea", map[string]interface{}{"id": clue_id})
-				JyBiTidb.InsertByTx(tx, "dwd_f_crm_private_sea", map[string]interface{}{
+				ok1 := JyBiTidb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, map[string]interface{}{"position_id": positionId, "seatNumber": seatNumber})
+				ok2 := JyBiTidb.DeleteByTx(tx, "dwd_f_crm_open_sea", map[string]interface{}{"id": clueId})
+				seaId := JyBiTidb.InsertByTx(tx, "dwd_f_crm_private_sea", map[string]interface{}{
 					"clue_id":      clueId,
 					"seatNumber":   seatNumber,
 					"position_id":  positionId,
@@ -52,7 +53,7 @@ func DrawClues(positionId, count1, count2, count3 int64) {
 					"comeinsource": 3,
 					"is_task":      0,
 				})
-				JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+				recordId := JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
 					"clue_id":      clueId,
 					"position_id":  positionId,
 					"change_field": "position_id",
@@ -63,70 +64,65 @@ func DrawClues(positionId, count1, count2, count3 int64) {
 					"BCPCID":       common.GetRandom(32),
 					"operator_id":  positionId,
 				})
+				return ok1 && ok2 && seaId > 0 && recordId > 0
 			})
 		}
 	}
 	if data2 != nil && len(*data2) > 0 {
 		for _, v := range *data2 {
-			JyBiTidb.ExecTx("领取线索等", func(tx *sql.Tx) bool {
-				clueId := common.Int64All(v["clue_id"])
-				nowTime := time.Now().Format("2006-01-02 15:04:05")
-				seatNumber, name := getSeatNumber(positionId)
-				JyBiMysql.ExecTx("领取线索等", func(tx *sql.Tx) bool {
-					JyBiTidb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"id": clue_id}, map[string]interface{}{"position_id": positionId, "seatNumber": seatNumber})
-					JyBiTidb.DeleteByTx(tx, "dwd_f_crm_open_sea", map[string]interface{}{"id": clue_id})
-					JyBiTidb.InsertByTx(tx, "dwd_f_crm_private_sea", map[string]interface{}{
-						"clue_id":      clueId,
-						"seatNumber":   seatNumber,
-						"position_id":  positionId,
-						"comeintime":   nowTime,
-						"comeinsource": 3,
-						"is_task":      0,
-					})
-					JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
-						"clue_id":      clueId,
-						"position_id":  positionId,
-						"change_field": "position_id",
-						"change_type":  "所属人变更",
-						"old_value":    "/",
-						"new_value":    name,
-						"createtime":   nowTime,
-						"BCPCID":       common.GetRandom(32),
-						"operator_id":  positionId,
-					})
+			clueId := common.Int64All(v["clue_id"])
+			JyBiMysql.ExecTx("领取线索等", func(tx *sql.Tx) bool {
+				ok1 := JyBiTidb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, map[string]interface{}{"position_id": positionId, "seatNumber": seatNumber})
+				ok2 := JyBiTidb.DeleteByTx(tx, "dwd_f_crm_open_sea", map[string]interface{}{"id": clueId})
+				seaId := JyBiTidb.InsertByTx(tx, "dwd_f_crm_private_sea", map[string]interface{}{
+					"clue_id":      clueId,
+					"seatNumber":   seatNumber,
+					"position_id":  positionId,
+					"comeintime":   nowTime,
+					"comeinsource": 3,
+					"is_task":      0,
+				})
+				recordId := JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+					"clue_id":      clueId,
+					"position_id":  positionId,
+					"change_field": "position_id",
+					"change_type":  "所属人变更",
+					"old_value":    "/",
+					"new_value":    name,
+					"createtime":   nowTime,
+					"BCPCID":       common.GetRandom(32),
+					"operator_id":  positionId,
 				})
+				return ok1 && ok2 && seaId > 0 && recordId > 0
 			})
 		}
 	}
 	if data3 != nil && len(*data3) > 0 {
 		for _, v := range *data3 {
-			JyBiTidb.ExecTx("领取线索等", func(tx *sql.Tx) bool {
-				clueId := common.Int64All(v["clue_id"])
-				nowTime := time.Now().Format("2006-01-02 15:04:05")
-				seatNumber, name := getSeatNumber(positionId)
-				JyBiMysql.ExecTx("领取线索等", func(tx *sql.Tx) bool {
-					JyBiTidb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"id": clue_id}, map[string]interface{}{"position_id": positionId, "seatNumber": seatNumber})
-					JyBiTidb.DeleteByTx(tx, "dwd_f_crm_open_sea", map[string]interface{}{"id": clue_id})
-					JyBiTidb.InsertByTx(tx, "dwd_f_crm_private_sea", map[string]interface{}{
-						"clue_id":      clueId,
-						"seatNumber":   seatNumber,
-						"position_id":  positionId,
-						"comeintime":   nowTime,
-						"comeinsource": 3,
-						"is_task":      0,
-					})
-					JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
-						"clue_id":      clueId,
-						"position_id":  positionId,
-						"change_field": "position_id",
-						"change_type":  "所属人变更",
-						"old_value":    "/",
-						"new_value":    name,
-						"createtime":   nowTime,
-						"BCPCID":       common.GetRandom(32),
-						"operator_id":  positionId,
-					})
+			clueId := common.Int64All(v["clue_id"])
+			JyBiMysql.ExecTx("领取线索等", func(tx *sql.Tx) bool {
+				ok1 := JyBiTidb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, map[string]interface{}{"position_id": positionId, "seatNumber": seatNumber})
+				ok2 := JyBiTidb.DeleteByTx(tx, "dwd_f_crm_open_sea", map[string]interface{}{"id": clueId})
+				seaId := JyBiTidb.InsertByTx(tx, "dwd_f_crm_private_sea", map[string]interface{}{
+					"clue_id":      clueId,
+					"seatNumber":   seatNumber,
+					"position_id":  positionId,
+					"comeintime":   nowTime,
+					"comeinsource": 3,
+					"is_task":      0,
+				})
+				recordId := JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
+					"clue_id":      clueId,
+					"position_id":  positionId,
+					"change_field": "position_id",
+					"change_type":  "所属人变更",
+					"old_value":    "/",
+					"new_value":    name,
+					"createtime":   nowTime,
+					"BCPCID":       common.GetRandom(32),
+					"operator_id":  positionId,
 				})
+				return ok1 && ok2 && seaId > 0 && recordId > 0
 			})
 		}
 	}
@@ -137,8 +133,8 @@ func getSeatNumber(positionId int64) (seatNumber, name string) {
 	if positionData != nil && len(*positionData) > 0 {
 		userId := common.Int64All((*positionData)["user_id"])
 		if userId > 0 {
-			userData := Mgo.FindOne("user", map[string]interface{}{"base_user_id": userId})
-			if userData != nil && len(*userData) > 0 {
+			userData, ok := Mgo.FindOne("user", map[string]interface{}{"base_user_id": userId})
+			if ok && userData != nil && len(*userData) > 0 {
 				s_phone := common.ObjToString((*userData)["s_phone"])
 				if s_phone == "" {
 					s_phone = common.ObjToString((*userData)["s_m_phone"])