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

51 lines
2.0 KiB
Go
Raw Normal View History

package models
import (
"gorm.io/gorm"
)
// Deliverycar 配送员表/*
type DeliveryCar struct {
gorm.Model
Identity string `gorm:"column:identity;type:varchar(36);uniqueIndex;"` // 唯一标识24位NanoID,36位为UUID
Brand string `gorm:"column:brand;type:varchar(36);index;;" json:"brand"` // 品牌
TeamIdentity string `gorm:"column:team_identity;type:varchar(36);Index;" json:"team_identity"` // 团队唯一标识
Version string `gorm:"column:version;type:varchar(36);index;;" json:"version"` // 型号
LicenseNumber string `gorm:"column:license_number;type:varchar(36);index;;" json:"license_number"` // 车牌号
Contacts string `gorm:"column:contacts;type:varchar(36);Index;" json:"contacts"` // 联系人姓名
Phone string `gorm:"column:phone;type:varchar(36);Index;" json:"phone"` // 联系人电话
Picture string `gorm:"column:picture;type:varchar(255);Index;" json:"picture"` // 车辆图片
Status int64 `gorm:"column:status;default:1;" json:"status"` // 状态1正常;-1禁用
}
// TableName .
func (table *DeliveryCar) TableName() string {
return "delivery_car" //对应数据库表名
}
// DeliveryMemberList 获取配送团队
func DeliverycarList(identity, teamIdentity, licenseNumber string, status int64, size, page int) (int64, []DeliveryCar, error) {
var (
cnt int64 = 0
data = make([]DeliveryCar, 0)
)
tx := DBService
if identity != "" {
tx = tx.Where("identity = ?", identity)
}
if teamIdentity != "" {
tx = tx.Where("team_identity = ?", teamIdentity)
}
if licenseNumber != "" {
tx = tx.Where("license_number like ? or brand like ?", "%"+licenseNumber+"%", "%"+licenseNumber+"%")
}
if status != 0 {
tx = tx.Where("status = ?", status)
}
err := tx.Model(DeliveryCar{}).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
}