|
@@ -5,6 +5,7 @@ import (
|
|
|
"entity"
|
|
|
"errors"
|
|
|
"log"
|
|
|
+ "math"
|
|
|
qutil "qfw/util"
|
|
|
// "strings"
|
|
|
"fmt"
|
|
@@ -22,7 +23,6 @@ import (
|
|
|
type RenewUpgrade struct {
|
|
|
*xweb.Action
|
|
|
getBuyMsg xweb.Mapper `xweb:"/renewUpgrade/getBuyMsg"` //获取购买相关信息
|
|
|
- getRenewUpgradePrice xweb.Mapper `xweb:"/renewUpgrade/getRenewUpgradePrice"` //获取价格
|
|
|
renewUpgradeCreateOrder xweb.Mapper `xweb:"/renewUpgrade/renewUpgradeCreateOrder"` //续费升级支付
|
|
|
}
|
|
|
|
|
@@ -65,80 +65,27 @@ func (this *RenewUpgrade) GetBuyMsg() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func (this *RenewUpgrade) GetRenewUpgradePrice() {
|
|
|
- years, _ := this.GetInteger("nowUpgradeYear")
|
|
|
- months, _ := this.GetInteger("nowUpgrade")
|
|
|
- log.Println("years", years)
|
|
|
- log.Println("months", months)
|
|
|
- var price int
|
|
|
- userId := qutil.ObjToString(this.GetSession("userId"))
|
|
|
- data, ok := util.MQFW.FindById("user", userId, nil)
|
|
|
- if ok && len(*data) > 0 && *data != nil {
|
|
|
- vipjy := (*data)["o_vipjy"].(map[string]interface{})
|
|
|
- area := vipjy["o_area"]
|
|
|
- buyerclass := vipjy["a_buyerclass"]
|
|
|
- //
|
|
|
- areaArr := qutil.ObjToMap(area)
|
|
|
- buyerclassArr := qutil.ObjArrToStringArr(buyerclass.([]interface{}))
|
|
|
- var completeMonth = 0
|
|
|
- var completeYear = 0
|
|
|
- if years >= 1 {
|
|
|
- monthprice := entity.JyVipSubStruct.GetSubVipPrice(areaArr, buyerclassArr, months, 2)
|
|
|
- yearprice := entity.JyVipSubStruct.GetSubVipPrice(areaArr, buyerclassArr, years, 1)
|
|
|
- price = yearprice + monthprice
|
|
|
- if monthprice == 0 {
|
|
|
- completeMonth = ((yearprice / years) / 10)
|
|
|
- completeYear = (yearprice / years)
|
|
|
- } else {
|
|
|
- completeMonth = (monthprice / months)
|
|
|
- completeYear = ((monthprice / months) * 10)
|
|
|
- }
|
|
|
- log.Println("yearprice", yearprice)
|
|
|
- log.Println("monthprice", monthprice)
|
|
|
- log.Println("price", price)
|
|
|
- } else {
|
|
|
- price = entity.JyVipSubStruct.GetSubVipPrice(areaArr, buyerclassArr, months, 2)
|
|
|
- completeMonth = (price / months)
|
|
|
- completeYear = ((price / months) * 10)
|
|
|
- log.Println("price111", price)
|
|
|
- }
|
|
|
- oldPrice := float32(price) / 100
|
|
|
- log.Println("price", oldPrice)
|
|
|
- log.Println("completeMonth", float32(completeMonth)/100)
|
|
|
- log.Println("completeYear", float32(completeYear)/100)
|
|
|
-
|
|
|
- dataArr := map[string]interface{}{
|
|
|
- "oldprice": oldPrice,
|
|
|
- "oldyearprice": float32(completeYear) / 100,
|
|
|
- "oldmonthprice": float32(completeMonth) / 100,
|
|
|
- }
|
|
|
- this.ServeJson(dataArr)
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
//升级续费
|
|
|
//创建订单返回支付串
|
|
|
func (this *RenewUpgrade) RenewUpgradeCreateOrder() {
|
|
|
- area := qutil.ObjToMap(this.GetString("area"))
|
|
|
- industry := strings.Split(this.GetString("industry"), ",")
|
|
|
- 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"))
|
|
|
- endtime := this.GetString("endtime")
|
|
|
- log.Println("endtime", endtime)
|
|
|
r := func() *entity.FuncResult {
|
|
|
now := time.Now()
|
|
|
//数据校验
|
|
|
- if len(industry) == 1 { //去掉[""]
|
|
|
- for _, i := range industry {
|
|
|
- if i == "" {
|
|
|
- industry = []string{}
|
|
|
- }
|
|
|
- }
|
|
|
+ if len(industry) == 1 && industry[0] == "" { //去掉[""]
|
|
|
+ industry = []string{}
|
|
|
+ }
|
|
|
+ if len(industrys) == 1 && industrys[0] == "" { //去掉[""]
|
|
|
+ industrys = []string{}
|
|
|
}
|
|
|
if !(pay_source == "Renew" || pay_source == "Upgrade") {
|
|
|
return &entity.FuncResult{false, errors.New("未知操作"), nil}
|
|
@@ -181,9 +128,17 @@ func (this *RenewUpgrade) RenewUpgradeCreateOrder() {
|
|
|
startTime = endTime
|
|
|
}
|
|
|
if date_unit == 1 { ///延长时间
|
|
|
- endTime = startTime.AddDate(date_count, 0, 0)
|
|
|
+ endTime = endTime.AddDate(date_count, 0, 0)
|
|
|
} else if date_unit == 2 { //月
|
|
|
- endTime = startTime.AddDate(0, date_count, 0)
|
|
|
+ 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,
|
|
@@ -197,14 +152,28 @@ func (this *RenewUpgrade) RenewUpgradeCreateOrder() {
|
|
|
return &entity.FuncResult{false, errors.New("创建订单出错"), nil}
|
|
|
}
|
|
|
//计算价格
|
|
|
- /*var totalfee int
|
|
|
- if effect != "" {
|
|
|
- totalfee = qutil.IntAll(this.GetString("price")) * 100
|
|
|
- } else {
|
|
|
+ var totalfee int
|
|
|
+ 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 //已购+新增延长时间价格 + 升级差价 = 最终价格
|
|
|
+ } else if date_unit == 2 {
|
|
|
+ lengPrice := entity.JyVipSubStruct.GetSubVipPrice(area, industry, date_count, 2) //单位为月的已购+新增延长时间价格
|
|
|
+ totalfee = totalfee + lengPrice //已购+新增延长时间价格 + 升级差价 = 最终价格
|
|
|
+ }
|
|
|
}
|
|
|
- log.Println("price", totalfee)*/
|
|
|
- totalfee := 1
|
|
|
+ log.Println("price", totalfee)
|
|
|
+ totalfee = 1 //设置测试价格为0.01
|
|
|
|
|
|
//创建订单
|
|
|
tradeno, prepayid, payStr := "", "", ""
|
|
@@ -295,3 +264,66 @@ 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())
|
|
|
+ endDay := time.Unix(endTime, 0).Day()
|
|
|
+ nowYear := time.Now().Year()
|
|
|
+ nowMonth := int(time.Now().Month())
|
|
|
+ nowDay := time.Now().Day()
|
|
|
+ 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 effect != "now" {
|
|
|
+ nowUpgrade = nowUpgrade - 1
|
|
|
+ }
|
|
|
+ if nowUpgrade == 0 {
|
|
|
+ nowUpgrade = 1
|
|
|
+ }
|
|
|
+ //
|
|
|
+ var nowUpgradeYear = 0
|
|
|
+ if nowUpgrade >= 12 {
|
|
|
+ nowUpgradeYear = int(math.Floor(float64(nowUpgrade) / float64(12)))
|
|
|
+ nowUpgrade = nowUpgrade - 12
|
|
|
+ } else if nowUpgrade >= 24 {
|
|
|
+ nowUpgradeYear = int(math.Floor(float64(nowUpgrade) / float64(12)))
|
|
|
+ nowUpgrade = nowUpgrade - 24
|
|
|
+ }
|
|
|
+ if nowUpgrade >= 10 {
|
|
|
+ nowUpgradeYear = nowUpgradeYear + 1
|
|
|
+ nowUpgrade = 0
|
|
|
+ }
|
|
|
+ return nowUpgradeYear, nowUpgrade
|
|
|
+}
|