refactor: reorganize modules and add Linux build tooling
This commit is contained in:
50
module/ec/delivery/internal/models/delivery_car.go
Normal file
50
module/ec/delivery/internal/models/delivery_car.go
Normal file
@@ -0,0 +1,50 @@
|
||||
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
|
||||
}
|
||||
49
module/ec/delivery/internal/models/delivery_item.go
Normal file
49
module/ec/delivery/internal/models/delivery_item.go
Normal file
@@ -0,0 +1,49 @@
|
||||
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
|
||||
}
|
||||
48
module/ec/delivery/internal/models/delivery_member.go
Normal file
48
module/ec/delivery/internal/models/delivery_member.go
Normal file
@@ -0,0 +1,48 @@
|
||||
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
|
||||
}
|
||||
28
module/ec/delivery/internal/models/impl.go
Normal file
28
module/ec/delivery/internal/models/impl.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/engine/database/sql"
|
||||
"git.apinb.com/bsm-sdk/engine/types"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var DBService *gorm.DB
|
||||
|
||||
var migrateTables = []any{
|
||||
&DeliveryItem{},
|
||||
&DeliveryMember{},
|
||||
&DeliveryCar{},
|
||||
}
|
||||
|
||||
func New(dsn string, options *types.SqlOptions) (err error) {
|
||||
DBService, err = sql.NewPostgreSql(dsn, options)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = DBService.AutoMigrate(migrateTables...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user