52 lines
1.4 KiB
Go
52 lines
1.4 KiB
Go
package freight
|
||
|
||
import (
|
||
"context"
|
||
"time"
|
||
|
||
"bsm/full/module/ec/mall/internal/impl"
|
||
"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"
|
||
)
|
||
|
||
// FreightRemove 运费模板删除
|
||
func Remove(ctx context.Context, in *pb.IdentRequest) (reply *pb.IdentityStatusReply, 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_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,
|
||
Message: "OK",
|
||
Timeseq: time.Now().UnixMilli(),
|
||
}, nil
|
||
|
||
}
|