interface.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package lock
  2. /**
  3. 用户消费接口
  4. */
  5. type Cost interface {
  6. Deduction() //扣费(剩余量|账户余额)
  7. Before() bool
  8. After()
  9. GetData() (interface{}, int, error)
  10. }
  11. type LeftNumCost struct {
  12. AppID string
  13. ProductID int
  14. LeftNum int
  15. ProductType int
  16. DataNumLimitOneTimes int
  17. GetData1 func() (interface{}, int, error)
  18. }
  19. type AccountBalanceCost struct {
  20. AppID string
  21. ProductID int
  22. AccountBalance int
  23. }
  24. func (l *LeftNumCost) Deduction() {
  25. }
  26. func (l *LeftNumCost) Before() bool {
  27. switch l.ProductType {
  28. case 0:
  29. //按次扣费的产品-判断left_num
  30. if l.LeftNum == 0 {
  31. return false
  32. }
  33. case 1:
  34. //按条扣费的产品-判断单次调用的limit
  35. if l.LeftNum < l.DataNumLimitOneTimes {
  36. return false
  37. }
  38. }
  39. return true
  40. }
  41. func (l *LeftNumCost) GetData() (interface{}, int, error) {
  42. return l.GetData1()
  43. }
  44. func (l *LeftNumCost) After() {
  45. switch l.ProductType {
  46. case 0:
  47. case 1:
  48. }
  49. }
  50. func (a *AccountBalanceCost) Deduction() {
  51. }
  52. func (a *AccountBalanceCost) Before() bool {
  53. return false
  54. }
  55. func (a *AccountBalanceCost) After() {
  56. }