pg_user_create_service.go 1.6 KB
package domainService

import (
	"fmt"
	coreDomain "github.com/linmadan/egglib-go/core/domain"
	pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
	"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
	"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/repository"
)

type UserCreateService struct {
	coreDomain.BaseEventPublisher
	transactionContext *pgTransaction.TransactionContext
}

func (service *UserCreateService) CreateUser(operatorId int64, user *domain.User) (*domain.User, error) {
	// 检查操作人权限
	var err error
	UserRepository, _ := repository.NewUserRepository(service.transactionContext)
	//operator,err := UserRepository.FindOne(map[string]interface{}{"userId":operatorId})
	//if err!=nil{
	//	return nil,err
	//}
	//if operator.AdminType>=domain.NormalUser{
	//	return nil, fmt.Errorf("权限不足")
	//}
	if user.UserType&domain.Partner > 0 {
		if user.PartnerInfo == nil {
			return nil, fmt.Errorf("合伙人信息不能为空")
		}
	}
	user, err = UserRepository.Save(user)
	if err != nil {
		return nil, err
	}

	PhoneAuthenticationService, _ := NewPhoneAuthenticationService(service.transactionContext)
	if _, err = PhoneAuthenticationService.PhoneAuth(user.UserId, user.UserInfo.UserAccount, ""); err != nil {
		return nil, err
	}
	return user, err
}

func NewUserCreateService(transactionContext *pgTransaction.TransactionContext) (*UserCreateService, error) {
	if transactionContext == nil {
		return nil, fmt.Errorf("transactionContext参数不能为nil")
	} else {
		return &UserCreateService{
			transactionContext: transactionContext,
		}, nil
	}
}