month.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package dao
  2. import (
  3. "context"
  4. xsql "database/sql"
  5. "go-common/app/admin/main/vip/model"
  6. "go-common/library/database/sql"
  7. "github.com/pkg/errors"
  8. )
  9. // GetMonth .
  10. func (d *Dao) GetMonth(c context.Context, id int64) (m *model.VipMonth, err error) {
  11. res := d.db.QueryRow(c, _getMonth, id)
  12. m = new(model.VipMonth)
  13. if err = res.Scan(&m.ID, &m.Month, &m.MonthType, &m.Operator, &m.Status, &m.Mtime); err != nil {
  14. if err == sql.ErrNoRows {
  15. err = nil
  16. m = nil
  17. } else {
  18. err = errors.WithStack(err)
  19. }
  20. }
  21. return
  22. }
  23. // MonthList get all month.
  24. func (d *Dao) MonthList(c context.Context) (res []*model.VipMonth, err error) {
  25. var rows *sql.Rows
  26. if rows, err = d.db.Query(c, _allMonth); err != nil {
  27. err = errors.WithStack(err)
  28. return
  29. }
  30. defer rows.Close()
  31. for rows.Next() {
  32. r := &model.VipMonth{}
  33. if err = rows.Scan(&r.ID, &r.Month, &r.MonthType, &r.Operator, &r.Status, &r.Mtime); err != nil {
  34. err = errors.WithStack(err)
  35. res = nil
  36. return
  37. }
  38. res = append(res, r)
  39. }
  40. return
  41. }
  42. // MonthEdit .
  43. func (d *Dao) MonthEdit(c context.Context, id int64, status int8, op string) (eff int64, err error) {
  44. var res xsql.Result
  45. if res, err = d.db.Exec(c, _updateMonthStatus, status, op, id); err != nil {
  46. err = errors.WithStack(err)
  47. return
  48. }
  49. if eff, err = res.RowsAffected(); err != nil {
  50. err = errors.WithStack(err)
  51. }
  52. return
  53. }
  54. // GetPrice .
  55. func (d *Dao) GetPrice(c context.Context, id int64) (r *model.VipMonthPrice, err error) {
  56. row := d.db.QueryRow(c, _monthPriceSQL, id)
  57. r = new(model.VipMonthPrice)
  58. if err = row.Scan(&r.ID, &r.MonthID, &r.MonthType, &r.Money, &r.Selected, &r.FirstDiscountMoney, &r.DiscountMoney, &r.StartTime, &r.EndTime, &r.Remark, &r.Operator); err != nil {
  59. if err == sql.ErrNoRows {
  60. err = nil
  61. r = nil
  62. } else {
  63. err = errors.WithStack(err)
  64. }
  65. }
  66. return
  67. }
  68. // PriceList .
  69. func (d *Dao) PriceList(c context.Context, mID int64) (res []*model.VipMonthPrice, err error) {
  70. var rows *sql.Rows
  71. if rows, err = d.db.Query(c, _allMonthPrice, mID); err != nil {
  72. err = errors.WithStack(err)
  73. return
  74. }
  75. defer rows.Close()
  76. for rows.Next() {
  77. r := &model.VipMonthPrice{}
  78. if err = rows.Scan(&r.ID, &r.MonthID, &r.MonthType, &r.Money, &r.Selected, &r.FirstDiscountMoney, &r.DiscountMoney, &r.StartTime, &r.EndTime, &r.Remark, &r.Operator); err != nil {
  79. err = errors.WithStack(err)
  80. res = nil
  81. return
  82. }
  83. res = append(res, r)
  84. }
  85. return
  86. }
  87. // PriceAdd .
  88. func (d *Dao) PriceAdd(c context.Context, mp *model.VipMonthPrice) (eff int64, err error) {
  89. var res xsql.Result
  90. if res, err = d.db.Exec(c, _addMonthPrice, mp.MonthID, mp.MonthType, mp.Money, mp.FirstDiscountMoney, mp.DiscountMoney, mp.StartTime, mp.EndTime, mp.Remark, mp.Operator); err != nil {
  91. err = errors.WithStack(err)
  92. return
  93. }
  94. if eff, err = res.RowsAffected(); err != nil {
  95. err = errors.WithStack(err)
  96. }
  97. return
  98. }
  99. // PriceEdit .
  100. func (d *Dao) PriceEdit(c context.Context, mp *model.VipMonthPrice) (eff int64, err error) {
  101. var res xsql.Result
  102. if res, err = d.db.Exec(c, _editMonthPrice, mp.MonthType, mp.Money, mp.FirstDiscountMoney, mp.DiscountMoney, mp.StartTime, mp.EndTime, mp.Remark, mp.Operator, mp.ID); err != nil {
  103. err = errors.WithStack(err)
  104. return
  105. }
  106. if eff, err = res.RowsAffected(); err != nil {
  107. err = errors.WithStack(err)
  108. }
  109. return
  110. }