55 lines
1.3 KiB
Go
55 lines
1.3 KiB
Go
package ads
|
|
|
|
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"
|
|
"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
|
|
|
|
}
|