feat:新增商户列表/保存用户信息
This commit is contained in:
@@ -10,6 +10,15 @@ import (
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
func (m *FsMerchantCategoryModel) BuilderDB(ctx context.Context, selectData []string) *gorm.DB {
|
||||
if selectData != nil {
|
||||
return m.db.WithContext(ctx).Select(selectData)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -140,22 +140,6 @@ func (t *FsProductTemplateV2Model) FindAllByModelIdsTemplateTag(ctx context.Cont
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// 获取产品某个物料下的第一个模板
|
||||
func (t *FsProductTemplateV2Model) GetSizeLatestTemplate(ctx context.Context, ids []int64, productId int64) (resp *FsProductTemplateV2, err error) {
|
||||
err = t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).
|
||||
Where("id in (?) and product_id = ? and status = ? and is_del = ?", ids, productId, 1, 0).
|
||||
Order("sort ASC").Take(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// 获取产品第一个物料下的第一个模板
|
||||
func (t *FsProductTemplateV2Model) GetProductLatestTemplate(ctx context.Context, ids []int64, productId int64) (resp *FsProductTemplateV2, err error) {
|
||||
err = t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).
|
||||
Where("id in (?) and product_id = ? and status = ? and is_del = ?", ids, productId, 1, 0).
|
||||
Order("sort ASC").Take(&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{}).
|
||||
|
||||
@@ -62,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 产品尺寸表
|
||||
@@ -159,7 +158,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