2026-08-09 10:43:45 +08:00
|
|
|
package notice
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"time"
|
|
|
|
|
|
2026-08-09 12:41:08 +08:00
|
|
|
"bsm/full/module/ec/mall/internal/impl"
|
|
|
|
|
"bsm/full/module/ec/mall/internal/models"
|
|
|
|
|
pb "bsm/full/module/ec/mall/pb"
|
2026-08-09 10:43:45 +08:00
|
|
|
"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"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// 修改公告
|
2026-08-09 20:14:57 +08:00
|
|
|
func Modify(ctx context.Context, in *pb.NoticeItem) (reply *pb.IdentityStatusReply, err error) {
|
2026-08-09 10:43:45 +08:00
|
|
|
// parse authorization meta.
|
2026-09-22 21:15:34 +08:00
|
|
|
auth, err := service.ParseMetaCtx(ctx, &service.ParseOptions{RoleValue: "Mall_Admin"})
|
2026-08-09 10:43:45 +08:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if in.GetTitle() == "" {
|
|
|
|
|
return nil, errcode.ErrInvalidArgument
|
|
|
|
|
}
|
2026-09-22 21:15:34 +08:00
|
|
|
|
|
|
|
|
// 只能修改当前登录者所属店铺的公告
|
|
|
|
|
owner, _ := auth.Owner.(map[string]any)
|
|
|
|
|
storeIdentity, _ := owner["store_identity"].(string)
|
|
|
|
|
if storeIdentity == "" {
|
|
|
|
|
return nil, errcode.ErrPermissionDenied
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-09 10:43:45 +08:00
|
|
|
data := models.MallNotice{
|
|
|
|
|
Title: in.Title,
|
|
|
|
|
Author: in.Author,
|
|
|
|
|
Content: in.Content,
|
|
|
|
|
Std_IICUDS: types.Std_IICUDS{Status: int8(in.GetStatus())},
|
|
|
|
|
}
|
2026-09-22 21:15:34 +08:00
|
|
|
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())
|
2026-08-09 10:43:45 +08:00
|
|
|
return nil, errcode.ErrDB
|
|
|
|
|
}
|
2026-09-22 21:15:34 +08:00
|
|
|
if tx.RowsAffected == 0 {
|
|
|
|
|
return nil, errcode.ErrPermissionDenied
|
|
|
|
|
}
|
2026-08-09 10:43:45 +08:00
|
|
|
|
2026-08-09 20:14:57 +08:00
|
|
|
return &pb.IdentityStatusReply{
|
2026-08-09 10:43:45 +08:00
|
|
|
Code: 0,
|
|
|
|
|
Message: "OK",
|
|
|
|
|
Identity: in.GetIdentity(),
|
|
|
|
|
Timeseq: time.Now().UnixMilli(),
|
|
|
|
|
}, nil
|
|
|
|
|
|
|
|
|
|
}
|