Procházet zdrojové kódy

feat:p525 兑换接口调整

fuwencai před 1 rokem
rodič
revize
d5ba3a2564

+ 12 - 1
jydocs-back/config.json

@@ -31,6 +31,12 @@
       "address": [
         "192.168.3.206:2379"
       ]
+    },
+    "partner": {
+      "key": "jydocs.partnerlib.rpc",
+      "address": [
+        "192.168.3.206:2379"
+      ]
     }
   },
   "indexSearchTag": [
@@ -58,6 +64,11 @@
   "docMember": {
     "times": 100,
     "discount": 8,
-    "source":["pc_Library details_free","app_Library details_free","wx_Library details_free","h5_Library details_free"]
+    "source": [
+      "pc_library_details_free",
+      "app_library_details_free",
+      "wx_library_details_free",
+      "h5_library_details_free"
+    ]
   }
 }

+ 1 - 0
jydocs-back/config/config.go

@@ -23,6 +23,7 @@ type appConfig struct {
 		UserDoc rpcConfig `json:"userDoc"` //用户收藏rpc接口
 		Points  rpcConfig `json:"points"`  //剑鱼积分rpc接口
 		JyFile  rpcConfig `json:"jyFile"`  //剑鱼文件rpc接口
+		Partner rpcConfig `json:"partner"` //剑鱼文库豆丁购买和下载接口rpc接口
 	} `json:"rpcServers"` //rpc服务配置
 	IndexSearchTag []string `json:"indexSearchTag"` //首页标签
 	SearchNumLimit int64    `json:"searchNumLimit"` //检索条数限制

+ 1 - 1
jydocs-back/go.mod

