platform.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/admin/main/vip/model"
  5. "go-common/library/ecode"
  6. )
  7. const (
  8. _vipConfPlatform = "vip_platform_config"
  9. )
  10. // PlatformAll .
  11. func (d *Dao) PlatformAll(c context.Context, order string) (res []*model.ConfPlatform, err error) {
  12. db := d.vip.Table(_vipConfPlatform)
  13. if err := db.Where("is_del=0").Order("id " + order).Find(&res).Error; err != nil {
  14. return nil, err
  15. }
  16. return
  17. }
  18. // PlatformByID vip platform config by id.
  19. func (d *Dao) PlatformByID(c context.Context, id int64) (re *model.ConfPlatform, err error) {
  20. re = &model.ConfPlatform{}
  21. if err := d.vip.Table(_vipConfPlatform).Where("id=?", id).First(re).Error; err != nil {
  22. if err == ecode.NothingFound {
  23. err = nil
  24. }
  25. return nil, err
  26. }
  27. return
  28. }
  29. // PlatformSave .
  30. func (d *Dao) PlatformSave(c context.Context, arg *model.ConfPlatform) (eff int64, err error) {
  31. db := d.vip.Table(_vipConfPlatform).Omit("ctime").Save(arg)
  32. if err = db.Error; err != nil {
  33. return
  34. }
  35. eff = db.RowsAffected
  36. return
  37. }
  38. // PlatformEnable .
  39. // func (d *Dao) PlatformEnable(c context.Context, arg *model.ConfPlatform) (eff int64, err error) {
  40. // isDel := map[string]interface{}{
  41. // "is_del": arg.IsDel,
  42. // "operator": arg.Operator,
  43. // }
  44. // db := d.vip.Table(_vipConfPlatform).Where("id=?", arg.ID).Updates(isDel)
  45. // if err = db.Error; err != nil {
  46. // return
  47. // }
  48. // eff = db.RowsAffected
  49. // return
  50. // }
  51. // PlatformDel delete vip platform config by id.
  52. func (d *Dao) PlatformDel(c context.Context, id int64, operator string) (eff int64, err error) {
  53. isDel := map[string]interface{}{
  54. "is_del": 1,
  55. "operator": operator,
  56. }
  57. db := d.vip.Table(_vipConfPlatform).Where("id=?", id).Updates(isDel)
  58. if err = db.Error; err != nil {
  59. return
  60. }
  61. eff = db.RowsAffected
  62. return
  63. }
  64. // PlatformTypes .
  65. func (d *Dao) PlatformTypes(c context.Context) (res []*model.TypePlatform, err error) {
  66. db := d.vip.Table(_vipConfPlatform)
  67. if err := db.Select("id, platform_name").Where("is_del=0").Order("id").Find(&res).Error; err != nil {
  68. return nil, err
  69. }
  70. return
  71. }