Răsfoiți Sursa

优先退款

xuzhiheng 1 an în urmă
părinte
comite
3e3522b498
1 a modificat fișierele cu 104 adăugiri și 103 ștergeri
  1. 104 103
      clueSync/kc.go

+ 104 - 103
clueSync/kc.go

@@ -617,109 +617,6 @@ func refundAuto() {
 			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 uid = "%s"`, uid)
 			log.Println("query1 ", query1)
 			log.Println("query2 ", query2)
-			order1 := TiDb.SelectBySql(query1)
-			if order1 == nil || len(*order1) == 0 {
-				isOk := false
-				query3 := fmt.Sprintf(`select vip_endtime from dwd_f_userbase_order_info where (product_type = "企业商机管理" or product_type = "大会员") and vip_endtime < "%s" and order_status = 1 and uid = "%s"`, nowTime, uid)
-				log.Println("query3 ", query3)
-				order3 := TiDb.SelectBySql(query3)
-				if order3 != nil && len(*order3) > 0 {
-					for _, vv := range *order3 {
-						if isRenewalProtection == 1 {
-							vip_endtime := common.ObjToString(vv["vip_endtime"])
-							vip_endtimes, _ := time.ParseInLocation(date.Date_Full_Layout, vip_endtime, time.Local)
-							if time.Now().Unix()-vip_endtimes.Unix() < 30*86400 {
-								isOk = true
-							}
-						}
-					}
-				}
-				if !isOk {
-					//全到期了
-					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)
-						} 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)
-								if adata != nil && len(*adata) > 0 {
-									isOks := false
-									for _, vv := range *adata {
-										position_ids := common.Int64All(vv["position_id"])
-										seatNumber := common.ObjToString(vv["seatNumber"])
-										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)
-											isOks = true
-											break
-										}
-									}
-									if !isOks {
-										sdata := TiDb.SelectBySql(`SELECT b.name,b.position_id,b.seat_number from dwd_d_crm_department_level_succbi a INNER JOIN dwd_f_crm_personnel_management b on a.position_id = b.position_id where a.bi_pcode = (SELECT bi_pcode from dwd_d_crm_department_level_succbi where position_id = ?) and b.role_id = 3`, saleId)
-										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)
-										}
-									}
-								}
-							} else {
-								sdata := TiDb.SelectBySql(`SELECT b.name,b.position_id,b.seat_number from dwd_d_crm_department_level_succbi a INNER JOIN dwd_f_crm_personnel_management b on a.position_id = b.position_id where a.bi_pcode = (SELECT bi_pcode from dwd_d_crm_department_level_succbi where position_id = ?) and b.role_id = 3`, saleId)
-								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)
-								}
-							}
-						}
-					} 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),
-						"change_type":  "基本信息变更",
-						"old_value":    "成交客户",
-						"change_field": "trailstatus",
-						"new_value":    "商机线索",
-						"createtime":   nowTime,
-						"BCPCID":       common.GetRandom(32),
-						"operator_id":  -1,
-					})
-					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.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
-						"clue_id":      clueId,
-						"position_id":  common.If(kcposition_id > 0, kcposition_id, -1),
-						"change_type":  "客户成功经理",
-						"change_field": "position_id",
-						"old_value":    name,
-						"new_value":    "/",
-						"createtime":   nowTime,
-						"BCPCID":       common.GetRandom(32),
-						"operator_id":  -1,
-					})
-					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)
-				}
-			}
 			order2 := TiDb.SelectBySql(query2)
 			if order2 == nil || len(*order2) == 0 {
 				//全退款了
@@ -765,6 +662,110 @@ func refundAuto() {
 					"operator_id": -1,
 				})
 				TiDb.UpdateOrDeleteBySql(`UPDATE dwd_f_csm_customer_info SET is_transfer=1 WHERE clue_id = ?`, clueId)
+			} else {
+				order1 := TiDb.SelectBySql(query1)
+				if order1 == nil || len(*order1) == 0 {
+					isOk := false
+					query3 := fmt.Sprintf(`select vip_endtime from dwd_f_userbase_order_info where (product_type = "企业商机管理" or product_type = "大会员") and vip_endtime < "%s" and order_status = 1 and uid = "%s"`, nowTime, uid)
+					log.Println("query3 ", query3)
+					order3 := TiDb.SelectBySql(query3)
+					if order3 != nil && len(*order3) > 0 {
+						for _, vv := range *order3 {
+							if isRenewalProtection == 1 {
+								vip_endtime := common.ObjToString(vv["vip_endtime"])
+								vip_endtimes, _ := time.ParseInLocation(date.Date_Full_Layout, vip_endtime, time.Local)
+								if time.Now().Unix()-vip_endtimes.Unix() < 30*86400 {
+									isOk = true
+								}
+							}
+						}
+					}
+					if !isOk {
+						//全到期了
+						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)
+							} 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)
+									if adata != nil && len(*adata) > 0 {
+										isOks := false
+										for _, vv := range *adata {
+											position_ids := common.Int64All(vv["position_id"])
+											seatNumber := common.ObjToString(vv["seatNumber"])
+											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)
+												isOks = true
+												break
+											}
+										}
+										if !isOks {
+											sdata := TiDb.SelectBySql(`SELECT b.name,b.position_id,b.seat_number from dwd_d_crm_department_level_succbi a INNER JOIN dwd_f_crm_personnel_management b on a.position_id = b.position_id where a.bi_pcode = (SELECT bi_pcode from dwd_d_crm_department_level_succbi where position_id = ?) and b.role_id = 3`, saleId)
+											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)
+											}
+										}
+									}
+								} else {
+									sdata := TiDb.SelectBySql(`SELECT b.name,b.position_id,b.seat_number from dwd_d_crm_department_level_succbi a INNER JOIN dwd_f_crm_personnel_management b on a.position_id = b.position_id where a.bi_pcode = (SELECT bi_pcode from dwd_d_crm_department_level_succbi where position_id = ?) and b.role_id = 3`, saleId)
+									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)
+									}
+								}
+							}
+						} 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),
+							"change_type":  "基本信息变更",
+							"old_value":    "成交客户",
+							"change_field": "trailstatus",
+							"new_value":    "商机线索",
+							"createtime":   nowTime,
+							"BCPCID":       common.GetRandom(32),
+							"operator_id":  -1,
+						})
+						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.Insert("dwd_f_crm_clue_change_record", map[string]interface{}{
+							"clue_id":      clueId,
+							"position_id":  common.If(kcposition_id > 0, kcposition_id, -1),
+							"change_type":  "客户成功经理",
+							"change_field": "position_id",
+							"old_value":    name,
+							"new_value":    "/",
+							"createtime":   nowTime,
+							"BCPCID":       common.GetRandom(32),
+							"operator_id":  -1,
+						})
+						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)
+					}
+				}
 			}
 		}
 		return true