|
|
package domain_service
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"github.com/go-pg/pg/v10"
|
|
|
"github.com/linmadan/egglib-go/utils/tool_funs"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/repository"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/service_gateway"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
|
|
|
"time"
|
|
|
)
|
...
|
...
|
@@ -191,3 +194,227 @@ func (ptr *CooperationStatisticsService) PersonCompanyPaymentHistoryStatistics(q |
|
|
|
|
|
return retMap, nil
|
|
|
}
|
|
|
|
|
|
// 个人 - 共创浏览 详情页
|
|
|
func (ptr *CooperationStatisticsService) PersonCooperationProjectSharedInfo(queryOptions map[string]interface{}) (interface{}, error) {
|
|
|
// 参数验证
|
|
|
var request = struct {
|
|
|
UserBaseId int64 `json:"userBaseId"`
|
|
|
// 项目ID
|
|
|
ProjectId int64 `json:"projectId" valid:"Required"`
|
|
|
// 敏感数据
|
|
|
Sensitive bool `json:"sensitive" valid:"Required"`
|
|
|
}{}
|
|
|
if err := LoadQueryObject(queryOptions, &request); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
queryOptions = tool_funs.SimpleStructToMap(&request)
|
|
|
var response = domain.CooperationProjectSharedInfoDto{
|
|
|
ContractParticipant: make([]*domain.ContractParticipant, 0),
|
|
|
}
|
|
|
|
|
|
projectRepository, _ := repository.NewCooperationProjectRepository(ptr.transactionContext)
|
|
|
project, err := projectRepository.FindOne(map[string]interface{}{"cooperationProjectId": request.ProjectId})
|
|
|
if err != nil {
|
|
|
return nil, fmt.Errorf("共创项目不存在")
|
|
|
}
|
|
|
|
|
|
// 0.共创项目数据
|
|
|
updateAt := project.UpdatedAt
|
|
|
if project.UpdatedAt.IsZero() {
|
|
|
updateAt = project.CreatedAt
|
|
|
}
|
|
|
response.Project = map[string]interface{}{
|
|
|
"cooperationProjectId": project.CooperationProjectId,
|
|
|
"attachment": project.Attachment,
|
|
|
"cooperationProjectDescription": project.CooperationProjectDescription,
|
|
|
"updatedAt": updateAt.Unix() * 1000,
|
|
|
}
|
|
|
// 0.1 组织数据
|
|
|
response.Org = project.Org
|
|
|
if request.UserBaseId != 0 {
|
|
|
// 当前用户对于项目组织的关注状态
|
|
|
userServiceGateway := service_gateway.NewHttplibUserServiceGateway()
|
|
|
userDetail, e := userServiceGateway.GetUserInfo(0, 0, request.UserBaseId)
|
|
|
if e == nil && userDetail != nil {
|
|
|
for i := range userDetail.Favorite.OrgItems {
|
|
|
if userDetail.Favorite.OrgItems[i] == project.Org.OrgId {
|
|
|
response.OrgStarred = true
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 0.2 合约数据
|
|
|
contractRepository, _ := dao.NewCooperationContractDao(ptr.transactionContext) // repository.NewCooperationContractRepository(ptr.transactionContext)
|
|
|
_, contracts, _ := contractRepository.Find(map[string]interface{}{"cooperationProjectNumber": project.CooperationProjectNumber, "companyId": project.Company.CompanyId, "orgId": project.Org.OrgId})
|
|
|
if len(contracts) == 0 {
|
|
|
return response, nil
|
|
|
}
|
|
|
|
|
|
contractNumbers := make([]string, 0)
|
|
|
mapContract := make(map[string]*domain.CooperationContract)
|
|
|
for i := range contracts {
|
|
|
contractNumbers = append(contractNumbers, contracts[i].CooperationContractNumber)
|
|
|
mapContract[contracts[i].CooperationContractNumber] = contracts[i]
|
|
|
}
|
|
|
keyfun := func(num string, userBaseId int64) string {
|
|
|
return num + "-" + fmt.Sprintf("%v", userBaseId)
|
|
|
}
|
|
|
|
|
|
// 1.项目的承接人
|
|
|
undertakerRepository, _ := repository.NewCooperationContractUndertakerRepository(ptr.transactionContext)
|
|
|
_, undertakers, err := undertakerRepository.Find(map[string]interface{}{"cooperationContractNumbers": contractNumbers, "companyId": project.Company.CompanyId, "orgId": project.Org.OrgId})
|
|
|
userSorted := make([]string, 0)
|
|
|
mapUser := make(map[string]*domain.ContractParticipant)
|
|
|
for i := range undertakers {
|
|
|
u := undertakers[i]
|
|
|
key := keyfun(u.CooperationContractNumber, u.Undertaker.UserBaseId)
|
|
|
userSorted = append(userSorted, key)
|
|
|
mapUser[keyfun(u.CooperationContractNumber, u.Undertaker.UserBaseId)] = domain.NewContractParticipant(u.Undertaker.ToUser(), key, u.Undertaker.ContractAttachment)
|
|
|
if u.Undertaker.Referrer != nil {
|
|
|
key = keyfun(u.CooperationContractNumber, u.Undertaker.Referrer.UserBaseId)
|
|
|
userSorted = append(userSorted, key)
|
|
|
mapUser[keyfun(u.CooperationContractNumber, u.Undertaker.Referrer.UserBaseId)] = domain.NewContractParticipant(u.Undertaker.Referrer.ToUser(), key, u.Undertaker.ContractAttachment)
|
|
|
}
|
|
|
if u.Undertaker.Salesman != nil {
|
|
|
userSorted = append(userSorted, keyfun(u.CooperationContractNumber, u.Undertaker.Salesman.UserBaseId))
|
|
|
mapUser[keyfun(u.CooperationContractNumber, u.Undertaker.Salesman.UserBaseId)] = domain.NewContractParticipant(u.Undertaker.Salesman.ToUser(), key, u.Undertaker.ContractAttachment)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 2.合约的订单金额
|
|
|
mapContractOrderAmount := make(map[string]float64)
|
|
|
dividendsOrderDao, _ := dao.NewDividendsOrderDao(ptr.transactionContext)
|
|
|
mapContractOrderAmount, _ = dividendsOrderDao.CalculateGoodOrderAmountByGroup(map[string]interface{}{
|
|
|
"cooperationContractNumbers": contractNumbers, "companyId": project.Company.CompanyId, "orgId": project.Org.OrgId,
|
|
|
})
|
|
|
|
|
|
// 3.计算合约用户的分红预算金额
|
|
|
dividendsEstimateRepository, _ := repository.NewDividendsEstimateRepository(ptr.transactionContext)
|
|
|
_, dividends, err := dividendsEstimateRepository.Find(map[string]interface{}{"cooperationContractNumbers": contractNumbers, "companyId": project.Company.CompanyId, "orgId": project.Org.OrgId, "dividendsAccountStatus": int32(1), "offsetLimit": false})
|
|
|
for i := range dividends {
|
|
|
d := dividends[i]
|
|
|
key := keyfun(d.CooperationContractNumber, d.DividendsUser.UserBaseId)
|
|
|
if v, ok := mapUser[key]; ok {
|
|
|
v.DividendsAmount += d.DividendsAmount
|
|
|
}
|
|
|
}
|
|
|
|
|
|
for _, v := range mapUser {
|
|
|
if v1, ok := mapContractOrderAmount[v.CooperationContractNumber()]; ok {
|
|
|
v.OrderAmount = v1
|
|
|
}
|
|
|
if v1, ok := mapContract[v.CooperationContractNumber()]; ok {
|
|
|
v.Contract = map[string]interface{}{
|
|
|
"cooperationContractId": v1.CooperationContractId,
|
|
|
"cooperationContractName": v1.CooperationContractName,
|
|
|
"status": v1.Status,
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
for i := range userSorted {
|
|
|
if v, ok := mapUser[userSorted[i]]; ok {
|
|
|
response.ContractParticipant = append(response.ContractParticipant, v.Complete(request.UserBaseId, request.Sensitive))
|
|
|
}
|
|
|
}
|
|
|
return response, nil
|
|
|
}
|
|
|
|
|
|
// 个人 - 共创浏览 合约列表
|
|
|
func (ptr *CooperationStatisticsService) CompanyCooperationProjectContracts(queryOptions map[string]interface{}) (interface{}, error) {
|
|
|
// 参数验证
|
|
|
var request = struct {
|
|
|
Offset int `json:"offset"`
|
|
|
Limit int `json:"limit"`
|
|
|
// 项目ID
|
|
|
ProjectId int64 `json:"projectId" valid:"Required"`
|
|
|
}{}
|
|
|
if err := LoadQueryObject(queryOptions, &request); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
projectRepository, _ := repository.NewCooperationProjectRepository(ptr.transactionContext)
|
|
|
project, err := projectRepository.FindOne(map[string]interface{}{"cooperationProjectId": request.ProjectId})
|
|
|
if err != nil {
|
|
|
return nil, fmt.Errorf("共创项目不存在")
|
|
|
}
|
|
|
|
|
|
// 0.2 合约数据
|
|
|
contractRepository, _ := dao.NewCooperationContractDao(ptr.transactionContext) // repository.NewCooperationContractRepository(ptr.transactionContext)
|
|
|
_, contracts, _ := contractRepository.Find(map[string]interface{}{"cooperationProjectNumber": project.CooperationProjectNumber,
|
|
|
"companyId": project.Company.CompanyId,
|
|
|
"orgId": project.Org.OrgId,
|
|
|
"limit": request.Limit,
|
|
|
"offset": request.Offset,
|
|
|
})
|
|
|
if len(contracts) == 0 {
|
|
|
return nil, nil
|
|
|
}
|
|
|
|
|
|
contractNumbers := make([]string, 0)
|
|
|
mapContract := make(map[string]*domain.CooperationContract)
|
|
|
for i := range contracts {
|
|
|
contractNumbers = append(contractNumbers, contracts[i].CooperationContractNumber)
|
|
|
mapContract[contracts[i].CooperationContractNumber] = contracts[i]
|
|
|
}
|
|
|
|
|
|
// 2.合约的订单金额
|
|
|
mapContractOrderAmount := make(map[string]float64)
|
|
|
dividendsOrderDao, _ := dao.NewDividendsOrderDao(ptr.transactionContext)
|
|
|
mapContractOrderAmount, _ = dividendsOrderDao.CalculateGoodOrderAmountByGroup(map[string]interface{}{
|
|
|
"cooperationContractNumbers": contractNumbers, "companyId": project.Company.CompanyId, "orgId": project.Org.OrgId,
|
|
|
})
|
|
|
|
|
|
// 3.计算合约用户的分红预算金额
|
|
|
dividendsEstimateRepository, _ := dao.NewDividendsEstimateDao(ptr.transactionContext) //repository.NewDividendsEstimateRepository(ptr.transactionContext)
|
|
|
mapDividends, err := dividendsEstimateRepository.DividendsEstimateStatisticsGroup(map[string]interface{}{"cooperationContractNumbers": contractNumbers, "companyId": project.Company.CompanyId, "orgId": project.Org.OrgId})
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
results := make([]interface{}, 0)
|
|
|
for i := range contracts {
|
|
|
item := contracts[i]
|
|
|
|
|
|
resultItem := &searchContractDividendsResult{
|
|
|
CooperationContractId: item.CooperationContractId,
|
|
|
CooperationContractName: item.CooperationContractName,
|
|
|
CooperationContractNumber: item.CooperationContractNumber,
|
|
|
Status: item.Status,
|
|
|
CreatedAt: item.CreatedAt.Unix() * 1000,
|
|
|
}
|
|
|
if v, ok := mapContractOrderAmount[contracts[i].CooperationContractNumber]; ok {
|
|
|
resultItem.DividendsOrderAmount = v
|
|
|
}
|
|
|
if v, ok := mapDividends[contracts[i].CooperationContractNumber]; ok {
|
|
|
resultItem.DividendsAmount = v
|
|
|
}
|
|
|
results = append(results, resultItem)
|
|
|
}
|
|
|
return results, nil
|
|
|
}
|
|
|
|
|
|
// func(ptr *CooperationStatisticsService)
|
|
|
|
|
|
// 个人 - 共创浏览 详情页 - 附件数据
|
|
|
func (ptr *CooperationStatisticsService) PersonCooperationProjectSharedInfoAttachment(queryOptions map[string]interface{}) (interface{}, error) {
|
|
|
// 参数验证
|
|
|
var request = struct {
|
|
|
UserBaseId int64 `json:"userBaseId"`
|
|
|
// 用户
|
|
|
UserId int64 `json:"userId" valid:"Required"`
|
|
|
// 项目ID
|
|
|
ProjectId int64 `json:"projectId" valid:"Required"`
|
|
|
// 合约ID
|
|
|
ContractId int64 `json:"contractId" valid:"Required"`
|
|
|
// 附件类型 1:合约附件 2:支付凭证
|
|
|
AttachType int `json:"attachType" valid:"Required"`
|
|
|
}{}
|
|
|
if err := LoadQueryObject(queryOptions, &request); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
queryOptions = tool_funs.SimpleStructToMap(&request)
|
|
|
var response = domain.CooperationProjectSharedInfoDto{}
|
|
|
return response, nil
|
|
|
} |
...
|
...
|
|