正在显示
9 个修改的文件
包含
158 行增加
和
4 行删除
| @@ -64,7 +64,11 @@ func Statistics(header *protocol.RequestHeader, request *protocolx.StatisticsReq | @@ -64,7 +64,11 @@ func Statistics(header *protocol.RequestHeader, request *protocolx.StatisticsReq | ||
| 64 | defer func() { | 64 | defer func() { |
| 65 | transactionContext.RollbackTransaction() | 65 | transactionContext.RollbackTransaction() |
| 66 | }() | 66 | }() |
| 67 | - | 67 | + rsp.Statistics, err = getStatistics(header.UserId, transactionContext) |
| 68 | + if err != nil { | ||
| 69 | + log.Error(err) | ||
| 70 | + return | ||
| 71 | + } | ||
| 68 | err = transactionContext.CommitTransaction() | 72 | err = transactionContext.CommitTransaction() |
| 69 | return | 73 | return |
| 70 | } | 74 | } |
| @@ -127,3 +131,47 @@ func getJoinWays(transactionContext *transaction.TransactionContext) (joinWays [ | @@ -127,3 +131,47 @@ func getJoinWays(transactionContext *transaction.TransactionContext) (joinWays [ | ||
| 127 | } | 131 | } |
| 128 | return | 132 | return |
| 129 | } | 133 | } |
| 134 | + | ||
| 135 | +// 获取公司统计 | ||
| 136 | +func getStatistics(userId int64, transactionContext *transaction.TransactionContext) (interface{}, error) { | ||
| 137 | + var ( | ||
| 138 | + UsersRepository, _ = factory.CreateUsersRepository(transactionContext) | ||
| 139 | + PartnerInfoDao, _ = factory.CreatePartnerInfoDao(transactionContext) | ||
| 140 | + OrderBaseDao, _ = factory.CreateOrderBaseDao(transactionContext) | ||
| 141 | + BusinessBonusDao, _ = factory.CreateBusinessBonusDao(transactionContext) | ||
| 142 | + //user *domain.Users | ||
| 143 | + partnerIds []int64 | ||
| 144 | + ) | ||
| 145 | + if user, e := UsersRepository.FindOne(map[string]interface{}{"id": userId}); e != nil || user == nil { | ||
| 146 | + return struct { | ||
| 147 | + }{}, nil | ||
| 148 | + } else { | ||
| 149 | + partnerIds = user.AccessPartnerIds() | ||
| 150 | + } | ||
| 151 | + Statistics := make(map[string]interface{}) | ||
| 152 | + if count, e := PartnerInfoDao.PartnerStatic(map[string]interface{}{"inPartnerIds": partnerIds, "inPartnerCategory": domain.Career}); e == nil { | ||
| 153 | + Statistics["careerCount"] = count | ||
| 154 | + } | ||
| 155 | + if count, e := PartnerInfoDao.PartnerStatic(map[string]interface{}{"inPartnerIds": partnerIds, "inPartnerCategory": domain.Business}); e == nil { | ||
| 156 | + Statistics["businessCount"] = count | ||
| 157 | + } | ||
| 158 | + if count, e := PartnerInfoDao.PartnerStatic(map[string]interface{}{"inPartnerIds": partnerIds, "inPartnerCategory": domain.Develop}); e == nil { | ||
| 159 | + Statistics["developCount"] = count | ||
| 160 | + } | ||
| 161 | + if count, e := PartnerInfoDao.PartnerStatic(map[string]interface{}{"inPartnerIds": partnerIds, "inPartnerCategory": domain.App}); e == nil { | ||
| 162 | + Statistics["appCount"] = count | ||
| 163 | + } | ||
| 164 | + if bonus, e := OrderBaseDao.OrderBonusStatics(domain.OrderBonusQuery{InPartnerIds: partnerIds}); e == nil { | ||
| 165 | + Statistics["careerOrdersMoney"] = bonus.TotalOrderAmount | ||
| 166 | + Statistics["careerDividend"] = bonus.BonusExpense | ||
| 167 | + } | ||
| 168 | + if businessBonus, e := BusinessBonusDao.OrderBonusStatics(domain.OrderBonusQuery{InPartnerIds: partnerIds, IsDisable: 1}); e == nil { | ||
| 169 | + Statistics["businessDividend"] = businessBonus.BonusExpense | ||
| 170 | + Statistics["businessOrdersMoney"] = businessBonus.TotalOrderAmount | ||
| 171 | + } | ||
| 172 | + Statistics["developDividend"] = 0 | ||
| 173 | + Statistics["developOrdersMoney"] = 0 | ||
| 174 | + Statistics["appDividend"] = 0 | ||
| 175 | + Statistics["appOrdersMoney"] = 0 | ||
| 176 | + return Statistics, nil | ||
| 177 | +} |
| @@ -12,3 +12,7 @@ func CreatePartnerInfoDao(ctx *transaction.TransactionContext) (*dao.PartnerInfo | @@ -12,3 +12,7 @@ func CreatePartnerInfoDao(ctx *transaction.TransactionContext) (*dao.PartnerInfo | ||
| 12 | func CreateOrderBaseDao(ctx *transaction.TransactionContext) (*dao.OrderBaseDao, error) { | 12 | func CreateOrderBaseDao(ctx *transaction.TransactionContext) (*dao.OrderBaseDao, error) { |
| 13 | return dao.NewOrderBaseDao(ctx) | 13 | return dao.NewOrderBaseDao(ctx) |
| 14 | } | 14 | } |
| 15 | + | ||
| 16 | +func CreateBusinessBonusDao(ctx *transaction.TransactionContext) (*dao.BusinessBonusDao, error) { | ||
| 17 | + return dao.NewBusinessBonusDao(ctx) | ||
| 18 | +} |
| @@ -26,6 +26,7 @@ type OrderBonusQuery struct { | @@ -26,6 +26,7 @@ type OrderBonusQuery struct { | ||
| 26 | PartnerId int64 `json:"partnerId,omitempty"` | 26 | PartnerId int64 `json:"partnerId,omitempty"` |
| 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 | } | 30 | } |
| 30 | 31 | ||
| 31 | // 订单分红统计-应答 | 32 | // 订单分红统计-应答 |
| @@ -36,4 +37,6 @@ type OrderBonusResponse struct { | @@ -36,4 +37,6 @@ type OrderBonusResponse struct { | ||
| 36 | Total int64 `json:"companyId,omitempty"` | 37 | Total int64 `json:"companyId,omitempty"` |
| 37 | // 分红支出 | 38 | // 分红支出 |
| 38 | BonusExpense float64 `json:"bonusExpense,omitempty"` | 39 | BonusExpense float64 `json:"bonusExpense,omitempty"` |
| 40 | + // 订单金额 | ||
| 41 | + TotalOrderAmount float64 `json:"totalOrderAmount"` | ||
| 39 | } | 42 | } |
| 1 | +package dao | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "github.com/go-pg/pg/v10" | ||
| 6 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" | ||
| 7 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/models" | ||
| 8 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction" | ||
| 9 | +) | ||
| 10 | + | ||
| 11 | +type BusinessBonusDao struct { | ||
| 12 | + transactionContext *transaction.TransactionContext | ||
| 13 | +} | ||
| 14 | + | ||
| 15 | +//订单分红统计 | ||
| 16 | +func (dao *BusinessBonusDao) OrderBonusStatics(option domain.OrderBonusQuery) (rsp domain.OrderBonusResponse, err error) { | ||
| 17 | + rsp = domain.OrderBonusResponse{} | ||
| 18 | + if option.PartnerId == 0 && option.CompanyId == 0 && len(option.InPartnerIds) == 0 { | ||
| 19 | + return | ||
| 20 | + } | ||
| 21 | + tx := dao.transactionContext.PgTx | ||
| 22 | + q := tx.Model(new(models.BusinessBonus)) | ||
| 23 | + q.ColumnExpr("count(*) count") | ||
| 24 | + q.ColumnExpr("sum(bonus) bonus") | ||
| 25 | + q.ColumnExpr("sum(bonus_expense) bonus_expense") | ||
| 26 | + if option.PartnerId > 0 { | ||
| 27 | + q.Where(`"business_bonus".partner_info_id =?`, option.PartnerId) | ||
| 28 | + } | ||
| 29 | + if option.CompanyId > 0 { | ||
| 30 | + q.Where(`"business_bonus".company_id =?`, option.CompanyId) | ||
| 31 | + } | ||
| 32 | + if option.IsDisable > 0 { | ||
| 33 | + q.Where(`"business_bonus".is_disable =?`, option.IsDisable) | ||
| 34 | + } | ||
| 35 | + if len(option.InPartnerIds) > 0 { | ||
| 36 | + q.Where(`"business_bonus".partner_info_id in (?)`, pg.In(option.InPartnerIds)) | ||
| 37 | + } | ||
| 38 | + err = q.Select(&rsp.Total, &rsp.Bonus, &rsp.BonusExpense) | ||
| 39 | + return | ||
| 40 | +} | ||
| 41 | + | ||
| 42 | +func NewBusinessBonusDao(transactionContext *transaction.TransactionContext) (*BusinessBonusDao, error) { | ||
| 43 | + if transactionContext == nil { | ||
| 44 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
| 45 | + } else { | ||
| 46 | + return &BusinessBonusDao{ | ||
| 47 | + transactionContext: transactionContext, | ||
| 48 | + }, nil | ||
| 49 | + } | ||
| 50 | +} |
| @@ -55,6 +55,7 @@ func (dao *OrderBaseDao) OrderBonusStatics(option domain.OrderBonusQuery) (rsp d | @@ -55,6 +55,7 @@ func (dao *OrderBaseDao) OrderBonusStatics(option domain.OrderBonusQuery) (rsp d | ||
| 55 | q.ColumnExpr("count(*) count") | 55 | q.ColumnExpr("count(*) count") |
| 56 | q.ColumnExpr("sum(plan_partner_bonus) bonus") | 56 | q.ColumnExpr("sum(plan_partner_bonus) bonus") |
| 57 | q.ColumnExpr("sum(partner_bonus_expense) bonus_expense") | 57 | q.ColumnExpr("sum(partner_bonus_expense) bonus_expense") |
| 58 | + q.ColumnExpr("sum(plan_order_amount) total_order_amount") | ||
| 58 | if option.PartnerId > 0 { | 59 | if option.PartnerId > 0 { |
| 59 | q.Where(`"order_base".partner_id =?`, option.PartnerId) | 60 | q.Where(`"order_base".partner_id =?`, option.PartnerId) |
| 60 | } | 61 | } |
| @@ -64,7 +65,7 @@ func (dao *OrderBaseDao) OrderBonusStatics(option domain.OrderBonusQuery) (rsp d | @@ -64,7 +65,7 @@ func (dao *OrderBaseDao) OrderBonusStatics(option domain.OrderBonusQuery) (rsp d | ||
| 64 | if len(option.InPartnerIds) > 0 { | 65 | if len(option.InPartnerIds) > 0 { |
| 65 | q.Where(`"order_base".partner_id in (?)`, pg.In(option.InPartnerIds)) | 66 | q.Where(`"order_base".partner_id in (?)`, pg.In(option.InPartnerIds)) |
| 66 | } | 67 | } |
| 67 | - err = q.Select(&rsp.Total, &rsp.Bonus, &rsp.BonusExpense) | 68 | + err = q.Select(&rsp.Total, &rsp.Bonus, &rsp.BonusExpense, &rsp.TotalOrderAmount) |
| 68 | return | 69 | return |
| 69 | } | 70 | } |
| 70 | 71 |
| @@ -2,6 +2,8 @@ package dao | @@ -2,6 +2,8 @@ package dao | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | 4 | "fmt" |
| 5 | + "github.com/go-pg/pg/v10" | ||
| 6 | + "github.com/go-pg/pg/v10/orm" | ||
| 5 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/models" | 7 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/models" |
| 6 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction" | 8 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction" |
| 7 | . "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" | 9 | . "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" |
| @@ -25,6 +27,33 @@ func (dao *PartnerInfoDao) Update(queryOptions map[string]interface{}) error { | @@ -25,6 +27,33 @@ func (dao *PartnerInfoDao) Update(queryOptions map[string]interface{}) error { | ||
| 25 | return err | 27 | return err |
| 26 | } | 28 | } |
| 27 | 29 | ||
| 30 | +func (dao *PartnerInfoDao) PartnerStatic(queryOptions map[string]interface{}) (count int, err error) { | ||
| 31 | + tx := dao.transactionContext.PgTx | ||
| 32 | + m := new(models.PartnerInfo) | ||
| 33 | + query := NewQuery(tx.Model(m), queryOptions) | ||
| 34 | + | ||
| 35 | + query.ColumnExpr("count(*) count") | ||
| 36 | + if inPartnerIds, ok := queryOptions["inPartnerIds"]; ok { | ||
| 37 | + query.Where("id in (?)", pg.In(inPartnerIds.([]int64))) | ||
| 38 | + } | ||
| 39 | + if inPartnerCategory, ok := queryOptions["inPartnerCategory"]; ok { | ||
| 40 | + query.Where(`partner_info.partner_category_infos @>'[{"id":?}]'`, inPartnerCategory) | ||
| 41 | + } | ||
| 42 | + // 多个合伙人类型 | ||
| 43 | + if inPartnerCategory, ok := queryOptions["inPartnerCategories"]; ok { | ||
| 44 | + query.Query = query.WhereGroup(func(q *orm.Query) (*orm.Query, error) { | ||
| 45 | + if arrayInPartnerCategory, ok := inPartnerCategory.([]int64); ok { | ||
| 46 | + for i := range arrayInPartnerCategory { | ||
| 47 | + q.WhereOr(`partner_info.partner_category_infos @>'[{"id":?}]')`, arrayInPartnerCategory[i]) | ||
| 48 | + } | ||
| 49 | + } | ||
| 50 | + return q, nil | ||
| 51 | + }) | ||
| 52 | + } | ||
| 53 | + err = query.Select(&count) | ||
| 54 | + return | ||
| 55 | +} | ||
| 56 | + | ||
| 28 | //func(dao *PartnerInfoDao)PartnerCompanyInfo(queryOptions map[string]interface{})(values map[string]interface{},err error){ | 57 | //func(dao *PartnerInfoDao)PartnerCompanyInfo(queryOptions map[string]interface{})(values map[string]interface{},err error){ |
| 29 | //// tx := dao.transactionContext.PgTx | 58 | //// tx := dao.transactionContext.PgTx |
| 30 | //// m := new(models.PartnerInfo) | 59 | //// m := new(models.PartnerInfo) |
| @@ -2,6 +2,7 @@ package repository | @@ -2,6 +2,7 @@ package repository | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "github.com/go-pg/pg/v10" | 4 | "github.com/go-pg/pg/v10" |
| 5 | + "github.com/go-pg/pg/v10/orm" | ||
| 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" |
| @@ -86,6 +87,17 @@ func (repository *PartnerInfoRepository) Find(queryOptions map[string]interface{ | @@ -86,6 +87,17 @@ func (repository *PartnerInfoRepository) Find(queryOptions map[string]interface{ | ||
| 86 | if inPartnerIds, ok := queryOptions["inPartnerIds"]; ok { | 87 | if inPartnerIds, ok := queryOptions["inPartnerIds"]; ok { |
| 87 | query.Where("id in (?)", pg.In(inPartnerIds.([]int64))) | 88 | query.Where("id in (?)", pg.In(inPartnerIds.([]int64))) |
| 88 | } | 89 | } |
| 90 | + // 合伙人类型 | ||
| 91 | + if inPartnerCategory, ok := queryOptions["inPartnerCategory"]; ok { | ||
| 92 | + query.Query = query.WhereGroup(func(q *orm.Query) (*orm.Query, error) { | ||
| 93 | + if arrayInPartnerCategory, ok := inPartnerCategory.([]int64); ok { | ||
| 94 | + for i := range arrayInPartnerCategory { | ||
| 95 | + q.WhereOr(`partner_info.partner_category_infos @>'[{"id":?}]')`, arrayInPartnerCategory[i]) | ||
| 96 | + } | ||
| 97 | + } | ||
| 98 | + return q, nil | ||
| 99 | + }) | ||
| 100 | + } | ||
| 89 | var err error | 101 | var err error |
| 90 | if query.AffectRow, err = query.SelectAndCount(); err != nil { | 102 | if query.AffectRow, err = query.SelectAndCount(); err != nil { |
| 91 | return 0, PartnerInfos, err | 103 | return 0, PartnerInfos, err |
-
请 注册 或 登录 后发表评论