Skip to content

Commit

Permalink
Merge branch 'fix/order-fee-cal' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
sjatsh committed Jan 27, 2024
2 parents 047d8a1 + 6d16298 commit 6f3c155
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
24 changes: 17 additions & 7 deletions dao/t_order_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,27 +266,37 @@ func (d *DbDao) GetOrderAmount(accountId string, paid bool) (result map[string]d
token := tokens[v.TokenId]
couponMinPrice := minPriceFee.Div(platformFeeRatio.Add(serviceFeeRate)).Mul(decimal.NewFromInt(int64(v.Years)))
tokenMinPrice := couponMinPrice.Mul(decimal.New(1, token.Decimals)).DivRound(token.Price, token.Decimals)
fee := minPriceFee.Mul(decimal.NewFromInt(int64(v.Years))).Mul(decimal.New(1, token.Decimals)).DivRound(token.Price, token.Decimals)
minTokenFee := minPriceFee.Mul(decimal.NewFromInt(int64(v.Years))).Mul(decimal.New(1, token.Decimals)).DivRound(token.Price, token.Decimals)
if v.CouponCode == "" {
if v.USDAmount.GreaterThan(decimal.Zero) {
if v.USDAmount.GreaterThan(couponMinPrice) {
amount = amount.Mul(feeRate)
} else {
if amount.Sub(fee).GreaterThan(decimal.Zero) {
amount = amount.Sub(fee)
// Greater than 0.99$, sub 0.99$ fee
subFee := amount.Sub(minTokenFee)
if subFee.GreaterThan(decimal.Zero) {
amount = amount.Sub(minTokenFee)
} else if subFee.Equal(decimal.Zero) {
// equal 0.99$, profit is 0
amount = decimal.Zero
} else {
// old data before 0.99
// old data
amount = amount.Mul(feeRate)
}
}
} else {
if v.Amount.GreaterThan(tokenMinPrice) {
amount = amount.Mul(feeRate)
} else {
if amount.Sub(fee).GreaterThan(decimal.Zero) {
amount = amount.Sub(fee)
// Greater than 0.99$, sub 0.99$ fee
subFee := amount.Sub(minTokenFee)
if subFee.GreaterThan(decimal.Zero) {
amount = amount.Sub(minTokenFee)
} else if subFee.Equal(decimal.Zero) {
// equal 0.99$, profit is 0
amount = decimal.Zero
} else {
// old data before 0.99
// old data
amount = amount.Mul(feeRate)
}
}
Expand Down
6 changes: 2 additions & 4 deletions txtool/parent_account_payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ func (s *SubAccountTxTool) StatisticsParentAccountPayment(parentAccount string,
amount = amount.Mul(feeRate)
} else {
fee := minPriceFee.Mul(decimal.NewFromInt(int64(v.Years))).Mul(decimal.New(1, token.Decimals)).Div(token.Price).Ceil()
if amount.Sub(fee).LessThanOrEqual(decimal.Zero) {
// old data before 0.99
if amount.Sub(fee).LessThan(decimal.Zero) {
fee = amount.Mul(decimal.NewFromInt(1).Sub(feeRate))
}
amount = amount.Sub(fee)
Expand All @@ -105,8 +104,7 @@ func (s *SubAccountTxTool) StatisticsParentAccountPayment(parentAccount string,
amount = amount.Mul(feeRate)
} else {
fee := minPriceFee.Mul(decimal.NewFromInt(int64(v.Years))).Mul(decimal.New(1, token.Decimals)).Div(token.Price).Ceil()
if amount.Sub(fee).LessThanOrEqual(decimal.Zero) {
// old data before 0.99
if amount.Sub(fee).LessThan(decimal.Zero) {
fee = amount.Mul(decimal.NewFromInt(1).Sub(feeRate))
}
amount = amount.Sub(fee)
Expand Down
4 changes: 4 additions & 0 deletions unipay/order_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ func (t *ToolUniPay) doOrderCheck() error {
if smtRecord.Id == 0 {
continue
}
if smtRecord.RecordType == tables.RecordTypeDefault {
continue
}

newStatus := tables.OrderStatusSuccess
if smtRecord.RecordType == tables.RecordTypeClosed {
newStatus = tables.OrderStatusFail
Expand Down

0 comments on commit 6f3c155

Please sign in to comment.