1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- package models
- import (
- "fmt"
- "github.com/beego/beego/v2/client/orm"
- "time"
- )
- // 留言点赞
- type CygxYanxuanSpecialMessageLike struct {
- MessageLikeId int `orm:"column(message_like_id);pk"`
- MessageId int `comment:"留言消息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:"修改时间"`
- }
- // 新增
- func AddCygxYanxuanSpecialMessageLike(item *CygxYanxuanSpecialMessageLike) (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_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, 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 user_id = ? AND message_id = ? `
- _, err = o.Raw(sql, userId, messageId).Exec()
- if err != nil {
- return
- }
- sql = `UPDATE cygx_yanxuan_special_message SET like_count = like_count-1 WHERE message_id = ?`
- _, err = o.Raw(sql, messageId).Exec()
- return
- }
- // 获取数量
- func GetCygxYanxuanSpecialMessageLikeCountByUidMid(userId, messageId int) (count int, err error) {
- o := orm.NewOrm()
- sqlCount := ` SELECT COUNT(1) AS count FROM cygx_yanxuan_special_message_like WHERE user_id = ? AND message_id = ? `
- err = o.Raw(sqlCount, userId, messageId).QueryRow(&count)
- return
- }
- func GetCygxYanxuanSpecialMessageLikeList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxYanxuanSpecialMessageLike, err error) {
- o := orm.NewOrm()
- sql := `SELECT *
- FROM
- cygx_yanxuan_special_message_like
- WHERE 1 = 1 ` + condition
- sql += ` LIMIT ?,? `
- _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
- return
- }
- // GetCygxYanxuanSpecialMessageLikeByUser 根据用户ID获取所有点赞留言
- func GetCygxYanxuanSpecialMessageLikeByUser(userId int) (items []*CygxYanxuanSpecialMessageLike, err error) {
- o := orm.NewOrm()
- sql := `SELECT message_id FROM cygx_yanxuan_special_message_like WHERE 1 =1 AND user_id =? `
- _, err = o.Raw(sql, userId).QueryRows(&items)
- return
- }
|