|
@@ -17,6 +17,38 @@ import (
|
|
|
type vipSubscribeStruct struct{}
|
|
|
|
|
|
var JyVipSubStruct vipSubscribeStruct
|
|
|
+var SubVipPrice subVipPrice
|
|
|
+
|
|
|
+func init() {
|
|
|
+ qutil.ReadConfig("./subvip_price.json", &SubVipPrice)
|
|
|
+}
|
|
|
+
|
|
|
+//价格表
|
|
|
+type subVipPrice 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"` //月份可计价最大数量
|
|
|
+}
|
|
|
|
|
|
//订单简单信息
|
|
|
type VipSimpleMsg struct {
|
|
@@ -313,99 +345,119 @@ func (this *vipSubscribeStruct) SaveSelectLog(userId, openId string, msg *VipSim
|
|
|
|
|
|
//计算价格
|
|
|
func (this *vipSubscribeStruct) GetSubVipPrice(area *map[string]interface{}, industry []string, count, unit int) int {
|
|
|
- if len(*area) == 0 { //全国
|
|
|
- if len(industry) == 1 {
|
|
|
+ //当行业数量大于最大值SubVipPrice.BuyerClassMaxCount 按照全行业计算
|
|
|
+ industryNum := len(industry)
|
|
|
+ if industryNum > SubVipPrice.BuyerClassMaxCount {
|
|
|
+ industryNum = 0
|
|
|
+ }
|
|
|
+ //计算地区数量
|
|
|
+ pCount := -1 //省份数量
|
|
|
+ cityCountMap := map[string]int{} //购买省份中城市数量
|
|
|
+
|
|
|
+ if len(*area) != 0 {
|
|
|
+ pCount = 0
|
|
|
+ for k, v := range *area {
|
|
|
+ tmp := v.([]interface{})
|
|
|
+ if len(tmp) == 0 { //省份
|
|
|
+ pCount++
|
|
|
+ } else { //城市
|
|
|
+ //当城市数量大于最大值时,按照全省计算
|
|
|
+ if len(tmp) > SubVipPrice.CityMaxCount {
|
|
|
+ pCount++
|
|
|
+ } else {
|
|
|
+ cityCountMap[k] = len(tmp)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //当省份数量大于SubVipPrice.ProvinceMaxCount 按照全国计算
|
|
|
+ if pCount > SubVipPrice.ProvinceMaxCount {
|
|
|
+ pCount = -1
|
|
|
+ }
|
|
|
+
|
|
|
+ //当选择月份大于 按照全年计算
|
|
|
+ if count > SubVipPrice.MonthMaxCount && unit == 2 { //月份十个月以上价格一样
|
|
|
+ count = 10
|
|
|
+ }
|
|
|
+
|
|
|
+ if pCount == -1 { //计算全国套餐价格
|
|
|
+ if industryNum == 1 {
|
|
|
return getSetMealPrice(0, 1, unit) * count //全国1行业套餐
|
|
|
- } else if len(industry) == 0 {
|
|
|
+ } else if industryNum == 0 {
|
|
|
return getSetMealPrice(0, 0, unit) * count //全国全行业套餐
|
|
|
} else {
|
|
|
- return getSetMealPrice(0, len(industry), unit) * count //全国多行业套餐
|
|
|
+ return getSetMealPrice(0, industryNum, unit) * count //全国多行业套餐
|
|
|
}
|
|
|
}
|
|
|
- final_price := 0 //最终价格
|
|
|
- for _, tmp := range *area {
|
|
|
+
|
|
|
+ //计算非全国套餐
|
|
|
+ finalPrice := pCount * getSetMealPrice(1, industryNum, unit) * count //省份价格
|
|
|
+ for _, cityCount := range cityCountMap {
|
|
|
thisPrice := 0
|
|
|
- citys := qutil.ObjArrToStringArr(tmp.([]interface{}))
|
|
|
- if len(citys) > 0 { //市
|
|
|
- if len(citys) == 1 { //单城市
|
|
|
- thisPrice = getSetMealPrice(2, len(industry), unit) * count
|
|
|
- } else { //多城市
|
|
|
- if len(industry) == 0 || len(industry) == 1 { //多城市 单行业
|
|
|
- thisPrice = len(citys) * getSetMealPrice(2, len(industry), unit) * count
|
|
|
- } else { //多行业 多行业
|
|
|
- if count > 10 && unit == 2 { //月份十个月以上价格一样
|
|
|
- count = 10
|
|
|
- }
|
|
|
- industry_Price := 580 * len(industry)
|
|
|
- if 580*len(industry) > 1800 {
|
|
|
- industry_Price = 1800
|
|
|
- }
|
|
|
- city_Price := len(citys) * 580
|
|
|
- if len(citys)*580 > 1180 {
|
|
|
- city_Price = 1180
|
|
|
- }
|
|
|
- thisPrice = (industry_Price + city_Price) * count
|
|
|
- if unit == 1 { //年的价格是月的价格10倍
|
|
|
- thisPrice *= 10
|
|
|
- }
|
|
|
+ if cityCount == 1 { //单城市
|
|
|
+ thisPrice = getSetMealPrice(2, industryNum, unit) * count
|
|
|
+ } else { //多城市
|
|
|
+ if industryNum == 0 || industryNum == 1 { //多城市 单行业
|
|
|
+ thisPrice = cityCount * getSetMealPrice(2, industryNum, unit) * count
|
|
|
+ } else { //多行业 多行业
|
|
|
+ industryPrice := SubVipPrice.BuyerClassPrice * industryNum
|
|
|
+ cityPrice := SubVipPrice.CityPrice * cityCount
|
|
|
+ thisPrice = (industryPrice + cityPrice) * count
|
|
|
+ if unit == 1 { //年
|
|
|
+ thisPrice *= 10
|
|
|
}
|
|
|
}
|
|
|
- } else { //省
|
|
|
- thisPrice = getSetMealPrice(1, len(industry), unit) * count
|
|
|
}
|
|
|
- final_price += thisPrice
|
|
|
+ finalPrice += thisPrice
|
|
|
}
|
|
|
- return final_price
|
|
|
+ return finalPrice
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
vip订阅 套餐价格
|
|
|
c(city) 全国:0 省:1 市:2
|
|
|
-i(industry) 全行业:0 行业:1 其他:多个行业
|
|
|
+iCount(industry) 全行业:0 行业:1 其他:多个行业
|
|
|
u(unit) 年:1 月:2
|
|
|
*/
|
|
|
-func getSetMealPrice(c, i, u int) int {
|
|
|
+func getSetMealPrice(c, iCount, u int) int {
|
|
|
t := u == 2 //是否是月单位
|
|
|
- icount := 1 //行业个数
|
|
|
- if i > 1 {
|
|
|
- icount = i
|
|
|
- }
|
|
|
switch c {
|
|
|
case 0:
|
|
|
- if i == 0 {
|
|
|
+ if iCount == 0 {
|
|
|
if t {
|
|
|
- return 38800 //1月全国全行业
|
|
|
+ return SubVipPrice.Month.AllProvince_allBuyerClass // 38800 //1月全国全行业
|
|
|
}
|
|
|
- return 388000 //1年全国全行业
|
|
|
+ return SubVipPrice.Year.AllProvince_allBuyerClass // 388000 //1年全国全行业
|
|
|
} else {
|
|
|
if t {
|
|
|
- return 11800 * icount //1月全国icount个行业
|
|
|
+ return SubVipPrice.Month.AllProvince_oneBuyerClass * iCount // 11800 * iCount //1月全国icount个行业
|
|
|
}
|
|
|
- return 118000 * icount //1年全国icount个行业
|
|
|
+ return SubVipPrice.Year.AllProvince_oneBuyerClass * iCount //118000 * iCount //1年全国icount个行业
|
|
|
}
|
|
|
case 1:
|
|
|
- if i == 0 {
|
|
|
+ if iCount == 0 {
|
|
|
if t {
|
|
|
- return 3800 //1月1省全行业
|
|
|
+ return SubVipPrice.Month.OneProvince_allBuyerClass //3800 //1月1省全行业
|
|
|
}
|
|
|
- return 38000 //1年1省全行业
|
|
|
+ return SubVipPrice.Year.OneProvince_allBuyerClass //38000 //1年1省全行业
|
|
|
} else {
|
|
|
if t {
|
|
|
- return 1180 * icount //1月1省icount个行业
|
|
|
+ return SubVipPrice.Month.OneProvince_oneBuyerClass * iCount //1180 * iCount //1月1省icount个行业
|
|
|
}
|
|
|
- return 11800 * icount //1年1省icount个行业
|
|
|
+ return SubVipPrice.Year.OneProvince_oneBuyerClass * iCount //1年1省icount个行业
|
|
|
}
|
|
|
default:
|
|
|
- if i == 0 {
|
|
|
+ if iCount == 0 {
|
|
|
if t {
|
|
|
- return 1800 //1月1市全行业
|
|
|
+ return SubVipPrice.Month.OneCity_allBuyerClass //1800 //1月1市全行业
|
|
|
}
|
|
|
- return 18000 //1年1市全行业
|
|
|
+ return SubVipPrice.Year.OneCity_allBuyerClass //1年1市全行业
|
|
|
} else {
|
|
|
if t {
|
|
|
- return 580 * icount //1月1市icount个行业
|
|
|
+ return SubVipPrice.Month.OneCity_oneBuyerClass * iCount // 580 * iCount //1月1市icount个行业
|
|
|
}
|
|
|
- return 5800 * icount //1年1市icount个行业
|
|
|
+ return SubVipPrice.Year.OneCity_oneBuyerClass * iCount //5800 * iCount //1年1市icount个行业
|
|
|
}
|
|
|
}
|
|
|
}
|