vip.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. "go-common/library/log"
  8. "go-common/library/time"
  9. )
  10. // const .
  11. const (
  12. _selVipUserInfoByMid = "SELECT id,mid,vip_type,vip_pay_type,vip_status,vip_start_time,vip_overdue_time,annual_vip_overdue_time,ctime,mtime,vip_recent_time FROM vip_user_info WHERE mid = ?"
  13. _UpdateVipUserInfoByID = "UPDATE vip_user_info SET vip_type=?,vip_status=?,vip_overdue_time=?,annual_vip_overdue_time=?,vip_recent_time=? WHERE id=?"
  14. _InsertVipChangeHistory = "INSERT INTO vip_user_change_history(mid,change_type,change_time,days,operator_id,relation_id,batch_id,remark) VALUES(?,?,?,?,?,?,?,?)"
  15. _DelBcoinSalary = "DELETE FROM vip_user_bcoin_salary WHERE status = 0 AND mid = ? and payday>=?"
  16. )
  17. // DelBcoinSalary del bacoin salary
  18. func (d *Dao) DelBcoinSalary(tx *sql.Tx, mid int64, month time.Time) (err error) {
  19. if _, err = tx.Exec(_DelBcoinSalary, mid, month); err != nil {
  20. log.Error("InertVipBcoinSalary.exec(mid:%v,month:%v) error(%+v)", mid, month, err)
  21. }
  22. return
  23. }
  24. // SelVipUserInfo select user info by mid
  25. func (d *Dao) SelVipUserInfo(c context.Context, mid int64) (r *model.VipUserInfo, err error) {
  26. var row = d.db.QueryRow(c, _selVipUserInfoByMid, mid)
  27. r = new(model.VipUserInfo)
  28. if err = row.Scan(&r.ID, &r.Mid, &r.VipType, &r.VipPayType, &r.VipStatus, &r.VipStartTime, &r.VipOverdueTime, &r.AnnualVipOverdueTime, &r.Ctime, &r.Mtime, &r.VipRecentTime); err != nil {
  29. if err == sql.ErrNoRows {
  30. r = nil
  31. err = nil
  32. } else {
  33. log.Error("row.Scan() error(%v)", err)
  34. }
  35. }
  36. return
  37. }
  38. // UpdateVipUserInfo update vip user info by id
  39. func (d *Dao) UpdateVipUserInfo(tx *sql.Tx, r *model.VipUserInfo) (a int64, err error) {
  40. var res xsql.Result
  41. if res, err = tx.Exec(_UpdateVipUserInfoByID, r.VipType, r.VipStatus, r.VipOverdueTime, r.AnnualVipOverdueTime, r.VipRecentTime, r.ID); err != nil {
  42. log.Error("UpdateVipUserInfo: db.Exec(%v) error(%v)", r, err)
  43. return
  44. }
  45. if a, err = res.RowsAffected(); err != nil {
  46. log.Error("UpdateVipUserInfo: res.RowsAffected error(%v)", err)
  47. return
  48. }
  49. return
  50. }
  51. // InsertVipChangeHistory insert vipChangeHistory
  52. func (d *Dao) InsertVipChangeHistory(tx *sql.Tx, r *model.VipChangeHistory) (id int64, err error) {
  53. var res xsql.Result
  54. if res, err = tx.Exec(_InsertVipChangeHistory, r.Mid, r.ChangeType, r.ChangeTime, r.Days, r.OperatorID, r.RelationID, r.BatchID, r.Remark); err != nil {
  55. log.Error("InsertVipChangeHistory db.Exec(%v) error(%v)", r, err)
  56. } else {
  57. if id, err = res.LastInsertId(); err != nil {
  58. log.Error("InsertVipChangeHistory LastInsertId() error(%v)", err)
  59. }
  60. }
  61. return
  62. }