作者 陈志颖

fix:财富值贡献值排行榜调整

@@ -302,12 +302,36 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang @@ -302,12 +302,36 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang
302 exchangeCashActivityRepository = value 302 exchangeCashActivityRepository = value
303 } 303 }
304 304
  305 + // 兑换现金活动仓储初始化
  306 + var exchangeActivityRepository domain.ExchangeActivityRepository
  307 + if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
  308 + "transactionContext": transactionContext,
  309 + }); err != nil {
  310 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  311 + } else {
  312 + exchangeActivityRepository = value
  313 + }
  314 +
305 // 时间格式化 315 // 时间格式化
306 - dd, _ := time.ParseDuration("24h")  
307 - var deadline = createExchangeCashActivityCommand.Deadline.Add(dd) 316 + //dd, _ := time.ParseDuration("24h")
  317 + //var deadline = createExchangeCashActivityCommand.Deadline.Add(dd)
  318 + var deadline = createExchangeCashActivityCommand.Deadline
308 var t1 = time.Now() 319 var t1 = time.Now()
309 var t2 = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 23, 59, 59, 0, time.Local) 320 var t2 = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 23, 59, 59, 0, time.Local)
310 321
  322 + // 获取该公司所有兑换现金活动
  323 + if _, activities, err := exchangeActivityRepository.FindAll(map[string]interface{}{
  324 + "companyId": createExchangeCashActivityCommand.CompanyId,
  325 + }); err != nil {
  326 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  327 + } else {
  328 + for _, activity := range activities {
  329 + if t2.Equal(activity.Deadline) {
  330 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "兑换活动截止时间不能重合")
  331 + }
  332 + }
  333 + }
  334 +
