主要包含下列功能:
service => source => database
service => mock
DAO-data access object
receivable = total_profit * rate - sum(exist_receivable_list)
stranity
stranity
stranity
// 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
}
// 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)),
}
}
database.Transation(db, func(tx *gorm.DB) error {
serviceA.DoSomething()
...
serviceB.DoSomething()
...
serviceC.DoSomething()
return nil
})
stranity
reseller
customers
投顧
reseller
tony
付款 100,000
AUM XXX 10%
AUM XXX 6%
AUM XXX 4%
付款 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
付款 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
付款 100,000
分潤10,000
AUM XXX 10%
-10%
AUM XXX 6%
-2%
AUM XXX 4%
往下分潤: (6-10)%
實拿10,000
實拿0
實拿0
付款 100,000
分潤10,000
AUM XXX 10%
-5%
AUM XXX 10%
is_end_user
往下分潤: (10-5)%
實拿5,000
實拿5,000
Mr.J
QI
付款 100,000
分潤10,000
AUM XXX 10%
-5%
AUM XXX 10%
is_end_user
fixed 2,000
實拿8,000
實拿2,000
Mr.J
QI
crond
event service
V1 | V2 | |
---|---|---|
獲利 | 算應收前撈 accdv2 算出來的 並記錄在 receivable ledger 內 |
算應收前撈 accdv2 算出來的 紀錄在獨立 table |
應收 |
profit*30% |
可擴充的 recivable method - profit * rate - fixed amount |
折讓 | 手動使用折價券 取消使用折價券 一鍵折讓 |
自動化一鍵折讓 |
付款 (行政面) |
先開好發票(某些人指定) 客戶匯款 grace 查帳 通知 vivian 已匯款 預覽分潤結果 付款沖銷並將分潤分給 root agent |
開好銷貨單 出帳單給終端使用者與經銷商 使用者付款給經銷商 經銷商付款給策略無限 收到經銷商匯款完成(虛擬帳戶) 自動分潤 |
分潤 | 一層一層 agent 慢慢分 | 在付款的時候自動分完 |
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
}
投顧合約