作者 yangfu

合约详情修改

@@ -387,6 +387,7 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC @@ -387,6 +387,7 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
387 CreatedAt: time.Now(), 387 CreatedAt: time.Now(),
388 DeletedAt: time.Time{}, 388 DeletedAt: time.Time{},
389 UpdatedAt: time.Time{}, 389 UpdatedAt: time.Time{},
  390 + CooperationProjectId: cooperationProject.CooperationProjectId,
390 } 391 }
391 392
392 // 共创合约仓储初始化 393 // 共创合约仓储初始化
@@ -77,6 +77,8 @@ type CooperationContract struct { @@ -77,6 +77,8 @@ type CooperationContract struct {
77 DeletedAt time.Time `json:"deletedAt"` 77 DeletedAt time.Time `json:"deletedAt"`
78 // 更新时间 78 // 更新时间
79 UpdatedAt time.Time `json:"updatedAt"` 79 UpdatedAt time.Time `json:"updatedAt"`
  80 + // 共创项目编号
  81 + CooperationProjectId int64 `json:"cooperationProjectId"`
80 } 82 }
81 83
82 type CooperationContractRepository interface { 84 type CooperationContractRepository interface {
@@ -175,3 +177,20 @@ func (cooperationContract *CooperationContract) MoneyIncentivesRuleSliceEqualBCE @@ -175,3 +177,20 @@ func (cooperationContract *CooperationContract) MoneyIncentivesRuleSliceEqualBCE
175 } 177 }
176 return true 178 return true
177 } 179 }
  180 +
  181 +func CooperationContractsToProjectIds(contracts []*CooperationContract) []int64 {
  182 + var projectIds = make([]int64, 0)
  183 + for i := range contracts {
  184 + var exist = false
  185 + for j := range projectIds {
  186 + if contracts[i].CooperationProjectId == projectIds[j] {
  187 + exist = true
  188 + break
  189 + }
  190 + }
  191 + if !exist {
  192 + projectIds = append(projectIds, contracts[i].CooperationProjectId)
  193 + }
  194 + }
  195 + return projectIds
  196 +}
@@ -91,3 +91,28 @@ func (cooperationProject *CooperationProject) Update(data map[string]interface{} @@ -91,3 +91,28 @@ func (cooperationProject *CooperationProject) Update(data map[string]interface{}
91 cooperationProject.UpdatedAt = time.Now() 91 cooperationProject.UpdatedAt = time.Now()
92 return nil 92 return nil
93 } 93 }
  94 +
  95 +func CooperationProjectsToMap(queryOptions map[string]interface{}, find func(queryOptions map[string]interface{}) (int64, []*CooperationProject, error)) (map[int64]*CooperationProject, error) {
  96 + var result = make(map[int64]*CooperationProject)
  97 + _, projects, err := find(queryOptions)
  98 + if err != nil {
  99 + return nil, err
  100 + }
  101 + for i := range projects {
  102 + result[projects[i].CooperationProjectId] = projects[i]
  103 + }
  104 + return result, nil
  105 +}
  106 +
  107 +func (cooperationProject *CooperationProject) CloneSimple() interface{} {
  108 + var mapResult = map[string]interface{}{
  109 + "cooperationProjectId": cooperationProject.CooperationProjectId,
  110 + "cooperationProjectName": cooperationProject.CooperationProjectName,
  111 + "cooperationProjectDescription": cooperationProject.CooperationProjectDescription,
  112 + "updatedAt": cooperationProject.UpdatedAt.Unix() * 1000,
  113 + }
  114 + if cooperationProject.UpdatedAt.Unix() < 0 {
  115 + mapResult["updatedAt"] = cooperationProject.CreatedAt.Unix() * 1000
  116 + }
  117 + return mapResult
  118 +}
@@ -107,6 +107,18 @@ func (ptr *CooperationStatisticsService) SearchContractDividends(queryOptions ma @@ -107,6 +107,18 @@ func (ptr *CooperationStatisticsService) SearchContractDividends(queryOptions ma
107 return nil, err 107 return nil, err
108 } 108 }
109 109
  110 + // 1.1 个人返回合约对应的项目
  111 +
  112 + var mapProject = make(map[int64]*domain.CooperationProject)
  113 + var projectIds = domain.CooperationContractsToProjectIds(contracts)
  114 + if request.UserBaseId > 0 && len(projectIds) > 0 {
  115 + cooperationProjectRepository, _ := repository.NewCooperationProjectRepository(ptr.transactionContext)
  116 + mapProject, err = domain.CooperationProjectsToMap(map[string]interface{}{"cooperationProjectIds": projectIds}, cooperationProjectRepository.Find)
  117 + if err != nil {
  118 + return nil, err
  119 + }
  120 + }
  121 +
