money_incentives_rule.go 1.8 KB
package transform

import (
	"github.com/shopspring/decimal"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
)

func TransformToMoneyIncentivesRuleDomainModelFromPgModels(moneyIncentivesRuleModel *models.MoneyIncentivesRule) (*domain.MoneyIncentivesRule, error) {
	stageString := utils.NumberToCNNumber(int(moneyIncentivesRuleModel.MoneyIncentivesStage))
	moneyIncentivesAmount, _ := decimal.NewFromFloatWithExponent(moneyIncentivesRuleModel.MoneyIncentivesAmount, -2).Float64()
	return &domain.MoneyIncentivesRule{
		MoneyIncentivesRuleId:     moneyIncentivesRuleModel.MoneyIncentivesRuleId,
		CooperationContractNumber: moneyIncentivesRuleModel.CooperationContractNumber,
		MoneyIncentivesAmount:     moneyIncentivesAmount,
		MoneyIncentivesStage:      moneyIncentivesRuleModel.MoneyIncentivesStage,
		MoneyIncentivesStageCN:    stageString,
		MoneyIncentivesStageEnd:   moneyIncentivesRuleModel.MoneyIncentivesStageEnd,
		MoneyIncentivesStageStart: moneyIncentivesRuleModel.MoneyIncentivesStageStart,
		MoneyIncentivesTime:       moneyIncentivesRuleModel.MoneyIncentivesTime,
		ReferrerPercentage:        moneyIncentivesRuleModel.ReferrerPercentage,
		SalesmanPercentage:        moneyIncentivesRuleModel.SalesmanPercentage,
		Remarks:                   moneyIncentivesRuleModel.Remarks,
		Org:                       moneyIncentivesRuleModel.Org,
		Company:                   moneyIncentivesRuleModel.Company,
		UpdatedAt:                 moneyIncentivesRuleModel.UpdatedAt,
		DeletedAt:                 moneyIncentivesRuleModel.DeletedAt,
		CreatedAt:                 moneyIncentivesRuleModel.CreatedAt,
	}, nil
}