Browse Source

Merge branch 'dev_v1.0.21_wh' of BaseService/biService into feature/v1.0.21

王浩 1 year ago
parent
commit
6ac8d701e4
1 changed files with 118 additions and 78 deletions
  1. 118 78
      vipTask/entity/timetask.go

+ 118 - 78
vipTask/entity/timetask.go

@@ -5,6 +5,7 @@ import (
 	"app.yhyue.com/moapp/jybase/date"
 	"app.yhyue.com/moapp/jybase/date"
 	"app.yhyue.com/moapp/jybase/mongodb"
 	"app.yhyue.com/moapp/jybase/mongodb"
 	"bp.jydev.jianyu360.cn/BaseService/biService/vipTask/config"
 	"bp.jydev.jianyu360.cn/BaseService/biService/vipTask/config"
+	"fmt"
 	"github.com/gogf/gf/v2/util/gconv"
 	"github.com/gogf/gf/v2/util/gconv"
 	"github.com/zeromicro/go-zero/core/logx"
 	"github.com/zeromicro/go-zero/core/logx"
 	"time"
 	"time"
@@ -62,7 +63,7 @@ func PersonExpireHandle(allocation *config.ExpireConfig, sourceId int64) {
 		"s_company":       1,
 		"s_company":       1,
 	}).Iter()
 	}).Iter()
 	for m := make(map[string]interface{}); it.Next(&m); {
 	for m := make(map[string]interface{}); it.Next(&m); {
-		logx.Info("个人数据处理", allocation, m)
+		//logx.Info("个人数据处理", allocation, m)
 		userId := mongodb.BsonIdToSId(m["_id"])
 		userId := mongodb.BsonIdToSId(m["_id"])
 		/*endTime := gconv.Int64(m["l_vip_endtime"])
 		/*endTime := gconv.Int64(m["l_vip_endtime"])
 		startTime := gconv.Int64(m["l_vip_starttime"])*/
 		startTime := gconv.Int64(m["l_vip_starttime"])*/
@@ -105,87 +106,88 @@ func PersonExpireHandle(allocation *config.ExpireConfig, sourceId int64) {
 }
 }
 func EntExpireHandle(allocation *config.ExpireConfig, sourceId int64) {
 func EntExpireHandle(allocation *config.ExpireConfig, sourceId int64) {
 	//按时间查询数据
 	//按时间查询数据
-	endTime := GetFutureDateTime(allocation.EndDays)
-	startTime := GetFutureDateTime(allocation.StartDays)
-	sess := config.UserMgo.GetMgoConn()
-	defer config.UserMgo.DestoryMongoConn(sess)
-	it := *sess.DB("qfw").C("ent_user").Pipe(
-		[]map[string]interface{}{
-			{
-				"$match": map[string]interface{}{
-					"l_vip_endtime": map[string]interface{}{
-						"$gte": startTime,
-						"$lte": endTime,
-					},
-					"i_vip_status": map[string]interface{}{
-						"$gt": 0,
-					},
-				},
-			},
-			{
-				"$group": map[string]interface{}{
-					"_id": "$i_entid",
-				},
-			},
-		},
-	).Iter()
-	for m := make(map[string]interface{}); it.Next(&m); {
-		logx.Info("企业数据处理", allocation, m)
-		userId := ""
-		endTime := gconv.Int64(m["l_vip_endtime"])
-		startTime := gconv.Int64(m["l_vip_starttime"])
-		nickname := ""
-		if TimeHandle(startTime, endTime, allocation.CycleDays) {
-			//周期符合条件
-			//查看新增还是修改
-			//先查询企业信息
-			endId := gconv.Int64(m["_id"])
-			entMap := config.JianYu.FindOne("entniche_info", map[string]interface{}{
-				"id": endId,
-			}, "name,phone", "")
-			if entMap == nil {
-				logx.Info(endId, ":企业查询不到")
+	endTime := GetFutureDateTimeStr(allocation.EndDays)
+	startTime := GetFutureDateTimeStr(allocation.StartDays)
+	config.JianYu.SelectByBath(1, func(l *[]map[string]interface{}) bool {
+		go func(m map[string]interface{}) {
+			//logx.Info("企业数据处理", allocation, m)
+			//企业开始结束时间查询
+			endId := gconv.Int64(m["ent_id"])
+			if endId == 86268 {
+				logx.Info(1111)
 			}
 			}
-			company := gconv.String((*entMap)["name"])
-			phone := gconv.String((*entMap)["phone"])
-			//用户信息查询
-			userData, ok := config.UserMgo.Find("user", map[string]interface{}{
-				"i_appid": 2,
-				"$or": []map[string]interface{}{
-					{"s_phone": phone},
-					{"s_m_phone": phone}},
-			}, `{"s_phone":-1}`, `{"_id":1,"s_nickname":1,"s_jyname":1}`, false, -1, -1)
-			if ok && userData != nil && len(*userData) > 0 {
-				nickname = gconv.String((*userData)[0]["s_nickname"])
-				if nickname == "" {
-					nickname = gconv.String((*userData)[0]["s_jyname"])
-				}
-				userId = gconv.String(mongodb.BsonIdToSId((*userData)[0]["_id"]))
+			orderList := config.JianYu.SelectBySql("select start_time,end_time  from  entniche_wait_empower where  ent_id=? ORDER BY  end_time desc", endId)
+			if (*orderList) == nil || len(*orderList) == 0 {
+				return
 			}
 			}
-			if config.Subjectdb.Count("clue_info", map[string]interface{}{
-				"userId": userId,
-			}) > 0 {
-				//修改
-				config.Subjectdb.Update("clue_info", map[string]interface{}{
-					"userId": userId,
-				}, map[string]interface{}{
-					"sourceId":   sourceId,
-					"updatetime": time.Now().Format(date.Date_Full_Layout),
-				})
+			endTime := int64(0)
+			startTime := int64(0)
+			if len(*orderList) == 1 {
+				time1, _ := time.Parse("2006-01-02 15:04:05", gconv.String((*orderList)[0]["start_time"]))
+				time2, _ := time.Parse("2006-01-02 15:04:05", gconv.String((*orderList)[0]["end_time"]))
+				startTime = time1.Unix()
+				endTime = time2.Unix()
 			} else {
 			} else {
-				//新增
-				config.Subjectdb.Insert("clue_info", map[string]interface{}{
-					"sourceId":    sourceId,
-					"updatetime":  time.Now().Format(date.Date_Full_Layout),
-					"phone":       phone,
-					"name":        nickname,
-					"companyName": company,
-					"createtime":  time.Now().Format(date.Date_Full_Layout),
-					"userId":      userId,
-				})
+				startTime, endTime = CalculateSuperOrderPeriod(orderList)
 			}
 			}
-		}
-	}
+			userId := ""
+			nickname := ""
+			logx.Info("企业数据处理", allocation, m, time.Unix(startTime, 0), time.Unix(endTime, 0))
+			if TimeHandle(startTime, endTime, allocation.CycleDays) {
+				//周期符合条件
+				//查看新增还是修改
+				//先查询企业信息
+				entMap := config.JianYu.FindOne("entniche_info", map[string]interface{}{
+					"id": endId,
+				}, "name,phone", "")
+				if entMap == nil {
+					logx.Info(endId, ":企业查询不到")
+				}
+				company := gconv.String((*entMap)["name"])
+				phone := gconv.String((*entMap)["phone"])
+				//用户信息查询
+				userData, ok := config.UserMgo.Find("user", map[string]interface{}{
+					"i_appid": 2,
+					"$or": []map[string]interface{}{
+						{"s_phone": phone},
+						{"s_m_phone": phone}},
+				}, `{"s_phone":-1}`, `{"_id":1,"s_nickname":1,"s_jyname":1}`, false, -1, -1)
+				if ok && userData != nil && len(*userData) > 0 {
+					nickname = gconv.String((*userData)[0]["s_nickname"])
+					if nickname == "" {
+						nickname = gconv.String((*userData)[0]["s_jyname"])
+					}
+					userId = gconv.String(mongodb.BsonIdToSId((*userData)[0]["_id"]))
+				}
+				if config.Subjectdb.Count("clue_info", map[string]interface{}{
+					"userId": userId,
+				}) > 0 {
+					//修改
+					config.Subjectdb.Update("clue_info", map[string]interface{}{
+						"userId": userId,
+					}, map[string]interface{}{
+						"sourceId":    sourceId,
+						"name":        nickname,
+						"companyName": company,
+						"updatetime":  time.Now().Format(date.Date_Full_Layout),
+					})
+				} else {
+					//新增
+					config.Subjectdb.Insert("clue_info", map[string]interface{}{
+						"sourceId":    sourceId,
+						"updatetime":  time.Now().Format(date.Date_Full_Layout),
+						"phone":       phone,
+						"name":        nickname,
+						"companyName": company,
+						"createtime":  time.Now().Format(date.Date_Full_Layout),
+						"userId":      userId,
+					})
+				}
+			}
+		}((*l)[0])
+		return true
+	}, ` select  * from  ( select  ent_id,MAX(end_time)   end_time from   entniche_wait_empower where product_type="VIP订阅"  GROUP BY   ent_id ) a    where  a.end_time<=? and  a.end_time>=?`, endTime, startTime)
+	fmt.Println(` select  * from  ( select  ent_id,MAX(end_time)   end_time from   entniche_wait_empower GROUP BY   ent_id ) a    where    a.end_time<=? and  a.end_time>=?`, endTime, startTime)
 }
 }
 
 
 // 获取几天以后的时间
 // 获取几天以后的时间
@@ -199,6 +201,17 @@ func GetFutureDateTime(days int64) int64 {
 	return future.Unix()
 	return future.Unix()
 }
 }
 
 
