2025-06-26 09:28:42 +08:00
|
|
|
package services
|
|
|
|
|
|
2025-11-24 18:44:06 +08:00
|
|
|
import (
|
|
|
|
|
m "platform/web/models"
|
2026-03-26 14:39:19 +08:00
|
|
|
q "platform/web/queries"
|
2025-11-24 18:44:06 +08:00
|
|
|
|
|
|
|
|
"github.com/shopspring/decimal"
|
|
|
|
|
)
|
|
|
|
|
|
2025-06-26 09:28:42 +08:00
|
|
|
var Bill = &billService{}
|
|
|
|
|
|
|
|
|
|
type billService struct{}
|
|
|
|
|
|
2026-03-26 14:39:19 +08:00
|
|
|
func (s *billService) CreateForBalance(q *q.Query, uid, tradeId int32, detail *TradeDetail) error {
|
|
|
|
|
return q.Bill.Create(&m.Bill{
|
2025-11-24 18:44:06 +08:00
|
|
|
UserID: uid,
|
2026-03-26 14:39:19 +08:00
|
|
|
BillNo: ID.GenReadable("bil"),
|
|
|
|
|
TradeID: &tradeId,
|
2025-11-24 18:44:06 +08:00
|
|
|
Type: m.BillTypeRecharge,
|
2026-03-26 14:39:19 +08:00
|
|
|
Info: &detail.Subject,
|
|
|
|
|
Amount: detail.Amount,
|
|
|
|
|
Actual: detail.Actual,
|
|
|
|
|
})
|
2025-11-24 18:44:06 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-26 14:39:19 +08:00
|
|
|
func (s *billService) CreateForResourceByTrade(q *q.Query, uid, tradeId, resourceId int32, detail *TradeDetail) error {
|
|
|
|
|
return q.Bill.Create(&m.Bill{
|
2025-11-24 18:44:06 +08:00
|
|
|
UserID: uid,
|
2026-03-26 14:39:19 +08:00
|
|
|
BillNo: ID.GenReadable("bil"),
|
|
|
|
|
ResourceID: &resourceId,
|
|
|
|
|
TradeID: &tradeId,
|
|
|
|
|
CouponID: detail.CouponId,
|
2025-11-24 18:44:06 +08:00
|
|
|
Type: m.BillTypeConsume,
|
2026-03-26 14:39:19 +08:00
|
|
|
Info: &detail.Subject,
|
|
|
|
|
Amount: detail.Amount,
|
|
|
|
|
Actual: detail.Actual,
|
|
|
|
|
})
|
|
|
|
|
}
|
2025-11-24 18:44:06 +08:00
|
|
|
|
2026-03-26 14:39:19 +08:00
|
|
|
func (s *billService) CreateForResourceByBalance(q *q.Query, uid, resourceId int32, couponId *int32, subject string, amount, actual decimal.Decimal) error {
|
|
|
|
|
return q.Bill.Create(&m.Bill{
|
|
|
|
|
UserID: uid,
|
|
|
|
|
BillNo: ID.GenReadable("bil"),
|
|
|
|
|
ResourceID: &resourceId,
|
|
|
|
|
CouponID: couponId,
|
|
|
|
|
Type: m.BillTypeConsume,
|
|
|
|
|
Info: &subject,
|
|
|
|
|
Amount: amount,
|
|
|
|
|
Actual: actual,
|
|
|
|
|
})
|
2025-11-24 18:44:06 +08:00
|
|
|
}
|