excel-export/data/card.go

64 lines
1.9 KiB
Go

package data
import (
"context"
"gorm.io/gorm"
"time"
)
type Card struct {
OrderNumber string `gorm:"primaryKey;column:order_number"`
ResellerId int `gorm:"column:reseller_id"`
ResellerOrderNumber string `gorm:"column:reseller_order_number"`
OursProductId int `gorm:"column:ours_product_id"`
Price float32 `gorm:"column:price"`
Quantity int `gorm:"column:quantity"`
Amount float32 `gorm:"column:amount"`
PayStatus int `gorm:"column:pay_status"`
Status int `gorm:"column:status"`
Profit float32 `gorm:"column:profit"`
NotifyTime int64 `gorm:"column:notify_time"`
CreateIp int64 `gorm:"column:create_ip"`
CreateTime int64 `gorm:"column:create_time"`
CardCode string `gorm:"column:card_code"`
FinishTime time.Time `gorm:"column:finish_time"`
Message string `gorm:"column:message"`
Mobile string `gorm:"column:mobile"`
OurProduct OurProduct `gorm:"foreignkey:id;references:ours_product_id"`
Reseller Reseller `gorm:"foreignkey:id;references:reseller_id"`
}
func (o Card) TableName() string {
return "order_card"
}
type CardRepo struct {
db *gorm.DB
}
func NewCardRepo(db *gorm.DB) *CardRepo {
return &CardRepo{
db: db,
}
}
func (repo CardRepo) List(ctx context.Context, begin, end time.Time, limit int, last string) ([]Card, error) {
var orders []Card
db := repo.db.WithContext(ctx).
Preload("OurProduct").
Preload("Reseller").
Where("create_time BETWEEN ? AND ?", begin.Unix(), end.Unix())
if last != "" {
db.Where("order_number > ?", last)
}
result := db.Order("create_time,order_number").
Limit(limit).
Find(&orders)
if result.Error != nil {
return nil, result.Error
}
return orders, nil
}