product_interior.go 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 CygxProductInterior struct {
  8. ProductInteriorId int `orm:"column(product_interior_id);pk"`
  9. ColumnName string `description:"栏目名称"`
  10. Title string `description:"标题"`
  11. PublishTime time.Time `description:"发布日期"`
  12. CreateTime time.Time `description:"创建时间"`
  13. ModifyTime time.Time `description:"更新时间"`
  14. Status int `description:"0:未发布,1:已发布"`
  15. Body string `description:"内容"`
  16. IsCancel int `description:"是否取消,1是,0否"`
  17. VisibleRange int `description:"设置可见范围1全部,0内部"`
  18. Abstract string `description:"摘要"`
  19. Department string `description:"作者"`
  20. AdminId int `description:"管理员ID"`
  21. }
  22. type AddProductInteriorReq struct {
  23. ProductInteriorId int `description:"ID"`
  24. DoType int `description:"操作类型 0,保存 、1,发布"`
  25. ColumnName string `description:"栏目名称"`
  26. Title string `description:"标题"`
  27. Abstract string `description:"摘要"`
  28. Department string `description:"作者"`
  29. Body string `description:"内容"`
  30. PublishTime string `description:"发布日期"`
  31. }
  32. type ProductInteriorIdReq struct {
  33. ProductInteriorId int `description:"ID"`
  34. }
  35. // 添加
  36. func AddProductInterior(item *CygxProductInterior) (err error) {
  37. o := orm.NewOrm()
  38. _, err = o.Insert(item)
  39. return
  40. }
  41. // 修改
  42. func UpdateProductInterior(item *CygxProductInterior) (err error) {
  43. to := orm.NewOrm()
  44. updateParams := make(map[string]interface{})
  45. updateParams["PublishTime"] = item.PublishTime
  46. updateParams["ModifyTime"] = item.ModifyTime
  47. updateParams["ColumnName"] = item.ColumnName
  48. updateParams["Title"] = item.Title
  49. updateParams["Status"] = item.Status
  50. updateParams["Body"] = item.Body
  51. updateParams["IsCancel"] = item.IsCancel
  52. updateParams["VisibleRange"] = item.VisibleRange
  53. updateParams["Abstract"] = item.Abstract
  54. updateParams["Department"] = item.Department
  55. ptrStructOrTableName := "cygx_product_interior"
  56. whereParam := map[string]interface{}{"product_interior_id": item.ProductInteriorId}
  57. qs := to.QueryTable(ptrStructOrTableName)
  58. for expr, exprV := range whereParam {
  59. qs = qs.Filter(expr, exprV)
  60. }
  61. _, err = qs.Update(updateParams)
  62. return
  63. }
  64. type GetCygxProductInteriorResp struct {
  65. Paging *paging.PagingItem `description:"分页数据"`
  66. List []*CygxProductInteriorResp
  67. }
  68. type CygxProductInteriorResp struct {
  69. ProductInteriorId int `description:"ID"`
  70. PublishTime string `description:"发布日期"`
  71. CreateTime string `description:"创建时间"`
  72. ModifyTime string `description:"更新时间"`
  73. Title string `description:"标题"`
  74. ColumnName string `description:"栏目名称"`
  75. Body string `description:"内容"`
  76. BodySlice []*ProductInteriorUrlResp `description:"内容切片"`
  77. IsCancel int `description:"是否取消,1是,0否"`
  78. VisibleRange int `description:"设置可见范围1全部,0内部"`
  79. Abstract string `description:"摘要"`
  80. Department string `description:"作者"`
  81. Pv int `description:"PV"`
  82. ShareImg string `description:"分享图片"`
  83. }
  84. type ProductInteriorUrlResp struct {
  85. ChartPermissionId int `description:"行业id"`
  86. SourceId int `description:"资源ID"`
  87. Type int `description:"类型:1普通文本,2:文章、3:活动、4:产业"`
  88. Body string `description:"内容"`
  89. }
  90. // 获取数量
  91. func GetCygxProductInteriorCount(condition string, pars []interface{}) (count int, err error) {
  92. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_product_interior as art WHERE 1= 1 `
  93. if condition != "" {
  94. sqlCount += condition
  95. }
  96. o := orm.NewOrm()
  97. err = o.Raw(sqlCount, pars).QueryRow(&count)
  98. return
  99. }
  100. // 列表
  101. func GetCygxProductInteriorList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxProductInteriorResp, err error) {
  102. o := orm.NewOrm()
  103. sql := `SELECT * FROM cygx_product_interior as art WHERE 1= 1 `
  104. if condition != "" {
  105. sql += condition
  106. }
  107. sql += ` LIMIT ?,? `
  108. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  109. return
  110. }
  111. type GetCygxProductInteriorDetailResp struct {
  112. Detail *CygxProductInteriorResp
  113. HasPermission int `description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,已提交过申请,4:无该行业权限,未提交过申请,5:潜在客户,未提交过申请,6:潜在客户,已提交过申请"`
  114. IsShow bool `description:"是否展示"`
  115. Disclaimers string `description:"免责声明"`
  116. }
  117. // 通过ID获取详情
  118. func GetCygxProductInteriorDetail(productInteriorId int) (item *CygxProductInteriorResp, err error) {
  119. o := orm.NewOrm()
  120. sql := `SELECT * FROM cygx_product_interior WHERE product_interior_id=? AND status = 1 `
  121. err = o.Raw(sql, productInteriorId).QueryRow(&item)
  122. return
  123. }
  124. // 删除数据
  125. func DeleteProductInterior(productInteriorId int) (err error) {
  126. o := orm.NewOrm()
  127. sql := ` DELETE FROM cygx_product_interior WHERE product_interior_id = ?`
  128. _, err = o.Raw(sql, productInteriorId).Exec()
  129. return
  130. }
  131. // 修改是否展示
  132. func EditProductInteriorStatus(status, isCancel, productInteriorId int) (err error) {
  133. o := orm.NewOrm()
  134. sql := `UPDATE cygx_product_interior SET status=?,is_cancel = ? , modify_time=NOW() WHERE product_interior_id=? `
  135. _, err = o.Raw(sql, status, isCancel, productInteriorId).Exec()
  136. return
  137. }
  138. // 修改可见范围
  139. func ProductInteriorVisibleRange(visibleRange, productInteriorId int) (err error) {
  140. o := orm.NewOrm()
  141. sql := `UPDATE cygx_product_interior SET visible_range=?, modify_time=NOW() WHERE product_interior_id=? `
  142. _, err = o.Raw(sql, visibleRange, productInteriorId).Exec()
  143. return
  144. }