|
@@ -1,596 +1,587 @@
|
|
|
package entity
|
|
|
|
|
|
import (
|
|
|
- qutil "app.yhyue.com/moapp/jybase/common"
|
|
|
- "app.yhyue.com/moapp/jybase/go-xweb/httpsession"
|
|
|
- "app.yhyue.com/moapp/jybase/redis"
|
|
|
- "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
|
|
|
- "errors"
|
|
|
- "fmt"
|
|
|
- "jy/src/jfw/modules/publicapply/src/config"
|
|
|
- "jy/src/jfw/modules/publicapply/src/db"
|
|
|
- "jy/src/jfw/modules/publicapply/src/util"
|
|
|
- "log"
|
|
|
- "sort"
|
|
|
- "strings"
|
|
|
- "time"
|
|
|
+ qutil "app.yhyue.com/moapp/jybase/common"
|
|
|
+ "app.yhyue.com/moapp/jybase/go-xweb/httpsession"
|
|
|
+ "app.yhyue.com/moapp/jybase/redis"
|
|
|
+ "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
|
|
|
+ "errors"
|
|
|
+ "fmt"
|
|
|
+ "jy/src/jfw/modules/publicapply/src/config"
|
|
|
+ "jy/src/jfw/modules/publicapply/src/db"
|
|
|
+ "jy/src/jfw/modules/publicapply/src/util"
|
|
|
+ "log"
|
|
|
+ "sort"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
)
|
|
|
|
|
|
//订阅设置设置修改
|
|
|
type SubscribeSet struct {
|
|
|
- Area map[string]interface{} //地区
|
|
|
- Industry []string //行业
|
|
|
- UserId string //用户id
|
|
|
- Type string //类型
|
|
|
- EntId int
|
|
|
- EntUserId int
|
|
|
- Session *httpsession.Session
|
|
|
+ Area map[string]interface{} //地区
|
|
|
+ Industry []string //行业
|
|
|
+ UserId string //用户id
|
|
|
+ Type string //类型
|
|
|
+ EntId int
|
|
|
+ EntUserId int
|
|
|
+ Session *httpsession.Session
|
|
|
}
|
|
|
|
|
|
func (this *SubscribeSet) SetAreaAndIndustry() *FuncResult {
|
|
|
- area := this.Area
|
|
|
- industry := this.Industry
|
|
|
- userId := this.UserId
|
|
|
- typ := this.Type
|
|
|
- if typ == "m" {
|
|
|
- return memberSet(area, industry, userId, this.Session)
|
|
|
- } else if typ == "v" {
|
|
|
- return vipSet(area, industry, userId, this.Session)
|
|
|
- } else {
|
|
|
- return freeSet(area, industry, userId, this.Session)
|
|
|
- }
|
|
|
+ area := this.Area
|
|
|
+ industry := this.Industry
|
|
|
+ userId := this.UserId
|
|
|
+ typ := this.Type
|
|
|
+ if typ == "m" {
|
|
|
+ return memberSet(area, industry, userId, this.Session)
|
|
|
+ } else if typ == "v" {
|
|
|
+ return vipSet(area, industry, userId, this.Session)
|
|
|
+ } else {
|
|
|
+ return freeSet(area, industry, userId, this.Session)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//
|
|
|
func freeSet(area map[string]interface{}, industry []string, userId string, session *httpsession.Session) *FuncResult {
|
|
|
- //isfirst:是否第一次设置地区;ppb:是否购买省级订阅包; areacount:省份订阅包购买的省份数量-1:全国 无限制调整
|
|
|
- isfirst, ppb, areacount := IsCanSet(userId, area, session)
|
|
|
- //购买省份订阅包 已调整地区次数
|
|
|
- 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))
|
|
|
- } else if len(area) == 0 {
|
|
|
- return &FuncResult{false, errors.New("地区参数异常"), nil}
|
|
|
- }
|
|
|
- //免费用户未购买省份订阅包 按年算
|
|
|
- year := fmt.Sprint(time.Now().Year())
|
|
|
- //免费用户 已调整地区次数
|
|
|
- fpnum := redis.GetInt(jy.PowerCacheDb, fmt.Sprintf(jy.UserUpdateAreaKey, userId, year))
|
|
|
- // log.Println(len(area), "fpnum:", fpnum, "ppnum:", ppnum)
|
|
|
- //第一次设置地区 || 购买全国 不扣次数
|
|
|
- var issetredis = areacount > -1 && !isfirst
|
|
|
- if issetredis {
|
|
|
- //地区范围判断
|
|
|
- if areacount+jy.BaseAreaNum < len(area) {
|
|
|
- return &FuncResult{false, errors.New("超出地区可设置范围"), nil}
|
|
|
- }
|
|
|
- //地区调整次数判断
|
|
|
- if areacount+jy.BaseAreaNum <= ppnum { //+fpnum
|
|
|
- return &FuncResult{false, errors.New(fmt.Sprintf("订阅地区调整次数(%d)已用完", areacount+jy.BaseAreaNum)), nil}
|
|
|
- }
|
|
|
- }
|
|
|
- //清楚缓存
|
|
|
- jy.ClearBigVipUserPower(userId)
|
|
|
- if !FreeSubChange(userId, &area, industry, ppb, isfirst) {
|
|
|
- return &FuncResult{false, errors.New("保存修改出错"), nil}
|
|
|
- } else if issetredis { //更新调整次数 非全国(第一次 不消耗次数)
|
|
|
- //优先使用省份订阅包次数
|
|
|
- // log.Println(areacount, "---", ppnum)
|
|
|
- // log.Println(jy.BaseAreaNum, "---", fpnum)
|
|
|
- if ppb {
|
|
|
- if areacount+jy.BaseAreaNum > ppnum {
|
|
|
- redis.Put(jy.PowerCacheDb, fmt.Sprintf(jy.UserUpdateAreaKey, userId, ym), ppnum+1, 31*24*60*60)
|
|
|
- } else {
|
|
|
- log.Println(fmt.Sprintf("免费用户购买省份订阅包设置地区 扣除次数异常 userId:%s", userId))
|
|
|
- }
|
|
|
- } 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", 0, session)
|
|
|
- return &FuncResult{true, nil, map[string]interface{}{
|
|
|
- "doSuccess": true,
|
|
|
- }}
|
|
|
+ //isfirst:是否第一次设置地区;ppb:是否购买省级订阅包; areacount:省份订阅包购买的省份数量-1:全国 无限制调整
|
|
|
+ isfirst, ppb, areacount := IsCanSet(userId, area, session)
|
|
|
+ //购买省份订阅包 已调整地区次数
|
|
|
+ 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))
|
|
|
+ } else if len(area) == 0 {
|
|
|
+ return &FuncResult{false, errors.New("地区参数异常"), nil}
|
|
|
+ }
|
|
|
+ //免费用户未购买省份订阅包 按年算
|
|
|
+ year := fmt.Sprint(time.Now().Year())
|
|
|
+ //免费用户 已调整地区次数
|
|
|
+ fpnum := redis.GetInt(jy.PowerCacheDb, fmt.Sprintf(jy.UserUpdateAreaKey, userId, year))
|
|
|
+ // log.Println(len(area), "fpnum:", fpnum, "ppnum:", ppnum)
|
|
|
+ //第一次设置地区 || 购买全国 不扣次数
|
|
|
+ var issetredis = areacount > -1 && !isfirst
|
|
|
+ if issetredis {
|
|
|
+ //地区范围判断
|
|
|
+ if areacount+jy.BaseAreaNum < len(area) {
|
|
|
+ return &FuncResult{false, errors.New("超出地区可设置范围"), nil}
|
|
|
+ }
|
|
|
+ //地区调整次数判断
|
|
|
+ if areacount+jy.BaseAreaNum <= ppnum { //+fpnum
|
|
|
+ return &FuncResult{false, errors.New(fmt.Sprintf("订阅地区调整次数(%d)已用完", areacount+jy.BaseAreaNum)), nil}
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //清楚缓存
|
|
|
+ jy.ClearBigVipUserPower(userId)
|
|
|
+ if !FreeSubChange(userId, &area, industry, ppb, isfirst) {
|
|
|
+ return &FuncResult{false, errors.New("保存修改出错"), nil}
|
|
|
+ } else if issetredis { //更新调整次数 非全国(第一次 不消耗次数)
|
|
|
+ //优先使用省份订阅包次数
|
|
|
+ // log.Println(areacount, "---", ppnum)
|
|
|
+ // log.Println(jy.BaseAreaNum, "---", fpnum)
|
|
|
+ if ppb {
|
|
|
+ if areacount+jy.BaseAreaNum > ppnum {
|
|
|
+ redis.Put(jy.PowerCacheDb, fmt.Sprintf(jy.UserUpdateAreaKey, userId, ym), ppnum+1, 31*24*60*60)
|
|
|
+ } else {
|
|
|
+ log.Println(fmt.Sprintf("免费用户购买省份订阅包设置地区 扣除次数异常 userId:%s", userId))
|
|
|
+ }
|
|
|
+ } 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", 0, session)
|
|
|
+ return &FuncResult{true, nil, map[string]interface{}{
|
|
|
+ "doSuccess": true,
|
|
|
+ }}
|
|
|
}
|
|
|
|
|
|
//免费用户地区调整
|
|
|
func FreeSubChange(userId string, area *map[string]interface{}, industry []string, ppb, isfirst bool) bool {
|
|
|
- setMap := map[string]interface{}{"$set": map[string]interface{}{
|
|
|
- "o_jy.o_area": area, //设置地区
|
|
|
- "o_jy.i_newfree": 1, //老免费用户=>新订阅设置页面 20211122
|
|
|
- }}
|
|
|
- if ppb {
|
|
|
- setMap = map[string]interface{}{"$set": map[string]interface{}{
|
|
|
- "o_jy.o_area_p": area, //设置地区
|
|
|
- "o_jy.i_newfree": 1, //老免费用户=>新订阅设置页面 20211122
|
|
|
- }}
|
|
|
- }
|
|
|
- updateOk := db.Mgo.UpdateById("user", userId, setMap)
|
|
|
- if !updateOk {
|
|
|
- return false
|
|
|
- }
|
|
|
- return true
|
|
|
+ setMap := map[string]interface{}{"$set": map[string]interface{}{
|
|
|
+ "o_jy.o_area": area, //设置地区
|
|
|
+ "o_jy.i_newfree": 1, //老免费用户=>新订阅设置页面 20211122
|
|
|
+ }}
|
|
|
+ if ppb {
|
|
|
+ setMap = map[string]interface{}{"$set": map[string]interface{}{
|
|
|
+ "o_jy.o_area_p": area, //设置地区
|
|
|
+ "o_jy.i_newfree": 1, //老免费用户=>新订阅设置页面 20211122
|
|
|
+ }}
|
|
|
+ }
|
|
|
+ updateOk := db.Mgo.UpdateById("user", userId, setMap)
|
|
|
+ if !updateOk {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ return true
|
|
|
}
|
|
|
|
|
|
//是否可进行地区调整
|
|
|
func IsCanSet(userId string, areamap map[string]interface{}, session *httpsession.Session) (bool, bool, int) {
|
|
|
- areacount := 0
|
|
|
- myarea := []string{}
|
|
|
- setarea := []string{}
|
|
|
- myareamap := map[string]interface{}{}
|
|
|
- o_jy := jy.GetSubScribeInfo(session, db.Mgo, "f", "10000")
|
|
|
- //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"])
|
|
|
+ areacount := 0
|
|
|
+ myarea := []string{}
|
|
|
+ setarea := []string{}
|
|
|
+ myareamap := map[string]interface{}{}
|
|
|
+ o_jy := jy.GetSubScribeInfo(session, db.Mgo, "f", "10000")
|
|
|
+ //地区是否完全一致
|
|
|
+ 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"])
|
|
|
- }
|
|
|
- myareabool := map[string]bool{}
|
|
|
- areasize := 0
|
|
|
- //库中地区
|
|
|
- for oak, _ := range myareamap {
|
|
|
- myareabool[oak] = true
|
|
|
- myarea = append(myarea, oak)
|
|
|
- }
|
|
|
- //参数地区
|
|
|
- for sak, _ := range areamap {
|
|
|
- if myareabool[sak] {
|
|
|
- areasize += 1
|
|
|
- }
|
|
|
- setarea = append(setarea, sak)
|
|
|
- }
|
|
|
- if areaSort(setarea) == areaSort(myarea) || areasize == len(setarea) {
|
|
|
- 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
|
|
|
+ }
|
|
|
+ //是否购买省份订阅包
|
|
|
+ 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"])
|
|
|
+ }
|
|
|
+ myareabool := map[string]bool{}
|
|
|
+ areasize := 0
|
|
|
+ //库中地区
|
|
|
+ for oak, _ := range myareamap {
|
|
|
+ myareabool[oak] = true
|
|
|
+ myarea = append(myarea, oak)
|
|
|
+ }
|
|
|
+ //参数地区
|
|
|
+ for sak, _ := range areamap {
|
|
|
+ if myareabool[sak] {
|
|
|
+ areasize += 1
|
|
|
+ }
|
|
|
+ setarea = append(setarea, sak)
|
|
|
+ }
|
|
|
+ if areaSort(setarea) == areaSort(myarea) || areasize == len(setarea) {
|
|
|
+ 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, ",")
|
|
|
+ sort.Slice(area, func(i, j int) bool {
|
|
|
+ return area[i] < area[j]
|
|
|
+ })
|
|
|
+ return strings.Join(area, ",")
|
|
|
}
|
|
|
|
|
|
//
|
|
|
func vipSet(area map[string]interface{}, industry []string, userId string, session *httpsession.Session) *FuncResult {
|
|
|
- if len(industry) == 1 && industry[0] == "" {
|
|
|
- industry = []string{}
|
|
|
- }
|
|
|
- positionType := qutil.Int64All(session.Get("positionType"))
|
|
|
- rData, oldBuyset, isVip := GetVipDetail(session)
|
|
|
- if !isVip {
|
|
|
- return &FuncResult{false, errors.New("请求异常,非vip状态"), nil}
|
|
|
- }
|
|
|
- if rData == nil || len(*rData) == 0 {
|
|
|
- return &FuncResult{false, errors.New("获取信息失败"), nil}
|
|
|
- }
|
|
|
- newBuyset := NewBuySet(&area, industry, oldBuyset.Upgrade == 1)
|
|
|
+ if len(industry) == 1 && industry[0] == "" {
|
|
|
+ industry = []string{}
|
|
|
+ }
|
|
|
+ positionType := qutil.Int64All(session.Get("positionType"))
|
|
|
+ rData, oldBuyset, isVip := GetVipDetail(session)
|
|
|
+ if !isVip {
|
|
|
+ return &FuncResult{false, errors.New("请求异常,非vip状态"), nil}
|
|
|
+ }
|
|
|
+ if rData == nil || len(*rData) == 0 {
|
|
|
+ return &FuncResult{false, errors.New("获取信息失败"), nil}
|
|
|
+ }
|
|
|
+ newBuyset := NewBuySet(&area, industry, oldBuyset.Upgrade == 1)
|
|
|
|
|
|
- if needUpgrade := needUpgrade(newBuyset, oldBuyset); needUpgrade {
|
|
|
- log.Printf("%s 订阅内容超出套餐 %+v area:%v industry:%v", userId, oldBuyset, area, industry)
|
|
|
- return &FuncResult{false, errors.New("订阅内容超出套餐"), nil}
|
|
|
- }
|
|
|
- if positionType == 1 {
|
|
|
- if !VipSubChange(userId, qutil.ObjToMap((*rData)["o_entniche"]), &area, industry, session) {
|
|
|
- return &FuncResult{false, errors.New("保存修改出错"), nil}
|
|
|
- }
|
|
|
- } else {
|
|
|
- if !VipSubChange(userId, qutil.ObjToMap((*rData)["o_vipjy"]), &area, industry, session) {
|
|
|
- return &FuncResult{false, errors.New("保存修改出错"), nil}
|
|
|
- }
|
|
|
- }
|
|
|
+ if needUpgrade := needUpgrade(newBuyset, oldBuyset); needUpgrade {
|
|
|
+ log.Printf("%s 订阅内容超出套餐 %+v area:%v industry:%v", userId, oldBuyset, area, industry)
|
|
|
+ return &FuncResult{false, errors.New("订阅内容超出套餐"), nil}
|
|
|
+ }
|
|
|
+ if positionType == 1 {
|
|
|
+ if !VipSubChange(userId, qutil.ObjToMap((*rData)["o_entniche"]), &area, industry, session) {
|
|
|
+ return &FuncResult{false, errors.New("保存修改出错"), nil}
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if !VipSubChange(userId, qutil.ObjToMap((*rData)["o_vipjy"]), &area, industry, session) {
|
|
|
+ return &FuncResult{false, errors.New("保存修改出错"), nil}
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- SetLog(userId, "o_vipjy", positionType, session)
|
|
|
- return &FuncResult{true, nil, map[string]interface{}{
|
|
|
- "doSuccess": true,
|
|
|
- }}
|
|
|
+ SetLog(userId, "o_vipjy", positionType, session)
|
|
|
+ return &FuncResult{true, nil, map[string]interface{}{
|
|
|
+ "doSuccess": true,
|
|
|
+ }}
|
|
|
}
|
|
|
|
|
|
//大会员订阅设置
|
|
|
func memberSet(area map[string]interface{}, industry []string, userId string, session *httpsession.Session) *FuncResult {
|
|
|
- if data := jy.GetBigVipUserBaseMsg( session, *config.Middleground); data.Status <= 0 {
|
|
|
- return &FuncResult{false, errors.New("请求异常,非大会员状态"), nil}
|
|
|
- }
|
|
|
- if len(industry) == 1 && industry[0] == "" {
|
|
|
- industry = []string{}
|
|
|
- }
|
|
|
- positionType := qutil.Int64All(session.Get("positionType"))
|
|
|
- if !MemberSubChange(userId, &area, industry, session) {
|
|
|
- return &FuncResult{false, errors.New("保存修改出错"), nil}
|
|
|
- }
|
|
|
- SetLog(userId, "o_member_jy", positionType, session)
|
|
|
- return &FuncResult{true, nil, map[string]interface{}{
|
|
|
- "doSuccess": true,
|
|
|
- }}
|
|
|
+ if data := jy.GetBigVipUserBaseMsg(session, *config.Middleground); data.Status <= 0 {
|
|
|
+ return &FuncResult{false, errors.New("请求异常,非大会员状态"), nil}
|
|
|
+ }
|
|
|
+ if len(industry) == 1 && industry[0] == "" {
|
|
|
+ industry = []string{}
|
|
|
+ }
|
|
|
+ positionType := qutil.Int64All(session.Get("positionType"))
|
|
|
+ if !MemberSubChange(userId, &area, industry, session) {
|
|
|
+ return &FuncResult{false, errors.New("保存修改出错"), nil}
|
|
|
+ }
|
|
|
+ SetLog(userId, "o_member_jy", positionType, session)
|
|
|
+ return &FuncResult{true, nil, map[string]interface{}{
|
|
|
+ "doSuccess": true,
|
|
|
+ }}
|
|
|
}
|
|
|
|
|
|
//购买内容
|
|
|
type SubvipBuySet struct {
|
|
|
- Upgrade int `json:"upgrade"` //是否是升级版;1是 其他不是
|
|
|
- AreaCount int `json:"areacount"` //-1 全国 >0 省份数量
|
|
|
- NewCitys []int `json:"newcitys"` //城市数量(新)
|
|
|
- BuyerclassCount int `json:"buyerclasscount"` //行业数
|
|
|
+ Upgrade int `json:"upgrade"` //是否是升级版;1是 其他不是
|
|
|
+ AreaCount int `json:"areacount"` //-1 全国 >0 省份数量
|
|
|
+ NewCitys []int `json:"newcitys"` //城市数量(新)
|
|
|
+ BuyerclassCount int `json:"buyerclasscount"` //行业数
|
|
|
}
|
|
|
|
|
|
//获取省份,城市,行业购买内容
|
|
|
//[省份,城市,行业]
|
|
|
func GetVipDetail(session *httpsession.Session) (*map[string]interface{}, *SubvipBuySet, bool) {
|
|
|
- /* mData, ok := db.Mgo.FindById("user", userId, `{"o_vipjy":1,"i_vip_status":1,"l_vip_endtime":1,"l_vip_starttime":1,"isread":1}`)
|
|
|
- if !ok || len(*mData) == 0 || mData == nil {
|
|
|
- return nil, nil, false
|
|
|
- }*/
|
|
|
- data := jy.GetBigVipUserBaseMsg( session,*config.Middleground)
|
|
|
- //是否处于vip状态
|
|
|
- vipStatus := data.Data.Vip.Status
|
|
|
- o_jy := jy.GetSubScribeInfo(session, db.Mgo, "v", "10000")
|
|
|
- tmp := qutil.ObjToMap((*o_jy)["o_buyset"])
|
|
|
- newCity, _ := (*tmp)["newcitys"].([]interface{})
|
|
|
- return o_jy, &SubvipBuySet{
|
|
|
- qutil.IntAll((*tmp)["upgrade"]),
|
|
|
- qutil.IntAll((*tmp)["areacount"]),
|
|
|
- util.ConfirmIntArr(newCity),
|
|
|
- qutil.IntAll((*tmp)["buyerclasscount"]),
|
|
|
- }, vipStatus > 0
|
|
|
+ data := jy.GetBigVipUserBaseMsg(session, *config.Middleground)
|
|
|
+ //是否处于vip状态
|
|
|
+ vipStatus := data.Data.Vip.Status
|
|
|
+ o_jy := jy.GetSubScribeInfo(session, db.Mgo, "v", "10000")
|
|
|
+ tmp := qutil.ObjToMap((*o_jy)["o_buyset"])
|
|
|
+ newCity, _ := (*tmp)["newcitys"].([]interface{})
|
|
|
+ return o_jy, &SubvipBuySet{
|
|
|
+ qutil.IntAll((*tmp)["upgrade"]),
|
|
|
+ qutil.IntAll((*tmp)["areacount"]),
|
|
|
+ util.ConfirmIntArr(newCity),
|
|
|
+ qutil.IntAll((*tmp)["buyerclasscount"]),
|
|
|
+ }, vipStatus > 0
|
|
|
}
|
|
|
|
|
|
var SubVipPrice subVipPrice
|
|
|
|
|
|
func init() {
|
|
|
- qutil.ReadConfig("./subvip_price.json", &SubVipPrice)
|
|
|
+ qutil.ReadConfig("./subvip_price.json", &SubVipPrice)
|
|
|
}
|
|
|
|
|
|
//价格表
|
|
|
type subVipPrice struct {
|
|
|
- Old struct {
|
|
|
- Month struct {
|
|
|
- OneCity_oneBuyerClass int `json:"oneCity_oneBuyerClass"` //一个城市一个行业
|
|
|
- OneCity_allBuyerClass int `json:"oneCity_allBuyerClass"` //一个城市全部行业
|
|
|
- OneProvince_oneBuyerClass int `json:"oneProvince_oneBuyerClass"` //一个省份一个行业
|
|
|
- OneProvince_allBuyerClass int `json:"oneProvince_allBuyerClass"` //一个省份全部行业
|
|
|
- AllProvince_oneBuyerClass int `json:"allProvince_oneBuyerClass"` //全国一个行业
|
|
|
- AllProvince_allBuyerClass int `json:"allProvince_allBuyerClass"` //全国全行业
|
|
|
- } `json:"month"`
|
|
|
- Year struct {
|
|
|
- OneCity_oneBuyerClass int `json:"oneCity_oneBuyerClass"` //一个城市一个行业
|
|
|
- OneCity_allBuyerClass int `json:"oneCity_allBuyerClass"` //一个城市全部行业
|
|
|
- OneProvince_oneBuyerClass int `json:"oneProvince_oneBuyerClass"` //一个省份一个行业
|
|
|
- OneProvince_allBuyerClass int `json:"oneProvince_allBuyerClass"` //一个省份全部行业
|
|
|
- AllProvince_oneBuyerClass int `json:"allProvince_oneBuyerClass"` //全国一个行业
|
|
|
- AllProvince_allBuyerClass int `json:"allProvince_allBuyerClass"` //全国全行业
|
|
|
- } `json:"year"`
|
|
|
- CityPrice int `json:"cityPrice"` //单个城市价格
|
|
|
- ProvincePrice int `json:"provincePrice"` //单个省份价格
|
|
|
- BuyerClassPrice int `json:"buyerClassPrice"` //单个行业价格
|
|
|
- CityMaxCount int `json:"cityMaxCount"` //单个省份城市可计价最大数量
|
|
|
- ProvinceMaxCount int `json:"provinceMaxCount"` //所有地区中省份可计价最大数量
|
|
|
- BuyerClassMaxCount int `json:"buyerClassMaxCount"` //行业价格可计价最大数量
|
|
|
- MonthMaxCount int `json:"monthMaxCount"` //月份可计价最大数量
|
|
|
- } `json:"old"`
|
|
|
- New struct {
|
|
|
- Month struct {
|
|
|
- OneProvince_allBuyerClass int `json:"oneProvince_allBuyerClass"` //一个省份全部行业
|
|
|
- AllProvince_allBuyerClass int `json:"allProvince_allBuyerClass"` //全国全行业
|
|
|
- } `json:"month"`
|
|
|
- Quarter struct {
|
|
|
- OneProvince_allBuyerClass int `json:"oneProvince_allBuyerClass"` //一个省份全部行业
|
|
|
- AllProvince_allBuyerClass int `json:"allProvince_allBuyerClass"` //全国全行业
|
|
|
- } `json:"quarter"`
|
|
|
- Year struct {
|
|
|
- OneProvince_allBuyerClass int `json:"oneProvince_allBuyerClass"` //一个省份全部行业
|
|
|
- AllProvince_allBuyerClass int `json:"allProvince_allBuyerClass"` //全国全行业
|
|
|
- } `json:"year"`
|
|
|
- ProvincePrice int `json:"provincePrice"` //单个省份价格
|
|
|
- ProvinceMaxCount int `json:"provinceMaxCount"` //所有地区中省份可计价最大数量
|
|
|
- MonthMaxCount int `json:"monthMaxCount"` //月份可计价最大数量
|
|
|
- } `json:"new"`
|
|
|
- Discount float64 `json:"discount"` //折扣(测试使用)
|
|
|
+ Old struct {
|
|
|
+ Month struct {
|
|
|
+ OneCity_oneBuyerClass int `json:"oneCity_oneBuyerClass"` //一个城市一个行业
|
|
|
+ OneCity_allBuyerClass int `json:"oneCity_allBuyerClass"` //一个城市全部行业
|
|
|
+ OneProvince_oneBuyerClass int `json:"oneProvince_oneBuyerClass"` //一个省份一个行业
|
|
|
+ OneProvince_allBuyerClass int `json:"oneProvince_allBuyerClass"` //一个省份全部行业
|
|
|
+ AllProvince_oneBuyerClass int `json:"allProvince_oneBuyerClass"` //全国一个行业
|
|
|
+ AllProvince_allBuyerClass int `json:"allProvince_allBuyerClass"` //全国全行业
|
|
|
+ } `json:"month"`
|
|
|
+ Year struct {
|
|
|
+ OneCity_oneBuyerClass int `json:"oneCity_oneBuyerClass"` //一个城市一个行业
|
|
|
+ OneCity_allBuyerClass int `json:"oneCity_allBuyerClass"` //一个城市全部行业
|
|
|
+ OneProvince_oneBuyerClass int `json:"oneProvince_oneBuyerClass"` //一个省份一个行业
|
|
|
+ OneProvince_allBuyerClass int `json:"oneProvince_allBuyerClass"` //一个省份全部行业
|
|
|
+ AllProvince_oneBuyerClass int `json:"allProvince_oneBuyerClass"` //全国一个行业
|
|
|
+ AllProvince_allBuyerClass int `json:"allProvince_allBuyerClass"` //全国全行业
|
|
|
+ } `json:"year"`
|
|
|
+ CityPrice int `json:"cityPrice"` //单个城市价格
|
|
|
+ ProvincePrice int `json:"provincePrice"` //单个省份价格
|
|
|
+ BuyerClassPrice int `json:"buyerClassPrice"` //单个行业价格
|
|
|
+ CityMaxCount int `json:"cityMaxCount"` //单个省份城市可计价最大数量
|
|
|
+ ProvinceMaxCount int `json:"provinceMaxCount"` //所有地区中省份可计价最大数量
|
|
|
+ BuyerClassMaxCount int `json:"buyerClassMaxCount"` //行业价格可计价最大数量
|
|
|
+ MonthMaxCount int `json:"monthMaxCount"` //月份可计价最大数量
|
|
|
+ } `json:"old"`
|
|
|
+ New struct {
|
|
|
+ Month struct {
|
|
|
+ OneProvince_allBuyerClass int `json:"oneProvince_allBuyerClass"` //一个省份全部行业
|
|
|
+ AllProvince_allBuyerClass int `json:"allProvince_allBuyerClass"` //全国全行业
|
|
|
+ } `json:"month"`
|
|
|
+ Quarter struct {
|
|
|
+ OneProvince_allBuyerClass int `json:"oneProvince_allBuyerClass"` //一个省份全部行业
|
|
|
+ AllProvince_allBuyerClass int `json:"allProvince_allBuyerClass"` //全国全行业
|
|
|
+ } `json:"quarter"`
|
|
|
+ Year struct {
|
|
|
+ OneProvince_allBuyerClass int `json:"oneProvince_allBuyerClass"` //一个省份全部行业
|
|
|
+ AllProvince_allBuyerClass int `json:"allProvince_allBuyerClass"` //全国全行业
|
|
|
+ } `json:"year"`
|
|
|
+ ProvincePrice int `json:"provincePrice"` //单个省份价格
|
|
|
+ ProvinceMaxCount int `json:"provinceMaxCount"` //所有地区中省份可计价最大数量
|
|
|
+ MonthMaxCount int `json:"monthMaxCount"` //月份可计价最大数量
|
|
|
+ } `json:"new"`
|
|
|
+ Discount float64 `json:"discount"` //折扣(测试使用)
|
|
|
}
|
|
|
|
|
|
//超级订阅获取购买项
|
|
|
func NewBuySet(area *map[string]interface{}, industry []string, isUpgrade bool) *SubvipBuySet {
|
|
|
- pCount := -1
|
|
|
- citys := []int{}
|
|
|
- if area != nil {
|
|
|
- if (*area)["全国"] != nil {
|
|
|
- area = &map[string]interface{}{}
|
|
|
- } else if pCount_tmp := qutil.IntAll((*area)["areacount"]); pCount_tmp > 0 {
|
|
|
- pCount = pCount_tmp
|
|
|
- }
|
|
|
- }
|
|
|
- buyset := SubvipBuySet{}
|
|
|
- if !isUpgrade {
|
|
|
- buyset.Upgrade = 0 //升级版超级订阅标识
|
|
|
- if len(*area) > 0 {
|
|
|
- pCount = 0
|
|
|
- for _, v := range *area {
|
|
|
- tmp := v.([]interface{})
|
|
|
- if len(tmp) == 0 || len(tmp) > SubVipPrice.Old.CityMaxCount { //省份
|
|
|
- pCount++
|
|
|
- } else { //城市
|
|
|
- citys = append(citys, len(tmp))
|
|
|
- }
|
|
|
- }
|
|
|
- //省份数量自动转换全国
|
|
|
- if pCount > SubVipPrice.Old.ProvinceMaxCount {
|
|
|
- pCount = -1
|
|
|
- citys = []int{}
|
|
|
- }
|
|
|
- }
|
|
|
- buyset.NewCitys = citys
|
|
|
- buyset.AreaCount = pCount //地区
|
|
|
- //行业数量自动转换全行业
|
|
|
- buyset.BuyerclassCount = len(industry)
|
|
|
- if len(industry) > SubVipPrice.Old.BuyerClassMaxCount || len(industry) == 0 {
|
|
|
- buyset.BuyerclassCount = -1
|
|
|
- }
|
|
|
- } else {
|
|
|
- buyset.Upgrade = 1 //升级版超级订阅标识
|
|
|
- if len(*area) > 0 {
|
|
|
- pCount = len(*area)
|
|
|
- //省份数量自动转换全国
|
|
|
- if pCount > SubVipPrice.New.ProvinceMaxCount {
|
|
|
- pCount = -1
|
|
|
- }
|
|
|
- } else {
|
|
|
- buyset.AreaCount = -1 //全国
|
|
|
- }
|
|
|
- buyset.AreaCount = pCount //地区
|
|
|
- buyset.NewCitys = citys //城市,4.4改版不支持购买城市
|
|
|
- buyset.BuyerclassCount = -1 //行业,4.4改版只能购买全行业
|
|
|
- }
|
|
|
- return &buyset
|
|
|
+ pCount := -1
|
|
|
+ citys := []int{}
|
|
|
+ if area != nil {
|
|
|
+ if (*area)["全国"] != nil {
|
|
|
+ area = &map[string]interface{}{}
|
|
|
+ } else if pCount_tmp := qutil.IntAll((*area)["areacount"]); pCount_tmp > 0 {
|
|
|
+ pCount = pCount_tmp
|
|
|
+ }
|
|
|
+ }
|
|
|
+ buyset := SubvipBuySet{}
|
|
|
+ if !isUpgrade {
|
|
|
+ buyset.Upgrade = 0 //升级版超级订阅标识
|
|
|
+ if len(*area) > 0 {
|
|
|
+ pCount = 0
|
|
|
+ for _, v := range *area {
|
|
|
+ tmp := v.([]interface{})
|
|
|
+ if len(tmp) == 0 || len(tmp) > SubVipPrice.Old.CityMaxCount { //省份
|
|
|
+ pCount++
|
|
|
+ } else { //城市
|
|
|
+ citys = append(citys, len(tmp))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //省份数量自动转换全国
|
|
|
+ if pCount > SubVipPrice.Old.ProvinceMaxCount {
|
|
|
+ pCount = -1
|
|
|
+ citys = []int{}
|
|
|
+ }
|
|
|
+ }
|
|
|
+ buyset.NewCitys = citys
|
|
|
+ buyset.AreaCount = pCount //地区
|
|
|
+ //行业数量自动转换全行业
|
|
|
+ buyset.BuyerclassCount = len(industry)
|
|
|
+ if len(industry) > SubVipPrice.Old.BuyerClassMaxCount || len(industry) == 0 {
|
|
|
+ buyset.BuyerclassCount = -1
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ buyset.Upgrade = 1 //升级版超级订阅标识
|
|
|
+ if len(*area) > 0 {
|
|
|
+ pCount = len(*area)
|
|
|
+ //省份数量自动转换全国
|
|
|
+ if pCount > SubVipPrice.New.ProvinceMaxCount {
|
|
|
+ pCount = -1
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ buyset.AreaCount = -1 //全国
|
|
|
+ }
|
|
|
+ buyset.AreaCount = pCount //地区
|
|
|
+ buyset.NewCitys = citys //城市,4.4改版不支持购买城市
|
|
|
+ buyset.BuyerclassCount = -1 //行业,4.4改版只能购买全行业
|
|
|
+ }
|
|
|
+ return &buyset
|
|
|
}
|
|
|
|
|
|
//是否需要升级
|
|
|
func needUpgrade(newBuySet, oldBuySet *SubvipBuySet) bool {
|
|
|
- if newBuySet.Upgrade != 1 { //旧版本订阅是否需要升级校验
|
|
|
- BuyerclassUpgrade, AreaNeedUpgrade := false, false
|
|
|
- UpgradeBuyset := &SubvipBuySet{
|
|
|
- oldBuySet.Upgrade,
|
|
|
- oldBuySet.AreaCount,
|
|
|
- oldBuySet.NewCitys,
|
|
|
- oldBuySet.BuyerclassCount,
|
|
|
- }
|
|
|
- //比较行业
|
|
|
- if oldBuySet.BuyerclassCount != -1 {
|
|
|
- //若当前买的不是全行业,并且当前行业数量小于新行业数量时
|
|
|
- if oldBuySet.BuyerclassCount < newBuySet.BuyerclassCount || newBuySet.BuyerclassCount == -1 {
|
|
|
- BuyerclassUpgrade = true
|
|
|
- //计算升级后的buySet
|
|
|
- UpgradeBuyset.BuyerclassCount = newBuySet.BuyerclassCount
|
|
|
- }
|
|
|
- }
|
|
|
- //比较地区
|
|
|
- if oldBuySet.AreaCount != -1 {
|
|
|
- if newBuySet.AreaCount == -1 { //升级为全国
|
|
|
- UpgradeBuyset.AreaCount = newBuySet.AreaCount
|
|
|
- UpgradeBuyset.NewCitys = newBuySet.NewCitys
|
|
|
- AreaNeedUpgrade = true
|
|
|
- } else {
|
|
|
- oldCitysBuyOne, oldCitysBuyTwo := 0, 0
|
|
|
- newCitysBuyOne, newCitysBuyTwo := 0, 0
|
|
|
- oldCopy := []int{} //复制(防止影响原数组)
|
|
|
- for _, v := range oldBuySet.NewCitys {
|
|
|
- if v == 1 {
|
|
|
- oldCitysBuyOne++
|
|
|
- } else {
|
|
|
- oldCitysBuyTwo++
|
|
|
- }
|
|
|
- oldCopy = append(oldCopy, v)
|
|
|
- }
|
|
|
- UpgradeBuyset.NewCitys = oldCopy
|
|
|
- for _, v := range newBuySet.NewCitys {
|
|
|
- if v == 1 {
|
|
|
- newCitysBuyOne++
|
|
|
- } else {
|
|
|
- newCitysBuyTwo++
|
|
|
- }
|
|
|
- }
|
|
|
+ if newBuySet.Upgrade != 1 { //旧版本订阅是否需要升级校验
|
|
|
+ BuyerclassUpgrade, AreaNeedUpgrade := false, false
|
|
|
+ UpgradeBuyset := &SubvipBuySet{
|
|
|
+ oldBuySet.Upgrade,
|
|
|
+ oldBuySet.AreaCount,
|
|
|
+ oldBuySet.NewCitys,
|
|
|
+ oldBuySet.BuyerclassCount,
|
|
|
+ }
|
|
|
+ //比较行业
|
|
|
+ if oldBuySet.BuyerclassCount != -1 {
|
|
|
+ //若当前买的不是全行业,并且当前行业数量小于新行业数量时
|
|
|
+ if oldBuySet.BuyerclassCount < newBuySet.BuyerclassCount || newBuySet.BuyerclassCount == -1 {
|
|
|
+ BuyerclassUpgrade = true
|
|
|
+ //计算升级后的buySet
|
|
|
+ UpgradeBuyset.BuyerclassCount = newBuySet.BuyerclassCount
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //比较地区
|
|
|
+ if oldBuySet.AreaCount != -1 {
|
|
|
+ if newBuySet.AreaCount == -1 { //升级为全国
|
|
|
+ UpgradeBuyset.AreaCount = newBuySet.AreaCount
|
|
|
+ UpgradeBuyset.NewCitys = newBuySet.NewCitys
|
|
|
+ AreaNeedUpgrade = true
|
|
|
+ } else {
|
|
|
+ oldCitysBuyOne, oldCitysBuyTwo := 0, 0
|
|
|
+ newCitysBuyOne, newCitysBuyTwo := 0, 0
|
|
|
+ oldCopy := []int{} //复制(防止影响原数组)
|
|
|
+ for _, v := range oldBuySet.NewCitys {
|
|
|
+ if v == 1 {
|
|
|
+ oldCitysBuyOne++
|
|
|
+ } else {
|
|
|
+ oldCitysBuyTwo++
|
|
|
+ }
|
|
|
+ oldCopy = append(oldCopy, v)
|
|
|
+ }
|
|
|
+ UpgradeBuyset.NewCitys = oldCopy
|
|
|
+ for _, v := range newBuySet.NewCitys {
|
|
|
+ if v == 1 {
|
|
|
+ newCitysBuyOne++
|
|
|
+ } else {
|
|
|
+ newCitysBuyTwo++
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- p_Diff := newBuySet.AreaCount - oldBuySet.AreaCount
|
|
|
- c_1_diff := newCitysBuyOne - oldCitysBuyOne
|
|
|
- c_2_diff := newCitysBuyTwo - oldCitysBuyTwo
|
|
|
+ p_Diff := newBuySet.AreaCount - oldBuySet.AreaCount
|
|
|
+ c_1_diff := newCitysBuyOne - oldCitysBuyOne
|
|
|
+ c_2_diff := newCitysBuyTwo - oldCitysBuyTwo
|
|
|
|
|
|
- if p_Diff > 0 {
|
|
|
- UpgradeBuyset.AreaCount = newBuySet.AreaCount
|
|
|
- }
|
|
|
+ if p_Diff > 0 {
|
|
|
+ UpgradeBuyset.AreaCount = newBuySet.AreaCount
|
|
|
+ }
|
|
|
|
|
|
- if p_Diff > 0 || p_Diff+c_2_diff > 0 || p_Diff+c_2_diff+c_1_diff > 0 {
|
|
|
- //有多余未使用名额保留
|
|
|
- if p_Diff+c_2_diff+c_1_diff < 0 {
|
|
|
- if c_1_diff < 0 && p_Diff+c_2_diff >= 0 {
|
|
|
- c_1_diff = -(p_Diff + c_2_diff)
|
|
|
- }
|
|
|
- if c_2_diff < 0 && p_Diff+c_1_diff >= 0 {
|
|
|
- c_2_diff = -(p_Diff + c_1_diff)
|
|
|
- }
|
|
|
- }
|
|
|
+ if p_Diff > 0 || p_Diff+c_2_diff > 0 || p_Diff+c_2_diff+c_1_diff > 0 {
|
|
|
+ //有多余未使用名额保留
|
|
|
+ if p_Diff+c_2_diff+c_1_diff < 0 {
|
|
|
+ if c_1_diff < 0 && p_Diff+c_2_diff >= 0 {
|
|
|
+ c_1_diff = -(p_Diff + c_2_diff)
|
|
|
+ }
|
|
|
+ if c_2_diff < 0 && p_Diff+c_1_diff >= 0 {
|
|
|
+ c_2_diff = -(p_Diff + c_1_diff)
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- //需要升级
|
|
|
- AreaNeedUpgrade = true
|
|
|
- //计算升级后的buySet
|
|
|
- if p_Diff < 0 { //有剩余省份未使用
|
|
|
- if c_2_diff > 0 {
|
|
|
- c_2_diff += p_Diff //转移给两个市使用
|
|
|
- } else {
|
|
|
- c_1_diff += p_Diff //转移给一个市使用
|
|
|
- }
|
|
|
- } else { //省份数量增加
|
|
|
- UpgradeBuyset.AreaCount = newBuySet.AreaCount
|
|
|
- }
|
|
|
- del_2_flag, del_1_flag := 0, 0 //被占用
|
|
|
- if c_2_diff < 0 { //有两个城市的名额未使用完
|
|
|
- if p_Diff > 0 {
|
|
|
- //转移给一个省使用
|
|
|
- if c_2_diff+p_Diff > 0 {
|
|
|
- del_2_flag += -c_2_diff
|
|
|
- c_2_diff = 0
|
|
|
- //p_Diff -= -c_2_diff;
|
|
|
- } else {
|
|
|
- c_2_diff += p_Diff
|
|
|
- del_2_flag += p_Diff
|
|
|
- //p_Diff = 0
|
|
|
- }
|
|
|
- }
|
|
|
- if c_1_diff > 0 && c_2_diff < 0 { //转移给一个市使用
|
|
|
- c_1_diff += c_2_diff
|
|
|
- }
|
|
|
- }
|
|
|
- if c_1_diff < 0 { //有一个城市的名额未使用完
|
|
|
- if p_Diff > 0 {
|
|
|
- if c_1_diff+p_Diff > 0 {
|
|
|
- del_1_flag += -c_1_diff
|
|
|
- c_1_diff = 0
|
|
|
- //p_Diff -= -c_1_diff
|
|
|
- } else {
|
|
|
- c_1_diff += p_Diff
|
|
|
- del_1_flag += p_Diff
|
|
|
- //p_Diff = 0
|
|
|
- }
|
|
|
- }
|
|
|
- if c_2_diff > 0 && c_1_diff < 0 {
|
|
|
- if c_1_diff+c_2_diff > 0 {
|
|
|
- del_1_flag += -c_1_diff
|
|
|
- c_1_diff = 0
|
|
|
- //c_2_diff -= -c_1_diff;
|
|
|
- } else {
|
|
|
- c_1_diff += c_2_diff
|
|
|
- del_1_flag += c_2_diff
|
|
|
- //c_2_diff = 0
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- //删除顶替
|
|
|
- log.Println("start", UpgradeBuyset.NewCitys, del_2_flag, del_1_flag)
|
|
|
- index_flag := 0
|
|
|
- for del_2_flag > 0 || del_1_flag > 0 {
|
|
|
- valueFlag := UpgradeBuyset.NewCitys[index_flag]
|
|
|
- if del_2_flag > 0 && valueFlag == 2 {
|
|
|
- UpgradeBuyset.NewCitys = append(UpgradeBuyset.NewCitys[:index_flag], UpgradeBuyset.NewCitys[index_flag+1:]...)
|
|
|
- del_2_flag--
|
|
|
- continue
|
|
|
- } else if del_1_flag > 0 && valueFlag == 1 {
|
|
|
- UpgradeBuyset.NewCitys = append(UpgradeBuyset.NewCitys[:index_flag], UpgradeBuyset.NewCitys[index_flag+1:]...)
|
|
|
- del_1_flag--
|
|
|
- continue
|
|
|
- }
|
|
|
- index_flag++
|
|
|
- }
|
|
|
- log.Println("end", UpgradeBuyset.NewCitys, c_2_diff, c_1_diff)
|
|
|
- //增加新增
|
|
|
- for i := c_2_diff; i > 0; i-- { //添加购买两个市数量
|
|
|
- UpgradeBuyset.NewCitys = append(UpgradeBuyset.NewCitys, 2)
|
|
|
- }
|
|
|
+ //需要升级
|
|
|
+ AreaNeedUpgrade = true
|
|
|
+ //计算升级后的buySet
|
|
|
+ if p_Diff < 0 { //有剩余省份未使用
|
|
|
+ if c_2_diff > 0 {
|
|
|
+ c_2_diff += p_Diff //转移给两个市使用
|
|
|
+ } else {
|
|
|
+ c_1_diff += p_Diff //转移给一个市使用
|
|
|
+ }
|
|
|
+ } else { //省份数量增加
|
|
|
+ UpgradeBuyset.AreaCount = newBuySet.AreaCount
|
|
|
+ }
|
|
|
+ del_2_flag, del_1_flag := 0, 0 //被占用
|
|
|
+ if c_2_diff < 0 { //有两个城市的名额未使用完
|
|
|
+ if p_Diff > 0 {
|
|
|
+ //转移给一个省使用
|
|
|
+ if c_2_diff+p_Diff > 0 {
|
|
|
+ del_2_flag += -c_2_diff
|
|
|
+ c_2_diff = 0
|
|
|
+ //p_Diff -= -c_2_diff;
|
|
|
+ } else {
|
|
|
+ c_2_diff += p_Diff
|
|
|
+ del_2_flag += p_Diff
|
|
|
+ //p_Diff = 0
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if c_1_diff > 0 && c_2_diff < 0 { //转移给一个市使用
|
|
|
+ c_1_diff += c_2_diff
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if c_1_diff < 0 { //有一个城市的名额未使用完
|
|
|
+ if p_Diff > 0 {
|
|
|
+ if c_1_diff+p_Diff > 0 {
|
|
|
+ del_1_flag += -c_1_diff
|
|
|
+ c_1_diff = 0
|
|
|
+ //p_Diff -= -c_1_diff
|
|
|
+ } else {
|
|
|
+ c_1_diff += p_Diff
|
|
|
+ del_1_flag += p_Diff
|
|
|
+ //p_Diff = 0
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if c_2_diff > 0 && c_1_diff < 0 {
|
|
|
+ if c_1_diff+c_2_diff > 0 {
|
|
|
+ del_1_flag += -c_1_diff
|
|
|
+ c_1_diff = 0
|
|
|
+ //c_2_diff -= -c_1_diff;
|
|
|
+ } else {
|
|
|
+ c_1_diff += c_2_diff
|
|
|
+ del_1_flag += c_2_diff
|
|
|
+ //c_2_diff = 0
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //删除顶替
|
|
|
+ log.Println("start", UpgradeBuyset.NewCitys, del_2_flag, del_1_flag)
|
|
|
+ index_flag := 0
|
|
|
+ for del_2_flag > 0 || del_1_flag > 0 {
|
|
|
+ valueFlag := UpgradeBuyset.NewCitys[index_flag]
|
|
|
+ if del_2_flag > 0 && valueFlag == 2 {
|
|
|
+ UpgradeBuyset.NewCitys = append(UpgradeBuyset.NewCitys[:index_flag], UpgradeBuyset.NewCitys[index_flag+1:]...)
|
|
|
+ del_2_flag--
|
|
|
+ continue
|
|
|
+ } else if del_1_flag > 0 && valueFlag == 1 {
|
|
|
+ UpgradeBuyset.NewCitys = append(UpgradeBuyset.NewCitys[:index_flag], UpgradeBuyset.NewCitys[index_flag+1:]...)
|
|
|
+ del_1_flag--
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ index_flag++
|
|
|
+ }
|
|
|
+ log.Println("end", UpgradeBuyset.NewCitys, c_2_diff, c_1_diff)
|
|
|
+ //增加新增
|
|
|
+ for i := c_2_diff; i > 0; i-- { //添加购买两个市数量
|
|
|
+ UpgradeBuyset.NewCitys = append(UpgradeBuyset.NewCitys, 2)
|
|
|
+ }
|
|
|
|
|
|
- for i := c_1_diff; i > 0; i-- { //添加购买一个市数量
|
|
|
- UpgradeBuyset.NewCitys = append(UpgradeBuyset.NewCitys, 1)
|
|
|
- }
|
|
|
- } else {
|
|
|
- //不需要升级
|
|
|
- AreaNeedUpgrade = false
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if BuyerclassUpgrade || AreaNeedUpgrade {
|
|
|
- return true
|
|
|
- } else {
|
|
|
- return false
|
|
|
- }
|
|
|
- } else {
|
|
|
- //return newBuySet.AreaCount == -1 || newBuySet.AreaCount > oldBuySet.AreaCount
|
|
|
- if oldBuySet.AreaCount != -1 {
|
|
|
- return newBuySet.AreaCount == -1 || newBuySet.AreaCount > oldBuySet.AreaCount
|
|
|
- } else {
|
|
|
- return false
|
|
|
- }
|
|
|
- }
|
|
|
+ for i := c_1_diff; i > 0; i-- { //添加购买一个市数量
|
|
|
+ UpgradeBuyset.NewCitys = append(UpgradeBuyset.NewCitys, 1)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //不需要升级
|
|
|
+ AreaNeedUpgrade = false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if BuyerclassUpgrade || AreaNeedUpgrade {
|
|
|
+ return true
|
|
|
+ } else {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //return newBuySet.AreaCount == -1 || newBuySet.AreaCount > oldBuySet.AreaCount
|
|
|
+ if oldBuySet.AreaCount != -1 {
|
|
|
+ return newBuySet.AreaCount == -1 || newBuySet.AreaCount > oldBuySet.AreaCount
|
|
|
+ } else {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//超级订阅 订阅修改
|
|
|
func VipSubChange(userId string, oldVip, areaNew *map[string]interface{}, industryNew []string, session *httpsession.Session) bool {
|
|
|
- updateOk := false
|
|
|
- positionType := qutil.Int64All(session.Get("positionType"))
|
|
|
- if positionType == 1 {
|
|
|
- query := map[string]interface{}{
|
|
|
- "i_userid": qutil.IntAll(session.Get("entUserId")),
|
|
|
- "i_entid": qutil.IntAll(session.Get("entId")),
|
|
|
- "i_type": 1,
|
|
|
- }
|
|
|
- updateOk = db.Mgo.Update("entniche_rule", query,
|
|
|
- map[string]interface{}{"$set": map[string]interface{}{
|
|
|
- "o_entniche.o_area": areaNew, //设置地区
|
|
|
- "o_entniche.a_buyerclass": industryNew, //设置行业
|
|
|
- "l_updatetime": time.Now().Unix(),
|
|
|
- }}, true, false)
|
|
|
- } else {
|
|
|
- updateOk = db.Mgo.UpdateById("user", userId,
|
|
|
- map[string]interface{}{"$set": map[string]interface{}{
|
|
|
- "o_vipjy.o_area": areaNew, //设置地区
|
|
|
- "o_vipjy.a_buyerclass": industryNew, //设置行业
|
|
|
- }})
|
|
|
- }
|
|
|
- if !updateOk {
|
|
|
- return false
|
|
|
- } else {
|
|
|
- //保存修改日志
|
|
|
- go func() {
|
|
|
- db.Mgo_Log.Save("subvip_edit_log", map[string]interface{}{
|
|
|
- "s_userid": userId,
|
|
|
- "o_area_old": (*oldVip)["o_area"],
|
|
|
- "a_buyerclass_old": (*oldVip)["a_buyerclass"],
|
|
|
- "o_area": areaNew,
|
|
|
- "a_buyerclass": industryNew,
|
|
|
- "l_changeTime": time.Now().Unix(),
|
|
|
- })
|
|
|
- }()
|
|
|
- }
|
|
|
- return true
|
|
|
+ updateOk := false
|
|
|
+ positionType := qutil.Int64All(session.Get("positionType"))
|
|
|
+ if positionType == 1 {
|
|
|
+ query := map[string]interface{}{
|
|
|
+ "i_userid": qutil.IntAll(session.Get("entUserId")),
|
|
|
+ "i_entid": qutil.IntAll(session.Get("entId")),
|
|
|
+ "i_type": 1,
|
|
|
+ }
|
|
|
+ updateOk = db.Mgo.Update("entniche_rule", query,
|
|
|
+ map[string]interface{}{"$set": map[string]interface{}{
|
|
|
+ "o_entniche.o_area": areaNew, //设置地区
|
|
|
+ "o_entniche.a_buyerclass": industryNew, //设置行业
|
|
|
+ "l_updatetime": time.Now().Unix(),
|
|
|
+ }}, true, false)
|
|
|
+ } else {
|
|
|
+ updateOk = db.Mgo.UpdateById("user", userId,
|
|
|
+ map[string]interface{}{"$set": map[string]interface{}{
|
|
|
+ "o_vipjy.o_area": areaNew, //设置地区
|
|
|
+ "o_vipjy.a_buyerclass": industryNew, //设置行业
|
|
|
+ }})
|
|
|
+ }
|
|
|
+ if !updateOk {
|
|
|
+ return false
|
|
|
+ } else {
|
|
|
+ //保存修改日志
|
|
|
+ go func() {
|
|
|
+ db.Mgo_Log.Save("subvip_edit_log", map[string]interface{}{
|
|
|
+ "s_userid": userId,
|
|
|
+ "o_area_old": (*oldVip)["o_area"],
|
|
|
+ "a_buyerclass_old": (*oldVip)["a_buyerclass"],
|
|
|
+ "o_area": areaNew,
|
|
|
+ "a_buyerclass": industryNew,
|
|
|
+ "l_changeTime": time.Now().Unix(),
|
|
|
+ })
|
|
|
+ }()
|
|
|
+ }
|
|
|
+ return true
|
|
|
}
|
|
|
|
|
|
//超级订阅 订阅修改
|
|
|
func MemberSubChange(userId string, areaNew *map[string]interface{}, industryNew []string, session *httpsession.Session) bool {
|
|
|
- positionType := qutil.Int64All(session.Get("positionType"))
|
|
|
- if positionType == 1 {
|
|
|
- query := map[string]interface{}{
|
|
|
- "i_userid": qutil.IntAll(session.Get("entUserId")),
|
|
|
- "i_entid": qutil.IntAll(session.Get("entId")),
|
|
|
- "i_type": 1,
|
|
|
- }
|
|
|
- if updateOk := db.Mgo.Update("entniche_rule", query,
|
|
|
- map[string]interface{}{"$set": map[string]interface{}{
|
|
|
- "o_entniche.o_area": areaNew, //设置地区
|
|
|
- "o_entniche.a_buyerclass": industryNew, //设置行业
|
|
|
- "l_updatetime": time.Now().Unix(),
|
|
|
- }}, true, false); !updateOk {
|
|
|
- return false
|
|
|
- }
|
|
|
- } else {
|
|
|
- if updateOk := db.Mgo.UpdateById("user", userId,
|
|
|
- map[string]interface{}{"$set": map[string]interface{}{
|
|
|
- "o_member_jy.o_area": areaNew, //设置地区
|
|
|
- "o_member_jy.a_buyerclass": industryNew, //设置行业
|
|
|
- }}); !updateOk {
|
|
|
- return false
|
|
|
- }
|
|
|
- }
|
|
|
+ positionType := qutil.Int64All(session.Get("positionType"))
|
|
|
+ if positionType == 1 {
|
|
|
+ query := map[string]interface{}{
|
|
|
+ "i_userid": qutil.IntAll(session.Get("entUserId")),
|
|
|
+ "i_entid": qutil.IntAll(session.Get("entId")),
|
|
|
+ "i_type": 1,
|
|
|
+ }
|
|
|
+ if updateOk := db.Mgo.Update("entniche_rule", query,
|
|
|
+ map[string]interface{}{"$set": map[string]interface{}{
|
|
|
+ "o_entniche.o_area": areaNew, //设置地区
|
|
|
+ "o_entniche.a_buyerclass": industryNew, //设置行业
|
|
|
+ "l_updatetime": time.Now().Unix(),
|
|
|
+ }}, true, false); !updateOk {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if updateOk := db.Mgo.UpdateById("user", userId,
|
|
|
+ map[string]interface{}{"$set": map[string]interface{}{
|
|
|
+ "o_member_jy.o_area": areaNew, //设置地区
|
|
|
+ "o_member_jy.a_buyerclass": industryNew, //设置行业
|
|
|
+ }}); !updateOk {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- return true
|
|
|
+ return true
|
|
|
}
|