interface.go 911 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package lock
  2. /**
  3. 用户消费接口
  4. */
  5. type Cost interface {
  6. deduction() //扣费(剩余量|账户余额)
  7. before() bool
  8. after()
  9. }
  10. type Deduction interface {
  11. }
  12. type LeftNumUserCost struct {
  13. AppID string
  14. ProductID int
  15. LeftNum int
  16. ProductType int
  17. DataNumLimitOneTimes int
  18. }
  19. type AccountBalanceUserCost struct {
  20. AppID string
  21. ProductID int
  22. AccountBalance int
  23. }
  24. func (l *LeftNumUserCost) deduction() {
  25. }
  26. func (l *LeftNumUserCost) 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 *LeftNumUserCost) after() {
  42. switch l.ProductType {
  43. case 0:
  44. case 1:
  45. }
  46. }
  47. func (a *AccountBalanceUserCost) deduction() {
  48. }