feat: import services and standardize Go 1.26.5
This commit is contained in:
48
apps/ec/mall/internal/logic/category/create.go
Normal file
48
apps/ec/mall/internal/logic/category/create.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package category
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-ec/mall/internal/impl"
|
||||
pb "git.apinb.com/bsm-ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
"git.apinb.com/bsm-sdk/core/utils"
|
||||
)
|
||||
|
||||
// 添加分类
|
||||
func Create(ctx context.Context, in *pb.CategoryItem) (reply *pb.StatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
AUTH, err := service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if in.GetTitle() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
data, err := ref(in)
|
||||
if err != nil {
|
||||
return nil, errcode.ErrInternal
|
||||
}
|
||||
data.Identity = utils.UUID()
|
||||
owner := AUTH.Owner.(map[string]any)
|
||||
data.Store_ID = uint(owner["store_id"].(float64))
|
||||
data.Store_Identity = owner["store_identity"].(string)
|
||||
|
||||
err = impl.DBService.Create(&data).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Identity: data.Identity,
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
40
apps/ec/mall/internal/logic/category/delete.go
Normal file
40
apps/ec/mall/internal/logic/category/delete.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package category
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-ec/mall/internal/impl"
|
||||
"git.apinb.com/bsm-ec/mall/internal/models"
|
||||
pb "git.apinb.com/bsm-ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// 删除分类
|
||||
func Delete(ctx context.Context, in *pb.IdentRequest) (reply *pb.StatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// valildate request id,identity.
|
||||
if in.Id == 0 && in.Identity == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
err = impl.DBService.Where("id=? or identity=?", in.GetId(), in.GetIdentity()).Delete(&models.MallCategory{}).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
34
apps/ec/mall/internal/logic/category/fetch.go
Normal file
34
apps/ec/mall/internal/logic/category/fetch.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package category
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.apinb.com/bsm-ec/mall/internal/models"
|
||||
pb "git.apinb.com/bsm-ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
)
|
||||
|
||||
// 获取分类数据
|
||||
func Fetch(ctx context.Context, in *pb.CategoryFetchRequest) (reply *pb.CategoryReply, err error) {
|
||||
if in.GetStoreIdentity() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
var (
|
||||
category = "all" // all全部,first1级
|
||||
)
|
||||
|
||||
if in.GetTypes() != "" {
|
||||
category = in.GetTypes()
|
||||
}
|
||||
data, err := models.GetCategoryList(in.GetKeywords(), in.GetStoreIdentity(), in.GetId())
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
return &pb.CategoryReply{
|
||||
Data: refList(data, category),
|
||||
Count: int64(len(data)),
|
||||
}, nil
|
||||
}
|
||||
43
apps/ec/mall/internal/logic/category/modify.go
Normal file
43
apps/ec/mall/internal/logic/category/modify.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package category
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-ec/mall/internal/impl"
|
||||
pb "git.apinb.com/bsm-ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// 修改分类
|
||||
func Modify(ctx context.Context, in *pb.CategoryItem) (reply *pb.StatusReply, err error) {
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if in.GetTitle() == "" || in.GetIdentity() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
data, err := ref(in)
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrInternal
|
||||
}
|
||||
err = impl.DBService.Select("title", "en_title", "parent_id", "paths", "intro", "icon", "sort", "status", "keys").Where("identity=?", in.GetIdentity()).Updates(&data).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Identity: in.Identity,
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().Unix(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
51
apps/ec/mall/internal/logic/category/ref.go
Normal file
51
apps/ec/mall/internal/logic/category/ref.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package category
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"git.apinb.com/bsm-ec/mall/internal/models"
|
||||
pb "git.apinb.com/bsm-ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/vars"
|
||||
)
|
||||
|
||||
// ref 获取分类详情
|
||||
func ref(in *pb.CategoryItem) (*models.MallCategory, error) {
|
||||
var category = models.MallCategory{}
|
||||
data, err := json.Marshal(in)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = json.Unmarshal(data, &category)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &category, err
|
||||
}
|
||||
|
||||
func refList(data []*models.MallCategory, types string) (list []*pb.CategoryItem) {
|
||||
if len(data) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
for _, v := range data {
|
||||
low := pb.CategoryItem{
|
||||
Id: int64(v.ID),
|
||||
Identity: v.Identity,
|
||||
Title: v.Title,
|
||||
EnTitle: v.EnTitle,
|
||||
Keys: v.Keys,
|
||||
ParentId: v.ParentID,
|
||||
Paths: v.Paths,
|
||||
Intro: v.Intro,
|
||||
Icon: v.Icon,
|
||||
Sort: v.Sort,
|
||||
CreatedAt: v.CreatedAt.Format(vars.YYYY_MM_DD_HH_MM_SS),
|
||||
Status: int32(v.Status),
|
||||
}
|
||||
if types == "all" {
|
||||
low.Categories = refList(v.Categories, types)
|
||||
}
|
||||
list = append(list, &low)
|
||||
}
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user