|
- package svc
-
- import (
- "applet/app/db"
- "applet/app/e"
- "applet/app/md"
- "applet/app/utils"
- "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
- "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
- "fmt"
- "github.com/gin-gonic/gin"
- "time"
- )
-
- func CollegeCate(c *gin.Context) {
- NewArticleCateDb := implement.NewArticleCateDb(db.Db)
- cate, _ := NewArticleCateDb.FindArticleCate("1", "1000", "4")
- data := make([]md.CollegeCate, 0)
- if cate != nil {
- for _, v := range *cate {
- tmp := md.CollegeCate{
- Id: utils.IntToStr(v.Id),
- Name: v.Name,
- Img: "",
- }
- data = append(data, tmp)
- }
- }
- e.OutSuc(c, data, nil)
- return
- }
- func CollegeList(c *gin.Context) {
- eg := db.Db
- var req md.CollegeListReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- NewArticleDb := implement.NewArticleDb(eg)
- article, _ := NewArticleDb.FindArticle(req.Page, req.Limit, "", req.CateId)
- data := make([]md.CollegeListResp, 0)
- if article != nil {
- for _, v := range *article {
- tmp := md.CollegeListResp{
- Id: utils.IntToStr(v.Id),
- Url: "",
- Title: v.Title,
- Cover: GetOssUrl(v.Cover),
- CreateAt: time.Unix(int64(v.CreatedAt), 0).Format("2006-01-02"),
- WatchCount: NumFormat(v.WatchCount),
- LikeCount: NumFormat(v.LikeCount),
- ForwardCount: NumFormat(v.ForwardCount),
- }
- data = append(data, tmp)
- }
- }
- e.OutSuc(c, data, nil)
- return
- }
- func CollegeDetail(c *gin.Context, uid int) {
- eg := db.Db
- var req md.CollegeDetailReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- NewArticleDb := implement.NewArticleDb(eg)
- article, _ := NewArticleDb.GetArticle(req.Id)
- data := md.CollegeDetailResp{}
- if article != nil {
- data = md.CollegeDetailResp{
- Id: utils.IntToStr(article.Id),
- Url: fmt.Sprintf("%s%s?id=%s&is_hide=1", GetSysCfgStr("wap_host"), "/#/pages/course-detail-page/course-detail-page", utils.AnyToString(article.Id)),
- Title: article.Title,
- Content: article.Content,
- AppName: GetSysCfgStr("app_name"),
- IsLike: "0",
- CreateAt: time.Unix(int64(article.CreatedAt), 0).Format("2006-01-02"),
- WatchCount: NumFormat(article.WatchCount),
- LikeCount: NumFormat(article.LikeCount),
- ForwardCount: NumFormat(article.ForwardCount),
- }
- count, _ := eg.Where("uid=? and article_id=?", uid, article.Id).Count(&model.ArticleUserLike{})
- if count > 0 {
- data.IsLike = "1"
- }
- }
- e.OutSuc(c, data, nil)
- return
- }
- func CollegeLikeAdd(c *gin.Context) {
- eg := db.Db
- var req md.CollegeDetailReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- user := GetUser(c)
- NewArticleDb := implement.NewArticleDb(eg)
- article, _ := NewArticleDb.GetArticle(req.Id)
- if article == nil {
- e.OutErr(c, 400, e.NewErr(400, "记录不存在"))
- return
- }
- count, _ := eg.Where("uid=? and article_id=?", user.Id, article.Id).Count(&model.ArticleUserLike{})
- if count > 0 {
- e.OutErr(c, 400, e.NewErr(400, "已点赞"))
- return
- }
- article.LikeCount++
- eg.Where("id=?", article.Id).Cols("like_count").Update(article)
- e.OutSuc(c, "success", nil)
- return
- }
- func CollegeLikeCancel(c *gin.Context) {
- eg := db.Db
- var req md.CollegeDetailReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- user := GetUser(c)
- NewArticleDb := implement.NewArticleDb(eg)
- article, _ := NewArticleDb.GetArticle(req.Id)
- if article == nil {
- e.OutErr(c, 400, e.NewErr(400, "记录不存在"))
- return
- }
- eg.Where("uid=? and article_id=?", user.Id, article.Id).Delete(&model.ArticleUserLike{})
- article.LikeCount--
- if article.LikeCount < 0 {
- article.LikeCount = 0
- }
- eg.Where("id=?", article.Id).Cols("like_count").Update(article)
- e.OutSuc(c, "success", nil)
- return
- }
-
- func CollegeShareAdd(c *gin.Context) {
- eg := db.Db
- var req md.CollegeDetailReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- NewArticleDb := implement.NewArticleDb(eg)
- article, _ := NewArticleDb.GetArticle(req.Id)
- if article == nil {
- e.OutErr(c, 400, e.NewErr(400, "记录不存在"))
- return
- }
- article.ForwardCount++
- eg.Where("id=?", article.Id).Cols("forward_count").Update(article)
- e.OutSuc(c, "success", nil)
- return
- }
|