正在显示
15 个修改的文件
包含
100 行增加
和
18 行删除
@@ -56,3 +56,17 @@ func CreateImInfoRepository(transactionContext *transaction.TransactionContext) | @@ -56,3 +56,17 @@ func CreateImInfoRepository(transactionContext *transaction.TransactionContext) | ||
56 | func CreateImCustomerServiceRepository(transactionContext *transaction.TransactionContext) (domain.ImCustomerServiceRepository, error) { | 56 | func CreateImCustomerServiceRepository(transactionContext *transaction.TransactionContext) (domain.ImCustomerServiceRepository, error) { |
57 | return repository.NewImCustomerServiceRepository(transactionContext) | 57 | return repository.NewImCustomerServiceRepository(transactionContext) |
58 | } | 58 | } |
59 | + | ||
60 | +// 合伙人类型 | ||
61 | +func CreatePartnerCategoryInfoRepository(transactionContext *transaction.TransactionContext) (domain.PartnerCategoryInfoRepository, error) { | ||
62 | + return repository.NewPartnerCategoryInfoRepository(transactionContext) | ||
63 | +} | ||
64 | + | ||
65 | +// 高管 | ||
66 | +func CreateUsersRepository(transactionContext *transaction.TransactionContext) (domain.UsersRepository, error) { | ||
67 | + return repository.NewUsersRepository(transactionContext) | ||
68 | +} | ||
69 | + | ||
70 | +func CreateBusinessBonusRepository(transactionContext *transaction.TransactionContext) (domain.BusinessBonusRepository, error) { | ||
71 | + return repository.NewBusinessBonusRepository(transactionContext) | ||
72 | +} |
1 | package order | 1 | package order |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | + "fmt" | ||
4 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory" | 5 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory" |
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/utils" | 7 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" |
@@ -117,8 +118,11 @@ func orderTotalStatic(order *domain.OrderBase) interface{} { | @@ -117,8 +118,11 @@ func orderTotalStatic(order *domain.OrderBase) interface{} { | ||
117 | // 订单统计 | 118 | // 订单统计 |
118 | func Statistics(header *protocol.RequestHeader, request *protocol.OrderStatisticsRequest) (rsp *protocol.OrderStatisticsResponse, err error) { | 119 | func Statistics(header *protocol.RequestHeader, request *protocol.OrderStatisticsRequest) (rsp *protocol.OrderStatisticsResponse, err error) { |
119 | var ( | 120 | var ( |
120 | - transactionContext, _ = factory.CreateTransactionContext(nil) | ||
121 | - OrderDao, _ = factory.CreateOrderBaseDao(transactionContext) | 121 | + transactionContext, _ = factory.CreateTransactionContext(nil) |
122 | + OrderDao, _ = factory.CreateOrderBaseDao(transactionContext) | ||
123 | + PartnerInfoRepository, _ = factory.CreatePartnerInfoRepositoryIn(transactionContext) | ||
124 | + partnerInfo *domain.PartnerInfo | ||
125 | + orderBonus domain.OrderBonusResponse | ||
122 | ) | 126 | ) |
123 | if err = transactionContext.StartTransaction(); err != nil { | 127 | if err = transactionContext.StartTransaction(); err != nil { |
124 | return nil, err | 128 | return nil, err |
@@ -127,14 +131,11 @@ func Statistics(header *protocol.RequestHeader, request *protocol.OrderStatistic | @@ -127,14 +131,11 @@ func Statistics(header *protocol.RequestHeader, request *protocol.OrderStatistic | ||
127 | transactionContext.RollbackTransaction() | 131 | transactionContext.RollbackTransaction() |
128 | }() | 132 | }() |
129 | rsp = &protocol.OrderStatisticsResponse{Statistics: protocol.OrderStatics{}} | 133 | rsp = &protocol.OrderStatisticsResponse{Statistics: protocol.OrderStatics{}} |
130 | - //if rsp.Statistics.TodayIntentionQuantity, rsp.Statistics.TodayIntentionMoney, err = OrderDao.OrderStatics(&domain.OrderStaticQuery{ | ||
131 | - // BeginTime: utils.GetDayBegin().Unix() * 1000, | ||
132 | - // EndTime: utils.GetDayEnd().Unix() * 1000, | ||
133 | - // OrderType: domain.OrderIntention, | ||
134 | - // PartnerId: header.UserId, | ||
135 | - //}); err != nil { | ||
136 | - // return | ||
137 | - //} | 134 | + if partnerInfo, err := PartnerInfoRepository.FindOne(map[string]interface{}{"id": header.UserId}); err != nil { |
135 | + err = protocol.NewCustomMessage(1, fmt.Sprintf("%v %v", "用户不存在:", header.UserId)) | ||
136 | + return | ||
137 | + } | ||
138 | + | ||
138 | if rsp.Statistics.TodayRealQuantity, rsp.Statistics.TodayRealMoney, err = OrderDao.OrderStatics(&domain.OrderStaticQuery{ | 139 | if rsp.Statistics.TodayRealQuantity, rsp.Statistics.TodayRealMoney, err = OrderDao.OrderStatics(&domain.OrderStaticQuery{ |
139 | BeginTime: utils.GetDayBegin().Unix() * 1000, | 140 | BeginTime: utils.GetDayBegin().Unix() * 1000, |
140 | EndTime: utils.GetDayEnd().Unix() * 1000, | 141 | EndTime: utils.GetDayEnd().Unix() * 1000, |
@@ -152,6 +153,12 @@ func Statistics(header *protocol.RequestHeader, request *protocol.OrderStatistic | @@ -152,6 +153,12 @@ func Statistics(header *protocol.RequestHeader, request *protocol.OrderStatistic | ||
152 | } | 153 | } |
153 | rsp.Statistics.TodayRealMoney = utils.Decimal(rsp.Statistics.TodayRealMoney) | 154 | rsp.Statistics.TodayRealMoney = utils.Decimal(rsp.Statistics.TodayRealMoney) |
154 | rsp.Statistics.CumulativeMoney = utils.Decimal(rsp.Statistics.CumulativeMoney) | 155 | rsp.Statistics.CumulativeMoney = utils.Decimal(rsp.Statistics.CumulativeMoney) |
156 | + | ||
157 | + //事业分红/业务分红 | ||
158 | + //var enterpriseBonus,businessBonus float64 | ||
159 | + //if orderBonus,err= OrderDao.OrderBonusStatics(domain.OrderBonusQuery{PartnerId:header.UserId});e==nil{ | ||
160 | + // | ||
161 | + //} | ||
155 | err = transactionContext.CommitTransaction() | 162 | err = transactionContext.CommitTransaction() |
156 | return | 163 | return |
157 | } | 164 | } |
@@ -9,6 +9,8 @@ import ( | @@ -9,6 +9,8 @@ import ( | ||
9 | type OrderBase struct { | 9 | type OrderBase struct { |
10 | //表id | 10 | //表id |
11 | Id int64 | 11 | Id int64 |
12 | + // 公司id | ||
13 | + CompanyId int64 `json:"companyId"` | ||
12 | //订单类型 1:实际订单 2:意向订单 | 14 | //订单类型 1:实际订单 2:意向订单 |
13 | OrderType int `pg:",notnull,default:1"` | 15 | OrderType int `pg:",notnull,default:1"` |
14 | //订单编号 | 16 | //订单编号 |
@@ -20,3 +20,19 @@ type DividendOrdersQuery struct { | @@ -20,3 +20,19 @@ type DividendOrdersQuery struct { | ||
20 | StartTime int64 `json:"startTime" valid:"Required"` | 20 | StartTime int64 `json:"startTime" valid:"Required"` |
21 | EndTime int64 `json:"endTime" valid:"Required"` | 21 | EndTime int64 `json:"endTime" valid:"Required"` |
22 | } | 22 | } |
23 | + | ||
24 | +// 订单分红统计-查询 | ||
25 | +type OrderBonusQuery struct { | ||
26 | + PartnerId int64 `json:"partnerId,omitempty"` | ||
27 | + CompanyId int64 `json:"companyId,omitempty"` | ||
28 | +} | ||
29 | + | ||
30 | +// 订单分红统计-应答 | ||
31 | +type OrderBonusResponse struct { | ||
32 | + // 应收分红 | ||
33 | + Bonus float64 `json:"partnerId,omitempty"` | ||
34 | + // 订单数量 | ||
35 | + Total int64 `json:"companyId,omitempty"` | ||
36 | + // 分红支出 | ||
37 | + BonusExpense float64 `json:"bonusExpense,omitempty"` | ||
38 | +} |
@@ -12,6 +12,8 @@ type PartnerInfoRepository interface { | @@ -12,6 +12,8 @@ type PartnerInfoRepository interface { | ||
12 | type PartnerInfo struct { | 12 | type PartnerInfo struct { |
13 | // 合伙人ID | 13 | // 合伙人ID |
14 | Id int64 `json:"id"` | 14 | Id int64 `json:"id"` |
15 | + // 公司id | ||
16 | + CompanyId int64 `json:"companyId"` | ||
15 | // 合伙人姓名 | 17 | // 合伙人姓名 |
16 | PartnerName string `json:"partnerName"` | 18 | PartnerName string `json:"partnerName"` |
17 | // 登录账号 | 19 | // 登录账号 |
@@ -22,7 +24,6 @@ type PartnerInfo struct { | @@ -22,7 +24,6 @@ type PartnerInfo struct { | ||
22 | Status int `json:"status"` | 24 | Status int `json:"status"` |
23 | // 合伙类别 (1.事业合伙人 2.业务合伙人 3.研发合伙人) | 25 | // 合伙类别 (1.事业合伙人 2.业务合伙人 3.研发合伙人) |
24 | PartnerCategory int `json:"partnerCategory"` | 26 | PartnerCategory int `json:"partnerCategory"` |
25 | - | ||
26 | //所属区域信息 | 27 | //所属区域信息 |
27 | RegionInfo *RegionInfo `json:"regionId"` | 28 | RegionInfo *RegionInfo `json:"regionId"` |
28 | //合作时间 | 29 | //合作时间 |
@@ -31,7 +32,6 @@ type PartnerInfo struct { | @@ -31,7 +32,6 @@ type PartnerInfo struct { | ||
31 | CreateAt time.Time `json:"createAt"` | 32 | CreateAt time.Time `json:"createAt"` |
32 | //更新时间 | 33 | //更新时间 |
33 | UpdateAt time.Time `json:"updateAt"` | 34 | UpdateAt time.Time `json:"updateAt"` |
34 | - | ||
35 | //关联业务员 | 35 | //关联业务员 |
36 | Salesman []*Salesman `json:"salesman"` | 36 | Salesman []*Salesman `json:"salesman"` |
37 | //合伙人分类信息 | 37 | //合伙人分类信息 |
@@ -43,6 +43,27 @@ func (dao *OrderBaseDao) OrderStatics(option *domain.OrderStaticQuery) (count in | @@ -43,6 +43,27 @@ func (dao *OrderBaseDao) OrderStatics(option *domain.OrderStaticQuery) (count in | ||
43 | return | 43 | return |
44 | } | 44 | } |
45 | 45 | ||
46 | +//订单分红统计 | ||
47 | +func (dao *OrderBaseDao) OrderBonusStatics(option domain.OrderBonusQuery) (rsp domain.OrderBonusResponse, err error) { | ||
48 | + rsp = domain.OrderBonusResponse{} | ||
49 | + if option.PartnerId == 0 && option.CompanyId == 0 { | ||
50 | + return | ||
51 | + } | ||
52 | + tx := dao.transactionContext.PgTx | ||
53 | + q := tx.Model(new(models.OrderBase)) | ||
54 | + q.ExcludeColumn("count(*) count") | ||
55 | + q.ExcludeColumn("sum(plan_partner_bonus) bonus") | ||
56 | + q.ExcludeColumn("sum(bonus_expense) bonus_expense") | ||
57 | + if option.PartnerId > 0 { | ||
58 | + q.Where(`"order_base".partner_id =?`, option.PartnerId) | ||
59 | + } | ||
60 | + if option.CompanyId > 0 { | ||
61 | + q.Where(`"order_base".company_id =?`, option.CompanyId) | ||
62 | + } | ||
63 | + err = q.Select(&rsp.Total, &rsp.Bonus, &rsp.BonusExpense) | ||
64 | + return | ||
65 | +} | ||
66 | + | ||
46 | //分红订单 | 67 | //分红订单 |
47 | func (dao *OrderBaseDao) DividendOrders(option *domain.DividendOrdersQueryOption) (count int, domainOrders []*domain.OrderBase, err error) { | 68 | func (dao *OrderBaseDao) DividendOrders(option *domain.DividendOrdersQueryOption) (count int, domainOrders []*domain.OrderBase, err error) { |
48 | tx := dao.transactionContext.PgTx | 69 | tx := dao.transactionContext.PgTx |
@@ -10,6 +10,8 @@ type OrderBase struct { | @@ -10,6 +10,8 @@ type OrderBase struct { | ||
10 | tableName struct{} `pg:"order_base"` | 10 | tableName struct{} `pg:"order_base"` |
11 | //表id | 11 | //表id |
12 | Id int64 `pg:",pk"` | 12 | Id int64 `pg:",pk"` |
13 | + // 公司id | ||
14 | + CompanyId int64 | ||
13 | //订单类型 1:实际订单 2:意向订单 | 15 | //订单类型 1:实际订单 2:意向订单 |
14 | OrderType int `pg:",notnull,default:1"` | 16 | OrderType int `pg:",notnull,default:1"` |
15 | //订单编号 | 17 | //订单编号 |
@@ -5,6 +5,8 @@ type OrderGood struct { | @@ -5,6 +5,8 @@ type OrderGood struct { | ||
5 | tableName struct{} `pg:"order_good"` | 5 | tableName struct{} `pg:"order_good"` |
6 | //货品id | 6 | //货品id |
7 | Id int64 `pg:",pk"` | 7 | Id int64 `pg:",pk"` |
8 | + // 公司id | ||
9 | + CompanyId int64 | ||
8 | //所属订单id | 10 | //所属订单id |
9 | OrderId int64 | 11 | OrderId int64 |
10 | //货品名称 长度可能较长 | 12 | //货品名称 长度可能较长 |
@@ -10,6 +10,8 @@ type PartnerInfo struct { | @@ -10,6 +10,8 @@ type PartnerInfo struct { | ||
10 | tableName struct{} `pg:"partner_info"` | 10 | tableName struct{} `pg:"partner_info"` |
11 | // 合伙人ID | 11 | // 合伙人ID |
12 | Id int64 `pg:",pk"` | 12 | Id int64 `pg:",pk"` |
13 | + // 公司id | ||
14 | + CompanyId int64 | ||
13 | // 合伙人姓名 | 15 | // 合伙人姓名 |
14 | PartnerName string | 16 | PartnerName string |
15 | // 登录账号 | 17 | // 登录账号 |
@@ -6,8 +6,10 @@ import ( | @@ -6,8 +6,10 @@ import ( | ||
6 | ) | 6 | ) |
7 | 7 | ||
8 | type UserTokenClaims struct { | 8 | type UserTokenClaims struct { |
9 | - UserId int64 `json:"userId"` | ||
10 | - Phone string `json:"phone"` | 9 | + UserId int64 `json:"userId"` |
10 | + CompanyId int64 `json:"companyId"` | ||
11 | + AdminType int `json:"adminType"` //用户类型 1:合伙人 2:高管 | ||
12 | + Phone string `json:"phone"` | ||
11 | jwt.StandardClaims | 13 | jwt.StandardClaims |
12 | } | 14 | } |
13 | 15 | ||
@@ -23,10 +25,12 @@ func ParseJWTToken(token string) (*UserTokenClaims, error) { | @@ -23,10 +25,12 @@ func ParseJWTToken(token string) (*UserTokenClaims, error) { | ||
23 | } | 25 | } |
24 | if tokenClaims != nil { | 26 | if tokenClaims != nil { |
25 | if claim, ok := tokenClaims.Claims.(*UserTokenClaims); ok && tokenClaims.Valid { | 27 | if claim, ok := tokenClaims.Claims.(*UserTokenClaims); ok && tokenClaims.Valid { |
28 | + // TODO:多类型用户登录 | ||
29 | + claim.CompanyId = 1 | ||
30 | + claim.AdminType = 1 | ||
26 | return claim, nil | 31 | return claim, nil |
27 | } | 32 | } |
28 | } | 33 | } |
29 | - | ||
30 | return nil, err | 34 | return nil, err |
31 | } | 35 | } |
32 | 36 |
@@ -80,6 +80,8 @@ func (this *BaseController) GetRequestHeader(ctx *context.Context) *protocol.Req | @@ -80,6 +80,8 @@ func (this *BaseController) GetRequestHeader(ctx *context.Context) *protocol.Req | ||
80 | if len(h.AccessToken) > 0 { | 80 | if len(h.AccessToken) > 0 { |
81 | if claim, err := utils.ParseJWTToken(h.AccessToken); err == nil { | 81 | if claim, err := utils.ParseJWTToken(h.AccessToken); err == nil { |
82 | h.UserId = claim.UserId | 82 | h.UserId = claim.UserId |
83 | + h.CompanyId = claim.CompanyId | ||
84 | + h.AdminType = claim.AdminType | ||
83 | } | 85 | } |
84 | } | 86 | } |
85 | return h | 87 | return h |
@@ -54,6 +54,12 @@ type OrderStatics struct { | @@ -54,6 +54,12 @@ type OrderStatics struct { | ||
54 | TodayRealMoney float64 `json:"todayRealMoney"` //今日新增实发订单金额 | 54 | TodayRealMoney float64 `json:"todayRealMoney"` //今日新增实发订单金额 |
55 | CumulativeQuantity int `json:"cumulativeQuantity"` //累计实发订单 | 55 | CumulativeQuantity int `json:"cumulativeQuantity"` //累计实发订单 |
56 | CumulativeMoney float64 `json:"cumulativeMoney"` //累计实发订单金额 | 56 | CumulativeMoney float64 `json:"cumulativeMoney"` //累计实发订单金额 |
57 | + | ||
58 | + //v0.3.0 新增加 | ||
59 | + CareerPrecent float64 `json:"careerPrecent"` // 事业占比 | ||
60 | + BusinessPrecent float64 `json:"businessPrecent"` // 业务占比 | ||
61 | + DevelopPrecent float64 `json:"developPrecent"` // 研发占比 | ||
62 | + BusinessMoney float64 `json:"businessMoney"` // 业务分红累计 | ||
57 | } | 63 | } |
58 | 64 | ||
59 | /*OrderList */ | 65 | /*OrderList */ |
@@ -9,8 +9,10 @@ type RequestHeader struct { | @@ -9,8 +9,10 @@ type RequestHeader struct { | ||
9 | AppProject string | 9 | AppProject string |
10 | AccessToken string | 10 | AccessToken string |
11 | Uid int64 //用户基本信息Id | 11 | Uid int64 //用户基本信息Id |
12 | - CompanyId int64 | ||
13 | - UserId int64 //UserId 唯一标识,唯一关联所有用户信息(=user_company.id) | 12 | + |
13 | + CompanyId int64 //公司编号 | ||
14 | + UserId int64 //UserId 唯一标识,(类型是合伙人对应表partner_info.id,类型是高层对应表users.id) | ||
15 | + AdminType int //合伙人:1 高管:2 | ||
14 | 16 | ||
15 | requestId string //请求编号 md5 | 17 | requestId string //请求编号 md5 |
16 | reqIndex int64 //请求链序号 | 18 | reqIndex int64 //请求链序号 |
-
请 注册 或 登录 后发表评论