|
@@ -23,6 +23,7 @@ type StdDoc struct {
|
|
getDoc xweb.Mapper `xweb:"/get(Show|Down)"` //文库在线查看 or 下载
|
|
getDoc xweb.Mapper `xweb:"/get(Show|Down)"` //文库在线查看 or 下载
|
|
topList xweb.Mapper `xweb:"/topList"` //最新文档&热门下载
|
|
topList xweb.Mapper `xweb:"/topList"` //最新文档&热门下载
|
|
activityList xweb.Mapper `xweb:"/activityList"` //活动文库(精品推荐、兑换榜)
|
|
activityList xweb.Mapper `xweb:"/activityList"` //活动文库(精品推荐、兑换榜)
|
|
|
|
+ docRecommend xweb.Mapper `xweb:"/docRecommend"` // 文库首页 :热门文档推荐、 会员免费 、精选推荐
|
|
}
|
|
}
|
|
|
|
|
|
func (stdDoc *StdDoc) Search() {
|
|
func (stdDoc *StdDoc) Search() {
|
|
@@ -111,7 +112,7 @@ func (stdDoc *StdDoc) Detail() {
|
|
detail.OssDocId = ""
|
|
detail.OssDocId = ""
|
|
downloadStatus := 0 // 1- 免费用户下载豆丁免费次数用完
|
|
downloadStatus := 0 // 1- 免费用户下载豆丁免费次数用完
|
|
// 如果是会员免费文档 并且不是文库会员 并且没有买过 时免费判断判断有没有超过10篇
|
|
// 如果是会员免费文档 并且不是文库会员 并且没有买过 时免费判断判断有没有超过10篇
|
|
- if !isBuy && userId != "" && detail.ProductType == public.ProductTypeMemberFree &&detail.Source==public.SourceDd {
|
|
|
|
|
|
+ if !isBuy && userId != "" && detail.ProductType == public.ProductTypeMemberFree && detail.Source == public.SourceDd {
|
|
mData := jy.GetBigVipUserBaseMsg(stdDoc.Session(), *config.Middleground)
|
|
mData := jy.GetBigVipUserBaseMsg(stdDoc.Session(), *config.Middleground)
|
|
if mData != nil && mData.Data != nil {
|
|
if mData != nil && mData.Data != nil {
|
|
if mData.Data.Docs.Status <= 0 {
|
|
if mData.Data.Docs.Status <= 0 {
|
|
@@ -294,3 +295,103 @@ func (stdDoc *StdDoc) ActivityList() {
|
|
}
|
|
}
|
|
stdDoc.ServeJson(NewResult(rData, errMsg))
|
|
stdDoc.ServeJson(NewResult(rData, errMsg))
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// 文库推荐
|
|
|
|
+func (stdDoc *StdDoc) DocRecommend() {
|
|
|
|
+ userId := common.ObjToString(stdDoc.GetSession("userId"))
|
|
|
|
+ rData, errMsg := func() (interface{}, error) {
|
|
|
|
+
|
|
|
|
+ tag := stdDoc.GetString("tag") //标签
|
|
|
|
+ //sort := stdDoc.GetString("sort") //排序 tSort dSort vSort
|
|
|
|
+ pageSizeReq, _ := stdDoc.GetInteger("size") //每页数量
|
|
|
|
+ productType, _ := stdDoc.GetInteger("productType") // 商品类型 1-会员免费 2-精品文档
|
|
|
|
+ if pageSizeReq > 50 {
|
|
|
|
+ return nil, fmt.Errorf("数量有误")
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ if (tag == "" && productType == 0) || (tag != "" && productType != 0) {
|
|
|
|
+ return nil, fmt.Errorf("不能为空")
|
|
|
|
+ }
|
|
|
|
+ var regionState int
|
|
|
|
+ if tag != "" {
|
|
|
|
+ regionState = public.RegionStateHot
|
|
|
|
+ } else if productType == public.ProductTypeMemberFree {
|
|
|
|
+ regionState = public.RegionStateMemberFree
|
|
|
|
+ } else if productType == public.ProductTypePremium {
|
|
|
|
+ regionState = public.RegionStatePremium
|
|
|
|
+ } else {
|
|
|
|
+ return nil, fmt.Errorf("参数无效")
|
|
|
|
+ }
|
|
|
|
+ topKey := fmt.Sprintf("jydoc_RecCache_%d_%s", regionState, tag)
|
|
|
|
+ listCache := redis.Get("other", topKey)
|
|
|
|
+ if listCache != nil {
|
|
|
|
+ list, ok := listCache.([]interface{})
|
|
|
|
+ if ok && list != nil && len(list) > 0 {
|
|
|
|
+ if len(list) > pageSizeReq {
|
|
|
|
+ list = list[:pageSizeReq]
|
|
|
|
+ }
|
|
|
|
+ return map[string]interface{}{
|
|
|
|
+ "total": len(list),
|
|
|
|
+ "list": list,
|
|
|
|
+ }, nil
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 查库
|
|
|
|
+ list := []map[string]interface{}{}
|
|
|
|
+ rs := public.GetRecDoc(regionState, tag)
|
|
|
|
+ // 格式化数据
|
|
|
|
+ for i := 0; i < len(rs); i++ {
|
|
|
|
+ tags := strings.Split(common.ObjToString((rs)[i]["docTags"]), ",")
|
|
|
|
+ tmptags := []string{}
|
|
|
|
+ subTag := ""
|
|
|
|
+ for j := 0; j < len(tags); j++ {
|
|
|
|
+ if _, ok := public.DocClassInfo[tags[j]]; ok && len(tmptags) == 0 {
|
|
|
|
+ tmptags = append(tmptags, tags[j])
|
|
|
|
+ } else {
|
|
|
|
+ subTag = tags[j]
|
|
|
|
+ }
|
|
|
|
+ if subTag != "" && len(tmptags) > 0 {
|
|
|
|
+ tmptags = append(tmptags, subTag)
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ previewImgId := ""
|
|
|
|
+ if common.IntAll((rs)[i]["source"]) == public.SourceDd {
|
|
|
|
+ previewImgId = fmt.Sprintf(config.JyDocsAppConfig.DoudingImg, rs[i]["previewImgId"])
|
|
|
|
+ } else {
|
|
|
|
+ previewImgId = fmt.Sprintf("https://%s.%s/%s", config.JyDocsAppConfig.OssBucket.Priv, config.JyDocsAppConfig.OssAdmin, rs[i]["previewImgId"])
|
|
|
|
+ }
|
|
|
|
+ doc := map[string]interface{}{
|
|
|
|
+ "docId": common.ObjToString((rs)[i]["id"]),
|
|
|
|
+ "docName": common.ObjToString((rs)[i]["docName"]),
|
|
|
|
+ "docPageSize": common.Int64All((rs)[i]["docPageSize"]),
|
|
|
|
+ "docFileSize": common.Int64All((rs)[i]["docFileSize"]),
|
|
|
|
+ "downTimes": common.Int64All((rs)[i]["downTimes"]),
|
|
|
|
+ "viewTimes": common.Int64All((rs)[i]["(rs)[i]iewTimes"]),
|
|
|
|
+ "uploadDate": common.ObjToString((rs)[i]["uploadDate"]),
|
|
|
|
+ "docSummary": common.ObjToString((rs)[i]["docSummary"]),
|
|
|
|
+ "docFileType": public.DocFileType[common.IntAll((rs)[i]["docFileType"])],
|
|
|
|
+ "previewImgId": previewImgId,
|
|
|
|
+ "productType": common.Int64All((rs)[i]["productType"]),
|
|
|
|
+ "source": common.Int64All((rs)[i]["source"]),
|
|
|
|
+ "docTags": strings.Join(tmptags, " "),
|
|
|
|
+ }
|
|
|
|
+ list = append(list, doc)
|
|
|
|
+ }
|
|
|
|
+ // 存缓存
|
|
|
|
+ if len(list) > 0 {
|
|
|
|
+ redis.Put("other", topKey, list, 60*60*2)
|
|
|
|
+ }
|
|
|
|
+ if len(list) > pageSizeReq {
|
|
|
|
+ list = list[:pageSizeReq]
|
|
|
|
+ }
|
|
|
|
+ return map[string]interface{}{
|
|
|
|
+ "total": len(list),
|
|
|
|
+ "list": list,
|
|
|
|
+ }, nil
|
|
|
|
+ }()
|
|
|
|
+ if errMsg != nil {
|
|
|
|
+ log.Printf("%s StdDoc search err:%s\n", userId, errMsg.Error())
|
|
|
|
+ }
|
|
|
|
+ stdDoc.ServeJson(NewResult(rData, errMsg))
|
|
|
|
+}
|