fix
This commit is contained in:
parent
ff05e127bd
commit
b1393950f2
|
@ -1,4 +1,6 @@
|
||||||
package gorm
|
package gmodel
|
||||||
|
|
||||||
|
import "gorm.io/gorm"
|
||||||
|
|
||||||
type FsAddress struct {
|
type FsAddress struct {
|
||||||
Id int64 `gorm:"primary_key" json:"id"`
|
Id int64 `gorm:"primary_key" json:"id"`
|
||||||
|
@ -16,3 +18,11 @@ type FsAddress struct {
|
||||||
Status *int64 `gorm:"default:1" json:"status"` // 1正常 0异常
|
Status *int64 `gorm:"default:1" json:"status"` // 1正常 0异常
|
||||||
IsDefault *int64 `gorm:"default:0" json:"is_default"` // 1默认地址,0非默认地址
|
IsDefault *int64 `gorm:"default:0" json:"is_default"` // 1默认地址,0非默认地址
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type FsAddressModel struct {
|
||||||
|
db *gorm.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFsAddressModel(db *gorm.DB) *FsAddressModel {
|
||||||
|
return &FsAddressModel{db}
|
||||||
|
}
|
42
model/gmodel/fscanteenproductmodel.go
Executable file
42
model/gmodel/fscanteenproductmodel.go
Executable file
|
@ -0,0 +1,42 @@
|
||||||
|
package gmodel
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type FsCanteenProduct struct {
|
||||||
|
Id int64 `gorm:"primary_key" json:"id"` // ID
|
||||||
|
CanteenType *int64 `gorm:"default:0" json:"canteen_type"` // 餐厅类别id
|
||||||
|
ProductId *int64 `gorm:"default:0" json:"product_id"` // 产品id
|
||||||
|
SizeId *int64 `gorm:"default:0" json:"size_id"` // 尺寸id
|
||||||
|
Sort *int64 `gorm:"default:0" json:"sort"` // 排序
|
||||||
|
Status *int64 `gorm:"default:1" json:"status"` // 状态位 1启用0停用
|
||||||
|
Ctime *int64 `gorm:"default:0" json:"ctime"` // 添加时间
|
||||||
|
Sid *string `gorm:"default:''" json:"sid"` // 前端带入的id
|
||||||
|
}
|
||||||
|
|
||||||
|
type FsCanteenProductModel struct {
|
||||||
|
db *gorm.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFsCanteenProductModel(db *gorm.DB) *FsCanteenProductModel {
|
||||||
|
return &FsCanteenProductModel{db}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *FsCanteenProductModel) GetAllByCanteenTypeId(ctx context.Context, typeId int64) (resp []FsCanteenProduct, err error) {
|
||||||
|
err = c.db.WithContext(ctx).Model(&FsCanteenProduct{}).Where("`canteen_type` = ? and `status` = ?", typeId, 1).Find(&resp).Error
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
func (c *FsCanteenProductModel) UpdateById(ctx context.Context, id int64, data *FsCanteenProduct) error {
|
||||||
|
return c.db.WithContext(ctx).Model(&FsCanteenProduct{}).Where("`id` = ? ", id).Updates(&data).Error
|
||||||
|
}
|
||||||
|
func (c *FsCanteenProductModel) UpdateByIdArr(ctx context.Context, ids []int64, data *FsCanteenProduct) error {
|
||||||
|
return c.db.WithContext(ctx).Model(&FsCanteenProduct{}).Where("`id` in (?) ", ids).Updates(&data).Error
|
||||||
|
}
|
||||||
|
func (c *FsCanteenProductModel) Create(ctx context.Context, data *FsCanteenProduct) error {
|
||||||
|
return c.db.WithContext(ctx).Model(&FsCanteenProduct{}).Create(data).Error
|
||||||
|
}
|
30
model/gmodel/fscanteentypemodel.go
Executable file
30
model/gmodel/fscanteentypemodel.go
Executable file
|
@ -0,0 +1,30 @@
|
||||||
|
package gmodel
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type FsCanteenType struct {
|
||||||
|
Id int64 `gorm:"primary_key" json:"id"` // ID
|
||||||
|
Name *string `gorm:"default:''" json:"name"` // 餐厅名字
|
||||||
|
Sort *int64 `gorm:"default:0" json:"sort"` // 排序
|
||||||
|
Status *int64 `gorm:"default:1" json:"status"` // 状态位 1启用0停用
|
||||||
|
Ctime *int64 `gorm:"default:0" json:"ctime"` // 添加时间
|
||||||
|
}
|
||||||
|
type FsCanteenTypeModel struct {
|
||||||
|
db *gorm.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFsCanteenTypeModel(db *gorm.DB) *FsCanteenTypeModel {
|
||||||
|
return &FsCanteenTypeModel{db}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *FsCanteenTypeModel) FindOne(ctx context.Context, id int64) (resp FsCanteenType, err error) {
|
||||||
|
err = c.db.WithContext(ctx).Model(&FsCanteenType{}).Where("`id` = ? and `status` = ? ", id, 1).First(&resp).Error
|
||||||
|
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
return FsCanteenType{}, err
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
|
@ -1,6 +1,9 @@
|
||||||
package gorm
|
package gmodel
|
||||||
|
|
||||||
import "database/sql"
|
import (
|
||||||
|
"database/sql"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
type FsFaq struct {
|
type FsFaq struct {
|
||||||
Id int64 `gorm:"primary_key" json:"id"`
|
Id int64 `gorm:"primary_key" json:"id"`
|
||||||
|
@ -12,3 +15,10 @@ type FsFaq struct {
|
||||||
Sort *int64 `gorm:"default:0" json:"sort"` // 排序
|
Sort *int64 `gorm:"default:0" json:"sort"` // 排序
|
||||||
Ctime *sql.NullInt64 `gorm:"default:0" json:"ctime"` // 添加时间
|
Ctime *sql.NullInt64 `gorm:"default:0" json:"ctime"` // 添加时间
|
||||||
}
|
}
|
||||||
|
type FsFaqModel struct {
|
||||||
|
db *gorm.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFsFaqModel(db *gorm.DB) *FsFaqModel {
|
||||||
|
return &FsFaqModel{db}
|
||||||
|
}
|
|
@ -1,4 +1,6 @@
|
||||||
package gorm
|
package gmodel
|
||||||
|
|
||||||
|
import "gorm.io/gorm"
|
||||||
|
|
||||||
type FsFont struct {
|
type FsFont struct {
|
||||||
Id int64 `gorm:"primary_key" json:"id"` // id
|
Id int64 `gorm:"primary_key" json:"id"` // id
|
||||||
|
@ -7,3 +9,10 @@ type FsFont struct {
|
||||||
FilePath *string `gorm:"default:''" json:"file_path"` // 字体文件路径
|
FilePath *string `gorm:"default:''" json:"file_path"` // 字体文件路径
|
||||||
Sort *int64 `gorm:"default:0" json:"sort"` // 排序
|
Sort *int64 `gorm:"default:0" json:"sort"` // 排序
|
||||||
}
|
}
|
||||||
|
type FsFontModel struct {
|
||||||
|
db *gorm.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFsFontModel(db *gorm.DB) *FsFontModel {
|
||||||
|
return &FsFontModel{db}
|
||||||
|
}
|
|
@ -1,4 +1,9 @@
|
||||||
package gorm
|
package gmodel
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
type FsProduct struct {
|
type FsProduct struct {
|
||||||
Id int64 `gorm:"primary_key" json:"id"`
|
Id int64 `gorm:"primary_key" json:"id"`
|
||||||
|
@ -31,3 +36,48 @@ type FsProduct struct {
|
||||||
RecommendProductSort *string `gorm:"default:''" json:"recommend_product_sort"` // 推荐排序例如:1324
|
RecommendProductSort *string `gorm:"default:''" json:"recommend_product_sort"` // 推荐排序例如:1324
|
||||||
SceneIds *string `gorm:"default:''" json:"scene_ids"` // 关联的场景id
|
SceneIds *string `gorm:"default:''" json:"scene_ids"` // 关联的场景id
|
||||||
}
|
}
|
||||||
|
type FsProductModel struct {
|
||||||
|
db *gorm.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFsProductModel(db *gorm.DB) *FsProductModel {
|
||||||
|
return &FsProductModel{db}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *FsProductModel) GetProductListByIds(ctx context.Context, productIds []int64, sort string) (resp []FsProduct, err error) {
|
||||||
|
db := p.db.Model(&FsProduct{}).
|
||||||
|
Where("`id` in (?) and `is_del` =? and `is_shelf` = ? and `status` =?", productIds, 0, 1, 1)
|
||||||
|
switch sort {
|
||||||
|
case "sort-asc":
|
||||||
|
db = db.Order("sort ASC")
|
||||||
|
case "sort-desc":
|
||||||
|
db = db.Order("sort DESC")
|
||||||
|
}
|
||||||
|
if err = db.Find(&resp).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *FsProductModel) GetProductListByTypeIds(ctx context.Context, productTypes []int64, sort string) (resp []FsProduct, err error) {
|
||||||
|
db := p.db.WithContext(ctx).Model(&FsProductModel{}).Where("`type` in (?) and `is_del` =? and `is_shelf` = ? and `status` =?", productTypes, 0, 1, 1)
|
||||||
|
switch sort {
|
||||||
|
case "sort-asc":
|
||||||
|
db = db.Order("`sort` ASC")
|
||||||
|
case "sort-desc":
|
||||||
|
db = db.Order("`sort` DESC")
|
||||||
|
}
|
||||||
|
err = db.Find(&resp).Error
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (p *FsProductModel) GetRandomProductList(ctx context.Context, limit int) (resp []FsProduct, err error) {
|
||||||
|
err = p.db.WithContext(ctx).Model(&FsProductModel{}).
|
||||||
|
Where("`is_del` =? and `is_shelf` = ?", 0, 1).Order("RAND()").Limit(limit).Find(&resp).Error
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
|
@ -1,4 +1,6 @@
|
||||||
package gorm
|
package gmodel
|
||||||
|
|
||||||
|
import "gorm.io/gorm"
|
||||||
|
|
||||||
type FsProductModel3dLight struct {
|
type FsProductModel3dLight struct {
|
||||||
Id int64 `gorm:"primary_key" json:"id"`
|
Id int64 `gorm:"primary_key" json:"id"`
|
||||||
|
@ -7,3 +9,10 @@ type FsProductModel3dLight struct {
|
||||||
Status *int64 `gorm:"default:1" json:"status"` // 状态值(1:显示,0:删除)
|
Status *int64 `gorm:"default:1" json:"status"` // 状态值(1:显示,0:删除)
|
||||||
Ctime *int64 `gorm:"default:0" json:"ctime"` // 创建时间
|
Ctime *int64 `gorm:"default:0" json:"ctime"` // 创建时间
|
||||||
}
|
}
|
||||||
|
type FsProductModel3dLightModel struct {
|
||||||
|
db *gorm.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFsProductModel3dLightModel(db *gorm.DB) *FsProductModel3dLightModel {
|
||||||
|
return &FsProductModel3dLightModel{db}
|
||||||
|
}
|
|
@ -1,4 +1,6 @@
|
||||||
package gorm
|
package gmodel
|
||||||
|
|
||||||
|
import "gorm.io/gorm"
|
||||||
|
|
||||||
type FsProductModel3d struct {
|
type FsProductModel3d struct {
|
||||||
Id int64 `gorm:"primary_key" json:"id"`
|
Id int64 `gorm:"primary_key" json:"id"`
|
||||||
|
@ -20,3 +22,10 @@ type FsProductModel3d struct {
|
||||||
Price *int64 `gorm:"default:0" json:"price"` // 仅配件用,配件的价格, 单位:美分
|
Price *int64 `gorm:"default:0" json:"price"` // 仅配件用,配件的价格, 单位:美分
|
||||||
Sku *string `gorm:"default:''" json:"sku"` // sku
|
Sku *string `gorm:"default:''" json:"sku"` // sku
|
||||||
}
|
}
|
||||||
|
type FsProductModel3dModel struct {
|
||||||
|
db *gorm.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFsProductModel3dModel(db *gorm.DB) *FsProductModel3dModel {
|
||||||
|
return &FsProductModel3dModel{db}
|
||||||
|
}
|
|
@ -1,4 +1,9 @@
|
||||||
package gorm
|
package gmodel
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
type FsProductPrice struct {
|
type FsProductPrice struct {
|
||||||
Id int64 `gorm:"primary_key" json:"id"`
|
Id int64 `gorm:"primary_key" json:"id"`
|
||||||
|
@ -15,3 +20,34 @@ type FsProductPrice struct {
|
||||||
Status *int64 `gorm:"default:1" json:"status"` // 是否可用
|
Status *int64 `gorm:"default:1" json:"status"` // 是否可用
|
||||||
IsDefault *int64 `gorm:"default:0" json:"is_default"` // 是否默认
|
IsDefault *int64 `gorm:"default:0" json:"is_default"` // 是否默认
|
||||||
}
|
}
|
||||||
|
type FsProductPriceModel struct {
|
||||||
|
db *gorm.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFsProductPriceModel(db *gorm.DB) *FsProductPriceModel {
|
||||||
|
return &FsProductPriceModel{db}
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetPriceListByProductIdsRsp struct {
|
||||||
|
ProductId int64 `json:"product_id"`
|
||||||
|
Price string `json:"price"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *FsProductPriceModel) GetPriceListByProductIds(ctx context.Context, productIds []int64) (resp []GetPriceListByProductIdsRsp, err error) {
|
||||||
|
if len(productIds) == 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
db := p.db.WithContext(ctx).Model(&FsProductPriceModel{}).Select("product_id,group_concat(step_price) as price").
|
||||||
|
Where("`product_id` in (?) and `status` = ? group by product_id", productIds, 1)
|
||||||
|
if err = db.Find(&resp).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (p *FsProductPriceModel) GetPriceListBySizeIds(ctx context.Context, sizeIds []int64) (resp []FsProductPrice, err error) {
|
||||||
|
err = p.db.WithContext(ctx).Model(&FsProductPriceModel{}).Where("`size_id` in (?) and `status` = ? ", sizeIds, 1).Find(&resp).Error
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
61
model/gmodel/fsproductsizemodel.go
Executable file
61
model/gmodel/fsproductsizemodel.go
Executable file
|
@ -0,0 +1,61 @@
|
||||||
|
package gmodel
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type FsProductSize struct {
|
||||||
|
Id int64 `gorm:"primary_key" json:"id"`
|
||||||
|
ProductId *int64 `gorm:"default:0" json:"product_id"` // 产品ID
|
||||||
|
Title *string `gorm:"default:''" json:"title"` // 标题 10*10*20
|
||||||
|
Cover *string `gorm:"default:''" json:"cover"` // 封面图
|
||||||
|
CoverImg *string `gorm:"default:''" json:"cover_img"` // 背景图
|
||||||
|
Capacity *string `gorm:"default:''" json:"capacity"` // 自己填的尺寸名称
|
||||||
|
Status *int64 `gorm:"default:1" json:"status"` // 状态位 1显示 0删除
|
||||||
|
Sort *int64 `gorm:"default:50" json:"sort"` // 排序
|
||||||
|
Remark *string `gorm:"default:''" json:"remark"` // 备注信息
|
||||||
|
PartsCanDeleted *int64 `gorm:"default:1" json:"parts_can_deleted"` // 配件是否可移除 1是0否
|
||||||
|
}
|
||||||
|
type FsProductSizeModel struct {
|
||||||
|
db *gorm.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFsProductSizeModel(db *gorm.DB) *FsProductSizeModel {
|
||||||
|
return &FsProductSizeModel{db}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *FsProductSizeModel) GetAllByIds(ctx context.Context, ids []int64, sort string) (resp []FsProductSize, err error) {
|
||||||
|
db := s.db.Model(&FsProductSizeModel{}).Where("`id` in (?) and `status` = ?", ids, 1)
|
||||||
|
switch sort {
|
||||||
|
case "sort-asc":
|
||||||
|
db = db.Order("`sort` ASC")
|
||||||
|
case "sort-desc":
|
||||||
|
db = db.Order("`sort` DESC")
|
||||||
|
}
|
||||||
|
if err = db.Find(&resp).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (s *FsProductSizeModel) CountByStatus(ctx context.Context, status int) (total int64, err error) {
|
||||||
|
err = s.db.WithContext(ctx).Model(&FsProductSizeModel{}).Where("`status` = ? ", status).Count(&total).Error
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (s *FsProductSizeModel) GetAllByProductIds(ctx context.Context, productIds []int64, sort string) (resp []FsProductSize, err error) {
|
||||||
|
db := s.db.WithContext(ctx).Model(&FsProductSizeModel{}).Where("`product_id` in(?) and `status` = ?", productIds, 1)
|
||||||
|
switch sort {
|
||||||
|
case "sort-asc":
|
||||||
|
db = db.Order("`sort` ASC")
|
||||||
|
case "sort-desc":
|
||||||
|
db = db.Order("`sort` DESC")
|
||||||
|
}
|
||||||
|
err = db.Find(&resp).Error
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
|
@ -1,4 +1,6 @@
|
||||||
package gorm
|
package gmodel
|
||||||
|
|
||||||
|
import "gorm.io/gorm"
|
||||||
|
|
||||||
type FsProductTemplateTags struct {
|
type FsProductTemplateTags struct {
|
||||||
Id int64 `gorm:"primary_key" json:"id"` // ID
|
Id int64 `gorm:"primary_key" json:"id"` // ID
|
||||||
|
@ -6,3 +8,10 @@ type FsProductTemplateTags struct {
|
||||||
Status *int64 `gorm:"default:1" json:"status"` // 状态 1:可用 0不可用
|
Status *int64 `gorm:"default:1" json:"status"` // 状态 1:可用 0不可用
|
||||||
CreateAt *int64 `gorm:"default:0" json:"create_at"` // 创建时间
|
CreateAt *int64 `gorm:"default:0" json:"create_at"` // 创建时间
|
||||||
}
|
}
|
||||||
|
type FsProductTemplateTagsModel struct {
|
||||||
|
db *gorm.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFsProductTemplateTagsModel(db *gorm.DB) *FsProductTemplateTagsModel {
|
||||||
|
return &FsProductTemplateTagsModel{db}
|
||||||
|
}
|
|
@ -1,4 +1,9 @@
|
||||||
package gorm
|
package gmodel
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
type FsProductTemplateV2 struct {
|
type FsProductTemplateV2 struct {
|
||||||
Id int64 `gorm:"primary_key" json:"id"`
|
Id int64 `gorm:"primary_key" json:"id"`
|
||||||
|
@ -18,3 +23,17 @@ type FsProductTemplateV2 struct {
|
||||||
Tag *string `gorm:"default:''" json:"tag"` // 标签(用户自填)
|
Tag *string `gorm:"default:''" json:"tag"` // 标签(用户自填)
|
||||||
IsDel *int64 `gorm:"default:0" json:"is_del"` // 是否删除 1删除
|
IsDel *int64 `gorm:"default:0" json:"is_del"` // 是否删除 1删除
|
||||||
}
|
}
|
||||||
|
type FsProductTemplateV2Model struct {
|
||||||
|
db *gorm.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFsProductTemplateV2Model(db *gorm.DB) *FsProductTemplateV2Model {
|
||||||
|
return &FsProductTemplateV2Model{db}
|
||||||
|
}
|
||||||
|
func (t *FsProductTemplateV2Model) FindAllByProductIds(ctx context.Context, productIds []int64) (resp []FsProductTemplateV2, err error) {
|
||||||
|
err = t.db.WithContext(ctx).Model(&FsProductTemplateV2Model{}).Where("`id` in (?) and `is_del` = ? and `status` = ?", productIds, 0, 1).Find(&resp).Error
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
|
@ -1,4 +1,6 @@
|
||||||
package gorm
|
package gmodel
|
||||||
|
|
||||||
|
import "gorm.io/gorm"
|
||||||
|
|
||||||
type FsQrcodeSet struct {
|
type FsQrcodeSet struct {
|
||||||
Id int64 `gorm:"primary_key" json:"id"` // id
|
Id int64 `gorm:"primary_key" json:"id"` // id
|
||||||
|
@ -14,3 +16,10 @@ type FsQrcodeSet struct {
|
||||||
Ctime *int64 `gorm:"default:0" json:"ctime"` // 添加时间
|
Ctime *int64 `gorm:"default:0" json:"ctime"` // 添加时间
|
||||||
Utime *int64 `gorm:"default:0" json:"utime"` // 更新时间
|
Utime *int64 `gorm:"default:0" json:"utime"` // 更新时间
|
||||||
}
|
}
|
||||||
|
type FsQrcodeSetModel struct {
|
||||||
|
db *gorm.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFsQrcodeSetModel(db *gorm.DB) *FsQrcodeSetModel {
|
||||||
|
return &FsQrcodeSetModel{db}
|
||||||
|
}
|
|
@ -1,4 +1,6 @@
|
||||||
package gorm
|
package gmodel
|
||||||
|
|
||||||
|
import "gorm.io/gorm"
|
||||||
|
|
||||||
type FsStandardLogo struct {
|
type FsStandardLogo struct {
|
||||||
Id int64 `gorm:"primary_key" json:"id"` // ID
|
Id int64 `gorm:"primary_key" json:"id"` // ID
|
||||||
|
@ -7,3 +9,10 @@ type FsStandardLogo struct {
|
||||||
Ctime *int64 `gorm:"default:0" json:"ctime"` // 添加时间
|
Ctime *int64 `gorm:"default:0" json:"ctime"` // 添加时间
|
||||||
Status *int64 `gorm:"default:1" json:"status"` // 状态 1正常 0删除
|
Status *int64 `gorm:"default:1" json:"status"` // 状态 1正常 0删除
|
||||||
}
|
}
|
||||||
|
type FsStandardLogoModel struct {
|
||||||
|
db *gorm.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFsStandardLogoModel(db *gorm.DB) *FsStandardLogoModel {
|
||||||
|
return &FsStandardLogoModel{db}
|
||||||
|
}
|
|
@ -1,4 +1,10 @@
|
||||||
package gorm
|
package gmodel
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
type FsTags struct {
|
type FsTags struct {
|
||||||
Id int64 `gorm:"primary_key" json:"id"` // ID
|
Id int64 `gorm:"primary_key" json:"id"` // ID
|
||||||
|
@ -13,3 +19,31 @@ type FsTags struct {
|
||||||
RecommendProduct *string `gorm:"default:''" json:"recommend_product"` // 推荐产品id例如: 1,3,4,5
|
RecommendProduct *string `gorm:"default:''" json:"recommend_product"` // 推荐产品id例如: 1,3,4,5
|
||||||
RecommendProductSort *string `gorm:"default:''" json:"recommend_product_sort"` // 推荐排序例如:1324
|
RecommendProductSort *string `gorm:"default:''" json:"recommend_product_sort"` // 推荐排序例如:1324
|
||||||
}
|
}
|
||||||
|
type FsTagsModel struct {
|
||||||
|
db *gorm.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFsTagsModel(db *gorm.DB) *FsTagsModel {
|
||||||
|
return &FsTagsModel{db}
|
||||||
|
}
|
||||||
|
func (t *FsTagsModel) FindOne(ctx context.Context, id int64) (resp FsTags, err error) {
|
||||||
|
err = t.db.WithContext(ctx).Model(&FsTagsModel{}).Where("`id` = ? and `status` = ?", id, 1).First(&resp).Error
|
||||||
|
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
return FsTags{}, err
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (t *FsTagsModel) GetAllByIds(ctx context.Context, ids []int64) (resp []FsTags, err error) {
|
||||||
|
err = t.db.WithContext(ctx).Model(&FsTagsModel{}).Where("`id` in(?) and `status` = ?", ids, 1).Find(&resp).Error
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (t *FsTagsModel) GetAllByLevel(ctx context.Context, level int) (resp []FsTags, err error) {
|
||||||
|
err = t.db.Model(&FsTagsModel{}).Where("`level` = ? and `status` = ?", level, 1).Find(&resp).Error
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
|
@ -1,4 +1,10 @@
|
||||||
package gorm
|
package gmodel
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
type FsUser struct {
|
type FsUser struct {
|
||||||
Id int64 `gorm:"primary_key" json:"id"` // ID
|
Id int64 `gorm:"primary_key" json:"id"` // ID
|
||||||
|
@ -28,3 +34,18 @@ type FsUser struct {
|
||||||
IsLowRendering int64 `gorm:"default:0" json:"is_low_rendering"` // 是否开启低渲染模型渲染
|
IsLowRendering int64 `gorm:"default:0" json:"is_low_rendering"` // 是否开启低渲染模型渲染
|
||||||
IsRemoveBg int64 `gorm:"default:1" json:"is_remove_bg"` // 用户上传logo是否去除背景
|
IsRemoveBg int64 `gorm:"default:1" json:"is_remove_bg"` // 用户上传logo是否去除背景
|
||||||
}
|
}
|
||||||
|
type FsUserModel struct {
|
||||||
|
db *gorm.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFsUserModel(db *gorm.DB) *FsUserModel {
|
||||||
|
return &FsUserModel{db}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *FsUserModel) FindOne(ctx context.Context, id int64) (resp FsUser, err error) {
|
||||||
|
err = u.db.WithContext(ctx).Model(&FsUserModel{}).Where("`id` = ? and is_del = ?", id, 0).First(&resp).Error
|
||||||
|
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
return FsUser{}, err
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
|
@ -1,12 +0,0 @@
|
||||||
package gorm
|
|
||||||
|
|
||||||
type FsCanteenProduct struct {
|
|
||||||
Id int64 `gorm:"primary_key" json:"id"` // ID
|
|
||||||
CanteenType *int64 `gorm:"default:0" json:"canteen_type"` // 餐厅类别id
|
|
||||||
ProductId *int64 `gorm:"default:0" json:"product_id"` // 产品id
|
|
||||||
SizeId *int64 `gorm:"default:0" json:"size_id"` // 尺寸id
|
|
||||||
Sort *int64 `gorm:"default:0" json:"sort"` // 排序
|
|
||||||
Status *int64 `gorm:"default:1" json:"status"` // 状态位 1启用0停用
|
|
||||||
Ctime *int64 `gorm:"default:0" json:"ctime"` // 添加时间
|
|
||||||
Sid *string `gorm:"default:''" json:"sid"` // 前端带入的id
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
package gorm
|
|
||||||
|
|
||||||
type FsCanteenType struct {
|
|
||||||
Id int64 `gorm:"primary_key" json:"id"` // ID
|
|
||||||
Name *string `gorm:"default:''" json:"name"` // 餐厅名字
|
|
||||||
Sort *int64 `gorm:"default:0" json:"sort"` // 排序
|
|
||||||
Status *int64 `gorm:"default:1" json:"status"` // 状态位 1启用0停用
|
|
||||||
Ctime *int64 `gorm:"default:0" json:"ctime"` // 添加时间
|
|
||||||
}
|
|
|
@ -1,14 +0,0 @@
|
||||||
package gorm
|
|
||||||
|
|
||||||
type FsProductSize struct {
|
|
||||||
Id int64 `gorm:"primary_key" json:"id"`
|
|
||||||
ProductId *int64 `gorm:"default:0" json:"product_id"` // 产品ID
|
|
||||||
Title *string `gorm:"default:''" json:"title"` // 标题 10*10*20
|
|
||||||
Cover *string `gorm:"default:''" json:"cover"` // 封面图
|
|
||||||
CoverImg *string `gorm:"default:''" json:"cover_img"` // 背景图
|
|
||||||
Capacity *string `gorm:"default:''" json:"capacity"` // 自己填的尺寸名称
|
|
||||||
Status *int64 `gorm:"default:1" json:"status"` // 状态位 1显示 0删除
|
|
||||||
Sort *int64 `gorm:"default:50" json:"sort"` // 排序
|
|
||||||
Remark *string `gorm:"default:''" json:"remark"` // 备注信息
|
|
||||||
PartsCanDeleted *int64 `gorm:"default:1" json:"parts_can_deleted"` // 配件是否可移除 1是0否
|
|
||||||
}
|
|
|
@ -7,15 +7,39 @@ import (
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
|
||||||
|
"fusenapi/utils/auth"
|
||||||
|
|
||||||
"fusenapi/server/canteen/internal/logic"
|
"fusenapi/server/canteen/internal/logic"
|
||||||
"fusenapi/server/canteen/internal/svc"
|
"fusenapi/server/canteen/internal/svc"
|
||||||
"fusenapi/server/canteen/internal/types"
|
"fusenapi/server/canteen/internal/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 获取餐厅详情
|
|
||||||
func GetCanteenDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetCanteenDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// 解析jwtToken
|
||||||
|
claims, err := svcCtx.ParseJwtToken(r)
|
||||||
|
// 如果解析出错,则返回未授权的JSON响应并记录错误消息
|
||||||
|
if err != nil {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, &types.Response{
|
||||||
|
Code: 401,
|
||||||
|
Message: "unauthorized",
|
||||||
|
})
|
||||||
|
logx.Info("unauthorized:", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
// 从Token里获取对应的信息
|
||||||
|
userinfo, err := auth.GetUserInfoFormMapClaims(claims)
|
||||||
|
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
||||||
|
if err != nil {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, &types.Response{
|
||||||
|
Code: 401,
|
||||||
|
Message: "unauthorized",
|
||||||
|
})
|
||||||
|
logx.Info("unauthorized:", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
var req types.GetCanteenDetailReq
|
var req types.GetCanteenDetailReq
|
||||||
|
// 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, &types.Response{
|
httpx.OkJsonCtx(r.Context(), w, &types.Response{
|
||||||
Code: 510,
|
Code: 510,
|
||||||
|
@ -24,9 +48,11 @@ func GetCanteenDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
logx.Info(err)
|
logx.Info(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// 创建一个业务逻辑层实例
|
||||||
l := logic.NewGetCanteenDetailLogic(r.Context(), svcCtx)
|
l := logic.NewGetCanteenDetailLogic(r.Context(), svcCtx)
|
||||||
resp := l.GetCanteenDetail(&req)
|
resp := l.GetCanteenDetail(&req, userinfo)
|
||||||
|
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
||||||
|
// 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -7,6 +7,8 @@ import (
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
|
||||||
|
"fusenapi/utils/auth"
|
||||||
|
|
||||||
"fusenapi/server/canteen/internal/logic"
|
"fusenapi/server/canteen/internal/logic"
|
||||||
"fusenapi/server/canteen/internal/svc"
|
"fusenapi/server/canteen/internal/svc"
|
||||||
"fusenapi/server/canteen/internal/types"
|
"fusenapi/server/canteen/internal/types"
|
||||||
|
@ -14,7 +16,30 @@ import (
|
||||||
|
|
||||||
func SaveCanteenTypeProductHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func SaveCanteenTypeProductHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// 解析jwtToken
|
||||||
|
claims, err := svcCtx.ParseJwtToken(r)
|
||||||
|
// 如果解析出错,则返回未授权的JSON响应并记录错误消息
|
||||||
|
if err != nil {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, &types.Response{
|
||||||
|
Code: 401,
|
||||||
|
Message: "unauthorized",
|
||||||
|
})
|
||||||
|
logx.Info("unauthorized:", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
// 从Token里获取对应的信息
|
||||||
|
userinfo, err := auth.GetUserInfoFormMapClaims(claims)
|
||||||
|
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
||||||
|
if err != nil {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, &types.Response{
|
||||||
|
Code: 401,
|
||||||
|
Message: "unauthorized",
|
||||||
|
})
|
||||||
|
logx.Info("unauthorized:", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
var req types.SaveCanteenTypeProductReq
|
var req types.SaveCanteenTypeProductReq
|
||||||
|
// 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, &types.Response{
|
httpx.OkJsonCtx(r.Context(), w, &types.Response{
|
||||||
Code: 510,
|
Code: 510,
|
||||||
|
@ -23,9 +48,11 @@ func SaveCanteenTypeProductHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
|
||||||
logx.Info(err)
|
logx.Info(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// 创建一个业务逻辑层实例
|
||||||
l := logic.NewSaveCanteenTypeProductLogic(r.Context(), svcCtx)
|
l := logic.NewSaveCanteenTypeProductLogic(r.Context(), svcCtx)
|
||||||
resp := l.SaveCanteenTypeProduct(&req)
|
resp := l.SaveCanteenTypeProduct(&req, userinfo)
|
||||||
|
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
||||||
|
// 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -2,14 +2,12 @@ package logic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"fusenapi/model"
|
"fusenapi/model/gmodel"
|
||||||
"fusenapi/utils/basic"
|
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
||||||
|
|
||||||
"fusenapi/server/canteen/internal/svc"
|
"fusenapi/server/canteen/internal/svc"
|
||||||
"fusenapi/server/canteen/internal/types"
|
"fusenapi/server/canteen/internal/types"
|
||||||
|
"fusenapi/utils/auth"
|
||||||
|
"fusenapi/utils/basic"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
@ -29,19 +27,19 @@ func NewGetCanteenDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取餐厅详情
|
// 获取餐厅详情
|
||||||
func (l *GetCanteenDetailLogic) GetCanteenDetail(req *types.GetCanteenDetailReq) (resp *types.Response) {
|
func (l *GetCanteenDetailLogic) GetCanteenDetail(req *types.GetCanteenDetailReq, loginInfo *auth.UserInfo) (resp *types.Response) {
|
||||||
//获取餐厅类型数据
|
//获取餐厅类型数据
|
||||||
canteenTypeModel := model.NewFsCanteenTypeModel(l.svcCtx.MysqlConn)
|
canteenTypeModel := gmodel.NewFsCanteenTypeModel(l.svcCtx.MysqlConn)
|
||||||
canteenTypeInfo, err := canteenTypeModel.FindOne(l.ctx, req.Id)
|
canteenTypeInfo, err := canteenTypeModel.FindOne(l.ctx, req.Id)
|
||||||
if err != nil && !errors.Is(err, sqlx.ErrNotFound) {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get canteen type info ")
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get canteen type info ")
|
||||||
}
|
}
|
||||||
if canteenTypeInfo == nil {
|
if canteenTypeInfo.Id == 0 {
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "canteen type is not exists ")
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "canteen type is not exists ")
|
||||||
}
|
}
|
||||||
//获取餐厅类型关联的所有产品
|
//获取餐厅类型关联的所有产品
|
||||||
canteenProductModel := model.NewFsCanteenProductModel(l.svcCtx.MysqlConn)
|
canteenProductModel := gmodel.NewFsCanteenProductModel(l.svcCtx.MysqlConn)
|
||||||
canteenProductList, err := canteenProductModel.GetAllByCanteenTypeId(l.ctx, req.Id)
|
canteenProductList, err := canteenProductModel.GetAllByCanteenTypeId(l.ctx, req.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
|
@ -50,43 +48,43 @@ func (l *GetCanteenDetailLogic) GetCanteenDetail(req *types.GetCanteenDetailReq)
|
||||||
if len(canteenProductList) == 0 {
|
if len(canteenProductList) == 0 {
|
||||||
return resp.SetStatusWithMessage(basic.CodeOK, "ok with no canteen product")
|
return resp.SetStatusWithMessage(basic.CodeOK, "ok with no canteen product")
|
||||||
}
|
}
|
||||||
productIds := make([]string, 0, len(canteenProductList))
|
productIds := make([]int64, 0, len(canteenProductList))
|
||||||
sizeIds := make([]string, 0, len(canteenProductList))
|
sizeIds := make([]int64, 0, len(canteenProductList))
|
||||||
for _, v := range canteenProductList {
|
for _, v := range canteenProductList {
|
||||||
productIds = append(productIds, fmt.Sprintf("%d", v.ProductId))
|
productIds = append(productIds, *v.ProductId)
|
||||||
sizeIds = append(sizeIds, fmt.Sprintf("%d", v.SizeId))
|
sizeIds = append(sizeIds, *v.SizeId)
|
||||||
}
|
}
|
||||||
productModel := model.NewFsProductModel(l.svcCtx.MysqlConn)
|
productModel := gmodel.NewFsProductModel(l.svcCtx.MysqlConn)
|
||||||
productList, err := productModel.GetProductListByIds(l.ctx, productIds, "")
|
productList, err := productModel.GetProductListByIds(l.ctx, productIds, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product list")
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product list")
|
||||||
}
|
}
|
||||||
mapProduct := make(map[int64]model.FsProduct)
|
mapProduct := make(map[int64]gmodel.FsProduct)
|
||||||
tagIds := make([]string, 0, len(productList))
|
tagIds := make([]int64, 0, len(productList))
|
||||||
for _, v := range productList {
|
for _, v := range productList {
|
||||||
mapProduct[v.Id] = v
|
mapProduct[v.Id] = v
|
||||||
tagIds = append(tagIds, fmt.Sprintf("%d", v.Type))
|
tagIds = append(tagIds, *v.Type)
|
||||||
}
|
}
|
||||||
//获取分类列表
|
//获取分类列表
|
||||||
tagModel := model.NewFsTagsModel(l.svcCtx.MysqlConn)
|
tagModel := gmodel.NewFsTagsModel(l.svcCtx.MysqlConn)
|
||||||
tagList, err := tagModel.GetAllByIds(l.ctx, tagIds)
|
tagList, err := tagModel.GetAllByIds(l.ctx, tagIds)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get tag list")
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get tag list")
|
||||||
}
|
}
|
||||||
mapTag := make(map[int64]model.FsTags)
|
mapTag := make(map[int64]gmodel.FsTags)
|
||||||
for _, v := range tagList {
|
for _, v := range tagList {
|
||||||
mapTag[v.Id] = v
|
mapTag[v.Id] = v
|
||||||
}
|
}
|
||||||
//获取尺寸列表
|
//获取尺寸列表
|
||||||
productSizeModel := model.NewFsProductSizeModel(l.svcCtx.MysqlConn)
|
productSizeModel := gmodel.NewFsProductSizeModel(l.svcCtx.MysqlConn)
|
||||||
productSizeList, err := productSizeModel.GetAllByIds(l.ctx, sizeIds, "")
|
productSizeList, err := productSizeModel.GetAllByIds(l.ctx, sizeIds, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product size list")
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product size list")
|
||||||
}
|
}
|
||||||
mapSize := make(map[int64]model.FsProductSize)
|
mapSize := make(map[int64]gmodel.FsProductSize)
|
||||||
for _, v := range productSizeList {
|
for _, v := range productSizeList {
|
||||||
mapSize[v.Id] = v
|
mapSize[v.Id] = v
|
||||||
}
|
}
|
||||||
|
@ -95,18 +93,18 @@ func (l *GetCanteenDetailLogic) GetCanteenDetail(req *types.GetCanteenDetailReq)
|
||||||
for _, v := range canteenProductList {
|
for _, v := range canteenProductList {
|
||||||
data := types.CanteenProduct{
|
data := types.CanteenProduct{
|
||||||
Id: v.Id,
|
Id: v.Id,
|
||||||
SizeId: v.SizeId,
|
SizeId: *v.SizeId,
|
||||||
SId: v.Sid,
|
SId: *v.Sid,
|
||||||
}
|
}
|
||||||
p, ok := mapProduct[v.ProductId]
|
p, ok := mapProduct[*v.ProductId]
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
tag, ok := mapTag[p.Type]
|
tag, ok := mapTag[*p.Type]
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
size, ok := mapSize[v.SizeId]
|
size, ok := mapSize[*v.SizeId]
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -115,7 +113,7 @@ func (l *GetCanteenDetailLogic) GetCanteenDetail(req *types.GetCanteenDetailReq)
|
||||||
}
|
}
|
||||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetCanteenDetailRsp{
|
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetCanteenDetailRsp{
|
||||||
Id: canteenTypeInfo.Id,
|
Id: canteenTypeInfo.Id,
|
||||||
Name: canteenTypeInfo.Name,
|
Name: *canteenTypeInfo.Name,
|
||||||
ProductList: list,
|
ProductList: list,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,10 @@ package logic
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"fusenapi/model"
|
"fusenapi/model/gmodel"
|
||||||
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
"gorm.io/gorm"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"fusenapi/server/canteen/internal/svc"
|
"fusenapi/server/canteen/internal/svc"
|
||||||
|
@ -30,34 +30,36 @@ func NewSaveCanteenTypeProductLogic(ctx context.Context, svcCtx *svc.ServiceCont
|
||||||
}
|
}
|
||||||
|
|
||||||
// 保存餐厅类型的关联产品
|
// 保存餐厅类型的关联产品
|
||||||
func (l *SaveCanteenTypeProductLogic) SaveCanteenTypeProduct(req *types.SaveCanteenTypeProductReq) (resp *types.Response) {
|
func (l *SaveCanteenTypeProductLogic) SaveCanteenTypeProduct(req *types.SaveCanteenTypeProductReq, loginInfo *auth.UserInfo) (resp *types.Response) {
|
||||||
if len(req.ProductList) == 0 {
|
if len(req.ProductList) == 0 {
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "product list can`t be empty")
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "product list can`t be empty")
|
||||||
}
|
}
|
||||||
canteenProductModel := model.NewFsCanteenProductModel(l.svcCtx.MysqlConn)
|
canteenProductModel := gmodel.NewFsCanteenProductModel(l.svcCtx.MysqlConn)
|
||||||
//获取原有餐厅类型的所有产品
|
//获取原有餐厅类型的所有产品
|
||||||
oldCanteenProductList, err := canteenProductModel.GetAllByCanteenTypeId(l.ctx, req.Id)
|
oldCanteenProductList, err := canteenProductModel.GetAllByCanteenTypeId(l.ctx, req.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get canteen product list")
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get canteen product list")
|
||||||
}
|
}
|
||||||
sizeIds := make([]string, 0, len(req.ProductList))
|
sizeIds := make([]int64, 0, len(req.ProductList))
|
||||||
for _, v := range req.ProductList {
|
for _, v := range req.ProductList {
|
||||||
sizeIds = append(sizeIds, fmt.Sprintf("%d", v.SizeId))
|
sizeIds = append(sizeIds, v.SizeId)
|
||||||
}
|
}
|
||||||
productSizeModel := model.NewFsProductSizeModel(l.svcCtx.MysqlConn)
|
productSizeModel := gmodel.NewFsProductSizeModel(l.svcCtx.MysqlConn)
|
||||||
productSizeList, err := productSizeModel.GetAllByIds(l.ctx, sizeIds, "")
|
productSizeList, err := productSizeModel.GetAllByIds(l.ctx, sizeIds, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product size list")
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product size list")
|
||||||
}
|
}
|
||||||
fmt.Println(len(productSizeList))
|
fmt.Println(len(productSizeList))
|
||||||
mapProductSize := make(map[int64]model.FsProductSize)
|
mapProductSize := make(map[int64]gmodel.FsProductSize)
|
||||||
for _, v := range productSizeList {
|
for _, v := range productSizeList {
|
||||||
mapProductSize[v.Id] = v
|
mapProductSize[v.Id] = v
|
||||||
}
|
}
|
||||||
|
now := time.Now().Unix()
|
||||||
//开启事务
|
//开启事务
|
||||||
err = l.svcCtx.MysqlConn.TransactCtx(l.ctx, func(ctx context.Context, session sqlx.Session) error {
|
err = l.svcCtx.MysqlConn.Transaction(func(tx *gorm.DB) error {
|
||||||
|
canteenProductModel = gmodel.NewFsCanteenProductModel(tx)
|
||||||
sort := int64(0)
|
sort := int64(0)
|
||||||
//新的变更记录
|
//新的变更记录
|
||||||
mapUpdateCanteenPid := make(map[int64]struct{})
|
mapUpdateCanteenPid := make(map[int64]struct{})
|
||||||
|
@ -69,33 +71,47 @@ func (l *SaveCanteenTypeProductLogic) SaveCanteenTypeProduct(req *types.SaveCant
|
||||||
}
|
}
|
||||||
if v.Id > 0 { //更新
|
if v.Id > 0 { //更新
|
||||||
mapUpdateCanteenPid[v.Id] = struct{}{}
|
mapUpdateCanteenPid[v.Id] = struct{}{}
|
||||||
if _, err = session.ExecCtx(l.ctx, "update `fs_canteen_product` set "+
|
err = canteenProductModel.UpdateById(l.ctx, v.Id, &gmodel.FsCanteenProduct{
|
||||||
"`size_id` = ?,`sid` = ?,`sort` = ?,`product_id` = ? where `id` = ? ",
|
SizeId: &v.SizeId,
|
||||||
v.SizeId, v.SId, sort, sizeInfo.ProductId, v.Id,
|
Sid: &v.SId,
|
||||||
); err != nil {
|
Sort: &sort,
|
||||||
|
ProductId: sizeInfo.ProductId,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
//新增
|
//新增
|
||||||
if _, err = session.ExecCtx(l.ctx, "insert into `fs_canteen_product` "+
|
err = canteenProductModel.Create(l.ctx, &gmodel.FsCanteenProduct{
|
||||||
"(`size_id`,`sid`,`sort`,`status`,`ctime`,`canteen_type`,`product_id`) "+
|
SizeId: &v.SizeId,
|
||||||
"values (?, ?, ?, ?, ?, ?, ?)", sizeInfo.Id, v.SId, sort, 1, time.Now().Unix(), req.Id, sizeInfo.ProductId); err != nil {
|
Sid: &v.SId,
|
||||||
|
Sort: &sort,
|
||||||
|
Ctime: &now,
|
||||||
|
CanteenType: &req.Id,
|
||||||
|
ProductId: sizeInfo.ProductId,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
diffCanteenProductId := make([]string, 0, len(oldCanteenProductList))
|
diffCanteenProductId := make([]int64, 0, len(oldCanteenProductList))
|
||||||
//旧的中不包含在更新的里面则去掉
|
//旧的中不包含在更新的里面则去掉
|
||||||
for _, v := range oldCanteenProductList {
|
for _, v := range oldCanteenProductList {
|
||||||
if _, ok := mapUpdateCanteenPid[v.Id]; !ok {
|
if _, ok := mapUpdateCanteenPid[v.Id]; !ok {
|
||||||
diffCanteenProductId = append(diffCanteenProductId, fmt.Sprintf("%d", v.Id))
|
diffCanteenProductId = append(diffCanteenProductId, v.Id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(diffCanteenProductId) == 0 {
|
if len(diffCanteenProductId) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
_, err = session.ExecCtx(l.ctx, "update `fs_canteen_product` set `status` = ? where `id` in (?)", 0, strings.Join(diffCanteenProductId, ","))
|
delStatus := int64(0)
|
||||||
return err
|
if err = canteenProductModel.UpdateByIdArr(l.ctx, diffCanteenProductId, &gmodel.FsCanteenProduct{
|
||||||
|
Status: &delStatus,
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
package svc
|
package svc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
"fusenapi/initalize"
|
"fusenapi/initalize"
|
||||||
"fusenapi/server/canteen/internal/config"
|
"fusenapi/server/canteen/internal/config"
|
||||||
|
"github.com/golang-jwt/jwt"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ServiceContext struct {
|
type ServiceContext struct {
|
||||||
|
@ -13,8 +17,35 @@ type ServiceContext struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServiceContext(c config.Config) *ServiceContext {
|
func NewServiceContext(c config.Config) *ServiceContext {
|
||||||
|
|
||||||
return &ServiceContext{
|
return &ServiceContext{
|
||||||
Config: c,
|
Config: c,
|
||||||
MysqlConn: initalize.InitMysql(c.SourceMysql),
|
MysqlConn: initalize.InitMysql(c.SourceMysql),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
|
||||||
|
AuthKey := r.Header.Get("Authorization")
|
||||||
|
if len(AuthKey) <= 50 {
|
||||||
|
return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey)))
|
||||||
|
}
|
||||||
|
|
||||||
|
token, err := jwt.Parse(AuthKey, func(token *jwt.Token) (interface{}, error) {
|
||||||
|
// 检查签名方法是否为 HS256
|
||||||
|
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
|
||||||
|
}
|
||||||
|
// 返回用于验证签名的密钥
|
||||||
|
return svcCxt.Config.Auth.AccessSecret, nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New(fmt.Sprint("Error parsing token:", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证成功返回
|
||||||
|
if claims, ok := token.Claims.(jwt.MapClaims); ok && token.Valid {
|
||||||
|
return claims, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, errors.New(fmt.Sprint("Invalid token", err))
|
||||||
|
}
|
||||||
|
|
|
@ -7,6 +7,8 @@ import (
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
|
||||||
|
"fusenapi/utils/auth"
|
||||||
|
|
||||||
"fusenapi/server/product/internal/logic"
|
"fusenapi/server/product/internal/logic"
|
||||||
"fusenapi/server/product/internal/svc"
|
"fusenapi/server/product/internal/svc"
|
||||||
"fusenapi/server/product/internal/types"
|
"fusenapi/server/product/internal/types"
|
||||||
|
@ -14,18 +16,43 @@ import (
|
||||||
|
|
||||||
func GetProductListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetProductListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// 解析jwtToken
|
||||||
|
claims, err := svcCtx.ParseJwtToken(r)
|
||||||
|
// 如果解析出错,则返回未授权的JSON响应并记录错误消息
|
||||||
|
if err != nil {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, &types.Response{
|
||||||
|
Code: 401,
|
||||||
|
Message: "unauthorized",
|
||||||
|
})
|
||||||
|
logx.Info("unauthorized:", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
// 从Token里获取对应的信息
|
||||||
|
userinfo, err := auth.GetUserInfoFormMapClaims(claims)
|
||||||
|
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
||||||
|
if err != nil {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, &types.Response{
|
||||||
|
Code: 401,
|
||||||
|
Message: "unauthorized",
|
||||||
|
})
|
||||||
|
logx.Info("unauthorized:", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
var req types.GetProductListReq
|
var req types.GetProductListReq
|
||||||
|
// 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, &types.Response{
|
httpx.OkJsonCtx(r.Context(), w, &types.Response{
|
||||||
Code: 510,
|
Code: 510,
|
||||||
Message: err.Error(),
|
Message: "parameter error",
|
||||||
})
|
})
|
||||||
logx.Info(err)
|
logx.Info(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// 创建一个业务逻辑层实例
|
||||||
l := logic.NewGetProductListLogic(r.Context(), svcCtx)
|
l := logic.NewGetProductListLogic(r.Context(), svcCtx)
|
||||||
resp := l.GetProductList(&req)
|
resp := l.GetProductList(&req, userinfo)
|
||||||
|
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
||||||
|
// 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -2,19 +2,46 @@ package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fusenapi/server/product/internal/types"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
|
||||||
|
"fusenapi/utils/auth"
|
||||||
|
|
||||||
"fusenapi/server/product/internal/logic"
|
"fusenapi/server/product/internal/logic"
|
||||||
"fusenapi/server/product/internal/svc"
|
"fusenapi/server/product/internal/svc"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetSizeByProductHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetSizeByProductHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// 解析jwtToken
|
||||||
|
claims, err := svcCtx.ParseJwtToken(r)
|
||||||
|
// 如果解析出错,则返回未授权的JSON响应并记录错误消息
|
||||||
|
if err != nil {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, &types.Response{
|
||||||
|
Code: 401,
|
||||||
|
Message: "unauthorized",
|
||||||
|
})
|
||||||
|
logx.Info("unauthorized:", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
// 从Token里获取对应的信息
|
||||||
|
userinfo, err := auth.GetUserInfoFormMapClaims(claims)
|
||||||
|
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
||||||
|
if err != nil {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, &types.Response{
|
||||||
|
Code: 401,
|
||||||
|
Message: "unauthorized",
|
||||||
|
})
|
||||||
|
logx.Info("unauthorized:", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
l := logic.NewGetSizeByProductLogic(r.Context(), svcCtx)
|
l := logic.NewGetSizeByProductLogic(r.Context(), svcCtx)
|
||||||
resp := l.GetSizeByProduct()
|
resp := l.GetSizeByProduct(userinfo)
|
||||||
|
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
||||||
|
// 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -7,6 +7,8 @@ import (
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"github.com/zeromicro/go-zero/rest/httpx"
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
|
||||||
|
"fusenapi/utils/auth"
|
||||||
|
|
||||||
"fusenapi/server/product/internal/logic"
|
"fusenapi/server/product/internal/logic"
|
||||||
"fusenapi/server/product/internal/svc"
|
"fusenapi/server/product/internal/svc"
|
||||||
"fusenapi/server/product/internal/types"
|
"fusenapi/server/product/internal/types"
|
||||||
|
@ -14,18 +16,43 @@ import (
|
||||||
|
|
||||||
func GetSuccessRecommandHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetSuccessRecommandHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// 解析jwtToken
|
||||||
|
claims, err := svcCtx.ParseJwtToken(r)
|
||||||
|
// 如果解析出错,则返回未授权的JSON响应并记录错误消息
|
||||||
|
if err != nil {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, &types.Response{
|
||||||
|
Code: 401,
|
||||||
|
Message: "unauthorized",
|
||||||
|
})
|
||||||
|
logx.Info("unauthorized:", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
// 从Token里获取对应的信息
|
||||||
|
userinfo, err := auth.GetUserInfoFormMapClaims(claims)
|
||||||
|
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
||||||
|
if err != nil {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, &types.Response{
|
||||||
|
Code: 401,
|
||||||
|
Message: "unauthorized",
|
||||||
|
})
|
||||||
|
logx.Info("unauthorized:", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
var req types.GetSuccessRecommandReq
|
var req types.GetSuccessRecommandReq
|
||||||
|
// 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, &types.Response{
|
httpx.OkJsonCtx(r.Context(), w, &types.Response{
|
||||||
Code: 510,
|
Code: 510,
|
||||||
Message: err.Error(),
|
Message: "parameter error",
|
||||||
})
|
})
|
||||||
logx.Info(err)
|
logx.Info(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// 创建一个业务逻辑层实例
|
||||||
l := logic.NewGetSuccessRecommandLogic(r.Context(), svcCtx)
|
l := logic.NewGetSuccessRecommandLogic(r.Context(), svcCtx)
|
||||||
resp := l.GetSuccessRecommand(&req)
|
resp := l.GetSuccessRecommand(&req, userinfo)
|
||||||
|
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
||||||
|
// 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -4,9 +4,8 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"fusenapi/constants"
|
"fusenapi/constants"
|
||||||
"fusenapi/model"
|
"fusenapi/model/gmodel"
|
||||||
"fusenapi/server/product/internal/svc"
|
"fusenapi/server/product/internal/svc"
|
||||||
"fusenapi/server/product/internal/types"
|
"fusenapi/server/product/internal/types"
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
|
@ -34,12 +33,8 @@ func NewGetProductListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取产品列表
|
// 获取产品列表
|
||||||
func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq) (resp *types.Response) {
|
func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, loginInfo *auth.UserInfo) (resp *types.Response) {
|
||||||
resp = &types.Response{}
|
resp = &types.Response{}
|
||||||
loginInfo := auth.GetUserInfoFormCtx(l.ctx)
|
|
||||||
if loginInfo.UserId == 0 {
|
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get login user info err")
|
|
||||||
}
|
|
||||||
//如果是demo
|
//如果是demo
|
||||||
if req.IsDemo == 1 {
|
if req.IsDemo == 1 {
|
||||||
var demo types.GetProductListRsp
|
var demo types.GetProductListRsp
|
||||||
|
@ -57,18 +52,18 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq) (resp
|
||||||
req.Size = image.GetCurrentSize(req.Size)
|
req.Size = image.GetCurrentSize(req.Size)
|
||||||
}
|
}
|
||||||
//查询用户信息
|
//查询用户信息
|
||||||
userModel := model.NewFsUserModel(l.svcCtx.MysqlConn)
|
userModel := gmodel.NewFsUserModel(l.svcCtx.MysqlConn)
|
||||||
userInfo, err := userModel.FindOne(l.ctx, loginInfo.UserId)
|
userInfo, err := userModel.FindOne(l.ctx, loginInfo.UserId)
|
||||||
if err != nil && !errors.Is(err, sqlc.ErrNotFound) {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get user info err")
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get user info err")
|
||||||
}
|
}
|
||||||
if userInfo == nil {
|
if userInfo.Id == 0 {
|
||||||
return resp.SetStatusWithMessage(basic.CodeUnAuth, "user not exists")
|
return resp.SetStatusWithMessage(basic.CodeUnAuth, "user not exists")
|
||||||
}
|
}
|
||||||
//查询符合的产品列表
|
//查询符合的产品列表
|
||||||
productModel := model.NewFsProductModel(l.svcCtx.MysqlConn)
|
productModel := gmodel.NewFsProductModel(l.svcCtx.MysqlConn)
|
||||||
productList, err := productModel.GetProductListByConditions(l.ctx, []string{fmt.Sprintf("%d", req.Cid)}, "sort-desc")
|
productList, err := productModel.GetProductListByTypeIds(l.ctx, []int64{req.Cid}, "sort-desc")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product list")
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product list")
|
||||||
|
@ -78,11 +73,11 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq) (resp
|
||||||
return resp.SetStatusWithMessage(basic.CodeOK, "success")
|
return resp.SetStatusWithMessage(basic.CodeOK, "success")
|
||||||
}
|
}
|
||||||
//提取产品ids
|
//提取产品ids
|
||||||
productIds := make([]string, 0, productLen)
|
productIds := make([]int64, 0, productLen)
|
||||||
for _, v := range productList {
|
for _, v := range productList {
|
||||||
productIds = append(productIds, fmt.Sprintf("%d", v.Id))
|
productIds = append(productIds, v.Id)
|
||||||
}
|
}
|
||||||
productPriceModel := model.NewFsProductPriceModel(l.svcCtx.MysqlConn)
|
productPriceModel := gmodel.NewFsProductPriceModel(l.svcCtx.MysqlConn)
|
||||||
productPriceList, err := productPriceModel.GetPriceListByProductIds(l.ctx, productIds)
|
productPriceList, err := productPriceModel.GetPriceListByProductIds(l.ctx, productIds)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
|
@ -104,28 +99,28 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq) (resp
|
||||||
mapProductMinPrice[v.ProductId] = int64(priceSlice[0])
|
mapProductMinPrice[v.ProductId] = int64(priceSlice[0])
|
||||||
}
|
}
|
||||||
//获取模板
|
//获取模板
|
||||||
productTemplateModel := model.NewFsProductTemplateV2Model(l.svcCtx.MysqlConn)
|
productTemplateModel := gmodel.NewFsProductTemplateV2Model(l.svcCtx.MysqlConn)
|
||||||
productTemplatesV2, err := productTemplateModel.FindAllByCondition(l.ctx, productIds)
|
productTemplatesV2, err := productTemplateModel.FindAllByProductIds(l.ctx, productIds)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get product template_v2 err")
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get product template_v2 err")
|
||||||
}
|
}
|
||||||
mapProductTemplate := make(map[int64]struct{})
|
mapProductTemplate := make(map[int64]struct{})
|
||||||
for _, v := range productTemplatesV2 {
|
for _, v := range productTemplatesV2 {
|
||||||
mapProductTemplate[v.ProductId] = struct{}{}
|
mapProductTemplate[*v.ProductId] = struct{}{}
|
||||||
}
|
}
|
||||||
//获取分类
|
//获取分类
|
||||||
tagsModel := model.NewFsTagsModel(l.svcCtx.MysqlConn)
|
tagsModel := gmodel.NewFsTagsModel(l.svcCtx.MysqlConn)
|
||||||
tagInfo, err := tagsModel.FindOne(l.ctx, req.Cid)
|
tagInfo, err := tagsModel.FindOne(l.ctx, req.Cid)
|
||||||
if err != nil && !errors.Is(err, sqlc.ErrNotFound) {
|
if err != nil && !errors.Is(err, sqlc.ErrNotFound) {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get tag err")
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get tag err")
|
||||||
}
|
}
|
||||||
if tagInfo == nil {
|
if tagInfo.Id == 0 {
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "tag is not exists")
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "tag is not exists")
|
||||||
}
|
}
|
||||||
//获取产品尺寸数量
|
//获取产品尺寸数量
|
||||||
productSizeModel := model.NewFsProductSizeModel(l.svcCtx.MysqlConn)
|
productSizeModel := gmodel.NewFsProductSizeModel(l.svcCtx.MysqlConn)
|
||||||
productSizeCount, err := productSizeModel.CountByStatus(l.ctx, 1)
|
productSizeCount, err := productSizeModel.CountByStatus(l.ctx, 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
|
@ -142,11 +137,11 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq) (resp
|
||||||
}
|
}
|
||||||
item := types.Items{
|
item := types.Items{
|
||||||
Id: v.Id,
|
Id: v.Id,
|
||||||
Sn: v.Sn,
|
Sn: *v.Sn,
|
||||||
Title: v.Title,
|
Title: *v.Title,
|
||||||
Intro: v.Intro.String,
|
Intro: *v.Intro,
|
||||||
IsEnv: v.IsProtection,
|
IsEnv: *v.IsProtection,
|
||||||
IsMicro: v.IsMicrowave,
|
IsMicro: *v.IsMicrowave,
|
||||||
SizeNum: uint32(productSizeCount),
|
SizeNum: uint32(productSizeCount),
|
||||||
MiniPrice: format.CentoDollar(minPrice),
|
MiniPrice: format.CentoDollar(minPrice),
|
||||||
}
|
}
|
||||||
|
@ -154,11 +149,11 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq) (resp
|
||||||
thousandFaceImageFormatReq := image.ThousandFaceImageFormatReq{
|
thousandFaceImageFormatReq := image.ThousandFaceImageFormatReq{
|
||||||
Size: int(req.Size),
|
Size: int(req.Size),
|
||||||
IsThousandFace: int(userInfo.IsThousandFace),
|
IsThousandFace: int(userInfo.IsThousandFace),
|
||||||
Cover: v.Cover,
|
Cover: *v.Cover,
|
||||||
CoverImg: v.CoverImg,
|
CoverImg: *v.CoverImg,
|
||||||
CoverDefault: v.CoverImg,
|
CoverDefault: *v.CoverImg,
|
||||||
ProductId: v.Id,
|
ProductId: v.Id,
|
||||||
UserInfo: *userInfo,
|
UserInfo: userInfo,
|
||||||
}
|
}
|
||||||
image.ThousandFaceImageFormat(&thousandFaceImageFormatReq)
|
image.ThousandFaceImageFormat(&thousandFaceImageFormatReq)
|
||||||
item.Cover = thousandFaceImageFormatReq.Cover
|
item.Cover = thousandFaceImageFormatReq.Cover
|
||||||
|
@ -169,6 +164,6 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq) (resp
|
||||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetProductListRsp{
|
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetProductListRsp{
|
||||||
Ob: types.Ob{
|
Ob: types.Ob{
|
||||||
Items: itemList,
|
Items: itemList,
|
||||||
}, TypeName: tagInfo.Title, Description: tagInfo.Description,
|
}, TypeName: *tagInfo.Title, Description: *tagInfo.Description,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,8 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"fusenapi/constants"
|
"fusenapi/constants"
|
||||||
"fusenapi/model"
|
"fusenapi/model/gmodel"
|
||||||
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
"fusenapi/utils/format"
|
"fusenapi/utils/format"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -31,9 +32,9 @@ func NewGetSizeByProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取分类下的产品以及尺寸
|
// 获取分类下的产品以及尺寸
|
||||||
func (l *GetSizeByProductLogic) GetSizeByProduct() (resp *types.Response) {
|
func (l *GetSizeByProductLogic) GetSizeByProduct(loginInfo *auth.UserInfo) (resp *types.Response) {
|
||||||
//获取所有网站目录
|
//获取所有网站目录
|
||||||
tagsModel := model.NewFsTagsModel(l.svcCtx.MysqlConn)
|
tagsModel := gmodel.NewFsTagsModel(l.svcCtx.MysqlConn)
|
||||||
tagsList, err := tagsModel.GetAllByLevel(l.ctx, constants.TYPE_WEBSITE)
|
tagsList, err := tagsModel.GetAllByLevel(l.ctx, constants.TYPE_WEBSITE)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
|
@ -42,41 +43,41 @@ func (l *GetSizeByProductLogic) GetSizeByProduct() (resp *types.Response) {
|
||||||
if len(tagsList) == 0 {
|
if len(tagsList) == 0 {
|
||||||
return resp.SetStatusWithMessage(basic.CodeOK, "tag list is null")
|
return resp.SetStatusWithMessage(basic.CodeOK, "tag list is null")
|
||||||
}
|
}
|
||||||
tagIds := make([]string, 0, len(tagsList))
|
tagIds := make([]int64, 0, len(tagsList))
|
||||||
for _, v := range tagsList {
|
for _, v := range tagsList {
|
||||||
tagIds = append(tagIds, fmt.Sprintf("%d", v.Id))
|
tagIds = append(tagIds, v.Id)
|
||||||
}
|
}
|
||||||
//获取这些类型的产品
|
//获取这些类型的产品
|
||||||
productModel := model.NewFsProductModel(l.svcCtx.MysqlConn)
|
productModel := gmodel.NewFsProductModel(l.svcCtx.MysqlConn)
|
||||||
productList, err := productModel.GetProductListByConditions(l.ctx, tagIds, "sort-desc")
|
productList, err := productModel.GetProductListByIds(l.ctx, tagIds, "sort-desc")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get tag product list")
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get tag product list")
|
||||||
}
|
}
|
||||||
productIds := make([]string, 0, len(productList))
|
productIds := make([]int64, 0, len(productList))
|
||||||
for _, v := range productList {
|
for _, v := range productList {
|
||||||
productIds = append(productIds, fmt.Sprintf("%d", v.Id))
|
productIds = append(productIds, v.Id)
|
||||||
}
|
}
|
||||||
productSizeModel := model.NewFsProductSizeModel(l.svcCtx.MysqlConn)
|
productSizeModel := gmodel.NewFsProductSizeModel(l.svcCtx.MysqlConn)
|
||||||
productSizeList, err := productSizeModel.GetAllByProductIds(l.ctx, productIds, "sort-desc")
|
productSizeList, err := productSizeModel.GetAllByProductIds(l.ctx, productIds, "sort-desc")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product size list")
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product size list")
|
||||||
}
|
}
|
||||||
sizeIds := make([]string, 0, len(productSizeList))
|
sizeIds := make([]int64, 0, len(productSizeList))
|
||||||
for _, v := range productSizeList {
|
for _, v := range productSizeList {
|
||||||
sizeIds = append(sizeIds, fmt.Sprintf("%d", v.Id))
|
sizeIds = append(sizeIds, v.Id)
|
||||||
}
|
}
|
||||||
//获取价格列表
|
//获取价格列表
|
||||||
productPriceModel := model.NewFsProductPriceModel(l.svcCtx.MysqlConn)
|
productPriceModel := gmodel.NewFsProductPriceModel(l.svcCtx.MysqlConn)
|
||||||
productPriceList, err := productPriceModel.GetPriceListBySizeIds(l.ctx, sizeIds)
|
productPriceList, err := productPriceModel.GetPriceListBySizeIds(l.ctx, sizeIds)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product proce list")
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product proce list")
|
||||||
}
|
}
|
||||||
mapProductPrice := make(map[int64]model.FsProductPrice)
|
mapProductPrice := make(map[int64]gmodel.FsProductPrice)
|
||||||
for _, v := range productPriceList {
|
for _, v := range productPriceList {
|
||||||
mapProductPrice[v.SizeId] = v
|
mapProductPrice[*v.SizeId] = v
|
||||||
}
|
}
|
||||||
//组装返回
|
//组装返回
|
||||||
list := make([]types.GetSizeByProductRsp, 0, len(tagsList))
|
list := make([]types.GetSizeByProductRsp, 0, len(tagsList))
|
||||||
|
@ -89,7 +90,7 @@ func (l *GetSizeByProductLogic) GetSizeByProduct() (resp *types.Response) {
|
||||||
}
|
}
|
||||||
data := types.GetSizeByProductRsp{
|
data := types.GetSizeByProductRsp{
|
||||||
Id: tag.Id,
|
Id: tag.Id,
|
||||||
Name: tag.Title,
|
Name: *tag.Title,
|
||||||
Children: firstChildrenList,
|
Children: firstChildrenList,
|
||||||
}
|
}
|
||||||
list = append(list, data)
|
list = append(list, data)
|
||||||
|
@ -98,21 +99,21 @@ func (l *GetSizeByProductLogic) GetSizeByProduct() (resp *types.Response) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 第一层子层
|
// 第一层子层
|
||||||
func (l *GetSizeByProductLogic) GetFirstChildrenList(tag model.FsTags, productList []model.FsProduct, productSizeList []model.FsProductSize, mapProductPrice map[int64]model.FsProductPrice) (childrenList []types.Children, err error) {
|
func (l *GetSizeByProductLogic) GetFirstChildrenList(tag gmodel.FsTags, productList []gmodel.FsProduct, productSizeList []gmodel.FsProductSize, mapProductPrice map[int64]gmodel.FsProductPrice) (childrenList []types.Children, err error) {
|
||||||
childrenList = make([]types.Children, 0, len(productList))
|
childrenList = make([]types.Children, 0, len(productList))
|
||||||
for _, product := range productList {
|
for _, product := range productList {
|
||||||
if product.Type != tag.Id {
|
if *product.Type != tag.Id {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
childrenObjList, err := l.GetSecondChildrenList(tag, product, productSizeList, mapProductPrice)
|
childrenObjList, err := l.GetSecondChildrenList(product, productSizeList, mapProductPrice)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
//获取第二层子类
|
//获取第二层子类
|
||||||
data := types.Children{
|
data := types.Children{
|
||||||
Id: product.Id,
|
Id: product.Id,
|
||||||
Name: product.Title,
|
Name: *product.Title,
|
||||||
Cycle: int(product.DeliveryDays + product.ProduceDays),
|
Cycle: int(*product.DeliveryDays + *product.ProduceDays),
|
||||||
ChildrenList: childrenObjList,
|
ChildrenList: childrenObjList,
|
||||||
}
|
}
|
||||||
childrenList = append(childrenList, data)
|
childrenList = append(childrenList, data)
|
||||||
|
@ -121,10 +122,10 @@ func (l *GetSizeByProductLogic) GetFirstChildrenList(tag model.FsTags, productLi
|
||||||
}
|
}
|
||||||
|
|
||||||
// 第2层子层
|
// 第2层子层
|
||||||
func (l *GetSizeByProductLogic) GetSecondChildrenList(tag model.FsTags, product model.FsProduct, productSizeList []model.FsProductSize, mapProductPrice map[int64]model.FsProductPrice) (childrenObjList []types.ChildrenObj, err error) {
|
func (l *GetSizeByProductLogic) GetSecondChildrenList(product gmodel.FsProduct, productSizeList []gmodel.FsProductSize, mapProductPrice map[int64]gmodel.FsProductPrice) (childrenObjList []types.ChildrenObj, err error) {
|
||||||
childrenObjList = make([]types.ChildrenObj, 0, len(productSizeList))
|
childrenObjList = make([]types.ChildrenObj, 0, len(productSizeList))
|
||||||
for _, productSize := range productSizeList {
|
for _, productSize := range productSizeList {
|
||||||
if product.Id != productSize.ProductId {
|
if product.Id != *productSize.ProductId {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
priceList := make([]types.PriceObj, 0, len(productSizeList))
|
priceList := make([]types.PriceObj, 0, len(productSizeList))
|
||||||
|
@ -133,7 +134,7 @@ func (l *GetSizeByProductLogic) GetSecondChildrenList(tag model.FsTags, product
|
||||||
if !ok {
|
if !ok {
|
||||||
childrenObjList = append(childrenObjList, types.ChildrenObj{
|
childrenObjList = append(childrenObjList, types.ChildrenObj{
|
||||||
Id: productSize.Id,
|
Id: productSize.Id,
|
||||||
Name: productSize.Capacity,
|
Name: *productSize.Capacity,
|
||||||
PriceList: []types.PriceObj{
|
PriceList: []types.PriceObj{
|
||||||
{Num: 1, Price: 0},
|
{Num: 1, Price: 0},
|
||||||
{Num: 1, Price: 0},
|
{Num: 1, Price: 0},
|
||||||
|
@ -142,18 +143,19 @@ func (l *GetSizeByProductLogic) GetSecondChildrenList(tag model.FsTags, product
|
||||||
})
|
})
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
price.StepNum = strings.Trim(price.StepNum, " ")
|
if price.StepNum == nil || price.StepPrice == nil {
|
||||||
price.StepPrice = strings.Trim(price.StepPrice, " ")
|
|
||||||
if price.StepNum == "" || price.StepPrice == "" {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
*price.StepNum = strings.Trim(*price.StepNum, " ")
|
||||||
|
*price.StepPrice = strings.Trim(*price.StepPrice, " ")
|
||||||
|
|
||||||
//阶梯数量切片
|
//阶梯数量切片
|
||||||
stepNum, err := format.StrSlicToIntSlice(strings.Split(price.StepNum, ","))
|
stepNum, err := format.StrSlicToIntSlice(strings.Split(*price.StepNum, ","))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
//阶梯价格切片
|
//阶梯价格切片
|
||||||
stepPrice, err := format.StrSlicToIntSlice(strings.Split(price.StepPrice, ","))
|
stepPrice, err := format.StrSlicToIntSlice(strings.Split(*price.StepPrice, ","))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -162,17 +164,17 @@ func (l *GetSizeByProductLogic) GetSecondChildrenList(tag model.FsTags, product
|
||||||
}
|
}
|
||||||
index := 0
|
index := 0
|
||||||
// 最小购买数量小于 最大阶梯数量+5
|
// 最小购买数量小于 最大阶梯数量+5
|
||||||
for int(price.MinBuyNum) < (stepNum[len(stepNum)-1]+5) && index < 3 {
|
for int(*price.MinBuyNum) < (stepNum[len(stepNum)-1]+5) && index < 3 {
|
||||||
priceList = append(priceList, types.PriceObj{
|
priceList = append(priceList, types.PriceObj{
|
||||||
Num: int(price.MinBuyNum * price.EachBoxNum),
|
Num: int(*price.MinBuyNum * *price.EachBoxNum),
|
||||||
Price: l.GetPrice(int(price.MinBuyNum), stepNum, stepPrice),
|
Price: l.GetPrice(int(*price.MinBuyNum), stepNum, stepPrice),
|
||||||
})
|
})
|
||||||
price.MinBuyNum++
|
*price.MinBuyNum++
|
||||||
index++
|
index++
|
||||||
}
|
}
|
||||||
data := types.ChildrenObj{
|
data := types.ChildrenObj{
|
||||||
Id: productSize.Id,
|
Id: productSize.Id,
|
||||||
Name: productSize.Capacity,
|
Name: *productSize.Capacity,
|
||||||
PriceList: priceList,
|
PriceList: priceList,
|
||||||
}
|
}
|
||||||
childrenObjList = append(childrenObjList, data)
|
childrenObjList = append(childrenObjList, data)
|
||||||
|
|
|
@ -2,15 +2,13 @@ package logic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"fusenapi/model/gmodel"
|
||||||
"fusenapi/model"
|
|
||||||
"fusenapi/server/product/internal/svc"
|
"fusenapi/server/product/internal/svc"
|
||||||
"fusenapi/server/product/internal/types"
|
"fusenapi/server/product/internal/types"
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
"fusenapi/utils/image"
|
"fusenapi/utils/image"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type GetSuccessRecommandLogic struct {
|
type GetSuccessRecommandLogic struct {
|
||||||
|
@ -28,20 +26,16 @@ func NewGetSuccessRecommandLogic(ctx context.Context, svcCtx *svc.ServiceContext
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取推荐的产品列表
|
// 获取推荐的产品列表
|
||||||
func (l *GetSuccessRecommandLogic) GetSuccessRecommand(req *types.GetSuccessRecommandReq) (resp *types.Response) {
|
func (l *GetSuccessRecommandLogic) GetSuccessRecommand(req *types.GetSuccessRecommandReq, loginInfo *auth.UserInfo) (resp *types.Response) {
|
||||||
resp = &types.Response{}
|
resp = &types.Response{}
|
||||||
loginInfo := auth.GetUserInfoFormCtx(l.ctx)
|
|
||||||
if loginInfo.UserId == 0 {
|
|
||||||
return resp.SetStatusWithMessage(basic.CodeUnAuth, "get login user info err")
|
|
||||||
}
|
|
||||||
//获取用户信息
|
//获取用户信息
|
||||||
userModel := model.NewFsUserModel(l.svcCtx.MysqlConn)
|
userModel := gmodel.NewFsUserModel(l.svcCtx.MysqlConn)
|
||||||
userInfo, err := userModel.FindOne(l.ctx, loginInfo.UserId)
|
userInfo, err := userModel.FindOne(l.ctx, loginInfo.UserId)
|
||||||
if err != nil && errors.Is(err, sqlx.ErrNotFound) {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get user info")
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get user info")
|
||||||
}
|
}
|
||||||
if userInfo == nil {
|
if userInfo.Id == 0 {
|
||||||
return resp.SetStatusWithMessage(basic.CodeUnAuth, "failed to get user info")
|
return resp.SetStatusWithMessage(basic.CodeUnAuth, "failed to get user info")
|
||||||
}
|
}
|
||||||
if req.Num == 0 || req.Num > 500 {
|
if req.Num == 0 || req.Num > 500 {
|
||||||
|
@ -51,7 +45,7 @@ func (l *GetSuccessRecommandLogic) GetSuccessRecommand(req *types.GetSuccessReco
|
||||||
req.Size = image.GetCurrentSize(req.Size)
|
req.Size = image.GetCurrentSize(req.Size)
|
||||||
}
|
}
|
||||||
//随机取8个产品
|
//随机取8个产品
|
||||||
productModel := model.NewFsProductModel(l.svcCtx.MysqlConn)
|
productModel := gmodel.NewFsProductModel(l.svcCtx.MysqlConn)
|
||||||
productList, err := productModel.GetRandomProductList(l.ctx, int(req.Num))
|
productList, err := productModel.GetRandomProductList(l.ctx, int(req.Num))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
|
@ -64,8 +58,8 @@ func (l *GetSuccessRecommandLogic) GetSuccessRecommand(req *types.GetSuccessReco
|
||||||
list := make([]types.GetSuccessRecommandRsp, 0, len(productList))
|
list := make([]types.GetSuccessRecommandRsp, 0, len(productList))
|
||||||
for _, v := range productList {
|
for _, v := range productList {
|
||||||
data := types.GetSuccessRecommandRsp{
|
data := types.GetSuccessRecommandRsp{
|
||||||
Title: v.Title,
|
Title: *v.Title,
|
||||||
Sn: v.Sn,
|
Sn: *v.Sn,
|
||||||
Id: v.Id,
|
Id: v.Id,
|
||||||
SkuId: 0, //???????
|
SkuId: 0, //???????
|
||||||
}
|
}
|
||||||
|
@ -73,11 +67,11 @@ func (l *GetSuccessRecommandLogic) GetSuccessRecommand(req *types.GetSuccessReco
|
||||||
thousandFaceImageFormatReq := image.ThousandFaceImageFormatReq{
|
thousandFaceImageFormatReq := image.ThousandFaceImageFormatReq{
|
||||||
Size: int(req.Size),
|
Size: int(req.Size),
|
||||||
IsThousandFace: int(userInfo.IsThousandFace),
|
IsThousandFace: int(userInfo.IsThousandFace),
|
||||||
Cover: v.Cover,
|
Cover: *v.Cover,
|
||||||
CoverImg: v.CoverImg,
|
CoverImg: *v.CoverImg,
|
||||||
CoverDefault: v.CoverImg,
|
CoverDefault: *v.CoverImg,
|
||||||
ProductId: v.Id,
|
ProductId: v.Id,
|
||||||
UserInfo: *userInfo,
|
UserInfo: userInfo,
|
||||||
}
|
}
|
||||||
image.ThousandFaceImageFormat(&thousandFaceImageFormatReq)
|
image.ThousandFaceImageFormat(&thousandFaceImageFormatReq)
|
||||||
data.Cover = thousandFaceImageFormatReq.Cover
|
data.Cover = thousandFaceImageFormatReq.Cover
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
package svc
|
package svc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
"fusenapi/initalize"
|
"fusenapi/initalize"
|
||||||
"fusenapi/server/product/internal/config"
|
"fusenapi/server/product/internal/config"
|
||||||
|
"github.com/golang-jwt/jwt"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ServiceContext struct {
|
type ServiceContext struct {
|
||||||
|
@ -13,8 +17,35 @@ type ServiceContext struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServiceContext(c config.Config) *ServiceContext {
|
func NewServiceContext(c config.Config) *ServiceContext {
|
||||||
|
|
||||||
return &ServiceContext{
|
return &ServiceContext{
|
||||||
Config: c,
|
Config: c,
|
||||||
MysqlConn: initalize.InitMysql(c.SourceMysql),
|
MysqlConn: initalize.InitMysql(c.DataSource),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (svcCxt *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
|
||||||
|
AuthKey := r.Header.Get("Authorization")
|
||||||
|
if len(AuthKey) <= 50 {
|
||||||
|
return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey)))
|
||||||
|
}
|
||||||
|
|
||||||
|
token, err := jwt.Parse(AuthKey, func(token *jwt.Token) (interface{}, error) {
|
||||||
|
// 检查签名方法是否为 HS256
|
||||||
|
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
|
||||||
|
}
|
||||||
|
// 返回用于验证签名的密钥
|
||||||
|
return svcCxt.Config.Auth.AccessSecret, nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New(fmt.Sprint("Error parsing token:", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证成功返回
|
||||||
|
if claims, ok := token.Claims.(jwt.MapClaims); ok && token.Valid {
|
||||||
|
return claims, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, errors.New(fmt.Sprint("Invalid token", err))
|
||||||
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package image
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"fusenapi/constants"
|
"fusenapi/constants"
|
||||||
"fusenapi/model"
|
"fusenapi/model/gmodel"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
@ -41,7 +41,7 @@ type ThousandFaceImageFormatReq struct {
|
||||||
CoverImg string
|
CoverImg string
|
||||||
CoverDefault string
|
CoverDefault string
|
||||||
ProductId int64
|
ProductId int64
|
||||||
UserInfo model.FsUser
|
UserInfo gmodel.FsUser
|
||||||
}
|
}
|
||||||
|
|
||||||
func ThousandFaceImageFormat(req *ThousandFaceImageFormatReq) {
|
func ThousandFaceImageFormat(req *ThousandFaceImageFormatReq) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user