product_interior.go 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. }
  83. type ProductInteriorUrlResp struct {
  84. ChartPermissionId int `description:"行业id"`
  85. SourceId int `description:"资源ID"`
  86. Type int `description:"类型:1普通文本,2:文章、3:活动、4:产业"`
  87. Body string `description:"内容"`
  88. }
  89. // 获取数量
  90. func GetCygxProductInteriorCount(condition string, pars []interface{}) (count int, err error) {
  91. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_product_interior as art WHERE 1= 1 `
  92. if condition != "" {
  93. sqlCount += condition
  94. }
  95. o := orm.NewOrm()
  96. err = o.Raw(sqlCount, pars).QueryRow(&count)
  97. return
  98. }
  99. // 列表
  100. func GetCygxProductInteriorList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxProductInteriorResp, err error) {
  101. o := orm.NewOrm()
  102. sql := `SELECT * FROM cygx_product_interior as art WHERE 1= 1 `
  103. if condition != "" {
  104. sql += condition
  105. }
  106. sql += ` LIMIT ?,? `
  107. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  108. return
  109. }
  110. type GetCygxProductInteriorDetailResp struct {
  111. Detail *CygxProductInteriorResp
  112. HasPermission int `description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,已提交过申请,4:无该行业权限,未提交过申请,5:潜在客户,未提交过申请,6:潜在客户,已提交过申请"`
  113. IsShow bool `description:"是否展示"`
  114. Disclaimers string `description:"免责声明"`
  115. }
  116. // 通过ID获取详情
  117. func GetCygxProductInteriorDetail(productInteriorId int) (item *CygxProductInteriorResp, err error) {
  118. o := orm.NewOrm()
  119. sql := `SELECT * FROM cygx_product_interior WHERE product_interior_id=? AND status = 1 `
  120. err = o.Raw(sql, productInteriorId).QueryRow(&item)
  121. return
  122. }
  123. // 删除数据
  124. func DeleteProductInterior(productInteriorId int) (err error) {
  125. o := orm.NewOrm()
  126. sql := ` DELETE FROM cygx_product_interior WHERE product_interior_id = ?`
  127. _, err = o.Raw(sql, productInteriorId).Exec()
  128. return
  129. }
  130. // 修改是否展示
  131. func EditProductInteriorStatus(status, isCancel, productInteriorId int) (err error) {
  132. o := orm.NewOrm()
  133. sql := `UPDATE cygx_product_interior SET status=?,is_cancel = ? , modify_time=NOW() WHERE product_interior_id=? `
  134. _, err = o.Raw(sql, status, isCancel, productInteriorId).Exec()
  135. return
  136. }
  137. // 修改可见范围
  138. func ProductInteriorVisibleRange(visibleRange, productInteriorId int) (err error) {
  139. o := orm.NewOrm()
  140. sql := `UPDATE cygx_product_interior SET visible_range=?, modify_time=NOW() WHERE product_interior_id=? `
  141. _, err = o.Raw(sql, visibleRange, productInteriorId).Exec()
  142. return
  143. }