xuzhiheng 5 жил өмнө
parent
commit
8079c02229

+ 140 - 39
src/jfw/modules/subscribepay/src/service/vipRenewUpgrade.go

@@ -16,7 +16,7 @@ import (
 	"util"
 
 	"github.com/go-xweb/xweb"
-	//	"gopkg.in/mgo.v2/bson"
+	"gopkg.in/mgo.v2/bson"
 )
 
 //订阅升级修改相关接口
@@ -25,6 +25,7 @@ type RenewUpgrade struct {
 	getBuyMsg               xweb.Mapper `xweb:"/renewUpgrade/getBuyMsg"`               //获取购买相关信息
 	renewUpgradeCreateOrder xweb.Mapper `xweb:"/renewUpgrade/renewUpgradeCreateOrder"` //续费升级支付
 	getExprie               xweb.Mapper `xweb:"/renewUpgrade/getExprie"`               //获取到期页面购买信息
+	zeroPay                 xweb.Mapper `xweb:"/renewUpgrade/zeroPay"`                 //升级0元支付
 }
 
 //获取购买订阅相关信息
@@ -291,46 +292,45 @@ func (this *RenewUpgrade) RenewUpgradeCreateOrder() {
 			}
 		}
 		log.Println("price", totalfee)
-		if totalfee == 0 {
-			totalfee = 1
-		}
 		//		totalfee = 1
 
 		//创建订单
 		tradeno, prepayid, payStr := "", "", ""
