Parcourir la source

Merge branch 'dev4.6.2.1' of http://192.168.3.207:8080/qmx/jy into dev4.6.2.1

yangfeng il y a 3 ans
Parent
commit
82f38cdda3

+ 1 - 0
src/jfw/front/login.go

@@ -120,6 +120,7 @@ func (l *Login) Login() error {
 							"l_modifydate": time.Now().Unix(),
 						},
 						"s_regsource": "pc",
+						"s_platform":  "pc",
 					}
 					source := l.GetString("source") //用户手机号用户记录百度统计
 					if ck, err := l.GetCookie("source"); err == nil && ck.Value != "" {

+ 4 - 1
src/jfw/modules/app/src/app/front/login.go

@@ -209,6 +209,7 @@ func (l *Login) Login() error {
 							"i_newfree":    1, //新免费用户=>新订阅设置页面 20211122
 							"l_modifydate": time.Now().Unix(),
 						},
+						"s_platform": "app",
 					}
 					data["s_regsource"] = isAndroidOrIOS(l.Header("User-Agent"))
 					_id := mongodb.Save("user", data)
@@ -467,6 +468,7 @@ func (l *Login) Register() error {
 						"l_modifydate": time.Now().Unix(),
 					}
 					data["s_regsource"] = isAndroidOrIOS(l.Header("User-Agent"))
+					data["s_platform"] = "app"
 					saveid = mongodb.Save("user", data)
 					saveSuccess = saveid != ""
 				}
@@ -610,8 +612,9 @@ func (l *Login) WxLogin() {
 					"i_newfree":    1, //新免费用户=>新订阅设置页面 20211122
 					"l_modifydate": time.Now().Unix(),
 				},
+				"s_platform": "app", //用户注册平台 app 微信 pc
 			}
-			newUser["s_regsource"] = isAndroidOrIOS(l.Header("User-Agent"))
+			newUser["s_regsource"] = isAndroidOrIOS(l.Header("User-Agent")) //用户注册终端 ios 安卓 pc
 			if _id := mongodb.Save("user", newUser); _id != "" {
 				returnSign = afterLogin(newUser, l.Session(), rid, oid, phoneType, channel, deviceId, 2, true, l.ResponseWriter)
 				if disWord != "" {

+ 26 - 9
src/jfw/modules/app/src/web/templates/areaPack/page_set_area.html

@@ -212,7 +212,7 @@
                 var restore = this.restoreState()
 
                 if (restore) {
-                    
+                    this.initPageInfo()
                 } else {
                     if (type === 'new') {
                         this.setAreaAllNotSelected()
@@ -222,6 +222,17 @@
                 }
             },
             methods: {
+                initPageInfo: function () {
+                    var area = this.selectedArea
+                    this.setComponentState(area)
+                },
+                setAreaSelected: function (area) {
+                    this.$set(this, 'selectedArea', area)
+                },
+                setComponentState: function (area) {
+                    vNode.data.initCityMap = area
+                    vueComponent.setCitySelected(area)
+                },
                 setAreaAllNotSelected: function () {
                     vueComponent.setCitySelected()
                     vueComponent.provinceListMap['#'][0].selectedState = ''
@@ -239,7 +250,14 @@
                                     if (res.data.area === null || res.data.area === undefined) {
                                         _this.setAreaAllNotSelected()
                                     } else {
-                                        Object.assign(_this.userSubInfo, res.data)
+                                        if (res.data.area) {
+                                            // 赋值默认已选
+                                            _this.setAreaSelected(res.data.area)
+                                        }
+                                        for (var key in res.data) {
+                                            _this.$set(_this.userSubInfo, key, res.data[key])
+                                        }
+                                        _this.initPageInfo()
                                     }
                                 }
                             } else {
@@ -270,9 +288,6 @@
                         }
                     })
                 },
-                setAreaSelected: function (area) {
-                    this.$set(this, 'selectedArea', area)
-                },
                 confirmed: function (area) {
                     this.setAreaSelected(area)
                     if (this.moreThanSubCount) {
@@ -301,16 +316,18 @@
                     if ($data) {
                         $data = JSON.parse($data)
 
-                        for (var key in $data) {
-                            Object.assign(this.$data[key], $data[key])
-                        }
+                        this.selectedArea = $data.selectedArea
+                        Object.assign(this.userSubInfo, $data.userSubInfo)
 
                         sessionStorage.removeItem(this.sessKey)
                     }
                     return !!$data
                 },
                 savePageState: function () {
-                    var data = JSON.stringify(this.$data)
+                    var data = {
+                        selectedArea: this.selectedArea,
+                        userSubInfo: this.userSubInfo
+                    }
                     sessionStorage.setItem(this.sessKey, JSON.stringify(data))
                 },
             }

