|
@@ -18,405 +18,114 @@ type vipSubscribeStruct struct{}
|
|
|
|
|
|
var JyVipSubStruct vipSubscribeStruct
|
|
|
|
|
|
+//订单简单信息
|
|
|
type VipSimpleMsg struct {
|
|
|
- Id string `json:"_id"`
|
|
|
- Area *map[string]interface{} `json:"area"`
|
|
|
- Industry []string `json:"industry"`
|
|
|
- Cyclecount int `json:"cyclecount"`
|
|
|
- Cycleunit int `json:"cycleunit"`
|
|
|
- Paysource string `json:"paysource"`
|
|
|
- Endtime string `json:"endtime"`
|
|
|
- Effect string `json:"effect"`
|
|
|
+ //Id string `json:"_id"` //mgo id
|
|
|
+ Area *map[string]interface{} `json:"area"` //地区
|
|
|
+ Industry []string `json:"industry"` //行业
|
|
|
+ Cyclecount int `json:"cyclecount"` //日期数量
|
|
|
+ Cycleunit int `json:"cycleunit"` //日期单位
|
|
|
+ OrderType int `json:"ordertype"` //类型 1:订单 2:续费 3:立即升级 4:下月升级
|
|
|
+}
|
|
|
+
|
|
|
+//购买内容
|
|
|
+type SubvipBuySet struct {
|
|
|
+ AreaCount int `json:"areaCount"` //-1 全国 >0 省份数量
|
|
|
+ Citys map[string]interface{} `json:"citys"` //城市数量
|
|
|
+ BuyerclassCount int `json:"buyerclassCount"` //行业数
|
|
|
}
|
|
|
|
|
|
//支付完成回调
|
|
|
-func (this *vipSubscribeStruct) PayCallBack(param *CallBackParam) (ok bool) {
|
|
|
+func (this *vipSubscribeStruct) PayCallBack(param *CallBackParam) bool {
|
|
|
now := time.Now()
|
|
|
orderdata := util.Mysql.FindOne("dataexport_order", map[string]interface{}{
|
|
|
"out_trade_no": param.OutTradeno,
|
|
|
"order_money": param.TotalFee,
|
|
|
- }, "id,filter,order_code,order_status,user_id", "")
|
|
|
+ }, "id,filter,order_code,order_status,user_id,vip_starttime,vip_endtime", "")
|
|
|
pay_time := qutil.FormatDate(&now, qutil.Date_Full_Layout)
|
|
|
if orderdata != nil {
|
|
|
- order_status := qutil.IntAll((*orderdata)["order_status"])
|
|
|
- if order_status == 0 {
|
|
|
- //计算时长
|
|
|
- vmsg := VipSimpleMsg{}
|
|
|
- filterStr := qutil.ObjToString((*orderdata)["filter"])
|
|
|
- userid := qutil.ObjToString((*orderdata)["user_id"])
|
|
|
- if err := json.Unmarshal([]byte(filterStr), &vmsg); err != nil {
|
|
|
- log.Printf("%s vipSubscribeStruct PayCallBack Unmarshal 出错 [%s]\n", userid, filterStr)
|
|
|
- }
|
|
|
- if vmsg.Paysource == "open" {
|
|
|
- startTime := time.Now()
|
|
|
- var endTime time.Time
|
|
|
- if vmsg.Cycleunit == 1 { //年
|
|
|
- endTime = startTime.AddDate(vmsg.Cyclecount, 0, 0)
|
|
|
- } else if vmsg.Cycleunit == 2 { //月
|
|
|
- endTime = startTime.AddDate(0, vmsg.Cyclecount, 0)
|
|
|
- }
|
|
|
- update := util.Mysql.Update("dataexport_order", map[string]interface{}{
|
|
|
- "order_status": 0,
|
|
|
- "out_trade_no": param.OutTradeno,
|
|
|
- "order_money": param.TotalFee,
|
|
|
- //"user_openid": openid,
|
|
|
- }, map[string]interface{}{
|
|
|
- "pay_money": param.CashFee,
|
|
|
- "pay_time": pay_time,
|
|
|
- "order_status": 1,
|
|
|
- "vip_endtime": qutil.FormatDate(&endTime, qutil.Date_Full_Layout),
|
|
|
- })
|
|
|
- if update {
|
|
|
- if JyVipSubStruct.StartSubVip(userid, vmsg.Area, vmsg.Industry, startTime, endTime, false, vmsg.Cyclecount, vmsg.Cycleunit) {
|
|
|
- ok = true
|
|
|
- }
|
|
|
- }
|
|
|
- } else if vmsg.Paysource == "Renew" {
|
|
|
- endtime := qutil.Int64All(vmsg.Endtime)
|
|
|
- nowTime := time.Now().Unix()
|
|
|
- if nowTime > endtime {
|
|
|
- endtime = nowTime
|
|
|
- }
|
|
|
- endtimes := time.Unix(endtime, 0)
|
|
|
- var endTime time.Time
|
|
|
- if vmsg.Cycleunit == 1 { //年
|
|
|
- endTime = endtimes.AddDate(vmsg.Cyclecount, 0, 0)
|
|
|
- } else if vmsg.Cycleunit == 2 { //月
|
|
|
- endTime = endtimes.AddDate(0, vmsg.Cyclecount, 0)
|
|
|
- }
|
|
|
- update := false
|
|
|
- if nowTime > endtime {
|
|
|
- startTime := time.Now()
|
|
|
- update = util.Mysql.Update("dataexport_order", map[string]interface{}{
|
|
|
- "order_status": 0,
|
|
|
- "out_trade_no": param.OutTradeno,
|
|
|
- "order_money": param.TotalFee,
|
|
|
- //"user_openid": openid,
|
|
|
- }, map[string]interface{}{
|
|
|
- "pay_money": param.CashFee,
|
|
|
- "pay_time": pay_time,
|
|
|
- "order_status": 1,
|
|
|
- "vip_starttime": qutil.FormatDate(&startTime, qutil.Date_Full_Layout),
|
|
|
- "vip_endtime": qutil.FormatDate(&endTime, qutil.Date_Full_Layout),
|
|
|
- })
|
|
|
- } else {
|
|
|
- data, oks := util.MQFW.FindById("user", userid, nil)
|
|
|
- var starttime time.Time
|
|
|
- if oks && len(*data) > 0 && *data != nil {
|
|
|
- start := qutil.Int64All((*data)["l_vip_starttime"])
|
|
|
- starttime = time.Unix(start, 0)
|
|
|
- }
|
|
|
- update = util.Mysql.Update("dataexport_order", map[string]interface{}{
|
|
|
- "order_status": 0,
|
|
|
- "out_trade_no": param.OutTradeno,
|
|
|
- "order_money": param.TotalFee,
|
|
|
- //"user_openid": openid,
|
|
|
- }, map[string]interface{}{
|
|
|
- "pay_money": param.CashFee,
|
|
|
- "pay_time": pay_time,
|
|
|
- "order_status": 1,
|
|
|
- "vip_starttime": qutil.FormatDate(&starttime, qutil.Date_Full_Layout),
|
|
|
- "vip_endtime": qutil.FormatDate(&endTime, qutil.Date_Full_Layout),
|
|
|
- })
|
|
|
- }
|
|
|
- if update {
|
|
|
- area := *vmsg.Area
|
|
|
- industry := vmsg.Industry
|
|
|
- buyset := SubvipBuySet{}
|
|
|
- if len(area) > 0 {
|
|
|
- pCount := 0
|
|
|
- citys := map[string]interface{}{}
|
|
|
- for k, v := range area {
|
|
|
- tmp := v.([]interface{})
|
|
|
- if len(tmp) == 0 { //省份
|
|
|
- pCount++
|
|
|
- } else { //城市
|
|
|
- citys[k] = len(tmp)
|
|
|
- }
|
|
|
- }
|
|
|
- buyset.Citys = citys //城市
|
|
|
- buyset.AreaCount = pCount //地区
|
|
|
- } else {
|
|
|
- buyset.BuyerclassCount = -1 //全国
|
|
|
- }
|
|
|
- //行业数量
|
|
|
- buyset.BuyerclassCount = qutil.If(len(industry) > 0, len(industry), -1).(int)
|
|
|
- if nowTime > endtime {
|
|
|
- if util.MQFW.UpdateById("user", userid,
|
|
|
- bson.M{"$set": bson.M{
|
|
|
- "o_vipjy.o_area": area, //试用设置地区
|
|
|
- "o_vipjy.a_buyerclass": industry, //试用设置行业
|
|
|
- "o_vipjy.o_buyset": buyset, //购买内容 城市、省份、行业数量
|
|
|
- "o_vipjy.i_cycleunit": vmsg.Cycleunit, //购买单位
|
|
|
- "o_vipjy.i_cyclecount": vmsg.Cyclecount, //购买时长
|
|
|
- "l_vip_starttime": nowTime, //开始时间
|
|
|
- "l_vip_endtime": endTime.Unix(), //结束时间
|
|
|
- }}) {
|
|
|
- ok = true
|
|
|
- }
|
|
|
- } else {
|
|
|
- if util.MQFW.UpdateById("user", userid,
|
|
|
- bson.M{"$set": bson.M{
|
|
|
- "o_vipjy.o_area": area, //试用设置地区
|
|
|
- "o_vipjy.a_buyerclass": industry, //试用设置行业
|
|
|
- "o_vipjy.o_buyset": buyset, //购买内容 城市、省份、行业数量
|
|
|
- "o_vipjy.i_cycleunit": vmsg.Cycleunit, //购买单位
|
|
|
- "o_vipjy.i_cyclecount": vmsg.Cyclecount, //购买时长
|
|
|
- // "l_vip_starttime": startTime.Unix(), //开始时间
|
|
|
- "l_vip_endtime": endTime.Unix(), //结束时间
|
|
|
- }}) {
|
|
|
- ok = true
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- effect := vmsg.Effect
|
|
|
- endtime := qutil.Int64All(vmsg.Endtime)
|
|
|
- endtimes := time.Unix(endtime, 0)
|
|
|
- var endTime time.Time
|
|
|
- if effect == "now" {
|
|
|
- if vmsg.Cycleunit >= 1 {
|
|
|
- if vmsg.Cycleunit == 1 { //年
|
|
|
- endTime = endtimes.AddDate(vmsg.Cyclecount, 0, 0)
|
|
|
- } else if vmsg.Cycleunit == 2 { //月
|
|
|
- endTime = endtimes.AddDate(0, vmsg.Cyclecount, 0)
|
|
|
- }
|
|
|
- data, oks := util.MQFW.FindById("user", userid, nil)
|
|
|
- var starttime time.Time
|
|
|
- if oks && len(*data) > 0 && *data != nil {
|
|
|
- start := qutil.Int64All((*data)["l_vip_starttime"])
|
|
|
- starttime = time.Unix(start, 0)
|
|
|
- }
|
|
|
- update := util.Mysql.Update("dataexport_order", map[string]interface{}{
|
|
|
- "order_status": 0,
|
|
|
- "out_trade_no": param.OutTradeno,
|
|
|
- "order_money": param.TotalFee,
|
|
|
- //"user_openid": openid,
|
|
|
- }, map[string]interface{}{
|
|
|
- "pay_money": param.CashFee,
|
|
|
- "pay_time": pay_time,
|
|
|
- "order_status": 1,
|
|
|
- "vip_starttime": qutil.FormatDate(&starttime, qutil.Date_Full_Layout),
|
|
|
- "vip_endtime": qutil.FormatDate(&endTime, qutil.Date_Full_Layout),
|
|
|
- })
|
|
|
- if update {
|
|
|
- area := *vmsg.Area
|
|
|
- industry := vmsg.Industry
|
|
|
- buyset := SubvipBuySet{}
|
|
|
- if len(area) > 0 {
|
|
|
- pCount := 0
|
|
|
- citys := map[string]interface{}{}
|
|
|
- for k, v := range area {
|
|
|
- tmp := v.([]interface{})
|
|
|
- if len(tmp) == 0 { //省份
|
|
|
- pCount++
|
|
|
- } else { //城市
|
|
|
- citys[k] = len(tmp)
|
|
|
- }
|
|
|
- }
|
|
|
- buyset.Citys = citys //城市
|
|
|
- buyset.AreaCount = pCount //地区
|
|
|
- } else {
|
|
|
- buyset.BuyerclassCount = -1 //全国
|
|
|
- }
|
|
|
- //行业数量
|
|
|
- buyset.BuyerclassCount = qutil.If(len(industry) > 0, len(industry), -1).(int)
|
|
|
- if util.MQFW.UpdateById("user", userid,
|
|
|
- bson.M{"$set": bson.M{
|
|
|
- "o_vipjy.o_area": area, //试用设置地区
|
|
|
- "o_vipjy.a_buyerclass": industry, //试用设置行业
|
|
|
- "o_vipjy.o_buyset": buyset, //购买内容 城市、省份、行业数量
|
|
|
- "o_vipjy.i_cycleunit": vmsg.Cycleunit, //购买单位
|
|
|
- "o_vipjy.i_cyclecount": vmsg.Cyclecount, //购买时长
|
|
|
- // "l_vip_starttime": startTime.Unix(), //开始时间
|
|
|
- "l_vip_endtime": endTime.Unix(), //结束时间
|
|
|
- }}) {
|
|
|
- ok = true
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- data, oks := util.MQFW.FindById("user", userid, nil)
|
|
|
- var starttime time.Time
|
|
|
- if oks && len(*data) > 0 && *data != nil {
|
|
|
- start := qutil.Int64All((*data)["l_vip_starttime"])
|
|
|
- starttime = time.Unix(start, 0)
|
|
|
- }
|
|
|
- update := util.Mysql.Update("dataexport_order", map[string]interface{}{
|
|
|
- "order_status": 0,
|
|
|
- "out_trade_no": param.OutTradeno,
|
|
|
- "order_money": param.TotalFee,
|
|
|
- //"user_openid": openid,
|
|
|
- }, map[string]interface{}{
|
|
|
- "pay_money": param.CashFee,
|
|
|
- "pay_time": pay_time,
|
|
|
- "order_status": 1,
|
|
|
- "vip_starttime": qutil.FormatDate(&starttime, qutil.Date_Full_Layout),
|
|
|
- "vip_endtime": qutil.FormatDate(&endTime, qutil.Date_Full_Layout),
|
|
|
- })
|
|
|
- if update {
|
|
|
- area := *vmsg.Area
|
|
|
- industry := vmsg.Industry
|
|
|
- buyset := SubvipBuySet{}
|
|
|
- if len(area) > 0 {
|
|
|
- pCount := 0
|
|
|
- citys := map[string]interface{}{}
|
|
|
- for k, v := range area {
|
|
|
- tmp := v.([]interface{})
|
|
|
- if len(tmp) == 0 { //省份
|
|
|
- pCount++
|
|
|
- } else { //城市
|
|
|
- citys[k] = len(tmp)
|
|
|
- }
|
|
|
- }
|
|
|
- buyset.Citys = citys //城市
|
|
|
- buyset.AreaCount = pCount //地区
|
|
|
- } else {
|
|
|
- buyset.BuyerclassCount = -1 //全国
|
|
|
- }
|
|
|
- //行业数量
|
|
|
- buyset.BuyerclassCount = qutil.If(len(industry) > 0, len(industry), -1).(int)
|
|
|
- if util.MQFW.UpdateById("user", userid,
|
|
|
- bson.M{"$set": bson.M{
|
|
|
- "o_vipjy.o_area": area, //试用设置地区
|
|
|
- "o_vipjy.a_buyerclass": industry, //试用设置行业
|
|
|
- "o_vipjy.o_buyset": buyset, //购买内容 城市、省份、行业数量
|
|
|
- }}) {
|
|
|
- ok = true
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- if vmsg.Cycleunit >= 1 {
|
|
|
- if vmsg.Cycleunit == 1 { //年
|
|
|
- endTime = endtimes.AddDate(vmsg.Cyclecount, 0, 0)
|
|
|
- } else if vmsg.Cycleunit == 2 { //月
|
|
|
- endTime = endtimes.AddDate(0, vmsg.Cyclecount, 0)
|
|
|
- }
|
|
|
- data, oks := util.MQFW.FindById("user", userid, nil)
|
|
|
- var starttime time.Time
|
|
|
- if oks && len(*data) > 0 && *data != nil {
|
|
|
- start := qutil.Int64All((*data)["l_vip_starttime"])
|
|
|
- starttime = time.Unix(start, 0)
|
|
|
- }
|
|
|
- update := util.Mysql.Update("dataexport_order", map[string]interface{}{
|
|
|
- "order_status": 0,
|
|
|
- "out_trade_no": param.OutTradeno,
|
|
|
- "order_money": param.TotalFee,
|
|
|
- //"user_openid": openid,
|
|
|
- }, map[string]interface{}{
|
|
|
- "pay_money": param.CashFee,
|
|
|
- "pay_time": pay_time,
|
|
|
- "order_status": 1,
|
|
|
- "vip_starttime": qutil.FormatDate(&starttime, qutil.Date_Full_Layout),
|
|
|
- "vip_endtime": qutil.FormatDate(&endTime, qutil.Date_Full_Layout),
|
|
|
- })
|
|
|
- if update {
|
|
|
- if util.MQFW.UpdateById("user", userid,
|
|
|
- bson.M{"$set": bson.M{
|
|
|
- "o_vipjy.i_cycleunit": vmsg.Cycleunit, //购买单位
|
|
|
- "o_vipjy.i_cyclecount": vmsg.Cyclecount, //购买时长
|
|
|
- // "l_vip_starttime": startTime.Unix(), //开始时间
|
|
|
- "l_vip_endtime": endTime.Unix(), //结束时间
|
|
|
- }}) {
|
|
|
- ok = true
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- data, oks := util.MQFW.FindById("user", userid, nil)
|
|
|
- var starttime time.Time
|
|
|
- if oks && len(*data) > 0 && *data != nil {
|
|
|
- start := qutil.Int64All((*data)["l_vip_starttime"])
|
|
|
- starttime = time.Unix(start, 0)
|
|
|
- }
|
|
|
- update := util.Mysql.Update("dataexport_order", map[string]interface{}{
|
|
|
- "order_status": 0,
|
|
|
- "out_trade_no": param.OutTradeno,
|
|
|
- "order_money": param.TotalFee,
|
|
|
- //"user_openid": openid,
|
|
|
- }, map[string]interface{}{
|
|
|
- "pay_money": param.CashFee,
|
|
|
- "pay_time": pay_time,
|
|
|
- "order_status": 1,
|
|
|
- "vip_starttime": qutil.FormatDate(&starttime, qutil.Date_Full_Layout),
|
|
|
- "vip_endtime": qutil.FormatDate(&endTime, qutil.Date_Full_Layout),
|
|
|
- })
|
|
|
- if update {
|
|
|
- ok = true
|
|
|
- }
|
|
|
- }
|
|
|
- area := *vmsg.Area
|
|
|
- industry := vmsg.Industry
|
|
|
- validtime := qutil.Int64All(effect)
|
|
|
- if util.MQFW.Save("vip_upgrade",
|
|
|
- bson.M{
|
|
|
- "s_userid": userid, //试用设置地区
|
|
|
- "a_buyerclass": industry, //试用设置行业
|
|
|
- "o_area": area, //购买内容 城市、省份、行业数量
|
|
|
- "l_validtime": validtime, //生效时间
|
|
|
- "l_createtime": time.Now().Unix(), //入库时间
|
|
|
- "i_isvalid": 0, //是否已经生效 0-未生效
|
|
|
- }) == "" {
|
|
|
- ok = true
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if ok {
|
|
|
- //支付成功后 其他未支付vip订阅订单 变为已取消
|
|
|
- if PayCancel(userid) {
|
|
|
- log.Println(userid, "更改其余未支付订单失败")
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- ok = true
|
|
|
+ return false //未找到订单
|
|
|
+ }
|
|
|
+ userid := qutil.ObjToString((*orderdata)["user_id"])
|
|
|
+ order_status := qutil.IntAll((*orderdata)["order_status"])
|
|
|
+ if order_status == 1 {
|
|
|
+ return true // 或已支付
|
|
|
+ }
|
|
|
+ if order_status != 0 {
|
|
|
+ log.Printf("%s订单状态异常%d\n", userid, order_status)
|
|
|
+ return false //
|
|
|
+ }
|
|
|
+ //计算时长
|
|
|
+ vmsg := 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)
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ updateMap := map[string]interface{}{
|
|
|
+ "pay_money": param.CashFee,
|
|
|
+ "pay_time": pay_time,
|
|
|
+ "order_status": 1,
|
|
|
+ }
|
|
|
+
|
|
|
+ var startTime time.Time
|
|
|
+ var endTime time.Time
|
|
|
+ if vmsg.OrderType == 1 { //新订单 计算开始时间 结束时间
|
|
|
+ startTime := time.Now()
|
|
|
+ if vmsg.Cycleunit == 1 { //年
|
|
|
+ endTime = startTime.AddDate(vmsg.Cyclecount, 0, 0)
|
|
|
+ } else if vmsg.Cycleunit == 2 { //月
|
|
|
+ endTime = startTime.AddDate(0, vmsg.Cyclecount, 0)
|
|
|
}
|
|
|
+ updateMap["vip_starttime"] = qutil.FormatDate(&startTime, qutil.Date_Full_Layout)
|
|
|
+ updateMap["vip_endtime"] = qutil.FormatDate(&endTime, qutil.Date_Full_Layout)
|
|
|
}
|
|
|
- return ok
|
|
|
-}
|
|
|
|
|
|
-//购买内容
|
|
|
-type SubvipBuySet struct {
|
|
|
- AreaCount int `json:"areaCount"` //-1 全国 >0 省份数量
|
|
|
- Citys map[string]interface{} `json:"citys"` //城市数量
|
|
|
- BuyerclassCount int `json:"buyerclassCount"` //行业数
|
|
|
+ update := util.Mysql.Update("dataexport_order", map[string]interface{}{
|
|
|
+ "order_status": 0,
|
|
|
+ "out_trade_no": param.OutTradeno,
|
|
|
+ "order_money": param.TotalFee,
|
|
|
+ }, updateMap)
|
|
|
+
|
|
|
+ if !update {
|
|
|
+ log.Printf("%s更新订单状态出错%+v\n", userid, updateMap)
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ flag := false
|
|
|
+ if vmsg.OrderType == 1 { //新订单
|
|
|
+ flag = JyVipSubStruct.StartSubVip(userid, vmsg, startTime, endTime, false)
|
|
|
+ } else if vmsg.OrderType == 2 { //续费
|
|
|
+ flag = JyVipSubStruct.RenewSubVip(userid, qutil.ObjToString((*orderdata)["vip_endtime"]))
|
|
|
+ } else if vmsg.OrderType == 3 { //立即升级
|
|
|
+ flag = JyVipSubStruct.UpgradeSubVip(userid, vmsg, qutil.ObjToString((*orderdata)["vip_starttime"]), qutil.ObjToString((*orderdata)["vip_endtime"]), true)
|
|
|
+ } else if vmsg.OrderType == 4 { //下月升级
|
|
|
+ flag = JyVipSubStruct.UpgradeSubVip(userid, vmsg, qutil.ObjToString((*orderdata)["vip_starttime"]), qutil.ObjToString((*orderdata)["vip_endtime"]), false)
|
|
|
+ }
|
|
|
+ //支付成功后 其他未支付vip订阅订单 变为已取消
|
|
|
+ if flag {
|
|
|
+ go PayCancel(userid)
|
|
|
+ }
|
|
|
+ return flag
|
|
|
}
|
|
|
|
|
|
-//设置开始使用
|
|
|
-func (this *vipSubscribeStruct) StartSubVip(userId string, area *map[string]interface{}, industry []string, startTime, endTime time.Time, isTrial bool, count, unit int) bool {
|
|
|
- buyset := SubvipBuySet{}
|
|
|
- //a_buyset 计算 0:省份数量 1:城市数量 2:行业数量
|
|
|
+//设置开始使用vip订阅
|
|
|
+func (this *vipSubscribeStruct) StartSubVip(userId string, vmsg VipSimpleMsg, startTime, endTime time.Time, isTrial bool) bool {
|
|
|
+ buyset := &SubvipBuySet{}
|
|
|
if !isTrial { //购买
|
|
|
- if len(*area) > 0 {
|
|
|
- pCount := 0
|
|
|
- citys := map[string]interface{}{}
|
|
|
- for k, v := range *area {
|
|
|
- tmp := v.([]interface{})
|
|
|
- if len(tmp) == 0 { //省份
|
|
|
- pCount++
|
|
|
- } else { //城市
|
|
|
- citys[k] = len(tmp)
|
|
|
- }
|
|
|
- }
|
|
|
- buyset.Citys = citys //城市
|
|
|
- buyset.AreaCount = pCount //地区
|
|
|
- } else {
|
|
|
- buyset.BuyerclassCount = -1 //全国
|
|
|
- }
|
|
|
- //行业数量
|
|
|
- buyset.BuyerclassCount = qutil.If(len(industry) > 0, len(industry), -1).(int)
|
|
|
+ buyset = JyVipSubStruct.NewBuySet(vmsg.Area, vmsg.Industry)
|
|
|
} else { //试用
|
|
|
buyset.AreaCount = -1 //城市数量
|
|
|
buyset.BuyerclassCount = -1 //行业数量
|
|
|
}
|
|
|
-
|
|
|
//计算服务时间
|
|
|
if !util.MQFW.UpdateById("user", userId,
|
|
|
bson.M{"$set": bson.M{
|
|
|
"o_vipjy.i_trial": -1, //已激活试用
|
|
|
- "o_vipjy.o_area": area, //试用设置地区
|
|
|
- "o_vipjy.a_buyerclass": industry, //试用设置行业
|
|
|
+ "o_vipjy.o_area": vmsg.Area, //设置地区
|
|
|
+ "o_vipjy.a_buyerclass": vmsg.Industry, //设置行业
|
|
|
+ "o_vipjy.i_cycleunit": vmsg.Cycleunit, //购买单位
|
|
|
+ "o_vipjy.i_cyclecount": vmsg.Cyclecount, //购买时长
|
|
|
"o_vipjy.o_buyset": buyset, //购买内容 城市、省份、行业数量
|
|
|
- "o_vipjy.i_cycleunit": unit, //购买单位
|
|
|
- "o_vipjy.i_cyclecount": count, //购买时长
|
|
|
"l_vip_starttime": startTime.Unix(), //开始时间
|
|
|
"l_vip_endtime": endTime.Unix(), //结束时间
|
|
|
"i_vip_status": qutil.If(isTrial, 1, 2), //1试用 2正式
|
|
@@ -428,6 +137,87 @@ func (this *vipSubscribeStruct) StartSubVip(userId string, area *map[string]inte
|
|
|
return true
|
|
|
}
|
|
|
|
|
|
+//续费
|
|
|
+func (this *vipSubscribeStruct) RenewSubVip(userId, endtime string) bool {
|
|
|
+ prepayTime, err := time.ParseInLocation(qutil.Date_Full_Layout, endtime, time.Local)
|
|
|
+ if err != nil {
|
|
|
+ log.Println("%s格式化日期出错%s\n", userId, endtime)
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ return util.MQFW.UpdateById("user", userId, bson.M{"$set": bson.M{"l_vip_endtime": prepayTime.Unix()}})
|
|
|
+}
|
|
|
+
|
|
|
+//升级
|
|
|
+func (this *vipSubscribeStruct) UpgradeSubVip(userId string, vmsg VipSimpleMsg, start, end string, isNow bool) bool {
|
|
|
+ startTime, err := time.ParseInLocation(qutil.Date_Full_Layout, start, time.Local)
|
|
|
+ if err != nil {
|
|
|
+ log.Println("%s格式化日期出错%s\n", userId, start)
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ endTime, err := time.ParseInLocation(qutil.Date_Full_Layout, end, time.Local)
|
|
|
+ if err != nil {
|
|
|
+ log.Println("%s格式化日期出错%s\n", userId, endTime)
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ buyset := JyVipSubStruct.NewBuySet(vmsg.Area, vmsg.Industry)
|
|
|
+ if isNow {
|
|
|
+ return util.MQFW.UpdateById("user", userId,
|
|
|
+ bson.M{"$set": bson.M{
|
|
|
+ "o_vipjy.o_area": vmsg.Area, //设置地区
|
|
|
+ "o_vipjy.a_buyerclass": vmsg.Industry, //设置行业
|
|
|
+ "o_vipjy.i_cycleunit": vmsg.Cycleunit, //购买单位
|
|
|
+ "o_vipjy.i_cyclecount": vmsg.Cyclecount, //购买时长
|
|
|
+ "o_vipjy.o_buyset": buyset,
|
|
|
+ "l_vip_endtime": endTime.Unix(),
|
|
|
+ "i_vip_status": 2,
|
|
|
+ // "l_vip_starttime": startTime.Unix(),
|
|
|
+ }})
|
|
|
+ } else {
|
|
|
+ if !util.MQFW.UpdateById("user", userId,
|
|
|
+ bson.M{"$set": bson.M{
|
|
|
+ "l_vip_endtime": endTime.Unix(),
|
|
|
+ }}) {
|
|
|
+ log.Println("%s更新结束日期出错", userId)
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ return util.MQFW.Save("vip_upgrade",
|
|
|
+ bson.M{
|
|
|
+ "s_userid": userId, //试用设置地区
|
|
|
+ "a_buyerclass": vmsg.Industry, //试用设置行业
|
|
|
+ "o_area": vmsg.Area, //购买内容 城市、省份、行业数量
|
|
|
+ "l_validtime": startTime.Unix(), //生效时间
|
|
|
+ "l_createtime": time.Now().Unix(), //入库时间
|
|
|
+ "o_buyset": buyset, //购买内容数量
|
|
|
+ "i_isvalid": 0, //是否已经生效 0-未生效
|
|
|
+ }) != ""
|
|
|
+ }
|
|
|
+ return false
|
|
|
+}
|
|
|
+
|
|
|
+//根据行业和地区 返回*SubvipBuySet
|
|
|
+func (this *vipSubscribeStruct) NewBuySet(area *map[string]interface{}, industry []string) *SubvipBuySet {
|
|
|
+ buyset := SubvipBuySet{}
|
|
|
+ if len(*area) > 0 {
|
|
|
+ pCount := 0
|
|
|
+ citys := map[string]interface{}{}
|
|
|
+ for k, v := range *area {
|
|
|
+ tmp := v.([]interface{})
|
|
|
+ if len(tmp) == 0 { //省份
|
|
|
+ pCount++
|
|
|
+ } else { //城市
|
|
|
+ citys[k] = len(tmp)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ buyset.Citys = citys //城市
|
|
|
+ buyset.AreaCount = pCount //地区
|
|
|
+ } else {
|
|
|
+ buyset.BuyerclassCount = -1 //全国
|
|
|
+ }
|
|
|
+ //行业数量
|
|
|
+ buyset.BuyerclassCount = qutil.If(len(industry) > 0, len(industry), -1).(int)
|
|
|
+ return &buyset
|
|
|
+}
|
|
|
+
|
|
|
//查询是否有试用权限
|
|
|
func (this *vipSubscribeStruct) CanTrial(userId string) bool {
|
|
|
m, ok := util.MQFW.FindById("user", userId, `{"o_vipjy":1,"i_vip_status":1}`)
|
|
@@ -485,6 +275,20 @@ func (this *vipSubscribeStruct) SubEditCheckArea(area *map[string]interface{}, b
|
|
|
return true
|
|
|
}
|
|
|
|
|
|
+//保存筛选日志
|
|
|
+func (this *vipSubscribeStruct) SaveSelectLog(userId, openId string, msg *VipSimpleMsg) string {
|
|
|
+ return util.MQFW.Save("subvip_select", map[string]interface{}{
|
|
|
+ "o_area": msg.Area, //地区(对象)
|
|
|
+ "a_industry": msg.Industry, //行业(数组)
|
|
|
+ "s_userid": userId,
|
|
|
+ "s_openid": openId,
|
|
|
+ "i_cyclecount": msg.Cyclecount, //时长
|
|
|
+ "i_cycleunit": msg.Cycleunit, //单位
|
|
|
+ "i_comeintime": time.Now().Unix(),
|
|
|
+ })
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
//计算价格
|
|
|
func (this *vipSubscribeStruct) GetSubVipPrice(area *map[string]interface{}, industry []string, count, unit int) int {
|
|
|
if len(*area) == 0 { //全国
|
|
@@ -606,7 +410,7 @@ func PayCancel(userId string) bool {
|
|
|
flag = true
|
|
|
}
|
|
|
if flag {
|
|
|
- //更改未支付订单状态 -2
|
|
|
+ //更改未支付订单状态 -2 逐个取消订单
|
|
|
bl := util.Mysql.Update("dataexport_order", bson.M{
|
|
|
"user_id": userId,
|
|
|
"product_type": "VIP订阅",
|
|
@@ -621,5 +425,8 @@ func PayCancel(userId string) bool {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ if i != order_len {
|
|
|
+ log.Printf("%s取消其他订单状态失败\n", userId)
|
|
|
+ }
|
|
|
return i == order_len //更改成功次数是否等于需要更改次数
|
|
|
}
|