Bladeren bron

no message

xingzai 8 maanden geleden
bovenliggende
commit
eb194c8006

+ 180 - 0
controllers/yanxuan_special.go

@@ -2,6 +2,7 @@ package controllers
 
 import (
 	"encoding/json"
+	"fmt"
 	"github.com/rdlucklib/rdluck_tools/paging"
 	"hongze/hongze_web_mfyx/models"
 	"hongze/hongze_web_mfyx/services"
@@ -1312,6 +1313,185 @@ func (this *YanxuanSpecialController) Check() {
 	br.Msg = "校验成功"
 }
 
+// @Title 专栏文章点赞/取消点赞
+// @Description  专栏文章点赞/取消点赞接口
+// @Param	request	body models.TopCygxYanxuanSpecialMessageReq true "type json string"
+// @Success Ret=200 {object}
+// @router /like [post]
+func (this *YanxuanSpecialController) Like() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	user := this.User
+	if user == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,用户信息为空"
+		br.Ret = 408
+		return
+	}
+	var req models.LikeCygxYanxuanSpecialSpecialLikeReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+
+	yanxuanSpecialId := req.YanxuanSpecialId
+	doType := req.DoType
+	userId := user.UserId
+	// 研选专栏
+	yanxuanSpecialBySpeciaDetail, err := models.GetYanxuanSpecialBySpecialId(yanxuanSpecialId)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取信息失败,Err:" + err.Error()
+		return
+	}
+	total, err := models.GetCygxYanxuanSpecialSpecialLikeCountByUidYid(userId, yanxuanSpecialId)
+	if err != nil {
+		br.Msg = "操作失败!"
+		br.ErrMsg = "操作失败,Err:" + err.Error()
+		return
+	}
+	fmt.Println("total", total)
+	if doType == 1 {
+		if total == 0 {
+			item := new(models.CygxYanxuanSpecialSpecialLike)
+			item.UserId = userId
+			item.Mobile = user.Mobile
+			item.Email = user.Email
+			item.CompanyId = user.CompanyId
+			item.CompanyName = user.CompanyName
+			item.RealName = user.RealName
+			item.YanxuanSpecialId = yanxuanSpecialId
+			item.CreateTime = time.Now()
+			item.ModifyTime = time.Now()
+			item.RegisterPlatform = utils.REGISTER_PLATFORM
+			err = models.AddCygxCygxYanxuanSpecialSpecialLike(item, yanxuanSpecialBySpeciaDetail.UserId)
+			if err != nil {
+				br.Msg = "点赞失败!"
+				br.ErrMsg = "点赞失败,Err:" + err.Error()
+				return
+			}
+		}
+	} else {
+		if total > 0 {
+			err = models.DeleteCygxYanxuanSpecialSpecialLike(userId, yanxuanSpecialId, yanxuanSpecialBySpeciaDetail.UserId)
+			if err != nil {
+				br.Msg = "点赞失败!"
+				br.ErrMsg = "点赞失败,Err:" + err.Error()
+				return
+			}
+		}
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+}
+
+// @Title 作者粉丝列表
+// @Description 作者粉丝列表接口
+// @Param   PageSize   query   int  true       "每页数据条数"
+// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
+// @Success 200 {object} models.AddEnglishReportResp
+// @router /author/fans_list [get]
+func (this *YanxuanSpecialController) FanList() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	user := this.User
+	if user == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,用户信息为空"
+		br.Ret = 408
+		return
+	}
+
+	pageSize, _ := this.GetInt("PageSize")
+	currentIndex, _ := this.GetInt("CurrentIndex")
+
+	var startSize int
+	if pageSize <= 0 {
+		pageSize = utils.PageSize20
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	startSize = utils.StartIndex(currentIndex, pageSize)
+	resp := new(models.CygxYanxuanSpecialFollowListResp)
+	var condition string
+	var pars []interface{}
+	condition = "  AND follow_user_id = ?   "
+	pars = append(pars, user.UserId)
+	//作者粉丝数量
+	total, err := models.GetCygxYanxuanSpecialFollowCount(condition, pars)
+	if err != nil {
+		br.Msg = "获取信息失败!"
+		br.ErrMsg = "获取信息失败,GetCygxYanxuanSpecialFollowCountErr:" + err.Error()
+		return
+	}
+	condition += "  ORDER  BY  cygx_yanxuan_special_follow_id DESC   "
+	list, err := models.GetCygxYanxuanSpecialFollowList(condition, pars, startSize, pageSize)
+	if err != nil {
+		br.Msg = "获取信息失败!"
+		br.ErrMsg = "获取信息失败,GetCygxYanxuanSpecialFollowList:" + err.Error()
+		return
+	}
+
+	if len(list) > 0 {
+		var userIds []int
+		for _, v := range list {
+			userIds = append(userIds, v.UserId)
+		}
+		//用户头像
+		listUser, err := models.GetWxUserListByUserIdsArr(userIds)
+		if err != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取失败, Err:" + err.Error()
+			return
+		}
+		mapUserImg := make(map[int]string)
+		for _, v := range listUser {
+			if v.Headimgurl != "" {
+				mapUserImg[v.UserId] = v.Headimgurl
+			} else {
+				mapUserImg[v.UserId] = utils.DefaultHeadimgurl
+			}
+		}
+
+		for _, v := range list {
+			item := new(models.CygxYanxuanSpecialFollowResp)
+			if v.CompanyName != "" {
+				item.CompanyName = v.CompanyName
+			} else {
+				item.CompanyName = "潜在客户"
+			}
+			if v.RealName != "" {
+				item.RealName = v.RealName
+			} else {
+				item.RealName = "--"
+			}
+			item.CreateTime = v.CreateTime.Format(utils.FormatDateTime)
+			item.Headimgurl = mapUserImg[v.UserId]
+			resp.List = append(resp.List, item)
+		}
+	} else {
+		resp.List = make([]*models.CygxYanxuanSpecialFollowResp, 0)
+	}
+
+	page := paging.GetPaging(currentIndex, pageSize, total)
+	resp.Paging = page
+	br.Data = resp
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+}
+
 //留言
 //点赞
 //列表

