作者 陈志颖

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

@@ -2,6 +2,7 @@ package service @@ -2,6 +2,7 @@ package service
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/utils"
5 6
6 "github.com/linmadan/egglib-go/core/application" 7 "github.com/linmadan/egglib-go/core/application"
7 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory" 8 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory"
@@ -238,7 +239,7 @@ func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(q query.GetPartnerI @@ -238,7 +239,7 @@ func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(q query.GetPartnerI
238 239
239 /** 240 /**
240 * @Author SteveChan 241 * @Author SteveChan
241 - * @Description // 更新合伙人 242 + * @Description //TODO 更新合伙人,判断合伙类型是否有业务数据
242 * @Date 00:07 2020/12/30 243 * @Date 00:07 2020/12/30
243 * @Param 244 * @Param
244 * @return 245 * @return
@@ -261,7 +262,9 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.Upd @@ -261,7 +262,9 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.Upd
261 var ( 262 var (
262 partnerInfoRepository domain.PartnerInfoRepository 263 partnerInfoRepository domain.PartnerInfoRepository
263 categoryRepository domain.PartnerCategoryRepository 264 categoryRepository domain.PartnerCategoryRepository
  265 + orderBaseRepository domain.OrderBaseRepository
264 categories []domain.PartnerCategory 266 categories []domain.PartnerCategory
  267 + orders []domain.OrderBase
265 partnerInfoDao *dao.PartnerInfoDao 268 partnerInfoDao *dao.PartnerInfoDao
266 ) 269 )
267 270
@@ -283,6 +286,12 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.Upd @@ -283,6 +286,12 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.Upd
283 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 286 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
284 } 287 }
285 288
  289 + if orderBaseRepository, err = factory.CreateOrderBaseRepository(map[string]interface{}{
  290 + "transactionContext": transactionContext,
  291 + }); err != nil {
  292 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  293 + }
  294 +
286 // 获取合伙人类型 295 // 获取合伙人类型
287 var categoryMap = make(map[int64]string) 296 var categoryMap = make(map[int64]string)
288 _, categories, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{ 297 _, categories, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{
@@ -349,6 +358,34 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.Upd @@ -349,6 +358,34 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.Upd
349 return lib.ThrowError(lib.BUSINESS_ERROR, "异常操作") 358 return lib.ThrowError(lib.BUSINESS_ERROR, "异常操作")
350 } 359 }
351 360
  361 + partnerCategoryInfos := partnerInfo.PartnerCategoryInfos
  362 +
  363 + //判断相应合伙类型下是否有订单数据
  364 + var notInPartnerCategoryInfos []int64
  365 + var categoryIdsQuery []int64
  366 + var categoryIdsCmd []int64
  367 + for _, partnerCategory := range partnerCategoryInfos {
  368 + categoryIdsQuery = append(categoryIdsQuery, partnerCategory.Id)
  369 + }
  370 + for _, category := range categories {
  371 + categoryIdsCmd = append(categoryIdsCmd, category.Id)
  372 + }
  373 + for _, v := range categoryIdsQuery {
  374 + if !utils.IsContainInt(categoryIdsCmd, v) {
  375 + notInPartnerCategoryInfos = append(notInPartnerCategoryInfos, v)
  376 + }
  377 + }
  378 + if len(notInPartnerCategoryInfos) > 0 {
  379 + orders, _, err = orderBaseRepository.Find(domain.OrderBaseFindQuery{
  380 + PartnerId: cmd.Id,
  381 + CompanyId: cmd.CompanyId,
  382 + PartnerCategoryIds: notInPartnerCategoryInfos,
  383 + })
  384 + if len(orders) > 0 {
  385 + return lib.ThrowError(lib.BUSINESS_ERROR, "该合伙类型下有业务数据,不可删除!")
  386 + }
  387 + }
  388 +
352 partnerInfo.Partner.PartnerName = cmd.PartnerName 389 partnerInfo.Partner.PartnerName = cmd.PartnerName
353 partnerInfo.Salesman = cmd.Salesman 390 partnerInfo.Salesman = cmd.Salesman
354 partnerInfo.Status = cmd.Status 391 partnerInfo.Status = cmd.Status
@@ -372,7 +409,7 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.Upd @@ -372,7 +409,7 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.Upd
372 // e := fmt.Sprintf("更新业务分红(partner_id=%d)数据失败:%s", partnerInfo.Partner.Id, err) 409 // e := fmt.Sprintf("更新业务分红(partner_id=%d)数据失败:%s", partnerInfo.Partner.Id, err)
373 // return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e) 410 // return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
374 // } 411 // }
375 - transactionContext.CommitTransaction() 412 + _ = transactionContext.CommitTransaction()
376 return 413 return
377 } 414 }
378 415
@@ -308,13 +308,14 @@ type OrderBaseFindOneQuery struct { @@ -308,13 +308,14 @@ type OrderBaseFindOneQuery struct {
308 } 308 }
309 309
310 type OrderBaseFindQuery struct { 310 type OrderBaseFindQuery struct {
311 - PartnerId int64  
312 - OrderCode string  
313 - DeliveryCode string  
314 - Offset int  
315 - Limit int  
316 - OrderType int  
317 - CompanyId int64 311 + PartnerId int64
  312 + OrderCode string
  313 + DeliveryCode string
  314 + Offset int
  315 + Limit int
  316 + OrderType int
  317 + CompanyId int64
  318 + PartnerCategoryIds []int64
318 } 319 }
319 320
320 // 导入错误信息 321 // 导入错误信息
@@ -2,6 +2,7 @@ package repository @@ -2,6 +2,7 @@ package repository
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "github.com/go-pg/pg/v10"
5 6
6 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" 7 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
7 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models" 8 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
@@ -84,9 +85,6 @@ func (repository OrderBaseRepository) Save(orderInfo *domain.OrderBase) error { @@ -84,9 +85,6 @@ func (repository OrderBaseRepository) Save(orderInfo *domain.OrderBase) error {
84 Remark: orderInfo.Remark, 85 Remark: orderInfo.Remark,
85 PartnerCategory: orderInfo.PartnerCategory, 86 PartnerCategory: orderInfo.PartnerCategory,
86 } 87 }
87 - //if m.OrderType > 2 { // TODO 非平台自建订单,默认销售日期取订单创建日期  
88 - // m.SaleDate = orderInfo.CreateTime  
89 - //}  
90 if m.Id == 0 { 88 if m.Id == 0 {
91 _, err = tx.Model(m). 89 _, err = tx.Model(m).
92 Returning("*"). 90 Returning("*").
@@ -124,6 +122,9 @@ func (repository OrderBaseRepository) Find(queryOption domain.OrderBaseFindQuery @@ -124,6 +122,9 @@ func (repository OrderBaseRepository) Find(queryOption domain.OrderBaseFindQuery
124 if queryOption.CompanyId > 0 { 122 if queryOption.CompanyId > 0 {
125 query = query.Where("company_id=?", queryOption.CompanyId) 123 query = query.Where("company_id=?", queryOption.CompanyId)
126 } 124 }
  125 + if len(queryOption.PartnerCategoryIds) > 0 {
  126 + query = query.Where(`(order_base.partner_category->>'id')::int IN (?)`, pg.In(queryOption.PartnerCategoryIds))
  127 + }
127 if queryOption.Offset > -1 { 128 if queryOption.Offset > -1 {
128 query = query.Offset(queryOption.Offset) 129 query = query.Offset(queryOption.Offset)
129 } 130 }
@@ -47,3 +47,19 @@ func IsContain(items []string, item string) bool { @@ -47,3 +47,19 @@ func IsContain(items []string, item string) bool {
47 } 47 }
48 return false 48 return false
49 } 49 }
  50 +
  51 +/**
  52 + * @Author SteveChan
  53 + * @Description //TODO
  54 + * @Date 23:34 2021/2/2
  55 + * @Param
  56 + * @return
  57 + **/
  58 +func IsContainInt(items []int64, item int64) bool {
  59 + for _, eachItem := range items {
  60 + if eachItem == item {
  61 + return true
  62 + }
  63 + }
  64 + return false
  65 +}