xuzhiheng 5 years ago
parent
commit
55ecef85ea

+ 2 - 2
src/jfw/front/vipsubscribe.go

@@ -31,13 +31,13 @@ type Subscribepay struct {
 	submitEditSub     xweb.Mapper `xweb:"/front/vipsubscribe/submitEditSub"`     //提交订阅收费
 
 	//升级
-	toUpgradePage xweb.Mapper `xweb:"/front/vipsubscribe/toUpgradePage"`           //订阅收费升级服务页面
+	toUpgradePage xweb.Mapper `xweb:"/weixin/pay/toUpgradePage"`                   //订阅收费升级服务页面
 	addArea       xweb.Mapper `xweb:"/front/vipsubscribe/toChooseAreaUpgrade"`     //订阅收费升级新增区域页面
 	addIndustry   xweb.Mapper `xweb:"/front/vipsubscribe/toChooseIndustryUpgrade"` //订阅收费升级新增行业页面
 
 	//续费
 	renewPage    xweb.Mapper `xweb:"/front/vipsubscribe/renewPage/(.*)"` //订阅到期(will:即将到期,exprie:已到期)
-	renewPayPage xweb.Mapper `xweb:"/front/vipsubscribe/renewPayPage"`   //订阅到期续费
+	renewPayPage xweb.Mapper `xweb:"/weixin/pay/renewPayPage"`           //订阅到期续费
 
 	//发票
 	openInvoice xweb.Mapper `xweb:"/front/vipsubscribe/openInvoice/(\\w+)"` //开发票

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

@@ -22,6 +22,7 @@ type VipSimpleMsg struct {
 	Industry   []string                `json:"industry"`
 	Cyclecount int                     `json:"cyclecount"`
 	Cycleunit  int                     `json:"cycleunit"`
+	PaySource  string                  `json:"paysource"`
 }
 
 //支付完成回调

+ 110 - 21
src/jfw/modules/subscribepay/src/service/vipRenewUpgrade.go

@@ -7,7 +7,9 @@ import (
 	"log"
 	qutil "qfw/util"
 	//	"strings"
+	"fmt"
 	"pay"
+	"strconv"
 	"strings"
 	"time"
 	"util"
@@ -38,6 +40,7 @@ func (this *RenewUpgrade) GetBuyMsg() {
 		start := time.Unix(starttime, 0).Format("2006-01-02")
 		endtime := qutil.Int64All((*data)["l_vip_endtime"])
 		end := time.Unix(endtime, 0).Format("2006-01-02")
+		now := time.Unix(time.Now().Unix(), 0).Format("2006-01-02")
 		areaArr := qutil.ObjToMap(area)
 		buyerclassArr := qutil.ObjArrToStringArr(buyerclass.([]interface{}))
 		monthprice := entity.JyVipSubStruct.GetSubVipPrice(areaArr, buyerclassArr, 1, 2)
@@ -54,6 +57,7 @@ func (this *RenewUpgrade) GetBuyMsg() {
 			"endtime":    endtime,
 			"start":      start,
 			"end":        end,
+			"now":        now,
 			"monthprice": float64(monthprice) / 100,
 			"yearprice":  float64(yearprice) / 100,
 		}
@@ -121,6 +125,8 @@ func (this *RenewUpgrade) RenewUpgradeCreateOrder() {
 	industry := strings.Split(this.GetString("industry"), ",")
 	date := this.GetString("time")
 	payWay := this.GetString("payWay")
+	effect := this.GetString("effect")
+	pay_source := this.GetString("pay_source")
 	userId := qutil.ObjToString(this.GetSession("userId"))
 	openId := qutil.ObjToString(this.GetSession("s_m_openid"))
 	r := func() *entity.FuncResult {
@@ -132,27 +138,64 @@ func (this *RenewUpgrade) RenewUpgradeCreateOrder() {
 		if !(payWay == "wx_js" || payWay == "wx_app" || payWay == "ali_app") {
 			return &entity.FuncResult{false, errors.New("未知支付"), nil}
 		}
-		date_count, date_unit, err := checkReqDate(date)
-		if err != nil {
-			return &entity.FuncResult{false, err, nil}
+		var date_count int
+		var date_unit int
+		var pro_count int
+		var pro_unit int
+		var err error
+		if effect != "" {
+			if date != "" {
+				pro_count, pro_unit, err = checkReqDates(date)
+				if err != nil {
+					return &entity.FuncResult{false, err, nil}
+				}
+			}
+		} else {
+			date_count, date_unit, err = checkReqDates(date)
+			if err != nil {
+				return &entity.FuncResult{false, err, nil}
+			}
 		}
+		log.Println("effect", effect)
+		log.Println("pay_source", pay_source)
+		log.Println("pro_count", pro_count)
+		log.Println("pro_unit", pro_unit)
+		log.Println("effect", effect)
 		log.Println(area, industry, date, payWay)
-		//插入订单表
-		mog_id := util.MQFW.Save("subvip_select", map[string]interface{}{
-			"o_area":       area,     //地区(对象)
-			"a_industry":   industry, //行业(数组)
-			"s_userid":     userId,
-			"s_openid":     openId,
-			"i_cyclecount": date_count, //时长
-			"i_cycleunit":  date_unit,  //单位
-			"i_comeintime": now.Unix(),
-		})
+		mog_id := ""
+		if effect != "" {
+			//插入订单表
+			mog_id = util.MQFW.Save("subvip_select", map[string]interface{}{
+				"o_area":       area,     //地区(对象)
+				"a_industry":   industry, //行业(数组)
+				"s_userid":     userId,
+				"s_openid":     openId,
+				"i_comeintime": now.Unix(),
+			})
+		} else {
+			mog_id = util.MQFW.Save("subvip_select", map[string]interface{}{
+				"o_area":       area,     //地区(对象)
+				"a_industry":   industry, //行业(数组)
+				"s_userid":     userId,
+				"s_openid":     openId,
+				"i_cyclecount": date_count, //时长
+				"i_cycleunit":  date_unit,  //单位
+				"i_comeintime": now.Unix(),
+			})
+		}
+
 		if mog_id == "" {
 			return &entity.FuncResult{false, errors.New("创建订单出错"), nil}
 		}
 		//计算价格
-		//totalfee := entity.GetSubVipPrice(area, industry, date_count, date_unit)
-		totalfee := 1
+		var totalfee int
+		if effect != "" {
+			totalfee = qutil.IntAll(this.GetString("price")) * 100
+		} else {
+			totalfee = entity.JyVipSubStruct.GetSubVipPrice(area, industry, date_count, date_unit)
+		}
+		log.Println("price", totalfee)
+
 		//创建订单
 		tradeno, prepayid, payStr := "", "", ""
 
@@ -185,13 +228,27 @@ func (this *RenewUpgrade) RenewUpgradeCreateOrder() {
 			prepayid = qutil.ObjToString((*ret)["prepayid"])
 			payStr = pay.WxStruct.GetAppWxPayStr(prepayid)
 		}
-		filter := entity.VipSimpleMsg{
-			mog_id,
-			area,
-			industry,
-			date_count,
-			date_unit,
+		var filter interface{}
+		if effect != "" {
+			filter = VipSimpleMsg{
+				mog_id,
+				area,
+				industry,
+				pay_source,
+				pro_count,
+				pro_unit,
+			}
+		} else {
+			filter = entity.VipSimpleMsg{
+				mog_id,
+				area,
+				industry,
+				date_count,
+				date_unit,
+				pay_source,
+			}
 		}
+
 		filterStr, _ := json.Marshal(filter)
 		ordercode := pay.GetOrderCode(userId)
 		orderid := util.Mysql.Insert("dataexport_order", map[string]interface{}{
@@ -222,3 +279,35 @@ func (this *RenewUpgrade) RenewUpgradeCreateOrder() {
 	}
 	this.ServeJson(r.Format())
 }
+
+//cycleunit(1:年 2:月)
+//cyclecount 数字长度
+func checkReqDates(dateStr string) (cyclecount, cycleunit int, err error) {
+	if strings.HasSuffix(dateStr, "年") {
+		cycleunit = 1
+		dateStr = strings.Replace(dateStr, "年", "", -1)
+		cyclecount, err = strconv.Atoi(dateStr)
+		if cyclecount > 3 && err == nil {
+			err = errors.New(fmt.Sprintf("日期%s返回超出最大值", dateStr))
+		}
+		return
+	} else if strings.HasSuffix(dateStr, "月") {
+		cycleunit = 2
+		dateStr = strings.Replace(dateStr, "个月", "", -1)
+		cyclecount, err = strconv.Atoi(dateStr)
+		if cyclecount > 12 && err == nil {
+			err = errors.New(fmt.Sprintf("日期%s范围超出最大值", dateStr))
+		}
+		return
+	}
+	return -1, -1, errors.New(fmt.Sprintf("日期%s格式化出错", dateStr))
+}
+
+type VipSimpleMsg struct {
+	Id            string                  `json:"_id"`
+	Area          *map[string]interface{} `json:"area"`
+	Industry      []string                `json:"industry"`
+	PaySource     string                  `json:"paysource"`
+	ProCyclecount int                     `json:"procyclecount"`
+	ProCycleunit  int                     `json:"procycleunit"`
+}

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

@@ -104,6 +104,7 @@ func (this *SubVipPayOrder) CreateOrder() {
 			industry,
 			date_count,
 			date_unit,
+			"open",
 		}
 		filterStr, _ := json.Marshal(filter)
 		ordercode := pay.GetOrderCode(userId)

+ 71 - 5
src/web/templates/weixin/vipsubscribe/renew_pay.html

@@ -48,7 +48,7 @@
                             </p>
                             <p>
                                 <!-- 正常点击vip首页续费进入显示去升级,即将到期点击vip首页续费显示订阅修改 -->
-                                <a href="/front/vipsubscribe/toUpgradePage" class="go_update renew_upgrade">去升级</a>
+                                <a href="/weixin/pay/toUpgradePage" class="go_update renew_upgrade">去升级</a>
                                 <a href="/front/vipsubscribe/toEditSubPage" class="go_update renew_update">订阅修改</a>
                             </p>
                         </div>
@@ -199,6 +199,7 @@
     <script src="/vipsubscribe/js/common.js"></script>
     <script src="/vipsubscribe/js/fastclick.js?v={{Msg "seo" "version"}}"></script>
     <script src="https://res.wx.qq.com/open/libs/weuijs/1.1.4/weui.min.js?v={{Msg "seo" "version"}}"></script>
+    {{include "/common/weixin.html"}}
     <script type="text/javascript">
     	try{
 			var signature = {{.T.signature}};
@@ -238,7 +239,6 @@
   				function(r){
 				    if(r.err_msg == "get_brand_wcpay_request:ok"){
 						setTimeout(function(){
-							
 							window.location.replace("/front/vipsubscribe/toPaySuccessPage?orderCode="+ordercode);
 						},500)
 					}else if(r.err_msg == "get_brand_wcpay_request:cancel"){               
@@ -261,6 +261,15 @@
 		}
     </script>
     <script>
+    	// 当续费时间 + 当前已经买的时间超过36个月,给出提醒
+//      var overtimeWarning = `最长订阅周期不可超过3年<br />当前订阅周期:16个月`
+//      weui.toast(overtimeWarning, {
+//          duration: 3000,
+//          className: 'custom-toast',
+//          callback: function() {
+//              console.log('close') 
+//          }
+//      })
         // 隐藏dialog选择框
         function hideDialog() {
             $('#pay_way').hide(200);
@@ -339,6 +348,9 @@
                     .numboxStep;
             }
             $number.text(currentNum)
+            if(currentNum >= 10){
+            	currentNum = 10;
+            }
             var price = (monthPrice * currentNum).toFixed(1);
             $('.computed_price').html('¥' + price)
             var firstButton = $('#number_box_month button:first')
@@ -382,6 +394,7 @@
             let val = $('.month_number').text();
             if (val >= 10) {
                 $('.profit_tips').show()
+                val = 10;
             }
 //          console.log(val)
             if (!isChecked) {
@@ -449,6 +462,7 @@
 	    var ends = "";
 	    var monthPrice = "";
 	    var yearPrice = "";
+	    //
 	    $DoPost("/subscribepay/renewUpgrade/getBuyMsg", {}, function (data) {
             if (data) {
                 area = data.area;
@@ -527,6 +541,50 @@
 			 	var cityLen = cityArr.length;
 		    }
         }, false);
+        //
+        var nowDate = new Date().toLocaleDateString();
+		nowDate = nowDate.split("/");
+		var nowMonth = Number(nowDate[1]);
+		var nowYear = Number(nowDate[0]);
+		var nowDay = Number(nowDate[2]);
+		//
+		var endDate = new Date(endTime).toLocaleDateString();
+		endDate = endDate.split("/");
+		var endMonth = Number(endDate[1]);
+		var endYear = Number(endDate[0]);
+		var endDay = Number(endDate[2]);
+		var nowUpgrade = 0;
+		if(endYear === nowYear){
+			if(endMonth === nowMonth){
+				nowUpgrade = 1;
+			}else{
+				if(endDay > nowDay){
+					nowUpgrade = endMonth - nowMonth +1;
+				}else{
+					nowUpgrade = endMonth - nowMonth;
+				}
+			}
+		}else{
+			if(endMonth === nowMonth){
+				if(endDay <= nowDay){
+					nowUpgrade = (endYear - nowYear) * 12;
+				}else{
+					nowUpgrade = (endYear - nowYear) * 12 +1;
+				}
+			}else if(endMonth > nowMonth){
+				if(endDay <= nowDay){
+					nowUpgrade = (endYear - nowYear) * 12 + (endMonth - nowMonth);
+				}else{
+					nowUpgrade = (endYear - nowYear) * 12 + (endMonth - nowMonth)+1;
+				}
+			}else{
+				if(endDay <= nowDay){
+					nowUpgrade = (endYear - nowYear-1) * 12 + (12-nowMonth+endMonth);
+				}else{
+					nowUpgrade = (endYear - nowYear-1) * 12 + (12-nowMonth+endMonth)+1;
+				}
+			}
+		}
 	    //
 	    if(sessionStorage.renew_cyclecount!==""&&sessionStorage.renew_cycleunit!==""){
 	 		var cycleunit = sessionStorage.renew_cycleunit;
@@ -558,15 +616,23 @@
 	    	$(".finally_price").html(sessionStorage.renew_finally_price);
 	    	$(".save_renew").removeAttr("disabled");
 	    }
-	    
 	    //
 	    $(".save_renew").on("click", function(){
 	    	var param = {
-	    		"area": area,
+	    		"area": JSON.stringify(area),
 	    		"industry": buyerclass.toString(),
 	    		"time": $('.choose_item.select_cycle .info').attr('placeholder'),
-	    		"payWay":"wx_js"
+	    		"payWay":"wx_js",
+	    		"pay_source": "Renew",
 	    	}
+	    	console.log(param)
+	    	$DoPost("/subscribepay/renewUpgrade/renewUpgradeCreateOrder",param,function(r){
+                if(r.success){
+//                  clearSessionStorage();
+                    onBridgeReady(JSON.parse(r.data.res),r.data.code);
+                }
+                $("#payHandle").removeAttr("disabled")  
+            })
 	    });
 	    
     </script>

+ 3 - 3
src/web/templates/weixin/vipsubscribe/vip_index.html

@@ -119,13 +119,13 @@
                 <div>
                     <i class="icon iconfont" id="close_renew">&#xe61a;</i>
                     <span>VIP订阅服务还有 <span class="renew_day"></span> 天到期,请及时续费!</span>
-                    <a href="/front/vipsubscribe/renewPayPage">去续费</a>
+                    <a href="/weixin/pay/renewPayPage">去续费</a>
                 </div>
             </div>
             <!-- 升级 续费 -->
             <div class="tabbar">
-                <a href="/front/vipsubscribe/toUpgradePage" class="update_btn">升级</a>
-                <a href="/front/vipsubscribe/renewPayPage" class="renew_btn">续费</a>
+                <a href="/weixin/pay/toUpgradePage" class="update_btn">升级</a>
+                <a href="/weixin/pay/renewPayPage" class="renew_btn">续费</a>
             </div>
         </div>
         <!-- 自动续费关闭提醒 -->

+ 69 - 4
src/web/templates/weixin/vipsubscribe/vip_upgrade.html

@@ -235,7 +235,7 @@
                         <label class="weui-cell weui-check__label now_label" for="nowTime">
                             <div class="weui-cell__bd read">
                                 <p class="effective_name now">立即生效,需支付当月费用差价</p>
-                                <p class="effective_time">2019.08.23 - 2020.06.06</p>
+                                <p class="effective_time nownow">2019.08.23 - 2020.06.06</p>
                             </div>
                             <div class="weui-cell__hd">
                                 <input type="radio" class="weui-check" name="date" value="立即生效,需支付当月费用差价" id="nowTime" checked />
@@ -245,7 +245,7 @@
                         <label class="weui-cell weui-check__label next_label" for="nextMonth">
                             <div class="weui-cell__bd read">
                                 <p class="effective_name notnow"></p>
-                                <p class="effective_time">2019.09.01 - 2020.06.06</p>
+                                <p class="effective_time notnownow">2019.09.01 - 2020.06.06</p>
                             </div>
                             <div class="weui-cell__hd">
                                 <input type="radio" class="weui-check" name="date" value="" id="nextMonth" />
@@ -294,6 +294,7 @@
     <script src="/vipsubscribe/js/fastclick.js?v={{Msg "seo" "version"}}"></script>
     <script src="/vipsubscribe/js/weui.min.js?v={{Msg "seo" "version"}}"></script>
     <script src="/vipsubscribe/js/common.js?v={{Msg "seo" "version"}}"></script>
+    {{include "/common/weixin.html"}}
     <script type="text/javascript">
     	try{
 			var signature = {{.T.signature}};
@@ -332,6 +333,7 @@
   				},
   				function(r){
 				    if(r.err_msg == "get_brand_wcpay_request:ok"){
+				    	//
 						setTimeout(function(){
 							window.location.replace("/front/vipsubscribe/toPaySuccessPage?orderCode="+ordercode);
 						},500)
@@ -393,6 +395,9 @@
         })
         //
 		var effectiveName = new Date().getMonth()+2;
+		if(effectiveName > 12){
+	    	effectiveName = effectiveName - 12
+	   	}
 		var effectiveNames = effectiveName+"月1日生效"
 		$(".effective_name.notnow").text(effectiveNames);
 		$('#nextMonth').val(effectiveNames);
@@ -403,6 +408,9 @@
             $('#effective_date').hide(200);
             var effective = "";
             var effectiveName = new Date().getMonth()+2;
+            if(effectiveName > 12){
+	    		effectiveName = effectiveName - 12
+	    	}
             var effectiveNames = effectiveName+"月1日生效"
             if(checkValue === "立即生效,需支付当月费用差价"){
             	effective = "now";
@@ -584,6 +592,9 @@
             $('#time_cycle').hide(function () { 
                 $('.choose_item.lengthen .info').text(val)
             })
+            var proPrice = $(".computed_price").html().replace("¥","")
+            sessionStorage.proPrice = proPrice;
+            window.location.reload();
         })
         //新增区域
 	    if(sessionStorage.vipSubSelectArea!==""&&sessionStorage.vipSubSelectArea!==undefined){
@@ -645,6 +656,9 @@
 	    		effectiveHtml = "立即生效,需支付当月费用差价";
 	    	}else if(effective === "notnow"){
 	    		var effectiveName = new Date().getMonth()+2;
+	    		if(effectiveName > 12){
+	    			effectiveName = effectiveName - 12
+	    		}
 	    		effectiveHtml = effectiveName+"月1日生效";
 	    	}
 	    	$(".effective_name").each(function(){
@@ -770,6 +784,12 @@
 		//	    	$(".item_industry .label_for").text(buyerclassHtml);
 					$('#buyerclass').val(buyerclassHtml);
 			    }
+			    //
+			    var nowDate = data.now.replace(/-/g, ".");
+			    var a = nowDate+ " - " +endTime
+			    console.log(a)
+			    $(".nownow").text(nowDate+ " - " +endTime)
+			    
 			}
         },false);
         //
@@ -777,9 +797,9 @@
         var completeYear = 0;
         var oldYearPrice = 0;
         var oldMonthPrice = 0;
+        var areasArr = {};
+	    var industrysArr = [];
         function FinallyPrice(){
-        	var areasArr = {};
-	    	var industrysArr = [];
 	    	var nowUpgrade = "";
 			//
 			var nowDate = new Date().toLocaleDateString();
@@ -957,10 +977,55 @@
 			console.log("oldPrice", oldPrice);
 			var cPrice = (price - oldPrice).toFixed(1);
 			console.log(cPrice);
+			if(sessionStorage.proPrice!==""&&sessionStorage.proPrice!==undefined){
+				let proPrice = sessionStorage.proPrice;
+				console.log("proprice",proPrice);
+				cPrice = (Number(cPrice) + Number(proPrice)).toFixed(1);
+			}
 			$(".finally_price").html("¥"+cPrice);
 			$(".save_upgrade").removeAttr('disabled');
         }
         FinallyPrice();
+        
+        //
+        $(".save_upgrade").on("click", function(){
+        	let effective = $("#effect_date_name").text();
+        	var effect = "now";
+        	if(effective !== "立即生效,需支付当月费用差价"){
+        		effect = "notnow";
+        	}
+        	let areas = areasArr;
+        	let industrys = industrysArr;
+        	if(areas["全国"]){
+                areas={};
+            }
+            if(industrys.length==1&&industrys[0]=="全部行业"){
+                industrys=[];
+            }
+            let renew_time = $('.choose_item.lengthen .info').text();
+            let times = "";
+            if(renew_time !== "不延长"){
+            	times = $('.choose_item.lengthen .info').text();
+            }
+            let price = $(".finally_price").html().replace("¥","");
+	    	var param = {
+	    		"area": JSON.stringify(areas),
+	    		"industry": industrys.join(","),
+	    		"payWay": "wx_js",
+	    		"effect": effect,
+	    		"pay_source" : "Upgrade",
+	    		"time": times,
+	    		"price": Number(price),
+	    	}
+	    	console.log(param)
+	    	$DoPost("/subscribepay/renewUpgrade/renewUpgradeCreateOrder",param,function(r){
+                if(r.success){
+//                  clearSessionStorage();
+                    onBridgeReady(JSON.parse(r.data.res),r.data.code);
+                }
+                $("#payHandle").removeAttr("disabled");
+            })
+	    });
     </script>
 </body>