|
|
package partner
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"github.com/tiptok/gocomm/pkg/log"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol"
|
|
|
protocol_company "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol/company"
|
|
|
protocolx "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol/partner"
|
|
|
)
|
|
|
|
|
|
func Detail(header *protocol.RequestHeader, request *protocolx.DetailRequest) (rsp *protocolx.DetailResponse, err error) {
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
)
|
|
|
rsp = &protocolx.DetailResponse{}
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
|
log.Error(err)
|
|
|
return nil, err
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
if rsp.Partner, err = getDetail(request.Uid, transactionContext); err != nil {
|
|
|
return
|
|
|
}
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func getDetail(userId int64, transactionContext *transaction.TransactionContext) (interface{}, error) {
|
|
|
var (
|
|
|
PartnerInfoRepository, _ = factory.CreatePartnerInfoRepositoryIn(transactionContext)
|
|
|
PartnerCategoryInfoRepository, _ = factory.CreatePartnerCategoryInfoRepository(transactionContext)
|
|
|
OrderBaseDao, _ = factory.CreateOrderBaseDao(transactionContext)
|
|
|
BusinessBonusDao, _ = factory.CreateBusinessBonusDao(transactionContext)
|
|
|
partner *domain.PartnerInfo
|
|
|
err error
|
|
|
)
|
|
|
if partner, err = PartnerInfoRepository.FindOne(map[string]interface{}{"id": userId}); err != nil {
|
|
|
log.Error(err)
|
|
|
return nil, err
|
|
|
}
|
|
|
p := protocolx.Partner{}
|
|
|
|
|
|
p.PartnerName = partner.PartnerName
|
|
|
if partner.RegionInfo != nil {
|
|
|
p.District = protocol_company.Districts{
|
|
|
Id: partner.RegionInfo.RegionId,
|
|
|
Name: partner.RegionInfo.RegionName,
|
|
|
}
|
|
|
}
|
|
|
if len(partner.PartnerCategoryInfos) > 0 {
|
|
|
var cIds []int64
|
|
|
for i := range partner.PartnerCategoryInfos {
|
|
|
cIds = append(cIds, partner.PartnerCategoryInfos[i].Id)
|
|
|
}
|
|
|
_, categories, _ := PartnerCategoryInfoRepository.Find(map[string]interface{}{"inIds": cIds})
|
|
|
for i := range categories {
|
|
|
c := categories[i]
|
|
|
p.JoinWay = append(p.JoinWay, map[string]interface{}{"type": fmt.Sprintf("%v", c.Id), "name": c.Name})
|
|
|
}
|
|
|
}
|
|
|
p.CooperateTime = partner.CooperateTime.Unix() * 1000
|
|
|
if bonus, e := OrderBaseDao.OrderBonusStatics(domain.OrderBonusQuery{PartnerId: userId, OrderType: domain.OrderReal}); e == nil {
|
|
|
p.CareerOrdersCount = int(bonus.Total)
|
|
|
p.CareerOrdersMoney = utils.Decimal(bonus.TotalOrderAmount)
|
|
|
p.CareerDividend = utils.Decimal(bonus.Bonus)
|
|
|
}
|
|
|
if businessBonus, e := BusinessBonusDao.OrderBonusStatics(domain.OrderBonusQuery{PartnerId: userId, IsDisable: 1}); e == nil {
|
|
|
p.BusinessOrdersCount = int(businessBonus.Total)
|
|
|
p.BusinessOrdersMoney = utils.Decimal(businessBonus.TotalOrderAmount)
|
|
|
p.BusinessDividend = utils.Decimal(businessBonus.Bonus)
|
|
|
}
|
|
|
return p, nil
|
|
|
} |
...
|
...
|
|