Files
full/module/ec/delivery/internal/models/delivery_item.go

50 lines
1.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package models
import (
"gorm.io/gorm"
)
// DeliveryItem 配送团队表/*
type DeliveryItem struct {
gorm.Model
Identity string `gorm:"column:identity;type:varchar(36);uniqueIndex;"` // 唯一标识24位NanoID,36位为UUID
Title string `gorm:"column:title;type:varchar(36);index;" json:"title"` // 团队名称
Owner string `gorm:"column:owner;type:varchar(36);Index;" json:"owner"` // 归属者唯一标识
Contacts string `gorm:"column:contacts;type:varchar(36);Index;" json:"contacts"` // 联系人姓名
Phone string `gorm:"column:phone;type:varchar(36);Index;" json:"phone"` // 联系人电话
Logo string `gorm:"column:logo;type:varchar(255);Index;" json:"logo"` // 团队图标地址
Status int64 `gorm:"column:status;default:1;" json:"status"` // 状态1正常;-1禁用
}
// TableName .
func (table *DeliveryItem) TableName() string {
return "delivery_item" //对应数据库表名
}
// DeliveryItemList 获取配送团队
func DeliveryItemList(identity, title, owner string, status int64, size, page int) (int64, []DeliveryItem, error) {
var (
cnt int64 = 0
data = make([]DeliveryItem, 0)
)
tx := DBService
if identity != "" {
tx = tx.Where("identity = ?", identity)
}
if title != "" {
tx = tx.Where("title like ?", "%"+title+"%")
}
if owner != "" {
tx = tx.Where("owner = ?", owner)
}
if status != 0 {
tx = tx.Where("status = ?", status)
}
err := tx.Model(DeliveryItem{}).Order("created_at desc").Count(&cnt).Limit(size).Offset((page - 1) * size).Find(&data).Error
if err != nil {
return 0, nil, err
}
return cnt, data, nil
}