|
@@ -64,8 +64,6 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
@@ -64,8 +64,6 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
64
|
&cooperationContract.CooperationContractDescription,
|
64
|
&cooperationContract.CooperationContractDescription,
|
65
|
&cooperationContract.CooperationContractName,
|
65
|
&cooperationContract.CooperationContractName,
|
66
|
&cooperationContract.CooperationContractNumber,
|
66
|
&cooperationContract.CooperationContractNumber,
|
67
|
- &cooperationContract.CooperationContractReferrer,
|
|
|
68
|
- &cooperationContract.CooperationContractSalesman,
|
|
|
69
|
pg.Array(&cooperationContract.CooperationContractUndertakerTypes),
|
67
|
pg.Array(&cooperationContract.CooperationContractUndertakerTypes),
|
70
|
&cooperationContract.CooperationContractSponsor,
|
68
|
&cooperationContract.CooperationContractSponsor,
|
71
|
&cooperationContract.CooperationMode.CooperationModeNumber,
|
69
|
&cooperationContract.CooperationMode.CooperationModeNumber,
|
|
@@ -83,8 +81,6 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
@@ -83,8 +81,6 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
83
|
cooperationContract.CooperationContractDescription,
|
81
|
cooperationContract.CooperationContractDescription,
|
84
|
cooperationContract.CooperationContractName,
|
82
|
cooperationContract.CooperationContractName,
|
85
|
cooperationContract.CooperationContractNumber,
|
83
|
cooperationContract.CooperationContractNumber,
|
86
|
- cooperationContract.CooperationContractReferrer,
|
|
|
87
|
- cooperationContract.CooperationContractSalesman,
|
|
|
88
|
pg.Array(cooperationContract.CooperationContractUndertakerTypes),
|
84
|
pg.Array(cooperationContract.CooperationContractUndertakerTypes),
|
89
|
cooperationContract.CooperationContractSponsor,
|
85
|
cooperationContract.CooperationContractSponsor,
|
90
|
cooperationContract.CooperationMode.CooperationModeNumber,
|
86
|
cooperationContract.CooperationMode.CooperationModeNumber,
|
|
@@ -200,8 +196,6 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
@@ -200,8 +196,6 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
200
|
&cooperationContract.CooperationContractDescription,
|
196
|
&cooperationContract.CooperationContractDescription,
|
201
|
&cooperationContract.CooperationContractName,
|
197
|
&cooperationContract.CooperationContractName,
|
202
|
&cooperationContract.CooperationContractNumber,
|
198
|
&cooperationContract.CooperationContractNumber,
|
203
|
- &cooperationContract.CooperationContractReferrer,
|
|
|
204
|
- &cooperationContract.CooperationContractSalesman,
|
|
|
205
|
pg.Array(&cooperationContract.CooperationContractUndertakerTypes),
|
199
|
pg.Array(&cooperationContract.CooperationContractUndertakerTypes),
|
206
|
&cooperationContract.CooperationContractSponsor,
|
200
|
&cooperationContract.CooperationContractSponsor,
|
207
|
&cooperationContract.CooperationMode.CooperationModeNumber,
|
201
|
&cooperationContract.CooperationMode.CooperationModeNumber,
|
|
@@ -219,8 +213,6 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
@@ -219,8 +213,6 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
219
|
cooperationContract.CooperationContractDescription,
|
213
|
cooperationContract.CooperationContractDescription,
|
220
|
cooperationContract.CooperationContractName,
|
214
|
cooperationContract.CooperationContractName,
|
221
|
cooperationContract.CooperationContractNumber,
|
215
|
cooperationContract.CooperationContractNumber,
|
222
|
- cooperationContract.CooperationContractReferrer,
|
|
|
223
|
- cooperationContract.CooperationContractSalesman,
|
|
|
224
|
pg.Array(cooperationContract.CooperationContractUndertakerTypes),
|
216
|
pg.Array(cooperationContract.CooperationContractUndertakerTypes),
|
225
|
cooperationContract.CooperationContractSponsor,
|
217
|
cooperationContract.CooperationContractSponsor,
|
226
|
cooperationContract.CooperationMode.CooperationModeNumber,
|
218
|
cooperationContract.CooperationMode.CooperationModeNumber,
|
|
@@ -237,8 +229,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
@@ -237,8 +229,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
237
|
return cooperationContract, err
|
229
|
return cooperationContract, err
|
238
|
}
|
230
|
}
|
239
|
|
231
|
|
240
|
- // 更新相关人
|
|
|
241
|
-
|
232
|
+ /******************************* 更新相关人 ****************************/
|
242
|
// 查找相关人列表
|
233
|
// 查找相关人列表
|
243
|
var cooperationContractRelevantModelsFetched []*models.CooperationContractRelevant
|
234
|
var cooperationContractRelevantModelsFetched []*models.CooperationContractRelevant
|
244
|
cooperationContractRelevantQuery := tx.Model(&cooperationContractRelevantModelsFetched)
|
235
|
cooperationContractRelevantQuery := tx.Model(&cooperationContractRelevantModelsFetched)
|
|
@@ -324,16 +315,93 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
@@ -324,16 +315,93 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
324
|
return nil, err
|
315
|
return nil, err
|
325
|
}
|
316
|
}
|
326
|
|
317
|
|
327
|
- //TODO 更新承接人
|
|
|
328
|
-
|
318
|
+ /************************* 更新承接人 ****************************/
|
329
|
// 获取承接人列表
|
319
|
// 获取承接人列表
|
330
|
- var cooperationContractUndertakersFetched []*models.CooperationContractUndertaker
|
|
|
331
|
- cooperationContractUndertakerQuery := tx.Model(&cooperationContractUndertakersFetched)
|
320
|
+ var cooperationContractUndertakersModelsFetched []*models.CooperationContractUndertaker
|
|
|
321
|
+ cooperationContractUndertakerQuery := tx.Model(&cooperationContractUndertakersModelsFetched)
|
332
|
if err := cooperationContractUndertakerQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
|
322
|
if err := cooperationContractUndertakerQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
|
333
|
return nil, err
|
323
|
return nil, err
|
334
|
}
|
324
|
}
|
335
|
|
325
|
|
336
|
- //TODO 更新分红激励规则
|
326
|
+ // 提取承接人id
|
|
|
327
|
+ var cooperationContractUndertakersIdsFetched []int64
|
|
|
328
|
+ for _, cooperationContractUndertaker := range cooperationContractUndertakersModelsFetched {
|
|
|
329
|
+ cooperationContractUndertakersIdsFetched = append(cooperationContractUndertakersIdsFetched, cooperationContractUndertaker.CooperationContractUndertakerId)
|
|
|
330
|
+ }
|
|
|
331
|
+
|
|
|
332
|
+ // 待更新相关人
|
|
|
333
|
+ var cooperationContractUndertakersToUpdate []*domain.Undertaker
|
|
|
334
|
+
|
|
|
335
|
+ // 待添加相关人
|
|
|
336
|
+ var cooperationContractUndertakersToAdd []*domain.Undertaker
|
|
|
337
|
+ for _, undertaker := range cooperationContract.Undertakers {
|
|
|
338
|
+ if undertaker.UndertakerId != 0 {
|
|
|
339
|
+ cooperationContractUndertakersToUpdate = append(cooperationContractUndertakersToUpdate, undertaker)
|
|
|
340
|
+ } else {
|
|
|
341
|
+ cooperationContractUndertakersToAdd = append(cooperationContractUndertakersToAdd, undertaker)
|
|
|
342
|
+ }
|
|
|
343
|
+ }
|
|
|
344
|
+
|
|
|
345
|
+ // 将待添加的相关人领域模型转换为数据模型
|
|
|
346
|
+ var cooperationContractUndertakersToAddModels []*models.CooperationContractUndertaker
|
|
|
347
|
+ for _, undertakerDomain := range cooperationContractUndertakersToAdd {
|
|
|
348
|
+ cooperationContractUndertakersToAddModels = append(cooperationContractUndertakersToAddModels, &models.CooperationContractUndertaker{
|
|
|
349
|
+ CooperationContractNumber: undertakerDomain.CooperationContractNumber,
|
|
|
350
|
+ UserId: undertakerDomain.UserId,
|
|
|
351
|
+ UserBaseId: undertakerDomain.UserBaseId,
|
|
|
352
|
+ Org: undertakerDomain.Org,
|
|
|
353
|
+ Orgs: undertakerDomain.Orgs,
|
|
|
354
|
+ Department: undertakerDomain.Department,
|
|
|
355
|
+ Role: undertakerDomain.Role,
|
|
|
356
|
+ UserInfo: undertakerDomain.UserInfo,
|
|
|
357
|
+ UserType: undertakerDomain.UserType,
|
|
|
358
|
+ Status: undertakerDomain.Status,
|
|
|
359
|
+ Company: undertakerDomain.Company,
|
|
|
360
|
+ UpdatedAt: time.Time{},
|
|
|
361
|
+ DeletedAt: time.Time{},
|
|
|
362
|
+ CreatedAt: time.Now(),
|
|
|
363
|
+ })
|
|
|
364
|
+ }
|
|
|
365
|
+ // 添加承接人
|
|
|
366
|
+ if _, err := tx.Model(&cooperationContractUndertakersToAddModels).Insert(); err != nil {
|
|
|
367
|
+ return nil, err
|
|
|
368
|
+ }
|
|
|
369
|
+
|
|
|
370
|
+ // 待更新或者删除的ids
|
|
|
371
|
+ var cooperationContractUndertakersToUpdateOrDeleteIds []int64
|
|
|
372
|
+ for _, cooperationContractUndertakerToUpdate := range cooperationContractUndertakersToUpdate {
|
|
|
373
|
+ cooperationContractUndertakersToUpdateOrDeleteIds = append(cooperationContractUndertakersToUpdateOrDeleteIds, cooperationContractUndertakerToUpdate.UndertakerId)
|
|
|
374
|
+ }
|
|
|
375
|
+
|
|
|
376
|
+ // 待更新的承接人id
|
|
|
377
|
+ undertakerIdsToUpdate := utils.Intersect(cooperationContractUndertakersIdsFetched, cooperationContractUndertakersToUpdateOrDeleteIds)
|
|
|
378
|
+ var undertakerModelsToUpdate []*models.CooperationContractUndertaker
|
|
|
379
|
+ for _, id := range undertakerIdsToUpdate {
|
|
|
380
|
+ for _, undertakerModel := range cooperationContractUndertakersModelsFetched {
|
|
|
381
|
+ if undertakerModel.CooperationContractUndertakerId == id {
|
|
|
382
|
+ undertakerModelsToUpdate = append(undertakerModelsToUpdate, undertakerModel)
|
|
|
383
|
+ }
|
|
|
384
|
+ }
|
|
|
385
|
+ }
|
|
|
386
|
+ if _, err := tx.Model(&undertakerModelsToUpdate).WherePK().Update(); err != nil {
|
|
|
387
|
+ return nil, err
|
|
|
388
|
+ }
|
|
|
389
|
+
|
|
|
390
|
+ // 待删除的相关人id
|
|
|
391
|
+ undertakerIdsToDelete := utils.Difference(cooperationContractUndertakersIdsFetched, cooperationContractUndertakersToUpdateOrDeleteIds)
|
|
|
392
|
+ var undertakerModelsToDelete []*models.CooperationContractUndertaker
|
|
|
393
|
+ for _, id := range undertakerIdsToDelete {
|
|
|
394
|
+ for _, undertakerModel := range cooperationContractUndertakersModelsFetched {
|
|
|
395
|
+ if undertakerModel.CooperationContractUndertakerId == id {
|
|
|
396
|
+ undertakerModelsToDelete = append(undertakerModelsToDelete, undertakerModel)
|
|
|
397
|
+ }
|
|
|
398
|
+ }
|
|
|
399
|
+ }
|
|
|
400
|
+ if _, err := tx.Model(&relevantModelsToDelete).WherePK().Delete(); err != nil {
|
|
|
401
|
+ return nil, err
|
|
|
402
|
+ }
|
|
|
403
|
+
|
|
|
404
|
+ //TODO /************************ 更新分红激励规则 **************************/
|
337
|
|
405
|
|
338
|
// 获取分红激励规则列表
|
406
|
// 获取分红激励规则列表
|
339
|
var dividendsIncentivesRulesFetched []*models.DividendsIncentivesRule
|
407
|
var dividendsIncentivesRulesFetched []*models.DividendsIncentivesRule
|
|
@@ -342,7 +410,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
|
@@ -342,7 +410,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai |
342
|
return nil, err
|
410
|
return nil, err
|
343
|
}
|
411
|
}
|
344
|
|
412
|
|
345
|
- //TODO 更新金额激励规则
|
413
|
+ //TODO /********************** 更新金额激励规则 **************************/
|
346
|
|
414
|
|
347
|
// 获取金额激励规则列表
|
415
|
// 获取金额激励规则列表
|
348
|
var moneyIncentivesRulesFetched []*models.MoneyIncentivesRule
|
416
|
var moneyIncentivesRulesFetched []*models.MoneyIncentivesRule
|