Browse Source

是否订阅处理

WH01243 8 months ago
parent
commit
92602f3999

+ 106 - 19
src/jfw/modules/publicapply/src/subscribe/entity/entity.go

@@ -86,58 +86,145 @@ func (this *ParamInfo) SetAreaByOneProvince() (b bool) {
 	}
 	return b
 }
-func (this *ParamInfo) IsSub() (bool, string) {
-	mData := config.Compatible.Select(this.UserId, `{"o_jy":1,"o_member_jy":1,"o_vipjy":1,"i_vip_status":1,"i_member_status":1}`)
+func (this *ParamInfo) IsSub() (bool, string, map[string][]interface{}, map[string][]interface{}) {
+	areaMap := make(map[string][]interface{})
+	districtMap := make(map[string][]interface{})
+	mData := config.Compatible.Select(this.UserId, `{"o_jy":1,"o_member_jy":1,"o_vipjy":1,"i_vip_status":1,"i_member_status":1,"last_trigger_time":1}`)
 	productType := "free"
+	isNull := false
 	memberStatus := gconv.Int64((*mData)["i_member_status"])
 	vipStatus := gconv.Int64((*mData)["i_vip_status"])
+	if memberStatus > 0 {
+		productType = "member"
+	} else if vipStatus > 0 {
+		productType = "vip"
+	}
 	if mData != nil && len(*mData) != 0 {
 		positionType := gconv.Int64(this.Session.Get("positionType"))
 		if positionType == 1 {
 			//企业身份
-			return false, productType
+			return false, productType, areaMap, districtMap
+		}
+		lastTriggerTime := gconv.Int64((*mData)["last_trigger_time"])
+		if time.Now().Unix()-lastTriggerTime < config.Config.FrequentContinuous*24*60*60 {
+			return false, productType, areaMap, districtMap
 		}
 		o_jy, _ := (*mData)["o_jy"].(map[string]interface{})
+		a_key, _ := o_jy["a_key"].([]interface{})
+		if len(a_key) > 0 {
+			return false, productType, areaMap, districtMap
+		}
 		if o_jy["o_area"] != nil {
 			oarea, _ := o_jy["o_area"].(map[string]interface{})
 			if len(oarea) > 0 {
-				return false, productType
+				for s, i := range oarea {
+					areaMap[s] = gconv.Interfaces(i)
+				}
 			}
+			isNull = false
+		} else {
+			isNull = true
 		}
-		a_key, _ := o_jy["a_key"].([]interface{})
-		if len(a_key) > 0 {
-			return false, productType
+		if o_jy["o_district"] != nil {
+			district, _ := o_jy["o_district"].(map[string]interface{})
+			if len(district) > 0 {
+				for s, i := range district {
+					districtMap[s] = gconv.Interfaces(i)
+				}
+			}
 		}
 		if vipStatus > 0 {
-			productType = "vip"
 			o_vipjy, _ := (*mData)["o_vipjy"].(map[string]interface{})
+			a_key, _ = o_vipjy["a_key"].([]interface{})
+			if len(a_key) > 0 {
+				return false, productType, areaMap, districtMap
+			}
 			if o_vipjy["o_area"] != nil {
 				oarea, _ := o_vipjy["o_area"].(map[string]interface{})
 				if len(oarea) > 0 {
-					return false, productType
+					for s, i := range oarea {
+						areaMap[s] = gconv.Interfaces(i)
+					}
 				}
+				isNull = false
+			} else {
+				isNull = true
+				areaMap = make(map[string][]interface{})
 			}
-			a_key, _ = o_vipjy["a_key"].([]interface{})
-			if len(a_key) > 0 {
-				return false, productType
+			if o_vipjy["o_district"] != nil {
+				district, _ := o_vipjy["o_district"].(map[string]interface{})
+				if len(district) > 0 {
+					for s, i := range district {
+						districtMap[s] = gconv.Interfaces(i)
+					}
+				} else {
+					districtMap = make(map[string][]interface{})
+				}
+			} else {
+				districtMap = make(map[string][]interface{})
 			}
 		}
 		if memberStatus > 0 {
-			productType = "member"
 			o_member_jy, _ := (*mData)["o_member_jy"].(map[string]interface{})
+			a_key, _ = o_member_jy["a_key"].([]interface{})
+			if len(a_key) > 0 {
+				return false, productType, areaMap, districtMap
+			}
 			if o_member_jy["o_area"] != nil {
 				oarea, _ := o_member_jy["o_area"].(map[string]interface{})
 				if len(oarea) > 0 {
-					return false, productType
+					for s, i := range oarea {
+						areaMap[s] = gconv.Interfaces(i)
+					}
+				} else {
+					areaMap = make(map[string][]interface{})
 				}
+				isNull = false
+			} else {
+				isNull = true
+				areaMap = make(map[string][]interface{})
 			}
-			a_key, _ = o_member_jy["a_key"].([]interface{})
-			if len(a_key) > 0 {
-				return false, productType
+			if o_member_jy["o_district"] != nil {
+				district, _ := o_member_jy["o_district"].(map[string]interface{})
+				if len(district) > 0 {
+					for s, i := range district {
+						districtMap[s] = gconv.Interfaces(i)
+					}
+				} else {
+					districtMap = make(map[string][]interface{})
+				}
+			} else {
+				districtMap = make(map[string][]interface{})
+			}
+		}
+
+	}
+	if isNull {
+		area, city, district := HistorySearch(this.UserId)
+		if area != "" {
+			if city != "" {
+				areaMap[area] = []interface{}{
+					city,
+				}
+			} else {
+				areaMap[area] = []interface{}{}
+			}
+		}
+		if productType != "free" && area != "" && district != "" {
+			districtMap[city] = []interface{}{
+				district,
 			}
 		}
 	}
-	return true, productType
+	config.Compatible.Update(this.UserId, map[string]interface{}{
+		"$set": map[string]interface{}{"last_trigger_time": time.Now().Unix()},
+	})
+	if len(areaMap) == 0 && areaMap != nil && len(districtMap) == 0 && districtMap != nil {
+		return true, productType, nil, nil
+	} else {
+		return true, productType, areaMap, districtMap
+	}
+
 }
 
 type RuleStruct struct {
@@ -145,7 +232,7 @@ type RuleStruct struct {
 }
 
 // 浏览记录查询
-func (this *ParamInfo) HistorySearch(userId string) (string, string, string) {
+func HistorySearch(userId string) (string, string, string) {
 	ass := []RuleStruct{}
 	rows, err1 := db.ClickhouseConn.Query(context.TODO(), "select  browse from  sub_recommend_rule where  userid=?", userId)
 	if err1 != nil {

+ 2 - 5
src/jfw/modules/publicapply/src/subscribe/service/service.go

@@ -30,16 +30,13 @@ func (this *ServiceStruct) IsSub() {
 			return Result{Data: nil, Error_msg: Error_msg_1005}
 		}
 		newFN := entity.NewParamInfo(userId, this.Session())
-
-		isSubscribe, productType := newFN.IsSub()
-		area, city, district := newFN.HistorySearch(userId)
+		isSubscribe, productType, area, district := newFN.IsSub()
 		returnData := map[string]interface{}{
 			"frequentContinuous": config.Config.FrequentContinuous,
 			"screenNumb":         config.Config.ScreenNumb,
 			"isSubscribe":        isSubscribe,
 			"area":               area,
-			"city":               qu.If(productType == "free", "", city),
-			"district":           qu.If(productType == "free", "", district),
+			"district":           district,
 			"positionType":       gconv.Int64(this.GetSession("positionType")),
 			"productType":        productType,
 			"stayTime":           config.Config.StayTime,