feat: import services and standardize Go 1.26.5
This commit is contained in:
26
apps/ec/mall/internal/models/mall_ads.go
Normal file
26
apps/ec/mall/internal/models/mall_ads.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/core/database"
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
)
|
||||
|
||||
type MallAds struct {
|
||||
types.Std_IICUDS
|
||||
Std_Store
|
||||
Title string `gorm:"column:title;type:varchar(255);not null;" json:"title"` // 广告名称
|
||||
PosKey string `gorm:"column:pos_key;type:varchar(255);not null;" json:"pos_key"` // 广告位key
|
||||
Content string `gorm:"column:content;type:varchar(255);measuring_name;" json:"content"` // 广告内容
|
||||
Type ContentType `gorm:"column:type;default:0;" json:"type"` // 广告类型
|
||||
ToUrl string `gorm:"column:to_url;type:varchar(255);default:'';" json:"to_url"` // 跳转链接
|
||||
|
||||
}
|
||||
|
||||
func init() {
|
||||
database.AppendMigrate(&MallAds{})
|
||||
}
|
||||
|
||||
// TableName .
|
||||
func (table *MallAds) TableName() string {
|
||||
return "mall_ads" //对应数据库表名
|
||||
}
|
||||
39
apps/ec/mall/internal/models/mall_apply.go
Normal file
39
apps/ec/mall/internal/models/mall_apply.go
Normal file
@@ -0,0 +1,39 @@
|
||||
// Models generated by mesh dev cli,@Author: David Yan(david.yan@qq.com).
|
||||
package models
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/core/database"
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
/*
|
||||
* StoreBasic
|
||||
* Comment: 电商系统-店铺申请表
|
||||
* Version: 10
|
||||
* Created: 2022-04-12 14:18:10 , Updated:0001-01-01 00:00:00
|
||||
*/
|
||||
type MallApply struct {
|
||||
gorm.Model
|
||||
Title string `gorm:"column:title;type:varchar(255);not null;" json:"title"` // 标题
|
||||
Intro string `gorm:"column:intro;type:varchar(255);default:'';" json:"intro"` // 描述说明
|
||||
Template string `gorm:"column:template;type:varchar(255);not null;" json:"template"` // 模板
|
||||
Subdomain string `gorm:"column:subdomain;type:varchar(255);not null;" json:"subdomain"` //子域名设置,可选
|
||||
Configs string `gorm:"column:configs;type:varchar(255);default:'';" json:"configs"` // 配置说明
|
||||
Name string `gorm:"type:varchar(255);index;default:'';"` // 姓名
|
||||
Account string `gorm:"type:varchar(255);index;default:'';"` // 登录账号
|
||||
Password string `gorm:"type:varchar(255);default:'';"` // 登录密码
|
||||
Phone string `gorm:"type:varchar(20);default:'';"`
|
||||
Email string `gorm:"type:varchar(255);default:'';"`
|
||||
ApplyRemarks string `gorm:"type:varchar(255);default:'';"`
|
||||
types.Std_Status
|
||||
}
|
||||
|
||||
func init() {
|
||||
database.AppendMigrate(&MallApply{})
|
||||
}
|
||||
|
||||
// TableName .
|
||||
func (table *MallApply) TableName() string {
|
||||
return "mall_apply" //对应数据库表名
|
||||
}
|
||||
31
apps/ec/mall/internal/models/mall_category.go
Normal file
31
apps/ec/mall/internal/models/mall_category.go
Normal file
@@ -0,0 +1,31 @@
|
||||
// Models generated by mesh dev cli,@Author: David Yan(david.yan@qq.com).
|
||||
package models
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/core/database"
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
)
|
||||
|
||||
// MallCategory /*
|
||||
type MallCategory struct {
|
||||
types.Std_IICUDS
|
||||
Std_Store
|
||||
Title string `gorm:"column:title;type:varchar(255);not null;" json:"title"` // 类别名称
|
||||
EnTitle string `gorm:"column:en_title;type:varchar(255);default:'';" json:"en_title"` // 类别英文名称,可用做url参数替代id
|
||||
Keys string `gorm:"column:keys;type:varchar(255);default:'';" json:"keys"` // 类别关键词
|
||||
ParentID int64 `gorm:"column:parent_id;default:0;" json:"parent_id"` // 类别父级id
|
||||
Paths string `gorm:"column:paths;type:varchar(255);default:'';" json:"paths"` // 分类id路径(存在父类时,多个分类ID用半角逗号分割,完全存储)
|
||||
Intro string `gorm:"column:intro;type:varchar(255);default:'';" json:"intro"` // 类别描述
|
||||
Icon string `gorm:"column:icon;type:varchar(255);default:'';" json:"icon"` // 图标
|
||||
Sort int32 `gorm:"column:sort;default:0;" json:"sort"` // 排序顺序索引
|
||||
Categories []*MallCategory `gorm:"foreignkey:ParentID;references:ID;" json:"categories"` // 子集
|
||||
}
|
||||
|
||||
func init() {
|
||||
database.AppendMigrate(&MallCategory{})
|
||||
}
|
||||
|
||||
// TableName .
|
||||
func (table *MallCategory) TableName() string {
|
||||
return "mall_category" //对应数据库表名
|
||||
}
|
||||
32
apps/ec/mall/internal/models/mall_freight.go
Normal file
32
apps/ec/mall/internal/models/mall_freight.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/core/database"
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// MallFreight 运费模板/*
|
||||
type MallFreight struct {
|
||||
gorm.Model
|
||||
types.Std_Identity
|
||||
types.Std_Status // 1 正常
|
||||
OwnerId uint `gorm:"column:owner_id;Index;"` // 所属机构id
|
||||
OwnerIdentity string `gorm:"column:owner_identity;type:varchar(255);not null;" json:"owner_identity"` // 所属机构唯一码
|
||||
CreatedIdentity string `gorm:"column:created_identity;type:varchar(36);Index;"` // 创建者一标识,24位NanoID,36位为UUID
|
||||
Title string `gorm:"column:title;type:varchar(255);not null;" json:"title"` // 名称
|
||||
PostType int32 `gorm:"column:post_type;default:1;" json:"post_type"` // 是否包邮:1包邮,2不包邮
|
||||
Quota int64 `gorm:"column:quota;default:0;" json:"quota"` // 当types=1时,满额包邮
|
||||
CostType int32 `gorm:"column:cost_type;default:1;" json:"cost_type"` // 计费类型:1计件收费,2按重收费
|
||||
RegionType int32 `gorm:"column:region_type;default:2;" json:"region_type"` // 区域限售:1限制,2不限制
|
||||
Rules []MallFreightAttr `gorm:"foreignKey:FreightIdentity;references:Identity;" json:"rules"` // 计费规则
|
||||
}
|
||||
|
||||
func init() {
|
||||
database.AppendMigrate(&MallFreight{})
|
||||
}
|
||||
|
||||
// TableName .
|
||||
func (table *MallFreight) TableName() string {
|
||||
return "mall_freight" //对应数据库表名
|
||||
}
|
||||
31
apps/ec/mall/internal/models/mall_freight_attr.go
Normal file
31
apps/ec/mall/internal/models/mall_freight_attr.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/core/database"
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type MallFreightAttr struct {
|
||||
gorm.Model
|
||||
types.Std_Identity
|
||||
FreightIdentity string `gorm:"column:freight_identity;type:varchar(255);not null;" json:"freight_identity"` // 模板唯一码
|
||||
Region string `gorm:"column:region;type:text;region;"` // 地区的json字符串
|
||||
RegionId string `gorm:"column:region_id;type:varchar(255);region_id;"` // 地区2级id(用,隔开)目前将1级id一起储存
|
||||
PriceBasic int64 `gorm:"column:price_basic;default:0;" json:"price_basic"` // 起步运费
|
||||
CountBasic int64 `gorm:"column:count_basic;default:0;" json:"count_basic"` // 起步数量
|
||||
CountExtra int64 `gorm:"column:count_extra;default:0;" json:"count_extra"` // 加价数量
|
||||
PriceExtra int64 `gorm:"column:price_extra;default:0;" json:"price_extra"` // 加价单价
|
||||
Total int64 `gorm:"column:total;default:0;" json:"total"` // 总价=加价总价+起步价
|
||||
IsDefault int32 `gorm:"column:is_default;default:1;" json:"is_default"` // 状态:1-普通,2默认
|
||||
Status int32 `gorm:"column:status;" json:"status"` // 状态:1-正常;2停用
|
||||
}
|
||||
|
||||
func init() {
|
||||
database.AppendMigrate(&MallFreightAttr{})
|
||||
}
|
||||
|
||||
// TableName .
|
||||
func (table *MallFreightAttr) TableName() string {
|
||||
return "mall_freight_attr" //对应数据库表名
|
||||
}
|
||||
28
apps/ec/mall/internal/models/mall_freight_deny.go
Normal file
28
apps/ec/mall/internal/models/mall_freight_deny.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/core/database"
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// Store Freight Deny
|
||||
type MallFreightDeny struct {
|
||||
gorm.Model
|
||||
types.Std_Identity
|
||||
types.Std_Status
|
||||
OwnerIdentity string `gorm:"column:owner_identity;type:varchar(36);Index;"` // 机构唯一标识,24位NanoID,36位为UUID
|
||||
CreatedIdentity string `gorm:"column:created_identity;type:varchar(36);Index;"` // 创建者一标识,24位NanoID,36位为UUID
|
||||
Title string `gorm:"column:title;type:varchar(255);not null;" json:"title"` // 名称
|
||||
Region string `gorm:"column:region;type:text;" json:"region"` // 限售区域json字符串
|
||||
RegionId string `gorm:"column:region_id;type:varchar(255);" json:"region_id"` // 限售区域id,用逗号隔开
|
||||
}
|
||||
|
||||
func init() {
|
||||
database.AppendMigrate(&MallFreightDeny{})
|
||||
}
|
||||
|
||||
// TableName .
|
||||
func (table *MallFreightDeny) TableName() string {
|
||||
return "mall_freight_deny" //对应数据库表名
|
||||
}
|
||||
23
apps/ec/mall/internal/models/mall_notice.go
Normal file
23
apps/ec/mall/internal/models/mall_notice.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/core/database"
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
)
|
||||
|
||||
type MallNotice struct {
|
||||
types.Std_IICUDS
|
||||
Std_Store
|
||||
Title string `gorm:"column:title;type:varchar(255);not null;" json:"title"` // 标题
|
||||
Author string `gorm:"column:author;type:varchar(255);not null;" json:"author"` // 作者
|
||||
Content string `gorm:"column:content;type:text;default:'';" json:"content"` // 正文
|
||||
}
|
||||
|
||||
func init() {
|
||||
database.AppendMigrate(&MallNotice{})
|
||||
}
|
||||
|
||||
// TableName .
|
||||
func (table *MallNotice) TableName() string {
|
||||
return "mall_notice" //对应数据库表名
|
||||
}
|
||||
296
apps/ec/mall/internal/models/mall_product.go
Normal file
296
apps/ec/mall/internal/models/mall_product.go
Normal file
@@ -0,0 +1,296 @@
|
||||
// Models generated by mesh dev cli,@Author: David Yan(david.yan@qq.com).
|
||||
package models
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-ec/mall/internal/impl"
|
||||
"git.apinb.com/bsm-sdk/core/database"
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
/*
|
||||
* MallProduct
|
||||
* Comment: 商品基本信息
|
||||
* Version: 10
|
||||
* Created: 2022-04-12 14:34:27 , Updated:0001-01-01 00:00:00
|
||||
*/
|
||||
type MallProduct struct {
|
||||
types.Std_IICUDS
|
||||
Std_Store
|
||||
SerialId string `gorm:"column:serial_id;type:varchar(36);Index;" json:"serial_id"` // 产品序列号
|
||||
SupplyId int64 `gorm:"column:supply_id;default:0;supply_id;"` // 供应商ID
|
||||
Title string `gorm:"column:title;type:varchar(255);not null;" json:"title"` // 商品副标题
|
||||
MeasuringName string `gorm:"column:measuring_name;type:varchar(255);default:'';" json:"measuring_name"` // 测量单位名称
|
||||
SellMax int32 `gorm:"column:sell_max;default:0;" json:"sell_max"` // 最高限购
|
||||
SellMin int32 `gorm:"column:sell_min;default:0;" json:"sell_min"` // 最低限购
|
||||
Wastage int32 `gorm:"column:wastage;default:0;" json:"wastage"` // 损耗率
|
||||
StandardNumber string `gorm:"column:standard_number;type:varchar(255);default:'';" json:"standard_number"` // 商品标准编号
|
||||
Brand string `gorm:"column:brand;type:varchar(255);default:'';" json:"brand"` // 品牌
|
||||
StockType int32 `gorm:"column:stock_type;default:1;" json:"stock_type"` // 库存计数方式:1-买方下单减库存,2-完成签约减库存
|
||||
Status int32 `gorm:"column:status;default:0;" json:"status"` // 商品状态:5-未上架,1-已上架,2-自动上架等待中,3-禁用 ,4-草稿
|
||||
PutawayTime string `gorm:"column:putaway_time;type:varchar(255);default:'';" json:"putaway_time"` // 预定的上架时间
|
||||
CoverImage string `gorm:"column:cover_image;type:varchar(255);default:'';" json:"cover_image"` // 商品代表性图片
|
||||
TemplateID int64 `gorm:"column:template_id;default:0;" json:"template_id"` // 运费模板id
|
||||
RecentNumber int64 `gorm:"column:recent_number;default:0;" json:"recent_number"` // 最近30天的销量
|
||||
Limitation int64 `gorm:"column:limitation;default:0;" json:"limitation"` // 区域限制:1不限制,2限制
|
||||
LiTemplateID int64 `gorm:"column:li_template_id;default:0;" json:"li_template_id"` // 区域限制的模板id
|
||||
Content string `gorm:"column:content;type:text;default:'';" json:"content"` // 详情
|
||||
Notes string `gorm:"column:notes;type:varchar(255);default:'';" json:"notes"` // 备注说明:发货方式及时间
|
||||
SaleTotal int32 `gorm:"column:sale_total;default:0;" json:"sale_total"` // 销售总数
|
||||
SalesPrice int64 `gorm:"column:sales_price;default:0;" json:"sales_price"` // 商品售价
|
||||
Stock int32 `gorm:"column:stock;default:0;" json:"stock"` // 库存
|
||||
|
||||
CategoryPaths string `gorm:"column:category_paths;type:varchar(255);default:'';" json:"category_paths"` // 商品类别ID路径(多个分类ID使用半角逗号分割)
|
||||
SubTitle string `gorm:"column:sub_title;type:varchar(255);not null;" json:"sub_title"` // 商品副标题
|
||||
Keyword string `gorm:"column:keyword;type:varchar(255);default:'';" json:"keyword"` // 商品关键词
|
||||
CostPrice int64 `gorm:"column:cost_price;default:0;" json:"cost_price"` // 成本价格
|
||||
Args string `gorm:"column:args;type:varchar(255);default:'';" json:"args"` // 商品相关参数JSON
|
||||
Star int64 `gorm:"column:star;default:0;" json:"star"` // 评分
|
||||
CommentTotal int32 `gorm:"column:comment_total;default:0;" json:"comment_total"` // 评论总数
|
||||
ViewTotal int32 `gorm:"column:view_total;default:0;" json:"view_total"` // 浏览总数
|
||||
ImageTotal int32 `gorm:"column:image_total;default:0;" json:"image_total"` // 图片总数
|
||||
PartnerPer int64 `gorm:"column:partner_per;default:0;" json:"partner_per"` // 分销人员利润占比
|
||||
Recommend int8 `gorm:"column:recommend;default:0;" json:"recommend"` // 2不推荐,1推荐的状态,0默认
|
||||
Sort int32 `gorm:"column:sort;default:0;" json:"sort"` // 排序
|
||||
Types int32 `gorm:"column:types;default:0;" json:"types"` // 商品类型:Product=1 实体商品,Service=2 服务,Membership=3 会员服务,Other=4 其它
|
||||
GasType int32 `gorm:"column:gas_types;default:1;" json:"gas_types"` // 商品类型:1其它商品 2按瓶计费,3 按kg计费
|
||||
|
||||
Images []MallProductPhotos `gorm:"foreignKey:ProductIdentity;references:Identity;" json:"images"`
|
||||
Specs []ProductSpec `gorm:"foreignKey:ProductIdentity;references:Identity;" json:"spec"`
|
||||
Categories []ProductCategory `gorm:"foreignKey:ProductIdentity;references:Identity;" json:"category"`
|
||||
CategoryId []int64 `gorm:"-"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
database.AppendMigrate(&MallProduct{})
|
||||
}
|
||||
|
||||
// TableName .
|
||||
func (table *MallProduct) TableName() string {
|
||||
return "mall_product" //对应数据库表名
|
||||
}
|
||||
|
||||
// ForbiddenProduct 批量停用产品
|
||||
func ForbiddenProduct(list []string, storeIdentity string) (int64, error) {
|
||||
tx := impl.DBService.Model(&MallProduct{}).Where("identity in ?", list).Where("store_identity = ?", storeIdentity).Updates(&MallProduct{Status: 3})
|
||||
return tx.RowsAffected, tx.Error
|
||||
}
|
||||
|
||||
// ProductDetail 获取产品详情
|
||||
func ProductDetail(identity string) (*MallProduct, error) {
|
||||
var data = &MallProduct{}
|
||||
tx := impl.DBService.Preload("Specs").Preload("Images").Preload("Categories").Where("identity = ?", identity).First(&data)
|
||||
return data, tx.Error
|
||||
}
|
||||
|
||||
// CreateProduct 创建新产品
|
||||
func CreateProduct(product *MallProduct, specId []*ProductSpec, photo []*MallProductPhotos, categoryId []*ProductCategory) error {
|
||||
tx := impl.DBService.Begin()
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tx.Rollback()
|
||||
}
|
||||
}()
|
||||
|
||||
// 创建主产品记录
|
||||
if err := tx.Create(product).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
|
||||
// 创建规格关联
|
||||
if len(specId) > 0 {
|
||||
for _, v := range specId {
|
||||
v.ProductId = product.ID
|
||||
v.ProductIdentity = product.Identity
|
||||
}
|
||||
if err := tx.Create(&specId).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// 创建图片关联
|
||||
if len(photo) > 0 {
|
||||
if err := tx.Create(&photo).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// 创建分类关联
|
||||
if len(categoryId) > 0 {
|
||||
for _, v := range categoryId {
|
||||
v.ProductId = product.ID
|
||||
v.ProductIdentity = product.Identity
|
||||
}
|
||||
if err := tx.Create(&categoryId).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return tx.Commit().Error
|
||||
}
|
||||
|
||||
// ModifyProduct 修改产品信息
|
||||
func ModifyProduct(product *MallProduct, specId []*ProductSpec, photo []*MallProductPhotos, categoryId []*ProductCategory) error {
|
||||
// 先查询原产品信息
|
||||
pt := MallProduct{}
|
||||
err := impl.DBService.Where("identity = ?", product.Identity).First(&pt).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tx := impl.DBService.Begin()
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tx.Rollback()
|
||||
}
|
||||
}()
|
||||
|
||||
// 更新主产品信息
|
||||
if err := tx.Where("identity = ?", product.Identity).Updates(product).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
|
||||
// 更新规格关联 - 先删除后创建
|
||||
if len(specId) > 0 {
|
||||
if err := tx.Where("product_identity = ?", product.Identity).Delete(&ProductSpec{}).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
for _, v := range specId {
|
||||
v.ProductId = pt.ID
|
||||
v.ProductIdentity = pt.Identity
|
||||
}
|
||||
if err := tx.Create(&specId).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// 更新图片关联 - 先删除后创建
|
||||
if len(photo) > 0 {
|
||||
if err := tx.Where("product_identity = ?", product.Identity).Delete(&MallProductPhotos{}).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
if err := tx.Create(&photo).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// 更新分类关联 - 先删除后创建
|
||||
if len(categoryId) > 0 {
|
||||
if err := tx.Where("product_identity = ?", product.Identity).Delete(&ProductCategory{}).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
for _, v := range categoryId {
|
||||
v.ProductId = pt.ID
|
||||
v.ProductIdentity = pt.Identity
|
||||
}
|
||||
if err := tx.Create(&categoryId).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return tx.Commit().Error
|
||||
}
|
||||
|
||||
// DelProduct 删除产品及其关联数据
|
||||
func DelProduct(identity string) error {
|
||||
tx := impl.DBService.Begin()
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tx.Rollback()
|
||||
}
|
||||
}()
|
||||
|
||||
// 按依赖关系顺序删除关联数据
|
||||
// 1. 删除评论
|
||||
if err := tx.Where("product_identity = ?", identity).Delete(&MallProductComment{}).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
|
||||
// 2. 删除图片
|
||||
if err := tx.Where("product_identity = ?", identity).Delete(&MallProductPhotos{}).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
|
||||
// 3. 删除规格
|
||||
if err := tx.Where("product_identity = ?", identity).Delete(&MallProductSpec{}).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
|
||||
// 4. 删除分类关联
|
||||
if err := tx.Where("product_identity = ?", identity).Delete(&ProductCategory{}).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
|
||||
// 5. 删除主产品记录
|
||||
if err := tx.Where("identity = ?", identity).Delete(&MallProduct{}).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.Commit().Error
|
||||
}
|
||||
|
||||
// GetProductList 获取产品列表
|
||||
func GetProductList(identity []string, page, size, status, category, recommend int64, keyword, timeStart, timeEnd string) ([]*MallProduct, int32, error) {
|
||||
tx := impl.DBService.Select("*")
|
||||
|
||||
// 店铺筛选
|
||||
if len(identity) == 1 {
|
||||
tx = tx.Where("store_identity = ?", identity[0])
|
||||
} else if len(identity) > 1 {
|
||||
tx = tx.Where("store_identity in ?", identity)
|
||||
}
|
||||
|
||||
// 分类筛选
|
||||
if category != 0 {
|
||||
tx = tx.Where("id in (SELECT product_id FROM product_category WHERE category_id = ?)", category)
|
||||
}
|
||||
|
||||
// 关键词搜索
|
||||
if keyword != "" {
|
||||
tx = tx.Where("title LIKE ? OR sub_title LIKE ?", "%"+keyword+"%", "%"+keyword+"%")
|
||||
}
|
||||
|
||||
// 时间范围筛选
|
||||
if timeStart != "" && timeEnd != "" {
|
||||
tx = tx.Where("created_at BETWEEN ? AND ?", timeStart, timeEnd)
|
||||
}
|
||||
|
||||
// 状态筛选
|
||||
if status != 0 {
|
||||
tx = tx.Where("status = ?", status)
|
||||
}
|
||||
|
||||
// 推荐状态筛选
|
||||
if recommend != 0 {
|
||||
tx = tx.Where("recommend = ?", recommend)
|
||||
}
|
||||
|
||||
posts := make([]*MallProduct, 0)
|
||||
var cnt int64 = 0
|
||||
|
||||
// 预加载关联数据,包括最低价格的规格
|
||||
tx.Order("created_at desc").Preload("Specs", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Table("mall_product_spec as s, (?) as b",
|
||||
db.Model(&MallProductSpec{}).Select("product_identity,min(price) price").Group("product_identity")).
|
||||
Select("s.*").Where("s.product_identity = b.product_identity and s.price = b.price").Order("s.product_identity")
|
||||
}).Limit(int(size)).Offset(int((page - 1) * size)).Find(&posts).Count(&cnt)
|
||||
|
||||
err := tx.Error
|
||||
return posts, int32(cnt), err
|
||||
}
|
||||
23
apps/ec/mall/internal/models/mall_product_attr.go
Normal file
23
apps/ec/mall/internal/models/mall_product_attr.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/core/database"
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
)
|
||||
|
||||
type MallProductAttr struct {
|
||||
types.Std_ID
|
||||
ProductID int32 `gorm:"column:product_id;index;not null;" json:"product_id"`
|
||||
Name string `gorm:"column:name;type:varchar(255);default:'';" json:"name"` // 属性名称
|
||||
ParentID int32 `gorm:"column:parent_id;" json:"parent_id"` // 父级属性id
|
||||
Value string `gorm:"column:value;type:varchar(255);default:'';" json:"value"` // 属性值
|
||||
}
|
||||
|
||||
func init() {
|
||||
database.AppendMigrate(&MallProductAttr{})
|
||||
}
|
||||
|
||||
// TableName .
|
||||
func (table *MallProductAttr) TableName() string {
|
||||
return "mall_product_attr" //对应数据库表名
|
||||
}
|
||||
67
apps/ec/mall/internal/models/mall_product_comment.go
Normal file
67
apps/ec/mall/internal/models/mall_product_comment.go
Normal file
@@ -0,0 +1,67 @@
|
||||
// Models generated by mesh dev cli,@Author: David Yan(david.yan@qq.com).
|
||||
package models
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-ec/mall/internal/impl"
|
||||
"git.apinb.com/bsm-sdk/core/database"
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
/*
|
||||
* MallProductComment
|
||||
* Comment: 商品评论
|
||||
* Version: 10
|
||||
* Created: 2022-04-12 14:36:54 , Updated:0001-01-01 00:00:00
|
||||
*/
|
||||
type MallProductComment struct {
|
||||
gorm.Model
|
||||
types.Std_Owner
|
||||
types.Std_Identity
|
||||
ProductIdentity string `gorm:"column:product_identity;type:varchar(36);" json:"product_identity"` // 商品唯一码
|
||||
SpecIdentity string `gorm:"column:spec_identity;type:varchar(36);" json:"spec_identity"` // 商品规格唯一码
|
||||
StoreIdentity string `gorm:"column:store_identity;type:varchar(36);" json:"store_identity"` // 店铺唯一标识
|
||||
CommentIdentity string `gorm:"column:comment_identity;type:varchar(36);default:'';" json:"comment_identity"` // 被回复的评论唯一标识
|
||||
Nickname string `gorm:"column:nickname;type:varchar(255);default:'';" json:"nick_name"` // 用户昵称
|
||||
Score int8 `gorm:"column:score;default:0;" json:"score"` // 评分
|
||||
Comment string `gorm:"column:comment;type:varchar(500);" json:"comment"` // 评论内容
|
||||
Reply string `gorm:"column:reply;type:varchar(500);" json:"reply"` // 评论回复
|
||||
Enabled int8 `gorm:"column:enabled;default:0;" json:"enabled"` // 是否允许展示
|
||||
List []*MallProductComment `gorm:"foreignKey:CommentIdentity;references:Identity;" json:"list"`
|
||||
|
||||
ProductSpec MallProductSpec `gorm:"foreignKey:Identity;references:SpecIdentity;" json:"product_spec"`
|
||||
Product MallProduct `gorm:"foreignKey:Identity;references:ProductIdentity;" json:"product"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
database.AppendMigrate(&MallProductComment{})
|
||||
}
|
||||
|
||||
// TableName .
|
||||
func (table *MallProductComment) TableName() string {
|
||||
return "mall_product_comment" //对应数据库表名
|
||||
}
|
||||
|
||||
// DelComment 删除评论
|
||||
func DelComment(identity string) (int64, error) {
|
||||
result := impl.DBService.Where("identity = ?", identity).Delete(&MallProductComment{})
|
||||
return result.RowsAffected, result.Error
|
||||
}
|
||||
|
||||
// CreateComment 添加评论
|
||||
func CreateComment(comment *MallProductComment) (int64, error) {
|
||||
result := impl.DBService.Create(&comment)
|
||||
return result.RowsAffected, result.Error
|
||||
}
|
||||
|
||||
// ReComment 回复评论
|
||||
func ReComment(identity, reply string) (int64, error) {
|
||||
result := impl.DBService.Model(&MallProductComment{}).Select("reply").Where("identity = ?", identity).Updates(MallProductComment{Reply: reply})
|
||||
return result.RowsAffected, result.Error
|
||||
}
|
||||
|
||||
// ModifyComment 修改评论
|
||||
func ModifyComment(comment *MallProductComment) (int64, error) {
|
||||
result := impl.DBService.Where("identity = ?", comment.Identity).Updates(&comment)
|
||||
return result.RowsAffected, result.Error
|
||||
}
|
||||
26
apps/ec/mall/internal/models/mall_product_link_category.go
Normal file
26
apps/ec/mall/internal/models/mall_product_link_category.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/core/database"
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
)
|
||||
|
||||
// ProductCategory /*
|
||||
type ProductCategory struct {
|
||||
types.Std_IICUDS
|
||||
ProductId uint `gorm:"column:product_id;not null;" json:"product_id"` // 商品ID
|
||||
ProductIdentity string `gorm:"column:product_identity;" json:"product_identity"` // 商品身份标识
|
||||
CategoryId int64 `gorm:"column:category_id;not null;" json:"category_id"` // 分类ID
|
||||
|
||||
Category MallCategory `gorm:"foreignKey:ID;references:CategoryId;"` // 关联分类
|
||||
Product MallProduct `gorm:"foreignKey:ID;references:ProductId;"` // 关联商品
|
||||
}
|
||||
|
||||
func init() {
|
||||
database.AppendMigrate(&ProductCategory{})
|
||||
}
|
||||
|
||||
// TableName .
|
||||
func (table *ProductCategory) TableName() string {
|
||||
return "product_category" //对应数据库表名
|
||||
}
|
||||
26
apps/ec/mall/internal/models/mall_product_link_spec.go
Normal file
26
apps/ec/mall/internal/models/mall_product_link_spec.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/core/database"
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
)
|
||||
|
||||
// ProductSpec /*
|
||||
type ProductSpec struct {
|
||||
types.Std_IICUDS
|
||||
ProductId uint `gorm:"column:product_id;not null;" json:"product_id"` // 产品ID
|
||||
ProductIdentity string `gorm:"column:product_identity;" json:"product_identity"` // 商品身份标识
|
||||
SpecId int64 `gorm:"column:spec_id;not null;" json:"spec_id"` // 规格ID
|
||||
|
||||
Spec MallProductSpec `gorm:"foreignKey:ID;references:SpecId;"` // 关联分类
|
||||
Product MallProduct `gorm:"foreignKey:ID;references:ProductId;"` // 关联商品
|
||||
}
|
||||
|
||||
func init() {
|
||||
database.AppendMigrate(&ProductSpec{})
|
||||
}
|
||||
|
||||
// TableName .
|
||||
func (table *ProductSpec) TableName() string {
|
||||
return "product_spec" //对应数据库表名
|
||||
}
|
||||
51
apps/ec/mall/internal/models/mall_product_photos.go
Normal file
51
apps/ec/mall/internal/models/mall_product_photos.go
Normal file
@@ -0,0 +1,51 @@
|
||||
// Models generated by mesh dev cli,@Author: David Yan(david.yan@qq.com).
|
||||
package models
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-ec/mall/internal/impl"
|
||||
"git.apinb.com/bsm-sdk/core/database"
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
/*
|
||||
* MallProductPhotos
|
||||
* Comment: 商品相册表
|
||||
* Version: 10
|
||||
* Created: 2022-04-12 15:36:17 , Updated:0001-01-01 00:00:00
|
||||
*/
|
||||
type MallProductPhotos struct {
|
||||
gorm.Model
|
||||
types.Std_Identity
|
||||
ProductID uint `gorm:"column:product_id;index;not null;" json:"product_id"` // 商品ID
|
||||
ProductIdentity string `gorm:"column:product_identity;type:varchar(255);default:'';" json:"product_identity"` // 商品唯一码
|
||||
Name string `gorm:"column:name;type:varchar(255);default:'';" json:"name"` // 说明
|
||||
Url string `gorm:"column:url;type:varchar(255);default:'';" json:"url"` // URL地址
|
||||
Sort int32 `gorm:"column:sort;default:0;" json:"sort"` // 排序
|
||||
|
||||
}
|
||||
|
||||
func init() {
|
||||
database.AppendMigrate(&MallProductPhotos{})
|
||||
}
|
||||
|
||||
// TableName .
|
||||
func (table *MallProductPhotos) TableName() string {
|
||||
return "mall_product_photos" //对应数据库表名
|
||||
}
|
||||
|
||||
// PhotoList 产品图片列表
|
||||
func PhotoList(identity string) ([]*MallProductPhotos, int32, error) {
|
||||
tx := impl.DBService.Where("product_identity = ?", identity)
|
||||
posts := make([]*MallProductPhotos, 0)
|
||||
var cnt int64 = 0
|
||||
tx.Order("created_at desc").Find(&posts).Count(&cnt)
|
||||
err := tx.Error
|
||||
return posts, int32(cnt), err
|
||||
}
|
||||
|
||||
// DelPhoto 删除图片
|
||||
func DelPhoto(identity string) (int64, error) {
|
||||
result := impl.DBService.Where("identity = ?", identity).Delete(&MallProductPhotos{})
|
||||
return result.RowsAffected, result.Error
|
||||
}
|
||||
61
apps/ec/mall/internal/models/mall_product_spec.go
Normal file
61
apps/ec/mall/internal/models/mall_product_spec.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-ec/mall/internal/impl"
|
||||
"git.apinb.com/bsm-sdk/core/database"
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// StoreProductSpec 商品规格
|
||||
type MallProductSpec struct {
|
||||
gorm.Model
|
||||
types.Std_Identity
|
||||
SupplyId int64 `gorm:"column:supply_id;default:0;supply_id;"` // 供应商ID
|
||||
SerialNumber string `gorm:"column:serial_number;type:varchar(36);Index;" json:"serial_number"` // 产品编号
|
||||
Title string `gorm:"column:title;type:varchar(255);not null;" json:"title"` // 类别名称
|
||||
StockType int32 `gorm:"column:stock_type;default:2;" json:"stock_type"` // 库存设置:1-设置库存限制,2-不设置库存限制
|
||||
Stock int64 `gorm:"column:stock;default:0;" json:"stock"` // 库存数量
|
||||
Price int64 `gorm:"column:price;default:0;" json:"price"` // 销售价格,单位:分
|
||||
DirectSales int64 `gorm:"column:direct_sales;default:0;" json:"direct_sales"` // 直营价格,单位:分
|
||||
PurchasingPrice int64 `gorm:"column:purchasing_price" json:"purchasing_price"` // 进货价 单位:分
|
||||
Wholesale int64 `gorm:"column:wholesale" json:"wholesale"` // 代理价 单位:分
|
||||
TpType int32 `gorm:"column:tp_type;default:2;" json:"tp_type"` // 阶梯价设置:1-启用,2-不启用
|
||||
DsTpType int32 `gorm:"column:ds_tp_type;default:2;" json:"ds_tp_type"` // 直营阶梯价设置:1-启用,2-不启用
|
||||
Img string `gorm:"column:img;type:varchar(255);default:'';" json:"img"` // 预览图
|
||||
StoreIdentity string `gorm:"column:store_identity;type:varchar(36);" json:"store_identity"` // 店铺唯一标识
|
||||
SpecNo string `gorm:"column:spec_no;type:varchar(36);" json:"spec_no"` // 规格编号
|
||||
Keyword string `gorm:"column:keyword;type:varchar(255);default:'';" json:"keyword"` // 关键词
|
||||
}
|
||||
|
||||
func init() {
|
||||
database.AppendMigrate(&MallProductSpec{})
|
||||
}
|
||||
|
||||
// TableName .
|
||||
func (table *MallProductSpec) TableName() string {
|
||||
return "mall_product_spec" //对应数据库表名
|
||||
}
|
||||
|
||||
// DetailSpec 规格详情
|
||||
func DetailSpec(identity string) (*MallProductSpec, error) {
|
||||
var data = &MallProductSpec{}
|
||||
tx := impl.DBService.Model(&MallProductSpec{}).Where("identity = ?", identity).Find(&data)
|
||||
return data, tx.Error
|
||||
}
|
||||
|
||||
// SpecList 规格列表
|
||||
func SpecList(page, size int64, identity string) ([]*MallProductSpec, int64, error) {
|
||||
tx := impl.DBService.Model(&MallProductSpec{}).Where("product_identity = ?", identity)
|
||||
posts := make([]*MallProductSpec, 0)
|
||||
var cnt int64 = 0
|
||||
tx.Order("created_at desc").Limit(int(size)).Offset(int((page - 1) * size)).Find(&posts).Count(&cnt)
|
||||
err := tx.Error
|
||||
return posts, cnt, err
|
||||
}
|
||||
|
||||
// DelSpec 删除规格
|
||||
func DelSpec(identity string) (int64, error) {
|
||||
result := impl.DBService.Where("identity = ?", identity).Delete(&MallProductSpec{})
|
||||
return result.RowsAffected, result.Error
|
||||
}
|
||||
41
apps/ec/mall/internal/models/mall_staff.go
Normal file
41
apps/ec/mall/internal/models/mall_staff.go
Normal file
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* @Author: ZhaoYadong
|
||||
* @Date: 2024-02-20 16:57:29
|
||||
* @LastEditors: ZhaoYadong
|
||||
* @LastEditTime: 2024-03-20 17:17:49
|
||||
* @FilePath: /org/internal/models/staff.go
|
||||
*/
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/database"
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
)
|
||||
|
||||
// Staff 店铺工作人员.
|
||||
type MallStaff struct {
|
||||
types.Std_IICUDS
|
||||
Std_Store
|
||||
Name string `gorm:"type:varchar(255);index;default:'';"` // 姓名
|
||||
Account string `gorm:"type:varchar(255);index;default:'';"` // 登录账号
|
||||
Password string `gorm:"type:varchar(255);default:'';"` // 登录密码
|
||||
Profile string `gorm:"type:varchar(255);default:'';"` // 个人说明
|
||||
Phone string `gorm:"type:varchar(20);uniqueIndex;default:'';"` // 手机号
|
||||
Email string `gorm:"type:varchar(255);default:'';"` // 邮箱
|
||||
Avatar string `gorm:"type:varchar(255);default:'';"` // 个人头像
|
||||
Role string `gorm:"type:varchar(36);index;default:'';"` // 角色类型: root 超级管理员、
|
||||
Salt string `gorm:"type:varchar(255);default:'';"` // 密码盐值
|
||||
LastLoginAt time.Time
|
||||
}
|
||||
|
||||
func init() {
|
||||
database.AppendMigrate(&MallStaff{})
|
||||
}
|
||||
|
||||
// TableName .
|
||||
func (MallStaff) TableName() string {
|
||||
return "mall_staff" //对应数据库表名
|
||||
}
|
||||
37
apps/ec/mall/internal/models/mall_store.go
Normal file
37
apps/ec/mall/internal/models/mall_store.go
Normal file
@@ -0,0 +1,37 @@
|
||||
// Models generated by mesh dev cli,@Author: David Yan(david.yan@qq.com).
|
||||
package models
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/core/database"
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
)
|
||||
|
||||
/*
|
||||
* MallStore
|
||||
* Comment: 电商系统-店铺信息表
|
||||
* Version: 10
|
||||
* Created: 2022-04-12 14:18:10 , Updated:0001-01-01 00:00:00
|
||||
*/
|
||||
type MallStore struct {
|
||||
types.Std_IICUDS
|
||||
Logo string `gorm:"column:logo;type:varchar(255);not null;" json:"logo"` // 公司logo
|
||||
Title string `gorm:"column:title;type:varchar(255);not null;" json:"title"` // 标题
|
||||
Intro string `gorm:"column:intro;type:varchar(255);default:'';" json:"intro"` // 描述说明
|
||||
Template string `gorm:"column:template;type:varchar(255);" json:"template"` // 模板
|
||||
Subdomain string `gorm:"column:subdomain;type:varchar(255);not null;" json:"subdomain"` //子域名设置
|
||||
Configs string `gorm:"column:configs;type:text;default:'';" json:"configs"` // 基础配置说明
|
||||
PayConfigs string `gorm:"column:pay_configs;type:text;default:'';" json:"pay_configs"` // 支付配置
|
||||
MailConfigs string `gorm:"column:mail_configs;type:text;default:'';" json:"mail_configs"` // 邮件服务器配置
|
||||
Keywords string `gorm:"column:keywords;type:varchar(255);default:'';" json:"keywords"` // SEO 关键词
|
||||
|
||||
Approve int8 `gorm:"column:approve;default:0;" json:"approve"` // 审核状态:0待审核,1审核通过,2审核失败
|
||||
}
|
||||
|
||||
func init() {
|
||||
database.AppendMigrate(&MallStore{})
|
||||
}
|
||||
|
||||
// TableName .
|
||||
func (table *MallStore) TableName() string {
|
||||
return "mall_store" //对应数据库表名
|
||||
}
|
||||
83
apps/ec/mall/internal/models/query.go
Normal file
83
apps/ec/mall/internal/models/query.go
Normal file
@@ -0,0 +1,83 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-ec/mall/internal/impl"
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
"git.apinb.com/bsm-sdk/core/utils"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ContentType int32
|
||||
|
||||
const (
|
||||
CONTENT_TYPE_TEXT ContentType = iota + 1 // 1.文本
|
||||
CONTENT_TYPE_IMAGE // 2.图片
|
||||
CONTENT_TYPE_VIDEO // 3.视频
|
||||
CONTENT_TYPE_AUDIO // 4.音频
|
||||
CONTENT_TYPE_LINK // 5.连接
|
||||
CONTENT_TYPE_ATTACHMENT // 6.附件
|
||||
)
|
||||
|
||||
const (
|
||||
// NormalStatus .
|
||||
NormalStatus = 1
|
||||
// DisabledStatus .
|
||||
DisabledStatus = -1
|
||||
)
|
||||
|
||||
type Std_Store struct {
|
||||
Store_ID uint `gorm:"primarykey;" json:"store_id"` // 店铺ID
|
||||
Store_Identity string `gorm:"column:store_identity;type:varchar(36);index;" json:"store_identity"` // 店铺唯一标识,24位NanoID,36位为ULID
|
||||
}
|
||||
|
||||
// 初始化数据
|
||||
func InitData() {
|
||||
CreateStore("to b", "localhost")
|
||||
}
|
||||
|
||||
func CreateStore(title, domain string) {
|
||||
var cnt int64 = 0
|
||||
|
||||
// 创建默认目录
|
||||
var store MallStore
|
||||
err := impl.DBService.Model(&MallStore{}).Where("subdomain=?", domain).First(&store).Error
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
store = MallStore{
|
||||
Title: title,
|
||||
Subdomain: domain,
|
||||
Std_IICUDS: types.Std_IICUDS{Identity: utils.UUID(), Status: NormalStatus},
|
||||
}
|
||||
impl.DBService.Create(&store)
|
||||
}
|
||||
|
||||
// 创建默认目录
|
||||
err = impl.DBService.Model(&MallStaff{}).Where("store_identity=? and account=?", store.Identity, "root").Count(&cnt).Error
|
||||
if cnt == 0 || err != nil {
|
||||
salt := utils.RandomString(8)
|
||||
root := &MallStaff{
|
||||
Std_Store: Std_Store{Store_ID: store.ID, Store_Identity: store.Identity},
|
||||
Account: "root",
|
||||
Password: utils.Md5("123456" + salt),
|
||||
Salt: salt,
|
||||
Role: "Mall_Admin",
|
||||
Std_IICUDS: types.Std_IICUDS{Identity: utils.UUID(), Status: 1},
|
||||
}
|
||||
impl.DBService.Create(root)
|
||||
}
|
||||
}
|
||||
|
||||
// GetCategoryList 获取分类列表
|
||||
func GetCategoryList(keyword, identity string, id int64) ([]*MallCategory, error) {
|
||||
tx := impl.DBService.Preload("Categories").Where("store_identity = ? ", identity).Where("parent_id = 0")
|
||||
if id != 0 {
|
||||
tx = tx.Where("id = ?", id)
|
||||
}
|
||||
if keyword != "" {
|
||||
tx = tx.Where("title like ?", "%"+keyword+"%")
|
||||
}
|
||||
|
||||
data := make([]*MallCategory, 0)
|
||||
tx.Order("created_at desc").Find(&data)
|
||||
err := tx.Error
|
||||
return data, err
|
||||
}
|
||||
Reference in New Issue
Block a user