bcoin.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package dao
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/service/main/vip/model"
  6. "go-common/library/database/sql"
  7. "github.com/pkg/errors"
  8. )
  9. const (
  10. _vipUserBcoinSalaryList = "SELECT `id`,`mid`,`status`,`give_now_status`,`payday`,`amount`,`memo`,`ctime`,`mtime` FROM `vip_user_bcoin_salary` WHERE `mid` = ? AND `payday` > ? AND `payday` < ?;"
  11. _SelLastBCoinByMid = "SELECT id,mid,`status`,give_now_status,payday,amount,memo,ctime,mtime from vip_user_bcoin_salary WHERE mid = ? ORDER BY payday DESC"
  12. _InsertVipBcoinSalary = "INSERT INTO vip_user_bcoin_salary(mid,status,give_now_status,payday,amount,memo) VALUES(?,?,?,?,?,?)"
  13. _delBcoinSalary = "DELETE FROM vip_bcoin_salary WHERE mid=? AND month>=?"
  14. )
  15. //BcoinSalaryList vip user bcoin salary list.
  16. func (d *Dao) BcoinSalaryList(c context.Context, mid int64, start, end time.Time) (res []*model.VipBcoinSalary, err error) {
  17. var rows *sql.Rows
  18. if rows, err = d.db.Query(c, _vipUserBcoinSalaryList, mid, start, end); err != nil {
  19. err = errors.WithStack(err)
  20. d.errProm.Incr("query_db")
  21. return
  22. }
  23. defer rows.Close()
  24. for rows.Next() {
  25. r := new(model.VipBcoinSalary)
  26. if err = rows.Scan(&r.ID, &r.Mid, &r.Status, &r.GiveNowStatus, &r.Month, &r.Amount, &r.Memo, &r.Ctime, &r.Mtime); err != nil {
  27. err = errors.WithStack(err)
  28. d.errProm.Incr("row_scan_db")
  29. res = nil
  30. return
  31. }
  32. res = append(res, r)
  33. }
  34. err = rows.Err()
  35. return
  36. }
  37. //SelLastBcoin sel last bcoin by mid.
  38. func (d *Dao) SelLastBcoin(c context.Context, mid int64) (r *model.VipBcoinSalary, err error) {
  39. row := d.db.QueryRow(c, _SelLastBCoinByMid, mid)
  40. r = new(model.VipBcoinSalary)
  41. if err = row.Scan(&r.ID, &r.Mid, &r.Status, &r.GiveNowStatus, &r.Amount, &r.Memo, &r.Ctime, &r.Mtime); err != nil {
  42. if err == sql.ErrNoRows {
  43. err = nil
  44. r = nil
  45. } else {
  46. err = errors.WithStack(err)
  47. }
  48. }
  49. return
  50. }
  51. //InsertVipBcoinSalary insert vip bcoin salary
  52. func (d *Dao) InsertVipBcoinSalary(c context.Context, r *model.VipBcoinSalary) (err error) {
  53. if _, err = d.db.Exec(c, _InsertVipBcoinSalary, &r.Mid, &r.Status, &r.GiveNowStatus, &r.PayDay, &r.Amount, &r.Memo); err != nil {
  54. err = errors.WithStack(err)
  55. }
  56. return
  57. }
  58. //OldTxDelBcoinSalary del bcoin salary
  59. func (d *Dao) OldTxDelBcoinSalary(tx *sql.Tx, mid int64, month time.Time) (err error) {
  60. if _, err = tx.Exec(_delBcoinSalary, mid, month); err != nil {
  61. err = errors.WithStack(err)
  62. }
  63. return
  64. }