xuzhiheng 5 anni fa
parent
commit
4f9c0113f9
1 ha cambiato i file con 31 aggiunte e 22 eliminazioni
  1. 31 22
      src/jfw/modules/subscribepay/src/service/vipRenewUpgrade.go

+ 31 - 22
src/jfw/modules/subscribepay/src/service/vipRenewUpgrade.go

@@ -68,14 +68,14 @@ func (this *RenewUpgrade) GetBuyMsg() {
 //升级续费
 //创建订单返回支付串
 func (this *RenewUpgrade) RenewUpgradeCreateOrder() {
-	area := qutil.ObjToMap(this.GetString("area"))
-	industry := strings.Split(this.GetString("industry"), ",")
-	areas := qutil.ObjToMap(this.GetString("areas"))
-	industrys := strings.Split(this.GetString("industrys"), ",")
-	date := this.GetString("time") //
-	payWay := this.GetString("payWay")
-	effect := this.GetString("effect")         //升级 生效日期 Now  下月一号的时间戳
-	pay_source := this.GetString("pay_source") //类型  Renew or Upgrade
+	area := qutil.ObjToMap(this.GetString("area"))               //已购买区域+新增区域
+	industry := strings.Split(this.GetString("industry"), ",")   //已购买行业+新增行业
+	areas := qutil.ObjToMap(this.GetString("areas"))             //已购买区域
+	industrys := strings.Split(this.GetString("industrys"), ",") //已购买行业
+	date := this.GetString("time")                               //不延长时为空,正常为 年或月
+	payWay := this.GetString("payWay")                           //支付方式
+	effect := this.GetString("effect")                           //升级 生效日期 立即生效-now  下月一号生效-下月一号的时间戳
+	pay_source := this.GetString("pay_source")                   //类型  续费-Renew or 升级-Upgrade
 	userId := qutil.ObjToString(this.GetSession("userId"))
 	openId := qutil.ObjToString(this.GetSession("s_m_openid"))
 	r := func() *entity.FuncResult {
@@ -132,6 +132,14 @@ func (this *RenewUpgrade) RenewUpgradeCreateOrder() {
 		} else if date_unit == 2 { //月
 			endTime = endTime.AddDate(0, date_count, 0)
 		}
+		if pay_source == "Renew" && now.Unix() > end { //到期后的续费从当前时间往后延长
+			startTime = now
+			if date_unit == 1 { ///延长时间
+				endTime = startTime.AddDate(date_count, 0, 0)
+			} else if date_unit == 2 { //月
+				endTime = startTime.AddDate(0, date_count, 0)
+			}
+		}
 		filter := entity.VipSimpleMsg{
 			area,
 			industry,
@@ -148,24 +156,24 @@ func (this *RenewUpgrade) RenewUpgradeCreateOrder() {
 		if pay_source == "Renew" {
 			totalfee = entity.JyVipSubStruct.GetSubVipPrice(area, industry, date_count, date_unit)
 		} else if pay_source == "Upgrade" {
-			upgradeYear, upgradeMonth := MaxUpgradeMonth(end, effect)
-			addY := entity.JyVipSubStruct.GetSubVipPrice(area, industry, upgradeYear, 1)
-			addM := entity.JyVipSubStruct.GetSubVipPrice(area, industry, upgradeMonth, 2)
-			addPrice := addM + addY
-			nowY := entity.JyVipSubStruct.GetSubVipPrice(areas, industrys, upgradeYear, 1)
-			nowM := entity.JyVipSubStruct.GetSubVipPrice(areas, industrys, upgradeMonth, 2)
-			nowPrice := nowM + nowY
-			totalfee = addPrice - nowPrice
-			if date_unit == 1 { //延长时间
-				lengPrice := entity.JyVipSubStruct.GetSubVipPrice(area, industry, date_count, 1)
-				totalfee = totalfee + lengPrice
+			upgradeYear, upgradeMonth := MaxUpgradeMonth(end, effect)                       //获取最大升级月数
+			addY := entity.JyVipSubStruct.GetSubVipPrice(area, industry, upgradeYear, 1)    //已购+新增,以年为单位的价格
+			addM := entity.JyVipSubStruct.GetSubVipPrice(area, industry, upgradeMonth, 2)   //已购+新增,以月为单位的价格
+			addPrice := addM + addY                                                         //已购+新增总价格
+			nowY := entity.JyVipSubStruct.GetSubVipPrice(areas, industrys, upgradeYear, 1)  //已购,以年为单位的价格
+			nowM := entity.JyVipSubStruct.GetSubVipPrice(areas, industrys, upgradeMonth, 2) //已购,以月为单位的价格
+			nowPrice := nowM + nowY                                                         //已购总价格
+			totalfee = addPrice - nowPrice                                                  //已购+新增的总价格 - 已购总价格 = 升级差价
+			if date_unit == 1 {                                                             //升级中的延长时间
+				lengPrice := entity.JyVipSubStruct.GetSubVipPrice(area, industry, date_count, 1) //单位为年的已购+新增延长时间价格
+				totalfee = totalfee + lengPrice                                                  //已购+新增延长时间价格 + 升级差价 = 最终价格
 			} else if date_unit == 2 {
-				lengPrice := entity.JyVipSubStruct.GetSubVipPrice(area, industry, date_count, 2)
-				totalfee = totalfee + lengPrice
+				lengPrice := entity.JyVipSubStruct.GetSubVipPrice(area, industry, date_count, 2) //单位为月的已购+新增延长时间价格
+				totalfee = totalfee + lengPrice                                                  //已购+新增延长时间价格 + 升级差价 = 最终价格
 			}
 		}
 		log.Println("price", totalfee)
-		totalfee = 1
+		totalfee = 1 //设置测试价格为0.01
 
 		//创建订单
 		tradeno, prepayid, payStr := "", "", ""
@@ -257,6 +265,7 @@ func checkReqDates(dateStr string) (cyclecount, cycleunit int, err error) {
 	return -1, -1, errors.New(fmt.Sprintf("日期%s格式化出错", dateStr))
 }
 
+//获取最大升级月数
 func MaxUpgradeMonth(endTime int64, effect string) (int, int) {
 	endYear := time.Unix(endTime, 0).Year()
 	endMonth := int(time.Unix(endTime, 0).Month())