wangchuanjin 2 年之前
父節點
當前提交
05d5f7f076

+ 203 - 204
src/jfw/modules/subscribepay/src/entity/member.go

@@ -1,18 +1,18 @@
 package entity
 
 import (
-        "encoding/json"
-        "fmt"
-        "jy/src/jfw/modules/subscribepay/src/config"
-        "jy/src/jfw/modules/subscribepay/src/util"
-        "log"
-        "strconv"
-        "strings"
-        "time"
+	"encoding/json"
+	"fmt"
+	"jy/src/jfw/modules/subscribepay/src/config"
+	"jy/src/jfw/modules/subscribepay/src/util"
+	"log"
+	"strconv"
+	"strings"
+	"time"
 
-        qutil "app.yhyue.com/moapp/jybase/common"
-        . "app.yhyue.com/moapp/jybase/date"
-        "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
+	qutil "app.yhyue.com/moapp/jybase/common"
+	. "app.yhyue.com/moapp/jybase/date"
+	"app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
 )
 
 type memberStruct struct{}
@@ -21,207 +21,206 @@ var MemberStruct memberStruct
 var Bigmember_serice map[int]map[int]int //权益 k:子id ; v:map[int]int{父id:年数量}
 
 func init() {
-        log.Println("初始化大会员权益")
-        //初始化用户权益
-        member_serice := map[int]map[int]int{}
-        if rdata := util.Mysql.SelectBySql(`SELECT id,s_name,i_pid,s_count_year FROM bigmember_service`); rdata != nil && len(*rdata) > 0 {
-                for _, v := range *rdata {
-                        sid := qutil.IntAll(v["id"])
-                        pid := qutil.IntAll(v["i_pid"])
-                        count_year := qutil.IntAll(v["s_count_year"])
-                        // log.Println(pid, sid, count_year)
-                        if pid != 0 {
-                                member_serice[sid] = map[int]int{
-                                        pid: count_year,
-                                }
-                        } else {
-                                member_serice[sid] = map[int]int{
-                                        sid: count_year,
-                                }
-                        }
-                }
-        }
-        Bigmember_serice = member_serice
-        log.Println("初始化大会员权益已结束")
+	log.Println("初始化大会员权益")
+	//初始化用户权益
+	member_serice := map[int]map[int]int{}
+	if rdata := util.Mysql.SelectBySql(`SELECT id,s_name,i_pid,s_count_year FROM bigmember_service`); rdata != nil && len(*rdata) > 0 {
+		for _, v := range *rdata {
+			sid := qutil.IntAll(v["id"])
+			pid := qutil.IntAll(v["i_pid"])
+			count_year := qutil.IntAll(v["s_count_year"])
+			// log.Println(pid, sid, count_year)
+			if pid != 0 {
+				member_serice[sid] = map[int]int{
+					pid: count_year,
+				}
+			} else {
+				member_serice[sid] = map[int]int{
+					sid: count_year,
+				}
+			}
+		}
+	}
+	Bigmember_serice = member_serice
+	log.Println("初始化大会员权益已结束")
 }
 
 // 大会员支付完成回调方法
 func (m *memberStruct) PayCallBack(param *CallBackParam) bool {
-        orderdata := util.Mysql.FindOne("dataexport_order", param.GetPaySuccessOrderQuery(), "id,filter,order_code,order_status,user_id,vip_type,prepay_time", "")
-        if orderdata == nil {
-                return false
-        }
-        userId := qutil.ObjToString((*orderdata)["user_id"])
-        if qutil.IntAll((*orderdata)["order_status"]) == 0 {
-                now := time.Now()
-                nowFormat := FormatDate(&now, Date_Full_Layout)
-                var filter map[string]interface{}
-                if err := json.Unmarshal([]byte(qutil.ObjToString((*orderdata)["filter"])), &filter); err != nil {
-                        log.Println("大会员支付成功json.Unmarshal出错", err)
-                } else {
-                        cycle := qutil.IntAll(filter["cycle"])
-                        level := qutil.IntAll(filter["level"])
-                        var enddate = time.Now()
-                        if level == 4 { //试用用户 试用七天
-                                enddate = time.Date(now.Year(), now.Month(), now.Day()+cycle, 23, 59, 59, 0, time.Local)
-                        } else {
-                                enddate = time.Date(now.Year()+cycle, now.Month(), now.Day(), 23, 59, 59, 0, time.Local)
-                        }
-                        normal_member(level, enddate, userId,0,0,0)
-                        update := util.Mysql.Update("dataexport_order", map[string]interface{}{
-                                "id": (*orderdata)["id"],
-                        }, map[string]interface{}{
-                                "pay_money":     param.CashFee,
-                                "pay_time":      nowFormat,
-                                "order_status":  1,
-                                "vip_starttime": nowFormat,
-                                "vip_endtime":   FormatDate(&enddate, Date_Full_Layout),
-                                //支付成功后更新成支付成功的out_trade_no 避免多人支付重复刷新字段
-                                "out_trade_no": param.OutTradeno,
-                        })
-                        if update {
-                                util.MsgRemind.BigMemberPaySuccess(qutil.IntAll((*orderdata)["id"]), qutil.ObjToString((*orderdata)["order_code"]), qutil.ObjToString((*orderdata)["user_id"]), qutil.ObjToString((*orderdata)["prepay_time"]), qutil.IntAllDef((*orderdata)["vip_type"], -1))
-                                //取消其他订单
-                                go PayCancel(userId, "大会员", "")
-                        }
-                }
-        }
-        return true
+	orderdata := util.Mysql.FindOne("dataexport_order", param.GetPaySuccessOrderQuery(), "id,filter,order_code,order_status,user_id,vip_type,prepay_time", "")
+	if orderdata == nil {
+		return false
+	}
+	userId := qutil.ObjToString((*orderdata)["user_id"])
+	if qutil.IntAll((*orderdata)["order_status"]) == 0 {
+		now := time.Now()
+		nowFormat := FormatDate(&now, Date_Full_Layout)
+		var filter map[string]interface{}
+		if err := json.Unmarshal([]byte(qutil.ObjToString((*orderdata)["filter"])), &filter); err != nil {
+			log.Println("大会员支付成功json.Unmarshal出错", err)
+		} else {
+			cycle := qutil.IntAll(filter["cycle"])
+			level := qutil.IntAll(filter["level"])
+			var enddate = time.Now()
+			if level == 4 { //试用用户 试用七天
+				enddate = time.Date(now.Year(), now.Month(), now.Day()+cycle, 23, 59, 59, 0, time.Local)
+			} else {
+				enddate = time.Date(now.Year()+cycle, now.Month(), now.Day(), 23, 59, 59, 0, time.Local)
+			}
+			normal_member(level, enddate, userId, 0, 0, 0)
+			update := util.Mysql.Update("dataexport_order", map[string]interface{}{
+				"id": (*orderdata)["id"],
+			}, map[string]interface{}{
+				"pay_money":     param.CashFee,
+				"pay_time":      nowFormat,
+				"order_status":  1,
+				"vip_starttime": nowFormat,
+				"vip_endtime":   FormatDate(&enddate, Date_Full_Layout),
+				//支付成功后更新成支付成功的out_trade_no 避免多人支付重复刷新字段
+				"out_trade_no": param.OutTradeno,
+			})
+			if update {
+				util.MsgRemind.BigMemberPaySuccess(qutil.IntAll((*orderdata)["id"]), qutil.ObjToString((*orderdata)["order_code"]), qutil.ObjToString((*orderdata)["user_id"]), qutil.ObjToString((*orderdata)["prepay_time"]), qutil.IntAllDef((*orderdata)["vip_type"], -1))
+				//取消其他订单
+				go PayCancel(userId, "大会员", "")
+			}
+		}
+	}
+	return true
 }
 
 func normal_member(level int, enddate time.Time, userId string, positionType, entId, entUserId int64) {
-        //修改用户表权限
-        set := map[string]interface{}{}
-        if positionType == 0 {
-                set = map[string]interface{}{
-                        "i_member_status":      level,
-                        "i_member_starttime":   time.Now().Unix(),
-                        "i_member_endtime":     enddate.Unix(),
-                        "o_member_jy.i_wxpush": 1,
-                }
-        } else {
-                set = map[string]interface{}{
-                        "i_status":            level,
-                        "i_starttime":         time.Now().Unix(),
-                        "i_endtime":           enddate.Unix(),
-                        "o_entniche.i_wxpush": 1,
-                }
-        }
-        if level == 4 { //试用用户
-                set["i_member_trial"] = 1 //试用标识
-        } else {
-                //查看当前用户是否是试用用户 正在试用中(大会员状态ing)
-                userInfo, ok:=&map[string]interface{}{},false
-                if  positionType==0{
-                        userInfo, ok = util.MQFW.FindById("user", userId, nil)
-                }else{
-                        query := map[string]interface{}{
-                                "i_userid": entUserId,
-                                "i_entid":  entId,
-                                "i_type":   1,
-                        }
-                        userInfo, ok = util.MQFW.FindOne("entniche_rule", query)
-                }
-                if ok && userInfo != nil && *userInfo != nil {
-                        if (*userInfo)["i_member_status"] != nil && qutil.IntAll((*userInfo)["i_member_status"]) > 0 {
-                                //禁用当前大会员服务
-                                util.Mysql.UpdateOrDeleteBySql(`UPDATE `+jy.BigmemberUserPowerTable+` a SET a.i_frequency = 0 , a.i_status = -1, a.l_updatetime=? WHERE a.s_userid = ?`, NowFormat(Date_Full_Layout), userId)
-                        }
-                }
-        }
-        if positionType == 0 {
-                util.MQFW.UpdateById("user", userId, map[string]interface{}{
-                        "$set": set,
-                })
-        } else {
-                query := map[string]interface{}{
-                        "i_userid": entUserId,
-                        "i_entid":  entId,
-                        "i_type":   1,
-                }
-                util.MQFW.Update("entniche_rule", query, map[string]interface{}{
-                        "$set": set,
-                }, true, false)
-        }
-        //更新大会员用户服务表
-        bigmember_combo_list := util.Mysql.SelectBySql(`SELECT * FROM bigmember_combo a WHERE a.id = ?`, level)
-        serviceCode := "" //大会员服务id集合
-        if len(*bigmember_combo_list) > 0 {
-                list := (*bigmember_combo_list)[0]
-                serviceCode = list["s_servers"].(string)
-        }
-        if serviceCode != "" {
-                for _, v := range strings.Split(serviceCode, ",") {
-                        var s_serviceid = v
-                        var frequency = 0
-                        sid, _ := strconv.Atoi(v)
-                        if Bigmember_serice[sid] != nil {
-                                for k, v := range Bigmember_serice[sid] {
-                                        s_serviceid = strconv.Itoa(k)
-                                        frequency = v
-                                }
-                        }
-                        if util.Mysql.CountBySql(`select count(*) from `+jy.BigmemberUserPowerTable+` where s_userid=? and s_serviceid=?`, userId, v) == 0 {
-                                insert := map[string]interface{}{
-                                        "s_userid":     userId,
-                                        "s_serviceid":  s_serviceid,
-                                        "i_frequency":  frequency,
-                                        "l_starttime":  NowFormat(Date_Full_Layout),
-                                        "l_endtime":    FormatDate(&enddate, Date_Full_Layout),
-                                        "i_status":     0,
-                                        "l_createtime": NowFormat(Date_Full_Layout),
-                                        "l_updatetime": NowFormat(Date_Full_Layout),
-                                        "s_smainid":    v,
-                                }
-                                order_id := util.Mysql.Insert(jy.BigmemberUserPowerTable, insert)
-                                if order_id == 0 {
-                                        log.Println("保存出错:", userId, "---", v)
-                                }
-                        } else {
-                                query := map[string]interface{}{
-                                        "s_userid":    userId,
-                                        "s_serviceid": s_serviceid,
-                                }
-                                update := map[string]interface{}{
-                                        "i_status":     0,
-                                        "i_frequency":  frequency,
-                                        "l_updatetime": NowFormat(Date_Full_Layout),
-                                        "l_endtime":    FormatDate(&enddate, Date_Full_Layout),
-                                        "s_smainid":    v,
-                                }
-                                if !util.Mysql.Update(jy.BigmemberUserPowerTable, query, update) {
-                                        log.Println("更新大会员用户服务表出错:", userId, v)
-                                }
-                        }
-                }
-                //redis 存储缓存
-                go func() {
-                        if !jy.ClearBigVipUserPower(userId) {
-                                log.Println("userid:", userId, "清除redis缓存失败-")
-                        }
-                }()
-        } else {
-                log.Println("查询 大会员套餐 信息出错:", userId, ";大会员等级:", level)
-        }
+	//修改用户表权限
+	set := map[string]interface{}{}
+	if positionType == 0 {
+		set = map[string]interface{}{
+			"i_member_status":      level,
+			"i_member_starttime":   time.Now().Unix(),
+			"i_member_endtime":     enddate.Unix(),
+			"o_member_jy.i_wxpush": 1,
+		}
+	} else {
+		set = map[string]interface{}{
+			"i_status":            level,
+			"i_starttime":         time.Now().Unix(),
+			"i_endtime":           enddate.Unix(),
+			"o_entniche.i_wxpush": 1,
+		}
+	}
+	if level == 4 { //试用用户
+		set["i_member_trial"] = 1 //试用标识
+	} else {
+		//查看当前用户是否是试用用户 正在试用中(大会员状态ing)
+		userInfo, ok := &map[string]interface{}{}, false
+		if positionType == 0 {
+			userInfo, ok = util.MQFW.FindById("user", userId, nil)
+		} else {
+			query := map[string]interface{}{
+				"i_userid": entUserId,
+				"i_entid":  entId,
+			}
+			userInfo, ok = util.MQFW.FindOne("ent_user", query)
+		}
+		if ok && userInfo != nil && *userInfo != nil {
+			if (*userInfo)["i_member_status"] != nil && qutil.IntAll((*userInfo)["i_member_status"]) > 0 {
+				//禁用当前大会员服务
+				util.Mysql.UpdateOrDeleteBySql(`UPDATE `+jy.BigmemberUserPowerTable+` a SET a.i_frequency = 0 , a.i_status = -1, a.l_updatetime=? WHERE a.s_userid = ?`, NowFormat(Date_Full_Layout), userId)
+			}
+		}
+	}
+	if positionType == 0 {
+		util.MQFW.UpdateById("user", userId, map[string]interface{}{
+			"$set": set,
+		})
+	} else {
+		query := map[string]interface{}{
+			"i_userid": entUserId,
+			"i_entid":  entId,
+			"i_type":   1,
+		}
+		util.MQFW.Update("entniche_rule", query, map[string]interface{}{
+			"$set": set,
+		}, true, false)
+	}
+	//更新大会员用户服务表
+	bigmember_combo_list := util.Mysql.SelectBySql(`SELECT * FROM bigmember_combo a WHERE a.id = ?`, level)
+	serviceCode := "" //大会员服务id集合
+	if len(*bigmember_combo_list) > 0 {
+		list := (*bigmember_combo_list)[0]
+		serviceCode = list["s_servers"].(string)
+	}
+	if serviceCode != "" {
+		for _, v := range strings.Split(serviceCode, ",") {
+			var s_serviceid = v
+			var frequency = 0
+			sid, _ := strconv.Atoi(v)
+			if Bigmember_serice[sid] != nil {
+				for k, v := range Bigmember_serice[sid] {
+					s_serviceid = strconv.Itoa(k)
+					frequency = v
+				}
+			}
+			if util.Mysql.CountBySql(`select count(*) from `+jy.BigmemberUserPowerTable+` where s_userid=? and s_serviceid=?`, userId, v) == 0 {
+				insert := map[string]interface{}{
+					"s_userid":     userId,
+					"s_serviceid":  s_serviceid,
+					"i_frequency":  frequency,
+					"l_starttime":  NowFormat(Date_Full_Layout),
+					"l_endtime":    FormatDate(&enddate, Date_Full_Layout),
+					"i_status":     0,
+					"l_createtime": NowFormat(Date_Full_Layout),
+					"l_updatetime": NowFormat(Date_Full_Layout),
+					"s_smainid":    v,
+				}
+				order_id := util.Mysql.Insert(jy.BigmemberUserPowerTable, insert)
+				if order_id == 0 {
+					log.Println("保存出错:", userId, "---", v)
+				}
+			} else {
+				query := map[string]interface{}{
+					"s_userid":    userId,
+					"s_serviceid": s_serviceid,
+				}
+				update := map[string]interface{}{
+					"i_status":     0,
+					"i_frequency":  frequency,
+					"l_updatetime": NowFormat(Date_Full_Layout),
+					"l_endtime":    FormatDate(&enddate, Date_Full_Layout),
+					"s_smainid":    v,
+				}
+				if !util.Mysql.Update(jy.BigmemberUserPowerTable, query, update) {
+					log.Println("更新大会员用户服务表出错:", userId, v)
+				}
+			}
+		}
+		//redis 存储缓存
+		go func() {
+			if !jy.ClearBigVipUserPower(userId) {
+				log.Println("userid:", userId, "清除redis缓存失败-")
+			}
+		}()
+	} else {
+		log.Println("查询 大会员套餐 信息出错:", userId, ";大会员等级:", level)
+	}
 }
 
 func (m *memberStruct) GetMoney(userId string, level, cycle int) int {
-        if level > 7 || cycle < 1 {
-                log.Println(userId, "大会员订单level、cycle参数不合法", level, cycle)
-                return -1
-        }
-        var price float64
-        price = config.MemberConfig.Price[fmt.Sprintf("%v", level)] * float64(cycle)
-        if level == 4 {
-                price = config.MemberConfig.Price[fmt.Sprintf("%v", level)]
-        }
-        log.Println(level, " : ", price)
-        if price == 0 {
-                log.Println(userId, "大会员订单获取price错误")
-                return -1
-        }
-        if price < 1 {
-                price = 1
-        }
-        return int(price)
+	if level > 7 || cycle < 1 {
+		log.Println(userId, "大会员订单level、cycle参数不合法", level, cycle)
+		return -1
+	}
+	var price float64
+	price = config.MemberConfig.Price[fmt.Sprintf("%v", level)] * float64(cycle)
+	if level == 4 {
+		price = config.MemberConfig.Price[fmt.Sprintf("%v", level)]
+	}
+	log.Println(level, " : ", price)
+	if price == 0 {
+		log.Println(userId, "大会员订单获取price错误")
+		return -1
+	}
+	if price < 1 {
+		price = 1
+	}
+	return int(price)
 }

