billing V2.1_final_final

contents

  • v1 overview
  • v2 overview
  • changes
  • what can we learn

billing v1

biling v1

主要包含下列功能:

  • 計算客戶應收帳款
  • 優惠券:
    • 額度優惠券:固定額度用完就沒了
    • 固定百分比:將應收 30 % 減免為選填百分比
    • 現折(現金折價券):一次性折抵固定金額
  • 折讓
  • 收款
  • 退佣(分潤):
    • 兌現
    • 轉發給名下客戶
    • 付款

biling v1

biling v1

service => source => database

service => mock 

DAO-data access object

biling v1

biling v1

receivable = total_profit * rate - sum(exist_receivable_list)

biling v1

biling v1

biling v1

biling v1

biling v1

biling v1

What's wrong?

biling v1

biling v1

我想收 50% 可不可以

我想收 90% 可不可以

What's wrong?

biling v1

biling v1

biling v1

stranity

billing v1.1

biling v1.1

stranity

biling v1.1

stranity

billing v2

What's news?

What's news?

  • 客製化 % 數
  • 經銷商系統
  • 付款自動分潤
  • 自動建銷貨單

biling v2

biling v2

biling v2

// Service defines exposed apis about billing system.
type Service struct {
	dbType string
	opUser *user.User

	cashService       *CashService
	contractService   *ContractService
	couponService     *CouponService
	eventService      *EventService
	ledgerService     *LedgerService
	paymentService    *PaymentService
	receivableService *ReceivableService
	profitService     *ProfitService
}

biling v2

// NewService creates service.
func NewService(dbType string, repo *resource.Repository) *Service {
	return &Service{
		dbType:            dbType,
		cashService:       NewCashService(&dbCashSource{}),
		contractService:   NewContractService(&dbContractSource{}),
		couponService:     NewCouponService(&dbCouponSource{}),
		eventService:      NewEventService(&dbEventSource{}),
		ledgerService:     NewLedgerService(&dbLedgerSource{}),
		paymentService:    NewPaymentService(&dbPaymentSource{}),
		receivableService: NewReceivableService(&dbReceivableSource{}),
		profitService:     NewProfitService(&dbProfitSource{}, NewProfitCalculator(repo)),
	}
}
  • 客製化 % 數

biling v2

biling v2

ACID

biling v2

database.Transation(db, func(tx *gorm.DB) error {
  serviceA.DoSomething()
  ...
  serviceB.DoSomething()
  ...
  serviceC.DoSomething()
  return nil
})

經銷商系統

biling v2

stranity

reseller

customers

投顧

自動分潤

biling v2

reseller

tony

biling v2

付款 100,000

AUM XXX 10%

AUM XXX 6%

AUM XXX 4%

biling v2

付款 100,000

分潤10,000

AUM XXX 10%

-0%

AUM XXX 6%

-0%

AUM XXX 4%

往下分潤: 6%

往下分潤: 4%

實拿10,000-6,000=4,000

實拿6,000-4,000=2,000

實拿4,000

biling v2

付款 100,000

分潤10,000

AUM XXX 10%

-2%

AUM XXX 6%

-2%

AUM XXX 4%

往下分潤: (6-2)%

往下分潤: (4-2)%

實拿10,000-4,000=6,000

實拿4,000-2,000=2,000

實拿2,000

biling v2

付款 100,000

分潤10,000

AUM XXX 10%

-10%

AUM XXX 6%

-2%

AUM XXX 4%

往下分潤: (6-10)%

實拿10,000

實拿0

實拿0

biling v2

付款 100,000

分潤10,000

AUM XXX 10%

-5%

AUM XXX 10%

is_end_user

往下分潤: (10-5)%

實拿5,000

實拿5,000

Mr.J

QI

biling v2

付款 100,000

分潤10,000

AUM XXX 10%

-5%

AUM XXX 10%

is_end_user

fixed 2,000

實拿8,000

實拿2,000

Mr.J

QI

整體流程

biling v2

crond

biling v2

event service

changes

changes

V1 V2
獲利 算應收前撈 accdv2 算出來的
並記錄在 receivable ledger 內
算應收前撈 accdv2 算出來的
紀錄在獨立 table
應收
profit*30%
可擴充的 recivable method
- profit * rate
- fixed amount
折讓 手動使用折價券
取消使用折價券
一鍵折讓

自動化一鍵折讓
付款
(行政面)
先開好發票(某些人指定)
客戶匯款
grace 查帳
通知 vivian 已匯款
預覽分潤結果
付款沖銷並將分潤分給 root agent
開好銷貨單
出帳單給終端使用者與經銷商
使用者付款給經銷商
經銷商付款給策略無限
收到經銷商匯款完成(虛擬帳戶)
自動分潤
分潤 一層一層 agent 慢慢分 在付款的時候自動分完

what can we learn

適應

彈性(減少日後噁心的 patch)

adjFunc := defaultCouponAdjectFunc
if couponType == CouponQuota {
	adjFunc = s.GetQuotaCouponAdjectFunc(rates)
}
switch couponType {
case CouponQuota, CouponAmount:
	quotaUsed := s.GetCouponUsed(ledgers, coupon.ID, adjFunc)
	...
case CouponLessRate:
	...
case CouponPercent:
	return nil, errors.Wrap(app.ErrUnexpected, "TBD")
}
// GetCouponUsed return coupon usage.
func (s *Service) GetCouponUsed(ledgers []Ledger, couponID uuid.UUID,
	adjFunc func(x float64, month string) float64) float64 {
	var total float64
	for _, ledger := range ledgers {
		if ledger.Subject != SubjectDiscount.String() {
			continue
		}

		if ledger.CouponID == couponID {
			total += adjFunc(-ledger.Amount, ledger.Date)
		}
	}
	return total
}

投顧合約

billing V2.0 final_final

By Raiven Kao

billing V2.0 final_final

  • 110