|
@@ -1,563 +0,0 @@
|
|
|
-package service
|
|
|
-
|
|
|
-import (
|
|
|
- "encoding/json"
|
|
|
- "entity"
|
|
|
- "errors"
|
|
|
- "log"
|
|
|
- "math"
|
|
|
- qutil "qfw/util"
|
|
|
- // "strings"
|
|
|
- "fmt"
|
|
|
- "pay"
|
|
|
- "strconv"
|
|
|
- "strings"
|
|
|
- "time"
|
|
|
- "util"
|
|
|
-
|
|
|
- "github.com/go-xweb/xweb"
|
|
|
- "gopkg.in/mgo.v2/bson"
|
|
|
-)
|
|
|
-
|
|
|
-//订阅升级修改相关接口
|
|
|
-type RenewUpgrade struct {
|
|
|
- *xweb.Action
|
|
|
- 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元支付
|
|
|
-}
|
|
|
-
|
|
|
-//获取购买订阅相关信息
|
|
|
-func (this *RenewUpgrade) GetBuyMsg() {
|
|
|
- userId := qutil.ObjToString(this.GetSession("userId"))
|
|
|
- r := func() *entity.FuncResult {
|
|
|
- if userId == "" {
|
|
|
- return &entity.FuncResult{false, errors.New("未登录"), nil}
|
|
|
- }
|
|
|
- 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"]
|
|
|
- starttime := qutil.Int64All((*data)["l_vip_starttime"])
|
|
|
- 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")
|
|
|
- vipStatus := (*data)["i_vip_status"]
|
|
|
- buyset := vipjy["o_buyset"]
|
|
|
- //
|
|
|
- var orderCode interface{}
|
|
|
- orderdata := util.Mysql.FindOne("dataexport_order", map[string]interface{}{
|
|
|
- "user_id": userId,
|
|
|
- "order_status": 1,
|
|
|
- "product_type": "VIP订阅",
|
|
|
- }, "order_code", "create_time desc")
|
|
|
- if len(*orderdata) > 0 && *orderdata != nil {
|
|
|
- orderCode = (*orderdata)["order_code"]
|
|
|
- }
|
|
|
- dataArr := map[string]interface{}{
|
|
|
- "area": area,
|
|
|
- "buyerclass": buyerclass,
|
|
|
- "starttime": starttime,
|
|
|
- "endtime": endtime,
|
|
|
- "start": start,
|
|
|
- "end": end,
|
|
|
- "now": now,
|
|
|
- "vipStatus": vipStatus,
|
|
|
- "buyset": buyset,
|
|
|
- "orderCode": orderCode,
|
|
|
- }
|
|
|
- return &entity.FuncResult{true, nil, dataArr}
|
|
|
- } else {
|
|
|
- return &entity.FuncResult{false, errors.New("非法请求"), nil}
|
|
|
- }
|
|
|
- }()
|
|
|
- if r.Err != nil {
|
|
|
- log.Printf("%s CreateOrder err:%v\n", userId, r.Err.Error())
|
|
|
- }
|
|
|
- this.ServeJson(r.Format())
|
|
|
-}
|
|
|
-
|
|
|
-//升级续费
|
|
|
-//创建订单返回支付串
|
|
|
-func (this *RenewUpgrade) RenewUpgradeCreateOrder() {
|
|
|
- allBuyArea := qutil.ObjToMap(this.GetString("allBuyArea")) //已购+新增区域
|
|
|
- allIndustry := strings.Split(this.GetString("allIndustry"), ",") //已购+新增行业
|
|
|
- date := this.GetString("time") //不延长时为空,正常为 年或月
|
|
|
- payWay := this.GetString("payWay") //支付方式
|
|
|
- pay_source := this.GetString("pay_source") //类型 续费-Renew or 升级-Upgrade
|
|
|
- addCount := this.GetString("addCount")
|
|
|
- buyset := qutil.ObjToMap(this.GetString("buyset"))
|
|
|
- log.Println("111", buyset)
|
|
|
- var vipBuyCount *map[string]interface{}
|
|
|
- if addCount != "" {
|
|
|
- vipBuyCount = qutil.ObjToMap(addCount) //新增购买区域数量
|
|
|
- } else {
|
|
|
- vipBuyCount = &map[string]interface{}{}
|
|
|
- }
|
|
|
- industryCount, _ := this.GetInteger("addIndustryCount") //新增购买行业数量
|
|
|
- userId := qutil.ObjToString(this.GetSession("userId"))
|
|
|
- openId := qutil.ObjToString(this.GetSession("s_m_openid"))
|
|
|
- r := func() *entity.FuncResult {
|
|
|
- if userId == "" {
|
|
|
- return &entity.FuncResult{false, errors.New("未登录"), nil}
|
|
|
- }
|
|
|
- now := time.Now()
|
|
|
- //数据校验
|
|
|
- if len(allIndustry) == 1 && allIndustry[0] == "" { //去掉[""]
|
|
|
- allIndustry = []string{}
|
|
|
- }
|
|
|
- if !(pay_source == "Renew" || pay_source == "Upgrade") {
|
|
|
- return &entity.FuncResult{false, errors.New("未知操作"), nil}
|
|
|
- }
|
|
|
- if !(payWay == "wx_js" || payWay == "wx_app" || payWay == "ali_app") {
|
|
|
- return &entity.FuncResult{false, errors.New("未知支付"), nil}
|
|
|
- }
|
|
|
-
|
|
|
- date_count, date_unit, err := checkReqDates(date)
|
|
|
- if err != nil {
|
|
|
- if pay_source == "Renew" { //续费 日期不能为空
|
|
|
- return &entity.FuncResult{false, err, nil}
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- res, ok := util.MQFW.FindById("user", userId, `{"l_vip_endtime":1,"l_vip_starttime":1,"o_vipjy":1,i_vip_status:1}`)
|
|
|
- if res == nil || len(*res) == 0 || !ok {
|
|
|
- return &entity.FuncResult{false, errors.New("数据库操作异常"), nil}
|
|
|
- }
|
|
|
-
|
|
|
- vipStatus := qutil.IntAll((*res)["i_vip_status"])
|
|
|
- if vipStatus == 1 {
|
|
|
- return &entity.FuncResult{false, errors.New("试用用户不可升级或续费"), nil}
|
|
|
- }
|
|
|
- start := qutil.Int64All((*res)["l_vip_starttime"])
|
|
|
- end := qutil.Int64All((*res)["l_vip_endtime"])
|
|
|
- vipjy := (*res)["o_vipjy"].(map[string]interface{})
|
|
|
- oldBuy := vipjy["o_buyset"]
|
|
|
- oldBuyset := oldBuy.(map[string]interface{})
|
|
|
- log.Println("old", oldBuyset)
|
|
|
- if start == 0 || end == 0 {
|
|
|
- return &entity.FuncResult{false, errors.New("数据异常"), nil}
|
|
|
- }
|
|
|
- startTime := time.Unix(start, 0)
|
|
|
- endTime := time.Unix(end, 0)
|
|
|
- orderType := 0
|
|
|
- isRenew := true
|
|
|
- if pay_source == "Upgrade" { //计算升级时间
|
|
|
- isRenew = false
|
|
|
- orderType = 3
|
|
|
- startTime = time.Now()
|
|
|
- } else { //续费时间
|
|
|
- orderType = 2 //续费操作
|
|
|
- startTime = endTime
|
|
|
- }
|
|
|
- if date_unit >= 1 {
|
|
|
- endTime = util.GetDATE(date_unit, date_count, end)
|
|
|
- }
|
|
|
- filter := entity.VipSimpleMsg{}
|
|
|
- if pay_source == "Renew" {
|
|
|
- areaMap := qutil.ObjToMap(vipjy["o_area"])
|
|
|
- industryMap := qutil.ObjArrToStringArr(vipjy["a_buyerclass"].([]interface{}))
|
|
|
- filter = entity.VipSimpleMsg{
|
|
|
- areaMap,
|
|
|
- industryMap,
|
|
|
- nil,
|
|
|
- 0,
|
|
|
- &oldBuyset,
|
|
|
- date_count,
|
|
|
- date_unit,
|
|
|
- orderType,
|
|
|
- }
|
|
|
- } else if pay_source == "Upgrade" {
|
|
|
- filter = entity.VipSimpleMsg{
|
|
|
- allBuyArea,
|
|
|
- allIndustry,
|
|
|
- vipBuyCount,
|
|
|
- industryCount,
|
|
|
- buyset,
|
|
|
- date_count,
|
|
|
- date_unit,
|
|
|
- orderType,
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- mog_id := entity.JyVipSubStruct.SaveSelectLog(userId, openId, &filter)
|
|
|
- if mog_id == "" {
|
|
|
- return &entity.FuncResult{false, errors.New("创建订单出错"), nil}
|
|
|
- }
|
|
|
-
|
|
|
- //计算价格
|
|
|
- var totalfee int
|
|
|
- if pay_source == "Renew" {
|
|
|
- cityArr := qutil.ObjToMap(oldBuyset["citys"])
|
|
|
- citysArr := map[string]int{}
|
|
|
- for k, v := range *cityArr {
|
|
|
- citysArr[k] = qutil.IntAll(v)
|
|
|
- }
|
|
|
- pCount := qutil.IntAll(oldBuyset["areacount"])
|
|
|
- iCount := qutil.IntAll(oldBuyset["buyerclasscount"])
|
|
|
- //
|
|
|
- totalfee = entity.JyVipSubStruct.GetSubVipPriceByBuySet(citysArr, pCount, iCount, date_count, date_unit, true)
|
|
|
- } else if pay_source == "Upgrade" {
|
|
|
- upgradeYear, upgradeMonth := MaxUpgradeMonth(end) //获取最大升级月数
|
|
|
- //
|
|
|
- cityArr := qutil.ObjToMap(oldBuyset["citys"])
|
|
|
- citysArr := map[string]int{}
|
|
|
- for k, v := range *cityArr {
|
|
|
- citysArr[k] = qutil.IntAll(v)
|
|
|
- }
|
|
|
- pCount := qutil.IntAll(oldBuyset["areacount"])
|
|
|
- iCount := qutil.IntAll(oldBuyset["buyerclasscount"])
|
|
|
- //
|
|
|
- newCityArr := qutil.ObjToMap((*buyset)["citys"])
|
|
|
- newCitysArr := map[string]int{}
|
|
|
- newPCount := qutil.IntAll((*buyset)["areacount"])
|
|
|
- newICount := qutil.IntAll((*buyset)["buyerclasscount"])
|
|
|
- for c, y := range *newCityArr {
|
|
|
- newCitysArr[c] = qutil.IntAll(y)
|
|
|
- }
|
|
|
- //------校验buyset、区域、行业是否异常
|
|
|
- upgradeBuyset := entity.JyVipSubStruct.NewBuySet(allBuyArea, allIndustry)
|
|
|
- log.Println("upgradeBuyset", upgradeBuyset)
|
|
|
- if newICount != -1 {
|
|
|
- if newICount < iCount {
|
|
|
- return &entity.FuncResult{false, errors.New("非法请求"), nil}
|
|
|
- }
|
|
|
- //行业是否异常
|
|
|
- if upgradeBuyset.BuyerclassCount > newICount || upgradeBuyset.BuyerclassCount == -1 {
|
|
|
- return &entity.FuncResult{false, errors.New("非法请求"), nil}
|
|
|
- }
|
|
|
- }
|
|
|
- if newPCount != -1 {
|
|
|
- if newPCount < pCount {
|
|
|
- return &entity.FuncResult{false, errors.New("非法请求"), nil}
|
|
|
- }
|
|
|
- //区域是否异常
|
|
|
- if upgradeBuyset.AreaCount == -1 {
|
|
|
- return &entity.FuncResult{false, errors.New("非法请求"), nil}
|
|
|
- }
|
|
|
- }
|
|
|
- //------校验buyset、区域、行业是否异常
|
|
|
-
|
|
|
- //
|
|
|
- oldPriceY := entity.JyVipSubStruct.GetSubVipPriceByBuySet(citysArr, pCount, iCount, upgradeYear, 1, false)
|
|
|
- oldPriceM := entity.JyVipSubStruct.GetSubVipPriceByBuySet(citysArr, pCount, iCount, upgradeMonth, 2, false)
|
|
|
- oldPrice := oldPriceY + oldPriceM
|
|
|
- //
|
|
|
- newPriceY := entity.JyVipSubStruct.GetSubVipPriceByBuySet(newCitysArr, newPCount, newICount, upgradeYear, 1, false)
|
|
|
- newPriceM := entity.JyVipSubStruct.GetSubVipPriceByBuySet(newCitysArr, newPCount, newICount, upgradeMonth, 2, false)
|
|
|
- newPrice := newPriceY + newPriceM
|
|
|
- //
|
|
|
- totalfee = newPrice - oldPrice
|
|
|
- // --------升级价格差价计算--------
|
|
|
- if date_unit == 1 { //升级中的延长时间
|
|
|
- lengPrice := entity.JyVipSubStruct.GetSubVipPriceByBuySet(newCitysArr, newPCount, newICount, date_count, 1, true) //单位为年的已购+新增延长时间价格
|
|
|
- totalfee = totalfee + lengPrice //已购+新增延长时间价格 + 升级差价 = 最终价格
|
|
|
- } else if date_unit == 2 {
|
|
|
- lengPrice := entity.JyVipSubStruct.GetSubVipPriceByBuySet(newCitysArr, newPCount, newICount, date_count, 2, true) //单位为月的已购+新增延长时间价格
|
|
|
- totalfee = totalfee + lengPrice //已购+新增延长时间价格 + 升级差价 = 最终价格
|
|
|
- }
|
|
|
- }
|
|
|
- //log.Println("price", totalfee)
|
|
|
- //tmp := float64(totalfee) * 0.000001
|
|
|
- //if tmp < 1 {
|
|
|
- // if tmp != 0 {
|
|
|
- // totalfee = 1
|
|
|
- // }
|
|
|
- //}
|
|
|
- log.Println("price", totalfee)
|
|
|
-
|
|
|
- //创建订单
|
|
|
- tradeno, prepayid, payStr := "", "", ""
|
|
|
- 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}
|
|
|
- }
|
|
|
- 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}
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- filterStr, _ := json.Marshal(filter)
|
|
|
- ordercode := pay.GetOrderCode(userId)
|
|
|
- insertMap := map[string]interface{}{
|
|
|
- "order_money": totalfee,
|
|
|
- "order_status": 0,
|
|
|
- "user_nickname": qutil.ObjToString(this.GetSession("s_nickname")),
|
|
|
- "user_openid": openId,
|
|
|
- "prepay_id": prepayid,
|
|
|
- "code_url": payStr,
|
|
|
- "out_trade_no": tradeno,
|
|
|
- "order_code": ordercode,
|
|
|
- "product_type": "VIP订阅",
|
|
|
- "create_time": qutil.FormatDate(&now, qutil.Date_Full_Layout),
|
|
|
- "prepay_time": qutil.FormatDate(&now, qutil.Date_Full_Layout),
|
|
|
- "original_price": totalfee,
|
|
|
- "filter_id": mog_id,
|
|
|
- "pay_way": payWay,
|
|
|
- "user_id": userId,
|
|
|
- "filter": string(filterStr), //筛选
|
|
|
- "vip_starttime": qutil.FormatDate(&startTime, qutil.Date_Full_Layout),
|
|
|
- "vip_endtime": qutil.FormatDate(&endTime, qutil.Date_Full_Layout),
|
|
|
- "vip_type": qutil.If(isRenew, 1, 2),
|
|
|
- }
|
|
|
-
|
|
|
- orderid := util.Mysql.Insert("dataexport_order", insertMap)
|
|
|
- if orderid == -1 {
|
|
|
- return &entity.FuncResult{false, errors.New("数据库操作异常"), nil}
|
|
|
- }
|
|
|
- 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}}
|
|
|
- }()
|
|
|
- if r.Err != nil {
|
|
|
- log.Printf("%s CreateOrder err:%v\n", userId, r.Err.Error())
|
|
|
- }
|
|
|
- this.ServeJson(r.Format())
|
|
|
-}
|
|
|
-
|
|
|
-//获取到期页面购买信息
|
|
|
-func (this *RenewUpgrade) GetExprie() {
|
|
|
- userId := qutil.ObjToString(this.GetSession("userId"))
|
|
|
- data, ok := util.MQFW.FindById("user", userId, nil)
|
|
|
- vipStatus := 0
|
|
|
- if ok && len(*data) > 0 && *data != nil {
|
|
|
- vipStatus = qutil.IntAll((*data)["i_vip_status"])
|
|
|
- }
|
|
|
- orderId := this.GetString("orderId")
|
|
|
- orderdata := util.Mysql.FindOne("dataexport_order", map[string]interface{}{
|
|
|
- "id": orderId,
|
|
|
- "user_id": userId,
|
|
|
- }, "filter,order_code", "")
|
|
|
- vmsg := entity.VipSimpleMsg{}
|
|
|
- if orderdata != nil && len(*orderdata) > 0 {
|
|
|
- filterStr := qutil.ObjToString((*orderdata)["filter"])
|
|
|
- if err := json.Unmarshal([]byte(filterStr), &vmsg); err != nil {
|
|
|
- log.Printf("%s vipSubscribeStruct PayCallBack Unmarshal 出错 [%s]\n", filterStr)
|
|
|
- return
|
|
|
- }
|
|
|
- dataArr := map[string]interface{}{
|
|
|
- "area": vmsg.Area,
|
|
|
- "buyerclass": vmsg.Industry,
|
|
|
- "orderCode": (*orderdata)["order_code"],
|
|
|
- "vipStatus": vipStatus,
|
|
|
- }
|
|
|
- log.Println(dataArr)
|
|
|
- this.ServeJson(dataArr)
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-//升级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) {
|
|
|
- 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))
|
|
|
-}
|
|
|
-
|
|
|
-//获取最大升级月数
|
|
|
-func MaxUpgradeMonth(endTime int64) (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
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //
|
|
|
- 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
|
|
|
-}
|