fix version 1
This commit is contained in:
@@ -15,7 +15,7 @@ import (
|
||||
// 删除广告
|
||||
func Delete(ctx context.Context, in *pb.IdentRequest) (reply *pb.IdentityStatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
auth, err := service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -25,11 +25,22 @@ func Delete(ctx context.Context, in *pb.IdentRequest) (reply *pb.IdentityStatusR
|
||||
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())
|
||||
// 只能删除当前登录者所属店铺的广告
|
||||
owner, _ := auth.Owner.(map[string]any)
|
||||
storeIdentity, _ := owner["store_identity"].(string)
|
||||
if storeIdentity == "" {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
tx := impl.DBService.Where("id=? or identity=?", in.GetId(), in.GetIdentity()).
|
||||
Where("store_identity = ?", storeIdentity).Delete(&models.MallAds{})
|
||||
if tx.Error != nil {
|
||||
printer.Error(tx.Error.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
if tx.RowsAffected == 0 {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
return &pb.IdentityStatusReply{
|
||||
Code: 0,
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
// 修改广告
|
||||
func Modify(ctx context.Context, in *pb.AdsItem) (reply *pb.IdentityStatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
auth, err := service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -26,6 +26,13 @@ func Modify(ctx context.Context, in *pb.AdsItem) (reply *pb.IdentityStatusReply,
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
// 只能修改当前登录者所属店铺的广告
|
||||
owner, _ := auth.Owner.(map[string]any)
|
||||
storeIdentity, _ := owner["store_identity"].(string)
|
||||
if storeIdentity == "" {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
data := models.MallAds{
|
||||
Title: in.Title,
|
||||
PosKey: in.PosKey,
|
||||
@@ -35,11 +42,15 @@ func Modify(ctx context.Context, in *pb.AdsItem) (reply *pb.IdentityStatusReply,
|
||||
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())
|
||||
tx := impl.DBService.Select("title", "pos_key", "content", "type", "to_url").
|
||||
Where("id=?", in.GetId()).Where("store_identity = ?", storeIdentity).Updates(&data)
|
||||
if tx.Error != nil {
|
||||
printer.Error(tx.Error.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
if tx.RowsAffected == 0 {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
return &pb.IdentityStatusReply{
|
||||
Code: 0,
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
// 删除分类
|
||||
func Delete(ctx context.Context, in *pb.IdentRequest) (reply *pb.IdentityStatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
auth, err := service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -25,11 +25,22 @@ func Delete(ctx context.Context, in *pb.IdentRequest) (reply *pb.IdentityStatusR
|
||||
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())
|
||||
// 只能删除当前登录者所属店铺的分类
|
||||
owner, _ := auth.Owner.(map[string]any)
|
||||
storeIdentity, _ := owner["store_identity"].(string)
|
||||
if storeIdentity == "" {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
tx := impl.DBService.Where("id=? or identity=?", in.GetId(), in.GetIdentity()).
|
||||
Where("store_identity = ?", storeIdentity).Delete(&models.MallCategory{})
|
||||
if tx.Error != nil {
|
||||
printer.Error(tx.Error.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
if tx.RowsAffected == 0 {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
return &pb.IdentityStatusReply{
|
||||
Code: 0,
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
|
||||
// 修改分类
|
||||
func Modify(ctx context.Context, in *pb.CategoryItem) (reply *pb.IdentityStatusReply, err error) {
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
auth, err := service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -22,16 +22,27 @@ func Modify(ctx context.Context, in *pb.CategoryItem) (reply *pb.IdentityStatusR
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
// 只能修改当前登录者所属店铺的分类
|
||||
owner, _ := auth.Owner.(map[string]any)
|
||||
storeIdentity, _ := owner["store_identity"].(string)
|
||||
if storeIdentity == "" {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
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())
|
||||
tx := impl.DBService.Select("title", "en_title", "parent_id", "paths", "intro", "icon", "sort", "status", "keys").
|
||||
Where("identity=?", in.GetIdentity()).Where("store_identity = ?", storeIdentity).Updates(&data)
|
||||
if tx.Error != nil {
|
||||
printer.Error(tx.Error.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
if tx.RowsAffected == 0 {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
return &pb.IdentityStatusReply{
|
||||
Identity: in.Identity,
|
||||
|
||||
@@ -2,7 +2,6 @@ package freight
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
pb "bsm/full/module/ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
@@ -21,12 +20,6 @@ func Create(ctx context.Context, in *pb.FreightItem) (reply *pb.IdentityStatusRe
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return &pb.IdentityStatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().Unix(),
|
||||
}, nil
|
||||
|
||||
// 该接口尚未实现,显式返回未实现错误,避免调用方误判成功。
|
||||
return nil, errcode.ErrUnimplemented
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package freight
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
pb "bsm/full/module/ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
@@ -22,12 +21,6 @@ func Delete(ctx context.Context, in *pb.IdentRequest) (reply *pb.IdentityStatusR
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return &pb.IdentityStatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().UnixNano(),
|
||||
}, nil
|
||||
|
||||
// 该接口尚未实现,显式返回未实现错误,避免调用方误判成功。
|
||||
return nil, errcode.ErrUnimplemented
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package freight
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
pb "bsm/full/module/ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
@@ -21,12 +20,6 @@ func DenyRegionCreate(ctx context.Context, in *pb.DenyRegionItem) (reply *pb.Ide
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return &pb.IdentityStatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().Unix(),
|
||||
}, nil
|
||||
|
||||
// 该接口尚未实现,显式返回未实现错误,避免调用方误判成功。
|
||||
return nil, errcode.ErrUnimplemented
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package freight
|
||||
|
||||
import (
|
||||
pb "bsm/full/module/ec/mall/pb"
|
||||
"context"
|
||||
|
||||
pb "bsm/full/module/ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 移除限制区域
|
||||
@@ -21,12 +21,6 @@ func DenyRegionDelete(ctx context.Context, in *pb.IdentRequest) (reply *pb.Ident
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return &pb.IdentityStatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().UnixNano(),
|
||||
}, nil
|
||||
|
||||
// 该接口尚未实现,显式返回未实现错误,避免调用方误判成功。
|
||||
return nil, errcode.ErrUnimplemented
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
pb "bsm/full/module/ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
@@ -22,7 +23,6 @@ func DenyRegionFetch(ctx context.Context, in *pb.MallFetchRequest) (reply *pb.De
|
||||
in.PageSize = 50
|
||||
}
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return
|
||||
// 该接口尚未实现,显式返回未实现错误,避免调用方误判成功。
|
||||
return nil, errcode.ErrUnimplemented
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@ package freight
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
pb "bsm/full/module/ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
@@ -16,14 +16,6 @@ func DenyRegionModify(ctx context.Context, in *pb.DenyRegionItem) (reply *pb.Ide
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// TODO: valid code
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return &pb.IdentityStatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().Unix(),
|
||||
}, nil
|
||||
|
||||
// 该接口尚未实现,显式返回未实现错误,避免调用方误判成功。
|
||||
return nil, errcode.ErrUnimplemented
|
||||
}
|
||||
|
||||
@@ -2,14 +2,14 @@ package freight
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
pb "bsm/full/module/ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// RemoveRegion 移除限制区域
|
||||
// DenyRegionRemove 移除禁运区域
|
||||
// 说明:该接口尚未实现,显式返回未实现错误,避免调用方误判成功。
|
||||
func DenyRegionRemove(ctx context.Context, in *pb.IdentRequest) (reply *pb.IdentityStatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
@@ -22,12 +22,5 @@ func DenyRegionRemove(ctx context.Context, in *pb.IdentRequest) (reply *pb.Ident
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return &pb.IdentityStatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().Unix(),
|
||||
}, nil
|
||||
|
||||
return nil, errcode.ErrUnimplemented
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ func Detail(ctx context.Context, in *pb.IdentRequest) (reply *pb.FreightItem, er
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return
|
||||
// 该接口尚未实现,显式返回未实现错误,避免调用方误判成功。
|
||||
return nil, errcode.ErrUnimplemented
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
pb "bsm/full/module/ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
@@ -23,7 +24,6 @@ func Fetch(ctx context.Context, in *pb.MallFetchRequest) (reply *pb.FreightReply
|
||||
in.PageSize = 50
|
||||
}
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return
|
||||
// 该接口尚未实现,显式返回未实现错误,避免调用方误判成功。
|
||||
return nil, errcode.ErrUnimplemented
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package freight
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
pb "bsm/full/module/ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
@@ -21,12 +20,6 @@ func Modify(ctx context.Context, in *pb.FreightItem) (reply *pb.IdentityStatusRe
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return &pb.IdentityStatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
// 该接口尚未实现,显式返回未实现错误,避免调用方误判成功。
|
||||
return nil, errcode.ErrUnimplemented
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
// FreightRemove 运费模板删除
|
||||
func Remove(ctx context.Context, in *pb.IdentRequest) (reply *pb.IdentityStatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
auth, err := service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -25,11 +25,22 @@ func Remove(ctx context.Context, in *pb.IdentRequest) (reply *pb.IdentityStatusR
|
||||
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())
|
||||
// 只能删除当前登录者所属店铺的运费模板(运费表归属字段为 owner_identity)
|
||||
owner, _ := auth.Owner.(map[string]any)
|
||||
storeIdentity, _ := owner["store_identity"].(string)
|
||||
if storeIdentity == "" {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
tx := impl.DBService.Where("id=? or identity=?", in.GetId(), in.GetIdentity()).
|
||||
Where("owner_identity = ?", storeIdentity).Delete(&models.MallFreight{})
|
||||
if tx.Error != nil {
|
||||
printer.Error(tx.Error.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
if tx.RowsAffected == 0 {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
return &pb.IdentityStatusReply{
|
||||
Code: 0,
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
// 删除公告
|
||||
func Delete(ctx context.Context, in *pb.IdentRequest) (reply *pb.IdentityStatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
auth, err := service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -25,11 +25,22 @@ func Delete(ctx context.Context, in *pb.IdentRequest) (reply *pb.IdentityStatusR
|
||||
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())
|
||||
// 只能删除当前登录者所属店铺的公告
|
||||
owner, _ := auth.Owner.(map[string]any)
|
||||
storeIdentity, _ := owner["store_identity"].(string)
|
||||
if storeIdentity == "" {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
tx := impl.DBService.Where("id=? or identity=?", in.GetId(), in.GetIdentity()).
|
||||
Where("store_identity = ?", storeIdentity).Delete(&models.MallNotice{})
|
||||
if tx.Error != nil {
|
||||
printer.Error(tx.Error.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
if tx.RowsAffected == 0 {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
return &pb.IdentityStatusReply{
|
||||
Code: 0,
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
// 修改公告
|
||||
func Modify(ctx context.Context, in *pb.NoticeItem) (reply *pb.IdentityStatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
auth, err := service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -24,18 +24,29 @@ func Modify(ctx context.Context, in *pb.NoticeItem) (reply *pb.IdentityStatusRep
|
||||
if in.GetTitle() == "" {
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
// 只能修改当前登录者所属店铺的公告
|
||||
owner, _ := auth.Owner.(map[string]any)
|
||||
storeIdentity, _ := owner["store_identity"].(string)
|
||||
if storeIdentity == "" {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
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())
|
||||
tx := impl.DBService.Model(&models.MallNotice{}).Select("title", "author", "content").
|
||||
Where("identity = ?", in.Identity).Where("store_identity = ?", storeIdentity).Updates(&data)
|
||||
if tx.Error != nil {
|
||||
printer.Error(tx.Error.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
if tx.RowsAffected == 0 {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
return &pb.IdentityStatusReply{
|
||||
Code: 0,
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
// Forbidden 批量操作
|
||||
func ItemBatchOp(ctx context.Context, in *pb.OpRequest) (reply *pb.IdentityStatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
auth, err := service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -23,12 +23,23 @@ func ItemBatchOp(ctx context.Context, in *pb.OpRequest) (reply *pb.IdentityStatu
|
||||
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())
|
||||
|
||||
// 只能批量操作当前登录者所属店铺的商品
|
||||
owner, _ := auth.Owner.(map[string]any)
|
||||
storeIdentity, _ := owner["store_identity"].(string)
|
||||
if storeIdentity == "" {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
tx := impl.DBService.Model(&models.MallProduct{}).Where("identity in ?", in.Identity).
|
||||
Where("store_identity = ?", storeIdentity).Update("status", in.Status)
|
||||
if tx.Error != nil {
|
||||
printer.Error(tx.Error.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
if tx.RowsAffected == 0 {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
return &pb.IdentityStatusReply{
|
||||
Code: 0,
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
// 删除产品
|
||||
func ItemDelete(ctx context.Context, in *pb.IdentRequest) (reply *pb.IdentityStatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
auth, err := service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -25,11 +25,22 @@ func ItemDelete(ctx context.Context, in *pb.IdentRequest) (reply *pb.IdentitySta
|
||||
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())
|
||||
// 只能删除当前登录者所属店铺的商品
|
||||
owner, _ := auth.Owner.(map[string]any)
|
||||
storeIdentity, _ := owner["store_identity"].(string)
|
||||
if storeIdentity == "" {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
tx := impl.DBService.Where("id=? or identity=?", in.GetId(), in.GetIdentity()).
|
||||
Where("store_identity = ?", storeIdentity).Delete(&models.MallProduct{})
|
||||
if tx.Error != nil {
|
||||
printer.Error(tx.Error.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
if tx.RowsAffected == 0 {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
return &pb.IdentityStatusReply{
|
||||
Code: 0,
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
pb "bsm/full/module/ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// Detail 获取产品详情
|
||||
@@ -42,5 +43,19 @@ func ItemDetail(ctx context.Context, in *pb.IdentRequest) (reply *pb.ProductItem
|
||||
for _, v := range data.Specs {
|
||||
reply.SpecId = append(reply.SpecId, int64(v.SpecId))
|
||||
}
|
||||
|
||||
// 成本类价格(进货价/代理价)仅店铺内部可见:匿名或非本店调用者不下发。
|
||||
callerStore := ""
|
||||
if auth, e := service.ParseMetaCtx(ctx, nil); e == nil && auth != nil {
|
||||
if owner, ok := auth.Owner.(map[string]any); ok {
|
||||
callerStore, _ = owner["store_identity"].(string)
|
||||
}
|
||||
}
|
||||
if callerStore == "" || callerStore != data.Store_Identity {
|
||||
for _, s := range reply.Specification {
|
||||
s.PurchasingPrice = 0
|
||||
s.Wholesale = 0
|
||||
}
|
||||
}
|
||||
return reply, nil
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ func ItemDetailBySerial(ctx context.Context, in *pb.StoreSerialRequest) (reply *
|
||||
}
|
||||
|
||||
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
|
||||
err = impl.DBService.Preload("Specs.Spec").Preload("Images").Preload("Categories.Category").Where("store_identity=? and serial_id in ?", in.StoreIdentity, in.SerialId).Find(&data).Error
|
||||
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
|
||||
@@ -13,9 +13,6 @@ func ItemDetailBySpec(ctx context.Context, in *pb.DetailBySpecRequest) (reply *p
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
// TODO: valid code
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return
|
||||
// 该接口尚未实现,显式返回未实现错误,避免调用方误判成功。
|
||||
return nil, errcode.ErrUnimplemented
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ func ItemFetch(ctx context.Context, in *pb.MallFetchRequest) (reply *pb.ListRepl
|
||||
params = map[string]string{
|
||||
"mall_product.store_identity": in.GetStoreIdentity(),
|
||||
}
|
||||
idList = make([]uint, 0)
|
||||
product []*models.MallProduct
|
||||
)
|
||||
|
||||
@@ -39,16 +38,10 @@ func ItemFetch(ctx context.Context, in *pb.MallFetchRequest) (reply *pb.ListRepl
|
||||
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).
|
||||
tx = tx.Where("product_category.category_id in ?", in.GetCategoryId()).
|
||||
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")
|
||||
}
|
||||
@@ -56,11 +49,18 @@ func ItemFetch(ctx context.Context, in *pb.MallFetchRequest) (reply *pb.ListRepl
|
||||
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())
|
||||
Joins("left join mall_product_spec on mall_product_spec.id = product_spec.spec_id")
|
||||
switch {
|
||||
case in.GetMinPrice() != 0 && in.GetMaxPrice() != 0:
|
||||
tx = tx.Where("mall_product_spec.price between ? and ?", in.GetMinPrice(), in.GetMaxPrice())
|
||||
case in.GetMinPrice() != 0:
|
||||
tx = tx.Where("mall_product_spec.price >= ?", in.GetMinPrice())
|
||||
default:
|
||||
tx = tx.Where("mall_product_spec.price <= ?", in.GetMaxPrice())
|
||||
}
|
||||
}
|
||||
|
||||
// 根据传入sort排序
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
// Modify 发布/取消发布 产品
|
||||
func ItemModify(ctx context.Context, in *pb.ModifyRequest) (reply *pb.IdentityStatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
auth, err := service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -25,11 +25,22 @@ func ItemModify(ctx context.Context, in *pb.ModifyRequest) (reply *pb.IdentitySt
|
||||
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())
|
||||
// 只能修改当前登录者所属店铺的商品
|
||||
owner, _ := auth.Owner.(map[string]any)
|
||||
storeIdentity, _ := owner["store_identity"].(string)
|
||||
if storeIdentity == "" {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
tx := impl.DBService.Model(&models.MallProduct{}).Where("identity = ?", in.Identity).
|
||||
Where("store_identity = ?", storeIdentity).Update("status", in.Status)
|
||||
if tx.Error != nil {
|
||||
printer.Error(tx.Error.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
if tx.RowsAffected == 0 {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
return &pb.IdentityStatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
|
||||
@@ -33,9 +33,12 @@ func PhotoCreate(ctx context.Context, in *pb.PhotoItem) (reply *pb.IdentityStatu
|
||||
}
|
||||
photo.Identity = utils.UUID()
|
||||
tx := impl.DBService.Create(&photo)
|
||||
cnt, err := tx.RowsAffected, tx.Error
|
||||
if cnt == 0 || err != nil {
|
||||
printer.Error(err.Error())
|
||||
if tx.Error != nil {
|
||||
printer.Error(tx.Error.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
if tx.RowsAffected == 0 {
|
||||
printer.Error("添加产品图片失败: 未写入任何记录")
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
// 删除产品图片
|
||||
func PhotoDelete(ctx context.Context, in *pb.IdentRequest) (reply *pb.IdentityStatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
auth, err := service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -25,11 +25,23 @@ func PhotoDelete(ctx context.Context, in *pb.IdentRequest) (reply *pb.IdentitySt
|
||||
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())
|
||||
// 只能删除当前登录者所属店铺商品的图片(图片表无店铺字段,按所属商品归属判定)
|
||||
owner, _ := auth.Owner.(map[string]any)
|
||||
storeIdentity, _ := owner["store_identity"].(string)
|
||||
if storeIdentity == "" {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
tx := impl.DBService.Where("id=? or identity=?", in.GetId(), in.GetIdentity()).
|
||||
Where("product_identity in (?)", impl.DBService.Model(&models.MallProduct{}).Select("identity").Where("store_identity = ?", storeIdentity)).
|
||||
Delete(&models.MallProductPhotos{})
|
||||
if tx.Error != nil {
|
||||
printer.Error(tx.Error.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
if tx.RowsAffected == 0 {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
// CreateSpec 添加产品规格
|
||||
func SpecCreate(ctx context.Context, in *pb.SpecItem) (reply *pb.IdentityStatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
auth, err := service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -27,16 +27,27 @@ func SpecCreate(ctx context.Context, in *pb.SpecItem) (reply *pb.IdentityStatusR
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 规格归属以 token 中的店铺为准,不采信请求参数
|
||||
owner, _ := auth.Owner.(map[string]any)
|
||||
storeIdentity, _ := owner["store_identity"].(string)
|
||||
if storeIdentity == "" {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
// 数据组装
|
||||
data, err := requestToModelSpec(in)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
data.Identity = utils.UUID()
|
||||
data.StoreIdentity = storeIdentity
|
||||
tx := impl.DBService.Create(data)
|
||||
cnt, err := tx.RowsAffected, tx.Error
|
||||
if cnt == 0 || err != nil {
|
||||
printer.Error(err.Error())
|
||||
if tx.Error != nil {
|
||||
printer.Error(tx.Error.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
if tx.RowsAffected == 0 {
|
||||
printer.Error("创建产品规格失败: 未写入任何记录")
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
@@ -93,9 +104,6 @@ func requestToModelSpec(in *pb.SpecItem) (*models.MallProductSpec, error) {
|
||||
PurchasingPrice: in.PurchasingPrice,
|
||||
Wholesale: in.Wholesale,
|
||||
}
|
||||
if in.StockType != 2 {
|
||||
specification.Stock = int64(in.StockType)
|
||||
}
|
||||
if in.TpType != 2 {
|
||||
specification.TpType = in.TpType
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
// 删除产品规格
|
||||
func SpecDelete(ctx context.Context, in *pb.IdentRequest) (reply *pb.IdentityStatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
auth, err := service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -25,12 +25,22 @@ func SpecDelete(ctx context.Context, in *pb.IdentRequest) (reply *pb.IdentitySta
|
||||
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())
|
||||
// 只能删除当前登录者所属店铺的规格
|
||||
owner, _ := auth.Owner.(map[string]any)
|
||||
storeIdentity, _ := owner["store_identity"].(string)
|
||||
if storeIdentity == "" {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
tx := impl.DBService.Where("id=? or identity=?", in.GetId(), in.GetIdentity()).
|
||||
Where("store_identity = ?", storeIdentity).Delete(&models.MallProductSpec{})
|
||||
if tx.Error != nil {
|
||||
printer.Error(tx.Error.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
// TODO: add your logic code & delete this line.
|
||||
if tx.RowsAffected == 0 {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
return &pb.IdentityStatusReply{
|
||||
Code: 0,
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
pb "bsm/full/module/ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// DetailSpec 产品详情
|
||||
@@ -23,7 +24,7 @@ func SpecDetail(ctx context.Context, in *pb.IdentRequest) (reply *pb.SpecItem, e
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
return &pb.SpecItem{
|
||||
reply = &pb.SpecItem{
|
||||
Id: int64(data.ID),
|
||||
Identity: data.Identity,
|
||||
SupplyId: data.SupplyId,
|
||||
@@ -37,5 +38,18 @@ func SpecDetail(ctx context.Context, in *pb.IdentRequest) (reply *pb.SpecItem, e
|
||||
Img: data.Img,
|
||||
PurchasingPrice: data.PurchasingPrice,
|
||||
Wholesale: data.Wholesale,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// 成本类价格(进货价/代理价)仅店铺内部可见:匿名或非本店调用者不下发。
|
||||
callerStore := ""
|
||||
if auth, e := service.ParseMetaCtx(ctx, nil); e == nil && auth != nil {
|
||||
if owner, ok := auth.Owner.(map[string]any); ok {
|
||||
callerStore, _ = owner["store_identity"].(string)
|
||||
}
|
||||
}
|
||||
if callerStore == "" || callerStore != data.StoreIdentity {
|
||||
reply.PurchasingPrice = 0
|
||||
reply.Wholesale = 0
|
||||
}
|
||||
return reply, nil
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
// 产品规格列表
|
||||
func SpecFetch(ctx context.Context, in *pb.MallFetchRequest) (reply *pb.SpecReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
auth, err := service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -23,8 +23,15 @@ func SpecFetch(ctx context.Context, in *pb.MallFetchRequest) (reply *pb.SpecRepl
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
// 只能查询当前登录者所属店铺的规格
|
||||
owner, _ := auth.Owner.(map[string]any)
|
||||
storeIdentity, _ := owner["store_identity"].(string)
|
||||
if storeIdentity == "" || storeIdentity != in.StoreIdentity {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
spec := make([]*models.MallProductSpec, 0)
|
||||
tx := impl.DBService.Model(&models.MallProductSpec{}).Where("store_identity = ?", in.StoreIdentity)
|
||||
tx := impl.DBService.Model(&models.MallProductSpec{}).Where("store_identity = ?", storeIdentity)
|
||||
if in.Keyword != "" {
|
||||
tx = tx.Where("keyword like ?", "%"+in.Keyword+"%")
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
// ModifySpec 修改产品规格
|
||||
func SpecModify(ctx context.Context, in *pb.SpecItem) (reply *pb.IdentityStatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
auth, err := service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -26,16 +26,27 @@ func SpecModify(ctx context.Context, in *pb.SpecItem) (reply *pb.IdentityStatusR
|
||||
|
||||
}
|
||||
|
||||
// 只能修改当前登录者所属店铺的规格,规格归属以 token 中的店铺为准
|
||||
owner, _ := auth.Owner.(map[string]any)
|
||||
storeIdentity, _ := owner["store_identity"].(string)
|
||||
if storeIdentity == "" {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
// 数据组装
|
||||
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())
|
||||
data.StoreIdentity = storeIdentity
|
||||
tx := impl.DBService.Where("identity=?", data.Identity).Where("store_identity = ?", storeIdentity).Updates(data)
|
||||
if tx.Error != nil {
|
||||
printer.Error(tx.Error.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
if tx.RowsAffected == 0 {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
return &pb.IdentityStatusReply{
|
||||
Code: 0,
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
// 删除工作人员
|
||||
func Delete(ctx context.Context, in *pb.IdentRequest) (reply *pb.IdentityStatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
auth, err := service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -25,11 +25,22 @@ func Delete(ctx context.Context, in *pb.IdentRequest) (reply *pb.IdentityStatusR
|
||||
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())
|
||||
// 只能删除当前登录者所属店铺的员工
|
||||
owner, _ := auth.Owner.(map[string]any)
|
||||
storeIdentity, _ := owner["store_identity"].(string)
|
||||
if storeIdentity == "" {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
tx := impl.DBService.Where("id=? or identity=?", in.GetId(), in.GetIdentity()).
|
||||
Where("store_identity = ?", storeIdentity).Delete(&models.MallStaff{})
|
||||
if tx.Error != nil {
|
||||
printer.Error(tx.Error.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
if tx.RowsAffected == 0 {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
return &pb.IdentityStatusReply{
|
||||
Code: 0,
|
||||
|
||||
@@ -9,15 +9,23 @@ import (
|
||||
pb "bsm/full/module/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 Fetch(ctx context.Context, in *pb.MallFetchRequest) (reply *pb.StaffListReply, err error) {
|
||||
// parse authorization meta.
|
||||
// _, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
auth, err := service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 仅可查询当前登录者所属店铺的员工,店铺取自 token,不采信请求参数
|
||||
owner, _ := auth.Owner.(map[string]any)
|
||||
storeIdentity, _ := owner["store_identity"].(string)
|
||||
if storeIdentity == "" {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
var (
|
||||
cnt int64 = 0
|
||||
@@ -25,7 +33,7 @@ func Fetch(ctx context.Context, in *pb.MallFetchRequest) (reply *pb.StaffListRep
|
||||
pageSize int64 = in.GetPageSize()
|
||||
offset int64 = (pageNo - 1) * pageSize
|
||||
params = map[string]string{
|
||||
"store_identity": in.GetStoreIdentity(),
|
||||
"store_identity": storeIdentity,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -16,9 +16,13 @@ import (
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/vars"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// 短信验证码在 Redis 中的 key 前缀,与 sender 模块保持一致:前缀 + 手机号
|
||||
const smsCodeKeyPrefix = "/SMS/Code/"
|
||||
|
||||
// Login 员工登录验证
|
||||
func Login(ctx context.Context, in *pb.LoginRequest) (reply *pb.LoginReply, err error) {
|
||||
var record models.MallStaff
|
||||
@@ -47,7 +51,27 @@ func Login(ctx context.Context, in *pb.LoginRequest) (reply *pb.LoginReply, err
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
err := impl.DBService.Where("phone = ?", in.Phone).First(&record).Error
|
||||
// 校验短信验证码,key 规则与 sender 模块一致:/SMS/Code/ + 手机号
|
||||
smsKey := smsCodeKeyPrefix + in.Phone
|
||||
storedCode, codeErr := impl.RedisService.Client.Get(impl.RedisService.Ctx, smsKey).Result()
|
||||
if codeErr != nil {
|
||||
if errors.Is(codeErr, redis.Nil) {
|
||||
printer.Error("验证码已过期或不存在: phone=%s", in.Phone)
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
printer.Error(codeErr.Error())
|
||||
return nil, errcode.ErrInternal
|
||||
}
|
||||
if storedCode != in.VerifyCode {
|
||||
printer.Error("验证码不正确: phone=%s", in.Phone)
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
// 校验成功后立即删除,避免同一验证码被重放
|
||||
if err := impl.RedisService.Client.Del(impl.RedisService.Ctx, smsKey).Err(); err != nil {
|
||||
printer.Error("清除验证码缓存异常: %v", err)
|
||||
}
|
||||
|
||||
err = impl.DBService.Where("phone = ?", in.Phone).First(&record).Error
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, errcode.ErrAccountNotFound
|
||||
@@ -55,7 +79,6 @@ func Login(ctx context.Context, in *pb.LoginRequest) (reply *pb.LoginReply, err
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
// TODO: 添加验证码校验逻辑
|
||||
|
||||
default:
|
||||
return nil, errcode.ErrUnimplemented
|
||||
|
||||
@@ -2,9 +2,9 @@ package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
pb "bsm/full/module/ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
@@ -16,14 +16,6 @@ func ApplyJoin(ctx context.Context, in *pb.ApplyJoinRequest) (reply *pb.Identity
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// TODO: valid code
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return &pb.IdentityStatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
Timeseq: time.Now().UnixMilli(),
|
||||
}, nil
|
||||
|
||||
// 该接口尚未实现,显式返回未实现错误,避免调用方误判成功。
|
||||
return nil, errcode.ErrUnimplemented
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
// 获取邮件服务器配置
|
||||
func GetEmail(ctx context.Context, in *pb.IdentRequest) (reply *pb.ConfigsReply, err error) {
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
auth, err := service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -21,11 +21,21 @@ func GetEmail(ctx context.Context, in *pb.IdentRequest) (reply *pb.ConfigsReply,
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
// 只能读取当前登录者所属店铺的配置
|
||||
owner, _ := auth.Owner.(map[string]any)
|
||||
storeIdentity, _ := owner["store_identity"].(string)
|
||||
|
||||
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())
|
||||
tx := impl.DBService.Model(&models.MallStore{}).Select("mail_configs").
|
||||
Where("id=? or identity=?", in.GetId(), in.GetIdentity()).
|
||||
Where("identity = ?", storeIdentity).Find(&sotre)
|
||||
if tx.Error != nil {
|
||||
print(tx.Error.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
if storeIdentity == "" || tx.RowsAffected == 0 {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
return &pb.ConfigsReply{
|
||||
Configs: sotre.MailConfigs,
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
// 获取支付方式配置
|
||||
func GetPayment(ctx context.Context, in *pb.IdentRequest) (reply *pb.ConfigsReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
auth, err := service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -22,11 +22,21 @@ func GetPayment(ctx context.Context, in *pb.IdentRequest) (reply *pb.ConfigsRepl
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
// 只能读取当前登录者所属店铺的配置
|
||||
owner, _ := auth.Owner.(map[string]any)
|
||||
storeIdentity, _ := owner["store_identity"].(string)
|
||||
|
||||
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())
|
||||
tx := impl.DBService.Model(&models.MallStore{}).Select("pay_configs").
|
||||
Where("id=? or identity=?", in.GetId(), in.GetIdentity()).
|
||||
Where("identity = ?", storeIdentity).Find(&sotre)
|
||||
if tx.Error != nil {
|
||||
print(tx.Error.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
if storeIdentity == "" || tx.RowsAffected == 0 {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
return &pb.ConfigsReply{Configs: sotre.PayConfigs}, nil
|
||||
|
||||
|
||||
@@ -8,20 +8,36 @@ import (
|
||||
"bsm/full/module/ec/mall/internal/models"
|
||||
pb "bsm/full/module/ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// 获取店铺基础配置
|
||||
func GetSetting(ctx context.Context, in *pb.IdentRequest) (reply *pb.StoreBasic, err error) {
|
||||
// parse authorization meta.
|
||||
auth, 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
|
||||
}
|
||||
|
||||
// 只能读取当前登录者所属店铺的配置
|
||||
owner, _ := auth.Owner.(map[string]any)
|
||||
storeIdentity, _ := owner["store_identity"].(string)
|
||||
|
||||
var data models.MallStore
|
||||
if err := impl.DBService.Where("id=? or identity=?", in.GetId(), in.GetIdentity()).First(&data).Error; err != nil {
|
||||
print(err.Error())
|
||||
tx := impl.DBService.Where("id=? or identity=?", in.GetId(), in.GetIdentity()).
|
||||
Where("identity = ?", storeIdentity).Find(&data)
|
||||
if tx.Error != nil {
|
||||
print(tx.Error.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
// TODO: add your logic code & delete this line.
|
||||
if storeIdentity == "" || tx.RowsAffected == 0 {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
return &pb.StoreBasic{
|
||||
Id: int64(data.ID),
|
||||
|
||||
@@ -9,10 +9,17 @@ import (
|
||||
"bsm/full/module/ec/mall/internal/models"
|
||||
pb "bsm/full/module/ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
// 店铺许可授权
|
||||
func Licensing(ctx context.Context, in *pb.LicensingRequest) (reply *pb.IdentityStatusReply, err error) {
|
||||
// 要求调用者已登录,避免仅凭子域名匿名枚举店铺标识。
|
||||
auth, err := service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var identity string
|
||||
licenseType := strings.ToUpper(in.GetLicenseType())
|
||||
|
||||
@@ -22,12 +29,17 @@ func Licensing(ctx context.Context, in *pb.LicensingRequest) (reply *pb.Identity
|
||||
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.
|
||||
// 归属校验:调用者只能是该店铺的成员,避免店铺标识被枚举获取。
|
||||
// 说明:完整许可码校验(in.License/in.LicenseType)需要许可数据源,当前仓库内不存在,暂无法实现。
|
||||
owner, _ := auth.Owner.(map[string]any)
|
||||
storeIdentity, _ := owner["store_identity"].(string)
|
||||
if storeIdentity == "" || storeIdentity != identity {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
return &pb.IdentityStatusReply{
|
||||
Code: 0,
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
pb "bsm/full/module/ec/mall/pb"
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
)
|
||||
|
||||
@@ -15,9 +16,6 @@ func MiniCode(ctx context.Context, in *pb.MiniCodeRequest) (reply *pb.MiniCodeRe
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// TODO: valid code
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
|
||||
return
|
||||
// 该接口尚未实现,显式返回未实现错误,避免调用方误判成功。
|
||||
return nil, errcode.ErrUnimplemented
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ func Search(ctx context.Context, in *pb.MallSearchRequest) (reply *pb.MallSearch
|
||||
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).
|
||||
if err := impl.DBService.Model(&models.MallStore{}).Where("keywords like ?", "%"+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
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
|
||||
// 设置邮件服务器配置
|
||||
func SetEmail(ctx context.Context, in *pb.SettingRequest) (reply *pb.IdentityStatusReply, err error) {
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
auth, err := service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -23,10 +23,21 @@ func SetEmail(ctx context.Context, in *pb.SettingRequest) (reply *pb.IdentitySta
|
||||
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())
|
||||
// 只能修改当前登录者所属店铺的配置
|
||||
owner, _ := auth.Owner.(map[string]any)
|
||||
storeIdentity, _ := owner["store_identity"].(string)
|
||||
if storeIdentity == "" || in.GetIdentity() != storeIdentity {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
tx := impl.DBService.Model(&models.MallStore{}).Where("identity = ?", in.GetIdentity()).Update("mail_configs", in.GetConfigs())
|
||||
if tx.Error != nil {
|
||||
printer.Error(tx.Error.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
if tx.RowsAffected == 0 {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
return &pb.IdentityStatusReply{
|
||||
Code: 0,
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
|
||||
// 设置支付方式配置
|
||||
func SetPayment(ctx context.Context, in *pb.SettingRequest) (reply *pb.IdentityStatusReply, err error) {
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
auth, err := service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -23,10 +23,21 @@ func SetPayment(ctx context.Context, in *pb.SettingRequest) (reply *pb.IdentityS
|
||||
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())
|
||||
// 只能修改当前登录者所属店铺的配置
|
||||
owner, _ := auth.Owner.(map[string]any)
|
||||
storeIdentity, _ := owner["store_identity"].(string)
|
||||
if storeIdentity == "" || in.GetIdentity() != storeIdentity {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
tx := impl.DBService.Model(&models.MallStore{}).Where("identity = ?", in.GetIdentity()).Update("pay_configs", in.GetConfigs())
|
||||
if tx.Error != nil {
|
||||
printer.Error(tx.Error.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
if tx.RowsAffected == 0 {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
return &pb.IdentityStatusReply{
|
||||
Code: 0,
|
||||
|
||||
@@ -8,13 +8,14 @@ import (
|
||||
"bsm/full/module/ec/mall/internal/models"
|
||||
pb "bsm/full/module/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 SetSetting(ctx context.Context, in *pb.StoreBasic) (reply *pb.IdentityStatusReply, err error) {
|
||||
// parse authorization meta.
|
||||
_, err = service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
auth, err := service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -22,6 +23,13 @@ func SetSetting(ctx context.Context, in *pb.StoreBasic) (reply *pb.IdentityStatu
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
// 只能修改当前登录者所属店铺的配置,禁止凭请求参数改他人店铺
|
||||
owner, _ := auth.Owner.(map[string]any)
|
||||
storeIdentity, _ := owner["store_identity"].(string)
|
||||
if storeIdentity == "" || in.GetIdentity() != storeIdentity {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
data := &models.MallStore{
|
||||
Logo: in.Logo,
|
||||
Title: in.Title,
|
||||
@@ -31,12 +39,15 @@ func SetSetting(ctx context.Context, in *pb.StoreBasic) (reply *pb.IdentityStatu
|
||||
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())
|
||||
tx := impl.DBService.Model(&models.MallStore{}).Where("identity = ?", storeIdentity).Updates(data)
|
||||
if tx.Error != nil {
|
||||
printer.Error(tx.Error.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
if tx.RowsAffected == 0 {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
// TODO: add your logic code & delete this line.
|
||||
return &pb.IdentityStatusReply{
|
||||
Code: 0,
|
||||
Message: "OK",
|
||||
|
||||
Reference in New Issue
Block a user