|
@@ -23,17 +23,9 @@ type VipSimpleMsg struct {
|
|
|
Industry []string `json:"industry"`
|
|
|
Cyclecount int `json:"cyclecount"`
|
|
|
Cycleunit int `json:"cycleunit"`
|
|
|
- PaySource string `json:"paysource"`
|
|
|
-}
|
|
|
-
|
|
|
-type VipUpgradeMsg struct {
|
|
|
- Id string `json:"_id"`
|
|
|
- Area *map[string]interface{} `json:"area"`
|
|
|
- Industry []string `json:"industry"`
|
|
|
- PaySource string `json:"paysource"`
|
|
|
- ProCyclecount int `json:"procyclecount"`
|
|
|
- ProCycleunit int `json:"procycleunit"`
|
|
|
- Effect string `json:"effect"`
|
|
|
+ Paysource string `json:"paysource"`
|
|
|
+ Endtime string `json:"endtime"`
|
|
|
+ Effect string `json:"effect"`
|
|
|
}
|
|
|
|
|
|
//支付完成回调
|
|
@@ -54,33 +46,324 @@ func (this *vipSubscribeStruct) PayCallBack(param *CallBackParam) (ok bool) {
|
|
|
if err := json.Unmarshal([]byte(filterStr), &vmsg); err != nil {
|
|
|
log.Printf("%s vipSubscribeStruct PayCallBack Unmarshal 出错 [%s]\n", userid, filterStr)
|
|
|
}
|
|
|
- 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)
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- 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 ok {
|
|
|
//支付成功后 其他未支付vip订阅订单 变为已取消
|
|
|
if PayCancel(userid) {
|
|
|
log.Println(userid, "更改其余未支付订单失效")
|
|
|
}
|
|
|
- if JyVipSubStruct.StartSubVip(userid, vmsg.Area, vmsg.Industry, startTime, endTime, false, vmsg.Cyclecount, vmsg.Cycleunit) {
|
|
|
- ok = true
|
|
|
- }
|
|
|
}
|
|
|
} else {
|
|
|
ok = true
|