pg_business_bonus_service.go
2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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
}
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)
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
}
return nil
}