作者 唐旭辉

Merge branch 'test'

正在显示 72 个修改的文件 包含 3054 行增加904 行删除

要显示太多修改。

为保证性能只显示 72 of 72+ 个文件。

@@ -68,6 +68,16 @@ spec: @@ -68,6 +68,16 @@ spec:
68 value: "1" 68 value: "1"
69 - name: ERROR_BASE_CODE_MULTIPLE 69 - name: ERROR_BASE_CODE_MULTIPLE
70 value: "1000" 70 value: "1000"
  71 + - name: UCENTER_HOST
  72 + value: "https://suplus-ucenter-dev.fjmaimaimai.com"
  73 + - name: UCENTER_SECRET
  74 + value: "cykbjnfqgctn"
  75 + - name: UCENTER_APP_KEY
  76 + value: "39aefef9e22744a3b2d2d3791824ae7b"
  77 + - name: UCENTER_CHECK_ALT
  78 + value: "6DwjBO735"
  79 + - name: BUSINESS_ADMIN_HOST
  80 + value: "http://suplus-business-admin-dev.fjmaimaimai.com"
71 volumes: 81 volumes:
72 - name: accesslogs 82 - name: accesslogs
73 emptyDir: {} 83 emptyDir: {}
@@ -65,10 +65,16 @@ spec: @@ -65,10 +65,16 @@ spec:
65 value: "1" 65 value: "1"
66 - name: ERROR_BASE_CODE_MULTIPLE 66 - name: ERROR_BASE_CODE_MULTIPLE
67 value: "1000" 67 value: "1000"
68 - - name: ABILITY_SERVICE_HOST  
69 - value: "https://ability.fjmaimaimai.com"  
70 - - name: MMM_OPEN_API_SERVICE_HOST  
71 - value: "https://public-interface.fjmaimaimai.com/openapi" 68 + - name: UCENTER_HOST
  69 + value: "https://public-interface.fjmaimaimai.com/ucenter"
  70 + - name: UCENTER_SECRET
  71 + value: "cykbjnfqgctn"
  72 + - name: UCENTER_APP_KEY
  73 + value: "39aefef9e22744a3b2d2d3791824ae7b"
  74 + - name: UCENTER_CHECK_ALT
  75 + value: "rsF0pL!6DwjBO735"
  76 + - name: BUSINESS_ADMIN_HOST
  77 + value: "http://suplus-business-admin-prd.fjmaimaimai.com"
72 volumes: 78 volumes:
73 - name: accesslogs 79 - name: accesslogs
74 emptyDir: {} 80 emptyDir: {}
@@ -65,6 +65,16 @@ spec: @@ -65,6 +65,16 @@ spec:
65 value: "1" 65 value: "1"
66 - name: ERROR_BASE_CODE_MULTIPLE 66 - name: ERROR_BASE_CODE_MULTIPLE
67 value: "1000" 67 value: "1000"
  68 + - name: UCENTER_HOST
  69 + value: "https://suplus-ucenter-test.fjmaimaimai.com"
  70 + - name: UCENTER_SECRET
  71 + value: "cykbjnfqgctn"
  72 + - name: UCENTER_APP_KEY
  73 + value: "39aefef9e22744a3b2d2d3791824ae7b"
  74 + - name: UCENTER_CHECK_ALT
  75 + value: "rsF0pL!6DwjBO735"
  76 + - name: BUSINESS_ADMIN_HOST
  77 + value: "http://suplus-business-admin-test.fjmaimaimai.com"
68 volumes: 78 volumes:
69 - name: accesslogs 79 - name: accesslogs
70 emptyDir: {} 80 emptyDir: {}
@@ -7,7 +7,7 @@ import ( @@ -7,7 +7,7 @@ import (
7 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib" 7 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
8 ) 8 )
9 9
10 -//AdminUserService 管理员相关服务 10 +//AdminPermissionService 管理员权限
11 type AdminPermissionService struct { 11 type AdminPermissionService struct {
12 } 12 }
13 13
@@ -39,12 +39,10 @@ func (adminPermissionSrv AdminPermissionService) ListAdminPermission(queryOption @@ -39,12 +39,10 @@ func (adminPermissionSrv AdminPermissionService) ListAdminPermission(queryOption
39 } else { 39 } else {
40 permissionRepository = value 40 permissionRepository = value
41 } 41 }
42 - permissions, err = permissionRepository.Find(domain.AdminPermissionFindQuery{  
43 - NotCode: queryOption.NotCode,  
44 - ParentId: queryOption.ParentId,  
45 - }) 42 + permissions, err = permissionRepository.Find(domain.PermissionFindOption{})
46 if err != nil { 43 if err != nil {
47 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 44 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
48 } 45 }
  46 + err = transactionContext.CommitTransaction()
49 return permissions, nil 47 return permissions, nil
50 } 48 }
1 -package command  
2 -  
3 -import (  
4 - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"  
5 -)  
6 -  
7 -type SaveAdminUserCommand struct {  
8 - Id int64 `json:"id"`  
9 - // 员工姓名  
10 - Name string `json:"name"`  
11 - // 员工账号  
12 - Account string `json:"account" `  
13 - //密码  
14 - Password string `json:"password"`  
15 - // 员工角色  
16 - PermissionId []int `json:"PermissionId"`  
17 -  
18 - IsUsable bool `json:"isUsable"`  
19 -}  
20 -  
21 -func (command SaveAdminUserCommand) ValidateCommand() error {  
22 - if len(command.Name) == 0 {  
23 - return lib.ThrowError(lib.ARG_ERROR, "用户名称必填")  
24 - }  
25 - if len(command.Account) == 0 {  
26 - return lib.ThrowError(lib.ARG_ERROR, "账号必填")  
27 - }  
28 - return nil  
29 -}  
1 -package command  
2 -  
3 -import "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"  
4 -  
5 -//UpdateAdminUserPwdCommand 修改密码  
6 -type UpdateAdminUserPwdCommand struct {  
7 - Id int64 `json:"id"`  
8 - //密码  
9 - Password string `json:"password"`  
10 -}  
11 -  
12 -func (command UpdateAdminUserPwdCommand) ValidateCommand() error {  
13 - if len(command.Password) == 0 {  
14 - return lib.ThrowError(lib.ARG_ERROR, "密码必填")  
15 - }  
16 - return nil  
17 -}  
1 -package service  
2 -  
3 -import (  
4 - "crypto/sha1"  
5 - "fmt"  
6 -  
7 - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminUser/command"  
8 - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminUser/query"  
9 - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory"  
10 - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"  
11 - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/dao"  
12 - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"  
13 -)  
14 -  
15 -//AdminUserService 管理员相关服务  
16 -type AdminUserService struct {  
17 -}  
18 -  
19 -func NewAdminUserService(option map[string]interface{}) *AdminUserService {  
20 - newAdminUserService := new(AdminUserService)  
21 - return newAdminUserService  
22 -}  
23 -  
24 -func (adminUserSrv AdminUserService) GetAdminUser(getAdminUserQuery *query.GetAdminUserQuery) (*domain.AdminUser, error) {  
25 - //实际业务  
26 - transactionContext, err := factory.CreateTransactionContext(nil)  
27 - if err != nil {  
28 - return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())  
29 - }  
30 - var (  
31 - adminuserRepository domain.AdminUserRepository  
32 - adminuser *domain.AdminUser  
33 - )  
34 - if value, err := factory.CreateAdminUserRepository(map[string]interface{}{  
35 - "transactionContext": transactionContext,  
36 - }); err != nil {  
37 - return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())  
38 - } else {  
39 - adminuserRepository = value  
40 - }  
41 - adminuser, err = adminuserRepository.FindOne(domain.AdminUserFindOneQuery{  
42 - AccountEqual: getAdminUserQuery.AdminAccount,  
43 - AdminUserId: getAdminUserQuery.Id,  
44 - })  
45 - if err != nil {  
46 - return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())  
47 - }  
48 - return adminuser, nil  
49 -}  
50 -  
51 -func (adminUserSrv AdminUserService) SaveAdminUser(saveUserCmd *command.SaveAdminUserCommand) (*domain.AdminUser, error) {  
52 - if err := saveUserCmd.ValidateCommand(); err != nil {  
53 - return nil, lib.ThrowError(lib.ARG_ERROR, err.Error())  
54 - }  
55 - //实际业务  
56 - transactionContext, err := factory.CreateTransactionContext(nil)  
57 - if err != nil {  
58 - return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())  
59 - }  
60 - if err := transactionContext.StartTransaction(); err != nil {  
61 - return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())  
62 - }  
63 - defer func() {  
64 - transactionContext.RollbackTransaction()  
65 - }()  
66 - var (  
67 - adminuserRepository domain.AdminUserRepository  
68 - adminuser *domain.AdminUser  
69 - )  
70 - if value, err := factory.CreateAdminUserRepository(map[string]interface{}{  
71 - "transactionContext": transactionContext,  
72 - }); err != nil {  
73 - return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())  
74 - } else {  
75 - adminuserRepository = value  
76 - }  
77 -  
78 - //获取权限  
79 - var (  
80 - permissionRepository domain.AdminPermissionRepository  
81 - permissions []domain.AdminPermission  
82 - )  
83 - if value, err := factory.CreateAdminPermissionRepository(map[string]interface{}{  
84 - "transactionContext": transactionContext,  
85 - }); err != nil {  
86 - return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())  
87 - } else {  
88 - permissionRepository = value  
89 - }  
90 - permissions, err = permissionRepository.Find(domain.AdminPermissionFindQuery{  
91 - IdsIn: saveUserCmd.PermissionId,  
92 - })  
93 - if err != nil {  
94 - return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())  
95 - }  
96 - for i := range permissions {  
97 - if permissions[i].Code == domain.PERMINSSION_ADMIN_USER {  
98 - return nil, lib.ThrowError(lib.BUSINESS_ERROR, "操作异常")  
99 - }  
100 - }  
101 - permissionBases := []domain.AdminPermissionBase{}  
102 -  
103 - for i := range permissions {  
104 - p := domain.AdminPermissionBase{  
105 - Id: permissions[i].Id, Code: permissions[i].Code,  
106 - }  
107 - permissionBases = append(permissionBases, p)  
108 - }  
109 - //账号是否有变更  
110 - var accountChange bool  
111 - if saveUserCmd.Id > 0 {  
112 - //更新数据  
113 - adminuser, err = adminuserRepository.FindOne(domain.AdminUserFindOneQuery{  
114 - AdminUserId: saveUserCmd.Id,  
115 - })  
116 - if err != nil {  
117 - return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())  
118 - }  
119 - if adminuser.Account != saveUserCmd.Account {  
120 - accountChange = true  
121 - }  
122 - adminuser.Account = saveUserCmd.Account  
123 - adminuser.AdminName = saveUserCmd.Name  
124 - adminuser.IsUsable = saveUserCmd.IsUsable  
125 - if !adminuser.IsDefault {  
126 - adminuser.Permission = permissionBases  
127 - }  
128 -  
129 - } else {  
130 - //添加新数据  
131 - accountChange = true  
132 - defaultPwd := fmt.Sprintf("%x", sha1.Sum([]byte("123456")))  
133 - adminuser = &domain.AdminUser{  
134 - Id: saveUserCmd.Id,  
135 - Account: saveUserCmd.Account,  
136 - Password: defaultPwd,  
137 - AdminName: saveUserCmd.Name,  
138 - IsUsable: saveUserCmd.IsUsable,  
139 - Permission: permissionBases,  
140 - }  
141 - }  
142 - if accountChange {  
143 - //检查账号是否已存在  
144 - var (  
145 - adminuserDao *dao.AdminUserDao  
146 - )  
147 - if v, err := factory.CreateAdminUserkDao(map[string]interface{}{  
148 - "transactionContext": transactionContext,  
149 - }); err != nil {  
150 - return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())  
151 - } else {  
152 - adminuserDao = v  
153 - }  
154 - ok, err := adminuserDao.AdminUserAccountExist(saveUserCmd.Account)  
155 - if err != nil {  
156 - return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())  
157 - }  
158 - if ok {  
159 - return nil, lib.ThrowError(lib.BUSINESS_ERROR, "账号已存在")  
160 - }  
161 - }  
162 -  
163 - adminuser, err = adminuserRepository.Save(*adminuser)  
164 - if err != nil {  
165 - return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())  
166 - }  
167 - transactionContext.CommitTransaction()  
168 - return adminuser, nil  
169 -}  
170 -  
171 -func (adminUserSrv AdminUserService) PageListAdminUser(listAdminUserQuery *query.ListAdminUserQuery) ([]domain.AdminUser, int, error) {  
172 - transactionContext, err := factory.CreateTransactionContext(nil)  
173 - if err != nil {  
174 - return nil, 0, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())  
175 - }  
176 - var (  
177 - adminuserRepository domain.AdminUserRepository  
178 - adminusers []domain.AdminUser  
179 - cnt int  
180 - )  
181 - if value, err := factory.CreateAdminUserRepository(map[string]interface{}{  
182 - "transactionContext": transactionContext,  
183 - }); err != nil {  
184 - return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())  
185 - } else {  
186 - adminuserRepository = value  
187 - }  
188 - adminusers, err = adminuserRepository.Find(domain.AdminUserFindQuery{  
189 - AccountLike: listAdminUserQuery.AdminAccountMatch,  
190 - Offset: listAdminUserQuery.Offset,  
191 - Limit: listAdminUserQuery.Limit,  
192 - })  
193 - if err != nil {  
194 - return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())  
195 - }  
196 - cnt, err = adminuserRepository.CountAll(domain.AdminUserFindQuery{  
197 - AccountLike: listAdminUserQuery.AdminAccountMatch,  
198 - })  
199 - if err != nil {  
200 - return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())  
201 - }  
202 - return adminusers, cnt, nil  
203 -}  
204 -  
205 -func (adminUserSrv AdminUserService) UpdateAdminPassword(updatecmd command.UpdateAdminUserPwdCommand) error {  
206 - if err := updatecmd.ValidateCommand(); err != nil {  
207 - return lib.ThrowError(lib.ARG_ERROR, err.Error())  
208 - }  
209 - transactionContext, err := factory.CreateTransactionContext(nil)  
210 - if err != nil {  
211 - return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())  
212 - }  
213 - if err := transactionContext.StartTransaction(); err != nil {  
214 - return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())  
215 - }  
216 - defer func() {  
217 - transactionContext.RollbackTransaction()  
218 - }()  
219 -  
220 - var (  
221 - adminuserDao *dao.AdminUserDao  
222 - )  
223 - if v, err := factory.CreateAdminUserkDao(map[string]interface{}{  
224 - "transactionContext": transactionContext,  
225 - }); err != nil {  
226 - return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())  
227 - } else {  
228 - adminuserDao = v  
229 - }  
230 - err = adminuserDao.UpdatePassword(updatecmd.Id, updatecmd.Password)  
231 - if err != nil {  
232 - return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())  
233 - }  
234 - transactionContext.CommitTransaction()  
235 - return nil  
236 -}  
237 -  
238 -func (adminUserSrv AdminUserService) UpdateAdminIsUsable(uid int64, isUsable bool) error {  
239 - transactionContext, err := factory.CreateTransactionContext(nil)  
240 - if err != nil {  
241 - return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())  
242 - }  
243 - if err := transactionContext.StartTransaction(); err != nil {  
244 - return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())  
245 - }  
246 - defer func() {  
247 - transactionContext.RollbackTransaction()  
248 - }()  
249 - var (  
250 - adminuserDao *dao.AdminUserDao  
251 - )  
252 - if v, err := factory.CreateAdminUserkDao(map[string]interface{}{  
253 - "transactionContext": transactionContext,  
254 - }); err != nil {  
255 - return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())  
256 - } else {  
257 - adminuserDao = v  
258 - }  
259 - if ok, err := adminuserDao.AdminUserIsDefault(uid); err != nil {  
260 - return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())  
261 - } else if ok {  
262 - return lib.ThrowError(lib.BUSINESS_ERROR, "请勿禁用超级管理员")  
263 - }  
264 - err = adminuserDao.UpdateIsUsable(uid, isUsable)  
265 - if err != nil {  
266 - return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())  
267 - }  
268 - transactionContext.CommitTransaction()  
269 - return nil  
270 -}  
  1 +package command
  2 +
  3 +type UpdateBusinessBonusCommand struct {
  4 + Id int64 `json:"id"`
  5 + Bonus float64 `json:"bonus"`
  6 + BonusStatus int8 `json:"bonusStatus"`
  7 + CompanyId int64 `json:"companyId"`
  8 +}
  9 +
  10 +func (cmd UpdateBusinessBonusCommand) ValidateCommand() error {
  11 + return nil
  12 +}
  1 +package query
  2 +
  3 +type GetBusinessBonusQuery struct {
  4 + Id int64 `json:"id"`
  5 + CompanyId int64 `json:"companyId"`
  6 +}
  1 +package query
  2 +
  3 +type ListBusinessBonusQuery struct {
  4 +
  5 + //用户名称匹配
  6 + PartnerNameMatch string `json:"userNameMatch" `
  7 + // 查询偏离量
  8 + Offset int `json:"offset" `
  9 + // 查询限制
  10 + Limit int `json:"limit"`
  11 + PartnerId int64 `json:"partnerId"`
  12 + CompanyId int64 `json:"companyId"`
  13 +}
  1 +package service
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/businessBonus/command"
  7 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/businessBonus/query"
  8 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory"
  9 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
  10 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/dao"
  11 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
  12 +)
  13 +
  14 +type BusinessBonusService struct {
  15 +}
  16 +
  17 +func NewBusinessBonusService(option map[string]interface{}) *BusinessBonusService {
  18 + newService := new(BusinessBonusService)
  19 + return newService
  20 +}
  21 +
  22 +// ListBusinessBonus 列表
  23 +func (srv BusinessBonusService) ListBusinessBonus(queryOption query.ListBusinessBonusQuery) (int, interface{}, error) {
  24 + var (
  25 + transactionContext, _ = factory.CreateTransactionContext(nil)
  26 + err error
  27 + )
  28 + if err = transactionContext.StartTransaction(); err != nil {
  29 + return 0, nil, err
  30 + }
  31 + defer func() {
  32 + transactionContext.RollbackTransaction()
  33 + }()
  34 +
  35 + var (
  36 + bonusDaoao *dao.BusinessBonusDao
  37 + )
  38 + if bonusDaoao, err = factory.CreateBusinessBonusDao(map[string]interface{}{
  39 + "transactionContext": transactionContext,
  40 + }); err != nil {
  41 + return 0, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
  42 + }
  43 + result, err := bonusDaoao.SearchBusinessBonus(queryOption.PartnerId, queryOption.PartnerNameMatch,
  44 + queryOption.CompanyId, queryOption.Limit, queryOption.Offset)
  45 + if err != nil {
  46 + return 0, nil, err
  47 + }
  48 + cnt, err := bonusDaoao.CountBusinessBonus(queryOption.PartnerId, queryOption.PartnerNameMatch,
  49 + queryOption.CompanyId, queryOption.Limit, queryOption.Offset)
  50 + if err != nil {
  51 + return 0, nil, err
  52 + }
  53 + err = transactionContext.CommitTransaction()
  54 +
  55 + returnData := []map[string]interface{}{}
  56 + for _, v := range result {
  57 + m := map[string]interface{}{
  58 + "id": v.Id,
  59 + "uncollectedDividends": v.BonusNot,
  60 + "receiveDividends": v.BonusHas,
  61 + "dividendsReceivable": v.Bonus,
  62 + "stateOfPayment": v.BonusStatus,
  63 + "stateOfPaymentName": domain.DescribeBusinessBonusStatus(v.BonusStatus),
  64 + "partner": v.PartnerName,
  65 + "updateTime": "",
  66 + }
  67 + if !v.UpdateAt.IsZero() {
  68 + m["updateTime"] = v.UpdateAt.Local().Format("2006-01-02 15:04:05")
  69 + }
  70 + returnData = append(returnData, m)
  71 + }
  72 + return cnt, returnData, nil
  73 +}
  74 +
  75 +func (srv BusinessBonusService) UpdateBusinessBonus(cmd command.UpdateBusinessBonusCommand) error {
  76 + var (
  77 + transactionContext, _ = factory.CreateTransactionContext(nil)
  78 + err error
  79 + )
  80 + if err = transactionContext.StartTransaction(); err != nil {
  81 + return err
  82 + }
  83 + defer func() {
  84 + transactionContext.RollbackTransaction()
  85 + }()
  86 + var (
  87 + bonusRespository domain.BusinessBonusRepository
  88 + bonusData *domain.BusinessBonus
  89 + )
  90 + if bonusRespository, err = factory.CreateBusinessBonusRepository(map[string]interface{}{
  91 + "transactionContext": transactionContext,
  92 + }); err != nil {
  93 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  94 + }
  95 + bonusData, err = bonusRespository.FindOne(domain.BusinessBonusFindOneQuery{
  96 + Id: cmd.Id, CompanyId: cmd.CompanyId,
  97 + })
  98 + if err != nil {
  99 + e := fmt.Sprintf("获取业务分红(id=%d;company_id=%d)数据失败:%s", cmd.Id, cmd.CompanyId, err)
  100 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
  101 + }
  102 + bonusData.Bonus = cmd.Bonus
  103 + switch cmd.BonusStatus {
  104 + case domain.BUSINESS_BONUS_HAS_PAY:
  105 + bonusData.BusinessBonusPayStatus.PayPartnerBonus(bonusData)
  106 + case domain.BUSINESS_BONUS_WAIT_PAY:
  107 + bonusData.BusinessBonusPayStatus.WartPayPartnerBonus(bonusData)
  108 + case domain.BUSINESS_BONUS_NULL_PAY:
  109 + bonusData.BusinessBonusPayStatus.NullPayPartnerBonus(bonusData)
  110 + default:
  111 + return lib.ThrowError(lib.BUSINESS_ERROR, "支付状态错误")
  112 + }
  113 + err = bonusRespository.Edit(bonusData)
  114 + if err != nil {
  115 + e := fmt.Sprintf("更新业务分红(id=%d)数据失败:%s", bonusData.Id, err)
  116 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
  117 + }
  118 + err = transactionContext.CommitTransaction()
  119 + return nil
  120 +}
  121 +
  122 +//GetBusinessBonus 获取详情
  123 +func (srv BusinessBonusService) GetBusinessBonus(queryOption query.GetBusinessBonusQuery) (map[string]interface{}, error) {
  124 +
  125 + var (
  126 + transactionContext, _ = factory.CreateTransactionContext(nil)
  127 + err error
  128 + )
  129 + if err = transactionContext.StartTransaction(); err != nil {
  130 + return nil, err
  131 + }
  132 + defer func() {
  133 + transactionContext.RollbackTransaction()
  134 + }()
  135 + var (
  136 + bonusRespository domain.BusinessBonusRepository
  137 + partnerInfoRepository domain.PartnerInfoRepository
  138 + bonusData *domain.BusinessBonus
  139 + partnerData *domain.PartnerInfo
  140 + )
  141 + if bonusRespository, err = factory.CreateBusinessBonusRepository(map[string]interface{}{
  142 + "transactionContext": transactionContext,
  143 + }); err != nil {
  144 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  145 + }
  146 + bonusData, err = bonusRespository.FindOne(domain.BusinessBonusFindOneQuery{
  147 + Id: queryOption.Id, CompanyId: queryOption.CompanyId,
  148 + })
  149 + if err != nil {
  150 + e := fmt.Sprintf("获取业务分红(id=%d;company_id=%d)数据失败:%s", queryOption.Id, queryOption.CompanyId, err)
  151 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
  152 + }
  153 + if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
  154 + "transactionContext": transactionContext,
  155 + }); err != nil {
  156 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  157 + }
  158 + partnerData, err = partnerInfoRepository.FindOne(domain.PartnerFindOneQuery{UserId: bonusData.PartnerInfoId})
  159 + if err != nil {
  160 + e := fmt.Sprintf("获取合伙人(id=%d)数据失败:%s", bonusData.PartnerInfoId, err)
  161 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
  162 + }
  163 + err = transactionContext.CommitTransaction()
  164 + returnData := map[string]interface{}{
  165 + "partner": partnerData.Partner.PartnerName,
  166 + "dividendsReceivable": bonusData.Bonus,
  167 + "receiveDividends": bonusData.BonusHas,
  168 + "uncollectedDividends": bonusData.BonusNot,
  169 + "updateTime": "",
  170 + "stateOfPayment": bonusData.BonusStatus,
  171 + "stateOfPaymentName": domain.DescribeBusinessBonusStatus(bonusData.BonusStatus),
  172 + "id": bonusData.Id,
  173 + }
  174 + if !bonusData.UpdateAt.IsZero() {
  175 + returnData["updateTime"] = bonusData.UpdateAt.Local().Format("2006-01-02 15:04:05")
  176 + }
  177 +
  178 + return returnData, nil
  179 +}
  1 +package service
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory"
  7 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
  8 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
  9 +)
  10 +
  11 +type CompanyService struct{}
  12 +
  13 +func NewCompanyService(options map[string]interface{}) *CompanyService {
  14 + newCompanyService := &CompanyService{}
  15 + return newCompanyService
  16 +}
  17 +
  18 +//AllowCompany 公司启用合伙人功能
  19 +func (service CompanyService) AllowCompany(companyId int64) error {
  20 + var (
  21 + transactionContext, _ = factory.CreateTransactionContext(nil)
  22 + err error
  23 + )
  24 + if err = transactionContext.StartTransaction(); err != nil {
  25 + return err
  26 + }
  27 + defer func() {
  28 + transactionContext.RollbackTransaction()
  29 + }()
  30 + var (
  31 + companyRespository domain.CompanyRepository
  32 + oldCompanyData domain.Company
  33 + )
  34 + if companyRespository, err = factory.CreateCompanyRepository(map[string]interface{}{
  35 + "transactionContext": transactionContext,
  36 + }); err != nil {
  37 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  38 + }
  39 + oldCompanyData, err = companyRespository.FindOne(domain.CompanyFindOneOptions{
  40 + Id: companyId,
  41 + })
  42 + if err != nil {
  43 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("获取公司(id=%d)的数据失败:%s", companyId, err.Error()))
  44 + }
  45 + err = oldCompanyData.Update(map[string]interface{}{
  46 + "Enable": domain.CompanyEnableYes,
  47 + })
  48 + if err != nil {
  49 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  50 + }
  51 + //更新公司数据
  52 + err = companyRespository.Edit(&oldCompanyData)
  53 + if err != nil {
  54 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("更新公司(id=%d)的数据失败:%s", companyId, err.Error()))
  55 + }
  56 + err = transactionContext.CommitTransaction()
  57 + return nil
  58 +}
  59 +
  60 +//ForbidCompany 公司禁用合伙人功能
  61 +func (service CompanyService) ForbidCompany(companyId int64) error {
  62 + var (
  63 + transactionContext, _ = factory.CreateTransactionContext(nil)
  64 + err error
  65 + )
  66 + if err = transactionContext.StartTransaction(); err != nil {
  67 + return err
  68 + }
  69 + defer func() {
  70 + transactionContext.RollbackTransaction()
  71 + }()
  72 + var (
  73 + companyRespository domain.CompanyRepository
  74 + oldCompanyData domain.Company
  75 + )
  76 + if companyRespository, err = factory.CreateCompanyRepository(map[string]interface{}{
  77 + "transactionContext": transactionContext,
  78 + }); err != nil {
  79 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  80 + }
  81 + oldCompanyData, err = companyRespository.FindOne(domain.CompanyFindOneOptions{
  82 + Id: companyId,
  83 + })
  84 + if err != nil {
  85 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("获取公司(id=%d)的数据失败:%s", companyId, err.Error()))
  86 + }
  87 + err = oldCompanyData.Update(map[string]interface{}{
  88 + "Enable": domain.CompanyEnableNo,
  89 + })
  90 + if err != nil {
  91 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  92 + }
  93 + //更新公司数据
  94 + err = companyRespository.Edit(&oldCompanyData)
  95 + if err != nil {
  96 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("更新公司(id=%d)的数据失败:%s", companyId, err.Error()))
  97 + }
  98 + err = transactionContext.CommitTransaction()
  99 + return nil
  100 +}
  101 +
  102 +//GetCompanyData 获取公司数据
  103 +func (service CompanyService) GetCompanyData(companyId int64) (*domain.Company, error) {
  104 + var (
  105 + transactionContext, _ = factory.CreateTransactionContext(nil)
  106 + err error
  107 + )
  108 + if err = transactionContext.StartTransaction(); err != nil {
  109 + return nil, err
  110 + }
  111 + defer func() {
  112 + transactionContext.RollbackTransaction()
  113 + }()
  114 + var (
  115 + companyRespository domain.CompanyRepository
  116 + companyData domain.Company
  117 + )
  118 + if companyRespository, err = factory.CreateCompanyRepository(map[string]interface{}{
  119 + "transactionContext": transactionContext,
  120 + }); err != nil {
  121 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  122 + }
  123 + companyData, err = companyRespository.FindOne(domain.CompanyFindOneOptions{
  124 + Id: companyId,
  125 + })
  126 + if err != nil {
  127 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("获取公司(id=%d)的数据失败:%s", companyId, err.Error()))
  128 + }
  129 + err = transactionContext.CommitTransaction()
  130 + return &companyData, nil
  131 +}
  132 +
  133 +func (service CompanyService) UpdateCompanyPhone(companyId int64, phone string) error {
  134 + var (
  135 + transactionContext, _ = factory.CreateTransactionContext(nil)
  136 + err error
  137 + )
  138 + if err = transactionContext.StartTransaction(); err != nil {
  139 + return err
  140 + }
  141 + defer func() {
  142 + transactionContext.RollbackTransaction()
  143 + }()
  144 + var (
  145 + companyRespository domain.CompanyRepository
  146 + companyData domain.Company
  147 + )
  148 + if companyRespository, err = factory.CreateCompanyRepository(map[string]interface{}{
  149 + "transactionContext": transactionContext,
  150 + }); err != nil {
  151 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  152 + }
  153 + companyData, err = companyRespository.FindOne(domain.CompanyFindOneOptions{
  154 + Id: companyId,
  155 + })
  156 + if err != nil {
  157 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("获取公司(id=%d)的数据失败:%s", companyId, err.Error()))
  158 + }
  159 + companyData.Phone = phone
  160 + err = companyRespository.Edit(&companyData)
  161 + if err != nil {
  162 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("更新公司(id=%d)的数据失败:%s", companyId, err.Error()))
  163 + }
  164 + err = transactionContext.CommitTransaction()
  165 + return nil
  166 +}
