正在显示
13 个修改的文件
包含
189 行增加
和
11 行删除
| @@ -161,7 +161,7 @@ func getStatistics(userId int64, transactionContext *transaction.TransactionCont | @@ -161,7 +161,7 @@ func getStatistics(userId int64, transactionContext *transaction.TransactionCont | ||
| 161 | if count, e := PartnerInfoDao.PartnerStatic(map[string]interface{}{"inPartnerIds": partnerIds, "inPartnerCategory": domain.App}); e == nil { | 161 | if count, e := PartnerInfoDao.PartnerStatic(map[string]interface{}{"inPartnerIds": partnerIds, "inPartnerCategory": domain.App}); e == nil { |
| 162 | Statistics["appCount"] = count | 162 | Statistics["appCount"] = count |
| 163 | } | 163 | } |
| 164 | - if bonus, e := OrderBaseDao.OrderBonusStatics(domain.OrderBonusQuery{InPartnerIds: partnerIds}); e == nil { | 164 | + if bonus, e := OrderBaseDao.OrderBonusStatics(domain.OrderBonusQuery{InPartnerIds: partnerIds, OrderType: domain.OrderReal}); e == nil { |
| 165 | Statistics["careerOrdersMoney"] = bonus.TotalOrderAmount | 165 | Statistics["careerOrdersMoney"] = bonus.TotalOrderAmount |
| 166 | Statistics["careerDividend"] = bonus.BonusExpense | 166 | Statistics["careerDividend"] = bonus.BonusExpense |
| 167 | } | 167 | } |
| @@ -119,6 +119,7 @@ func Statistics(header *protocol.RequestHeader, request *protocol.OrderStatistic | @@ -119,6 +119,7 @@ func Statistics(header *protocol.RequestHeader, request *protocol.OrderStatistic | ||
| 119 | var ( | 119 | var ( |
| 120 | transactionContext, _ = factory.CreateTransactionContext(nil) | 120 | transactionContext, _ = factory.CreateTransactionContext(nil) |
| 121 | OrderDao, _ = factory.CreateOrderBaseDao(transactionContext) | 121 | OrderDao, _ = factory.CreateOrderBaseDao(transactionContext) |
| 122 | + BusinessBonusRepository, _ = factory.CreateBusinessBonusRepository(transactionContext) | ||
| 122 | //PartnerInfoRepository, _ = factory.CreatePartnerInfoRepositoryIn(transactionContext) | 123 | //PartnerInfoRepository, _ = factory.CreatePartnerInfoRepositoryIn(transactionContext) |
| 123 | //partnerInfo *domain.PartnerInfo | 124 | //partnerInfo *domain.PartnerInfo |
| 124 | //orderBonus domain.OrderBonusResponse | 125 | //orderBonus domain.OrderBonusResponse |
| @@ -154,10 +155,22 @@ func Statistics(header *protocol.RequestHeader, request *protocol.OrderStatistic | @@ -154,10 +155,22 @@ func Statistics(header *protocol.RequestHeader, request *protocol.OrderStatistic | ||
| 154 | rsp.Statistics.CumulativeMoney = utils.Decimal(rsp.Statistics.CumulativeMoney) | 155 | rsp.Statistics.CumulativeMoney = utils.Decimal(rsp.Statistics.CumulativeMoney) |
| 155 | 156 | ||
| 156 | //事业分红/业务分红 | 157 | //事业分红/业务分红 |
| 157 | - //var enterpriseBonus,businessBonus float64 | ||
| 158 | - //if orderBonus,err= OrderDao.OrderBonusStatics(domain.OrderBonusQuery{PartnerId:header.UserId});e==nil{ | ||
| 159 | - // | ||
| 160 | - //} | 158 | + var careerBonus, businessBonus, total float64 //,developBonus,appBonus |
| 159 | + if bonus, e := OrderDao.OrderBonusStatics(domain.OrderBonusQuery{PartnerId: header.UserId, OrderType: domain.OrderReal}); e == nil { | ||
| 160 | + careerBonus = bonus.Bonus | ||
| 161 | + total += careerBonus | ||
| 162 | + } | ||
| 163 | + if bonus, e := BusinessBonusRepository.FindOne(map[string]interface{}{"partner_id": header.UserId, "isDisable": 1}); e == nil { | ||
| 164 | + businessBonus = bonus.Bonus | ||
| 165 | + total += businessBonus | ||
| 166 | + rsp.Statistics.BusinessMoney = bonus.Bonus | ||
| 167 | + } | ||
| 168 | + | ||
| 169 | + if total == 0 { | ||
| 170 | + return | ||
| 171 | + } | ||
| 172 | + rsp.Statistics.CareerPercent = utils.DecimalToNumber(careerBonus * 100 / total) | ||
| 173 | + rsp.Statistics.BusinessPercent = utils.DecimalToNumber(businessBonus * 100 / total) | ||
| 161 | err = transactionContext.CommitTransaction() | 174 | err = transactionContext.CommitTransaction() |
| 162 | return | 175 | return |
| 163 | } | 176 | } |
pkg/application/partner/partner.go
0 → 100644
| 1 | +package partner | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "github.com/tiptok/gocomm/pkg/log" | ||
| 6 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory" | ||
| 7 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" | ||
| 8 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction" | ||
| 9 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" | ||
| 10 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" | ||
| 11 | + protocol_company "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol/company" | ||
| 12 | + protocolx "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol/partner" | ||
| 13 | +) | ||
| 14 | + | ||
| 15 | +func Detail(header *protocol.RequestHeader, request *protocolx.DetailRequest) (rsp *protocolx.DetailResponse, err error) { | ||
| 16 | + var ( | ||
| 17 | + transactionContext, _ = factory.CreateTransactionContext(nil) | ||
| 18 | + ) | ||
| 19 | + rsp = &protocolx.DetailResponse{} | ||
| 20 | + if err = transactionContext.StartTransaction(); err != nil { | ||
| 21 | + log.Error(err) | ||
| 22 | + return nil, err | ||
| 23 | + } | ||
| 24 | + defer func() { | ||
| 25 | + transactionContext.RollbackTransaction() | ||
| 26 | + }() | ||
| 27 | + if rsp.Partner, err = getDetail(request.Uid, transactionContext); err != nil { | ||
| 28 | + return | ||
| 29 | + } | ||
| 30 | + err = transactionContext.CommitTransaction() | ||
| 31 | + return | ||
| 32 | +} | ||
| 33 | + | ||
| 34 | +func getDetail(userId int64, transactionContext *transaction.TransactionContext) (interface{}, error) { | ||
| 35 | + var ( | ||
| 36 | + PartnerInfoRepository, _ = factory.CreatePartnerInfoRepositoryIn(transactionContext) | ||
| 37 | + PartnerCategoryInfoRepository, _ = factory.CreatePartnerCategoryInfoRepository(transactionContext) | ||
| 38 | + OrderBaseDao, _ = factory.CreateOrderBaseDao(transactionContext) | ||
| 39 | + BusinessBonusDao, _ = factory.CreateBusinessBonusDao(transactionContext) | ||
| 40 | + partner *domain.PartnerInfo | ||
| 41 | + err error | ||
| 42 | + ) | ||
| 43 | + if partner, err = PartnerInfoRepository.FindOne(map[string]interface{}{"id": userId}); err != nil { | ||
| 44 | + log.Error(err) | ||
| 45 | + return nil, err | ||
| 46 | + } | ||
| 47 | + p := protocolx.Partner{} | ||
| 48 | + | ||
| 49 | + p.PartnerName = partner.PartnerName | ||
| 50 | + if partner.RegionInfo != nil { | ||
| 51 | + p.District = protocol_company.Districts{ | ||
| 52 | + Id: partner.RegionInfo.RegionId, | ||
| 53 | + Name: partner.RegionInfo.RegionName, | ||
| 54 | + } | ||
| 55 | + } | ||
| 56 | + if len(partner.PartnerCategoryInfos) > 0 { | ||
| 57 | + var cIds []int64 | ||
| 58 | + for i := range partner.PartnerCategoryInfos { | ||
| 59 | + cIds = append(cIds, partner.PartnerCategoryInfos[i].Id) | ||
| 60 | + } | ||
| 61 | + _, categories, _ := PartnerCategoryInfoRepository.Find(map[string]interface{}{"inIds": cIds}) | ||
| 62 | + for i := range categories { | ||
| 63 | + c := categories[i] | ||
| 64 | + p.JoinWay = append(p.JoinWay, map[string]interface{}{"type": fmt.Sprintf("%v", c.Id), "name": c.Name}) | ||
| 65 | + } | ||
| 66 | + } | ||
| 67 | + p.CooperateTime = partner.CooperateTime.Unix() * 1000 | ||
| 68 | + if bonus, e := OrderBaseDao.OrderBonusStatics(domain.OrderBonusQuery{PartnerId: userId, OrderType: domain.OrderReal}); e == nil { | ||
| 69 | + p.CareerOrdersCount = int(bonus.Total) | ||
| 70 | + p.CareerOrdersMoney = utils.Decimal(bonus.TotalOrderAmount) | ||
| 71 | + p.CareerDividend = utils.Decimal(bonus.Bonus) | ||
| 72 | + } | ||
| 73 | + if businessBonus, e := BusinessBonusDao.OrderBonusStatics(domain.OrderBonusQuery{PartnerId: userId, IsDisable: 1}); e == nil { | ||
| 74 | + p.BusinessOrdersCount = int(businessBonus.Total) | ||
| 75 | + p.BusinessOrdersMoney = utils.Decimal(businessBonus.TotalOrderAmount) | ||
| 76 | + p.BusinessDividend = utils.Decimal(businessBonus.Bonus) | ||
| 77 | + } | ||
| 78 | + return p, nil | ||
| 79 | +} |
| @@ -27,6 +27,7 @@ type OrderBonusQuery struct { | @@ -27,6 +27,7 @@ type OrderBonusQuery struct { | ||
| 27 | CompanyId int64 `json:"companyId,omitempty"` | 27 | CompanyId int64 `json:"companyId,omitempty"` |
| 28 | InPartnerIds []int64 `json:"inPartnerIds,omitempty"` | 28 | InPartnerIds []int64 `json:"inPartnerIds,omitempty"` |
| 29 | IsDisable int `json:"isDisable,omitempty"` | 29 | IsDisable int `json:"isDisable,omitempty"` |
| 30 | + OrderType int `json:"orderType,omitempty"` | ||
| 30 | } | 31 | } |
| 31 | 32 | ||
| 32 | // 订单分红统计-应答 | 33 | // 订单分红统计-应答 |
| @@ -65,6 +65,9 @@ func (dao *OrderBaseDao) OrderBonusStatics(option domain.OrderBonusQuery) (rsp d | @@ -65,6 +65,9 @@ func (dao *OrderBaseDao) OrderBonusStatics(option domain.OrderBonusQuery) (rsp d | ||
| 65 | if len(option.InPartnerIds) > 0 { | 65 | if len(option.InPartnerIds) > 0 { |
| 66 | q.Where(`"order_base".partner_id in (?)`, pg.In(option.InPartnerIds)) | 66 | q.Where(`"order_base".partner_id in (?)`, pg.In(option.InPartnerIds)) |
| 67 | } | 67 | } |
| 68 | + if option.OrderType > 0 { | ||
| 69 | + q.Where(`"order_base".order_type =?`, option.OrderType) | ||
| 70 | + } | ||
| 68 | err = q.Select(&rsp.Total, &rsp.Bonus, &rsp.BonusExpense, &rsp.TotalOrderAmount) | 71 | err = q.Select(&rsp.Total, &rsp.Bonus, &rsp.BonusExpense, &rsp.TotalOrderAmount) |
| 69 | return | 72 | return |
| 70 | } | 73 | } |
| @@ -88,7 +88,7 @@ func (svr *PgLoginService) PartnerStaticInfo() (interface{}, error) { | @@ -88,7 +88,7 @@ func (svr *PgLoginService) PartnerStaticInfo() (interface{}, error) { | ||
| 88 | if len(companyList) == 0 { | 88 | if len(companyList) == 0 { |
| 89 | return nil, nil | 89 | return nil, nil |
| 90 | } | 90 | } |
| 91 | - totalBonus, e := OrderDao.OrderBonusStatics(domain.OrderBonusQuery{InPartnerIds: doGetPartnerIds()}) | 91 | + totalBonus, e := OrderDao.OrderBonusStatics(domain.OrderBonusQuery{InPartnerIds: doGetPartnerIds(), OrderType: domain.OrderReal}) |
| 92 | if e != nil { | 92 | if e != nil { |
| 93 | return nil, e | 93 | return nil, e |
| 94 | } | 94 | } |
| @@ -110,7 +110,7 @@ func (svr *PgLoginService) PartnerStaticInfo() (interface{}, error) { | @@ -110,7 +110,7 @@ func (svr *PgLoginService) PartnerStaticInfo() (interface{}, error) { | ||
| 110 | if partner == nil { | 110 | if partner == nil { |
| 111 | continue | 111 | continue |
| 112 | } | 112 | } |
| 113 | - bonus, _ := OrderDao.OrderBonusStatics(domain.OrderBonusQuery{PartnerId: partner.Id}) | 113 | + bonus, _ := OrderDao.OrderBonusStatics(domain.OrderBonusQuery{PartnerId: partner.Id, OrderType: domain.OrderReal}) |
| 114 | item := &Company{ | 114 | item := &Company{ |
| 115 | CompanyBase: newCompanyBase(c), | 115 | CompanyBase: newCompanyBase(c), |
| 116 | IncomePercent: computeBonusPercent(totalBonus.Bonus*100, bonus.Bonus), | 116 | IncomePercent: computeBonusPercent(totalBonus.Bonus*100, bonus.Bonus), |
| @@ -255,7 +255,7 @@ type Company struct { | @@ -255,7 +255,7 @@ type Company struct { | ||
| 255 | IncomePercent float64 `json:"incomePercent"` | 255 | IncomePercent float64 `json:"incomePercent"` |
| 256 | // 分红金额 | 256 | // 分红金额 |
| 257 | DividendMoney float64 `json:"dividendMoney"` | 257 | DividendMoney float64 `json:"dividendMoney"` |
| 258 | - JoinWays []joinWay | 258 | + JoinWays []joinWay `json:"joinWays"` |
| 259 | } | 259 | } |
| 260 | type incomeInfo struct { | 260 | type incomeInfo struct { |
| 261 | // 收入占比 | 261 | // 收入占比 |
| @@ -49,6 +49,7 @@ func (repository *BusinessBonusRepository) FindOne(queryOptions map[string]inter | @@ -49,6 +49,7 @@ func (repository *BusinessBonusRepository) FindOne(queryOptions map[string]inter | ||
| 49 | BusinessBonusModel := new(models.BusinessBonus) | 49 | BusinessBonusModel := new(models.BusinessBonus) |
| 50 | query := NewQuery(tx.Model(BusinessBonusModel), queryOptions) | 50 | query := NewQuery(tx.Model(BusinessBonusModel), queryOptions) |
| 51 | query.SetWhere("id = ?", "id") | 51 | query.SetWhere("id = ?", "id") |
| 52 | + query.SetWhere("is_disable = ?", "isDisable") | ||
| 52 | query.SetWhere("partner_info_id = ?", "partner_id") | 53 | query.SetWhere("partner_info_id = ?", "partner_id") |
| 53 | if err := query.First(); err != nil { | 54 | if err := query.First(); err != nil { |
| 54 | return nil, fmt.Errorf("query row not found") | 55 | return nil, fmt.Errorf("query row not found") |
| @@ -2,6 +2,7 @@ package repository | @@ -2,6 +2,7 @@ package repository | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | 4 | "fmt" |
| 5 | + "github.com/go-pg/pg/v10" | ||
| 5 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" | 6 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" |
| 6 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/models" | 7 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/models" |
| 7 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction" | 8 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction" |
| @@ -66,6 +67,9 @@ func (repository *PartnerCategoryInfoRepository) Find(queryOptions map[string]in | @@ -66,6 +67,9 @@ func (repository *PartnerCategoryInfoRepository) Find(queryOptions map[string]in | ||
| 66 | SetOrder("create_time", "sortByCreateTime"). | 67 | SetOrder("create_time", "sortByCreateTime"). |
| 67 | SetOrder("update_time", "sortByUpdateTime"). | 68 | SetOrder("update_time", "sortByUpdateTime"). |
| 68 | SetOrder("id", "sortById") | 69 | SetOrder("id", "sortById") |
| 70 | + if value, ok := queryOptions["inIds"]; ok { | ||
| 71 | + query.Where("id in (?)", pg.In(value)) | ||
| 72 | + } | ||
| 69 | var err error | 73 | var err error |
| 70 | if query.AffectRow, err = query.SelectAndCount(); err != nil { | 74 | if query.AffectRow, err = query.SelectAndCount(); err != nil { |
| 71 | return 0, PartnerCategoryInfos, err | 75 | return 0, PartnerCategoryInfos, err |
pkg/port/appsvr/controllers/partner.go
0 → 100644
| 1 | +package controllers | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "github.com/tiptok/gocomm/pkg/log" | ||
| 5 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partner" | ||
| 6 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" | ||
| 7 | + protocolx "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol/partner" | ||
| 8 | +) | ||
| 9 | + | ||
| 10 | +type PartnerController struct { | ||
| 11 | + BaseController | ||
| 12 | +} | ||
| 13 | + | ||
| 14 | +// Detail | ||
| 15 | +// 测试 | ||
| 16 | +func (this *PartnerController) Detail() { | ||
| 17 | + var msg *protocol.ResponseMessage | ||
| 18 | + defer func() { | ||
| 19 | + this.Resp(msg) | ||
| 20 | + }() | ||
| 21 | + var request *protocolx.DetailRequest | ||
| 22 | + if err := this.JsonUnmarshal(&request); err != nil { | ||
| 23 | + msg = protocol.BadRequestParam(1) | ||
| 24 | + return | ||
| 25 | + } | ||
| 26 | + if b, m := this.Valid(request); !b { | ||
| 27 | + msg = m | ||
| 28 | + return | ||
| 29 | + } | ||
| 30 | + header := this.GetRequestHeader(this.Ctx) | ||
| 31 | + data, err := partner.Detail(header, request) | ||
| 32 | + if err != nil { | ||
| 33 | + log.Error(err) | ||
| 34 | + } | ||
| 35 | + msg = protocol.NewReturnResponse(data, err) | ||
| 36 | +} |
| @@ -35,6 +35,8 @@ func init() { | @@ -35,6 +35,8 @@ func init() { | ||
| 35 | nsV1.Router("/company/property", &controllers.CompanyController{}, "post:Property") | 35 | nsV1.Router("/company/property", &controllers.CompanyController{}, "post:Property") |
| 36 | nsV1.Router("/company/partners", &controllers.CompanyController{}, "post:Partners") | 36 | nsV1.Router("/company/partners", &controllers.CompanyController{}, "post:Partners") |
| 37 | nsV1.Router("/company/statistics", &controllers.CompanyController{}, "post:Statistics") | 37 | nsV1.Router("/company/statistics", &controllers.CompanyController{}, "post:Statistics") |
| 38 | + | ||
| 39 | + nsV1.Router("/partner/detail", &controllers.PartnerController{}, "post:Detail") | ||
| 38 | beego.AddNamespace(nsV1) | 40 | beego.AddNamespace(nsV1) |
| 39 | 41 | ||
| 40 | InitV2() | 42 | InitV2() |
| @@ -56,9 +56,10 @@ type OrderStatics struct { | @@ -56,9 +56,10 @@ type OrderStatics struct { | ||
| 56 | CumulativeMoney float64 `json:"cumulativeMoney"` //累计实发订单金额 | 56 | CumulativeMoney float64 `json:"cumulativeMoney"` //累计实发订单金额 |
| 57 | 57 | ||
| 58 | //v0.3.0 新增加 | 58 | //v0.3.0 新增加 |
| 59 | - CareerPrecent float64 `json:"careerPrecent"` // 事业占比 | ||
| 60 | - BusinessPrecent float64 `json:"businessPrecent"` // 业务占比 | ||
| 61 | - DevelopPrecent float64 `json:"developPrecent"` // 研发占比 | 59 | + CareerPercent float64 `json:"careerPercent"` // 事业占比 |
| 60 | + BusinessPercent float64 `json:"businessPercent"` // 业务占比 | ||
| 61 | + DevelopPercent float64 `json:"developPercent"` // 研发占比 | ||
| 62 | + AppPercent float64 `json:"appPercent"` // 研发占比 | ||
| 62 | BusinessMoney float64 `json:"businessMoney"` // 业务分红累计 | 63 | BusinessMoney float64 `json:"businessMoney"` // 业务分红累计 |
| 63 | } | 64 | } |
| 64 | 65 |
pkg/protocol/partner/detail_request.go
0 → 100644
pkg/protocol/partner/detail_response.go
0 → 100644
| 1 | +package partner | ||
| 2 | + | ||
| 3 | +type DetailResponse struct { | ||
| 4 | + Partner interface{} `json:"partner"` | ||
| 5 | +} | ||
| 6 | + | ||
| 7 | +type Partner struct { | ||
| 8 | + //用户名称 | ||
| 9 | + PartnerName string `json:"uname"` | ||
| 10 | + //合作区域 | ||
| 11 | + District interface{} `json:"district"` | ||
| 12 | + // 合伙类别 (1.研发合伙人 2.业务合伙人 3.事业) | ||
| 13 | + JoinWay []interface{} `json:"joinWays"` | ||
| 14 | + //合作时间 | ||
| 15 | + CooperateTime int64 `json:"cooperationTime"` | ||
| 16 | + | ||
| 17 | + CareerOrdersCount int `json:"careerOrdersCount"` | ||
| 18 | + CareerOrdersMoney float64 `json:"careerOrdersMoney"` | ||
| 19 | + CareerDividend float64 `json:"careerDividend"` | ||
| 20 | + | ||
| 21 | + BusinessOrdersCount int `json:"businessOrdersCount"` | ||
| 22 | + BusinessOrdersMoney float64 `json:"businessOrdersMoney"` | ||
| 23 | + BusinessDividend float64 `json:"businessDividend"` | ||
| 24 | + | ||
| 25 | + DevelopOrdersCount int `json:"developOrdersCount"` | ||
| 26 | + DevelopOrdersMoney float64 `json:"developOrdersMoney"` | ||
| 27 | + DevelopDividend float64 `json:"developDividend"` | ||
| 28 | + | ||
| 29 | + ApplicationOrdersCount int `json:"applicationOrdersCount"` | ||
| 30 | + ApplicationOrdersMoney float64 `json:"applicationOrdersMoney"` | ||
| 31 | + ApplicationDividend float64 `json:"applicationDividend"` | ||
| 32 | +} |
-
请 注册 或 登录 后发表评论