feat: import services and standardize Go 1.26.5
This commit is contained in:
29
apps/ec/mall/internal/logic/ads/by_pos.go
Normal file
29
apps/ec/mall/internal/logic/ads/by_pos.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package ads
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
// 通过广告位获取广告信息
|
||||
func ByPos(ctx context.Context, in *pb.ByPosRequest) (reply *pb.AdsListReply, err error) {
|
||||
if in.GetStoreIdentity() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
result := make([]*pb.AdsItem, 0)
|
||||
|
||||
err = impl.DBService.Model(&models.MallAds{}).Where("store_identity=? and pos_key in ?", in.StoreIdentity, in.PosKey).Find(&result).Error
|
||||
if err != nil {
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.AdsListReply{
|
||||
Data: result,
|
||||
Count: int64(len(result)),
|
||||
}, nil
|
||||
}
|
||||
54
apps/ec/mall/internal/logic/ads/create.go
Normal file
54
apps/ec/mall/internal/logic/ads/create.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package ads
|
||||
|
||||
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"
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
"git.apinb.com/bsm-sdk/core/utils"
|
||||
)
|
||||
|
||||
// 新建广告
|
||||
func Create(ctx context.Context, in *pb.AdsItem) (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 := models.MallAds{
|
||||
Std_IICUDS: types.Std_IICUDS{Identity: utils.UUID(), Status: 1},
|
||||
Title: in.Title,
|
||||
PosKey: in.PosKey,
|
||||
Content: in.Content,
|
||||
Type: models.ContentType(in.Type),
|
||||
ToUrl: in.ToUrl,
|
||||
}
|
||||
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{
|
||||
Identity: data.Identity,
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().Unix(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
40
apps/ec/mall/internal/logic/ads/delete.go
Normal file
40
apps/ec/mall/internal/logic/ads/delete.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package ads
|
||||
|
||||
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.MallAds{}).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
50
apps/ec/mall/internal/logic/ads/fetch.go
Normal file
50
apps/ec/mall/internal/logic/ads/fetch.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package ads
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
// 广告列表
|
||||
func Fetch(ctx context.Context, in *pb.FetchRequest) (reply *pb.AdsListReply, err error) {
|
||||
if in.GetStoreIdentity() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
var (
|
||||
cnt int64 = 0
|
||||
pageNo int64 = in.GetPageNo()
|
||||
pageSize int64 = in.GetPageSize()
|
||||
offset int64 = (pageNo - 1) * pageSize
|
||||
params = map[string]string{
|
||||
"store_identity": in.GetStoreIdentity(),
|
||||
}
|
||||
)
|
||||
|
||||
// vlidate request page_no,page_size.
|
||||
if pageNo < 1 {
|
||||
pageNo = 1
|
||||
offset = 0
|
||||
}
|
||||
if pageSize < 50 {
|
||||
pageSize = 50
|
||||
offset = (pageNo - 1) * pageSize
|
||||
}
|
||||
|
||||
var data []*models.MallAds
|
||||
if err := impl.DBService.Model(&models.MallAds{}).Where(params).Order("created_at desc").Count(&cnt).Offset(int(offset)).
|
||||
Limit(int(pageSize)).Find(&data).Error; err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.AdsListReply{
|
||||
Count: cnt,
|
||||
Data: ref(data),
|
||||
}, nil
|
||||
}
|
||||
50
apps/ec/mall/internal/logic/ads/modify.go
Normal file
50
apps/ec/mall/internal/logic/ads/modify.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package ads
|
||||
|
||||
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"
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
)
|
||||
|
||||
// 修改广告
|
||||
func Modify(ctx context.Context, in *pb.AdsItem) (reply *pb.StatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// valid must params.
|
||||
if in.GetId() == 0 {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
data := models.MallAds{
|
||||
Title: in.Title,
|
||||
PosKey: in.PosKey,
|
||||
Content: in.Content,
|
||||
Type: models.ContentType(in.Type),
|
||||
ToUrl: in.ToUrl,
|
||||
Std_IICUDS: types.Std_IICUDS{Status: int8(in.GetStatus())},
|
||||
}
|
||||
|
||||
err = impl.DBService.Select("title", "pos_key", "content", "type", "to_url").Where("id=?", in.GetId()).Updates(&data).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().Unix(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
28
apps/ec/mall/internal/logic/ads/ref.go
Normal file
28
apps/ec/mall/internal/logic/ads/ref.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package ads
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-ec/mall/internal/models"
|
||||
pb "git.apinb.com/bsm-ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/vars"
|
||||
)
|
||||
|
||||
func ref(data []*models.MallAds) (list []*pb.AdsItem) {
|
||||
if len(data) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
for _, in := range data {
|
||||
row := pb.AdsItem{
|
||||
Id: int64(in.ID),
|
||||
Title: in.Title,
|
||||
PosKey: in.PosKey,
|
||||
Content: in.Content,
|
||||
Type: int32(in.Type),
|
||||
ToUrl: in.ToUrl,
|
||||
CreatedAt: in.CreatedAt.Format(vars.YYYY_MM_DD_HH_MM_SS),
|
||||
}
|
||||
|
||||
list = append(list, &row)
|
||||
}
|
||||
return
|
||||
}
|
||||
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
|
||||
}
|
||||
32
apps/ec/mall/internal/logic/freight/create.go
Normal file
32
apps/ec/mall/internal/logic/freight/create.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package freight
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
pb "git.apinb.com/bsm-ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// Create 运费模板创建
|
||||
func Create(ctx context.Context, in *pb.FreightItem) (reply *pb.StatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if in.GetTitle() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().Unix(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
33
apps/ec/mall/internal/logic/freight/delete.go
Normal file
33
apps/ec/mall/internal/logic/freight/delete.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package freight
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
pb "git.apinb.com/bsm-ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"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, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// valildate request id,identity.
|
||||
if in.Id == 0 && in.Identity == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().UnixNano(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
32
apps/ec/mall/internal/logic/freight/deny_region_create.go
Normal file
32
apps/ec/mall/internal/logic/freight/deny_region_create.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package freight
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
pb "git.apinb.com/bsm-ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// CreateRegion 新建限制区域
|
||||
func DenyRegionCreate(ctx context.Context, in *pb.DenyRegionItem) (reply *pb.StatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if in.GetTitle() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().Unix(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
32
apps/ec/mall/internal/logic/freight/deny_region_delete.go
Normal file
32
apps/ec/mall/internal/logic/freight/deny_region_delete.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package freight
|
||||
|
||||
import (
|
||||
"context"
|
||||
pb "git.apinb.com/bsm-ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 移除限制区域
|
||||
func DenyRegionDelete(ctx context.Context, in *pb.IdentRequest) (reply *pb.StatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// valildate request id,identity.
|
||||
if in.Id == 0 && in.Identity == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().UnixNano(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
28
apps/ec/mall/internal/logic/freight/deny_region_fetch.go
Normal file
28
apps/ec/mall/internal/logic/freight/deny_region_fetch.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package freight
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
pb "git.apinb.com/bsm-ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// DenyRegionFetch 限制区域列表
|
||||
func DenyRegionFetch(ctx context.Context, in *pb.FetchRequest) (reply *pb.DenyRegionReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// valildate request page_no,page_size.
|
||||
if in.GetPageNo() < 1 {
|
||||
in.PageNo = 1
|
||||
}
|
||||
if in.GetPageSize() < 10 {
|
||||
in.PageSize = 50
|
||||
}
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return
|
||||
}
|
||||
29
apps/ec/mall/internal/logic/freight/deny_region_modify.go
Normal file
29
apps/ec/mall/internal/logic/freight/deny_region_modify.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package freight
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
pb "git.apinb.com/bsm-ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// ModifyRegion 编辑限制区域
|
||||
func DenyRegionModify(ctx context.Context, in *pb.DenyRegionItem) (reply *pb.StatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// TODO: valid code
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().Unix(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
33
apps/ec/mall/internal/logic/freight/deny_region_remove.go
Normal file
33
apps/ec/mall/internal/logic/freight/deny_region_remove.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package freight
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
pb "git.apinb.com/bsm-ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// RemoveRegion 移除限制区域
|
||||
func DenyRegionRemove(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
|
||||
}
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().Unix(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
27
apps/ec/mall/internal/logic/freight/detail.go
Normal file
27
apps/ec/mall/internal/logic/freight/detail.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package freight
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
pb "git.apinb.com/bsm-ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// Detail 运费模板详情
|
||||
func Detail(ctx context.Context, in *pb.IdentRequest) (reply *pb.FreightItem, 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
|
||||
}
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return
|
||||
}
|
||||
29
apps/ec/mall/internal/logic/freight/fetch.go
Normal file
29
apps/ec/mall/internal/logic/freight/fetch.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package freight
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
pb "git.apinb.com/bsm-ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// Freight 运费模板列表
|
||||
func Fetch(ctx context.Context, in *pb.FetchRequest) (reply *pb.FreightReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// valildate request page_no,page_size.
|
||||
if in.GetPageNo() < 1 {
|
||||
in.PageNo = 1
|
||||
}
|
||||
if in.GetPageSize() < 10 {
|
||||
in.PageSize = 50
|
||||
}
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return
|
||||
}
|
||||
32
apps/ec/mall/internal/logic/freight/modify.go
Normal file
32
apps/ec/mall/internal/logic/freight/modify.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package freight
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
pb "git.apinb.com/bsm-ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// Modify 运费模板修改
|
||||
func Modify(ctx context.Context, in *pb.FreightItem) (reply *pb.StatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if in.GetTitle() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
40
apps/ec/mall/internal/logic/freight/remove.go
Normal file
40
apps/ec/mall/internal/logic/freight/remove.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package freight
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
// FreightRemove 运费模板删除
|
||||
func Remove(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.MallFreight{}).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
53
apps/ec/mall/internal/logic/notice/create.go
Normal file
53
apps/ec/mall/internal/logic/notice/create.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package notice
|
||||
|
||||
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"
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
"git.apinb.com/bsm-sdk/core/utils"
|
||||
)
|
||||
|
||||
// 新建公告
|
||||
func Create(ctx context.Context, in *pb.NoticeItem) (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 := models.MallNotice{
|
||||
Title: in.Title,
|
||||
Author: in.Author,
|
||||
Content: in.Content,
|
||||
Std_IICUDS: types.Std_IICUDS{Identity: utils.UUID(), Status: 1},
|
||||
}
|
||||
|
||||
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",
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
40
apps/ec/mall/internal/logic/notice/delete.go
Normal file
40
apps/ec/mall/internal/logic/notice/delete.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package notice
|
||||
|
||||
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.MallNotice{}).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
51
apps/ec/mall/internal/logic/notice/fetch.go
Normal file
51
apps/ec/mall/internal/logic/notice/fetch.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package notice
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
// 公告列表
|
||||
func Fetch(ctx context.Context, in *pb.FetchRequest) (reply *pb.NoticeListReply, err error) {
|
||||
|
||||
if in.GetStoreIdentity() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
var (
|
||||
cnt int64 = 0
|
||||
pageNo int64 = in.GetPageNo()
|
||||
pageSize int64 = in.GetPageSize()
|
||||
offset int64 = (pageNo - 1) * pageSize
|
||||
params = map[string]string{
|
||||
"store_identity": in.GetStoreIdentity(),
|
||||
}
|
||||
)
|
||||
|
||||
// vlidate request page_no,page_size.
|
||||
if pageNo < 1 {
|
||||
pageNo = 1
|
||||
offset = 0
|
||||
}
|
||||
if pageSize < 50 {
|
||||
pageSize = 50
|
||||
offset = (pageNo - 1) * pageSize
|
||||
}
|
||||
|
||||
var data []*models.MallNotice
|
||||
if err := impl.DBService.Model(&models.MallNotice{}).Where(params).Order("created_at desc").Count(&cnt).Offset(int(offset)).Limit(int(pageSize)).Find(&data).Error; err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return &pb.NoticeListReply{
|
||||
Count: cnt,
|
||||
Data: ref(data),
|
||||
}, nil
|
||||
}
|
||||
47
apps/ec/mall/internal/logic/notice/modify.go
Normal file
47
apps/ec/mall/internal/logic/notice/modify.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package notice
|
||||
|
||||
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"
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
)
|
||||
|
||||
// 修改公告
|
||||
func Modify(ctx context.Context, in *pb.NoticeItem) (reply *pb.StatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if in.GetTitle() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
// TODO: add your logic code & delete this line.
|
||||
data := models.MallNotice{
|
||||
Title: in.Title,
|
||||
Author: in.Author,
|
||||
Content: in.Content,
|
||||
Std_IICUDS: types.Std_IICUDS{Status: int8(in.GetStatus())},
|
||||
}
|
||||
err = impl.DBService.Model(&models.MallNotice{}).Select("title", "author", "content").Where("identity = ?", in.Identity).Updates(&data).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Identity: in.GetIdentity(),
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
29
apps/ec/mall/internal/logic/notice/ref.go
Normal file
29
apps/ec/mall/internal/logic/notice/ref.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package notice
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-ec/mall/internal/models"
|
||||
pb "git.apinb.com/bsm-ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/vars"
|
||||
)
|
||||
|
||||
func ref(data []*models.MallNotice) (list []*pb.NoticeItem) {
|
||||
if len(data) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
for _, in := range data {
|
||||
row := pb.NoticeItem{
|
||||
Identity: in.Identity,
|
||||
Title: in.Title,
|
||||
StoreId: int64(in.Store_ID),
|
||||
StoreIdentity: in.Store_Identity,
|
||||
Author: in.Author,
|
||||
Content: in.Content,
|
||||
CreatedAt: in.CreatedAt.Format(vars.YYYY_MM_DD_HH_MM_SS),
|
||||
Status: int64(in.Status),
|
||||
}
|
||||
|
||||
list = append(list, &row)
|
||||
}
|
||||
return
|
||||
}
|
||||
71
apps/ec/mall/internal/logic/product/comment_create.go
Normal file
71
apps/ec/mall/internal/logic/product/comment_create.go
Normal file
@@ -0,0 +1,71 @@
|
||||
package product
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"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"
|
||||
"git.apinb.com/bsm-sdk/core/utils"
|
||||
)
|
||||
|
||||
// CreateComment 评论
|
||||
func CommentCreate(ctx context.Context, in *pb.CommentItem) (reply *pb.StatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
RoleValve := &service.ParseOptions{RoleValue: "Mall_Admin"}
|
||||
if in.GetIsComment() == true {
|
||||
RoleValve = nil
|
||||
}
|
||||
auth, err := service.ParseMetaCtx(ctx, RoleValve)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if in.GetComment() == "" || in.GetNickName() == "" || in.GetProductIdentity() == "" || in.GetStoreIdentity() == "" || in.GetSpecIdentity() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
// 组装model
|
||||
data, err := itemToCommentModel(in)
|
||||
if err != nil {
|
||||
return nil, errcode.ErrInternal
|
||||
}
|
||||
data.OwnerID = auth.ID
|
||||
data.OwnerIdentity = auth.Identity
|
||||
data.ProductIdentity = in.ProductIdentity
|
||||
data.SpecIdentity = in.SpecIdentity
|
||||
data.StoreIdentity = in.StoreIdentity
|
||||
data.Identity = utils.UUID()
|
||||
|
||||
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
|
||||
|
||||
}
|
||||
|
||||
func itemToCommentModel(in *pb.CommentItem) (*models.MallProductComment, error) {
|
||||
var commentProduct = models.MallProductComment{}
|
||||
data, err := json.Marshal(in)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = json.Unmarshal(data, &commentProduct)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &commentProduct, err
|
||||
}
|
||||
40
apps/ec/mall/internal/logic/product/comment_delete.go
Normal file
40
apps/ec/mall/internal/logic/product/comment_delete.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package product
|
||||
|
||||
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 CommentDelete(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=? or comment_identity=?", in.GetId(), in.GetIdentity(), in.GetIdentity()).Delete(&models.MallProductComment{}).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().UnixNano(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
91
apps/ec/mall/internal/logic/product/comment_fetch.go
Normal file
91
apps/ec/mall/internal/logic/product/comment_fetch.go
Normal file
@@ -0,0 +1,91 @@
|
||||
package product
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
// 产品的评论列表
|
||||
func CommentFetch(ctx context.Context, in *pb.FetchRequest) (reply *pb.CommentListReply, err error) {
|
||||
// valildate request id,identity.
|
||||
if in.GetStoreIdentity() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
var (
|
||||
cnt int64 = 0
|
||||
pageNo int64 = in.GetPageNo()
|
||||
pageSize int64 = in.GetPageSize()
|
||||
offset int64 = (pageNo - 1) * pageSize
|
||||
params = map[string]string{
|
||||
"store_identity": in.GetStoreIdentity(),
|
||||
}
|
||||
data = make([]models.MallProductComment, 0)
|
||||
res = make([]*pb.CommentItemRep, 0)
|
||||
)
|
||||
|
||||
// vlidate request page_no,page_size.
|
||||
if pageNo < 1 {
|
||||
pageNo = 1
|
||||
offset = 0
|
||||
}
|
||||
if pageSize < 50 {
|
||||
pageSize = 50
|
||||
offset = (pageNo - 1) * pageSize
|
||||
}
|
||||
|
||||
if err := impl.DBService.Model(&models.MallProductComment{}).Preload("List").Where(params).
|
||||
Order("created_at desc").Count(&cnt).Offset(int(offset)).Limit(int(pageSize)).Find(&data).Error; err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
for _, val := range data {
|
||||
line := &pb.CommentItemRep{
|
||||
Id: int64(val.ID),
|
||||
Identity: val.Identity,
|
||||
CreatedAt: val.CreatedAt.Format(time.DateTime),
|
||||
NickName: val.Nickname,
|
||||
Score: int32(val.Score),
|
||||
Comment: val.Comment,
|
||||
Reply: val.Reply,
|
||||
ProductIdentity: val.ProductIdentity,
|
||||
StoreIdentity: val.StoreIdentity,
|
||||
SpecIdentity: val.SpecIdentity,
|
||||
CommentIdentity: val.CommentIdentity,
|
||||
Product: val.Product.Title,
|
||||
ProductSpec: val.ProductSpec.Title,
|
||||
}
|
||||
if len(val.List) > 0 {
|
||||
for _, v := range val.List {
|
||||
line.List = append(line.List, &pb.CommentItem{
|
||||
Id: int64(v.ID),
|
||||
Identity: v.Identity,
|
||||
CreatedAt: v.CreatedAt.Format(time.DateTime),
|
||||
NickName: v.Nickname,
|
||||
Score: int32(v.Score),
|
||||
Comment: v.Comment,
|
||||
Reply: v.Reply,
|
||||
ProductIdentity: v.ProductIdentity,
|
||||
StoreIdentity: v.StoreIdentity,
|
||||
SpecIdentity: v.SpecIdentity,
|
||||
CommentIdentity: v.CommentIdentity,
|
||||
Product: v.Product.Title,
|
||||
ProductSpec: v.ProductSpec.Title,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
res = append(res, line)
|
||||
}
|
||||
return &pb.CommentListReply{
|
||||
Data: res,
|
||||
Count: cnt,
|
||||
}, nil
|
||||
}
|
||||
43
apps/ec/mall/internal/logic/product/comment_modify.go
Normal file
43
apps/ec/mall/internal/logic/product/comment_modify.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package product
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
// ModifyComment 修改评论
|
||||
func CommentModify(ctx context.Context, in *pb.CommentItem) (reply *pb.StatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if in.GetIdentity() == "" || in.GetComment() == "" || in.GetNickName() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
// 参数转换
|
||||
data, err := itemToCommentModel(in)
|
||||
if err != nil {
|
||||
return nil, errcode.ErrInternal
|
||||
}
|
||||
err = impl.DBService.Select("score", "reply", "product_identity", "store_identity", "spec_identity").Where("identity = ?", in.Identity).Updates(data).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
49
apps/ec/mall/internal/logic/product/comment_re.go
Normal file
49
apps/ec/mall/internal/logic/product/comment_re.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package product
|
||||
|
||||
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/service"
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
"git.apinb.com/bsm-sdk/core/utils"
|
||||
)
|
||||
|
||||
// ReComment 回复评论
|
||||
func CommentRe(ctx context.Context, in *pb.CommentItem) (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.GetProductIdentity() == "" || in.GetStoreIdentity() == "" || in.GetSpecIdentity() == "" || in.GetComment() == "" || in.GetCommentIdentity() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
comment := models.MallProductComment{
|
||||
ProductIdentity: in.ProductIdentity,
|
||||
SpecIdentity: in.SpecIdentity,
|
||||
StoreIdentity: in.StoreIdentity,
|
||||
CommentIdentity: in.Identity,
|
||||
Nickname: in.NickName,
|
||||
Score: int8(in.Score),
|
||||
Comment: in.Comment,
|
||||
Std_Owner: types.Std_Owner{OwnerID: auth.ID, OwnerIdentity: auth.Identity},
|
||||
Std_Identity: types.Std_Identity{Identity: utils.ULID()},
|
||||
}
|
||||
if err := impl.DBService.Create(&comment).Error; err != nil {
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
Identity: comment.Identity,
|
||||
}, nil
|
||||
|
||||
}
|
||||
39
apps/ec/mall/internal/logic/product/item_batch_op.go
Normal file
39
apps/ec/mall/internal/logic/product/item_batch_op.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package product
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
// Forbidden 批量操作
|
||||
func ItemBatchOp(ctx context.Context, in *pb.OpRequest) (reply *pb.StatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(in.GetIdentity()) == 0 {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
// TODO: add your logic code & delete this line.
|
||||
err = impl.DBService.Model(&models.MallProduct{}).Where("identity in ?", in.Identity).Update("status", in.Status).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
225
apps/ec/mall/internal/logic/product/item_create.go
Normal file
225
apps/ec/mall/internal/logic/product/item_create.go
Normal file
@@ -0,0 +1,225 @@
|
||||
package product
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-ec/mall/internal/models"
|
||||
pb "git.apinb.com/bsm-ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/crypto/token"
|
||||
"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/types"
|
||||
"git.apinb.com/bsm-sdk/core/utils"
|
||||
)
|
||||
|
||||
// ItemCreate 创建或更新产品
|
||||
func ItemCreate(ctx context.Context, in *pb.ProductItem) (reply *pb.StatusReply, err error) {
|
||||
// 解析授权信息
|
||||
auth, err := service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 参数校验
|
||||
err = checkParam(in)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 数据转换和组装
|
||||
data, specId, photo, categoryId, err := transitionData(in, auth)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 根据是否有Identity判断是创建还是更新
|
||||
if in.Identity == "" {
|
||||
// 新建产品 - 创建产品及其关联数据
|
||||
err = models.CreateProduct(data, specId, photo, categoryId)
|
||||
} else {
|
||||
// 更新产品 - 修改现有产品信息
|
||||
err = models.ModifyProduct(data, specId, photo, categoryId)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Identity: data.Identity,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
||||
// checkParam 参数校验
|
||||
func checkParam(in *pb.ProductItem) error {
|
||||
// 保存为草稿状态时,可以跳过部分参数验证
|
||||
if in.GetStatus() == 4 {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 必填字段校验
|
||||
if len(in.GetCategoryId()) == 0 {
|
||||
return errcode.ErrInvalidArgument
|
||||
}
|
||||
if in.GetTitle() == "" {
|
||||
return errcode.ErrInvalidArgument
|
||||
}
|
||||
if in.GetCoverImage() == "" {
|
||||
return errcode.ErrInvalidArgument
|
||||
}
|
||||
if in.GetMeasuringName() == "" {
|
||||
return errcode.ErrInvalidArgument
|
||||
}
|
||||
if in.GetContent() == "" {
|
||||
return errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
// 数值范围校验
|
||||
if in.GetSellMin() < 0 || in.GetSellMax() < 0 {
|
||||
return errcode.ErrInvalidArgument
|
||||
}
|
||||
if in.GetSellMin() > in.GetSellMax() {
|
||||
return errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// transitionData 数据转换和组装
|
||||
func transitionData(in *pb.ProductItem, auth *token.Claims) (*models.MallProduct, []*models.ProductSpec, []*models.MallProductPhotos, []*models.ProductCategory, error) {
|
||||
// 转换产品基本信息
|
||||
data, err := itemToModel(in)
|
||||
if err != nil {
|
||||
return nil, nil, nil, nil, errcode.ErrInternal
|
||||
}
|
||||
|
||||
// 新建产品时设置默认值
|
||||
if data.Identity == "" {
|
||||
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)
|
||||
}
|
||||
|
||||
// 组装分类关联数据
|
||||
categoryId := make([]*models.ProductCategory, 0, len(in.CategoryId))
|
||||
for _, v := range in.CategoryId {
|
||||
|
||||
categoryId = append(categoryId, &models.ProductCategory{
|
||||
Std_IICUDS: types.Std_IICUDS{Identity: utils.UUID()},
|
||||
CategoryId: v,
|
||||
})
|
||||
}
|
||||
|
||||
// 组装规格关联数据
|
||||
specId := make([]*models.ProductSpec, 0, len(in.SpecId))
|
||||
for _, v := range in.SpecId {
|
||||
specId = append(specId, &models.ProductSpec{
|
||||
Std_IICUDS: types.Std_IICUDS{Identity: utils.UUID()},
|
||||
SpecId: v,
|
||||
})
|
||||
}
|
||||
|
||||
// 转换产品图片数据
|
||||
photo := itemToModelPhoto(data.Identity, in.Images)
|
||||
return data, specId, photo, categoryId, nil
|
||||
}
|
||||
|
||||
// itemToModel 将请求数据转换为模型数据
|
||||
func itemToModel(in *pb.ProductItem) (*models.MallProduct, error) {
|
||||
mallProduct := models.MallProduct{
|
||||
SerialId: in.SerialId,
|
||||
SupplyId: in.SupplyId,
|
||||
Title: in.Title,
|
||||
MeasuringName: in.MeasuringName,
|
||||
SellMax: int32(in.SellMax),
|
||||
SellMin: int32(in.SellMin),
|
||||
Wastage: int32(in.Wastage),
|
||||
StandardNumber: in.StandardNumber,
|
||||
Brand: in.Brand,
|
||||
StockType: int32(in.StockType),
|
||||
Status: in.Status,
|
||||
PutawayTime: in.PutawayTime,
|
||||
CoverImage: in.CoverImage,
|
||||
TemplateID: int64(in.TemplateId),
|
||||
RecentNumber: in.RecentNumber,
|
||||
Limitation: in.Limitation,
|
||||
LiTemplateID: in.LiTemplateId,
|
||||
Content: in.Content,
|
||||
Notes: in.Note,
|
||||
SaleTotal: int32(in.SaleTotal),
|
||||
GasType: int32(in.GasTypes),
|
||||
Recommend: 1, // 默认推荐状态
|
||||
}
|
||||
|
||||
// 更新操作时设置Identity
|
||||
if in.Identity != "" {
|
||||
mallProduct.Identity = in.Identity
|
||||
}
|
||||
|
||||
// 根据序列号设置气体类型
|
||||
if in.SerialId == "gas_by_kg" {
|
||||
mallProduct.GasType = 2
|
||||
} else if in.SerialId == "gas_by_bottle" {
|
||||
mallProduct.GasType = 1
|
||||
}
|
||||
|
||||
return &mallProduct, nil
|
||||
}
|
||||
func itemToModelSpec(identity string) ([]*models.MallProductSpec, error) {
|
||||
var specification = make([]*models.MallProductSpec, 0)
|
||||
|
||||
// for _, v := range in {
|
||||
|
||||
// data := models.MallProductSpec{
|
||||
// Title: v.Title,
|
||||
// StockType: v.StockType,
|
||||
// Stock: v.Stock,
|
||||
// Price: v.Price,
|
||||
// DirectSales: v.DirectSales,
|
||||
// DsTpType: v.DsTpType,
|
||||
// TpType: v.TpType,
|
||||
// Img: v.Img,
|
||||
// ProductIdentity: identity,
|
||||
// }
|
||||
// if v.Identity == "" {
|
||||
// data.Identity = utils.UUID()
|
||||
// } else {
|
||||
// data.ID = uint(v.Id)
|
||||
// data.Identity = v.Identity
|
||||
// }
|
||||
|
||||
// specification = append(specification, &data)
|
||||
// }
|
||||
return specification, nil
|
||||
}
|
||||
|
||||
// itemToModelPhoto 转换产品图片数据
|
||||
func itemToModelPhoto(identity string, in []*pb.PhotoItem) []*models.MallProductPhotos {
|
||||
photo := make([]*models.MallProductPhotos, 0, len(in))
|
||||
for _, v := range in {
|
||||
img := &models.MallProductPhotos{
|
||||
Url: v.Url,
|
||||
ProductIdentity: identity,
|
||||
Name: v.Name,
|
||||
}
|
||||
|
||||
// 更新操作时设置ID和Identity
|
||||
if v.Identity != "" {
|
||||
img.ID = uint(v.Id)
|
||||
img.Identity = v.Identity
|
||||
} else {
|
||||
// 新建时生成新的Identity
|
||||
img.Identity = utils.ULID()
|
||||
}
|
||||
photo = append(photo, img)
|
||||
}
|
||||
return photo
|
||||
}
|
||||
40
apps/ec/mall/internal/logic/product/item_delete.go
Normal file
40
apps/ec/mall/internal/logic/product/item_delete.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package product
|
||||
|
||||
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 ItemDelete(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.MallProduct{}).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().UnixNano(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
46
apps/ec/mall/internal/logic/product/item_detail.go
Normal file
46
apps/ec/mall/internal/logic/product/item_detail.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package product
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
// Detail 获取产品详情
|
||||
func ItemDetail(ctx context.Context, in *pb.IdentRequest) (reply *pb.ProductItem, err error) {
|
||||
if in.Identity == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
var data = &models.MallProduct{}
|
||||
err = impl.DBService.Preload("Specs.Spec").Preload("Images").Preload("Categories.Category").Where("identity = ?", in.Identity).First(data).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
reply, err = ModelToProductItem(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if reply.SupplyId != 0 {
|
||||
supply := map[string]any{}
|
||||
if err := impl.DBService.Table("market_supply").Take(&supply, "id = ?", reply.SupplyId).Error; err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
reply.SupplyName = supply["name"].(string)
|
||||
}
|
||||
|
||||
for _, v := range data.Categories {
|
||||
reply.CategoryId = append(reply.CategoryId, int64(v.CategoryId))
|
||||
|
||||
}
|
||||
for _, v := range data.Specs {
|
||||
reply.SpecId = append(reply.SpecId, int64(v.SpecId))
|
||||
}
|
||||
return reply, nil
|
||||
}
|
||||
37
apps/ec/mall/internal/logic/product/item_detail_by_serial.go
Normal file
37
apps/ec/mall/internal/logic/product/item_detail_by_serial.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package product
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"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"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// Detail 通过产品序列获取产品详情
|
||||
func ItemDetailBySerial(ctx context.Context, in *pb.StoreSerialRequest) (reply *pb.ListReply, err error) {
|
||||
if len(in.SerialId) == 0 || in.StoreIdentity == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
data := make([]*models.MallProduct, 0)
|
||||
err = impl.DBService.Preload("Spec").Preload("Images").Preload("Category").Where("store_identity=? and serial_id in ?", in.StoreIdentity, in.SerialId).Find(&data).Error
|
||||
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, errcode.ErrNotFound(404, "Product")
|
||||
}
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
resp := ModelsToProductItems(data)
|
||||
|
||||
return &pb.ListReply{
|
||||
Count: int64(len(resp)),
|
||||
Data: resp,
|
||||
}, nil
|
||||
}
|
||||
21
apps/ec/mall/internal/logic/product/item_detail_by_spec.go
Normal file
21
apps/ec/mall/internal/logic/product/item_detail_by_spec.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package product
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
pb "git.apinb.com/bsm-ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
)
|
||||
|
||||
// DetailBySpec 通过规格编号获取产品详情
|
||||
func ItemDetailBySpec(ctx context.Context, in *pb.DetailBySpecRequest) (reply *pb.ListItem, err error) {
|
||||
if in.GetSpecNo() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
// TODO: valid code
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return
|
||||
}
|
||||
100
apps/ec/mall/internal/logic/product/item_fetch.go
Normal file
100
apps/ec/mall/internal/logic/product/item_fetch.go
Normal file
@@ -0,0 +1,100 @@
|
||||
package product
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"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"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// 获取产品列表
|
||||
func ItemFetch(ctx context.Context, in *pb.FetchRequest) (reply *pb.ListReply, err error) {
|
||||
if in.GetStoreIdentity() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
var (
|
||||
cnt int64 = 0
|
||||
pageNo int64 = in.GetPageNo()
|
||||
pageSize int64 = in.GetPageSize()
|
||||
offset int64 = (pageNo - 1) * pageSize
|
||||
params = map[string]string{
|
||||
"mall_product.store_identity": in.GetStoreIdentity(),
|
||||
}
|
||||
idList = make([]uint, 0)
|
||||
product []*models.MallProduct
|
||||
)
|
||||
|
||||
// vlidate request page_no,page_size.
|
||||
if pageNo < 1 {
|
||||
pageNo = 1
|
||||
offset = 0
|
||||
}
|
||||
if pageSize <= 0 {
|
||||
pageSize = 10
|
||||
offset = (pageNo - 1) * pageSize
|
||||
}
|
||||
|
||||
if err := impl.DBService.Model(&models.MallProduct{}).Where(params).Preload("Images").Preload("Specs.Spec").Preload("Categories.Category").
|
||||
Order("created_at desc").Count(&cnt).Offset(int(offset)).Limit(int(pageSize)).Find(&product).Error; err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
tx := impl.DBService.Model(&models.MallProduct{})
|
||||
// 根据传入的分类id进行过滤
|
||||
if len(in.GetCategoryId()) != 0 {
|
||||
tx = tx.Where("product_category.category_id in ?", idList).
|
||||
Joins("left join product_category on mall_product.id = product_category.product_id").
|
||||
Joins("left join mall_category on mall_category.id = product_category.category_id")
|
||||
}
|
||||
// 根据传入的关键字进行模糊搜索
|
||||
if in.GetKeyword() != "" {
|
||||
tx = tx.Where("mall_product.title like ?", "%"+in.GetKeyword()+"%")
|
||||
}
|
||||
// 根据传入的价格区间进行价格过滤
|
||||
if in.GetMinPrice() != 0 || in.GetMaxPrice() != 0 {
|
||||
tx = tx.Joins("left join product_spec on product_spec.product_id = mall_product.id").
|
||||
Joins("left join mall_product_spec on mall_product_spec.id = product_spec.spec_id").
|
||||
Where("mall_product_spec.price between ? and ?", in.GetMinPrice(), in.GetMaxPrice())
|
||||
}
|
||||
|
||||
// 根据传入sort排序
|
||||
switch in.GetSort() {
|
||||
case "1":
|
||||
tx = tx.Order("mall_product.title asc")
|
||||
case "2":
|
||||
tx = tx.Order("mall_product.title desc")
|
||||
case "3":
|
||||
tx = tx.Order("mall_product.sales_price asc")
|
||||
default:
|
||||
tx = tx.Order("mall_product.created_at desc")
|
||||
}
|
||||
if err := tx.Where(params).Preload("Images").
|
||||
Preload("Specs.Spec", func(db *gorm.DB) *gorm.DB { return db.Order("mall_product_spec.price") }).
|
||||
Preload("Categories.Category").Count(&cnt).Offset(int(offset)).Limit(int(pageSize)).
|
||||
Find(&product).Error; err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
// 将数据库中的数据转换成pb.ProductItem
|
||||
data := ModelsToProductItems(product)
|
||||
for _, val := range data {
|
||||
for _, v := range val.Categories {
|
||||
val.CategoryId = append(val.CategoryId, v.Id)
|
||||
}
|
||||
}
|
||||
for _, val := range data {
|
||||
for _, v := range val.Specification {
|
||||
val.SpecId = append(val.SpecId, v.Id)
|
||||
}
|
||||
}
|
||||
return &pb.ListReply{
|
||||
Count: cnt,
|
||||
Data: data,
|
||||
}, nil
|
||||
}
|
||||
39
apps/ec/mall/internal/logic/product/item_modify.go
Normal file
39
apps/ec/mall/internal/logic/product/item_modify.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package product
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
// Modify 发布/取消发布 产品
|
||||
func ItemModify(ctx context.Context, in *pb.ModifyRequest) (reply *pb.StatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 检测参数
|
||||
if in.GetIdentity() == "" || in.GetStatus() == 0 {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
if err := impl.DBService.Model(&models.MallProduct{}).Where("identity = ?", in.Identity).Update("status", in.Status).Error; err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
48
apps/ec/mall/internal/logic/product/photo_create.go
Normal file
48
apps/ec/mall/internal/logic/product/photo_create.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package product
|
||||
|
||||
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"
|
||||
"git.apinb.com/bsm-sdk/core/utils"
|
||||
)
|
||||
|
||||
// 添加产品图片
|
||||
func PhotoCreate(ctx context.Context, in *pb.PhotoItem) (reply *pb.StatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 参数检测
|
||||
if in.GetUrl() == "" || in.GetProductIdentity() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
// 数据组装
|
||||
var photo = models.MallProductPhotos{
|
||||
Name: in.Name,
|
||||
ProductIdentity: in.ProductIdentity,
|
||||
Url: in.Url,
|
||||
}
|
||||
photo.Identity = utils.UUID()
|
||||
tx := impl.DBService.Create(&photo)
|
||||
cnt, err := tx.RowsAffected, tx.Error
|
||||
if cnt == 0 || err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().UnixNano(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
42
apps/ec/mall/internal/logic/product/photo_delete.go
Normal file
42
apps/ec/mall/internal/logic/product/photo_delete.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package product
|
||||
|
||||
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 PhotoDelete(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.MallProductPhotos{}).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().UnixNano(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
43
apps/ec/mall/internal/logic/product/photo_list.go
Normal file
43
apps/ec/mall/internal/logic/product/photo_list.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package product
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
// 图片列表
|
||||
func PhotoList(ctx context.Context, in *pb.PhotoItem) (reply *pb.PhotoReply, err error) {
|
||||
if in.GetProductIdentity() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
var cnt int64 = 0
|
||||
data := make([]*models.MallProductPhotos, 0)
|
||||
|
||||
err = impl.DBService.Where("product_identity = ?", in.ProductIdentity).Order("created_at desc").Find(&data).Count(&cnt).Error
|
||||
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
return &pb.PhotoReply{Count: cnt, Data: ModelToReplyPhotoList(data)}, nil
|
||||
}
|
||||
|
||||
func ModelToReplyPhotoList(data []*models.MallProductPhotos) []*pb.PhotoItem {
|
||||
var list = make([]*pb.PhotoItem, 0)
|
||||
for _, v := range data {
|
||||
low := &pb.PhotoItem{
|
||||
Name: v.Name,
|
||||
Identity: v.Identity,
|
||||
ProductIdentity: v.ProductIdentity,
|
||||
Url: v.Url,
|
||||
}
|
||||
list = append(list, low)
|
||||
}
|
||||
return list
|
||||
}
|
||||
189
apps/ec/mall/internal/logic/product/ref.go
Normal file
189
apps/ec/mall/internal/logic/product/ref.go
Normal file
@@ -0,0 +1,189 @@
|
||||
package product
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-ec/mall/internal/models"
|
||||
pb "git.apinb.com/bsm-ec/mall/pb"
|
||||
)
|
||||
|
||||
func ModelsToProductItems(data []*models.MallProduct) (list []*pb.ProductItem) {
|
||||
if len(data) == 0 {
|
||||
return
|
||||
}
|
||||
for _, v := range data {
|
||||
line := pb.ProductItem{
|
||||
Id: int64(v.ID),
|
||||
Identity: v.Identity,
|
||||
SupplyId: v.SupplyId,
|
||||
Title: v.Title,
|
||||
MeasuringName: v.MeasuringName,
|
||||
SellMax: int64(v.SellMax),
|
||||
SellMin: int64(v.SellMin),
|
||||
Wastage: int64(v.Wastage),
|
||||
StandardNumber: v.StandardNumber,
|
||||
Brand: v.Brand,
|
||||
StockType: int64(v.StockType),
|
||||
Status: v.Status,
|
||||
PutawayTime: v.PutawayTime,
|
||||
CoverImage: v.CoverImage,
|
||||
Content: v.Content,
|
||||
SerialId: v.SerialId,
|
||||
CreatedAt: v.CreatedAt.Format("2006-01-02 15:04:05"),
|
||||
SaleTotal: int64(v.SaleTotal),
|
||||
RecentNumber: v.RecentNumber,
|
||||
GasTypes: int64(v.GasType),
|
||||
}
|
||||
|
||||
for _, image := range v.Images {
|
||||
line.Images = append(line.Images, &pb.PhotoItem{
|
||||
Id: int64(image.ID),
|
||||
Identity: image.Identity,
|
||||
Name: image.Name,
|
||||
ProductIdentity: image.ProductIdentity,
|
||||
Sort: image.Sort,
|
||||
Url: image.Url,
|
||||
})
|
||||
}
|
||||
for _, specs := range v.Specs {
|
||||
line.Specification = append(line.Specification, &pb.SpecItem{
|
||||
Id: int64(specs.Spec.ID),
|
||||
Identity: specs.Identity,
|
||||
ProductIdentity: v.Identity,
|
||||
Title: specs.Spec.Title,
|
||||
StockType: specs.Spec.StockType,
|
||||
Stock: specs.Spec.Stock,
|
||||
Price: specs.Spec.Price,
|
||||
DirectSales: specs.Spec.DirectSales,
|
||||
TpType: specs.Spec.TpType,
|
||||
DsTpType: specs.Spec.DsTpType,
|
||||
Img: specs.Spec.Img,
|
||||
})
|
||||
}
|
||||
for _, categories := range v.Categories {
|
||||
line.Categories = append(line.Categories, &pb.CategoriesItem{
|
||||
Id: int64(categories.Category.ID),
|
||||
Identity: categories.Identity,
|
||||
Title: categories.Category.Title,
|
||||
EnTitle: categories.Category.EnTitle,
|
||||
ParentId: int64(categories.Category.ParentID),
|
||||
Paths: categories.Category.Paths,
|
||||
Intro: categories.Category.Intro,
|
||||
Icon: categories.Category.Icon,
|
||||
Sort: int32(categories.Category.Sort),
|
||||
Status: int32(categories.Status),
|
||||
Keys: categories.Category.Keys,
|
||||
})
|
||||
}
|
||||
if len(line.Images) == 0 {
|
||||
line.Images = make([]*pb.PhotoItem, 0)
|
||||
}
|
||||
if len(v.Specs) > 0 {
|
||||
line.Price = v.Specs[0].Spec.Price
|
||||
line.Stock = v.Specs[0].Spec.Stock
|
||||
}
|
||||
list = append(list, &line)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func ModelToProductItem(data *models.MallProduct) (*pb.ProductItem, error) {
|
||||
var item = &pb.ProductItem{
|
||||
Id: int64(data.ID),
|
||||
Identity: data.Identity,
|
||||
SupplyId: data.SupplyId,
|
||||
SerialId: data.SerialId,
|
||||
Title: data.Title,
|
||||
MeasuringName: data.MeasuringName,
|
||||
SellMax: int64(data.SellMax),
|
||||
SellMin: int64(data.SellMin),
|
||||
Wastage: int64(data.Wastage),
|
||||
StandardNumber: data.StandardNumber,
|
||||
Brand: data.Brand,
|
||||
StockType: int64(data.StockType),
|
||||
Status: data.Status,
|
||||
PutawayTime: data.PutawayTime,
|
||||
CoverImage: data.CoverImage,
|
||||
Content: data.Content,
|
||||
TemplateId: int32(data.TemplateID),
|
||||
Note: data.Notes,
|
||||
Images: []*pb.PhotoItem{},
|
||||
Specification: []*pb.SpecItem{},
|
||||
Categories: []*pb.CategoriesItem{},
|
||||
RecentNumber: data.RecentNumber,
|
||||
Limitation: data.Limitation,
|
||||
LiTemplateId: data.LiTemplateID,
|
||||
SaleTotal: int64(data.SaleTotal),
|
||||
CreatedAt: data.CreatedAt.Format("2006-01-02 15:04:05"),
|
||||
GasTypes: int64(data.GasType),
|
||||
}
|
||||
|
||||
if len(data.Images) != 0 {
|
||||
item.Images = make([]*pb.PhotoItem, 0)
|
||||
for _, v := range data.Images {
|
||||
item.Images = append(item.Images, &pb.PhotoItem{
|
||||
Identity: v.Identity,
|
||||
Url: v.Url,
|
||||
Name: v.Name,
|
||||
Id: int64(v.ID),
|
||||
})
|
||||
}
|
||||
}
|
||||
if len(data.Specs) != 0 {
|
||||
item.Specification = make([]*pb.SpecItem, 0)
|
||||
for _, specs := range data.Specs {
|
||||
item.Specification = append(item.Specification, &pb.SpecItem{
|
||||
Id: int64(specs.Spec.ID),
|
||||
Identity: specs.Identity,
|
||||
Title: specs.Spec.Title,
|
||||
StockType: specs.Spec.StockType,
|
||||
Stock: specs.Spec.Stock,
|
||||
Img: specs.Spec.Img,
|
||||
Price: specs.Spec.Price,
|
||||
SpecNo: specs.Spec.SerialNumber,
|
||||
Keyword: specs.Spec.Keyword,
|
||||
PurchasingPrice: specs.Spec.PurchasingPrice,
|
||||
Wholesale: specs.Spec.Wholesale,
|
||||
})
|
||||
}
|
||||
}
|
||||
if len(data.Categories) != 0 {
|
||||
item.Categories = make([]*pb.CategoriesItem, 0)
|
||||
for _, categories := range data.Categories {
|
||||
item.Categories = append(item.Categories, &pb.CategoriesItem{
|
||||
Id: int64(categories.Category.ID),
|
||||
Identity: categories.Identity,
|
||||
Title: categories.Category.Title,
|
||||
EnTitle: categories.Category.EnTitle,
|
||||
ParentId: int64(categories.Category.ParentID),
|
||||
Paths: categories.Category.Paths,
|
||||
Intro: categories.Category.Intro,
|
||||
Icon: categories.Category.Icon,
|
||||
Sort: int32(categories.Category.Sort),
|
||||
Keys: categories.Category.Keys,
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
return item, nil
|
||||
}
|
||||
|
||||
func ModelToReplySpecList(data []*models.MallProductSpec) []*pb.SpecItem {
|
||||
var res []*pb.SpecItem
|
||||
for _, datum := range data {
|
||||
res = append(res, &pb.SpecItem{
|
||||
Id: int64(datum.ID),
|
||||
Identity: datum.Identity,
|
||||
Title: datum.Title,
|
||||
StockType: datum.StockType,
|
||||
Stock: datum.Stock,
|
||||
Price: datum.Price,
|
||||
DirectSales: datum.DirectSales,
|
||||
TpType: datum.TpType,
|
||||
DsTpType: datum.DsTpType,
|
||||
Img: datum.Img,
|
||||
SpecNo: datum.SpecNo,
|
||||
Keyword: datum.Keyword,
|
||||
Wholesale: datum.Wholesale,
|
||||
})
|
||||
}
|
||||
return res
|
||||
}
|
||||
109
apps/ec/mall/internal/logic/product/spec_create.go
Normal file
109
apps/ec/mall/internal/logic/product/spec_create.go
Normal file
@@ -0,0 +1,109 @@
|
||||
package product
|
||||
|
||||
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"
|
||||
"git.apinb.com/bsm-sdk/core/utils"
|
||||
)
|
||||
|
||||
// CreateSpec 添加产品规格
|
||||
func SpecCreate(ctx context.Context, in *pb.SpecItem) (reply *pb.StatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 检测参数
|
||||
err = checkParamSpecCreate(in)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 数据组装
|
||||
data, err := requestToModelSpec(in)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
data.Identity = utils.UUID()
|
||||
tx := impl.DBService.Create(data)
|
||||
cnt, err := tx.RowsAffected, tx.Error
|
||||
if cnt == 0 || err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Identity: data.Identity,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
||||
func checkParamSpecCreate(in *pb.SpecItem) error {
|
||||
if in.GetTitle() == "" {
|
||||
return errcode.ErrInvalidArgument
|
||||
}
|
||||
if in.GetImg() == "" {
|
||||
return errcode.ErrInvalidArgument
|
||||
}
|
||||
if in.GetStock() == 0 {
|
||||
return errcode.ErrInvalidArgument
|
||||
}
|
||||
if in.GetPrice() == 0 {
|
||||
return errcode.ErrInvalidArgument
|
||||
}
|
||||
if in.GetSpecNo() == "" {
|
||||
return errcode.ErrInvalidArgument
|
||||
}
|
||||
// if in.GetKeyword() == "" {
|
||||
// return errcode.ErrInvalidArgument
|
||||
// }
|
||||
if in.GetPurchasingPrice() == 0 {
|
||||
return errcode.ErrInvalidArgument
|
||||
}
|
||||
// if in.GetSupplyId() == 0 {
|
||||
// return errcode.ErrInvalidArgument
|
||||
// }
|
||||
return nil
|
||||
}
|
||||
func requestToModelSpec(in *pb.SpecItem) (*models.MallProductSpec, error) {
|
||||
var specification = &models.MallProductSpec{
|
||||
SupplyId: in.SupplyId,
|
||||
StoreIdentity: in.StoreIdentity,
|
||||
Title: in.Title,
|
||||
StockType: 2,
|
||||
Stock: in.Stock,
|
||||
Price: in.Price,
|
||||
DirectSales: in.DirectSales,
|
||||
TpType: 2,
|
||||
DsTpType: 2,
|
||||
Img: in.Img,
|
||||
SpecNo: in.SpecNo,
|
||||
Keyword: in.Keyword,
|
||||
PurchasingPrice: in.PurchasingPrice,
|
||||
Wholesale: in.Wholesale,
|
||||
}
|
||||
if in.StockType != 2 {
|
||||
specification.Stock = int64(in.StockType)
|
||||
}
|
||||
if in.TpType != 2 {
|
||||
specification.TpType = in.TpType
|
||||
}
|
||||
if in.DsTpType != 2 {
|
||||
specification.DsTpType = in.DsTpType
|
||||
}
|
||||
if in.Identity != "" {
|
||||
specification.Identity = in.Identity
|
||||
}
|
||||
return specification, nil
|
||||
}
|
||||
41
apps/ec/mall/internal/logic/product/spec_delete.go
Normal file
41
apps/ec/mall/internal/logic/product/spec_delete.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package product
|
||||
|
||||
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 SpecDelete(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.MallProductSpec{}).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().UnixNano(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
41
apps/ec/mall/internal/logic/product/spec_detail.go
Normal file
41
apps/ec/mall/internal/logic/product/spec_detail.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package product
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
// DetailSpec 产品详情
|
||||
func SpecDetail(ctx context.Context, in *pb.IdentRequest) (reply *pb.SpecItem, err error) {
|
||||
if in.GetIdentity() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
var data models.MallProductSpec
|
||||
err = impl.DBService.Model(&models.MallProductSpec{}).Where("identity = ?", in.Identity).First(&data).Error
|
||||
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
return &pb.SpecItem{
|
||||
Id: int64(data.ID),
|
||||
Identity: data.Identity,
|
||||
SupplyId: data.SupplyId,
|
||||
Title: data.Title,
|
||||
StockType: data.StockType,
|
||||
Stock: data.Stock,
|
||||
Price: data.Price,
|
||||
DirectSales: data.DirectSales,
|
||||
TpType: data.TpType,
|
||||
DsTpType: data.DsTpType,
|
||||
Img: data.Img,
|
||||
PurchasingPrice: data.PurchasingPrice,
|
||||
Wholesale: data.Wholesale,
|
||||
}, nil
|
||||
}
|
||||
41
apps/ec/mall/internal/logic/product/spec_fetch.go
Normal file
41
apps/ec/mall/internal/logic/product/spec_fetch.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package product
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"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 SpecFetch(ctx context.Context, in *pb.FetchRequest) (reply *pb.SpecReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if in.StoreIdentity == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
spec := make([]*models.MallProductSpec, 0)
|
||||
tx := impl.DBService.Model(&models.MallProductSpec{}).Where("store_identity = ?", in.StoreIdentity)
|
||||
if in.Keyword != "" {
|
||||
tx = tx.Where("keyword like ?", "%"+in.Keyword+"%")
|
||||
}
|
||||
err = tx.Order("created_at desc").Find(&spec).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.SpecReply{
|
||||
Count: int64(len(spec)),
|
||||
Data: ModelToReplySpecList(spec),
|
||||
}, nil
|
||||
}
|
||||
73
apps/ec/mall/internal/logic/product/spec_modify.go
Normal file
73
apps/ec/mall/internal/logic/product/spec_modify.go
Normal file
@@ -0,0 +1,73 @@
|
||||
package product
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
// ModifySpec 修改产品规格
|
||||
func SpecModify(ctx context.Context, in *pb.SpecItem) (reply *pb.StatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 检测参数
|
||||
err = checkParamSpecModify(in)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
}
|
||||
|
||||
// 数据组装
|
||||
data, err := requestToModelSpec(in)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = impl.DBService.Where("identity=?", data.Identity).Updates(data).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Identity: data.Identity,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
||||
func checkParamSpecModify(in *pb.SpecItem) error {
|
||||
if in.GetIdentity() == "" {
|
||||
return errcode.ErrInvalidArgument
|
||||
}
|
||||
// if in.GetProductIdentity() == "" {
|
||||
// return errcode.ErrInvalidArgument
|
||||
// }
|
||||
if in.GetTitle() == "" {
|
||||
return errcode.ErrInvalidArgument
|
||||
}
|
||||
if in.GetImg() == "" {
|
||||
return errcode.ErrInvalidArgument
|
||||
}
|
||||
if in.GetStock() == 0 {
|
||||
return errcode.ErrInvalidArgument
|
||||
}
|
||||
if in.GetPrice() == 0 {
|
||||
return errcode.ErrInvalidArgument
|
||||
}
|
||||
if in.GetPurchasingPrice() == 0 {
|
||||
return errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
76
apps/ec/mall/internal/logic/staff/create.go
Normal file
76
apps/ec/mall/internal/logic/staff/create.go
Normal file
@@ -0,0 +1,76 @@
|
||||
package staff
|
||||
|
||||
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"
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
"git.apinb.com/bsm-sdk/core/utils"
|
||||
)
|
||||
|
||||
// 创建工作人员
|
||||
func Create(ctx context.Context, in *pb.StaffItem) (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.GetAccount() == "" || in.GetPassword() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
salt := utils.RandomString(8)
|
||||
data := models.MallStaff{
|
||||
Name: in.Name,
|
||||
Account: in.Account,
|
||||
Password: utils.Md5(in.Password + salt),
|
||||
Profile: in.Profile,
|
||||
Phone: in.Phone,
|
||||
Email: in.Email,
|
||||
Avatar: in.Avatar,
|
||||
Salt: salt,
|
||||
Role: "staff",
|
||||
Std_IICUDS: types.Std_IICUDS{Status: 1},
|
||||
}
|
||||
|
||||
ownerStore := auth.Owner.(map[string]any)
|
||||
storeId := uint(ownerStore["store_id"].(float64))
|
||||
storeIdentity := ownerStore["store_identity"].(string)
|
||||
|
||||
data.Identity = utils.UUID()
|
||||
data.Store_ID = storeId
|
||||
data.Store_Identity = storeIdentity
|
||||
|
||||
var cnt int64
|
||||
err = impl.DBService.Model(&models.MallStaff{}).Where("store_identity = ?", storeIdentity).Where("account = ?", in.Account).Count(&cnt).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
// 账号已存在
|
||||
if cnt > 0 {
|
||||
return nil, errcode.ErrAlreadyExists
|
||||
}
|
||||
|
||||
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/staff/delete.go
Normal file
40
apps/ec/mall/internal/logic/staff/delete.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package staff
|
||||
|
||||
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.MallStaff{}).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
79
apps/ec/mall/internal/logic/staff/fetch.go
Normal file
79
apps/ec/mall/internal/logic/staff/fetch.go
Normal file
@@ -0,0 +1,79 @@
|
||||
package staff
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
// 获取工作人员列表
|
||||
func Fetch(ctx context.Context, in *pb.FetchRequest) (reply *pb.StaffListReply, err error) {
|
||||
// parse authorization meta.
|
||||
// _, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
|
||||
var (
|
||||
cnt int64 = 0
|
||||
pageNo int64 = in.GetPageNo()
|
||||
pageSize int64 = in.GetPageSize()
|
||||
offset int64 = (pageNo - 1) * pageSize
|
||||
params = map[string]string{
|
||||
"store_identity": in.GetStoreIdentity(),
|
||||
}
|
||||
)
|
||||
|
||||
// vlidate request page_no,page_size.
|
||||
if pageNo < 1 {
|
||||
pageNo = 1
|
||||
offset = 0
|
||||
}
|
||||
if pageSize < 50 {
|
||||
pageSize = 50
|
||||
offset = (pageNo - 1) * pageSize
|
||||
}
|
||||
|
||||
var data []*models.MallStaff
|
||||
if err := impl.DBService.Model(&models.MallStaff{}).Where(params).Order("created_at desc").Count(&cnt).
|
||||
Offset(int(offset)).Limit(int(pageSize)).Find(&data).Error; err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return &pb.StaffListReply{
|
||||
Count: cnt,
|
||||
Data: ModelToReply(data),
|
||||
}, nil
|
||||
}
|
||||
func ModelToReply(data []*models.MallStaff) (list []*pb.StaffItem) {
|
||||
if len(data) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
for _, in := range data {
|
||||
row := pb.StaffItem{
|
||||
Id: int64(in.ID),
|
||||
Identity: in.Identity,
|
||||
Name: in.Name,
|
||||
Account: in.Account,
|
||||
Profile: in.Profile,
|
||||
Role: in.Role,
|
||||
Phone: in.Phone,
|
||||
Email: in.Email,
|
||||
Status: int32(in.Status),
|
||||
Avatar: in.Avatar,
|
||||
CreatedAt: in.CreatedAt.Format(time.DateTime),
|
||||
}
|
||||
|
||||
list = append(list, &row)
|
||||
}
|
||||
return
|
||||
}
|
||||
48
apps/ec/mall/internal/logic/staff/get_profile.go
Normal file
48
apps/ec/mall/internal/logic/staff/get_profile.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package staff
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
// GetProfile 获取个人信息
|
||||
func GetProfile(ctx context.Context, in *pb.IdentRequest) (reply *pb.StaffItem, 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
|
||||
}
|
||||
|
||||
var data models.MallStaff
|
||||
err = impl.DBService.Where("id=? or identity=?", in.GetId(), in.GetIdentity()).First(&data).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.StaffItem{
|
||||
Id: int64(data.ID),
|
||||
Identity: data.Identity,
|
||||
Name: data.Name,
|
||||
Account: data.Account,
|
||||
Profile: data.Profile,
|
||||
Phone: data.Phone,
|
||||
Email: data.Email,
|
||||
Avatar: data.Avatar,
|
||||
Role: data.Role,
|
||||
Status: int32(data.Status),
|
||||
CreatedAt: data.CreatedAt.Format(time.DateTime),
|
||||
}, nil
|
||||
}
|
||||
122
apps/ec/mall/internal/logic/staff/login.go
Normal file
122
apps/ec/mall/internal/logic/staff/login.go
Normal file
@@ -0,0 +1,122 @@
|
||||
package staff
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"regexp"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-ec/mall/internal/excode"
|
||||
"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/crypto/encipher"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/utils"
|
||||
"git.apinb.com/bsm-sdk/core/vars"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// Login 员工登录验证
|
||||
func Login(ctx context.Context, in *pb.LoginRequest) (reply *pb.LoginReply, err error) {
|
||||
var record models.MallStaff
|
||||
|
||||
// 根据登录类型进行不同的验证
|
||||
switch in.LoginGenre {
|
||||
case 1: // 账号密码登录
|
||||
if in.Account == "" || in.Password == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
err := impl.DBService.Where("account = ?", in.Account).First(&record).Error
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, errcode.ErrAccountNotFound
|
||||
}
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
// 密码校验 - 使用MD5加盐验证
|
||||
if record.Password != utils.Md5(in.Password+record.Salt) {
|
||||
return nil, errcode.ErrPassword
|
||||
}
|
||||
|
||||
case 2: // 手机验证码登录
|
||||
if in.Phone == "" || in.VerifyCode == "" || ValidatePhone(in.Phone) != nil {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
err := impl.DBService.Where("phone = ?", in.Phone).First(&record).Error
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, errcode.ErrAccountNotFound
|
||||
}
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
// TODO: 添加验证码校验逻辑
|
||||
|
||||
default:
|
||||
return nil, errcode.ErrUnimplemented
|
||||
}
|
||||
|
||||
// 账号状态校验
|
||||
if record.Status == models.DisabledStatus {
|
||||
return nil, errcode.ErrAccountDisabled
|
||||
}
|
||||
|
||||
// 检查店铺是否正常运营
|
||||
var storeData = models.MallStore{}
|
||||
err = impl.DBService.Model(&models.MallStore{}).Where("id = ? AND status = 1", record.Store_ID).First(&storeData).Error
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, excode.ErrStoreNotFound
|
||||
}
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
if storeData.Status == 0 {
|
||||
return nil, excode.ErrStoreDisabled
|
||||
}
|
||||
|
||||
store := models.Std_Store{
|
||||
Store_ID: record.Store_ID,
|
||||
Store_Identity: record.Store_Identity,
|
||||
}
|
||||
|
||||
token, err := encipher.GenerateTokenAes(record.ID, record.Identity, "", record.Role, store, map[string]string{"role": record.Role})
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 更新登录时间
|
||||
record.LastLoginAt = time.Now()
|
||||
err = impl.DBService.Where("id = ?", record.ID).Select("last_login_at").Updates(record).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.LoginReply{
|
||||
Token: token,
|
||||
Identity: record.Identity,
|
||||
Name: record.Name,
|
||||
Account: record.Account,
|
||||
Role: record.Role,
|
||||
StoreName: storeData.Title,
|
||||
StoreIdentity: storeData.Identity,
|
||||
Status: int32(record.Status),
|
||||
CreatedAt: record.CreatedAt.Format(vars.YYYY_MM_DD_HH_MM_SS),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ValidatePhone 验证手机号格式
|
||||
func ValidatePhone(phone string) error {
|
||||
// 中国大陆手机号验证:1开头,第二位为3-9,总共11位数字
|
||||
matched, err := regexp.MatchString("^1[3-9]\\d{9}$", phone)
|
||||
if err != nil || !matched {
|
||||
return errcode.ErrInvalidArgument
|
||||
}
|
||||
return nil
|
||||
}
|
||||
32
apps/ec/mall/internal/logic/staff/ref.go
Normal file
32
apps/ec/mall/internal/logic/staff/ref.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package staff
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-ec/mall/internal/models"
|
||||
pb "git.apinb.com/bsm-ec/mall/pb"
|
||||
)
|
||||
|
||||
func ref(data []*models.MallStaff) (list []*pb.StaffItem) {
|
||||
if len(data) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
for _, in := range data {
|
||||
row := pb.StaffItem{
|
||||
Identity: in.Identity,
|
||||
Name: in.Name,
|
||||
Account: in.Account,
|
||||
Password: "***",
|
||||
Profile: in.Profile,
|
||||
Phone: in.Phone,
|
||||
Email: in.Email,
|
||||
Avatar: in.Avatar,
|
||||
Role: "staff",
|
||||
CreatedAt: in.CreatedAt.Format(time.DateTime),
|
||||
}
|
||||
|
||||
list = append(list, &row)
|
||||
}
|
||||
return
|
||||
}
|
||||
42
apps/ec/mall/internal/logic/staff/set_password.go
Normal file
42
apps/ec/mall/internal/logic/staff/set_password.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package staff
|
||||
|
||||
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"
|
||||
"git.apinb.com/bsm-sdk/core/utils"
|
||||
)
|
||||
|
||||
// SetPassword 设置账号密码
|
||||
func SetPassword(ctx context.Context, in *pb.SetAccountRequest) (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.Password == "" || in.Password != in.PasswordConfirmed {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
salt := utils.RandomString(8)
|
||||
pwd := utils.Md5(in.Password + salt)
|
||||
err = impl.DBService.Where("id = ?", auth.ID).Updates(&models.MallStaff{Salt: salt, Password: pwd}).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
43
apps/ec/mall/internal/logic/staff/set_profile.go
Normal file
43
apps/ec/mall/internal/logic/staff/set_profile.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package staff
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
// SetProfile 设置个人信息
|
||||
func SetProfile(ctx context.Context, in *pb.StaffItem) (reply *pb.StatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
auth, err := service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
data := &models.MallStaff{
|
||||
Name: in.Name,
|
||||
Account: in.Account,
|
||||
Profile: in.Profile,
|
||||
Phone: in.Phone,
|
||||
Email: in.Email,
|
||||
Avatar: in.Avatar,
|
||||
}
|
||||
err = impl.DBService.Debug().Where("identity = ?", auth.Identity).Updates(data).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
29
apps/ec/mall/internal/logic/store/apply_join.go
Normal file
29
apps/ec/mall/internal/logic/store/apply_join.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
pb "git.apinb.com/bsm-ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// 申请加入店铺
|
||||
func ApplyJoin(ctx context.Context, in *pb.ApplyJoinRequest) (reply *pb.StatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// TODO: valid code
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
34
apps/ec/mall/internal/logic/store/get_email.go
Normal file
34
apps/ec/mall/internal/logic/store/get_email.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"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/service"
|
||||
)
|
||||
|
||||
// 获取邮件服务器配置
|
||||
func GetEmail(ctx context.Context, in *pb.IdentRequest) (reply *pb.ConfigsReply, err error) {
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if in.Id == 0 && in.Identity == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
sotre := models.MallStore{}
|
||||
if err := impl.DBService.Model(&models.MallStore{}).Select("mail_configs").Where("id=? or identity=?", in.GetId(), in.GetIdentity()).Find(&sotre).Error; err != nil {
|
||||
print(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.ConfigsReply{
|
||||
Configs: sotre.MailConfigs,
|
||||
}, nil
|
||||
|
||||
}
|
||||
33
apps/ec/mall/internal/logic/store/get_payment.go
Normal file
33
apps/ec/mall/internal/logic/store/get_payment.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"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/service"
|
||||
)
|
||||
|
||||
// 获取支付方式配置
|
||||
func GetPayment(ctx context.Context, in *pb.IdentRequest) (reply *pb.ConfigsReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if in.Id == 0 && in.Identity == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
sotre := models.MallStore{}
|
||||
if err := impl.DBService.Model(&models.MallStore{}).Select("pay_configs").Where("id=? or identity=?", in.GetId(), in.GetIdentity()).Find(&sotre).Error; err != nil {
|
||||
print(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.ConfigsReply{Configs: sotre.PayConfigs}, nil
|
||||
|
||||
}
|
||||
39
apps/ec/mall/internal/logic/store/get_setting.go
Normal file
39
apps/ec/mall/internal/logic/store/get_setting.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package store
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
// 获取店铺基础配置
|
||||
func GetSetting(ctx context.Context, in *pb.IdentRequest) (reply *pb.StoreBasic, err error) {
|
||||
// valildate request id,identity.
|
||||
if in.Id == 0 && in.Identity == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
var data models.MallStore
|
||||
if err := impl.DBService.Where("id=? or identity=?", in.GetId(), in.GetIdentity()).First(&data).Error; err != nil {
|
||||
print(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return &pb.StoreBasic{
|
||||
Id: int64(data.ID),
|
||||
Identity: data.Identity,
|
||||
Logo: data.Logo,
|
||||
Title: data.Title,
|
||||
Intro: data.Intro,
|
||||
Template: data.Template,
|
||||
Subdomain: data.Subdomain,
|
||||
Configs: data.Configs,
|
||||
CreatedAt: data.CreatedAt.Format(time.DateTime),
|
||||
Keywords: data.Keywords,
|
||||
Approve: int32(data.Approve),
|
||||
}, nil
|
||||
}
|
||||
49
apps/ec/mall/internal/logic/store/licensing.go
Normal file
49
apps/ec/mall/internal/logic/store/licensing.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"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"
|
||||
)
|
||||
|
||||
// 店铺许可授权
|
||||
func Licensing(ctx context.Context, in *pb.LicensingRequest) (reply *pb.StatusReply, err error) {
|
||||
var identity string
|
||||
licenseType := strings.ToUpper(in.GetLicenseType())
|
||||
|
||||
switch licenseType {
|
||||
case "DOMAIN":
|
||||
identity, err = LicensingDomain(in.Domain)
|
||||
default:
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
// TODO: valid code
|
||||
if identity == "" {
|
||||
return nil, errcode.ErrNotFound(404, "store not found")
|
||||
}
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Identity: identity,
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
||||
func LicensingDomain(domain string) (string, error) {
|
||||
var store models.MallStore
|
||||
err := impl.DBService.Model(&models.MallStore{}).Where("subdomain=?", domain).First(&store).Error
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return store.Identity, nil
|
||||
}
|
||||
23
apps/ec/mall/internal/logic/store/mini_code.go
Normal file
23
apps/ec/mall/internal/logic/store/mini_code.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
pb "git.apinb.com/bsm-ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// 获取小程序推荐码
|
||||
func MiniCode(ctx context.Context, in *pb.MiniCodeRequest) (reply *pb.MiniCodeReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// TODO: valid code
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return
|
||||
}
|
||||
73
apps/ec/mall/internal/logic/store/search.go
Normal file
73
apps/ec/mall/internal/logic/store/search.go
Normal file
@@ -0,0 +1,73 @@
|
||||
package store
|
||||
|
||||
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 Search(ctx context.Context, in *pb.MallSearchRequest) (reply *pb.MallSearchReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var (
|
||||
cnt int64 = 0
|
||||
pageNo int64 = in.GetPageNo()
|
||||
pageSize int64 = in.GetPageSize()
|
||||
offset int64 = (pageNo - 1) * pageSize
|
||||
)
|
||||
|
||||
if pageNo < 1 {
|
||||
pageNo = 1
|
||||
offset = 0
|
||||
}
|
||||
if pageSize < 50 {
|
||||
pageSize = 50
|
||||
offset = (pageNo - 1) * pageSize
|
||||
}
|
||||
var data []*models.MallStore
|
||||
if err := impl.DBService.Model(&models.MallStore{}).Where("keyword = ?", in.GetKeyword()).Order("created_at desc").Count(&cnt).
|
||||
Offset(int(offset)).Limit(int(pageSize)).Find(&data).Error; err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.MallSearchReply{
|
||||
Count: cnt,
|
||||
List: ModelToReply(data),
|
||||
}, nil
|
||||
}
|
||||
func ModelToReply(data []*models.MallStore) (list []*pb.StoreBasic) {
|
||||
if len(data) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
for _, in := range data {
|
||||
row := pb.StoreBasic{
|
||||
Id: int64(in.ID),
|
||||
Identity: in.Identity,
|
||||
Logo: in.Logo,
|
||||
Title: in.Title,
|
||||
Intro: in.Intro,
|
||||
Template: in.Template,
|
||||
Subdomain: in.Subdomain,
|
||||
Configs: in.Configs,
|
||||
CreatedAt: in.CreatedAt.Format(time.DateTime),
|
||||
Approve: int32(in.Approve),
|
||||
Keywords: in.Keywords,
|
||||
}
|
||||
|
||||
list = append(list, &row)
|
||||
}
|
||||
return
|
||||
}
|
||||
37
apps/ec/mall/internal/logic/store/set_email.go
Normal file
37
apps/ec/mall/internal/logic/store/set_email.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package store
|
||||
|
||||
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 SetEmail(ctx context.Context, in *pb.SettingRequest) (reply *pb.StatusReply, err error) {
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if in.GetIdentity() == "" || in.GetConfigs() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
if err := impl.DBService.Model(&models.MallStore{}).Where("identity = ?", in.GetIdentity()).Update("mail_configs", in.GetConfigs()).Error; err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
37
apps/ec/mall/internal/logic/store/set_payment.go
Normal file
37
apps/ec/mall/internal/logic/store/set_payment.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package store
|
||||
|
||||
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 SetPayment(ctx context.Context, in *pb.SettingRequest) (reply *pb.StatusReply, err error) {
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if in.GetIdentity() == "" || in.GetConfigs() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
if err := impl.DBService.Model(&models.MallStore{}).Where("identity = ?", in.GetIdentity()).Update("pay_configs", in.GetConfigs()).Error; err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
46
apps/ec/mall/internal/logic/store/set_setting.go
Normal file
46
apps/ec/mall/internal/logic/store/set_setting.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package store
|
||||
|
||||
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/service"
|
||||
)
|
||||
|
||||
// 设置店铺基础配置
|
||||
func SetSetting(ctx context.Context, in *pb.StoreBasic) (reply *pb.StatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if in.Id == 0 && in.Identity == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
data := &models.MallStore{
|
||||
Logo: in.Logo,
|
||||
Title: in.Title,
|
||||
Intro: in.Intro,
|
||||
Template: in.Template,
|
||||
Subdomain: in.Subdomain,
|
||||
Configs: in.Configs,
|
||||
}
|
||||
|
||||
if err := impl.DBService.Model(&models.MallStore{}).Where("id=? or identity=?", in.GetId(), in.GetIdentity()).Updates(data).Error; err != nil {
|
||||
print(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
return &pb.StatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user