...
|
...
|
@@ -2,19 +2,24 @@ package service |
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"strings"
|
|
|
"time"
|
|
|
|
|
|
"github.com/astaxie/beego/logs"
|
|
|
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/event/subscriber"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/orderinfo/command"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/orderinfo/query"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
|
|
|
domainService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain/service"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/dao"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
|
|
|
)
|
|
|
|
|
|
//OrderService 管理员相关服务
|
|
|
//OrderService 自建订单,意向单,实发订单
|
|
|
type OrderInfoService struct {
|
|
|
}
|
|
|
|
...
|
...
|
@@ -151,6 +156,7 @@ func (service OrderInfoService) GetOrderDetail(getOrderQuery query.GetOrderQuery |
|
|
return order, nil
|
|
|
}
|
|
|
|
|
|
//CreateNewOrder 创建订单
|
|
|
func (service OrderInfoService) CreateNewOrder(cmd command.CreateOrderCommand) (*domain.OrderBase, error) {
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
...
|
...
|
@@ -436,9 +442,11 @@ func (service OrderInfoService) UpdateOrderData(cmd command.UpdateOrderCommand) |
|
|
oldOrderData.Goods = newOrderGoods
|
|
|
//删不需要的订单总不需要的商品
|
|
|
delGoods = service.deleteOldOrderGoods(newOrderGoods, oldOrderGoods)
|
|
|
err = orderGoodRepository.Remove(oldOrderData.Id, cmd.CompanyId, delGoods...)
|
|
|
if err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("删除订单中的商品数据失败:%s", err))
|
|
|
if len(delGoods) > 0 {
|
|
|
err = orderGoodRepository.Remove(oldOrderData.Id, cmd.CompanyId, delGoods...)
|
|
|
if err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("删除订单中的商品数据失败:%s", err))
|
|
|
}
|
|
|
}
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
if err != nil {
|
...
|
...
|
@@ -612,7 +620,7 @@ func (service OrderInfoService) DisableOrEnable(cmd command.DisableOrderCommand) |
|
|
return nil
|
|
|
}
|
|
|
|
|
|
//UpdateGoodBouns 更新货品的分红相关的数值
|
|
|
//UpdateGoodBouns 分红时,更新货品的分红相关的数值
|
|
|
func (service OrderInfoService) UpdateGoodBouns(cmd command.UpdateGoodBouns) error {
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
...
|
...
|
@@ -687,7 +695,7 @@ func (service OrderInfoService) UpdateGoodBouns(cmd command.UpdateGoodBouns) err |
|
|
}
|
|
|
}
|
|
|
oldOrderData.Goods = oldOrderGoods
|
|
|
//变更订单类型
|
|
|
|
|
|
err = oldOrderData.Compute()
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中合计的数值失败:%s", err))
|
...
|
...
|
@@ -707,3 +715,466 @@ func (service OrderInfoService) UpdateGoodBouns(cmd command.UpdateGoodBouns) err |
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
//PageListOrderBouns 获取订单的分红列表
|
|
|
func (service OrderInfoService) PageListOrderBonus(listOrderQuery query.ListOrderBonusQuery) ([]map[string]interface{}, int, error) {
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, 0, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
|
return nil, 0, err
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
var (
|
|
|
ordersM []models.OrderBase
|
|
|
orders []domain.OrderBase
|
|
|
cnt int
|
|
|
orderBaseDao *dao.OrderBaseDao
|
|
|
)
|
|
|
|
|
|
if orderBaseDao, err = factory.CreateOrderBaseDao(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, cnt, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
ordersM, cnt, err = orderBaseDao.OrderBonusListByCondition(
|
|
|
listOrderQuery.CompanyId,
|
|
|
listOrderQuery.OrderType,
|
|
|
listOrderQuery.PartnerOrCode,
|
|
|
listOrderQuery.Limit,
|
|
|
listOrderQuery.Offset,
|
|
|
)
|
|
|
for _, orderModel := range ordersM {
|
|
|
order := domain.OrderBase{
|
|
|
Id: orderModel.Id, OrderType: orderModel.OrderType, OrderCode: orderModel.OrderCode,
|
|
|
DeliveryCode: orderModel.DeliveryCode, Buyer: orderModel.Buyer, RegionInfo: orderModel.RegionInfo,
|
|
|
PartnerId: orderModel.PartnerId, SalesmanBonusPercent: orderModel.SalesmanBonusPercent,
|
|
|
CreateTime: orderModel.CreateTime, DeliveryTime: orderModel.DeliveryTime, UpdateTime: orderModel.UpdateTime,
|
|
|
IsDisable: orderModel.IsDisable,
|
|
|
OrderCompute: domain.OrderCompute{
|
|
|
PlanPartnerBonus: orderModel.PlanPartnerBonus, UsePartnerBonus: orderModel.UsePartnerBonus,
|
|
|
PartnerBonusHas: orderModel.PartnerBonusHas, PartnerBonusNot: orderModel.PartnerBonusNot,
|
|
|
PartnerBonusExpense: orderModel.PartnerBonusExpense, SalesmanBonus: orderModel.SalesmanBonus,
|
|
|
PlanOrderCount: orderModel.PlanOrderCount, PlanOrderAmount: orderModel.PlanOrderAmount,
|
|
|
UseOrderCount: orderModel.UseOrderCount, UseOrderAmount: orderModel.UseOrderAmount,
|
|
|
},
|
|
|
PartnerInfo: domain.Partner{
|
|
|
Id: orderModel.PartnerId,
|
|
|
},
|
|
|
BonusStatus: orderModel.BonusStatus,
|
|
|
CompanyId: orderModel.CompanyId,
|
|
|
}
|
|
|
orders = append(orders, order)
|
|
|
}
|
|
|
var (
|
|
|
PartnerInfoRepository domain.PartnerInfoRepository
|
|
|
orderGoodRepository domain.OrderGoodRepository
|
|
|
)
|
|
|
if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if orderGoodRepository, err = factory.CreateOrderGoodRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
var resp = []map[string]interface{}{}
|
|
|
for i := range orders {
|
|
|
partnerData := &domain.PartnerInfo{}
|
|
|
partnerData, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{
|
|
|
UserId: orders[i].PartnerId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
logs.Error("获取合伙(id=%d)失败%s", orders[i].PartnerId, err)
|
|
|
} else {
|
|
|
orders[i].PartnerInfo = partnerData.Partner
|
|
|
}
|
|
|
var (
|
|
|
goods []domain.OrderGood
|
|
|
hasBonusPercent bool
|
|
|
)
|
|
|
goods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{OrderId: orders[i].Id})
|
|
|
for ii := range goods {
|
|
|
if goods[ii].PartnerBonusPercent > 0 {
|
|
|
hasBonusPercent = true
|
|
|
}
|
|
|
}
|
|
|
listItem := map[string]interface{}{
|
|
|
"updateTime": orders[i].UpdateTime.Local().Format("2006-01-02 15:04:05"),
|
|
|
"id": orders[i].Id,
|
|
|
"shipmentsId": orders[i].DeliveryCode,
|
|
|
"partner": orders[i].PartnerInfo.PartnerName,
|
|
|
"dividendsReceivable": fmt.Sprint(orders[i].GetCurrentPartnerBonus()),
|
|
|
"dividendSpending": fmt.Sprint(orders[i].OrderCompute.PartnerBonusExpense),
|
|
|
"receiveDividends": fmt.Sprint(orders[i].OrderCompute.PartnerBonusHas),
|
|
|
"uncollectedDividends": fmt.Sprint(orders[i].OrderCompute.PartnerBonusNot),
|
|
|
"stateOfPayment": orders[i].BonusStatus,
|
|
|
"orderType": orders[i].OrderType,
|
|
|
"orderTypeName": domain.GetOrderBaseTypeName(orders[i].OrderType),
|
|
|
"orderNumber": orders[i].OrderCode,
|
|
|
}
|
|
|
if !hasBonusPercent {
|
|
|
listItem["receiveDividends"] = "-"
|
|
|
listItem["dividendsReceivable"] = "-"
|
|
|
listItem["dividendSpending"] = "-"
|
|
|
listItem["uncollectedDividends"] = "-"
|
|
|
}
|
|
|
resp = append(resp, listItem)
|
|
|
}
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
if err != nil {
|
|
|
return resp, cnt, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
return resp, cnt, nil
|
|
|
}
|
|
|
|
|
|
//GetOrderBestshopInfo 获取来源于xiangmi订单的详情以及分红数据
|
|
|
func (service OrderInfoService) GetOrderBestshopInfoWithBonus(orderBaseId int64, companyId int64) (interface{}, error) {
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
err error
|
|
|
)
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
var (
|
|
|
orderBaseRepository domain.OrderBaseRepository
|
|
|
orderGoodRepository domain.OrderGoodRepository
|
|
|
orderBestshopRepository domain.OrderBestshopRepository
|
|
|
orderGoodBestshopRepository domain.OrderGoodBestshopRepository
|
|
|
orderLogRepository domain.OrderLogRepository
|
|
|
partnerRepository domain.PartnerInfoRepository
|
|
|
)
|
|
|
if orderBaseRepository, err = factory.CreateOrderBaseRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if orderGoodRepository, err = factory.CreateOrderGoodRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if orderBestshopRepository, err = factory.CreateOrderBestshopRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if orderGoodBestshopRepository, err = factory.CreateOrderGoodBestshopRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if orderLogRepository, err = factory.CreateOrderLogRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if partnerRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
var (
|
|
|
orderData *domain.OrderBase
|
|
|
orderGoods []domain.OrderGood
|
|
|
orderBestshopData *domain.OrderBestShop
|
|
|
orderGoodBestshop []domain.OrderGoodBestShop
|
|
|
orderLogs []domain.OrderLog
|
|
|
partnerInfo *domain.PartnerInfo
|
|
|
)
|
|
|
|
|
|
orderData, err = orderBaseRepository.FindOne(domain.OrderBaseFindOneQuery{
|
|
|
OrderId: orderBaseId,
|
|
|
CompanyId: companyId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
e := fmt.Sprintf("获取订单(order_base)数据失败,id=%d,company_id=%d,err=%s", orderBaseId, companyId, err)
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
|
|
|
}
|
|
|
if orderData.OrderType != domain.OrderTypeBestShop {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, "获取的订单数据失败,OrderType err")
|
|
|
}
|
|
|
orderGoods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{OrderId: orderData.Id})
|
|
|
if err != nil {
|
|
|
e := fmt.Sprintf("获取订单的商品(order_good)数据失败,order_id=%d,err=%s", orderData.Id, err)
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
|
|
|
}
|
|
|
orderData.Goods = orderGoods
|
|
|
partnerInfo, err = partnerRepository.FindOne(domain.PartnerFindOneQuery{UserId: orderData.PartnerId})
|
|
|
if err != nil {
|
|
|
e := fmt.Sprintf("获取订单中的合伙人(partner)数据失败,id=%d,order_id=%d,err=%s", orderData.PartnerId, orderData.Id, err)
|
|
|
logs.Error(e)
|
|
|
}
|
|
|
orderData.PartnerInfo = partnerInfo.Partner
|
|
|
orderBestshopData, err = orderBestshopRepository.FindOne(domain.OrderBestshopFindOneQuery{OrderId: orderData.DataFrom.DataId})
|
|
|
if err != nil {
|
|
|
e := fmt.Sprintf("获取xiangmi订单(order_bestshop)数据失败,id=%d,err=%s", orderData.DataFrom.DataId, err)
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
|
|
|
}
|
|
|
orderGoodBestshop, err = orderGoodBestshopRepository.Find(domain.OrderGoodBestshopFindQuery{OrderId: orderBestshopData.Id})
|
|
|
if err != nil {
|
|
|
e := fmt.Sprintf("获取xiangmi订单货品(order_good_bestshop)数据失败,order_id=%d,err=%s", orderBestshopData.Id, err)
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
|
|
|
}
|
|
|
orderBestshopData.Goods = orderGoodBestshop
|
|
|
orderLogs, err = orderLogRepository.Find(domain.OrderLogFindQuery{OrderId: orderData.Id})
|
|
|
if err != nil {
|
|
|
e := fmt.Sprintf("获取订单的修改记录(order_log)失败,err=%s", err)
|
|
|
logs.Error(e)
|
|
|
}
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
if err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
result := service.buildOrderBestshopInfoData(orderData, orderBestshopData, orderLogs)
|
|
|
return result, nil
|
|
|
}
|
|
|
|
|
|
//BuildOrderBestshopInfoData 构建前端需要的数据结构
|
|
|
func (service OrderInfoService) buildOrderBestshopInfoData(orderBase *domain.OrderBase,
|
|
|
orderBestshop *domain.OrderBestShop, orderLogs []domain.OrderLog) interface{} {
|
|
|
orderGoodBestshopMap := map[int64]*domain.OrderGoodBestShop{}
|
|
|
for i := range orderBestshop.Goods {
|
|
|
goodid := orderBestshop.Goods[i].Id
|
|
|
orderGoodBestshopMap[goodid] = &orderBestshop.Goods[i]
|
|
|
}
|
|
|
//订单中的商品
|
|
|
productDetail := []map[string]interface{}{}
|
|
|
var hasPartnerBonusPercent bool
|
|
|
for i := range orderBase.Goods {
|
|
|
detail := map[string]interface{}{
|
|
|
"commodityName": orderBase.Goods[i].GoodName,
|
|
|
"productCodes": "",
|
|
|
"commodityCode": "",
|
|
|
"univalence": orderBase.Goods[i].Price,
|
|
|
"orderNum": orderBase.Goods[i].GetCurrentGoodNumber(),
|
|
|
"commodityPrice": orderBase.Goods[i].GetCurrentAmount(),
|
|
|
"partnerDividends": "",
|
|
|
"productId": orderBase.Goods[i].Id,
|
|
|
"paymentStatus": orderBase.Goods[i].BonusStatus,
|
|
|
"partnerRatio": orderBase.Goods[i].PartnerBonusPercent,
|
|
|
}
|
|
|
if orderBase.Goods[i].PartnerBonusPercent >= 0 {
|
|
|
hasPartnerBonusPercent = true
|
|
|
detail["partnerDividends"] = fmt.Sprint(orderBase.Goods[i].GetCurrentPartnerBonus())
|
|
|
}
|
|
|
goodBestshopId := orderBase.Goods[i].DataFrom.DataId
|
|
|
if v, ok := orderGoodBestshopMap[goodBestshopId]; ok {
|
|
|
detail["productCodes"] = v.Sn
|
|
|
detail["commodityCode"] = v.Bn
|
|
|
}
|
|
|
productDetail = append(productDetail, detail)
|
|
|
}
|
|
|
product := map[string]interface{}{
|
|
|
"orderNumCount": orderBase.GetCurrentOrderCount(),
|
|
|
"partnerDividendsCount": "",
|
|
|
"orderAmountAdjustmentCount": orderBase.GetCurrentOrderAmount(),
|
|
|
"detail": productDetail,
|
|
|
}
|
|
|
if hasPartnerBonusPercent {
|
|
|
product["partnerDividendsCount"] = fmt.Sprint(orderBase.GetCurrentPartnerBonus())
|
|
|
}
|
|
|
//订单描述
|
|
|
order := map[string]interface{}{
|
|
|
"orderId": orderBase.Id,
|
|
|
"orderState": orderBestshop.OrderState,
|
|
|
"customers": orderBestshop.BuyerName,
|
|
|
"address": orderBestshop.BuyerAddress,
|
|
|
"remarks": orderBestshop.BuyerRemark,
|
|
|
"partner": orderBase.PartnerInfo.PartnerName,
|
|
|
"phone": orderBestshop.BuyerPhone,
|
|
|
"orderTime": orderBestshop.OrderTime,
|
|
|
"shippingStatus": orderBestshop.DeliveryState,
|
|
|
"partnerDividends": "",
|
|
|
"receivedDividends": "",
|
|
|
"notReceivedDividend": "",
|
|
|
"dividendSpending": "",
|
|
|
"orderNumber": orderBase.OrderCode,
|
|
|
}
|
|
|
if hasPartnerBonusPercent {
|
|
|
order["partnerDividends"] = fmt.Sprint(orderBase.GetCurrentPartnerBonus())
|
|
|
order["receivedDividends"] = fmt.Sprint(orderBase.OrderCompute.PartnerBonusHas)
|
|
|
order["notReceivedDividend"] = fmt.Sprint(orderBase.OrderCompute.PartnerBonusNot)
|
|
|
order["dividendSpending"] = fmt.Sprint(orderBase.OrderCompute.PartnerBonusExpense)
|
|
|
}
|
|
|
modifyLog := []map[string]interface{}{}
|
|
|
for i := range orderLogs {
|
|
|
m := map[string]interface{}{
|
|
|
"title": orderLogs[i].LogAction,
|
|
|
"time": orderLogs[i].AlterTime.Local().Format("2006-01-02 15:04:05"),
|
|
|
"userName": orderLogs[i].Operator,
|
|
|
"id": orderLogs[i].Id,
|
|
|
}
|
|
|
detail := []map[string]string{}
|
|
|
for ii, vv := range orderLogs[i].Descript {
|
|
|
d := map[string]string{
|
|
|
"updateTitle": vv.Title,
|
|
|
"id": fmt.Sprint(ii),
|
|
|
"content": vv.Item,
|
|
|
}
|
|
|
if len(vv.Action) > 0 {
|
|
|
d["content"] = vv.Item + ":" + strings.Join(vv.Action, ";")
|
|
|
}
|
|
|
detail = append(detail, d)
|
|
|
}
|
|
|
m["updateList"] = detail
|
|
|
modifyLog = append(modifyLog, m)
|
|
|
}
|
|
|
|
|
|
result := map[string]interface{}{
|
|
|
"order": order,
|
|
|
"product": product,
|
|
|
"modify": modifyLog,
|
|
|
"remark": orderBase.Remark.RemarkBonus,
|
|
|
}
|
|
|
return result
|
|
|
}
|
|
|
|
|
|
//UpdateBounsWithGoodNumber 分红时,因修改订单中商品的数量发生分红变动
|
|
|
func (service OrderInfoService) UpdateBonusByGoodNumber(orderId int64, goodId int64, adminId int64, goodNumber int, reason string) error {
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
err error
|
|
|
)
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
|
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
var (
|
|
|
orderBonuSrv domainService.OrderBonusService
|
|
|
)
|
|
|
orderBonuSrv, err = factory.CreateOrderBonusService(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
orderBonuSrv.Subscribe(&subscriber.OrderLogSubscriber{
|
|
|
TransactionContext: transactionContext.(*transaction.TransactionContext),
|
|
|
})
|
|
|
err = orderBonuSrv.UpdateBounsByGoodNumber(orderId, adminId, goodId, goodNumber, reason)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
//UpdateBounsByPartnerBonusPercent 分红时,因修改订单中商品的合伙人分行比例发生分红变动
|
|
|
func (service OrderInfoService) UpdateBonusByPartnerBonusPercent(orderId int64, goodId int64, adminId int64, percent float64, reason string) error {
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
err error
|
|
|
)
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
|
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
var (
|
|
|
orderBonuSrv domainService.OrderBonusService
|
|
|
)
|
|
|
orderBonuSrv, err = factory.CreateOrderBonusService(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
orderBonuSrv.Subscribe(&subscriber.OrderLogSubscriber{
|
|
|
TransactionContext: transactionContext.(*transaction.TransactionContext),
|
|
|
})
|
|
|
err = orderBonuSrv.UpdateBounsByPartnerBonusPercent(orderId, adminId, goodId, percent, reason)
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
//PayPartnerBonusWithOrderBestshop 支付分红,海鲜干货的订单 (orderType=domain.OrderTypeBestShop)
|
|
|
func (service OrderInfoService) PayPartnerBonusWithOrderBestshop(orderId int64, goodId int64, adminId int64) error {
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
err error
|
|
|
)
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
|
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
var (
|
|
|
orderBonuSrv domainService.OrderBonusService
|
|
|
)
|
|
|
orderBonuSrv, err = factory.CreateOrderBonusService(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
orderBonuSrv.Subscribe(&subscriber.OrderLogSubscriber{
|
|
|
TransactionContext: transactionContext.(*transaction.TransactionContext),
|
|
|
})
|
|
|
err = orderBonuSrv.PayOrderGoodBonus(orderId, goodId, adminId)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
//PayPartnerBonusWithOrderBestshop 支付分红,海鲜干货的订单 (orderType=domain.OrderTypeBestShop)
|
|
|
func (service OrderInfoService) UpdateOrderRemarkBonus(orderId int64, adminId int64, remark string) error {
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
err error
|
|
|
)
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
|
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
var (
|
|
|
orderBonuSrv domainService.OrderBonusService
|
|
|
)
|
|
|
orderBonuSrv, err = factory.CreateOrderBonusService(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
orderBonuSrv.Subscribe(&subscriber.OrderLogSubscriber{
|
|
|
TransactionContext: transactionContext.(*transaction.TransactionContext),
|
|
|
})
|
|
|
err = orderBonuSrv.UpdateOrderRemarkBonus(orderId, adminId, remark)
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
return nil
|
|
|
} |
...
|
...
|
|