package models import ( "github.com/beego/beego/v2/client/orm" "time" ) type CygxIndustryFllow struct { Id int `orm:"column(id);pk"` IndustrialManagementId int `description:"产业D"` UserId int `description:"用户ID"` Mobile string `description:"手机号"` Email string `description:"邮箱"` CompanyId int `description:"公司id"` CompanyName string `description:"公司名称"` Type int `description:"操作方式,1报名,2取消报名"` CreateTime time.Time `description:"创建时间"` ModifyTime time.Time `description:"更新时间"` RealName string `description:"用户实际名称"` Source int `description:"来源1查研观向,2查研观向小助手"` FollowType int `description:"1,重点关注,3不感兴趣,0默认接受推送"` FollowTypeOrder int `description:"排序方式,重点关注在最前面,不感兴趣在最后面。1,重点关注,-1不感兴趣,0默认接受推送"` } type CygxIndustryFllowRep struct { IndustrialManagementId int `description:"产业D"` FollowType int `description:"1,重点关注,3不感兴趣,0默认接受推送"` } type CygxCategoryFllowRep struct { CategoryId int `description:"分类ID"` FollowType int `description:"1,重点关注,3不感兴趣,0默认接受推送"` } // 根据手机号获取用户关注的产业 func GetCygxIndustryFllowList(mobile string) (items []*CygxIndustryFllow, err error) { o := orm.NewOrm() sql := `SELECT * FROM cygx_industry_fllow WHERE mobile = ?` _, err = o.Raw(sql, mobile).QueryRows(&items) return } type CygxIndustryFllowResp struct { Status int `description:"1:关注,2:取消关注"` } // 获取数量 func GetCountCygxIndustryFllowByUid(userId int) (count int, err error) { sql := `SELECT COUNT(1) AS count FROM cygx_industry_fllow WHERE user_id=? ` err = orm.NewOrm().Raw(sql, userId).QueryRow(&count) return } // 添加 func AddCygxIndustryFllow(item *CygxIndustryFllow) (lastId int64, err error) { o, err := orm.NewOrm().Begin() if err != nil { return } defer func() { if err == nil { o.Commit() } else { o.Rollback() } }() sql := `DELETE FROM cygx_industry_fllow WHERE user_id=? AND industrial_management_id=? ` _, err = o.Raw(sql, item.UserId, item.IndustrialManagementId).Exec() if err != nil { return } lastId, err = o.Insert(item) return } // 删除 func RemoveCygxIndustryFllow(userId, industrialManagementId int) (err error) { o := orm.NewOrm() sql := `DELETE FROM cygx_industry_fllow WHERE user_id=? AND industrial_management_id=? ` _, err = o.Raw(sql, userId, industrialManagementId).Exec() return } // 获取某个用户关注某个行业下的产业数量 func GetCountCygxIndustryFllowByUidAndChartPermissionId(userId, ChartPermissionId int) (count int, err error) { sql := `SELECT COUNT( 1 ) AS count FROM cygx_industry_fllow AS f INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = f.industrial_management_id WHERE user_id = ? AND m.chart_permission_id = ? ` err = orm.NewOrm().Raw(sql, userId, ChartPermissionId).QueryRow(&count) return } // 获取用户关注的产业列表 func GetUserFllowIndustrialList(userId int) (items []*CygxIndustryFllow, err error) { o := orm.NewOrm() sql := `SELECT f.user_id, f.follow_type, m.industry_name, m.industrial_management_id FROM cygx_industry_fllow AS f INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = f.industrial_management_id WHERE 1 = 1 AND f.user_id = ? ` _, err = o.Raw(sql, userId).QueryRows(&items) return }