@@ -5,26 +5,34 @@ import ( @@ -5,26 +5,34 @@ import (
5 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction" 5 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
6 ) 6 )
7 7
8 -func CreateAdminUserkDao(options map[string]interface{}) (*dao.AdminUserDao, error) { 8 +func CreatePartnerInfoDao(options map[string]interface{}) (*dao.PartnerInfoDao, error) {
9 var transactionContext *transaction.TransactionContext 9 var transactionContext *transaction.TransactionContext
10 if value, ok := options["transactionContext"]; ok { 10 if value, ok := options["transactionContext"]; ok {
11 transactionContext = value.(*transaction.TransactionContext) 11 transactionContext = value.(*transaction.TransactionContext)
12 } 12 }
13 - return dao.NewAdminUserDao(transactionContext) 13 + return dao.NewPartnerInfoDao(transactionContext)
14 } 14 }
15 15
16 -func CreatePartnerInfoDao(options map[string]interface{}) (*dao.PartnerInfoDao, error) { 16 +func CreateOrderBaseDao(options map[string]interface{}) (*dao.OrderBaseDao, error) {
17 var transactionContext *transaction.TransactionContext 17 var transactionContext *transaction.TransactionContext
18 if value, ok := options["transactionContext"]; ok { 18 if value, ok := options["transactionContext"]; ok {
19 transactionContext = value.(*transaction.TransactionContext) 19 transactionContext = value.(*transaction.TransactionContext)
20 } 20 }
21 - return dao.NewPartnerInfoDao(transactionContext) 21 + return dao.NewOrderBaseDao(transactionContext)
22 } 22 }
23 23
24 -func CreateOrderBaseDao(options map[string]interface{}) (*dao.OrderBaseDao, error) { 24 +func CreateUsersDao(options map[string]interface{}) (*dao.UsersDao, error) {
25 var transactionContext *transaction.TransactionContext 25 var transactionContext *transaction.TransactionContext
26 if value, ok := options["transactionContext"]; ok { 26 if value, ok := options["transactionContext"]; ok {
27 transactionContext = value.(*transaction.TransactionContext) 27 transactionContext = value.(*transaction.TransactionContext)
28 } 28 }
29 - return dao.NewOrderBaseDao(transactionContext) 29 + return dao.NewUsersDao(transactionContext)
  30 +}
  31 +
  32 +func CreateBusinessBonusDao(options map[string]interface{}) (*dao.BusinessBonusDao, error) {
  33 + var transactionContext *transaction.TransactionContext
  34 + if value, ok := options["transactionContext"]; ok {
  35 + transactionContext = value.(*transaction.TransactionContext)
  36 + }
  37 + return dao.NewBusinessBonusDao(transactionContext)
30 } 38 }
  1 +package factory
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain/service"
  5 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/domainService"
  6 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
  7 +)
  8 +
  9 +func CreateBusinessBonusService(options map[string]interface{}) (service.BusinessBonusService, error) {
  10 + var transactionContext *transaction.TransactionContext
  11 + if value, ok := options["transactionContext"]; ok {
  12 + transactionContext = value.(*transaction.TransactionContext)
  13 + }
  14 + return domainService.NewBusinessBonusService(transactionContext), nil
  15 +}
@@ -15,15 +15,6 @@ func CreatePartnerInfoRepository(options map[string]interface{}) (domain.Partner @@ -15,15 +15,6 @@ func CreatePartnerInfoRepository(options map[string]interface{}) (domain.Partner
15 return repository.NewPartnerInfoRepository(transactionContext) 15 return repository.NewPartnerInfoRepository(transactionContext)
16 } 16 }
17 17
18 -//CreateAdminUserRepository 管理员信息  
19 -func CreateAdminUserRepository(options map[string]interface{}) (domain.AdminUserRepository, error) {  
20 - var transactionContext *transaction.TransactionContext  
21 - if value, ok := options["transactionContext"]; ok {  
22 - transactionContext = value.(*transaction.TransactionContext)  
23 - }  
24 - return repository.NewAdminUserRepository(transactionContext)  
25 -}  
26 -  
27 //CreateAdminUserRepository 管理员权限信息 18 //CreateAdminUserRepository 管理员权限信息
28 func CreateAdminPermissionRepository(options map[string]interface{}) (domain.AdminPermissionRepository, error) { 19 func CreateAdminPermissionRepository(options map[string]interface{}) (domain.AdminPermissionRepository, error) {
29 var transactionContext *transaction.TransactionContext 20 var transactionContext *transaction.TransactionContext
@@ -50,3 +41,39 @@ func CreateOrderGoodRepository(options map[string]interface{}) (domain.OrderGood @@ -50,3 +41,39 @@ func CreateOrderGoodRepository(options map[string]interface{}) (domain.OrderGood
50 } 41 }
51 return repository.NewOrderGoodRepository(transactionContext) 42 return repository.NewOrderGoodRepository(transactionContext)
52 } 43 }
  44 +
  45 +//CreateOrderGoodRepository 订单信息
  46 +func CreateUsersRepository(options map[string]interface{}) (domain.UsersRepository, error) {
  47 + var transactionContext *transaction.TransactionContext
  48 + if value, ok := options["transactionContext"]; ok {
  49 + transactionContext = value.(*transaction.TransactionContext)
  50 + }
  51 + return repository.NewUsersRepository(transactionContext)
  52 +}
  53 +
  54 +// CreateUsersRepository 公司企业信息
  55 +func CreateCompanyRepository(options map[string]interface{}) (domain.CompanyRepository, error) {
  56 + var transactionContext *transaction.TransactionContext
  57 + if value, ok := options["transactionContext"]; ok {
  58 + transactionContext = value.(*transaction.TransactionContext)
  59 + }
  60 + return repository.NewCompanyRepository(transactionContext)
  61 +}
  62 +
  63 +// CreatePartnerCategoryRepository 合伙人分类数据
  64 +func CreatePartnerCategoryRepository(options map[string]interface{}) (domain.PartnerCategoryRepository, error) {
  65 + var transactionContext *transaction.TransactionContext
  66 + if value, ok := options["transactionContext"]; ok {
  67 + transactionContext = value.(*transaction.TransactionContext)
  68 + }
  69 + return repository.NewPartnerCategoryRepository(transactionContext)
  70 +}
  71 +
  72 +// CreateBusinessBonusRepository 业务分红
  73 +func CreateBusinessBonusRepository(options map[string]interface{}) (domain.BusinessBonusRepository, error) {
  74 + var transactionContext *transaction.TransactionContext
  75 + if value, ok := options["transactionContext"]; ok {
  76 + transactionContext = value.(*transaction.TransactionContext)
  77 + }
  78 + return repository.NewBusinessBonusRepository(transactionContext)
  79 +}
@@ -16,5 +16,6 @@ type CreateOrderCommand struct { @@ -16,5 +16,6 @@ type CreateOrderCommand struct {
16 //业务员抽成比例 16 //业务员抽成比例
17 SalesmanBonusPercent float64 `json:"salesmanBonusPercent"` 17 SalesmanBonusPercent float64 `json:"salesmanBonusPercent"`
18 //货品 18 //货品
19 - Goods []OrderGoodData `json:"goods"` 19 + Goods []OrderGoodData `json:"goods"`
  20 + CompanyId int64 `json:"companyId"`
20 } 21 }
@@ -5,4 +5,5 @@ type DisableOrderCommand struct { @@ -5,4 +5,5 @@ type DisableOrderCommand struct {
5 OrderId int64 `json:"orderId"` 5 OrderId int64 `json:"orderId"`
6 IsDisable int `json:"isDisable"` 6 IsDisable int `json:"isDisable"`
7 OrderType int `json:"orderType"` 7 OrderType int `json:"orderType"`
  8 + CompanyId int64 `json:"companyId"`
8 } 9 }
@@ -7,4 +7,5 @@ type OrderDeliveryCommand struct { @@ -7,4 +7,5 @@ type OrderDeliveryCommand struct {
7 DeliveryTime time.Time `json:"deliveryTime"` 7 DeliveryTime time.Time `json:"deliveryTime"`
8 DeliveryCode string `json:"deliveryCode"` 8 DeliveryCode string `json:"deliveryCode"`
9 Goods []OrderGoodData `json:"goods"` 9 Goods []OrderGoodData `json:"goods"`
  10 + CompanyId int64
10 } 11 }
@@ -4,6 +4,7 @@ package command @@ -4,6 +4,7 @@ package command
4 type UpdateGoodBouns struct { 4 type UpdateGoodBouns struct {
5 Id int64 `json:"id"` //订单id 5 Id int64 `json:"id"` //订单id
6 GoodBouns []GoodBouns `json:"goodBouns"` 6 GoodBouns []GoodBouns `json:"goodBouns"`
  7 + CompanyId int64 `json:"companyId"`
7 } 8 }
8 9
9 //GoodBoun 商品数量调整 10 //GoodBoun 商品数量调整
@@ -18,5 +18,6 @@ type UpdateOrderCommand struct { @@ -18,5 +18,6 @@ type UpdateOrderCommand struct {
18 //订单类型 18 //订单类型
19 OrderType int `json:"orderType"` 19 OrderType int `json:"orderType"`
20 //货品 20 //货品
21 - Goods []OrderGoodData `json:"goods"` 21 + Goods []OrderGoodData `json:"goods"`
  22 + CompanyId int64 `json:"companyId"`
22 } 23 }
@@ -2,5 +2,6 @@ package query @@ -2,5 +2,6 @@ package query
2 2
3 //GetOrderQuery 获取订单详情 3 //GetOrderQuery 获取订单详情
4 type GetOrderQuery struct { 4 type GetOrderQuery struct {
5 - OrderId int64 `json:"orderId"` 5 + OrderId int64 `json:"orderId"`
  6 + CompanyId int64 `json:"companyId"`
6 } 7 }
@@ -14,4 +14,5 @@ type ListOrderBaseQuery struct { @@ -14,4 +14,5 @@ type ListOrderBaseQuery struct {
14 OrderType int `json:"orderType"` 14 OrderType int `json:"orderType"`
15 //发货单号 15 //发货单号
16 DeliveryCode string `json:"deliveryCode"` 16 DeliveryCode string `json:"deliveryCode"`
  17 + CompanyId int64 `json:"companyId"`
17 } 18 }
@@ -4,6 +4,8 @@ import ( @@ -4,6 +4,8 @@ import (
4 "fmt" 4 "fmt"
5 "time" 5 "time"
6 6
  7 + "github.com/astaxie/beego/logs"
  8 +
7 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory" 9 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory"
8 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/orderinfo/command" 10 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/orderinfo/command"
9 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/orderinfo/query" 11 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/orderinfo/query"
@@ -27,11 +29,18 @@ func (service OrderInfoService) PageListOrderBase(listOrderQuery query.ListOrder @@ -27,11 +29,18 @@ func (service OrderInfoService) PageListOrderBase(listOrderQuery query.ListOrder
27 if err != nil { 29 if err != nil {
28 return nil, 0, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) 30 return nil, 0, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
29 } 31 }
  32 + if err = transactionContext.StartTransaction(); err != nil {
  33 + return nil, 0, err
  34 + }
  35 + defer func() {
  36 + transactionContext.RollbackTransaction()
  37 + }()
30 var ( 38 var (
31 orderRepository domain.OrderBaseRepository 39 orderRepository domain.OrderBaseRepository
32 orders []domain.OrderBase 40 orders []domain.OrderBase
33 cnt int 41 cnt int
34 ) 42 )
  43 +
35 if value, err := factory.CreateOrderBaseRepository(map[string]interface{}{ 44 if value, err := factory.CreateOrderBaseRepository(map[string]interface{}{
36 "transactionContext": transactionContext, 45 "transactionContext": transactionContext,
37 }); err != nil { 46 }); err != nil {
@@ -46,6 +55,7 @@ func (service OrderInfoService) PageListOrderBase(listOrderQuery query.ListOrder @@ -46,6 +55,7 @@ func (service OrderInfoService) PageListOrderBase(listOrderQuery query.ListOrder
46 Limit: listOrderQuery.Limit, 55 Limit: listOrderQuery.Limit,
47 OrderType: listOrderQuery.OrderType, 56 OrderType: listOrderQuery.OrderType,
48 DeliveryCode: listOrderQuery.DeliveryCode, 57 DeliveryCode: listOrderQuery.DeliveryCode,
  58 + CompanyId: listOrderQuery.CompanyId,
49 } 59 }
50 orders, cnt, err = orderRepository.Find(query) 60 orders, cnt, err = orderRepository.Find(query)
51 if err != nil { 61 if err != nil {
@@ -58,15 +68,17 @@ func (service OrderInfoService) PageListOrderBase(listOrderQuery query.ListOrder @@ -58,15 +68,17 @@ func (service OrderInfoService) PageListOrderBase(listOrderQuery query.ListOrder
58 return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 68 return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
59 } 69 }
60 for i := range orders { 70 for i := range orders {
61 - var partnerData *domain.PartnerInfo 71 + partnerData := &domain.PartnerInfo{}
62 partnerData, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{ 72 partnerData, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{
63 UserId: orders[i].PartnerId, 73 UserId: orders[i].PartnerId,
64 }) 74 })
65 if err != nil { 75 if err != nil {
66 - return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 76 + logs.Error("获取合伙(id=%d)失败%s", orders[i].PartnerId, err)
  77 + } else {
  78 + orders[i].PartnerInfo = partnerData.Partner
67 } 79 }
68 - orders[i].PartnerInfo = partnerData.Partner  
69 } 80 }
  81 + transactionContext.CommitTransaction()
70 return orders, cnt, nil 82 return orders, cnt, nil
71 } 83 }
72 84
@@ -79,7 +91,7 @@ func (service OrderInfoService) GetOrderDetail(getOrderQuery query.GetOrderQuery @@ -79,7 +91,7 @@ func (service OrderInfoService) GetOrderDetail(getOrderQuery query.GetOrderQuery
79 } 91 }
80 var ( 92 var (
81 orderBaseRepository domain.OrderBaseRepository 93 orderBaseRepository domain.OrderBaseRepository
82 - PartnerInfoRepository domain.PartnerInfoRepository 94 + partnerInfoRepository domain.PartnerInfoRepository
83 orderGoodRepository domain.OrderGoodRepository 95 orderGoodRepository domain.OrderGoodRepository
84 order *domain.OrderBase 96 order *domain.OrderBase
85 ) 97 )
@@ -89,14 +101,12 @@ func (service OrderInfoService) GetOrderDetail(getOrderQuery query.GetOrderQuery @@ -89,14 +101,12 @@ func (service OrderInfoService) GetOrderDetail(getOrderQuery query.GetOrderQuery
89 defer func() { 101 defer func() {
90 transactionContext.RollbackTransaction() 102 transactionContext.RollbackTransaction()
91 }() 103 }()
92 - if value, err := factory.CreateOrderBaseRepository(map[string]interface{}{ 104 + if orderBaseRepository, err = factory.CreateOrderBaseRepository(map[string]interface{}{
93 "transactionContext": transactionContext, 105 "transactionContext": transactionContext,
94 }); err != nil { 106 }); err != nil {
95 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 107 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
96 - } else {  
97 - orderBaseRepository = value  
98 } 108 }
99 - if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{ 109 + if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
100 "transactionContext": transactionContext, 110 "transactionContext": transactionContext,
101 }); err != nil { 111 }); err != nil {
102 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 112 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
@@ -107,7 +117,8 @@ func (service OrderInfoService) GetOrderDetail(getOrderQuery query.GetOrderQuery @@ -107,7 +117,8 @@ func (service OrderInfoService) GetOrderDetail(getOrderQuery query.GetOrderQuery
107 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 117 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
108 } 118 }
109 order, err = orderBaseRepository.FindOne(domain.OrderBaseFindOneQuery{ 119 order, err = orderBaseRepository.FindOne(domain.OrderBaseFindOneQuery{
110 - OrderId: getOrderQuery.OrderId, 120 + OrderId: getOrderQuery.OrderId,
  121 + CompanyId: getOrderQuery.CompanyId,
111 }) 122 })
112 if err != nil { 123 if err != nil {
113 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("获取订单数据失败:%s", err)) 124 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("获取订单数据失败:%s", err))
@@ -117,13 +128,17 @@ func (service OrderInfoService) GetOrderDetail(getOrderQuery query.GetOrderQuery @@ -117,13 +128,17 @@ func (service OrderInfoService) GetOrderDetail(getOrderQuery query.GetOrderQuery
117 goods []domain.OrderGood 128 goods []domain.OrderGood
118 ) 129 )
119 130
120 - partnerData, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{UserId: order.PartnerId}) 131 + partnerData, err = partnerInfoRepository.FindOne(domain.PartnerFindOneQuery{
  132 + UserId: order.PartnerId,
  133 + CompanyId: getOrderQuery.CompanyId,
  134 + })
121 if err != nil { 135 if err != nil {
122 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("检索合伙人数据失败:%s", err)) 136 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("检索合伙人数据失败:%s", err))
123 } 137 }
124 order.PartnerInfo = partnerData.Partner 138 order.PartnerInfo = partnerData.Partner
125 goods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{ 139 goods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{
126 - OrderId: order.Id, 140 + OrderId: order.Id,
  141 + CompanyId: getOrderQuery.CompanyId,
127 }) 142 })
128 if err != nil { 143 if err != nil {
129 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("获取订单中的商品列表失败:%s", err)) 144 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("获取订单中的商品列表失败:%s", err))
@@ -188,7 +203,7 @@ func (service OrderInfoService) CreateNewOrder(cmd command.CreateOrderCommand) ( @@ -188,7 +203,7 @@ func (service OrderInfoService) CreateNewOrder(cmd command.CreateOrderCommand) (
188 // } 203 // }
189 //检查delivery_code是否重复 204 //检查delivery_code是否重复
190 if len(cmd.DeliveryCode) > 0 { 205 if len(cmd.DeliveryCode) > 0 {
191 - if ok, err := orderBaseDao.DeliveryCodeExist(cmd.DeliveryCode); err != nil { 206 + if ok, err := orderBaseDao.DeliveryCodeExist(cmd.DeliveryCode, cmd.CompanyId); err != nil {
192 return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) 207 return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
193 } else if ok { 208 } else if ok {
194 return nil, lib.ThrowError(lib.BUSINESS_ERROR, "发货号已存在") 209 return nil, lib.ThrowError(lib.BUSINESS_ERROR, "发货号已存在")
@@ -197,15 +212,16 @@ func (service OrderInfoService) CreateNewOrder(cmd command.CreateOrderCommand) ( @@ -197,15 +212,16 @@ func (service OrderInfoService) CreateNewOrder(cmd command.CreateOrderCommand) (
197 newOrder := &domain.OrderBase{ 212 newOrder := &domain.OrderBase{
198 OrderType: cmd.OrderType, OrderCode: cmd.OrderCode, 213 OrderType: cmd.OrderType, OrderCode: cmd.OrderCode,
199 DeliveryCode: cmd.DeliveryCode, 214 DeliveryCode: cmd.DeliveryCode,
200 - Buyer: &domain.Buyer{ 215 + Buyer: domain.Buyer{
201 BuyerName: cmd.BuyerName, 216 BuyerName: cmd.BuyerName,
202 }, 217 },
203 - RegionInfo: &domain.RegionInfo{ 218 + RegionInfo: domain.RegionInfo{
204 RegionName: cmd.OrderRegion, 219 RegionName: cmd.OrderRegion,
205 }, 220 },
206 PartnerId: cmd.PartnerId, 221 PartnerId: cmd.PartnerId,
207 PartnerInfo: partnerData.Partner, 222 PartnerInfo: partnerData.Partner,
208 SalesmanBonusPercent: cmd.SalesmanBonusPercent, 223 SalesmanBonusPercent: cmd.SalesmanBonusPercent,
  224 + CompanyId: cmd.CompanyId,
209 } 225 }
210 var orderGoods []domain.OrderGood 226 var orderGoods []domain.OrderGood
211 for _, good := range cmd.Goods { 227 for _, good := range cmd.Goods {
@@ -216,6 +232,7 @@ func (service OrderInfoService) CreateNewOrder(cmd command.CreateOrderCommand) ( @@ -216,6 +232,7 @@ func (service OrderInfoService) CreateNewOrder(cmd command.CreateOrderCommand) (
216 m.Price = good.Price 232 m.Price = good.Price
217 m.PartnerBonusPercent = good.PartnerBonusPercent 233 m.PartnerBonusPercent = good.PartnerBonusPercent
218 m.Remark = good.Remark 234 m.Remark = good.Remark
  235 + m.CompanyId = cmd.CompanyId
219 err = m.Compute() 236 err = m.Compute()
220 if err != nil { 237 if err != nil {
221 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的数值失败:%s", err)) 238 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的数值失败:%s", err))
@@ -251,7 +268,7 @@ func (service OrderInfoService) CreateNewOrder(cmd command.CreateOrderCommand) ( @@ -251,7 +268,7 @@ func (service OrderInfoService) CreateNewOrder(cmd command.CreateOrderCommand) (
251 } 268 }
252 269
253 //DeleteOrder 删除订单 270 //DeleteOrder 删除订单
254 -func (service OrderInfoService) DeleteOrder(orderId int64) error { 271 +func (service OrderInfoService) DeleteOrder(orderId int64, companyId int64) error {
255 var ( 272 var (
256 transactionContext, _ = factory.CreateTransactionContext(nil) 273 transactionContext, _ = factory.CreateTransactionContext(nil)
257 err error 274 err error
@@ -276,11 +293,11 @@ func (service OrderInfoService) DeleteOrder(orderId int64) error { @@ -276,11 +293,11 @@ func (service OrderInfoService) DeleteOrder(orderId int64) error {
276 }); err != nil { 293 }); err != nil {
277 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 294 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
278 } 295 }
279 - err = orderBaseRepository.Remove(orderId) 296 + err = orderBaseRepository.Remove(orderId, companyId)
280 if err != nil { 297 if err != nil {
281 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("删除订单数据失败:%s", err)) 298 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("删除订单数据失败:%s", err))
282 } 299 }
283 - err = orderGoodRepository.Remove(orderId) 300 + err = orderGoodRepository.Remove(orderId, companyId)
284 if err != nil { 301 if err != nil {
285 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("删除订单中商品数据失败:%s", err)) 302 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("删除订单中商品数据失败:%s", err))
286 } 303 }
@@ -312,7 +329,9 @@ func (service OrderInfoService) UpdateOrderData(cmd command.UpdateOrderCommand) @@ -312,7 +329,9 @@ func (service OrderInfoService) UpdateOrderData(cmd command.UpdateOrderCommand)
312 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 329 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
313 } 330 }
314 var partnerData *domain.PartnerInfo 331 var partnerData *domain.PartnerInfo
315 - partnerData, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{UserId: cmd.PartnerId}) 332 + partnerData, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{
  333 + UserId: cmd.PartnerId, CompanyId: cmd.CompanyId,
  334 + })
316 if err != nil { 335 if err != nil {
317 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("检索合伙人数据失败")) 336 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("检索合伙人数据失败"))
318 } 337 }
@@ -337,7 +356,8 @@ func (service OrderInfoService) UpdateOrderData(cmd command.UpdateOrderCommand) @@ -337,7 +356,8 @@ func (service OrderInfoService) UpdateOrderData(cmd command.UpdateOrderCommand)
337 } 356 }
338 //获取旧的订单 357 //获取旧的订单
339 oldOrderData, err = orderBaseRepository.FindOne(domain.OrderBaseFindOneQuery{ 358 oldOrderData, err = orderBaseRepository.FindOne(domain.OrderBaseFindOneQuery{
340 - OrderId: cmd.Id, 359 + OrderId: cmd.Id,
  360 + CompanyId: cmd.CompanyId,
341 }) 361 })
342 if err != nil { 362 if err != nil {
343 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单:%s", err)) 363 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单:%s", err))
@@ -359,7 +379,7 @@ func (service OrderInfoService) UpdateOrderData(cmd command.UpdateOrderCommand) @@ -359,7 +379,7 @@ func (service OrderInfoService) UpdateOrderData(cmd command.UpdateOrderCommand)
359 // } 379 // }
360 //检查delivery_code是否重复 380 //检查delivery_code是否重复
361 if len(cmd.DeliveryCode) > 0 { 381 if len(cmd.DeliveryCode) > 0 {
362 - if ok, err := orderBaseDao.DeliveryCodeExist(cmd.DeliveryCode, cmd.Id); err != nil { 382 + if ok, err := orderBaseDao.DeliveryCodeExist(cmd.DeliveryCode, cmd.CompanyId, cmd.Id); err != nil {
363 return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) 383 return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
364 } else if ok { 384 } else if ok {
365 return nil, lib.ThrowError(lib.BUSINESS_ERROR, "发货号已存在") 385 return nil, lib.ThrowError(lib.BUSINESS_ERROR, "发货号已存在")
@@ -367,7 +387,8 @@ func (service OrderInfoService) UpdateOrderData(cmd command.UpdateOrderCommand) @@ -367,7 +387,8 @@ func (service OrderInfoService) UpdateOrderData(cmd command.UpdateOrderCommand)
367 } 387 }
368 //获取旧的订单中的商品 388 //获取旧的订单中的商品
369 oldOrderGoods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{ 389 oldOrderGoods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{
370 - OrderId: cmd.Id, 390 + OrderId: cmd.Id,
  391 + CompanyId: cmd.CompanyId,
371 }) 392 })
372 if err != nil { 393 if err != nil {
373 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单中的商品列表失败:%s", err)) 394 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单中的商品列表失败:%s", err))
@@ -380,6 +401,7 @@ func (service OrderInfoService) UpdateOrderData(cmd command.UpdateOrderCommand) @@ -380,6 +401,7 @@ func (service OrderInfoService) UpdateOrderData(cmd command.UpdateOrderCommand)
380 m.Price = good.Price 401 m.Price = good.Price
381 m.PartnerBonusPercent = good.PartnerBonusPercent 402 m.PartnerBonusPercent = good.PartnerBonusPercent
382 m.Remark = good.Remark 403 m.Remark = good.Remark
  404 + m.CompanyId = cmd.CompanyId