-		if payWay == "wx_js" { //微信js支付
-			var ret *map[string]string
-			tradeno, ret = pay.WxStruct.CreatePrepayOrder(pay.WX_SUBVIP_JSAPI, this.IP(), openId, "", totalfee)
-			if ret == nil || (*ret)["status"] != "1" {
-				errMsg := "创建微信订单出错"
-				if (*ret)["errcodedes"] != "" {
-					errMsg = (*ret)["errcodedes"]
-				} else if (*ret)["errcode"] != "" {
-					errMsg = (*ret)["errcode"]
+		if totalfee != 0 {
+			if payWay == "wx_js" { //微信js支付
+				var ret *map[string]string
+				tradeno, ret = pay.WxStruct.CreatePrepayOrder(pay.WX_SUBVIP_JSAPI, this.IP(), openId, "", totalfee)
+				if ret == nil || (*ret)["status"] != "1" {
+					errMsg := "创建微信订单出错"
+					if (*ret)["errcodedes"] != "" {
+						errMsg = (*ret)["errcodedes"]
+					} else if (*ret)["errcode"] != "" {
+						errMsg = (*ret)["errcode"]
+					}
+					return &entity.FuncResult{false, errors.New(errMsg), nil}
 				}
-				return &entity.FuncResult{false, errors.New(errMsg), nil}
-			}
-			prepayid = qutil.ObjToString((*ret)["prepayid"])
-			payStr = pay.GetWxJsPayStr(prepayid)
-		} else if payWay == "wx_app" {
-			var ret *map[string]string
-			tradeno, ret = pay.WxStruct.CreatePrepayOrder(pay.WX_SUBVIP_APP, this.IP(), openId, "", totalfee)
-			if ret == nil || (*ret)["status"] != "1" {
-				errMsg := "创建微信订单出错"
-				if (*ret)["errcodedes"] != "" {
-					errMsg = (*ret)["errcodedes"]
-				} else if (*ret)["errcode"] != "" {
-					errMsg = (*ret)["errcode"]
+				prepayid = qutil.ObjToString((*ret)["prepayid"])
+				payStr = pay.GetWxJsPayStr(prepayid)
+			} else if payWay == "wx_app" {
+				var ret *map[string]string
+				tradeno, ret = pay.WxStruct.CreatePrepayOrder(pay.WX_SUBVIP_APP, this.IP(), openId, "", totalfee)
+				if ret == nil || (*ret)["status"] != "1" {
+					errMsg := "创建微信订单出错"
+					if (*ret)["errcodedes"] != "" {
+						errMsg = (*ret)["errcodedes"]
+					} else if (*ret)["errcode"] != "" {
+						errMsg = (*ret)["errcode"]
+					}
+					return &entity.FuncResult{false, errors.New(errMsg), nil}
+				}
+				prepayid = qutil.ObjToString((*ret)["prepayid"])
+				payStr = pay.WxStruct.GetAppWxPayStr(prepayid)
+			} else { //支付宝支付
+				var err error
+				payStr, tradeno, err = pay.Alipay.GetOrderPayParam((qutil.Float64All(totalfee)), "", pay.ALI_SUBVIP_APP)
+				if err != nil {
+					return &entity.FuncResult{false, errors.New("创建支付宝订单出错"), nil}
 				}
-				return &entity.FuncResult{false, errors.New(errMsg), nil}
-			}
-			prepayid = qutil.ObjToString((*ret)["prepayid"])
-			payStr = pay.WxStruct.GetAppWxPayStr(prepayid)
-		} else { //支付宝支付
-			var err error
-			payStr, tradeno, err = pay.Alipay.GetOrderPayParam((qutil.Float64All(totalfee)), "", pay.ALI_SUBVIP_APP)
-			if err != nil {
-				return &entity.FuncResult{false, errors.New("创建支付宝订单出错"), nil}
 			}
 		}
 
@@ -362,10 +362,12 @@ func (this *RenewUpgrade) RenewUpgradeCreateOrder() {
 		if orderid == -1 {
 			return &entity.FuncResult{false, errors.New("数据库操作异常"), nil}
 		}
-		if isRenew {
-			util.MsgRemind.Add(qutil.IntAll(orderid), totalfee, 1, 0, ordercode, userId, now.Unix())
-		} else {
-			util.MsgRemind.Add(qutil.IntAll(orderid), totalfee, 2, 0, ordercode, userId, now.Unix())
+		if totalfee != 0 {
+			if isRenew {
+				util.MsgRemind.Add(qutil.IntAll(orderid), totalfee, 1, 0, ordercode, userId, now.Unix())
+			} else {
+				util.MsgRemind.Add(qutil.IntAll(orderid), totalfee, 2, 0, ordercode, userId, now.Unix())
+			}
 		}
 		return &entity.FuncResult{true, nil, map[string]interface{}{"code": ordercode, "res": payStr}}
 	}()
@@ -406,6 +408,105 @@ func (this *RenewUpgrade) GetExprie() {
 	}
 }
 
+//升级0元支付
+func (this *RenewUpgrade) ZeroPay() {
+	userId := qutil.ObjToString(this.GetSession("userId"))
+	orderCode := this.GetString("order_code")
+	now := time.Now()
+	orderdata := util.Mysql.FindOne("dataexport_order", map[string]interface{}{
+		"user_id":     userId,
+		"order_code":  orderCode,
+		"order_money": 0,
+	}, "id,filter,order_code,order_status,user_id,vip_starttime,vip_endtime,vip_type,prepay_time", "")
+	pay_time := qutil.FormatDate(&now, qutil.Date_Full_Layout)
+	if orderdata == nil {
+		log.Println("未找到订单")
+		this.ServeJson(map[string]interface{}{
+			"success": false,
+		})
+		return //未找到订单
+	}
+	order_status := qutil.IntAll((*orderdata)["order_status"])
+	if order_status == 1 {
+		this.ServeJson(map[string]interface{}{
+			"success": true,
+		})
+		return // 或已支付
+	}
+	if order_status != 0 {
+		log.Printf("%s订单状态异常%d\n", userId, order_status)
+		this.ServeJson(map[string]interface{}{
+			"success": false,
+		})
+		return
+	}
+	//计算时长
+	vmsg := entity.VipSimpleMsg{}
+	filterStr := qutil.ObjToString((*orderdata)["filter"])
+	if err := json.Unmarshal([]byte(filterStr), &vmsg); err != nil {
+		log.Printf("%s vipSubscribeStruct PayCallBack Unmarshal 出错 [%s]\n", userId, filterStr)
+		this.ServeJson(map[string]interface{}{
+			"success": false,
+		})
+		return
+	}
+	updateMap := map[string]interface{}{
+		"pay_money":    0,
+		"pay_time":     pay_time,
+		"order_status": 1,
+	}
+
+	update := util.Mysql.Update("dataexport_order", map[string]interface{}{
+		"order_status": 0,
+		"order_code":   orderCode,
+		"order_money":  0,
+	}, updateMap)
+
+	if !update {
+		log.Printf("%s更新订单状态出错%+v\n", userId, updateMap)
+		this.ServeJson(map[string]interface{}{
+			"success": false,
+		})
+		return
+	}
+
+	//	start := qutil.ObjToString((*orderdata)["vip_starttime"])
+	end := qutil.ObjToString((*orderdata)["vip_endtime"])
+	endTime, err := time.ParseInLocation(qutil.Date_Full_Layout, end, time.Local)
+	//	startTime, err := time.ParseInLocation(qutil.Date_Full_Layout, start, time.Local)
+	if err != nil {
+		log.Println("%s格式化日期出错%s\n", userId, endTime)
+		this.ServeJson(map[string]interface{}{
+			"success": false,
+		})
+		return
+	}
+
+	buyset := entity.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
+	isok := util.MQFW.UpdateById("user", userId,
+		bson.M{"$set": bson.M{
+			"o_vipjy.o_area":       vmsg.Area,     //设置地区
+			"o_vipjy.a_buyerclass": vmsg.Industry, //设置行业
+			"o_vipjy.o_buyset":     buyset,
+			"l_vip_endtime":        endTime.Unix(),
+			"i_vip_status":         2,
+			"i_vip_expire_tip":     0,
+		}})
+	this.ServeJson(map[string]interface{}{
+		"success": isok,
+	})
+	return
+}
+
 //cycleunit(1:年 2:月)
 //cyclecount 数字长度
 func checkReqDates(dateStr string) (cyclecount, cycleunit int, err error) {

+ 17 - 1
src/web/templates/weixin/vipsubscribe/vip_upgrade.html

@@ -1269,7 +1269,23 @@
 	    	console.log(param)
 	    	$DoPost("/subscribepay/renewUpgrade/renewUpgradeCreateOrder",param,function(r){
                 if(r.success){
-                    onBridgeReady(JSON.parse(r.data.res),r.data.code);
+					let finally_price = $(".finally_price").text().replace("¥","");
+					if(Number(finally_price) !== 0){
+						onBridgeReady(JSON.parse(r.data.res),r.data.code);
+					}else{
+						let orderCode = r.data.code
+						$DoPost("/subscribepay/renewUpgrade/zeroPay",{"order_code":orderCode},function(data){
+							if(data.success){
+								$("#areaUp").removeAttr("href");
+								$("#industryUp").removeAttr("href");
+								$(".save_upgrade").attr("disabled","disabled");
+								clearSessionStorage();
+								sessionStorage.To_introducePage=2;
+								sessionStorage.removeItem("historypushDataCache");
+								window.location.replace("/front/vipsubscribe/toPaySuccessPage?orderCode="+orderCode);
+							}
+						})
+					}
                 }
                 $(".save_upgrade").removeAttr("disabled");
             })