|
@@ -0,0 +1,135 @@
|
|
|
|
+package servers
|
|
|
|
+
|
|
|
|
+import (
|
|
|
|
+ . "app.yhyue.com/moapp/jybase/api"
|
|
|
|
+ "app.yhyue.com/moapp/jybase/common"
|
|
|
|
+ "app.yhyue.com/moapp/jybase/go-xweb/xweb"
|
|
|
|
+ "fmt"
|
|
|
|
+ "jy-docs/public"
|
|
|
|
+ "jy-docs/rpc"
|
|
|
|
+ "log"
|
|
|
|
+ "strings"
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+type StdDoc struct {
|
|
|
|
+ *xweb.Action
|
|
|
|
+ search xweb.Mapper `xweb:"/search"` //检索文库
|
|
|
|
+ detail xweb.Mapper `xweb:"/detail"` //文库详情
|
|
|
|
+ content xweb.Mapper `xweb:"/content"` //文库内容
|
|
|
|
+ topList xweb.Mapper `xweb:"/topList"` //最新文档&热门下载
|
|
|
|
+ activityList xweb.Mapper `xweb:"/activityList"` //活动文库(精品推荐、兑换榜)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (stdDoc *StdDoc) Search() {
|
|
|
|
+ userId := common.ObjToString(stdDoc.GetSession("userId"))
|
|
|
|
+ rData, errMsg := func() (interface{}, error) {
|
|
|
|
+ keyWord := strings.TrimSpace(stdDoc.GetString("keyWord")) //关键词
|
|
|
|
+ tag := stdDoc.GetString("tag") //标签
|
|
|
|
+ sort := stdDoc.GetString("sort") //排序 tSort dSort vSort
|
|
|
|
+ pageNumReq, _ := stdDoc.GetInt("num") //页码 从1开始
|
|
|
|
+ pageSizeReq, _ := stdDoc.GetInt("size") //每页数量
|
|
|
|
+ pageNum, pageSize, err := public.PageNumParse(pageNumReq, pageSizeReq, 20*10)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return nil, err
|
|
|
|
+ }
|
|
|
|
+ if keyWord == "" {
|
|
|
|
+ return nil, fmt.Errorf("检索内容不能为空")
|
|
|
|
+ }
|
|
|
|
+ list, total, err := rpc.GetDocQuery(userId, keyWord, tag, pageNum, pageSize, sort)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return nil, err
|
|
|
|
+ }
|
|
|
|
+ return map[string]interface{}{
|
|
|
|
+ "total": total,
|
|
|
|
+ "list": list,
|
|
|
|
+ }, nil
|
|
|
|
+ }()
|
|
|
|
+ if errMsg != nil {
|
|
|
|
+ log.Printf("%s StdDoc search err:%s\n", userId, errMsg.Error())
|
|
|
|
+ }
|
|
|
|
+ stdDoc.ServeJson(NewResult(rData, errMsg))
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (stdDoc *StdDoc) Detail() {
|
|
|
|
+ userId := common.ObjToString(stdDoc.GetSession("userId"))
|
|
|
|
+ rData, errMsg := func() (interface{}, error) {
|
|
|
|
+ docId := stdDoc.GetString("docId")
|
|
|
|
+ if docId == "" {
|
|
|
|
+ return nil, fmt.Errorf("参数异常")
|
|
|
|
+ }
|
|
|
|
+ detail, isBuy, err := rpc.GetDocDetail(userId, docId)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return nil, err
|
|
|
|
+ }
|
|
|
|
+ return map[string]interface{}{
|
|
|
|
+ "status": common.If(isBuy, 1, 0),
|
|
|
|
+ "detail": detail,
|
|
|
|
+ }, nil
|
|
|
|
+ }()
|
|
|
|
+ if errMsg != nil {
|
|
|
|
+ log.Printf("%s StdDoc detail err:%s\n", userId, errMsg.Error())
|
|
|
|
+ }
|
|
|
|
+ stdDoc.ServeJson(NewResult(rData, errMsg))
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (stdDoc *StdDoc) Content() {
|
|
|
|
+ userId := common.ObjToString(stdDoc.GetSession("userId"))
|
|
|
|
+ rData, errMsg := func() (interface{}, error) {
|
|
|
|
+
|
|
|
|
+ return nil, nil
|
|
|
|
+ }()
|
|
|
|
+ if errMsg != nil {
|
|
|
|
+ log.Printf("%s StdDoc content err:%s\n", userId, errMsg.Error())
|
|
|
|
+ }
|
|
|
|
+ stdDoc.ServeJson(NewResult(rData, errMsg))
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (stdDoc *StdDoc) TopList() {
|
|
|
|
+ userId := common.ObjToString(stdDoc.GetSession("userId"))
|
|
|
|
+ rData, errMsg := func() (interface{}, error) {
|
|
|
|
+ num, _ := stdDoc.GetInt("num") //返回数量
|
|
|
|
+ sign := stdDoc.GetString("sign") //类别
|
|
|
|
+ reqSort := ""
|
|
|
|
+ if num > 50 {
|
|
|
|
+ num = 50
|
|
|
|
+ }
|
|
|
|
+ if sign == "hot" {
|
|
|
|
+ reqSort = "dSort"
|
|
|
|
+ } else if sign == "new" {
|
|
|
|
+ reqSort = "tSort"
|
|
|
|
+ } else {
|
|
|
|
+ return nil, fmt.Errorf("未知请求")
|
|
|
|
+ }
|
|
|
|
+ list, _, err := rpc.GetDocQuery(userId, "", "", 1, num, reqSort)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return nil, err
|
|
|
|
+ }
|
|
|
|
+ return list, nil
|
|
|
|
+ }()
|
|
|
|
+ if errMsg != nil {
|
|
|
|
+ log.Printf("%s StdDoc topList err:%s\n", userId, errMsg.Error())
|
|
|
|
+ }
|
|
|
|
+ stdDoc.ServeJson(NewResult(rData, errMsg))
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (stdDoc *StdDoc) ActivityList() {
|
|
|
|
+ userId := common.ObjToString(stdDoc.GetSession("userId"))
|
|
|
|
+ rData, errMsg := func() (interface{}, error) {
|
|
|
|
+ code, _ := stdDoc.GetInt("code")
|
|
|
|
+ pageNumReq, _ := stdDoc.GetInt("num") //页码 从1开始
|
|
|
|
+ pageSizeReq, _ := stdDoc.GetInt("size") //每页数量
|
|
|
|
+ pageNum, pageSize, err := public.PageNumParse(pageNumReq, pageSizeReq, 20*10)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return nil, err
|
|
|
|
+ }
|
|
|
|
+ list, err := rpc.GeActivityList(userId, code, pageNum, pageSize)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return nil, err
|
|
|
|
+ }
|
|
|
|
+ return list, nil
|
|
|
|
+ }()
|
|
|
|
+ if errMsg != nil {
|
|
|
|
+ log.Printf("%s StdDoc activityList err:%s\n", userId, errMsg.Error())
|
|
|
|
+ }
|
|
|
|
+ stdDoc.ServeJson(NewResult(rData, errMsg))
|
|
|
|
+}
|