feat: import services and standardize Go 1.26.5
This commit is contained in:
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
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user