49 lines
1.7 KiB
Go
49 lines
1.7 KiB
Go
|
|
package models
|
|||
|
|
|
|||
|
|
import (
|
|||
|
|
"gorm.io/gorm"
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
// DeliveryMember 配送员表/*
|
|||
|
|
type DeliveryMember struct {
|
|||
|
|
gorm.Model
|
|||
|
|
Identity string `gorm:"column:identity;type:varchar(36);uniqueIndex;"` // 唯一标识,24位NanoID,36位为UUID
|
|||
|
|
Name string `gorm:"column:name;type:varchar(36);index;" json:"name"` // 姓名
|
|||
|
|
TeamIdentity string `gorm:"column:team_identity;type:varchar(36);Index;" json:"team_identity"` // 团队唯一标识
|
|||
|
|
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禁用
|
|||
|
|
Turnover int64 `gorm:"column:turnover;default:1;" json:"turnover"` // 总成交量
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// TableName .
|
|||
|
|
func (table *DeliveryMember) TableName() string {
|
|||
|
|
return "delivery_member" //对应数据库表名
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// DeliveryMemberList 获取配送团队成员
|
|||
|
|
func DeliveryMemberList(identity, teamIdentity, name string, status int64, size, page int) (int64, []DeliveryMember, error) {
|
|||
|
|
var (
|
|||
|
|
cnt int64 = 0
|
|||
|
|
data = make([]DeliveryMember, 0)
|
|||
|
|
)
|
|||
|
|
tx := DBService
|
|||
|
|
if identity != "" {
|
|||
|
|
tx = tx.Where("identity = ?", identity)
|
|||
|
|
}
|
|||
|
|
if name != "" {
|
|||
|
|
tx = tx.Where("name like ?", "%"+name+"%")
|
|||
|
|
}
|
|||
|
|
if teamIdentity != "" {
|
|||
|
|
tx = tx.Where("team_identity = ?", teamIdentity)
|
|||
|
|
}
|
|||
|
|
if status != 0 {
|
|||
|
|
tx = tx.Where("status = ?", status)
|
|||
|
|
}
|
|||
|
|
err := tx.Model(DeliveryMember{}).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
|
|||
|
|
}
|