associate_old.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package dao
  2. import (
  3. "context"
  4. xsql "database/sql"
  5. "go-common/app/service/main/vip/model"
  6. "go-common/library/database/sql"
  7. "github.com/pkg/errors"
  8. )
  9. const (
  10. _activityOrderSQL = "SELECT id,mid,order_no,product_id,months,panel_type,associate_state,ctime,mtime FROM vip_order_activity_record WHERE order_no = ?;"
  11. _updateActivityStateSQL = "UPDATE vip_order_activity_record SET associate_state =? WHERE order_no = ?;"
  12. _productBuyCountSQL = "SELECT current_count as count FROM vip_product_pay_record WHERE mid = ? AND months=? AND panel_type = ?;"
  13. )
  14. //ActivityOrder get activity order by order_no.
  15. func (d *Dao) ActivityOrder(c context.Context, orderNO string) (res *model.VipOrderActivityRecord, err error) {
  16. res = new(model.VipOrderActivityRecord)
  17. if err = d.olddb.QueryRow(c, _activityOrderSQL, orderNO).
  18. Scan(&res.ID, &res.Mid, &res.OrderNO, &res.ProductID, &res.Months, &res.PanelType, &res.AssociateState, &res.Ctime, &res.Mtime); err != nil {
  19. if err == sql.ErrNoRows {
  20. res = nil
  21. err = nil
  22. return
  23. }
  24. err = errors.Wrapf(err, "dao activity order(%s)", orderNO)
  25. }
  26. return
  27. }
  28. // UpdateActivityState update act vip grant state.
  29. func (d *Dao) UpdateActivityState(c context.Context, state int8, orderNO string) (aff int64, err error) {
  30. var res xsql.Result
  31. if res, err = d.olddb.Exec(c, _updateActivityStateSQL, state, orderNO); err != nil {
  32. err = errors.Wrapf(err, "dao update associate state(%d,%s)", state, orderNO)
  33. return
  34. }
  35. return res.RowsAffected()
  36. }
  37. // CountProductBuy get user by product count.
  38. func (d *Dao) CountProductBuy(c context.Context, mid int64, months int32, panelType string) (count int64, err error) {
  39. row := d.olddb.QueryRow(c, _productBuyCountSQL, mid, months, panelType)
  40. if err = row.Scan(&count); err != nil {
  41. if err == sql.ErrNoRows {
  42. err = nil
  43. return
  44. }
  45. err = errors.Wrapf(err, "dao update associate state(%d,%d,%s)", mid, months, panelType)
  46. }
  47. return
  48. }