作者 唐旭辉

更新

... ... @@ -2,7 +2,6 @@ package service
import (
"fmt"
"strings"
"time"
"github.com/astaxie/beego/logs"
... ... @@ -902,212 +901,6 @@ 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": orderBase.Buyer.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 (
... ...
package service
import (
"fmt"
"strings"
"github.com/astaxie/beego/logs"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
)
//GetOrderInfoWithBonus 获取订单的分红详情
func (service OrderInfoService) GetOrderInfoWithBonus(orderBaseId int64, companyId int64) (interface{}, error) {
var err error
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
var (
orderBaseRepository domain.OrderBaseRepository
order *domain.OrderBase
)
if orderBaseRepository, err = factory.CreateOrderBaseRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
order, err = orderBaseRepository.FindOne(domain.OrderBaseFindOneQuery{
OrderId: orderBaseId,
CompanyId: companyId,
})
if err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("获取订单数据失败:%s", err))
}
var (
returnData interface{}
)
switch order.OrderType {
case domain.OrderIntention:
returnData, err = service.GetOrderBaseDetailWithBonus(orderBaseId, companyId)
case domain.OrderTypeBestShop:
returnData, err = service.GetOrderBestshopInfoWithBonus(orderBaseId, companyId)
}
return returnData, err
}
//GetOrderBaseDetailWithBonus 获取实际订单分红详情
func (service OrderInfoService) GetOrderBaseDetailWithBonus(orderBaseId int64, companyId int64) (interface{}, error) {
//实际业务
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
var (
orderBaseRepository domain.OrderBaseRepository
partnerInfoRepository domain.PartnerInfoRepository
orderGoodRepository domain.OrderGoodRepository
orderLogRepository domain.OrderLogRepository
order *domain.OrderBase
)
if err = transactionContext.StartTransaction(); err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
if orderBaseRepository, err = factory.CreateOrderBaseRepository(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 partnerInfoRepository, err = factory.CreatePartnerInfoRepository(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())
}
order, err = orderBaseRepository.FindOne(domain.OrderBaseFindOneQuery{
OrderId: orderBaseId,
CompanyId: companyId,
})
if err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("获取订单数据失败:%s", err))
}
var (
partnerData *domain.PartnerInfo
goods []domain.OrderGood
orderLogs []domain.OrderLog
)
partnerData, err = partnerInfoRepository.FindOne(domain.PartnerFindOneQuery{
UserId: order.PartnerId,
CompanyId: companyId,
})
if err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("检索合伙人数据失败:%s", err))
}
order.PartnerInfo = partnerData.Partner
goods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{
OrderId: order.Id,
CompanyId: companyId,
})
if err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("获取订单中的商品列表失败:%s", err))
}
order.Goods = goods
orderLogs, err = orderLogRepository.Find(domain.OrderLogFindQuery{OrderId: order.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.buildOrderBaseInfoData(order, orderLogs)
return result, nil
}
//BuildOrderBestshopInfoData 构建前端需要的数据结构
func (service OrderInfoService) buildOrderBaseInfoData(orderBase *domain.OrderBase, orderLogs []domain.OrderLog) interface{} {
//订单中的商品
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())
}
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,
"orderType": orderBase.OrderType,
"orderState": "",
"customers": orderBase.Buyer.BuyerName,
"address": "",
"remarks": "",
"partner": orderBase.PartnerInfo.PartnerName,
"phone": "",
"orderTime": orderBase.CreateTime.Local().Format("2006-01-02 15:04:05"),
"shippingStatus": orderBase.CreateTime.Local().Format("2006-01-02 15:04:05"),
"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
}
//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,
"orderType": orderBase.OrderType,
"orderState": orderBestshop.OrderState,
"customers": orderBase.Buyer.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
}
... ...
... ... @@ -2,7 +2,6 @@ package controllers
import (
"errors"
"fmt"
"strconv"
"time"
... ... @@ -109,6 +108,119 @@ func (c *OrderDividendController) PageListOrderDividend() {
}
//OrderDividendDetail 订单的分红详情
// func (c *OrderDividendController) OrderDividendDetail() {
// type Parameter struct {
// Id string `json:"id"`
// }
// var (
// param Parameter
// err error
// )
// if err = c.BindJsonData(&param); err != nil {
// logs.Error(err)
// c.ResponseError(errors.New("json数据解析失败"))
// return
// }
// orderid, _ := strconv.ParseInt(param.Id, 10, 64)
// if orderid == 0 {
// c.ResponseError(errors.New("参数错误"))
// return
// }
// companyId := c.GetUserCompany()
// orderSrv := orderService.NewOrderInfoService(nil)
// orderinfo, err := orderSrv.GetOrderDetail(orderQuery.GetOrderQuery{
// OrderId: orderid,
// CompanyId: companyId,
// })
// if err != nil {
// c.ResponseError(err)
// return
// }
// if orderinfo.OrderType != domain.OrderReal {
// c.ResponseError(errors.New("参数错误"))
// return
// }
// allGoods := []map[string]interface{}{}
// for _, v := range orderinfo.Goods {
// detail := map[string]interface{}{
// "productName": v.GoodName,
// "orderNum": v.PlanGoodNumber,
// "univalence": v.Price,
// "partnerRatio": v.PartnerBonusPercent,
// "orderPrice": v.GoodCompute.PlanAmount,
// "partnerDividendsReceivable": v.GoodCompute.PlanPartnerBonus,
// }
// m := map[string]interface{}{
// "detail": detail,
// "quantityControl": "",
// "id": v.Id,
// "stateOfPayment": v.BonusStatus,
// "remark": v.Remark,
// "amountControl": "",
// "partnerDividendControl": "",
// "receivedDividends": v.GoodCompute.PartnerBonusHas,
// "notReceivedDividend": v.GoodCompute.PartnerBonusNot,
// "dividendSpending": v.GoodCompute.PartnerBonusExpense,
// }
// if v.GoodCompute.UseAmount >= 0 {
// m["amountControl"] = fmt.Sprint(v.GoodCompute.UseAmount)
// }
// if v.UseGoodNumber >= 0 {
// m["quantityControl"] = fmt.Sprint(v.UseGoodNumber)
// }
// if v.GoodCompute.UsePartnerBonus >= 0 {
// m["partnerDividendControl"] = fmt.Sprint(v.GoodCompute.UsePartnerBonus)
// }
// allGoods = append(allGoods, m)
// }
// orderData := map[string]interface{}{
// "buyer": orderinfo.Buyer.BuyerName,
// "shipmentsId": orderinfo.DeliveryCode,
// "orderDist": orderinfo.RegionInfo.RegionName,
// "partner": orderinfo.PartnerInfo.PartnerName,
// "id": orderinfo.Id,
// "orderId": orderinfo.OrderCode,
// "partnerCategoryId": orderinfo.PartnerCategory.Id,
// "partnerCategoryName": orderinfo.PartnerCategory.Name,
// }
// dividendCount := map[string]interface{}{
// "orderNum": orderinfo.OrderCompute.PlanOrderCount,
// "orderAmountAdjustment": orderinfo.OrderCompute.PlanOrderAmount,
// "orderNumControl": "",
// "orderAmountAdjustmentControl": "",
// "partnerDividends": orderinfo.OrderCompute.PlanPartnerBonus,
// "partnerDividendsControl": "",
// "receivedDividends": orderinfo.OrderCompute.PartnerBonusHas,
// "notReceivedDividend": orderinfo.OrderCompute.PartnerBonusNot,
// "dividendSpending": orderinfo.OrderCompute.PartnerBonusExpense,
// "commissionProportion": orderinfo.SalesmanBonusPercent,
// "expectedCommission": orderinfo.OrderCompute.SalesmanBonus,
// }
// if orderinfo.OrderCompute.UseOrderAmount >= 0 {
// dividendCount["orderAmountAdjustmentControl"] = fmt.Sprint(orderinfo.OrderCompute.UseOrderAmount)
// }
// if orderinfo.OrderCompute.UsePartnerBonus >= 0 {
// dividendCount["partnerDividendsControl"] = fmt.Sprint(orderinfo.OrderCompute.UsePartnerBonus)
// }
// if orderinfo.OrderCompute.UseOrderCount >= 0 {
// dividendCount["orderNumControl"] = fmt.Sprint(orderinfo.OrderCompute.UseOrderCount)
// }
// rsp := map[string]interface{}{
// "order": orderData,
// "product": allGoods,
// "dividendCount": dividendCount,
// "operationTime": orderinfo.UpdateTime.Local().Format("2006-01-02 15:04:06"),
// }
// if orderinfo.OrderCompute.UseOrderAmount >= 0 {
// rsp["orderNumCountControl"] = fmt.Sprint(orderinfo.OrderCompute.UseOrderAmount)
// }
// if orderinfo.OrderCompute.UseOrderCount >= 0 {
// rsp["orderAmountAdjustmentCountControl"] = fmt.Sprint(orderinfo.OrderCompute.UseOrderCount)
// }
// c.ResponseData(rsp)
// return
// }
func (c *OrderDividendController) OrderDividendDetail() {
type Parameter struct {
Id string `json:"id"`
... ... @@ -129,96 +241,12 @@ func (c *OrderDividendController) OrderDividendDetail() {
}
companyId := c.GetUserCompany()
orderSrv := orderService.NewOrderInfoService(nil)
orderinfo, err := orderSrv.GetOrderDetail(orderQuery.GetOrderQuery{
OrderId: orderid,
CompanyId: companyId,
})
orderinfo, err := orderSrv.GetOrderInfoWithBonus(orderid, companyId)
if err != nil {
c.ResponseError(err)
return
}
if orderinfo.OrderType != domain.OrderReal {
c.ResponseError(errors.New("参数错误"))
return
}
allGoods := []map[string]interface{}{}
for _, v := range orderinfo.Goods {
detail := map[string]interface{}{
"productName": v.GoodName,
"orderNum": v.PlanGoodNumber,
"univalence": v.Price,
"partnerRatio": v.PartnerBonusPercent,
"orderPrice": v.GoodCompute.PlanAmount,
"partnerDividendsReceivable": v.GoodCompute.PlanPartnerBonus,
}
m := map[string]interface{}{
"detail": detail,
"quantityControl": "",
"id": v.Id,
"stateOfPayment": v.BonusStatus,
"remark": v.Remark,
"amountControl": "",
"partnerDividendControl": "",
"receivedDividends": v.GoodCompute.PartnerBonusHas,
"notReceivedDividend": v.GoodCompute.PartnerBonusNot,
"dividendSpending": v.GoodCompute.PartnerBonusExpense,
}
if v.GoodCompute.UseAmount >= 0 {
m["amountControl"] = fmt.Sprint(v.GoodCompute.UseAmount)
}
if v.UseGoodNumber >= 0 {
m["quantityControl"] = fmt.Sprint(v.UseGoodNumber)
}
if v.GoodCompute.UsePartnerBonus >= 0 {
m["partnerDividendControl"] = fmt.Sprint(v.GoodCompute.UsePartnerBonus)
}
allGoods = append(allGoods, m)
}
orderData := map[string]interface{}{
"buyer": orderinfo.Buyer.BuyerName,
"shipmentsId": orderinfo.DeliveryCode,
"orderDist": orderinfo.RegionInfo.RegionName,
"partner": orderinfo.PartnerInfo.PartnerName,
"id": orderinfo.Id,
"orderId": orderinfo.OrderCode,
"partnerCategoryId": orderinfo.PartnerCategory.Id,
"partnerCategoryName": orderinfo.PartnerCategory.Name,
}
dividendCount := map[string]interface{}{
"orderNum": orderinfo.OrderCompute.PlanOrderCount,
"orderAmountAdjustment": orderinfo.OrderCompute.PlanOrderAmount,
"orderNumControl": "",
"orderAmountAdjustmentControl": "",
"partnerDividends": orderinfo.OrderCompute.PlanPartnerBonus,
"partnerDividendsControl": "",
"receivedDividends": orderinfo.OrderCompute.PartnerBonusHas,
"notReceivedDividend": orderinfo.OrderCompute.PartnerBonusNot,
"dividendSpending": orderinfo.OrderCompute.PartnerBonusExpense,
"commissionProportion": orderinfo.SalesmanBonusPercent,
"expectedCommission": orderinfo.OrderCompute.SalesmanBonus,
}
if orderinfo.OrderCompute.UseOrderAmount >= 0 {
dividendCount["orderAmountAdjustmentControl"] = fmt.Sprint(orderinfo.OrderCompute.UseOrderAmount)
}
if orderinfo.OrderCompute.UsePartnerBonus >= 0 {
dividendCount["partnerDividendsControl"] = fmt.Sprint(orderinfo.OrderCompute.UsePartnerBonus)
}
if orderinfo.OrderCompute.UseOrderCount >= 0 {
dividendCount["orderNumControl"] = fmt.Sprint(orderinfo.OrderCompute.UseOrderCount)
}
rsp := map[string]interface{}{
"order": orderData,
"product": allGoods,
"dividendCount": dividendCount,
"operationTime": orderinfo.UpdateTime.Local().Format("2006-01-02 15:04:06"),
}
if orderinfo.OrderCompute.UseOrderAmount >= 0 {
rsp["orderNumCountControl"] = fmt.Sprint(orderinfo.OrderCompute.UseOrderAmount)
}
if orderinfo.OrderCompute.UseOrderCount >= 0 {
rsp["orderAmountAdjustmentCountControl"] = fmt.Sprint(orderinfo.OrderCompute.UseOrderCount)
}
c.ResponseData(rsp)
c.ResponseData(orderinfo)
return
}
... ...
... ... @@ -29,7 +29,7 @@ func init() {
beego.NSRouter("/list", &controllers.OrderDividendController{}, "POST:PageListOrderDividend"),
beego.NSRouter("/edit", &controllers.OrderDividendController{}, "POST:EditOrderDividend"),
beego.NSRouter("/detail", &controllers.OrderDividendController{}, "POST:OrderDividendDetail"),
beego.NSRouter("/mini-program/detail", &controllers.OrderDividendController{}, "POST:OrderDividendDetailForBestshop"),
// beego.NSRouter("/mini-program/detail", &controllers.OrderDividendController{}, "POST:OrderDividendDetailForBestshop"),
beego.NSRouter("/mini-program/modify", &controllers.OrderDividendController{}, "POST:EditOrderDividendForBestshop"),
beego.NSRouter("/mini-program/payDividends", &controllers.OrderDividendController{}, "POST:PayOrderGoodBonusForBestshop"),
beego.NSRouter("/mini-program/remarks", &controllers.OrderDividendController{}, "POST:EditOrderRemarkBonusForBestshop"),
... ...