Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion model/manage/manage_goods_category.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

type MallGoodsCategory struct {
CategoryId int `json:"categoryId"gorm:"primarykey;AUTO_INCREMENT"`
CategoryId int `json:"categoryId" gorm:"primarykey;AUTO_INCREMENT"`
CategoryLevel int `json:"categoryLevel" gorm:"comment:分类等级"`
ParentId int `json:"parentId" gorm:"comment:父类id"`
CategoryName string `json:"categoryName" gorm:"comment:分类名称"`
Expand Down
7 changes: 6 additions & 1 deletion router/manage/manage_goods_category.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ func (r *ManageGoodsCategoryRouter) InitManageGoodsCategoryRouter(Router *gin.Ro
goodsCategoryRouter.GET("categories", goodsCategoryApi.GetCategoryList)
goodsCategoryRouter.GET("categories/:id", goodsCategoryApi.GetCategory)
goodsCategoryRouter.DELETE("categories", goodsCategoryApi.DelCategory)
goodsCategoryRouter.GET("categories4Select", goodsCategoryApi.ListForSelect)
// TODO:这个路由有错误:由于 URL 中没有名为 id 的路径参数,函数中直接调用 c.Param("id") 在这个示例中将无法获取到任何值
// goodsCategoryRouter.GET("categories4Select", goodsCategoryApi.ListForSelect)
// fix1:
goodsCategoryRouter.GET("categories4Select/:id", goodsCategoryApi.ListForSelect)
// fix2:
// goodsCategoryRouter.GET("categories4Select", goodsCategoryApi.ListForSelect) goodsCategoryApi.ListForSelect函数中使用c.Query("id")获取参数
}
}
7 changes: 4 additions & 3 deletions service/example/exa_file_upload_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package example

import (
"errors"
"mime/multipart"
"strings"

"main.go/global"
"main.go/model/common/request"
"main.go/model/example"
"main.go/utils/upload"
"mime/multipart"
"strings"
)

//@author: [piexlmax](https://github.com/piexlmax)
Expand Down Expand Up @@ -81,7 +82,7 @@ func (e *FileUploadAndDownloadService) UploadFile(header *multipart.FileHeader,
oss := upload.NewOss()
filePath, key, uploadErr := oss.UploadFile(header)
if uploadErr != nil {
panic(err)
panic(uploadErr) // 如果使用panic(err) 此时的err没有获得报错信息,不够准确
}
if noSave == "0" {
s := strings.Split(header.Filename, ".")
Expand Down
8 changes: 6 additions & 2 deletions service/manage/manage_goods_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package manage

import (
"errors"
"strconv"
"time"

"gorm.io/gorm"
"main.go/global"
"main.go/model/common"
Expand All @@ -10,8 +13,6 @@ import (
"main.go/model/manage"
manageReq "main.go/model/manage/request"
"main.go/utils"
"strconv"
"time"
)

type ManageGoodsInfoService struct {
Expand All @@ -21,6 +22,9 @@ type ManageGoodsInfoService struct {
func (m *ManageGoodsInfoService) CreateMallGoodsInfo(req manageReq.GoodsInfoAddParam) (err error) {
var goodsCategory manage.MallGoodsCategory
err = global.GVA_DB.Where("category_id=? AND is_deleted=0", req.GoodsCategoryId).First(&goodsCategory).Error
if err != nil { // 新增错误处理
return
}
if goodsCategory.CategoryLevel != enum.LevelThree.Code() {
return errors.New("分类数据异常")
}
Expand Down
9 changes: 5 additions & 4 deletions service/manage/manage_index_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package manage

import (
"errors"
"strconv"
"time"

"gorm.io/gorm"
"main.go/global"
"main.go/model/common"
"main.go/model/common/request"
"main.go/model/manage"
manageReq "main.go/model/manage/request"
"main.go/utils"
"strconv"
"time"
)

type ManageIndexConfigService struct {
Expand All @@ -22,7 +23,7 @@ func (m *ManageIndexConfigService) CreateMallIndexConfig(req manageReq.MallIndex
if errors.Is(global.GVA_DB.Where("goods_id=?", req.GoodsId).First(&goodsInfo).Error, gorm.ErrRecordNotFound) {
return errors.New("商品不存在")
}
if errors.Is(global.GVA_DB.Where("config_type =? and goods_id=? and is_deleted=0", req.ConfigType, req.GoodsId).First(&manage.MallIndexConfig{}).Error, gorm.ErrRecordNotFound) {
if !errors.Is(global.GVA_DB.Where("config_type =? and goods_id=? and is_deleted=0", req.ConfigType, req.GoodsId).First(&manage.MallIndexConfig{}).Error, gorm.ErrRecordNotFound) {
return errors.New("已存在相同的首页配置项")
}
goodsId, _ := strconv.Atoi(req.GoodsId)
Expand Down Expand Up @@ -74,7 +75,7 @@ func (m *ManageIndexConfigService) UpdateMallIndexConfig(req manageReq.MallIndex
}
var newIndexConfig manage.MallIndexConfig
err = global.GVA_DB.Where("config_type=? and goods_id=?", mallIndexConfig.ConfigType, mallIndexConfig.GoodsId).First(&newIndexConfig).Error
if err != nil && newIndexConfig.ConfigId == mallIndexConfig.ConfigId {
if err == nil && newIndexConfig.ConfigId == mallIndexConfig.ConfigId {
return errors.New("已存在相同的首页配置项")
}
err = global.GVA_DB.Where("config_id=?", mallIndexConfig.ConfigId).Updates(&mallIndexConfig).Error
Expand Down