作者 Your Name

Merge branch 'test' into master

正在显示 36 个修改的文件 包含 1584 行增加1383 行删除
# 合伙人项目
vendor 文件夹如果不是迫不得已,请不要手动修改其中的文件!
如果手动修改vendor中的文件,需自行进行版本管理。(慎重考虑!慎重考虑!慎重考虑!)
\ No newline at end of file
... ...
package command
type UpdateBusinessBonusCommand struct {
Id int64 `json:"id"`
Bonus float64 `json:"bonus"`
BonusStatus int8 `json:"bonusStatus"`
CompanyId int64 `json:"companyId"`
}
// type UpdateBusinessBonusCommand struct {
// Id int64 `json:"id"`
// Bonus float64 `json:"bonus"`
// BonusStatus int8 `json:"bonusStatus"`
// CompanyId int64 `json:"companyId"`
// }
func (cmd UpdateBusinessBonusCommand) ValidateCommand() error {
return nil
}
// func (cmd UpdateBusinessBonusCommand) ValidateCommand() error {
// return nil
// }
... ...
package query
type GetBusinessBonusQuery struct {
Id int64 `json:"id"`
CompanyId int64 `json:"companyId"`
}
// type GetBusinessBonusQuery struct {
// Id int64 `json:"id"`
// CompanyId int64 `json:"companyId"`
// }
... ...
package query
type ListBusinessBonusQuery struct {
// type ListBusinessBonusQuery struct {
//用户名称匹配
PartnerNameMatch string `json:"userNameMatch" `
// 查询偏离量
Offset int `json:"offset" `
// 查询限制
Limit int `json:"limit"`
PartnerId int64 `json:"partnerId"`
CompanyId int64 `json:"companyId"`
}
// //用户名称匹配
// PartnerNameMatch string `json:"userNameMatch" `
// // 查询偏离量
// Offset int `json:"offset" `
// // 查询限制
// Limit int `json:"limit"`
// PartnerId int64 `json:"partnerId"`
// CompanyId int64 `json:"companyId"`
// }
... ...
package service
type BusinessBonusService struct {
}
// type BusinessBonusService struct {
// }
func NewBusinessBonusService(option map[string]interface{}) *BusinessBonusService {
newService := new(BusinessBonusService)
return newService
}
// func NewBusinessBonusService(option map[string]interface{}) *BusinessBonusService {
// newService := new(BusinessBonusService)
// return newService
// }
// ListBusinessBonus 列表
// func (srv BusinessBonusService) ListBusinessBonus(queryOption query.ListBusinessBonusQuery) (int, interface{}, error) {
... ... @@ -166,3 +166,4 @@ func NewBusinessBonusService(option map[string]interface{}) *BusinessBonusServic
// return returnData, nil
// }
// }
... ...
... ... @@ -111,6 +111,7 @@ func (subscriber *OrderLogSubscriber) HandleEvent(domainEvent coreDomain.DomainE
GoodId: 0,
Descript: []domain.OrderLogDescript{
domain.OrderLogDescript{
GoodId: currentEvent.OrderId,
Title: "编辑备注",
Item: currentEvent.NewRemark,
Action: []string{},
... ... @@ -119,33 +120,58 @@ func (subscriber *OrderLogSubscriber) HandleEvent(domainEvent coreDomain.DomainE
}
err = orderLogRepository.Add(&orderLog)
break
// 支付订单中货品的分红
case event.PAY_ORDER_GOOD_BONUS_EVENT:
currentEvent := domainEvent.(event.PayOrderGoodBonus)
adminUser, err = userRepository.FindOne(domain.UsersFindOneQuery{Id: currentEvent.AdminId})
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
orderLog := domain.OrderLog{
OperatorType: domain.ORDER_LOG_OPERATOR_ADMIN,
OperatorId: currentEvent.AdminId,
OperatorId: currentEvent.Admin.Id,
Operator: adminUser.Name,
AlterTime: time.Now(),
DataFrom: domain.ORDER_LOG_FROM,
LogAction: "支付",
OrderId: currentEvent.OrderId,
GoodId: currentEvent.GoodId,
Descript: []domain.OrderLogDescript{
domain.OrderLogDescript{
OrderId: currentEvent.OrderBase.Id,
Descript: []domain.OrderLogDescript{},
}
for i := range currentEvent.Goods {
m := domain.OrderLogDescript{
GoodId: currentEvent.Goods[i].Id,
Title: "支付分红",
Item: currentEvent.GoodName,
Item: currentEvent.Goods[i].GoodName,
Action: []string{
fmt.Sprintf(`支付分红"¥%.2f"`, currentEvent.PartnerBonus),
},
fmt.Sprintf(`支付分红"¥%.2f"`, currentEvent.Goods[i].GetCurrentPartnerBonus()),
},
}
orderLog.Descript = append(orderLog.Descript, m)
}
err = orderLogRepository.Add(&orderLog)
break
case event.BATCH_PAY_ORDER_GOOD_BONUS_EVENT:
currentEvent := domainEvent.(event.BatchPayOrderGoodBonus)
for i := range currentEvent {
orderLog := domain.OrderLog{
OperatorType: domain.ORDER_LOG_OPERATOR_ADMIN,
OperatorId: currentEvent[i].Admin.Id,
Operator: adminUser.Name,
AlterTime: time.Now(),
DataFrom: domain.ORDER_LOG_FROM,
LogAction: "支付",
OrderId: currentEvent[i].OrderBase.Id,
Descript: []domain.OrderLogDescript{},
}
for ii := range currentEvent[i].Goods {
m := domain.OrderLogDescript{
GoodId: currentEvent[i].Goods[ii].Id,
Title: "支付分红",
Item: currentEvent[i].Goods[ii].GoodName,
Action: []string{
fmt.Sprintf(`支付分红"¥%.2f"`, currentEvent[i].Goods[ii].GetCurrentPartnerBonus()),
},
}
orderLog.Descript = append(orderLog.Descript, m)
}
err = orderLogRepository.Add(&orderLog)
}
break
}
return err
... ... @@ -156,6 +182,7 @@ func (subscriber *OrderLogSubscriber) SubscribedToEventTypes() []string {
event.UPDATE_BONUS_BY_GOOD_NUMBER_EVENT,
event.UPDATE_BONUS_BY_PARTENT_BONUS_PERCENT_EVENT,
event.UPDATE_ORDER_REMARK,
event.BATCH_PAY_ORDER_GOOD_BONUS_EVENT,
event.PAY_ORDER_GOOD_BONUS_EVENT,
}
}
... ...
... ... @@ -6,14 +6,6 @@ import (
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
)
func CreateBusinessBonusService(options map[string]interface{}) (service.BusinessBonusService, error) {
var transactionContext *transaction.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*transaction.TransactionContext)
}
return domainService.NewBusinessBonusService(transactionContext), nil
}
func CreateOrderBonusService(options map[string]interface{}) (service.OrderBonusService, error) {
var transactionContext *transaction.TransactionContext
if value, ok := options["transactionContext"]; ok {
... ...
... ... @@ -15,4 +15,6 @@ type ListOrderBaseQuery struct {
PartnerCategory int `json:"partnerCategory"`
UpdateTimeBegin string `json:"updateTimeBegin"`
UpdateTimeEnd string `json:"updateTimeEnd"`
CreateTimeBegin string `json:"createTimeBegin"`
CreateTimeEnd string `json:"createTimeEnd"`
}
... ...
... ... @@ -10,4 +10,6 @@ type ListOrderBonusQuery struct {
//订单类型
OrderType int `json:"orderType"`
PartnerOrCode string `json:"partnerOrCode"`
CreateTimeBegin string `json:"createTimeBegin"`
CreateTimeEnd string `json:"createTimeEnd"`
}
... ...
... ... @@ -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
}
... ...
package service
import (
"fmt"
"strings"
"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/domain"
domainService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain/service"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
"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())
}
if err = transactionContext.StartTransaction(); err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
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))
}
_ = transactionContext.CommitTransaction()
var (
returnData interface{}
)
switch order.OrderType {
case domain.OrderReal:
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": fmt.Sprint(orderBase.Id),
"orderType": orderBase.OrderType,
"orderTypeName": domain.GetOrderBaseTypeName(orderBase.OrderType),
"orderState": "",
"customers": orderBase.Buyer.BuyerName,
"address": "",
"remarks": "",
"partner": orderBase.PartnerInfo.PartnerName,
"phone": "",
"orderTime": "",
"shippingStatus": "",
"partnerDividends": "",
"receivedDividends": "",
"notReceivedDividend": "",
"dividendSpending": "",
"orderNumber": orderBase.OrderCode,
"shipmentsId": orderBase.DeliveryCode,
"orderArea": orderBase.RegionInfo.RegionName,
"partnerCategory": orderBase.PartnerCategory.Name,
}
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": fmt.Sprint(orderBase.Id),
"orderType": orderBase.OrderType,
"orderTypeName": domain.GetOrderBaseTypeName(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,
"orderArea": orderBase.RegionInfo.RegionName,
"partnerCategory": orderBase.PartnerCategory.Name,
"shipmentsId": orderBase.DeliveryCode,
}
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
}
//BatchPayPartnerBonus 批量支付分红
func (service OrderInfoService) BatchPayPartnerBonus(orderId []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.BatchPayPartnerBonus(orderId, adminId)
if err != nil {
return err
}
err = transactionContext.CommitTransaction()
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
return nil
}
... ...
... ... @@ -8,7 +8,6 @@ import (
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/command"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/query"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"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/lib"
)
... ... @@ -23,7 +22,7 @@ func NewPartnerInfoService(options map[string]interface{}) *PartnerInfoService {
}
// CreatePartnerInfo 创建合伙人
func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.CreatePartnerInfoCommand) (data interface{}, err error) {
func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.CreatePartnerInfoCommand) (data *domain.PartnerInfo, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
... ... @@ -92,19 +91,19 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre
if err = partnerInfoRepository.Save(&newPartnerInfo); err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
var businessBonusSrv service.BusinessBonusService
if businessBonusSrv, err = factory.CreateBusinessBonusService(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
err = businessBonusSrv.EnableOrDisable(newPartnerInfo.Partner.Id)
if err != nil {
e := fmt.Sprintf("更新业务分红(partner_id=%d)数据失败:%s", newPartnerInfo.Partner.Id, err)
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
//var businessBonusSrv service.BusinessBonusService
// if businessBonusSrv, err = factory.CreateBusinessBonusService(map[string]interface{}{
// "transactionContext": transactionContext,
// }); err != nil {
// return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
// }
// err = businessBonusSrv.EnableOrDisable(newPartnerInfo.Partner.Id)
// if err != nil {
// e := fmt.Sprintf("更新业务分红(partner_id=%d)数据失败:%s", newPartnerInfo.Partner.Id, err)
// return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
// }
err = transactionContext.CommitTransaction()
return newPartnerInfo, nil
return &newPartnerInfo, nil
}
// GetPartnerInfo 返回合伙人
... ... @@ -216,18 +215,18 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.Upd
if err = partnerInfoRepository.Save(partnerInfo); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
var businessBonusSrv service.BusinessBonusService
if businessBonusSrv, err = factory.CreateBusinessBonusService(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
//TODO 修改为本地消息订阅
err = businessBonusSrv.EnableOrDisable(partnerInfo.Partner.Id)
if err != nil {
e := fmt.Sprintf("更新业务分红(partner_id=%d)数据失败:%s", partnerInfo.Partner.Id, err)
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
//到0.6.0 彻底删除
// var businessBonusSrv service.BusinessBonusService
// if businessBonusSrv, err = factory.CreateBusinessBonusService(map[string]interface{}{
// "transactionContext": transactionContext,
// }); err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
// }
// err = businessBonusSrv.EnableOrDisable(partnerInfo.Partner.Id)
// if err != nil {
// e := fmt.Sprintf("更新业务分红(partner_id=%d)数据失败:%s", partnerInfo.Partner.Id, err)
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
// }
transactionContext.CommitTransaction()
return
}
... ...
... ... @@ -28,6 +28,7 @@ type CreateOrderFromBestshop struct {
//发货时间
DeliveryTime string `json:"deliveryTime"`
PartnerId int64 `json:"partnerId"`
OrderArea string `json:"orderArea"`
Goods []struct {
Id int64 `json:"id"`
//货品编号
... ...
... ... @@ -126,6 +126,7 @@ func (s SyncOrderService) CreateOrderFromBestshop(cmd command.CreateOrderFromBes
DeliveryTime: cmd.DeliveryTime,
IsCopy: false,
CompanyId: cmd.CompanyId,
OrderArea: cmd.OrderArea,
}
err = orderBestshopRepository.Add(&order)
if err != nil {
... ... @@ -224,7 +225,7 @@ func (s SyncOrderService) copyOrderBestshopToOrderBase(orderBestshop *domain.Ord
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
for _, v := range companyData.Applets {
if v.Id == BEST_SHOP_UNIONID {
if len(v.Id) > 0 {
canCopyOrder = true
}
}
... ...
... ... @@ -501,9 +501,9 @@ func (service UsersService) EditUserPermission(cmd command.EditUserPermissionCom
partners = append(partners, p)
}
for i := range permissionList {
if permissionList[i].Code == domain.PERMINSSION_ADMIN_USER && !usersData.IsSuperAdmin() {
return lib.ThrowError(lib.BUSINESS_ERROR, "操作异常")
}
// if permissionList[i].Code == domain.PERMINSSION_ADMIN_USER && !usersData.IsSuperAdmin() {
// return lib.ThrowError(lib.BUSINESS_ERROR, "操作异常")
// }
p := domain.AdminPermissionBase{
Id: permissionList[i].Id,
Code: permissionList[i].Code,
... ...
package event
import "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
const (
//支付订单中货品的分红
PAY_ORDER_GOOD_BONUS_EVENT string = "PayOrderGoodBonus"
BATCH_PAY_ORDER_GOOD_BONUS_EVENT string = "BatchPayOrderGoodBonus"
)
//BatchPayOrderGoodBonus
//事件:批量支付一个订单中货品的分红
type BatchPayOrderGoodBonus []PayOrderGoodBonus
func (p BatchPayOrderGoodBonus) EventType() string {
return BATCH_PAY_ORDER_GOOD_BONUS_EVENT
}
//PayOrderGoodBonus
//事件:支付订单中货品的分红
//事件:支付一个订单中货品的分红
type PayOrderGoodBonus struct {
//订单id
OrderId int64
//货品名称
GoodName string
//订单中的货品id
GoodId int64
//管理员id
AdminId int64
//
PartnerBonus float64
OrderBase *domain.OrderBase
Goods []domain.OrderGood
Admin *domain.Users
}
func (p PayOrderGoodBonus) EventType() string {
... ...
... ... @@ -182,16 +182,14 @@ func (order *OrderBase) AddGoods(goods []OrderGood) {
order.Compute()
}
func (order *OrderBase) DeleteGoods(goodIds []int64) {
var newGoods []OrderGood
func (order *OrderBase) ModifyGoodNumber(goodid int64, number int64) {
for i := range order.Goods {
for _, goodId := range goodIds {
order.Goods[i].Id = goodId
if order.Goods[i].Id != goodid {
continue
}
newGoods = append(newGoods, order.Goods[i])
// thisGood := order.Goods[i]
}
order.Goods = newGoods
order.Compute()
}
... ...
... ... @@ -36,6 +36,7 @@ type OrderBestShop struct {
//是否将数据同步到 order_base ,order_good
IsCopy bool `json:"isCopy"`
CompanyId int64 `json:"companyId"`
OrderArea string `json:"orderArea"`
}
func (order OrderBestShop) CopyToOrderBase(o *OrderBase) {
... ... @@ -54,6 +55,7 @@ func (order OrderBestShop) CopyToOrderBase(o *OrderBase) {
o.OrderCompute.PlanOrderAmount = order.OrderAmount
o.OrderCompute.PlanOrderCount = order.OrderCount
o.DeliveryTime, _ = time.Parse("2006-01-02 15:04:05", order.DeliveryTime)
o.RegionInfo.RegionName = order.OrderArea
return
}
... ...
... ... @@ -2,6 +2,7 @@ package domain
import (
"errors"
"fmt"
"github.com/shopspring/decimal"
)
... ... @@ -12,6 +13,10 @@ type OrderGoodBonusStatus interface {
WartPayPartnerBonus(orderGood *OrderGood) error
//状态变更为已支付
PayPartnerBonus(orderGood *OrderGood) error
//变更货品数量
ModifyOrderGoodNumber(good *OrderGood, number int, orderType int) error
//变更合伙人分红比例
ModifyPertnerBonusPercent(good *OrderGood, percent float64, orderType int) error
}
//货单的支付状态
... ... @@ -43,6 +48,7 @@ type GoodCompute struct {
//合伙人分红支出
PartnerBonusExpense float64 `json:"partnerBonusExpense"`
}
type OrderGoodRemarkReason struct {
ModifyGoodNumber string `json:"modifyGoodNumber"` //货品数量变更的理由
ModifyPartnerBonusPercent string `json:"modifyPartnerBonusPercent"` //合伙人分红比例变更的理由
... ... @@ -105,6 +111,20 @@ func (good OrderGood) GetCurrentPartnerBonus() float64 {
return good.GoodCompute.PlanPartnerBonus
}
//GetCurrentAmount 获取当前的商品合伙人分红
func (good *OrderGood) ModifyOrderGoodNumber(number int, orderType int) error {
if good.PlanGoodNumber < number {
return fmt.Errorf("修改数量不能大于初始值:%d", good.PlanGoodNumber)
}
err := good.CurrentBonusStatus.ModifyOrderGoodNumber(good, number, orderType)
return err
}
func (good *OrderGood) ModifyPertnerBonusPercent(percent float64, orderType int) error {
err := good.CurrentBonusStatus.ModifyPertnerBonusPercent(good, percent, orderType)
return err
}
//Update 更新商品相关的数据
func (good *OrderGood) Update(m map[string]interface{}) error {
if v, ok := m["GoodName"]; ok {
... ... @@ -194,6 +214,68 @@ func (hasPay OrderGoodBonusHasPay) WartPayPartnerBonus(good *OrderGood) error {
return errors.New("已支付的货单不能将状态回退为待支付")
}
func (hasPay OrderGoodBonusHasPay) ModifyOrderGoodNumber(good *OrderGood, number int, orderType int) error {
//规则描述:
//实际自建订单(orderType==1),已支付分红状态下“可以”修改货品数量
//香米小程序订单(orderType==3),已支付分红状态下“不可以”修改货品数量
switch orderType {
case OrderReal:
good.UseGoodNumber = number
//待支付状态计算
err := good.Compute()
if err != nil {
return errors.New("核算商品数据失败" + err.Error())
}
case OrderTypeBestShop:
return errors.New("小程序订单里已支付分红的货品订单,不能修改货品数量")
}
good.CurrentBonusStatus.PayPartnerBonus(good)
return nil
}
func (waitPay OrderGoodBonusWaitPay) ModifyOrderGoodNumber(good *OrderGood, number int, orderType int) error {
//规则描述:
//实际自建订单(orderType==1),未支付分红状态下“可以”修改货品数量
//香米小程序订单(orderType==3),未支付分红状态下“可以”修改货品数量
good.UseGoodNumber = number
//待支付状态计算
err := good.Compute()
if err != nil {
return errors.New("核算商品数据失败" + err.Error())
}
good.CurrentBonusStatus.WartPayPartnerBonus(good)
return nil
}
func (waitPay OrderGoodBonusWaitPay) ModifyPertnerBonusPercent(good *OrderGood, percent float64, orderType int) error {
//规则描述:
//实际自建订单(orderType==1),未支付分红状态下“不可以”修改合伙人分红比例
//香米小程序订单(orderType==3),未支付分红状态下“可以”修改合伙人分红比例
switch orderType {
case OrderReal:
return errors.New("自建订单不能修改合伙人分红比例")
case OrderTypeBestShop:
good.PartnerBonusPercent = percent
//待支付状态计算
err := good.Compute()
if err != nil {
return errors.New("核算商品数据失败" + err.Error())
}
err = good.CurrentBonusStatus.WartPayPartnerBonus(good)
if err != nil {
return errors.New("核算商品数据失败" + err.Error())
}
}
return nil
}
func (hasPay OrderGoodBonusHasPay) ModifyPertnerBonusPercent(good *OrderGood, percent float64, orderType int) error {
//规则描述:
//实际自建订单(orderType==1),已支付分红状态下“不可以”修改合伙人分红比例
//香米小程序订单(orderType==3),已支付分红状态下“不可以”修改合伙人分红比例
return errors.New("已支付分红的货品订单,不能修改合伙人分红比例")
}
//NewOrderGood 初始值设定
func NewOrderGood() OrderGood {
return OrderGood{
... ...
... ... @@ -16,6 +16,7 @@ const (
//OrderLogDescript 描述日志内容
type OrderLogDescript struct {
GoodId int64 `json:"goodId"`
Title string `json:"title"` //标题
Item string `json:"item"` //修改的项目
Action []string `json:"action"` //执行的操作
... ...
package domain
import (
"errors"
"fmt"
)
//类型为(orderType=OrderTypeBestShop) 海鲜干货的订单分红
//因页面上的对于该类型的订单分红状态处理方式 有别于原有的其他类型(OrderReal),所以单独提取出来
// OrderGoodWithBestshopBonusStatus 支付状态
type OrderGoodWithBestshopBonusStatus interface {
OrderGoodBonusStatus
UpdateOrderGoodNumber(good *OrderGood, number int) error
UpdatePertnerBonusPercent(good *OrderGood, percent float64) error
}
//OrderGoodWithBestshop 处理订单中商品的分红相关数据
type OrderGoodWithBestshop struct {
currentBonusStatus OrderGoodWithBestshopBonusStatus
}
func (o *OrderGoodWithBestshop) UpdateBonusByGoodNumber(good *OrderGood, number int) error {
o.reset(good)
if good.PlanGoodNumber < number {
return fmt.Errorf("修改商品数量的值不能大于初始值%d", good.PlanGoodNumber)
}
err := o.currentBonusStatus.UpdateOrderGoodNumber(good, number)
return err
}
func (o *OrderGoodWithBestshop) UpdateBonusByPertnerBonusPercent(good *OrderGood, percent float64) error {
o.reset(good)
err := o.currentBonusStatus.UpdatePertnerBonusPercent(good, percent)
return err
}
func (o *OrderGoodWithBestshop) PayPartnerBonus(good *OrderGood) error {
o.currentBonusStatus = OrderGoodBonusBestshopHasPay{}
err := good.Compute()
if err != nil {
return errors.New("核算商品数据失败" + err.Error())
}
err = good.CurrentBonusStatus.PayPartnerBonus(good)
return err
}
func (o *OrderGoodWithBestshop) reset(good *OrderGood) {
switch good.BonusStatus {
case OrderGoodWaitPay:
o.currentBonusStatus = OrderGoodBonusBestshopWaitPay{}
case OrderGoodHasPay:
o.currentBonusStatus = OrderGoodBonusBestshopHasPay{}
}
return
}
//OrderGoodBonusBestshopWaitPay 货品支付状态:待支付
type OrderGoodBonusBestshopWaitPay struct {
OrderGoodBonusWaitPay
}
var _ OrderGoodWithBestshopBonusStatus = (*OrderGoodBonusBestshopWaitPay)(nil)
func (waitPay OrderGoodBonusBestshopWaitPay) UpdateOrderGoodNumber(good *OrderGood, number int) error {
good.UseGoodNumber = number
//待支付状态计算
err := good.Compute()
if err != nil {
return errors.New("核算商品数据失败" + err.Error())
}
err = good.CurrentBonusStatus.WartPayPartnerBonus(good)
return err
}
func (waitPay OrderGoodBonusBestshopWaitPay) UpdatePertnerBonusPercent(good *OrderGood, percent float64) error {
good.PartnerBonusPercent = percent
//待支付状态计算
err := good.Compute()
if err != nil {
return errors.New("核算商品数据失败" + err.Error())
}
err = good.CurrentBonusStatus.WartPayPartnerBonus(good)
return err
}
//OrderGoodBonusBestshopHasPay 货品支付状态:已支付
type OrderGoodBonusBestshopHasPay struct {
OrderGoodBonusHasPay
}
var _ OrderGoodWithBestshopBonusStatus = (*OrderGoodBonusBestshopHasPay)(nil)
func (hasPay OrderGoodBonusBestshopHasPay) UpdateOrderGoodNumber(good *OrderGood, number int) error {
return errors.New("已支付分红的货品订单,不能修改货品数量")
}
func (hasPay OrderGoodBonusBestshopHasPay) UpdatePertnerBonusPercent(good *OrderGood, percent float64) error {
return errors.New("已支付分红的货品订单,不能修改合伙人分红比例")
}
package service
type BusinessBonusService interface {
EnableOrDisable(userid int64) error
}
// type BusinessBonusService interface {
// EnableOrDisable(userid int64) error
// }
// EnableOrDisable(userid int64) error
// }
... ...
... ... @@ -10,4 +10,5 @@ type OrderBonusService interface {
UpdateBounsByPartnerBonusPercent(orderId int64, adminId int64, goodId int64, partnerPercent float64, reason string) error
UpdateOrderRemarkBonus(orderId int64, adminId int64, remark string) error
PayOrderGoodBonus(orderId int64, goodId int64, adminId int64) error
BatchPayPartnerBonus(orderIds []int64, adminId int64) error
}
... ...
... ... @@ -2,11 +2,7 @@ package dao
import (
"fmt"
"strings"
"time"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
)
... ... @@ -24,81 +20,81 @@ func NewBusinessBonusDao(transactionContext *transaction.TransactionContext) (*B
}
}
type CustomBusinessBonus struct {
Id int64
Bonus string
BonusNot string
BonusExpense string
BonusHas string
BonusStatus int8
PartnerName string
UpdateAt time.Time
}
// type CustomBusinessBonus struct {
// Id int64
// Bonus string
// BonusNot string
// BonusExpense string
// BonusHas string
// BonusStatus int8
// PartnerName string
// UpdateAt time.Time
// }
func (dao BusinessBonusDao) SearchBusinessBonus(partnerId int64, partnerNameMatch string,
companyId int64, limit int, offset int) ([]CustomBusinessBonus, error) {
sql := `SELECT business_bonus.id, business_bonus.bonus,business_bonus.bonus_not
,business_bonus.bonus_expense,business_bonus.bonus_status,business_bonus.update_at
,partner_info.partner_name,business_bonus.bonus_has
FROM business_bonus
JOIN partner_info ON business_bonus.partner_info_id=partner_info.id
WHERE business_bonus.is_disable=? AND business_bonus.company_id = ? `
partnerCondition := []string{}
allParam := []interface{}{domain.BUSINESS_BONUS_ENABLE, companyId}
if partnerId > 0 {
partnerCondition = append(partnerCondition, ` business_bonus.partner_info_id=? `)
allParam = append(allParam, partnerId)
}
if len(partnerNameMatch) > 0 {
allParam = append(allParam, "%"+partnerNameMatch+"%")
partnerCondition = append(partnerCondition, ` partner_info.partner_name like ? `)
}
if len(partnerCondition) > 0 {
sql += fmt.Sprintf(" AND (%s)", strings.Join(partnerCondition, " OR "))
}
sql += `ORDER BY business_bonus.id DESC limit ? OFFSET ? `
allParam = append(allParam, limit, offset)
tx := dao.transactionContext.PgTx
var (
result []CustomBusinessBonus
err error
)
_, err = tx.Query(&result, sql, allParam...)
return result, err
}
// func (dao BusinessBonusDao) SearchBusinessBonus(partnerId int64, partnerNameMatch string,
// companyId int64, limit int, offset int) ([]CustomBusinessBonus, error) {
// sql := `SELECT business_bonus.id, business_bonus.bonus,business_bonus.bonus_not
// ,business_bonus.bonus_expense,business_bonus.bonus_status,business_bonus.update_at
// ,partner_info.partner_name,business_bonus.bonus_has
// FROM business_bonus
// JOIN partner_info ON business_bonus.partner_info_id=partner_info.id
// WHERE business_bonus.is_disable=? AND business_bonus.company_id = ? `
// partnerCondition := []string{}
// allParam := []interface{}{domain.BUSINESS_BONUS_ENABLE, companyId}
// if partnerId > 0 {
// partnerCondition = append(partnerCondition, ` business_bonus.partner_info_id=? `)
// allParam = append(allParam, partnerId)
// }
// if len(partnerNameMatch) > 0 {
// allParam = append(allParam, "%"+partnerNameMatch+"%")
// partnerCondition = append(partnerCondition, ` partner_info.partner_name like ? `)
// }
// if len(partnerCondition) > 0 {
// sql += fmt.Sprintf(" AND (%s)", strings.Join(partnerCondition, " OR "))
// }
// sql += `ORDER BY business_bonus.id DESC limit ? OFFSET ? `
// allParam = append(allParam, limit, offset)
// tx := dao.transactionContext.PgTx
// var (
// result []CustomBusinessBonus
// err error
// )
// _, err = tx.Query(&result, sql, allParam...)
// return result, err
// }
func (dao BusinessBonusDao) CountBusinessBonus(partnerId int64, partnerNameMatch string,
companyId int64, limit int, offset int) (int, error) {
sql := `SELECT count(*)
FROM business_bonus
JOIN partner_info ON business_bonus.partner_info_id=partner_info.id
WHERE business_bonus.is_disable=? AND business_bonus.company_id = ? `
partnerCondition := []string{}
allParam := []interface{}{domain.BUSINESS_BONUS_ENABLE, companyId}
if partnerId > 0 {
partnerCondition = append(partnerCondition, ` business_bonus.partner_info_id=? `)
allParam = append(allParam, partnerId)
}
if len(partnerNameMatch) > 0 {
allParam = append(allParam, "%"+partnerNameMatch+"%")
partnerCondition = append(partnerCondition, ` partner_info.partner_name like ? `)
}
if len(partnerCondition) > 0 {
sql += fmt.Sprintf(" AND (%s)", strings.Join(partnerCondition, " OR "))
}
tx := dao.transactionContext.PgTx
var (
result int
err error
)
_, err = tx.Query(&result, sql, allParam...)
return result, err
}
// func (dao BusinessBonusDao) CountBusinessBonus(partnerId int64, partnerNameMatch string,
// companyId int64, limit int, offset int) (int, error) {
// sql := `SELECT count(*)
// FROM business_bonus
// JOIN partner_info ON business_bonus.partner_info_id=partner_info.id
// WHERE business_bonus.is_disable=? AND business_bonus.company_id = ? `
// partnerCondition := []string{}
// allParam := []interface{}{domain.BUSINESS_BONUS_ENABLE, companyId}
// if partnerId > 0 {
// partnerCondition = append(partnerCondition, ` business_bonus.partner_info_id=? `)
// allParam = append(allParam, partnerId)
// }
// if len(partnerNameMatch) > 0 {
// allParam = append(allParam, "%"+partnerNameMatch+"%")
// partnerCondition = append(partnerCondition, ` partner_info.partner_name like ? `)
// }
// if len(partnerCondition) > 0 {
// sql += fmt.Sprintf(" AND (%s)", strings.Join(partnerCondition, " OR "))
// }
// tx := dao.transactionContext.PgTx
// var (
// result int
// err error
// )
// _, err = tx.Query(&result, sql, allParam...)
// return result, err
// }
func (dao BusinessBonusDao) ExistBusinessBonus(userId int64) (bool, error) {
tx := dao.transactionContext.PgTx
ok, err := tx.Model(&models.BusinessBonus{}).
Where("partner_info_id=?", userId).
Exists()
return ok, err
}
// func (dao BusinessBonusDao) ExistBusinessBonus(userId int64) (bool, error) {
// tx := dao.transactionContext.PgTx
// ok, err := tx.Model(&models.BusinessBonus{}).
// Where("partner_info_id=?", userId).
// Exists()
// return ok, err
// }
... ...
... ... @@ -47,11 +47,14 @@ func (dao OrderBaseDao) DeliveryCodeExist(code string, companyId int64, notId ..
return ok, err
}
//OrderListByCondition 根据条件获取订单分红列表
//orderType 订单类型
//partnerOrCode 合伙人姓名或订单号或发货单号
//OrderBonusListByCondition 根据条件获取订单分红列表
//@param orderType 订单类型
//@param partnerOrCode 合伙人姓名或订单号或发货单号
//@param companyId 公司id
//@param partnerCategory 合伙人类型
//@param createTime 创建时间
func (dao OrderBaseDao) OrderBonusListByCondition(companyId int64, orderType int, partnerOrCode string,
partnerCategory int, limit, offset int) ([]models.OrderBase, int, error) {
partnerCategory int, createTime [2]string, limit, offset int) ([]models.OrderBase, int, error) {
tx := dao.transactionContext.GetDB()
var orders []models.OrderBase
query := tx.Model(&orders).Where("order_base.company_id=?", companyId)
... ... @@ -63,6 +66,15 @@ func (dao OrderBaseDao) OrderBonusListByCondition(companyId int64, orderType int
if partnerCategory > 0 {
query = query.Where(`order_base.partner_category@>'{"id":?}'`, partnerCategory)
}
if len(createTime[0]) > 0 {
query = query.Where(`order_base.create_time>=?`, createTime[0])
}
if len(createTime[1]) > 0 {
query = query.Where(`order_base.create_time<=?`, createTime[1])
}
if len(partnerOrCode) > 0 {
query = query.Join("LEFT JOIN partner_info as p ON order_base.partner_id=p.id").
WhereGroup(func(q *orm.Query) (*orm.Query, error) {
... ... @@ -72,7 +84,7 @@ func (dao OrderBaseDao) OrderBonusListByCondition(companyId int64, orderType int
return q, nil
})
}
query = query.Order("order_base.update_time DESC").
query = query.Order("order_base.create_time DESC").
Offset(offset).
Limit(limit)
... ... @@ -88,6 +100,7 @@ type CustomOrderBonusForExcel struct {
BonusStatus int
DeliveryCode string
UpdateTime string
CreateTime string
PartnerBonus float64
PartnerBonusHas float64
PartnerBonusNot float64
... ... @@ -101,9 +114,10 @@ type CustomOrderBonusForExcel struct {
//@param orderType 订单类型
//@param partnerOrCode 合伙人姓名或订单号或发货单号
//@param partnerCategory 合伙人类型id
//@param createTime 订单的创建时间范围"[开始时间,结束时间]" 时间格式"2006-01-02 15:04:05+07"
//@return result 查询结果数据
func (dao OrderBaseDao) OrderBonusListForExcel(companyId int64, orderType int, partnerOrCode string,
partnerCategory int) (result []CustomOrderBonusForExcel, err error) {
partnerCategory int, createTime [2]string) (result []CustomOrderBonusForExcel, err error) {
//导出分红列表所用的sql
sqlStr := `SELECT
t1.ID AS order_id,
... ... @@ -112,6 +126,7 @@ func (dao OrderBaseDao) OrderBonusListForExcel(companyId int64, orderType int, p
t1.delivery_code,
t1.bonus_status,
to_char(t1.update_time AT TIME ZONE 'CCT' ,'YYYY-MM-DD HH24:MI:SS') AS update_time,
to_char(t1.create_time AT TIME ZONE 'CCT' ,'YYYY-MM-DD HH24:MI:SS') AS create_time,
(CASE
WHEN t1.use_partner_bonus>0
THEN
... ... @@ -152,7 +167,15 @@ func (dao OrderBaseDao) OrderBonusListForExcel(companyId int64, orderType int, p
sqlStr += ` AND t1.partner_category @>'{"id":?}'`
param = append(param, partnerCategory)
}
sqlStr += ` ORDER BY t1.update_time DESC limit 10000 `
if len(createTime[0]) > 0 {
param = append(param, createTime[0])
sqlStr += ` AND t1.create_time>=? `
}
if len(createTime[1]) > 0 {
param = append(param, createTime[1])
sqlStr += ` AND t1.create_time<=? `
}
sqlStr += ` ORDER BY t1.create_time DESC limit 10000 `
tx := dao.transactionContext.GetDB()
_, err = tx.Query(&result, sqlStr, param...)
... ... @@ -168,8 +191,9 @@ func (dao OrderBaseDao) OrderBonusListForExcel(companyId int64, orderType int, p
//@param partnerOrCode 合伙人姓名或订单号或发货单号
//@param partnerCategory 合伙人类型id
//@param updateTime 订单更新时间范围"[开始时间,结束时间]",时间格式"2006-01-02 15:04:05+07"
//@param createTime 订单的创建时间范围"[开始时间,结束时间]" 时间格式"2006-01-02 15:04:05+07"
func (dao OrderBaseDao) OrderListByCondition(companyId int64, orderType int, partnerOrCode string,
updateTime [2]string, partnerCategory int, limit, offset int) ([]models.OrderBase, int, error) {
updateTime [2]string, createTime [2]string, partnerCategory int, limit, offset int) ([]models.OrderBase, int, error) {
tx := dao.transactionContext.GetDB()
var orders []models.OrderBase
query := tx.Model(&orders).Where("order_base.company_id=?", companyId)
... ... @@ -187,6 +211,13 @@ func (dao OrderBaseDao) OrderListByCondition(companyId int64, orderType int, par
if len(updateTime[1]) > 0 {
query = query.Where(`order_base.update_time<=?`, updateTime[1])
}
if len(createTime[0]) > 0 {
query = query.Where(`order_base.create_time>=?`, createTime[0])
}
if len(createTime[1]) > 0 {
query = query.Where(`order_base.create_time<=?`, createTime[1])
}
if len(partnerOrCode) > 0 {
query = query.Join("LEFT JOIN partner_info as p ON order_base.partner_id=p.id").
WhereGroup(func(q *orm.Query) (*orm.Query, error) {
... ... @@ -196,7 +227,7 @@ func (dao OrderBaseDao) OrderListByCondition(companyId int64, orderType int, par
return q, nil
})
}
query = query.Order("order_base.update_time DESC").
query = query.Order("order_base.create_time DESC").
Offset(offset).
Limit(limit)
... ... @@ -204,3 +235,80 @@ func (dao OrderBaseDao) OrderListByCondition(companyId int64, orderType int, par
return orders, cnt, err
}
//CustomOrderListForExcel 导出实际订单列表所用的结构
type CustomOrderListForExcel struct {
OrderCode string //订单编号
DeliveryCode string //发货编号
UpdateTime string //更新时间
CreateTime string //创建时间
PlanOrderCount int64 //货品总数
UseOrderCount int64 //货品总数调整
RegionName string //订单区域
PlanOrderAmount float64 //订单金额
UseOrderAmount float64 //订单金额调整
PartnerCategory string //合伙人类型
BuyerName string //买家
PartnerName string //合伙人
}
//OrderListForExcel 获取实际订单列表用于excel导出
//@param companyId 公司id
//@param orderType 订单类型
//@param partnerOrCode 合伙人姓名或订单号或发货单号
//@param partnerCategory 合伙人类型id
//@param updateTime 订单更新时间范围"[开始时间,结束时间]",时间格式"2006-01-02 15:04:05+07"
//@param createTime 订单的创建时间范围"[开始时间,结束时间]" 时间格式"2006-01-02 15:04:05+07"
func (dao OrderBaseDao) OrderListForExcel(companyId int64, partnerOrCode string,
updateTime [2]string, createTime [2]string, partnerCategory int) (
result []CustomOrderListForExcel, err error) {
sqlstr := `
SELECT t1.order_code,t1.delivery_code
,to_char(t1.create_time AT TIME ZONE 'CCT' ,'YYYY-MM-DD HH24:MI:SS') AS create_time
,to_char(t1.update_time AT TIME ZONE 'CCT' ,'YYYY-MM-DD HH24:MI:SS') AS update_time
,t1.plan_order_count,t1.use_order_count,t1.plan_order_amount,t1.use_order_amount
,t1.region_info->'regionName' AS region_name,t1.buyer->'buyerName' AS buyer_name
,t1.partner_category->'name' AS partner_category
,t2.partner_name
FROM "order_base" AS t1
LEFT JOIN partner_info as t2 ON t1.partner_id=t2.id
WHERE 1=1 AND t1.order_type = 1 AND t1.company_id=?
`
params := []interface{}{companyId}
if len(partnerOrCode) > 0 {
like := "%" + partnerOrCode + "%"
params = append(params, like, like, like)
sqlstr += " AND (t1.order_code like ? OR t1.delivery_code like ? OR t2.partner_name like ? ) "
}
if partnerCategory > 0 {
params = append(params, partnerCategory)
sqlstr += ` AND t1.partner_category@>'{"id":?}' `
}
if len(updateTime[0]) > 0 {
params = append(params, updateTime[0])
sqlstr += ` AND t1.update_time>=? `
}
if len(updateTime[1]) > 0 {
params = append(params, updateTime[1])
sqlstr += ` AND t1.update_time<=? `
}
if len(createTime[0]) > 0 {
params = append(params, createTime[0])
sqlstr += ` AND t1.create_time>=? `
}
if len(createTime[1]) > 0 {
params = append(params, createTime[1])
sqlstr += ` AND t1.create_time<=? `
}
sqlstr += ` ORDER BY t1.create_time DESC limit 10000 `
tx := dao.transactionContext.GetDB()
_, err = tx.Query(&result, sqlstr, params...)
if err != nil {
return result, err
}
return result, nil
}
... ...
package domainService
import (
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/dao"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/repository"
)
// type BusinessBonusService struct {
// transactionContext *transaction.TransactionContext
// }
type BusinessBonusService struct {
transactionContext *transaction.TransactionContext
}
// func NewBusinessBonusService(tcx *transaction.TransactionContext) *BusinessBonusService {
// return &BusinessBonusService{
// transactionContext: tcx,
// }
// }
func NewBusinessBonusService(tcx *transaction.TransactionContext) *BusinessBonusService {
return &BusinessBonusService{
transactionContext: tcx,
}
}
// func (srv BusinessBonusService) EnableOrDisable(parntnerId int64) error {
// var (
// bonusDao, _ = dao.NewBusinessBonusDao(srv.transactionContext)
// bonusReponsitory, _ = repository.NewBusinessBonusRepository(srv.transactionContext)
// partnerReponsitory, _ = repository.NewPartnerInfoRepository(srv.transactionContext)
func (srv BusinessBonusService) EnableOrDisable(parntnerId int64) error {
var (
bonusDao, _ = dao.NewBusinessBonusDao(srv.transactionContext)
bonusReponsitory, _ = repository.NewBusinessBonusRepository(srv.transactionContext)
partnerReponsitory, _ = repository.NewPartnerInfoRepository(srv.transactionContext)
// err error
// partnerHasInBonus bool
// partnerData *domain.PartnerInfo
// partnerHasBusinessCategory bool
// )
// partnerHasInBonus, err = bonusDao.ExistBusinessBonus(parntnerId)
// if err != nil {
// return err
// }
// partnerData, err = partnerReponsitory.FindOne(domain.PartnerFindOneQuery{UserId: parntnerId})
// if err != nil {
// return err
// }
// for _, v := range partnerData.PartnerCategoryInfos {
// if v.Id == 2 {
// partnerHasBusinessCategory = true
// break
// }
// }
// if partnerHasInBonus && partnerHasBusinessCategory {
// //已存在业务分红数据况 && 是业务合伙人类型
// var bonusData *domain.BusinessBonus
// bonusData, err = bonusReponsitory.FindOne(domain.BusinessBonusFindOneQuery{
// PartnerId: parntnerId,
// })
// if bonusData.IsDisable == domain.BUSINESS_BONUS_ENABLE {
// return nil
// }
// bonusData.IsDisable = domain.BUSINESS_BONUS_ENABLE
// err = bonusReponsitory.Edit(bonusData)
// return err
// }
// if partnerHasInBonus && !partnerHasBusinessCategory {
// //已存在业务分红数据况 && 不是业务合伙人类型
// var bonusData *domain.BusinessBonus
// bonusData, err = bonusReponsitory.FindOne(domain.BusinessBonusFindOneQuery{
// PartnerId: parntnerId,
// })
// if bonusData.IsDisable == domain.BUSINESS_BONUS_DISABLE {
// return nil
// }
// bonusData.IsDisable = domain.BUSINESS_BONUS_DISABLE
// err = bonusReponsitory.Edit(bonusData)
// return err
// }
err error
partnerHasInBonus bool
partnerData *domain.PartnerInfo
partnerHasBusinessCategory bool
)
partnerHasInBonus, err = bonusDao.ExistBusinessBonus(parntnerId)
if err != nil {
return err
}
partnerData, err = partnerReponsitory.FindOne(domain.PartnerFindOneQuery{UserId: parntnerId})
if err != nil {
return err
}
for _, v := range partnerData.PartnerCategoryInfos {
if v.Id == 2 {
partnerHasBusinessCategory = true
break
}
}
if partnerHasInBonus && partnerHasBusinessCategory {
//已存在业务分红数据况 && 是业务合伙人类型
var bonusData *domain.BusinessBonus
bonusData, err = bonusReponsitory.FindOne(domain.BusinessBonusFindOneQuery{
PartnerId: parntnerId,
})
if bonusData.IsDisable == domain.BUSINESS_BONUS_ENABLE {
return nil
}
bonusData.IsDisable = domain.BUSINESS_BONUS_ENABLE
err = bonusReponsitory.Edit(bonusData)
return err
}
if partnerHasInBonus && !partnerHasBusinessCategory {
//已存在业务分红数据况 && 不是业务合伙人类型
var bonusData *domain.BusinessBonus
bonusData, err = bonusReponsitory.FindOne(domain.BusinessBonusFindOneQuery{
PartnerId: parntnerId,
})
if bonusData.IsDisable == domain.BUSINESS_BONUS_DISABLE {
return nil
}
bonusData.IsDisable = domain.BUSINESS_BONUS_DISABLE
err = bonusReponsitory.Edit(bonusData)
return err
}
// if !partnerHasInBonus && partnerHasBusinessCategory {
// //不存在业务分红数据况 && 是业务合伙人类型
// newBonus := &domain.BusinessBonus{
// PartnerInfoId: partnerData.Partner.Id,
// IsDisable: domain.BUSINESS_BONUS_ENABLE,
// CompanyId: partnerData.CompanyId,
// Bonus: 0,
// }
// err = bonusReponsitory.Add(newBonus)
// return err
// }
if !partnerHasInBonus && partnerHasBusinessCategory {
//不存在业务分红数据况 && 是业务合伙人类型
newBonus := &domain.BusinessBonus{
PartnerInfoId: partnerData.Partner.Id,
IsDisable: domain.BUSINESS_BONUS_ENABLE,
CompanyId: partnerData.CompanyId,
Bonus: 0,
}
err = bonusReponsitory.Add(newBonus)
return err
}
return nil
}
// return nil
// }
// }
... ...
... ... @@ -28,7 +28,6 @@ func NewOrderBonusService(tcx *transaction.TransactionContext) *OrderBonusServic
}
//UpdateBounsWithGoodNumber 分红时,因修改订单中商品的数量发生分红变动
//目前只处理 xiangmi的订单 即 order_type = OrderTypeBestShop (3)
func (serve *OrderBonusService) UpdateBounsByGoodNumber(orderId int64, adminId int64, goodId int64, goodWithNumber int, reason string) error {
var (
userRepository domain.UsersRepository
... ... @@ -52,9 +51,6 @@ func (serve *OrderBonusService) UpdateBounsByGoodNumber(orderId int64, adminId i
e := fmt.Sprintf("获取订单(id=%d)数据失败,%s", orderId, err)
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
if oldOrder.OrderType != domain.OrderTypeBestShop {
return lib.ThrowError(lib.BUSINESS_ERROR, "订单类型错误")
}
oldOrder.Goods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{OrderId: orderId})
if err != nil {
e := fmt.Sprintf("获取订单(id=%d)中的货品数据失败,%s", orderId, err)
... ... @@ -82,8 +78,13 @@ func (serve *OrderBonusService) UpdateBounsByGoodNumber(orderId int64, adminId i
updateGood = oldOrder.Goods[i]
formerNumber = updateGood.GetCurrentGoodNumber()
formerAmount = updateGood.GetCurrentAmount()
err := new(domain.OrderGoodWithBestshop).
UpdateBonusByGoodNumber(&updateGood, goodWithNumber)
//TODO
// err := new(domain.OrderGoodWithBestshop).
// UpdateBonusByGoodNumber(&updateGood, goodWithNumber)
// if err != nil {
// return lib.ThrowError(lib.BUSINESS_ERROR, err.Error())
// }
err = updateGood.ModifyOrderGoodNumber(goodWithNumber, oldOrder.OrderType)
if err != nil {
return lib.ThrowError(lib.BUSINESS_ERROR, err.Error())
}
... ... @@ -128,7 +129,6 @@ func (serve *OrderBonusService) UpdateBounsByGoodNumber(orderId int64, adminId i
}
//UpdateBounsByPartnerBonusPercent 分红时,因修改订单中商品的合伙人分行比例发生分红变动
////目前只处理 xiangmi的订单 即 order_type = OrderTypeBestShop (3)
func (serve *OrderBonusService) UpdateBounsByPartnerBonusPercent(orderId int64, adminId int64, goodId int64, partnerPercent float64, reason string) error {
var (
userRepository domain.UsersRepository
... ... @@ -152,9 +152,7 @@ func (serve *OrderBonusService) UpdateBounsByPartnerBonusPercent(orderId int64,
e := fmt.Sprintf("获取订单(id=%d)数据失败,%s", orderId, err)
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
if oldOrder.OrderType != domain.OrderTypeBestShop {
return lib.ThrowError(lib.BUSINESS_ERROR, "订单类型错误")
}
oldOrder.Goods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{OrderId: orderId})
if err != nil {
e := fmt.Sprintf("获取订单中(id=%d)的货品数据失败,%s", orderId, err)
... ... @@ -182,8 +180,10 @@ func (serve *OrderBonusService) UpdateBounsByPartnerBonusPercent(orderId int64,
updateGood = oldOrder.Goods[i]
formerPartnerBonusPercent = updateGood.PartnerBonusPercent
formerPartnerBonus = updateGood.GetCurrentPartnerBonus()
err := new(domain.OrderGoodWithBestshop).
UpdateBonusByPertnerBonusPercent(&updateGood, partnerPercent)
// err := new(domain.OrderGoodWithBestshop).
// UpdateBonusByPertnerBonusPercent(&updateGood, partnerPercent)
err = updateGood.ModifyPertnerBonusPercent(partnerPercent, oldOrder.OrderType)
if err != nil {
return lib.ThrowError(lib.BUSINESS_ERROR, err.Error())
}
... ... @@ -230,7 +230,6 @@ func (serve *OrderBonusService) UpdateBounsByPartnerBonusPercent(orderId int64,
}
//PayOrderGoodBonus 支付订单中货品的分红
//目前只处理 海鲜干货的订单 即 order_type = OrderTypeBestShop (3)
func (serve *OrderBonusService) PayOrderGoodBonus(orderId int64, goodId int64, adminId int64) error {
var (
userRepository domain.UsersRepository
... ... @@ -254,9 +253,6 @@ func (serve *OrderBonusService) PayOrderGoodBonus(orderId int64, goodId int64, a
e := fmt.Sprintf("获取订单(id=%d)数据失败,%s", orderId, err)
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
if oldOrder.OrderType != domain.OrderTypeBestShop {
return lib.ThrowError(lib.BUSINESS_ERROR, "订单类型错误")
}
oldOrder.Goods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{OrderId: orderId})
if err != nil {
e := fmt.Sprintf("获取订单中(id=%d)的货品数据失败,%s", orderId, err)
... ... @@ -279,7 +275,13 @@ func (serve *OrderBonusService) PayOrderGoodBonus(orderId int64, goodId int64, a
continue
}
updateGood = oldOrder.Goods[i]
err := new(domain.OrderGoodWithBestshop).PayPartnerBonus(&updateGood)
if updateGood.PartnerBonusPercent < 0 {
return nil
}
if updateGood.BonusStatus == domain.OrderGoodHasPay {
return nil
}
err = updateGood.CurrentBonusStatus.PayPartnerBonus(&updateGood)
if err != nil {
return lib.ThrowError(lib.BUSINESS_ERROR, err.Error())
}
... ... @@ -305,11 +307,11 @@ func (serve *OrderBonusService) PayOrderGoodBonus(orderId int64, goodId int64, a
}
//
payEvent := event.PayOrderGoodBonus{
OrderId: orderId,
GoodId: goodId,
AdminId: adminId,
GoodName: updateGood.GoodName,
PartnerBonus: updateGood.GetCurrentPartnerBonus(),
OrderBase: oldOrder,
Goods: []domain.OrderGood{
updateGood,
},
Admin: &adminUser,
}
if err = serve.Publish(payEvent); err != nil {
return err
... ... @@ -318,7 +320,6 @@ func (serve *OrderBonusService) PayOrderGoodBonus(orderId int64, goodId int64, a
}
//UpdateOrderRemarkBonus 更新备注
//目前只处理 海鲜干货的订单 即 order_type = OrderTypeBestShop (3)
func (serve *OrderBonusService) UpdateOrderRemarkBonus(orderId int64, adminId int64, remark string) error {
var (
userRepository domain.UsersRepository
... ... @@ -338,9 +339,6 @@ func (serve *OrderBonusService) UpdateOrderRemarkBonus(orderId int64, adminId in
e := fmt.Sprintf("获取订单(id=%d)数据失败,%s", orderId, err)
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
if oldOrder.OrderType != domain.OrderTypeBestShop {
return lib.ThrowError(lib.BUSINESS_ERROR, "订单类型错误")
}
adminUser, err = userRepository.FindOne(domain.UsersFindOneQuery{Id: adminId})
if err != nil {
e := fmt.Sprintf("获取管理员用户(id=%d)数据失败,%s", adminId, err)
... ... @@ -368,6 +366,95 @@ func (serve *OrderBonusService) UpdateOrderRemarkBonus(orderId int64, adminId in
return err
}
}
return nil
}
//BatchPayPartnerBonus 批量支付订单中货品的分红
func (serve *OrderBonusService) BatchPayPartnerBonus(orderIds []int64, adminId int64) error {
var (
userRepository domain.UsersRepository
orderBaseReponsitory domain.OrderBaseRepository
orderGoodRepository domain.OrderGoodRepository
adminUser domain.Users
err error
)
if orderGoodRepository, err = repository.NewOrderGoodRepository(serve.transactionContext); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
if orderBaseReponsitory, err = repository.NewOrderBaseRepository(serve.transactionContext); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
if userRepository, err = repository.NewUsersRepository(serve.transactionContext); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
adminUser, err = userRepository.FindOne(domain.UsersFindOneQuery{Id: adminId})
if err != nil {
e := fmt.Sprintf("获取管理员用户(id=%d)数据失败,%s", adminId, err)
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
var (
payEvents []event.PayOrderGoodBonus
)
for _, orderId := range orderIds {
var oldOrder *domain.OrderBase
oldOrder, err = orderBaseReponsitory.FindOne(domain.OrderBaseFindOneQuery{OrderId: orderId})
if err != nil {
e := fmt.Sprintf("获取订单(id=%d)数据失败,%s", orderId, err)
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
oldOrder.Goods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{OrderId: orderId})
if err != nil {
e := fmt.Sprintf("获取订单中(id=%d)的货品数据失败,%s", orderId, err)
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
if ok := adminUser.InCompany(oldOrder.CompanyId); !ok {
return lib.ThrowError(lib.BUSINESS_ERROR, "用户不能更新非自己公司的订单")
}
var updateGoods []domain.OrderGood
for i := range oldOrder.Goods {
thisGood := oldOrder.Goods[i]
if thisGood.BonusStatus == domain.OrderGoodHasPay {
//已支付
continue
}
if thisGood.PartnerBonusPercent < 0 {
//未设置合伙人分红比例
continue
}
thisGood.CurrentBonusStatus.PayPartnerBonus(&thisGood)
oldOrder.Goods[i] = thisGood
//货品更新
updateGoods = append(updateGoods, thisGood)
}
err = oldOrder.Compute()
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, "核算订单数据失败")
}
//更新订单货品
if len(updateGoods) > 0 {
err = orderBaseReponsitory.Save(oldOrder)
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
err = orderGoodRepository.Save(updateGoods)
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
//构建事件
payEvent := event.PayOrderGoodBonus{
OrderBase: oldOrder,
Goods: updateGoods,
Admin: &adminUser,
}
payEvents = append(payEvents, payEvent)
}
}
if len(payEvents) > 0 {
if err = serve.Publish(event.BatchPayOrderGoodBonus(payEvents)); err != nil {
return err
}
}
return nil
}
... ...
... ... @@ -116,7 +116,7 @@ func (repository OrderBaseRepository) Find(queryOption domain.OrderBaseFindQuery
err error
ordersReturn = make([]domain.OrderBase, 0)
)
query = query.Order("order_base.id DESC")
query = query.Order("order_base.create_time DESC")
count, err := query.SelectAndCount()
if err != nil {
return ordersReturn, 0, err
... ...
... ... @@ -106,7 +106,7 @@ func (repository OrderGoodRepository) Find(queryOption domain.OrderGoodFindQuery
if queryOption.Limit > 0 {
query = query.Limit(queryOption.Limit)
} else {
query = query.Limit(100)
query = query.Limit(1000)
}
var (
err error
... ...
package controllers
import (
"encoding/json"
"errors"
"fmt"
"time"
"github.com/GeeTeam/gt3-golang-sdk/geetest"
"github.com/astaxie/beego/logs"
userCmd "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/users/command"
userService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/users/service"
... ... @@ -54,27 +51,26 @@ func (c *AdminLoginController) Login() {
}
//CaptchaInit 极验初始化
func (c *AdminLoginController) CaptchaInit() {
const (
captchaID = "33a2abf9c5df0d6bc3b89fb39280114b"
privateKey = "13320fd2b10199e9a2440a4fbb4d46f7"
)
newGeetest := geetest.NewGeetestLib(captchaID, privateKey, 2*time.Second)
userip := c.Ctx.Input.IP()
_, responseBt := newGeetest.PreProcess("", userip)
// c.SetSession("geetest_status", status)
var geetestRsp geetest.FailbackRegisterRespnse
json.Unmarshal(responseBt, &geetestRsp)
//对前端定义的数据格式进行适配。。。
rspData := map[string]interface{}{
"success": geetestRsp.Success,
"gt": geetestRsp.GT,
"challenge": geetestRsp.Challenge,
"newCaptcha": geetestRsp.NewCaptcha,
}
c.ResponseData(rspData)
return
}
// func (c *AdminLoginController) CaptchaInit() {
// const (
// captchaID = "33a2abf9c5df0d6bc3b89fb39280114b"
// privateKey = "13320fd2b10199e9a2440a4fbb4d46f7"
// )
// newGeetest := geetest.NewGeetestLib(captchaID, privateKey, 2*time.Second)
// userip := c.Ctx.Input.IP()
// _, responseBt := newGeetest.PreProcess("", userip)
// var geetestRsp geetest.FailbackRegisterRespnse
// json.Unmarshal(responseBt, &geetestRsp)
// //对前端定义的数据格式进行适配。。。
// rspData := map[string]interface{}{
// "success": geetestRsp.Success,
// "gt": geetestRsp.GT,
// "challenge": geetestRsp.Challenge,
// "newCaptcha": geetestRsp.NewCaptcha,
// }
// c.ResponseData(rspData)
// return
// }
//AdminpPofile 获取登录用户的权限配置
func (c *AdminLoginController) AdminpPofile() {
... ...
package controllers
import (
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
)
type BusinessBonusController struct {
BaseController
}
// type BusinessBonusController struct {
// BaseController
// }
func (c *BusinessBonusController) Prepare() {
c.BaseController.Prepare()
if ok := c.ValidJWTToken(); !ok {
return
}
if ok := c.ValidAdminPermission(domain.PERMISSION_DIVIDEND); !ok {
return
}
}
// func (c *BusinessBonusController) Prepare() {
// c.BaseController.Prepare()
// if ok := c.ValidJWTToken(); !ok {
// return
// }
// if ok := c.ValidAdminPermission(domain.PERMISSION_DIVIDEND); !ok {
// return
// }
// }
// func (c *BusinessBonusController) ListBusinessBonus() {
// type Parameter struct {
... ... @@ -110,3 +106,27 @@ func (c *BusinessBonusController) Prepare() {
// }
// c.ResponseData(data)
// }
// type Parameter struct {
// Id int64 `json:"id"`
// }
// var (
// param Parameter
// err error
// )
// if err = c.BindJsonData(&param); err != nil {
// logs.Error(err)
// c.ResponseError(errors.New("json数据解析失败"))
// return
// }
// companyId := c.GetUserCompany()
// srv := businessService.NewBusinessBonusService(nil)
// data, err := srv.GetBusinessBonus(businessQuery.GetBusinessBonusQuery{
// Id: param.Id,
// CompanyId: companyId,
// })
// if err != nil {
// c.ResponseError(err)
// return
// }
// c.ResponseData(data)
// }
... ...
... ... @@ -2,11 +2,10 @@ package controllers
import (
"errors"
"fmt"
"strconv"
"time"
"github.com/astaxie/beego/logs"
orderCmd "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/orderinfo/command"
orderQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/orderinfo/query"
orderService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/orderinfo/service"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
... ... @@ -37,6 +36,7 @@ func (c *OrderDividendController) PageListOrderDividend() {
PageSize int `json:"pageSize"`
PageNumber int `json:"pageNumber"`
PartnerCategoryId int `json:"partnerCategoryId"`
CreateTime []string `json:"createTime"`
}
var (
param Parameter
... ... @@ -59,6 +59,33 @@ func (c *OrderDividendController) PageListOrderDividend() {
if param.PageSize == 0 {
param.PageSize = 20
}
var (
createTimeBegin string
createTimeEnd string
)
if len(param.CreateTime) > 0 {
if len(param.CreateTime[0]) > 0 {
t, err := time.ParseInLocation("2006-01-02", param.CreateTime[0], time.Local)
if err != nil {
c.ResponseError(errors.New("UpdateTimeBegin 时间格式错误"))
return
}
createTimeBegin = t.Format("2006-01-02 15:04:05-07")
}
}
if len(param.CreateTime) > 1 {
if len(param.CreateTime[1]) > 0 {
t, err := time.ParseInLocation("2006-01-02", param.CreateTime[1], time.Local)
if err != nil {
c.ResponseError(errors.New("UpdateTimeEnd 时间格式错误"))
return
}
//设定时间边界
t = t.Add(86399 * time.Second)
createTimeEnd = t.Format("2006-01-02 15:04:05-07")
}
}
companyId := c.GetUserCompany()
orderSrv := orderService.NewOrderInfoService(nil)
resp, cnt, err := orderSrv.PageListOrderBonus(orderQuery.ListOrderBonusQuery{
... ... @@ -68,6 +95,8 @@ func (c *OrderDividendController) PageListOrderDividend() {
Offset: (param.PageNumber - 1) * param.PageSize,
CompanyId: companyId,
PartnerCategory: param.PartnerCategoryId,
CreateTimeBegin: createTimeBegin,
CreateTimeEnd: createTimeEnd,
})
if err != nil {
c.ResponseError(err)
... ... @@ -77,7 +106,6 @@ func (c *OrderDividendController) PageListOrderDividend() {
return
}
//OrderDividendDetail 订单的分红详情
func (c *OrderDividendController) OrderDividendDetail() {
type Parameter struct {
Id string `json:"id"`
... ... @@ -98,168 +126,26 @@ 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
}
type postOrderDividend struct {
Id int64 `json:"id"`
DividendPayments []postDividendPayment `json:"dividendPayment"`
}
type postDividendPayment struct {
QuantityControl string `json:"quantityControl"`
StateOfPayment int `json:"stateOfPayment"`
ProductId int64 `json:"productId"`
Remark string `json:"remark"`
}
func (c *OrderDividendController) EditOrderDividend() {
var (
param postOrderDividend
err error
)
if err = c.BindJsonData(&param); err != nil {
logs.Error(err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
// type postOrderDividend struct {
// Id int64 `json:"id"`
// DividendPayments []postDividendPayment `json:"dividendPayment"`
// }
if param.Id == 0 {
c.ResponseError(errors.New("参数错误"))
return
}
goodbouns := []orderCmd.GoodBouns{}
for _, v := range param.DividendPayments {
if v.ProductId == 0 {
c.ResponseError(errors.New("参数错误"))
return
}
if !(v.StateOfPayment == domain.OrderGoodWaitPay || v.StateOfPayment == domain.OrderGoodHasPay) {
c.ResponseError(errors.New("参数错误"))
return
}
g := orderCmd.GoodBouns{
GoodId: v.ProductId,
Remark: v.Remark,
BounsStatus: v.StateOfPayment,
}
if len(v.QuantityControl) == 0 {
g.UseGoodNumber = -1
} else {
num, err := strconv.Atoi(v.QuantityControl)
if err != nil {
c.ResponseError(errors.New("参数错误"))
return
}
g.UseGoodNumber = num
}
goodbouns = append(goodbouns, g)
}
companyId := c.GetUserCompany()
cmd := orderCmd.UpdateGoodBouns{
Id: param.Id,
GoodBouns: goodbouns,
CompanyId: companyId,
}
orderSrv := orderService.NewOrderInfoService(nil)
err = orderSrv.UpdateGoodBouns(cmd)
if err != nil {
c.ResponseError(err)
return
}
c.ResponseData(nil)
return
}
// type postDividendPayment struct {
// QuantityControl string `json:"quantityControl"`
// StateOfPayment int `json:"stateOfPayment"`
// ProductId int64 `json:"productId"`
// Remark string `json:"remark"`
// }
//OrderDividendDetailForBestshop 海鲜干货的订单分红详情
func (c *OrderDividendController) OrderDividendDetailForBestshop() {
... ... @@ -291,8 +177,8 @@ func (c *OrderDividendController) OrderDividendDetailForBestshop() {
return
}
//EditOrderForBestshop 编辑海鲜干货的订单 中的 货品数量和分红比例
func (c *OrderDividendController) EditOrderDividendForBestshop() {
//EditOrderForBestshop 编辑订单分红详情中的 货品数量和分红比例
func (c *OrderDividendController) EditOrderDividend() {
type Parameter struct {
State int `json:"state"`
OrderId string `json:"orderId"`
... ... @@ -337,8 +223,8 @@ func (c *OrderDividendController) EditOrderDividendForBestshop() {
return
}
//PayOrderGoodBonusForBestshop 支付海鲜干货订单中的分红
func (c *OrderDividendController) PayOrderGoodBonusForBestshop() {
//PayOrderGoodBonus 支付订单中的分红
func (c *OrderDividendController) PayOrderGoodBonus() {
type Parameter struct {
OrderId string `json:"orderId"`
ProductId string `json:"productId"`
... ... @@ -364,7 +250,7 @@ func (c *OrderDividendController) PayOrderGoodBonusForBestshop() {
}
adminId := c.GetUserId()
orderSrv := orderService.NewOrderInfoService(nil)
err = orderSrv.PayPartnerBonusWithOrderBestshop(orderid, productId, adminId)
err = orderSrv.PayPartnerBonus(orderid, productId, adminId)
if err != nil {
c.ResponseError(err)
return
... ... @@ -373,8 +259,8 @@ func (c *OrderDividendController) PayOrderGoodBonusForBestshop() {
return
}
//EditOrderRemarkBonusForBestshop 编辑海鲜干货订单中的备注
func (c *OrderDividendController) EditOrderRemarkBonusForBestshop() {
//EditOrderRemarkBonus 编辑订单分红详情中的备注
func (c *OrderDividendController) EditOrderRemarkBonus() {
type Parameter struct {
OrderId string `json:"orderId"`
Remark string `json:"remark"`
... ... @@ -412,6 +298,7 @@ func (c *OrderDividendController) ListOrderBonusForExcel() {
PageSize int `json:"pageSize"`
PageNumber int `json:"pageNumber"`
PartnerCategoryId int `json:"partnerCategoryId"`
CreateTime []string `json:"createTime"`
}
var (
param Parameter
... ... @@ -428,7 +315,32 @@ func (c *OrderDividendController) ListOrderBonusForExcel() {
c.ResponseError(errors.New("参数异常"))
return
}
var (
createTimeBegin string
createTimeEnd string
)
if len(param.CreateTime) > 0 {
if len(param.CreateTime[0]) > 0 {
t, err := time.ParseInLocation("2006-01-02", param.CreateTime[0], time.Local)
if err != nil {
c.ResponseError(errors.New("UpdateTimeBegin 时间格式错误"))
return
}
createTimeBegin = t.Format("2006-01-02 15:04:05-07")
}
}
if len(param.CreateTime) > 1 {
if len(param.CreateTime[1]) > 0 {
t, err := time.ParseInLocation("2006-01-02", param.CreateTime[1], time.Local)
if err != nil {
c.ResponseError(errors.New("UpdateTimeEnd 时间格式错误"))
return
}
//设定时间边界
t = t.Add(86399 * time.Second)
createTimeEnd = t.Format("2006-01-02 15:04:05-07")
}
}
companyId := c.GetUserCompany()
orderSrv := orderService.NewOrderInfoService(nil)
dataResult, column, err := orderSrv.ListOrderBonusForExcel(
... ... @@ -437,6 +349,8 @@ func (c *OrderDividendController) ListOrderBonusForExcel() {
PartnerOrCode: param.SearchWord,
CompanyId: companyId,
PartnerCategory: param.PartnerCategoryId,
CreateTimeBegin: createTimeBegin,
CreateTimeEnd: createTimeEnd,
})
if err != nil {
c.ResponseError(err)
... ... @@ -456,3 +370,34 @@ func (c *OrderDividendController) ListOrderBonusForExcel() {
c.ResponseExcelByFile(c.Ctx, excelMaker)
return
}
//BatchPayOrderGoodBonus 批量支付订单中的分红
func (c *OrderDividendController) BatchPayOrderGoodBonus() {
type Parameter struct {
OrderIds []string `json:"orderIds"`
}
var (
param Parameter
err error
)
if err = c.BindJsonData(&param); err != nil {
logs.Error(err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
orderIds := []int64{}
for _, v := range param.OrderIds {
id, _ := strconv.ParseInt(v, 10, 64)
orderIds = append(orderIds, id)
}
adminId := c.GetUserId()
orderSrv := orderService.NewOrderInfoService(nil)
err = orderSrv.BatchPayPartnerBonus(orderIds, adminId)
if err != nil {
c.ResponseError(err)
return
}
c.ResponseData(nil)
return
}
... ...
... ... @@ -15,6 +15,7 @@ import (
orderService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/orderinfo/service"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib/exceltool"
)
type OrderInfoController struct {
... ... @@ -32,142 +33,6 @@ func (c *OrderInfoController) Prepare() {
}
}
//PageListOrderPurpose 分页获取意向订单列表
// func (c *OrderInfoController) PageListOrderPurpose() {
// type Parameter struct {
// SearchText string `json:"searchText"`
// Partner int64 `json:"partner"`
// PageSize int `json:"pageSize"`
// PageNumber int `json:"pageNumber"`
// }
// var (
// param Parameter
// err error
// )
// if err = c.BindJsonData(&param); err != nil {
// logs.Error(err)
// c.ResponseError(errors.New("json数据解析失败"))
// return
// }
// if param.PageNumber == 0 {
// param.PageNumber = 1
// }
// if param.PageSize == 0 {
// param.PageSize = 20
// }
// companyId := c.GetUserCompany()
// orderSrv := orderService.NewOrderInfoService(nil)
// orderinfos, cnt, err := orderSrv.PageListOrderBase(orderQuery.ListOrderBaseQuery{
// PartnerId: param.Partner,
// OrderCode: param.SearchText,
// OrderType: domain.OrderIntention,
// Limit: param.PageSize,
// Offset: (param.PageNumber - 1) * param.PageSize,
// CompanyId: companyId,
// })
// if err != nil {
// c.ResponseError(err)
// return
// }
// rsp := []map[string]interface{}{}
// for i := range orderinfos {
// orderinfo := orderinfos[i]
// m := map[string]interface{}{
// "createTime": orderinfo.CreateTime.Local().Format("2006-01-02 15:04:05"),
// "updateTime": orderinfo.UpdateTime.Local().Format("2006-01-02 15:04:05"),
// "buyer": orderinfo.Buyer.BuyerName,
// "id": orderinfo.Id,
// "orderId": orderinfo.OrderCode,
// "partner": orderinfo.PartnerInfo.PartnerName,
// "orderNum": orderinfo.OrderCompute.PlanOrderCount,
// "orderPrice": orderinfo.OrderCompute.PlanOrderAmount,
// "orderDist": orderinfo.RegionInfo.RegionName,
// }
// rsp = append(rsp, m)
// }
// c.ResponsePageList(rsp, cnt, param.PageNumber)
// }
//GetOrderPurpose 获取意向订单详情
// func (c *OrderInfoController) GetOrderPurpose() {
// 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)
// 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.OrderIntention {
// c.ResponseError(errors.New("参数错误"))
// return
// }
// allGoods := []map[string]interface{}{}
// for _, v := range orderinfo.Goods {
// m := map[string]interface{}{
// "id": v.Id,
// "productName": v.GoodName,
// "orderNum": v.PlanGoodNumber,
// "univalence": v.Price,
// "partnerRatio": v.PartnerBonusPercent,
// "orderPrice": v.GoodCompute.PlanAmount,
// }
// allGoods = append(allGoods, m)
// }
// rsp := map[string]interface{}{
// "buyer": orderinfo.Buyer.BuyerName,
// "id": orderinfo.Id,
// "partnerID": orderinfo.PartnerInfo.Id,
// "partner": orderinfo.PartnerInfo.PartnerName,
// "orderDist": orderinfo.RegionInfo.RegionName,
// "orderId": orderinfo.OrderCode,
// "product": allGoods,
// "commissionProportion": orderinfo.SalesmanBonusPercent,
// "orderNumCount": orderinfo.OrderCompute.PlanOrderCount,
// "orderAmountAdjustmentCount": orderinfo.OrderCompute.PlanOrderAmount,
// }
// c.ResponseData(rsp)
// }
//RemoveOrderPurpose 删除意向订单
// func (c *OrderInfoController) RemoveOrderPurpose() {
// type Parameter struct {
// Id int64 `json:"id"`
// }
// var (
// param Parameter
// err error
// )
// if err = c.BindJsonData(&param); err != nil {
// logs.Error(err)
// c.ResponseError(errors.New("json数据解析失败"))
// return
// }
// companyId := c.GetUserCompany()
// orderSrv := orderService.NewOrderInfoService(nil)
// err = orderSrv.DeleteOrder(param.Id, companyId)
// if err != nil {
// c.ResponseError(err)
// return
// }
// c.ResponseData(nil)
// }
//postPurposeOrderDetail 请求添加/更新的订单数据
type postPurposeOrderDetail struct {
Id int64 `json:"id"`
... ... @@ -252,93 +117,6 @@ func (postData *postOrderGood) Valid() error {
return nil
}
// //UpdateOrderPurpose 更新意向订单
// func (c *OrderInfoController) UpdateOrderPurpose() {
// //用与适配前端定义的数据结构
// var (
// param postPurposeOrderDetail
// err error
// )
// if err = c.BindJsonData(&param); err != nil {
// logs.Error(err)
// c.ResponseError(errors.New("json数据解析失败"))
// return
// }
// if err := param.Valid(); err != nil {
// c.ResponseError(err)
// return
// }
// if param.Id == 0 {
// err = c.addOrderPurpose(param)
// } else {
// err = c.editOrderPurpose(param)
// }
// if err != nil {
// c.ResponseError(err)
// }
// c.ResponseData(nil)
// return
// }
// func (c *OrderInfoController) addOrderPurpose(param postPurposeOrderDetail) error {
// newGoods := []orderCmd.OrderGoodData{}
// for _, v := range param.Product {
// g := orderCmd.OrderGoodData{
// GoodName: v.ProductName,
// PlanGoodNumber: v.OrderNum,
// Price: v.Univalence,
// PartnerBonusPercent: v.PartnerRatio,
// }
// newGoods = append(newGoods, g)
// }
// companyId := c.GetUserCompany()
// createcmd := orderCmd.CreateOrderCommand{
// OrderType: domain.OrderIntention,
// OrderCode: param.OrderId,
// DeliveryCode: "",
// BuyerName: param.BuyerName,
// OrderRegion: param.OrderDist,
// PartnerId: param.PartnerId,
// SalesmanBonusPercent: param.CommissionProportion,
// Goods: newGoods,
// CompanyId: companyId,
// }
// orderSrv := orderService.NewOrderInfoService(nil)
// _, err := orderSrv.CreateNewOrder(createcmd)
// return err
// }
// func (c *OrderInfoController) editOrderPurpose(param postPurposeOrderDetail) error {
// orderSrv := orderService.NewOrderInfoService(nil)
// newGoods := []orderCmd.OrderGoodData{}
// for _, v := range param.Product {
// g := orderCmd.OrderGoodData{
// GoodName: v.ProductName,
// PlanGoodNumber: v.OrderNum,
// Price: v.Univalence,
// PartnerBonusPercent: v.PartnerRatio,
// }
// newGoods = append(newGoods, g)
// }
// companyId := c.GetUserCompany()
// updatecmd := orderCmd.UpdateOrderCommand{
// Id: param.Id,
// OrderType: domain.OrderIntention,
// OrderCode: param.OrderId,
// DeliveryCode: "",
// BuyerName: param.BuyerName,
// OrderRegion: param.OrderDist,
// PartnerId: param.PartnerId,
// SalesmanBonusPercent: param.CommissionProportion,
// Goods: newGoods,
// CompanyId: companyId,
// }
// _, err := orderSrv.UpdateOrderData(updatecmd)
// return err
// }
type postOrderPurposeDelivery struct {
ShipmentsId string `json:"shipmentsId"` //发货单号
Id string `json:"id"` //订单id
... ... @@ -363,51 +141,6 @@ func (postData *postOrderPurposeDelivery) Valid() error {
return nil
}
//OrderPurposeDelivery 发货 意向订单转实发单
// func (c *OrderInfoController) OrderPurposeDelivery() {
// //用与适配前端定义的数据结构
// var (
// param postOrderPurposeDelivery
// err error
// )
// if err = c.BindJsonData(&param); err != nil {
// logs.Error(err)
// c.ResponseError(errors.New("json数据解析失败"))
// return
// }
// param.ShipmentsId = strings.TrimSpace(param.ShipmentsId)
// orderid, _ := strconv.ParseInt(param.Id, 10, 64)
// if orderid <= 0 {
// c.ResponseError(errors.New("参数错误"))
// return
// }
// if err = param.Valid(); err != nil {
// c.ResponseError(err)
// return
// }
// goods := []orderCmd.OrderGoodData{}
// for _, v := range param.ProductDetail {
// g := orderCmd.OrderGoodData{
// Id: v.Id, GoodName: v.ProductName, PlanGoodNumber: v.OrderNum,
// Price: v.Univalence, PartnerBonusPercent: v.PartnerRatio,
// }
// goods = append(goods, g)
// }
// companyId := c.GetUserCompany()
// deliveryCommand := orderCmd.OrderDeliveryCommand{
// OrderId: orderid, DeliveryCode: param.ShipmentsId,
// DeliveryTime: time.Now(), Goods: goods, CompanyId: companyId,
// }
// orderSrv := orderService.NewOrderInfoService(nil)
// err = orderSrv.Delivery(deliveryCommand)
// if err != nil {
// c.ResponseError(err)
// }
// c.ResponseData(nil)
// return
// }
//PageListOrderReal 获取实发订单列表
func (c *OrderInfoController) PageListOrderReal() {
type Parameter struct {
... ... @@ -416,6 +149,7 @@ func (c *OrderInfoController) PageListOrderReal() {
PageSize int `json:"pageSize"`
PageNumber int `json:"pageNumber"`
UpdateTime []string `json:"updateTime"`
CreateTime []string `json:"createTime"`
}
var (
param Parameter
... ... @@ -458,6 +192,33 @@ func (c *OrderInfoController) PageListOrderReal() {
updateTimeEnd = t.Format("2006-01-02 15:04:05-07")
}
}
var (
createTimeBegin string
createTimeEnd string
)
if len(param.CreateTime) > 0 {
if len(param.CreateTime[0]) > 0 {
t, err := time.ParseInLocation("2006-01-02", param.CreateTime[0], time.Local)
if err != nil {
c.ResponseError(errors.New("UpdateTimeBegin 时间格式错误"))
return
}
createTimeBegin = t.Format("2006-01-02 15:04:05-07")
}
}
if len(param.CreateTime) > 1 {
if len(param.CreateTime[1]) > 0 {
t, err := time.ParseInLocation("2006-01-02", param.CreateTime[1], time.Local)
if err != nil {
c.ResponseError(errors.New("UpdateTimeEnd 时间格式错误"))
return
}
//设定时间边界
t = t.Add(86399 * time.Second)
createTimeEnd = t.Format("2006-01-02 15:04:05-07")
}
}
companyId := c.GetUserCompany()
orderSrv := orderService.NewOrderInfoService(nil)
orderinfos, cnt, err := orderSrv.PageListOrderBase(orderQuery.ListOrderBaseQuery{
... ... @@ -469,6 +230,8 @@ func (c *OrderInfoController) PageListOrderReal() {
PartnerCategory: param.PartnerCategory,
UpdateTimeBegin: updateTimeBegin,
UpdateTimeEnd: updateTimeEnd,
CreateTimeBegin: createTimeBegin,
CreateTimeEnd: createTimeEnd,
})
if err != nil {
c.ResponseError(err)
... ... @@ -514,7 +277,7 @@ func (c *OrderInfoController) GetOrderReal() {
allGoods := []map[string]interface{}{}
for _, v := range orderinfo.Goods {
m := map[string]interface{}{
"id": v.Id,
"id": fmt.Sprint(v.Id),
"productName": v.GoodName,
"orderNum": v.PlanGoodNumber,
"univalence": v.Price,
... ... @@ -594,8 +357,9 @@ func (c *OrderInfoController) UpdateOrderReal() {
c.ResponseError(err)
return
}
var orderDataReturn *domain.OrderBase
if param.Id == 0 {
err = c.addOrderReal(param)
orderDataReturn, err = c.addOrderReal(param)
} else {
err = c.editOrderReal(param)
}
... ... @@ -603,11 +367,17 @@ func (c *OrderInfoController) UpdateOrderReal() {
c.ResponseError(err)
return
}
if orderDataReturn != nil {
c.ResponseData(map[string]interface{}{
"id": orderDataReturn.Id,
})
return
}
c.ResponseData(nil)
return
}
func (c *OrderInfoController) addOrderReal(param postRealOrderDetail) error {
func (c *OrderInfoController) addOrderReal(param postRealOrderDetail) (*domain.OrderBase, error) {
orderSrv := orderService.NewOrderInfoService(nil)
newGoods := []orderCmd.OrderGoodData{}
for _, v := range param.Product {
... ... @@ -632,8 +402,8 @@ func (c *OrderInfoController) addOrderReal(param postRealOrderDetail) error {
CompanyId: companyId,
PartnerCategory: param.PartnerCategoryId,
}
_, err := orderSrv.CreateNewOrder(createcmd)
return err
orderData, err := orderSrv.CreateNewOrder(createcmd)
return orderData, err
}
func (c *OrderInfoController) editOrderReal(param postRealOrderDetail) error {
... ... @@ -711,7 +481,7 @@ func (c *OrderInfoController) OrderDisable() {
//RemoveOrderReal 删除意向订单
func (c *OrderInfoController) RemoveOrderReal() {
type Parameter struct {
Id int64 `json:"id"`
Id string `json:"id"`
}
var (
param Parameter
... ... @@ -723,11 +493,113 @@ func (c *OrderInfoController) RemoveOrderReal() {
return
}
companyId := c.GetUserCompany()
id, _ := strconv.ParseInt(param.Id, 10, 64)
orderSrv := orderService.NewOrderInfoService(nil)
err = orderSrv.DeleteOrder(param.Id, companyId)
err = orderSrv.DeleteOrder(id, companyId)
if err != nil {
c.ResponseError(err)
return
}
c.ResponseData(nil)
}
//ListOrderForExcel excel 导出实际订单的列表
func (c *OrderInfoController) ListOrderForExcel() {
type Parameter struct {
SearchText string `json:"searchText"`
PartnerCategory int `json:"PartnerCategory"`
UpdateTime []string `json:"updateTime"`
CreateTime []string `json:"createTime"`
}
var (
param Parameter
err error
)
if err = c.BindJsonData(&param); err != nil {
logs.Error(err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
var (
updateTimeBegin string
updateTimeEnd string
)
if len(param.UpdateTime) > 0 {
if len(param.UpdateTime[0]) > 0 {
t, err := time.ParseInLocation("2006-01-02", param.UpdateTime[0], time.Local)
if err != nil {
c.ResponseError(errors.New("UpdateTimeBegin 时间格式错误"))
return
}
updateTimeBegin = t.Format("2006-01-02 15:04:05-07")
}
}
if len(param.UpdateTime) > 1 {
if len(param.UpdateTime[1]) > 0 {
t, err := time.ParseInLocation("2006-01-02", param.UpdateTime[1], time.Local)
if err != nil {
c.ResponseError(errors.New("UpdateTimeEnd 时间格式错误"))
return
}
//设定时间边界
t = t.Add(86399 * time.Second)
updateTimeEnd = t.Format("2006-01-02 15:04:05-07")
}
}
var (
createTimeBegin string
createTimeEnd string
)
if len(param.CreateTime) > 0 {
if len(param.CreateTime[0]) > 0 {
t, err := time.ParseInLocation("2006-01-02", param.CreateTime[0], time.Local)
if err != nil {
c.ResponseError(errors.New("UpdateTimeBegin 时间格式错误"))
return
}
createTimeBegin = t.Format("2006-01-02 15:04:05-07")
}
}
if len(param.CreateTime) > 1 {
if len(param.CreateTime[1]) > 0 {
t, err := time.ParseInLocation("2006-01-02", param.CreateTime[1], time.Local)
if err != nil {
c.ResponseError(errors.New("UpdateTimeEnd 时间格式错误"))
return
}
//设定时间边界
t = t.Add(86399 * time.Second)
createTimeEnd = t.Format("2006-01-02 15:04:05-07")
}
}
companyId := c.GetUserCompany()
orderSrv := orderService.NewOrderInfoService(nil)
orderinfos, columns, err := orderSrv.ListOrderForExcel(orderQuery.ListOrderBaseQuery{
PartnerOrCode: param.SearchText,
OrderType: domain.OrderReal,
CompanyId: companyId,
PartnerCategory: param.PartnerCategory,
UpdateTimeBegin: updateTimeBegin,
UpdateTimeEnd: updateTimeEnd,
CreateTimeBegin: createTimeBegin,
CreateTimeEnd: createTimeEnd,
})
if err != nil {
c.ResponseError(err)
return
}
var excelHeaders []exceltool.ExcelHead
for i := range columns {
h := exceltool.ExcelHead{
Key: columns[i][0],
Name: columns[i][1],
}
excelHeaders = append(excelHeaders, h)
}
excelMaker := exceltool.NewExcelMaker()
excelMaker.SetListHead(excelHeaders)
excelMaker.MakeListExcel(orderinfos)
c.ResponseExcelByFile(c.Ctx, excelMaker)
return
}
... ...
... ... @@ -84,11 +84,17 @@ func (c *PartnerInfoController) CreatePartnerInfo() {
}
}
serve := partnerInfoService.NewPartnerInfoService(nil)
_, err = serve.CreatePartnerInfo(&cmd)
newPartner, err := serve.CreatePartnerInfo(&cmd)
if err != nil {
c.ResponseError(err)
return
}
if newPartner != nil {
c.ResponseData(map[string]interface{}{
"id": newPartner.Partner.Id,
})
return
}
c.ResponseData(nil)
return
}
... ... @@ -202,11 +208,12 @@ func (c *PartnerInfoController) GetPartnerInfo() {
return
}
//PartnerInfoSetState 合伙人批量禁用
//PartnerInfoSetState 合伙人批量禁用.启用
func (c *PartnerInfoController) PartnerInfoSetState() {
//用与适配前端定义的数据结构
type Parameter struct {
Id []int64 `json:"id"`
Status int `json:"status"`
}
var (
param Parameter
... ... @@ -218,11 +225,24 @@ func (c *PartnerInfoController) PartnerInfoSetState() {
return
}
comanyId := c.GetUserCompany()
cmd := partnerInfoCmd.StatusPartnerInfoCommand{
var cmd partnerInfoCmd.StatusPartnerInfoCommand
switch param.Status {
case 0:
cmd = partnerInfoCmd.StatusPartnerInfoCommand{
Ids: param.Id,
CompanyId: comanyId,
Status: domain.PARTNER_STATUS_NO,
}
case 1:
cmd = partnerInfoCmd.StatusPartnerInfoCommand{
Ids: param.Id,
CompanyId: comanyId,
Status: domain.PARTNER_STATUS_YES,
}
default:
c.ResponseError(errors.New("参数错误"))
return
}
newPartnerService := partnerInfoService.NewPartnerInfoService(nil)
err = newPartnerService.UpdateStatus(cmd)
if err != nil {
... ...
... ... @@ -80,9 +80,6 @@ func (c *UserController) BeforeEditUser() {
}
var rspData []map[string]interface{}
for i := range allPermission {
if allPermission[i].Code == domain.PERMINSSION_ADMIN_USER {
continue
}
m := map[string]interface{}{
"id": allPermission[i].Id,
"permissionName": allPermission[i].Name,
... ...
... ... @@ -22,29 +22,20 @@ func init() {
beego.NSRouter("/add", &controllers.PartnerInfoController{}, "POST:CreatePartnerInfo"),
beego.NSRouter("/edit", &controllers.PartnerInfoController{}, "POST:UpdatePartnerInfo"),
beego.NSRouter("/detail", &controllers.PartnerInfoController{}, "POST:GetPartnerInfo"),
//beego.NSRouter("/set-status", &controllers.PartnerInfoController{}, "POST:PartnerInfoSetState"),
beego.NSRouter("/batchDisabled", &controllers.PartnerInfoController{}, "POST:PartnerInfoSetState"),
),
beego.NSNamespace("/dividends",
beego.NSRouter("/list", &controllers.OrderDividendController{}, "POST:PageListOrderDividend"),
beego.NSRouter("/edit", &controllers.OrderDividendController{}, "POST:EditOrderDividend"),
beego.NSRouter("/modify", &controllers.OrderDividendController{}, "POST:EditOrderDividend"),
beego.NSRouter("/detail", &controllers.OrderDividendController{}, "POST:OrderDividendDetail"),
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"),
beego.NSRouter("/payDividends", &controllers.OrderDividendController{}, "POST:PayOrderGoodBonus"),
beego.NSRouter("/payDividends/batch", &controllers.OrderDividendController{}, "POST:BatchPayOrderGoodBonus"),
beego.NSRouter("/remarks", &controllers.OrderDividendController{}, "POST:EditOrderRemarkBonus"),
beego.NSRouter("/list/excel", &controllers.OrderDividendController{}, "POST:ListOrderBonusForExcel"),
// beego.NSRouter("/business/detail", &controllers.BusinessBonusController{}, "POST:GetBusinessBonus"),
// beego.NSRouter("/business/edit", &controllers.BusinessBonusController{}, "POST:UpdateBusinessBonus"),
// beego.NSRouter("/business/list", &controllers.BusinessBonusController{}, "POST:ListBusinessBonus"),
),
beego.NSNamespace("/order",
// beego.NSRouter("/purpose/list", &controllers.OrderInfoController{}, "POST:PageListOrderPurpose"),
// beego.NSRouter("/purpose/update", &controllers.OrderInfoController{}, "POST:UpdateOrderPurpose"),
// beego.NSRouter("/purpose/detail", &controllers.OrderInfoController{}, "POST:GetOrderPurpose"),
// beego.NSRouter("/purpose/del", &controllers.OrderInfoController{}, "POST:RemoveOrderPurpose"),
// beego.NSRouter("/purpose/sendout", &controllers.OrderInfoController{}, "POST:OrderPurposeDelivery"),
beego.NSRouter("/actual/list", &controllers.OrderInfoController{}, "POST:PageListOrderReal"),
beego.NSRouter("/actual/list/excel", &controllers.OrderInfoController{}, "POST:ListOrderForExcel"),
beego.NSRouter("/actual/detail", &controllers.OrderInfoController{}, "POST:GetOrderReal"),
beego.NSRouter("/actual/del", &controllers.OrderInfoController{}, "POST:RemoveOrderReal"),
beego.NSRouter("/actual/update", &controllers.OrderInfoController{}, "POST:UpdateOrderReal"),
... ...