+ 1 - 1
src/jfw/modules/common/src/qfw/util/jy/bigVipPower.go

@@ -53,7 +53,7 @@ const (
 	PowerCacheEntPortKey   = "free_power_entport_%s"
 	PowerCacheBuyerPortKey = "free_power_buyerport_%s"
 	PowerCacheFileKey      = "free_power_File_%s"
-	UserUpdateAreaKey      = "free_area_num_%s"
+	UserUpdateAreaKey      = "free_area_num_%s_%s"
 	BaseAreaNum            = 1
 )
 

+ 15 - 5
src/jfw/modules/publicapply/src/subscribe/entity/entity.go

@@ -9,6 +9,7 @@ import (
 	"qfw/util/elastic"
 	"qfw/util/jy"
 	"qfw/util/redis"
+	"time"
 
 	// "reflect"
 	"strconv"
@@ -160,16 +161,25 @@ func (pi *ParamInfo) GetSubMsg() UserSubMsg {
 			res.Area, _ = o_jy["o_area"].(map[string]interface{})
 		}
 		res.Infotype, _ = o_jy["a_infotype"].([]interface{})
-		//地区调整可用次数
-		pnum := redis.GetInt(jy.PowerCacheDb, fmt.Sprintf(jy.UserUpdateAreaKey, pi.UserId))
-		res.Areanum = qutil.If(pnum > 0, jy.BaseAreaNum-pnum, jy.BaseAreaNum).(int)
-		//购买省份订阅包
+
+		//免费用户未购买省份订阅包 按年算
+		year := fmt.Sprint(time.Now().Year())
+		//免费用户未购买省份订阅包 已调整地区次数(年)
+		fpnum := redis.GetInt(jy.PowerCacheDb, fmt.Sprintf(jy.UserUpdateAreaKey, pi.UserId, year))
+		//免费用户未购买省份订阅包 地区调整可用次数(默认值)
+		res.Areanum = qutil.If(fpnum > 0, jy.BaseAreaNum-fpnum, jy.BaseAreaNum).(int)
+		//免费用户已购买省份订阅包
 		if o_jy["i_ppstatus"] != nil && qutil.IntAll(o_jy["i_ppstatus"]) > 0 {
 			o_buyset_p, _ := o_jy["o_buyset_p"].(map[string]interface{})
 			res.Provincenum = qutil.IntAll(o_buyset_p["areacount"]) //-1 全国无限制
 			res.Areanum = res.Provincenum
 			if res.Provincenum > 0 {
-				res.Areanum = res.Provincenum + jy.BaseAreaNum - pnum
+				//按月算
+				ym := fmt.Sprint(time.Now().Year()) + "-" + fmt.Sprint(time.Now().Month())
+				//已调整地区次数(月)
+				ppnum := redis.GetInt(jy.PowerCacheDb, fmt.Sprintf(jy.UserUpdateAreaKey, pi.UserId, ym))
+				//可调整次数(月)
+				res.Areanum = res.Provincenum + jy.BaseAreaNum - fpnum - ppnum
 			}
 			res.Ppstarttime = qutil.Int64All(o_jy["l_areaStart_p"])
 			res.Ppendtime = qutil.Int64All(o_jy["l_areaEnd_p"])

+ 66 - 19
src/jfw/modules/publicapply/src/subscribePush/entity/setting.go

@@ -8,6 +8,8 @@ import (
 	qutil "qfw/util"
 	"qfw/util/jy"
 	"qfw/util/redis"
+	"sort"
+	"strings"
 	"time"
 	"util"
 )
@@ -39,25 +41,47 @@ func freeSet(area map[string]interface{}, industry []string, userId string) *Fun
 	if len(area) == 0 {
 		return &FuncResult{false, errors.New("地区参数异常"), nil}
 	}
-
-	//地区调整已用次数
-	pnum := redis.GetInt(jy.PowerCacheDb, fmt.Sprintf(jy.UserUpdateAreaKey, userId))
-	log.Println(len(area), "pnum:", pnum)
-	//是否购买省级订阅包   省份订阅包购买的省份数量-1:全国 无限制调整;isfirst:是否第一次设置地区
-	isfirst, ppb, areacount := IsCanSet(userId)
-	//第一次设置地区不扣次数
-	if !isfirst {
-		//
-		if len(area) > areacount+jy.BaseAreaNum {
+	//isfirst:是否第一次设置地区;ppb:是否购买省级订阅包; areacount:省份订阅包购买的省份数量-1:全国 无限制调整
+	isfirst, ppb, areacount := IsCanSet(userId, area)
+	//购买省份订阅包 已调整地区次数
+	ppnum := 0
+	//免费用户购买省份订阅包 按月算
+	ym := fmt.Sprint(time.Now().Year()) + "-" + fmt.Sprint(time.Now().Month())
+	if ppb {
+		ppnum = redis.GetInt(jy.PowerCacheDb, fmt.Sprintf(jy.UserUpdateAreaKey, userId, ym))
+	}
+	//免费用户未购买省份订阅包 按年算
+	year := fmt.Sprint(time.Now().Year())
+	//免费用户 已调整地区次数
+	fpnum := redis.GetInt(jy.PowerCacheDb, fmt.Sprintf(jy.UserUpdateAreaKey, userId, year))
+	// log.Println(len(area), "pnum:", pnum)
+	//第一次设置地区 || 购买全国  不扣次数
+	var issetredis = areacount > -1 && !isfirst
+	if issetredis {
+		//地区范围判断
+		if areacount+jy.BaseAreaNum < len(area) {
 			return &FuncResult{false, errors.New("超出地区可设置范围"), nil}
 		}
-		//
-		if areacount > -1 && areacount+jy.BaseAreaNum <= pnum {
+		//地区调整次数判断
+		if areacount+jy.BaseAreaNum <= ppnum+fpnum {
 			return &FuncResult{false, errors.New(fmt.Sprintf("订阅地区调整次数(%d)已用完", areacount+jy.BaseAreaNum)), nil}
 		}
 	}
 	if !FreeSubChange(userId, &area, industry, ppb, isfirst) {
 		return &FuncResult{false, errors.New("保存修改出错"), nil}
+	} else if issetredis { //更新调整次数 非全国(第一次 不消耗次数)
+		//清楚缓存
+		jy.ClearBigVipUserPower(userId)
+		//优先使用省份订阅包次数
+		// log.Println(areacount, "---", ppnum)
+		// log.Println(jy.BaseAreaNum, "---", fpnum)
+		if ppb && areacount > ppnum {
+			redis.Put(jy.PowerCacheDb, fmt.Sprintf(jy.UserUpdateAreaKey, userId, ym), ppnum+1, 31*24*60*60)
+		} else if jy.BaseAreaNum > fpnum {
+			redis.Put(jy.PowerCacheDb, fmt.Sprintf(jy.UserUpdateAreaKey, userId, year), fpnum+1, 365*24*60*60)
+		} else {
+			log.Println(fmt.Sprintf("免费用户设置地区 扣除次数异常  userId:%s", userId))
+		}
 	}
 	SetLog(userId, "o_jy")
 	return &FuncResult{true, nil, map[string]interface{}{
@@ -80,29 +104,52 @@ func FreeSubChange(userId string, area *map[string]interface{}, industry []strin
 	updateOk := db.Mgo.UpdateById("user", userId, setMap)
 	if !updateOk {
 		return false
-	} else if !isfirst && redis.GetInt(jy.PowerCacheDb, fmt.Sprintf(jy.UserUpdateAreaKey, userId)) > -1 { //更新调整次数 非全国(第一次 不消耗次数)
-		//清楚缓存
-		jy.ClearBigVipUserPower(userId)
-		redis.Incr(jy.PowerCacheDb, fmt.Sprintf(jy.UserUpdateAreaKey, userId))
 	}
 	return true
 }
 
 //是否可进行地区调整
-func IsCanSet(userId string) (bool, bool, int) {
+func IsCanSet(userId string, areamap map[string]interface{}) (bool, bool, int) {
 	areacount := 0
+	myarea := []string{}
+	setarea := []string{}
+	myareamap := map[string]interface{}{}
 	mData, ok := db.Mgo.FindById("user", userId, `{"o_jy":1}`)
 	if !ok || len(*mData) == 0 || mData == nil {
 		return false, false, areacount
 	}
 	o_jy, _ := (*mData)["o_jy"].(map[string]interface{})
+	//地区是否完全一致
+	if o_jy["o_area"] != nil {
+		myareamap = *qutil.ObjToMap(o_jy["o_area"])
+
+	}
 	//是否购买省份订阅包
 	if o_jy["i_ppstatus"] != nil && qutil.IntAll(o_jy["i_ppstatus"]) > 0 {
 		o_buyset_p, _ := o_jy["o_buyset_p"].(map[string]interface{})
 		areacount = qutil.IntAll(o_buyset_p["areacount"]) //-1 全国无限制
+		myareamap = *qutil.ObjToMap(o_jy["o_area_p"])
+	}
+	for oak, _ := range myareamap {
+		myarea = append(myarea, oak)
+	}
+	for sak, _ := range areamap {
+		setarea = append(setarea, sak)
 	}
-	log.Println(jy.BaseAreaNum, "---areacount:", areacount)
-	return o_jy["o_area"] == nil, o_jy["i_ppstatus"] != nil && qutil.IntAll(o_jy["i_ppstatus"]) > 0, areacount
+	if areaSort(setarea) == areaSort(myarea) {
+		log.Println(setarea, "-地区选择前后一致-", myarea)
+		return true, qutil.IntAll(o_jy["i_ppstatus"]) > 0, areacount
+	}
+	// log.Println(areaSort(setarea) == areaSort(myarea), "---areacount:", areacount)
+	return o_jy["o_area"] == nil, qutil.IntAll(o_jy["i_ppstatus"]) > 0, areacount
+}
+
+//
+func areaSort(area []string) string {
+	sort.Slice(area, func(i, j int) bool {
+		return area[i] < area[j]
+	})
+	return strings.Join(area, ",")
 }
 
 //

+ 1 - 0
src/jfw/modules/subscribepay/src/entity/areaPack.go

@@ -195,6 +195,7 @@ func (this *AreaPackFilter) Power(userid string, startime, endtime time.Time) bo
 		"o_jy.o_buyset_p":  map[string]interface{}{"areacount": this.Num},
 		"o_jy.l_areaEnd_p": endtime.Unix(),
 		"o_jy.i_ppstatus":  1,
+		"o_jy.i_newfree":   1, //新免费用户=>新订阅设置页面 20211122
 	}
 	if this.OrderType == 1 || this.OrderType == 2 {
 		setMap["o_jy.l_areaStart_p"] = startime.Unix()

+ 26 - 9
src/web/templates/areaPack/wx/page_set_area.html

@@ -212,7 +212,7 @@
                 var restore = this.restoreState()
 
                 if (restore) {
-                    
+                    this.initPageInfo()
                 } else {
                     if (type === 'new') {
                         this.setAreaAllNotSelected()
@@ -222,6 +222,17 @@
                 }
             },
             methods: {
+                initPageInfo: function () {
+                    var area = this.selectedArea
+                    this.setComponentState(area)
+                },
+                setAreaSelected: function (area) {
+                    this.$set(this, 'selectedArea', area)
+                },
+                setComponentState: function (area) {
+                    vNode.data.initCityMap = area
+                    vueComponent.setCitySelected(area)
+                },
                 setAreaAllNotSelected: function () {
                     vueComponent.setCitySelected()
                     vueComponent.provinceListMap['#'][0].selectedState = ''
@@ -239,7 +250,14 @@
                                     if (res.data.area === null || res.data.area === undefined) {
                                         _this.setAreaAllNotSelected()
                                     } else {
-                                        Object.assign(_this.userSubInfo, res.data)
+                                        if (res.data.area) {
+                                            // 赋值默认已选
+                                            _this.setAreaSelected(res.data.area)
+                                        }
+                                        for (var key in res.data) {
+                                            _this.$set(_this.userSubInfo, key, res.data[key])
+                                        }
+                                        _this.initPageInfo()
                                     }
                                 }
                             } else {
@@ -270,9 +288,6 @@
                         }
                     })
                 },
-                setAreaSelected: function (area) {
-                    this.$set(this, 'selectedArea', area)
-                },
                 confirmed: function (area) {
                     this.setAreaSelected(area)
                     if (this.moreThanSubCount) {
@@ -301,16 +316,18 @@
                     if ($data) {
                         $data = JSON.parse($data)
 
-                        for (var key in $data) {
-                            Object.assign(this.$data[key], $data[key])
-                        }
+                        this.selectedArea = $data.selectedArea
+                        Object.assign(this.userSubInfo, $data.userSubInfo)
 
                         sessionStorage.removeItem(this.sessKey)
                     }
                     return !!$data
                 },
                 savePageState: function () {
-                    var data = JSON.stringify(this.$data)
+                    var data = {
+                        selectedArea: this.selectedArea,
+                        userSubInfo: this.userSubInfo
+                    }
                     sessionStorage.setItem(this.sessKey, JSON.stringify(data))
                 },
             }