383 err = m.Compute() 405 err = m.Compute()
384 if err != nil { 406 if err != nil {
385 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的数值失败:%s", err)) 407 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的数值失败:%s", err))
@@ -414,7 +436,7 @@ func (service OrderInfoService) UpdateOrderData(cmd command.UpdateOrderCommand) @@ -414,7 +436,7 @@ func (service OrderInfoService) UpdateOrderData(cmd command.UpdateOrderCommand)
414 oldOrderData.Goods = newOrderGoods 436 oldOrderData.Goods = newOrderGoods
415 //删不需要的订单总不需要的商品 437 //删不需要的订单总不需要的商品
416 delGoods = service.deleteOldOrderGoods(newOrderGoods, oldOrderGoods) 438 delGoods = service.deleteOldOrderGoods(newOrderGoods, oldOrderGoods)
417 - err = orderGoodRepository.Remove(oldOrderData.Id, delGoods...) 439 + err = orderGoodRepository.Remove(oldOrderData.Id, cmd.CompanyId, delGoods...)
418 if err != nil { 440 if err != nil {
419 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("删除订单中的商品数据失败:%s", err)) 441 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("删除订单中的商品数据失败:%s", err))
420 } 442 }
@@ -474,7 +496,8 @@ func (service OrderInfoService) Delivery(cmd command.OrderDeliveryCommand) error @@ -474,7 +496,8 @@ func (service OrderInfoService) Delivery(cmd command.OrderDeliveryCommand) error
474 } 496 }
475 //获取旧的订单 497 //获取旧的订单
476 oldOrderData, err = orderBaseRepository.FindOne(domain.OrderBaseFindOneQuery{ 498 oldOrderData, err = orderBaseRepository.FindOne(domain.OrderBaseFindOneQuery{
477 - OrderId: cmd.OrderId, 499 + CompanyId: cmd.CompanyId,
  500 + OrderId: cmd.OrderId,
478 }) 501 })
479 if err != nil { 502 if err != nil {
480 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单:%s", err)) 503 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单:%s", err))
@@ -488,14 +511,15 @@ func (service OrderInfoService) Delivery(cmd command.OrderDeliveryCommand) error @@ -488,14 +511,15 @@ func (service OrderInfoService) Delivery(cmd command.OrderDeliveryCommand) error
488 return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) 511 return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
489 } 512 }
490 //检查delivery_code是否重复 513 //检查delivery_code是否重复
491 - if ok, err := orderBaseDao.DeliveryCodeExist(cmd.DeliveryCode, cmd.OrderId); err != nil { 514 + if ok, err := orderBaseDao.DeliveryCodeExist(cmd.DeliveryCode, cmd.CompanyId, cmd.OrderId); err != nil {
492 return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) 515 return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
493 } else if ok { 516 } else if ok {
494 return lib.ThrowError(lib.BUSINESS_ERROR, "发货号已存在") 517 return lib.ThrowError(lib.BUSINESS_ERROR, "发货号已存在")
495 } 518 }
496 //获取旧的订单中的商品 519 //获取旧的订单中的商品
497 oldOrderGoods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{ 520 oldOrderGoods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{
498 - OrderId: cmd.OrderId, 521 + OrderId: cmd.OrderId,
  522 + CompanyId: cmd.CompanyId,
499 }) 523 })
500 if err != nil { 524 if err != nil {
501 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单中的商品列表失败:%s", err)) 525 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单中的商品列表失败:%s", err))
@@ -567,7 +591,8 @@ func (service OrderInfoService) DisableOrEnable(cmd command.DisableOrderCommand) @@ -567,7 +591,8 @@ func (service OrderInfoService) DisableOrEnable(cmd command.DisableOrderCommand)
567 } 591 }
568 //获取旧的订单 592 //获取旧的订单
569 oldOrderData, err = orderBaseRepository.FindOne(domain.OrderBaseFindOneQuery{ 593 oldOrderData, err = orderBaseRepository.FindOne(domain.OrderBaseFindOneQuery{
570 - OrderId: cmd.OrderId, 594 + OrderId: cmd.OrderId,
  595 + CompanyId: cmd.CompanyId,
571 }) 596 })
572 if err != nil { 597 if err != nil {
573 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单:%s", err)) 598 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单:%s", err))
@@ -617,7 +642,8 @@ func (service OrderInfoService) UpdateGoodBouns(cmd command.UpdateGoodBouns) err @@ -617,7 +642,8 @@ func (service OrderInfoService) UpdateGoodBouns(cmd command.UpdateGoodBouns) err
617 } 642 }
618 //获取旧的订单 643 //获取旧的订单
619 oldOrderData, err = orderBaseRepository.FindOne(domain.OrderBaseFindOneQuery{ 644 oldOrderData, err = orderBaseRepository.FindOne(domain.OrderBaseFindOneQuery{
620 - OrderId: cmd.Id, 645 + OrderId: cmd.Id,
  646 + CompanyId: cmd.CompanyId,
621 }) 647 })
622 if err != nil { 648 if err != nil {
623 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单:%s", err)) 649 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单:%s", err))
1 package query 1 package query
2 2
3 -type GetAdminUserQuery struct {  
4 - Id int64 `json:"id"`  
5 - AdminAccount string `json:"adminAccount"` 3 +type ListPartnerCategoryCommand struct {
6 } 4 }
  1 +package service
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory"
  5 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerCategory/query"
  6 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
  7 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
  8 +)
  9 +
  10 +type PartnerCategoryService struct {
  11 +}
  12 +
  13 +func NewPartnerCategoryService(option map[string]interface{}) *PartnerCategoryService {
  14 + newService := new(PartnerCategoryService)
  15 + return newService
  16 +}
  17 +
  18 +func (srv PartnerCategoryService) ListPartnerCategory(q query.ListPartnerCategoryCommand) (int, []domain.PartnerCategory, error) {
  19 + //实际业务
  20 + var err error
  21 + transactionContext, err := factory.CreateTransactionContext(nil)
  22 + if err != nil {
  23 + return 0, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
  24 + }
  25 + if err := transactionContext.StartTransaction(); err != nil {
  26 + return 0, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
  27 + }
  28 + defer func() {
  29 + transactionContext.RollbackTransaction()
  30 + }()
  31 + var (
  32 + categoryRepository domain.PartnerCategoryRepository
  33 + categorys []domain.PartnerCategory
  34 + cnt int
  35 + )
  36 + if categoryRepository, err = factory.CreatePartnerCategoryRepository(map[string]interface{}{
  37 + "transactionContext": transactionContext,
  38 + }); err != nil {
  39 + return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  40 + }
  41 + cnt, categorys, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{})
  42 + if err != nil {
  43 + return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  44 + }
  45 + err = transactionContext.CommitTransaction()
  46 + return cnt, categorys, nil
  47 +}
