cygx_yanxuan_special.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hongze_web_mfyx/models/order"
  6. "time"
  7. )
  8. type CygxYanxuanSpecial struct {
  9. Id int `orm:"column(id);pk"`
  10. UserId int // 用户ID
  11. CreateTime time.Time // 创建时间
  12. ModifyTime time.Time // 修改时间
  13. PublishTime time.Time // 提审过审或驳回时间
  14. Content string // 内容
  15. CompanyTags string // 标签
  16. IndustryTags string // 标签
  17. Status int // 1:未发布,2:审核中 3:已发布 4:驳回
  18. ImgUrl string // 图片链接
  19. DocUrl string // 文档链接
  20. Reason string // 理由
  21. Title string // 标题
  22. Type int // 类型1:笔记,2:观点
  23. AdminName string // 审核人员姓名
  24. }
  25. type CygxYanxuanSpecialItem struct {
  26. Id int `orm:"column(id);pk"`
  27. UserId int // 用户ID
  28. SpecialColumnId int // 专栏栏目ID
  29. CreateTime string // 创建时间
  30. ModifyTime string // 修改时间
  31. PublishTime string // 提审过审或驳回时间
  32. Content string // 内容
  33. Tags string // 标签
  34. TagList []string // 标签
  35. Status int // 1:未发布,2:审核中 3:已发布 4:驳回
  36. ImgUrl string // 图片链接
  37. ImgUrlList []string // 图片链接
  38. DocUrl string // 文档链接
  39. SpecialName string // 专栏名称
  40. Introduction string // 介绍
  41. Label string // 标签
  42. NickName string // 昵称
  43. RealName string // 姓名
  44. Mobile string // 手机号
  45. HeadImg string // 头像
  46. BgImg string // 背景图
  47. Reason string // 理由
  48. Title string // 标题
  49. AuthorStatus int // 作者状态
  50. Type int // 类型1:笔记,2:观点
  51. CollectNum int
  52. MyCollectNum int
  53. IsCollect int
  54. ContentHasImg int //正文是否包含图片 1包含 0不包含
  55. CompanyTags string
  56. IndustryTags string
  57. Docs []Doc
  58. Annotation string `description:"核心观点"`
  59. Pv int `description:"Pv"`
  60. Uv int `description:"Uv"`
  61. BodyHighlight []string `description:"搜索高亮展示结果"`
  62. LabelKeywordImgLink string `description:"标签关键词ico"`
  63. LikeCount int `comment:"点赞数量"`
  64. IsLikeCount bool `comment:"是否点赞"`
  65. }
  66. type CygxYanxuanSpecialDetailResp struct {
  67. Detail *CygxYanxuanSpecialResp
  68. HasPermission int `description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,已提交过申请,4:无该行业权限,未提交过申请,5:潜在客户,未提交过申请,6:潜在客户,已提交过申请"`
  69. PopupPriceMsg string `description:"价格弹窗信息"`
  70. IsShowWxPay bool `description:"是否展示微信支付"`
  71. IsCompanyApply bool `description:"机构是否申请过试用"`
  72. IsNeedBusinessCard bool `description:"是否需要上传名片"`
  73. GoodsList []*order.CygxGoodsResp `description:"商品信息"`
  74. CygxYanxuanSpecialItem
  75. Docs []Doc
  76. CompanyTags []string
  77. IndustryTags []string
  78. IsApprovalAdmin bool // 是否是审批人员
  79. ShareImg string `description:"分享图片"`
  80. IsFollowAuthor bool // 是否关注作者
  81. }
  82. type CygxYanxuanSpecialResp struct {
  83. CygxYanxuanSpecialItem
  84. Docs []Doc
  85. CompanyTags []string
  86. IndustryTags []string
  87. HasPermission int `description:"1:正常展示,2:不展示"`
  88. IsApprovalAdmin bool // 是否是审批人员
  89. ShareImg string `description:"分享图片"`
  90. IsFollowAuthor bool // 是否关注作者
  91. }
  92. type Doc struct {
  93. DocName string
  94. DocSuffix string
  95. DocUrl string
  96. DocIcon string
  97. }
  98. type DocReq struct {
  99. DocName string
  100. DocSuffix string
  101. DocUrl string
  102. }
  103. func GetYanxuanSpecialList(userId int, condition string, pars []interface{}, startSize, pageSize int) (items []*CygxYanxuanSpecialItem, err error) {
  104. o := orm.NewOrm()
  105. sql := ``
  106. sql = `SELECT a.*,b.id AS special_column_id,b.bg_img,b.head_img,b.introduction,b.label,b.mobile,b.nick_name,b.real_name,b.special_name,b.status AS author_status,
  107. ( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac WHERE ac.yanxuan_special_id = a.id ) AS collect_num,
  108. ( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac WHERE ac.yanxuan_special_id = a.id AND user_id = ? ) AS my_collect_num
  109. FROM cygx_yanxuan_special AS a
  110. JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
  111. WHERE 1=1 `
  112. if condition != "" {
  113. sql += condition
  114. }
  115. sql += `ORDER BY a.publish_time DESC `
  116. if startSize+pageSize > 0 {
  117. sql += ` LIMIT ?,? `
  118. _, err = o.Raw(sql, userId, pars, startSize, pageSize).QueryRows(&items)
  119. } else {
  120. _, err = o.Raw(sql, userId, pars).QueryRows(&items)
  121. }
  122. return
  123. }
  124. func GetYanxuanSpecialListHome(userId int, condition string, pars []interface{}, startSize, pageSize int) (items []*CygxYanxuanSpecialItem, err error) {
  125. o := orm.NewOrm()
  126. sql := ``
  127. sql = `SELECT a.id,a.publish_time,a.title ,a.content,a.type, b.id AS special_column_id,b.bg_img,b.head_img,b.introduction,b.label,b.mobile,b.nick_name,b.real_name,b.special_name,b.status AS author_status
  128. FROM cygx_yanxuan_special AS a
  129. JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
  130. WHERE 1=1 `
  131. if condition != "" {
  132. sql += condition
  133. }
  134. sql += `ORDER BY a.publish_time DESC `
  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 []*CygxYanxuanSpecialItem
  160. }
  161. func GetYanxuanSpecialById(specialId, userId int) (item *CygxYanxuanSpecialItem, err error) {
  162. o := orm.NewOrm()
  163. sql := ``
  164. sql = `SELECT a.*,b.id AS special_column_id,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 GetYanxuanSpecialListBycondition(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxYanxuanSpecialItem, err error) {
  175. o := orm.NewOrm()
  176. sql := `SELECT a.* FROM cygx_yanxuan_special AS a WHERE 1=1 `
  177. if condition != "" {
  178. sql += condition
  179. }
  180. if startSize+pageSize > 0 {
  181. sql += ` LIMIT ?,? `
  182. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  183. } else {
  184. _, err = o.Raw(sql, pars).QueryRows(&items)
  185. }
  186. return
  187. }
  188. type CygxYanxuanSpecialReq struct {
  189. Id int `orm:"column(id);pk"`
  190. Content string // 内容
  191. IndustryTags []string // 行业标签
  192. CompanyTags []string // 公司标签
  193. DoType int // 1保存 2发布
  194. ImgUrl []string // 图片链接
  195. Docs []Doc // 文档链接
  196. Title string // 标题
  197. Type int // 类型1:笔记,2:观点
  198. IsApprovalPersonnel bool // 是否是审批人员操作
  199. }
  200. func AddCygxYanxuanSpecial(item *CygxYanxuanSpecial) (lastId int64, err error) {
  201. o := orm.NewOrm()
  202. lastId, err = o.Insert(item)
  203. return
  204. }
  205. func UpdateYanxuanSpecial(item *CygxYanxuanSpecial) (err error) {
  206. o := orm.NewOrm()
  207. sql := ``
  208. sql = `UPDATE cygx_yanxuan_special SET title=?,content=?,company_tags=?,industry_tags=?,img_url=?,doc_url=?,type=?,status=?,
  209. modify_time=NOW(),publish_time=NOW(),admin_name = ? WHERE id = ? `
  210. _, err = o.Raw(sql, item.Title, item.Content, item.CompanyTags, item.IndustryTags, item.ImgUrl, item.DocUrl, item.Type, item.Status, item.AdminName, item.Id).Exec()
  211. return
  212. }
  213. func GetYanxuanSpecialBySpecialId(specialId int) (item *CygxYanxuanSpecialItem, err error) {
  214. o := orm.NewOrm()
  215. sql := ``
  216. sql = `SELECT a.*
  217. FROM cygx_yanxuan_special AS a
  218. WHERE a.id=? `
  219. err = o.Raw(sql, specialId).QueryRow(&item)
  220. return
  221. }
  222. func GetYanxuanSpecialIndustry(keyword string) (IndustryNames []string, err error) {
  223. o := orm.NewOrm()
  224. sql := ``
  225. if keyword == "" {
  226. sql = `SELECT industry_name FROM cygx_yanxuan_special_industry `
  227. } else {
  228. sql = `SELECT industry_name FROM cygx_yanxuan_special_industry WHERE industry_name LIKE '%` + keyword + `%' `
  229. }
  230. _, err = o.Raw(sql).QueryRows(&IndustryNames)
  231. return
  232. }
  233. type CancelPublishCygxYanxuanSpecialReq struct {
  234. Id int // 文章id
  235. }
  236. func CancelPublishYanxuanSpecial(id int) (err error) {
  237. o := orm.NewOrm()
  238. sql := ``
  239. sql = `UPDATE cygx_yanxuan_special SET status=1,publish_time=NOW(),modify_time=NOW() WHERE id = ? `
  240. _, err = o.Raw(sql, id).Exec()
  241. return
  242. }
  243. type DelCygxYanxuanSpecialReq struct {
  244. Id int // 文章id
  245. }
  246. func DelYanxuanSpecial(id int) (err error) {
  247. o := orm.NewOrm()
  248. sql := ``
  249. sql = `DELETE FROM cygx_yanxuan_special WHERE id = ? `
  250. _, err = o.Raw(sql, id).Exec()
  251. return
  252. }
  253. type CygxYanxuanSpecialCheckReq struct {
  254. Content string // 内容
  255. ImgUrl []string // 图片
  256. }
  257. func GetYanxuanSpecialFollowUserById(specialId int) (items []int, err error) {
  258. o := orm.NewOrm()
  259. sql := ``
  260. sql = `SELECT b.user_id
  261. FROM cygx_yanxuan_special AS a
  262. JOIN cygx_yanxuan_special_follow AS b ON a.user_id = b.follow_user_id
  263. WHERE a.id=? `
  264. _, err = o.Raw(sql, specialId).QueryRows(&items)
  265. return
  266. }
  267. func GetYanxuanSpecialItemById(specialId int) (item *CygxYanxuanSpecialItem, err error) {
  268. o := orm.NewOrm()
  269. sql := ``
  270. sql = `SELECT a.*,b.bg_img,b.head_img,b.introduction,b.label,b.mobile,
  271. b.nick_name,b.real_name,b.special_name
  272. FROM cygx_yanxuan_special AS a
  273. JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
  274. WHERE a.id=? `
  275. err = o.Raw(sql, specialId).QueryRow(&item)
  276. return
  277. }
  278. // 获取数量
  279. func GetCygxYanxuanSpecialCount(condition string, pars []interface{}) (count int, err error) {
  280. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_yanxuan_special as a WHERE 1= 1 `
  281. if condition != "" {
  282. sqlCount += condition
  283. }
  284. o := orm.NewOrm()
  285. err = o.Raw(sqlCount, pars).QueryRow(&count)
  286. return
  287. }
  288. // UpdateYanxuanSpecialPv 修改研选专栏的阅读Pv
  289. func UpdateYanxuanSpecialPv(id int) (err error) {
  290. o := orm.NewOrm()
  291. sql := `UPDATE cygx_yanxuan_special SET pv=pv+1 WHERE id = ? `
  292. _, err = o.Raw(sql, id).Exec()
  293. return
  294. }
  295. // UpdateYanxuanSpecialUv 修改研选专栏的阅读Uv
  296. func UpdateYanxuanSpecialUv(id int) (err error) {
  297. o := orm.NewOrm()
  298. sql := `UPDATE cygx_yanxuan_special SET uv=uv+1 WHERE id = ? `
  299. _, err = o.Raw(sql, id).Exec()
  300. return
  301. }
  302. // 增加收藏数量
  303. func UpdateYanxuanSpecialarticleCollectNumIncrease(id int) (err error) {
  304. o := orm.NewOrm()
  305. sql := ``
  306. sql = `UPDATE cygx_yanxuan_special SET article_collect_num = article_collect_num +1 WHERE id = ? `
  307. _, err = o.Raw(sql, id).Exec()
  308. return
  309. }
  310. // 减少收藏数量
  311. func UpdateYanxuanSpecialarticleCollectNumReduce(id int) (err error) {
  312. o := orm.NewOrm()
  313. sql := ``
  314. sql = `UPDATE cygx_yanxuan_special SET article_collect_num = article_collect_num - 1 WHERE id = ? `
  315. _, err = o.Raw(sql, id).Exec()
  316. return
  317. }
  318. // 更新收藏数量
  319. func UpdateYanxuanSpecialarticleCollectNum(collectNum, id int) (err error) {
  320. o := orm.NewOrm()
  321. sql := ``
  322. sql = `UPDATE cygx_yanxuan_special SET article_collect_num = ? WHERE id = ? `
  323. _, err = o.Raw(sql, collectNum, id).Exec()
  324. return
  325. }