Procházet zdrojové kódy

feat:p525 jydocs-back 文库详情页接口调整

fuwencai před 1 rokem
rodič
revize
d663e6e438

+ 18 - 1
jydocs-back/config.json

@@ -42,5 +42,22 @@
   ],
   "searchNumLimit": 200,
   "shareUrl": "https://web-wky.jydev.jianyu360.com/swordfish/SingleLogin",
-  "doudingImg": "https://img3.douding.cn/%s_90x80.jpg"
+  "doudingImg": "https://img3.douding.cn/%s_90x80.jpg",
+  "price": {
+    "2": {
+      "1": {
+        "rate": 0,
+        "base": 50
+      },
+      "2": {
+        "rate": 100,
+        "base": 100
+      }
+    }
+  },
+  "docMember": {
+    "times": 100,
+    "discount": 8,
+    "source":["pc_Library details_free","app_Library details_free","wx_Library details_free","h5_Library details_free"]
+  }
 }

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

@@ -28,8 +28,33 @@ type appConfig struct {
 	SearchNumLimit int64    `json:"searchNumLimit"` //检索条数限制
 	ShareUrl       string   `json:"shareUrl"`       //分享地址
 	DoudingImg     string   `json:"doudingImg"`     // 豆丁封面图片地址
+	Price          map[int64]map[int64]struct {
+		Rate int64 `json:"rate"` // 价格转换比率
+		Base int64 `json:"base"` // 价格基数
+	} `json:"price"`
+	DocMember struct {
+		Times    int      `json:"times"`    // 会员免费下载次数
+		Discount int64    `json:"discount"` // 会员折扣
+		Source   []string `json:"source"`   // 留资source
+	} `json:"docMember"`
 }
 