+// 获取几天以后的时间
+func GetFutureDateTimeStr(days int64) string {
+	// 获取当前时间
+	now := time.Now()
+	// 计算未来的时间
+	future := now.AddDate(0, 0, gconv.Int(days))
+	// 设置时间为23点59分59秒
+	future = time.Date(future.Year(), future.Month(), future.Day(), 23, 59, 59, 0, future.Location())
+	return future.Format("2006-01-02 15:04:05")
+}
+
 // 时间处理
 // 时间处理
 func TimeHandle(startTime, endTime, cycleDays int64) bool {
 func TimeHandle(startTime, endTime, cycleDays int64) bool {
 	if endTime-startTime > cycleDays*24*60*60 {
 	if endTime-startTime > cycleDays*24*60*60 {
@@ -206,3 +219,30 @@ func TimeHandle(startTime, endTime, cycleDays int64) bool {
 	}
 	}
 	return false
 	return false
 }
 }
+
+type Order struct {
+	StartDate time.Time
+	EndDate   time.Time
+}
+
+// 时间对比
+func CalculateSuperOrderPeriod(orders *[]map[string]interface{}) (int64, int64) {
+	startDate, _ := time.Parse("2006-01-02 15:04:05", gconv.String((*orders)[0]["start_time"]))
+	endDate, _ := time.Parse("2006-01-02 15:04:05", gconv.String((*orders)[0]["end_time"]))
+	for i, order := range *orders {
+		if i == 0 {
+			continue
+		}
+		time1, _ := time.Parse("2006-01-02 15:04:05", gconv.String(order["start_time"]))
+		time2, _ := time.Parse("2006-01-02 15:04:05", gconv.String(order["end_time"]))
+		//先查看有没有交集
+		if startDate.Unix() <= time2.Unix() || (startDate.Unix() > time2.Unix() && startDate.Unix()-time2.Unix() < 24*60*60) {
+			if startDate.Unix() >= time1.Unix() {
+				startDate = time1
+			}
+		} else {
+			break
+		}
+	}
+	return startDate.Unix(), endDate.Unix()
+}