110 // 2.根据合约查询分红预算 122 // 2.根据合约查询分红预算
111 orderGoodDao, _ := dao.NewDividendsOrderDao(ptr.transactionContext) 123 orderGoodDao, _ := dao.NewDividendsOrderDao(ptr.transactionContext)
112 dividendsEstimateDao, _ := dao.NewDividendsEstimateDao(ptr.transactionContext) 124 dividendsEstimateDao, _ := dao.NewDividendsEstimateDao(ptr.transactionContext)
@@ -123,20 +135,12 @@ func (ptr *CooperationStatisticsService) SearchContractDividends(queryOptions ma @@ -123,20 +135,12 @@ func (ptr *CooperationStatisticsService) SearchContractDividends(queryOptions ma
123 } 135 }
124 resultItem.DividendsOrderAmount, _ = orderGoodDao.CalculateGoodOrderAmount(map[string]interface{}{"orgId": request.OrgId, "cooperationContractNumbers": []string{item.CooperationContractNumber}}) 136 resultItem.DividendsOrderAmount, _ = orderGoodDao.CalculateGoodOrderAmount(map[string]interface{}{"orgId": request.OrgId, "cooperationContractNumbers": []string{item.CooperationContractNumber}})
125 resultItem.DividendsAmount, _ = dividendsEstimateDao.CountDividendsEstimateDividendsAmount(map[string]interface{}{"orgId": request.OrgId, "userBaseId": request.UserBaseId, "cooperationContractNumbers": []string{item.CooperationContractNumber}}) 137 resultItem.DividendsAmount, _ = dividendsEstimateDao.CountDividendsEstimateDividendsAmount(map[string]interface{}{"orgId": request.OrgId, "userBaseId": request.UserBaseId, "cooperationContractNumbers": []string{item.CooperationContractNumber}})
126 - 138 + if v, ok := mapProject[item.CooperationProjectId]; ok {
  139 + resultItem.Project = v.CloneSimple()
  140 + }