+/*
+例如
+
+	"price": {
+	  "2": {  // 对应文档来源 文档来源:;2:豆丁;
+	    "1": { // 对应商品类型 1:会员免费;2:精品(付费)
+	      "rate": 0, // 比率
+	      "base": 50 // 基数   例如会员免费文档  50+0*price = 50
+	    },
+	    "2": {
+	      "rate": 100, // 例如 精品  100+100*price
+	      "base": 100
+	    }
+	  }
+	}
+*/
 type rpcConfig struct {
 	Key     string   `json:"key"`
 	Address []string `json:"address"` //集群地址

+ 1 - 1
jydocs-back/filter/sessionfilter.go

@@ -19,7 +19,7 @@ func (l *sessionfilter) Do(w http.ResponseWriter, req *http.Request) bool {
 		strings.HasPrefix(rul, "/jydocs/detail") || strings.HasPrefix(rul, "/jydocs/detail/recommend") ||
 		strings.HasPrefix(rul, "/jydocs/topList") || strings.HasPrefix(rul, "/jydocs/activityList") ||
 		strings.HasPrefix(rul, "/jydocs/getAdvertisement") || strings.HasPrefix(rul, "/jydocs/indexTag") ||
-		strings.HasPrefix(rul, "/jydocs/share/img") {
+		strings.HasPrefix(rul, "/jydocs/share/img") || strings.HasPrefix(rul, "/jydocs/user/info") {
 		return true
 	}
 	if session.Get("userId") == nil {

+ 1 - 1
jydocs-back/go.mod

@@ -4,7 +4,7 @@ go 1.21
 
 require (
 	app.yhyue.com/moapp/jyPoints v1.1.2-0.20231020023521-1a4b1bbf9736
-	app.yhyue.com/moapp/jy_docs v1.1.2-0.20240529083647-124db78ce6f4
+	app.yhyue.com/moapp/jy_docs v1.1.2-0.20240529121147-a2577391267f
 	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

+ 2 - 0
jydocs-back/go.sum

@@ -10,6 +10,8 @@ app.yhyue.com/moapp/jy_docs v1.1.2-0.20240527084525-87fb4a434b94 h1:IQ4HT0TWdx18
 app.yhyue.com/moapp/jy_docs v1.1.2-0.20240527084525-87fb4a434b94/go.mod h1:54sK98Z5tpMFd2aPLN1IRfEyV3zpFRyFxKj6oi2C5/Q=
 app.yhyue.com/moapp/jy_docs v1.1.2-0.20240529083647-124db78ce6f4 h1:wC+IgdEWOdGE/wVl8MDtyuscZpGSd65aBYCOaZahx0g=
 app.yhyue.com/moapp/jy_docs v1.1.2-0.20240529083647-124db78ce6f4/go.mod h1:54sK98Z5tpMFd2aPLN1IRfEyV3zpFRyFxKj6oi2C5/Q=
+app.yhyue.com/moapp/jy_docs v1.1.2-0.20240529121147-a2577391267f h1:gn4CqfuivcZ6cbJiRFq31AEYYkE4Gjs6Ip7tOvn62V8=
+app.yhyue.com/moapp/jy_docs v1.1.2-0.20240529121147-a2577391267f/go.mod h1:54sK98Z5tpMFd2aPLN1IRfEyV3zpFRyFxKj6oi2C5/Q=
 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=

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

@@ -7,6 +7,9 @@ const (
 	SourceJy              = 1 // 文档来源 剑鱼
 	SourceDd              = 2 // 文档来源 豆丁
 
+	FreeDownloadNoSL           = 0 // 文库没有留资
+	Free_download_NoFreeTimes  = 1 // 已经使用过一次特权下载机会
+	Free_download_HasFreeTimes = 2 // 留过资有一次特权下载机会
 	// 缓存key
-	
+
 )

+ 30 - 2
jydocs-back/servers/stdDoc.go

@@ -1,6 +1,7 @@
 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"
@@ -92,6 +93,12 @@ 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) {
@@ -110,12 +117,33 @@ func (stdDoc *StdDoc) Detail() {
 		//ossId清除
 		detail.OssPdfId = ""
 		detail.OssDocId = ""
-		detail.PreviewImgId = fmt.Sprintf("https://%s.%s/%s", config.JyDocsAppConfig.OssBucket.Priv, config.JyDocsAppConfig.OssAdmin, detail.PreviewImgId)
+		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.DocId)
+		} 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":  detail,
+			"detail":  rs,
 		}, nil
 	}()
 	if errMsg != nil {

+ 22 - 2
jydocs-back/servers/userDoc.go

@@ -7,6 +7,7 @@ import (
 	"encoding/json"
 	"errors"
 	"fmt"
+	"jy-docs/config"
 	"jy-docs/public"
 	"jy-docs/rpc"
 	"log"
@@ -19,7 +20,7 @@ type UserDoc struct {
 	collectAdd    xweb.Mapper `xweb:"/user/collect/add"`    //收藏文库
 	collectRemove xweb.Mapper `xweb:"/user/collect/remove"` //取消收藏
 	docBuy        xweb.Mapper `xweb:"/user/buy"`            //文库购买
-	info          xweb.Mapper `xweb:"/user/info"`           //文库购买
+	info          xweb.Mapper `xweb:"/user/info"`           //文库会员信息
 }
 
 // 用户文库列表
@@ -162,13 +163,32 @@ func (userDoc *UserDoc) DocBuy() {
 func (userDoc *UserDoc) Info() {
 	userId := common.ObjToString(userDoc.GetSession("userId"))
 	rData, errMsg := func() (interface{}, error) {
-		mData := public.Compatible.Select(userId, `{"i_doc_status":1,"l_doc_endtime":1,"l_doc_starttime":1}`)
+		if userId == "" {
+			return map[string]interface{}{
+				"docMemberStatus": false,
+				"startTime":       0,
+				"endTime":         0,
+				"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("获取文库会员状态失败")

+ 6 - 0
jydocs-back/test/p525.http

@@ -35,3 +35,9 @@ POST http://127.0.0.1:821/jydocs/indexTag
 Content-Type: application/x-www-form-urlencoded
 Cookie: SESSIONID=d6d16e5272466216cb3fb63c80f82cb2938a4e6c;
 
+###
+POST http://127.0.0.1:821/jydocs/detail
+Content-Type: application/x-www-form-urlencoded
+Cookie: SESSIONID=d6d16e5272466216cb3fb63c80f82cb2938a4e6c;
+
+docId=9d97d240-8dd3-11eb-8419-0050568f1307