cygx_yanxuan_special.go 13 KB

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