reason.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/admin/main/manager/model"
  5. )
  6. // AddCateSecExt .
  7. func (d *Dao) AddCateSecExt(c context.Context, e *model.CateSecExt) (err error) {
  8. str := "INSERT INTO manager_reason_catesecext (bid,name,type) VALUES (?,?,?) ON DUPLICATE KEY UPDATE bid=values(bid),name=values(name),type=values(type)"
  9. return d.db.Exec(str, e.BusinessID, e.Name, e.Type).Error
  10. }
  11. // UpdateCateSecExt .
  12. func (d *Dao) UpdateCateSecExt(c context.Context, e *model.CateSecExt) (err error) {
  13. return d.db.Table("manager_reason_catesecext").Where("id = ?", e.ID).Update("name", e.Name).Error
  14. }
  15. // BanCateSecExt .
  16. func (d *Dao) BanCateSecExt(c context.Context, e *model.CateSecExt) (err error) {
  17. return d.db.Table("manager_reason_catesecext").Where("id = ?", e.ID).Update("state", e.State).Error
  18. }
  19. // AddAssociation .
  20. func (d *Dao) AddAssociation(c context.Context, e *model.Association) (err error) {
  21. return d.db.Table("manager_reason_association").Create(&e).Error
  22. }
  23. // UpdateAssociation .
  24. func (d *Dao) UpdateAssociation(c context.Context, e *model.Association) (err error) {
  25. return d.db.Table("manager_reason_association").Where("id = ?", e.ID).Updates(
  26. map[string]interface{}{
  27. "rid": e.RoleID,
  28. "cid": e.CategoryID,
  29. "sids": e.SecondIDs,
  30. }).Error
  31. }
  32. // BanAssociation .
  33. func (d *Dao) BanAssociation(c context.Context, e *model.Association) (err error) {
  34. return d.db.Table("manager_reason_association").Where("id = ?", e.ID).Update("state", e.State).Error
  35. }
  36. // AddReason .
  37. func (d *Dao) AddReason(c context.Context, e *model.Reason) (err error) {
  38. return d.db.Table("manager_reason").Create(e).Error
  39. }
  40. // UpdateReason .
  41. func (d *Dao) UpdateReason(c context.Context, e *model.Reason) (err error) {
  42. return d.db.Table("manager_reason").Where("id = ?", e.ID).
  43. Updates(map[string]interface{}{
  44. "rid": e.RoleID,
  45. "cid": e.CategoryID,
  46. "sid": e.SecondID,
  47. "state": e.State,
  48. "common": e.Common,
  49. "uid": e.UID,
  50. "description": e.Description,
  51. "weight": e.Weight,
  52. "flag": e.Flag,
  53. "lid": e.LinkID,
  54. "type_id": e.TypeID,
  55. "tid": e.TagID,
  56. }).Error
  57. }
  58. // ReasonList .
  59. func (d *Dao) ReasonList(c context.Context, e *model.SearchReasonParams) (res []*model.Reason, err error) {
  60. db := d.db.Table("manager_reason")
  61. if e.BusinessID != -1 {
  62. db = db.Where("bid = ?", e.BusinessID)
  63. }
  64. if e.KeyWord != "" {
  65. db = db.Where("description LIKE ?", "%"+e.KeyWord+"%")
  66. }
  67. if e.RoleID != 0 {
  68. db = db.Where("rid = ?", e.RoleID)
  69. }
  70. if e.CategoryID != 0 {
  71. db = db.Where("cid = ?", e.CategoryID)
  72. }
  73. if e.SecondID != 0 {
  74. db = db.Where("sid = ?", e.SecondID)
  75. }
  76. if e.State != -1 {
  77. db = db.Where("state = ?", e.State)
  78. }
  79. if e.UName != "" {
  80. db = db.Where("uid = ?", e.UID)
  81. }
  82. if e.Order != "" {
  83. db = db.Order(e.Order+" "+e.Sort, true)
  84. }
  85. err = db.Find(&res).Error
  86. return
  87. }
  88. // CateSecByIDs .
  89. func (d *Dao) CateSecByIDs(c context.Context, ids []int64) (res map[int64]string, err error) {
  90. r := []*model.CateSecExt{}
  91. res = make(map[int64]string)
  92. if err = d.db.Table("manager_reason_catesecext").Where("id IN (?)", ids).Find(&r).Error; err != nil {
  93. return
  94. }
  95. for _, cn := range r {
  96. res[cn.ID] = cn.Name
  97. }
  98. return
  99. }
  100. // BatchUpdateReasonState .
  101. func (d *Dao) BatchUpdateReasonState(c context.Context, b *model.BatchUpdateReasonState) (err error) {
  102. return d.db.Table("manager_reason").Where("id IN (?)", b.IDs).Update("state", b.State).Error
  103. }
  104. // CateSecExtList .
  105. func (d *Dao) CateSecExtList(c context.Context, e *model.CateSecExt) (res []*model.CateSecExt, err error) {
  106. // Display all record
  107. db := d.db.Table("manager_reason_catesecext").Where("bid = ? and type = ?", e.BusinessID, e.Type)
  108. if e.State != -1 {
  109. db = db.Where("state = ?", e.State)
  110. }
  111. err = db.Find(&res).Error
  112. return
  113. }
  114. // CateSecList .
  115. func (d *Dao) CateSecList(c context.Context, bid int64) (res []*model.CateSecExt, err error) {
  116. err = d.db.Table("manager_reason_catesecext").Where("bid = ?", bid).Find(&res).Error
  117. return
  118. }
  119. // AssociationList .
  120. func (d *Dao) AssociationList(c context.Context, state int64, bid int64) (res []*model.Association, err error) {
  121. db := d.db.Table("manager_reason_association").Where("bid = ?", bid)
  122. if state != -1 {
  123. db = db.Where("state = ?", state)
  124. }
  125. err = db.Find(&res).Error
  126. return
  127. }