xuzhiheng 5 years ago
parent
commit
4fc208b25c

+ 83 - 1
src/jfw/modules/subscribepay/src/entity/subscribeVip.go

@@ -58,6 +58,7 @@ type VipSimpleMsg struct {
 	Industry           []string                `json:"industry"`           //行业
 	Addareacount       *map[string]interface{} `json:"addareacount"`       //新增购买区域数量
 	Addbuyerclasscount int                     `json:"addbuyerclasscount"` //新增行业数量
+	Buyset             *map[string]interface{} `json:"buyset"`             //原始信息
 	Cyclecount         int                     `json:"cyclecount"`         //日期数量
 	Cycleunit          int                     `json:"cycleunit"`          //日期单位
 	OrderType          int                     `json:"ordertype"`          //类型 1:订单 2:续费 3:立即升级 4:下月升级 5:即将到期(升降级)6:升级订单未生效再次升级
@@ -205,7 +206,17 @@ func (this *vipSubscribeStruct) UpgradeSubVip(userId string, vmsg VipSimpleMsg,
 		return false
 	}
 	if isNow {
-		buyset := JyVipSubStruct.NewBuySet(vmsg.Area, vmsg.Industry)
+		//		buyset := JyVipSubStruct.NewBuySet(vmsg.Area, vmsg.Industry)
+		buyset := SubvipBuySet{}
+		addBuyset := vmsg.Buyset
+		buyset.AreaCount = qutil.IntAll((*addBuyset)["areacount"])
+		buyset.BuyerclassCount = qutil.IntAll((*addBuyset)["buyerclasscount"])
+		cityArr := qutil.ObjToMap((*addBuyset)["citys"])
+		citys := map[string]interface{}{}
+		for cityMap, cityCount := range *cityArr {
+			citys[cityMap] = qutil.IntAll(cityCount)
+		}
+		buyset.Citys = citys
 		return util.MQFW.UpdateById("user", userId,
 			bson.M{"$set": bson.M{
 				"o_vipjy.o_area":       vmsg.Area,     //设置地区
@@ -449,6 +460,77 @@ func (this *vipSubscribeStruct) GetSubVipPrice(area *map[string]interface{}, ind
 	return payMoney
 }
 
+//计算价格
+func (this *vipSubscribeStruct) GetSubVipBuysetPrice(buyset *map[string]interface{}, count, unit int) int {
+	payMoney := func() int {
+
+		industryNum := qutil.IntAll((*buyset)["buyerclasscount"])
+		//当行业数量大于最大值SubVipPrice.BuyerClassMaxCount 按照全行业计算
+		//		industryNum := len(industry)
+		if industryNum > SubVipPrice.BuyerClassMaxCount {
+			industryNum = 0
+		}
+		//计算地区数量
+		pCount := qutil.IntAll((*buyset)["areacount"]) //省份数量
+		//		cityCountMap := map[string]int{}               //购买省份中城市数量
+
+		//当选择月份大于  按照全年计算
+		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 //全国多行业套餐
+			}
+		}
+
+		//计算非全国套餐
+		finalPrice := 0 //省份价格
+		cityCountMap := qutil.ObjToMap((*buyset)["citys"])
+		for _, cityCount := range *cityCountMap {
+			thisPrice := 0
+			//			cityCount = qutil.IntAll(cityCount)
+			if qutil.IntAll(cityCount) == 1 { //单城市
+				thisPrice = getSetMealPrice(2, industryNum, unit) * count
+			} else { //多城市
+				if industryNum == 0 || industryNum == 1 { //多城市 单行业
+					if qutil.IntAll(cityCount) > SubVipPrice.CityMaxCount {
+						pCount++
+					} else {
+						thisPrice = qutil.IntAll(cityCount) * getSetMealPrice(2, industryNum, unit) * count
+					}
+				} else { //多城市 多行业
+					if qutil.IntAll(cityCount) > SubVipPrice.CityMaxCount {
+						pCount++
+					} else {
+						thisPrice = getSetMealPrice(2, industryNum, unit) * qutil.IntAll(cityCount) * count
+					}
+				}
+			}
+			finalPrice += thisPrice
+		}
+		finalPrice += pCount * getSetMealPrice(1, industryNum, unit) * count
+		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)
+		}
+		log.Printf("进行折扣计算 折扣后金额%d\n", payMoney)
+	}
+	return payMoney
+}
+
 /*
 vip订阅 套餐价格
 c(city) 全国:0 省:1 市:2

+ 13 - 6
src/jfw/modules/subscribepay/src/service/vipRenewUpgrade.go

@@ -124,6 +124,8 @@ func (this *RenewUpgrade) RenewUpgradeCreateOrder() {
 	payWay := this.GetString("payWay")                               //支付方式
 	pay_source := this.GetString("pay_source")                       //类型  续费-Renew or 升级-Upgrade
 	addCount := this.GetString("addCount")
+	buyset := qutil.ObjToMap(this.GetString("buyset"))
+	log.Println("111", buyset)
 	var vipBuyCount *map[string]interface{}
 	if addCount != "" {
 		vipBuyCount = qutil.ObjToMap(addCount) //新增购买区域数量
@@ -193,6 +195,7 @@ func (this *RenewUpgrade) RenewUpgradeCreateOrder() {
 				industry,
 				nil,
 				0,
+				nil,
 				date_count,
 				date_unit,
 				orderType,
@@ -203,6 +206,7 @@ func (this *RenewUpgrade) RenewUpgradeCreateOrder() {
 				allIndustry,
 				vipBuyCount,
 				industryCount,
+				buyset,
 				date_count,
 				date_unit,
 				orderType,
@@ -270,17 +274,20 @@ func (this *RenewUpgrade) RenewUpgradeCreateOrder() {
 			oldPriceY := entity.JyVipSubStruct.GetSubVipPrice(areas, industrys, upgradeYear, 1)
 			oldPriceM := entity.JyVipSubStruct.GetSubVipPrice(areas, industrys, upgradeMonth, 2)
 			oldPrice := oldPriceY + oldPriceM
-			newPriceY := entity.JyVipSubStruct.GetSubVipPrice(allBuyArea, allIndustry, upgradeYear, 1)
-			newPriceM := entity.JyVipSubStruct.GetSubVipPrice(allBuyArea, allIndustry, upgradeMonth, 2)
+			//			newPriceY := entity.JyVipSubStruct.GetSubVipPrice(allBuyArea, allIndustry, upgradeYear, 1)
+			//			newPriceM := entity.JyVipSubStruct.GetSubVipPrice(allBuyArea, allIndustry, upgradeMonth, 2)
+			newPriceY := entity.JyVipSubStruct.GetSubVipBuysetPrice(buyset, upgradeYear, 1)
+			newPriceM := entity.JyVipSubStruct.GetSubVipBuysetPrice(buyset, upgradeMonth, 2)
 			newPrice := newPriceY + newPriceM
 			totalfee = newPrice - oldPrice
 			// --------升级价格差价计算--------
 			if date_unit == 1 { //升级中的延长时间
-				lengPrice := entity.JyVipSubStruct.GetSubVipPrice(allBuyArea, allIndustry, date_count, 1) //单位为年的已购+新增延长时间价格
-				totalfee = totalfee + lengPrice                                                           //已购+新增延长时间价格 + 升级差价 = 最终价格
+
+				lengPrice := entity.JyVipSubStruct.GetSubVipBuysetPrice(buyset, date_count, 1) //单位为年的已购+新增延长时间价格
+				totalfee = totalfee + lengPrice                                                //已购+新增延长时间价格 + 升级差价 = 最终价格
 			} else if date_unit == 2 {
-				lengPrice := entity.JyVipSubStruct.GetSubVipPrice(allBuyArea, allIndustry, date_count, 2) //单位为月的已购+新增延长时间价格
-				totalfee = totalfee + lengPrice                                                           //已购+新增延长时间价格 + 升级差价 = 最终价格
+				lengPrice := entity.JyVipSubStruct.GetSubVipBuysetPrice(buyset, date_count, 2) //单位为月的已购+新增延长时间价格
+				totalfee = totalfee + lengPrice                                                //已购+新增延长时间价格 + 升级差价 = 最终价格
 			}
 		}
 		log.Println("price", totalfee)

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

@@ -88,6 +88,7 @@ func (this *SubVipPayOrder) CreateOrder() {
 			industry,
 			nil,
 			0,
+			nil,
 			date_count,
 			date_unit,
 			orderType,

+ 1 - 0
src/jfw/modules/subscribepay/src/service/vipSubscribeTrial.go

@@ -286,6 +286,7 @@ func (this *TrialOrder) TrialPay() {
 			industry,
 			nil,
 			0,
+			nil,
 			date_count,
 			date_unit,
 			0,

+ 5 - 0
src/web/staticres/vipsubscribe/js/updateArea.js

@@ -706,6 +706,11 @@ $(function () {
 	
 	function showOther(){
 		let areaCount = areaData.data.buyset.areacount;
+		let areaSelect = $('.checkbox:checked:not([disabled])').length;
+		if(areaSelect === 0){
+			$(".tips_d_text").hide();
+			return
+		}
 		let showCounts = 0;
 		if(areaCount === -1){
 			$(".tips_d_text").hide();

+ 118 - 67
src/web/templates/weixin/vipsubscribe/vip_upgrade.html

@@ -743,7 +743,7 @@
         var areasArr = {};
         var areas_arr = {};
 	    var industrysArr = [];
-	    // var allArea = {};
+	    var allArea = {};
 	    var allBuyArea = {};
 	    var allIndustry = [];
 	    var nowRenew = "";
@@ -786,44 +786,48 @@
 						areas_arr = {"全国":[]};
 					}
 		    	}
-				// if(area !== ""&&area !== undefined){
-				// 	for(let province in area){
-			 //    		let citys = area[province];
-			 //    		if(citys.length===0){
-				// 			allArea[province] = [];
-			 //    		}else{
-			 //    			allArea[province] = citys;
-			 //    		}
-			 //    	}
-				// 	for(let province in vipArea){
-				// 		let citys = vipArea[province];
-				// 		if(allArea[province] === undefined){
-				// 			allArea[province] = citys
-				// 		}else{
-				// 			let cityArr = [];
-				// 			for(let i in citys){
-				// 				cityArr.push(citys[i]);
-				// 			}
-				// 			for(let i in allArea[province]){
-				// 				cityArr.push(allArea[province][i]);
-				// 			}
-				// 			//
-				// 			for (var x = 0; x < cityArr.length; x++) {
-				// 	            for (var j =x+1; j <cityArr.length; ) {
-				// 	                if (cityArr[x] === cityArr[j]){
-				// 	                    cityArr.splice(j, 1);
-				// 	                }
-				// 	                else j++;
-				// 	            }
-				// 	       	}
-				// 			//
-				// 			allArea[province] = cityArr;
-				// 		}
-				// 		if(province === "全国"){
-				// 			allArea = {"全国":[]};
-				// 		}
-				// 	}
-				// }
+				if(area !== ""&&area !== undefined){
+					for(let province in area){
+			    		let citys = area[province];
+			    		if(citys.length===0){
+							allArea[province] = [];
+			    		}else{
+			    			allArea[province] = citys;
+			    		}
+			    	}
+					for(let province in vipArea){
+						let citys = vipArea[province];
+						if(allArea[province] === undefined){
+							allArea[province] = citys
+						}else{
+							if(checkObj(citys)){
+								allArea[province] = [];
+							}else{
+								let cityArr = [];
+								for(let i in citys){
+									cityArr.push(citys[i]);
+								}
+								for(let i in allArea[province]){
+									cityArr.push(allArea[province][i]);
+								}
+								//
+								for (var x = 0; x < cityArr.length; x++) {
+								    for (var j =x+1; j <cityArr.length; ) {
+								        if (cityArr[x] === cityArr[j]){
+								            cityArr.splice(j, 1);
+								        }
+								        else j++;
+								    }
+								}
+								//
+								allArea[province] = cityArr;
+							}
+						}
+						if(province === "全国"){
+							allArea = {"全国":[]};
+						}
+					}
+				}
 				if(buyArea !== ""&&buyArea !== undefined){
 					for(let province in buyArea){
 			    		let citys = buyArea[province];
@@ -838,24 +842,28 @@
 						if(allBuyArea[province] === undefined){
 							allBuyArea[province] = citys
 						}else{
-							let cityArr = [];
-							for(let i in citys){
-								cityArr.push(citys[i]);
-							}
-							for(let i in allBuyArea[province]){
-								cityArr.push(allBuyArea[province][i]);
+							if(checkObj(citys)){
+								allBuyArea[province] = [];
+							}else{
+								let cityArr = [];
+								for(let i in citys){
+									cityArr.push(citys[i]);
+								}
+								for(let i in allBuyArea[province]){
+									cityArr.push(allBuyArea[province][i]);
+								}
+								//
+								for (var x = 0; x < cityArr.length; x++) {
+									for (var j =x+1; j <cityArr.length; ) {
+										if (cityArr[x] === cityArr[j]){
+											cityArr.splice(j, 1);
+										}
+										else j++;
+									}
+								}
+								//
+								allBuyArea[province] = cityArr;
 							}
-							//
-							for (var x = 0; x < cityArr.length; x++) {
-					            for (var j =x+1; j <cityArr.length; ) {
-					                if (cityArr[x] === cityArr[j]){
-					                    cityArr.splice(j, 1);
-					                }
-					                else j++;
-					            }
-					       	}
-							//
-							allBuyArea[province] = cityArr;
 						}
 						if(province === "全国"){
 							allBuyArea = {"全国":[]};
@@ -1031,6 +1039,7 @@
 					oldYearPrice = ((monthprice / nowUpgrade) * 10).toFixed(1);
 				}
 			} else {
+				console.log(buyArea)
 				oldPrice = getsubVipOrderPrice(buyArea, buyIndustry, [nowUpgrade, 2])
 				oldMonthPrice = (oldPrice / nowUpgrade)
 				oldYearPrice = ((oldPrice / nowUpgrade) * 10).toFixed(1);
@@ -1062,10 +1071,15 @@
 				// price = addAreaPriceY + addAreaPriceM + oldAreaPriceY + oldAreaPriceM + addIndustryPriceY + addIndustryPriceM;
 				// ------- 升级价格交叉计算 ---------
 				// ------- 升级价格差价计算 ---------
-				let newPriceY = getsubVipOrderPrice(allBuyArea,allIndustry,[nowUpgradeYear,1]);
-				let newPriceM = getsubVipOrderPrice(allBuyArea,allIndustry,[nowUpgrade,2]);
-				let yearprice = getsubVipOrderPrice(allBuyArea,allIndustry,[nowUpgradeYear,1]);
-				let monthprice = getsubVipOrderPrice(allBuyArea,allIndustry,[nowUpgrade,2]);
+				let buyset = getBuySet(buyArea,buyIndustry)
+				// let newPriceY = getsubVipOrderPrice(allBuyArea,allIndustry,[nowUpgradeYear,1]);
+				// let newPriceM = getsubVipOrderPrice(allBuyArea,allIndustry,[nowUpgrade,2]);
+				// let yearprice = getsubVipOrderPrice(allBuyArea,allIndustry,[nowUpgradeYear,1]);
+				// let monthprice = getsubVipOrderPrice(allBuyArea,allIndustry,[nowUpgrade,2]);
+				let newPriceY = getsubVipOrderPriceBybuyset(areaObj(),[nowUpgradeYear,1]);
+				let newPriceM = getsubVipOrderPriceBybuyset(areaObj(),[nowUpgrade,2]);
+				let yearprice = getsubVipOrderPriceBybuyset(areaObj(),[nowUpgradeYear,1]);
+				let monthprice = getsubVipOrderPriceBybuyset(areaObj(),[nowUpgrade,2]);
 				price = newPriceY + newPriceM - oldPrice;
 				// ------- 升级延长周期价格计算 ---------
 				if(monthprice === 0){
@@ -1095,10 +1109,13 @@
 				// }
 				// price = addAreaPriceM + oldAreaPriceM + addIndustryPriceM;
 				// // ------- 升级价格交叉计算 ---------
-				let monthprice = getsubVipOrderPrice(allBuyArea,allIndustry,[nowUpgrade,2]);
+				// let monthprice = getsubVipOrderPrice(allBuyArea,allIndustry,[nowUpgrade,2]);
+				let monthprice = getsubVipOrderPriceBybuyset(areaObj(),[nowUpgrade,2]);
 				
 				// ------- 升级价格差价计算 ---------
-				let newPrice = getsubVipOrderPrice(allBuyArea,allIndustry,[nowUpgrade,2]);
+				
+				// let newPrice = getsubVipOrderPrice(allBuyArea,allIndustry,[nowUpgrade,2]);
+				let newPrice = getsubVipOrderPriceBybuyset(areaObj(),[nowUpgrade,2]);
 				price = newPrice - oldPrice;
 				// ------- 升级价格差价计算 ---------
 				// ------- 升级延长周期价格计算 ---------
@@ -1202,11 +1219,10 @@
             //
             let areaarr = buyArea;
         	let industryarr = buyIndustry;
-        	// let allAreaArr = allArea;
         	let allIndustryArr = allIndustry;
-        	// if(allAreaArr["全国"]){
-         //        allAreaArr={};
-         //    }
+        	if(allArea["全国"]){
+                allArea={};
+            }
         	if(allIndustryArr.length==1&&allIndustryArr[0]=="全部行业"){
                 allIndustryArr=[];
             }
@@ -1239,12 +1255,13 @@
 	    		"industryarr": industryarr.join(","),
 	    		// "allArea": JSON.stringify(allAreaArr),
 	    		"allIndustry": allIndustryArr.join(","),
-	    		"allBuyArea": JSON.stringify(allBuyArea),
+	    		"allBuyArea": JSON.stringify(allArea),
 	    		"payWay": "wx_js",
 	    		"pay_source" : "Upgrade",
 	    		"time": times,
 	    		"addCount":vipCount,
 	    		"addIndustryCount": vipIndustry,
+				"buyset":JSON.stringify(areaObj()),
 	    	}
 	    	console.log(param)
 	    	$DoPost("/subscribepay/renewUpgrade/renewUpgradeCreateOrder",param,function(r){
@@ -1326,6 +1343,40 @@
 	//     	}
 	//     	return areasObj
 	//     }
+	function areaObj(){
+		let buyset = getBuySet(buyArea,buyIndustry)
+		if(sessionStorage.vipSubSelectAreaAdd!==undefined&&sessionStorage.vipSubSelectAreaAdd!==""){
+			let addbuyset = JSON.parse(sessionStorage.vipSubSelectAreaAdd);
+			if(addbuyset.country !== -1){
+				if(addbuyset.province !== 0){
+					buyset.areacount = buyset.areacount + addbuyset.province;
+				}
+				if(!checkObj(addbuyset.city)){
+					let cityArr = addbuyset.city
+					for(var i in cityArr){
+						let citysArr = buyset.citys
+						if(citysArr[i] !== undefined){
+							citysArr[i] = citysArr[i] + cityArr[i]
+						}else{
+							citysArr[i] = cityArr[i];
+						}
+					}
+				}
+			}else{
+				buyset.areacount = -1;
+				buyset.citys = {};
+			}
+		}
+		if(sessionStorage.vipSubSelectIndustryAdd!==undefined){
+			var addindustrys = JSON.parse(sessionStorage.vipSubSelectIndustryAdd);
+			if(addindustrys.length === 1 && addindustrys[0] === "全部行业"){
+				buyset.buyerclasscount = -1;
+			}else{
+				buyset.buyerclasscount = buyset.buyerclasscount + addindustrys.length;
+			}
+		}
+		return buyset
+	}
 	    
     </script>
 </body>