作者 陈志颖

fix:增加删除合伙人类型判断

... ... @@ -2,6 +2,7 @@ package service
import (
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/utils"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory"
... ... @@ -238,7 +239,7 @@ func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(q query.GetPartnerI
/**
* @Author SteveChan
* @Description // 更新合伙人
* @Description //TODO 更新合伙人,判断合伙类型是否有业务数据
* @Date 00:07 2020/12/30
* @Param
* @return
... ... @@ -261,7 +262,9 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.Upd
var (
partnerInfoRepository domain.PartnerInfoRepository
categoryRepository domain.PartnerCategoryRepository
orderBaseRepository domain.OrderBaseRepository
categories []domain.PartnerCategory
orders []domain.OrderBase
partnerInfoDao *dao.PartnerInfoDao
)
... ... @@ -283,6 +286,12 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.Upd
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
if orderBaseRepository, err = factory.CreateOrderBaseRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
// 获取合伙人类型
var categoryMap = make(map[int64]string)
_, categories, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{
... ... @@ -349,6 +358,34 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.Upd
return lib.ThrowError(lib.BUSINESS_ERROR, "异常操作")
}
partnerCategoryInfos := partnerInfo.PartnerCategoryInfos
//判断相应合伙类型下是否有订单数据
var notInPartnerCategoryInfos []int64
var categoryIdsQuery []int64
var categoryIdsCmd []int64
for _, partnerCategory := range partnerCategoryInfos {
categoryIdsQuery = append(categoryIdsQuery, partnerCategory.Id)
}
for _, category := range categories {
categoryIdsCmd = append(categoryIdsCmd, category.Id)
}
for _, v := range categoryIdsQuery {
if !utils.IsContainInt(categoryIdsCmd, v) {
notInPartnerCategoryInfos = append(notInPartnerCategoryInfos, v)
}
}
if len(notInPartnerCategoryInfos) > 0 {
orders, _, err = orderBaseRepository.Find(domain.OrderBaseFindQuery{
PartnerId: cmd.Id,
CompanyId: cmd.CompanyId,
PartnerCategoryIds: notInPartnerCategoryInfos,
})
if len(orders) > 0 {
return lib.ThrowError(lib.BUSINESS_ERROR, "该合伙类型下有业务数据,不可删除!")
}
}
partnerInfo.Partner.PartnerName = cmd.PartnerName
partnerInfo.Salesman = cmd.Salesman
partnerInfo.Status = cmd.Status
... ... @@ -372,7 +409,7 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.Upd
// e := fmt.Sprintf("更新业务分红(partner_id=%d)数据失败:%s", partnerInfo.Partner.Id, err)
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
// }
transactionContext.CommitTransaction()
_ = transactionContext.CommitTransaction()
return
}
... ...
... ... @@ -308,13 +308,14 @@ type OrderBaseFindOneQuery struct {
}
type OrderBaseFindQuery struct {
PartnerId int64
OrderCode string
DeliveryCode string
Offset int
Limit int
OrderType int
CompanyId int64
PartnerId int64
OrderCode string
DeliveryCode string
Offset int
Limit int
OrderType int
CompanyId int64
PartnerCategoryIds []int64
}
// 导入错误信息
... ...
... ... @@ -2,6 +2,7 @@ package repository
import (
"fmt"
"github.com/go-pg/pg/v10"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
... ... @@ -84,9 +85,6 @@ func (repository OrderBaseRepository) Save(orderInfo *domain.OrderBase) error {
Remark: orderInfo.Remark,
PartnerCategory: orderInfo.PartnerCategory,
}
//if m.OrderType > 2 { // TODO 非平台自建订单,默认销售日期取订单创建日期
// m.SaleDate = orderInfo.CreateTime
//}
if m.Id == 0 {
_, err = tx.Model(m).
Returning("*").
... ... @@ -124,6 +122,9 @@ func (repository OrderBaseRepository) Find(queryOption domain.OrderBaseFindQuery
if queryOption.CompanyId > 0 {
query = query.Where("company_id=?", queryOption.CompanyId)
}
if len(queryOption.PartnerCategoryIds) > 0 {
query = query.Where(`(order_base.partner_category->>'id')::int IN (?)`, pg.In(queryOption.PartnerCategoryIds))
}
if queryOption.Offset > -1 {
query = query.Offset(queryOption.Offset)
}
... ...
... ... @@ -47,3 +47,19 @@ func IsContain(items []string, item string) bool {
}
return false
}
/**
* @Author SteveChan
* @Description //TODO
* @Date 23:34 2021/2/2
* @Param
* @return
**/
func IsContainInt(items []int64, item int64) bool {
for _, eachItem := range items {
if eachItem == item {
return true
}
}
return false
}
... ...