|
@@ -40,32 +40,49 @@ func (this *SubVipPayOrder) GetSelectPrice() {
|
|
|
area := qutil.ObjToMap(this.GetString("area")) //地区
|
|
|
timeRenew := this.GetString("time") //周期
|
|
|
orderType, _ := this.GetInteger("orderType") //1 购买;2 续费;3 升级
|
|
|
- totalPrice := 0
|
|
|
+ // 原价;订单价
|
|
|
+ original_price, order_price := 0, 0
|
|
|
userMsg := jy.GetBigVipUserBaseMsg(userId, util.Mysql, util.MQFW)
|
|
|
if (userMsg.VipStatus > 0 && orderType == 1) || (userMsg.VipStatus <= 0 && (orderType == 3 || orderType == 2)) {
|
|
|
return &entity.FuncResult{false, errors.New("参数异常"), nil}
|
|
|
} else if userMsg.VipStatus <= 0 && orderType == 1 { //购买价格
|
|
|
- // now := time.Now()
|
|
|
date_count, date_unit, err := checkReqDate(timeRenew)
|
|
|
if err != nil {
|
|
|
return &entity.FuncResult{false, err, nil}
|
|
|
}
|
|
|
buyset := entity.JyVipSubStruct.NewBuySet(area, nil, true) //改版后只能购买升级版超级订阅
|
|
|
//计算价格
|
|
|
- totalPrice = entity.JyVipSubStruct.GetSubVipPrice(buyset, date_count, date_unit)
|
|
|
- } else if userMsg.VipStatus > 0 && orderType == 3 { //升级价格(升级只升级地区)
|
|
|
+ original_price = entity.JyVipSubStruct.GetSubVipPrice(buyset, date_count, date_unit)
|
|
|
+ } else if userMsg.VipStatus > 0 { //2:续费价格(只延长时间);3:升级价格(升级只升级地区)
|
|
|
rData, oldBuyset, _ := entity.JyVipSubStruct.GetVipDetail(userId)
|
|
|
- endUnix := qutil.Int64All((*rData)["l_vip_endtime"])
|
|
|
- newBuyset := entity.JyVipSubStruct.NewBuySet(area, nil, true) //改版后只能购买升级版超级订阅
|
|
|
- //升级校验
|
|
|
- totalPrice, _ = getNewUpgradeDetail(userId, newBuyset, oldBuyset, endUnix, 0, 0)
|
|
|
- if totalPrice < 0 {
|
|
|
- if totalPrice == -1 {
|
|
|
- return &entity.FuncResult{false, errors.New("不能升级此状态"), nil}
|
|
|
- } else {
|
|
|
- return &entity.FuncResult{false, errors.New("查询续费订单出错"), nil}
|
|
|
+ switch orderType {
|
|
|
+ case 2:
|
|
|
+ now := time.Now()
|
|
|
+ date_count, date_unit, err := checkReqDate(timeRenew)
|
|
|
+ if err != nil {
|
|
|
+ return &entity.FuncResult{false, err, nil}
|
|
|
+ }
|
|
|
+ endUnix := qutil.Int64All((*rData)["l_vip_endtime"])
|
|
|
+ isTrail := qutil.IntAll((*rData)["i_vip_status"]) == 1
|
|
|
+ if time.Date(now.Year(), now.Month(), now.Day(), 23, 59, 59, 59, now.Location()).
|
|
|
+ AddDate(3, 0, 0).Before(util.GetDATE(date_unit, date_count, endUnix)) && !isTrail {
|
|
|
+ return &entity.FuncResult{false, errors.New("订阅周期超过三年"), nil}
|
|
|
+ }
|
|
|
+ original_price = entity.JyVipSubStruct.GetSubVipPriceByBuySet(oldBuyset, date_count, date_unit, false)
|
|
|
+ case 3:
|
|
|
+ endUnix := qutil.Int64All((*rData)["l_vip_endtime"])
|
|
|
+ newBuyset := entity.JyVipSubStruct.NewBuySet(area, nil, true) //改版后只能购买升级版超级订阅
|
|
|
+ //升级校验
|
|
|
+ original_price, _ = getNewUpgradeDetail(userId, newBuyset, oldBuyset, endUnix, 0, 0)
|
|
|
+ if original_price < 0 {
|
|
|
+ if original_price == -1 {
|
|
|
+ return &entity.FuncResult{false, errors.New("不能升级此状态"), nil}
|
|
|
+ } else {
|
|
|
+ return &entity.FuncResult{false, errors.New("查询续费订单出错"), nil}
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
//卡卷信息的id
|
|
|
lotteryId := this.GetString("lotteryId")
|
|
@@ -78,19 +95,23 @@ func (this *SubVipPayOrder) GetSelectPrice() {
|
|
|
full_price, reduce_price := 0, 0
|
|
|
var discount float64
|
|
|
full_price, reduce_price, discount, _ = util.GetCouponInfo(userId, lotteryId, products)
|
|
|
- if full_price <= totalPrice {
|
|
|
+ if full_price <= original_price {
|
|
|
if discount == 100 { //满减
|
|
|
- totalPrice = totalPrice - reduce_price
|
|
|
+ order_price = original_price - reduce_price
|
|
|
} else { //满折
|
|
|
disCount_int := int(math.Ceil(discount * 100))
|
|
|
- totalPrice = totalPrice * disCount_int / 1000
|
|
|
+ order_price = original_price * disCount_int / 1000
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- return &entity.FuncResult{true, nil, map[string]interface{}{"price": totalPrice}}
|
|
|
+ return &entity.FuncResult{true, nil, map[string]interface{}{
|
|
|
+ "original_price": original_price,
|
|
|
+ "order_price": order_price,
|
|
|
+ },
|
|
|
+ }
|
|
|
}()
|
|
|
if r.Err != nil {
|
|
|
- log.Printf("%s CreateOrder err:%v\n", userId, r.Err.Error())
|
|
|
+ log.Printf("%s 价格计算 err:%v\n", userId, r.Err.Error())
|
|
|
}
|
|
|
this.ServeJson(r.Format())
|
|
|
}
|