Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into feature/auth
This commit is contained in:
@@ -4,6 +4,7 @@ package gmodel
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type FindOneCartByParamsReq struct {
|
||||
@@ -94,3 +95,22 @@ func (c *FsCartModel) DeleteCartsByIds(ctx context.Context, ids []int64) ( err e
|
||||
}
|
||||
return c.db.Table(c.name).WithContext(ctx).Model(&FsCart{}).Where("`id` in (?)", ids).Update("status", 0).Error
|
||||
}
|
||||
|
||||
func (c *FsCartModel) RBDeleteCartsByIds(rowBuilder *gorm.DB,ids []int64) ( err error) {
|
||||
if len(ids) == 0 {
|
||||
return
|
||||
}
|
||||
return rowBuilder.Where("`id` in (?)", ids).Update("status", 0).Error
|
||||
}
|
||||
|
||||
func (c *FsCartModel) BuilderTrans(ctx context.Context,selectData []string) *gorm.DB {
|
||||
var rowBuilder = c.db.WithContext(ctx)
|
||||
|
||||
if selectData != nil {
|
||||
rowBuilder = rowBuilder.Select(selectData)
|
||||
} else {
|
||||
rowBuilder = rowBuilder.Select("*")
|
||||
}
|
||||
return rowBuilder
|
||||
}
|
||||
|
||||
|
||||
25
model/gmodel/fs_merchant_category_gen.go
Normal file
25
model/gmodel/fs_merchant_category_gen.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package gmodel
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// fs_merchant_category 商户类型表
|
||||
type FsMerchantCategory struct {
|
||||
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // Id
|
||||
ZnName *string `gorm:"default:'';" json:"zn_name"` // 中文名
|
||||
EnName *string `gorm:"default:'';" json:"en_name"` // 英文名
|
||||
Icon *string `gorm:"default:'';" json:"icon"` // 图标
|
||||
RecommendProduct *string `gorm:"default:'';" json:"recommend_product"` // 推荐商品
|
||||
Sort *int64 `gorm:"default:128;" json:"sort"` // 排序
|
||||
Status *int64 `gorm:"default:0;" json:"status"` // 状态
|
||||
Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间
|
||||
}
|
||||
type FsMerchantCategoryModel struct {
|
||||
db *gorm.DB
|
||||
name string
|
||||
}
|
||||
|
||||
func NewFsMerchantCategoryModel(db *gorm.DB) *FsMerchantCategoryModel {
|
||||
return &FsMerchantCategoryModel{db: db, name: "fs_merchant_category"}
|
||||
}
|
||||
13
model/gmodel/fs_merchant_category_logic.go
Normal file
13
model/gmodel/fs_merchant_category_logic.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package gmodel
|
||||
|
||||
import "context"
|
||||
|
||||
// TODO: 使用model的属性做你想做的
|
||||
func (m *FsMerchantCategoryModel) FindOne(ctx context.Context, id int64) (resp *FsMerchantCategory, err error) {
|
||||
err = m.db.WithContext(ctx).Model(&FsMerchantCategory{}).Where("id = ? and status = ?", id, 1).Take(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
func (m *FsMerchantCategoryModel) FindRandOne(ctx context.Context) (resp *FsMerchantCategory, err error) {
|
||||
err = m.db.WithContext(ctx).Model(&FsMerchantCategory{}).Where("status = ?", 1).Order("RAND()").Take(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
@@ -26,6 +26,10 @@ func (dt *FsOrderDetailTemplateModel) FindOne(ctx context.Context, id int64) (re
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (dt *FsOrderDetailTemplateModel) RBCreate(ctx context.Context, data *FsOrderDetailTemplate) error {
|
||||
return dt.db.WithContext(ctx).Create(&data).Error
|
||||
}
|
||||
|
||||
func (m *FsOrderDetailTemplateModel) TableName() string {
|
||||
return m.name
|
||||
}
|
||||
|
||||
@@ -28,6 +28,10 @@ func (o *FsOrderModel) Update(ctx context.Context, data *FsOrder) error {
|
||||
return o.db.WithContext(ctx).Model(&FsOrder{}).Where("`id` = ?", data.Id).Updates(&data).Error
|
||||
}
|
||||
|
||||
func (o *FsOrderModel) RBUpdate(ctx context.Context, data *FsOrder) error {
|
||||
return o.db.WithContext(ctx).Where("`id` = ?", data.Id).Updates(&data).Error
|
||||
}
|
||||
|
||||
func (o *FsOrderModel) Create(ctx context.Context, data *FsOrder) error {
|
||||
return o.db.WithContext(ctx).Model(&FsOrder{}).Create(&data).Error
|
||||
}
|
||||
@@ -120,6 +124,17 @@ func (m *FsOrderModel) RowSelectBuilder(selectData []string) *gorm.DB {
|
||||
return rowBuilder
|
||||
}
|
||||
|
||||
func (m *FsOrderModel) BuilderTrans(selectData []string) *gorm.DB {
|
||||
var rowBuilder = m.db
|
||||
|
||||
if selectData != nil {
|
||||
rowBuilder = rowBuilder.Select(selectData)
|
||||
} else {
|
||||
rowBuilder = rowBuilder.Select("*")
|
||||
}
|
||||
return rowBuilder
|
||||
}
|
||||
|
||||
func (m *FsOrderModel) FindCount(ctx context.Context, countBuilder *gorm.DB, filterMap map[string]string) (int64, error) {
|
||||
var count int64
|
||||
|
||||
|
||||
@@ -29,6 +29,14 @@ func (p *FsPayModel) GetListByOrderNumberStage(ctx context.Context, sn string, s
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (p *FsPayModel) RBGetListByOrderNumberStage(ctx context.Context, sn string, stage int64) (resp *FsPay, err error) {
|
||||
err = p.db.WithContext(ctx).Where("`order_number` = ? ", sn).Where("`pay_stage` = ? ", stage).Take(&resp).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (p *FsPayModel) CreateOrUpdate(ctx context.Context, req *FsPay) (resp *FsPay, err error) {
|
||||
rowBuilder := p.db.Table(p.name).WithContext(ctx)
|
||||
if req.Id > 0 {
|
||||
@@ -39,6 +47,16 @@ func (p *FsPayModel) CreateOrUpdate(ctx context.Context, req *FsPay) (resp *FsPa
|
||||
return req, err
|
||||
}
|
||||
|
||||
func (p *FsPayModel) RBCreateOrUpdate(ctx context.Context, req *FsPay) (resp *FsPay, err error) {
|
||||
rowBuilder := p.db.WithContext(ctx)
|
||||
if req.Id > 0 {
|
||||
err = rowBuilder.Save(req).Error
|
||||
} else {
|
||||
err = rowBuilder.Create(req).Error
|
||||
}
|
||||
return req, err
|
||||
}
|
||||
|
||||
func (m *FsPayModel) RowSelectBuilder(selectData []string) *gorm.DB {
|
||||
var rowBuilder = m.db.Table(m.name)
|
||||
|
||||
@@ -50,6 +68,17 @@ func (m *FsPayModel) RowSelectBuilder(selectData []string) *gorm.DB {
|
||||
return rowBuilder
|
||||
}
|
||||
|
||||
func (m *FsPayModel) BuilderTrans(selectData []string) *gorm.DB {
|
||||
var rowBuilder = m.db
|
||||
|
||||
if selectData != nil {
|
||||
rowBuilder = rowBuilder.Select(selectData)
|
||||
} else {
|
||||
rowBuilder = rowBuilder.Select("*")
|
||||
}
|
||||
return rowBuilder
|
||||
}
|
||||
|
||||
func (m *FsPayModel) FindCount(ctx context.Context, countBuilder *gorm.DB, filterMap map[string]string) (int64, error) {
|
||||
var count int64
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ package gmodel
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func (d *FsProductDesignModel) FindOneBySn(ctx context.Context, sn string, userId int64) (resp *FsProductDesign, err error) {
|
||||
@@ -39,6 +41,21 @@ func (d *FsProductDesignModel) UpdateByIds(ctx context.Context, ids []int64, dat
|
||||
return d.db.Table(d.name).WithContext(ctx).Model(&FsProductDesign{}).Where("`id` in ?", ids).Updates(&data).Error
|
||||
}
|
||||
|
||||
func (d *FsProductDesignModel) RBUpdateByIds(rowBuilder *gorm.DB, ids []int64, data *FsProductDesign) error {
|
||||
return rowBuilder.Where("`id` in ?", ids).Updates(&data).Error
|
||||
}
|
||||
|
||||
func (m *FsProductDesignModel) BuilderTrans(ctx context.Context, selectData []string) *gorm.DB {
|
||||
var rowBuilder = m.db.WithContext(ctx)
|
||||
|
||||
if selectData != nil {
|
||||
rowBuilder = rowBuilder.Select(selectData)
|
||||
} else {
|
||||
rowBuilder = rowBuilder.Select("*")
|
||||
}
|
||||
return rowBuilder
|
||||
}
|
||||
|
||||
func (m *FsProductDesignModel) TableName() string {
|
||||
return m.name
|
||||
}
|
||||
|
||||
@@ -101,3 +101,14 @@ func (d *FsProductModel3dModel) FindOneJoinSize(ctx context.Context, productId i
|
||||
Order("s.sort ASC").Take(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (d *FsProductModel3dModel) GetOneBySizeIdTag(ctx context.Context, sizeId int64, tag int64, fields ...string) (resp *FsProductModel3d, err error) {
|
||||
db := d.db.WithContext(ctx).Model(&FsProductModel3d{}).
|
||||
Where("`size_id` = ? and `tag` = ? and `status` = ?", sizeId, tag, 1).
|
||||
Order("sort DESC")
|
||||
if len(fields) != 0 {
|
||||
db = db.Select(fields[0])
|
||||
}
|
||||
err = db.Take(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
package gmodel
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// fs_product_recommend 推荐商品表
|
||||
type FsProductRecommend struct {
|
||||
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` //
|
||||
ProductId *int64 `gorm:"default:0;" json:"product_id"` // 产品ID
|
||||
Status *int64 `gorm:"default:1;" json:"status"` // 状态 1正常 0不正常
|
||||
Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间
|
||||
}
|
||||
type FsProductRecommendModel struct {
|
||||
db *gorm.DB
|
||||
name string
|
||||
}
|
||||
|
||||
func NewFsProductRecommendModel(db *gorm.DB) *FsProductRecommendModel {
|
||||
return &FsProductRecommendModel{db: db, name: "fs_product_recommend"}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
package gmodel
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type GetRecommendProductListReq struct {
|
||||
Ctx context.Context
|
||||
Page int
|
||||
Limit int
|
||||
}
|
||||
|
||||
func (r *FsProductRecommendModel) GetRecommendProductList(req GetRecommendProductListReq) (resp []FsProduct, total int64, err error) {
|
||||
db := r.db.WithContext(req.Ctx).
|
||||
Table("fs_product_recommend as r").
|
||||
Joins("inner join fs_product as p on r.product_id = p.id").
|
||||
Where("r.status = ? ", 1).
|
||||
Where("p.is_shelf = ? and p.is_del = ? and p.status = ?", 1, 0, 1)
|
||||
if err = db.Limit(1).Count(&total).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
db = db.Select("p.*")
|
||||
offset := (req.Page - 1) * req.Limit
|
||||
err = db.Offset(offset).Limit(req.Limit).Find(&resp).Error
|
||||
return resp, total, err
|
||||
}
|
||||
func (r *FsProductRecommendModel) CreateOrUpdate(ctx context.Context, productId int64, data *FsProductRecommend) error {
|
||||
var info FsProductRecommend
|
||||
err := r.db.WithContext(ctx).Model(&FsProductRecommend{}).Where("`product_id` = ?", productId).Take(&info).Error
|
||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return err
|
||||
}
|
||||
if info.Id == 0 {
|
||||
return r.db.WithContext(ctx).Model(&FsProductRecommend{}).Create(data).Error
|
||||
}
|
||||
return r.db.WithContext(ctx).Model(&FsProductRecommend{}).Where("`product_id` = ?", productId).Updates(data).Error
|
||||
}
|
||||
@@ -9,20 +9,21 @@ type FsProductTemplateV2 struct {
|
||||
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` //
|
||||
ProductId *int64 `gorm:"index;default:0;" json:"product_id"` // 产品ID
|
||||
ModelId *int64 `gorm:"default:0;" json:"model_id"` // 模型ID
|
||||
Title *string `gorm:"default:'';" json:"title"` // 模板(sku),预留字段
|
||||
Name *string `gorm:"default:'';" json:"name"` // 名称
|
||||
CoverImg *string `gorm:"default:'';" json:"cover_img"` // 模板背景图
|
||||
TemplateInfo *string `gorm:"default:'';" json:"template_info"` // 模板详情
|
||||
MaterialImg *string `gorm:"default:'';" json:"material_img"` // 合成好的贴图
|
||||
Title *string `gorm:"default:'';" json:"title"` //
|
||||
Name *string `gorm:"default:'';" json:"name"` //
|
||||
CoverImg *string `gorm:"default:'';" json:"cover_img"` //
|
||||
TemplateInfo *string `gorm:"default:'';" json:"template_info"` //
|
||||
MaterialImg *string `gorm:"default:'';" json:"material_img"` //
|
||||
Sort *int64 `gorm:"default:0;" json:"sort"` // 排序
|
||||
LogoWidth *int64 `gorm:"default:0;" json:"logo_width"` // logo图最大宽度
|
||||
LogoHeight *int64 `gorm:"default:0;" json:"logo_height"` // logo图最大高度
|
||||
IsPublic *int64 `gorm:"default:0;" json:"is_public"` // 是否可公用(1:可以,0:不可以)
|
||||
Status *int64 `gorm:"default:0;" json:"status"` // 状态1正常 2异常
|
||||
Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间
|
||||
Tag *string `gorm:"default:'';" json:"tag"` // 标签(用户自填)
|
||||
Tag *string `gorm:"default:'';" json:"tag"` //
|
||||
IsDel *int64 `gorm:"default:0;" json:"is_del"` // 是否删除 1删除
|
||||
GroupOptions *string `gorm:"default:'';" json:"group_options"` // 颜色分组
|
||||
SwitchInfo *string `gorm:"default:'';" json:"switch_info"` //
|
||||
GroupOptions *string `gorm:"default:'';" json:"group_options"` //
|
||||
Version *int64 `gorm:"default:0;" json:"version"` //
|
||||
}
|
||||
type FsProductTemplateV2Model struct {
|
||||
|
||||
@@ -139,3 +139,14 @@ func (t *FsProductTemplateV2Model) FindAllByModelIdsTemplateTag(ctx context.Cont
|
||||
err = db.Find(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// 获取产品在指定模板标签下的所有模板
|
||||
func (t *FsProductTemplateV2Model) GetListByProductAndTemplateTag(ctx context.Context, templateTagId string, productId int64, fields ...string) (resp []FsProductTemplateV2, err error) {
|
||||
db := t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).
|
||||
Where("tag = ? and product_id = ? and status = ? and is_del = ?", templateTagId, productId, 1, 0)
|
||||
if len(fields) > 0 {
|
||||
db = db.Select(fields[0])
|
||||
}
|
||||
err = db.Find(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
|
||||
@@ -36,6 +36,16 @@ func (m *FsRefundReasonModel) CreateOrUpdate(ctx context.Context, req *FsRefundR
|
||||
return req, err
|
||||
}
|
||||
|
||||
func (m *FsRefundReasonModel) RBCreateOrUpdate(ctx context.Context, req *FsRefundReason) (resp *FsRefundReason, err error) {
|
||||
rowBuilder := m.db.WithContext(ctx)
|
||||
if req.Id > 0 {
|
||||
err = rowBuilder.Save(req).Error
|
||||
} else {
|
||||
err = rowBuilder.Create(req).Error
|
||||
}
|
||||
return req, err
|
||||
}
|
||||
|
||||
func (m *FsRefundReasonModel) FindOneByQuery(ctx context.Context, rowBuilder *gorm.DB, filterMap map[string]string) (*FsRefundReason, error) {
|
||||
var resp FsRefundReason
|
||||
|
||||
@@ -62,6 +72,16 @@ func (m *FsRefundReasonModel) RowSelectBuilder(selectData []string) *gorm.DB {
|
||||
return rowBuilder
|
||||
}
|
||||
|
||||
func (m *FsRefundReasonModel) BuilderTrans(selectData []string) *gorm.DB {
|
||||
var rowBuilder = m.db
|
||||
if selectData != nil {
|
||||
rowBuilder = rowBuilder.Select(selectData)
|
||||
} else {
|
||||
rowBuilder = rowBuilder.Select("*")
|
||||
}
|
||||
return rowBuilder
|
||||
}
|
||||
|
||||
func (m *FsRefundReasonModel) TableName() string {
|
||||
return m.name
|
||||
}
|
||||
|
||||
@@ -24,6 +24,16 @@ func (p *FsResourceModel) Update(ctx context.Context, req *FsResource) (resp *Fs
|
||||
return req, err
|
||||
}
|
||||
|
||||
func (p *FsResourceModel) BuilderCreate(ctx context.Context, rowBuilder *gorm.DB, req *FsResource) (resp *FsResource, err error) {
|
||||
err = rowBuilder.WithContext(ctx).Create(req).Error
|
||||
return req, err
|
||||
}
|
||||
|
||||
func (p *FsResourceModel) BuilderUpdate(ctx context.Context, rowBuilder *gorm.DB, req *FsResource) (resp *FsResource, err error) {
|
||||
err = rowBuilder.WithContext(ctx).Where("resource_id =?", req.ResourceId).Save(req).Error
|
||||
return req, err
|
||||
}
|
||||
|
||||
func (m *FsResourceModel) FindOneByQuery(ctx context.Context, rowBuilder *gorm.DB, filterMap map[string]string) (*FsResource, error) {
|
||||
var resp FsResource
|
||||
|
||||
@@ -50,6 +60,17 @@ func (m *FsResourceModel) RowSelectBuilder(selectData []string) *gorm.DB {
|
||||
return rowBuilder
|
||||
}
|
||||
|
||||
func (m *FsResourceModel) BuilderTrans(selectData []string) *gorm.DB {
|
||||
var rowBuilder = m.db
|
||||
|
||||
if selectData != nil {
|
||||
rowBuilder = rowBuilder.Select(selectData)
|
||||
} else {
|
||||
rowBuilder = rowBuilder.Select("*")
|
||||
}
|
||||
return rowBuilder
|
||||
}
|
||||
|
||||
// 事务
|
||||
func (m *FsResourceModel) Trans(ctx context.Context, fn func(ctx context.Context, connGorm *gorm.DB) error) error {
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ type AllModelsGen struct {
|
||||
FsLog *FsLogModel // fs_log 日志表
|
||||
FsMapLibrary *FsMapLibraryModel // fs_map_library 贴图库
|
||||
FsMenu *FsMenuModel // fs_menu 后台菜单
|
||||
FsMerchantCategory *FsMerchantCategoryModel // fs_merchant_category 商户类型表
|
||||
FsMigration *FsMigrationModel // fs_migration 版本库
|
||||
FsOrder *FsOrderModel // fs_order
|
||||
FsOrderAffiliate *FsOrderAffiliateModel // fs_order_affiliate 订单附属表-流程控制时间等
|
||||
@@ -61,7 +62,6 @@ type AllModelsGen struct {
|
||||
FsProductModel3dLight *FsProductModel3dLightModel // fs_product_model3d_light 模型-灯光组表
|
||||
FsProductOption *FsProductOptionModel // fs_product_option 产品选项表(已废弃)
|
||||
FsProductPrice *FsProductPriceModel // fs_product_price 阶梯价格表
|
||||
FsProductRecommend *FsProductRecommendModel // fs_product_recommend 推荐商品表
|
||||
FsProductRenderDesign *FsProductRenderDesignModel // fs_product_render_design
|
||||
FsProductScene *FsProductSceneModel // fs_product_scene 产品场景表
|
||||
FsProductSize *FsProductSizeModel // fs_product_size 产品尺寸表
|
||||
@@ -139,6 +139,7 @@ func NewAllModels(gdb *gorm.DB) *AllModelsGen {
|
||||
FsLog: NewFsLogModel(gdb),
|
||||
FsMapLibrary: NewFsMapLibraryModel(gdb),
|
||||
FsMenu: NewFsMenuModel(gdb),
|
||||
FsMerchantCategory: NewFsMerchantCategoryModel(gdb),
|
||||
FsMigration: NewFsMigrationModel(gdb),
|
||||
FsOrder: NewFsOrderModel(gdb),
|
||||
FsOrderAffiliate: NewFsOrderAffiliateModel(gdb),
|
||||
@@ -155,7 +156,6 @@ func NewAllModels(gdb *gorm.DB) *AllModelsGen {
|
||||
FsProductModel3dLight: NewFsProductModel3dLightModel(gdb),
|
||||
FsProductOption: NewFsProductOptionModel(gdb),
|
||||
FsProductPrice: NewFsProductPriceModel(gdb),
|
||||
FsProductRecommend: NewFsProductRecommendModel(gdb),
|
||||
FsProductRenderDesign: NewFsProductRenderDesignModel(gdb),
|
||||
FsProductScene: NewFsProductSceneModel(gdb),
|
||||
FsProductSize: NewFsProductSizeModel(gdb),
|
||||
|
||||
Reference in New Issue
Block a user