cygx_yanxuan_special.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "time"
  6. )
  7. type CygxYanxuanSpecial struct {
  8. Id int `orm:"column(id);pk"`
  9. UserId int // 用户ID
  10. CreateTime time.Time // 创建时间
  11. ModifyTime time.Time // 修改时间
  12. PublishTime time.Time // 提审过审或驳回时间
  13. Content string // 内容
  14. Tags string // 标签
  15. Status int // 1:未发布,2:审核中 3:已发布 4:驳回
  16. ImgUrl string // 图片链接
  17. DocUrl string // 文档链接
  18. Reason string // 理由
  19. Title string // 标题
  20. Type int // 类型1:笔记,2:观点
  21. CompanyTags string // 公司标签
  22. IndustryTags string // 行业标签
  23. }
  24. type CygxYanxuanSpecialItem struct {
  25. Id int `orm:"column(id);pk"`
  26. UserId int // 用户ID
  27. CreateTime string // 创建时间
  28. ModifyTime string // 修改时间
  29. PublishTime string // 提审过审或驳回时间
  30. Content string // 内容
  31. Tags string // 标签
  32. Status int // 1:未发布,2:审核中 3:已发布 4:驳回
  33. ImgUrl string // 图片链接
  34. DocUrl string // 文档链接
  35. SpecialName string // 专栏名称
  36. Introduction string // 介绍
  37. Label string // 标签
  38. NickName string // 昵称
  39. RealName string // 姓名
  40. Mobile string // 手机号
  41. HeadImg string // 头像
  42. BgImg string // 背景图
  43. Reason string // 理由
  44. Title string // 标题
  45. Type int // 类型1:笔记,2:观点
  46. CollectNum int
  47. MyCollectNum int
  48. IsCollect int
  49. CompanyTags string
  50. IndustryTags string
  51. ContentHasImg int //正文是否包含图片 1包含 0不包含
  52. ContentHasStyle bool //正文是否包含格式
  53. Docs []Doc
  54. Pv string `description:"Pv"`
  55. Uv string `description:"Uv"`
  56. }
  57. type CygxYanxuanSpecialResp struct {
  58. CygxYanxuanSpecialItem
  59. Docs []Doc
  60. CompanyTags []string
  61. IndustryTags []string
  62. HasPermission int `description:"1:正常展示,2:不展示"`
  63. ExamineStatus int `description:"1:未发布,2:审核中 3:已发布 4:驳回"`
  64. IsShowExamine bool `description:"是否展示审核状态按钮"`
  65. }
  66. type CygxYanxuanSpecialCenterResp struct {
  67. Id int `orm:"column(id);pk"`
  68. UserId int // 用户ID
  69. CreateTime string // 创建时间
  70. ModifyTime string // 修改时间
  71. PublishTime string // 提审过审或驳回时间
  72. Content string // 内容
  73. Tags string // 标签
  74. Status int // 1:未发布,2:审核中 3:已发布 4:驳回
  75. ImgUrl string // 图片链接
  76. DocUrl string // 文档链接
  77. SpecialName string // 专栏名称
  78. Introduction string // 介绍
  79. Label string // 标签
  80. NickName string // 昵称
  81. RealName string // 姓名
  82. Mobile string // 手机号
  83. HeadImg string // 头像
  84. BgImg string // 背景图
  85. Reason string // 理由
  86. Title string // 标题
  87. Type int // 类型1:笔记,2:观点
  88. CollectNum int
  89. MyCollectNum int
  90. IsCollect int
  91. CompanyTags string
  92. IndustryTags string
  93. ContentHasImg int //正文是否包含图片 1包含 0不包含
  94. ContentHasStyle bool //正文是否包含格式
  95. Docs []Doc
  96. Annotation string `description:"核心观点"`
  97. Source string `description:"来源"`
  98. Pv string `description:"Pv"`
  99. Uv string `description:"Uv"`
  100. PublishDate string // 提审过审或驳回时间 string `description:"核心观点"`
  101. }
  102. type Doc struct {
  103. DocName string
  104. DocSuffix string
  105. DocUrl string
  106. DocIcon string
  107. }
  108. func GetYanxuanSpecialList(userId int, condition string, pars []interface{}, startSize, pageSize int) (items []*CygxYanxuanSpecialCenterResp, err error) {
  109. o := orm.NewOrm()
  110. sql := ``
  111. sql = `SELECT a.*,b.bg_img,b.head_img,b.introduction,b.label,b.mobile,b.nick_name,b.real_name,b.special_name,
  112. ( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac WHERE ac.yanxuan_special_id = a.id ) AS collect_num,
  113. ( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac WHERE ac.yanxuan_special_id = a.id AND user_id = ? ) AS my_collect_num
  114. FROM cygx_yanxuan_special AS a
  115. JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
  116. WHERE 1=1 `
  117. if condition != "" {
  118. sql += condition
  119. }
  120. sql += `ORDER BY a.publish_time DESC `
  121. if startSize+pageSize > 0 {
  122. sql += ` LIMIT ?,? `
  123. _, err = o.Raw(sql, userId, pars, startSize, pageSize).QueryRows(&items)
  124. } else {
  125. _, err = o.Raw(sql, userId, pars).QueryRows(&items)
  126. }
  127. return
  128. }
  129. func GetYanxuanSpecialListBycondition(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxYanxuanSpecialCenterResp, err error) {
  130. o := orm.NewOrm()
  131. sql := `SELECT a.* FROM cygx_yanxuan_special AS a WHERE 1=1 `
  132. if condition != "" {
  133. sql += condition
  134. }
  135. if startSize+pageSize > 0 {
  136. sql += ` LIMIT ?,? `
  137. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  138. } else {
  139. _, err = o.Raw(sql, pars).QueryRows(&items)
  140. }
  141. return
  142. }
  143. type EnableCygxYanxuanSpecialReq struct {
  144. Id int // 文章id
  145. Status int // 1通过2驳回
  146. Reason string //理由
  147. }
  148. func EnableYanxuanSpecial(id, status int, reason, adminName string) (err error) {
  149. o := orm.NewOrm()
  150. sql := ``
  151. sql = `UPDATE cygx_yanxuan_special SET status=?,reason=?,admin_name = ? , publish_time=NOW() WHERE id = ? `
  152. _, err = o.Raw(sql, status, reason, adminName, id).Exec()
  153. return
  154. }
  155. type SpecialListResp struct {
  156. IsAuthor bool `description:"是否开通了研选专栏"`
  157. IsImproveInformation bool `description:"作者信息是否完善"`
  158. Paging *paging.PagingItem `description:"分页数据"`
  159. List []*CygxYanxuanSpecialCenterResp
  160. }
  161. func GetYanxuanSpecialById(specialId, userId int) (item *CygxYanxuanSpecialItem, err error) {
  162. o := orm.NewOrm()
  163. sql := ``
  164. sql = `SELECT a.*,b.bg_img,b.head_img,b.introduction,b.label,b.mobile,
  165. b.nick_name,b.real_name,b.special_name,
  166. ( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac WHERE ac.yanxuan_special_id = a.id ) AS collect_num,
  167. ( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac WHERE ac.yanxuan_special_id = a.id AND user_id = ? ) AS my_collect_num
  168. FROM cygx_yanxuan_special AS a
  169. JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
  170. WHERE a.id=? `
  171. err = o.Raw(sql, userId, specialId).QueryRow(&item)
  172. return
  173. }
  174. func GetYanxuanSpecialBySpecialId(specialId int) (item *CygxYanxuanSpecialItem, err error) {
  175. o := orm.NewOrm()
  176. sql := ``
  177. sql = `SELECT a.*
  178. FROM cygx_yanxuan_special AS a
  179. WHERE a.id=? `
  180. err = o.Raw(sql, specialId).QueryRow(&item)
  181. return
  182. }
  183. type CygxYanxuanSpecialReq struct {
  184. Id int `orm:"column(id);pk"`
  185. Content string // 内容
  186. Tags string // 标签
  187. DoType int // 1保存 2发布
  188. ImgUrl string // 图片链接
  189. DocUrl string // 文档链接
  190. Title string // 标题
  191. Type int // 类型1:笔记,2:观点
  192. IndustryTags string // 行业标签
  193. CompanyTags string // 公司标签
  194. IsApprovalPersonnel bool // 是否是审批人员操作
  195. }
  196. func AddCygxYanxuanSpecial(item *CygxYanxuanSpecial) (lastId int64, err error) {
  197. o := orm.NewOrm()
  198. lastId, err = o.Insert(item)
  199. return
  200. }
  201. func UpdateYanxuanSpecial(item *CygxYanxuanSpecial) (err error) {
  202. o := orm.NewOrm()
  203. sql := ``
  204. sql = `UPDATE cygx_yanxuan_special SET title=?,content=?,company_tags=?,industry_tags=?,img_url=?,doc_url=?,type=?,status=?,
  205. modify_time=NOW(),publish_time=NOW() WHERE id = ? `
  206. _, err = o.Raw(sql, item.Title, item.Content, item.CompanyTags, item.IndustryTags, item.ImgUrl, item.DocUrl, item.Type, item.Status, item.Id).Exec()
  207. return
  208. }
  209. func GetYanxuanSpecialIndustry(keyword string) (IndustryNames []string, err error) {
  210. o := orm.NewOrm()
  211. sql := ``
  212. if keyword == "" {
  213. sql = `SELECT industry_name FROM cygx_yanxuan_special_industry `
  214. } else {
  215. sql = `SELECT industry_name FROM cygx_yanxuan_special_industry WHERE industry_name LIKE '%` + keyword + `%' `
  216. }
  217. _, err = o.Raw(sql).QueryRows(&IndustryNames)
  218. return
  219. }
  220. type CancelPublishCygxYanxuanSpecialReq struct {
  221. Id int // 文章id
  222. }
  223. func CancelPublishYanxuanSpecial(id int) (err error) {
  224. o := orm.NewOrm()
  225. sql := ``
  226. sql = `UPDATE cygx_yanxuan_special SET status=1,publish_time=NOW(),modify_time=NOW() WHERE id = ? `
  227. _, err = o.Raw(sql, id).Exec()
  228. return
  229. }
  230. type DelCygxYanxuanSpecialReq struct {
  231. Id int // 文章id
  232. }
  233. func DelYanxuanSpecial(id int) (err error) {
  234. o := orm.NewOrm()
  235. sql := ``
  236. sql = `DELETE FROM cygx_yanxuan_special WHERE id = ? `
  237. _, err = o.Raw(sql, id).Exec()
  238. return
  239. }
  240. type CygxYanxuanSpecialCheckReq struct {
  241. Content string // 内容
  242. ImgUrl []string // 图片
  243. }
  244. func GetYanxuanSpecialFollowUserById(specialId int) (items []int, err error) {
  245. o := orm.NewOrm()
  246. sql := ``
  247. sql = `SELECT b.user_id
  248. FROM cygx_yanxuan_special AS a
  249. JOIN cygx_yanxuan_special_follow AS b ON a.user_id = b.follow_user_id
  250. WHERE a.id=? `
  251. _, err = o.Raw(sql, specialId).QueryRows(&items)
  252. return
  253. }
  254. func GetYanxuanSpecialItemById(specialId int) (item *CygxYanxuanSpecialItem, err error) {
  255. o := orm.NewOrm()
  256. sql := ``
  257. sql = `SELECT a.*,b.bg_img,b.head_img,b.introduction,b.label,b.mobile,
  258. b.nick_name,b.real_name,b.special_name
  259. FROM cygx_yanxuan_special AS a
  260. JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
  261. WHERE a.id=? `
  262. err = o.Raw(sql, specialId).QueryRow(&item)
  263. return
  264. }
  265. // 获取数量
  266. func GetCygxYanxuanSpecialCount(condition string, pars []interface{}) (count int, err error) {
  267. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_yanxuan_special as a WHERE 1= 1 `
  268. if condition != "" {
  269. sqlCount += condition
  270. }
  271. o := orm.NewOrm()
  272. err = o.Raw(sqlCount, pars).QueryRow(&count)
  273. return
  274. }
  275. // UpdateYanxuanSpecialPv 修改研选专栏的阅读Pv
  276. func UpdateYanxuanSpecialPv(id int) (err error) {
  277. o := orm.NewOrm()
  278. sql := `UPDATE cygx_yanxuan_special SET pv=pv+1 WHERE id = ? `
  279. _, err = o.Raw(sql, id).Exec()
  280. return
  281. }
  282. // UpdateYanxuanSpecialUv 修改研选专栏的阅读Uv
  283. func UpdateYanxuanSpecialUv(id int) (err error) {
  284. o := orm.NewOrm()
  285. sql := `UPDATE cygx_yanxuan_special SET uv=uv+1 WHERE id = ? `
  286. _, err = o.Raw(sql, id).Exec()
  287. return
  288. }
  289. // 增加收藏数量
  290. func UpdateYanxuanSpecialarticleCollectNumIncrease(id int) (err error) {
  291. o := orm.NewOrm()
  292. sql := ``
  293. sql = `UPDATE cygx_yanxuan_special SET article_collect_num = article_collect_num +1 WHERE id = ? `
  294. _, err = o.Raw(sql, id).Exec()
  295. return
  296. }
  297. // 减少收藏数量
  298. func UpdateYanxuanSpecialarticleCollectNumReduce(id int) (err error) {
  299. o := orm.NewOrm()
  300. sql := ``
  301. sql = `UPDATE cygx_yanxuan_special SET article_collect_num = article_collect_num - 1 WHERE id = ? `
  302. _, err = o.Raw(sql, id).Exec()
  303. return
  304. }