作者 yangfu

Merge remote-tracking branch 'origin/test'

... ... @@ -351,10 +351,12 @@ func CenterCompanys(header *protocol.RequestHeader, request *protocolx.CenterCom
break
case protocol.LoginByCredentials:
//凭证是否存在
if credential, e := userAuth.NewRedisUserCredential(request.Phone).GetAuth(); e != nil || !strings.EqualFold(credential, request.Credentials) {
log.Debug("凭证过期或者已失效:", request.Phone)
err = protocol.NewErrWithMessage(4140, err)
return
if constant.DISENABLE_MULTI_DEVICE_LOGIN {
if credential, e := userAuth.NewRedisUserCredential(request.Phone).GetAuth(); e != nil || !strings.EqualFold(credential, request.Credentials) {
log.Debug("凭证过期或者已失效:", request.Phone)
err = protocol.NewErrWithMessage(4140, err)
return
}
}
if _, err = utils.ParseJWTToken(request.Credentials); err != nil {
err = protocol.NewErrWithMessage(4140, err)
... ... @@ -419,10 +421,12 @@ func Companys(header *protocol.RequestHeader, request *protocolx.CompanysRequest
return
}
//凭证是否存在
if credential, e := userAuth.NewRedisUserCredential(claim.Phone).GetAuth(); e != nil || !strings.EqualFold(credential, request.Credentials) {
log.Debug("凭证过期或者已失效:", claim.Phone)
err = protocol.NewErrWithMessage(4140, err)
return
if constant.DISENABLE_MULTI_DEVICE_LOGIN {
if credential, e := userAuth.NewRedisUserCredential(claim.Phone).GetAuth(); e != nil || !strings.EqualFold(credential, request.Credentials) {
log.Debug("凭证过期或者已失效:", claim.Phone)
err = protocol.NewErrWithMessage(4140, err)
return
}
}
loginSvr.Init(claim.Phone)
rsp.Partner, _ = loginSvr.PartnerStaticInfo()
... ... @@ -458,11 +462,13 @@ func LoginV2(header *protocol.RequestHeader, request *protocol.LoginRequestV2) (
err = protocol.NewErrWithMessage(4140, err)
return
}
//凭证是否存在
if credential, e := userAuth.NewRedisUserCredential(claim.Phone).GetAuth(); e != nil || !strings.EqualFold(credential, request.Credentials) {
log.Debug("凭证过期或者已失效:", claim.Phone)
err = protocol.NewErrWithMessage(4140, err)
return
if constant.DISENABLE_MULTI_DEVICE_LOGIN {
//凭证是否存在
if credential, e := userAuth.NewRedisUserCredential(claim.Phone).GetAuth(); e != nil || !strings.EqualFold(credential, request.Credentials) {
log.Debug("凭证过期或者已失效:", claim.Phone)
err = protocol.NewErrWithMessage(4140, err)
return
}
}
if company, e := CompanyRepository.FindOne(map[string]interface{}{"id": request.Cid, "enable": 1}); e != nil || company == nil {
err = protocol.NewErrWithMessage(10007, err)
... ...
... ... @@ -142,10 +142,10 @@ func getJoinWays(transactionContext *transaction.TransactionContext) (joinWays [
// 获取公司统计
func getStatistics(userId int64, transactionContext *transaction.TransactionContext) (interface{}, error) {
var (
UsersRepository, _ = factory.CreateUsersRepository(transactionContext)
PartnerInfoDao, _ = factory.CreatePartnerInfoDao(transactionContext)
OrderBaseDao, _ = factory.CreateOrderBaseDao(transactionContext)
BusinessBonusDao, _ = factory.CreateBusinessBonusDao(transactionContext)
UsersRepository, _ = factory.CreateUsersRepository(transactionContext)
PartnerInfoDao, _ = factory.CreatePartnerInfoDao(transactionContext)
OrderBaseDao, _ = factory.CreateOrderBaseDao(transactionContext)
//BusinessBonusDao, _ = factory.CreateBusinessBonusDao(transactionContext)
//user *domain.Users
partnerIds []int64
)
... ... @@ -156,6 +156,10 @@ func getStatistics(userId int64, transactionContext *transaction.TransactionCont
partnerIds = user.AccessPartnerIds()
}
Statistics := make(map[string]interface{})
//Statistics["developDividend"] = 0
//Statistics["developOrdersMoney"] = 0
//Statistics["appDividend"] = 0
//Statistics["appOrdersMoney"] = 0
if count, e := PartnerInfoDao.PartnerStatic(map[string]interface{}{"inPartnerIds": partnerIds, "inPartnerCategory": domain.Career}); e == nil {
Statistics["careerCount"] = count
}
... ... @@ -168,18 +172,27 @@ 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, OrderTypes: domain.UserOrderTypes(domain.Career)}); e == nil {
if bonus, e := OrderBaseDao.OrderBonusStatics(domain.OrderBonusQuery{InPartnerIds: partnerIds, OrderTypes: domain.UserOrderTypes(domain.Career), PartnerCategoryId: domain.Career}); e == nil {
Statistics["careerOrdersMoney"] = bonus.TotalOrderAmount
Statistics["careerDividend"] = bonus.Bonus
}
if businessBonus, e := BusinessBonusDao.OrderBonusStatics(domain.OrderBonusQuery{InPartnerIds: partnerIds, IsDisable: 1}); e == nil {
Statistics["businessDividend"] = businessBonus.Bonus
Statistics["businessOrdersMoney"] = businessBonus.TotalOrderAmount
if bonus, e := OrderBaseDao.OrderBonusStatics(domain.OrderBonusQuery{InPartnerIds: partnerIds, OrderTypes: domain.UserOrderTypes(domain.Career), PartnerCategoryId: domain.Business}); e == nil {
Statistics["businessOrdersMoney"] = bonus.TotalOrderAmount
Statistics["businessDividend"] = bonus.Bonus
}
Statistics["developDividend"] = 0
Statistics["developOrdersMoney"] = 0
Statistics["appDividend"] = 0
Statistics["appOrdersMoney"] = 0
if bonus, e := OrderBaseDao.OrderBonusStatics(domain.OrderBonusQuery{InPartnerIds: partnerIds, OrderTypes: domain.UserOrderTypes(domain.Career), PartnerCategoryId: domain.Develop}); e == nil {
Statistics["developOrdersMoney"] = bonus.TotalOrderAmount
Statistics["developDividend"] = bonus.Bonus
}
if bonus, e := OrderBaseDao.OrderBonusStatics(domain.OrderBonusQuery{InPartnerIds: partnerIds, OrderTypes: domain.UserOrderTypes(domain.Career), PartnerCategoryId: domain.App}); e == nil {
Statistics["appOrdersMoney"] = bonus.TotalOrderAmount
Statistics["appDividend"] = bonus.Bonus
}
//if businessBonus, e := BusinessBonusDao.OrderBonusStatics(domain.OrderBonusQuery{InPartnerIds: partnerIds, IsDisable: 1}); e == nil {
// Statistics["businessDividend"] = businessBonus.Bonus
// Statistics["businessOrdersMoney"] = businessBonus.TotalOrderAmount
//}
Statistics["totalCount"] = len(partnerIds)
return Statistics, nil
}
... ...
package company
import (
"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"
protocolx "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol/company"
userx "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol/user"
)
func PartnersV2(header *protocol.RequestHeader, request *protocolx.PartnersRequest) (rsp *protocolx.PartnersResponse, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.PartnersResponse{}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
if rsp.Partners, err = getPartnersV2(header.UserId, request, transactionContext); err != nil {
log.Error(err)
return
}
if rsp.Partners == nil {
rsp.Partners = []struct{}{}
}
err = transactionContext.CommitTransaction()
return
}
func getPartnersV2(userId int64, request *protocolx.PartnersRequest, transactionContext *transaction.TransactionContext) (interface{}, error) {
var (
UsersRepository, _ = factory.CreateUsersRepository(transactionContext)
PartnerInfo, _ = factory.CreatePartnerInfoDao(transactionContext)
user *domain.Users
err error
PartnerCategoryInfoRepository, _ = factory.CreatePartnerCategoryInfoRepository(transactionContext)
)
if user, err = UsersRepository.FindOne(map[string]interface{}{"id": userId}); err != nil {
return nil, err
}
var company *domain.Company
var CompanyResponsitory, _ = factory.CreateCompanyRepository(transactionContext)
if company, err = CompanyResponsitory.FindOne(map[string]interface{}{"id": user.CompanyId}); err != nil {
return nil, err
}
if len(user.AccessPartnerIds()) == 0 {
return nil, nil
}
mapCategoryInfo := make(map[int64]*domain.PartnerCategoryInfo)
if _, categories, e := PartnerCategoryInfoRepository.Find(nil); e == nil {
for i := range categories {
mapCategoryInfo[categories[i].Id] = categories[i]
}
}
queryOption := make(map[string]interface{})
if len(request.Districts) > 0 {
var districts []string
for i := 0; i < len(request.Districts); i++ {
districts = append(districts, request.Districts[i].Name)
}
queryOption["districts"] = districts
}
if len(request.JoinWays) > 0 {
var joinWays []int64
for i := 0; i < len(request.JoinWays); i++ {
joinWays = append(joinWays, request.JoinWays[i].Type)
}
queryOption["joinWays"] = joinWays
}
if request.StartTime > 0 {
queryOption["startTime"] = request.StartTime / 1000
}
if request.EndTime > 0 {
queryOption["endTime"] = request.EndTime / 1000
}
queryOption["limit"] = request.PageSize
queryOption["offset"] = request.PageSize * request.PageIndex
queryOption["sortByBonus"] = domain.DESC
if request.SortBy != 0 {
queryOption["sortByBonus"] = domain.ASC
}
if partners, e := PartnerInfo.Partners(user.AccessPartnerIds(), queryOption); e == nil {
var array []interface{}
for i := range partners {
mapPartners := make(map[string]interface{})
p := partners[i]
mapPartners["uid"] = p.Id
mapPartners["uname"] = p.PartnerName
var joinWays []protocolx.JoinWays
for j := range p.PartnerCategoryInfos {
c := p.PartnerCategoryInfos[j]
if v, ok := mapCategoryInfo[c.Id]; ok {
joinWays = append(joinWays, protocolx.JoinWays{Type: v.Id, Name: v.Name})
}
}
mapPartners["joinWays"] = joinWays
mapPartners["dividend"] = utils.Decimal(p.Bonus)
mapPartners["ordersCount"] = p.Total
mapPartners["ordersMoney"] = utils.Decimal(p.Amount)
mapPartners["phone"] = p.Account
partnerCompany := userx.Company{
Id: company.Id,
Name: company.Name,
Phone: company.Phone,
SerialNo: p.Id,
CooperateTime: p.CooperateTime.Unix() * 1000,
MiniProgram: nil,
District: map[string]interface{}{"id": p.RegionInfo.RegionId, "name": p.RegionInfo.RegionName},
}
if len(p.Salesman) > 0 {
partnerCompany.Salesman = map[string]interface{}{"uname": p.Salesman[0].Name, "phone": p.Salesman[0].Telephone}
} else {
partnerCompany.Salesman = map[string]interface{}{}
}
mapPartners["company"] = partnerCompany
array = append(array, mapPartners)
}
return array, nil
}
return nil, nil
}
func funcPartnerCompanyInfo(companyId int64, transactionContext *transaction.TransactionContext) (partnerCompany userx.Company, err error) {
var (
CompanyResponsitory, _ = factory.CreateCompanyRepository(transactionContext)
company *domain.Company
)
if company, err = CompanyResponsitory.FindOne(map[string]interface{}{"id": companyId}); err != nil {
return
}
partnerCompany = userx.Company{
Id: company.Id,
Name: company.Name,
Phone: company.Phone,
//SerialNo: partnerInfo.Id,
//CooperateTime: partnerInfo.CooperateTime.Unix() * 1000,
MiniProgram: nil,
//District: map[string]interface{}{"id": partnerInfo.RegionInfo.RegionId, "name": partnerInfo.RegionInfo.RegionName},
}
//if len(partnerInfo.Salesman) > 0 {
// u.CooperateCompany.Salesman = map[string]interface{}{"uname": partnerInfo.Salesman[0].Name, "phone": partnerInfo.Salesman[0].Telephone}
//} else {
// u.CooperateCompany.Salesman = map[string]interface{}{}
//}
//rspMap["user"] = u
//rsp = rspMap
return
}
... ...
... ... @@ -24,7 +24,7 @@ func Statistics(header *protocol.RequestHeader, request *protocol.DividendStatis
}()
// 事业分红统计-查询订单
_, orderAll, e := OrderBaseResponsitory.Find(utils.ObjectJsonToMap(domain.OrderQueryOption{PartnerId: header.UserId, EndTime: time.Now(), SortByCreateTime: domain.DESC, OrderTypes: domain.UserOrderTypes(domain.Career)}))
_, orderAll, e := OrderBaseResponsitory.Find(utils.ObjectJsonToMap(domain.OrderQueryOption{PartnerId: request.PartnerId, EndTime: time.Now(), SortByCreateTime: domain.DESC, OrderTypes: domain.UserOrderTypes(domain.Career)}))
if e != nil {
log.Error(e)
}
... ... @@ -40,7 +40,7 @@ func Statistics(header *protocol.RequestHeader, request *protocol.DividendStatis
bonusQuarters := QuartersBonusStatics(orderBetween, 0)
// 业务分红统计
if bonus, e := BusinessBonusRepository.FindOne(map[string]interface{}{"partner_id": header.UserId, "isDisable": 1}); e == nil {
if bonus, e := BusinessBonusRepository.FindOne(map[string]interface{}{"partner_id": request.PartnerId, "isDisable": 1}); e == nil {
bonusAll.Receivable += bonus.Bonus
bonusAll.Received += bonus.BonusHas
bonusAll.Outstanding += bonus.BonusNot
... ... @@ -125,7 +125,7 @@ func OrderList(header *protocol.RequestHeader, request *protocol.DividendOrdersR
count, orders, err = OrderDao.DividendOrders(&domain.DividendOrdersQueryOption{
OrderTypes: domain.UserOrderTypes(domain.Career),
PartnerId: header.UserId,
PartnerId: request.PartnerId,
DetailAction: request.DetailAction,
DividendAction: request.DividendAction,
//IsDisable: "0",
... ...
... ... @@ -3,10 +3,13 @@ package event
import (
"github.com/tiptok/gocomm/xa/eda"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/event/subscriber"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/constant"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain/event"
)
func InitEventCenter() {
eda.RegisterSubscribe(&event.AccessTokenEvent{}, &subscriber.AuthCacheSubscribe{})
eda.RegisterSubscribe(&event.RefreshTokenEvent{}, &subscriber.AuthCacheSubscribe{})
if constant.DISENABLE_MULTI_DEVICE_LOGIN {
eda.RegisterSubscribe(&event.AccessTokenEvent{}, &subscriber.AuthCacheSubscribe{})
eda.RegisterSubscribe(&event.RefreshTokenEvent{}, &subscriber.AuthCacheSubscribe{})
}
}
... ...
... ... @@ -132,7 +132,7 @@ func Statistics(header *protocol.RequestHeader, request *protocol.OrderStatistic
defer func() {
transactionContext.RollbackTransaction()
}()
rsp = &protocol.OrderStatisticsResponse{Statistics: protocol.OrderStatics{}}
rsp = &protocol.OrderStatisticsResponse{Statistics: &protocol.OrderStatics{}}
// 当天订单/累计订单
if rsp.Statistics.TodayRealQuantity, rsp.Statistics.TodayRealMoney, err = OrderDao.OrderStatics(&domain.OrderStaticQuery{
... ... @@ -195,10 +195,11 @@ func List(header *protocol.RequestHeader, request *protocol.OrderListRequest) (r
// 查询订单列表
queryOption := &domain.OrderQueryOption{
PartnerId: header.UserId,
Limit: request.PageSize,
Offset: request.PageSize * request.PageIndex,
SortByUpdateTime: domain.DESC,
Limit: request.PageSize,
Offset: request.PageSize * request.PageIndex,
SortByUpdateTime: domain.DESC,
PartnerId: request.PartnerId,
PartnerCategoryId: request.JoinWay,
}
if request.StartTime > 0 {
queryOption.BeginTime = time.Unix(request.StartTime/1000, 0)
... ... @@ -211,7 +212,12 @@ func List(header *protocol.RequestHeader, request *protocol.OrderListRequest) (r
total, orders, _ = OrderResponsitory.Find(utils.ObjectJsonToMap(queryOption))
if len(orders) != 0 {
for i := range orders {
rsp.List = append(rsp.List, DomainOrderToOrderListItem(orders[i]))
item := DomainOrderToOrderListItem(orders[i])
// 高管查看都是标记已读
if orders[i].PartnerId != header.UserId {
item.IsRead = 1
}
rsp.List = append(rsp.List, item)
}
}
... ... @@ -222,9 +228,10 @@ func List(header *protocol.RequestHeader, request *protocol.OrderListRequest) (r
)
//累计实发订单
cumulativeQuantity, _, err = OrderDao.OrderStatics(&domain.OrderStaticQuery{
EndTime: time.Now().Unix() * 1000,
OrderTypes: domain.UserOrderTypes(domain.Career),
PartnerId: header.UserId,
EndTime: time.Now().Unix() * 1000,
OrderTypes: domain.UserOrderTypes(domain.Career),
PartnerId: request.PartnerId,
PartnerCategoryId: request.JoinWay,
})
rsp.Total = cumulativeQuantity
}
... ...
package order
import (
"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"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol"
"time"
)
// 订单统计
func StatisticsV2(header *protocol.RequestHeader, request *protocol.OrderStatisticsRequest) (rsp *protocol.OrderStatisticsResponse, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
OrderDao, _ = factory.CreateOrderBaseDao(transactionContext)
)
if err = transactionContext.StartTransaction(); err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
rsp = &protocol.OrderStatisticsResponse{}
//事业分红/业务分红
var total float64 //,developBonus,appBonus,careerBonus, businessBonus,
if bonus, e := OrderDao.OrderBonusStatics(domain.OrderBonusQuery{PartnerId: request.PartnerId, OrderTypes: domain.UserOrderTypes(domain.Career)}); e == nil {
//careerBonus = bonus.Bonus
total += bonus.Bonus
}
calcOrderStatic := func(catId int, total float64) protocol.OrderStatic {
todayRealQuantity, todayRealMoney, _ := OrderDao.OrderStatics(&domain.OrderStaticQuery{
BeginTime: utils.GetDayBegin().Unix() * 1000,
EndTime: utils.GetDayEnd().Unix() * 1000,
OrderTypes: domain.UserOrderTypes(domain.Career),
PartnerId: request.PartnerId,
PartnerCategoryId: catId,
})
cumulativeQuantity, cumulativeMoney, _ := OrderDao.OrderStatics(&domain.OrderStaticQuery{
EndTime: time.Now().Unix() * 1000,
OrderTypes: domain.UserOrderTypes(domain.Career),
PartnerId: request.PartnerId,
PartnerCategoryId: catId,
})
bonus, _ := OrderDao.OrderBonusStatics(domain.OrderBonusQuery{PartnerId: request.PartnerId, OrderTypes: domain.UserOrderTypes(domain.Career), PartnerCategoryId: catId})
var percent float64 = 0
if bonus.Bonus != 0 {
percent = utils.DecimalToNumber(bonus.Bonus * 100 / total)
}
return protocol.OrderStatic{
Percent: percent,
TodayRealQuantity: todayRealQuantity,
TodayRealMoney: utils.Decimal(todayRealMoney),
CumulativeQuantity: cumulativeQuantity,
CumulativeMoney: utils.Decimal(cumulativeMoney),
}
}
rsp.Career = calcOrderStatic(domain.Career, total)
rsp.Business = calcOrderStatic(domain.Business, total)
rsp.Develop = calcOrderStatic(domain.Develop, total)
rsp.App = calcOrderStatic(domain.App, total)
err = transactionContext.CommitTransaction()
return
}
... ...
... ... @@ -220,7 +220,9 @@ func UserInfoV2(header *protocol.RequestHeader, request *protocol.UserInfoReques
miniProgram["userName"] = company.Applets[0].Id
miniProgram["path"] = fmt.Sprintf("%v?inviter_id=%v&company_id=%v", company.Applets[0].URL, partnerInfo.Id, partnerInfo.CompanyId)
miniProgram["hdImageUrl"] = constant.SHARE_SHOP_PREVIEW_IMADGE
//miniProgram["miniprogramType"] = constant.WEHAT_MINI_PROGRAM_VERSION_TYPE
if len(company.Applets[0].ImageUrl) > 0 {
miniProgram["hdImageUrl"] = company.Applets[0].ImageUrl
}
miniProgram["title"] = company.Applets[0].Name
}
}
... ...
... ... @@ -21,6 +21,9 @@ var DEFAULT_GUEST_COMPANY int = 10011
var SHARE_SHOP_PREVIEW_IMADGE = "https://media.fjmaimaimai.com/image/default/3E0C7050C13147CE8C7AF86C75F904E9-6-2.jpg" //分享店铺预览图
var WEHAT_MINI_PROGRAM_VERSION_TYPE = 2 //0:正式版 1:开发版 2:体验版
var DISENABLE_MULTI_DEVICE_LOGIN = false //不允许多端登录 (注:正式环境需要为true 测试环境设为false,方便多个设备测试)
func init() {
if os.Getenv("LOG_LEVEL") != "" {
LOG_LEVEL = os.Getenv("LOG_LEVEL")
... ...
... ... @@ -7,7 +7,7 @@ var POSTGRESQL_USER = "postgres" //
var POSTGRESQL_PASSWORD = "eagle1010" //pgsql@123
var POSTGRESQL_HOST = "114.55.200.59" //127.0.0.1
var POSTGRESQL_PORT = "31543" //5432
var DISABLE_CREATE_TABLE = false
var DISABLE_CREATE_TABLE = true
var DISABLE_SQL_GENERATE_PRINT = false
func init() {
... ... @@ -32,4 +32,7 @@ func init() {
if os.Getenv("DISABLE_SQL_GENERATE_PRINT") != "" {
DISABLE_SQL_GENERATE_PRINT = true
}
if POSTGRESQL_DB_NAME == "partner" {
DISENABLE_MULTI_DEVICE_LOGIN = true
}
}
... ...
package domain
type CompanyApplets struct {
Name string `json:"name"`
URL string `json:"url"`
Id string `json:"id"`
Name string `json:"name"`
URL string `json:"url"`
ImageUrl string `json:"imageUrl"`
Id string `json:"id"`
}
func (applets CompanyApplets) Valid() bool {
... ...
... ... @@ -63,6 +63,8 @@ type OrderBase struct {
DataFrom *OrderDataFrom
// 备注
Remark string
// 订单所属合伙人类别
PartnerCategory *PartnerCategoryInfo
}
func (m *OrderBase) Identify() interface{} {
... ... @@ -150,10 +152,11 @@ type OrderQueryOption struct {
BeginTime time.Time `json:"beginTime,omitempty"`
EndTime time.Time `json:"endTime,omitempty"`
//IsDisable string `json:"isDisable,omitempty"`
SortByCreateTime string `json:"sortByCreateTime,omitempty"`
SortByUpdateTime string `json:"sortByUpdateTime,omitempty"`
Offset int `json:"offset,omitempty"`
Limit int `json:"limit,omitempty"`
SortByCreateTime string `json:"sortByCreateTime,omitempty"`
SortByUpdateTime string `json:"sortByUpdateTime,omitempty"`
Offset int `json:"offset,omitempty"`
Limit int `json:"limit,omitempty"`
PartnerCategoryId int `json:"partnerCategoryId,omitempty"`
}
type DividendOrdersQueryOption struct {
... ...
... ... @@ -13,6 +13,7 @@ type OrderStaticQuery struct {
OrderType int `json:"orderType,omitempty"`
OrderTypes []int `json:"orderTypes,omitempty"`
//IsDisable int `json:"isDisable,omitempty"`
PartnerCategoryId int `json:"partnerCategoryId,omitempty"`
}
type DividendOrdersQuery struct {
... ... @@ -24,12 +25,13 @@ type DividendOrdersQuery struct {
// 订单分红统计-查询
type OrderBonusQuery struct {
PartnerId int64 `json:"partnerId,omitempty"`
CompanyId int64 `json:"companyId,omitempty"`
InPartnerIds []int64 `json:"inPartnerIds,omitempty"`
IsDisable int `json:"isDisable,omitempty"`
OrderType int `json:"orderType,omitempty"`
OrderTypes []int `json:"orderTypes,omitempty"`
PartnerId int64 `json:"partnerId,omitempty"`
CompanyId int64 `json:"companyId,omitempty"`
InPartnerIds []int64 `json:"inPartnerIds,omitempty"`
IsDisable int `json:"isDisable,omitempty"`
OrderType int `json:"orderType,omitempty"`
OrderTypes []int `json:"orderTypes,omitempty"`
PartnerCategoryId int `json:"partnerCategoryId,omitempty"` //订单所属类型
}
// 订单分红统计-应答
... ...
... ... @@ -39,6 +39,9 @@ func (dao *OrderBaseDao) OrderStatics(option *domain.OrderStaticQuery) (count in
if option.EndTime > 0 {
q.Where(`"order_base".create_time <?`, time.Unix(option.EndTime/1000, 0))
}
if option.PartnerCategoryId > 0 {
q.Where(`"order_base".partner_category @>'{"id":?}'`, option.PartnerCategoryId)
}
//q.Where(`"order_base".is_disable =?`, 0)
err = q.Select(&count, &amount, &orderAmount)
if option.OrderType == domain.OrderIntention { //意向订单值只有 order_amount order_actual_amount还未赋值
... ... @@ -74,6 +77,9 @@ func (dao *OrderBaseDao) OrderBonusStatics(option domain.OrderBonusQuery) (rsp d
if len(option.OrderTypes) > 0 {
q.Where(`"order_base".order_type in (?)`, pg.In(option.OrderTypes))
}
if option.PartnerCategoryId > 0 {
q.Where(`"order_base".partner_category @>'{"id":?}'`, option.PartnerCategoryId)
}
err = q.Select(&rsp.Total, &rsp.Bonus, &rsp.BonusExpense, &rsp.TotalOrderAmount)
return
}
... ...
... ... @@ -64,4 +64,6 @@ type OrderBase struct {
DataFrom *domain.OrderDataFrom
// 备注
Remark string
// 订单所属合伙人类别
PartnerCategory *domain.PartnerCategoryInfo
}
... ...
package repository
import (
"encoding/json"
"github.com/go-pg/pg/v10"
"github.com/go-pg/pg/v10/orm"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
... ... @@ -88,6 +89,10 @@ func (repository *OrderBaseRepository) Find(queryOptions map[string]interface{})
if v, ok := queryOptions["orderTypes"]; ok {
query.Where(`"order_base".order_type in (?)`, pg.In(v))
}
if v, ok := queryOptions["partnerCategoryId"]; ok {
catId, _ := (v.(json.Number)).Int64()
query.Where(`"order_base".partner_category @>'{"id":?}'`, catId)
}
var err error
if query.AffectRow, err = query.SelectAndCount(); err != nil {
return 0, OrderBases, err
... ...
... ... @@ -59,6 +59,30 @@ func (this *CompanyController) Partners() {
msg = protocol.NewReturnResponse(data, err)
}
// Partners
// 测试
func (this *CompanyController) PartnersV2() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocolx.PartnersRequest
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 := company.PartnersV2(header, request)
if err != nil {
log.Error(err)
}
msg = protocol.NewReturnResponse(data, err)
}
// Statistics
// 测试
func (this *CompanyController) Statistics() {
... ...
... ... @@ -25,6 +25,9 @@ func (this *DividendController) DividendStatistics() {
return
}
header := this.GetRequestHeader(this.Ctx)
if request.PartnerId == 0 {
request.PartnerId = header.UserId
}
msg = protocol.NewReturnResponse(dividend.Statistics(header, request))
}
... ... @@ -44,5 +47,8 @@ func (this *DividendController) DividendOrders() {
return
}
header := this.GetRequestHeader(this.Ctx)
if request.PartnerId == 0 {
request.PartnerId = header.UserId
}
msg = protocol.NewReturnResponse(dividend.OrderList(header, request))
}
... ...
... ... @@ -31,6 +31,29 @@ func (this *OrderController) Statistics() {
msg = protocol.NewReturnResponse(order.Statistics(header, request))
}
//OrderStatistics 订单统计
// @router /statistics [post]
func (this *OrderController) StatisticsV2() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.OrderStatisticsRequest
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)
if request.PartnerId == 0 {
request.PartnerId = header.UserId
}
msg = protocol.NewReturnResponse(order.StatisticsV2(header, request))
}
//OrderDetail 订单详情
// @router /orderDetail [post]
func (this *OrderController) OrderDetail() {
... ... @@ -68,6 +91,9 @@ func (this *OrderController) OrderList() {
}
request.OrderTypes = domain.UserOrderTypes(domain.Career)
header := this.GetRequestHeader(this.Ctx)
if request.PartnerId == 0 {
request.PartnerId = header.UserId
}
msg = protocol.NewReturnResponse(order.List(header, request))
}
... ...
... ... @@ -3,6 +3,7 @@ package middleware
import (
"github.com/astaxie/beego/context"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/userAuth"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/constant"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol"
"strconv"
... ... @@ -39,15 +40,17 @@ func CheckJWTToken(ctx *context.Context) {
} else {
ctx.Input.SetData("UserId", u.UserId)
// valid token
userPhone, _ := strconv.Atoi(u.Phone)
tokenAuth := userAuth.NewRedisUserAuth(userAuth.WithUserId(int64(userPhone)))
err := tokenAuth.Check(
userAuth.NewOptions(userAuth.WithAccessToken(token)),
)
if err != nil {
msg = protocol.NewMesage(4141)
return
if constant.DISENABLE_MULTI_DEVICE_LOGIN {
// valid token
userPhone, _ := strconv.Atoi(u.Phone)
tokenAuth := userAuth.NewRedisUserAuth(userAuth.WithUserId(int64(userPhone)))
err := tokenAuth.Check(
userAuth.NewOptions(userAuth.WithAccessToken(token)),
)
if err != nil {
msg = protocol.NewMesage(4141)
return
}
}
}
return
... ...
... ... @@ -45,5 +45,8 @@ func InitV2() {
nsV2 := beego.NewNamespace("v2") // ,, beego.NSBefore(middleware.CheckJWTToken)
nsV2.Router("/auth/login", &controllers.AuthController{}, "Post:LoginV2")
nsV2.Router("/user/userInfo", &controllers.UserController{}, "Post:UserInfoV2")
nsV2.Router("/company/partners", &controllers.CompanyController{}, "post:PartnersV2")
nsV2.Router("/order/statistics", &controllers.OrderController{}, "Post:StatisticsV2")
beego.AddNamespace(nsV2)
}
... ...
... ... @@ -11,6 +11,7 @@ type DividendStatisticsRequest struct {
EndTime int64 `json:"endTime" valid:"Required"`
//分红类型(0累计分红、1分红支出)
//DividendAction int `json:"dividendAction"`
PartnerId int64 `json:"partnerId"`
}
type DividendStatisticsResponse struct {
Statistics DividendStatistics `json:"statistics"`
... ... @@ -39,6 +40,8 @@ type DividendOrdersRequest struct {
PageIndex int `json:"pageIndex,omitempty"`
PageSize int `json:"pageSize,omitempty"`
PartnerId int64 `json:"partnerId"`
}
type DividendOrdersResponse struct {
List []*DividendOrderListItem `json:"list"`
... ...
... ... @@ -43,9 +43,14 @@ type Customer struct {
/*OrderStatistics */
type OrderStatisticsRequest struct {
PartnerId int64 `json:"partnerId"`
}
type OrderStatisticsResponse struct {
Statistics OrderStatics `json:"statistics"`
Statistics *OrderStatics `json:"statistics,omitempty"`
Career OrderStatic `json:"career,omitempty"` //事业
Business OrderStatic `json:"business,omitempty"` //业务
Develop OrderStatic `json:"develop,omitempty"` //开发
App OrderStatic `json:"app,omitempty"` //业务-产品应用
}
type OrderStatics struct {
TodayIntentionQuantity int `json:"-"` //今日新增意向订单
... ... @@ -63,6 +68,14 @@ type OrderStatics struct {
BusinessMoney float64 `json:"businessMoney"` // 业务分红累计
}
type OrderStatic struct {
Percent float64 `json:"percent"` // 事业占比
TodayRealQuantity int `json:"todayRealQuantity"` //今日新增实发订单
TodayRealMoney float64 `json:"todayRealMoney"` //今日新增实发订单金额
CumulativeQuantity int `json:"cumulativeQuantity"` //累计实发订单
CumulativeMoney float64 `json:"cumulativeMoney"` //累计实发订单金额
}
/*OrderList */
type OrderListRequest struct {
StartTime int64 `json:"startTime"`
... ... @@ -72,6 +85,9 @@ type OrderListRequest struct {
PageSize int `json:"pageSize" valid:"Required"`
OrderType int `json:"-"`
OrderTypes []int `json:"-"`
PartnerId int64 `json:"partnerId"`
JoinWay int `json:"joinWay"` //合伙方式(0或不传,即所有合伙方式)
}
type OrderListResponse struct {
List []*OrderListItem `json:"list"`
... ...