|
@@ -1,6 +1,8 @@
|
|
|
package entity
|
|
|
+
|
|
|
//vip订阅公共方法
|
|
|
import (
|
|
|
+ "encoding/json"
|
|
|
"log"
|
|
|
"time"
|
|
|
"util"
|
|
@@ -10,20 +12,97 @@ import (
|
|
|
qutil "qfw/util"
|
|
|
)
|
|
|
|
|
|
-//设置开始试用
|
|
|
-func StartTrial(userId string, area *map[string]interface{}, industry []string) bool {
|
|
|
+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"`
|
|
|
+}
|
|
|
+
|
|
|
+//支付完成回调
|
|
|
+func (this *vipSubscribeStruct) PayCallBack(param *CallBackParam) (ok 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", "")
|
|
|
+ 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)
|
|
|
+ }
|
|
|
+ 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_starttime": qutil.FormatDate(&startTime, qutil.Date_Full_Layout),
|
|
|
+ "vip_endtime": qutil.FormatDate(&endTime, qutil.Date_Full_Layout),
|
|
|
+ })
|
|
|
+ if update {
|
|
|
+ if JyVipSubStruct.StartSubVip(userid, vmsg.Area, vmsg.Industry, startTime, endTime, false) {
|
|
|
+ ok = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ ok = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ok
|
|
|
+}
|
|
|
+
|
|
|
+//设置开始使用
|
|
|
+func (this *vipSubscribeStruct) StartSubVip(userId string, area *map[string]interface{}, industry []string, startTime, endTime time.Time, isTrial bool) bool {
|
|
|
+ buyset := [3]int{-1, -1, -1}
|
|
|
+ //a_buyset 计算 0:省份数量 1:城市数量 2:行业数量
|
|
|
+ if !isTrial {
|
|
|
+ if len(*area) > 0 {
|
|
|
+ areaCount := JyVipSubStruct.GetBuyAreaCount(area);
|
|
|
+ buyset[0] = areaCount[0] //省份数量
|
|
|
+ buyset[1] = areaCount[1] //城市数量
|
|
|
+ } else {
|
|
|
+ buyset[0] = -1
|
|
|
+ buyset[1] = -1
|
|
|
+ }
|
|
|
+ if len(industry) > 0 {
|
|
|
+ buyset[2] = len(industry) //行业数量
|
|
|
+ } else {
|
|
|
+ buyset[2] = -1
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//计算服务时间
|
|
|
- startTime := time.Now()
|
|
|
- endTime := startTime.AddDate(0, 0, 7)
|
|
|
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.a_buyset": []int{-1, -1, -1}, //购买内容 城市、省份、行业数量
|
|
|
- "l_vip_starttime": startTime.Unix(), //开始时间
|
|
|
- "l_vip_endtime": endTime.Unix(), //结束时间
|
|
|
- "i_vip_status": 1, //1试用 2正式
|
|
|
+ "o_vipjy.i_trial": -1, //已激活试用
|
|
|
+ "o_vipjy.o_area": area, //试用设置地区
|
|
|
+ "o_vipjy.a_buyerclass": industry, //试用设置行业
|
|
|
+ "o_vipjy.a_buyset": buyset, //购买内容 城市、省份、行业数量
|
|
|
+ "l_vip_starttime": startTime.Unix(), //开始时间
|
|
|
+ "l_vip_endtime": endTime.Unix(), //结束时间
|
|
|
+ "i_vip_status": qutil.If(isTrial, 1, 2), //1试用 2正式
|
|
|
}}) {
|
|
|
return false
|
|
|
}
|
|
@@ -31,17 +110,17 @@ func StartTrial(userId string, area *map[string]interface{}, industry []string)
|
|
|
}
|
|
|
|
|
|
//查询是否有试用权限
|
|
|
-func CanTrial(userId string) bool {
|
|
|
+func (this *vipSubscribeStruct) CanTrial(userId string) bool {
|
|
|
m, ok := util.MQFW.FindById("user", userId, `{"o_vipjy":1,"i_vip_status":1}`)
|
|
|
if m == nil || len(*m) == 0 || !ok {
|
|
|
return false
|
|
|
}
|
|
|
obj := qutil.ObjToMap((*m)["o_vipjy"])
|
|
|
- if qutil.IntAll((*obj)["i_trial"]) != 1 {//是否有试用资格
|
|
|
+ if qutil.IntAll((*obj)["i_trial"]) != 1 { //是否有试用资格
|
|
|
return false
|
|
|
}
|
|
|
//是否使用过(使用过VIP订阅功能,就不能试用)
|
|
|
- if qutil.IntAll((*m)["i_vip_status"])!=0{ //开启状态:0-暂不使用vip订阅 1-试用 2-正式 -1-试用到期 -2-正式到期
|
|
|
+ if qutil.IntAll((*m)["i_vip_status"]) != 0 { //开启状态:0-暂不使用vip订阅 1-试用 2-正式 -1-试用到期 -2-正式到期
|
|
|
return false
|
|
|
}
|
|
|
return true
|
|
@@ -49,7 +128,7 @@ func CanTrial(userId string) bool {
|
|
|
|
|
|
//获取省份,城市,行业购买数量;-1为全部
|
|
|
//[省份,城市,行业]
|
|
|
-func GetBuySet(userId string) (result [3]int) {
|
|
|
+func (this *vipSubscribeStruct) GetBuySet(userId string) (result [3]int) {
|
|
|
mData, ok := util.MQFW.FindById("user", userId, `{"o_vipjy":1}`)
|
|
|
if !ok || len(*mData) == 0 || mData == nil {
|
|
|
return
|
|
@@ -62,10 +141,10 @@ func GetBuySet(userId string) (result [3]int) {
|
|
|
}
|
|
|
|
|
|
//根据区域获取城市和省份数量
|
|
|
-func GetBuyAreaCount(area map[string]interface{}) (result [2]int) {
|
|
|
+func (this *vipSubscribeStruct) GetBuyAreaCount(area *map[string]interface{}) (result [2]int) {
|
|
|
p := []interface{}{} //省份
|
|
|
c := []interface{}{} //城市
|
|
|
- for k, v := range area {
|
|
|
+ for k, v := range *area {
|
|
|
tmp := v.([]interface{})
|
|
|
if len(tmp) == 0 { //省份
|
|
|
result[0]++
|
|
@@ -80,7 +159,7 @@ func GetBuyAreaCount(area map[string]interface{}) (result [2]int) {
|
|
|
}
|
|
|
|
|
|
//计算价格
|
|
|
-func GetSubVipPrice(area *map[string]interface{}, industry []string, count, unit int) int {
|
|
|
+func (this *vipSubscribeStruct) GetSubVipPrice(area *map[string]interface{}, industry []string, count, unit int) int {
|
|
|
if len(*area) == 0 { //全国
|
|
|
if len(industry) == 1 {
|
|
|
return getSetMealPrice(0, 1, unit) * count //全国1行业套餐
|