88 lines
2.8 KiB
Go
88 lines
2.8 KiB
Go
package data
|
|
|
|
import (
|
|
"context"
|
|
"gorm.io/gorm"
|
|
"time"
|
|
)
|
|
|
|
type HistoryDirect struct {
|
|
SerialNumber string `gorm:"primaryKey;column:serial_number"`
|
|
OrderOrderNumber string `gorm:"column:order_order_number"`
|
|
TerminalAccount string `gorm:"column:terminal_account"`
|
|
OursProductId int `gorm:"column:ours_product_id"`
|
|
Status int `gorm:"column:status"`
|
|
TradePrice float32 `gorm:"column:trade_price"`
|
|
PlatformProductId int `gorm:"column:platform_product_id"`
|
|
PlatformPrice float32 `gorm:"column:platform_price"`
|
|
CreateTime time.Time `gorm:"column:create_time"`
|
|
ExecuteTime time.Time `gorm:"column:execute_time"`
|
|
Identifier int `gorm:"column:identifier"`
|
|
Version int `gorm:"column:version"`
|
|
Type int `gorm:"column:type"`
|
|
Position int `gorm:"column:position"`
|
|
Order HistoryOrder `gorm:"foreignkey:order_number;references:order_order_number"`
|
|
OrderItem HistoryOrderItem `gorm:"foreignkey:order_order_number;references:order_order_number"`
|
|
PlatformProduct PlatformProduct `gorm:"foreignkey:id;references:platform_product_id"`
|
|
Batch Batch `gorm:"foreignkey:batch_id;references:order_order_number"`
|
|
}
|
|
|
|
func (d HistoryDirect) TableName() string {
|
|
return "history_order_direct"
|
|
}
|
|
|
|
type HistoryDirectRepo struct {
|
|
db *gorm.DB
|
|
}
|
|
|
|
func NewHistoryDirectRepo(db *gorm.DB) *HistoryDirectRepo {
|
|
return &HistoryDirectRepo{
|
|
db: db,
|
|
}
|
|
}
|
|
|
|
func (repo HistoryDirectRepo) List(ctx context.Context, begin, end time.Time, limit int, last string) ([]HistoryDirect, error) {
|
|
var directs []HistoryDirect
|
|
db := repo.db.WithContext(ctx).
|
|
Preload("Order.Remark").
|
|
Preload("Order.Reseller").
|
|
Preload("OrderItem").
|
|
Preload("PlatformProduct").
|
|
Preload("PlatformProduct.Platform").
|
|
Where("create_time BETWEEN ? AND ?", begin, end)
|
|
if last != "" {
|
|
db.Where("serial_number > ?", last)
|
|
}
|
|
result := db.Order("create_time,serial_number").
|
|
Limit(limit).
|
|
Find(&directs)
|
|
|
|
if result.Error != nil {
|
|
return nil, result.Error
|
|
}
|
|
|
|
return directs, nil
|
|
}
|
|
|
|
func (repo HistoryDirectRepo) BatchList(ctx context.Context, begin, end time.Time, limit int, last string) ([]HistoryDirect, error) {
|
|
var directs []HistoryDirect
|
|
db := repo.db.WithContext(ctx).
|
|
InnerJoins("Batch").
|
|
Preload("Batch.Reseller").
|
|
Preload("PlatformProduct").
|
|
Preload("PlatformProduct.Platform").
|
|
Where("history_order_direct.create_time BETWEEN ? AND ?", begin, end)
|
|
if last != "" {
|
|
db.Where("history_order_direct.serial_number > ?", last)
|
|
}
|
|
result := db.Order("history_order_direct.create_time,history_order_direct.serial_number").
|
|
Limit(limit).
|
|
Find(&directs)
|
|
|
|
if result.Error != nil {
|
|
return nil, result.Error
|
|
}
|
|
|
|
return directs, nil
|
|
}
|