作者 yangfu

Merge branch 'dev' into feature_review

... ... @@ -353,10 +353,12 @@ func CompaniesLogin(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)
... ... @@ -421,10 +423,12 @@ func CompaniesLoginByCredential(header *protocol.RequestHeader, request *protoco
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 初始化
... ... @@ -462,11 +466,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)
... ...
... ... @@ -149,10 +149,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
)
... ... @@ -163,6 +163,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
}
... ... @@ -175,18 +179,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
}
... ...
... ... @@ -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{})
}
}
... ...
... ... @@ -212,7 +212,12 @@ func List(header *protocol.RequestHeader, request *protocol.OrderListRequest) (r
total, orders, _ = OrderRepository.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)
}
}
... ...
... ... @@ -19,8 +19,11 @@ var BUSINESS_ADMIN_PLATFORM_ID = "25" //合伙人模块
var DEFAULT_GUEST_COMPANY int = 10011
var SHARE_SHOP_PREVIEW_IMADGE = "https://media.fjmaimaimai.com/image/default/6E0A8136F1654B24B141150487FADC04-6-2.jpg" //分享店铺预览图
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")
... ...
... ... @@ -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
}
}
... ...
... ... @@ -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
... ...