127 results = append(results, resultItem) 141 results = append(results, resultItem)
128 numbers = append(numbers, item.CooperationContractNumber) 142 numbers = append(numbers, item.CooperationContractNumber)
129 } 143 }
130 - //mapCreditAccount, err := ptr.getContractsCreditAccount(numbers)  
131 - //if err != nil {  
132 - // return nil, err  
133 - //}  
134 - //for i := range results {  
135 - // if v, ok := mapCreditAccount[results[i].CooperationContractNumber]; ok {  
136 - // results[i].DividendsAmount = v.SettlementAmount  
137 - // results[i].DividendsOrderAmount = v.GoodAmountCount  
138 - // }  
139 - //}  
140 return results, nil 144 return results, nil
141 } 145 }
142 146
@@ -273,6 +277,8 @@ type searchContractDividendsResult struct { @@ -273,6 +277,8 @@ type searchContractDividendsResult struct {
273 DividendsOrderAmount float64 `json:"dividendsOrderAmount"` 277 DividendsOrderAmount float64 `json:"dividendsOrderAmount"`
274 // 创建时间 278 // 创建时间
275 CreatedAt int64 `json:"createdAt"` 279 CreatedAt int64 `json:"createdAt"`
  280 + // 共创项目数据
  281 + Project interface{} `json:"project"`
276 } 282 }
277 283
278 /*1.2 分红合约详情*/ 284 /*1.2 分红合约详情*/
@@ -306,7 +312,7 @@ func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[s @@ -306,7 +312,7 @@ func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[s
306 if err != nil { 312 if err != nil {
307 return nil, err 313 return nil, err
308 } 314 }
309 - res["cooperationContract"] = map[string]interface{}{ 315 + mapContract := map[string]interface{}{
310 "cooperationContractDescription": contract.CooperationContractDescription, 316 "cooperationContractDescription": contract.CooperationContractDescription,
311 "cooperationContractId": contract.CooperationContractId, 317 "cooperationContractId": contract.CooperationContractId,
312 "cooperationContractName": contract.CooperationContractName, 318 "cooperationContractName": contract.CooperationContractName,
@@ -314,21 +320,36 @@ func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[s @@ -314,21 +320,36 @@ func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[s
314 "createdAt": contract.CreatedAt.Unix() * 1000, 320 "createdAt": contract.CreatedAt.Unix() * 1000,
315 "status": contract.Status, 321 "status": contract.Status,
316 } 322 }
  323 + if request.UserBaseId > 0 {
  324 + // 1.1.合约第一条合同的附件
  325 + undertakerRepository, _ := repository.NewCooperationContractUndertakerRepository(ptr.transactionContext)
  326 + _, undertakers, err := undertakerRepository.Find(map[string]interface{}{"cooperationContractId": contract.CooperationContractId, "userBaseId": request.UserBaseId, "companyId": contract.Company.CompanyId, "orgId": contract.Org.OrgId, "offsetLimit": false})
  327 + if err != nil {
  328 + return nil, err
  329 + }
  330 + for i := range undertakers {
  331 + if len(undertakers[i].Undertaker.ContractAttachment) > 0 && len(undertakers[i].Undertaker.ContractAttachment[0].Url) > 0 {
  332 + mapContract["contractAttachment"] = undertakers[i].Undertaker.ContractAttachment[0]
  333 + }
  334 + }
  335 + }
  336 +
  337 + res["cooperationContract"] = mapContract
317 338
318 // 2.合约分红列表 339 // 2.合约分红列表
319 - creditAccountRepository, _ := repository.NewDividendsEstimateRepository(ptr.transactionContext) 340 + dividendsEstimateRepository, _ := repository.NewDividendsEstimateRepository(ptr.transactionContext)
320 queryOptions["cooperationContractNumber"] = contract.CooperationContractNumber 341 queryOptions["cooperationContractNumber"] = contract.CooperationContractNumber
321 queryOptions["orgId"] = contract.Org.OrgId 342 queryOptions["orgId"] = contract.Org.OrgId
322 queryOptions["isCanceled"] = false 343 queryOptions["isCanceled"] = false
323 - _, creditAccounts, err := creditAccountRepository.Find(queryOptions) 344 + _, dividendsEstimates, err := dividendsEstimateRepository.Find(queryOptions)
324 if err != nil { 345 if err != nil {
325 return res, err 346 return res, err
326 } 347 }
327 348
328 // 3.取订单商品列表 349 // 3.取订单商品列表
329 var orderGoodIds []int64 350 var orderGoodIds []int64
330 - for i := range creditAccounts {  
331 - a := creditAccounts[i] 351 + for i := range dividendsEstimates {
  352 + a := dividendsEstimates[i]
332 orderGoodIds = append(orderGoodIds, a.OrderGoodId) 353 orderGoodIds = append(orderGoodIds, a.OrderGoodId)
333 } 354 }
334 var mapOrderGoods = make(map[int64]*domain.OrderGood) 355 var mapOrderGoods = make(map[int64]*domain.OrderGood)
@@ -344,14 +365,14 @@ func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[s @@ -344,14 +365,14 @@ func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[s
344 } 365 }
345 366
346 var dividends = make([]interface{}, 0) 367 var dividends = make([]interface{}, 0)
347 - for i := range creditAccounts {  
348 - a := creditAccounts[i] 368 + for i := range dividendsEstimates {
  369 + a := dividendsEstimates[i]
349 // 个人查看的时候只查看自己的分红明细 370 // 个人查看的时候只查看自己的分红明细
350 //if request.UserBaseId!=0 && a.DividendsUser.UserBaseId!=request.UserBaseId{ 371 //if request.UserBaseId!=0 && a.DividendsUser.UserBaseId!=request.UserBaseId{
351 // continue 372 // continue
352 //} 373 //}
353 item := map[string]interface{}{ 374 item := map[string]interface{}{
354 - "creditAccountId": a.DividendsEstimateId, 375 + "dividendsEstimateId": a.DividendsEstimateId,
355 "orderGoodName": "", 376 "orderGoodName": "",
356 "dividendsType": a.DividendsType, 377 "dividendsType": a.DividendsType,
357 "dividendsRatio": 0, 378 "dividendsRatio": 0,
@@ -364,6 +385,7 @@ func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[s @@ -364,6 +385,7 @@ func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[s
364 "dividendsAccountStatus": a.DividendsAccountStatus, 385 "dividendsAccountStatus": a.DividendsAccountStatus,
365 "dividendsEstimateTime": a.CreatedAt.Unix() * 1000, 386 "dividendsEstimateTime": a.CreatedAt.Unix() * 1000,
366 "orderOrReturnedOrderNum": a.DividendsEstimateOrderNumber, 387 "orderOrReturnedOrderNum": a.DividendsEstimateOrderNumber,
  388 + "creditAccountId": a.CreditAccountId,
367 } 389 }
368 if a.PaymentStatus == 2 { 390 if a.PaymentStatus == 2 {
369 item["dividendsAccountStatus"] = 3 391 item["dividendsAccountStatus"] = 3
@@ -43,4 +43,6 @@ type CooperationContract struct { @@ -43,4 +43,6 @@ type CooperationContract struct {
43 DeletedAt time.Time `comment:"删除时间" pg:",soft_delete"` 43 DeletedAt time.Time `comment:"删除时间" pg:",soft_delete"`
44 // 更新时间 44 // 更新时间
45 UpdatedAt time.Time `comment:"更新时间"` 45 UpdatedAt time.Time `comment:"更新时间"`
  46 + // 共创项目编号
  47 + CooperationProjectId int64 `comment:"共创项目编号"`
46 } 48 }
@@ -134,5 +134,6 @@ func TransformToCooperationContractDomainModelFromPgModels( @@ -134,5 +134,6 @@ func TransformToCooperationContractDomainModelFromPgModels(
134 CreatedAt: cooperationContractModel.CreatedAt, 134 CreatedAt: cooperationContractModel.CreatedAt,
135 DeletedAt: cooperationContractModel.DeletedAt, 135 DeletedAt: cooperationContractModel.DeletedAt,
136 UpdatedAt: cooperationContractModel.UpdatedAt, 136 UpdatedAt: cooperationContractModel.UpdatedAt,
  137 + CooperationProjectId: cooperationContractModel.CooperationProjectId,
137 }, nil 138 }, nil
138 } 139 }
@@ -44,6 +44,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -44,6 +44,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
44 "created_at", 44 "created_at",
45 "deleted_at", 45 "deleted_at",
46 "updated_at", 46 "updated_at",
  47 + "cooperation_project_id",
47 } 48 }
48 insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) 49 insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
49 insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields) 50 insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields)
@@ -78,6 +79,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -78,6 +79,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
78 &cooperationContract.CreatedAt, 79 &cooperationContract.CreatedAt,
79 &cooperationContract.DeletedAt, 80 &cooperationContract.DeletedAt,
80 &cooperationContract.UpdatedAt, 81 &cooperationContract.UpdatedAt,
  82 + &cooperationContract.CooperationProjectId,
81 ), 83 ),
82 fmt.Sprintf("INSERT INTO cooperation_contracts (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), 84 fmt.Sprintf("INSERT INTO cooperation_contracts (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
83 cooperationContract.CooperationContractId, 85 cooperationContract.CooperationContractId,
@@ -98,6 +100,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -98,6 +100,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
98 cooperationContract.CreatedAt, 100 cooperationContract.CreatedAt,
99 nil, 101 nil,
100 cooperationContract.UpdatedAt, 102 cooperationContract.UpdatedAt,
  103 + cooperationContract.CooperationProjectId,
101 ); err != nil { 104 ); err != nil {
102 return cooperationContract, err 105 return cooperationContract, err
103 } 106 }
@@ -277,6 +280,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -277,6 +280,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
277 &cooperationContract.CreatedAt, 280 &cooperationContract.CreatedAt,
278 &cooperationContract.DeletedAt, 281 &cooperationContract.DeletedAt,
279 &cooperationContract.UpdatedAt, 282 &cooperationContract.UpdatedAt,
  283 + &cooperationContract.CooperationProjectId,
280 ), 284 ),
281 fmt.Sprintf("UPDATE cooperation_contracts SET %s WHERE cooperation_contract_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), 285 fmt.Sprintf("UPDATE cooperation_contracts SET %s WHERE cooperation_contract_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
282 cooperationContract.CooperationContractId, 286 cooperationContract.CooperationContractId,
@@ -297,6 +301,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -297,6 +301,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
297 cooperationContract.CreatedAt, 301 cooperationContract.CreatedAt,
298 nil, 302 nil,
299 cooperationContract.UpdatedAt, 303 cooperationContract.UpdatedAt,
  304 + cooperationContract.CooperationProjectId,
300 cooperationContract.Identify(), 305 cooperationContract.Identify(),
301 ); err != nil { 306 ); err != nil {
302 return cooperationContract, err 307 return cooperationContract, err
@@ -183,6 +183,9 @@ func (repository *CooperationContractUndertakerRepository) Find(queryOptions map @@ -183,6 +183,9 @@ func (repository *CooperationContractUndertakerRepository) Find(queryOptions map
183 var cooperationContractUndertakerModels []*models.CooperationContractUndertaker 183 var cooperationContractUndertakerModels []*models.CooperationContractUndertaker
184 cooperationContractUndertakers := make([]*domain.CooperationContractUndertaker, 0) 184 cooperationContractUndertakers := make([]*domain.CooperationContractUndertaker, 0)
185 query := sqlbuilder.BuildQuery(tx.Model(&cooperationContractUndertakerModels), queryOptions) 185 query := sqlbuilder.BuildQuery(tx.Model(&cooperationContractUndertakerModels), queryOptions)
  186 + if cooperationContractId, ok := queryOptions["cooperationContractId"]; ok && cooperationContractId.(int64) != 0 {
  187 + query.Where("cooperation_contract_id = ? ", cooperationContractId)
  188 + }
186 if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 { 189 if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
187 query.Where("company->>'companyId' = '?'", companyId) 190 query.Where("company->>'companyId' = '?'", companyId)
188 } 191 }