cooperation_contract.go 4.5 KB
package service

import (
	"time"

	"github.com/linmadan/egglib-go/core/application"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/cooperationContract/command"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/cooperationContract/query"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_cooperation"
)

// 共创合约管理
type CooperationContractService struct {
}

// 创建共创合约管理
func (cooperationContractService *CooperationContractService) CreateCooperationContract(createCooperationContractCommand *command.CreateCooperationContractCommand) (interface{}, error) {
	if err := createCooperationContractCommand.ValidateCommand(); err != nil {
		return nil, application.ThrowError(application.ARG_ERROR, err.Error())
	}
	creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(createCooperationContractCommand.Operator)

	rules1 := []allied_creation_cooperation.DividendsIncentivesRule{}
	for _, v := range createCooperationContractCommand.DividendsIncentivesRules {
		r := allied_creation_cooperation.DividendsIncentivesRule{
			CooperationContractNumber:     v.CooperationContractNumber,
			ReferrerPercentage:            v.ReferrerPercentage,
			SalesmanPercentage:            v.SalesmanPercentage,
			DividendsIncentivesPercentage: v.DividendsIncentivesPercentage,
			DividendsIncentivesStage:      v.DividendsIncentivesStage,
			DividendsIncentivesStageEnd:   time.Unix(int64(v.DividendsIncentivesStageEnd), 0),
			DividendsIncentivesStageStart: time.Unix(int64(v.DividendsIncentivesStageStart), 0),
		}
		rules1 = append(rules1, r)
	}
	// rules2 := []allied_creation_cooperation.MoneyIncentivesRule{}

	_, err := creationCooperationGateway.CooperationContractAdd(allied_creation_cooperation.ReqCooperationContractAdd{})
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	return createCooperationContractCommand, err
}

// 暂停恢复共创合约
func (cooperationContractService *CooperationContractService) EnableCooperationContract(enableCooperationContractCommand *command.EnableCooperationContractCommand) (interface{}, error) {
	if err := enableCooperationContractCommand.ValidateCommand(); err != nil {
		return nil, application.ThrowError(application.ARG_ERROR, err.Error())
	}

	return nil, nil
}

// 返回共创合约管理
func (cooperationContractService *CooperationContractService) GetCooperationContract(getCooperationContractQuery *query.GetCooperationContractQuery) (interface{}, error) {
	if err := getCooperationContractQuery.ValidateQuery(); err != nil {
		return nil, application.ThrowError(application.ARG_ERROR, err.Error())
	}
	creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(getCooperationContractQuery.Operator)
	result, err := creationCooperationGateway.CooperationContractGet(allied_creation_cooperation.ReqCooperationContractGet{
		CooperationContractId: getCooperationContractQuery.CooperationContractId,
	})
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	return result, nil
}

// 返回共创合约管理列表
func (cooperationContractService *CooperationContractService) ListCooperationContract(listCooperationContractQuery *query.ListCooperationContractQuery) (interface{}, error) {
	if err := listCooperationContractQuery.ValidateQuery(); err != nil {
		return nil, application.ThrowError(application.ARG_ERROR, err.Error())
	}
	creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(listCooperationContractQuery.Operator)
	result, err := creationCooperationGateway.CooperationContractSearch(allied_creation_cooperation.ReqCooperationContractSearch{})
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	_ = result
	return nil, nil
}

// 更新共创合约管理
func (cooperationContractService *CooperationContractService) UpdateCooperationContract(updateCooperationContractCommand *command.UpdateCooperationContractCommand) (interface{}, error) {
	if err := updateCooperationContractCommand.ValidateCommand(); err != nil {
		return nil, application.ThrowError(application.ARG_ERROR, err.Error())
	}
	return nil, nil
}

func NewCooperationContractService(options map[string]interface{}) *CooperationContractService {
	newCooperationContractService := &CooperationContractService{}
	return newCooperationContractService
}