pg_dividends_order_dao.go
1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package dao
import (
"fmt"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
"time"
)
type DividendsOrderDao struct {
transactionContext *pgTransaction.TransactionContext
}
// GenerateDividendsOrderNumber 生成分红订单号
func (dao *DividendsOrderDao) GenerateDividendsOrderNumber() (string, error) {
tx := dao.transactionContext.PgTx
var dividendsOrderModels []*models.DividendsOrder
query := tx.Model(÷ndsOrderModels)
currentTime := time.Now()
todayZeroTime := utils.GetZeroTime(currentTime)
nextDayZeroTime := utils.GetNextDayZeroTime(currentTime)
query.Where("dividends_order.created_at >= ?", todayZeroTime)
query.Where("dividends_order.created_at < ?", nextDayZeroTime)
if count, err := query.AllWithDeleted().SelectAndCount(); err != nil {
return "", err
} else {
countStr := fmt.Sprintf("%03d", count+1)
timestamp := currentTime.Unix()
timeNow := time.Unix(timestamp, 0)
timeString := timeNow.Format("20060102")
timeString = timeString[2:len(timeString)]
dividendsOrderNumber := "SL" + timeString + "#" + countStr
return dividendsOrderNumber, nil
}
}
func NewDividendsOrderDao(transactionContext *pgTransaction.TransactionContext) (*DividendsOrderDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能未")
} else {
return &DividendsOrderDao{
transactionContext: transactionContext,
}, nil
}
}