company.go
3.8 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package company
import (
"github.com/tiptok/gocomm/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol"
protocolx "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol/company"
"strings"
)
func Property(header *protocol.RequestHeader, request *protocolx.PropertyRequest) (rsp *protocolx.PropertyResponse, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.PropertyResponse{}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
//用户查询区域
if (request.Action & 0x01) > 0 {
rsp.Districts, _ = getDistricts(header.UserId, transactionContext)
}
//查询合伙人类型
if (request.Action & 0x02) > 0 {
rsp.JoinWays, _ = getJoinWays(transactionContext)
}
err = transactionContext.CommitTransaction()
return
}
func Partners(header *protocol.RequestHeader, request *protocolx.PartnersRequest) (rsp *protocolx.PartnersResponse, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.PartnersResponse{}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
err = transactionContext.CommitTransaction()
return
}
func Statistics(header *protocol.RequestHeader, request *protocolx.StatisticsRequest) (rsp *protocolx.StatisticsResponse, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
rsp = &protocolx.StatisticsResponse{}
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
err = transactionContext.CommitTransaction()
return
}
// 获取区域列表
func getDistricts(userId int64, transactionContext *transaction.TransactionContext) (districts []protocolx.Districts, err error) {
var (
user *domain.Users
partnerInfos []*domain.PartnerInfo
UsersRepository, _ = factory.CreateUsersRepository(transactionContext)
PartnerInfoRepository, _ = factory.CreatePartnerInfoRepositoryIn(transactionContext)
)
if user, err = UsersRepository.FindOne(map[string]interface{}{"id": userId}); err != nil {
log.Error(err)
return
}
if user == nil || len(user.AccessPartners) == 0 {
return
}
if _, partnerInfos, err = PartnerInfoRepository.Find(map[string]interface{}{
"inPartnerIds": user.AccessPartnerIds(),
"sortByCreateTime": domain.ASC},
); err != nil {
return
}
for i := range partnerInfos {
partner := partnerInfos[i]
include := false
if partner.RegionInfo == nil {
continue
}
for j := range districts {
if strings.TrimSpace(districts[j].Name) == strings.TrimSpace(partner.RegionInfo.RegionName) {
include = true
break
}
}
if !include {
districts = append(districts, protocolx.Districts{
Id: partner.RegionInfo.RegionId,
Name: partner.RegionInfo.RegionName,
})
}
}
return
}
// 获取合伙人类型列表
func getJoinWays(transactionContext *transaction.TransactionContext) (joinWays []protocolx.JoinWays, err error) {
var (
CategoryInfoRepository, _ = factory.CreatePartnerCategoryInfoRepository(transactionContext)
categories []*domain.PartnerCategoryInfo
)
if _, categories, err = CategoryInfoRepository.Find(nil); err != nil && len(categories) == 0 {
return
}
for i := range categories {
c := categories[i]
joinWays = append(joinWays, protocolx.JoinWays{Type: c.Id, Name: c.Name})
}
return
}