作者 yangfu

合约详情修改

... ... @@ -387,6 +387,7 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
CreatedAt: time.Now(),
DeletedAt: time.Time{},
UpdatedAt: time.Time{},
CooperationProjectId: cooperationProject.CooperationProjectId,
}
// 共创合约仓储初始化
... ...
... ... @@ -77,6 +77,8 @@ type CooperationContract struct {
DeletedAt time.Time `json:"deletedAt"`
// 更新时间
UpdatedAt time.Time `json:"updatedAt"`
// 共创项目编号
CooperationProjectId int64 `json:"cooperationProjectId"`
}
type CooperationContractRepository interface {
... ... @@ -175,3 +177,20 @@ func (cooperationContract *CooperationContract) MoneyIncentivesRuleSliceEqualBCE
}
return true
}
func CooperationContractsToProjectIds(contracts []*CooperationContract) []int64 {
var projectIds = make([]int64, 0)
for i := range contracts {
var exist = false
for j := range projectIds {
if contracts[i].CooperationProjectId == projectIds[j] {
exist = true
break
}
}
if !exist {
projectIds = append(projectIds, contracts[i].CooperationProjectId)
}
}
return projectIds
}
... ...
... ... @@ -91,3 +91,28 @@ func (cooperationProject *CooperationProject) Update(data map[string]interface{}
cooperationProject.UpdatedAt = time.Now()
return nil
}
func CooperationProjectsToMap(queryOptions map[string]interface{}, find func(queryOptions map[string]interface{}) (int64, []*CooperationProject, error)) (map[int64]*CooperationProject, error) {
var result = make(map[int64]*CooperationProject)
_, projects, err := find(queryOptions)
if err != nil {
return nil, err
}
for i := range projects {
result[projects[i].CooperationProjectId] = projects[i]
}
return result, nil
}
func (cooperationProject *CooperationProject) CloneSimple() interface{} {
var mapResult = map[string]interface{}{
"cooperationProjectId": cooperationProject.CooperationProjectId,
"cooperationProjectName": cooperationProject.CooperationProjectName,
"cooperationProjectDescription": cooperationProject.CooperationProjectDescription,
"updatedAt": cooperationProject.UpdatedAt.Unix() * 1000,
}
if cooperationProject.UpdatedAt.Unix() < 0 {
mapResult["updatedAt"] = cooperationProject.CreatedAt.Unix() * 1000
}
return mapResult
}
... ...
... ... @@ -107,6 +107,18 @@ func (ptr *CooperationStatisticsService) SearchContractDividends(queryOptions ma
return nil, err
}
// 1.1 个人返回合约对应的项目
var mapProject = make(map[int64]*domain.CooperationProject)
var projectIds = domain.CooperationContractsToProjectIds(contracts)
if request.UserBaseId > 0 && len(projectIds) > 0 {
cooperationProjectRepository, _ := repository.NewCooperationProjectRepository(ptr.transactionContext)
mapProject, err = domain.CooperationProjectsToMap(map[string]interface{}{"cooperationProjectIds": projectIds}, cooperationProjectRepository.Find)
if err != nil {
return nil, err
}
}
// 2.根据合约查询分红预算
orderGoodDao, _ := dao.NewDividendsOrderDao(ptr.transactionContext)
dividendsEstimateDao, _ := dao.NewDividendsEstimateDao(ptr.transactionContext)
... ... @@ -123,20 +135,12 @@ func (ptr *CooperationStatisticsService) SearchContractDividends(queryOptions ma
}
resultItem.DividendsOrderAmount, _ = orderGoodDao.CalculateGoodOrderAmount(map[string]interface{}{"orgId": request.OrgId, "cooperationContractNumbers": []string{item.CooperationContractNumber}})
resultItem.DividendsAmount, _ = dividendsEstimateDao.CountDividendsEstimateDividendsAmount(map[string]interface{}{"orgId": request.OrgId, "userBaseId": request.UserBaseId, "cooperationContractNumbers": []string{item.CooperationContractNumber}})
if v, ok := mapProject[item.CooperationProjectId]; ok {
resultItem.Project = v.CloneSimple()
}
results = append(results, resultItem)
numbers = append(numbers, item.CooperationContractNumber)
}
//mapCreditAccount, err := ptr.getContractsCreditAccount(numbers)
//if err != nil {
// return nil, err
//}
//for i := range results {
// if v, ok := mapCreditAccount[results[i].CooperationContractNumber]; ok {
// results[i].DividendsAmount = v.SettlementAmount
// results[i].DividendsOrderAmount = v.GoodAmountCount
// }
//}
return results, nil
}
... ... @@ -273,6 +277,8 @@ type searchContractDividendsResult struct {
DividendsOrderAmount float64 `json:"dividendsOrderAmount"`
// 创建时间
CreatedAt int64 `json:"createdAt"`
// 共创项目数据
Project interface{} `json:"project"`
}
/*1.2 分红合约详情*/
... ... @@ -306,7 +312,7 @@ func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[s
if err != nil {
return nil, err
}
res["cooperationContract"] = map[string]interface{}{
mapContract := map[string]interface{}{
"cooperationContractDescription": contract.CooperationContractDescription,
"cooperationContractId": contract.CooperationContractId,
"cooperationContractName": contract.CooperationContractName,
... ... @@ -314,21 +320,36 @@ func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[s
"createdAt": contract.CreatedAt.Unix() * 1000,
"status": contract.Status,
}
if request.UserBaseId > 0 {
// 1.1.合约第一条合同的附件
undertakerRepository, _ := repository.NewCooperationContractUndertakerRepository(ptr.transactionContext)
_, undertakers, err := undertakerRepository.Find(map[string]interface{}{"cooperationContractId": contract.CooperationContractId, "userBaseId": request.UserBaseId, "companyId": contract.Company.CompanyId, "orgId": contract.Org.OrgId, "offsetLimit": false})
if err != nil {
return nil, err
}
for i := range undertakers {
if len(undertakers[i].Undertaker.ContractAttachment) > 0 && len(undertakers[i].Undertaker.ContractAttachment[0].Url) > 0 {
mapContract["contractAttachment"] = undertakers[i].Undertaker.ContractAttachment[0]
}
}
}
res["cooperationContract"] = mapContract
// 2.合约分红列表
creditAccountRepository, _ := repository.NewDividendsEstimateRepository(ptr.transactionContext)
dividendsEstimateRepository, _ := repository.NewDividendsEstimateRepository(ptr.transactionContext)
queryOptions["cooperationContractNumber"] = contract.CooperationContractNumber
queryOptions["orgId"] = contract.Org.OrgId
queryOptions["isCanceled"] = false
_, creditAccounts, err := creditAccountRepository.Find(queryOptions)
_, dividendsEstimates, err := dividendsEstimateRepository.Find(queryOptions)
if err != nil {
return res, err
}
// 3.取订单商品列表
var orderGoodIds []int64
for i := range creditAccounts {
a := creditAccounts[i]
for i := range dividendsEstimates {
a := dividendsEstimates[i]
orderGoodIds = append(orderGoodIds, a.OrderGoodId)
}
var mapOrderGoods = make(map[int64]*domain.OrderGood)
... ... @@ -344,14 +365,14 @@ func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[s
}
var dividends = make([]interface{}, 0)
for i := range creditAccounts {
a := creditAccounts[i]
for i := range dividendsEstimates {
a := dividendsEstimates[i]
// 个人查看的时候只查看自己的分红明细
//if request.UserBaseId!=0 && a.DividendsUser.UserBaseId!=request.UserBaseId{
// continue
//}
item := map[string]interface{}{
"creditAccountId": a.DividendsEstimateId,
"dividendsEstimateId": a.DividendsEstimateId,
"orderGoodName": "",
"dividendsType": a.DividendsType,
"dividendsRatio": 0,
... ... @@ -364,6 +385,7 @@ func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[s
"dividendsAccountStatus": a.DividendsAccountStatus,
"dividendsEstimateTime": a.CreatedAt.Unix() * 1000,
"orderOrReturnedOrderNum": a.DividendsEstimateOrderNumber,
"creditAccountId": a.CreditAccountId,
}
if a.PaymentStatus == 2 {
item["dividendsAccountStatus"] = 3
... ...
... ... @@ -43,4 +43,6 @@ type CooperationContract struct {
DeletedAt time.Time `comment:"删除时间" pg:",soft_delete"`
// 更新时间
UpdatedAt time.Time `comment:"更新时间"`
// 共创项目编号
CooperationProjectId int64 `comment:"共创项目编号"`
}
... ...
... ... @@ -134,5 +134,6 @@ func TransformToCooperationContractDomainModelFromPgModels(
CreatedAt: cooperationContractModel.CreatedAt,
DeletedAt: cooperationContractModel.DeletedAt,
UpdatedAt: cooperationContractModel.UpdatedAt,
CooperationProjectId: cooperationContractModel.CooperationProjectId,
}, nil
}
... ...
... ... @@ -44,6 +44,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
"created_at",
"deleted_at",
"updated_at",
"cooperation_project_id",
}
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields)
... ... @@ -78,6 +79,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
&cooperationContract.CreatedAt,
&cooperationContract.DeletedAt,
&cooperationContract.UpdatedAt,
&cooperationContract.CooperationProjectId,
),
fmt.Sprintf("INSERT INTO cooperation_contracts (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
cooperationContract.CooperationContractId,
... ... @@ -98,6 +100,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
cooperationContract.CreatedAt,
nil,
cooperationContract.UpdatedAt,
cooperationContract.CooperationProjectId,
); err != nil {
return cooperationContract, err
}
... ... @@ -277,6 +280,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
&cooperationContract.CreatedAt,
&cooperationContract.DeletedAt,
&cooperationContract.UpdatedAt,
&cooperationContract.CooperationProjectId,
),
fmt.Sprintf("UPDATE cooperation_contracts SET %s WHERE cooperation_contract_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
cooperationContract.CooperationContractId,
... ... @@ -297,6 +301,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
cooperationContract.CreatedAt,
nil,
cooperationContract.UpdatedAt,
cooperationContract.CooperationProjectId,
cooperationContract.Identify(),
); err != nil {
return cooperationContract, err
... ...
... ... @@ -183,6 +183,9 @@ func (repository *CooperationContractUndertakerRepository) Find(queryOptions map
var cooperationContractUndertakerModels []*models.CooperationContractUndertaker
cooperationContractUndertakers := make([]*domain.CooperationContractUndertaker, 0)
query := sqlbuilder.BuildQuery(tx.Model(&cooperationContractUndertakerModels), queryOptions)
if cooperationContractId, ok := queryOptions["cooperationContractId"]; ok && cooperationContractId.(int64) != 0 {
query.Where("cooperation_contract_id = ? ", cooperationContractId)
}
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query.Where("company->>'companyId' = '?'", companyId)
}
... ...