...
|
...
|
@@ -2,8 +2,6 @@ package service |
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"strings"
|
|
|
"time"
|
|
|
|
|
|
"github.com/astaxie/beego/logs"
|
|
|
|
...
|
...
|
@@ -57,6 +55,7 @@ func (service OrderInfoService) PageListOrderBase(listOrderQuery query.ListOrder |
|
|
listOrderQuery.OrderType,
|
|
|
listOrderQuery.PartnerOrCode,
|
|
|
[2]string{listOrderQuery.UpdateTimeBegin, listOrderQuery.UpdateTimeEnd},
|
|
|
[2]string{listOrderQuery.CreateTimeBegin, listOrderQuery.CreateTimeEnd},
|
|
|
listOrderQuery.PartnerCategory,
|
|
|
listOrderQuery.Limit, listOrderQuery.Offset,
|
|
|
)
|
...
|
...
|
@@ -78,6 +77,8 @@ func (service OrderInfoService) PageListOrderBase(listOrderQuery query.ListOrder |
|
|
UserId: orders[i].PartnerId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
//防崩溃
|
|
|
partnerData = &domain.PartnerInfo{}
|
|
|
logs.Error("获取合伙(id=%d)失败%s", orders[i].PartnerId, err)
|
|
|
}
|
|
|
listIndex := listOrderQuery.Offset + (1 + i)
|
...
|
...
|
@@ -86,7 +87,7 @@ func (service OrderInfoService) PageListOrderBase(listOrderQuery query.ListOrder |
|
|
"createTime": orders[i].CreateTime.Local().Format("2006-01-02 15:04:05"),
|
|
|
"updateTime": orders[i].UpdateTime.Local().Format("2006-01-02 15:04:05"),
|
|
|
"buyer": orders[i].Buyer.BuyerName,
|
|
|
"id": orders[i].Id,
|
|
|
"id": fmt.Sprint(orders[i].Id),
|
|
|
"orderId": orders[i].OrderCode,
|
|
|
"shipmentsId": orders[i].DeliveryCode,
|
|
|
"partner": partnerData.Partner.PartnerName,
|
...
|
...
|
@@ -533,110 +534,6 @@ func (service OrderInfoService) deleteOldOrderGoods(newGoods []domain.OrderGood, |
|
|
return
|
|
|
}
|
|
|
|
|
|
//Delivery 发货
|
|
|
func (service OrderInfoService) Delivery(cmd command.OrderDeliveryCommand) error {
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
err error
|
|
|
)
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
var (
|
|
|
orderBaseRepository domain.OrderBaseRepository
|
|
|
orderGoodRepository domain.OrderGoodRepository
|
|
|
oldOrderData *domain.OrderBase
|
|
|
oldOrderGoods []domain.OrderGood
|
|
|
orderBaseDao *dao.OrderBaseDao
|
|
|
)
|
|
|
|
|
|
if orderBaseRepository, err = factory.CreateOrderBaseRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if orderGoodRepository, err = factory.CreateOrderGoodRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
//获取旧的订单
|
|
|
oldOrderData, err = orderBaseRepository.FindOne(domain.OrderBaseFindOneQuery{
|
|
|
CompanyId: cmd.CompanyId,
|
|
|
OrderId: cmd.OrderId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单:%s", err))
|
|
|
}
|
|
|
if oldOrderData.OrderType != domain.OrderIntention {
|
|
|
return lib.ThrowError(lib.BUSINESS_ERROR, "订单类型已发生变更")
|
|
|
}
|
|
|
if orderBaseDao, err = factory.CreateOrderBaseDao(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
//检查delivery_code是否重复
|
|
|
if ok, err := orderBaseDao.DeliveryCodeExist(cmd.DeliveryCode, cmd.CompanyId, cmd.OrderId); err != nil {
|
|
|
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
} else if ok {
|
|
|
return lib.ThrowError(lib.BUSINESS_ERROR, "发货号已存在")
|
|
|
}
|
|
|
//获取旧的订单中的商品
|
|
|
oldOrderGoods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{
|
|
|
OrderId: cmd.OrderId,
|
|
|
CompanyId: cmd.CompanyId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单中的商品列表失败:%s", err))
|
|
|
}
|
|
|
for _, newGood := range cmd.Goods {
|
|
|
for i := range oldOrderGoods {
|
|
|
if newGood.Id != oldOrderGoods[i].Id {
|
|
|
continue
|
|
|
}
|
|
|
oldOrderGoods[i].GoodName = newGood.GoodName
|
|
|
oldOrderGoods[i].PlanGoodNumber = newGood.PlanGoodNumber
|
|
|
oldOrderGoods[i].Price = newGood.Price
|
|
|
oldOrderGoods[i].PartnerBonusPercent = newGood.PartnerBonusPercent
|
|
|
oldOrderGoods[i].Remark = newGood.Remark
|
|
|
err = oldOrderGoods[i].Compute()
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的数值失败:%s", err))
|
|
|
}
|
|
|
err = oldOrderGoods[i].CurrentBonusStatus.WartPayPartnerBonus(&oldOrderGoods[i])
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的分红数值失败:%s", err))
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
oldOrderData.DeliveryCode = cmd.DeliveryCode
|
|
|
oldOrderData.DeliveryTime = time.Now()
|
|
|
oldOrderData.Goods = oldOrderGoods
|
|
|
//变更订单类型
|
|
|
oldOrderData.OrderType = domain.OrderReal
|
|
|
err = oldOrderData.Compute()
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中合计的数值失败:%s", err))
|
|
|
}
|
|
|
err = orderBaseRepository.Save(oldOrderData)
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单数据失败:%s", err))
|
|
|
}
|
|
|
err = orderGoodRepository.Save(oldOrderGoods)
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单中的商品数据失败:%s", err))
|
|
|
}
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
//DisableOrEnable 开启关闭订单
|
|
|
func (service OrderInfoService) DisableOrEnable(cmd command.DisableOrderCommand) error {
|
|
|
var (
|
...
|
...
|
@@ -681,102 +578,6 @@ func (service OrderInfoService) DisableOrEnable(cmd command.DisableOrderCommand) |
|
|
return nil
|
|
|
}
|
|
|
|
|
|
//UpdateGoodBouns 分红时,更新货品的分红相关的数值
|
|
|
func (service OrderInfoService) UpdateGoodBouns(cmd command.UpdateGoodBouns) error {
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
err error
|
|
|
)
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
var (
|
|
|
orderBaseRepository domain.OrderBaseRepository
|
|
|
orderGoodRepository domain.OrderGoodRepository
|
|
|
oldOrderData *domain.OrderBase
|
|
|
oldOrderGoods []domain.OrderGood
|
|
|
)
|
|
|
if orderBaseRepository, err = factory.CreateOrderBaseRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if orderGoodRepository, err = factory.CreateOrderGoodRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
//获取旧的订单
|
|
|
oldOrderData, err = orderBaseRepository.FindOne(domain.OrderBaseFindOneQuery{
|
|
|
OrderId: cmd.Id,
|
|
|
CompanyId: cmd.CompanyId,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单:%s", err))
|
|
|
}
|
|
|
if oldOrderData.OrderType != domain.OrderReal {
|
|
|
return lib.ThrowError(lib.BUSINESS_ERROR, fmt.Sprintf("指定的订单的订单类型发生变更"))
|
|
|
}
|
|
|
//获取旧的订单中的商品
|
|
|
oldOrderGoods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{
|
|
|
OrderId: cmd.Id,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单中的商品列表失败:%s", err))
|
|
|
}
|
|
|
for _, newGood := range cmd.GoodBouns {
|
|
|
for i := range oldOrderGoods {
|
|
|
if newGood.GoodId != oldOrderGoods[i].Id {
|
|
|
continue
|
|
|
}
|
|
|
oldOrderGoods[i].UseGoodNumber = newGood.UseGoodNumber
|
|
|
oldOrderGoods[i].Remark = newGood.Remark
|
|
|
oldOrderGoods[i].BonusStatus = newGood.BounsStatus
|
|
|
err = oldOrderGoods[i].Compute()
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的数值失败:%s", err))
|
|
|
}
|
|
|
switch newGood.BounsStatus {
|
|
|
case domain.OrderGoodWaitPay:
|
|
|
err = oldOrderGoods[i].CurrentBonusStatus.WartPayPartnerBonus(&oldOrderGoods[i])
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的分红数值失败:%s", err))
|
|
|
}
|
|
|
case domain.OrderGoodHasPay:
|
|
|
err = oldOrderGoods[i].CurrentBonusStatus.PayPartnerBonus(&oldOrderGoods[i])
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的分红数值失败:%s", err))
|
|
|
}
|
|
|
default:
|
|
|
return lib.ThrowError(lib.ARG_ERROR, fmt.Sprintf("货品的支付状态错误"))
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
oldOrderData.Goods = oldOrderGoods
|
|
|
|
|
|
err = oldOrderData.Compute()
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中合计的数值失败:%s", err))
|
|
|
}
|
|
|
err = orderBaseRepository.Save(oldOrderData)
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单数据失败:%s", err))
|
|
|
}
|
|
|
err = orderGoodRepository.Save(oldOrderGoods)
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单中的商品数据失败:%s", err))
|
|
|
}
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
//PageListOrderBouns 获取订单的分红列表
|
|
|
func (service OrderInfoService) PageListOrderBonus(listOrderQuery query.ListOrderBonusQuery) ([]map[string]interface{}, int, error) {
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
...
|
...
|
@@ -806,6 +607,7 @@ func (service OrderInfoService) PageListOrderBonus(listOrderQuery query.ListOrde |
|
|
listOrderQuery.OrderType,
|
|
|
listOrderQuery.PartnerOrCode,
|
|
|
listOrderQuery.PartnerCategory,
|
|
|
[2]string{listOrderQuery.CreateTimeBegin, listOrderQuery.CreateTimeEnd},
|
|
|
listOrderQuery.Limit,
|
|
|
listOrderQuery.Offset,
|
|
|
)
|
...
|
...
|
@@ -862,15 +664,16 @@ func (service OrderInfoService) PageListOrderBonus(listOrderQuery query.ListOrde |
|
|
)
|
|
|
goods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{OrderId: orders[i].Id})
|
|
|
for ii := range goods {
|
|
|
if goods[ii].PartnerBonusPercent > 0 {
|
|
|
if goods[ii].PartnerBonusPercent >= 0 {
|
|
|
hasBonusPercent = true
|
|
|
}
|
|
|
}
|
|
|
listIndex := listOrderQuery.Offset + (1 + i)
|
|
|
listItem := map[string]interface{}{
|
|
|
"index": listIndex,
|
|
|
"createTime": orders[i].CreateTime.Local().Format("2006-01-02 15:04:05"),
|
|
|
"updateTime": orders[i].UpdateTime.Local().Format("2006-01-02 15:04:05"),
|
|
|
"id": orders[i].Id,
|
|
|
"id": fmt.Sprint(orders[i].Id),
|
|
|
"shipmentsId": orders[i].DeliveryCode,
|
|
|
"partner": orders[i].PartnerInfo.PartnerName,
|
|
|
"dividendsReceivable": fmt.Sprint(orders[i].GetCurrentPartnerBonus()),
|
...
|
...
|
@@ -897,284 +700,8 @@ func (service OrderInfoService) PageListOrderBonus(listOrderQuery query.ListOrde |
|
|
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 {
|
|
|
//PayPartnerBonusWithOrderBestshop 支付分红
|
|
|
func (service OrderInfoService) PayPartnerBonus(orderId int64, goodId int64, adminId int64) error {
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
err error
|
...
|
...
|
@@ -1208,7 +735,7 @@ func (service OrderInfoService) PayPartnerBonusWithOrderBestshop(orderId int64, |
|
|
return nil
|
|
|
}
|
|
|
|
|
|
//PayPartnerBonusWithOrderBestshop 支付分红,海鲜干货的订单 (orderType=domain.OrderTypeBestShop)
|
|
|
//UpdateOrderRemarkBonus 订单分红详情,更新备注
|
|
|
func (service OrderInfoService) UpdateOrderRemarkBonus(orderId int64, adminId int64, remark string) error {
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
...
|
...
|
@@ -1268,6 +795,7 @@ func (service OrderInfoService) ListOrderBonusForExcel(listOrderQuery query.List |
|
|
listOrderQuery.OrderType,
|
|
|
listOrderQuery.PartnerOrCode,
|
|
|
listOrderQuery.PartnerCategory,
|
|
|
[2]string{listOrderQuery.CreateTimeBegin, listOrderQuery.CreateTimeEnd},
|
|
|
)
|
|
|
if err != nil {
|
|
|
return nil, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -1287,10 +815,14 @@ func (service OrderInfoService) ListOrderBonusForExcel(listOrderQuery query.List |
|
|
"partner_name": result[i].PartnerName,
|
|
|
"bonus_status": "",
|
|
|
"update_time": result[i].UpdateTime,
|
|
|
"partner_bonus": fmt.Sprint(result[i].PartnerBonus),
|
|
|
"partner_bonus_has": fmt.Sprint(result[i].PartnerBonusHas),
|
|
|
"partner_bonus_not": fmt.Sprint(result[i].PartnerBonusNot),
|
|
|
"partner_bonus_expense": fmt.Sprint(result[i].PartnerBonusExpense),
|
|
|
"create_time": result[i].CreateTime,
|
|
|
"partner_bonus": fmt.Sprintf("%10.2f", result[i].PartnerBonus),
|
|
|
"partner_bonus_has": fmt.Sprintf("%10.2f", result[i].PartnerBonusHas),
|
|
|
"partner_bonus_not": fmt.Sprintf("%10.2f", result[i].PartnerBonusNot),
|
|
|
"partner_bonus_expense": fmt.Sprintf("%10.2f", result[i].PartnerBonusExpense),
|
|
|
}
|
|
|
if len(result[i].DeliveryCode) == 0 {
|
|
|
m["delivery_code"] = "-"
|
|
|
}
|
|
|
if result[i].HasBonusPercent == 0 {
|
|
|
m["partner_bonus"] = "-"
|
...
|
...
|
@@ -1313,7 +845,7 @@ func (service OrderInfoService) ListOrderBonusForExcel(listOrderQuery query.List |
|
|
[2]string{"delivery_code", "发货单号"},
|
|
|
[2]string{"partner_name", "合伙人"},
|
|
|
[2]string{"bonus_status", "支付状态"},
|
|
|
[2]string{"update_time", "最后操作时间"},
|
|
|
[2]string{"create_time", "创建时间"},
|
|
|
[2]string{"partner_bonus", "应收分红"},
|
|
|
[2]string{"partner_bonus_has", "已收分红"},
|
|
|
[2]string{"partner_bonus_not", "未收分红"},
|
...
|
...
|
@@ -1321,3 +853,80 @@ func (service OrderInfoService) ListOrderBonusForExcel(listOrderQuery query.List |
|
|
}
|
|
|
return resultMaps, column, nil
|
|
|
}
|
|
|
|
|
|
func (service OrderInfoService) ListOrderForExcel(listOrderQuery query.ListOrderBaseQuery) ([]map[string]string, [][2]string, error) {
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
|
return nil, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
var (
|
|
|
orderBaseDao *dao.OrderBaseDao
|
|
|
)
|
|
|
|
|
|
if orderBaseDao, err = factory.CreateOrderBaseDao(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
ordersData, err := orderBaseDao.OrderListForExcel(
|
|
|
listOrderQuery.CompanyId,
|
|
|
listOrderQuery.PartnerOrCode,
|
|
|
[2]string{listOrderQuery.UpdateTimeBegin, listOrderQuery.UpdateTimeEnd},
|
|
|
[2]string{listOrderQuery.CreateTimeBegin, listOrderQuery.CreateTimeEnd},
|
|
|
listOrderQuery.PartnerCategory,
|
|
|
)
|
|
|
if err != nil {
|
|
|
return nil, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
if err != nil {
|
|
|
return nil, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
var resultMaps []map[string]string
|
|
|
for i := range ordersData {
|
|
|
m := map[string]string{
|
|
|
"num": fmt.Sprint(i + 1),
|
|
|
"order_code": ordersData[i].OrderCode,
|
|
|
"delivery_code": ordersData[i].DeliveryCode,
|
|
|
"partner_name": ordersData[i].PartnerName,
|
|
|
"update_time": ordersData[i].UpdateTime,
|
|
|
"create_time": ordersData[i].CreateTime,
|
|
|
"plan_order_count": fmt.Sprint(ordersData[i].PlanOrderCount),
|
|
|
"use_order_count": "",
|
|
|
"region_name": fmt.Sprint(ordersData[i].RegionName),
|
|
|
"plan_order_amount": fmt.Sprintf("%10.2f", ordersData[i].PlanOrderAmount),
|
|
|
"use_order_amount": "",
|
|
|
"partner_category": ordersData[i].PartnerCategory,
|
|
|
"buyer_name": ordersData[i].BuyerName,
|
|
|
}
|
|
|
if ordersData[i].UseOrderCount >= 0 {
|
|
|
m["use_order_count"] = fmt.Sprint(ordersData[i].UseOrderCount)
|
|
|
}
|
|
|
if ordersData[i].UseOrderAmount >= 0 {
|
|
|
m["use_order_amount"] = fmt.Sprintf("%10.2f", ordersData[i].UseOrderAmount)
|
|
|
}
|
|
|
resultMaps = append(resultMaps, m)
|
|
|
}
|
|
|
column := [][2]string{
|
|
|
[2]string{"num", "序号"},
|
|
|
[2]string{"order_code", "订单号"},
|
|
|
[2]string{"delivery_code", "发货单号"},
|
|
|
[2]string{"create_time", "创建时间"},
|
|
|
[2]string{"update_time", "更新时间"},
|
|
|
[2]string{"plan_order_count", "订单数量"},
|
|
|
[2]string{"use_order_count", "数量调整"},
|
|
|
[2]string{"plan_order_amount", "订单金额"},
|
|
|
[2]string{"use_order_amount", "金额调整"},
|
|
|
[2]string{"region_name", "订单区域"},
|
|
|
[2]string{"partner_category", "合伙人类型"},
|
|
|
[2]string{"buyer_name", "客户"},
|
|
|
[2]string{"partner_name", "合伙人"},
|
|
|
}
|
|
|
return resultMaps, column, nil
|
|
|
} |
...
|
...
|
|