@@ -16,25 +16,24 @@ type CreatePartnerInfoCommand struct { @@ -16,25 +16,24 @@ type CreatePartnerInfoCommand struct {
16 Password string `json:"password,omitempty"` 16 Password string `json:"password,omitempty"`
17 // 状态(1:启用或者0:禁用) 17 // 状态(1:启用或者0:禁用)
18 Status int `json:"status"` 18 Status int `json:"status"`
19 - // 合伙类别 (1.研发合伙人 2.业务合伙人 3.事业)  
20 - PartnerCategory int `json:"partnerCategory,omitempty"` 19 + // 合伙类别
  20 + PartnerCategory []int64 `json:"partnerCategory,omitempty"`
21 //合作时间 21 //合作时间
22 CooperateTime time.Time `json:"cooperateTime"` 22 CooperateTime time.Time `json:"cooperateTime"`
23 // 区域 23 // 区域
24 RegionInfo *domain.RegionInfo `json:"regionInfo"` 24 RegionInfo *domain.RegionInfo `json:"regionInfo"`
25 //关联业务员 25 //关联业务员
26 Salesman []domain.Salesman `json:"salesman,omitempty"` 26 Salesman []domain.Salesman `json:"salesman,omitempty"`
  27 + //公司id
  28 + CompanyId int64 `json:"companyId"`
27 } 29 }
28 30
29 func (command CreatePartnerInfoCommand) ValidateCommand() error { 31 func (command CreatePartnerInfoCommand) ValidateCommand() error {
30 if !(command.Status == domain.PARTNER_STATUS_NO || command.Status == domain.PARTNER_STATUS_YES) { 32 if !(command.Status == domain.PARTNER_STATUS_NO || command.Status == domain.PARTNER_STATUS_YES) {
31 return lib.ThrowError(lib.ARG_ERROR, "合伙人状态错误") 33 return lib.ThrowError(lib.ARG_ERROR, "合伙人状态错误")
32 } 34 }
33 - if !(command.PartnerCategory == domain.PARTNER_CATEGORY_1 ||  
34 - command.PartnerCategory == domain.PARTNER_CATEGORY_2 ||  
35 - command.PartnerCategory == domain.PARTNER_CATEGORY_3 ||  
36 - command.PartnerCategory == domain.PARTNER_CATEGORY_4) {  
37 - return lib.ThrowError(lib.ARG_ERROR, "合伙类别错误") 35 + if len(command.PartnerCategory) == 0 {
  36 + return lib.ThrowError(lib.ARG_ERROR, "合伙类别必填")
38 } 37 }
39 if len(command.PartnerName) == 0 { 38 if len(command.PartnerName) == 0 {
40 return lib.ThrowError(lib.ARG_ERROR, "合伙人名称必填") 39 return lib.ThrowError(lib.ARG_ERROR, "合伙人名称必填")
@@ -7,16 +7,14 @@ import ( @@ -7,16 +7,14 @@ import (
7 7
8 type StatusPartnerInfoCommand struct { 8 type StatusPartnerInfoCommand struct {
9 // 合伙人ID 9 // 合伙人ID
10 - Id int64 `json:"id"`  
11 - Status int `json:"status"` 10 + Ids []int64 `json:"id"`
  11 + Status int `json:"status"`
  12 + CompanyId int64 `json:"companyId"`
12 } 13 }
13 14
14 func (command *StatusPartnerInfoCommand) ValidateCommand() error { 15 func (command *StatusPartnerInfoCommand) ValidateCommand() error {
15 if !(command.Status == domain.PARTNER_STATUS_NO || command.Status == domain.PARTNER_STATUS_YES) { 16 if !(command.Status == domain.PARTNER_STATUS_NO || command.Status == domain.PARTNER_STATUS_YES) {
16 return lib.ThrowError(lib.ARG_ERROR, "合伙人状态错误") 17 return lib.ThrowError(lib.ARG_ERROR, "合伙人状态错误")
17 } 18 }
18 - if command.Id == 0 {  
19 - return lib.ThrowError(lib.ARG_ERROR, "合伙人id错误")  
20 - }  
21 return nil 19 return nil
22 } 20 }
@@ -13,25 +13,21 @@ type UpdatePartnerInfoCommand struct { @@ -13,25 +13,21 @@ type UpdatePartnerInfoCommand struct {
13 // 状态(1:启用或者0:禁用) 13 // 状态(1:启用或者0:禁用)
14 Status int `json:"status"` 14 Status int `json:"status"`
15 // 合伙类别 (1.研发合伙人 2.业务合伙人 3.事业) 15 // 合伙类别 (1.研发合伙人 2.业务合伙人 3.事业)
16 - PartnerCategory int `json:"partnerCategory,omitempty"` 16 + PartnerCategory []int64 `json:"partnerCategory,omitempty"`
17 // 区域 17 // 区域
18 RegionInfo *domain.RegionInfo `json:"regionInfo"` 18 RegionInfo *domain.RegionInfo `json:"regionInfo"`
19 //关联业务员 19 //关联业务员
20 Salesman []domain.Salesman `json:"salesman,omitempty"` 20 Salesman []domain.Salesman `json:"salesman,omitempty"`
21 //合作时间 21 //合作时间
22 CooperateTime time.Time `json:"cooperateTime"` 22 CooperateTime time.Time `json:"cooperateTime"`
  23 + //公司id
  24 + CompanyId int64 `json:"companyId"`
23 } 25 }
24 26
25 func (command *UpdatePartnerInfoCommand) ValidateCommand() error { 27 func (command *UpdatePartnerInfoCommand) ValidateCommand() error {
26 if !(command.Status == domain.PARTNER_STATUS_NO || command.Status == domain.PARTNER_STATUS_YES) { 28 if !(command.Status == domain.PARTNER_STATUS_NO || command.Status == domain.PARTNER_STATUS_YES) {
27 return lib.ThrowError(lib.ARG_ERROR, "合伙人状态错误") 29 return lib.ThrowError(lib.ARG_ERROR, "合伙人状态错误")
28 } 30 }
29 - if !(command.PartnerCategory == domain.PARTNER_CATEGORY_1 ||  
30 - command.PartnerCategory == domain.PARTNER_CATEGORY_2 ||  
31 - command.PartnerCategory == domain.PARTNER_CATEGORY_3 ||  
32 - command.PartnerCategory == domain.PARTNER_CATEGORY_4) {  
33 - return lib.ThrowError(lib.ARG_ERROR, "合伙类别错误")  
34 - }  
35 if command.RegionInfo == nil { 31 if command.RegionInfo == nil {
36 return lib.ThrowError(lib.ARG_ERROR, "区域必填") 32 return lib.ThrowError(lib.ARG_ERROR, "区域必填")
37 } 33 }
@@ -2,7 +2,8 @@ package query @@ -2,7 +2,8 @@ package query
2 2
3 type GetPartnerInfoQuery struct { 3 type GetPartnerInfoQuery struct {
4 // 合伙人ID 4 // 合伙人ID
5 - Id int64 `json:"id" ` 5 + Id int64 `json:"id" `
  6 + CompanyId int64 `json:"companyId"`
6 } 7 }
7 8
8 func (q *GetPartnerInfoQuery) ValidateQuery() error { 9 func (q *GetPartnerInfoQuery) ValidateQuery() error {
@@ -7,6 +7,7 @@ type ListPartnerInfoQuery struct { @@ -7,6 +7,7 @@ type ListPartnerInfoQuery struct {
7 RegionInfo string `json:"regionInfo"` 7 RegionInfo string `json:"regionInfo"`
8 // 合伙人姓名 8 // 合伙人姓名
9 PartnerName string `json:"partnerName"` 9 PartnerName string `json:"partnerName"`
  10 + CompanyId int64 `json:"companyId"`
10 // 查询偏离量 11 // 查询偏离量
11 Offset int `json:"offset"` 12 Offset int `json:"offset"`
12 // 查询限制 13 // 查询限制
1 package service 1 package service
2 2
3 import ( 3 import (
  4 + "fmt"
  5 +
4 "github.com/linmadan/egglib-go/core/application" 6 "github.com/linmadan/egglib-go/core/application"
5 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory" 7 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory"
6 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/command" 8 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/command"
7 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/query" 9 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/query"
8 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" 10 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
  11 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain/service"
9 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/dao" 12 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/dao"
10 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib" 13 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
11 ) 14 )
@@ -19,12 +22,12 @@ func NewPartnerInfoService(options map[string]interface{}) *PartnerInfoService { @@ -19,12 +22,12 @@ func NewPartnerInfoService(options map[string]interface{}) *PartnerInfoService {
19 return newPartnerInfoService 22 return newPartnerInfoService
20 } 23 }
21 24
22 -// 创建客户价值  
23 -func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(command *command.CreatePartnerInfoCommand) (data interface{}, err error) { 25 +// CreatePartnerInfo 创建合伙人
  26 +func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.CreatePartnerInfoCommand) (data interface{}, err error) {
24 var ( 27 var (
25 transactionContext, _ = factory.CreateTransactionContext(nil) 28 transactionContext, _ = factory.CreateTransactionContext(nil)
26 ) 29 )
27 - if err = command.ValidateCommand(); err != nil { 30 + if err = cmd.ValidateCommand(); err != nil {
28 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 31 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
29 } 32 }
30 if err = transactionContext.StartTransaction(); err != nil { 33 if err = transactionContext.StartTransaction(); err != nil {
@@ -37,14 +40,12 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(command *command @@ -37,14 +40,12 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(command *command
37 var ( 40 var (
38 partnerinfoDao *dao.PartnerInfoDao 41 partnerinfoDao *dao.PartnerInfoDao
39 ) 42 )
40 - if v, err := factory.CreatePartnerInfoDao(map[string]interface{}{ 43 + if partnerinfoDao, err = factory.CreatePartnerInfoDao(map[string]interface{}{
41 "transactionContext": transactionContext, 44 "transactionContext": transactionContext,
42 }); err != nil { 45 }); err != nil {
43 return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) 46 return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
44 - } else {  
45 - partnerinfoDao = v  
46 } 47 }
47 - ok, err := partnerinfoDao.PartnerAccountExist(command.Account) 48 + ok, err := partnerinfoDao.PartnerAccountExist(cmd.Account, cmd.CompanyId)
48 if err != nil { 49 if err != nil {
49 return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) 50 return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
50 } 51 }
@@ -52,37 +53,66 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(command *command @@ -52,37 +53,66 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(command *command
52 return nil, lib.ThrowError(lib.BUSINESS_ERROR, "账号已存在") 53 return nil, lib.ThrowError(lib.BUSINESS_ERROR, "账号已存在")
53 } 54 }
54 55
55 - var PartnerInfoRepository domain.PartnerInfoRepository  
56 - if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{ 56 + var (
  57 + partnerInfoRepository domain.PartnerInfoRepository
  58 + categoryRepository domain.PartnerCategoryRepository
  59 + categorys []domain.PartnerCategory
  60 + )
  61 + if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
57 "transactionContext": transactionContext, 62 "transactionContext": transactionContext,
58 }); err != nil { 63 }); err != nil {
59 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 64 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
60 } 65 }
  66 + if categoryRepository, err = factory.CreatePartnerCategoryRepository(map[string]interface{}{
  67 + "transactionContext": transactionContext,
  68 + }); err != nil {
  69 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  70 + }
  71 + _, categorys, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{
  72 + Ids: cmd.PartnerCategory,
  73 + })
  74 + if err != nil {
  75 + e := fmt.Sprintf("获取合伙人分类数据失败:%s", err)
  76 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
  77 + }
61 newPartnerInfo := domain.PartnerInfo{ 78 newPartnerInfo := domain.PartnerInfo{
62 Partner: domain.Partner{ 79 Partner: domain.Partner{
63 - Account: command.Account,  
64 - PartnerName: command.PartnerName, 80 + Account: cmd.Account,
  81 + PartnerName: cmd.PartnerName,
65 }, 82 },
66 - PartnerCategory: command.PartnerCategory,  
67 - Password: command.Password,  
68 - Status: command.Status,  
69 - RegionInfo: command.RegionInfo,  
70 - Salesman: command.Salesman,  
71 - CooperateTime: command.CooperateTime,  
72 - }  
73 - if data, err = PartnerInfoRepository.Save(newPartnerInfo); err != nil { 83 + PartnerCategory: 0,
  84 + Password: cmd.Password,
  85 + Status: cmd.Status,
  86 + RegionInfo: *cmd.RegionInfo,
  87 + Salesman: cmd.Salesman,
  88 + CooperateTime: cmd.CooperateTime,
  89 + CompanyId: cmd.CompanyId,
  90 + PartnerCategoryInfos: categorys,
  91 + }
  92 + if err = partnerInfoRepository.Save(&newPartnerInfo); err != nil {
74 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 93 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
75 } 94 }
  95 + var businessBonusSrv service.BusinessBonusService
  96 + if businessBonusSrv, err = factory.CreateBusinessBonusService(map[string]interface{}{
  97 + "transactionContext": transactionContext,
  98 + }); err != nil {
  99 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  100 + }
  101 + err = businessBonusSrv.EnableOrDisable(newPartnerInfo.Partner.Id)
  102 + if err != nil {
  103 + e := fmt.Sprintf("更新业务分红(partner_id=%d)数据失败:%s", newPartnerInfo.Partner.Id, err)
  104 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
  105 + }
76 err = transactionContext.CommitTransaction() 106 err = transactionContext.CommitTransaction()
77 - return 107 + return newPartnerInfo, nil
78 } 108 }
79 109
80 // GetPartnerInfo 返回合伙人 110 // GetPartnerInfo 返回合伙人
81 -func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(command query.GetPartnerInfoQuery) (data *domain.PartnerInfo, err error) { 111 +func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(q query.GetPartnerInfoQuery) (data *domain.PartnerInfo, err error) {
82 var ( 112 var (
83 transactionContext, _ = factory.CreateTransactionContext(nil) 113 transactionContext, _ = factory.CreateTransactionContext(nil)
84 ) 114 )
85 - if err = command.ValidateQuery(); err != nil { 115 + if err = q.ValidateQuery(); err != nil {
86 return nil, lib.ThrowError(lib.ARG_ERROR, err.Error()) 116 return nil, lib.ThrowError(lib.ARG_ERROR, err.Error())
87 } 117 }
88 if err := transactionContext.StartTransaction(); err != nil { 118 if err := transactionContext.StartTransaction(); err != nil {
@@ -91,26 +121,54 @@ func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(command query.GetPa @@ -91,26 +121,54 @@ func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(command query.GetPa
91 defer func() { 121 defer func() {
92 transactionContext.RollbackTransaction() 122 transactionContext.RollbackTransaction()
93 }() 123 }()
94 - var PartnerInfoRepository domain.PartnerInfoRepository 124 + var (
  125 + PartnerInfoRepository domain.PartnerInfoRepository
  126 + categoryRepository domain.PartnerCategoryRepository
  127 + categorys []domain.PartnerCategory
  128 + partnerData *domain.PartnerInfo
  129 + )
95 if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{ 130 if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
96 "transactionContext": transactionContext, 131 "transactionContext": transactionContext,
97 }); err != nil { 132 }); err != nil {
98 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 133 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
99 } 134 }
100 - data, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{UserId: command.Id}) 135 + partnerData, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{
  136 + UserId: q.Id, CompanyId: q.CompanyId,
  137 + })
101 if err != nil { 138 if err != nil {
102 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 139 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
103 } 140 }
  141 + if !partnerData.IsCompany(q.CompanyId) {
  142 + return nil, lib.ThrowError(lib.BUSINESS_ERROR, "企业信息异常操作")
  143 + }
  144 + if categoryRepository, err = factory.CreatePartnerCategoryRepository(map[string]interface{}{
  145 + "transactionContext": transactionContext,
  146 + }); err != nil {
  147 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  148 + }
  149 + categoryIds := []int64{}
  150 + for _, v := range partnerData.PartnerCategoryInfos {
  151 + categoryIds = append(categoryIds, v.Id)
  152 + }
  153 + if len(categoryIds) > 0 {
  154 + _, categorys, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{
  155 + Ids: categoryIds,
  156 + })
  157 + if err != nil {
  158 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  159 + }
  160 + }
  161 + partnerData.PartnerCategoryInfos = categorys
104 err = transactionContext.CommitTransaction() 162 err = transactionContext.CommitTransaction()
105 - return 163 + return partnerData, nil
106 } 164 }
107 165
108 //UpdatePartnerInfo 更新合伙人 166 //UpdatePartnerInfo 更新合伙人
109 -func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(updatePartnerInfoCommand *command.UpdatePartnerInfoCommand) (err error) { 167 +func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.UpdatePartnerInfoCommand) (err error) {
110 var ( 168 var (
111 transactionContext, _ = factory.CreateTransactionContext(nil) 169 transactionContext, _ = factory.CreateTransactionContext(nil)
112 ) 170 )
113 - if err = updatePartnerInfoCommand.ValidateCommand(); err != nil { 171 + if err = cmd.ValidateCommand(); err != nil {
114 return application.ThrowError(application.ARG_ERROR, err.Error()) 172 return application.ThrowError(application.ARG_ERROR, err.Error())
115 } 173 }
116 if err := transactionContext.StartTransaction(); err != nil { 174 if err := transactionContext.StartTransaction(); err != nil {
@@ -119,31 +177,61 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(updatePartnerInf @@ -119,31 +177,61 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(updatePartnerInf
119 defer func() { 177 defer func() {
120 transactionContext.RollbackTransaction() 178 transactionContext.RollbackTransaction()
121 }() 179 }()
122 - var partnerInfoRepository domain.PartnerInfoRepository 180 + var (
  181 + partnerInfoRepository domain.PartnerInfoRepository
  182 + categoryRepository domain.PartnerCategoryRepository
  183 + categorys []domain.PartnerCategory
  184 + )
123 if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{ 185 if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
124 "transactionContext": transactionContext, 186 "transactionContext": transactionContext,
125 }); err != nil { 187 }); err != nil {
126 return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) 188 return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
127 } 189 }
  190 + if categoryRepository, err = factory.CreatePartnerCategoryRepository(map[string]interface{}{
  191 + "transactionContext": transactionContext,
  192 + }); err != nil {
  193 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  194 + }
  195 + _, categorys, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{
  196 + Ids: cmd.PartnerCategory,
  197 + })
  198 + if err != nil {
  199 + e := fmt.Sprintf("获取合伙人分类数据失败:%s", err)
  200 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
  201 + }
128 partnerInfo, err := partnerInfoRepository.FindOne(domain.PartnerFindOneQuery{ 202 partnerInfo, err := partnerInfoRepository.FindOne(domain.PartnerFindOneQuery{
129 - UserId: updatePartnerInfoCommand.Id, 203 + UserId: cmd.Id, CompanyId: cmd.CompanyId,
130 }) 204 })
131 if err != nil { 205 if err != nil {
132 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 206 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
133 } 207 }
134 - partnerInfo.PartnerCategory = updatePartnerInfoCommand.PartnerCategory  
135 - partnerInfo.Salesman = updatePartnerInfoCommand.Salesman  
136 - partnerInfo.Status = updatePartnerInfoCommand.Status  
137 - partnerInfo.RegionInfo = updatePartnerInfoCommand.RegionInfo  
138 - partnerInfo.CooperateTime = updatePartnerInfoCommand.CooperateTime  
139 - if _, err = partnerInfoRepository.Save(*partnerInfo); err != nil { 208 + if !partnerInfo.IsCompany(cmd.CompanyId) {
  209 + return lib.ThrowError(lib.BUSINESS_ERROR, "异常操作")
  210 + }
  211 + partnerInfo.Salesman = cmd.Salesman
  212 + partnerInfo.Status = cmd.Status
  213 + partnerInfo.RegionInfo = *cmd.RegionInfo
  214 + partnerInfo.CooperateTime = cmd.CooperateTime
  215 + partnerInfo.PartnerCategoryInfos = categorys
  216 + if err = partnerInfoRepository.Save(partnerInfo); err != nil {
  217 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  218 + }
  219 + var businessBonusSrv service.BusinessBonusService
  220 + if businessBonusSrv, err = factory.CreateBusinessBonusService(map[string]interface{}{
  221 + "transactionContext": transactionContext,
  222 + }); err != nil {
140 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 223 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
141 } 224 }
  225 + err = businessBonusSrv.EnableOrDisable(partnerInfo.Partner.Id)
  226 + if err != nil {
  227 + e := fmt.Sprintf("更新业务分红(partner_id=%d)数据失败:%s", partnerInfo.Partner.Id, err)
  228 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
  229 + }
142 transactionContext.CommitTransaction() 230 transactionContext.CommitTransaction()
143 return 231 return
144 } 232 }
145 233
146 -// 返回客户价值列表 234 +// ListPartnerInfo 合伙人列表
147 func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQuery *query.ListPartnerInfoQuery) (int, []domain.PartnerInfo, error) { 235 func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQuery *query.ListPartnerInfoQuery) (int, []domain.PartnerInfo, error) {
148 var ( 236 var (
149 transactionContext, _ = factory.CreateTransactionContext(nil) 237 transactionContext, _ = factory.CreateTransactionContext(nil)
@@ -158,21 +246,30 @@ func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQue @@ -158,21 +246,30 @@ func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQue
158 return 0, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) 246 return 0, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
159 } 247 }
160 defer func() { 248 defer func() {
161 - if err != nil {  
162 - transactionContext.RollbackTransaction()  
163 - } 249 +
  250 + transactionContext.RollbackTransaction()
  251 +
164 }() 252 }()
165 - var partnerInfoRepository domain.PartnerInfoRepository 253 + var (
  254 + partnerInfoRepository domain.PartnerInfoRepository
  255 + categoryRepository domain.PartnerCategoryRepository
  256 + categorys []domain.PartnerCategory
  257 + )
166 if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{ 258 if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
167 "transactionContext": transactionContext, 259 "transactionContext": transactionContext,
168 }); err != nil { 260 }); err != nil {
169 return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 261 return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
170 } 262 }
  263 + if categoryRepository, err = factory.CreatePartnerCategoryRepository(map[string]interface{}{
  264 + "transactionContext": transactionContext,
  265 + }); err != nil {
  266 + return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  267 + }
171 queryOption := domain.PartnerFindQuery{ 268 queryOption := domain.PartnerFindQuery{
172 - Offset: listPartnerInfoQuery.Offset,  
173 - Limit: listPartnerInfoQuery.Limit,  
174 - 269 + Offset: listPartnerInfoQuery.Offset,
  270 + Limit: listPartnerInfoQuery.Limit,
175 PartnerName: listPartnerInfoQuery.PartnerName, 271 PartnerName: listPartnerInfoQuery.PartnerName,
  272 + CompanyId: listPartnerInfoQuery.CompanyId,
176 } 273 }
177 if listPartnerInfoQuery.Partnertype > 0 { 274 if listPartnerInfoQuery.Partnertype > 0 {
178 queryOption.PartnerCategory = []int{listPartnerInfoQuery.Partnertype} 275 queryOption.PartnerCategory = []int{listPartnerInfoQuery.Partnertype}
@@ -187,17 +284,37 @@ func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQue @@ -187,17 +284,37 @@ func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQue
187 if count, err = partnerInfoRepository.CountAll(queryOption); err != nil { 284 if count, err = partnerInfoRepository.CountAll(queryOption); err != nil {
188 return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 285 return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
189 } 286 }
  287 + _, categorys, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{})
  288 + if err != nil {
  289 + return count, partnerInfos, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  290 + }
  291 + categorysMap := make(map[int64]domain.PartnerCategory)
  292 + for i := range categorys {
  293 + categorysMap[categorys[i].Id] = categorys[i]
  294 + }
  295 + for i := range partnerInfos {
  296 + categoryInPartner := []domain.PartnerCategory{}
  297 + for _, vv := range partnerInfos[i].PartnerCategoryInfos {
  298 + if categoryData, ok := categorysMap[vv.Id]; ok {
  299 + categoryInPartner = append(categoryInPartner, categoryData)
  300 + }
  301 + }
  302 + partnerInfos[i].PartnerCategoryInfos = categoryInPartner
  303 + }
190 if err = transactionContext.CommitTransaction(); err != nil { 304 if err = transactionContext.CommitTransaction(); err != nil {
191 return 0, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) 305 return 0, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
192 } 306 }
193 return count, partnerInfos, nil 307 return count, partnerInfos, nil
194 } 308 }
195 309
196 -func (PartnerInfoService *PartnerInfoService) UpdateStatus(command command.StatusPartnerInfoCommand) (err error) { 310 +func (PartnerInfoService *PartnerInfoService) UpdateStatus(cmd command.StatusPartnerInfoCommand) (err error) {
  311 + if len(cmd.Ids) == 0 {
  312 + return nil
  313 + }
197 var ( 314 var (
198 transactionContext, _ = factory.CreateTransactionContext(nil) 315 transactionContext, _ = factory.CreateTransactionContext(nil)
199 ) 316 )
200 - if err = command.ValidateCommand(); err != nil { 317 + if err = cmd.ValidateCommand(); err != nil {
201 return application.ThrowError(application.ARG_ERROR, err.Error()) 318 return application.ThrowError(application.ARG_ERROR, err.Error())
202 } 319 }
203 if err := transactionContext.StartTransaction(); err != nil { 320 if err := transactionContext.StartTransaction(); err != nil {
@@ -206,21 +323,18 @@ func (PartnerInfoService *PartnerInfoService) UpdateStatus(command command.Statu @@ -206,21 +323,18 @@ func (PartnerInfoService *PartnerInfoService) UpdateStatus(command command.Statu
206 defer func() { 323 defer func() {
207 transactionContext.RollbackTransaction() 324 transactionContext.RollbackTransaction()
208 }() 325 }()
209 - var partnerInfoRepository domain.PartnerInfoRepository  
210 - if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{ 326 + var (
  327 + partnerinfoDao *dao.PartnerInfoDao
  328 + )
  329 + if partnerinfoDao, err = factory.CreatePartnerInfoDao(map[string]interface{}{
211 "transactionContext": transactionContext, 330 "transactionContext": transactionContext,
212 }); err != nil { 331 }); err != nil {
213 return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) 332 return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
214 } 333 }
215 - partnerInfo, err := partnerInfoRepository.FindOne(domain.PartnerFindOneQuery{  
216 - UserId: command.Id,  
217 - }) 334 + err = partnerinfoDao.UpdatePartnerStatus(cmd.Ids, cmd.CompanyId, cmd.Status)
218 if err != nil { 335 if err != nil {
219 - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())  
220 - }  
221 - partnerInfo.Status = command.Status  
222 - if _, err = partnerInfoRepository.Save(*partnerInfo); err != nil {  
223 - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 336 + e := fmt.Sprintf("更新合伙人(id=%v)的数据失败;%s", cmd.Ids, err)
  337 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
224 } 338 }
225 transactionContext.CommitTransaction() 339 transactionContext.CommitTransaction()
226 return 340 return
  1 +package command
  2 +
  3 +type ChanceSuperAdminCommand struct {
  4 + CompanyId int64 `json:"company_id"` //公司id
  5 + Phone string `json:"phone"` //新的超级管理员手机号(账号)
  6 +}
  1 +package command
  2 +
  3 +import (
  4 + "encoding/json"
  5 + "fmt"
  6 +)
  7 +
  8 +type SyncCallbackCommand struct {
  9 + //position:职位,department:部门,employee:员工,company:公司
  10 + Module string `json:"module"`
  11 + //add:添加,edit:编辑,delete删除,batchDelete:批量删除,
  12 + //setCompanyCharge:更改公司主管,batchForbid:批量禁用用户,
  13 + //batchRemove:批量更改用户部门,changeAdmin换管理员
  14 + Action string `json:"action"`
  15 + //具体的对象JSON数据
  16 + Data json.RawMessage `json:"data" `
  17 +}
  18 +
  19 +func (command *SyncCallbackCommand) ValidateCommand() error {
  20 + if len(command.Module) == 0 {
  21 + return fmt.Errorf("module 必填")
  22 + }
  23 + if len(command.Action) == 0 {
  24 + return fmt.Errorf("action 必填")
  25 + }
  26 + return nil
  27 +}
  1 +package service
  2 +
  3 +import (
  4 + "encoding/json"
  5 + "errors"
  6 + "fmt"
  7 + "time"
  8 +
  9 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory"
  10 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
  11 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
  12 +)
  13 +
  14 +type SyncCompanyService struct{}
  15 +
  16 +var _ SyncAction = (*SyncCompanyService)(nil)
  17 +
  18 +//企业平台的公司基础数据
  19 +type CompanyBase struct {
  20 + Id int64 `json:"id"` //id
  21 + Name string `json:"name"` //公司名称名称
  22 + AdminCompanyId int `json:"admin_company_id"` //总后台的公司id
  23 + Logo string `json:"logo"` //公司图标
  24 + Remarks string `json:"remarks"` //备注
  25 + Abbreviation string `json:"abbreviation"`
  26 +}
  27 +
  28 +// CompanytData 企业平台发送过来的公司数据数据
  29 +type CompanytData struct {
  30 + Company CompanyBase `json:"company"`
  31 + User EmployeeData `json:"user"`
  32 +}
  33 +
  34 +//CompanyCharge 企业平台发送过来的变更公司主管数据
  35 +type CompanyCharge struct {
  36 + Id int64 `json:"id"`
  37 + Charge []int64 `json:"charge"`
  38 +}
  39 +
  40 +func (service SyncCompanyService) DoAction(action string, byteData []byte) error {
  41 + switch action {
  42 + case "add":
  43 + //添加公司
  44 + var (
  45 + data CompanytData
  46 + err error
  47 + )
  48 + err = json.Unmarshal(byteData, &data)
  49 + if err != nil {
  50 + return fmt.Errorf("数据解析失败:%s", err)
  51 + }
  52 + return service.addCompany(data)
  53 + case "edit":
  54 + //编辑
  55 + var (
  56 + data CompanytData
  57 + err error
  58 + )
  59 + err = json.Unmarshal(byteData, &data)
  60 + if err != nil {
  61 + return fmt.Errorf("数据解析失败:%s", err)
  62 + }
  63 + return service.updateCompany(data)
  64 + case "setCompanyCharge":
  65 + //设置公司主管
  66 + var (
  67 + data CompanyCharge
  68 + err error
  69 + )
  70 + err = json.Unmarshal(byteData, &data)
  71 + if err != nil {
  72 + return fmt.Errorf("数据解析失败:%s", err)
  73 + }
  74 + return service.updateCompanyCharge(data)
  75 + default:
  76 + return errors.New("action not found")
  77 + }
  78 +}
  79 +
  80 +func (service SyncCompanyService) addCompany(data CompanytData) error {
  81 + var (
  82 + transactionContext, _ = factory.CreateTransactionContext(nil)
  83 + err error
  84 + )
  85 + if err = transactionContext.StartTransaction(); err != nil {
  86 + return err
  87 + }
  88 + defer func() {
  89 + transactionContext.RollbackTransaction()
  90 + }()
  91 + var (
  92 + companyRespository domain.CompanyRepository
  93 + userRespository domain.UsersRepository
  94 + )
  95 + if companyRespository, err = factory.CreateCompanyRepository(map[string]interface{}{
  96 + "transactionContext": transactionContext,
  97 + }); err != nil {
  98 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  99 + }
  100 + if userRespository, err = factory.CreateUsersRepository(map[string]interface{}{
  101 + "transactionContext": transactionContext,
  102 + }); err != nil {
  103 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  104 + }
  105 + comany := domain.Company{
  106 + Id: data.Company.Id,
  107 + Name: data.Company.Name,
  108 + Phone: "",
  109 + Logo: data.Company.Logo,
  110 + Remarks: data.Company.Remarks,
  111 + AdminCompanyId: data.Company.AdminCompanyId,
  112 + //Status: data.Company.Status,
  113 + Enable: domain.CompanyEnableYes, //默认初始化值
  114 + Abbreviation: data.Company.Abbreviation,
  115 + }
  116 + err = companyRespository.Add(&comany)
  117 + if err != nil {
  118 + return fmt.Errorf("添加公司数据失败,%s", err)
  119 + }
  120 + user := domain.Users{
  121 + Id: data.User.Id,
  122 + CompanyId: data.User.CompanyId,
  123 + OpenId: data.User.OpenId,
  124 + Name: data.User.Name,
  125 + Sex: data.User.Sex,
  126 + JobNum: data.User.JobNum,
  127 + Phone: data.User.Phone,
  128 + PrivatePhone: data.User.PrivatePhone,
  129 + Email: data.User.Email,
  130 + ExtensionNum: data.User.ExtensionNum,
  131 + Workspace: data.User.WorkSpace,
  132 + Status: data.User.Status,
  133 + Avatar: data.User.Avatar,
  134 + Remarks: data.User.Remarks,
  135 + ChargeStatus: data.User.ChargeStatus,
  136 + Permission: []domain.AdminPermissionBase{}, //初始化权限
  137 + AccessPartners: []domain.Partner{},
  138 + AdminType: data.User.AdminType,
  139 + }
  140 + err = userRespository.Add(&user)
  141 + if err != nil {
  142 + return fmt.Errorf("添加用户数据失败,%s", err)
  143 + }
  144 + err = transactionContext.CommitTransaction()
  145 + return nil
  146 +}
  147 +
  148 +func (service SyncCompanyService) updateCompany(data CompanytData) error {
  149 + var (
  150 + transactionContext, _ = factory.CreateTransactionContext(nil)
  151 + err error
  152 + )
  153 + if err = transactionContext.StartTransaction(); err != nil {
  154 + return err
  155 + }
  156 + defer func() {
  157 + transactionContext.RollbackTransaction()
  158 + }()
  159 + var (
  160 + companyRespository domain.CompanyRepository
  161 + userRespository domain.UsersRepository
  162 + oldCompany domain.Company
  163 + oldUser domain.Users
  164 + )
  165 + if companyRespository, err = factory.CreateCompanyRepository(map[string]interface{}{
  166 + "transactionContext": transactionContext,
  167 + }); err != nil {
  168 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  169 + }
  170 + if userRespository, err = factory.CreateUsersRepository(map[string]interface{}{
  171 + "transactionContext": transactionContext,
  172 + }); err != nil {
  173 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  174 + }
  175 + oldCompany, err = companyRespository.FindOne(domain.CompanyFindOneOptions{
  176 + Id: data.Company.Id,
  177 + })
  178 + oldUser, err = userRespository.FindOne(domain.UsersFindOneQuery{
  179 + Id: data.User.Id,
  180 + })
  181 + oldCompany.Update(map[string]interface{}{
  182 + "Name": data.Company.Name,
  183 + "Logo": data.Company.Logo,
  184 + "Remarks": data.Company.Remarks,
  185 + "AdminCompanyId": data.Company.AdminCompanyId,
  186 + "Abbreviation": data.Company.Abbreviation,
  187 + })
  188 + entryTime, _ := time.Parse("2006-01-02", data.User.EntryTime)
  189 + oldUser.Update(map[string]interface{}{
  190 + "CompanyId": data.User.CompanyId,
  191 + "OpenId": data.User.OpenId,
  192 + "Name": data.User.Name,
  193 + "Sex": data.User.Sex,
  194 + "JobNum": data.User.JobNum,
  195 + "Phone": data.User.Phone,
  196 + "PrivatePhone": data.User.PrivatePhone,
  197 + "Email": data.User.Email,
  198 + "ExtensionNum": data.User.ExtensionNum,
  199 + "Workspace": data.User.WorkSpace,
  200 + "Status": data.User.Status,
  201 + "Avatar": data.User.Avatar,
  202 + "Remarks": data.User.Remarks,
  203 + "ChargeStatus": data.User.ChargeStatus,
  204 + "EntryTime": entryTime,
  205 + "AdminType": data.User.AdminType,
  206 + })
  207 + err = companyRespository.Edit(&oldCompany)
  208 + if err != nil {
  209 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  210 + }
  211 + err = userRespository.Edit(&oldUser)
  212 + if err != nil {
  213 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  214 + }
  215 + err = transactionContext.CommitTransaction()
  216 + return nil
  217 +}
  218 +
  219 +func (service SyncCompanyService) updateCompanyCharge(data CompanyCharge) error {
  220 + var (
  221 + transactionContext, _ = factory.CreateTransactionContext(nil)
  222 + err error
  223 + )
  224 + if err = transactionContext.StartTransaction(); err != nil {
  225 + return err
  226 + }
  227 + defer func() {
  228 + transactionContext.RollbackTransaction()
  229 + }()
  230 + var (
  231 + userRespository domain.UsersRepository
  232 + )
  233 + if userRespository, err = factory.CreateUsersRepository(map[string]interface{}{
  234 + "transactionContext": transactionContext,
  235 + }); err != nil {
  236 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  237 + }
  238 + var oldUsers []domain.Users
  239 + _, oldUsers, err = userRespository.Find(domain.UsersFindQuery{
  240 + CompanyId: data.Id,
  241 + ChargeStatus: domain.UserIsCompanyCharge,
  242 + Limit: -1,
  243 + })
  244 + for i := range oldUsers {
  245 + _ = oldUsers[i].Update(map[string]interface{}{
  246 + "ChargeStatus": domain.UserIsNotCompanyCharge,
  247 + })
  248 + err = userRespository.Edit(&oldUsers[i])
  249 + if err != nil {
  250 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, "更新用户的charge_status失败:"+err.Error())
  251 + }
  252 + }
  253 + for _, v := range data.Charge {
  254 + var userToUpdate domain.Users
  255 + userToUpdate, err := userRespository.FindOne(domain.UsersFindOneQuery{
  256 + Id: v,
  257 + })
  258 + if err != nil {
  259 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("获取用户(id=%d)的数据失败:%s", v, err.Error()))
  260 + }
  261 + _ = userToUpdate.Update(map[string]interface{}{
  262 + "ChargeStatus": domain.UserIsCompanyCharge,
  263 + })
  264 + err = userRespository.Edit(&userToUpdate)
  265 + if err != nil {
  266 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("更新用户(id=%d)的数据失败:%s", v, err.Error()))
  267 + }
  268 + }
  269 + err = transactionContext.CommitTransaction()
  270 + return nil
  271 +}
  1 +package service
  2 +
  3 +import (
  4 + "encoding/json"
  5 + "errors"
  6 + "fmt"
  7 + "time"
  8 +
  9 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory"
  10 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/unifiedUserCenter/command"
  11 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
  12 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/dao"
  13 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
  14 +)
  15 +
  16 +// UserDepartData 用户的部门数据
  17 +type UserDepartData struct {
  18 + Id int64 `json:"id"`
  19 + CompanyId int64 `json:"company_id"`
  20 + DepartmentId int64 `json:"department_id"`
  21 + UserId int64 `json:"user_id"`
  22 +}
  23 +
  24 +//UserPositionData 用户的职位数据
  25 +type UserPositionData struct {
  26 + Id int64 `json:"id"`
  27 + CompanyId int64 `json:"company_id"`
  28 + PositionId int64 `json:"position_id"`
  29 + UserId int64 `json:"user_id"`
  30 +}
  31 +
  32 +//EmployeeData 从平台平台接收的数据
  33 +type EmployeeData struct {
  34 + Id int64 `json:"id"` //用户的id,对应本地的user_company_id
  35 + OpenId int64 `json:"open_id"` //同一用户中心的用户id
  36 + Phone string `json:"phone"`
  37 + Name string `json:"name"`
  38 + Sex int8 `json:"sex"`
  39 + JobNum string `json:"job_num"`
  40 + PrivatePhone string `json:"private_phone"` //私人手机
  41 + CompanyId int64 `json:"company_id"` //总后台的company_id
  42 + Email string `json:"email"`
  43 + ExtensionNum string `json:"extension_num"` //分机号
  44 + EntryTime string `json:"entry_time"` //入职时间
  45 + WorkSpace string `json:"workspace"`
  46 + IsBusiness int8 `json:"is_business"` //
  47 + Status int8 `json:"status"`
  48 + Avatar string `json:"avatar"`
  49 + ExtraText string `json:"extra_text"`
  50 + Remarks string `json:"remarks"`
  51 + AdminType int8 `json:"admin_type"`
  52 + ChargeStatus int8 `json:"charge_status"`
  53 + UserDepartments []UserDepartData `json:"user_departments"`
  54 + UserPositions []UserPositionData `json:"user_positions"`
  55 +}
  56 +
  57 +//DeleteUserData 批量删除用户
  58 +type DeleteUserData struct {
  59 + CompanyId int64 `json:"companyId"`
  60 + Ids []int64 `json:"ids"`
  61 +}
  62 +
  63 +//ForbidAllowUserData 禁用启用用户
  64 +type ForbidAllowUserData struct {
  65 + CompanyId int64 `json:"companyId"`
  66 + Ids []int64 `json:"ids"`
  67 + Status int8 `json:"status"`
  68 +}
  69 +
  70 +//ImportEmployeeData 批量导入用户
  71 +type ImportEmployeeData struct {
  72 + Add []EmployeeData `json:"add"`
  73 + Edit []EmployeeData `json:"edit"`
  74 +}
  75 +
  76 +//SyncEmployeeService 同步用户数据
  77 +type SyncEmployeeService struct{}
  78 +
  79 +func NewSyncEmployeeService(option map[string]interface{}) *SyncEmployeeService {
  80 + syncEmployee := new(SyncEmployeeService)
  81 + return syncEmployee
  82 +}
  83 +
  84 +var _ SyncAction = (*SyncEmployeeService)(nil)
  85 +
  86 +func (service SyncEmployeeService) DoAction(action string, byteData []byte) error {
  87 + switch action {
  88 + case "add":
  89 + //添加
  90 + var (
  91 + data EmployeeData
  92 + err error
  93 + )
  94 + err = json.Unmarshal(byteData, &data)
  95 + if err != nil {
  96 + return fmt.Errorf("数据解析失败:%s", err)
  97 + }
  98 + err = service.addEmployeeData([]EmployeeData{data})
  99 + return err
  100 + case "edit":
  101 + //编辑更新
  102 + var (
  103 + data EmployeeData
  104 + err error
  105 + )
  106 + err = json.Unmarshal(byteData, &data)
  107 + if err != nil {
  108 + return fmt.Errorf("数据解析失败:%s", err)
  109 + }
  110 + err = service.updateEmployeeData([]EmployeeData{data})
  111 + return err
  112 + case "batchDelete":
  113 + //批量删除
  114 + var (
  115 + err error
  116 + data DeleteUserData
  117 + )
  118 + err = json.Unmarshal(byteData, &data)
  119 + if err != nil {
  120 + return fmt.Errorf("数据解析失败:%s", err)
  121 + }
  122 + return service.deleteEmployeeData(data)
  123 + case "batchForbid":
  124 + //启用禁用
  125 + var (
  126 + err error
  127 + data ForbidAllowUserData
  128 + )
  129 + err = json.Unmarshal(byteData, &data)
  130 + if err != nil {
  131 + return fmt.Errorf("数据解析失败:%s", err)
  132 + }
  133 + return service.updateUsersStatus(data)
  134 + // case "batchRemove":
  135 + // //移动通讯录用户部门 暂时不需要
  136 + // return nil
  137 + case "import":
  138 + //批量导入
  139 + var (
  140 + data ImportEmployeeData
  141 + err error
  142 + )
  143 + err = json.Unmarshal(byteData, &data)
  144 + if err != nil {
  145 + return fmt.Errorf("数据解析失败:%s", err)
  146 + }
  147 + err1 := service.addEmployeeData(data.Add)
  148 + err2 := service.updateEmployeeData(data.Edit)
  149 + if err1 != nil || err2 != nil {
  150 + return fmt.Errorf("添加用户错误:%s,更新用户发生错误:%s", err1, err2)
  151 + }
  152 + return nil
  153 + default:
  154 + return errors.New("action not found")
  155 + }
  156 +}
  157 +
  158 +func (service SyncEmployeeService) addEmployeeData(datas []EmployeeData) error {
  159 + var (
  160 + transactionContext, _ = factory.CreateTransactionContext(nil)
  161 + err error
  162 + )
  163 + if err = transactionContext.StartTransaction(); err != nil {
  164 + return err
  165 + }
  166 + defer func() {
  167 + transactionContext.RollbackTransaction()
  168 + }()
  169 + var usersRepository domain.UsersRepository
  170 + if usersRepository, err = factory.CreateUsersRepository(map[string]interface{}{
  171 + "transactionContext": transactionContext,
  172 + }); err != nil {
  173 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  174 + }
  175 + for i := range datas {
  176 + data := datas[i]
  177 + newUser := domain.Users{
  178 + Id: data.Id,
  179 + CompanyId: data.CompanyId,
  180 + OpenId: data.OpenId,
  181 + Name: data.Name,
  182 + Sex: data.Sex,
  183 + JobNum: data.JobNum,
  184 + Phone: data.Phone,
  185 + PrivatePhone: data.PrivatePhone,
  186 + Email: data.Email,
  187 + ExtensionNum: data.ExtensionNum,
  188 + Workspace: data.WorkSpace,
  189 + Status: data.Status,
  190 + Avatar: data.Avatar,
  191 + Remarks: data.Remarks,
  192 + ChargeStatus: data.ChargeStatus,
  193 + Permission: []domain.AdminPermissionBase{}, //初始化权限
  194 + AccessPartners: []domain.Partner{}, //默认初始化
  195 + AdminType: data.AdminType,
  196 + }
  197 + newUser.EntryTime, _ = time.Parse("2006-01-02", data.EntryTime)
  198 + if err = usersRepository.Add(&newUser); err != nil {
  199 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  200 + }
  201 + }
  202 + err = transactionContext.CommitTransaction()
  203 + return err
  204 +}
  205 +
  206 +func (service SyncEmployeeService) updateEmployeeData(datas []EmployeeData) error {
  207 + var (
  208 + transactionContext, _ = factory.CreateTransactionContext(nil)
  209 + err error
  210 + )
  211 + if err = transactionContext.StartTransaction(); err != nil {
  212 + return err
  213 + }
  214 + defer func() {
  215 + transactionContext.RollbackTransaction()
  216 + }()
  217 + var usersRepository domain.UsersRepository
  218 + if usersRepository, err = factory.CreateUsersRepository(map[string]interface{}{
  219 + "transactionContext": transactionContext,
  220 + }); err != nil {
  221 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  222 + }
  223 + for i := range datas {
  224 + data := datas[i]
  225 + var oldUser domain.Users
  226 + oldUser, err = usersRepository.FindOne(domain.UsersFindOneQuery{
  227 + Id: data.Id,
  228 + })
  229 + if err != nil {
  230 + return lib.ThrowError(lib.BUSINESS_ERROR, err.Error())
  231 + }
  232 + entryTime, _ := time.Parse("2006-01-02", data.EntryTime)
  233 + _ = oldUser.Update(map[string]interface{}{
  234 + "CompanyId": data.CompanyId,
  235 + "Name": data.Name,
  236 + "Sex": data.Sex,
  237 + "JobNum": data.JobNum,
  238 + "Phone": data.Phone,
  239 + "PrivatePhone": data.PrivatePhone,
  240 + "Email": data.Email,
  241 + "ExtensionNum": data.ExtensionNum,
  242 + "Workspace": data.WorkSpace,
  243 + "Status": data.Status,
  244 + "Avatar": data.Avatar,
  245 + "Remarks": data.Remarks,
  246 + "ChargeStatus": data.ChargeStatus,
  247 + "EntryTime": entryTime,
  248 + "AdminType": data.AdminType,
  249 + })
  250 + if err = usersRepository.Edit(&oldUser); err != nil {
  251 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  252 + }
  253 + }
  254 + err = transactionContext.CommitTransaction()
  255 + return err
  256 +}
  257 +
  258 +//deleteEmployeeData 删除用户
  259 +func (service SyncEmployeeService) deleteEmployeeData(data DeleteUserData) error {
  260 + var (
  261 + transactionContext, _ = factory.CreateTransactionContext(nil)
  262 + err error
  263 + )
  264 + if err = transactionContext.StartTransaction(); err != nil {
  265 + return err
  266 + }
  267 + defer func() {
  268 + transactionContext.RollbackTransaction()
  269 + }()
  270 + var usersRepository domain.UsersRepository
  271 + if usersRepository, err = factory.CreateUsersRepository(map[string]interface{}{
  272 + "transactionContext": transactionContext,
  273 + }); err != nil {
  274 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  275 + }
  276 + if err = usersRepository.Remove(data.Ids); err != nil {
  277 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  278 + }
  279 + err = transactionContext.CommitTransaction()
  280 + return err
  281 +}
  282 +
  283 +//UpdateUsersStatus 批量更新用户的状态
  284 +func (service SyncEmployeeService) updateUsersStatus(data ForbidAllowUserData) error {
  285 + var (
  286 + transactionContext, _ = factory.CreateTransactionContext(nil)
  287 + err error
  288 + )
  289 + if err = transactionContext.StartTransaction(); err != nil {
  290 + return err
  291 + }
  292 + defer func() {
  293 + transactionContext.RollbackTransaction()
  294 + }()
  295 + var uDao *dao.UsersDao
  296 + if uDao, err = factory.CreateUsersDao(map[string]interface{}{
  297 + "transactionContext": transactionContext,
  298 + }); err != nil {
  299 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  300 + }
  301 + if err = uDao.UpdateUserStatus(data.Ids, data.Status); err != nil {
  302 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  303 + }
  304 + err = transactionContext.CommitTransaction()
  305 + return err
  306 +}
  307 +
  308 +//ChangeAdmin 变更公司负责人,超级管理员
  309 +func (service SyncEmployeeService) ChangeSuperAdmin(cmd command.ChanceSuperAdminCommand) error {
  310 + var (
  311 + transactionContext, _ = factory.CreateTransactionContext(nil)
  312 + err error
  313 + )
  314 + if err = transactionContext.StartTransaction(); err != nil {
  315 + return err
  316 + }
  317 + defer func() {
  318 + transactionContext.RollbackTransaction()
  319 + }()
  320 + var usersRepository domain.UsersRepository
  321 + if usersRepository, err = factory.CreateUsersRepository(map[string]interface{}{
  322 + "transactionContext": transactionContext,
  323 + }); err != nil {
  324 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  325 + }
  326 + var (
  327 + oldSuperUser domain.Users
  328 + newSuperUser domain.Users
  329 + userList []domain.Users
  330 + )
  331 + _, userList, err = usersRepository.Find(domain.UsersFindQuery{
  332 + CompanyId: cmd.CompanyId,
  333 + AdminType: domain.UserIsAdmin,
  334 + })
  335 + if err != nil {
  336 + e := fmt.Sprintf("获取用户(admin_type=%d;company_id=%d)数据失败:%s",
  337 + domain.UserIsAdmin, cmd.CompanyId, err.Error())
  338 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
  339 + }
  340 + if len(userList) == 0 {
  341 + e := fmt.Sprintf("没有获得公司主管数据(admin_type=%d;company_id=%d)",
  342 + domain.UserIsAdmin, cmd.CompanyId)
  343 + return lib.ThrowError(lib.BUSINESS_ERROR, e)
  344 + }
  345 + if len(userList) > 1 {
  346 + e := fmt.Sprintf("存在复数公司主管数据(admin_type=%d;company_id=%d)",
  347 + domain.UserIsAdmin, cmd.CompanyId)
  348 + return lib.ThrowError(lib.BUSINESS_ERROR, e)
  349 + }
  350 + oldSuperUser = userList[0]
  351 + newSuperUser, err = usersRepository.FindOne(domain.UsersFindOneQuery{
  352 + CompanyId: cmd.CompanyId,
  353 + Phone: cmd.Phone,
  354 + })
  355 + if err != nil {
  356 + e := fmt.Sprintf("获取公司用户数据(phone=%s;company_id=%d)",
  357 + cmd.Phone, cmd.CompanyId)
  358 + return lib.ThrowError(lib.BUSINESS_ERROR, e)
  359 + }
  360 + err = oldSuperUser.Update(map[string]interface{}{
  361 + "AdminType": domain.UserIsNotAdmin,
  362 + })
  363 + if err != nil {
  364 + return lib.ThrowError(lib.BUSINESS_ERROR, err.Error())
  365 + }
  366 + err = newSuperUser.Update(map[string]interface{}{
  367 + "AdminType": domain.UserIsAdmin,
  368 + })
  369 + if err != nil {
  370 + return lib.ThrowError(lib.BUSINESS_ERROR, err.Error())
  371 + }
  372 + err = usersRepository.Edit(&oldSuperUser)
  373 + if err != nil {
  374 + e := fmt.Sprintf("更新公司主管user数据(id=%d)失败:%s",
  375 + oldSuperUser.Id, err)
  376 + return lib.ThrowError(lib.BUSINESS_ERROR, e)
  377 + }
  378 + err = usersRepository.Edit(&newSuperUser)
  379 + if err != nil {
  380 + e := fmt.Sprintf("更新公司主管user数据(id=%d)失败:%s",
  381 + newSuperUser.Id, err)
  382 + return lib.ThrowError(lib.BUSINESS_ERROR, e)
  383 + }
  384 + err = transactionContext.CommitTransaction()
  385 + return nil
  386 +}
  1 +package service
  2 +
  3 +import (
  4 + "errors"
  5 +
  6 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/unifiedUserCenter/command"
  7 +)
  8 +
  9 +//PlatformAction 企业平台数据同步服务 动作接口设定
  10 +type SyncAction interface {
  11 + DoAction(string, []byte) error
  12 +}
  13 +
  14 +//actionMap 数据同步需要的动作集合,静态不要在运行时变更这里的数据
  15 +//position:职位,department:部门,employee:员工,company:公司
  16 +var actionMap = map[string]SyncAction{
  17 + // "department":
  18 + // "position":
  19 + "employee": SyncEmployeeService{},
  20 + "company": SyncCompanyService{},
  21 +}
  22 +
  23 +func NewSyncAction(cmd command.SyncCallbackCommand) error {
  24 + err := cmd.ValidateCommand()
  25 + if err != nil {
  26 + return err
  27 + }
  28 + var (
  29 + action SyncAction
  30 + ok bool
  31 + )
  32 + if action, ok = actionMap[cmd.Module]; !ok {
  33 + return errors.New("module cannot found")
  34 + }
  35 + return action.DoAction(cmd.Action, cmd.Data)
  36 +}
  1 +package command
  2 +
  3 +import "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
  4 +
  5 +type LoginBySecretKeyCommand struct {
  6 + Code string `json:"code"`
  7 +}
  8 +
  9 +func (login LoginBySecretKeyCommand) ValidateCommand() error {
  10 + if len(login.Code) == 0 {
  11 + return lib.ThrowError(lib.ARG_ERROR, "登录参数错误")
  12 + }
  13 + return nil
  14 +}
  1 +package command
  2 +
  3 +type EditUserPermissionCommand struct {
  4 + Id int64 `json:"id"`
  5 + CompanyId int64 `json:"-"`
  6 + PermissionType []int64 `json:"permissionType"` //权限数据
  7 + CheckedPartner []int64 `json:"checkedPartner"` //可查看合伙人列表合伙人
  8 +}
