作者 yangfu

增加:订单统计

... ... @@ -56,3 +56,17 @@ func CreateImInfoRepository(transactionContext *transaction.TransactionContext)
func CreateImCustomerServiceRepository(transactionContext *transaction.TransactionContext) (domain.ImCustomerServiceRepository, error) {
return repository.NewImCustomerServiceRepository(transactionContext)
}
// 合伙人类型
func CreatePartnerCategoryInfoRepository(transactionContext *transaction.TransactionContext) (domain.PartnerCategoryInfoRepository, error) {
return repository.NewPartnerCategoryInfoRepository(transactionContext)
}
// 高管
func CreateUsersRepository(transactionContext *transaction.TransactionContext) (domain.UsersRepository, error) {
return repository.NewUsersRepository(transactionContext)
}
func CreateBusinessBonusRepository(transactionContext *transaction.TransactionContext) (domain.BusinessBonusRepository, error) {
return repository.NewBusinessBonusRepository(transactionContext)
}
... ...
package order
import (
"fmt"
"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/utils"
... ... @@ -117,8 +118,11 @@ 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)
PartnerInfoRepository, _ = factory.CreatePartnerInfoRepositoryIn(transactionContext)
partnerInfo *domain.PartnerInfo
orderBonus domain.OrderBonusResponse
)
if err = transactionContext.StartTransaction(); err != nil {
return nil, err
... ... @@ -127,14 +131,11 @@ func Statistics(header *protocol.RequestHeader, request *protocol.OrderStatistic
transactionContext.RollbackTransaction()
}()
rsp = &protocol.OrderStatisticsResponse{Statistics: protocol.OrderStatics{}}
//if rsp.Statistics.TodayIntentionQuantity, rsp.Statistics.TodayIntentionMoney, err = OrderDao.OrderStatics(&domain.OrderStaticQuery{
// BeginTime: utils.GetDayBegin().Unix() * 1000,
// EndTime: utils.GetDayEnd().Unix() * 1000,
// OrderType: domain.OrderIntention,
// PartnerId: header.UserId,
//}); err != nil {
// return
//}
if partnerInfo, err := PartnerInfoRepository.FindOne(map[string]interface{}{"id": header.UserId}); err != nil {
err = protocol.NewCustomMessage(1, fmt.Sprintf("%v %v", "用户不存在:", header.UserId))
return
}
if rsp.Statistics.TodayRealQuantity, rsp.Statistics.TodayRealMoney, err = OrderDao.OrderStatics(&domain.OrderStaticQuery{
BeginTime: utils.GetDayBegin().Unix() * 1000,
EndTime: utils.GetDayEnd().Unix() * 1000,
... ... @@ -152,6 +153,12 @@ func Statistics(header *protocol.RequestHeader, request *protocol.OrderStatistic
}
rsp.Statistics.TodayRealMoney = utils.Decimal(rsp.Statistics.TodayRealMoney)
rsp.Statistics.CumulativeMoney = utils.Decimal(rsp.Statistics.CumulativeMoney)
//事业分红/业务分红
//var enterpriseBonus,businessBonus float64
//if orderBonus,err= OrderDao.OrderBonusStatics(domain.OrderBonusQuery{PartnerId:header.UserId});e==nil{
//
//}
err = transactionContext.CommitTransaction()
return
}
... ...
... ... @@ -9,6 +9,8 @@ import (
type OrderBase struct {
//表id
Id int64
// 公司id
CompanyId int64 `json:"companyId"`
//订单类型 1:实际订单 2:意向订单
OrderType int `pg:",notnull,default:1"`
//订单编号
... ...
... ... @@ -4,6 +4,8 @@ package domain
type OrderGood struct {
//货品id
Id int64
// 公司id
CompanyId int64 `json:"companyId"`
//所属订单id
OrderId int64
//货品名称 长度可能较长
... ...
... ... @@ -20,3 +20,19 @@ type DividendOrdersQuery struct {
StartTime int64 `json:"startTime" valid:"Required"`
EndTime int64 `json:"endTime" valid:"Required"`
}
// 订单分红统计-查询
type OrderBonusQuery struct {
PartnerId int64 `json:"partnerId,omitempty"`
CompanyId int64 `json:"companyId,omitempty"`
}
// 订单分红统计-应答
type OrderBonusResponse struct {
// 应收分红
Bonus float64 `json:"partnerId,omitempty"`
// 订单数量
Total int64 `json:"companyId,omitempty"`
// 分红支出
BonusExpense float64 `json:"bonusExpense,omitempty"`
}
... ...
... ... @@ -12,6 +12,8 @@ type PartnerInfoRepository interface {
type PartnerInfo struct {
// 合伙人ID
Id int64 `json:"id"`
// 公司id
CompanyId int64 `json:"companyId"`
// 合伙人姓名
PartnerName string `json:"partnerName"`
// 登录账号
... ... @@ -22,7 +24,6 @@ type PartnerInfo struct {
Status int `json:"status"`
// 合伙类别 (1.事业合伙人 2.业务合伙人 3.研发合伙人)
PartnerCategory int `json:"partnerCategory"`
//所属区域信息
RegionInfo *RegionInfo `json:"regionId"`
//合作时间
... ... @@ -31,7 +32,6 @@ type PartnerInfo struct {
CreateAt time.Time `json:"createAt"`
//更新时间
UpdateAt time.Time `json:"updateAt"`
//关联业务员
Salesman []*Salesman `json:"salesman"`
//合伙人分类信息
... ...
... ... @@ -43,6 +43,27 @@ func (dao *OrderBaseDao) OrderStatics(option *domain.OrderStaticQuery) (count in
return
}
//订单分红统计
func (dao *OrderBaseDao) OrderBonusStatics(option domain.OrderBonusQuery) (rsp domain.OrderBonusResponse, err error) {
rsp = domain.OrderBonusResponse{}
if option.PartnerId == 0 && option.CompanyId == 0 {
return
}
tx := dao.transactionContext.PgTx
q := tx.Model(new(models.OrderBase))
q.ExcludeColumn("count(*) count")
q.ExcludeColumn("sum(plan_partner_bonus) bonus")
q.ExcludeColumn("sum(bonus_expense) bonus_expense")
if option.PartnerId > 0 {
q.Where(`"order_base".partner_id =?`, option.PartnerId)
}
if option.CompanyId > 0 {
q.Where(`"order_base".company_id =?`, option.CompanyId)
}
err = q.Select(&rsp.Total, &rsp.Bonus, &rsp.BonusExpense)
return
}
//分红订单
func (dao *OrderBaseDao) DividendOrders(option *domain.DividendOrdersQueryOption) (count int, domainOrders []*domain.OrderBase, err error) {
tx := dao.transactionContext.PgTx
... ...
... ... @@ -10,6 +10,8 @@ type OrderBase struct {
tableName struct{} `pg:"order_base"`
//表id
Id int64 `pg:",pk"`
// 公司id
CompanyId int64
//订单类型 1:实际订单 2:意向订单
OrderType int `pg:",notnull,default:1"`
//订单编号
... ...
... ... @@ -5,6 +5,8 @@ type OrderGood struct {
tableName struct{} `pg:"order_good"`
//货品id
Id int64 `pg:",pk"`
// 公司id
CompanyId int64
//所属订单id
OrderId int64
//货品名称 长度可能较长
... ...
... ... @@ -10,6 +10,8 @@ type PartnerInfo struct {
tableName struct{} `pg:"partner_info"`
// 合伙人ID
Id int64 `pg:",pk"`
// 公司id
CompanyId int64
// 合伙人姓名
PartnerName string
// 登录账号
... ...
... ... @@ -4,7 +4,7 @@ import "time"
// 公司信息
type Company struct {
tableName struct{} `pg:"Company"`
tableName struct{} `pg:"company"`
// 唯一标识
Id int64
// 名称
... ...
... ... @@ -6,8 +6,10 @@ import (
)
type UserTokenClaims struct {
UserId int64 `json:"userId"`
Phone string `json:"phone"`
UserId int64 `json:"userId"`
CompanyId int64 `json:"companyId"`
AdminType int `json:"adminType"` //用户类型 1:合伙人 2:高管
Phone string `json:"phone"`
jwt.StandardClaims
}
... ... @@ -23,10 +25,12 @@ func ParseJWTToken(token string) (*UserTokenClaims, error) {
}
if tokenClaims != nil {
if claim, ok := tokenClaims.Claims.(*UserTokenClaims); ok && tokenClaims.Valid {
// TODO:多类型用户登录
claim.CompanyId = 1
claim.AdminType = 1
return claim, nil
}
}
return nil, err
}
... ...
... ... @@ -80,6 +80,8 @@ func (this *BaseController) GetRequestHeader(ctx *context.Context) *protocol.Req
if len(h.AccessToken) > 0 {
if claim, err := utils.ParseJWTToken(h.AccessToken); err == nil {
h.UserId = claim.UserId
h.CompanyId = claim.CompanyId
h.AdminType = claim.AdminType
}
}
return h
... ...
... ... @@ -54,6 +54,12 @@ type OrderStatics struct {
TodayRealMoney float64 `json:"todayRealMoney"` //今日新增实发订单金额
CumulativeQuantity int `json:"cumulativeQuantity"` //累计实发订单
CumulativeMoney float64 `json:"cumulativeMoney"` //累计实发订单金额
//v0.3.0 新增加
CareerPrecent float64 `json:"careerPrecent"` // 事业占比
BusinessPrecent float64 `json:"businessPrecent"` // 业务占比
DevelopPrecent float64 `json:"developPrecent"` // 研发占比
BusinessMoney float64 `json:"businessMoney"` // 业务分红累计
}
/*OrderList */
... ...
... ... @@ -9,8 +9,10 @@ type RequestHeader struct {
AppProject string
AccessToken string
Uid int64 //用户基本信息Id
CompanyId int64
UserId int64 //UserId 唯一标识,唯一关联所有用户信息(=user_company.id)
CompanyId int64 //公司编号
UserId int64 //UserId 唯一标识,(类型是合伙人对应表partner_info.id,类型是高层对应表users.id)
AdminType int //合伙人:1 高管:2
requestId string //请求编号 md5
reqIndex int64 //请求链序号
... ...