wangkaiyue il y a 5 ans
Parent
commit
888f13e6c7

+ 76 - 61
src/jfw/modules/subscribepay/src/entity/subscribeVip.go

@@ -41,13 +41,14 @@ type subVipPrice struct {
 		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"`      //月份可计价最大数量
+	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"`      //月份可计价最大数量
+	Discount           float64 `json:"discount"`           //折扣(测试使用)
 }
 
 //订单简单信息
@@ -345,73 +346,87 @@ func (this *vipSubscribeStruct) SaveSelectLog(userId, openId string, msg *VipSim
 
 //计算价格
 func (this *vipSubscribeStruct) GetSubVipPrice(area *map[string]interface{}, industry []string, count, unit int) int {
-	//当行业数量大于最大值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 {
+	payMoney := func() int {
+		//当行业数量大于最大值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 {
-					cityCountMap[k] = len(tmp)
+				} else { //城市
+					//当城市数量大于最大值时,按照全省计算
+					if len(tmp) > SubVipPrice.CityMaxCount {
+						pCount++
+					} else {
+						cityCountMap[k] = len(tmp)
+					}
 				}
 			}
 		}
-	}
 
-	//当省份数量大于SubVipPrice.ProvinceMaxCount 按照全国计算
-	if pCount > SubVipPrice.ProvinceMaxCount {
-		pCount = -1
-	}
+		//当省份数量大于SubVipPrice.ProvinceMaxCount 按照全国计算
+		if pCount > SubVipPrice.ProvinceMaxCount {
+			pCount = -1
+		}
 
-	//当选择月份大于  按照全年计算
-	if count > SubVipPrice.MonthMaxCount && unit == 2 { //月份十个月以上价格一样
-		count = 10
-	}
+		//当选择月份大于  按照全年计算
+		if count > SubVipPrice.MonthMaxCount && unit == 2 { //月份十个月以上价格一样
+			count = 10
+		}
 
-	if pCount == -1 { //计算全国套餐价格
-		if industryNum == 1 {
-			return getSetMealPrice(0, 1, unit) * count //全国1行业套餐
-		} else if industryNum == 0 {
-			return getSetMealPrice(0, 0, unit) * count //全国全行业套餐
-		} else {
-			return getSetMealPrice(0, industryNum, unit) * count //全国多行业套餐
+		if pCount == -1 { //计算全国套餐价格
+			if industryNum == 1 {
+				return getSetMealPrice(0, 1, unit) * count //全国1行业套餐
+			} else if industryNum == 0 {
+				return getSetMealPrice(0, 0, unit) * count //全国全行业套餐
+			} else {
+				return getSetMealPrice(0, industryNum, unit) * count //全国多行业套餐
+			}
 		}
-	}
 
-	//计算非全国套餐
-	finalPrice := pCount * getSetMealPrice(1, industryNum, unit) * count //省份价格
-	for _, cityCount := range cityCountMap {
-		thisPrice := 0
-		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
+		//计算非全国套餐
+		finalPrice := pCount * getSetMealPrice(1, industryNum, unit) * count //省份价格
+		for _, cityCount := range cityCountMap {
+			thisPrice := 0
+			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
+					}
 				}
 			}
+			finalPrice += thisPrice
+		}
+		return finalPrice
+	}()
+	if SubVipPrice.Discount < 1 {
+		//测试环境修改金额
+		log.Printf("进行折扣计算 折扣前金额%d\n", payMoney)
+		tmp := float64(payMoney) * SubVipPrice.Discount
+		if tmp < 1 {
+			payMoney = 1
+		} else {
+			payMoney = int(tmp)
 		}
-		finalPrice += thisPrice
+		log.Printf("进行折扣计算 折扣后金额%d\n", payMoney)
 	}
-	return finalPrice
+	return payMoney
 }
 
 /*

+ 0 - 2
src/jfw/modules/subscribepay/src/service/vipSubscribePay.go

@@ -75,8 +75,6 @@ func (this *SubVipPayOrder) CreateOrder() {
 		}
 		//计算价格
 		totalfee := entity.JyVipSubStruct.GetSubVipPrice(area, industry, date_count, date_unit)
-		log.Println("totalfee",totalfee)
-		//totalfee := 1
 		//创建订单
 		tradeno, prepayid, payStr := "", "", ""
 		if payWay == "wx_js" { //微信js支付

+ 2 - 1
src/jfw/modules/subscribepay/src/subvip_price.json

@@ -21,5 +21,6 @@
   "cityMaxCount": 2,
   "provinceMaxCount": 9,
   "buyerClassMaxCount": 3,
-  "monthMaxCount": 9
+  "monthMaxCount": 9,
+  "discount": 1
 }