1 package query 1 package query
2 2
3 -//ListAdminUserQuery 获取用户列表  
4 -type ListAdminUserQuery struct {  
5 - //账号匹配  
6 - AdminAccountMatch string `json:"adminAccountMatch" ` 3 +type UserListQuery struct {
  4 + //用户名称匹配
  5 + UserNameMatch string `json:"userNameMatch" `
7 // 查询偏离量 6 // 查询偏离量
8 Offset int `json:"offset" ` 7 Offset int `json:"offset" `
9 // 查询限制 8 // 查询限制
10 - Limit int `json:"limit"` 9 + Limit int `json:"limit"`
  10 + CompanyId int64 `json:"companyId"`
11 } 11 }
  1 +package query
  2 +
  3 +type ValidatePermissionQuery struct {
  4 + PermissionCode string
  5 + UserId int64
  6 + CompanyId int64
  7 +}
  1 +package service
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory"
  7 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/users/command"
  8 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/users/query"
  9 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
  10 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/serviceGateway"
  11 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
  12 +)
  13 +
  14 +type UsersService struct {
  15 +}
  16 +
  17 +func NewUsersService(option map[string]interface{}) *UsersService {
  18 + newUsersService := new(UsersService)
  19 + return newUsersService
  20 +}
  21 +
  22 +func (service UsersService) UserLoginBySecretKey(cmd command.LoginBySecretKeyCommand) (interface{}, error) {
  23 + var err error
  24 + if err = cmd.ValidateCommand(); err != nil {
  25 + return nil, err
  26 + }
  27 + //向统一用户中心确认密钥信息并获取用户数据
  28 + ucenterService := serviceGateway.NewMmmUserCenterServiceGateway()
  29 + loginResp, err := ucenterService.RequestUCenterLoginBySecret(cmd.Code)
  30 + if err != nil {
  31 + e := fmt.Sprintf("通过密钥(code=%s)从统一用户中心获取数据失败:%s", cmd.Code, err.Error())
  32 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
  33 + }
  34 +
  35 + if err := loginResp.IsOK(); err != nil {
  36 + e := fmt.Sprintf("登录失败:%s", err)
  37 + return nil, lib.ThrowError(lib.BUSINESS_ERROR, e)
  38 + }
  39 + adminBusinessService := serviceGateway.NewMmmBusinessAdminServiceGateway()
  40 + getUserAuthResp, err := adminBusinessService.GetUserAuth(loginResp.Data.Muid)
  41 + if err != nil {
  42 + e := fmt.Sprintf("用户鉴权失败:%s", err)
  43 + return nil, lib.ThrowError(lib.BUSINESS_ERROR, e)
  44 + }
  45 + if err := getUserAuthResp.IsOK(); err != nil {
  46 + return nil, lib.ThrowError(lib.BUSINESS_ERROR, "该公司没有操作权限")
  47 + }
  48 + if !getUserAuthResp.Data.UserAuth {
  49 + return nil, lib.ThrowError(lib.BUSINESS_ERROR, "该公司没有操作权限")
  50 + }
  51 + var (
  52 + transactionContext, _ = factory.CreateTransactionContext(nil)
  53 + )
  54 + if err = transactionContext.StartTransaction(); err != nil {
  55 + return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
  56 + }
  57 + defer func() {
  58 + transactionContext.RollbackTransaction()
  59 + }()
  60 + var (
  61 + companyRespository domain.CompanyRepository
  62 + userRespository domain.UsersRepository
  63 + companyData domain.Company
  64 + usersData domain.Users
  65 + )
  66 + if companyRespository, err = factory.CreateCompanyRepository(map[string]interface{}{
  67 + "transactionContext": transactionContext,
  68 + }); err != nil {
  69 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  70 + }
  71 + if userRespository, err = factory.CreateUsersRepository(map[string]interface{}{
  72 + "transactionContext": transactionContext,
  73 + }); err != nil {
  74 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  75 + }
  76 + //检索本系统的公司数据判断公司权限
  77 + companyData, err = companyRespository.FindOne(domain.CompanyFindOneOptions{
  78 + AdminCompanyId: loginResp.Data.CompanyId,
  79 + })
  80 + if err != nil {
  81 + e := fmt.Sprintf("获取公司(admin_company_id=%d)数据失败:%s", loginResp.Data.CompanyId, err.Error())
  82 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
  83 + }
  84 + //检索本系统的用户数据
  85 + usersData, err = userRespository.FindOne(domain.UsersFindOneQuery{
  86 + Id: loginResp.Data.Muid,
  87 + CompanyId: companyData.Id,
  88 + })
  89 + if err != nil {
  90 + e := fmt.Sprintf("获取用户(id=%d;CompanyId=%d)数据失败:%s",
  91 + loginResp.Data.Muid, companyData.Id, err.Error())
  92 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
  93 + }
  94 + //确认用户权限
  95 + if !usersData.IsUsable() {
  96 + return nil, lib.ThrowError(lib.BUSINESS_ERROR, "用户被禁用")
  97 + }
  98 + err = transactionContext.CommitTransaction()
  99 + newJwt := lib.NewMyToken(usersData.Id, companyData.Id)
  100 + newToken, err := newJwt.CreateJWTToken()
  101 + //生成token
  102 + returnData := map[string]interface{}{
  103 + "access": map[string]interface{}{
  104 + "accessToken": newToken,
  105 + "expiresIn": lib.JWtExpiresSecond,
  106 + },
  107 + }
  108 + return returnData, nil
  109 +}
  110 +
  111 +//GetAdminpPofile 登录后获取用户的权限配置数据
  112 +func (service UsersService) GetUserPofile(userId int64) (interface{}, error) {
  113 + var (
  114 + transactionContext, _ = factory.CreateTransactionContext(nil)
  115 + err error
  116 + )
  117 + if err = transactionContext.StartTransaction(); err != nil {
  118 + return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
  119 + }
  120 + defer func() {
  121 + transactionContext.RollbackTransaction()
  122 + }()
  123 + var (
  124 + userRespository domain.UsersRepository
  125 + usersData domain.Users
  126 + permissionRepository domain.AdminPermissionRepository
  127 + permissionList []domain.AdminPermission
  128 + )
  129 + if userRespository, err = factory.CreateUsersRepository(map[string]interface{}{
  130 + "transactionContext": transactionContext,
  131 + }); err != nil {
  132 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  133 + }
  134 + if permissionRepository, err = factory.CreateAdminPermissionRepository(map[string]interface{}{
  135 + "transactionContext": transactionContext,
  136 + }); err != nil {
  137 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  138 + }
  139 + usersData, err = userRespository.FindOne(domain.UsersFindOneQuery{
  140 + Id: userId,
  141 + })
  142 + if err != nil {
  143 + e := fmt.Sprintf("获取用户(Id=%d)数据失败:%s",
  144 + userId, err.Error())
  145 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
  146 + }
  147 + var permissionQuery domain.PermissionFindOption
  148 + permissionList, err = permissionRepository.Find(permissionQuery)
  149 + if err != nil {
  150 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  151 + }
  152 + err = transactionContext.CommitTransaction()
  153 + returnData := service.buildUserPofile(usersData, permissionList)
  154 + return returnData, nil
  155 +}
  156 +
  157 +//buildUserPofile 组装前端需要的数据 ,用户登录后获取的配置
  158 +func (service UsersService) buildUserPofile(userData domain.Users, permissionList []domain.AdminPermission) map[string]interface{} {
  159 + menus := make([]map[string]interface{}, 0, len(permissionList))
  160 + for _, v := range permissionList {
  161 + m := map[string]interface{}{
  162 + "code": v.Code,
  163 + "icon": v.Icon,
  164 + "parentId": v.ParentId,
  165 + "sort": v.Sort,
  166 + "name": v.Name,
  167 + "id": v.Id,
  168 + "status": 0, //状态 1-启用 0-禁用,前端需要
  169 + }
  170 + if userData.IsSuperAdmin() {
  171 + m["status"] = 1
  172 + menus = append(menus, m)
  173 + continue
  174 + }
  175 + for _, p := range userData.Permission {
  176 + if p.Id == v.Id {
  177 + m["status"] = 1
  178 + break
  179 + }
  180 + if p.Id == v.ParentId {
  181 + m["status"] = 1
  182 + break
  183 + }
  184 + }
  185 + menus = append(menus, m)
  186 + }
  187 + user := map[string]string{
  188 + "id": fmt.Sprint(userData.Id),
  189 + "name": userData.Name,
  190 + "adminType": "2", // 前端需要的管理员类型 1-超级管理员 2-子管理员
  191 + }
  192 + if userData.IsSuperAdmin() {
  193 + user["adminType"] = "1"
  194 + }
  195 + respData := map[string]interface{}{
  196 + "user": user,
  197 + "menus": menus,
  198 + }
  199 + return respData
  200 +}
  201 +
  202 +//ValidateAdminpPermission 校验用户的操作权限
  203 +func (service UsersService) ValidateAdminpPermission(queryOption query.ValidatePermissionQuery) (bool, error) {
  204 + var (
  205 + transactionContext, _ = factory.CreateTransactionContext(nil)
  206 + err error
  207 + )
  208 + if err = transactionContext.StartTransaction(); err != nil {
  209 + return false, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
  210 + }
  211 + defer func() {
  212 + transactionContext.RollbackTransaction()
  213 + }()
  214 + var (
  215 + userRespository domain.UsersRepository
  216 + usersData domain.Users
  217 + )
  218 +
  219 + if userRespository, err = factory.CreateUsersRepository(map[string]interface{}{
  220 + "transactionContext": transactionContext,
  221 + }); err != nil {
  222 + return false, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  223 + }
  224 + usersData, err = userRespository.FindOne(domain.UsersFindOneQuery{
  225 + Id: queryOption.UserId,
  226 + })
  227 + if err != nil {
  228 + return false, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  229 + }
  230 + if !usersData.IsUsable() {
  231 + return false, nil
  232 + }
  233 + err = transactionContext.CommitTransaction()
  234 + ok := usersData.HasPermissionByCode(queryOption.PermissionCode)
  235 + return ok, nil
  236 +}
  237 +
  238 +//获取用户列表
  239 +func (service UsersService) GetUserList(queryOption query.UserListQuery) (int, []map[string]interface{}, error) {
  240 + var (
  241 + transactionContext, _ = factory.CreateTransactionContext(nil)
  242 + err error
  243 + )
  244 + if err = transactionContext.StartTransaction(); err != nil {
  245 + return 0, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
  246 + }
  247 + defer func() {
  248 + transactionContext.RollbackTransaction()
  249 + }()
  250 + var (
  251 + userRespository domain.UsersRepository
  252 + usersData []domain.Users
  253 + cnt int
  254 + permissionRepository domain.AdminPermissionRepository
  255 + permissionList []domain.AdminPermission
  256 + )
  257 + if userRespository, err = factory.CreateUsersRepository(map[string]interface{}{
  258 + "transactionContext": transactionContext,
  259 + }); err != nil {
  260 + return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  261 + }
  262 + if permissionRepository, err = factory.CreateAdminPermissionRepository(map[string]interface{}{
  263 + "transactionContext": transactionContext,
  264 + }); err != nil {
  265 + return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  266 + }
  267 + cnt, usersData, err = userRespository.Find(domain.UsersFindQuery{
  268 + UserNameMatch: queryOption.UserNameMatch,
  269 + Offset: queryOption.Offset,
  270 + Limit: queryOption.Limit,
  271 + CompanyId: queryOption.CompanyId,
  272 + })
  273 + var permissionQuery = domain.PermissionFindOption{}
  274 + permissionList, err = permissionRepository.Find(permissionQuery)
  275 + if err != nil {
  276 + return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  277 + }
  278 + err = transactionContext.CommitTransaction()
  279 + result := service.buildGetUserList(usersData, permissionList)
  280 + return cnt, result, nil
  281 +}
  282 +
  283 +//buildGetUserList 组装构建前端需要的用户列表数据
  284 +func (service UsersService) buildGetUserList(usersData []domain.Users, permissionData []domain.AdminPermission) []map[string]interface{} {
  285 + result := make([]map[string]interface{}, 0, len(usersData))
  286 + permissionMap := map[int64]domain.AdminPermission{}
  287 + for i := range permissionData {
  288 + if permissionData[i].ParentId > 0 {
  289 + continue
  290 + }
  291 + permissionMap[permissionData[i].Id] = permissionData[i]
  292 + }
  293 + for i := range usersData {
  294 + permissionTypes := []string{}
  295 + if usersData[i].IsSuperAdmin() {
  296 + for _, pd := range permissionData {
  297 + if pd.ParentId > 0 {
  298 + continue
  299 + }
  300 + permissionTypes = append(permissionTypes, pd.Name)
  301 + }
  302 + } else {
  303 + for _, vv := range usersData[i].Permission {
  304 + if pm, ok := permissionMap[vv.Id]; ok {
  305 + permissionTypes = append(permissionTypes, pm.Name)
  306 + }
  307 + }
  308 + }
  309 + m := map[string]interface{}{
  310 + "id": usersData[i].Id,
  311 + "account": usersData[i].Phone,
  312 + "name": usersData[i].Name,
  313 + "permission": permissionTypes,
  314 + "isAdmin": 0,
  315 + "partnership": len(usersData[i].AccessPartners),
  316 + }
  317 + if usersData[i].IsSuperAdmin() {
  318 + m["isAdmin"] = 1
  319 + }
  320 + result = append(result, m)
  321 + }
  322 + return result
  323 +}
  324 +
  325 +func (service UsersService) GetUserData(userId int64, companyId int64) (map[string]interface{}, error) {
  326 + var (
  327 + transactionContext, _ = factory.CreateTransactionContext(nil)
  328 + err error
  329 + )
  330 + if err = transactionContext.StartTransaction(); err != nil {
  331 + return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
  332 + }
  333 + defer func() {
  334 + transactionContext.RollbackTransaction()
  335 + }()
  336 + var (
  337 + userRespository domain.UsersRepository
  338 + perterRespository domain.PartnerInfoRepository
  339 + usersData domain.Users
  340 + pertnerList []domain.PartnerInfo
  341 + )
  342 + if userRespository, err = factory.CreateUsersRepository(map[string]interface{}{
  343 + "transactionContext": transactionContext,
  344 + }); err != nil {
  345 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  346 + }
  347 + if perterRespository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
  348 + "transactionContext": transactionContext,
  349 + }); err != nil {
  350 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  351 + }
  352 + usersData, err = userRespository.FindOne(domain.UsersFindOneQuery{
  353 + Id: userId, CompanyId: companyId,
  354 + })
  355 + if err != nil {
  356 + e := fmt.Sprintf("获取用户(id=%d;company_id=%d)数据失败;%s", userId, companyId, err)
  357 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
  358 + }
  359 + var partnerIds []int64
  360 + for _, v := range usersData.AccessPartners {
  361 + partnerIds = append(partnerIds, v.Id)
  362 + }
  363 + if len(partnerIds) > 0 {
  364 + pertnerList, err = perterRespository.Find(domain.PartnerFindQuery{
  365 + Ids: partnerIds,
  366 + })
  367 + if err != nil {
  368 + e := fmt.Sprintf("获取合伙人数据失败:%s", err)
  369 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
  370 + }
  371 + }
  372 + transactionContext.CommitTransaction()
  373 + return service.buildGetUserData(&usersData, pertnerList)
  374 +}
  375 +
  376 +//buildGetUserData 构建前端需要的数据
  377 +func (service UsersService) buildGetUserData(userData *domain.Users, partnerList []domain.PartnerInfo) (map[string]interface{}, error) {
  378 + result := map[string]interface{}{
  379 + "id": userData.Id,
  380 + "permissionType": []int64{},
  381 + "name": userData.Name,
  382 + "account": userData.Phone,
  383 + "isAdmin": 0,
  384 + "status": 0,
  385 + "checkedPartner": []map[string]interface{}{},
  386 + }
  387 + if userData.IsSuperAdmin() {
  388 + result["isAdmin"] = 1
  389 + }
  390 + if userData.IsUsable() {
  391 + result["status"] = 1
  392 + }
  393 + permissionIds := make([]int64, 0, len(userData.Permission))
  394 + for _, v := range userData.Permission {
  395 + permissionIds = append(permissionIds, v.Id)
  396 + }
  397 +
  398 + if userData.IsSuperAdmin() {
  399 + transactionContext, _ := factory.CreateTransactionContext(nil)
  400 + var permissionRepository domain.AdminPermissionRepository
  401 + var err error
  402 + if permissionRepository, err = factory.CreateAdminPermissionRepository(map[string]interface{}{
  403 + "transactionContext": transactionContext,
  404 + }); err != nil {
  405 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  406 + }
  407 + permissionList, err := permissionRepository.Find(domain.PermissionFindOption{})
  408 + if err != nil {
  409 + e := fmt.Sprintf("获取权限列表数据失败:%s", err)
  410 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
  411 + }
  412 + permissionIds = make([]int64, 0)
  413 + for _, v := range permissionList {
  414 + permissionIds = append(permissionIds, v.Id)
  415 + }
  416 + }
  417 + result["permissionType"] = permissionIds
  418 + checkedPartner := make([]map[string]interface{}, 0, len(partnerList))
  419 + for i := range partnerList {
  420 + m := map[string]interface{}{
  421 + "id": partnerList[i].Partner.Id,
  422 + "name": partnerList[i].Partner.PartnerName,
  423 + }
  424 + checkedPartner = append(checkedPartner, m)
  425 + }
  426 + result["checkedPartner"] = checkedPartner
  427 + return result, nil
  428 +}
  429 +
  430 +//EditUserPermission 编辑用户的权限
  431 +func (service UsersService) EditUserPermission(cmd command.EditUserPermissionCommand) error {
  432 + var (
  433 + transactionContext, _ = factory.CreateTransactionContext(nil)
  434 + err error
  435 + )
  436 + if err = transactionContext.StartTransaction(); err != nil {
  437 + return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
  438 + }
  439 + defer func() {
  440 + transactionContext.RollbackTransaction()
  441 + }()
  442 + var (
  443 + userRespository domain.UsersRepository
  444 + usersData domain.Users
  445 + permissionRepository domain.AdminPermissionRepository
  446 + permissionList []domain.AdminPermission
  447 + partnerRespository domain.PartnerInfoRepository
  448 + partnerList []domain.PartnerInfo
  449 + )
  450 + if userRespository, err = factory.CreateUsersRepository(map[string]interface{}{
  451 + "transactionContext": transactionContext,
  452 + }); err != nil {
  453 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  454 + }
  455 + usersData, err = userRespository.FindOne(domain.UsersFindOneQuery{
  456 + Id: cmd.Id,
  457 + })
  458 + if err != nil {
  459 + e := fmt.Sprintf("获取用户(id=%d)数据失败,%s", cmd.Id, err)
  460 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
  461 + }
  462 + if !usersData.InCompany(cmd.CompanyId) {
  463 + return lib.ThrowError(lib.BUSINESS_ERROR, "提交的数据异常")
  464 + }
  465 +
  466 + if permissionRepository, err = factory.CreateAdminPermissionRepository(map[string]interface{}{
  467 + "transactionContext": transactionContext,
  468 + }); err != nil {
  469 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  470 + }
  471 + if len(cmd.PermissionType) > 0 {
  472 + permissionList, err = permissionRepository.Find(domain.PermissionFindOption{
  473 + Ids: cmd.PermissionType,
  474 + })
  475 + if err != nil {
  476 + e := fmt.Sprintf("获取权限列表数据失败:%s", err)
  477 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
  478 + }
  479 + }
  480 + if partnerRespository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
  481 + "transactionContext": transactionContext,
  482 + }); err != nil {
  483 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  484 + }
  485 + if len(cmd.CheckedPartner) > 0 {
  486 + partnerList, err = partnerRespository.Find(domain.PartnerFindQuery{
  487 + Ids: cmd.CheckedPartner,
  488 + CompanyId: cmd.CompanyId,
  489 + })
  490 + if err != nil {
  491 + e := fmt.Sprintf("获取合伙人列表数据失败:%s", err)
  492 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
  493 + }
  494 + }
  495 + var (
  496 + partners = make([]domain.Partner, 0, len(partnerList))
  497 + permissionsBase = make([]domain.AdminPermissionBase, 0)
  498 + )
  499 + for i := range partnerList {
  500 + p := partnerList[i].Partner
  501 + partners = append(partners, p)
  502 + }
  503 + for i := range permissionList {
  504 + if permissionList[i].Code == domain.PERMINSSION_ADMIN_USER && !usersData.IsSuperAdmin() {
  505 + return lib.ThrowError(lib.BUSINESS_ERROR, "操作异常")
  506 + }
  507 + p := domain.AdminPermissionBase{
  508 + Id: permissionList[i].Id,
  509 + Code: permissionList[i].Code,
  510 + }
  511 + permissionsBase = append(permissionsBase, p)
  512 + }
  513 + updateMap := map[string]interface{}{
  514 + "AccessPartners": partners,
  515 + }
  516 + if !usersData.IsSuperAdmin() {
  517 + updateMap["Permission"] = permissionsBase
  518 + }
  519 + _ = usersData.Update(updateMap)
  520 + err = userRespository.Edit(&usersData)
  521 + if err != nil {
  522 + e := fmt.Sprintf("更新用户(id=%d)数据失败:%s", usersData.Id, err)
  523 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
  524 + }
  525 + err = transactionContext.CommitTransaction()
  526 + return nil
  527 +}
