|
@@ -185,7 +185,7 @@ func ClueAdd(this *biservice.ClueAddReq, col string) *biservice.AddProjectResp {
|
|
|
if this.Company == "" {
|
|
|
this.Company = this.Phone
|
|
|
}
|
|
|
- isGroup, isCommerce := CompanyType(this.Company)
|
|
|
+ isGroup, isCommerce, _ := CompanyType(this.Company)
|
|
|
saveMap := map[string]interface{}{
|
|
|
"unique_id": this.Phone,
|
|
|
"phone": this.Phone,
|
|
@@ -499,8 +499,8 @@ func DrawClue(this *biservice.DrawClueReq) *biservice.AddProjectResp {
|
|
|
func DrawClueSync(this *biservice.DrawClueReq) (int, int) {
|
|
|
if DataLock.TryLock() {
|
|
|
defer DataLock.Unlock()
|
|
|
- count1 := JyBiTidb.CountBySql(`select count(1) as count from dwd_f_crm_clue_info where level_open=1 and is_assign=0 and is_transfer != 1`)
|
|
|
- count2 := JyBiTidb.CountBySql(`select count(1) as count from dwd_f_crm_clue_info where level_open=2 and is_assign=0 and is_transfer != 1`)
|
|
|
+ count1 := JyBiTidb.CountBySql(`select count(1) as count from dwd_f_crm_clue_info where level_open=1 and is_assign=0 and (lock_position_id is null and lock_position_id=? ) and is_transfer != 1 `, this.PositionId)
|
|
|
+ count2 := JyBiTidb.CountBySql(`select count(1) as count from dwd_f_crm_clue_info where level_open=2 and is_assign=0 and (lock_position_id is null and lock_position_id=? ) and is_transfer != 1`, this.PositionId)
|
|
|
counts1, counts2, counts3 := int64(0), int64(0), int64(0)
|
|
|
counts1 = int64(math.Ceil(float64(this.Count) / float64(10) * 5))
|
|
|
if this.Count-counts1 == 0 {
|
|
@@ -534,56 +534,6 @@ func DrawClues(positionId, count1, count2, count3 int64) int {
|
|
|
nowTime := time.Now().Format("2006-01-02 15:04:05")
|
|
|
seatNumber, name := getSeatNumber(positionId)
|
|
|
drawCount := 0
|
|
|
- //data1, data2, data3, drawCount := &[]map[string]interface{}{}, &[]map[string]interface{}{}, &[]map[string]interface{}{}, 0
|
|
|
- /*if count1 > 0 {
|
|
|
- data1 = JyBiTidb.SelectBySql(`SELECT * from dwd_f_crm_clue_info where is_assign = 0 and level_open = ? and cluename in (SELECT cluename from dwd_f_crm_clue_info where position_id = ? GROUP BY cluename)`, 1, positionId)
|
|
|
- if data1 != nil && len(*data1) > 0 {
|
|
|
- if int64(len(*data1)) >= count1 {
|
|
|
- data11 := (*data1)[0:count1]
|
|
|
- data1 = &data11
|
|
|
- count1 = 0
|
|
|
- } else {
|
|
|
- count1 = count1 - int64(len(*data1))
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if count2 > 0 {
|
|
|
- data2 = JyBiTidb.SelectBySql(`SELECT * from dwd_f_crm_clue_info where is_assign = 0 and level_open = ? and cluename in (SELECT cluename from dwd_f_crm_clue_info where position_id = ? GROUP BY cluename)`, 2, positionId)
|
|
|
- if data2 != nil && len(*data2) > 0 {
|
|
|
- if int64(len(*data2)) >= count2 {
|
|
|
- data11 := (*data2)[0:count2]
|
|
|
- data2 = &data11
|
|
|
- count2 = 0
|
|
|
- } else {
|
|
|
- count2 = count2 - int64(len(*data2))
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if count3 > 0 {
|
|
|
- data3 = JyBiTidb.SelectBySql(`SELECT * from dwd_f_crm_clue_info where is_assign = 0 and level_open = ? and cluename in (SELECT cluename from dwd_f_crm_clue_info where position_id = ? GROUP BY cluename)`, 3, positionId)
|
|
|
- if data3 != nil && len(*data3) > 0 {
|
|
|
- if int64(len(*data3)) >= count3 {
|
|
|
- data11 := (*data3)[0:count3]
|
|
|
- data3 = &data11
|
|
|
- count3 = 0
|
|
|
- } else {
|
|
|
- count3 = count3 - int64(len(*data3))
|
|
|
- }
|
|
|
- }
|
|
|
- }*/
|
|
|
- //
|
|
|
- /*if data1 != nil && len(*data1) > 0 {
|
|
|
- count := batchDraw(*data1, nowTime, seatNumber, name, positionId, "1")
|
|
|
- drawCount += count
|
|
|
- }
|
|
|
- if data2 != nil && len(*data2) > 0 {
|
|
|
- count := batchDraw(*data2, nowTime, seatNumber, name, positionId, "1")
|
|
|
- drawCount += count
|
|
|
- }
|
|
|
- if data3 != nil && len(*data3) > 0 {
|
|
|
- count := batchDraw(*data3, nowTime, seatNumber, name, positionId, "1")
|
|
|
- drawCount += count
|
|
|
- }*/
|
|
|
//
|
|
|
logx.Info("count1,count2,count3 ", count1, count2, count3, drawCount)
|
|
|
if count1 > 0 {
|
|
@@ -591,7 +541,7 @@ func DrawClues(positionId, count1, count2, count3 int64) int {
|
|
|
for {
|
|
|
logx.Info("等级1线索领取", count1, counts1, counts)
|
|
|
data := JyBiTidb.SelectBySql(`SELECT a.last_ring_time as ctime,a.id,a.trailstatus,a.cluename FROM dwd_f_crm_clue_info a
|
|
|
- WHERE a.level_open = 1 AND a.is_assign = 0 AND a.uid !="" AND a.is_transfer != 1 GROUP BY a.id ORDER BY ctime asc limit ?,1`, counts1)
|
|
|
+ WHERE a.level_open = 1 AND a.is_assign=0 and (a.lock_position_id is null or a.lock_position_id=? ) AND a.uid !="" AND a.is_transfer != 1 GROUP BY a.id ORDER BY ctime asc limit ?,1`, counts1, positionId)
|
|
|
counts1++
|
|
|
if data != nil && len(*data) > 0 {
|
|
|
count := batchDraw(*data, nowTime, seatNumber, name, positionId, "2")
|
|
@@ -615,7 +565,7 @@ func DrawClues(positionId, count1, count2, count3 int64) int {
|
|
|
for {
|
|
|
logx.Info("等级2线索领取", count2, counts1, counts)
|
|
|
data := JyBiTidb.SelectBySql(`SELECT a.last_ring_time as ctime,a.id,a.trailstatus,a.cluename FROM dwd_f_crm_clue_info a
|
|
|
- WHERE a.level_open = 2 AND a.is_assign = 0 AND a.uid !="" AND a.is_transfer != 1 GROUP BY a.id ORDER BY ctime asc limit ?,1`, counts1)
|
|
|
+ WHERE a.level_open = 2 AND a.is_assign=0 and (a.lock_position_id is null or a.lock_position_id=? ) AND a.uid !="" AND a.is_transfer != 1 GROUP BY a.id ORDER BY ctime asc limit ?,1`, counts1, positionId)
|
|
|
counts1++
|
|
|
if data != nil && len(*data) > 0 {
|
|
|
count := batchDraw(*data, nowTime, seatNumber, name, positionId, "2")
|
|
@@ -664,32 +614,6 @@ func batchDraw(data []map[string]interface{}, nowTime, seatNumber, name string,
|
|
|
count := 0
|
|
|
for _, v := range data {
|
|
|
clueId := common.Int64All(v["id"])
|
|
|
- //cluename := common.ObjToString(v["cluename"])
|
|
|
- /* if dataType == "2" {
|
|
|
- cdata := JyBiMysql.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"cluename": cluename, "is_assign": 1, "company_nature": 0, "company_verification": 1}, "", "")
|
|
|
- if cdata != nil && len(*cdata) > 0 {
|
|
|
- salePositionId := common.Int64All((*cdata)["position_id"])
|
|
|
- if pcount := JyBiMysql.Count("dwd_f_crm_personnel_management", map[string]interface{}{"resign": 0, "position_id": salePositionId}); pcount > 0 {
|
|
|
- logx.Info("当前线索有在职销售 ", clueId, cluename)
|
|
|
- return count
|
|
|
- } else {
|
|
|
- saledata := JyBiMysql.SelectBySql(`SELECT position_id from dwd_d_crm_department_level_succbi WHERE bi_pcode in (SELECT bi_pcode from dwd_d_crm_department_level_succbi WHERE position_id = ?) AND resign = 0`, salePositionId)
|
|
|
- if saledata != nil && len(*saledata) > 0 {
|
|
|
- isOk := false
|
|
|
- for _, s := range *saledata {
|
|
|
- sid := common.Int64All(s["position_id"])
|
|
|
- if sid == positionId {
|
|
|
- isOk = true
|
|
|
- }
|
|
|
- }
|
|
|
- if !isOk {
|
|
|
- logx.Info("当前线索销售离职,只能同部门领取 ", clueId, cluename)
|
|
|
- return count
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }*/
|
|
|
trailstatus := common.ObjToString(v["trailstatus"])
|
|
|
if JyBiMysql.ExecTx("领取线索等", func(tx *sql.Tx) bool {
|
|
|
updateClue := map[string]interface{}{
|
|
@@ -708,6 +632,93 @@ func batchDraw(data []map[string]interface{}, nowTime, seatNumber, name string,
|
|
|
"clue_level": nil,
|
|
|
}
|
|
|
updateClue["trailstatus"] = "01"
|
|
|
+ //判断一下是否需要变更锁定信息
|
|
|
+ recordId3, recordId4, recordId5, recordId6 := int64(0), int64(0), int64(0), int64(0)
|
|
|
+ lock_position_id := gconv.Int64(v["lock_position_id"])
|
|
|
+ lock_status := gconv.Int64(v["lock_status"])
|
|
|
+ group := gconv.Int64(v["COMPANY_NATURE"])
|
|
|
+ business := gconv.Int64(v["COMPANY_VERIFICATION"])
|
|
|
+ new_lock_status := int64(2)
|
|
|
+ clueName := gconv.String(v["cluename"])
|
|
|
+ if group == 1 && business != 3 {
|
|
|
+ //无需锁定处理
|
|
|
+ if lock_status != 3 {
|
|
|
+ new_lock_status = 3
|
|
|
+ }
|
|
|
+ } else if group == 0 && business == 1 {
|
|
|
+ //已锁定处理
|
|
|
+ new_lock_status = 1
|
|
|
+ }
|
|
|
+ updateClue["lock_status"] = new_lock_status
|
|
|
+ updateClue["lock_time"] = nowTime
|
|
|
+ if new_lock_status != lock_status {
|
|
|
+ //锁定状态变更
|
|
|
+ recordId5 = JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
+ "clue_id": clueId,
|
|
|
+ "position_id": positionId,
|
|
|
+ "change_field": "lock_status",
|
|
|
+ "change_type": "基本信息变更",
|
|
|
+ "old_value": common.If(lock_status == 0, "/", CodeLock[lock_status]),
|
|
|
+ "new_value": CodeLock[lock_status],
|
|
|
+ "createtime": nowTime,
|
|
|
+ "BCPCID": common.GetRandom(32),
|
|
|
+ "operator_id": positionId,
|
|
|
+ })
|
|
|
+ recordId6 = JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
+ "clue_id": clueId,
|
|
|
+ "position_id": positionId,
|
|
|
+ "change_field": "lock_position_id",
|
|
|
+ "change_type": "绑定人变更",
|
|
|
+ "old_value": "/",
|
|
|
+ "new_value": name,
|
|
|
+ "createtime": nowTime,
|
|
|
+ "BCPCID": common.GetRandom(32),
|
|
|
+ "operator_id": positionId,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if positionId != lock_position_id && new_lock_status != lock_status && new_lock_status == 1 {
|
|
|
+ updateClue["lock_position_id"] = positionId
|
|
|
+ //锁定人员变更
|
|
|
+ clueArr := JyBiMysql.SelectBySql(`SELECT
|
|
|
+ b.id,b.lock_status,b.lock_position_id
|
|
|
+ FROM
|
|
|
+ relatedRelationships a
|
|
|
+ INNER JOIN dwd_f_crm_clue_info b
|
|
|
+ on a.company=? and a.association_company=b.cluename and b.COMPANY_VERIFICATION=1 and b.COMPANY_NATURE=0`, clueName)
|
|
|
+ if clueArr != nil && len(*clueArr) > 0 {
|
|
|
+ for _, v1 := range collection {
|
|
|
+ lock_position_id1 := gconv.Int64(v1["lock_position_id"])
|
|
|
+ lock_status1 := gconv.Int64(v1["lock_status"])
|
|
|
+ clueId1 := gconv.Int64(v1["id"])
|
|
|
+ if ((lock_position_id1 != positionId && lock_position_id1 != 0) || lock_position_id1 == 0) && lock_status1 != lock_status {
|
|
|
+ //锁定状态变更
|
|
|
+ JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
+ "clue_id": clueId1,
|
|
|
+ "position_id": positionId,
|
|
|
+ "change_field": "lock_status",
|
|
|
+ "change_type": "基本信息变更",
|
|
|
+ "old_value": common.If(lock_status1 == 0, "/", CodeLock[lock_status1]),
|
|
|
+ "new_value": CodeLock[lock_status],
|
|
|
+ "createtime": nowTime,
|
|
|
+ "BCPCID": common.GetRandom(32),
|
|
|
+ "operator_id": positionId,
|
|
|
+ })
|
|
|
+ JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
+ "clue_id": clueId,
|
|
|
+ "position_id": positionId,
|
|
|
+ "change_field": "lock_position_id",
|
|
|
+ "change_type": "绑定人变更",
|
|
|
+ "old_value": "/",
|
|
|
+ "new_value": name,
|
|
|
+ "createtime": nowTime,
|
|
|
+ "BCPCID": common.GetRandom(32),
|
|
|
+ "operator_id": positionId,
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
ok1 := JyBiTidb.UpdateByTx(tx, "dwd_f_crm_clue_info", map[string]interface{}{"id": clueId}, updateClue)
|
|
|
recordId := JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
"clue_id": clueId,
|
|
@@ -737,7 +748,7 @@ func batchDraw(data []map[string]interface{}, nowTime, seatNumber, name string,
|
|
|
"BCPCID": common.GetRandom(32),
|
|
|
"operator_id": positionId,
|
|
|
})
|
|
|
- recordId3, recordId4 := int64(0), int64(0)
|
|
|
+
|
|
|
recordId3 = JyBiTidb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
|
|
|
"clue_id": clueId,
|
|
|
"position_id": positionId,
|
|
@@ -914,7 +925,7 @@ func ClueImportSync(this *biservice.ClueImportReq) (string, int) {
|
|
|
cluename := common.ObjToString(v["cluename"])
|
|
|
name := common.ObjToString(v["name"])
|
|
|
position := common.ObjToString(v["position"])
|
|
|
- isGroup, isCommerce := CompanyType(cluename)
|
|
|
+ isGroup, isCommerce, _ := CompanyType(cluename)
|
|
|
clueData := JyBiTidb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"phone": phone}, "", "")
|
|
|
if clueData == nil || len(*clueData) == 0 {
|
|
|
countAdd++
|