作者 陈志颖

合并分支 'dev' 到 'master'

Dev



查看合并请求 !5
appname = partner
runmode = "${RUN_MODE||dev}"
httpport = "${HTTP_PORT||8080}"
httpport = "${HTTP_PORT||8082}"
#开启监控
EnableAdmin = false
... ...
... ... @@ -11,5 +11,5 @@ require (
github.com/linmadan/egglib-go v0.0.0-20191217144343-ca4539f95bf9
github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 // indirect
github.com/shopspring/decimal v1.2.0
github.com/tiptok/gocomm v1.0.2
github.com/tiptok/gocomm v1.0.5
)
... ...
... ... @@ -19,6 +19,7 @@ import (
"time"
)
// 该方法废弃
func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp *protocol.LoginResponse, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
... ... @@ -222,7 +223,7 @@ func RefreshToken(request *protocol.RefreshTokenRequest) (rsp *protocol.RefreshT
return
}
//验证短信验证码 T
// 验证短信验证码 T
func CheckSmsCode(phone, code string) (result bool, err error) {
sms, _ := factory.CreateSmsCodeService()
var data map[string]interface{}
... ... @@ -236,7 +237,7 @@ func CheckSmsCode(phone, code string) (result bool, err error) {
return
}
//验证手机号码(修改手机号码、重置密码的前一步)
// 验证手机号码(修改手机号码、重置密码的前一步)
func AuthCheckSmsCode(header *protocol.RequestHeader, request *protocol.AuthCheckSmsCodeRequest) (rsp *protocol.AuthCheckSmsCodeResponse, err error) {
var ()
if _, err = CheckSmsCode(request.Phone, request.Captcha); err != nil {
... ... @@ -248,7 +249,7 @@ func AuthCheckSmsCode(header *protocol.RequestHeader, request *protocol.AuthChec
return
}
//注销登录
// 注销登录
func Revoke(header *protocol.RequestHeader, request *protocol.RevokeRequest) (rsp *protocol.RevokeResponse, err error) {
//auth := userAuth.NewRedisUserAuth(userAuth.WithUserId(header.UserId))
//rsp = &protocol.RevokeResponse{}
... ... @@ -263,7 +264,7 @@ func Revoke(header *protocol.RequestHeader, request *protocol.RevokeRequest) (rs
return
}
//注销登录
// 注销登录
func UCenterRevoke(header *protocol.RequestHeader, userId int64) (rsp *protocol.RevokeResponse, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
... ... @@ -300,7 +301,8 @@ func UCenterRevoke(header *protocol.RequestHeader, userId int64) (rsp *protocol.
return
}
func CenterCompanys(header *protocol.RequestHeader, request *protocolx.CenterCompanysRequest) (v interface{}, err error) {
// 企业平台-多公司登录
func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCompanysRequest) (v interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
imInfo *domain.ImInfo
... ... @@ -320,14 +322,14 @@ func CenterCompanys(header *protocol.RequestHeader, request *protocolx.CenterCom
defer func() {
transactionContext.RollbackTransaction()
}()
// 通过短信验证码登录的游客,注册一个账号到配置的公司去(ios审核使用)
if request.GrantType == protocol.LoginBySmsCode {
e := loginSvr.RegistryGuest(request.Phone)
if e != nil {
log.Error(e)
}
}
// loginSvr 初始化
loginSvr.Init(request.Phone)
if len(loginSvr.Users) == 0 && len(loginSvr.PartnerInfo) == 0 {
err = protocol.NewErrWithMessage(10001)
... ... @@ -367,22 +369,21 @@ func CenterCompanys(header *protocol.RequestHeader, request *protocolx.CenterCom
break
}
//获取统计信息
// 获取统计信息(合伙人/高管)
rsp.Partner, _ = loginSvr.PartnerStaticInfo()
rsp.Manager, _ = loginSvr.ManagerStaticInfo()
//没有有效人的时候
if !loginSvr.AvailableCompany {
if !loginSvr.HasAvailableCompany {
err = protocol.NewErrWithMessage(10008) //账号禁用
return
}
// 初始化网易IM信息
var nickName string
if len(loginSvr.Users) > 0 {
nickName = loginSvr.Users[0].Name
} else if len(loginSvr.PartnerInfo) > 0 {
nickName = loginSvr.PartnerInfo[0].PartnerName
}
//初始化im信息
if imInfo, err = InitOrUpdateUserIMInfo(int64(phoneId), nickName, transactionContext); err != nil {
log.Error(err)
return
... ... @@ -397,12 +398,13 @@ func CenterCompanys(header *protocol.RequestHeader, request *protocolx.CenterCom
//添加手机对应的凭证
userAuth.NewRedisUserCredential(request.Phone).AddAuth(rsp.Credentials)
err = transactionContext.CommitTransaction()
v = map[string]interface{}{"center": rsp}
err = transactionContext.CommitTransaction()
return
}
func Companys(header *protocol.RequestHeader, request *protocolx.CompanysRequest) (rsp *protocolx.CompanysResponse, err error) {
// 企业平台-多公司登录 - 通过凭证
func CompaniesLoginByCredential(header *protocol.RequestHeader, request *protocolx.CompanysRequest) (rsp *protocolx.CompanysResponse, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
loginSvr = domain_service.NewPgLoginService(transactionContext)
... ... @@ -428,11 +430,12 @@ func Companys(header *protocol.RequestHeader, request *protocolx.CompanysRequest
return
}
}
// loginSvr 初始化
loginSvr.Init(claim.Phone)
rsp.Partner, _ = loginSvr.PartnerStaticInfo()
rsp.Manager, _ = loginSvr.ManagerStaticInfo()
//没有有效人的时候
if !loginSvr.AvailableCompany {
if !loginSvr.HasAvailableCompany {
err = protocol.NewErrWithMessage(4140, err) //账号禁用
return
}
... ... @@ -441,6 +444,7 @@ func Companys(header *protocol.RequestHeader, request *protocolx.CompanysRequest
return
}
// 登录
func LoginV2(header *protocol.RequestHeader, request *protocol.LoginRequestV2) (rsp *protocol.LoginResponse, err error) {
var (
claim *utils.UserTokenClaims
... ... @@ -483,12 +487,12 @@ func LoginV2(header *protocol.RequestHeader, request *protocol.LoginRequestV2) (
return
}
}
//验证公司模块权限
if _, adminUsers, e := UsersRepository.Find(map[string]interface{}{"inCompanyIds": []int64{int64(request.Cid)}, "adminType": 2, "deleteAtIsNull": true}); e == nil {
if len(adminUsers) > 0 {
au := adminUsers[0]
if code, e := adminApiGateway.UserAuth(au.Id, constant.BUSINESS_ADMIN_PLATFORM_ID); e != nil || code != 0 {
log.Debug("【合伙人检查权限】", claim.Phone, "【公司】", request.Cid, au.Id, code, e.Error())
//合伙人 需要验证对应公司模块权限(查询该公司的主管理员是否有权限)
if _, admins, e := UsersRepository.Find(map[string]interface{}{"inCompanyIds": []int64{int64(request.Cid)}, "adminType": 2, "deleteAtIsNull": true}); e == nil {
if len(admins) > 0 {
admin := admins[0]
if code, e := adminApiGateway.UserAuth(admin.Id, constant.BUSINESS_ADMIN_PLATFORM_ID); e != nil || code != 0 {
log.Debug("【合伙人检查权限】", claim.Phone, "【公司】", request.Cid, admin.Id, code, e.Error())
err = protocol.NewErrWithMessage(10008, err) // 抱歉,企业管理员未帮您开通权限
return
}
... ... @@ -503,7 +507,7 @@ func LoginV2(header *protocol.RequestHeader, request *protocol.LoginRequestV2) (
return
}
}
//校验模块权限
//高管 需要校验高管是否模块权限
if userId != 0 {
if code, e := adminApiGateway.UserAuth(userId, constant.BUSINESS_ADMIN_PLATFORM_ID); e != nil || code != 0 {
log.Debug("【检查权限】", userId, "【公司】", request.Cid, "【错误】:", code, e.Error())
... ... @@ -520,7 +524,8 @@ func LoginV2(header *protocol.RequestHeader, request *protocol.LoginRequestV2) (
err = protocol.NewErrWithMessage(10001, err) //账号不存在
return
}
//根据simnum + cid
// 生成授权码
userClaims := utils.UserTokenClaims{
UserId: userId,
CompanyId: int64(request.Cid),
... ...
... ... @@ -2,6 +2,7 @@ package company
import (
"github.com/tiptok/gocomm/pkg/log"
"github.com/tiptok/gocomm/sync/task"
"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"
... ... @@ -11,6 +12,7 @@ import (
"strings"
)
// 公司属性 合伙人类型/区域
func Property(header *protocol.RequestHeader, request *protocolx.PropertyRequest) (rsp *protocolx.PropertyResponse, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
... ... @@ -24,14 +26,19 @@ func Property(header *protocol.RequestHeader, request *protocolx.PropertyRequest
transactionContext.RollbackTransaction()
}()
//用户查询区域
if (request.Action & 0x01) > 0 {
rsp.Districts, _ = getDistricts(header.UserId, transactionContext)
}
//查询合伙人类型
if (request.Action & 0x02) > 0 {
rsp.JoinWays, _ = getJoinWays(transactionContext)
}
//并行查询区域/合伙人类型
task.Parallel(
func() {
if (request.Action & 0x01) > 0 {
rsp.Districts, _ = getDistricts(header.UserId, transactionContext)
}
},
func() {
if (request.Action & 0x02) > 0 {
rsp.JoinWays, _ = getJoinWays(transactionContext)
}
},
)
err = transactionContext.CommitTransaction()
return
}
... ... @@ -145,9 +152,7 @@ func getStatistics(userId int64, transactionContext *transaction.TransactionCont
UsersRepository, _ = factory.CreateUsersRepository(transactionContext)
PartnerInfoDao, _ = factory.CreatePartnerInfoDao(transactionContext)
OrderBaseDao, _ = factory.CreateOrderBaseDao(transactionContext)
//BusinessBonusDao, _ = factory.CreateBusinessBonusDao(transactionContext)
//user *domain.Users
partnerIds []int64
partnerIds []int64
)
if user, e := UsersRepository.FindOne(map[string]interface{}{"id": userId}); e != nil || user == nil {
return struct {
... ... @@ -156,10 +161,7 @@ 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
// TODO:分组统计
if count, e := PartnerInfoDao.PartnerStatic(map[string]interface{}{"inPartnerIds": partnerIds, "inPartnerCategory": domain.Career}); e == nil {
Statistics["careerCount"] = count
}
... ... @@ -188,11 +190,6 @@ func getStatistics(userId int64, transactionContext *transaction.TransactionCont
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
}
... ... @@ -218,6 +215,32 @@ func getPartners(userId int64, request *protocolx.PartnersRequest, transactionCo
}
}
queryOption := newQueryOption(request)
if partners, e := PartnerInfo.Partners(user.AccessPartnerIds(), queryOption); e == nil {
var array []interface{}
for i := range partners {
mapPartner := make(map[string]interface{})
p := partners[i]
mapPartner["uid"] = p.Id
mapPartner["uname"] = p.PartnerName
mapPartner["joinWays"] = newJoinWays(mapCategoryInfo, p)
if p.RegionInfo != nil {
mapPartner["district"] = protocolx.Districts{Id: p.RegionInfo.RegionId, Name: p.RegionInfo.RegionName}
}
mapPartner["cooperationTime"] = p.CooperateTime.Unix() * 1000
mapPartner["dividend"] = utils.Decimal(p.Bonus)
mapPartner["ordersCount"] = p.Total
mapPartner["ordersMoney"] = utils.Decimal(p.Amount)
array = append(array, mapPartner)
}
return array, nil
}
return nil, nil
}
// 查询参数
func newQueryOption(request *protocolx.PartnersRequest) map[string]interface{} {
queryOption := make(map[string]interface{})
if len(request.Districts) > 0 {
... ... @@ -247,33 +270,16 @@ func getPartners(userId int64, request *protocolx.PartnersRequest, transactionCo
if request.SortBy != 0 {
queryOption["sortByBonus"] = domain.ASC
}
return queryOption
}
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
if p.RegionInfo != nil {
mapPartners["district"] = protocolx.Districts{Id: p.RegionInfo.RegionId, Name: p.RegionInfo.RegionName}
}
mapPartners["cooperationTime"] = p.CooperateTime.Unix() * 1000
mapPartners["dividend"] = utils.Decimal(p.Bonus)
mapPartners["ordersCount"] = p.Total
mapPartners["ordersMoney"] = utils.Decimal(p.Amount)
array = append(array, mapPartners)
func newJoinWays(mapCategoryInfo map[int64]*domain.PartnerCategoryInfo, p *domain.PartnerStatics) []protocolx.JoinWays {
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})
}
return array, nil
}
return nil, nil
return joinWays
}
... ...
... ... @@ -48,8 +48,8 @@ func getPartnersV2(userId int64, request *protocolx.PartnersRequest, transaction
}
var company *domain.Company
var CompanyResponsitory, _ = factory.CreateCompanyRepository(transactionContext)
if company, err = CompanyResponsitory.FindOne(map[string]interface{}{"id": user.CompanyId}); err != nil {
var CompanyRepository, _ = factory.CreateCompanyRepository(transactionContext)
if company, err = CompanyRepository.FindOne(map[string]interface{}{"id": user.CompanyId}); err != nil {
return nil, err
}
... ... @@ -63,7 +63,31 @@ func getPartnersV2(userId int64, request *protocolx.PartnersRequest, transaction
}
}
queryOption := newQueryOptionV2(request)
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
mapPartners["joinWays"] = newJoinWays(mapCategoryInfo, p)
mapPartners["dividend"] = utils.Decimal(p.Bonus)
mapPartners["ordersCount"] = p.Total
mapPartners["ordersMoney"] = utils.Decimal(p.Amount)
mapPartners["phone"] = p.Account
mapPartners["company"] = newCompany(company, p)
array = append(array, mapPartners)
}
return array, nil
}
return nil, nil
}
// 查询参数
func newQueryOptionV2(request *protocolx.PartnersRequest) map[string]interface{} {
queryOption := make(map[string]interface{})
if len(request.Districts) > 0 {
var districts []string
for i := 0; i < len(request.Districts); i++ {
... ... @@ -84,6 +108,9 @@ func getPartnersV2(userId int64, request *protocolx.PartnersRequest, transaction
if request.EndTime > 0 {
queryOption["endTime"] = request.EndTime / 1000
}
if request.Keyword != "" {
queryOption["keyword"] = request.Keyword
}
queryOption["limit"] = request.PageSize
queryOption["offset"] = request.PageSize * request.PageIndex
... ... @@ -91,77 +118,23 @@ func getPartnersV2(userId int64, request *protocolx.PartnersRequest, transaction
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
return queryOption
}
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
func newCompany(company *domain.Company, p *domain.PartnerStatics) userx.Company {
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},
}
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(p.Salesman) > 0 {
partnerCompany.Salesman = map[string]interface{}{"uname": p.Salesman[0].Name, "phone": p.Salesman[0].Telephone}
} else {
partnerCompany.Salesman = map[string]interface{}{}
}
//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
return partnerCompany
}
... ...
... ... @@ -12,9 +12,9 @@ import (
// 分红统计
func Statistics(header *protocol.RequestHeader, request *protocol.DividendStatisticsRequest) (rsp *protocol.DividendStatisticsResponse, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
OrderBaseResponsitory, _ = factory.CreateOrderBaseRepository(transactionContext)
BusinessBonusRepository, _ = factory.CreateBusinessBonusRepository(transactionContext)
transactionContext, _ = factory.CreateTransactionContext(nil)
OrderBaseResponsitory, _ = factory.CreateOrderBaseRepository(transactionContext)
//BusinessBonusRepository, _ = factory.CreateBusinessBonusRepository(transactionContext)
)
if err = transactionContext.StartTransaction(); err != nil {
return nil, err
... ... @@ -40,17 +40,17 @@ func Statistics(header *protocol.RequestHeader, request *protocol.DividendStatis
bonusQuarters := QuartersBonusStatics(orderBetween, 0)
// 业务分红统计
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
if bonus.UpdateAt.Unix() >= (request.StartTime/1000) && bonus.UpdateAt.Unix() < (request.EndTime/1000) {
q := quarter(bonus.UpdateAt)
bonusQuarters[q].Receivable += bonus.Bonus
bonusQuarters[q].Received += bonus.BonusHas
bonusQuarters[q].Outstanding += bonus.BonusNot
}
}
//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
// if bonus.UpdateAt.Unix() >= (request.StartTime/1000) && bonus.UpdateAt.Unix() < (request.EndTime/1000) {
// q := quarter(bonus.UpdateAt)
// bonusQuarters[q].Receivable += bonus.Bonus
// bonusQuarters[q].Received += bonus.BonusHas
// bonusQuarters[q].Outstanding += bonus.BonusNot
// }
//}
rsp = &protocol.DividendStatisticsResponse{}
rsp.Statistics = protocol.DividendStatistics{
... ... @@ -124,16 +124,17 @@ func OrderList(header *protocol.RequestHeader, request *protocol.DividendOrdersR
rsp = &protocol.DividendOrdersResponse{List: make([]*protocol.DividendOrderListItem, 0)}
count, orders, err = OrderDao.DividendOrders(&domain.DividendOrdersQueryOption{
OrderTypes: domain.UserOrderTypes(domain.Career),
PartnerId: request.PartnerId,
DetailAction: request.DetailAction,
DividendAction: request.DividendAction,
//IsDisable: "0",
OrderTypes: domain.UserOrderTypes(domain.Career),
PartnerId: request.PartnerId,
DetailAction: request.DetailAction,
DividendAction: request.DividendAction,
StartTime: request.StartTime,
EndTime: request.EndTime,
Offset: request.PageIndex * request.PageSize,
Limit: request.PageSize,
SortByUpdateTime: domain.DESC,
//SortByUpdateTime: domain.DESC,
SortByCreateTime: domain.DESC,
JoinWays: request.JoinWays,
})
if err != nil {
return
... ... @@ -145,7 +146,7 @@ func OrderList(header *protocol.RequestHeader, request *protocol.DividendOrdersR
item := &protocol.DividendOrderListItem{
Id: o.Id,
DeliveryNo: o.DeliveryCode,
OrderAmount: s.PlanOrderAmount, //s.OrderAmount(),
OrderAmount: s.PlanOrderAmount,
DividendReceivable: utils.Decimal(s.OrderTotalReceivable()),
}
rsp.List = append(rsp.List, item)
... ...
... ... @@ -177,7 +177,7 @@ func Statistics(header *protocol.RequestHeader, request *protocol.OrderStatistic
func List(header *protocol.RequestHeader, request *protocol.OrderListRequest) (rsp *protocol.OrderListResponse, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
OrderResponsitory, _ = factory.CreateOrderBaseRepository(transactionContext)
OrderRepository, _ = factory.CreateOrderBaseRepository(transactionContext)
OrderDao, _ = factory.CreateOrderBaseDao(transactionContext)
orders []*domain.OrderBase
total int64
... ... @@ -197,9 +197,12 @@ func List(header *protocol.RequestHeader, request *protocol.OrderListRequest) (r
queryOption := &domain.OrderQueryOption{
Limit: request.PageSize,
Offset: request.PageSize * request.PageIndex,
SortByUpdateTime: domain.DESC,
//SortByUpdateTime: domain.DESC,
SortByCreateTime: domain.DESC,
PartnerId: request.PartnerId,
PartnerCategoryId: request.JoinWay,
OrderType: request.OrderType,
OrderTypes: request.OrderTypes,
}
if request.StartTime > 0 {
queryOption.BeginTime = time.Unix(request.StartTime/1000, 0)
... ... @@ -207,9 +210,7 @@ func List(header *protocol.RequestHeader, request *protocol.OrderListRequest) (r
if request.EndTime > 0 {
queryOption.EndTime = time.Unix(request.EndTime/1000, 0)
}
queryOption.OrderType = request.OrderType
queryOption.OrderTypes = request.OrderTypes
total, orders, _ = OrderResponsitory.Find(utils.ObjectJsonToMap(queryOption))
total, orders, _ = OrderRepository.Find(utils.ObjectJsonToMap(queryOption))
if len(orders) != 0 {
for i := range orders {
item := DomainOrderToOrderListItem(orders[i])
... ... @@ -221,12 +222,11 @@ func List(header *protocol.RequestHeader, request *protocol.OrderListRequest) (r
}
}
// 查询统计数据
// 【特殊处理1】 查询第0页时,需要查询累计实发订单数
if request.PageIndex == 0 {
var (
cumulativeQuantity int
)
//累计实发订单
cumulativeQuantity, _, err = OrderDao.OrderStatics(&domain.OrderStaticQuery{
EndTime: time.Now().Unix() * 1000,
OrderTypes: domain.UserOrderTypes(domain.Career),
... ... @@ -235,7 +235,7 @@ func List(header *protocol.RequestHeader, request *protocol.OrderListRequest) (r
})
rsp.Total = cumulativeQuantity
}
// 今天累计数量特殊处理,不需要返回所有订单总数(因为要复用rsp.Total字段)
//【特殊处理2】 今天累计数量特殊处理 当前查询时间段内所有订单总数(复用rsp.Total字段)
if request.StartTime > 0 && request.EndTime > 0 {
zero := time.Time(xtime.XTime(time.Now()).DayBefore(0)).Unix()
if request.StartTime == (zero * 1000) {
... ... @@ -249,13 +249,17 @@ func List(header *protocol.RequestHeader, request *protocol.OrderListRequest) (r
func DomainOrderToOrderListItem(order *domain.OrderBase) *protocol.OrderListItem {
bonusStatic := order.OrderBonusStatic()
return &protocol.OrderListItem{
Id: order.Id,
OrderType: order.OrderType,
OrderNo: order.OrderCode,
DeliveryNo: order.DeliveryCode,
OrderAmount: order.PlanOrderAmount,
UpdateTime: order.UpdateTime.Unix() * 1000,
MyDividend: bonusStatic.OrderTotalReceivable(),
IsRead: order.IsRead(),
Id: order.Id,
OrderType: order.OrderType,
OrderNo: order.OrderCode,
DeliveryNo: order.DeliveryCode,
OrderDistrict: map[string]interface{}{
"id": order.RegionInfo.RegionId,
"name": order.RegionInfo.RegionName,
},
OrderAmount: order.PlanOrderAmount,
UpdateTime: order.UpdateTime.Unix() * 1000,
MyDividend: bonusStatic.OrderTotalReceivable(),
IsRead: order.IsRead(),
}
}
... ...
package order
import (
"github.com/tiptok/gocomm/sync/task"
"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"
... ... @@ -23,9 +24,8 @@ func StatisticsV2(header *protocol.RequestHeader, request *protocol.OrderStatist
rsp = &protocol.OrderStatisticsResponse{}
//事业分红/业务分红
var total float64 //,developBonus,appBonus,careerBonus, businessBonus,
var total float64
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 {
... ... @@ -55,10 +55,12 @@ func StatisticsV2(header *protocol.RequestHeader, request *protocol.OrderStatist
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)
task.Parallel(
func() { rsp.Career = calcOrderStatic(domain.Career, total) },
func() { rsp.Business = calcOrderStatic(domain.Business, total) },
func() { rsp.Develop = calcOrderStatic(domain.Develop, total) },
func() { rsp.App = calcOrderStatic(domain.App, total) },
)
err = transactionContext.CommitTransaction()
return
... ...
... ... @@ -12,6 +12,7 @@ import (
protocolx "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol/partner"
)
// 模块已废弃
func Detail(header *protocol.RequestHeader, request *protocolx.DetailRequest) (rsp *protocolx.DetailResponse, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
... ...
... ... @@ -22,14 +22,14 @@ import (
//用户信息
func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest) (rsp *protocol.UserInfoResponse, err error) {
var (
partnerInfo *domain.PartnerInfo
transactionContext, _ = factory.CreateTransactionContext(nil)
CompanyResponsitory, _ = factory.CreateCompanyRepository(transactionContext)
PartnerInfoService, _ = factory.CreatePartnerInfoRepositoryIn(transactionContext)
UsersRepository, _ = factory.CreateUsersRepository(transactionContext)
ImInfoRepository, _ = factory.CreateImInfoRepository(transactionContext)
company *domain.Company
user *domain.Users
partnerInfo *domain.PartnerInfo
transactionContext, _ = factory.CreateTransactionContext(nil)
CompanyRepository, _ = factory.CreateCompanyRepository(transactionContext)
PartnerInfoService, _ = factory.CreatePartnerInfoRepositoryIn(transactionContext)
UsersRepository, _ = factory.CreateUsersRepository(transactionContext)
ImInfoRepository, _ = factory.CreateImInfoRepository(transactionContext)
company *domain.Company
user *domain.Users
)
if err = transactionContext.StartTransaction(); err != nil {
return nil, err
... ... @@ -44,7 +44,7 @@ func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest)
err = protocol.NewErrWithMessage(502, err) //账号不存在
return
}
if company, err = CompanyResponsitory.FindOne(map[string]interface{}{"id": header.CompanyId}); err != nil {
if company, err = CompanyRepository.FindOne(map[string]interface{}{"id": header.CompanyId}); err != nil {
return
}
rsp.User = protocol.User{
... ... @@ -72,7 +72,7 @@ func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest)
err = protocol.NewErrWithMessage(502, err) //账号不存在
return
}
if company, err = CompanyResponsitory.FindOne(map[string]interface{}{"id": header.CompanyId}); err != nil {
if company, err = CompanyRepository.FindOne(map[string]interface{}{"id": header.CompanyId}); err != nil {
return
}
rsp.User = protocol.User{
... ... @@ -188,13 +188,13 @@ func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePass
func UserInfoV2(header *protocol.RequestHeader, request *protocol.UserInfoRequest) (rsp interface{}, err error) {
var (
partnerInfo *domain.PartnerInfo
transactionContext, _ = factory.CreateTransactionContext(nil)
CompanyResponsitory, _ = factory.CreateCompanyRepository(transactionContext)
PartnerInfoService, _ = factory.CreatePartnerInfoRepositoryIn(transactionContext)
UsersRepository, _ = factory.CreateUsersRepository(transactionContext)
company *domain.Company
user *domain.Users
partnerInfo *domain.PartnerInfo
transactionContext, _ = factory.CreateTransactionContext(nil)
CompanyRepository, _ = factory.CreateCompanyRepository(transactionContext)
PartnerInfoService, _ = factory.CreatePartnerInfoRepositoryIn(transactionContext)
UsersRepository, _ = factory.CreateUsersRepository(transactionContext)
company *domain.Company
user *domain.Users
)
if err = transactionContext.StartTransaction(); err != nil {
return nil, err
... ... @@ -209,7 +209,7 @@ func UserInfoV2(header *protocol.RequestHeader, request *protocol.UserInfoReques
err = protocol.NewErrWithMessage(502, err) //账号不存在
return
}
if company, err = CompanyResponsitory.FindOne(map[string]interface{}{"id": header.CompanyId}); err != nil {
if company, err = CompanyRepository.FindOne(map[string]interface{}{"id": header.CompanyId}); err != nil {
return
}
var miniProgram map[string]interface{}
... ... @@ -253,7 +253,7 @@ func UserInfoV2(header *protocol.RequestHeader, request *protocol.UserInfoReques
err = protocol.NewErrWithMessage(502, err) //账号不存在
return
}
if company, err = CompanyResponsitory.FindOne(map[string]interface{}{"id": header.CompanyId}); err != nil {
if company, err = CompanyRepository.FindOne(map[string]interface{}{"id": header.CompanyId}); err != nil {
return
}
rspMap["user"] = userx.User{
... ...
... ... @@ -2,11 +2,11 @@ package constant
import "os"
var POSTGRESQL_DB_NAME = "partner_dev" //partner
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 POSTGRESQL_DB_NAME = "partner_dev" //partner_test/partner_dev
var POSTGRESQL_USER = "postgres" //postgres
var POSTGRESQL_PASSWORD = "eagle1010" //pgsql@123/1993618jack
var POSTGRESQL_HOST = "114.55.200.59" //127.0.0.1/114.55.200.59
var POSTGRESQL_PORT = "31543" //5432/31543
var DISABLE_CREATE_TABLE = true
var DISABLE_SQL_GENERATE_PRINT = false
... ...
... ... @@ -4,7 +4,7 @@ import "os"
var REDIS_HOST = "127.0.0.1"
var REDIS_PORT = "6379"
var REDIS_AUTH = "123456"
var REDIS_AUTH = ""
func init() {
if os.Getenv("REDIS_HOST") != "" {
... ...
... ... @@ -2,6 +2,7 @@ package domain
import (
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol/company"
"time"
)
... ... @@ -145,8 +146,10 @@ func (m *OrderBase) OrderBonusStatic() *OrderStatics {
}
type OrderQueryOption struct {
PartnerId int64 `json:"partnerId,omitempty"`
OrderType int `json:"orderType,omitempty"`
PartnerId int64 `json:"partnerId,omitempty"`
// 订单类型 单个
OrderType int `json:"orderType,omitempty"`
// 订单类型 多个
OrderTypes []int `json:"orderTypes,omitempty"`
OrderStatus int `json:"orderStatus,omitempty"`
BeginTime time.Time `json:"beginTime,omitempty"`
... ... @@ -171,6 +174,8 @@ type DividendOrdersQueryOption struct {
Offset int `json:"offset,omitempty"`
Limit int `json:"limit,omitempty"`
SortByUpdateTime string `json:"sortByUpdateTime,omitempty"`
SortByCreateTime string `json:"sortByCreateTime,omitempty"`
JoinWays []*company.JoinWays `json:"joinWays,omitempty"` // 合伙类型
}
//买家
... ...
... ... @@ -32,6 +32,7 @@ type OrderBonusQuery struct {
OrderType int `json:"orderType,omitempty"`
OrderTypes []int `json:"orderTypes,omitempty"`
PartnerCategoryId int `json:"partnerCategoryId,omitempty"` //订单所属类型
//IsGroupByPartnerCategoryId bool `json:"isGroupByPartnerCategoryId,omitempty"`
}
// 订单分红统计-应答
... ... @@ -44,4 +45,5 @@ type OrderBonusResponse struct {
BonusExpense float64 `json:"bonusExpense,omitempty"`
// 订单金额
TotalOrderAmount float64 `json:"totalOrderAmount"`
//PartnerCategory *PartnerCategoryInfo
}
... ...
... ... @@ -7,6 +7,7 @@ import (
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils"
"strings"
"time"
)
... ... @@ -62,6 +63,7 @@ func (dao *OrderBaseDao) OrderBonusStatics(option domain.OrderBonusQuery) (rsp d
q.ColumnExpr("sum((case when use_order_count>=0 then use_partner_bonus else plan_partner_bonus end)) bonus")
q.ColumnExpr("sum(partner_bonus_expense) bonus_expense")
q.ColumnExpr("sum(plan_order_amount) total_order_amount")
//q.ColumnExpr("partner_category")
if option.PartnerId > 0 {
q.Where(`"order_base".partner_id =?`, option.PartnerId)
}
... ... @@ -80,6 +82,9 @@ func (dao *OrderBaseDao) OrderBonusStatics(option domain.OrderBonusQuery) (rsp d
if option.PartnerCategoryId > 0 {
q.Where(`"order_base".partner_category @>'{"id":?}'`, option.PartnerCategoryId)
}
//if option.IsGroupByPartnerCategoryId{
// q.Group(`partner_category`)
//}
err = q.Select(&rsp.Total, &rsp.Bonus, &rsp.BonusExpense, &rsp.TotalOrderAmount)
return
}
... ... @@ -105,6 +110,20 @@ func (dao *OrderBaseDao) DividendOrders(option *domain.DividendOrdersQueryOption
if option.EndTime > 0 {
q.Where(`"order_base".create_time <?`, time.Unix(option.EndTime/1000, 0))
}
if len(option.JoinWays) > 0 {
var joinWays []int64
for i := 0; i < len(option.JoinWays); i++ {
joinWays = append(joinWays, option.JoinWays[i].Type)
}
var filterJoinWays = strings.Builder{}
for i := range joinWays {
filterJoinWays.WriteString(fmt.Sprintf(` partner_category @>'{"id":%v}'`, joinWays[i]))
if i != (len(joinWays) - 1) {
filterJoinWays.WriteString(" or ")
}
}
q.Where(filterJoinWays.String())
}
//if len(option.IsDisable) > 0 {
// value, _ := strconv.Atoi(option.IsDisable)
// q.Where(`"order_base".is_disable =?`, value)
... ... @@ -125,7 +144,11 @@ func (dao *OrderBaseDao) DividendOrders(option *domain.DividendOrdersQueryOption
q.Offset(option.Offset)
}
if len(option.SortByUpdateTime) > 0 {
q.Order(fmt.Sprintf("order_base.id %v", option.SortByUpdateTime))
//q.Order(fmt.Sprintf("order_base.id %v", option.SortByUpdateTime))
q.Order(fmt.Sprintf("order_base.update_time %v", option.SortByUpdateTime))
}
if len(option.SortByCreateTime) > 0 {
q.Order(fmt.Sprintf("order_base.create_time %v", option.SortByCreateTime))
}
count, err = q.Distinct().SelectAndCount()
for i := range orders {
... ...
... ... @@ -96,6 +96,9 @@ func (dao *PartnerInfoDao) Partners(partnerIds []int64, queryOptions map[string]
if endTime, ok := queryOptions["endTime"]; ok {
filterPartners.WriteString(fmt.Sprintf(" and cooperate_time<to_timestamp(%v)", endTime))
}
if keyword, ok := queryOptions["keyword"]; ok && keyword.(string) != "" {
filterPartners.WriteString(fmt.Sprintf(` and partner_name LIKE '%v'`, fmt.Sprintf("%%%s%%", "%%" + keyword.(string) + "%")))
}
sql.WriteString(fmt.Sprintf(`
SELECT A.*,B.total,B.amount,COALESCE(B.bonus,0) bonus,B.bonus_expense
... ...
... ... @@ -23,7 +23,8 @@ type PgLoginService struct {
PartnerInfo []*domain.PartnerInfo
Users []*domain.Users
transactionContext *transaction.TransactionContext
AvailableCompany bool
// 标识:登录的账号信息是否有可用的公司, true:有 false:没有
HasAvailableCompany bool
}
func (svr *PgLoginService) Init(phone string) (err error) {
... ... @@ -166,7 +167,7 @@ func (svr *PgLoginService) PartnerStaticInfo() (interface{}, error) {
companys = append(companys, item)
}
if len(companys) > 0 {
svr.AvailableCompany = true
svr.HasAvailableCompany = true
}
response["companys"] = companys
... ... @@ -218,7 +219,7 @@ func (svr *PgLoginService) ManagerStaticInfo() (interface{}, error) {
companys = append(companys, item)
}
if len(companys) > 0 {
svr.AvailableCompany = true
svr.HasAvailableCompany = true
}
response["companys"] = companys
... ... @@ -341,7 +342,7 @@ type joinWay struct {
func NewPgLoginService(ctx *transaction.TransactionContext) *PgLoginService {
return &PgLoginService{
transactionContext: ctx,
AvailableCompany: false,
transactionContext: ctx,
HasAvailableCompany: false,
}
}
... ...
... ... @@ -77,8 +77,7 @@ func (repository *OrderBaseRepository) Find(queryOptions map[string]interface{})
var OrderBaseModels []*models.OrderBase
OrderBases := make([]*domain.OrderBase, 0)
query := NewQuery(tx.Model(&OrderBaseModels), queryOptions)
query.
SetWhere(`"order_base".partner_id= ?`, "partnerId").
query.SetWhere(`"order_base".partner_id= ?`, "partnerId").
SetWhere(`"order_base".order_type= ?`, "orderType").
SetWhere(`"order_base".create_time >= ?`, "beginTime").
SetWhere(`"order_base".create_time < ?`, "endTime").
... ...
... ... @@ -183,7 +183,7 @@ func (this *AuthController) CenterCompanys() {
return
}
header := this.GetRequestHeader(this.Ctx)
data, err := auth.CenterCompanys(header, request)
data, err := auth.CompaniesLogin(header, request)
if err != nil {
log.Error(err)
}
... ... @@ -211,7 +211,7 @@ func (this *AuthController) Companys() {
return
}
header := this.GetRequestHeader(this.Ctx)
data, err := auth.Companys(header, request)
data, err := auth.CompaniesLoginByCredential(header, request)
if err != nil {
log.Error(err)
}
... ...
... ... @@ -26,8 +26,8 @@ func CreateResponseLogFilter(logger *logs.BeeLogger) func(ctx *context.Context)
return func(ctx *context.Context) {
requestId := ctx.Request.Header.Get("requestId")
body, _ := json.Marshal(ctx.Input.GetData("outputData"))
if len(body) > 1000 {
body = body[:1000]
if len(body) > 10000 {
body = body[:10000]
}
logger.Debug(fmt.Sprintf("<====Send RequestId:%v BodyData:%s", requestId, body))
}
... ...
... ... @@ -29,7 +29,7 @@ type LoginResponse struct {
type LoginRequestV2 struct {
Cid int `json:"cid"`
IdType int `json:"idType"`
IdType int `json:"idType"` // 用户类型 1:合伙人 2:高管
Credentials string `json:"credentials"` // 登录类型 1:密码 2:验证码
ClientId string `json:"clientId"`
}
... ...
... ... @@ -15,4 +15,6 @@ type PartnersRequest struct {
JoinWays []JoinWays `json:"joinWays"`
// 分红排序(0.从多到少 1.从少到多)
SortBy int `json:"sortBy"`
// 合伙人姓名
Keyword string `json:"keyword"`
}
... ...
package protocol
import "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol/company"
const (
BonusTotal = iota //0 累计分红
BonusOutstanding //1 分红支出
... ... @@ -38,6 +40,9 @@ type DividendOrdersRequest struct {
StartTime int64 `json:"startTime"`
EndTime int64 `json:"endTime" valid:"Required"`
// 合作类型(空或不传,即所有类型)
JoinWays []*company.JoinWays `json:"joinWays"`
PageIndex int `json:"pageIndex,omitempty"`
PageSize int `json:"pageSize,omitempty"`
... ...
... ... @@ -24,6 +24,7 @@ type OrderDetailResponse struct {
// MyDividend float64 `json:"myDividend"`
// MyDividendPercent float64 `json:"myDividendPercent"`
//}
type OrderDetail struct {
Id int64 `json:"id"`
OrderNo string `json:"orderNo"` //订单号
... ... @@ -36,6 +37,7 @@ type OrderDetail struct {
Products interface{} `json:"products"`
Total interface{} `json:"total"`
}
type Customer struct {
Uname string `json:"uname"`
Phone string `json:"phone"`
... ... @@ -110,8 +112,11 @@ type OrderListItem struct {
OrderStatus int `json:"-"`
//实际订单数量
OrderActualCount int `json:"-"`
// 订单区域
OrderDistrict map[string]interface{} `json:"orderDistrict"`
//订单金额
OrderAmount float64 `json:"orderAmount"`
// 订单更新时间
UpdateTime int64 `json:"updateTime"`
//我的分红
MyDividend float64 `json:"dividendReceivable"`
... ...