cygx_yanxuan_special.go 12 KB

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