052425970a
CI / changes (push) Successful in 40s
CI / ad (push) Successful in 0s
CI / admin (push) Successful in 0s
CI / bff (push) Successful in 24s
CI / chore (push) Successful in 23s
CI / equipment (push) Successful in 1s
CI / express (push) Successful in 0s
CI / factory (push) Successful in 0s
CI / payment (push) Successful in 1s
CI / product (push) Successful in 0s
CI / record (push) Successful in 0s
CI / sale (push) Successful in 23s
CI / task (push) Successful in 0s
CI / user (push) Successful in 24s
CI / wecom (push) Successful in 0s
82 lines
2.2 KiB
Go
82 lines
2.2 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
|
|
"lone-services/pkg/rpcclient"
|
|
"lone-services/pkg/utils"
|
|
userpb "lone-services/rpc/user/pb"
|
|
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
const saleClientCode = "sale_beauty"
|
|
|
|
func checkSaleIdentityCreatable(ctx context.Context, userSvcName, mobile string) error {
|
|
cli, err := rpcclient.Get(userSvcName)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
res, err := userpb.NewUserClient(cli.Conn()).InternalCheckCreate(ctx, &userpb.InternalCheckCreateReq{
|
|
Mobile: mobile,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if res == nil || !res.GetResult() {
|
|
return status.Error(codes.AlreadyExists, utils.ErrorDataIsExist.Msg)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func ensureSaleIdentity(ctx context.Context, userSvcName, mobile, password string, bizId int64) (*userpb.InternalCreateData, error) {
|
|
cli, err := rpcclient.Get(userSvcName)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return userpb.NewUserClient(cli.Conn()).InternalCreate(ctx, &userpb.InternalCreateReq{
|
|
Mobile: mobile,
|
|
ClientCode: []string{saleClientCode},
|
|
CredentialType: []string{"password"},
|
|
Secret: password,
|
|
BizId: bizId,
|
|
})
|
|
}
|
|
|
|
func updateSaleUserMobile(ctx context.Context, userSvcName string, userId int64, mobile string) (*userpb.InternalUpdateMobileData, error) {
|
|
cli, err := rpcclient.Get(userSvcName)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return userpb.NewUserClient(cli.Conn()).InternalUpdateMobile(ctx, &userpb.InternalUpdateMobileReq{
|
|
UserId: userId,
|
|
Mobile: mobile,
|
|
})
|
|
}
|
|
|
|
func revokeSaleUserClient(ctx context.Context, userSvcName string, userId int64) (*userpb.InternalRevokeBizClientData, error) {
|
|
cli, err := rpcclient.Get(userSvcName)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return userpb.NewUserClient(cli.Conn()).InternalRevokeBizClient(ctx, &userpb.InternalRevokeBizClientReq{
|
|
UserId: userId,
|
|
ClientCode: saleClientCode,
|
|
})
|
|
}
|
|
|
|
func reopenSaleUserClient(ctx context.Context, userSvcName, mobile string) (*userpb.InternalCreateData, error) {
|
|
return ensureSaleIdentity(ctx, userSvcName, mobile, utils.StringEmpty, utils.NumberZero)
|
|
}
|
|
|
|
func userRPCError(err error) (string, bool) {
|
|
if err == nil {
|
|
return utils.StringEmpty, false
|
|
}
|
|
if st, ok := status.FromError(err); ok {
|
|
return st.Message(), true
|
|
}
|
|
return err.Error(), true
|
|
}
|