+ 5 - 5
src/jfw/modules/subscribepay/src/entity/order.go

@@ -1117,7 +1117,8 @@ func areaPackOrder(m map[string]interface{}, userId string, session *httpsession
 
 //附件下载包
 func filePackOrder(m map[string]interface{}, userId string, session *httpsession.Session) (*OrderInfo, string) {
-	if jy.GetBigVipUserBaseMsg(session, *config.Middleground).VipStatus <= 0 {
+	data := jy.GetBigVipUserBaseMsg(session, *config.Middleground)
+	if data.VipStatus <= 0 {
 		return nil, "非超级订阅用户,暂无权益"
 	}
 	num := qu.IntAll(m["num"])
@@ -1128,10 +1129,9 @@ func filePackOrder(m map[string]interface{}, userId string, session *httpsession
 	}
 	validTime := JyresoucePack.LastDate(time.Now())
 	//先判断用户到期时间
-	rdata, ok := util.MQFW.FindById("user", userId, `{"l_vip_endtime":1}`)
-	if ok && rdata != nil {
-		if (*rdata)["l_vip_endtime"] != nil {
-			vip_endtime := qu.Int64All((*rdata)["l_vip_endtime"])
+	if data != nil {
+		if data.Data.Vip.EndTime != 0 {
+			vip_endtime := data.Data.Vip.EndTime
 			if validTime.After(time.Unix(vip_endtime, 0)) {
 				validTime = time.Unix(vip_endtime, 0)
 				m["is_end"] = true

+ 8 - 8
src/jfw/modules/subscribepay/src/entity/resourcePackStruct.go

@@ -1,7 +1,6 @@
 package entity
 
 import (
-	"app.yhyue.com/moapp/jybase/go-xweb/httpsession"
 	"encoding/json"
 	"fmt"
 	"jy/src/jfw/modules/subscribepay/src/config"
@@ -11,6 +10,8 @@ import (
 	"strconv"
 	"time"
 
+	"app.yhyue.com/moapp/jybase/go-xweb/httpsession"
+
 	qu "app.yhyue.com/moapp/jybase/common"
 	. "app.yhyue.com/moapp/jybase/date"
 	"app.yhyue.com/moapp/jybase/redis"
@@ -120,12 +121,13 @@ func (this *resoucePackStruct) Filter(product, userid, lotteryId, discountId str
 	filter := map[string]interface{}{}
 	rs := ReturnStruct{}
 	msg := ""
+	data := jy.GetBigVipUserBaseMsg(session, *config.Middleground)
 	//产品 计算价格 生成 filter
 	switch product {
 	case "dataExportPack":
 	//TODO
 	case "attachmentDownPack": //超级订阅用户可以购买
-		if jy.GetBigVipUserBaseMsg(session, *config.Middleground).VipStatus <= 0 {
+		if data.VipStatus <= 0 {
 			msg = "非超级订阅用户,暂无权益"
 		}
 		num := qu.IntAll(m["num"])
@@ -137,10 +139,9 @@ func (this *resoucePackStruct) Filter(product, userid, lotteryId, discountId str
 		filter["num"] = num
 		validTime := this.LastDate(time.Now())
 		//先判断用户到期时间
-		rdata, ok := util.MQFW.FindById("user", userid, `{"l_vip_endtime":1}`)
-		if ok && rdata != nil {
-			if (*rdata)["l_vip_endtime"] != nil {
-				vip_endtime := qu.Int64All((*rdata)["l_vip_endtime"])
+		if data != nil {
+			if data.Data.Vip.EndTime != 0 {
+				vip_endtime := data.Data.Vip.EndTime
 				if validTime.After(time.Unix(vip_endtime, 0)) {
 					validTime = time.Unix(vip_endtime, 0)
 					filter["is_end"] = true
@@ -150,8 +151,7 @@ func (this *resoucePackStruct) Filter(product, userid, lotteryId, discountId str
 		filter["validTime"] = validTime.Format("2006-01-02")
 		rs = ReturnStruct{Filter: filter, Price: price, OrderMoney: price, Product: products}
 	case "buyerPortraitPack": //超级订阅升级版用户可以购买使用
-		uData := jy.GetBigVipUserBaseMsg(session, *config.Middleground)
-		if uData.VipStatus <= 0 || uData.Vip_BuySet.Upgrade <= 0 {
+		if data.VipStatus <= 0 || data.Vip_BuySet.Upgrade <= 0 {
 			msg = "非新版超级订阅用户,暂无权益"
 		}
 		num := qu.IntAll(m["num"])

+ 37 - 22
src/jfw/modules/subscribepay/src/entity/subscribeVip.go

@@ -6,6 +6,7 @@ import (
 	"errors"
 	"fmt"
 	"jy/src/jfw/modules/subscribepay/src/active"
+	"jy/src/jfw/modules/subscribepay/src/config"
 	"jy/src/jfw/modules/subscribepay/src/pay"
 	"jy/src/jfw/modules/subscribepay/src/util"
 	"log"
@@ -15,6 +16,7 @@ import (
 
 	qutil "app.yhyue.com/moapp/jybase/common"
 	. "app.yhyue.com/moapp/jybase/date"
+	"app.yhyue.com/moapp/jybase/go-xweb/httpsession"
 	"app.yhyue.com/moapp/jybase/redis"
 	"app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
 	"go.mongodb.org/mongo-driver/bson"
@@ -192,9 +194,9 @@ func (this *vipSubscribeStruct) PayCallBack(param *CallBackParam) bool {
 				query := map[string]interface{}{
 					"i_userid": entUserId,
 					"i_entid":  entId,
-					"i_type":   1,
 				}
-				delay_user, delay_ok = util.MQFW.FindOneByField("entniche_rule", query, `{"i_endtime":1}`)
+				delay_user, delay_ok = util.MQFW.FindOneByField("ent_user", query, `{"i_vip_status":1,"l_vip_endtime":1}`)
+
 			}
 		} else {
 			//个人类型
@@ -554,29 +556,44 @@ func (this *vipSubscribeStruct) NewBuySet(area *map[string]interface{}, industry
 }
 
 // 查询是否有试用权限
-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 { //是否有试用资格
-		return false
-	}
+func (this *vipSubscribeStruct) CanTrial(userId string, session *httpsession.Session) bool {
+	/*m, ok := util.MQFW.FindById("user", userId, `{"o_vipjy":1,"i_vip_status":1}`)
+	  if m == nil || len(*m) == 0 || !ok {
+	      return false
+	  }*/
+	data := jy.GetBigVipUserBaseMsg(session, *config.Middleground)
 	//是否使用过(使用过VIP订阅功能,就不能试用)
-	if qutil.IntAll((*m)["i_vip_status"]) != 0 { //开启状态:0-暂不使用vip订阅 1-试用 2-正式 -1-试用到期 -2-正式到期
+	if data.Data.Vip.Status != 0 { //开启状态:0-暂不使用vip订阅 1-试用 2-正式 -1-试用到期 -2-正式到期
 		return false
 	}
 	return true
 }
 
 // 订阅修改
-func (this *vipSubscribeStruct) SubChange(userId string, oldVip, areaNew *map[string]interface{}, industryNew []string) bool {
-	updateOk := util.MQFW.UpdateById("user", userId,
-		bson.M{"$set": bson.M{
-			"o_vipjy.o_area":       areaNew,     //设置地区
-			"o_vipjy.a_buyerclass": industryNew, //设置行业
-		}})
+func (this *vipSubscribeStruct) SubChange(userId string, oldVip, areaNew *map[string]interface{}, industryNew []string, session *httpsession.Session) bool {
+	updateOk := false
+	positionType := qutil.IntAll(session.Get("positionType"))
+	if positionType == 0 {
+		updateOk = util.MQFW.UpdateById("user", userId,
+			bson.M{"$set": bson.M{
+				"o_vipjy.o_area":       areaNew,     //设置地区
+				"o_vipjy.a_buyerclass": industryNew, //设置行业
+			}})
+	} else {
+		entUserId := qutil.IntAll(session.Get("entUserId"))
+		entId := qutil.IntAll(session.Get("entId"))
+		query := map[string]interface{}{
+			"i_userid": entUserId,
+			"i_entid":  entId,
+			"i_type":   1,
+		}
+		updateOk = util.MQFW.Update("entniche_rule", query,
+			bson.M{"$set": bson.M{
+				"o_entniche.o_area":       areaNew,     //设置地区
+				"o_entniche.a_buyerclass": industryNew, //设置行业
+			}}, true, false)
+	}
+
 	if !updateOk {
 		return false
 	} else {
@@ -602,9 +619,7 @@ func (this *vipSubscribeStruct) GetVipDetail(id string) (*map[string]interface{}
 	//是否处于vip状态
 	vipStatus := qutil.IntAll((*mData)["i_vip_status"])
 	tmp := qutil.ObjToMap((*qutil.ObjToMap((*mData)["o_vipjy"]))["o_buyset"])
-
 	newCity, _ := (*tmp)["newcitys"].([]interface{})
-
 	return mData, &SubvipBuySet{
 		qutil.IntAll((*tmp)["upgrade"]),
 		qutil.IntAll((*tmp)["areacount"]),
@@ -920,8 +935,8 @@ func BuyerClassStatus(userid string) bool {
 	if !ok || len(*mData) == 0 || mData == nil {
 		return false
 	}
-	if (*mData)["o_vipjy"] != nil {
-		ovipjy, _ := (*mData)["o_vipjy"].(map[string]interface{})
+	ovipjy, _ := (*mData)["o_vipjy"].(map[string]interface{})
+	if ovipjy != nil {
 		if ovipjy["a_buyerclass"] != nil {
 			return true
 		}

+ 7 - 4
src/jfw/modules/subscribepay/src/report/report.go

@@ -2,6 +2,7 @@ package report
 
 import (
 	"fmt"
+	"jy/src/jfw/modules/subscribepay/src/config"
 	"jy/src/jfw/modules/subscribepay/src/util"
 	"sort"
 	"strings"
@@ -11,6 +12,7 @@ import (
 	"app.yhyue.com/moapp/jybase/encrypt"
 	"app.yhyue.com/moapp/jybase/go-xweb/httpsession"
 	"app.yhyue.com/moapp/jybase/go-xweb/xweb"
+	"app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
 )
 
 var (
@@ -92,7 +94,7 @@ func (r *Report) Newest() {
 func (r *Report) Index() {
 	ym, _ := r.GetInteger("ym")
 	result := map[string]interface{}{}
-	userId, qk, qv := getQuery(r.Session())
+	_, qk, qv := getQuery(r.Session())
 	if qk == "" || qv == nil {
 		return
 	}
@@ -126,14 +128,15 @@ func (r *Report) Index() {
 			delete(result, "month")
 		}
 	}
-	u, ok := util.MQFW.FindById("user", userId, `{"i_vip_status":1,"i_member_status":1}`)
+	//u, ok := util.MQFW.FindById("user", userId, `{"i_vip_status":1,"i_member_status":1}`)
+	u := jy.GetBigVipUserBaseMsg(r.Session(), *config.Middleground)
 	services := []string{}
 	memberStatus := 0
 	if ok && u != nil {
-		if qutil.IntAll((*u)["i_vip_status"]) > 0 {
+		if u.VipStatus > 0 {
 			services = append(services, "vip")
 		}
-		memberStatus = qutil.IntAll((*u)["i_member_status"])
+		memberStatus = u.Status
 		if memberStatus > 0 {
 			services = append(services, "member")
 		}

+ 4 - 3
src/jfw/modules/subscribepay/src/service/afterPay.go

@@ -43,10 +43,11 @@ func (a *AfterPay) Modification() error {
 	userId, _ := a.GetSession("userId").(string)
 	mflag := false
 	if userId != "" {
-		data, ok := util.MQFW.FindById("user", userId, `{"o_vipjy":1}`)
-		if ok && len(*data) > 0 && data != nil {
+		//data, ok := util.MQFW.FindById("user", userId, `{"o_vipjy":1}`)
+		data := jy.GetSubScribeInfo(a.Session(), util.MQFW, "v", "10000")
+		if len(*data) > 0 && data != nil {
 			var snapMap = map[string]interface{}{}
-			snapMap["o_vipjy"], _ = (*data)["o_vipjy"].(map[string]interface{})
+			snapMap["o_vipjy"] = &data
 			snapMap["s_userId"], _ = a.GetSession("userId").(string)
 			snapMap["s_nickname"], _ = a.GetSession("s_nickname").(string)
 			snapMap["l_modifydate"] = time.Now().Unix()

+ 1 - 3
src/jfw/modules/subscribepay/src/service/vipSubscribeChange.go

@@ -107,7 +107,6 @@ func (this *SubscribeChange) SaveChange() {
 	area := qutil.ObjToMap(this.GetString("area"))
 	industry := strings.Split(this.GetString("industry"), ",")
 	userId := qutil.ObjToString(this.GetSession("userId"))
-
 	r := func() *entity.FuncResult {
 		if len(industry) == 1 && industry[0] == "" {
 			industry = []string{}
@@ -120,12 +119,11 @@ func (this *SubscribeChange) SaveChange() {
 			return &entity.FuncResult{false, errors.New("获取信息失败"), nil}
 		}
 		newBuyset := entity.JyVipSubStruct.NewBuySet(area, industry, oldBuyset.Upgrade == 1)
-
 		if needUpgrade := needUpgrade(newBuyset, oldBuyset); needUpgrade {
 			log.Printf("%s 订阅内容超出套餐 %+v area:%s industry:%s", userId, oldBuyset, this.GetString("area"), this.GetString("industry"))
 			return &entity.FuncResult{false, errors.New("订阅内容超出套餐"), nil}
 		}
-		if !entity.JyVipSubStruct.SubChange(userId, qutil.ObjToMap((*rData)["o_vipjy"]), area, industry) {
+		if !entity.JyVipSubStruct.SubChange(userId, qutil.ObjToMap((*rData)["o_vipjy"]), area, industry, this.Session()) {
 			return &entity.FuncResult{false, errors.New("保存修改出错"), nil}
 		}
 		return &entity.FuncResult{true, nil, map[string]interface{}{

+ 302 - 302
src/jfw/modules/subscribepay/src/service/vipSubscribeTrial.go

@@ -1,355 +1,355 @@
 package service
 
 import (
-        "encoding/json"
-        "errors"
-        "jy/src/jfw/modules/subscribepay/src/config"
-        "jy/src/jfw/modules/subscribepay/src/entity"
-        "jy/src/jfw/modules/subscribepay/src/pay"
-        "jy/src/jfw/modules/subscribepay/src/util"
-        "log"
-        "regexp"
-        "strings"
-        "time"
+	"encoding/json"
+	"errors"
+	"jy/src/jfw/modules/subscribepay/src/config"
+	"jy/src/jfw/modules/subscribepay/src/entity"
+	"jy/src/jfw/modules/subscribepay/src/pay"
+	"jy/src/jfw/modules/subscribepay/src/util"
+	"log"
+	"regexp"
+	"strings"
+	"time"
 
-        qutil "app.yhyue.com/moapp/jybase/common"
-        . "app.yhyue.com/moapp/jybase/date"
-        "app.yhyue.com/moapp/jybase/go-xweb/httpsession"
-        "app.yhyue.com/moapp/jybase/go-xweb/xweb"
-        "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
-        "github.com/dchest/captcha"
-        "go.mongodb.org/mongo-driver/bson"
+	qutil "app.yhyue.com/moapp/jybase/common"
+	. "app.yhyue.com/moapp/jybase/date"
+	"app.yhyue.com/moapp/jybase/go-xweb/httpsession"
+	"app.yhyue.com/moapp/jybase/go-xweb/xweb"
+	"app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
+	"github.com/dchest/captcha"
+	"go.mongodb.org/mongo-driver/bson"
 )
 
 //试用用户
 type TrialOrder struct {
-        *xweb.Action
-        showTrailTip        xweb.Mapper `xweb:"/trial/showTrailTip"`        //首页试用弹框是否展示
-        closeTrailTip       xweb.Mapper `xweb:"/trial/closeTrailTip"`       //关闭首页试用弹框
-        getUserPhone        xweb.Mapper `xweb:"/trial/GetUserPhone"`        //获取用户手机号码
-        captcha             xweb.Mapper `xweb:"/trial/captcha"`             //图形验证码
-        sendPhoneCaptcha    xweb.Mapper `xweb:"/trial/sendPhoneCaptcha"`    //发送手机验证码
-        submitApply         xweb.Mapper `xweb:"/trial/submitApply"`         //提交申请信息
-        trialPay            xweb.Mapper `xweb:"/order/trialPay"`            //试用用户创建订单
-        getTrialOrderPayMsg xweb.Mapper `xweb:"/order/getTrialOrderPayMsg"` //订单数据展示(支付成功页面)
+	*xweb.Action
+	showTrailTip        xweb.Mapper `xweb:"/trial/showTrailTip"`        //首页试用弹框是否展示
+	closeTrailTip       xweb.Mapper `xweb:"/trial/closeTrailTip"`       //关闭首页试用弹框
+	getUserPhone        xweb.Mapper `xweb:"/trial/GetUserPhone"`        //获取用户手机号码
+	captcha             xweb.Mapper `xweb:"/trial/captcha"`             //图形验证码
+	sendPhoneCaptcha    xweb.Mapper `xweb:"/trial/sendPhoneCaptcha"`    //发送手机验证码
+	submitApply         xweb.Mapper `xweb:"/trial/submitApply"`         //提交申请信息
+	trialPay            xweb.Mapper `xweb:"/order/trialPay"`            //试用用户创建订单
+	getTrialOrderPayMsg xweb.Mapper `xweb:"/order/getTrialOrderPayMsg"` //订单数据展示(支付成功页面)
 }
 
 var (
-        phoneReg = regexp.MustCompile("^[1][3-9][0-9]{9}$")
-        nameReg  = regexp.MustCompile("^[\u4E00-\u9FA5A-Za-z\\s]+(·[\u4E00-\u9FA5A-Za-z]+)*$")
+	phoneReg = regexp.MustCompile("^[1][3-9][0-9]{9}$")
+	nameReg  = regexp.MustCompile("^[\u4E00-\u9FA5A-Za-z\\s]+(·[\u4E00-\u9FA5A-Za-z]+)*$")
 )
 
 //首页试用弹框是否展示
 func (t *TrialOrder) ShowTrailTip() {
-        userId := qutil.ObjToString(t.GetSession("userId"))
-        showTrailTip := true
-        m, _ := util.MQFW.FindById("user", userId, `{"o_vipjy":1}`)
-        if m != nil && len(*m) > 0 {
-                if (*qutil.ObjToMap((*m)["o_vipjy"]))["i_trial"] != nil {
-                        showTrailTip = false
-                }
-        }
-        t.ServeJson(map[string]interface{}{
-                "showTrailTip": showTrailTip,
-        })
+	userId := qutil.ObjToString(t.GetSession("userId"))
+	showTrailTip := true
+	m, _ := util.MQFW.FindById("user", userId, `{"o_vipjy":1}`)
+	if m != nil && len(*m) > 0 {
+		if (*qutil.ObjToMap((*m)["o_vipjy"]))["i_trial"] != nil {
+			showTrailTip = false
+		}
+	}
+	t.ServeJson(map[string]interface{}{
+		"showTrailTip": showTrailTip,
+	})
 }
 
 //关闭首页试用弹框
 func (t *TrialOrder) CloseTrailTip() {
-        userId := qutil.ObjToString(t.GetSession("userId"))
-        ok := false
-        if util.MQFW.UpdateById("user", userId,
-                bson.M{"$set": bson.M{
-                        "o_vipjy.i_trial": 2}}) {
-                ok = true
-        } //已激活试用
-        t.ServeJson(map[string]interface{}{
-                "success": ok,
-        })
+	userId := qutil.ObjToString(t.GetSession("userId"))
+	ok := false
+	if util.MQFW.UpdateById("user", userId,
+		bson.M{"$set": bson.M{
+			"o_vipjy.i_trial": 2}}) {
+		ok = true
+	} //已激活试用
+	t.ServeJson(map[string]interface{}{
+		"success": ok,
+	})
 }
 
 //获取之前用户信息
 func (t *TrialOrder) GetUserPhone() {
-        var phoneNum string
-        userId := qutil.ObjToString(t.GetSession("userId"))
-        if userId != "" {
-                m, ok := util.MQFW.FindById("user", userId, `{"s_phone":1}`)
-                if ok && len(*m) > 0 {
-                        phoneNum = qutil.ObjToString((*m)["s_phone"])
-                }
-        }
-        if phoneNum == "" {
-                openid := qutil.ObjToString(t.GetSession("s_m_openid"))
-                if openid != "" {
-                        m, ok := util.MQFW.FindOneByField("applysub_user", bson.M{"s_openid": openid}, `{"s_phone":1}`)
-                        if ok && len(*m) > 0 {
-                                phoneNum = qutil.ObjToString((*m)["s_phone"])
-                        }
-                }
-        }
-        t.ServeJson(map[string]interface{}{
-                "success":  qutil.If(phoneNum == "", false, true).(bool),
-                "phoneNum": phoneNum,
-        })
+	var phoneNum string
+	userId := qutil.ObjToString(t.GetSession("userId"))
+	if userId != "" {
+		m, ok := util.MQFW.FindById("user", userId, `{"s_phone":1}`)
+		if ok && len(*m) > 0 {
+			phoneNum = qutil.ObjToString((*m)["s_phone"])
+		}
+	}
+	if phoneNum == "" {
+		openid := qutil.ObjToString(t.GetSession("s_m_openid"))
+		if openid != "" {
+			m, ok := util.MQFW.FindOneByField("applysub_user", bson.M{"s_openid": openid}, `{"s_phone":1}`)
+			if ok && len(*m) > 0 {
+				phoneNum = qutil.ObjToString((*m)["s_phone"])
+			}
+		}
+	}
+	t.ServeJson(map[string]interface{}{
+		"success":  qutil.If(phoneNum == "", false, true).(bool),
+		"phoneNum": phoneNum,
+	})
 }
 
 //试用用户图片验证码
 func (t *TrialOrder) Captcha() error {
-        id := captcha.NewLen(4)
-        t.SetSession("subvip_trial_imgCode", id)
-        w := t.ResponseWriter
-        w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
-        w.Header().Set("Pragma", "no-cache")
-        w.Header().Set("Expires", "0")
-        w.Header().Set("Content-Type", "image/png")
-        return captcha.WriteImage(w, id, 90, 30)
+	id := captcha.NewLen(4)
+	t.SetSession("subvip_trial_imgCode", id)
+	w := t.ResponseWriter
+	w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
+	w.Header().Set("Pragma", "no-cache")
+	w.Header().Set("Expires", "0")
+	w.Header().Set("Content-Type", "image/png")
+	return captcha.WriteImage(w, id, 90, 30)
 }
 
 //发送手机验证码
 func (t *TrialOrder) SendPhoneCaptcha() {
-        phoneNum := t.GetString("phoneNum")
-        imgcode_req := t.GetString("imgCancode")
-        ok, errMsg := func() (bool, string) {
-                if !phoneReg.MatchString(phoneNum) {
-                        return false, "手机格式不正确"
-                }
-                imgcode_sess := qutil.ObjToString(t.GetSession("subvip_trial_imgCode"))
-                if !captcha.VerifyString(imgcode_sess, imgcode_req) || imgcode_req == "" {
-                        return false, "图形验证码错误"
-                }
-                //获取上次发送验证码时间
-                lastSend := qutil.Int64All(t.GetSession("subvip_trial_lastSend"))
-                if time.Now().Unix()-lastSend < 60 {
-                        return false, "信息已发送"
-                }
-                //判断手机号是否存在
-                if isExist(phoneNum) {
-                        return false, "手机号已使用"
-                }
-                MsgCode := qutil.GetRandom(6)
-                t.SetSession("subvip_trial_MsgCode", MsgCode)
-                t.SetSession("subvip_trial_phoneNum", phoneNum)
-                t.SetSession("subvip_trial_lastSend", time.Now().Unix())
-                log.Printf("%s 发送短信验证码 %s\n", t.GetSession("userId"), MsgCode)
-                go func() {
-                        jy.SendSMS(config.Config.SmsServiceRpc, phoneNum, MsgCode)
-                }()
-                return true, ""
-        }()
-        t.ServeJson(map[string]interface{}{
-                "success": ok,
-                "errMsg":  errMsg,
-        })
+	phoneNum := t.GetString("phoneNum")
+	imgcode_req := t.GetString("imgCancode")
+	ok, errMsg := func() (bool, string) {
+		if !phoneReg.MatchString(phoneNum) {
+			return false, "手机格式不正确"
+		}
+		imgcode_sess := qutil.ObjToString(t.GetSession("subvip_trial_imgCode"))
+		if !captcha.VerifyString(imgcode_sess, imgcode_req) || imgcode_req == "" {
+			return false, "图形验证码错误"
+		}
+		//获取上次发送验证码时间
+		lastSend := qutil.Int64All(t.GetSession("subvip_trial_lastSend"))
+		if time.Now().Unix()-lastSend < 60 {
+			return false, "信息已发送"
+		}
+		//判断手机号是否存在
+		if isExist(phoneNum) {
+			return false, "手机号已使用"
+		}
+		MsgCode := qutil.GetRandom(6)
+		t.SetSession("subvip_trial_MsgCode", MsgCode)
+		t.SetSession("subvip_trial_phoneNum", phoneNum)
+		t.SetSession("subvip_trial_lastSend", time.Now().Unix())
+		log.Printf("%s 发送短信验证码 %s\n", t.GetSession("userId"), MsgCode)
+		go func() {
+			jy.SendSMS(config.Config.SmsServiceRpc, phoneNum, MsgCode)
+		}()
+		return true, ""
+	}()
+	t.ServeJson(map[string]interface{}{
+		"success": ok,
+		"errMsg":  errMsg,
+	})
 }
 
 //提交申请信息
 func (t *TrialOrder) SubmitApply() {
-        name := t.GetString("name")
-        tel := t.GetString("tel")
-        code := t.GetString("code")
-        company := t.GetString("company")
-        job := t.GetString("job")
-        ok, errMsg := func() (bool, string) {
-                //校验数据
-                if !nameReg.MatchString(name) || code == "" || company == "" {
-                        return false, "输入校验不通过"
-                }
-                //校验验证码
-                lastSend := qutil.Int64All(t.GetSession("subvip_trial_lastSend"))
-                if time.Now().Unix()-lastSend > 60*5 {
-                        return false, "短信验证码已过期"
-                }
-                code_sess := qutil.ObjToString(t.GetSession("subvip_trial_MsgCode"))
-                tel_sess := qutil.ObjToString(t.GetSession("subvip_trial_phoneNum"))
-                if code != code_sess || tel != tel_sess {
-                        return false, "短信验证码错误"
-                }
-                if isExist(tel_sess) {
-                        return false, "手机号已使用"
-                }
-                //储存数据
-                userId := qutil.ObjToString(t.GetSession("userId"))
-                flag := util.MQFW.Save("user_msg", map[string]interface{}{
-                        "s_userId":  userId,
-                        "s_name":    name,
-                        "s_phone":   tel,
-                        "s_openid":  t.GetSession("s_m_openid"),
-                        "s_company": company,
-                        "s_job":     job,
-                        "i_time":    time.Now().Unix(),
-                        "s_source":  "vipsub_trial",
-                })
-                util.CollectPhone(userId, tel) //收集手机号
-                if flag == "" {
-                        return false, "稍后重试"
-                }
-                go func() {
-                        //更新user表可试用(未试用状态)
-                        res, ok := util.MQFW.FindById("user", userId, `{"o_vipjy.i_trial":1}`)
-                        if res != nil && len(*res) > 0 && ok {
-                                o_vipjy := qutil.ObjToMap((*res)["o_vipjy"])
-                                i_trial, ok := (*o_vipjy)["i_trial"]
-                                if !ok || qutil.IntAll(i_trial) == 2 { //2为不提示状态
-                                        if !util.MQFW.UpdateById("user", userId, bson.M{"$set": bson.M{"o_vipjy.i_trial": 1}}) {
-                                                log.Println("更新使用状态出错", userId)
-                                        }
-                                } else {
-                                        log.Printf("%s: 状态%d不能修改为试用状态\n", userId, i_trial)
-                                }
-                        }
-                }()
-                clearTrialSession(t.Session())
-                return true, ""
-        }()
-        t.ServeJson(map[string]interface{}{
-                "success": ok,
-                "errMsg":  errMsg,
-        })
+	name := t.GetString("name")
+	tel := t.GetString("tel")
+	code := t.GetString("code")
+	company := t.GetString("company")
+	job := t.GetString("job")
+	ok, errMsg := func() (bool, string) {
+		//校验数据
+		if !nameReg.MatchString(name) || code == "" || company == "" {
+			return false, "输入校验不通过"
+		}
+		//校验验证码
+		lastSend := qutil.Int64All(t.GetSession("subvip_trial_lastSend"))
+		if time.Now().Unix()-lastSend > 60*5 {
+			return false, "短信验证码已过期"
+		}
+		code_sess := qutil.ObjToString(t.GetSession("subvip_trial_MsgCode"))
+		tel_sess := qutil.ObjToString(t.GetSession("subvip_trial_phoneNum"))
+		if code != code_sess || tel != tel_sess {
+			return false, "短信验证码错误"
+		}
+		if isExist(tel_sess) {
+			return false, "手机号已使用"
+		}
+		//储存数据
+		userId := qutil.ObjToString(t.GetSession("userId"))
+		flag := util.MQFW.Save("user_msg", map[string]interface{}{
+			"s_userId":  userId,
+			"s_name":    name,
+			"s_phone":   tel,
+			"s_openid":  t.GetSession("s_m_openid"),
+			"s_company": company,
+			"s_job":     job,
+			"i_time":    time.Now().Unix(),
+			"s_source":  "vipsub_trial",
+		})
+		util.CollectPhone(userId, tel) //收集手机号
+		if flag == "" {
+			return false, "稍后重试"
+		}
+		go func() {
+			//更新user表可试用(未试用状态)
+			res, ok := util.MQFW.FindById("user", userId, `{"o_vipjy.i_trial":1}`)
+			if res != nil && len(*res) > 0 && ok {
+				o_vipjy := qutil.ObjToMap((*res)["o_vipjy"])
+				i_trial, ok := (*o_vipjy)["i_trial"]
+				if !ok || qutil.IntAll(i_trial) == 2 { //2为不提示状态
+					if !util.MQFW.UpdateById("user", userId, bson.M{"$set": bson.M{"o_vipjy.i_trial": 1}}) {
+						log.Println("更新使用状态出错", userId)
+					}
+				} else {
+					log.Printf("%s: 状态%d不能修改为试用状态\n", userId, i_trial)
+				}
+			}
+		}()
+		clearTrialSession(t.Session())
+		return true, ""
+	}()
+	t.ServeJson(map[string]interface{}{
+		"success": ok,
+		"errMsg":  errMsg,
+	})
 }
 
 //查询手机号是否存在
 func isExist(phone string) bool {
-        res, ok := util.MQFW.FindOne("user_msg", bson.M{"s_phone": phone, "s_source": "vipsub_trial"})
-        if ok && len(*res) > 0 {
-                return true
-        }
-        return false
+	res, ok := util.MQFW.FindOne("user_msg", bson.M{"s_phone": phone, "s_source": "vipsub_trial"})
+	if ok && len(*res) > 0 {
+		return true
+	}
+	return false
 }
 
 //清除session
 func clearTrialSession(session *httpsession.Session) {
-        session.Del("subvip_trial_MsgCode")
-        session.Del("subvip_trial_phoneNum")
-        session.Del("subvip_trial_lastSend")
-        session.Del("subvip_trial_imgCode")
+	session.Del("subvip_trial_MsgCode")
+	session.Del("subvip_trial_phoneNum")
+	session.Del("subvip_trial_lastSend")
+	session.Del("subvip_trial_imgCode")
 }
 
 //订单数据展示(支付成功页面)
 func (this *TrialOrder) GetTrialOrderPayMsg() {
-        orderCode := this.GetString("orderCode")
-        userId := this.GetSession("userId")
-        query := map[string]interface{}{
-                "user_id":      userId,
-                "order_code":   orderCode,
-                "order_status": 1,
-        }
-        m := util.Mysql.FindOne("dataexport_order", query, "pay_time,pay_way", "")
-        result := map[string]interface{}{}
-        if m == nil || len(*m) == 0 {
-                result["success"] = false
-                result["errMsg"] = "未找到订单"
-        } else {
-                result["success"] = true
-                result["pay_time"] = (*m)["pay_time"]
-                result["pay_way"] = (*m)["pay_way"]
-        }
-        this.ServeJson(result)
+	orderCode := this.GetString("orderCode")
+	userId := this.GetSession("userId")
+	query := map[string]interface{}{
+		"user_id":      userId,
+		"order_code":   orderCode,
+		"order_status": 1,
+	}
+	m := util.Mysql.FindOne("dataexport_order", query, "pay_time,pay_way", "")
+	result := map[string]interface{}{}
+	if m == nil || len(*m) == 0 {
+		result["success"] = false
+		result["errMsg"] = "未找到订单"
+	} else {
+		result["success"] = true
+		result["pay_time"] = (*m)["pay_time"]
+		result["pay_way"] = (*m)["pay_way"]
+	}
+	this.ServeJson(result)
 
 }
 
 //试用用户 创建订单
 func (this *TrialOrder) TrialPay() {
-        area := qutil.ObjToMap(this.GetString("area"))
-        industry := strings.Split(this.GetString("industry"), ",")
-        userId := qutil.ObjToString(this.GetSession("userId"))
-        openId := qutil.ObjToString(this.GetSession("s_m_openid"))
-        r := func() *entity.FuncResult {
-                date_count, date_unit := 7, 3
-                now := time.Now()
-                //数据校验
-                if len(industry) == 1 && industry[0] == "" { //去掉[""]
-                        industry = []string{}
-                }
-                order_phone := this.GetString("order_phone") //p19.3用户信息采集 手机号
-                //插入订单表
-                mog_id := util.MQFW.Save("subvip_select", map[string]interface{}{
-                        "o_area":       area,     //地区(对象)
-                        "a_industry":   industry, //行业(数组)
-                        "s_userid":     userId,
-                        "s_openid":     openId,
-                        "i_cyclecount": date_count, //时长
-                        "i_cycleunit":  date_unit,  //单位
-                        "i_comeintime": now.Unix(),
-                })
-                if mog_id == "" {
-                        return &entity.FuncResult{false, errors.New("创建订单出错"), nil}
-                }
-                if !entity.JyVipSubStruct.CanTrial(userId) {
-                        return &entity.FuncResult{false, errors.New("无试用权限"), nil}
-                }
-                //计算价格
-                totalfee := 0
-                ordercode := pay.GetOrderCode(userId)
-                //存入订单表
-                buyset := entity.JyVipSubStruct.NewBuySet(area, industry, true) //试用用户
-                filter := entity.VipSimpleMsg{
-                        Area:       area,
-                        Industry:   industry,
-                        Cyclecount: date_count,
-                        Cycleunit:  date_unit,
-                        NewBuyset:  buyset,
-                        OrderType:  0,
-                        DisWord:    "",
-                }
-                filterStr, _ := json.Marshal(filter)
-                //结束日期 按照 自然周 算 (例:11.11开通 11.17 23.59.59结束)
-                //endTime := now.AddDate(0, 0, 7)
-                endTime_format := now.AddDate(0, 0, 7).Format(Date_Short_Layout)
-                stamp, _ := time.ParseInLocation(Date_Short_Layout, endTime_format, time.Local)
-                stamp_time := stamp.Unix() - 1 //23.59.59
-                endt := time.Unix(stamp_time, 0).Format(Date_Full_Layout)
-                endTime, _ := time.ParseInLocation(Date_Full_Layout, endt, time.Local)
-                distributionChannel, orderChannel := util.GetJyOrderChannel("", this.Header("User-Agent"))
-                entId := qutil.Int64All(this.GetSession("entId"))
-                buy_subject := 1
-                if entId > 0 {
-                        buy_subject = 2
-                }
-                insertObj := map[string]interface{}{
-                        "order_money":          totalfee,
-                        "order_status":         1,
-                        "user_nickname":        qutil.ObjToString(this.GetSession("s_nickname")),
-                        "user_openid":          openId,
-                        "out_trade_no":         "tradeno",
-                        "order_code":           ordercode,
-                        "product_type":         "VIP订阅",
-                        "create_time":          FormatDate(&now, Date_Full_Layout),
-                        "prepay_time":          FormatDate(&now, Date_Full_Layout),
-                        "original_price":       totalfee,
-                        "filter_id":            mog_id,
-                        "pay_way":              "trial", //试用
-                        "user_id":              userId,
-                        "vip_type":             0,                 //试用用户订单
-                        "filter":               string(filterStr), //筛选
-                        "pay_time":             FormatDate(&now, Date_Full_Layout),
-                        "vip_starttime":        FormatDate(&now, Date_Full_Layout),
-                        "vip_endtime":          FormatDate(&endTime, Date_Full_Layout),
-                        "distribution_channel": distributionChannel, //销售渠道
-                        "order_channel":        orderChannel,        //下单渠道
-                        "audit_status":         3,                   //默认审核通过
-                        "buy_subject":          buy_subject,
-                        "ent_id":               entId,
-                }
-                if order_phone != "" {
-                        if !jy.PhoneReg.MatchString(order_phone) {
-                                return &entity.FuncResult{false, errors.New("手机号格式异常"), nil}
-                        }
-                        insertObj["user_phone"] = order_phone
-                }
-                orderid := util.Mysql.Insert("dataexport_order", insertObj)
-                if orderid == -1 {
-                        return &entity.FuncResult{false, errors.New("数据保存异常"), nil}
-                }
-                //后期
-                if !entity.JyVipSubStruct.StartSubVip(userId, filter, now, endTime, true, 0, 0, 0) { //设置开始试用
-                        return &entity.FuncResult{false, errors.New("开通试用异常"), nil}
-                }
-                //支付提醒
-                util.MsgRemind.PaySuccess(qutil.IntAll(orderid), ordercode, userId, FormatDate(&now, Date_Full_Layout), 0)
-                return &entity.FuncResult{true, nil, map[string]interface{}{"code": ordercode}}
-        }()
-        if r.Err != nil {
-                log.Printf("%s CreateTrialOrder err:%v\n", userId, r.Err.Error())
-        }
-        this.ServeJson(r.Format())
+	area := qutil.ObjToMap(this.GetString("area"))
+	industry := strings.Split(this.GetString("industry"), ",")
+	userId := qutil.ObjToString(this.GetSession("userId"))
+	openId := qutil.ObjToString(this.GetSession("s_m_openid"))
+	r := func() *entity.FuncResult {
+		date_count, date_unit := 7, 3
+		now := time.Now()
+		//数据校验
+		if len(industry) == 1 && industry[0] == "" { //去掉[""]
+			industry = []string{}
+		}
+		order_phone := this.GetString("order_phone") //p19.3用户信息采集 手机号
+		//插入订单表
+		mog_id := util.MQFW.Save("subvip_select", map[string]interface{}{
+			"o_area":       area,     //地区(对象)
+			"a_industry":   industry, //行业(数组)
+			"s_userid":     userId,
+			"s_openid":     openId,
+			"i_cyclecount": date_count, //时长
+			"i_cycleunit":  date_unit,  //单位
+			"i_comeintime": now.Unix(),
+		})
+		if mog_id == "" {
+			return &entity.FuncResult{false, errors.New("创建订单出错"), nil}
+		}
+		if !entity.JyVipSubStruct.CanTrial(userId, this.Session()) {
+			return &entity.FuncResult{false, errors.New("无试用权限"), nil}
+		}
+		//计算价格
+		totalfee := 0
+		ordercode := pay.GetOrderCode(userId)
+		//存入订单表
+		buyset := entity.JyVipSubStruct.NewBuySet(area, industry, true) //试用用户
+		filter := entity.VipSimpleMsg{
+			Area:       area,
+			Industry:   industry,
+			Cyclecount: date_count,
+			Cycleunit:  date_unit,
+			NewBuyset:  buyset,
+			OrderType:  0,
+			DisWord:    "",
+		}
+		filterStr, _ := json.Marshal(filter)
+		//结束日期 按照 自然周 算 (例:11.11开通 11.17 23.59.59结束)
+		//endTime := now.AddDate(0, 0, 7)
+		endTime_format := now.AddDate(0, 0, 7).Format(Date_Short_Layout)
+		stamp, _ := time.ParseInLocation(Date_Short_Layout, endTime_format, time.Local)
+		stamp_time := stamp.Unix() - 1 //23.59.59
+		endt := time.Unix(stamp_time, 0).Format(Date_Full_Layout)
+		endTime, _ := time.ParseInLocation(Date_Full_Layout, endt, time.Local)
+		distributionChannel, orderChannel := util.GetJyOrderChannel("", this.Header("User-Agent"))
+		entId := qutil.Int64All(this.GetSession("entId"))
+		buy_subject := 1
+		if entId > 0 {
+			buy_subject = 2
+		}
+		insertObj := map[string]interface{}{
+			"order_money":          totalfee,
+			"order_status":         1,
+			"user_nickname":        qutil.ObjToString(this.GetSession("s_nickname")),
+			"user_openid":          openId,
+			"out_trade_no":         "tradeno",
+			"order_code":           ordercode,
+			"product_type":         "VIP订阅",
+			"create_time":          FormatDate(&now, Date_Full_Layout),
+			"prepay_time":          FormatDate(&now, Date_Full_Layout),
+			"original_price":       totalfee,
+			"filter_id":            mog_id,
+			"pay_way":              "trial", //试用
+			"user_id":              userId,
+			"vip_type":             0,                 //试用用户订单
+			"filter":               string(filterStr), //筛选
+			"pay_time":             FormatDate(&now, Date_Full_Layout),
+			"vip_starttime":        FormatDate(&now, Date_Full_Layout),
+			"vip_endtime":          FormatDate(&endTime, Date_Full_Layout),
+			"distribution_channel": distributionChannel, //销售渠道
+			"order_channel":        orderChannel,        //下单渠道
+			"audit_status":         3,                   //默认审核通过
+			"buy_subject":          buy_subject,
+			"ent_id":               entId,
+		}
+		if order_phone != "" {
+			if !jy.PhoneReg.MatchString(order_phone) {
+				return &entity.FuncResult{false, errors.New("手机号格式异常"), nil}
+			}
+			insertObj["user_phone"] = order_phone
+		}
+		orderid := util.Mysql.Insert("dataexport_order", insertObj)
+		if orderid == -1 {
+			return &entity.FuncResult{false, errors.New("数据保存异常"), nil}
+		}
+		//后期
+		if !entity.JyVipSubStruct.StartSubVip(userId, filter, now, endTime, true, 0, 0, 0) { //设置开始试用
+			return &entity.FuncResult{false, errors.New("开通试用异常"), nil}
+		}
+		//支付提醒
+		util.MsgRemind.PaySuccess(qutil.IntAll(orderid), ordercode, userId, FormatDate(&now, Date_Full_Layout), 0)
+		return &entity.FuncResult{true, nil, map[string]interface{}{"code": ordercode}}
+	}()
+	if r.Err != nil {
+		log.Printf("%s CreateTrialOrder err:%v\n", userId, r.Err.Error())
+	}
+	this.ServeJson(r.Format())
 }