作者 yangfu

增加:配置注入

... ... @@ -74,6 +74,13 @@ spec:
value: "https://suplus-worth-app-gateway-dev.fjmaimaimai.com"
- name: MMM_OPEN_API_SERVICE_HOST
value: "http://mmm-open-api-dev.fjmaimaimai.com"
- name: UCENTER_SERVICE_HOST
value: "https://suplus-ucenter-dev.fjmaimaimai.com"
- name: BUSINESS_ADMIN_SERVICE_HOST
valueFrom:
configMapKeyRef:
name: suplus-config
key: service.businessadmin
volumes:
- name: accesslogs
emptyDir: {}
\ No newline at end of file
... ...
... ... @@ -74,6 +74,13 @@ spec:
value: "https://ability.fjmaimaimai.com"
- name: MMM_OPEN_API_SERVICE_HOST
value: "https://public-interface.fjmaimaimai.com/openapi"
- name: UCENTER_SERVICE_HOST
value: "https://suplus-ucenter-prd.fjmaimaimai.com"
- name: BUSINESS_ADMIN_SERVICE_HOST
valueFrom:
configMapKeyRef:
name: suplus-config
key: service.businessadmin
volumes:
- name: accesslogs
emptyDir: {}
\ No newline at end of file
... ...
... ... @@ -74,6 +74,13 @@ spec:
value: "https://suplus-worth-app-gateway-dev.fjmaimaimai.com"
- name: MMM_OPEN_API_SERVICE_HOST
value: "http://mmm-open-api-dev.fjmaimaimai.com"
- name: UCENTER_SERVICE_HOST
value: "https://suplus-ucenter-test.fjmaimaimai.com"
- name: BUSINESS_ADMIN_SERVICE_HOST
valueFrom:
configMapKeyRef:
name: suplus-config
key: service.businessadmin
volumes:
- name: accesslogs
emptyDir: {}
\ No newline at end of file
... ...
... ... @@ -22,6 +22,8 @@ func Statistics(header *protocol.RequestHeader, request *protocol.DividendStatis
defer func() {
transactionContext.RollbackTransaction()
}()
// 事业分红统计-查询订单
_, orderAll, e := OrderBaseResponsitory.Find(utils.ObjectJsonToMap(domain.OrderQueryOption{PartnerId: header.UserId, EndTime: time.Now(), SortByCreateTime: domain.DESC, OrderType: domain.OrderReal}))
if e != nil {
log.Error(e)
... ... @@ -32,11 +34,16 @@ func Statistics(header *protocol.RequestHeader, request *protocol.DividendStatis
orderBetween = append(orderBetween, orderAll[i])
}
}
// 事业分红统计-所有订单统计
bonusAll := AllBonusStatics(orderAll, 0)
// 事业分红统计-季度订单统计
bonusQuarters := QuartersBonusStatics(orderBetween, 0)
// 业务分红统计
if bonus, e := BusinessBonusRepository.FindOne(map[string]interface{}{"partner_id": header.UserId, "isDisable": 1}); e == nil {
bonusAll.Receivable += bonus.Bonus
}
rsp = &protocol.DividendStatisticsResponse{}
rsp.Statistics = protocol.DividendStatistics{
Received: bonusAll.Received,
... ... @@ -44,6 +51,7 @@ func Statistics(header *protocol.RequestHeader, request *protocol.DividendStatis
Receivable: bonusAll.Receivable,
Quarters: bonusQuarters,
}
err = transactionContext.CommitTransaction()
return
}
... ...
... ... @@ -2,21 +2,243 @@ 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/log"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol"
"time"
)
func Template(header *protocol.RequestHeader, request *protocol.OrderDetailRequest) (rsp *protocol.OrderDetailResponse, err error) {
// 订单详情
func Detail(header *protocol.RequestHeader, request *protocol.OrderDetailRequest) (rsp *protocol.OrderDetailResponse, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
//OrderResponsitory,_ =factory.CreateOrderRepository(transactionContext)
OrderResponsitory, _ = factory.CreateOrderBaseRepository(transactionContext)
OrderDao, _ = factory.CreateOrderBaseDao(transactionContext)
order *domain.OrderBase
)
if err = transactionContext.StartTransaction(); err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
rsp = &protocol.OrderDetailResponse{}
// 订单详情
if order, err = OrderResponsitory.FindOne(utils.ObjectJsonToMap(request)); err != nil {
log.Error(err)
return
}
rsp.Order = protocol.OrderDetail{
Id: order.Id,
OrderNo: order.OrderCode,
DeliveryNo: order.DeliveryCode,
OrderStatus: orderStatus(order),
CreateTime: order.CreateTime.Unix() * 1000,
UpdateTime: order.UpdateTime.Unix() * 1000,
OrderDistrict: map[string]interface{}{"id": order.RegionInfo.RegionId, "name": order.RegionInfo.RegionName},
Customer: protocol.Customer{Uname: order.Buyer.BuyerName, Phone: order.Buyer.ContactInfo},
Products: orderProducts(order),
Total: orderTotalStatic(order),
}
// 更新已读(关联事件)
if header.UserId == order.PartnerId && order.UpdateTime.After(order.LastViewTime) {
if err = OrderDao.UpdateLastViewTime(order.Id, time.Now()); err != nil {
return
}
}
err = transactionContext.CommitTransaction()
return
}
func orderStatus(order *domain.OrderBase) int {
var hasBonus = false
for i := range order.OrderGood {
good := order.OrderGood[i]
if good.BonusStatus == domain.BonusPaid {
hasBonus = true
break
}
}
if hasBonus {
if order.UseOrderCount >= 0 && order.UseOrderCount < order.PlanOrderCount {
return 3 // 已支付退货
}
return 2 // 已支付分红
}
if !hasBonus {
if order.UseOrderCount >= 0 && order.UseOrderCount < order.PlanOrderCount {
return 4 // 待支付退货
}
return 1
}
return 1
}
func orderProducts(order *domain.OrderBase) interface{} {
var products []map[string]interface{}
for i := range order.OrderGood {
good := order.OrderGood[i]
static := good.OrderBonusStatic()
item := make(map[string]interface{})
item["productName"] = good.GoodName
item["orderCount"] = good.PlanGoodNumber
item["orderAmount"] = good.PlanAmount
item["dividendPercent"] = good.PartnerBonusPercent
item["dividendReceivable"] = static.OrderTotalReceivable() //应收分红
item["dividendReceived"] = static.OrderBonusReceive() //已收分红
item["dividendUnReceive"] = static.OrderBonusWait() // 未收分红
item["dividendExpend"] = static.OrderBonusOutstanding() //分红支出
if len(good.Remark) > 0 {
item["orderUpdateReason"] = good.Remark
}
item["dividendStatus"] = good.Status()
if good.Status() > 2 {
item["countAdjust"] = good.UseGoodNumber
item["amountAdjust"] = good.UseAmount
}
products = append(products, item)
}
return products
}
func orderTotalStatic(order *domain.OrderBase) interface{} {
item := make(map[string]interface{})
static := order.OrderBonusStatic()
item["totalCount"] = order.PlanOrderCount
item["totalAmount"] = order.PlanOrderAmount
item["totalDividendReceivable"] = static.OrderTotalReceivable()
item["totalReceived"] = static.OrderBonusReceive()
item["totalUnReceive"] = static.OrderBonusWait()
item["totalExpend"] = static.OrderBonusOutstanding()
if order.UseOrderCount > 0 {
item["totalCountAdjust"] = order.UseOrderCount
item["totalAmountAdjust"] = order.UseOrderAmount
}
return item
}
// 订单统计
func Statistics(header *protocol.RequestHeader, request *protocol.OrderStatisticsRequest) (rsp *protocol.OrderStatisticsResponse, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
OrderDao, _ = factory.CreateOrderBaseDao(transactionContext)
BusinessBonusRepository, _ = factory.CreateBusinessBonusRepository(transactionContext)
)
if err = transactionContext.StartTransaction(); err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
rsp = &protocol.OrderStatisticsResponse{Statistics: protocol.OrderStatics{}}
// 当天订单/累计订单
if rsp.Statistics.TodayRealQuantity, rsp.Statistics.TodayRealMoney, err = OrderDao.OrderStatics(&domain.OrderStaticQuery{
BeginTime: utils.GetDayBegin().Unix() * 1000,
EndTime: utils.GetDayEnd().Unix() * 1000,
OrderType: domain.OrderReal,
PartnerId: header.UserId,
}); err != nil {
return
}
if rsp.Statistics.CumulativeQuantity, rsp.Statistics.CumulativeMoney, err = OrderDao.OrderStatics(&domain.OrderStaticQuery{
EndTime: time.Now().Unix() * 1000,
OrderType: domain.OrderReal,
PartnerId: header.UserId,
}); err != nil {
return
}
rsp.Statistics.TodayRealMoney = utils.Decimal(rsp.Statistics.TodayRealMoney)
rsp.Statistics.CumulativeMoney = utils.Decimal(rsp.Statistics.CumulativeMoney)
//事业分红/业务分红
var careerBonus, businessBonus, total float64 //,developBonus,appBonus
if bonus, e := OrderDao.OrderBonusStatics(domain.OrderBonusQuery{PartnerId: header.UserId, OrderType: domain.OrderReal}); e == nil {
careerBonus = bonus.Bonus
total += careerBonus
}
if bonus, e := BusinessBonusRepository.FindOne(map[string]interface{}{"partner_id": header.UserId, "isDisable": 1}); e == nil {
businessBonus = bonus.Bonus
total += businessBonus
rsp.Statistics.BusinessMoney = bonus.Bonus
}
if total != 0 {
rsp.Statistics.CareerPercent = utils.DecimalToNumber(careerBonus * 100 / total)
rsp.Statistics.BusinessPercent = utils.DecimalToNumber(businessBonus * 100 / total)
}
err = transactionContext.CommitTransaction()
return
}
// 订单列表
func List(header *protocol.RequestHeader, request *protocol.OrderListRequest) (rsp *protocol.OrderListResponse, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
OrderResponsitory, _ = factory.CreateOrderBaseRepository(transactionContext)
OrderDao, _ = factory.CreateOrderBaseDao(transactionContext)
orders []*domain.OrderBase
)
rsp = &protocol.OrderListResponse{
List: make([]*protocol.OrderListItem, 0),
}
if err = transactionContext.StartTransaction(); err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
// 查询订单列表
queryOption := &domain.OrderQueryOption{
PartnerId: header.UserId,
Limit: request.PageSize,
Offset: request.PageSize * request.PageIndex,
SortByUpdateTime: domain.DESC,
}
if request.StartTime > 0 {
queryOption.BeginTime = time.Unix(request.StartTime/1000, 0)
}
if request.EndTime > 0 {
queryOption.EndTime = time.Unix(request.EndTime/1000, 0)
}
queryOption.OrderType = request.OrderType
_, orders, _ = OrderResponsitory.Find(utils.ObjectJsonToMap(queryOption))
if len(orders) != 0 {
for i := range orders {
rsp.List = append(rsp.List, DomainOrderToOrderListItem(orders[i]))
}
}
// 查询统计数据
if request.PageIndex == 0 {
var (
cumulativeQuantity int
)
//累计实发订单
cumulativeQuantity, _, err = OrderDao.OrderStatics(&domain.OrderStaticQuery{
EndTime: time.Now().Unix() * 1000,
OrderType: domain.OrderReal,
PartnerId: header.UserId,
})
rsp.Total = cumulativeQuantity
}
err = transactionContext.CommitTransaction()
return
}
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(),
}
}
... ...
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/log"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol"
"time"
)
// 订单详情
func Detail(header *protocol.RequestHeader, request *protocol.OrderDetailRequest) (rsp *protocol.OrderDetailResponse, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
OrderResponsitory, _ = factory.CreateOrderBaseRepository(transactionContext)
OrderDao, _ = factory.CreateOrderBaseDao(transactionContext)
order *domain.OrderBase
)
if err = transactionContext.StartTransaction(); err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
rsp = &protocol.OrderDetailResponse{}
if order, err = OrderResponsitory.FindOne(utils.ObjectJsonToMap(request)); err != nil {
log.Error(err)
return
}
rsp.Order = protocol.OrderDetail{
Id: order.Id,
OrderNo: order.OrderCode,
DeliveryNo: order.DeliveryCode,
OrderStatus: orderStatus(order),
CreateTime: order.CreateTime.Unix() * 1000,
UpdateTime: order.UpdateTime.Unix() * 1000,
OrderDistrict: map[string]interface{}{"id": order.RegionInfo.RegionId, "name": order.RegionInfo.RegionName},
Customer: protocol.Customer{Uname: order.Buyer.BuyerName, Phone: order.Buyer.ContactInfo},
Products: orderProducts(order),
Total: orderTotalStatic(order),
}
if header.UserId == order.PartnerId && order.UpdateTime.After(order.LastViewTime) {
if err = OrderDao.UpdateLastViewTime(order.Id, time.Now()); err != nil {
return
}
}
err = transactionContext.CommitTransaction()
return
}
func orderStatus(order *domain.OrderBase) int {
var hasBonus = false
for i := range order.OrderGood {
good := order.OrderGood[i]
if good.BonusStatus == domain.BonusPaid {
hasBonus = true
break
}
}
if hasBonus {
if order.UseOrderCount >= 0 && order.UseOrderCount < order.PlanOrderCount {
return 3 // 已支付退货
}
return 2 // 已支付分红
}
if !hasBonus {
if order.UseOrderCount >= 0 && order.UseOrderCount < order.PlanOrderCount {
return 4 // 待支付退货
}
return 1
}
return 1
}
func orderProducts(order *domain.OrderBase) interface{} {
var products []map[string]interface{}
for i := range order.OrderGood {
good := order.OrderGood[i]
static := good.OrderBonusStatic()
item := make(map[string]interface{})
item["productName"] = good.GoodName
item["orderCount"] = good.PlanGoodNumber
item["orderAmount"] = good.PlanAmount
item["dividendPercent"] = good.PartnerBonusPercent
item["dividendReceivable"] = static.OrderTotalReceivable() //应收分红
item["dividendReceived"] = static.OrderBonusReceive() //已收分红
item["dividendUnReceive"] = static.OrderBonusWait() // 未收分红
item["dividendExpend"] = static.OrderBonusOutstanding() //分红支出
if len(good.Remark) > 0 {
item["orderUpdateReason"] = good.Remark
}
item["dividendStatus"] = good.Status()
if good.Status() > 2 {
item["countAdjust"] = good.UseGoodNumber
item["amountAdjust"] = good.UseAmount
}
products = append(products, item)
}
return products
}
func orderTotalStatic(order *domain.OrderBase) interface{} {
item := make(map[string]interface{})
static := order.OrderBonusStatic()
item["totalCount"] = order.PlanOrderCount
item["totalAmount"] = order.PlanOrderAmount
item["totalDividendReceivable"] = static.OrderTotalReceivable()
item["totalReceived"] = static.OrderBonusReceive()
item["totalUnReceive"] = static.OrderBonusWait()
item["totalExpend"] = static.OrderBonusOutstanding()
if order.UseOrderCount > 0 {
item["totalCountAdjust"] = order.UseOrderCount
item["totalAmountAdjust"] = order.UseOrderAmount
}
return item
}
// 订单统计
func Statistics(header *protocol.RequestHeader, request *protocol.OrderStatisticsRequest) (rsp *protocol.OrderStatisticsResponse, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
OrderDao, _ = factory.CreateOrderBaseDao(transactionContext)
BusinessBonusRepository, _ = factory.CreateBusinessBonusRepository(transactionContext)
//PartnerInfoRepository, _ = factory.CreatePartnerInfoRepositoryIn(transactionContext)
//partnerInfo *domain.PartnerInfo
//orderBonus domain.OrderBonusResponse
)
if err = transactionContext.StartTransaction(); err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
rsp = &protocol.OrderStatisticsResponse{Statistics: protocol.OrderStatics{}}
//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,
OrderType: domain.OrderReal,
PartnerId: header.UserId,
}); err != nil {
return
}
if rsp.Statistics.CumulativeQuantity, rsp.Statistics.CumulativeMoney, err = OrderDao.OrderStatics(&domain.OrderStaticQuery{
EndTime: time.Now().Unix() * 1000,
OrderType: domain.OrderReal,
PartnerId: header.UserId,
}); err != nil {
return
}
rsp.Statistics.TodayRealMoney = utils.Decimal(rsp.Statistics.TodayRealMoney)
rsp.Statistics.CumulativeMoney = utils.Decimal(rsp.Statistics.CumulativeMoney)
//事业分红/业务分红
var careerBonus, businessBonus, total float64 //,developBonus,appBonus
if bonus, e := OrderDao.OrderBonusStatics(domain.OrderBonusQuery{PartnerId: header.UserId, OrderType: domain.OrderReal}); e == nil {
careerBonus = bonus.Bonus
total += careerBonus
}
if bonus, e := BusinessBonusRepository.FindOne(map[string]interface{}{"partner_id": header.UserId, "isDisable": 1}); e == nil {
businessBonus = bonus.Bonus
total += businessBonus
rsp.Statistics.BusinessMoney = bonus.Bonus
}
if total == 0 {
return
}
rsp.Statistics.CareerPercent = utils.DecimalToNumber(careerBonus * 100 / total)
rsp.Statistics.BusinessPercent = utils.DecimalToNumber(businessBonus * 100 / total)
err = transactionContext.CommitTransaction()
return
}
// 订单列表
func List(header *protocol.RequestHeader, request *protocol.OrderListRequest) (rsp *protocol.OrderListResponse, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
OrderResponsitory, _ = factory.CreateOrderBaseRepository(transactionContext)
OrderDao, _ = factory.CreateOrderBaseDao(transactionContext)
orders []*domain.OrderBase
)
rsp = &protocol.OrderListResponse{
List: make([]*protocol.OrderListItem, 0),
Statistics: make(map[string]interface{}),
}
if err = transactionContext.StartTransaction(); err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
queryOption := &domain.OrderQueryOption{
PartnerId: header.UserId,
Limit: request.PageSize,
Offset: request.PageSize * request.PageIndex,
SortByUpdateTime: domain.DESC,
}
if request.StartTime > 0 {
queryOption.BeginTime = time.Unix(request.StartTime/1000, 0)
}
if request.EndTime > 0 {
queryOption.EndTime = time.Unix(request.EndTime/1000, 0)
}
queryOption.OrderType = request.OrderType
_, orders, _ = OrderResponsitory.Find(utils.ObjectJsonToMap(queryOption))
//统计数据
if request.PageIndex == 0 {
var (
cumulativeQuantity int
)
//累计实发订单
cumulativeQuantity, _, err = OrderDao.OrderStatics(&domain.OrderStaticQuery{
EndTime: time.Now().Unix() * 1000,
OrderType: domain.OrderReal,
PartnerId: header.UserId,
})
rsp.Total = cumulativeQuantity
}
if len(orders) == 0 {
return
}
for i := range orders {
rsp.List = append(rsp.List, DomainOrderToOrderListItem(orders[i]))
}
err = transactionContext.CommitTransaction()
return
}
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(),
}
}