123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- package lock
- /**
- 用户消费接口
- */
- type Cost interface {
- Deduction() //扣费(剩余量|账户余额)
- Before() bool
- After()
- GetData() (interface{}, int, error)
- }
- type LeftNumCost struct {
- AppID string
- ProductID int
- LeftNum int
- ProductType int
- DataNumLimitOneTimes int
- GetData1 func() (interface{}, int, error)
- }
- type AccountBalanceCost struct {
- AppID string
- ProductID int
- AccountBalance int
- }
- func (l *LeftNumCost) Deduction() {
- }
- func (l *LeftNumCost) Before() bool {
- switch l.ProductType {
- case 0:
- //按次扣费的产品-判断left_num
- if l.LeftNum == 0 {
- return false
- }
- case 1:
- //按条扣费的产品-判断单次调用的limit
- if l.LeftNum < l.DataNumLimitOneTimes {
- return false
- }
- }
- return true
- }
- func (l *LeftNumCost) GetData() (interface{}, int, error) {
- return l.GetData1()
- }
- func (l *LeftNumCost) After() {
- switch l.ProductType {
- case 0:
- case 1:
- }
- }
- func (a *AccountBalanceCost) Deduction() {
- }
- func (a *AccountBalanceCost) Before() bool {
- return false
- }
- func (a *AccountBalanceCost) After() {
- }
|