recompute.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package service
  2. import (
  3. "context"
  4. "go-common/app/job/main/growup/model"
  5. )
  6. // AvIncomes av_income
  7. func (s *Service) AvIncomes(c context.Context, mid int64, date string) (result map[int64]*model.Patch, err error) {
  8. avs, err := s.dao.GetAvs(c, date, mid)
  9. if err != nil {
  10. return
  11. }
  12. var avIds []int64
  13. for avID := range avs {
  14. avIds = append(avIds, avID)
  15. }
  16. charges, err := s.dao.GetAvCharges(c, avIds, date)
  17. if err != nil {
  18. return
  19. }
  20. result = avIncomes(charges, avs)
  21. return
  22. }
  23. // result key: av_id, value: income
  24. func avIncomes(avCharges map[int64]int64, avs map[int64]*model.Av) (result map[int64]*model.Patch) {
  25. var totalCharge int64
  26. for _, charge := range avCharges {
  27. totalCharge += charge
  28. }
  29. tax := int64(Round(Tax(Div(float64(totalCharge), 100))*100, 0))
  30. netIncome := totalCharge - tax
  31. percent := Div(float64(netIncome), float64(totalCharge))
  32. result = make(map[int64]*model.Patch)
  33. for avID, charge := range avCharges {
  34. avIncome := int64(float64(charge) * percent)
  35. avTax := int64(Round(Mul(float64(tax), Div(float64(avIncome), float64(netIncome))), 0))
  36. result[avID] = &model.Patch{
  37. Tax: avTax,
  38. Income: avIncome,
  39. OldTax: avs[avID].TaxMoney,
  40. OldIncome: avs[avID].Income,
  41. MID: avs[avID].MID,
  42. TagID: avs[avID].TagID,
  43. }
  44. }
  45. return
  46. }