@@ -8,27 +8,35 @@ var LOG_LEVEL = "debug" @@ -8,27 +8,35 @@ var LOG_LEVEL = "debug"
8 var LOG_File = "./logs/partnermg.log" 8 var LOG_File = "./logs/partnermg.log"
9 9
10 var ( 10 var (
11 - UCENTER_HOST = "http://suplus-ucenter-dev.fjmaimaimai.com" //统一用户中心地址 11 + UCENTER_HOST = "https://suplus-ucenter-dev.fjmaimaimai.com" //统一用户中心地址
12 UCENTER_SECRET = "cykbjnfqgctn" 12 UCENTER_SECRET = "cykbjnfqgctn"
13 UCENTER_APP_KEY = "39aefef9e22744a3b2d2d3791824ae7b" 13 UCENTER_APP_KEY = "39aefef9e22744a3b2d2d3791824ae7b"
14 UCENTER_CHECK_ALT = "rsF0pL!6DwjBO735" 14 UCENTER_CHECK_ALT = "rsF0pL!6DwjBO735"
15 ) 15 )
16 16
  17 +var (
  18 + BUSINESS_ADMIN_HOST = "http://suplus-business-admin-dev.fjmaimaimai.com" //企业平台的地址
  19 +)
  20 +
17 func init() { 21 func init() {
18 if os.Getenv("LOG_LEVEL") != "" { 22 if os.Getenv("LOG_LEVEL") != "" {
19 LOG_LEVEL = os.Getenv("LOG_LEVEL") 23 LOG_LEVEL = os.Getenv("LOG_LEVEL")
20 } 24 }
21 if os.Getenv("UCENTER_HOST") != "" { 25 if os.Getenv("UCENTER_HOST") != "" {
22 - LOG_LEVEL = os.Getenv("UCENTER_HOST") 26 + UCENTER_HOST = os.Getenv("UCENTER_HOST")
23 } 27 }
24 if os.Getenv("UCENTER_SECRET") != "" { 28 if os.Getenv("UCENTER_SECRET") != "" {
25 - LOG_LEVEL = os.Getenv("UCENTER_SECRET") 29 + UCENTER_SECRET = os.Getenv("UCENTER_SECRET")
26 } 30 }
27 if os.Getenv("UCENTER_APP_KEY") != "" { 31 if os.Getenv("UCENTER_APP_KEY") != "" {
28 - LOG_LEVEL = os.Getenv("UCENTER_APP_KEY") 32 + UCENTER_APP_KEY = os.Getenv("UCENTER_APP_KEY")
29 } 33 }
30 if os.Getenv("UCENTER_CHECK_ALT") != "" { 34 if os.Getenv("UCENTER_CHECK_ALT") != "" {
31 - LOG_LEVEL = os.Getenv("UCENTER_CHECK_ALT") 35 + UCENTER_CHECK_ALT = os.Getenv("UCENTER_CHECK_ALT")
  36 + }
  37 +
  38 + if os.Getenv("BUSINESS_ADMIN_HOST") != "" {
  39 + BUSINESS_ADMIN_HOST = os.Getenv("BUSINESS_ADMIN_HOST")
32 } 40 }
33 41
34 } 42 }
@@ -4,9 +4,9 @@ import "os" @@ -4,9 +4,9 @@ import "os"
4 4
5 var POSTGRESQL_DB_NAME = "partner_dev" 5 var POSTGRESQL_DB_NAME = "partner_dev"
6 var POSTGRESQL_USER = "postgres" 6 var POSTGRESQL_USER = "postgres"
7 -var POSTGRESQL_PASSWORD = "postgres_15432"  
8 -var POSTGRESQL_HOST = "101.37.68.23"  
9 -var POSTGRESQL_PORT = "15432" 7 +var POSTGRESQL_PASSWORD = "eagle1010"
  8 +var POSTGRESQL_HOST = "114.55.200.59"
  9 +var POSTGRESQL_PORT = "31543"
10 var DISABLE_CREATE_TABLE = true 10 var DISABLE_CREATE_TABLE = true
11 var DISABLE_SQL_GENERATE_PRINT = false 11 var DISABLE_SQL_GENERATE_PRINT = false
12 12
1 package domain 1 package domain
2 2
3 //权限代码 3 //权限代码
4 -//权限配置 1合作管理人 2订单管理 3分红管理 4管理员管理 4 +//权限配置 :admin_permission表中对应的权限编码
5 const ( 5 const (
6 - PERMINSSION_PARTNER string = "PARTER" //合作管理人  
7 - PERMISSION_ORDER string = "ORDER" //订单管理  
8 - PERMISSION_DIVIDEND string = "DIVIDEND" //分红管理  
9 - PERMINSSION_ADMIN_USER string = "ADMIN" //管理员管理  
10 - PERMINSSION_ORDER_ACTUA string = "ORDER_ACTUA" //实际订单  
11 - PERMINSSION_ORDER_INTENTION string = "ORDER_INTENTION" //意向订单 6 + PERMINSSION_PARTNER string = "PARTER" //合作管理人
  7 + PERMISSION_ORDER string = "ORDER" //订单管理
  8 + PERMISSION_DIVIDEND string = "DIVIDEND" //分红管理
  9 + PERMINSSION_ADMIN_USER string = "ADMIN" //管理员管理
  10 + PERMINSSION_ORDER_ACTUA string = "ORDER_ACTUA" //实际订单
  11 + PERMINSSION_ORDER_INTENTION string = "ORDER_INTENTION" //意向订单
  12 + PERMISSION_ENTERPRISE_SET string = "ENTERPRISE-SETTING" //企业配置
  13 + PERMISSION_ENTERPRISE_SET_PHONE string = "ENTERPRISE-SETTING-PHONE" //企业配置电话号码
12 ) 14 )
13 15
14 type AdminPermissionBase struct { 16 type AdminPermissionBase struct {
15 - Id int `json:"id"` 17 + Id int64 `json:"id"`
16 Code string `json:"code"` 18 Code string `json:"code"`
17 } 19 }
18 20
19 // 权限结构 21 // 权限结构
20 type AdminPermission struct { 22 type AdminPermission struct {
21 - Id int `json:"id"`  
22 - ParentId int `json:"parentId"` 23 + Id int64 `json:"id"`
  24 + ParentId int64 `json:"parentId"`
23 Code string `json:"code"` 25 Code string `json:"code"`
24 Name string `json:"name"` 26 Name string `json:"name"`
25 Sort int `json:"sort"` 27 Sort int `json:"sort"`
26 Icon string `json:"icon"` 28 Icon string `json:"icon"`
27 } 29 }
28 30
29 -type AdminPermissionFindQuery struct {  
30 - IdsIn []int  
31 - NotCode []string  
32 - ParentId interface{} 31 +type PermissionFindOption struct {
  32 + Ids []int64
  33 +}
  34 +
  35 +type PermissionFindOneOption struct {
  36 + Id int64
  37 + Code string
33 } 38 }
34 39
35 type AdminPermissionRepository interface { 40 type AdminPermissionRepository interface {
36 - Find(queryOptions AdminPermissionFindQuery) ([]AdminPermission, error) 41 + Find(PermissionFindOption) ([]AdminPermission, error)
  42 + FindOne(PermissionFindOneOption) (AdminPermission, error)
37 } 43 }
  1 +package domain
  2 +
  3 +import "time"
  4 +
  5 +// 业务分红信息 是否有效【0;无效】【1:有效】
  6 +const (
  7 + BUSINESS_BONUS_ENABLE int8 = 1
  8 + BUSINESS_BONUS_DISABLE int8 = 0
  9 +)
  10 +
  11 +// 分红状态 1:待支付分红 2:已支付分红
  12 +const (
  13 + //空状态
  14 + BUSINESS_BONUS_NULL_PAY int8 = 0
  15 + //待支付
  16 + BUSINESS_BONUS_WAIT_PAY int8 = 1
  17 + //已支付
  18 + BUSINESS_BONUS_HAS_PAY int8 = 2
  19 +)
  20 +
  21 +func DescribeBusinessBonusStatus(i int8) string {
  22 + m := map[int8]string{
  23 + BUSINESS_BONUS_WAIT_PAY: "等待支付分红",
  24 + BUSINESS_BONUS_HAS_PAY: "已支付分红",
  25 + }
  26 + if v, ok := m[i]; ok {
  27 + return v
  28 + }
  29 + return ""
  30 +}
  31 +
  32 +//分红状态
  33 +type BusinessBonusBonusStatus interface {
  34 + //状态变更为空
  35 + NullPayPartnerBonus(*BusinessBonus) error
  36 + //状态变更为待支付
  37 + WartPayPartnerBonus(*BusinessBonus) error
  38 + //状态变更为已支付
  39 + PayPartnerBonus(*BusinessBonus) error
  40 +}
  41 +
  42 +// 业务分红信息
  43 +type BusinessBonus struct {
  44 + // 唯一标识
  45 + Id int64 `json:"id"`
  46 + // 公司编号
  47 + CompanyId int64 `json:"companyId"`
  48 + // 合伙人信息Id
  49 + PartnerInfoId int64 `json:"partnerInfoId"`
  50 + // 应收分红
  51 + Bonus float64 `json:"bonus"`
  52 + // 未收分红
  53 + BonusNot float64 `json:"bonusNot"`
  54 + //已收分红
  55 + BonusHas float64 `json:"bonusHas"`
  56 + // 分红支出
  57 + BonusExpense float64 `json:"bonusExpense"`
  58 + // 是否关闭【0;否】【1:是】
  59 + IsDisable int8 `json:"isDisable"`
  60 + // 分红状态 1:待支付分红 2:已支付分红
  61 + BonusStatus int8 `json:"bonusStatus"`
  62 + // 创建时间
  63 + CreateAt time.Time `json:"createAt"`
  64 + // 更新时间
  65 + UpdateAt time.Time `json:"updateAt"`
  66 + // 删除时间
  67 + DeleteAt time.Time `json:"deleteAt"`
  68 +
  69 + BusinessBonusPayStatus BusinessBonusBonusStatus
  70 +}
  71 +
  72 +type BusinessBonusNullPay struct{}
  73 +
  74 +var _ BusinessBonusBonusStatus = (*BusinessBonusNullPay)(nil)
  75 +
  76 +type BusinessBonusWaitPay struct{}
  77 +
  78 +var _ BusinessBonusBonusStatus = (*BusinessBonusWaitPay)(nil)
  79 +
  80 +//OrderGoodBonusHasPay 货品分红已支付
  81 +type BusinessBonusHasPay struct{}
  82 +
  83 +var _ BusinessBonusBonusStatus = (*BusinessBonusHasPay)(nil)
  84 +
  85 +// -----默认空状态-----
  86 +//状态变更为空
  87 +func (pay BusinessBonusNullPay) NullPayPartnerBonus(bonus *BusinessBonus) error {
  88 + bonus.BonusStatus = 0
  89 + bonus.BonusExpense = 0
  90 + bonus.BonusHas = 0
  91 + bonus.BonusNot = 0
  92 + bonus.Bonus = 0
  93 + bonus.BusinessBonusPayStatus = &BusinessBonusNullPay{}
  94 + return nil
  95 +}
  96 +
  97 +//状态变更为待支付
  98 +func (pay BusinessBonusNullPay) WartPayPartnerBonus(bonus *BusinessBonus) error {
  99 + bonus.BonusNot = bonus.Bonus
  100 + bonus.BonusStatus = BUSINESS_BONUS_WAIT_PAY
  101 + bonus.BonusHas = 0
  102 + bonus.BusinessBonusPayStatus = &BusinessBonusWaitPay{}
  103 + return nil
  104 +}
  105 +
  106 +//状态变更为已支付
  107 +func (pay BusinessBonusNullPay) PayPartnerBonus(bonus *BusinessBonus) error {
  108 + bonus.BonusNot = 0
  109 + bonus.BonusHas = bonus.Bonus
  110 + bonus.BonusStatus = BUSINESS_BONUS_HAS_PAY
  111 + bonus.BusinessBonusPayStatus = &BusinessBonusHasPay{}
  112 + return nil
  113 +}
  114 +
  115 +// -----待支付状态-----
  116 +//状态变更为空
  117 +func (pay BusinessBonusWaitPay) NullPayPartnerBonus(bonus *BusinessBonus) error {
  118 + bonus.BonusStatus = 0
  119 + bonus.BonusExpense = 0
  120 + bonus.BonusHas = 0
  121 + bonus.BonusNot = 0
  122 + bonus.Bonus = 0
  123 + bonus.BusinessBonusPayStatus = &BusinessBonusNullPay{}
  124 + return nil
  125 +}
  126 +
  127 +//状态变更为待支付
  128 +func (pay BusinessBonusWaitPay) WartPayPartnerBonus(bonus *BusinessBonus) error {
  129 + bonus.BonusNot = bonus.Bonus
  130 + bonus.BonusStatus = BUSINESS_BONUS_WAIT_PAY
  131 + bonus.BonusHas = 0
  132 + bonus.BusinessBonusPayStatus = &BusinessBonusWaitPay{}
  133 + return nil
  134 +}
  135 +
  136 +//状态变更为已支付
  137 +func (pay BusinessBonusWaitPay) PayPartnerBonus(bonus *BusinessBonus) error {
  138 + bonus.BonusNot = 0
  139 + bonus.BonusHas = bonus.Bonus
  140 + bonus.BonusStatus = BUSINESS_BONUS_HAS_PAY
  141 + bonus.BusinessBonusPayStatus = &BusinessBonusHasPay{}
  142 + return nil
  143 +}
  144 +
  145 +// -----已经支付状态-----
  146 +//状态变更为空
  147 +func (pay BusinessBonusHasPay) NullPayPartnerBonus(bonus *BusinessBonus) error {
  148 + bonus.BonusStatus = 0
  149 + bonus.BonusExpense = 0
  150 + bonus.BonusHas = 0
  151 + bonus.BonusNot = 0
  152 + bonus.Bonus = 0
  153 + bonus.BusinessBonusPayStatus = &BusinessBonusNullPay{}
  154 + return nil
  155 +}
  156 +
  157 +//状态变更为待支付
  158 +func (pay BusinessBonusHasPay) WartPayPartnerBonus(bonus *BusinessBonus) error {
  159 + bonus.BonusNot = bonus.Bonus
  160 + bonus.BonusStatus = BUSINESS_BONUS_WAIT_PAY
  161 + bonus.BonusHas = 0
  162 + bonus.BusinessBonusPayStatus = &BusinessBonusWaitPay{}
  163 + return nil
  164 +}
  165 +
  166 +//状态变更为已支付
  167 +func (pay BusinessBonusHasPay) PayPartnerBonus(bonus *BusinessBonus) error {
  168 + bonus.BonusNot = 0
  169 + bonus.BonusHas = bonus.Bonus
  170 + bonus.BonusStatus = BUSINESS_BONUS_HAS_PAY
  171 + bonus.BusinessBonusPayStatus = &BusinessBonusHasPay{}
  172 + return nil
  173 +}
  174 +
  175 +type BusinessBonusFindOneQuery struct {
  176 + Id int64
  177 + PartnerId int64
  178 + CompanyId int64
  179 +}
  180 +type BusinessBonusFindQuery struct {
  181 + Offset int
  182 + Limit int
  183 +}
  184 +
  185 +type BusinessBonusRepository interface {
  186 + Add(dm *BusinessBonus) error
  187 + Edit(dm *BusinessBonus) error
  188 + FindOne(BusinessBonusFindOneQuery) (*BusinessBonus, error)
  189 + Find(BusinessBonusFindQuery) (int, []BusinessBonus, error)
  190 +}
  1 +package domain
  2 +
  3 +import (
  4 + "fmt"
  5 + "time"
  6 +)
  7 +
  8 +// 公司的状态 1正常 2禁用
  9 +const (
  10 + companyStatusUsable int8 = 1
  11 + companyStatusUnusable int8 = 2
  12 +)
  13 +
  14 +//是否开启机会模块,是否有效【1:有效】【2:无效】
  15 +const (
  16 + CompanyEnableYes int8 = 1
  17 + CompanyEnableNo int8 = 2
  18 +)
  19 +
  20 +// 公司信息
  21 +type Company struct {
  22 + // 唯一标识
  23 + Id int64 `json:"id"`
  24 + // 名称
  25 + Name string `json:"name"`
  26 + //简称
  27 + Abbreviation string `json:"abbreviation"`
  28 + // 手机号码
  29 + Phone string `json:"phone"`
  30 + // 公司logo
  31 + Logo string `json:"logo"`
  32 + // 备注
  33 + Remarks string `json:"remarks"`
  34 + // 总后台的公司id
  35 + AdminCompanyId int `json:"adminCompanyId"`
  36 + //是否有效【1:有效】【2:无效】
  37 + Enable int8 `json:"enable"`
  38 + // 创建时间
  39 + CreateAt time.Time `json:"createAt"`
  40 + // 更新时间
  41 + UpdateAt time.Time `json:"updateAt"`
  42 + // 删除时间
  43 + DeleteAt time.Time `json:"deleteAt"`
  44 +}
  45 +
  46 +// func (c Company) StatusIsOk() bool {
  47 +// return c.Status == companyStatusUsable
  48 +// }
  49 +
  50 +func (c Company) EnableIsOk() bool {
  51 + return c.Enable == CompanyEnableYes
  52 +}
  53 +
  54 +func (c *Company) Update(m map[string]interface{}) error {
  55 + if v, ok := m["Name"]; ok {
  56 + c.Name = fmt.Sprint(v)
  57 + }
  58 + if v, ok := m["Phone"]; ok {
  59 + c.Phone = fmt.Sprint(v)
  60 + }
  61 + if v, ok := m["Logo"]; ok {
  62 + c.Logo = fmt.Sprint(v)
  63 + }
  64 + if v, ok := m["Remarks"]; ok {
  65 + c.Remarks = fmt.Sprint(v)
  66 + }
  67 + if v, ok := m["AdminCompanyId"]; ok {
  68 + c.AdminCompanyId = v.(int)
  69 + }
  70 + if v, ok := m["Remarks"]; ok {
  71 + c.Remarks = fmt.Sprint(v)
  72 + }
  73 + if v, ok := m["Enable"]; ok {
  74 + c.Enable = v.(int8)
  75 + }
  76 + if v, ok := m["Abbreviation"]; ok {
  77 + c.Abbreviation = v.(string)
  78 + }
  79 + return nil
  80 +}
  81 +
  82 +type CompanyFindOneOptions struct {
  83 + Id int64
  84 + AdminCompanyId int64
  85 +}
  86 +
  87 +type CompanyFindOptions struct {
  88 +}
  89 +
  90 +type CompanyRepository interface {
  91 + Add(*Company) error
  92 + Edit(*Company) error
  93 + FindOne(queryOptions CompanyFindOneOptions) (Company, error)
  94 + Find(queryOptions CompanyFindOptions) (int64, []Company, error)
  95 +}
