...
|
...
|
@@ -9,6 +9,7 @@ import ( |
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/repository"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
|
|
|
"strconv"
|
|
|
"time"
|
|
|
)
|
...
|
...
|
@@ -103,21 +104,16 @@ func (ptr *CooperationStatisticsService) SearchContractDividends(queryOptions ma |
|
|
results = append(results, resultItem)
|
|
|
numbers = append(numbers, item.CooperationContractNumber)
|
|
|
}
|
|
|
mapEstimate, err := ptr.getContractsDividendsEstimate(numbers)
|
|
|
mapCreditAccount, err := ptr.getContractsCreditAccount(numbers)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
for i := range results {
|
|
|
if v, ok := mapEstimate[results[i].CooperationContractNumber]; ok {
|
|
|
results[i].DividendsAmount = v.DividendsAmount
|
|
|
if v, ok := mapCreditAccount[results[i].CooperationContractNumber]; ok {
|
|
|
results[i].DividendsAmount = v.SettlementAmount
|
|
|
results[i].DividendsOrderAmount = v.GoodAmountCount
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// TODO: 3.根据合约查询订单金额
|
|
|
//for i:=range results{
|
|
|
// queryOptions["cooperationContractNumber"] =results[i].CooperationContractNumber
|
|
|
// results[i].DividendsOrderAmount = ptr.CalculateOrderAmount(queryOptions)
|
|
|
//}
|
|
|
return results, nil
|
|
|
}
|
|
|
|
...
|
...
|
@@ -171,6 +167,33 @@ group by cooperation_contract_number |
|
|
return resMap, nil
|
|
|
}
|
|
|
|
|
|
// getContractsDividendsEstimate 合约分红预算
|
|
|
func (ptr *CooperationStatisticsService) getContractsCreditAccount(numbers []string) (map[string]*domain.CreditAccount, error) {
|
|
|
var creditAccounts []*domain.CreditAccount
|
|
|
var resMap = make(map[string]*domain.CreditAccount)
|
|
|
if len(numbers) == 0 {
|
|
|
return resMap, nil
|
|
|
}
|
|
|
var creditAccount = new(domain.CreditAccount)
|
|
|
|
|
|
query := ptr.transactionContext.PgDd.Model(creditAccount)
|
|
|
query.Column("cooperation_contract_number")
|
|
|
query.ColumnExpr("sum(good_amount_count) good_amount_count")
|
|
|
query.ColumnExpr("sum(settlement_amount) settlement_amount")
|
|
|
query.Where("cooperation_contract_number in (?)", pg.In(numbers))
|
|
|
query.Where("deleted_at is null")
|
|
|
query.Group("cooperation_contract_number")
|
|
|
err := query.Select(&creditAccounts)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
for i := range creditAccounts {
|
|
|
resMap[creditAccounts[i].CooperationContractNumber] = creditAccounts[i]
|
|
|
}
|
|
|
return resMap, nil
|
|
|
}
|
|
|
|
|
|
type searchContractDividendsResult struct {
|
|
|
// 共创合约ID
|
|
|
CooperationContractId int64 `json:"cooperationContractId,string"`
|
...
|
...
|
@@ -220,17 +243,40 @@ func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[s |
|
|
if err != nil {
|
|
|
return res, err
|
|
|
}
|
|
|
|
|
|
// 3.取订单商品列表
|
|
|
var orderGoodIds []int64
|
|
|
for i := range creditAccounts {
|
|
|
a := creditAccounts[i]
|
|
|
for j := range a.AccountDetail {
|
|
|
if a.AccountDetail[j].OrderGoodId > 0 {
|
|
|
orderGoodIds = append(orderGoodIds, a.AccountDetail[j].OrderGoodId)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
orderGoodRepository, _ := repository.NewOrderGoodRepository(ptr.transactionContext)
|
|
|
_, orderGoods, err := orderGoodRepository.Find(map[string]interface{}{"orderGoodIds": orderGoodIds})
|
|
|
if err != nil {
|
|
|
return res, err
|
|
|
}
|
|
|
var mapOrderGoods = make(map[int64]*domain.OrderGood)
|
|
|
for i := range orderGoods {
|
|
|
mapOrderGoods[orderGoods[i].OrderGoodId] = orderGoods[i]
|
|
|
}
|
|
|
|
|
|
var dividends = make([]interface{}, 0)
|
|
|
for i := range creditAccounts {
|
|
|
a := creditAccounts[i]
|
|
|
for j := range a.AccountDetail {
|
|
|
participateType, _ := strconv.Atoi(a.ParticipateType)
|
|
|
detail := a.AccountDetail[j]
|
|
|
item := map[string]interface{}{
|
|
|
"creditAccountId": a.CreditAccountId,
|
|
|
"orderGoodName": "",
|
|
|
"dividendsType": 0,
|
|
|
"dividendsRatio": 0,
|
|
|
"dividendsAmount": a.AccountDetail[j].DividendsAmount,
|
|
|
"dividendsAmount": detail.DividendsAmount,
|
|
|
"dividendsUser": map[string]interface{}{
|
|
|
"userInfo": a.Participator.UserInfo,
|
|
|
"userId": a.Participator.UserId,
|
...
|
...
|
@@ -240,7 +286,14 @@ func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[s |
|
|
"dividendsEstimateTime": a.CreatedAt.Unix() * 1000,
|
|
|
"orderOrReturnedOrderNum": a.CreditAccountOrderNum,
|
|
|
}
|
|
|
if detail.OrderGoodAmount > 0 {
|
|
|
item["dividendsRatio"] = utils.Round(detail.DividendsAmount/detail.OrderGoodAmount*100, 2)
|
|
|
}
|
|
|
item["dividendsType"] = a.AccountDetail[j].DividendsType
|
|
|
if v, ok := mapOrderGoods[detail.OrderGoodId]; ok {
|
|
|
item["orderGoodName"] = v.OrderGoodName
|
|
|
}
|
|
|
|
|
|
dividends = append(dividends, item)
|
|
|
}
|
|
|
|
...
|
...
|
|