@@ -4,7 +4,6 @@ go 1.21
 
 require (
 	app.yhyue.com/moapp/jyPoints v1.1.2-0.20231020023521-1a4b1bbf9736
-	app.yhyue.com/moapp/jy_docs v1.1.5
 	app.yhyue.com/moapp/jybase v0.0.0-20240523083821-42a82b37ae20
 	app.yhyue.com/moapp/jyfs v0.0.0-20231024061508-480c270480d4
 	app.yhyue.com/moapp/jypkg v1.20.1
@@ -17,6 +16,7 @@ require (
 
 require (
 	app.yhyue.com/moapp/jyMarketing v0.0.2-0.20230304035551-21bb1eedf547 // indirect
+	app.yhyue.com/moapp/jy_docs v1.1.6-0.20240604014054-b9f28f2d7d7d // indirect
 	bp.jydev.jianyu360.cn/BaseService/entManageApplication v0.0.0-20231226074509-942d80dc34eb // indirect
 	bp.jydev.jianyu360.cn/BaseService/jyMicroservices v0.0.2 // indirect
 	bp.jydev.jianyu360.cn/BaseService/powerCheckCenter v0.0.0-20231222060155-36e225b61353 // indirect

+ 2 - 0
jydocs-back/go.sum

@@ -7,6 +7,8 @@ app.yhyue.com/moapp/jyPoints v1.1.2-0.20231020023521-1a4b1bbf9736/go.mod h1:NEkV
 app.yhyue.com/moapp/jy_docs v1.1.1/go.mod h1:54sK98Z5tpMFd2aPLN1IRfEyV3zpFRyFxKj6oi2C5/Q=
 app.yhyue.com/moapp/jy_docs v1.1.5 h1:IvpRZd3P7vBxrIIRfio2reK2hiNbX9xppKGu/egCO5w=
 app.yhyue.com/moapp/jy_docs v1.1.5/go.mod h1:54sK98Z5tpMFd2aPLN1IRfEyV3zpFRyFxKj6oi2C5/Q=
+app.yhyue.com/moapp/jy_docs v1.1.6-0.20240604014054-b9f28f2d7d7d h1:3Vn7GPoc8NSlJGCcKe4gw5hlOpFe5niDtB4lX+wuJKs=
+app.yhyue.com/moapp/jy_docs v1.1.6-0.20240604014054-b9f28f2d7d7d/go.mod h1:7sezFJGUgZ/I6RXFLN/7ouUEnHA14Q/mV6T/pt0BvCs=
 app.yhyue.com/moapp/jybase v0.0.0-20210322021809-141cc2c37946/go.mod h1:29ShuI8y7qEyg2KviHSx1iamiCioBKdTMm2ndVzWAhk=
 app.yhyue.com/moapp/jybase v0.0.0-20220415064050-37ce64b3e2d4/go.mod h1:qNRA0sHuYqcLoYoP8irpaWnW9YsXixe6obBIkwaXpD0=
 app.yhyue.com/moapp/jybase v0.0.0-20220418104200-46c3fff161c7/go.mod h1:qNRA0sHuYqcLoYoP8irpaWnW9YsXixe6obBIkwaXpD0=

+ 10 - 4
jydocs-back/public/consts.go

@@ -7,9 +7,15 @@ const (
 	SourceJy              = 1 // 文档来源 剑鱼
 	SourceDd              = 2 // 文档来源 豆丁
 
-	FreeDownloadNoSL           = 0 // 文库没有留资
-	Free_download_NoFreeTimes  = 1 // 已经使用过一次特权下载机会
-	Free_download_HasFreeTimes = 2 // 留过资有一次特权下载机会
-	// 缓存key
+	FreeDownloadNoSL          = 0 // 文库没有留资
+	Free_download_NoFreeTimes = 1 // 已经使用过一次特权下载机会
+	FreeDownloadHasFreeTimes  = 2 // 留过资有一次特权下载机会
 
+	PayTypeNormal           = 0 // 正常下载
+	PayTypeFullPrice        = 1 // 原价下载
+	PayTypeFreeSL           = 2 // 使用留资的一次会员免费机会
+	StatusMemberFreeExhaust = 1 // 会员免费下载机会用尽
+	AppID                   = "10000"
+	PartnerState            = 1 // 豆丁
+	DdUserBuyType1          = 1 // 购买类型:1 币买文档,2 券买文档,3 月大会员,4 季大会员,5 年大会员
 )

+ 35 - 0
jydocs-back/public/userInfo.go

@@ -0,0 +1,35 @@
+package public
+
+import (
+	"app.yhyue.com/moapp/jybase/common"
+	"app.yhyue.com/moapp/jybase/go-xweb/httpsession"
+)
+
+// SessUserInfo 从session获取用户基本信息
+type SessUserInfo struct {
+	BaseUserId   int64
+	AccountId    int64
+	EntId        int64
+	PositionType int64
+	PositionId   int64
+	EntUserId    int64
+	Phone        string
+	MgoUserId    string
+	UserId       string
+}
+
+// GetUserBaseInfo 获取用户基本信息从session
+func GetUserBaseInfo(sess *httpsession.Session) SessUserInfo {
+	getSession := sess.GetMultiple()
+	return SessUserInfo{
+		MgoUserId:    common.ObjToString(getSession["mgoUserId"]),
+		BaseUserId:   common.Int64All(getSession["base_user_id"]),
+		AccountId:    common.Int64All(getSession["accountId"]),
+		EntId:        common.Int64All(getSession["entId"]),
+		PositionType: common.Int64All(getSession["positionType"]),
+		PositionId:   common.Int64All(getSession["positionId"]),
+		Phone:        common.ObjToString(getSession["phone"]),
+		UserId:       common.ObjToString(getSession["userId"]),
+		EntUserId:    common.Int64All(getSession["entUserId"]),
+	}
+}

+ 66 - 0
jydocs-back/rpc/partnerRpc.go

@@ -0,0 +1,66 @@
+package rpc
+
+import (
+	"app.yhyue.com/moapp/jy_docs/rpc/partnerlib/partner"
+	"context"
+	"github.com/zeromicro/go-zero/core/discov"
+	"github.com/zeromicro/go-zero/zrpc"
+	"jy-docs/config"
+	"jy-docs/public"
+	"log"
+)
+
+// 标准库RPC接口
+var jyParterLib partner.Partner
+
+func init() {
+	jyParterLib = partner.NewPartner(zrpc.MustNewClient(zrpc.RpcClientConf{
+		Etcd: discov.EtcdConf{
+			Key:   config.JyDocsAppConfig.RpcServers.Partner.Key,
+			Hosts: config.JyDocsAppConfig.RpcServers.Partner.Address,
+		},
+	}))
+}
+
+// PartDocDownload 下载
+func PartDocDownload(docId, mgoUserId, phone string, positionId int64) (*partner.UDRes, error) {
+	resp, err := jyParterLib.DocDownload(context.Background(), &partner.UserDownloadRequest{
+		MgoUserId:  mgoUserId,
+		Phone:      phone,
+		PositionId: positionId,
+		AppId:      public.AppID,
+		State:      public.PartnerState,
+		DocId:      docId,
+	})
+	if err != nil || resp == nil {
+		log.Printf("%s %d  jyParterLib.DocDownload call error %v\n", mgoUserId, positionId, err)
+		return resp, err
+	}
+	if resp.Code < 0 {
+		log.Printf("%s %d  jyParterLib.DocDownload call code error %v\n", mgoUserId, positionId, resp)
+		return resp, err
+	}
+	return resp, nil
+}
+
+// PartUserBuy 购买
+func PartUserBuy(docId, mgoUserId, phone string, positionId int64) (*partner.UBVRes, error) {
+	resp, err := jyParterLib.UserBuy(context.Background(), &partner.UserBuyVipRequest{
+		MgoUserId:  mgoUserId,
+		Phone:      phone,
+		PositionId: positionId,
+		AppId:      public.AppID,
+		State:      public.PartnerState,
+		DocId:      docId,
+		Type:       public.DdUserBuyType1,
+	})
+	if err != nil || resp == nil {
+		log.Printf("%s %d  jyParterLib.PartUserBuy call error %v\n", mgoUserId, positionId, err)
+		return resp, err
+	}
+	if resp.Code < 0 {
+		log.Printf("%s %d  jyParterLib.PartUserBuy call code error %v\n", mgoUserId, positionId, resp)
+		return resp, err
+	}
+	return resp, nil
+}

+ 32 - 2
jydocs-back/rpc/stdDocRpc.go

@@ -7,6 +7,7 @@ import (
 	"github.com/zeromicro/go-zero/core/discov"
 	"github.com/zeromicro/go-zero/zrpc"
 	"jy-docs/config"
+	"jy-docs/public"
 	"log"
 )
 
@@ -113,7 +114,14 @@ return
 	DocInfo 文库详情
 	error 异常
 */
-func GetDocDetail(userId, docId string) (*stdlib.DocInfo, bool, bool, error) {
+
+type returnDetail struct {
+	*stdlib.DocInfo
+	DocMemberPrice    int64 `json:"docMemberPrice"`
+	DocMemberDiscount int64 `json:"docMemberDiscount"`
+}
+
+func GetDocDetail(userId, docId string) (*returnDetail, bool, bool, error) {
 	resp, err := jyStdDocStdlib.DocGetCheck(context.Background(), &stdlib.DocGetCheckReq{
 		AppId:  config.JyDocsAppConfig.AppId,
 		UserId: userId,
@@ -130,7 +138,29 @@ func GetDocDetail(userId, docId string) (*stdlib.DocInfo, bool, bool, error) {
 	if resp.DocDeail == nil {
 		return nil, false, false, fmt.Errorf("查询文档异常")
 	}
-	return resp.DocDeail, resp.IsBuy, resp.IsCollect, nil
+	detail := resp.DocDeail
+	if detail.Source == public.SourceDd {
+		priceConfig := config.JyDocsAppConfig.Price[detail.Source][detail.ProductType]
+		// 豆丁的预览图和价格需要重新计算
+		detail.Price = priceConfig.Rate*detail.Price + priceConfig.Base
+		detail.PreviewImgId = fmt.Sprintf(config.JyDocsAppConfig.DoudingImg, detail.PreviewImgId)
+	} else {
+		detail.PreviewImgId = fmt.Sprintf("https://%s.%s/%s", config.JyDocsAppConfig.OssBucket.Priv, config.JyDocsAppConfig.OssAdmin, detail.PreviewImgId)
+	}
+	// 计算会员价
+	rs := returnDetail{
+		DocInfo:           detail,
+		DocMemberDiscount: config.JyDocsAppConfig.DocMember.Discount,
+	}
+	// 会员免费
+	if detail.ProductType == public.ProductTypeMemberFree {
+		rs.DocMemberPrice = 0
+	}
+	// 精品 8折
+	if detail.ProductType == public.ProductTypePremium {
+		rs.DocMemberPrice = detail.Price * config.JyDocsAppConfig.DocMember.Discount / 10
+	}
+	return &rs, resp.IsBuy, resp.IsCollect, nil
 }
 
 /*

+ 15 - 0
jydocs-back/rpc/userDocRpc.go

@@ -139,3 +139,18 @@ func PayDoc(userId, docId string) error {
 	}
 	return nil
 }
+func TodayCount(userId string) (int64, error) {
+	resp, err := jyUserDocLib.UserTodayCount(context.Background(), &userlib.UserTodayCountReq{
+		AppId:  config.JyDocsAppConfig.AppId,
+		UserId: userId,
+	})
+	if err != nil {
+		log.Printf("%s UserTodayCount call error %v\n", userId, err)
+		return 0, err
+	}
+	if resp.Code != 1 {
+		log.Printf("%s UserTodayCount fail Message %v\n", userId, resp.Message)
+		return 0, fmt.Errorf("获取用户")
+	}
+	return resp.Count, nil
+}

+ 12 - 42
jydocs-back/servers/stdDoc.go

@@ -1,7 +1,6 @@
 package servers
 
 import (
-	"app.yhyue.com/moapp/jy_docs/rpc/stdlib/type/stdlib"
 	. "app.yhyue.com/moapp/jybase/api"
 	"app.yhyue.com/moapp/jybase/common"
 	"app.yhyue.com/moapp/jybase/go-xweb/xweb"
@@ -63,24 +62,22 @@ func (stdDoc *StdDoc) Search() {
 		if total > config.JyDocsAppConfig.SearchNumLimit {
 			total = config.JyDocsAppConfig.SearchNumLimit
 		}
-		returnList := []interface{}{}
-		for _, v := range list {
-			//
-			if v.Source == public.SourceDd {
-				v.PreviewImgId = fmt.Sprintf(config.JyDocsAppConfig.DoudingImg, v.PreviewImgId)
+		for i := 0; i < len(list); i++ {
+			if list[i].Source == public.SourceDd {
+				list[i].PreviewImgId = fmt.Sprintf(config.JyDocsAppConfig.DoudingImg, list[i].PreviewImgId)
 			} else {
-				v.PreviewImgId = fmt.Sprintf("https://%s.%s/%s", config.JyDocsAppConfig.OssBucket.Priv, config.JyDocsAppConfig.OssAdmin, v.PreviewImgId)
+				list[i].PreviewImgId = fmt.Sprintf("https://%s.%s/%s", config.JyDocsAppConfig.OssBucket.Priv, config.JyDocsAppConfig.OssAdmin, list[i].PreviewImgId)
 			}
-			returnList = append(returnList, v)
-		}
-		// 存缓存
-		if keyWord == "" && len(returnList) > 0 {
-			redis.Put("other", topKey, list, 60*60*2)
 		}
-		return map[string]interface{}{
+		rs := map[string]interface{}{
 			"total": total,
 			"list":  list,
-		}, nil
+		}
+		// 存缓存
+		if keyWord == "" && len(list) > 0 {
+			redis.Put("other", topKey, rs, 60*60*2)
+		}
+		return rs, nil
 	}()
 	if errMsg != nil {
 		log.Printf("%s StdDoc search err:%s\n", userId, errMsg.Error())
@@ -93,12 +90,6 @@ func (stdDoc *StdDoc) IndexTag() {
 	stdDoc.ServeJson(NewResult(tags, err))
 }
 
-type returnDetail struct {
-	*stdlib.DocInfo
-	DocMemberPrice    int64 `json:"docMemberPrice"`
-	DocMemberDiscount int64 `json:"docMemberDiscount"`
-}
-
 func (stdDoc *StdDoc) Detail() {
 	userId := common.ObjToString(stdDoc.GetSession("userId"))
 	rData, errMsg := func() (interface{}, error) {
@@ -117,33 +108,12 @@ func (stdDoc *StdDoc) Detail() {
 		//ossId清除
 		detail.OssPdfId = ""
 		detail.OssDocId = ""
-		if detail.Source == public.SourceDd {
-			priceConfig := config.JyDocsAppConfig.Price[detail.Source][detail.ProductType]
-			// 豆丁的预览图和价格需要重新计算
-			detail.Price = priceConfig.Rate*detail.Price + priceConfig.Base
-			detail.PreviewImgId = fmt.Sprintf(config.JyDocsAppConfig.DoudingImg, detail.PreviewImgId)
-		} else {
-			detail.PreviewImgId = fmt.Sprintf("https://%s.%s/%s", config.JyDocsAppConfig.OssBucket.Priv, config.JyDocsAppConfig.OssAdmin, detail.PreviewImgId)
-		}
-		// 计算会员价
-		rs := returnDetail{
-			DocInfo:           detail,
-			DocMemberDiscount: config.JyDocsAppConfig.DocMember.Discount,
-		}
-		// 会员免费
-		if detail.ProductType == public.ProductTypeMemberFree {
-			rs.DocMemberPrice = 0
-		}
-		// 精品 8折
-		if detail.ProductType == public.ProductTypePremium {
-			rs.DocMemberPrice = detail.Price * config.JyDocsAppConfig.DocMember.Discount / 10
-		}
 
 		go rpc.DocStatistics(userId, docId, rpc.View) //统计下载次数
 		return map[string]interface{}{
 			"status":  common.If(isBuy, 1, 0),
 			"collect": common.If(IsCollect, 1, 0),
-			"detail":  rs,
+			"detail":  detail,
 		}, nil
 	}()
 	if errMsg != nil {

+ 123 - 43
jydocs-back/servers/userDoc.go

@@ -88,21 +88,21 @@ func (userDoc *UserDoc) CollectRemove() {
 }
 
 func (userDoc *UserDoc) DocBuy() {
-	userId := common.ObjToString(userDoc.GetSession("userId"))
+	// todo 加用户锁
+	userInfo := public.GetUserBaseInfo(userDoc.Session())
+	userId := userInfo.UserId
 	rData, errMsg := func() (interface{}, error) {
 		docId := userDoc.GetString("docId")
 		phone := userDoc.GetString("phone")
+		payType, _ := userDoc.GetInt("payType") // 0-正常下载  1-原价下载 2-使用一次免费下载机会(会员免费文档 留资)
 		if docId == "" {
 			return nil, fmt.Errorf("参数异常")
 		}
 		var userPoint, docPoint int64 = 0, 0
 		var err error
-		//查询用户剩余积分
-		userPoint, err = rpc.GetUserPointValue(userId)
-		if err != nil {
-			return nil, err
-		}
-		//查询文档所需积分
+		usePoint := true    // 是否消耗剑鱼币  会员免费文档且当天100篇以内的或者使用免费下载机会的 不用扣积分
+		useSLTimes := false // 使用留资机会的下载次数
+		//查询文档所需积分及文档类型
 		docInfo, isBuy, _, err := rpc.GetDocDetail(userId, docId)
 		if err != nil {
 			return nil, err
@@ -110,29 +110,106 @@ func (userDoc *UserDoc) DocBuy() {
 		if isBuy {
 			return nil, fmt.Errorf("已兑换,请勿重复操作")
 		}
-		docPoint = docInfo.Price
-		//积分够调扣积分
-		if userPoint < docPoint {
-			return nil, fmt.Errorf("剩余积分不足")
-		}
-		bytes, err := json.Marshal(map[string]interface{}{
-			"name":    docInfo.DocName,
-			"summary": docInfo.DocSummary,
-			"img":     docInfo.PreviewImgId,
-			"fType":   docInfo.DocFileType,
-		})
-		if err != nil {
-			return nil, fmt.Errorf("文库异常")
-		}
-		serialNumber, err := rpc.SpendUserPoint(userId, docInfo.DocId, string(bytes), docPoint)
+		// 获取用户身份
+		docMember, err := getDocMemberStatus(userId)
 		if err != nil {
 			return nil, err
 		}
+		docMemberStatus := docMember["docMemberStatus"].(bool)
+		freeDownload := docMember["free_download"].(int)
+		if docMemberStatus {
+			// 会员
+			switch payType {
+			case public.PayTypeNormal:
+				if docInfo.ProductType == public.ProductTypeMemberFree {
+					// 如果是会员免费 判断是否超出进入下载次数
+					// 获取今日下载次数
+					count, err2 := rpc.TodayCount(userId)
+					if err2 != nil {
+						return nil, err2
+					}
+					if int(count) >= config.JyDocsAppConfig.DocMember.Times {
+						return map[string]interface{}{
+							"status": public.StatusMemberFreeExhaust,
+						}, nil
+					}
+					//  没有超过下载次数  下一步应该到转存 不用扣剑鱼币
+					usePoint = false
+				} else {
+					// 精品文档
+					docPoint = docInfo.DocMemberPrice // 会员价
+				}
+			case public.PayTypeFullPrice:
+				docPoint = docInfo.Price
+			default:
+				return nil, errors.New("payType类型不匹配")
+			}
+		} else {
+			switch payType {
+			case public.PayTypeFreeSL:
+				if freeDownload != public.FreeDownloadHasFreeTimes || docInfo.ProductType != public.ProductTypeMemberFree {
+					return nil, fmt.Errorf("没有免费下载机会")
+				}
+				usePoint = false  // 免费下载的不扣剑鱼币
+				useSLTimes = true // 后边要处理该字段
+			case public.PayTypeFullPrice:
+				docPoint = docInfo.Price // 原价下的
+			default:
+				return nil, errors.New("payType类型不匹配")
+			}
+		}
+		var serialNumber string
+		if usePoint { // 扣积分
+			//查询用户剩余积分
+			userPoint, err = rpc.GetUserPointValue(userId)
+			if err != nil {
+				return nil, err
+			}
+			//积分够调扣积分
+			if userPoint < docPoint {
+				return nil, fmt.Errorf("剩余积分不足")
+			}
+			bytes, err := json.Marshal(map[string]interface{}{
+				"name":    docInfo.DocName,
+				"summary": docInfo.DocSummary,
+				"img":     docInfo.PreviewImgId,
+				"fType":   docInfo.DocFileType,
+			})
+			if err != nil {
+				return nil, fmt.Errorf("文库异常")
+			}
+			serialNumber, err = rpc.SpendUserPoint(userId, docInfo.DocId, string(bytes), docPoint)
+			if err != nil {
+				return nil, err
+			}
+		}
+		// 没有ossdocId 说明是还没有下过的 需要先获得地址
+		if docInfo.OssDocId == "" {
+			// 如果是精品 则需要先调购买接口
+			if docInfo.ProductType == public.ProductTypePremium {
+				_, err2 := rpc.PartUserBuy(docId, userInfo.MgoUserId, userInfo.Phone, userInfo.PositionId)
+				if err2 != nil {
+					return nil, fmt.Errorf("获取失败")
+				}
+			}
+			// 如果是免费则直接调
+			_, err := rpc.PartDocDownload(docId, userInfo.MgoUserId, userInfo.Phone, userInfo.PositionId)
+			if err != nil {
+				return nil, fmt.Errorf("获取失败")
+			}
+		}
 		//转存文库
 		err = rpc.PayDoc(userId, docId)
 		if err != nil {
 			return nil, err
 		}
+		if useSLTimes {
+			public.Compatible.Update(userId, map[string]interface{}{
+				"$set": M{
+					"i_doc_free_download": 1,
+				},
+			})
+		}
 		//手机号采集
 		go func() {
 			if phone != "" {
@@ -171,30 +248,33 @@ func (userDoc *UserDoc) Info() {
 				"free_download":   public.FreeDownloadNoSL,
 			}, nil
 		}
-		mData := public.Compatible.Select(userId, `{"i_doc_status":1,"l_doc_endtime":1,"l_doc_starttime":1,"i_doc_free_download":1}`)
-		if mData != nil && len(*mData) > 0 {
-			free_download := common.IntAll((*mData)["i_doc_free_download"])
-			if (*mData)["i_doc_free_download"] == 0 { // 没有使用过一次免费下载机会
-				// 查留资
-				count := public.MQFW.Count("saleLeads", map[string]interface{}{"userid": userId, "source": map[string]interface{}{"$in": config.JyDocsAppConfig.DocMember.Source}})
-				if count > 0 {
-					free_download = public.Free_download_HasFreeTimes
-				} else {
-					free_download = public.FreeDownloadNoSL
-				}
-			}
-			vipStatus := common.IntAll((*mData)["i_doc_status"])
-			return map[string]interface{}{
-				"docMemberStatus": vipStatus > 0,
-				"startTime":       (*mData)["l_doc_starttime"],
-				"endTime":         (*mData)["l_doc_endtime"],
-				"free_download":   free_download,
-			}, nil
-		}
-		return nil, errors.New("获取文库会员状态失败")
+		return getDocMemberStatus(userId)
 	}()
 	if errMsg != nil {
 		log.Printf("%s UserDoc Info err:%s\n", userId, errMsg.Error())
 	}
 	userDoc.ServeJson(NewResult(rData, errMsg))
 }
+func getDocMemberStatus(userId string) (map[string]interface{}, error) {
+	mData := public.Compatible.Select(userId, `{"i_doc_status":1,"l_doc_endtime":1,"l_doc_starttime":1,"i_doc_free_download":1}`)
+	if mData != nil && len(*mData) > 0 {
+		vipStatus := common.IntAll((*mData)["i_doc_status"])
+		free_download := common.IntAll((*mData)["i_doc_free_download"])
+		if free_download == 0 && vipStatus <= 0 { // 不是文库会员时再查 没有使用过一次免费下载机会
+			// 查留资
+			count := public.MQFW.Count("saleLeads", map[string]interface{}{"userid": userId, "source": map[string]interface{}{"$in": config.JyDocsAppConfig.DocMember.Source}})
+			if count > 0 {
+				free_download = public.FreeDownloadHasFreeTimes
+			} else {
+				free_download = public.FreeDownloadNoSL
+			}
+		}
+		return map[string]interface{}{
+			"docMemberStatus": vipStatus > 0,
+			"startTime":       (*mData)["l_doc_starttime"],
+			"endTime":         (*mData)["l_doc_endtime"],
+			"free_download":   free_download,
+		}, nil
+	}
+	return nil, errors.New("获取文库会员状态失败")
+}

+ 1 - 1
jydocs-back/test/p525.http

@@ -1,4 +1,4 @@
-POST http://127.0.0.1:821/jydocs/user/info
+POST https://jybx3-webtest.jydev.jianyu360.com/jydocs/user/info
 Content-Type: application/x-www-form-urlencoded
 Cookie: SESSIONID=d6d16e5272466216cb3fb63c80f82cb2938a4e6c;