311 // 创建兑换活动命令 335 // 创建兑换活动命令
312 newActivity := &domain.ExchangeCashActivity{ 336 newActivity := &domain.ExchangeCashActivity{
313 ExchangeActivityName: createExchangeCashActivityCommand.ExchangeActivityName, 337 ExchangeActivityName: createExchangeCashActivityCommand.ExchangeActivityName,
@@ -332,6 +356,8 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang @@ -332,6 +356,8 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang
332 if err := transactionContext.CommitTransaction(); err != nil { 356 if err := transactionContext.CommitTransaction(); err != nil {
333 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 357 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
334 } 358 }
  359 + activity.ExchangedCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", activity.ExchangedCash), 64)
  360 + activity.ExchangedSuMoney, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", activity.ExchangedSuMoney), 64)
335 return activity, nil 361 return activity, nil
336 } 362 }
337 } 363 }
@@ -454,12 +480,14 @@ func (cashPoolService *CashPoolService) SearchExchangeCashActivity(activityComma @@ -454,12 +480,14 @@ func (cashPoolService *CashPoolService) SearchExchangeCashActivity(activityComma
454 480
455 var activitiesFormat []interface{} 481 var activitiesFormat []interface{}
456 for _, activity := range activities { 482 for _, activity := range activities {
  483 + cash, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", activity.ExchangedCash), 64)
  484 + suMoney, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", activity.ExchangedSuMoney), 64)
457 activityFormat := map[string]interface{} { 485 activityFormat := map[string]interface{} {
458 "activityId": activity.ActivityId, 486 "activityId": activity.ActivityId,
459 "exchangeActivityName": activity.ExchangeActivityName, 487 "exchangeActivityName": activity.ExchangeActivityName,
460 "companyId": activity.CompanyId, 488 "companyId": activity.CompanyId,
461 - "exchangedCash": activity.ExchangedCash,  
462 - "exchangedSuMoney": activity.ExchangedSuMoney, 489 + "exchangedCash": cash,
  490 + "exchangedSuMoney": suMoney,
463 "deadline": activity.Deadline.UTC().Format("2006-01-02"), 491 "deadline": activity.Deadline.UTC().Format("2006-01-02"),
464 "countDown": activity.CountDown, 492 "countDown": activity.CountDown,
465 "rate": activity.Rate, 493 "rate": activity.Rate,
@@ -682,6 +710,8 @@ func (cashPoolService *CashPoolService) GetExchangeCashActivity(getExchangeCashA @@ -682,6 +710,8 @@ func (cashPoolService *CashPoolService) GetExchangeCashActivity(getExchangeCashA
682 if err := transactionContext.CommitTransaction(); err != nil { 710 if err := transactionContext.CommitTransaction(); err != nil {
683 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 711 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
684 } 712 }
  713 + activityUpdated.ExchangedSuMoney, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", activityUpdated.ExchangedSuMoney), 64)
  714 + activityUpdated.ExchangedCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", activityUpdated.ExchangedCash), 64)
685 return activityUpdated, nil 715 return activityUpdated, nil
686 } 716 }
687 } 717 }
@@ -872,6 +902,8 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang @@ -872,6 +902,8 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
872 if err := transactionContext.CommitTransaction(); err != nil { 902 if err := transactionContext.CommitTransaction(); err != nil {
873 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 903 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
874 } 904 }
  905 + activityUpdated.ExchangedSuMoney, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", activityUpdated.ExchangedSuMoney), 64)
  906 + activityUpdated.ExchangedCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", activityUpdated.ExchangedCash), 64)
875 return activityUpdated, nil 907 return activityUpdated, nil
876 } 908 }
877 } 909 }
@@ -1831,7 +1863,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC @@ -1831,7 +1863,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashPerson(createExchangeC
1831 1863
1832 // 判断兑换活动的现金是否超过现金池未兑换现金 1864 // 判断兑换活动的现金是否超过现金池未兑换现金
1833 if activityUpdated.ExchangedSuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolsFound[0].UnExchangeCash { 1865 if activityUpdated.ExchangedSuMoney * updateExchangeCashActivityCommand.ExchangeRate > cashPoolsFound[0].UnExchangeCash {
1834 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过现金池未兑换现金") 1866 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已超过投入现金池未兑换现金")
1835 } 1867 }
1836 1868
1837 // 获取平台素币兑换情况 1869 // 获取平台素币兑换情况
1 package domain 1 package domain
2 2
3 import ( 3 import (
4 - "fmt"  
5 - "strconv"  
6 "time" 4 "time"
7 ) 5 )
8 6
@@ -45,13 +43,13 @@ func (exchangeCashActivity *ExchangeCashActivity) Update(data map[string]interfa @@ -45,13 +43,13 @@ func (exchangeCashActivity *ExchangeCashActivity) Update(data map[string]interfa
45 exchangeCashActivity.CountDown = countDown.(int64) 43 exchangeCashActivity.CountDown = countDown.(int64)
46 } 44 }
47 if exchangedSuMoney, ok := data["exchangedSuMoney"]; ok && exchangedSuMoney != 0 { 45 if exchangedSuMoney, ok := data["exchangedSuMoney"]; ok && exchangedSuMoney != 0 {
48 - exchangeCashActivity.ExchangedSuMoney, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", exchangedSuMoney.(float64)), 64) 46 + exchangeCashActivity.ExchangedSuMoney = exchangedSuMoney.(float64)
49 } 47 }
50 if exchangedCash, ok := data["exchangedCash"]; ok && exchangedCash != 0 { 48 if exchangedCash, ok := data["exchangedCash"]; ok && exchangedCash != 0 {
51 - exchangeCashActivity.ExchangedCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", exchangedCash.(float64)), 64) 49 + exchangeCashActivity.ExchangedCash = exchangedCash.(float64)
52 } 50 }
53 if exchangeRate, ok := data["exchangeRate"]; ok && exchangeRate != 0 { 51 if exchangeRate, ok := data["exchangeRate"]; ok && exchangeRate != 0 {
54 - exchangeCashActivity.Rate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", exchangeRate.(float64)), 64) 52 + exchangeCashActivity.Rate = exchangeRate.(float64)
55 } 53 }
56 return nil 54 return nil
57 } 55 }
@@ -385,7 +385,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter @@ -385,7 +385,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
385 if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) { 385 if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
386 queryContributionsDecrease = queryContributionsDecrease.Where("e.company_id = ?", companyId) 386 queryContributionsDecrease = queryContributionsDecrease.Where("e.company_id = ?", companyId)
387 } 387 }
388 - queryContributionsDecrease = queryContributionsDecrease.Where(`e.status = ?`, 1) 388 + //queryContributionsDecrease = queryContributionsDecrease.Where(`e.status = ?`, 1)
389 queryContributionsDecrease = queryContributionsDecrease.Where(`su_money_transaction_record.record_type = ?`, 4) 389 queryContributionsDecrease = queryContributionsDecrease.Where(`su_money_transaction_record.record_type = ?`, 4)
390 if startTime, ok := queryOptions["startTime"]; ok { 390 if startTime, ok := queryOptions["startTime"]; ok {
391 queryContributionsDecrease = queryContributionsDecrease.Where(`su_money_transaction_record.create_time > ?`, startTime) 391 queryContributionsDecrease = queryContributionsDecrease.Where(`su_money_transaction_record.create_time > ?`, startTime)
@@ -406,6 +406,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter @@ -406,6 +406,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
406 queryContributions = queryContributions.ColumnExpr(`(sum(su_money_transaction_records.su_money) - t.employee_contributions_decrease) AS employees_contributions`) 406 queryContributions = queryContributions.ColumnExpr(`(sum(su_money_transaction_records.su_money) - t.employee_contributions_decrease) AS employees_contributions`)
407 queryContributions = queryContributions.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(su_money_transaction_records.su_money) - t.employee_contributions_decrease DESC) AS ranking") 407 queryContributions = queryContributions.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(su_money_transaction_records.su_money) - t.employee_contributions_decrease DESC) AS ranking")
408 queryContributions = queryContributions.Where(`e.status = ?`, 1) 408 queryContributions = queryContributions.Where(`e.status = ?`, 1)
  409 + queryContributions = queryContributions.Where("e.uid = t.uid::bigint")
409 queryContributions = queryContributions.Where(`su_money_transaction_records.record_type IN (?)`, pg.In([]int{2, 3})) 410 queryContributions = queryContributions.Where(`su_money_transaction_records.record_type IN (?)`, pg.In([]int{2, 3}))
410 if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) { 411 if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
411 queryContributions = queryContributions.Where("e.company_id = ?", companyId) 412 queryContributions = queryContributions.Where("e.company_id = ?", companyId)