...
|
...
|
@@ -789,6 +789,188 @@ func (service OrderInfoService) PageListOrderBonus(listOrderQuery query.ListOrde |
|
|
return orders, cnt, nil
|
|
|
}
|
|
|
|
|
|
//GetOrderBestshopInfo 获取来源于海鲜干货订单的详情以及分红数据
|
|
|
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("获取海鲜干货订单(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("获取海鲜干货订单货品(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]
|
|
|
}
|
|
|
//订单描述
|
|
|
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,
|
|
|
}
|
|
|
//订单中的商品
|
|
|
product := map[string]interface{}{
|
|
|
"orderNumCount": orderBase.GetCurrentOrderCount(),
|
|
|
"partnerDividendsCount": orderBase.GetCurrentPartnerBonus(),
|
|
|
"orderAmountAdjustmentCount": orderBase.GetCurrentOrderAmount(),
|
|
|
}
|
|
|
productDetail := []map[string]interface{}{}
|
|
|
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": orderBase.Goods[i].GetCurrentPartnerBonus(),
|
|
|
"productId": orderBase.Goods[i].Id,
|
|
|
"paymentStatus": orderBase.Goods[i].BonusStatus,
|
|
|
"partnerRatio": orderBase.Goods[i].PartnerBonusPercent,
|
|
|
}
|
|
|
goodBestshopId := orderBase.Goods[i].DataFrom.DataId
|
|
|
if v, ok := orderGoodBestshopMap[goodBestshopId]; ok {
|
|
|
detail["productCodes"] = v.Sn
|
|
|
detail["commodityCode"] = v.Bn
|
|
|
}
|
|
|
}
|
|
|
product["detail"] = productDetail
|
|
|
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": fmt.Sprintf("%s:%s;%s", vv.Item, vv.Action, vv.Result),
|
|
|
}
|
|
|
detail = append(detail, d)
|
|
|
}
|
|
|
m["updateList"] = detail
|
|
|
modifyLog = append(modifyLog, m)
|
|
|
}
|
|
|
|
|
|
result := map[string]interface{}{
|
|
|
"order": order,
|
|
|
"product": product,
|
|
|
"modify": modifyLog,
|
|
|
}
|
|
|
return result
|
|
|
}
|
|
|
|
|
|
//UpdateBounsWithGoodNumber 分红时,因修改订单中商品的数量发生分红变动
|
|
|
func (service OrderInfoService) UpdateBonusByGoodNumber() error {
|
|
|
var (
|
...
|
...
|
|