123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- 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
- }
|