作者 yangfu

增加:合伙人信息接口

... ... @@ -161,7 +161,7 @@ func getStatistics(userId int64, transactionContext *transaction.TransactionCont
if count, e := PartnerInfoDao.PartnerStatic(map[string]interface{}{"inPartnerIds": partnerIds, "inPartnerCategory": domain.App}); e == nil {
Statistics["appCount"] = count
}
if bonus, e := OrderBaseDao.OrderBonusStatics(domain.OrderBonusQuery{InPartnerIds: partnerIds}); e == nil {
if bonus, e := OrderBaseDao.OrderBonusStatics(domain.OrderBonusQuery{InPartnerIds: partnerIds, OrderType: domain.OrderReal}); e == nil {
Statistics["careerOrdersMoney"] = bonus.TotalOrderAmount
Statistics["careerDividend"] = bonus.BonusExpense
}
... ...
... ... @@ -117,8 +117,9 @@ func orderTotalStatic(order *domain.OrderBase) interface{} {
// 订单统计
func Statistics(header *protocol.RequestHeader, request *protocol.OrderStatisticsRequest) (rsp *protocol.OrderStatisticsResponse, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
OrderDao, _ = factory.CreateOrderBaseDao(transactionContext)
transactionContext, _ = factory.CreateTransactionContext(nil)
OrderDao, _ = factory.CreateOrderBaseDao(transactionContext)
BusinessBonusRepository, _ = factory.CreateBusinessBonusRepository(transactionContext)
//PartnerInfoRepository, _ = factory.CreatePartnerInfoRepositoryIn(transactionContext)
//partnerInfo *domain.PartnerInfo
//orderBonus domain.OrderBonusResponse
... ... @@ -154,10 +155,22 @@ func Statistics(header *protocol.RequestHeader, request *protocol.OrderStatistic
rsp.Statistics.CumulativeMoney = utils.Decimal(rsp.Statistics.CumulativeMoney)
//事业分红/业务分红
//var enterpriseBonus,businessBonus float64
//if orderBonus,err= OrderDao.OrderBonusStatics(domain.OrderBonusQuery{PartnerId:header.UserId});e==nil{
//
//}
var careerBonus, businessBonus, total float64 //,developBonus,appBonus
if bonus, e := OrderDao.OrderBonusStatics(domain.OrderBonusQuery{PartnerId: header.UserId, OrderType: domain.OrderReal}); e == nil {
careerBonus = bonus.Bonus
total += careerBonus
}
if bonus, e := BusinessBonusRepository.FindOne(map[string]interface{}{"partner_id": header.UserId, "isDisable": 1}); e == nil {
businessBonus = bonus.Bonus
total += businessBonus
rsp.Statistics.BusinessMoney = bonus.Bonus
}
if total == 0 {
return
}
rsp.Statistics.CareerPercent = utils.DecimalToNumber(careerBonus * 100 / total)
rsp.Statistics.BusinessPercent = utils.DecimalToNumber(businessBonus * 100 / total)
err = transactionContext.CommitTransaction()
return
}
... ...
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
}
... ...
... ... @@ -27,6 +27,7 @@ type OrderBonusQuery struct {
CompanyId int64 `json:"companyId,omitempty"`
InPartnerIds []int64 `json:"inPartnerIds,omitempty"`
IsDisable int `json:"isDisable,omitempty"`
OrderType int `json:"orderType,omitempty"`
}
// 订单分红统计-应答
... ...
... ... @@ -65,6 +65,9 @@ func (dao *OrderBaseDao) OrderBonusStatics(option domain.OrderBonusQuery) (rsp d
if len(option.InPartnerIds) > 0 {
q.Where(`"order_base".partner_id in (?)`, pg.In(option.InPartnerIds))
}
if option.OrderType > 0 {
q.Where(`"order_base".order_type =?`, option.OrderType)
}
err = q.Select(&rsp.Total, &rsp.Bonus, &rsp.BonusExpense, &rsp.TotalOrderAmount)
return
}
... ...
... ... @@ -88,7 +88,7 @@ func (svr *PgLoginService) PartnerStaticInfo() (interface{}, error) {
if len(companyList) == 0 {
return nil, nil
}
totalBonus, e := OrderDao.OrderBonusStatics(domain.OrderBonusQuery{InPartnerIds: doGetPartnerIds()})
totalBonus, e := OrderDao.OrderBonusStatics(domain.OrderBonusQuery{InPartnerIds: doGetPartnerIds(), OrderType: domain.OrderReal})
if e != nil {
return nil, e
}
... ... @@ -110,7 +110,7 @@ func (svr *PgLoginService) PartnerStaticInfo() (interface{}, error) {
if partner == nil {
continue
}
bonus, _ := OrderDao.OrderBonusStatics(domain.OrderBonusQuery{PartnerId: partner.Id})
bonus, _ := OrderDao.OrderBonusStatics(domain.OrderBonusQuery{PartnerId: partner.Id, OrderType: domain.OrderReal})
item := &Company{
CompanyBase: newCompanyBase(c),
IncomePercent: computeBonusPercent(totalBonus.Bonus*100, bonus.Bonus),
... ... @@ -254,8 +254,8 @@ type Company struct {
// 收入占比
IncomePercent float64 `json:"incomePercent"`
// 分红金额
DividendMoney float64 `json:"dividendMoney"`
JoinWays []joinWay
DividendMoney float64 `json:"dividendMoney"`
JoinWays []joinWay `json:"joinWays"`
}
type incomeInfo struct {
// 收入占比
... ...
... ... @@ -49,6 +49,7 @@ func (repository *BusinessBonusRepository) FindOne(queryOptions map[string]inter
BusinessBonusModel := new(models.BusinessBonus)
query := NewQuery(tx.Model(BusinessBonusModel), queryOptions)
query.SetWhere("id = ?", "id")
query.SetWhere("is_disable = ?", "isDisable")
query.SetWhere("partner_info_id = ?", "partner_id")
if err := query.First(); err != nil {
return nil, fmt.Errorf("query row not found")
... ...
... ... @@ -2,6 +2,7 @@ package repository
import (
"fmt"
"github.com/go-pg/pg/v10"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction"
... ... @@ -66,6 +67,9 @@ func (repository *PartnerCategoryInfoRepository) Find(queryOptions map[string]in
SetOrder("create_time", "sortByCreateTime").
SetOrder("update_time", "sortByUpdateTime").
SetOrder("id", "sortById")
if value, ok := queryOptions["inIds"]; ok {
query.Where("id in (?)", pg.In(value))
}
var err error
if query.AffectRow, err = query.SelectAndCount(); err != nil {
return 0, PartnerCategoryInfos, err
... ...
package controllers
import (
"github.com/tiptok/gocomm/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partner"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol"
protocolx "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol/partner"
)
type PartnerController struct {
BaseController
}
// Detail
// 测试
func (this *PartnerController) Detail() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocolx.DetailRequest
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := this.GetRequestHeader(this.Ctx)
data, err := partner.Detail(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewReturnResponse(data, err)
}
... ...
... ... @@ -35,6 +35,8 @@ func init() {
nsV1.Router("/company/property", &controllers.CompanyController{}, "post:Property")
nsV1.Router("/company/partners", &controllers.CompanyController{}, "post:Partners")
nsV1.Router("/company/statistics", &controllers.CompanyController{}, "post:Statistics")
nsV1.Router("/partner/detail", &controllers.PartnerController{}, "post:Detail")
beego.AddNamespace(nsV1)
InitV2()
... ...
... ... @@ -56,9 +56,10 @@ type OrderStatics struct {
CumulativeMoney float64 `json:"cumulativeMoney"` //累计实发订单金额
//v0.3.0 新增加
CareerPrecent float64 `json:"careerPrecent"` // 事业占比
BusinessPrecent float64 `json:"businessPrecent"` // 业务占比
DevelopPrecent float64 `json:"developPrecent"` // 研发占比
CareerPercent float64 `json:"careerPercent"` // 事业占比
BusinessPercent float64 `json:"businessPercent"` // 业务占比
DevelopPercent float64 `json:"developPercent"` // 研发占比
AppPercent float64 `json:"appPercent"` // 研发占比
BusinessMoney float64 `json:"businessMoney"` // 业务分红累计
}
... ...
package partner
type DetailRequest struct {
// 唯一标识
Uid int64 `json:"uid" valid:"Required"`
}
... ...
package partner
type DetailResponse struct {
Partner interface{} `json:"partner"`
}
type Partner struct {
//用户名称
PartnerName string `json:"uname"`
//合作区域
District interface{} `json:"district"`
// 合伙类别 (1.研发合伙人 2.业务合伙人 3.事业)
JoinWay []interface{} `json:"joinWays"`
//合作时间
CooperateTime int64 `json:"cooperationTime"`
CareerOrdersCount int `json:"careerOrdersCount"`
CareerOrdersMoney float64 `json:"careerOrdersMoney"`
CareerDividend float64 `json:"careerDividend"`
BusinessOrdersCount int `json:"businessOrdersCount"`
BusinessOrdersMoney float64 `json:"businessOrdersMoney"`
BusinessDividend float64 `json:"businessDividend"`
DevelopOrdersCount int `json:"developOrdersCount"`
DevelopOrdersMoney float64 `json:"developOrdersMoney"`
DevelopDividend float64 `json:"developDividend"`
ApplicationOrdersCount int `json:"applicationOrdersCount"`
ApplicationOrdersMoney float64 `json:"applicationOrdersMoney"`
ApplicationDividend float64 `json:"applicationDividend"`
}
... ...