ソースを参照

Merge branch 'dev_v1.5.2_wh' of jianyu/datatools into feature/v1.5.2

王浩 1 年間 前
コミット
3c207ecb58
4 ファイル変更78 行追加126 行削除
  1. 0 110
      clueSync/config.json
  2. 1 11
      clueSync/job.go
  3. 76 5
      clueSync/kc.go
  4. 1 0
      clueSync/main.go

ファイルの差分が大きいため隠しています
+ 0 - 110
clueSync/config.json


+ 1 - 11
clueSync/job.go

@@ -821,17 +821,7 @@ func UpdateClue(data map[string]interface{}, saleData []map[string]interface{},
 				})
 			}
 			if old_role != role && role != "" {
-				updateId9 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{
-					"clue_id":      clueId,
-					"position_id":  common.If(trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400, -1, common.If(trailstatus == "00" || is_assign == 0, positionId, common.Int64All(data["position_id"]))),
-					"change_field": "role",
-					"change_type":  "基本信息变更",
-					"old_value":    common.If(old_role != "", old_role, "/"),
-					"new_value":    common.If(role != "", role, "/"),
-					"createtime":   nowTime,
-					"BCPCID":       BCPCID,
-					"operator_id":  -1,
-				})
+				updateId9 = TiDb.InsertByTx(tx, "dwd_f_crm_clue_change_record", map[string]interface{}{"clue_id": clueId, "position_id": common.If(trailstatus == "00" && trailstatusTime != "" && time.Now().Unix()-trailstatusTimes.Unix() < 86400, -1, common.If(trailstatus == "00" || is_assign == 0, positionId, common.Int64All(data["position_id"]))), "change_field": "role", "change_type": "基本信息变更", "old_value": common.If(old_role != "", old_role, "/"), "new_value": common.If(role != "", role, "/"), "createtime": nowTime, "BCPCID": BCPCID, "operator_id": -1})
 			}
 			if old_follow_project_area != follow_project_area && follow_project_area != "" {
 				old_area, old_area_arr := "", []string{}

+ 76 - 5
clueSync/kc.go

@@ -4,6 +4,7 @@ import (
 	"database/sql"
 	"encoding/json"
 	"fmt"
+	"github.com/gogf/gf/v2/util/gconv"
 	"log"
 	"strconv"
 	"strings"
@@ -425,12 +426,14 @@ func ordersClue() {
 			if order_status == 1 && is_backstage_order == 1 && salesperson != "" && !strings.HasPrefix(user_phone, "9") && strings.Contains(product_type_str2, product_type) {
 				//销售部
 				query := map[string]interface{}{}
+				source := ""
 				if product_type == "企业商机管理" {
 					query["phone"] = user_phone
 					userInfo := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
 					if userInfo != nil && len(*userInfo) > 0 {
 						uId = common.ObjToString((*userInfo)["uid"])
 						userId = common.ObjToString((*userInfo)["userid"])
+						source = common.ObjToString((*userInfo)["source"])
 					} else {
 						log.Println("后台订单--未查询到 ", user_phone)
 						break
@@ -449,6 +452,7 @@ func ordersClue() {
 					userInfo := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
 					if userInfo != nil && len(*userInfo) > 0 {
 						uId = common.ObjToString((*userInfo)["uid"])
+						source = common.ObjToString((*userInfo)["source"])
 					} else {
 						log.Println("后台订单--未查询到 ", query, user_phone)
 						break
@@ -534,12 +538,17 @@ func ordersClue() {
 							seatNumber = common.ObjToString((*saleData)["seat_number"])
 							positionId = common.Int64All((*saleData)["position_id"])
 						}
+						is_assign := 1
+						if IsFreeze(source, pay_money, gconv.String(positionId)) && (isGroup != 1 && isCommerce == 1) {
+							//线索需要冻结
+							is_assign = -3
+						}
 						clueId = TiDb.Insert("dwd_f_crm_clue_info", map[string]interface{}{
 							"userid":               userId,
 							"uid":                  uId,
 							"seatNumber":           seatNumber,
 							"position_id":          positionId,
-							"is_assign":            1,
+							"is_assign":            is_assign,
 							"comeintime":           nowTime,
 							"createtime":           nowTime,
 							"updatetime":           nowTime,
@@ -554,6 +563,7 @@ func ordersClue() {
 							"taskstatus":           0,
 							"company_nature":       isGroup,
 							"company_verification": isCommerce,
+							"FREEZE_TIME":          common.If(is_assign == -3, nowTime, ""),
 						})
 					} else if strings.HasPrefix(saleDep, "03") {
 						log.Println("市场部订单", saleDep)
@@ -585,6 +595,28 @@ func ordersClue() {
 							"BCPCID":      common.GetRandom(32),
 							"operator_id": -1,
 						})
+						if strings.HasPrefix(saleDep, "01") || strings.HasPrefix(saleDep, "05") {
+							if IsFreeze(source, pay_money, gconv.String(positionId)) && (isGroup != 1 && isCommerce == 1) {
+								//新增冻结记录
+								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,
+								})
+								//移交失败发送消息
+								if IsFreeze(source, pay_money, gconv.String(positionId)) {
+									//发送邮件信息
+								}
+								if isGroup != 1 && isCommerce == 1 {
+									//发送邮件信息
+								}
+							}
+
+						}
 					}
 				}
 			}
@@ -613,6 +645,7 @@ func refundAuto() {
 				company_verification = common.IntAll((*clueData)["company_verification"])
 				uid = common.ObjToString((*clueData)["uid"])
 			}
+			isFull := FindUpperLimit(gconv.String(saleId), "positionId")
 			query1 := fmt.Sprintf(`select id from dwd_f_userbase_order_info where (product_type = "企业商机管理" or product_type = "大会员") and vip_endtime > "%s" and order_status = 1 and pay_money > 0 and uid = "%s"`, nowTime, uid)
 			query2 := fmt.Sprintf(`select id from dwd_f_userbase_order_info where (product_type = "企业商机管理" or product_type = "大会员") and refund_status in (0,2) and order_status = 1 and pay_money > 0 and uid = "%s"`, uid)
 			log.Println("query1 ", query1)
@@ -685,7 +718,11 @@ func refundAuto() {
 						if saleId > 0 {
 							saleData := TiDb.FindOne("dwd_f_crm_personnel_management", map[string]interface{}{"position_id": saleId, "resign": 0}, "", "")
 							if saleData != nil && len(*saleData) > 0 {
-								TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_clue_info SET updatetime=?,trailstatus="01",is_task=1,tasktime=?,top_cluetype="532",sub_cluetype="537",taskstatus=0,tasksource="其他-成交客户续约失败",is_transfer=0 WHERE id = ?`, nowTime, nowTime, clueId)
+								if FindUpperLimit(gconv.String(saleId), "positionId") {
+									TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_clue_info SET updatetime=?,trailstatus="01",is_task=0,tasktime=?,top_cluetype="532",sub_cluetype="537",taskstatus=0,tasksource="其他-成交客户续约失败",is_transfer=0 WHERE id = ?,is_assign=-2,FREEZE_TIME=?`, nowTime, nowTime, clueId, nowTime)
+								} else {
+									TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_clue_info SET updatetime=?,trailstatus="01",is_task=1,tasktime=?,top_cluetype="532",sub_cluetype="537",taskstatus=0,tasksource="其他-成交客户续约失败",is_transfer=0 WHERE id = ?`, nowTime, nowTime, clueId)
+								}
 							} else {
 								if company_nature == 0 && company_verification == 1 && cluename != "" {
 									adata := TiDb.Find("dwd_f_crm_clue_info", map[string]interface{}{"cluename": cluename, "is_assign": 1}, "seatNumber,position_id", "", -1, -1)
@@ -697,7 +734,11 @@ func refundAuto() {
 											saleDatas := TiDb.FindOne("dwd_f_crm_personnel_management", map[string]interface{}{"position_id": position_ids, "resign": 0}, "", "")
 											if saleDatas != nil && len(*saleDatas) > 0 {
 												saleId = position_ids
-												TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_clue_info SET updatetime=?,trailstatus="01",position_id=?,seatNumber=?,is_task=1,tasktime=?,top_cluetype="532",sub_cluetype="537",taskstatus=0,tasksource="其他-成交客户续约失败",is_transfer=0 WHERE id = ?`, nowTime, saleId, seatNumber, nowTime, clueId)
+												if isFull {
+													TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_clue_info SET updatetime=?,trailstatus="01",position_id=?,seatNumber=?,is_task=0,tasktime=?,top_cluetype="532",sub_cluetype="537",taskstatus=0,tasksource="其他-成交客户续约失败",is_transfer=0,is_assign=-2,FREEZE_TIME=? WHERE id = ?`, nowTime, saleId, seatNumber, nowTime, clueId, seatNumber)
+												} else {
+													TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_clue_info SET updatetime=?,trailstatus="01",position_id=?,seatNumber=?,is_task=1,tasktime=?,top_cluetype="532",sub_cluetype="537",taskstatus=0,tasksource="其他-成交客户续约失败",is_transfer=0 WHERE id = ?`, nowTime, saleId, seatNumber, nowTime, clueId)
+												}
 												isOks = true
 												break
 											}
@@ -707,7 +748,11 @@ func refundAuto() {
 											if sdata != nil && len(*sdata) > 0 {
 												saleId = common.Int64All((*sdata)[0]["position_id"])
 												seatNumber := common.ObjToString((*sdata)[0]["seat_number"])
-												TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_clue_info SET updatetime=?,trailstatus="01",position_id=?,seatNumber=?,is_task=1,tasktime=?,top_cluetype="532",sub_cluetype="537",taskstatus=0,tasksource="其他-成交客户续约失败",is_transfer=0 WHERE id = ?`, nowTime, saleId, seatNumber, nowTime, clueId)
+												if isFull {
+													TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_clue_info SET updatetime=?,trailstatus="01",position_id=?,seatNumber=?,is_task=0,tasktime=?,top_cluetype="532",sub_cluetype="537",taskstatus=0,tasksource="其他-成交客户续约失败",is_transfer=0,is_assign=-2,FREEZE_TIME=? WHERE id = ?`, nowTime, saleId, seatNumber, nowTime, clueId, seatNumber)
+												} else {
+													TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_clue_info SET updatetime=?,trailstatus="01",position_id=?,seatNumber=?,is_task=1,tasktime=?,top_cluetype="532",sub_cluetype="537",taskstatus=0,tasksource="其他-成交客户续约失败",is_transfer=0 WHERE id = ?`, nowTime, saleId, seatNumber, nowTime, clueId)
+												}
 											}
 										}
 									}
@@ -716,13 +761,19 @@ func refundAuto() {
 									if sdata != nil && len(*sdata) > 0 {
 										saleId = common.Int64All((*sdata)[0]["position_id"])
 										seatNumber := common.ObjToString((*sdata)[0]["seat_number"])
-										TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_clue_info SET updatetime=?,trailstatus="01",position_id=?,seatNumber=?,is_task=1,tasktime=?,top_cluetype="532",sub_cluetype="537",taskstatus=0,tasksource="其他-成交客户续约失败",is_transfer=0 WHERE id = ?`, nowTime, saleId, seatNumber, nowTime, clueId)
+										if isFull {
+											TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_clue_info SET updatetime=?,trailstatus="01",position_id=?,seatNumber=?,is_task=0,tasktime=?,top_cluetype="532",sub_cluetype="537",taskstatus=0,tasksource="其他-成交客户续约失败",is_transfer=0,is_assign=-2,FREEZE_TIME=? WHERE id = ?`, nowTime, saleId, seatNumber, nowTime, clueId, seatNumber)
+										} else {
+											TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_clue_info SET updatetime=?,trailstatus="01",position_id=?,seatNumber=?,is_task=1,tasktime=?,top_cluetype="532",sub_cluetype="537",taskstatus=0,tasksource="其他-成交客户续约失败",is_transfer=0 WHERE id = ?`, nowTime, saleId, seatNumber, nowTime, clueId)
+
+										}
 									}
 								}
 							}
 						} else {
 							TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_crm_clue_info SET updatetime=?,trailstatus="01",top_cluetype="532",sub_cluetype="537",is_transfer=0 WHERE id = ?`, 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),
@@ -764,6 +815,19 @@ func refundAuto() {
 							"operator_id": -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,
+							})
+							TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_csm_customer_info SET is_transfer=1 WHERE clue_id = ?`, clueId)
+						}
 					}
 				}
 			}
@@ -791,3 +855,10 @@ func refundAutoHistory() {
 		}
 	}
 }
+func IsFreeze(source string, pay_money int, positionId string) bool {
+	if source == "0104" && pay_money == 0 && FindUpperLimit(gconv.String(
+		positionId), "positionId") {
+		return true
+	}
+	return false
+}

+ 1 - 0
clueSync/main.go

@@ -160,6 +160,7 @@ func main() {
 			refundAuto() //客成移交销售
 			autoTask()   //超时未跟进加入任务车
 			autoTasks()  //按照下次跟进时间提前一天加入任务车
+			upperLimitAutoExitSea()
 		})
 		g.Start()
 		select {}

この差分においてかなりの量のファイルが変更されているため、一部のファイルを表示していません