cygx_yanxuan_special.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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. }
  64. type CygxYanxuanSpecialDetailResp struct {
  65. Detail *CygxYanxuanSpecialResp
  66. HasPermission int `description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,已提交过申请,4:无该行业权限,未提交过申请,5:潜在客户,未提交过申请,6:潜在客户,已提交过申请"`
  67. PopupPriceMsg string `description:"价格弹窗信息"`
  68. IsShowWxPay bool `description:"是否展示微信支付"`
  69. IsCompanyApply bool `description:"机构是否申请过试用"`
  70. IsNeedBusinessCard bool `description:"是否需要上传名片"`
  71. GoodsList []*order.CygxGoodsResp `description:"商品信息"`
  72. }
  73. type CygxYanxuanSpecialResp struct {
  74. CygxYanxuanSpecialItem
  75. Docs []Doc
  76. CompanyTags []string
  77. IndustryTags []string
  78. HasPermission int `description:"1:正常展示,2:不展示"`
  79. IsApprovalAdmin bool // 是否是审批人员
  80. ShareImg string `description:"分享图片"`
  81. IsFollowAuthor bool // 是否关注作者
  82. }
  83. type Doc struct {
  84. DocName string
  85. DocSuffix string
  86. DocUrl string
  87. DocIcon string
  88. }
  89. type DocReq struct {
  90. DocName string
  91. DocSuffix string
  92. DocUrl string
  93. }
  94. func GetYanxuanSpecialList(userId int, condition string, pars []interface{}, startSize, pageSize int) (items []*CygxYanxuanSpecialItem, err error) {
  95. o := orm.NewOrm()
  96. sql := ``
  97. 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,
  98. ( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac WHERE ac.yanxuan_special_id = a.id ) AS collect_num,
  99. ( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac WHERE ac.yanxuan_special_id = a.id AND user_id = ? ) AS my_collect_num
  100. FROM cygx_yanxuan_special AS a
  101. JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
  102. WHERE 1=1 `
  103. if condition != "" {
  104. sql += condition
  105. }
  106. sql += `ORDER BY a.publish_time DESC `
  107. if startSize+pageSize > 0 {
  108. sql += ` LIMIT ?,? `
  109. _, err = o.Raw(sql, userId, pars, startSize, pageSize).QueryRows(&items)
  110. } else {
  111. _, err = o.Raw(sql, userId, pars).QueryRows(&items)
  112. }
  113. return
  114. }
  115. type EnableCygxYanxuanSpecialReq struct {
  116. Id int // 文章id
  117. Status int // 1通过2驳回
  118. Reason string //理由
  119. }
  120. func EnableYanxuanSpecial(id, status int, reason, adminName string) (err error) {
  121. o := orm.NewOrm()
  122. sql := ``
  123. sql = `UPDATE cygx_yanxuan_special SET status=?,reason=?,admin_name = ? , publish_time=NOW() WHERE id = ? `
  124. _, err = o.Raw(sql, status, reason, adminName, id).Exec()
  125. return
  126. }
  127. type SpecialListResp struct {
  128. IsAuthor bool `description:"是否开通了研选专栏"`
  129. IsImproveInformation bool `description:"作者信息是否完善"`
  130. Paging *paging.PagingItem `description:"分页数据"`
  131. List []*CygxYanxuanSpecialItem
  132. }
  133. func GetYanxuanSpecialById(specialId, userId int) (item *CygxYanxuanSpecialItem, err error) {
  134. o := orm.NewOrm()
  135. sql := ``
  136. sql = `SELECT a.*,b.id AS special_column_id,b.bg_img,b.head_img,b.introduction,b.label,b.mobile,
  137. b.nick_name,b.real_name,b.special_name,
  138. ( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac WHERE ac.yanxuan_special_id = a.id ) AS collect_num,
  139. ( SELECT count( 1 ) FROM cygx_yanxuan_special_collect AS ac WHERE ac.yanxuan_special_id = a.id AND user_id = ? ) AS my_collect_num
  140. FROM cygx_yanxuan_special AS a
  141. JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
  142. WHERE a.id=? `
  143. err = o.Raw(sql, userId, specialId).QueryRow(&item)
  144. return
  145. }
  146. func GetYanxuanSpecialListBycondition(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxYanxuanSpecialItem, err error) {
  147. o := orm.NewOrm()
  148. sql := `SELECT a.* FROM cygx_yanxuan_special AS a WHERE 1=1 `
  149. if condition != "" {
  150. sql += condition
  151. }
  152. if startSize+pageSize > 0 {
  153. sql += ` LIMIT ?,? `
  154. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  155. } else {
  156. _, err = o.Raw(sql, pars).QueryRows(&items)
  157. }
  158. return
  159. }
  160. type CygxYanxuanSpecialReq struct {
  161. Id int `orm:"column(id);pk"`
  162. Content string // 内容
  163. IndustryTags []string // 行业标签
  164. CompanyTags []string // 公司标签
  165. DoType int // 1保存 2发布
  166. ImgUrl []string // 图片链接
  167. Docs []Doc // 文档链接
  168. Title string // 标题
  169. Type int // 类型1:笔记,2:观点
  170. IsApprovalPersonnel bool // 是否是审批人员操作
  171. }
  172. func AddCygxYanxuanSpecial(item *CygxYanxuanSpecial) (lastId int64, err error) {
  173. o := orm.NewOrm()
  174. lastId, err = o.Insert(item)
  175. return
  176. }
  177. func UpdateYanxuanSpecial(item *CygxYanxuanSpecial) (err error) {
  178. o := orm.NewOrm()
  179. sql := ``
  180. sql = `UPDATE cygx_yanxuan_special SET title=?,content=?,company_tags=?,industry_tags=?,img_url=?,doc_url=?,type=?,status=?,
  181. modify_time=NOW(),publish_time=NOW(),admin_name = ? WHERE id = ? `
  182. _, 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()
  183. return
  184. }
  185. func GetYanxuanSpecialBySpecialId(specialId int) (item *CygxYanxuanSpecialItem, err error) {
  186. o := orm.NewOrm()
  187. sql := ``
  188. sql = `SELECT a.*
  189. FROM cygx_yanxuan_special AS a
  190. WHERE a.id=? `
  191. err = o.Raw(sql, specialId).QueryRow(&item)
  192. return
  193. }
  194. func GetYanxuanSpecialIndustry(keyword string) (IndustryNames []string, err error) {
  195. o := orm.NewOrm()
  196. sql := ``
  197. if keyword == "" {
  198. sql = `SELECT industry_name FROM cygx_yanxuan_special_industry `
  199. } else {
  200. sql = `SELECT industry_name FROM cygx_yanxuan_special_industry WHERE industry_name LIKE '%` + keyword + `%' `
  201. }
  202. _, err = o.Raw(sql).QueryRows(&IndustryNames)
  203. return
  204. }
  205. type CancelPublishCygxYanxuanSpecialReq struct {
  206. Id int // 文章id
  207. }
  208. func CancelPublishYanxuanSpecial(id int) (err error) {
  209. o := orm.NewOrm()
  210. sql := ``
  211. sql = `UPDATE cygx_yanxuan_special SET status=1,publish_time=NOW(),modify_time=NOW() WHERE id = ? `
  212. _, err = o.Raw(sql, id).Exec()
  213. return
  214. }
  215. type DelCygxYanxuanSpecialReq struct {
  216. Id int // 文章id
  217. }
  218. func DelYanxuanSpecial(id int) (err error) {
  219. o := orm.NewOrm()
  220. sql := ``
  221. sql = `DELETE FROM cygx_yanxuan_special WHERE id = ? `
  222. _, err = o.Raw(sql, id).Exec()
  223. return
  224. }
  225. type CygxYanxuanSpecialCheckReq struct {
  226. Content string // 内容
  227. ImgUrl []string // 图片
  228. }
  229. func GetYanxuanSpecialFollowUserById(specialId int) (items []int, err error) {
  230. o := orm.NewOrm()
  231. sql := ``
  232. sql = `SELECT b.user_id
  233. FROM cygx_yanxuan_special AS a
  234. JOIN cygx_yanxuan_special_follow AS b ON a.user_id = b.follow_user_id
  235. WHERE a.id=? `
  236. _, err = o.Raw(sql, specialId).QueryRows(&items)
  237. return
  238. }
  239. func GetYanxuanSpecialItemById(specialId int) (item *CygxYanxuanSpecialItem, err error) {
  240. o := orm.NewOrm()
  241. sql := ``
  242. sql = `SELECT a.*,b.bg_img,b.head_img,b.introduction,b.label,b.mobile,
  243. b.nick_name,b.real_name,b.special_name
  244. FROM cygx_yanxuan_special AS a
  245. JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
  246. WHERE a.id=? `
  247. err = o.Raw(sql, specialId).QueryRow(&item)
  248. return
  249. }
  250. // 获取数量
  251. func GetCygxYanxuanSpecialCount(condition string, pars []interface{}) (count int, err error) {
  252. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_yanxuan_special as a WHERE 1= 1 `
  253. if condition != "" {
  254. sqlCount += condition
  255. }
  256. o := orm.NewOrm()
  257. err = o.Raw(sqlCount, pars).QueryRow(&count)
  258. return
  259. }
  260. // UpdateYanxuanSpecialPv 修改研选专栏的阅读Pv
  261. func UpdateYanxuanSpecialPv(id int) (err error) {
  262. o := orm.NewOrm()
  263. sql := `UPDATE cygx_yanxuan_special SET pv=pv+1 WHERE id = ? `
  264. _, err = o.Raw(sql, id).Exec()
  265. return
  266. }
  267. // UpdateYanxuanSpecialUv 修改研选专栏的阅读Uv
  268. func UpdateYanxuanSpecialUv(id int) (err error) {
  269. o := orm.NewOrm()
  270. sql := `UPDATE cygx_yanxuan_special SET uv=uv+1 WHERE id = ? `
  271. _, err = o.Raw(sql, id).Exec()
  272. return
  273. }
  274. // 增加收藏数量
  275. func UpdateYanxuanSpecialarticleCollectNumIncrease(id int) (err error) {
  276. o := orm.NewOrm()
  277. sql := ``
  278. sql = `UPDATE cygx_yanxuan_special SET article_collect_num = article_collect_num +1 WHERE id = ? `
  279. _, err = o.Raw(sql, id).Exec()
  280. return
  281. }
  282. // 减少收藏数量
  283. func UpdateYanxuanSpecialarticleCollectNumReduce(id int) (err error) {
  284. o := orm.NewOrm()
  285. sql := ``
  286. sql = `UPDATE cygx_yanxuan_special SET article_collect_num = article_collect_num - 1 WHERE id = ? `
  287. _, err = o.Raw(sql, id).Exec()
  288. return
  289. }
  290. // 更新收藏数量
  291. func UpdateYanxuanSpecialarticleCollectNum(collectNum, id int) (err error) {
  292. o := orm.NewOrm()
  293. sql := ``
  294. sql = `UPDATE cygx_yanxuan_special SET article_collect_num = ? WHERE id = ? `
  295. _, err = o.Raw(sql, collectNum, id).Exec()
  296. return
  297. }