cooperation_person_statistics_dto.go 2.9 KB
package domain

import (
	"strings"
	"time"
)

// CooperationPersonStatisticsDto 共创人员信息统计
type CooperationPersonStatisticsDto struct {
	// 共创时间
	CooperationTime time.Time `json:"cooperationTime"`
	// 合伙类型,即共创模式
	CooperationTypes []*CooperationMode `json:"cooperationTypes"`
	// 分红明细
	DividendsDetails *DividendsDetails `json:"dividendsDetails"`
	// 订单明细
	OrderDetails *OrderDetails `json:"orderDetails"`
	// 共创人员姓名
	UserName string `json:"userName"`
}

// 1.共创项目浏览详情

// 共创项目详情
type CooperationProjectSharedInfoDto struct {
	// 共创项目数据
	Project interface{} `json:"project"`
	// 企业信息
	Org *Org `json:"org"`
	// 企业关注状态
	OrgStarred bool `json:"orgStarred"`
	// 合同参与人
	ContractParticipant []*ContractParticipant `json:"contractParticipant"`
}

// 项目参与人
type ContractParticipant struct {
	//
	User *User `json:"-"`
	// 参与人
	Participant interface{} `json:"participant"`
	// 合约数据 (合约名称、合约状态、合约附件)
	Contract interface{} `json:"contract"`
	// 订单金额
	OrderAmount float64 `json:"orderAmount"`
	// 分红金额 ()
	DividendsAmount float64 `json:"dividendsAmount"`
	// 合同内容
	ContractContent string `json:"contractContent"`
	// 敏感标识
	SensitiveFlag bool `json:"sensitiveFlag"`
	// 共创合约编号
	primaryKey string `json:"key"`
}

func (u *User) SimpleCopy() map[string]interface{} {
	return map[string]interface{}{
		"userId": u.UserId,
		//"userBaseId":u.UserBaseId,
		"userInfo": u.UserInfo,
	}
}
func (ut *Undertaker) ToUser() *User {
	return &User{UserId: ut.UserId, UserBaseId: ut.UserBaseId, UserInfo: ut.UserInfo}
}

func (ut *Referrer) ToUser() *User {
	return &User{UserId: ut.UserId, UserBaseId: ut.UserBaseId, UserInfo: ut.UserInfo}
}

func (ut *Salesman) ToUser() *User {
	return &User{UserId: ut.UserId, UserBaseId: ut.UserBaseId, UserInfo: ut.UserInfo}
}

func NewContractParticipant(u *User, primaryKey string, attachments []*Attachment) *ContractParticipant {
	p := &ContractParticipant{
		User:        u,
		Participant: u.SimpleCopy(),
		primaryKey:  primaryKey,
	}
	if len(attachments) > 0 {
		p.ContractContent = attachments[0].Name
	}
	return p
}

func (cp *ContractParticipant) Complete(userBaseId int64, sensitive bool) *ContractParticipant {
	cp.SensitiveFlag = false
	if sensitive {
		if cp.User.UserBaseId != userBaseId {
			cp.DividendsAmount = 0
			cp.SensitiveFlag = true
			name := []byte(cp.User.UserInfo.UserName)
			for i := range name {
				if i == 0 {
					continue
				}
				name[i] = byte('*')
			}
			cp.User.UserInfo.UserName = string(name)
			cp.Participant = cp.User.SimpleCopy()
		}
		return cp
	}
	return cp
}

func (cp *ContractParticipant) CooperationContractNumber() string {
	sp := strings.Split(cp.primaryKey, "-")
	if len(sp) == 0 {
		return ""
	}
	return sp[0]
}