confirm_dividends_incentives_estimate.go 2.6 KB
package service

import (
	"fmt"
	coreDomain "github.com/linmadan/egglib-go/core/domain"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
	"time"
)

type DividendsEstimateDetail struct {
	DividendsUser                   *domain.User `json:"dividendsUser"`                   // 共创参与(分红用户)
	DividendsPercentage             float64      `json:"dividendsPercentage"`             // 分红比例
	DividendsParticipateType        int32        `json:"dividendsParticipateType"`        // 参与类型 1承接人,2推荐人,3关联业务员
	DividendsStage                  int32        `json:"dividendsStage"`                  // 分红阶段
	DividendsAmount                 float64      `json:"dividendsAmount"`                 // 分红金额
	OrderOrReturnedOrderNumber      string       `json:"orderOrReturnedOrderNumber"`      // 分红订单号或退货单号
	IsSuccessfully                  bool         `json:"isSuccessfully"`                  // 是否预算成功
	Reason                          string       `json:"reason"`                          // 错误原因
	CooperationContractUndertakerId int64        `json:"cooperationContractUndertakerId"` // 承接人记录ID
	CooperationContractNumber       string       `json:"cooperationContractNumber"`
	OrderGoodId                     int64        `json:"orderGoodId"`
	OrderGoodAmount                 float64      `json:"orderGoodAmount"`
}

// GenerateSpecificDividendsEstimateNumber 批量生成自定义分红预算单号
func (DividendsEstimateDetail *DividendsEstimateDetail) GenerateSpecificDividendsEstimateNumber(count int64, index int64) (string, error) {
	currentTime := time.Now()
	if count+index < 1000 {
		countStr := fmt.Sprintf("%03d", count+index+1)
		timestamp := currentTime.Unix()
		timeNow := time.Unix(timestamp, 0)
		timeString := timeNow.Format("20060102")
		timeString = timeString[2:len(timeString)]
		dividendsEstimateNumber := "FH" + timeString + "#" + countStr
		return dividendsEstimateNumber, nil
	} else {
		countStr := fmt.Sprintf("%d", count+index+1)
		timestamp := currentTime.Unix()
		timeNow := time.Unix(timestamp, 0)
		timeString := timeNow.Format("20060102")
		timeString = timeString[2:len(timeString)]
		dividendsEstimateNumber := "FH" + timeString + "#" + countStr
		return dividendsEstimateNumber, nil
	}
}

type ConfirmDividendsIncentivesEstimateService interface {
	coreDomain.DomainEventPublisher
	Confirm(orderGoods []*domain.OrderGood, companyId int64, orgId int64, cooperationContractsMap map[string]*domain.CooperationContract) ([]*DividendsEstimateDetail, error)
}