@@ -37,9 +37,9 @@ type OrderBase struct { @@ -37,9 +37,9 @@ type OrderBase struct {
37 //交货编号 37 //交货编号
38 DeliveryCode string `json:"deliveryCode"` 38 DeliveryCode string `json:"deliveryCode"`
39 //买家 39 //买家
40 - Buyer *Buyer `json:"buyer"` 40 + Buyer Buyer `json:"buyer"`
41 //订单区域信息 41 //订单区域信息
42 - RegionInfo *RegionInfo `json:"regionInfo"` 42 + RegionInfo RegionInfo `json:"regionInfo"`
43 //订单对应的合伙人 43 //订单对应的合伙人
44 PartnerId int64 `json:"partnerId"` 44 PartnerId int64 `json:"partnerId"`
45 PartnerInfo Partner `json:"partnerInfo"` 45 PartnerInfo Partner `json:"partnerInfo"`
@@ -59,6 +59,8 @@ type OrderBase struct { @@ -59,6 +59,8 @@ type OrderBase struct {
59 IsDisable int `json:"isDisable"` 59 IsDisable int `json:"isDisable"`
60 //分红支付状态 60 //分红支付状态
61 BonusStatus int `json:"bonusStatus"` 61 BonusStatus int `json:"bonusStatus"`
  62 + //公司
  63 + CompanyId int64 `json:"companyId"`
62 } 64 }
63 65
64 type OrderCompute struct { 66 type OrderCompute struct {
@@ -178,7 +180,8 @@ func (order *OrderBase) Compute() error { @@ -178,7 +180,8 @@ func (order *OrderBase) Compute() error {
178 } 180 }
179 181
180 type OrderBaseFindOneQuery struct { 182 type OrderBaseFindOneQuery struct {
181 - OrderId int64 183 + OrderId int64
  184 + CompanyId int64
182 } 185 }
183 186
184 type OrderBaseFindQuery struct { 187 type OrderBaseFindQuery struct {
@@ -188,11 +191,12 @@ type OrderBaseFindQuery struct { @@ -188,11 +191,12 @@ type OrderBaseFindQuery struct {
188 Offset int 191 Offset int
189 Limit int 192 Limit int
190 OrderType int 193 OrderType int
  194 + CompanyId int64
191 } 195 }
192 196
193 type OrderBaseRepository interface { 197 type OrderBaseRepository interface {
194 Save(order *OrderBase) error 198 Save(order *OrderBase) error
195 FindOne(qureyOptions OrderBaseFindOneQuery) (*OrderBase, error) 199 FindOne(qureyOptions OrderBaseFindOneQuery) (*OrderBase, error)
196 Find(queryOptions OrderBaseFindQuery) ([]OrderBase, int, error) 200 Find(queryOptions OrderBaseFindQuery) ([]OrderBase, int, error)
197 - Remove(id int64) error 201 + Remove(id int64, companyId int64) error
198 } 202 }
@@ -48,6 +48,8 @@ type OrderGood struct { @@ -48,6 +48,8 @@ type OrderGood struct {
48 CurrentBonusStatus OrderGoodBonusStatus `json:"-"` 48 CurrentBonusStatus OrderGoodBonusStatus `json:"-"`
49 ///核算订单相关数据 49 ///核算订单相关数据
50 GoodCompute GoodCompute `json:"goodCompute"` 50 GoodCompute GoodCompute `json:"goodCompute"`
  51 + //公司
  52 + CompanyId int64
51 } 53 }
52 54
53 type GoodCompute struct { 55 type GoodCompute struct {
@@ -170,13 +172,14 @@ func (good *OrderGood) Compute() error { @@ -170,13 +172,14 @@ func (good *OrderGood) Compute() error {
170 } 172 }
171 173
172 type OrderGoodFindQuery struct { 174 type OrderGoodFindQuery struct {
173 - OrderId int64  
174 - Offset int  
175 - Limit int 175 + OrderId int64
  176 + Offset int
  177 + Limit int
  178 + CompanyId int64
176 } 179 }
177 180
178 type OrderGoodRepository interface { 181 type OrderGoodRepository interface {
179 Save(order []OrderGood) error 182 Save(order []OrderGood) error
180 Find(queryOptions OrderGoodFindQuery) ([]OrderGood, int, error) 183 Find(queryOptions OrderGoodFindQuery) ([]OrderGood, int, error)
181 - Remove(orderid int64, ids ...int64) error 184 + Remove(orderid int64, companyId int64, ids ...int64) error
182 } 185 }
  1 +package domain
  2 +
  3 +// 合伙人分类信息
  4 +type PartnerCategory struct {
  5 + // 唯一标识
  6 + Id int64 `json:"id"`
  7 + // 名称
  8 + Name string `json:"name,omitempty"`
  9 +}
  10 +
  11 +type PartnerCategoryFindQuery struct {
  12 + Ids []int64
  13 +}
  14 +type PartnerCategoryRepository interface {
  15 + Find(PartnerCategoryFindQuery) (int, []PartnerCategory, error)
  16 +}
1 package domain 1 package domain
2 2
3 import ( 3 import (
4 - "fmt"  
5 "time" 4 "time"
6 ) 5 )
7 6
@@ -12,25 +11,23 @@ const ( @@ -12,25 +11,23 @@ const (
12 ) 11 )
13 12
14 //合伙类别 (1.事业合伙人 2.业务合伙人 3.研发合伙人) 13 //合伙类别 (1.事业合伙人 2.业务合伙人 3.研发合伙人)
15 -const (  
16 - PARTNER_CATEGORY_1 int = 1  
17 - PARTNER_CATEGORY_2 int = 2  
18 - PARTNER_CATEGORY_3 int = 3  
19 - PARTNER_CATEGORY_4 int = 4  
20 -) 14 +// const (
  15 +// PARTNER_CATEGORY_1 int = 1
  16 +// PARTNER_CATEGORY_2 int = 2
  17 +// PARTNER_CATEGORY_3 int = 3
  18 +// PARTNER_CATEGORY_4 int = 4
  19 +// )
21 20
22 -//partnerCategoryMap 合伙类别键值对 (只读,请勿在运行时修改)  
23 -var partnerCategoryMap = map[int]string{  
24 - PARTNER_CATEGORY_1: "事业合伙人",  
25 - PARTNER_CATEGORY_2: "业务合伙人",  
26 - PARTNER_CATEGORY_3: "研发合伙人",  
27 - PARTNER_CATEGORY_4: "业务-产品应用合伙人",  
28 -} 21 +// //partnerCategoryMap 合伙类别键值对 (只读,请勿在运行时修改)
  22 +// var partnerCategoryMap = map[int]string{
  23 +// PARTNER_CATEGORY_1: "事业合伙人",
  24 +// PARTNER_CATEGORY_2: "业务合伙人",
  25 +// PARTNER_CATEGORY_3: "研发合伙人",
  26 +// PARTNER_CATEGORY_4: "业务-产品应用合伙人",
  27 +// }
29 28
30 type PartnerInfo struct { 29 type PartnerInfo struct {
31 Partner Partner `json:"partner"` 30 Partner Partner `json:"partner"`
32 - //合伙类别  
33 - PartnerCategory int `json:"partnerCategory"`  
34 // 登录密码 31 // 登录密码
35 Password string `json:"password"` 32 Password string `json:"password"`
36 // 状态(1:启用或者0:禁用) 33 // 状态(1:启用或者0:禁用)
@@ -41,38 +38,30 @@ type PartnerInfo struct { @@ -41,38 +38,30 @@ type PartnerInfo struct {
41 UpdateAt time.Time `json:"updateAt"` 38 UpdateAt time.Time `json:"updateAt"`
42 //合作时间 39 //合作时间
43 CooperateTime time.Time `json:"cooperateTime"` 40 CooperateTime time.Time `json:"cooperateTime"`
44 - //关联业务员//所属区域信息  
45 - RegionInfo *RegionInfo `json:"regionInfo"`  
46 - 41 + //所属区域信息
  42 + RegionInfo RegionInfo `json:"regionInfo"`
  43 + //关联业务员
47 Salesman []Salesman `json:"salesman"` 44 Salesman []Salesman `json:"salesman"`
  45 + //合伙人分类
  46 + PartnerCategoryInfos []PartnerCategory `json:"partnerCategoryInfos"`
  47 + //合伙类别
  48 + PartnerCategory int `json:"partnerCategory"`
  49 + //公司id
  50 + CompanyId int64 `json:"companyId"`
48 } 51 }
49 52
50 -func (p *PartnerInfo) GetPartnerCategory() map[int]string {  
51 - categoryMap := map[int]string{}  
52 - for k, v := range partnerCategoryMap {  
53 - //合伙类别 按二进制位区分  
54 - if (p.PartnerCategory & k) > 0 {  
55 - categoryMap[k] = v  
56 - }  
57 - }  
58 - return categoryMap 53 +func (p *PartnerInfo) IsUsable() bool {
  54 + return p.Status == PARTNER_STATUS_YES
59 } 55 }
60 56
61 -func (p *PartnerInfo) SetPartnerCategory(category []int) error {  
62 - n := 0  
63 - for _, v := range category {  
64 - if _, ok := partnerCategoryMap[v]; !ok {  
65 - return fmt.Errorf("未知的合伙人类型:%d", v)  
66 - }  
67 - n += v  
68 - }  
69 - p.PartnerCategory = n  
70 - return nil 57 +func (p *PartnerInfo) IsCompany(companyId int64) bool {
  58 + return p.CompanyId == companyId
71 } 59 }
72 60
73 type PartnerFindOneQuery struct { 61 type PartnerFindOneQuery struct {
74 UserId int64 62 UserId int64
75 AccountEqual string 63 AccountEqual string
  64 + CompanyId int64
76 } 65 }
77 66
78 type PartnerFindQuery struct { 67 type PartnerFindQuery struct {
@@ -81,10 +70,12 @@ type PartnerFindQuery struct { @@ -81,10 +70,12 @@ type PartnerFindQuery struct {
81 PartnerCategory []int //合伙人类型 70 PartnerCategory []int //合伙人类型
82 RegionInfo *RegionInfo //区域 71 RegionInfo *RegionInfo //区域
83 PartnerName string //合伙人姓名 72 PartnerName string //合伙人姓名
  73 + CompanyId int64
  74 + Ids []int64
84 } 75 }
85 76
86 type PartnerInfoRepository interface { 77 type PartnerInfoRepository interface {
87 - Save(dm PartnerInfo) (*PartnerInfo, error) 78 + Save(dm *PartnerInfo) error
88 FindOne(queryOptions PartnerFindOneQuery) (*PartnerInfo, error) 79 FindOne(queryOptions PartnerFindOneQuery) (*PartnerInfo, error)
89 Find(queryOptions PartnerFindQuery) ([]PartnerInfo, error) 80 Find(queryOptions PartnerFindQuery) ([]PartnerInfo, error)
90 CountAll(queryOptions PartnerFindQuery) (int, error) 81 CountAll(queryOptions PartnerFindQuery) (int, error)
  1 +package service
  2 +
  3 +type BusinessBonusService interface {
  4 + EnableOrDisable(userid int64) error
  5 +}
  1 +package domain
  2 +
  3 +import "time"
  4 +
  5 +//用户是否可用状态:【1:正常】【 2:禁用】
  6 +const (
  7 + userStatusUsable int8 = 1
  8 + userStatusUnusable int8 = 2
  9 +)
  10 +
  11 +//用户是否是主管 :【1:是主管】【 2:不是主管】
  12 +const (
  13 + UserIsCompanyCharge int8 = 1
  14 + UserIsNotCompanyCharge int8 = 2
  15 +)
  16 +
  17 +//用户类型 1普通用户 2主管理员
  18 +const (
  19 + UserIsNotAdmin int8 = 1
  20 + UserIsAdmin int8 = 2
  21 +)
  22 +
  23 +//Users 企业平台的用户
  24 +type Users struct {
  25 + Id int64 //用户id
  26 + CompanyId int64 //公司id
  27 + OpenId int64 //统一用户中心
  28 + Name string //用户名称
  29 + Sex int8 //性别:【0:未知】【1:男】【2:女】
  30 + JobNum string //工号
  31 + Phone string //手机号,同账号
  32 + PrivatePhone string //私人手机号
  33 + Email string //邮件
  34 + ExtensionNum string //分机号
  35 + EntryTime time.Time //入职时间
  36 + Workspace string //工作地
  37 + Status int8 //状态:【1:正常】【 2:禁用】
  38 + Avatar string ///头像
  39 + Remarks string //备注
  40 + ChargeStatus int8 //是否为当前公司主管 【1:是】【2:否】
  41 + CreateAt time.Time
  42 + UpdateAt time.Time
  43 + Permission []AdminPermissionBase //权限
  44 + AccessPartners []Partner
  45 + AdminType int8 //是否是公司负责人,即超级管理员 1普通用户 2主管理员
  46 +}
  47 +
  48 +//IsUsable 用户是否可用
  49 +func (u Users) IsUsable() bool {
  50 + return u.Status == userStatusUsable
  51 +}
  52 +
  53 +//IsSuperAdmin 用户是否是负责人
  54 +func (u Users) IsSuperAdmin() bool {
  55 + return u.AdminType == UserIsAdmin
  56 +}
  57 +
  58 +func (u Users) InCompany(companyid int64) bool {
  59 + return u.CompanyId == companyid
  60 +}
  61 +
  62 +func (u Users) HasPermissionByCode(code string) bool {
  63 + if u.IsSuperAdmin() {
  64 + return true
  65 + }
  66 + for _, v := range u.Permission {
  67 + if v.Code == code {
  68 + return true
  69 + }
  70 + }
  71 + return false
  72 +}
  73 +
  74 +func (u *Users) Update(m map[string]interface{}) error {
  75 + if v, ok := m["CompanyId"]; ok {
  76 + u.CompanyId = v.(int64)
  77 + }
  78 + if v, ok := m["OpenId"]; ok {
  79 + u.OpenId = v.(int64)
  80 + }
  81 + if v, ok := m["Name"]; ok {
  82 + u.Name = v.(string)
  83 + }
  84 + if v, ok := m["Sex"]; ok {
  85 + u.Sex = v.(int8)
  86 + }
  87 + if v, ok := m["JobNum"]; ok {
  88 + u.JobNum = v.(string)
  89 + }
  90 + if v, ok := m["Phone"]; ok {
  91 + u.Phone = v.(string)
  92 + }
  93 + if v, ok := m["PrivatePhone"]; ok {
  94 + u.PrivatePhone = v.(string)
  95 + }
  96 + if v, ok := m["Email"]; ok {
  97 + u.Email = v.(string)
  98 + }
  99 + if v, ok := m["ExtensionNum"]; ok {
  100 + u.ExtensionNum = v.(string)
  101 + }
  102 + if v, ok := m["EntryTime"]; ok {
  103 + u.EntryTime = v.(time.Time)
  104 + }
  105 + if v, ok := m["Workspace"]; ok {
  106 + u.Workspace = v.(string)
  107 + }
  108 + if v, ok := m["Status"]; ok {
  109 + u.Status = v.(int8)
  110 + }
  111 + if v, ok := m["Avatar"]; ok {
  112 + u.Avatar = v.(string)
  113 + }
  114 + if v, ok := m["Remarks"]; ok {
  115 + u.Remarks = v.(string)
  116 + }
  117 + if v, ok := m["ChargeStatus"]; ok {
  118 + u.ChargeStatus = v.(int8)
  119 + }
  120 + if v, ok := m["Permission"]; ok {
  121 + u.Permission = v.([]AdminPermissionBase)
  122 + }
  123 + if v, ok := m["AccessPartners"]; ok {
  124 + u.AccessPartners = v.([]Partner)
  125 + }
  126 + if v, ok := m["AdminType"]; ok {
  127 + u.AdminType = v.(int8)
  128 + }
  129 + return nil
  130 +}
  131 +
  132 +type UsersFindOneQuery struct {
  133 + Id int64
  134 + Phone string
  135 + CompanyId int64
  136 + OpenId int64
  137 +}
  138 +
  139 +type UsersFindQuery struct {
  140 + AdminType int8
  141 + ChargeStatus int8
  142 + CompanyId int64
  143 + Ids []int64
  144 + Offset int
  145 + Limit int
  146 + UserNameMatch string
  147 +}
  148 +type UsersRepository interface {
  149 + Add(*Users) error
  150 + Edit(*Users) error
  151 + Remove([]int64) error
  152 + FindOne(queryOptions UsersFindOneQuery) (Users, error)
  153 + Find(queryOptions UsersFindQuery) (int, []Users, error)
  154 +}
1 -package dao  
2 -  
3 -import (  
4 - "fmt"  
5 -  
6 - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"  
7 - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"  
8 -)  
9 -  
10 -type AdminUserDao struct {  
11 - transactionContext *transaction.TransactionContext  
12 -}  
13 -  
14 -func NewAdminUserDao(transactionContext *transaction.TransactionContext) (*AdminUserDao, error) {  
15 - if transactionContext == nil {  
16 - return nil, fmt.Errorf("transactionContext参数不能为nil")  
17 - } else {  
18 - return &AdminUserDao{  
19 - transactionContext: transactionContext,  
20 - }, nil  
21 - }  
22 -}  
23 -  
24 -//UpdatePassword ....  
25 -func (dao *AdminUserDao) UpdatePassword(id int64, pwd string) error {  
26 - tx := dao.transactionContext.PgDd  
27 - m := &models.AdminUser{}  
28 - err := tx.Model(m).Where("id=?", id).First()  
29 - if err != nil {  
30 - return err  
31 - }  
32 - _, err = tx.Model(m).Where("id=?", id).  
33 - Set("password=?", pwd).  
34 - Update()  
35 - return err  
36 -}  
37 -  
38 -//UpdatePassword ....  
39 -func (dao *AdminUserDao) UpdateIsUsable(id int64, isUsable bool) error {  
40 - tx := dao.transactionContext.PgDd  
41 - m := &models.AdminUser{}  
42 - err := tx.Model(m).Where("id=?", id).First()  
43 - if err != nil {  
44 - return err  
45 - }  
46 - _, err = tx.Model(m).Where("id=?", id).  
47 - Set("is_usable=?", isUsable).  
48 - Update()  
49 - return err  
50 -}  
51 -  
52 -//AdminUserAccountExist ...  
53 -func (dao *AdminUserDao) AdminUserAccountExist(account string) (bool, error) {  
54 - tx := dao.transactionContext.PgDd  
55 - m := &models.AdminUser{}  
56 - ok, err := tx.Model(m).  
57 - Where("account=?", account).  
58 - Exists()  
59 -  
60 - return ok, err  
61 -}  
62 -  
63 -func (dao *AdminUserDao) AdminUserIsDefault(id int64) (bool, error) {  
64 - tx := dao.transactionContext.PgDd  
65 - m := &models.AdminUser{}  
66 - err := tx.Model(m).  
67 - Where("id=?", id).  
68 - Column("is_default").  
69 - First()  
70 -  
71 - return m.IsDefault, err  
72 -}  
  1 +package dao
  2 +
  3 +import (
  4 + "fmt"
  5 + "strings"
  6 + "time"
  7 +
  8 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
  9 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
  10 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
  11 +)
  12 +
  13 +type BusinessBonusDao struct {
  14 + transactionContext *transaction.TransactionContext
  15 +}
  16 +
  17 +func NewBusinessBonusDao(transactionContext *transaction.TransactionContext) (*BusinessBonusDao, error) {
  18 + if transactionContext == nil {
  19 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  20 + } else {
  21 + return &BusinessBonusDao{
  22 + transactionContext: transactionContext,
  23 + }, nil
  24 + }
  25 +}
  26 +
  27 +type CustomBusinessBonus struct {
  28 + Id int64
  29 + Bonus string
  30 + BonusNot string
  31 + BonusExpense string
  32 + BonusHas string
  33 + BonusStatus int8
  34 + PartnerName string
  35 + UpdateAt time.Time
  36 +}
  37 +
  38 +func (dao BusinessBonusDao) SearchBusinessBonus(partnerId int64, partnerNameMatch string,
  39 + companyId int64, limit int, offset int) ([]CustomBusinessBonus, error) {
  40 + sql := `SELECT business_bonus.id, business_bonus.bonus,business_bonus.bonus_not
  41 + ,business_bonus.bonus_expense,business_bonus.bonus_status,business_bonus.update_at
  42 + ,partner_info.partner_name,business_bonus.bonus_has
  43 + FROM business_bonus
  44 + JOIN partner_info ON business_bonus.partner_info_id=partner_info.id
  45 + WHERE business_bonus.is_disable=? AND business_bonus.company_id = ? `
  46 + partnerCondition := []string{}
  47 + allParam := []interface{}{domain.BUSINESS_BONUS_ENABLE, companyId}
  48 + if partnerId > 0 {
  49 + partnerCondition = append(partnerCondition, ` business_bonus.partner_info_id=? `)
  50 + allParam = append(allParam, partnerId)
  51 + }
  52 + if len(partnerNameMatch) > 0 {
  53 + allParam = append(allParam, "%"+partnerNameMatch+"%")
  54 + partnerCondition = append(partnerCondition, ` partner_info.partner_name like ? `)
  55 + }
  56 + if len(partnerCondition) > 0 {
  57 + sql += fmt.Sprintf(" AND (%s)", strings.Join(partnerCondition, " OR "))
  58 + }
  59 + sql += `ORDER BY business_bonus.id DESC limit ? OFFSET ? `
  60 + allParam = append(allParam, limit, offset)
  61 + tx := dao.transactionContext.PgTx
  62 + var (
  63 + result []CustomBusinessBonus
  64 + err error
  65 + )
  66 + _, err = tx.Query(&result, sql, allParam...)
  67 + return result, err
  68 +}
  69 +
  70 +func (dao BusinessBonusDao) CountBusinessBonus(partnerId int64, partnerNameMatch string,
  71 + companyId int64, limit int, offset int) (int, error) {
  72 + sql := `SELECT count(*)
  73 + FROM business_bonus
  74 + JOIN partner_info ON business_bonus.partner_info_id=partner_info.id
  75 + WHERE business_bonus.is_disable=? AND business_bonus.company_id = ? `
  76 + partnerCondition := []string{}
  77 + allParam := []interface{}{domain.BUSINESS_BONUS_ENABLE, companyId}
  78 + if partnerId > 0 {
  79 + partnerCondition = append(partnerCondition, ` business_bonus.partner_info_id=? `)
  80 + allParam = append(allParam, partnerId)
  81 + }
  82 + if len(partnerNameMatch) > 0 {
  83 + allParam = append(allParam, "%"+partnerNameMatch+"%")
  84 + partnerCondition = append(partnerCondition, ` partner_info.partner_name like ? `)
  85 + }
  86 + if len(partnerCondition) > 0 {
  87 + sql += fmt.Sprintf(" AND (%s)", strings.Join(partnerCondition, " OR "))
  88 + }
  89 + tx := dao.transactionContext.PgTx
  90 + var (
  91 + result int
  92 + err error
  93 + )
  94 + _, err = tx.Query(&result, sql, allParam...)
  95 + return result, err
  96 +}
  97 +
  98 +func (dao BusinessBonusDao) ExistBusinessBonus(userId int64) (bool, error) {
  99 + tx := dao.transactionContext.PgTx
  100 + ok, err := tx.Model(&models.BusinessBonus{}).
  101 + Where("partner_info_id=?", userId).
  102 + Exists()
  103 + return ok, err
  104 +}
@@ -32,10 +32,10 @@ func (dao OrderBaseDao) OrderCodeExist(code string, notId ...int64) (bool, error @@ -32,10 +32,10 @@ func (dao OrderBaseDao) OrderCodeExist(code string, notId ...int64) (bool, error
32 return ok, err 32 return ok, err
33 } 33 }
34 34
35 -func (dao OrderBaseDao) DeliveryCodeExist(code string, notId ...int64) (bool, error) { 35 +func (dao OrderBaseDao) DeliveryCodeExist(code string, companyId int64, notId ...int64) (bool, error) {
36 tx := dao.transactionContext.PgDd 36 tx := dao.transactionContext.PgDd
37 m := &models.OrderBase{} 37 m := &models.OrderBase{}
38 - query := tx.Model(m).Where("delivery_code=?", code) 38 + query := tx.Model(m).Where("delivery_code=?", code).Where("company_id=?", companyId)
39 if len(notId) > 0 { 39 if len(notId) > 0 {
40 query = query.WhereIn("id not in(?)", notId) 40 query = query.WhereIn("id not in(?)", notId)
41 } 41 }
@@ -21,12 +21,24 @@ func NewPartnerInfoDao(transactionContext *transaction.TransactionContext) (*Par @@ -21,12 +21,24 @@ func NewPartnerInfoDao(transactionContext *transaction.TransactionContext) (*Par
21 } 21 }
22 } 22 }
23 23
24 -func (dao PartnerInfoDao) PartnerAccountExist(account string) (bool, error) { 24 +func (dao PartnerInfoDao) PartnerAccountExist(account string, companyId int64) (bool, error) {
25 tx := dao.transactionContext.PgDd 25 tx := dao.transactionContext.PgDd
26 m := &models.PartnerInfo{} 26 m := &models.PartnerInfo{}
27 ok, err := tx.Model(m). 27 ok, err := tx.Model(m).
28 Where("account=?", account). 28 Where("account=?", account).
  29 + Where("company_id=?", companyId).
29 Exists() 30 Exists()
30 31
31 return ok, err 32 return ok, err
32 } 33 }
  34 +
  35 +func (dao PartnerInfoDao) UpdatePartnerStatus(ids []int64, companyId int64, status int) error {
  36 + tx := dao.transactionContext.PgDd
  37 + m := &models.PartnerInfo{}
  38 + _, err := tx.Model(m).
  39 + WhereIn("id in (?)", ids).
  40 + Where("company_id=?", companyId).
  41 + Set("status=?", status).
  42 + Update()
  43 + return err
  44 +}
  1 +package dao
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
  7 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
  8 +)
  9 +
  10 +type UsersDao struct {
  11 + transactionContext *transaction.TransactionContext
  12 +}
  13 +
  14 +func NewUsersDao(transactionContext *transaction.TransactionContext) (*UsersDao, error) {
  15 + if transactionContext == nil {
  16 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  17 + } else {
  18 + return &UsersDao{
  19 + transactionContext: transactionContext,
  20 + }, nil
  21 + }
  22 +}
  23 +
  24 +func (dao UsersDao) UpdateUserStatus(ids []int64, ststus int8) error {
  25 + tx := dao.transactionContext.PgTx
  26 + m := &models.Users{}
  27 + _, err := tx.Model(m).
  28 + Set("status=?", ststus).
  29 + WhereIn("id in(?)", ids).
  30 + Update()
  31 + return err
  32 +}
  1 +package domainService
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
  5 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/dao"
  6 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
  7 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/repository"
  8 +)
  9 +
  10 +type BusinessBonusService struct {
  11 + transactionContext *transaction.TransactionContext
  12 +}
  13 +
  14 +func NewBusinessBonusService(tcx *transaction.TransactionContext) *BusinessBonusService {
  15 + return &BusinessBonusService{
  16 + transactionContext: tcx,
  17 + }
  18 +}
  19 +func (srv BusinessBonusService) EnableOrDisable(parntnerId int64) error {
  20 + var (
  21 + bonusDao, _ = dao.NewBusinessBonusDao(srv.transactionContext)
  22 + bonusReponsitory, _ = repository.NewBusinessBonusRepository(srv.transactionContext)
  23 + partnerReponsitory, _ = repository.NewPartnerInfoRepository(srv.transactionContext)
  24 +
  25 + err error
  26 + partnerHasInBonus bool
  27 + partnerData *domain.PartnerInfo
  28 + partnerHasBusinessCategory bool
  29 + )
  30 + partnerHasInBonus, err = bonusDao.ExistBusinessBonus(parntnerId)
  31 + if err != nil {
  32 + return err
  33 + }
  34 + partnerData, err = partnerReponsitory.FindOne(domain.PartnerFindOneQuery{UserId: parntnerId})
  35 + if err != nil {
  36 + return err
  37 + }
  38 + for _, v := range partnerData.PartnerCategoryInfos {
  39 + if v.Id == 2 {
  40 + partnerHasBusinessCategory = true
  41 + break
  42 + }
  43 + }
  44 + if partnerHasInBonus && partnerHasBusinessCategory {
  45 + //已存在业务分红数据况 && 是业务合伙人类型
  46 + var bonusData *domain.BusinessBonus
  47 + bonusData, err = bonusReponsitory.FindOne(domain.BusinessBonusFindOneQuery{
  48 + PartnerId: parntnerId,
  49 + })
  50 + if bonusData.IsDisable == domain.BUSINESS_BONUS_ENABLE {
  51 + return nil
  52 + }
  53 + bonusData.IsDisable = domain.BUSINESS_BONUS_ENABLE
  54 + err = bonusReponsitory.Edit(bonusData)
  55 + return err
  56 + }
  57 + if partnerHasInBonus && !partnerHasBusinessCategory {
  58 + //已存在业务分红数据况 && 不是业务合伙人类型
  59 + var bonusData *domain.BusinessBonus
  60 + bonusData, err = bonusReponsitory.FindOne(domain.BusinessBonusFindOneQuery{
  61 + PartnerId: parntnerId,
  62 + })
  63 + if bonusData.IsDisable == domain.BUSINESS_BONUS_DISABLE {
  64 + return nil
  65 + }
  66 + bonusData.IsDisable = domain.BUSINESS_BONUS_DISABLE
  67 + err = bonusReponsitory.Edit(bonusData)
  68 + return err
  69 + }
  70 +
  71 + if !partnerHasInBonus && partnerHasBusinessCategory {
  72 + //不存在业务分红数据况 && 是业务合伙人类型
  73 + newBonus := &domain.BusinessBonus{
  74 + PartnerInfoId: partnerData.Partner.Id,
  75 + IsDisable: domain.BUSINESS_BONUS_ENABLE,
  76 + CompanyId: partnerData.CompanyId,
  77 + Bonus: 0,
  78 + }
  79 + err = bonusReponsitory.Add(newBonus)
  80 + return err
  81 + }
  82 +
  83 + return nil
  84 +}
@@ -3,13 +3,13 @@ package models @@ -3,13 +3,13 @@ package models
3 type AdminPermission struct { 3 type AdminPermission struct {
4 tableName struct{} `pg:"admin_permission,alias:admin_permission"` 4 tableName struct{} `pg:"admin_permission,alias:admin_permission"`
5 //id 5 //id
6 - Id int `pg:",pk"` 6 + Id int64 `pg:",pk"`
7 //权限名称、菜单名称 7 //权限名称、菜单名称
8 Name string 8 Name string
9 //权限编码 9 //权限编码
10 Code string 10 Code string
11 //父级id 11 //父级id
12 - ParentId int 12 + ParentId int64
13 //排序编号 13 //排序编号
14 Sort int 14 Sort int
15 //图标 15 //图标
1 -package models  
2 -  
3 -import (  
4 - "context"  
5 - "time"  
6 -  
7 - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"  
8 -  
9 - "github.com/go-pg/pg/v10"  
10 -)  
11 -  
12 -type AdminUser struct {  
13 - tableName struct{} `pg:"admin_user,alias:admin_user"`  
14 - //id  
15 - Id int64 `pg:",pk"`  
16 - //用户账号  
17 - Account string `pg:",unique"`  
18 - //用户名称  
19 - AdminName string  
20 - //账号密码  
21 - Password string  
22 - //是否是默认账号  
23 - IsDefault bool `pg:",use_zero"`  
24 - //账号是否可用  
25 - IsUsable bool `pg:",use_zero"`  
26 - //用户的权限  
27 - Permission []domain.AdminPermissionBase  
28 -  
29 - CreateAt time.Time  
30 - UpdateAt time.Time  
31 -}  
32 -  
33 -var _ pg.BeforeUpdateHook = (*AdminUser)(nil)  
34 -  
35 -func (user *AdminUser) BeforeUpdate(ctx context.Context) (context.Context, error) {  
36 - user.UpdateAt = time.Now()  
37 - return ctx, nil  
38 -}  
39 -  
40 -var _ pg.BeforeInsertHook = (*AdminUser)(nil)  
41 -  
42 -func (user *AdminUser) BeforeInsert(ctx context.Context) (context.Context, error) {  
43 - user.CreateAt = time.Now()  
44 - user.UpdateAt = time.Now()  
45 - return ctx, nil  
46 -}  
  1 +package models
  2 +
  3 +import (
  4 + "context"
  5 + "time"
  6 +
  7 + "github.com/go-pg/pg/v10"
  8 +)
  9 +
  10 +// 业务分红信息
  11 +type BusinessBonus struct {
  12 + tableName struct{} `pg:"business_bonus"`
  13 + // 唯一标识
  14 + Id int64 `pg:",pk"`
  15 + // 公司编号
  16 + CompanyId int64
  17 + // 合伙人信息Id
  18 + PartnerInfoId int64
  19 + // 应收分红
  20 + Bonus float64 `pg:",use_zero"`
  21 + // 未收分红
  22 + BonusNot float64 `pg:",use_zero"`
  23 + // 分红支出
  24 + BonusExpense float64 `pg:",use_zero"`
  25 + //已收分红
  26 + BonusHas float64 `pg:",use_zero"`
  27 + //是否有效【0;无效】【1:有效】
  28 + IsDisable int8 `pg:",use_zero"`
  29 + // 分红状态 1:待支付分红 2:已支付分红
  30 + BonusStatus int8 `pg:",use_zero"`
  31 + // 创建时间
  32 + CreateAt time.Time
  33 + // 更新时间
  34 + UpdateAt time.Time
  35 + // 删除时间
  36 + DeleteAt time.Time
  37 +}
  38 +
  39 +var _ pg.BeforeUpdateHook = (*BusinessBonus)(nil)
  40 +
  41 +func (bonus *BusinessBonus) BeforeUpdate(ctx context.Context) (context.Context, error) {
  42 + bonus.UpdateAt = time.Now()
  43 + return ctx, nil
  44 +}
  45 +
  46 +var _ pg.BeforeInsertHook = (*BusinessBonus)(nil)
  47 +
  48 +func (bonus *BusinessBonus) BeforeInsert(ctx context.Context) (context.Context, error) {
  49 + bonus.CreateAt = time.Now()
  50 + return ctx, nil
  51 +}
  1 +package models
  2 +
  3 +import (
  4 + "context"
  5 + "time"
  6 +
  7 + "github.com/go-pg/pg/v10"
  8 +)
  9 +
  10 +// 公司信息
  11 +type Company struct {
  12 + tableName struct{} `pg:"company"`
  13 + // 唯一标识
  14 + Id int64 `pg:",pk"`
  15 + // 名称
  16 + Name string
  17 + //简称
  18 + Abbreviation string
  19 + // 手机号码
  20 + Phone string
  21 + // 公司logo
  22 + Logo string
  23 + // 备注
  24 + Remarks string
  25 + // 总后台的公司id
  26 + AdminCompanyId int
  27 + // 状态 1正常 2禁用
  28 + //Status int8
  29 + //是否开启机会模块,是否有效【1:有效】【2:无效】
  30 + Enable int8
  31 + // 创建时间
  32 + CreateAt time.Time
  33 + // 更新时间
  34 + UpdateAt time.Time
  35 + // 删除时间
  36 + DeleteAt time.Time
  37 +}
  38 +
  39 +var _ pg.BeforeUpdateHook = (*Company)(nil)
  40 +
  41 +func (c *Company) BeforeUpdate(ctx context.Context) (context.Context, error) {
  42 + c.UpdateAt = time.Now()
  43 + return ctx, nil
  44 +}
  45 +
  46 +var _ pg.BeforeInsertHook = (*Company)(nil)
  47 +
  48 +func (c *Company) BeforeInsert(ctx context.Context) (context.Context, error) {
  49 + c.CreateAt = time.Now()
  50 + c.UpdateAt = time.Now()
  51 + return ctx, nil
  52 +}
1 -package models  
2 -  
3 -import (  
4 - "context"  
5 - "time"  
6 -  
7 - "github.com/go-pg/pg/v10"  
8 - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"  
9 -)  
10 -  
11 -type Order struct {  
12 - tableName struct{} `pg:"order"`  
13 - //id  
14 - Id int64 `pg:",pk"`  
15 - //订单类型 1:实际订单 2:意向订单  
16 - OrderType int `pg:",notnull,default:1"`  
17 - //订单编号  
18 - OrderCode string `pg:",unique,notnull`  
19 - //订单名称  
20 - OrderName string  
21 - //订单状态  
22 - OrderStatus int `pg:",notnull,default:1"`  
23 - //订单数量  
24 - OrderCount int  
25 - //实际订单数量  
26 - OrderActualCount int  
27 - //订单金额  
28 - OrderAmount float64  
29 - //订单实际金额  
30 - OrderActualAmount float64  
31 - //订单已支付金额(货款)  
32 - OrderPaymentAmount float64 `pg:",use_zero"`  
33 - //最后分红状态  
34 - BonusStatus int `pg:",default:1"`  
35 - //订单区域信息  
36 - OrderRegionInfo domain.RegionInfo  
37 -  
38 - Buyer domain.Buyer  
39 - //合伙人编号  
40 - PartnerId int64  
41 - PartnerInfo PartnerInfo `pg:"fk:partner_id"`  
42 - //合伙人分红百分比  
43 - PartnerBonusPercent float64  
44 - //业务员分红百分比  
45 - SalesmanBonusPercent float64  
46 -  
47 - //创建时间  
48 - CreateAt time.Time  
49 - //更新时间  
50 - UpdateAt time.Time  
51 -  
52 - //上一次查看时间 已读情况  
53 - LastViewTime time.Time  
54 - //理由  
55 - Reason string  
56 -}  
57 -  
58 -var _ pg.BeforeUpdateHook = (*Order)(nil)  
59 -  
60 -func (or *Order) BeforeUpdate(ctx context.Context) (context.Context, error) {  
61 - or.UpdateAt = time.Now()  
62 - return ctx, nil  
63 -}  
64 -  
65 -var _ pg.BeforeInsertHook = (*Order)(nil)  
66 -  
67 -func (or *Order) BeforeInsert(ctx context.Context) (context.Context, error) {  
68 - or.CreateAt = time.Now()  
69 - or.UpdateAt = time.Now()  
70 - return ctx, nil  
71 -}  
@@ -20,9 +20,9 @@ type OrderBase struct { @@ -20,9 +20,9 @@ type OrderBase struct {
20 //交货编号 20 //交货编号
21 DeliveryCode string 21 DeliveryCode string
22 //买家 22 //买家
23 - Buyer *domain.Buyer 23 + Buyer domain.Buyer
24 //订单区域信息 24 //订单区域信息
25 - RegionInfo *domain.RegionInfo 25 + RegionInfo domain.RegionInfo
26 //订单对应的合伙人 26 //订单对应的合伙人
27 PartnerId int64 27 PartnerId int64
28 //业务员抽成比例 28 //业务员抽成比例
@@ -62,6 +62,7 @@ type OrderBase struct { @@ -62,6 +62,7 @@ type OrderBase struct {
62 IsDisable int `pg:",use_zero"` 62 IsDisable int `pg:",use_zero"`
63 //分红支付状态 63 //分红支付状态
64 BonusStatus int 64 BonusStatus int
  65 + CompanyId int64
65 } 66 }
66 67
67 var _ pg.BeforeUpdateHook = (*OrderBase)(nil) 68 var _ pg.BeforeUpdateHook = (*OrderBase)(nil)
@@ -36,5 +36,6 @@ type OrderGood struct { @@ -36,5 +36,6 @@ type OrderGood struct {
36 //分红状态 36 //分红状态
37 BonusStatus int 37 BonusStatus int
38 //备注信息 38 //备注信息
39 - Remark string 39 + Remark string
  40 + CompanyId int64
40 } 41 }
1 -package models  
2 -  
3 -import "time"  
4 -  
5 -type OrderPayment struct {  
6 - tableName struct{} `pg:"order_payment"`  
7 - //编号  
8 - Id int64 `pg:",pk"`  
9 - //订单编号  
10 - OrderId int64  
11 - //合伙人编号  
12 - PartnerId int64  
13 - //支付货款  
14 - PaymentAmount float64 `pg:",notnull,default:0"`  
15 - //分红金额  
16 - BonusAmount float64  
17 - //分红状态 1.等待支付分红 2.已支付分红  
18 - BonusStatus int `pg:",notnull,default:1"`  
19 - //创建时间  
20 - CreateAt time.Time  
21 - //更新时间  
22 - UpdateAt time.Time  
23 -}  
  1 +package models
  2 +
  3 +// 合伙人分类信息
  4 +type PartnerCategoryInfo struct {
  5 + tableName struct{} `pg:"partner_category_info"`
  6 + // 唯一标识
  7 + Id int64
  8 + // 名称
  9 + Name string
  10 +}
@@ -9,7 +9,7 @@ import ( @@ -9,7 +9,7 @@ import (
9 ) 9 )
10 10
11 type PartnerInfo struct { 11 type PartnerInfo struct {
12 - tableName struct{} `pg:"partner_info,alias:partner_info"` 12 + tableName struct{} `pg:"partner_info"`
13 // 合伙人ID 13 // 合伙人ID
14 Id int64 `pg:",pk"` 14 Id int64 `pg:",pk"`
15 // 合伙人姓名 15 // 合伙人姓名
@@ -20,10 +20,8 @@ type PartnerInfo struct { @@ -20,10 +20,8 @@ type PartnerInfo struct {
20 Password string 20 Password string
21 // 状态(1:启用或者0:禁用) 21 // 状态(1:启用或者0:禁用)
22 Status int `pg:",use_zero"` 22 Status int `pg:",use_zero"`
23 - // 合伙类别 (1.研发合伙人 2.业务合伙人 3.事业)  
24 - PartnerCategory int `pg:",default:1"` //partner_category  
25 //所属区域信息 23 //所属区域信息
26 - RegionInfo *domain.RegionInfo 24 + RegionInfo domain.RegionInfo
27 //创建时间 25 //创建时间
28 CreateAt time.Time 26 CreateAt time.Time
29 //更新时间 27 //更新时间
@@ -32,6 +30,12 @@ type PartnerInfo struct { @@ -32,6 +30,12 @@ type PartnerInfo struct {
32 CooperateTime time.Time 30 CooperateTime time.Time
33 //关联业务员 31 //关联业务员
34 Salesman []domain.Salesman 32 Salesman []domain.Salesman
  33 + // 合伙类别 (1.研发合伙人 2.业务合伙人 3.事业)
  34 + PartnerCategory int `pg:",default:1"` //partner_category
  35 + //合伙类别
  36 + PartnerCategoryInfos []domain.PartnerCategory
  37 + //公司id
  38 + CompanyId int64
35 } 39 }
36 40
37 var _ pg.BeforeUpdateHook = (*PartnerInfo)(nil) 41 var _ pg.BeforeUpdateHook = (*PartnerInfo)(nil)
  1 +package models
  2 +
  3 +import (
  4 + "context"
  5 + "time"
  6 +
  7 + "github.com/go-pg/pg/v10"
  8 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
  9 +)
  10 +
  11 +type Users struct {
  12 + tableName struct{} `pg:"users"`
  13 + Id int64 `pg:",pk"` //用户id
  14 + CompanyId int64 //公司id
  15 + OpenId int64 //统一用户中心
  16 + Name string //用户名称
  17 + Sex int8 //性别:【0:未知】【1:男】【2:女】
  18 + JobNum string //工号
  19 + Phone string //手机号,同账号
  20 + PrivatePhone string //私人手机号
  21 + Email string //邮件
  22 + ExtensionNum string //分机号
  23 + EntryTime time.Time //入职时间
  24 + Workspace string //工作地
  25 + Status int8 //状态:【1:正常】【 2:禁用】
  26 + Avatar string ///头像
  27 + Remarks string //备注
  28 + AdminType int8 //是否为当前公司负责人 【1:是】【2:否】
  29 + ChargeStatus int8 //是否为当前公司主管 【1:是】【2:否】
  30 + Permission []domain.AdminPermissionBase //权限
  31 + AccessPartners []domain.Partner //可查看的合伙人
  32 + CreateAt time.Time
  33 + UpdateAt time.Time
  34 + DeleteAt time.Time
  35 +}
  36 +
  37 +var _ pg.BeforeUpdateHook = (*Users)(nil)
  38 +
  39 +func (user *Users) BeforeUpdate(ctx context.Context) (context.Context, error) {
  40 + user.UpdateAt = time.Now()
  41 + return ctx, nil
  42 +}
  43 +
  44 +var _ pg.BeforeInsertHook = (*Users)(nil)
  45 +
  46 +func (user *Users) BeforeInsert(ctx context.Context) (context.Context, error) {
  47 + user.CreateAt = time.Now()
  48 + user.UpdateAt = time.Now()
  49 + return ctx, nil
  50 +}
1 package transaction 1 package transaction
2 2
3 -import "github.com/go-pg/pg/v10" 3 +import (
  4 + "github.com/go-pg/pg/v10"
  5 + "github.com/go-pg/pg/v10/orm"
  6 +)
4 7
5 type TransactionContext struct { 8 type TransactionContext struct {
6 PgDd *pg.DB 9 PgDd *pg.DB
@@ -26,6 +29,13 @@ func (transactionContext *TransactionContext) RollbackTransaction() error { @@ -26,6 +29,13 @@ func (transactionContext *TransactionContext) RollbackTransaction() error {
26 return err 29 return err
27 } 30 }
28 31
  32 +func (transactionContext *TransactionContext) GetDB() orm.DB {
  33 + if transactionContext.PgTx != nil {
  34 + return transactionContext.PgTx
  35 + }
  36 + return transactionContext.PgDd
  37 +}
  38 +
29 func NewPGTransactionContext(pgDd *pg.DB) *TransactionContext { 39 func NewPGTransactionContext(pgDd *pg.DB) *TransactionContext {
30 return &TransactionContext{ 40 return &TransactionContext{
31 PgDd: pgDd, 41 PgDd: pgDd,
1 package repository 1 package repository
2 2
3 import ( 3 import (
  4 + "errors"
4 "fmt" 5 "fmt"
5 6
6 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" 7 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
@@ -29,23 +30,19 @@ func (reponsitory AdminPermissionRepository) transformPgModelToDomainModel(permi @@ -29,23 +30,19 @@ func (reponsitory AdminPermissionRepository) transformPgModelToDomainModel(permi
29 Name: permissionModel.Name, 30 Name: permissionModel.Name,
30 Icon: permissionModel.Icon, 31 Icon: permissionModel.Icon,
31 Code: permissionModel.Code, 32 Code: permissionModel.Code,
  33 + Sort: permissionModel.Sort,
32 } 34 }
33 return result, nil 35 return result, nil
34 } 36 }
35 37
36 -func (reponsitory AdminPermissionRepository) Find(queryOptions domain.AdminPermissionFindQuery) ([]domain.AdminPermission, error) { 38 +func (reponsitory AdminPermissionRepository) Find(queryOptions domain.PermissionFindOption) ([]domain.AdminPermission, error) {
37 db := reponsitory.transactionContext.PgDd 39 db := reponsitory.transactionContext.PgDd
38 permissionModels := make([]models.AdminPermission, 0) 40 permissionModels := make([]models.AdminPermission, 0)
39 query := db.Model(&permissionModels) 41 query := db.Model(&permissionModels)
40 - if queryOptions.ParentId != nil {  
41 - query = query.Where("parent_id=?", queryOptions.ParentId)  
42 - }  
43 - if len(queryOptions.NotCode) > 0 {  
44 - query = query.WhereIn("code not in (?) ", queryOptions.NotCode)  
45 - }  
46 - if len(queryOptions.IdsIn) > 0 {  
47 - query = query.WhereIn(" id in (?) ", queryOptions.IdsIn) 42 + if len(queryOptions.Ids) > 0 {
  43 + query = query.WhereIn("id in (?) ", queryOptions.Ids)
48 } 44 }
  45 + query = query.Order("sort")
49 if err := query.Select(); err != nil { 46 if err := query.Select(); err != nil {
50 return nil, err 47 return nil, err
51 } 48 }
@@ -56,3 +53,29 @@ func (reponsitory AdminPermissionRepository) Find(queryOptions domain.AdminPermi @@ -56,3 +53,29 @@ func (reponsitory AdminPermissionRepository) Find(queryOptions domain.AdminPermi
56 } 53 }
57 return result, nil 54 return result, nil
58 } 55 }
  56 +
  57 +func (reponsitory AdminPermissionRepository) FindOne(queryOptions domain.PermissionFindOneOption) (domain.AdminPermission, error) {
  58 + db := reponsitory.transactionContext.PgDd
  59 + var permissionModels models.AdminPermission
  60 + var hasCondition bool
  61 + query := db.Model(&permissionModels)
  62 + if len(queryOptions.Code) > 0 {
  63 + hasCondition = true
  64 + query = query.Where("code=?", queryOptions.Code)
  65 + }
  66 + if queryOptions.Id > 0 {
  67 + hasCondition = true
  68 + query = query.Where("id=?", queryOptions.Id)
  69 + }
  70 + var result domain.AdminPermission
  71 + if !hasCondition {
  72 + return result, errors.New("FindOne 必须要有查询条件")
  73 + }
  74 +
  75 + err := query.First()
  76 + if err != nil {
  77 + return result, err
  78 + }
  79 + result, _ = reponsitory.transformPgModelToDomainModel(&permissionModels)
  80 + return result, nil
  81 +}
1 -package repository  
2 -  
3 -import (  
4 - "fmt"  
5 -  
6 - "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/transaction"  
9 -)  
10 -  
11 -type AdminUserRepository struct {  
12 - transactionContext *transaction.TransactionContext  
13 -}  
14 -  
15 -var (  
16 - _ domain.AdminUserRepository = (*AdminUserRepository)(nil)  
17 -)  
18 -  
19 -func NewAdminUserRepository(transactionContext *transaction.TransactionContext) (*AdminUserRepository, error) {  
20 - if transactionContext == nil {  
21 - return nil, fmt.Errorf("transactionContext参数不能为nil")  
22 - }  
23 - return &AdminUserRepository{transactionContext: transactionContext}, nil  
24 -}  
25 -func (reponsitory AdminUserRepository) transformPgModelToDomainModel(adminuserModel *models.AdminUser) (domain.AdminUser, error) {  
26 - result := domain.AdminUser{  
27 - Id: adminuserModel.Id,  
28 - Account: adminuserModel.Account,  
29 - AdminName: adminuserModel.AdminName,  
30 - IsDefault: adminuserModel.IsDefault,  
31 - CreateAt: adminuserModel.CreateAt,  
32 - IsUsable: adminuserModel.IsUsable,  
33 - Password: adminuserModel.Password,  
34 - Permission: adminuserModel.Permission,  
35 - }  
36 - return result, nil  
37 -}  
38 -  
39 -func (reponsitory AdminUserRepository) FindOne(queryOption domain.AdminUserFindOneQuery) (*domain.AdminUser, error) {  
40 - db := reponsitory.transactionContext.PgDd  
41 - adminuserModel := new(models.AdminUser)  
42 - query := db.Model(adminuserModel)  
43 -  
44 - if queryOption.AdminUserId > 0 {  
45 - query = query.Where("id=?", queryOption.AdminUserId)  
46 - }  
47 - if len(queryOption.AccountEqual) > 0 {  
48 - query = query.Where("account=?", queryOption.AccountEqual)  
49 - }  
50 - err := query.First()  
51 - if err != nil {  
52 - return nil, err  
53 - }  
54 - adminUser, err := reponsitory.transformPgModelToDomainModel(adminuserModel)  
55 - return &adminUser, err  
56 -}  
57 -  
58 -func (reponsitory AdminUserRepository) updateAdminUser(adminuser domain.AdminUser) (*domain.AdminUser, error) {  
59 - tx := reponsitory.transactionContext.PgTx  
60 - adminUserModel := &models.AdminUser{  
61 - Id: adminuser.Id,  
62 - Account: adminuser.Account,  
63 - AdminName: adminuser.AdminName,  
64 - Password: adminuser.Password,  
65 - IsUsable: adminuser.IsUsable,  
66 - Permission: adminuser.Permission,  
67 - }  
68 - _, err := tx.Model(adminUserModel).  
69 - Where("id=?", adminUserModel.Id).  
70 - Column("admin_name", "account", "password", "is_usable", "permission").  
71 - Update()  
72 - if err != nil {  
73 - return nil, fmt.Errorf("更新用户数据失败:%s", err)  
74 - }  
75 - return &adminuser, nil  
76 -}  
77 -  
78 -func (reponsitory AdminUserRepository) addAdminUser(adminuser domain.AdminUser) (*domain.AdminUser, error) {  
79 - tx := reponsitory.transactionContext.PgTx  
80 - adminuserModel := &models.AdminUser{  
81 - Account: adminuser.Account,  
82 - AdminName: adminuser.AdminName,  
83 - Password: adminuser.Password,  
84 - IsDefault: false,  
85 - IsUsable: adminuser.IsUsable,  
86 - Permission: adminuser.Permission,  
87 - }  
88 - //添加用户数据  
89 - _, err := tx.Model(adminuserModel).Insert()  
90 - if err != nil {  
91 - return nil, err  
92 - }  
93 - return nil, nil  
94 -}  
95 -  
96 -func (reponsitory AdminUserRepository) Save(adminuser domain.AdminUser) (*domain.AdminUser, error) {  
97 - if adminuser.Id == 0 {  
98 - return reponsitory.addAdminUser(adminuser)  
99 - }  
100 - return reponsitory.updateAdminUser(adminuser)  
101 -}  
102 -  
103 -func (reponsitory AdminUserRepository) Find(queryOption domain.AdminUserFindQuery) ([]domain.AdminUser, error) {  
104 - db := reponsitory.transactionContext.PgDd  
105 - adminuserModels := []models.AdminUser{}  
106 - query := db.Model(&adminuserModels)  
107 - if len(queryOption.AccountLike) > 0 {  
108 - query = query.Where("account like ?", "%"+queryOption.AccountLike+"%")  
109 - }  
110 -  
111 - if queryOption.Offset > -1 {  
112 - query = query.Offset(queryOption.Offset)  
113 - }  
114 - if queryOption.Limit > 0 {  
115 - query = query.Limit(queryOption.Limit)  
116 - } else {  
117 - query = query.Limit(20)  
118 - }  
119 - var (  
120 - err error  
121 - adminuserReturn = make([]domain.AdminUser, 0)  
122 - )  
123 - query = query.Order("admin_user.id DESC")  
124 - err = query.Select()  
125 - if err != nil {  
126 - return adminuserReturn, err  
127 - }  
128 - for i := range adminuserModels {  
129 - domainAdminUser, err := reponsitory.transformPgModelToDomainModel(&adminuserModels[i])  
130 - if err != nil {  
131 - return adminuserReturn, err  
132 - }  
133 - adminuserReturn = append(adminuserReturn, domainAdminUser)  
134 - }  
135 - return adminuserReturn, nil  
136 -}  
137 -  
138 -func (reponsitory AdminUserRepository) CountAll(queryOption domain.AdminUserFindQuery) (int, error) {  
139 - db := reponsitory.transactionContext.PgDd  
140 - adminuserModels := models.AdminUser{}  
141 - query := db.Model(&adminuserModels)  
142 - if len(queryOption.AccountLike) > 0 {  
143 - query = query.Where("account like ?", "%"+queryOption.AccountLike+"%")  
144 - }  
145 - cnt, err := query.Count()  
146 - return cnt, err  
147 -}