+ 10 - 5
controllers/yanxuan_special_message.go

@@ -2,7 +2,6 @@ package controllers
 
 import (
 	"encoding/json"
-	"fmt"
 	"github.com/rdlucklib/rdluck_tools/paging"
 	"hongze/hongze_web_mfyx/models"
 	"hongze/hongze_web_mfyx/services"
@@ -461,6 +460,14 @@ func (this *YanxuanSpecialMessageController) MessageSpecialList() {
 
 	userId := user.UserId
 	resp := new(models.YanxuanSpecialMessageManageRespListResp)
+
+	publiccTotal, err := models.GetCygxYanxuanSpecialMessagerPublicCount(yanxuanSpecialId)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败, Err:" + err.Error()
+		return
+	}
+	resp.PublicMessageTotal = publiccTotal
 	var condition string
 	var pars []interface{}
 
@@ -470,7 +477,6 @@ func (this *YanxuanSpecialMessageController) MessageSpecialList() {
 	parsMyself = append(parsMyself, userId)
 
 	var listMyself []*models.CygxYanxuanSpecialMessage
-	var err error
 	if currentIndex == 1 {
 		//获取自己未公开的留言
 		listMyself, err = models.GetCygxYanxuanSpecialMessageList(conditionMyself, parsMyself, 0, 999)
@@ -532,6 +538,7 @@ func (this *YanxuanSpecialMessageController) MessageSpecialList() {
 				userIds = append(userIds, v.UserId)
 				messageIdsAll = append(messageIdsAll, v.MessageId)
 				itemChild := new(models.CygxYanxuanSpecialMessageManageChildResp)
+				itemChild.UserId = v.UserId
 				itemChild.MessageId = v.MessageId
 				itemChild.Content = v.Content
 				itemChild.CreateTime = v.CreateTime.Format(utils.FormatDateTime)
@@ -540,7 +547,6 @@ func (this *YanxuanSpecialMessageController) MessageSpecialList() {
 		}
 
 		likeMap := services.GetYanxuanSpecialMessageLikeMap(userId)
-		fmt.Println(likeMap)
 		//用户头像
 		listUser, err := models.GetWxUserListByUserIdsArr(userIds)
 		if err != nil {
@@ -575,8 +581,7 @@ func (this *YanxuanSpecialMessageController) MessageSpecialList() {
 			if len(itemChildMap[v.MessageId]) > 0 {
 				for _, vm := range itemChildMap[v.MessageId] {
 					vm.IsLikeCount = likeMap[vm.MessageId]
-					vm.Headimgurl = mapUserImg[vm.MessageId]
-					fmt.Println(vm.Headimgurl)
+					vm.Headimgurl = mapUserImg[vm.UserId]
 				}
 				item.ChildList = itemChildMap[v.MessageId]
 			} else {

+ 24 - 0
models/cygx_yanxuan_special_follow.go

@@ -2,6 +2,7 @@ package models
 
 import (
 	"github.com/beego/beego/v2/client/orm"
+	"github.com/rdlucklib/rdluck_tools/paging"
 	"time"
 )
 
@@ -74,3 +75,26 @@ func GetCygxYanxuanSpecialFollowCountByUser(userId, followUserId int) (count int
 	err = o.Raw(sqlCount, userId, followUserId).QueryRow(&count)
 	return
 }
+
+type CygxYanxuanSpecialFollowResp struct {
+	CompanyName string // 公司名称
+	RealName    string // 用户实际名称
+	CreateTime  string // 创建时间
+	Headimgurl  string `comment:"用户头像"`
+}
+
+type CygxYanxuanSpecialFollowListResp struct {
+	Paging *paging.PagingItem `description:"分页数据"`
+	List   []*CygxYanxuanSpecialFollowResp
+}
+
+func GetCygxYanxuanSpecialFollowList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxYanxuanSpecialFollow, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT *
+			FROM
+			cygx_yanxuan_special_follow
+			WHERE 1 = 1 ` + condition
+	sql += ` LIMIT ?,?  `
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	return
+}

+ 12 - 2
models/cygx_yanxuan_special_message.go

@@ -110,6 +110,14 @@ func GetCygxYanxuanSpecialMessagerCount(condition string, pars []interface{}) (c
 	return
 }
 
+// 获取留言公开数量
+func GetCygxYanxuanSpecialMessagerPublicCount(yanxuanSpecialId int) (count int, err error) {
+	o := orm.NewOrm()
+	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_yanxuan_special_message WHERE   status = 1 AND  yanxuan_special_id = ?  `
+	err = o.Raw(sqlCount, yanxuanSpecialId).QueryRow(&count)
+	return
+}
+
 type CygxYanxuanSpecialMessageManageResp struct {
 	MessageId        int                                         `comment:"留言消息ID"`
 	RealName         string                                      `comment:"用户实际名称"`
@@ -129,6 +137,7 @@ type CygxYanxuanSpecialMessageManageResp struct {
 }
 
 type CygxYanxuanSpecialMessageManageChildResp struct {
+	UserId      int    `comment:"用户ID"`
 	MessageId   int    `comment:"留言消息ID"`
 	Content     string `comment:"留言内容"`
 	Headimgurl  string `comment:"用户头像"`
@@ -138,6 +147,7 @@ type CygxYanxuanSpecialMessageManageChildResp struct {
 }
 
 type YanxuanSpecialMessageManageRespListResp struct {
-	Paging *paging.PagingItem `description:"分页数据"`
-	List   []*CygxYanxuanSpecialMessageManageResp
+	PublicMessageTotal int                `comment:"公开留言数量"`
+	Paging             *paging.PagingItem `description:"分页数据"`
+	List               []*CygxYanxuanSpecialMessageManageResp
 }

+ 35 - 3
models/cygx_yanxuan_special_message_like.go

@@ -1,6 +1,7 @@
 package models
 
 import (
+	"fmt"
 	"github.com/beego/beego/v2/client/orm"
 	"time"
 )
@@ -22,16 +23,47 @@ type CygxYanxuanSpecialMessageLike struct {
 
 // 新增
 func AddCygxYanxuanSpecialMessageLike(item *CygxYanxuanSpecialMessageLike) (err error) {
-	o := orm.NewOrm()
+	o, err := orm.NewOrm().Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		fmt.Println(err)
+		if err == nil {
+			o.Commit()
+		} else {
+			o.Rollback()
+		}
+	}()
 	_, err = o.Insert(item)
+	if err != nil {
+		return
+	}
+
+	sql := `UPDATE cygx_yanxuan_special_message SET like_count = like_count+1  WHERE  message_id = ?`
+	_, err = o.Raw(sql, item.MessageId).Exec()
 	return
 }
 
 // 删除
 func DeleteCygxYanxuanSpecialMessageLike(userId, messageId int) (err error) {
-	o := orm.NewOrm()
-	sql := ` DELETE FROM cygx_yanxuan_special_message WHERE  WHERE user_id  = ? AND  message_id = ?   `
+	o, err := orm.NewOrm().Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		fmt.Println(err)
+		if err == nil {
+			o.Commit()
+		} else {
+			o.Rollback()
+		}
+	}()
+	sql := ` DELETE FROM cygx_yanxuan_special_message_like WHERE  WHERE user_id  = ? AND  message_id = ?   `
 	_, err = o.Raw(sql, userId, messageId).Exec()
+
+	sql = `UPDATE cygx_yanxuan_special_message SET like_count = like_count-1  WHERE  message_id = ?`
+	_, err = o.Raw(sql, messageId).Exec()
 	return
 }
 

+ 116 - 0
models/cygx_yanxuan_special_special_like.go

@@ -0,0 +1,116 @@
+package models
+
+import (
+	"fmt"
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+// 留言点赞
+type CygxYanxuanSpecialSpecialLike struct {
+	YanxuanSpecialLikeId int       `orm:"column(yanxuan_special_like_id);pk"`
+	YanxuanSpecialId     int       `comment:"cygx_yanxuan_special 表主键ID"`
+	UserId               int       `comment:"用户ID"`
+	Mobile               string    `comment:"手机号"`
+	Email                string    `comment:"邮箱"`
+	CompanyId            int       `comment:"公司ID"`
+	CompanyName          string    `comment:"公司名称"`
+	RealName             string    `comment:"用户实际名称"`
+	RegisterPlatform     int       `comment:"来源 1小程序,2:网页,5买方研选小程序,6:买方研选网页版"`
+	CreateTime           time.Time `comment:"创建时间"`
+	ModifyTime           time.Time `comment:"修改时间"`
+}
+
+type LikeCygxYanxuanSpecialSpecialLikeReq struct {
+	YanxuanSpecialId int `comment:"专栏文章ID"`
+	DoType           int `comment:"0取消置顶,1置顶"`
+}
+
+// 新增
+func AddCygxCygxYanxuanSpecialSpecialLike(item *CygxYanxuanSpecialSpecialLike, authorUserId int) (err error) {
+	o, err := orm.NewOrm().Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		fmt.Println(err)
+		if err == nil {
+			o.Commit()
+		} else {
+			o.Rollback()
+		}
+	}()
+	_, err = o.Insert(item)
+	if err != nil {
+		return
+	}
+
+	sql := `UPDATE cygx_yanxuan_special SET like_count = like_count+1  WHERE  id = ?`
+	_, err = o.Raw(sql, item.YanxuanSpecialId).Exec()
+	if err != nil {
+		return
+	}
+
+	sql = `UPDATE cygx_yanxuan_special_author SET special_like_count = special_like_count+1  WHERE  user_id = ?`
+	_, err = o.Raw(sql, authorUserId).Exec()
+	return
+}
+
+// 删除
+func DeleteCygxYanxuanSpecialSpecialLike(userId, yanxuanSpecialId, authorUserId int) (err error) {
+	o, err := orm.NewOrm().Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		fmt.Println(err)
+		if err == nil {
+			o.Commit()
+		} else {
+			o.Rollback()
+		}
+	}()
+	//o := orm.NewOrm()
+	sql := ` DELETE FROM cygx_yanxuan_special_special_like WHERE   user_id  = ? AND  yanxuan_special_id = ?   `
+	_, err = o.Raw(sql, userId, yanxuanSpecialId).Exec()
+	if err != nil {
+		return
+	}
+	sql = `UPDATE cygx_yanxuan_special SET like_count = like_count-1  WHERE  id = ?`
+	_, err = o.Raw(sql, yanxuanSpecialId).Exec()
+
+	if err != nil {
+		return
+	}
+
+	sql = `UPDATE cygx_yanxuan_special_author SET special_like_count = special_like_count-1  WHERE  user_id = ?`
+	_, err = o.Raw(sql, authorUserId).Exec()
+	return
+}
+
+// 获取数量
+func GetCygxYanxuanSpecialSpecialLikeCountByUidYid(userId, yanxuanSpecialId int) (count int, err error) {
+	o := orm.NewOrm()
+	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_yanxuan_special_special_like  WHERE user_id  = ? AND  yanxuan_special_id = ? `
+	err = o.Raw(sqlCount, userId, yanxuanSpecialId).QueryRow(&count)
+	return
+}
+
+func GetCygxYanxuanSpecialSpecialLikeList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxYanxuanSpecialMessageLike, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT *
+			FROM
+			cygx_yanxuan_special_special_like
+			WHERE 1 = 1 ` + condition
+	sql += ` LIMIT ?,?  `
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	return
+}
+
+// GetCygxYanxuanSpecialMessageLikeByUser 根据用户ID获取所有点赞留言
+func GetCygxYanxuanSpecialSpecialLikeByUser(userId int) (items []*CygxYanxuanSpecialSpecialLike, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT yanxuan_special_id  FROM cygx_yanxuan_special_special_like  WHERE 1 =1  AND  user_id =?  `
+	_, err = o.Raw(sql, userId).QueryRows(&items)
+	return
+}

+ 1 - 0
models/cygx_yanxuan_special_user.go

@@ -46,6 +46,7 @@ type CygxYanxuanSpecialAuthorItem struct {
 	IsFollow            int       // 是否已关注 1已关注 0 未关注
 	FansNum             int       // 粉丝数量
 	LabelKeywordImgLink string    `description:"标签关键词ico"`
+	SpecialLikeCount    int       `description:"专栏点赞数量"`
 	//YanxuanSpecialCenter *CygxYanxuanSpecialCenterAuthorResp // 研选专栏文章内容
 }
 

+ 1 - 0
models/db.go

@@ -100,6 +100,7 @@ func init() {
 		new(CygxYanxuanSpecialApprovalLog),
 		new(CygxYanxuanSpecialMessage),
 		new(CygxYanxuanSpecialMessageLike),
+		new(CygxYanxuanSpecialSpecialLike),
 		new(CygxResourceData),
 		new(CygxMorningMeetingReviewChapterHistory),
 		new(CygxAskserieVideoHistoryRecord),

+ 18 - 0
routers/commentsRouter.go

@@ -970,6 +970,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hongze_web_mfyx/controllers:YanxuanSpecialController"] = append(beego.GlobalControllerRouter["hongze/hongze_web_mfyx/controllers:YanxuanSpecialController"],
+        beego.ControllerComments{
+            Method: "FanList",
+            Router: `/author/fans_list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hongze_web_mfyx/controllers:YanxuanSpecialController"] = append(beego.GlobalControllerRouter["hongze/hongze_web_mfyx/controllers:YanxuanSpecialController"],
         beego.ControllerComments{
             Method: "AuthorHeadImg",
@@ -1069,6 +1078,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hongze_web_mfyx/controllers:YanxuanSpecialController"] = append(beego.GlobalControllerRouter["hongze/hongze_web_mfyx/controllers:YanxuanSpecialController"],
+        beego.ControllerComments{
+            Method: "Like",
+            Router: `/like`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hongze_web_mfyx/controllers:YanxuanSpecialController"] = append(beego.GlobalControllerRouter["hongze/hongze_web_mfyx/controllers:YanxuanSpecialController"],
         beego.ControllerComments{
             Method: "Record",