|
@@ -2,6 +2,7 @@ package service
|
|
|
|
|
|
import (
|
|
|
"database/sql"
|
|
|
+ "log"
|
|
|
"math"
|
|
|
"time"
|
|
|
|
|
@@ -14,15 +15,27 @@ 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})
|
|
|
- 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
|
|
|
+ counts1, counts2, counts3 := int64(0), int64(0), int64(0)
|
|
|
+ counts1 = int64(math.Ceil(float64(this.Count) / float64(10) * 2))
|
|
|
+ if this.Count-counts1 == 0 {
|
|
|
+ counts2 = 0
|
|
|
+ counts3 = 0
|
|
|
+ } else {
|
|
|
+ counts2 = int64(math.Ceil(float64(this.Count) / float64(10) * 4))
|
|
|
+ if this.Count-counts1-counts2 == 0 {
|
|
|
+ counts3 = 0
|
|
|
+ } else {
|
|
|
+ counts3 = this.Count - counts1 - counts2
|
|
|
+ }
|
|
|
+ }
|
|
|
if counts1 > count1 {
|
|
|
counts2 += counts1 - count1
|
|
|
}
|
|
|
if counts2 > count2 {
|
|
|
counts3 += counts2 - count2
|
|
|
}
|
|
|
+ log.Println(count1, count2)
|
|
|
+ log.Println(counts1, counts2, counts3)
|
|
|
DrawClues(this.PositionId, counts1, counts2, counts3)
|
|
|
return &biservice.AddProjectResp{
|
|
|
ErrorCode: 0,
|
|
@@ -33,25 +46,36 @@ 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, 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))
|
|
|
+ data1, data2, data3 := &[]map[string]interface{}{}, &[]map[string]interface{}{}, &[]map[string]interface{}{}
|
|
|
+ if count1 > 0 {
|
|
|
+ data1 = JyBiTidb.Find("dwd_f_crm_open_sea", map[string]interface{}{"level": 1}, "", "", 0, int(count1))
|
|
|
+ }
|
|
|
+ if count2 > 0 {
|
|
|
+ data2 = JyBiTidb.Find("dwd_f_crm_open_sea", map[string]interface{}{"level": 2}, "", "", 0, int(count2))
|
|
|
+ }
|
|
|
+ if count3 > 0 {
|
|
|
+ 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"])
|
|
|
- JyBiMysql.ExecTx("领取线索等", func(tx *sql.Tx) bool {
|
|
|
+ if 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})
|
|
|
+ ok2 := JyBiTidb.DeleteByTx(tx, "dwd_f_crm_open_sea", map[string]interface{}{"clue_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,
|
|
|
+ "is_task": 1,
|
|
|
+ "task_time": nowTime,
|
|
|
+ "tasktime": nowTime,
|
|
|
+ "taskstatus": 0,
|
|
|
+ "tasksource": "领取公海线索",
|
|
|
})
|
|
|
recordId := JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
"clue_id": clueId,
|
|
@@ -64,16 +88,37 @@ func DrawClues(positionId, count1, count2, count3 int64) {
|
|
|
"BCPCID": common.GetRandom(32),
|
|
|
"operator_id": positionId,
|
|
|
})
|
|
|
- return ok1 && ok2 && seaId > 0 && recordId > 0
|
|
|
- })
|
|
|
+ recordId1 := JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
+ "clue_id": clueId,
|
|
|
+ "position_id": positionId,
|
|
|
+ "change_type": "领取公海线索",
|
|
|
+ "createtime": nowTime,
|
|
|
+ "BCPCID": common.GetRandom(32),
|
|
|
+ "operator_id": positionId,
|
|
|
+ })
|
|
|
+ recordId2 := 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": positionId,
|
|
|
+ })
|
|
|
+ return ok1 && ok2 && seaId > 0 && recordId > 0 && recordId1 > 0 && recordId2 > 0
|
|
|
+ }) {
|
|
|
+ log.Println("领取线索1成功")
|
|
|
+ } else {
|
|
|
+ log.Println("领取线索1失败")
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
if data2 != nil && len(*data2) > 0 {
|
|
|
for _, v := range *data2 {
|
|
|
clueId := common.Int64All(v["clue_id"])
|
|
|
- JyBiMysql.ExecTx("领取线索等", func(tx *sql.Tx) bool {
|
|
|
+ if 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})
|
|
|
+ ok2 := JyBiTidb.DeleteByTx(tx, "dwd_f_crm_open_sea", map[string]interface{}{"clue_id": clueId})
|
|
|
seaId := JyBiTidb.InsertByTx(tx, "dwd_f_crm_private_sea", map[string]interface{}{
|
|
|
"clue_id": clueId,
|
|
|
"seatNumber": seatNumber,
|
|
@@ -93,16 +138,37 @@ func DrawClues(positionId, count1, count2, count3 int64) {
|
|
|
"BCPCID": common.GetRandom(32),
|
|
|
"operator_id": positionId,
|
|
|
})
|
|
|
- return ok1 && ok2 && seaId > 0 && recordId > 0
|
|
|
- })
|
|
|
+ recordId1 := JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
+ "clue_id": clueId,
|
|
|
+ "position_id": positionId,
|
|
|
+ "change_type": "领取公海线索",
|
|
|
+ "createtime": nowTime,
|
|
|
+ "BCPCID": common.GetRandom(32),
|
|
|
+ "operator_id": positionId,
|
|
|
+ })
|
|
|
+ recordId2 := 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": positionId,
|
|
|
+ })
|
|
|
+ return ok1 && ok2 && seaId > 0 && recordId > 0 && recordId1 > 0 && recordId2 > 0
|
|
|
+ }) {
|
|
|
+ log.Println("领取线索2成功")
|
|
|
+ } else {
|
|
|
+ log.Println("领取线索2失败")
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
if data3 != nil && len(*data3) > 0 {
|
|
|
for _, v := range *data3 {
|
|
|
clueId := common.Int64All(v["clue_id"])
|
|
|
- JyBiMysql.ExecTx("领取线索等", func(tx *sql.Tx) bool {
|
|
|
+ if 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})
|
|
|
+ ok2 := JyBiTidb.DeleteByTx(tx, "dwd_f_crm_open_sea", map[string]interface{}{"clue_id": clueId})
|
|
|
seaId := JyBiTidb.InsertByTx(tx, "dwd_f_crm_private_sea", map[string]interface{}{
|
|
|
"clue_id": clueId,
|
|
|
"seatNumber": seatNumber,
|
|
@@ -122,8 +188,29 @@ func DrawClues(positionId, count1, count2, count3 int64) {
|
|
|
"BCPCID": common.GetRandom(32),
|
|
|
"operator_id": positionId,
|
|
|
})
|
|
|
- return ok1 && ok2 && seaId > 0 && recordId > 0
|
|
|
- })
|
|
|
+ recordId1 := JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
+ "clue_id": clueId,
|
|
|
+ "position_id": positionId,
|
|
|
+ "change_type": "领取公海线索",
|
|
|
+ "createtime": nowTime,
|
|
|
+ "BCPCID": common.GetRandom(32),
|
|
|
+ "operator_id": positionId,
|
|
|
+ })
|
|
|
+ recordId2 := 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": positionId,
|
|
|
+ })
|
|
|
+ return ok1 && ok2 && seaId > 0 && recordId > 0 && recordId1 > 0 && recordId2 > 0
|
|
|
+ }) {
|
|
|
+ log.Println("领取线索3成功")
|
|
|
+ } else {
|
|
|
+ log.Println("领取线索3失败")
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|