interface.go 947 B

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