作者 唐旭辉

Merge branch 'test'

正在显示 95 个修改的文件 包含 4406 行增加1306 行删除
@@ -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 -}  
  1 +package repository
  2 +
  3 +import (
  4 + "errors"
  5 + "fmt"
  6 +
  7 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
  8 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
  9 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
  10 +)
  11 +
  12 +type BusinessBonusRepository struct {
  13 + transactionContext *transaction.TransactionContext
  14 +}
  15 +
  16 +func (repository *BusinessBonusRepository) transformPgModelToDomainModel(m *models.BusinessBonus) (domain.BusinessBonus, error) {
  17 + dm := domain.BusinessBonus{
  18 + Id: m.Id,
  19 + CompanyId: m.CompanyId,
  20 + PartnerInfoId: m.PartnerInfoId,
  21 + Bonus: m.Bonus,
  22 + BonusNot: m.BonusNot,
  23 + BonusHas: m.BonusHas,
  24 + BonusExpense: m.BonusExpense,
  25 + IsDisable: m.IsDisable,
  26 + BonusStatus: m.BonusStatus,
  27 + CreateAt: m.CreateAt,
  28 + UpdateAt: m.UpdateAt,
  29 + }
  30 + switch m.BonusStatus {
  31 + case domain.BUSINESS_BONUS_WAIT_PAY:
  32 + dm.BusinessBonusPayStatus = domain.BusinessBonusWaitPay{}
  33 + case domain.BUSINESS_BONUS_HAS_PAY:
  34 + dm.BusinessBonusPayStatus = domain.BusinessBonusHasPay{}
  35 + default:
  36 + dm.BusinessBonusPayStatus = domain.BusinessBonusNullPay{}
  37 + }
  38 + return dm, nil
  39 +}
  40 +
  41 +func NewBusinessBonusRepository(transactionContext *transaction.TransactionContext) (*BusinessBonusRepository, error) {
  42 + if transactionContext == nil {
  43 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  44 + }
  45 + return &BusinessBonusRepository{transactionContext: transactionContext}, nil
  46 +}
  47 +
  48 +func (repository *BusinessBonusRepository) Add(dm *domain.BusinessBonus) error {
  49 + tx := repository.transactionContext.PgTx
  50 + bonusModel := models.BusinessBonus{
  51 + Id: dm.Id,
  52 + CompanyId: dm.CompanyId,
  53 + PartnerInfoId: dm.PartnerInfoId,
  54 + Bonus: dm.Bonus,
  55 + BonusNot: dm.Bonus,
  56 + BonusHas: dm.BonusHas,
  57 + BonusExpense: dm.BonusExpense,
  58 + IsDisable: dm.IsDisable,
  59 + BonusStatus: dm.BonusStatus,
  60 + }
  61 + _, err := tx.Model(&bonusModel).
  62 + Insert()
  63 + dm.CreateAt = bonusModel.CreateAt
  64 + dm.UpdateAt = bonusModel.UpdateAt
  65 + dm.Id = bonusModel.Id
  66 + return err
  67 +}
  68 +
  69 +func (repository *BusinessBonusRepository) Edit(dm *domain.BusinessBonus) error {
  70 + tx := repository.transactionContext.PgTx
  71 + bonusModel := models.BusinessBonus{
  72 + Id: dm.Id,
  73 + CompanyId: dm.CompanyId,
  74 + PartnerInfoId: dm.PartnerInfoId,
  75 + Bonus: dm.Bonus,
  76 + BonusNot: dm.BonusNot,
  77 + BonusExpense: dm.BonusExpense,
  78 + BonusHas: dm.BonusHas,
  79 + IsDisable: dm.IsDisable,
  80 + BonusStatus: dm.BonusStatus,
  81 + CreateAt: dm.CreateAt,
  82 + UpdateAt: dm.UpdateAt,
  83 + }
  84 + _, err := tx.Model(&bonusModel).WherePK().Update()
  85 + return err
  86 +
  87 +}
  88 +
  89 +func (repository *BusinessBonusRepository) FindOne(queryOptions domain.BusinessBonusFindOneQuery) (*domain.BusinessBonus, error) {
  90 + tx := repository.transactionContext.PgTx
  91 + BusinessBonusModel := new(models.BusinessBonus)
  92 + var hasCondition bool
  93 + query := tx.Model(BusinessBonusModel).Where("delete_at ISNULL")
  94 + if queryOptions.Id > 0 {
  95 + hasCondition = true
  96 + query = query.Where("id=?", queryOptions.Id)
  97 + }
  98 + if queryOptions.PartnerId > 0 {
  99 + hasCondition = true
  100 + query = query.Where("partner_info_id=?", queryOptions.PartnerId)
  101 + }
  102 + if queryOptions.CompanyId > 0 {
  103 + hasCondition = true
  104 + query = query.Where("company_id=?", queryOptions.CompanyId)
  105 + }
  106 + if !hasCondition {
  107 + return nil, errors.New("没有查询条件")
  108 + }
  109 + if err := query.First(); err != nil {
  110 + return nil, err
  111 + }
  112 + data, err := repository.transformPgModelToDomainModel(BusinessBonusModel)
  113 + return &data, err
  114 +}
  115 +
  116 +func (repository *BusinessBonusRepository) Find(queryOptions domain.BusinessBonusFindQuery) (int, []domain.BusinessBonus, error) {
  117 + tx := repository.transactionContext.PgTx
  118 + var (
  119 + err error
  120 + cnt int
  121 + businessBonuss []domain.BusinessBonus
  122 + businessBonusModels []models.BusinessBonus
  123 + )
  124 + query := tx.Model(&businessBonusModels)
  125 + if queryOptions.Offset > -1 {
  126 + query = query.Offset(queryOptions.Offset)
  127 + }
  128 + if queryOptions.Limit > 0 {
  129 + query = query.Limit(queryOptions.Limit)
  130 + } else {
  131 + query = query.Limit(1000)
  132 + }
  133 + query = query.Order("business_bonus.id DESC")
  134 + if cnt, err = query.SelectAndCount(); err != nil {
  135 + return 0, businessBonuss, err
  136 + }
  137 +
  138 + for i := range businessBonusModels {
  139 + businessBonus, err := repository.transformPgModelToDomainModel(&businessBonusModels[i])
  140 + if err != nil {
  141 + return 0, businessBonuss, err
  142 + }
  143 + businessBonuss = append(businessBonuss, businessBonus)
  144 + }
  145 + return cnt, businessBonuss, nil
  146 +}
  1 +package repository
  2 +
  3 +import (
  4 + "errors"
  5 + "fmt"
  6 +
  7 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
  8 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
  9 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
  10 +)
  11 +
  12 +type CompanyRepository struct {
  13 + transactionContext *transaction.TransactionContext
  14 +}
  15 +
  16 +var (
  17 + _ domain.CompanyRepository = (*CompanyRepository)(nil)
  18 +)
  19 +
  20 +func NewCompanyRepository(transactionContext *transaction.TransactionContext) (*CompanyRepository, error) {
  21 + if transactionContext == nil {
  22 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  23 + }
  24 + return &CompanyRepository{transactionContext: transactionContext}, nil
  25 +}
  26 +
  27 +func (repository CompanyRepository) transformPgModelToDomainModel(m *models.Company) (domain.Company, error) {
  28 + return domain.Company{
  29 + Id: m.Id,
  30 + Name: m.Name,
  31 + Phone: m.Phone,
  32 + Logo: m.Logo,
  33 + Remarks: m.Remarks,
  34 + AdminCompanyId: m.AdminCompanyId,
  35 + Enable: m.Enable,
  36 + CreateAt: m.CreateAt,
  37 + UpdateAt: m.UpdateAt,
  38 + Abbreviation: m.Abbreviation,
  39 + }, nil
  40 +}
  41 +
  42 +func (reponsitory CompanyRepository) Add(m *domain.Company) error {
  43 + var (
  44 + err error
  45 + tx = reponsitory.transactionContext.PgTx
  46 + )
  47 + companyModel := models.Company{
  48 + Id: m.Id,
  49 + Name: m.Name,
  50 + Phone: m.Phone,
  51 + Logo: m.Logo,
  52 + Remarks: m.Remarks,
  53 + AdminCompanyId: m.AdminCompanyId,
  54 + Enable: m.Enable,
  55 + CreateAt: m.CreateAt,
  56 + UpdateAt: m.UpdateAt,
  57 + Abbreviation: m.Abbreviation,
  58 + }
  59 + _, err = tx.Model(&companyModel).Insert()
  60 + return err
  61 +}
  62 +
  63 +func (reponsitory CompanyRepository) Edit(m *domain.Company) error {
  64 + var (
  65 + err error
  66 + tx = reponsitory.transactionContext.PgTx
  67 + )
  68 + companyModel := models.Company{
  69 + Id: m.Id,
  70 + Name: m.Name,
  71 + Phone: m.Phone,
  72 + Logo: m.Logo,
  73 + Remarks: m.Remarks,
  74 + AdminCompanyId: m.AdminCompanyId,
  75 + Enable: m.Enable,
  76 + CreateAt: m.CreateAt,
  77 + DeleteAt: m.DeleteAt,
  78 + UpdateAt: m.UpdateAt,
  79 + Abbreviation: m.Abbreviation,
  80 + }
  81 + _, err = tx.Model(&companyModel).WherePK().Update()
  82 + return err
  83 +}
  84 +
  85 +func (reponsitory CompanyRepository) FindOne(queryOptions domain.CompanyFindOneOptions) (domain.Company, error) {
  86 + var (
  87 + err error
  88 + tx = reponsitory.transactionContext.PgTx
  89 + m models.Company
  90 + hasCondition bool
  91 + )
  92 +
  93 + query := tx.Model(&m)
  94 + if queryOptions.Id > 0 {
  95 + hasCondition = true
  96 + query = query.Where("id=?", queryOptions.Id)
  97 + }
  98 + if queryOptions.AdminCompanyId > 0 {
  99 + hasCondition = true
  100 + query = query.Where("admin_company_id=?", queryOptions.AdminCompanyId)
  101 + }
  102 + if !hasCondition {
  103 + return domain.Company{}, errors.New("findOne 必须要有查询条件")
  104 + }
  105 + err = query.First()
  106 + if err != nil {
  107 + return domain.Company{}, err
  108 + }
  109 + return reponsitory.transformPgModelToDomainModel(&m)
  110 +}
  111 +
  112 +func (reponsitory CompanyRepository) Find(queryOptions domain.CompanyFindOptions) (int64, []domain.Company, error) {
  113 + return 0, nil, nil
  114 +}
@@ -41,6 +41,7 @@ func (reponsitory OrderBaseRepository) transformPgModelToDomainModel(orderModel @@ -41,6 +41,7 @@ func (reponsitory OrderBaseRepository) transformPgModelToDomainModel(orderModel
41 Id: orderModel.PartnerId, 41 Id: orderModel.PartnerId,
42 }, 42 },
43 BonusStatus: orderModel.BonusStatus, 43 BonusStatus: orderModel.BonusStatus,
  44 + CompanyId: orderModel.CompanyId,
44 } 45 }
45 return order, nil 46 return order, nil
46 } 47 }
@@ -61,6 +62,7 @@ func (repository OrderBaseRepository) Save(orderInfo *domain.OrderBase) error { @@ -61,6 +62,7 @@ func (repository OrderBaseRepository) Save(orderInfo *domain.OrderBase) error {
61 PartnerBonusHas: orderInfo.OrderCompute.PartnerBonusHas, PartnerBonusNot: orderInfo.OrderCompute.PartnerBonusNot, 62 PartnerBonusHas: orderInfo.OrderCompute.PartnerBonusHas, PartnerBonusNot: orderInfo.OrderCompute.PartnerBonusNot,
62 PartnerBonusExpense: orderInfo.OrderCompute.PartnerBonusExpense, IsDisable: orderInfo.IsDisable, 63 PartnerBonusExpense: orderInfo.OrderCompute.PartnerBonusExpense, IsDisable: orderInfo.IsDisable,
63 CreateTime: orderInfo.CreateTime, BonusStatus: orderInfo.BonusStatus, 64 CreateTime: orderInfo.CreateTime, BonusStatus: orderInfo.BonusStatus,
  65 + CompanyId: orderInfo.CompanyId,
64 } 66 }
65 if m.Id == 0 { 67 if m.Id == 0 {
66 _, err = tx.Model(m). 68 _, err = tx.Model(m).
@@ -95,6 +97,9 @@ func (repository OrderBaseRepository) Find(queryOption domain.OrderBaseFindQuery @@ -95,6 +97,9 @@ func (repository OrderBaseRepository) Find(queryOption domain.OrderBaseFindQuery
95 if queryOption.OrderType > 0 { 97 if queryOption.OrderType > 0 {
96 query = query.Where("order_type=?", queryOption.OrderType) 98 query = query.Where("order_type=?", queryOption.OrderType)
97 } 99 }
  100 + if queryOption.CompanyId > 0 {
  101 + query = query.Where("company_id=?", queryOption.CompanyId)
  102 + }
98 if queryOption.Offset > -1 { 103 if queryOption.Offset > -1 {
99 query = query.Offset(queryOption.Offset) 104 query = query.Offset(queryOption.Offset)
100 } 105 }
@@ -128,9 +133,12 @@ func (repository OrderBaseRepository) FindOne(qureyOptions domain.OrderBaseFindO @@ -128,9 +133,12 @@ func (repository OrderBaseRepository) FindOne(qureyOptions domain.OrderBaseFindO
128 tx = repository.transactionContext.PgDd 133 tx = repository.transactionContext.PgDd
129 ) 134 )
130 m := new(models.OrderBase) 135 m := new(models.OrderBase)
131 - err = tx.Model(m).  
132 - Where("id=?", qureyOptions.OrderId).  
133 - First() 136 + query := tx.Model(m).
  137 + Where("id=?", qureyOptions.OrderId)
  138 + if qureyOptions.CompanyId > 0 {
  139 + query = query.Where("company_id=?", qureyOptions.CompanyId)
  140 + }
  141 + err = query.First()
134 if err != nil { 142 if err != nil {
135 return nil, err 143 return nil, err
136 } 144 }
@@ -138,7 +146,7 @@ func (repository OrderBaseRepository) FindOne(qureyOptions domain.OrderBaseFindO @@ -138,7 +146,7 @@ func (repository OrderBaseRepository) FindOne(qureyOptions domain.OrderBaseFindO
138 return &result, err 146 return &result, err
139 } 147 }
140 148
141 -func (repository OrderBaseRepository) Remove(id int64) error { 149 +func (repository OrderBaseRepository) Remove(id int64, companyId int64) error {
142 var ( 150 var (
143 err error 151 err error
144 tx = repository.transactionContext.PgTx 152 tx = repository.transactionContext.PgTx
@@ -146,6 +154,9 @@ func (repository OrderBaseRepository) Remove(id int64) error { @@ -146,6 +154,9 @@ func (repository OrderBaseRepository) Remove(id int64) error {
146 m := &models.OrderBase{ 154 m := &models.OrderBase{
147 Id: id, 155 Id: id,
148 } 156 }
149 - _, err = tx.Model(m).WherePK().Delete() 157 + _, err = tx.Model(m).
  158 + Where("id=?", id).
  159 + Where("company_id=?", companyId).
  160 + Delete()
150 return err 161 return err
151 } 162 }
@@ -38,6 +38,7 @@ func (reponsitory OrderGoodRepository) transformPgModelToDomainModel(orderModel @@ -38,6 +38,7 @@ func (reponsitory OrderGoodRepository) transformPgModelToDomainModel(orderModel
38 PartnerBonusNot: orderModel.PartnerBonusNot, 38 PartnerBonusNot: orderModel.PartnerBonusNot,
39 PartnerBonusExpense: orderModel.PartnerBonusExpense, 39 PartnerBonusExpense: orderModel.PartnerBonusExpense,
40 }, 40 },
  41 + CompanyId: orderModel.CompanyId,
41 } 42 }
42 switch orderModel.BonusStatus { 43 switch orderModel.BonusStatus {
43 case domain.OrderGoodWaitPay: 44 case domain.OrderGoodWaitPay:
@@ -62,7 +63,8 @@ func (repository OrderGoodRepository) Save(data []domain.OrderGood) error { @@ -62,7 +63,8 @@ func (repository OrderGoodRepository) Save(data []domain.OrderGood) error {
62 PlanPartnerBonus: v.GoodCompute.PlanPartnerBonus, UsePartnerBonus: v.GoodCompute.UsePartnerBonus, 63 PlanPartnerBonus: v.GoodCompute.PlanPartnerBonus, UsePartnerBonus: v.GoodCompute.UsePartnerBonus,
63 PartnerBonusHas: v.GoodCompute.PartnerBonusHas, PartnerBonusNot: v.GoodCompute.PartnerBonusNot, 64 PartnerBonusHas: v.GoodCompute.PartnerBonusHas, PartnerBonusNot: v.GoodCompute.PartnerBonusNot,
64 PartnerBonusExpense: v.GoodCompute.PartnerBonusExpense, BonusStatus: v.BonusStatus, 65 PartnerBonusExpense: v.GoodCompute.PartnerBonusExpense, BonusStatus: v.BonusStatus,
65 - Remark: v.Remark, 66 + Remark: v.Remark,
  67 + CompanyId: v.CompanyId,
66 } 68 }
67 if v.Id == 0 { 69 if v.Id == 0 {
68 _, err = tx.Model(m). 70 _, err = tx.Model(m).
@@ -91,6 +93,9 @@ func (repository OrderGoodRepository) Find(queryOption domain.OrderGoodFindQuery @@ -91,6 +93,9 @@ func (repository OrderGoodRepository) Find(queryOption domain.OrderGoodFindQuery
91 if queryOption.OrderId > 0 { 93 if queryOption.OrderId > 0 {
92 query = query.Where("order_id=?", queryOption.OrderId) 94 query = query.Where("order_id=?", queryOption.OrderId)
93 } 95 }
  96 + if queryOption.CompanyId > 0 {
  97 + query = query.Where("company_id=?", queryOption.CompanyId)
  98 + }
94 if queryOption.Offset > -1 { 99 if queryOption.Offset > -1 {
95 query = query.Offset(queryOption.Offset) 100 query = query.Offset(queryOption.Offset)
96 } 101 }
@@ -118,13 +123,15 @@ func (repository OrderGoodRepository) Find(queryOption domain.OrderGoodFindQuery @@ -118,13 +123,15 @@ func (repository OrderGoodRepository) Find(queryOption domain.OrderGoodFindQuery
118 return orderGoods, count, nil 123 return orderGoods, count, nil
119 } 124 }
120 125
121 -func (repository OrderGoodRepository) Remove(orderId int64, goodids ...int64) error { 126 +func (repository OrderGoodRepository) Remove(orderId int64, companyId int64, goodids ...int64) error {
122 var ( 127 var (
123 err error 128 err error
124 tx = repository.transactionContext.PgTx 129 tx = repository.transactionContext.PgTx
125 ) 130 )
126 m := &models.OrderGood{} 131 m := &models.OrderGood{}
127 - query := tx.Model(m).Where("order_id=?", orderId) 132 + query := tx.Model(m).
  133 + Where("order_id=?", orderId).
  134 + Where("company_id=?", companyId)
128 if len(goodids) > 0 { 135 if len(goodids) > 0 {
129 query = query.WhereIn("id in(?)", goodids) 136 query = query.WhereIn("id in(?)", goodids)
130 } 137 }
  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 PartnerCategoryRepository struct {
  12 + transactionContext *transaction.TransactionContext
  13 +}
  14 +
  15 +func (repository PartnerCategoryRepository) transformPgModelToDomainModel(m *models.PartnerCategoryInfo) (domain.PartnerCategory, error) {
  16 + pc := domain.PartnerCategory{
  17 + Id: m.Id,
  18 + Name: m.Name,
  19 + }
  20 + return pc, nil
  21 +}
  22 +
  23 +func NewPartnerCategoryRepository(transactionContext *transaction.TransactionContext) (*PartnerCategoryRepository, error) {
  24 + if transactionContext == nil {
  25 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  26 + }
  27 + return &PartnerCategoryRepository{transactionContext: transactionContext}, nil
  28 +}
  29 +
  30 +func (repository PartnerCategoryRepository) Find(queryOptions domain.PartnerCategoryFindQuery) (int, []domain.PartnerCategory, error) {
  31 + tx := repository.transactionContext.PgTx
  32 + var (
  33 + PartnerCategoryInfoModels []models.PartnerCategoryInfo
  34 + cnt int
  35 + err error
  36 + )
  37 + query := tx.Model(&PartnerCategoryInfoModels)
  38 + if len(queryOptions.Ids) > 0 {
  39 + query = query.WhereIn("id in(?)", queryOptions.Ids)
  40 + }
  41 + if cnt, err = query.SelectAndCount(); err != nil {
  42 + return 0, nil, err
  43 + }
  44 + partnerCategoryInfos := make([]domain.PartnerCategory, 0, len(PartnerCategoryInfoModels))
  45 + for i := range PartnerCategoryInfoModels {
  46 + m, _ := repository.transformPgModelToDomainModel(&PartnerCategoryInfoModels[i])
  47 + partnerCategoryInfos = append(partnerCategoryInfos, m)
  48 + }
  49 + return cnt, partnerCategoryInfos, nil
  50 +}
1 package repository 1 package repository
2 2
3 import ( 3 import (
  4 + "errors"
4 "fmt" 5 "fmt"
5 6
  7 + "github.com/go-pg/pg/v10/orm"
6 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" 8 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
7 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models" 9 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
8 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction" 10 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
@@ -30,7 +32,16 @@ func (repository *PartnerInfoRepository) transformPgModelToDomainModel(partnerIn @@ -30,7 +32,16 @@ func (repository *PartnerInfoRepository) transformPgModelToDomainModel(partnerIn
30 Salesman: partnerInfoModel.Salesman, 32 Salesman: partnerInfoModel.Salesman,
31 RegionInfo: partnerInfoModel.RegionInfo, 33 RegionInfo: partnerInfoModel.RegionInfo,
32 CooperateTime: partnerInfoModel.CooperateTime, 34 CooperateTime: partnerInfoModel.CooperateTime,
  35 + CompanyId: partnerInfoModel.CompanyId,
33 } 36 }
  37 + p := []domain.PartnerCategory{}
  38 + for _, v := range partnerInfoModel.PartnerCategoryInfos {
  39 + catagory := domain.PartnerCategory{
  40 + Id: v.Id,
  41 + }
  42 + p = append(p, catagory)
  43 + }
  44 + m.PartnerCategoryInfos = p
34 return m, nil 45 return m, nil
35 } 46 }
36 47
@@ -41,50 +52,69 @@ func NewPartnerInfoRepository(transactionContext *transaction.TransactionContext @@ -41,50 +52,69 @@ func NewPartnerInfoRepository(transactionContext *transaction.TransactionContext
41 return &PartnerInfoRepository{transactionContext: transactionContext}, nil 52 return &PartnerInfoRepository{transactionContext: transactionContext}, nil
42 } 53 }
43 54
44 -func (repository *PartnerInfoRepository) Save(dm domain.PartnerInfo) (*domain.PartnerInfo, error) { 55 +func (repository *PartnerInfoRepository) Save(dm *domain.PartnerInfo) error {
45 var ( 56 var (
46 err error 57 err error
47 tx = repository.transactionContext.PgTx 58 tx = repository.transactionContext.PgTx
48 ) 59 )
  60 +
  61 + categorys := []domain.PartnerCategory{}
  62 + for _, v := range dm.PartnerCategoryInfos {
  63 + categorys = append(categorys, domain.PartnerCategory{
  64 + Id: v.Id,
  65 + })
  66 + }
49 m := &models.PartnerInfo{ 67 m := &models.PartnerInfo{
50 - Id: dm.Partner.Id,  
51 - PartnerName: dm.Partner.PartnerName,  
52 - Account: dm.Partner.Account,  
53 - Password: dm.Password,  
54 - Status: dm.Status,  
55 - PartnerCategory: dm.PartnerCategory,  
56 - Salesman: dm.Salesman,  
57 - RegionInfo: dm.RegionInfo,  
58 - CooperateTime: dm.CooperateTime, 68 + Id: dm.Partner.Id,
  69 + PartnerName: dm.Partner.PartnerName,
  70 + Account: dm.Partner.Account,
  71 + Password: dm.Password,
  72 + Status: dm.Status,
  73 + PartnerCategory: dm.PartnerCategory,
  74 + Salesman: dm.Salesman,
  75 + RegionInfo: dm.RegionInfo,
  76 + CooperateTime: dm.CooperateTime,
  77 + CompanyId: dm.CompanyId,
  78 + PartnerCategoryInfos: categorys,
59 } 79 }
60 if m.Id == 0 { 80 if m.Id == 0 {
61 err = tx.Insert(m) 81 err = tx.Insert(m)
62 dm.Partner.Id = m.Id 82 dm.Partner.Id = m.Id
63 if err != nil { 83 if err != nil {
64 - return nil, err 84 + return err
65 } 85 }
66 } else { 86 } else {
67 _, err = tx.Model(m).WherePK(). 87 _, err = tx.Model(m).WherePK().
68 Column("partner_name", "account", "password", "status", "partner_category", "salesman", 88 Column("partner_name", "account", "password", "status", "partner_category", "salesman",
69 - "region_info", "cooperate_time", "update_at"). 89 + "region_info", "cooperate_time", "update_at", "partner_category_infos").
70 Update() 90 Update()
71 if err != nil { 91 if err != nil {
72 - return nil, err 92 + return err
73 } 93 }
74 } 94 }
75 - return &dm, nil 95 + return nil
76 } 96 }
77 97
78 func (repository *PartnerInfoRepository) FindOne(queryOptions domain.PartnerFindOneQuery) (*domain.PartnerInfo, error) { 98 func (repository *PartnerInfoRepository) FindOne(queryOptions domain.PartnerFindOneQuery) (*domain.PartnerInfo, error) {
79 - tx := repository.transactionContext.PgDd 99 + tx := repository.transactionContext.PgTx
80 PartnerInfoModel := new(models.PartnerInfo) 100 PartnerInfoModel := new(models.PartnerInfo)
  101 + var hasCondition bool
81 query := tx.Model(PartnerInfoModel) 102 query := tx.Model(PartnerInfoModel)
82 if len(queryOptions.AccountEqual) > 0 { 103 if len(queryOptions.AccountEqual) > 0 {
  104 + hasCondition = true
83 query = query.Where("account=?", queryOptions.AccountEqual) 105 query = query.Where("account=?", queryOptions.AccountEqual)
84 } 106 }
85 if queryOptions.UserId > 0 { 107 if queryOptions.UserId > 0 {
  108 + hasCondition = true
86 query = query.Where("id=?", queryOptions.UserId) 109 query = query.Where("id=?", queryOptions.UserId)
87 } 110 }
  111 + if queryOptions.CompanyId > 0 {
  112 + hasCondition = true
  113 + query = query.Where("company_id=?", queryOptions.CompanyId)
  114 + }
  115 + if !hasCondition {
  116 + return nil, errors.New("FindOne 必须要有查询条件")
  117 + }
88 if err := query.First(); err != nil { 118 if err := query.First(); err != nil {
89 return nil, err 119 return nil, err
90 } 120 }
@@ -93,7 +123,7 @@ func (repository *PartnerInfoRepository) FindOne(queryOptions domain.PartnerFind @@ -93,7 +123,7 @@ func (repository *PartnerInfoRepository) FindOne(queryOptions domain.PartnerFind
93 } 123 }
94 124
95 func (repository *PartnerInfoRepository) Find(queryOption domain.PartnerFindQuery) ([]domain.PartnerInfo, error) { 125 func (repository *PartnerInfoRepository) Find(queryOption domain.PartnerFindQuery) ([]domain.PartnerInfo, error) {
96 - db := repository.transactionContext.PgDd 126 + db := repository.transactionContext.PgTx
97 partnerModels := []models.PartnerInfo{} 127 partnerModels := []models.PartnerInfo{}
98 query := db.Model(&partnerModels) 128 query := db.Model(&partnerModels)
99 if len(queryOption.PartnerName) > 0 { 129 if len(queryOption.PartnerName) > 0 {
@@ -102,8 +132,20 @@ func (repository *PartnerInfoRepository) Find(queryOption domain.PartnerFindQuer @@ -102,8 +132,20 @@ func (repository *PartnerInfoRepository) Find(queryOption domain.PartnerFindQuer
102 if queryOption.RegionInfo != nil { 132 if queryOption.RegionInfo != nil {
103 query = query.Where("region_info::jsonb->>'regionName' like ?", "%"+queryOption.RegionInfo.RegionName+"%") 133 query = query.Where("region_info::jsonb->>'regionName' like ?", "%"+queryOption.RegionInfo.RegionName+"%")
104 } 134 }
  135 + //合伙人类型
105 if len(queryOption.PartnerCategory) > 0 { 136 if len(queryOption.PartnerCategory) > 0 {
106 - query = query.WhereIn("partner_category in(?)", queryOption.PartnerCategory) 137 + query = query.WhereGroup(func(q *orm.Query) (*orm.Query, error) {
  138 + for _, value := range queryOption.PartnerCategory {
  139 + q = q.WhereOr(`partner_category_infos@> '[{"id":?}]'`, value)
  140 + }
  141 + return q, nil
  142 + })
  143 + }
  144 + if queryOption.CompanyId > 0 {
  145 + query = query.Where("company_id=?", queryOption.CompanyId)
  146 + }
  147 + if len(queryOption.Ids) > 0 {
  148 + query = query.WhereIn("id in(?)", queryOption.Ids)
107 } 149 }
108 if queryOption.Offset > -1 { 150 if queryOption.Offset > -1 {
109 query = query.Offset(queryOption.Offset) 151 query = query.Offset(queryOption.Offset)
@@ -111,7 +153,7 @@ func (repository *PartnerInfoRepository) Find(queryOption domain.PartnerFindQuer @@ -111,7 +153,7 @@ func (repository *PartnerInfoRepository) Find(queryOption domain.PartnerFindQuer
111 if queryOption.Limit > 0 { 153 if queryOption.Limit > 0 {
112 query = query.Limit(queryOption.Limit) 154 query = query.Limit(queryOption.Limit)
113 } else { 155 } else {
114 - query = query.Limit(20) 156 + query = query.Limit(1000)
115 } 157 }
116 var ( 158 var (
117 err error 159 err error
@@ -133,7 +175,7 @@ func (repository *PartnerInfoRepository) Find(queryOption domain.PartnerFindQuer @@ -133,7 +175,7 @@ func (repository *PartnerInfoRepository) Find(queryOption domain.PartnerFindQuer
133 } 175 }
134 176
135 func (repository PartnerInfoRepository) CountAll(queryOption domain.PartnerFindQuery) (int, error) { 177 func (repository PartnerInfoRepository) CountAll(queryOption domain.PartnerFindQuery) (int, error) {
136 - db := repository.transactionContext.PgDd 178 + db := repository.transactionContext.PgTx
137 partnerModels := models.PartnerInfo{} 179 partnerModels := models.PartnerInfo{}
138 query := db.Model(&partnerModels) 180 query := db.Model(&partnerModels)
139 if len(queryOption.PartnerName) > 0 { 181 if len(queryOption.PartnerName) > 0 {
@@ -142,8 +184,20 @@ func (repository PartnerInfoRepository) CountAll(queryOption domain.PartnerFindQ @@ -142,8 +184,20 @@ func (repository PartnerInfoRepository) CountAll(queryOption domain.PartnerFindQ
142 if queryOption.RegionInfo != nil { 184 if queryOption.RegionInfo != nil {
143 query = query.Where("region_info::jsonb->>'regionName' like ?", "%"+queryOption.RegionInfo.RegionName+"%") 185 query = query.Where("region_info::jsonb->>'regionName' like ?", "%"+queryOption.RegionInfo.RegionName+"%")
144 } 186 }
  187 + //合伙人类型
145 if len(queryOption.PartnerCategory) > 0 { 188 if len(queryOption.PartnerCategory) > 0 {
146 - query = query.WhereIn("partner_category in(?)", queryOption.PartnerCategory) 189 + query = query.WhereGroup(func(q *orm.Query) (*orm.Query, error) {
  190 + for _, value := range queryOption.PartnerCategory {
  191 + q = q.WhereOr(`partner_category_infos@> '[{"id":?}]'`, value)
  192 + }
  193 + return q, nil
  194 + })
  195 + }
  196 + if queryOption.CompanyId > 0 {
  197 + query = query.Where("company_id=?", queryOption.CompanyId)
  198 + }
  199 + if len(queryOption.Ids) > 0 {
  200 + query = query.WhereIn("id in(?)", queryOption.Ids)
147 } 201 }
148 cnt, err := query.Count() 202 cnt, err := query.Count()
149 return cnt, err 203 return cnt, err
  1 +package repository
  2 +
  3 +import (
  4 + "errors"
  5 + "fmt"
  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 UsersRepository struct {
  14 + transactionContext *transaction.TransactionContext
  15 +}
  16 +
  17 +var (
  18 + _ domain.UsersRepository = (*UsersRepository)(nil)
  19 +)
  20 +
  21 +func NewUsersRepository(transactionContext *transaction.TransactionContext) (*UsersRepository, error) {
  22 + if transactionContext == nil {
  23 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  24 + }
  25 + return &UsersRepository{transactionContext: transactionContext}, nil
  26 +}
  27 +
  28 +func (repository UsersRepository) transformPgModelToDomainModel(m *models.Users) (domain.Users, error) {
  29 + return domain.Users{
  30 + Id: m.Id,
  31 + CompanyId: m.CompanyId,
  32 + OpenId: m.OpenId,
  33 + Name: m.Name,
  34 + Sex: m.Sex,
  35 + JobNum: m.JobNum,
  36 + Phone: m.Phone,
  37 + PrivatePhone: m.PrivatePhone,
  38 + Email: m.Email,
  39 + ExtensionNum: m.ExtensionNum,
  40 + EntryTime: m.EntryTime,
  41 + Workspace: m.Workspace,
  42 + Status: m.Status,
  43 + Avatar: m.Avatar,
  44 + Remarks: m.Remarks,
  45 + ChargeStatus: m.ChargeStatus,
  46 + CreateAt: m.CreateAt,
  47 + UpdateAt: m.UpdateAt,
  48 + Permission: m.Permission,
  49 + AccessPartners: m.AccessPartners,
  50 + AdminType: m.AdminType,
  51 + }, nil
  52 +}
  53 +
  54 +func (reponsitory UsersRepository) Add(u *domain.Users) error {
  55 + var (
  56 + err error
  57 + tx = reponsitory.transactionContext.PgTx
  58 + )
  59 + m := &models.Users{
  60 + Id: u.Id,
  61 + CompanyId: u.CompanyId,
  62 + OpenId: u.OpenId,
  63 + Name: u.Name,
  64 + Sex: u.Sex,
  65 + JobNum: u.JobNum,
  66 + Phone: u.Phone,
  67 + PrivatePhone: u.PrivatePhone,
  68 + Email: u.Email,
  69 + ExtensionNum: u.ExtensionNum,
  70 + EntryTime: u.EntryTime,
  71 + Workspace: u.Workspace,
  72 + Status: u.Status,
  73 + Avatar: u.Avatar,
  74 + Remarks: u.Remarks,
  75 + ChargeStatus: u.ChargeStatus,
  76 + CreateAt: u.CreateAt,
  77 + UpdateAt: u.UpdateAt,
  78 + Permission: u.Permission,
  79 + AccessPartners: u.AccessPartners,
  80 + AdminType: u.AdminType,
  81 + }
  82 + _, err = tx.Model(m).Insert()
  83 + return err
  84 +}
  85 +
  86 +func (reponsitory UsersRepository) Edit(u *domain.Users) error {
  87 + var (
  88 + err error
  89 + tx = reponsitory.transactionContext.PgTx
  90 + )
  91 + m := &models.Users{
  92 + Id: u.Id,
  93 + CompanyId: u.CompanyId,
  94 + OpenId: u.OpenId,
  95 + Name: u.Name,
  96 + Sex: u.Sex,
  97 + JobNum: u.JobNum,
  98 + Phone: u.Phone,
  99 + PrivatePhone: u.PrivatePhone,
  100 + Email: u.Email,
  101 + ExtensionNum: u.ExtensionNum,
  102 + EntryTime: u.EntryTime,
  103 + Workspace: u.Workspace,
  104 + Status: u.Status,
  105 + Avatar: u.Avatar,
  106 + Remarks: u.Remarks,
  107 + ChargeStatus: u.ChargeStatus,
  108 + CreateAt: u.CreateAt,
  109 + UpdateAt: u.UpdateAt,
  110 + Permission: u.Permission,
  111 + AccessPartners: u.AccessPartners,
  112 + AdminType: u.AdminType,
  113 + }
  114 + _, err = tx.Model(m).WherePK().Update()
  115 + return err
  116 +}
  117 +
  118 +func (reponsitory UsersRepository) FindOne(queryOptions domain.UsersFindOneQuery) (domain.Users, error) {
  119 + var (
  120 + err error
  121 + tx = reponsitory.transactionContext.PgTx
  122 + m models.Users
  123 + hasCondition bool
  124 + )
  125 + query := tx.Model(&m)
  126 + query.Where("delete_at ISNULL")
  127 + if queryOptions.Id > 0 {
  128 + hasCondition = true
  129 + query = query.Where("id=?", queryOptions.Id)
  130 + }
  131 + if len(queryOptions.Phone) > 0 {
  132 + hasCondition = true
  133 + query = query.Where("phone=?", queryOptions.Phone)
  134 + }
  135 + if queryOptions.CompanyId > 0 {
  136 + hasCondition = true
  137 + query = query.Where("company_id=?", queryOptions.CompanyId)
  138 + }
  139 + if queryOptions.OpenId > 0 {
  140 + hasCondition = true
  141 + query = query.Where("open_id=?", queryOptions.OpenId)
  142 + }
  143 + if !hasCondition {
  144 + return domain.Users{}, errors.New("FindOne 必须要有查询条件")
  145 + }
  146 + err = query.First()
  147 + if err != nil {
  148 + return domain.Users{}, err
  149 + }
  150 + return reponsitory.transformPgModelToDomainModel(&m)
  151 +}
  152 +
  153 +func (reponsitory UsersRepository) Find(queryOption domain.UsersFindQuery) (int, []domain.Users, error) {
  154 + db := reponsitory.transactionContext.PgTx
  155 + usersModels := []models.Users{}
  156 + query := db.Model(&usersModels)
  157 + query.Where("delete_at ISNULL")
  158 + if queryOption.CompanyId > 0 {
  159 + query = query.Where("company_id=?", queryOption.CompanyId)
  160 + }
  161 + if queryOption.ChargeStatus > 0 {
  162 + query = query.Where("charge_status=?", queryOption.ChargeStatus)
  163 + }
  164 + if queryOption.AdminType > 0 {
  165 + query = query.Where("admin_type=?", queryOption.AdminType)
  166 + }
  167 + if len(queryOption.UserNameMatch) > 0 {
  168 + query = query.Where("name like ?", "%"+queryOption.UserNameMatch+"%")
  169 + }
  170 + if queryOption.Offset >= 0 {
  171 + query = query.Offset(queryOption.Offset)
  172 + }
  173 + if queryOption.Limit > 0 {
  174 + query = query.Limit(queryOption.Limit)
  175 + } else {
  176 + query = query.Limit(1000)
  177 + }
  178 + var (
  179 + err error
  180 + usersReturn = make([]domain.Users, 0)
  181 + cnt int
  182 + )
  183 + query = query.Order("id DESC")
  184 + cnt, err = query.SelectAndCount()
  185 + if err != nil {
  186 + return 0, usersReturn, err
  187 + }
  188 + for i := range usersModels {
  189 + domainUsers, err := reponsitory.transformPgModelToDomainModel(&usersModels[i])
  190 + if err != nil {
  191 + return 0, usersReturn, err
  192 + }
  193 + usersReturn = append(usersReturn, domainUsers)
  194 + }
  195 + return cnt, usersReturn, nil
  196 +}
  197 +
  198 +func (reponsitory UsersRepository) Remove(ids []int64) error {
  199 + if len(ids) == 0 {
  200 + return nil
  201 + }
  202 + var (
  203 + err error
  204 + tx = reponsitory.transactionContext.PgTx
  205 + )
  206 + _, err = tx.Model(&models.Users{}).
  207 + Set("delete_at=?", time.Now()).
  208 + WhereIn("id in(?)", ids).
  209 + Update()
  210 + return err
  211 +}
  1 +package serviceGateway
  2 +
  3 +import (
  4 + "bytes"
  5 + "encoding/json"
  6 + "fmt"
  7 + "io/ioutil"
  8 + "net/http"
  9 + "time"
  10 +
  11 + "github.com/astaxie/beego/logs"
  12 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/constant"
  13 +)
  14 +
  15 +type MmmBusinessAdminServiceGateway struct {
  16 + baseURL string
  17 +}
  18 +
  19 +func NewMmmBusinessAdminServiceGateway() *MmmBusinessAdminServiceGateway {
  20 + return &MmmBusinessAdminServiceGateway{
  21 + baseURL: constant.BUSINESS_ADMIN_HOST,
  22 + }
  23 +}
  24 +func (client MmmBusinessAdminServiceGateway) buildHeader() http.Header {
  25 + var h = http.Header{}
  26 + h.Set("Content-Type", "application/json")
  27 + h.Set("Accept", "application/json")
  28 + return h
  29 +}
  30 +
  31 +type ResponseGetUserAuth struct {
  32 + UCenterCommonMsg
  33 + Data struct {
  34 + UserAuth bool `json:"userAuth"`
  35 + } `json:"data"`
  36 +}
  37 +
  38 +func (gateway MmmBusinessAdminServiceGateway) httpDo(reqURL string, mathod string, bodyData interface{}) ([]byte, error) {
  39 + httpclient := http.Client{
  40 + Timeout: 60 * time.Second, //请求超时时间60秒
  41 + }
  42 + bt := &bytes.Buffer{}
  43 + if bodyData != nil {
  44 + enc := json.NewEncoder(bt)
  45 + enc.Encode(bodyData)
  46 + }
  47 + logs.Info("====>Send To URL:%s", reqURL)
  48 + logs.Info("====>Send To BusinessAdmin:%s", bt.String())
  49 + req, err := http.NewRequest(mathod, reqURL, bt)
  50 + req.Header = gateway.buildHeader()
  51 + if err != nil {
  52 + return nil, err
  53 + }
  54 + resp, err := httpclient.Do(req)
  55 + if err != nil {
  56 + return nil, err
  57 + }
  58 + defer resp.Body.Close()
  59 + body, err := ioutil.ReadAll(resp.Body)
  60 + if err != nil {
  61 + return nil, err
  62 + }
  63 + logs.Info("<====BusinessAdmin Return:%s", string(body))
  64 + return body, nil
  65 +}
  66 +
  67 +func (gateway MmmBusinessAdminServiceGateway) GetUserAuth(userId int64) (*ResponseGetUserAuth, error) {
  68 + param := map[string]interface{}{
  69 + "userId": fmt.Sprint(userId),
  70 + "platformId": "25", //天联共创固定值:25
  71 + }
  72 + url := gateway.baseURL + "/auth/get-user-auth"
  73 + byteData, err := gateway.httpDo(url, "POST", param)
  74 + if err != nil {
  75 + return nil, err
  76 + }
  77 + respData := &ResponseGetUserAuth{}
  78 + err = json.Unmarshal(byteData, respData)
  79 + if err != nil {
  80 + return nil, fmt.Errorf("body data %s; err:%s", string(byteData), err)
  81 + }
  82 + return respData, nil
  83 +}
1 -package service_gateway 1 +package serviceGateway
2 2
3 import ( 3 import (
  4 + "bytes"
4 "crypto/sha1" 5 "crypto/sha1"
  6 + "encoding/json"
5 "fmt" 7 "fmt"
  8 + "io/ioutil"
6 "net/http" 9 "net/http"
  10 + "net/url"
7 "time" 11 "time"
8 12
  13 + "github.com/astaxie/beego/logs"
9 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/constant" 14 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/constant"
10 ) 15 )
11 16
  17 +type UCenterCommonMsg struct {
  18 + Code int `json:"code"`
  19 + Msg string `json:"msg"`
  20 +}
  21 +
  22 +func (msg UCenterCommonMsg) IsOK() error {
  23 + if msg.Code != 0 {
  24 + return fmt.Errorf("统一用户中心响应数据异常,code:%d,msg:%s", msg.Code, msg.Msg)
  25 + }
  26 + return nil
  27 +}
  28 +
12 type MmmUserCenterServiceGateway struct { 29 type MmmUserCenterServiceGateway struct {
13 - httplibBaseServiceGateway 30 + baseURL string
14 } 31 }
15 32
16 func NewMmmUserCenterServiceGateway() *MmmUserCenterServiceGateway { 33 func NewMmmUserCenterServiceGateway() *MmmUserCenterServiceGateway {
17 return &MmmUserCenterServiceGateway{ 34 return &MmmUserCenterServiceGateway{
18 - httplibBaseServiceGateway{  
19 - baseURL: constant.UCENTER_HOST,  
20 - connectTimeout: 100 * time.Second,  
21 - readWriteTimeout: 30 * time.Second,  
22 - }} 35 + baseURL: constant.UCENTER_HOST,
  36 + }
23 } 37 }
24 38
25 func (gateway MmmUserCenterServiceGateway) buildHeader() http.Header { 39 func (gateway MmmUserCenterServiceGateway) buildHeader() http.Header {
@@ -37,12 +51,40 @@ func (gateway MmmUserCenterServiceGateway) buildHeader() http.Header { @@ -37,12 +51,40 @@ func (gateway MmmUserCenterServiceGateway) buildHeader() http.Header {
37 return h 51 return h
38 } 52 }
39 53
  54 +func (gateway MmmUserCenterServiceGateway) httpDo(reqURL string, mathod string, bodyData interface{}) ([]byte, error) {
  55 + httpclient := http.Client{
  56 + Timeout: 60 * time.Second, //请求超时时间60秒
  57 + }
  58 + bt := &bytes.Buffer{}
  59 + if bodyData != nil {
  60 + enc := json.NewEncoder(bt)
  61 + enc.Encode(bodyData)
  62 + }
  63 + logs.Info("====>Send To URL:%s", reqURL)
  64 + logs.Info("====>Send To BusinessAdmin:%s", bt.String())
  65 + req, err := http.NewRequest(mathod, reqURL, bt)
  66 + if err != nil {
  67 + return nil, err
  68 + }
  69 + req.Header = gateway.buildHeader()
  70 + resp, err := httpclient.Do(req)
  71 + if err != nil {
  72 + return nil, err
  73 + }
  74 + defer resp.Body.Close()
  75 + body, err := ioutil.ReadAll(resp.Body)
  76 + if err != nil {
  77 + return nil, err
  78 + }
  79 + logs.Info("<====BusinessAdmin Return:%s", string(body))
  80 + return body, nil
  81 +}
  82 +
40 type ResponseLogin struct { 83 type ResponseLogin struct {
41 - Code int `json:"code"`  
42 - Msg string `json:"msg"` 84 + UCenterCommonMsg
43 Data struct { 85 Data struct {
44 - Id int64 `json:"id"` //统一用户中心的id,对应本系统中users表的open_id  
45 - Phone string `json:"phone"` 86 + Id int64 `json:"id"` //统一用户中心的id,对应本系统中users表的open_id
  87 + Phone string `json:"phone"` //手机号 ,账号
46 NickName string `json:"nickname"` //昵称 88 NickName string `json:"nickname"` //昵称
47 Avatar string `json:"avatar"` //头像 89 Avatar string `json:"avatar"` //头像
48 Imtoken string `json:"imtoken"` //网易云imtoken 90 Imtoken string `json:"imtoken"` //网易云imtoken
@@ -53,13 +95,23 @@ type ResponseLogin struct { @@ -53,13 +95,23 @@ type ResponseLogin struct {
53 } `json:"data"` 95 } `json:"data"`
54 } 96 }
55 97
  98 +//RequestUCenterLoginBySecret 使用密钥方式登录统一用户中心
56 func (gateway MmmUserCenterServiceGateway) RequestUCenterLoginBySecret(secret string) (*ResponseLogin, error) { 99 func (gateway MmmUserCenterServiceGateway) RequestUCenterLoginBySecret(secret string) (*ResponseLogin, error) {
57 - // param := map[string]interface{}{  
58 - // "type": 3, //登录方式 固定值  
59 - // "secret": url.QueryEscape(secret), //必要的转换  
60 - // }  
61 - // url := "/auth/serverLogin"  
62 - // httpRequest := gateway.createRequest(url, "post")  
63 - // httpRequest.  
64 - return nil, nil 100 + param := map[string]interface{}{
  101 + "type": 3, //登录方式 固定值
  102 + "secret": url.QueryEscape(secret), //必要的转换
  103 + }
  104 + url := gateway.baseURL + "/auth/serverLogin"
  105 + byteData, err := gateway.httpDo(url, "POST", param)
  106 + if err != nil {
  107 + return nil, err
  108 + }
  109 + respData := &ResponseLogin{}
  110 + err = json.Unmarshal(byteData, respData)
  111 + if err != nil {
  112 + return nil, fmt.Errorf("body data %s; err:%s", string(byteData), err)
  113 + }
  114 + return respData, nil
65 } 115 }
  116 +
  117 +//企业鉴权 接口
1 -package service_gateway  
2 -  
3 -import (  
4 - "time"  
5 -)  
6 -  
7 -type httplibBaseServiceGateway struct {  
8 - baseURL string  
9 - connectTimeout time.Duration  
10 - readWriteTimeout time.Duration  
11 -}  
@@ -6,15 +6,10 @@ import ( @@ -6,15 +6,10 @@ import (
6 "fmt" 6 "fmt"
7 "time" 7 "time"
8 8
9 - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"  
10 -  
11 "github.com/GeeTeam/gt3-golang-sdk/geetest" 9 "github.com/GeeTeam/gt3-golang-sdk/geetest"
12 "github.com/astaxie/beego/logs" 10 "github.com/astaxie/beego/logs"
13 - adminPermissionquery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminPermission/query"  
14 - adminPermissionService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminPermission/service"  
15 - adminuserCmd "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminUser/command"  
16 - adminuserquery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminUser/query"  
17 - adminuserservice "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminUser/service" 11 + userCmd "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/users/command"
  12 + userService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/users/service"
18 ) 13 )
19 14
20 type AdminLoginController struct { 15 type AdminLoginController struct {
@@ -29,6 +24,7 @@ func (c *AdminLoginController) Prepare() { @@ -29,6 +24,7 @@ func (c *AdminLoginController) Prepare() {
29 "/v1/auth/captcha-init": 1, 24 "/v1/auth/captcha-init": 1,
30 "/v1/auth/login": 1, 25 "/v1/auth/login": 1,
31 } 26 }
  27 +
32 nowUrl := c.Ctx.Input.URL() 28 nowUrl := c.Ctx.Input.URL()
33 if _, ok := urlIn[nowUrl]; ok { 29 if _, ok := urlIn[nowUrl]; ok {
34 //跳过校验 30 //跳过校验
@@ -39,50 +35,21 @@ func (c *AdminLoginController) Prepare() { @@ -39,50 +35,21 @@ func (c *AdminLoginController) Prepare() {
39 } 35 }
40 } 36 }
41 37
42 -//Login 用户登录  
43 func (c *AdminLoginController) Login() { 38 func (c *AdminLoginController) Login() {
44 - type Paramter struct {  
45 - Username string `json:"username"`  
46 - Password string `json:"password"`  
47 - }  
48 var ( 39 var (
49 - param Paramter  
50 - err error 40 + param userCmd.LoginBySecretKeyCommand
51 ) 41 )
52 - if err = c.BindJsonData(&param); err != nil { 42 + if err := c.BindJsonData(&param); err != nil {
53 c.ResponseError(fmt.Errorf("json解析失败:%s", err)) 43 c.ResponseError(fmt.Errorf("json解析失败:%s", err))
54 return 44 return
55 } 45 }
56 - newAdminuserquery := adminuserquery.GetAdminUserQuery{AdminAccount: param.Username}  
57 - newAdminUserService := adminuserservice.NewAdminUserService(nil)  
58 - adminuser, err := newAdminUserService.GetAdminUser(&newAdminuserquery) 46 + newUserService := userService.NewUsersService(nil)
  47 + resp, err := newUserService.UserLoginBySecretKey(param)
59 if err != nil { 48 if err != nil {
60 - logs.Error("获取用户数据失败:%s", err)  
61 - c.ResponseError(errors.New("用户不存在"))  
62 - return  
63 - }  
64 - if adminuser.Password != param.Password {  
65 - c.ResponseError(errors.New("账号或密码错误"))  
66 - return  
67 - }  
68 - if !adminuser.IsUsable {  
69 - c.ResponseError(errors.New("用户被禁用"))  
70 - }  
71 - //TODO  
72 - newJwt := lib.NewMyToken(adminuser.Id, 0)  
73 - newToken, err := newJwt.CreateJWTToken()  
74 - if err != nil {  
75 - logs.Error("生成jwt数据失败:%s", err)  
76 - c.ResponseError(errors.New("服务异常")) 49 + c.ResponseError(err)
77 return 50 return
78 } 51 }
79 - rspdata := map[string]interface{}{  
80 - "access": map[string]interface{}{  
81 - "accessToken": newToken,  
82 - "expiresIn": lib.JWtExpiresSecond,  
83 - },  
84 - }  
85 - c.ResponseData(rspdata) 52 + c.ResponseData(resp)
86 return 53 return
87 } 54 }
88 55
@@ -112,86 +79,13 @@ func (c *AdminLoginController) CaptchaInit() { @@ -112,86 +79,13 @@ func (c *AdminLoginController) CaptchaInit() {
112 //AdminpPofile 获取登录用户的权限配置 79 //AdminpPofile 获取登录用户的权限配置
113 func (c *AdminLoginController) AdminpPofile() { 80 func (c *AdminLoginController) AdminpPofile() {
114 adminId := c.GetUserId() 81 adminId := c.GetUserId()
115 - newAdminuserquery := adminuserquery.GetAdminUserQuery{Id: adminId}  
116 - newAdminUserService := adminuserservice.NewAdminUserService(nil)  
117 - adminuser, err := newAdminUserService.GetAdminUser(&newAdminuserquery) 82 + newUserService := userService.NewUsersService(nil)
  83 + respData, err := newUserService.GetUserPofile(adminId)
118 if err != nil { 84 if err != nil {
119 logs.Error("获取用户数据失败:%s", err) 85 logs.Error("获取用户数据失败:%s", err)
120 c.ResponseError(errors.New("用户不存在")) 86 c.ResponseError(errors.New("用户不存在"))
121 return 87 return
122 } 88 }
123 -  
124 - newPermissionSrv := adminPermissionService.NewAdminPermissionService(nil)  
125 - allPermission, err := newPermissionSrv.ListAdminPermission(adminPermissionquery.ListAdminPermissionQuery{})  
126 - if err != nil {  
127 - logs.Error("获取权限数据失败:%s", err)  
128 - c.ResponseError(errors.New("服务异常"))  
129 - return  
130 - }  
131 - //适配前端的数据格式  
132 - permissionSlice := make([]map[string]interface{}, 0)  
133 - for _, v := range allPermission {  
134 - m := map[string]interface{}{  
135 - "code": v.Code,  
136 - "icon": v.Icon,  
137 - "parentId": v.ParentId,  
138 - "sort": v.Sort,  
139 - "name": v.Name,  
140 - "id": v.Id,  
141 - "status": 0, //状态 1-启用 0-禁用,前端需要  
142 - }  
143 - for _, p := range adminuser.Permission {  
144 - if p.Id == v.Id {  
145 - m["status"] = 1  
146 - break  
147 - }  
148 - if p.Id == v.ParentId {  
149 - m["status"] = 1  
150 - break  
151 - }  
152 - }  
153 - permissionSlice = append(permissionSlice, m)  
154 - }  
155 - userData := map[string]string{  
156 - "id": fmt.Sprint(adminuser.Id),  
157 - "name": adminuser.AdminName,  
158 - "adminType": "2", // 管理员类型 1-超级管理员 2-子管理员  
159 - }  
160 - if adminuser.IsDefault {  
161 - userData["adminType"] = "1"  
162 - }  
163 - respData := map[string]interface{}{  
164 - "user": userData,  
165 - "menus": permissionSlice,  
166 - }  
167 c.ResponseData(respData) 89 c.ResponseData(respData)
168 -}  
169 -  
170 -func (c *AdminLoginController) PwdUpdate() {  
171 - //用与适配前端定义的数据结构  
172 - type Paramater struct {  
173 - Pwd string `json:"pwd"`  
174 - }  
175 - var (  
176 - param Paramater  
177 - err error  
178 - )  
179 - if err = c.BindJsonData(&param); err != nil {  
180 - logs.Error(err)  
181 - c.ResponseError(errors.New("json数据解析失败"))  
182 - return  
183 - }  
184 - uid := c.GetUserId()  
185 - newAdminUserService := adminuserservice.NewAdminUserService(nil)  
186 - cmd := adminuserCmd.UpdateAdminUserPwdCommand{  
187 - Id: uid,  
188 - Password: param.Pwd,  
189 - }  
190 - err = newAdminUserService.UpdateAdminPassword(cmd)  
191 - if err != nil {  
192 - c.ResponseError(err)  
193 - return  
194 - }  
195 - c.ResponseData(nil)  
196 return 90 return
197 } 91 }
@@ -11,8 +11,8 @@ import ( @@ -11,8 +11,8 @@ import (
11 "github.com/astaxie/beego" 11 "github.com/astaxie/beego"
12 "github.com/astaxie/beego/logs" 12 "github.com/astaxie/beego/logs"
13 13
14 - adminuserquery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminUser/query"  
15 - adminuserservice "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminUser/service" 14 + userQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/users/query"
  15 + userService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/users/service"
16 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib" 16 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
17 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/port/beego/protocol" 17 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/port/beego/protocol"
18 ) 18 )
@@ -33,7 +33,7 @@ func (controller BaseController) ResponseError(err error) { @@ -33,7 +33,7 @@ func (controller BaseController) ResponseError(err error) {
33 if !(e.Code == lib.ARG_ERROR || e.Code == lib.BUSINESS_ERROR) { 33 if !(e.Code == lib.ARG_ERROR || e.Code == lib.BUSINESS_ERROR) {
34 controller.Data["json"] = protocol.ResponseData{ 34 controller.Data["json"] = protocol.ResponseData{
35 Code: -1, 35 Code: -1,
36 - Msg: "服务异常", 36 + Msg: "操作失败",
37 Data: struct{}{}, 37 Data: struct{}{},
38 } 38 }
39 controller.ServeJSON() 39 controller.ServeJSON()
@@ -144,6 +144,7 @@ func (controller *BaseController) ValidJWTToken() bool { @@ -144,6 +144,7 @@ func (controller *BaseController) ValidJWTToken() bool {
144 return false 144 return false
145 } 145 }
146 controller.setUserId(tokenData.UID) 146 controller.setUserId(tokenData.UID)
  147 + controller.setUserCompanyId(tokenData.CompanyId)
147 return true 148 return true
148 } 149 }
149 150
@@ -161,27 +162,22 @@ func (controller *BaseController) ValidAdminPermission(permissionCode string, ex @@ -161,27 +162,22 @@ func (controller *BaseController) ValidAdminPermission(permissionCode string, ex
161 controller.ResponseError(errors.New("无操作权限")) 162 controller.ResponseError(errors.New("无操作权限"))
162 return false 163 return false
163 } 164 }
164 - newAdminuserquery := adminuserquery.GetAdminUserQuery{Id: userId}  
165 - newAdminUserService := adminuserservice.NewAdminUserService(nil)  
166 - adminuser, err := newAdminUserService.GetAdminUser(&newAdminuserquery) 165 + comanyId := controller.GetUserCompany()
  166 + newQuery := userQuery.ValidatePermissionQuery{
  167 + UserId: userId,
  168 + PermissionCode: permissionCode,
  169 + CompanyId: comanyId,
  170 + }
  171 + newUserService := userService.NewUsersService(nil)
  172 + ok, err := newUserService.ValidateAdminpPermission(newQuery)
167 if err != nil { 173 if err != nil {
168 - logs.Error("获取用户数据失败:%s", err) 174 + logs.Error("用户鉴权失败:%s", err)
169 controller.ResponseError(errors.New("无操作权限")) 175 controller.ResponseError(errors.New("无操作权限"))
170 return false 176 return false
171 } 177 }
172 - if adminuser.IsDefault {  
173 - logs.Debug("用户是超级管理员") 178 + if ok {
174 return true 179 return true
175 } 180 }
176 - if !adminuser.IsUsable {  
177 - controller.ResponseError(errors.New("用户被禁用"))  
178 - return false  
179 - }  
180 - for _, v := range adminuser.Permission {  
181 - if v.Code == permissionCode {  
182 - return true  
183 - }  
184 - }  
185 controller.ResponseError(errors.New("无操作权限")) 181 controller.ResponseError(errors.New("无操作权限"))
186 return false 182 return false
187 } 183 }
@@ -196,3 +192,17 @@ func (controller *BaseController) setUserId(id int64) { @@ -196,3 +192,17 @@ func (controller *BaseController) setUserId(id int64) {
196 logs.Info("token:admin_user_id = ", id) 192 logs.Info("token:admin_user_id = ", id)
197 controller.Ctx.Input.SetData("token:admin_user_id", id) 193 controller.Ctx.Input.SetData("token:admin_user_id", id)
198 } 194 }
  195 +
  196 +func (controller *BaseController) setUserCompanyId(id int64) {
  197 + logs.Info("token:company_id = ", id)
  198 + controller.Ctx.Input.SetData("token:company_id", id)
  199 +}
  200 +
  201 +func (controller *BaseController) GetUserCompany() int64 {
  202 + idV := controller.Ctx.Input.GetData("token:company_id")
  203 + uid, err := strconv.ParseInt(fmt.Sprint(idV), 10, 64)
  204 + if err != nil {
  205 + logs.Error(err)
  206 + }
  207 + return uid
  208 +}
  1 +package controllers
  2 +
  3 +import (
  4 + "errors"
  5 +
  6 + "github.com/astaxie/beego/logs"
  7 + businessCommand "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/businessBonus/command"
  8 + businessQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/businessBonus/query"
  9 + businessService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/businessBonus/service"
  10 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
  11 +)
  12 +
  13 +type BusinessBonusController struct {
  14 + BaseController
  15 +}
  16 +
  17 +func (c *BusinessBonusController) Prepare() {
  18 + c.BaseController.Prepare()
  19 + if ok := c.ValidJWTToken(); !ok {
  20 + return
  21 + }
  22 + if ok := c.ValidAdminPermission(domain.PERMISSION_DIVIDEND); !ok {
  23 + return
  24 + }
  25 +}
  26 +
  27 +func (c *BusinessBonusController) ListBusinessBonus() {
  28 + type Parameter struct {
  29 + PageNumber int `json:"pageNumber"`
  30 + Partner int64 `json:"partner"`
  31 + PageSize int `json:"pageSize"`
  32 + SearchText string `json:"searchText"`
  33 + }
  34 + var (
  35 + param Parameter
  36 + err error
  37 + )
  38 + if err = c.BindJsonData(&param); err != nil {
  39 + logs.Error(err)
  40 + c.ResponseError(errors.New("json数据解析失败"))
  41 + return
  42 + }
  43 + if param.PageSize == 0 {
  44 + param.PageSize = 20
  45 + }
  46 + if param.PageNumber == 0 {
  47 + param.PageNumber = 1
  48 + }
  49 + companyId := c.GetUserCompany()
  50 + srv := businessService.NewBusinessBonusService(nil)
  51 + cnt, result, err := srv.ListBusinessBonus(businessQuery.ListBusinessBonusQuery{
  52 + CompanyId: companyId,
  53 + Limit: param.PageSize,
  54 + Offset: param.PageSize * (param.PageNumber - 1),
  55 + PartnerId: param.Partner,
  56 + })
  57 + if err != nil {
  58 + c.ResponseError(err)
  59 + return
  60 + }
  61 + c.ResponsePageList(result, cnt, param.PageNumber)
  62 +}
  63 +
  64 +func (c *BusinessBonusController) UpdateBusinessBonus() {
  65 + type Parameter struct {
  66 + Id int64 `json:"id"`
  67 + DividendsReceivable float64 `json:"dividendsReceivable"`
  68 + StateOfPayment int8 `json:"stateOfPayment"`
  69 + }
  70 + var (
  71 + param Parameter
  72 + err error
  73 + )
  74 + if err = c.BindJsonData(&param); err != nil {
  75 + logs.Error(err)
  76 + c.ResponseError(errors.New("json数据解析失败"))
  77 + return
  78 + }
  79 + companyId := c.GetUserCompany()
  80 + srv := businessService.NewBusinessBonusService(nil)
  81 + err = srv.UpdateBusinessBonus(businessCommand.UpdateBusinessBonusCommand{
  82 + CompanyId: companyId,
  83 + Id: param.Id,
  84 + Bonus: param.DividendsReceivable,
  85 + BonusStatus: param.StateOfPayment,
  86 + })
  87 + if err != nil {
  88 + c.ResponseError(err)
  89 + return
  90 + }
  91 + c.ResponseData(nil)
  92 +}
  93 +
  94 +func (c *BusinessBonusController) GetBusinessBonus() {
  95 + type Parameter struct {
  96 + Id int64 `json:"id"`
  97 + }
  98 + var (
  99 + param Parameter
  100 + err error
  101 + )
  102 + if err = c.BindJsonData(&param); err != nil {
  103 + logs.Error(err)
  104 + c.ResponseError(errors.New("json数据解析失败"))
  105 + return
  106 + }
  107 + companyId := c.GetUserCompany()
  108 + srv := businessService.NewBusinessBonusService(nil)
  109 + data, err := srv.GetBusinessBonus(businessQuery.GetBusinessBonusQuery{
  110 + Id: param.Id,
  111 + CompanyId: companyId,
  112 + })
  113 + if err != nil {
  114 + c.ResponseError(err)
  115 + return
  116 + }
  117 + c.ResponseData(data)
  118 +}
1 package controllers 1 package controllers
2 2
3 import ( 3 import (
  4 + categoryQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerCategory/query"
  5 + categoryService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerCategory/service"
4 partnerQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/query" 6 partnerQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/query"
5 partnerInfoService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/service" 7 partnerInfoService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/service"
6 ) 8 )
@@ -19,9 +21,11 @@ func (c *CommonController) Prepare() { @@ -19,9 +21,11 @@ func (c *CommonController) Prepare() {
19 21
20 // GetPartnerList 下拉选项数据通用接口,获取合伙人列表 22 // GetPartnerList 下拉选项数据通用接口,获取合伙人列表
21 func (c *CommonController) GetPartnerList() { 23 func (c *CommonController) GetPartnerList() {
  24 + companyId := c.GetUserCompany()
22 query := partnerQuery.ListPartnerInfoQuery{ 25 query := partnerQuery.ListPartnerInfoQuery{
23 - Limit: 5000,  
24 - Offset: 0, 26 + Limit: 1000,
  27 + Offset: 0,
  28 + CompanyId: companyId,
25 } 29 }
26 newPartnerService := partnerInfoService.NewPartnerInfoService(nil) 30 newPartnerService := partnerInfoService.NewPartnerInfoService(nil)
27 _, partners, err := newPartnerService.ListPartnerInfo(&query) 31 _, partners, err := newPartnerService.ListPartnerInfo(&query)
@@ -41,3 +45,22 @@ func (c *CommonController) GetPartnerList() { @@ -41,3 +45,22 @@ func (c *CommonController) GetPartnerList() {
41 } 45 }
42 c.ResponseData(resp) 46 c.ResponseData(resp)
43 } 47 }
  48 +
  49 +// GetPartnerCategory 下拉选项数据通用接口,获取合伙人分类列表
  50 +func (c *CommonController) GetPartnerCategory() {
  51 + newService := categoryService.NewPartnerCategoryService(nil)
  52 + _, categorys, err := newService.ListPartnerCategory(categoryQuery.ListPartnerCategoryCommand{})
  53 + if err != nil {
  54 + c.ResponseError(err)
  55 + return
  56 + }
  57 + resp := []map[string]interface{}{}
  58 + for i := range categorys {
  59 + m := map[string]interface{}{
  60 + "id": categorys[i].Id,
  61 + "name": categorys[i].Name,
  62 + }
  63 + resp = append(resp, m)
  64 + }
  65 + c.ResponseData(resp)
  66 +}
  1 +package controllers
  2 +
  3 +import (
  4 + "errors"
  5 +
  6 + "github.com/astaxie/beego/logs"
  7 + companyService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/company/service"
  8 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
  9 +)
  10 +
  11 +type CompanyController struct {
  12 + BaseController
  13 +}
  14 +
  15 +//Prepare 重写 BaseController 的Prepare方法
  16 +func (c *CompanyController) Prepare() {
  17 + c.BaseController.Prepare()
  18 + if ok := c.ValidJWTToken(); !ok {
  19 + return
  20 + }
  21 + if ok := c.ValidAdminPermission(domain.PERMISSION_ENTERPRISE_SET); !ok {
  22 + return
  23 + }
  24 +}
  25 +
  26 +func (c *CompanyController) SetPhone() {
  27 + //用与适配前端定义的数据结构
  28 + type Paramter struct {
  29 + Type int `json:"type"`
  30 + Phone string `json:"phone"`
  31 + }
  32 + var (
  33 + param Paramter
  34 + err error
  35 + )
  36 + if err = c.BindJsonData(&param); err != nil {
  37 + logs.Error(err)
  38 + c.ResponseError(errors.New("json数据解析失败"))
  39 + return
  40 + }
  41 + switch param.Type {
  42 + case 1:
  43 + c.editPhone(param.Phone)
  44 + case 2:
  45 + c.getPhone()
  46 + default:
  47 + c.ResponseError(errors.New("参数错误"))
  48 + }
  49 + return
  50 +}
  51 +
  52 +func (c *CompanyController) getPhone() {
  53 + companyid := c.GetUserCompany()
  54 + srv := companyService.NewCompanyService(nil)
  55 + data, err := srv.GetCompanyData(companyid)
  56 + if err != nil {
  57 + c.ResponseError(err)
  58 + return
  59 + }
  60 + result := map[string]interface{}{
  61 + "phone": data.Phone,
  62 + }
  63 + c.ResponseData(result)
  64 + return
  65 +}
  66 +
  67 +func (c *CompanyController) editPhone(phone string) {
  68 + companyid := c.GetUserCompany()
  69 + srv := companyService.NewCompanyService(nil)
  70 + err := srv.UpdateCompanyPhone(companyid, phone)
  71 + if err != nil {
  72 + c.ResponseError(err)
  73 + return
  74 + }
  75 + c.ResponseData(nil)
  76 + return
  77 +}
@@ -51,7 +51,7 @@ func (c *OrderDividendController) PageListOrderDividend() { @@ -51,7 +51,7 @@ func (c *OrderDividendController) PageListOrderDividend() {
51 if param.PageSize == 0 { 51 if param.PageSize == 0 {
52 param.PageSize = 20 52 param.PageSize = 20
53 } 53 }
54 - 54 + companyId := c.GetUserCompany()
55 orderSrv := orderService.NewOrderInfoService(nil) 55 orderSrv := orderService.NewOrderInfoService(nil)
56 orderinfos, cnt, err := orderSrv.PageListOrderBase(orderQuery.ListOrderBaseQuery{ 56 orderinfos, cnt, err := orderSrv.PageListOrderBase(orderQuery.ListOrderBaseQuery{
57 PartnerId: param.Partner, 57 PartnerId: param.Partner,
@@ -59,6 +59,7 @@ func (c *OrderDividendController) PageListOrderDividend() { @@ -59,6 +59,7 @@ func (c *OrderDividendController) PageListOrderDividend() {
59 OrderType: domain.OrderReal, 59 OrderType: domain.OrderReal,
60 Limit: param.PageSize, 60 Limit: param.PageSize,
61 Offset: (param.PageNumber - 1) * param.PageSize, 61 Offset: (param.PageNumber - 1) * param.PageSize,
  62 + CompanyId: companyId,
62 }) 63 })
63 if err != nil { 64 if err != nil {
64 c.ResponseError(err) 65 c.ResponseError(err)
@@ -106,9 +107,11 @@ func (c *OrderDividendController) OrderDividendDetail() { @@ -106,9 +107,11 @@ func (c *OrderDividendController) OrderDividendDetail() {
106 c.ResponseError(errors.New("参数错误")) 107 c.ResponseError(errors.New("参数错误"))
107 return 108 return
108 } 109 }
  110 + companyId := c.GetUserCompany()
109 orderSrv := orderService.NewOrderInfoService(nil) 111 orderSrv := orderService.NewOrderInfoService(nil)
110 orderinfo, err := orderSrv.GetOrderDetail(orderQuery.GetOrderQuery{ 112 orderinfo, err := orderSrv.GetOrderDetail(orderQuery.GetOrderQuery{
111 - OrderId: orderid, 113 + OrderId: orderid,
  114 + CompanyId: companyId,
112 }) 115 })
113 if err != nil { 116 if err != nil {
114 c.ResponseError(err) 117 c.ResponseError(err)
@@ -251,9 +254,11 @@ func (c *OrderDividendController) EditOrderDividend() { @@ -251,9 +254,11 @@ func (c *OrderDividendController) EditOrderDividend() {
251 } 254 }
252 goodbouns = append(goodbouns, g) 255 goodbouns = append(goodbouns, g)
253 } 256 }
  257 + companyId := c.GetUserCompany()
254 cmd := orderCmd.UpdateGoodBouns{ 258 cmd := orderCmd.UpdateGoodBouns{
255 Id: param.Id, 259 Id: param.Id,
256 GoodBouns: goodbouns, 260 GoodBouns: goodbouns,
  261 + CompanyId: companyId,
257 } 262 }
258 orderSrv := orderService.NewOrderInfoService(nil) 263 orderSrv := orderService.NewOrderInfoService(nil)
259 err = orderSrv.UpdateGoodBouns(cmd) 264 err = orderSrv.UpdateGoodBouns(cmd)
@@ -24,7 +24,6 @@ type OrderInfoController struct { @@ -24,7 +24,6 @@ type OrderInfoController struct {
24 ////Prepare 重写 BaseController 的Prepare方法 24 ////Prepare 重写 BaseController 的Prepare方法
25 func (c *OrderInfoController) Prepare() { 25 func (c *OrderInfoController) Prepare() {
26 c.BaseController.Prepare() 26 c.BaseController.Prepare()
27 - return  
28 if ok := c.ValidJWTToken(); !ok { 27 if ok := c.ValidJWTToken(); !ok {
29 return 28 return
30 } 29 }
@@ -56,7 +55,7 @@ func (c *OrderInfoController) PageListOrderPurpose() { @@ -56,7 +55,7 @@ func (c *OrderInfoController) PageListOrderPurpose() {
56 if param.PageSize == 0 { 55 if param.PageSize == 0 {
57 param.PageSize = 20 56 param.PageSize = 20
58 } 57 }
59 - 58 + companyId := c.GetUserCompany()
60 orderSrv := orderService.NewOrderInfoService(nil) 59 orderSrv := orderService.NewOrderInfoService(nil)
61 orderinfos, cnt, err := orderSrv.PageListOrderBase(orderQuery.ListOrderBaseQuery{ 60 orderinfos, cnt, err := orderSrv.PageListOrderBase(orderQuery.ListOrderBaseQuery{
62 PartnerId: param.Partner, 61 PartnerId: param.Partner,
@@ -64,6 +63,7 @@ func (c *OrderInfoController) PageListOrderPurpose() { @@ -64,6 +63,7 @@ func (c *OrderInfoController) PageListOrderPurpose() {
64 OrderType: domain.OrderIntention, 63 OrderType: domain.OrderIntention,
65 Limit: param.PageSize, 64 Limit: param.PageSize,
66 Offset: (param.PageNumber - 1) * param.PageSize, 65 Offset: (param.PageNumber - 1) * param.PageSize,
  66 + CompanyId: companyId,
67 }) 67 })
68 if err != nil { 68 if err != nil {
69 c.ResponseError(err) 69 c.ResponseError(err)
@@ -103,9 +103,11 @@ func (c *OrderInfoController) GetOrderPurpose() { @@ -103,9 +103,11 @@ func (c *OrderInfoController) GetOrderPurpose() {
103 return 103 return
104 } 104 }
105 orderid, _ := strconv.ParseInt(param.Id, 10, 64) 105 orderid, _ := strconv.ParseInt(param.Id, 10, 64)
  106 + companyId := c.GetUserCompany()
106 orderSrv := orderService.NewOrderInfoService(nil) 107 orderSrv := orderService.NewOrderInfoService(nil)
107 orderinfo, err := orderSrv.GetOrderDetail(orderQuery.GetOrderQuery{ 108 orderinfo, err := orderSrv.GetOrderDetail(orderQuery.GetOrderQuery{
108 - OrderId: orderid, 109 + OrderId: orderid,
  110 + CompanyId: companyId,
109 }) 111 })
110 if err != nil { 112 if err != nil {
111 c.ResponseError(err) 113 c.ResponseError(err)
@@ -156,8 +158,9 @@ func (c *OrderInfoController) RemoveOrderPurpose() { @@ -156,8 +158,9 @@ func (c *OrderInfoController) RemoveOrderPurpose() {
156 c.ResponseError(errors.New("json数据解析失败")) 158 c.ResponseError(errors.New("json数据解析失败"))
157 return 159 return
158 } 160 }
  161 + companyId := c.GetUserCompany()
159 orderSrv := orderService.NewOrderInfoService(nil) 162 orderSrv := orderService.NewOrderInfoService(nil)
160 - err = orderSrv.DeleteOrder(param.Id) 163 + err = orderSrv.DeleteOrder(param.Id, companyId)
161 if err != nil { 164 if err != nil {
162 c.ResponseError(err) 165 c.ResponseError(err)
163 return 166 return
@@ -290,6 +293,7 @@ func (c *OrderInfoController) addOrderPurpose(param postPurposeOrderDetail) erro @@ -290,6 +293,7 @@ func (c *OrderInfoController) addOrderPurpose(param postPurposeOrderDetail) erro
290 } 293 }
291 newGoods = append(newGoods, g) 294 newGoods = append(newGoods, g)
292 } 295 }
  296 + companyId := c.GetUserCompany()
293 createcmd := orderCmd.CreateOrderCommand{ 297 createcmd := orderCmd.CreateOrderCommand{
294 OrderType: domain.OrderIntention, 298 OrderType: domain.OrderIntention,
295 OrderCode: param.OrderId, 299 OrderCode: param.OrderId,
@@ -299,6 +303,7 @@ func (c *OrderInfoController) addOrderPurpose(param postPurposeOrderDetail) erro @@ -299,6 +303,7 @@ func (c *OrderInfoController) addOrderPurpose(param postPurposeOrderDetail) erro
299 PartnerId: param.PartnerId, 303 PartnerId: param.PartnerId,
300 SalesmanBonusPercent: param.CommissionProportion, 304 SalesmanBonusPercent: param.CommissionProportion,
301 Goods: newGoods, 305 Goods: newGoods,
  306 + CompanyId: companyId,
302 } 307 }
303 orderSrv := orderService.NewOrderInfoService(nil) 308 orderSrv := orderService.NewOrderInfoService(nil)
304 _, err := orderSrv.CreateNewOrder(createcmd) 309 _, err := orderSrv.CreateNewOrder(createcmd)
@@ -317,6 +322,7 @@ func (c *OrderInfoController) editOrderPurpose(param postPurposeOrderDetail) err @@ -317,6 +322,7 @@ func (c *OrderInfoController) editOrderPurpose(param postPurposeOrderDetail) err
317 } 322 }
318 newGoods = append(newGoods, g) 323 newGoods = append(newGoods, g)
319 } 324 }
  325 + companyId := c.GetUserCompany()
320 updatecmd := orderCmd.UpdateOrderCommand{ 326 updatecmd := orderCmd.UpdateOrderCommand{
321 Id: param.Id, 327 Id: param.Id,
322 OrderType: domain.OrderIntention, 328 OrderType: domain.OrderIntention,
@@ -327,6 +333,7 @@ func (c *OrderInfoController) editOrderPurpose(param postPurposeOrderDetail) err @@ -327,6 +333,7 @@ func (c *OrderInfoController) editOrderPurpose(param postPurposeOrderDetail) err
327 PartnerId: param.PartnerId, 333 PartnerId: param.PartnerId,
328 SalesmanBonusPercent: param.CommissionProportion, 334 SalesmanBonusPercent: param.CommissionProportion,
329 Goods: newGoods, 335 Goods: newGoods,
  336 + CompanyId: companyId,
330 } 337 }
331 _, err := orderSrv.UpdateOrderData(updatecmd) 338 _, err := orderSrv.UpdateOrderData(updatecmd)
332 return err 339 return err
@@ -369,7 +376,7 @@ func (c *OrderInfoController) OrderPurposeDelivery() { @@ -369,7 +376,7 @@ func (c *OrderInfoController) OrderPurposeDelivery() {
369 c.ResponseError(errors.New("json数据解析失败")) 376 c.ResponseError(errors.New("json数据解析失败"))
370 return 377 return
371 } 378 }
372 - 379 + param.ShipmentsId = strings.TrimSpace(param.ShipmentsId)
373 orderid, _ := strconv.ParseInt(param.Id, 10, 64) 380 orderid, _ := strconv.ParseInt(param.Id, 10, 64)
374 if orderid <= 0 { 381 if orderid <= 0 {
375 c.ResponseError(errors.New("参数错误")) 382 c.ResponseError(errors.New("参数错误"))
@@ -387,9 +394,10 @@ func (c *OrderInfoController) OrderPurposeDelivery() { @@ -387,9 +394,10 @@ func (c *OrderInfoController) OrderPurposeDelivery() {
387 } 394 }
388 goods = append(goods, g) 395 goods = append(goods, g)
389 } 396 }
  397 + companyId := c.GetUserCompany()
390 deliveryCommand := orderCmd.OrderDeliveryCommand{ 398 deliveryCommand := orderCmd.OrderDeliveryCommand{
391 OrderId: orderid, DeliveryCode: param.ShipmentsId, 399 OrderId: orderid, DeliveryCode: param.ShipmentsId,
392 - DeliveryTime: time.Now(), Goods: goods, 400 + DeliveryTime: time.Now(), Goods: goods, CompanyId: companyId,
393 } 401 }
394 orderSrv := orderService.NewOrderInfoService(nil) 402 orderSrv := orderService.NewOrderInfoService(nil)
395 err = orderSrv.Delivery(deliveryCommand) 403 err = orderSrv.Delivery(deliveryCommand)
@@ -423,7 +431,7 @@ func (c *OrderInfoController) PageListOrderReal() { @@ -423,7 +431,7 @@ func (c *OrderInfoController) PageListOrderReal() {
423 if param.PageSize == 0 { 431 if param.PageSize == 0 {
424 param.PageSize = 20 432 param.PageSize = 20
425 } 433 }
426 - 434 + companyId := c.GetUserCompany()
427 orderSrv := orderService.NewOrderInfoService(nil) 435 orderSrv := orderService.NewOrderInfoService(nil)
428 orderinfos, cnt, err := orderSrv.PageListOrderBase(orderQuery.ListOrderBaseQuery{ 436 orderinfos, cnt, err := orderSrv.PageListOrderBase(orderQuery.ListOrderBaseQuery{
429 PartnerId: param.Partner, 437 PartnerId: param.Partner,
@@ -431,6 +439,7 @@ func (c *OrderInfoController) PageListOrderReal() { @@ -431,6 +439,7 @@ func (c *OrderInfoController) PageListOrderReal() {
431 OrderType: domain.OrderReal, 439 OrderType: domain.OrderReal,
432 Limit: param.PageSize, 440 Limit: param.PageSize,
433 Offset: (param.PageNumber - 1) * param.PageSize, 441 Offset: (param.PageNumber - 1) * param.PageSize,
  442 + CompanyId: companyId,
434 }) 443 })
435 if err != nil { 444 if err != nil {
436 c.ResponseError(err) 445 c.ResponseError(err)
@@ -485,9 +494,11 @@ func (c *OrderInfoController) GetOrderReal() { @@ -485,9 +494,11 @@ func (c *OrderInfoController) GetOrderReal() {
485 c.ResponseError(errors.New("参数错误")) 494 c.ResponseError(errors.New("参数错误"))
486 return 495 return
487 } 496 }
  497 + companyId := c.GetUserCompany()
488 orderSrv := orderService.NewOrderInfoService(nil) 498 orderSrv := orderService.NewOrderInfoService(nil)
489 orderinfo, err := orderSrv.GetOrderDetail(orderQuery.GetOrderQuery{ 499 orderinfo, err := orderSrv.GetOrderDetail(orderQuery.GetOrderQuery{
490 - OrderId: orderid, 500 + OrderId: orderid,
  501 + CompanyId: companyId,
491 }) 502 })
492 if err != nil { 503 if err != nil {
493 c.ResponseError(err) 504 c.ResponseError(err)
@@ -601,6 +612,7 @@ func (c *OrderInfoController) addOrderReal(param postRealOrderDetail) error { @@ -601,6 +612,7 @@ func (c *OrderInfoController) addOrderReal(param postRealOrderDetail) error {
601 } 612 }
602 newGoods = append(newGoods, g) 613 newGoods = append(newGoods, g)
603 } 614 }
  615 + companyId := c.GetUserCompany()
604 createcmd := orderCmd.CreateOrderCommand{ 616 createcmd := orderCmd.CreateOrderCommand{
605 OrderType: domain.OrderReal, 617 OrderType: domain.OrderReal,
606 OrderCode: param.OrderId, 618 OrderCode: param.OrderId,
@@ -610,6 +622,7 @@ func (c *OrderInfoController) addOrderReal(param postRealOrderDetail) error { @@ -610,6 +622,7 @@ func (c *OrderInfoController) addOrderReal(param postRealOrderDetail) error {
610 PartnerId: param.PartnerId, 622 PartnerId: param.PartnerId,
611 SalesmanBonusPercent: param.CommissionProportion, 623 SalesmanBonusPercent: param.CommissionProportion,
612 Goods: newGoods, 624 Goods: newGoods,
  625 + CompanyId: companyId,
613 } 626 }
614 _, err := orderSrv.CreateNewOrder(createcmd) 627 _, err := orderSrv.CreateNewOrder(createcmd)
615 return err 628 return err
@@ -627,6 +640,7 @@ func (c *OrderInfoController) editOrderReal(param postRealOrderDetail) error { @@ -627,6 +640,7 @@ func (c *OrderInfoController) editOrderReal(param postRealOrderDetail) error {
627 } 640 }
628 newGoods = append(newGoods, g) 641 newGoods = append(newGoods, g)
629 } 642 }
  643 + companyId := c.GetUserCompany()
630 updatecmd := orderCmd.UpdateOrderCommand{ 644 updatecmd := orderCmd.UpdateOrderCommand{
631 Id: param.Id, 645 Id: param.Id,
632 OrderType: domain.OrderReal, 646 OrderType: domain.OrderReal,
@@ -637,6 +651,7 @@ func (c *OrderInfoController) editOrderReal(param postRealOrderDetail) error { @@ -637,6 +651,7 @@ func (c *OrderInfoController) editOrderReal(param postRealOrderDetail) error {
637 PartnerId: param.PartnerId, 651 PartnerId: param.PartnerId,
638 SalesmanBonusPercent: param.CommissionProportion, 652 SalesmanBonusPercent: param.CommissionProportion,
639 Goods: newGoods, 653 Goods: newGoods,
  654 + CompanyId: companyId,
640 } 655 }
641 orderSrv := orderService.NewOrderInfoService(nil) 656 orderSrv := orderService.NewOrderInfoService(nil)
642 _, err := orderSrv.UpdateOrderData(updatecmd) 657 _, err := orderSrv.UpdateOrderData(updatecmd)
@@ -668,10 +683,12 @@ func (c *OrderInfoController) OrderDisable() { @@ -668,10 +683,12 @@ func (c *OrderInfoController) OrderDisable() {
668 c.ResponseError(errors.New("参数错误")) 683 c.ResponseError(errors.New("参数错误"))
669 return 684 return
670 } 685 }
  686 + companyId := c.GetUserCompany()
671 cmd := orderCmd.DisableOrderCommand{ 687 cmd := orderCmd.DisableOrderCommand{
672 OrderId: orderId, 688 OrderId: orderId,
673 IsDisable: param.Status, 689 IsDisable: param.Status,
674 OrderType: domain.OrderReal, 690 OrderType: domain.OrderReal,
  691 + CompanyId: companyId,
675 } 692 }
676 orderSrv := orderService.NewOrderInfoService(nil) 693 orderSrv := orderService.NewOrderInfoService(nil)
677 err = orderSrv.DisableOrEnable(cmd) 694 err = orderSrv.DisableOrEnable(cmd)
@@ -696,8 +713,9 @@ func (c *OrderInfoController) RemoveOrderReal() { @@ -696,8 +713,9 @@ func (c *OrderInfoController) RemoveOrderReal() {
696 c.ResponseError(errors.New("json数据解析失败")) 713 c.ResponseError(errors.New("json数据解析失败"))
697 return 714 return
698 } 715 }
  716 + companyId := c.GetUserCompany()
699 orderSrv := orderService.NewOrderInfoService(nil) 717 orderSrv := orderService.NewOrderInfoService(nil)
700 - err = orderSrv.DeleteOrder(param.Id) 718 + err = orderSrv.DeleteOrder(param.Id, companyId)
701 if err != nil { 719 if err != nil {
702 c.ResponseError(err) 720 c.ResponseError(err)
703 return 721 return
@@ -35,14 +35,14 @@ func (c *PartnerInfoController) Prepare() { @@ -35,14 +35,14 @@ func (c *PartnerInfoController) Prepare() {
35 func (c *PartnerInfoController) CreatePartnerInfo() { 35 func (c *PartnerInfoController) CreatePartnerInfo() {
36 //用与适配前端定义的数据结构 36 //用与适配前端定义的数据结构
37 type Parameter struct { 37 type Parameter struct {
38 - PartnerName string `json:"partnerName"`  
39 - PartnerType int `json:"partnerType"`  
40 - Area string `json:"area"`  
41 - Account string `json:"account"`  
42 - State int `json:"state"`  
43 - CooperationTime string `json:"cooperationTime"`  
44 - SalesmanName string `json:"salesmanName"`  
45 - Phone string `json:"phone"` 38 + PartnerName string `json:"partnerName"`
  39 + PartnerType []int64 `json:"partnerType"`
  40 + Area string `json:"area"`
  41 + Account string `json:"account"`
  42 + State int `json:"state"`
  43 + CooperationTime string `json:"cooperationTime"`
  44 + SalesmanName string `json:"salesmanName"`
  45 + Phone string `json:"phone"`
46 } 46 }
47 var ( 47 var (
48 param Parameter 48 param Parameter
@@ -60,6 +60,7 @@ func (c *PartnerInfoController) CreatePartnerInfo() { @@ -60,6 +60,7 @@ func (c *PartnerInfoController) CreatePartnerInfo() {
60 c.ResponseError(e) 60 c.ResponseError(e)
61 return 61 return
62 } 62 }
  63 + companyId := c.GetUserCompany()
63 cmd := partnerInfoCmd.CreatePartnerInfoCommand{ 64 cmd := partnerInfoCmd.CreatePartnerInfoCommand{
64 PartnerName: param.PartnerName, 65 PartnerName: param.PartnerName,
65 Account: param.Account, 66 Account: param.Account,
@@ -73,6 +74,7 @@ func (c *PartnerInfoController) CreatePartnerInfo() { @@ -73,6 +74,7 @@ func (c *PartnerInfoController) CreatePartnerInfo() {
73 Telephone: param.Phone, 74 Telephone: param.Phone,
74 }, 75 },
75 }, 76 },
  77 + CompanyId: companyId,
76 } 78 }
77 if len(param.Area) > 0 { 79 if len(param.Area) > 0 {
78 cmd.RegionInfo = &domain.RegionInfo{ 80 cmd.RegionInfo = &domain.RegionInfo{
@@ -93,13 +95,13 @@ func (c *PartnerInfoController) CreatePartnerInfo() { @@ -93,13 +95,13 @@ func (c *PartnerInfoController) CreatePartnerInfo() {
93 func (c *PartnerInfoController) UpdatePartnerInfo() { 95 func (c *PartnerInfoController) UpdatePartnerInfo() {
94 //用与适配前端定义的数据结构 96 //用与适配前端定义的数据结构
95 type Parameter struct { 97 type Parameter struct {
96 - ID int64 `json:"id"`  
97 - PartnerType int `json:"partnerType"`  
98 - Area string `json:"area"`  
99 - State int `json:"state"`  
100 - CooperationTime string `json:"cooperationTime"`  
101 - SalesmanName string `json:"salesmanName"`  
102 - Phone string `json:"phone"` 98 + ID int64 `json:"id"`
  99 + PartnerType []int64 `json:"partnerType"`
  100 + Area string `json:"area"`
  101 + State int `json:"state"`
  102 + CooperationTime string `json:"cooperationTime"`
  103 + SalesmanName string `json:"salesmanName"`
  104 + Phone string `json:"phone"`
103 } 105 }
104 var ( 106 var (
105 param Parameter 107 param Parameter
@@ -116,6 +118,7 @@ func (c *PartnerInfoController) UpdatePartnerInfo() { @@ -116,6 +118,7 @@ func (c *PartnerInfoController) UpdatePartnerInfo() {
116 c.ResponseError(e) 118 c.ResponseError(e)
117 return 119 return
118 } 120 }
  121 + companyId := c.GetUserCompany()
119 cmd := partnerInfoCmd.UpdatePartnerInfoCommand{ 122 cmd := partnerInfoCmd.UpdatePartnerInfoCommand{
120 Id: param.ID, 123 Id: param.ID,
121 Status: param.State, 124 Status: param.State,
@@ -130,6 +133,7 @@ func (c *PartnerInfoController) UpdatePartnerInfo() { @@ -130,6 +133,7 @@ func (c *PartnerInfoController) UpdatePartnerInfo() {
130 Telephone: param.Phone, 133 Telephone: param.Phone,
131 }, 134 },
132 }, 135 },
  136 + CompanyId: companyId,
133 } 137 }
134 serve := partnerInfoService.NewPartnerInfoService(nil) 138 serve := partnerInfoService.NewPartnerInfoService(nil)
135 err = serve.UpdatePartnerInfo(&cmd) 139 err = serve.UpdatePartnerInfo(&cmd)
@@ -156,9 +160,11 @@ func (c *PartnerInfoController) GetPartnerInfo() { @@ -156,9 +160,11 @@ func (c *PartnerInfoController) GetPartnerInfo() {
156 c.ResponseError(errors.New("json数据解析失败")) 160 c.ResponseError(errors.New("json数据解析失败"))
157 return 161 return
158 } 162 }
  163 + companyId := c.GetUserCompany()
159 newPartnerService := partnerInfoService.NewPartnerInfoService(nil) 164 newPartnerService := partnerInfoService.NewPartnerInfoService(nil)
160 partnerInfo, err := newPartnerService.GetPartnerInfo(partnerQuery.GetPartnerInfoQuery{ 165 partnerInfo, err := newPartnerService.GetPartnerInfo(partnerQuery.GetPartnerInfoQuery{
161 - Id: param.Id, 166 + Id: param.Id,
  167 + CompanyId: companyId,
162 }) 168 })
163 if err != nil { 169 if err != nil {
164 c.ResponseError(err) 170 c.ResponseError(err)
@@ -166,9 +172,9 @@ func (c *PartnerInfoController) GetPartnerInfo() { @@ -166,9 +172,9 @@ func (c *PartnerInfoController) GetPartnerInfo() {
166 } 172 }
167 //数据适配 173 //数据适配
168 rspResult := map[string]interface{}{ 174 rspResult := map[string]interface{}{
169 - "account": partnerInfo.Partner.Account,  
170 - "partnerName": partnerInfo.Partner.PartnerName,  
171 - "partnerType": partnerInfo.PartnerCategory, 175 + "account": partnerInfo.Partner.Account,
  176 + "partnerName": partnerInfo.Partner.PartnerName,
  177 + // "partnerType": []map[string]interface{}{},
172 "area": partnerInfo.RegionInfo.RegionName, 178 "area": partnerInfo.RegionInfo.RegionName,
173 "salesmanName": "", 179 "salesmanName": "",
174 "phone": "", 180 "phone": "",
@@ -181,16 +187,24 @@ func (c *PartnerInfoController) GetPartnerInfo() { @@ -181,16 +187,24 @@ func (c *PartnerInfoController) GetPartnerInfo() {
181 rspResult["salesmanName"] = partnerInfo.Salesman[0].Name 187 rspResult["salesmanName"] = partnerInfo.Salesman[0].Name
182 rspResult["phone"] = partnerInfo.Salesman[0].Telephone 188 rspResult["phone"] = partnerInfo.Salesman[0].Telephone
183 } 189 }
  190 + partnerTypes := []map[string]interface{}{}
  191 + for _, v := range partnerInfo.PartnerCategoryInfos {
  192 + m := map[string]interface{}{
  193 + "id": v.Id,
  194 + "name": v.Name,
  195 + }
  196 + partnerTypes = append(partnerTypes, m)
  197 + }
  198 + rspResult["partnerType"] = partnerTypes
184 c.ResponseData(rspResult) 199 c.ResponseData(rspResult)
185 return 200 return
186 } 201 }
187 202
188 -//PartnerInfoSetState 合伙人禁用启 203 +//PartnerInfoSetState 合伙人批量禁
189 func (c *PartnerInfoController) PartnerInfoSetState() { 204 func (c *PartnerInfoController) PartnerInfoSetState() {
190 //用与适配前端定义的数据结构 205 //用与适配前端定义的数据结构
191 type Parameter struct { 206 type Parameter struct {
192 - Id int64 `json:"id"`  
193 - Status int `json:"status"` 207 + Id []int64 `json:"id"`
194 } 208 }
195 var ( 209 var (
196 param Parameter 210 param Parameter
@@ -201,20 +215,11 @@ func (c *PartnerInfoController) PartnerInfoSetState() { @@ -201,20 +215,11 @@ func (c *PartnerInfoController) PartnerInfoSetState() {
201 c.ResponseError(errors.New("json数据解析失败")) 215 c.ResponseError(errors.New("json数据解析失败"))
202 return 216 return
203 } 217 }
204 - 218 + comanyId := c.GetUserCompany()
205 cmd := partnerInfoCmd.StatusPartnerInfoCommand{ 219 cmd := partnerInfoCmd.StatusPartnerInfoCommand{
206 - Id: param.Id,  
207 - }  
208 - if param.Status == 1 {  
209 - //禁用操作  
210 - cmd.Status = domain.PARTNER_STATUS_NO  
211 - } else if param.Status == 2 {  
212 - //启用操作  
213 - cmd.Status = domain.PARTNER_STATUS_YES  
214 - } else {  
215 - //错误  
216 - c.ResponseError(lib.ThrowError(lib.ARG_ERROR, "状态错误"))  
217 - return 220 + Ids: param.Id,
  221 + CompanyId: comanyId,
  222 + Status: domain.PARTNER_STATUS_NO,
218 } 223 }
219 newPartnerService := partnerInfoService.NewPartnerInfoService(nil) 224 newPartnerService := partnerInfoService.NewPartnerInfoService(nil)
220 err = newPartnerService.UpdateStatus(cmd) 225 err = newPartnerService.UpdateStatus(cmd)
@@ -251,12 +256,14 @@ func (c *PartnerInfoController) ListPartnerInfo() { @@ -251,12 +256,14 @@ func (c *PartnerInfoController) ListPartnerInfo() {
251 if param.PageSize == 0 { 256 if param.PageSize == 0 {
252 param.PageSize = 20 257 param.PageSize = 20
253 } 258 }
  259 + companyId := c.GetUserCompany()
254 query := partnerQuery.ListPartnerInfoQuery{ 260 query := partnerQuery.ListPartnerInfoQuery{
255 Partnertype: param.Partnertype, 261 Partnertype: param.Partnertype,
256 PartnerName: param.PartnerName, 262 PartnerName: param.PartnerName,
257 RegionInfo: param.Area, 263 RegionInfo: param.Area,
258 Limit: param.PageSize, 264 Limit: param.PageSize,
259 Offset: (param.PageNumber - 1) * param.PageSize, 265 Offset: (param.PageNumber - 1) * param.PageSize,
  266 + CompanyId: companyId,
260 } 267 }
261 268
262 newPartnerService := partnerInfoService.NewPartnerInfoService(nil) 269 newPartnerService := partnerInfoService.NewPartnerInfoService(nil)
@@ -275,7 +282,7 @@ func (c *PartnerInfoController) ListPartnerInfo() { @@ -275,7 +282,7 @@ func (c *PartnerInfoController) ListPartnerInfo() {
275 "createTime": partners[i].CreateAt.Local().Format("2006-01-02 15:04:05"), 282 "createTime": partners[i].CreateAt.Local().Format("2006-01-02 15:04:05"),
276 "cooperationTime": partners[i].CooperateTime.Local().Format("2006-01-02"), 283 "cooperationTime": partners[i].CooperateTime.Local().Format("2006-01-02"),
277 "state": partners[i].Status, 284 "state": partners[i].Status,
278 - "partnerType": partners[i].PartnerCategory, 285 + "partnerType": partners[i].PartnerCategoryInfos,
279 "salesmanName": "", 286 "salesmanName": "",
280 "phone": "", 287 "phone": "",
281 } 288 }
  1 +package controllers
  2 +
  3 +//用于和企业平台和总后台进行数据通讯
  4 +import (
  5 + "encoding/json"
  6 + "errors"
  7 +
  8 + "github.com/astaxie/beego/logs"
  9 + companyService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/company/service"
  10 + syncCmd "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/unifiedUserCenter/command"
  11 + syncService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/unifiedUserCenter/service"
  12 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
  13 +)
  14 +
  15 +type SyncDataController struct {
  16 + BaseController
  17 +}
  18 +
  19 +////Prepare 重写 BaseController 的Prepare方法
  20 +func (c *SyncDataController) Prepare() {
  21 + c.BaseController.Prepare()
  22 +}
  23 +
  24 +//SyncData 和企业后台同步数据
  25 +func (c *SyncDataController) SyncData() {
  26 + var (
  27 + cmd syncCmd.SyncCallbackCommand
  28 + err error
  29 + )
  30 + if err = c.BindJsonData(&cmd); err != nil {
  31 + logs.Error(err)
  32 + c.ResponseError(errors.New("json数据解析失败"))
  33 + return
  34 + }
  35 + err = syncService.NewSyncAction(cmd)
  36 + if err != nil {
  37 + logs.Error("同步数据异常;%s", err)
  38 + }
  39 + //不论子系统如何处理以及处理结果成功失败 必须返回 0
  40 + c.ResponseData(nil)
  41 + return
  42 +}
  43 +
  44 +//CompanyAdminChance 变更公司主管(超级管理)
  45 +func (c *SyncDataController) CompanyAdminChance() {
  46 +
  47 + var (
  48 + param syncCmd.ChanceSuperAdminCommand
  49 + err error
  50 + )
  51 + if err = c.BindJsonData(&param); err != nil {
  52 + logs.Error(err)
  53 + c.ResponseError(errors.New("json数据解析失败"))
  54 + return
  55 + }
  56 + syncEmployeeSrv := syncService.NewSyncEmployeeService(nil)
  57 + syncEmployeeSrv.ChangeSuperAdmin(param)
  58 + if err != nil {
  59 + logs.Error("变更公司的主管失败;%s", err)
  60 + }
  61 + c.ResponseData(nil)
  62 + return
  63 +}
  64 +
  65 +//AllowForidCompany 总后台调用
  66 +func (c *SyncDataController) AllowForidCompany() {
  67 + type Paremeter struct {
  68 + Companyid int64 `json:"company_id"`
  69 + Status int `json:"status"`
  70 + }
  71 + var param Paremeter
  72 + if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
  73 + logs.Error("json 解析失败 err:%s", err)
  74 + c.ResponseError(errors.New("json数据解析失败"))
  75 + return
  76 + }
  77 + var (
  78 + err error
  79 + )
  80 + comanySrv := companyService.NewCompanyService(nil)
  81 + switch param.Status {
  82 + case 1:
  83 + err = comanySrv.AllowCompany(param.Companyid)
  84 + case 2:
  85 + err = comanySrv.ForbidCompany(param.Companyid)
  86 + default:
  87 + c.ResponseError(errors.New("参数错误"))
  88 + return
  89 + }
  90 + if err != nil {
  91 + c.ResponseError(err)
  92 + }
  93 + c.ResponseData(nil)
  94 + return
  95 +}
  96 +
  97 +//GetCompanyInfo 总后台调用
  98 +func (c *SyncDataController) GetCompanyInfo() {
  99 + type Paremeter struct {
  100 + Companyid int64 `json:"company_id"`
  101 + }
  102 + var param Paremeter
  103 + if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
  104 + logs.Error("json 解析失败 err:%s", err)
  105 + c.ResponseError(errors.New("json数据解析失败"))
  106 + return
  107 + }
  108 + var (
  109 + err error
  110 + companyData *domain.Company
  111 + )
  112 + comanySrv := companyService.NewCompanyService(nil)
  113 + companyData, err = comanySrv.GetCompanyData(param.Companyid)
  114 + rspData := map[string]interface{}{
  115 + "comopany_id": 0,
  116 + "exist": -1, //公司【1:存在;【-1:不存在】
  117 + "status": -1, //公司的启用状态【1:启用,-1:禁用】
  118 + }
  119 + if err != nil {
  120 + logs.Error(err)
  121 + c.ResponseData(rspData)
  122 + return
  123 + }
  124 + if companyData.EnableIsOk() {
  125 + rspData["status"] = 1
  126 + }
  127 + rspData["exist"] = 1
  128 + c.ResponseData(rspData)
  129 + return
  130 +}
@@ -6,18 +6,18 @@ import ( @@ -6,18 +6,18 @@ import (
6 "github.com/astaxie/beego/logs" 6 "github.com/astaxie/beego/logs"
7 adminPermissionquery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminPermission/query" 7 adminPermissionquery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminPermission/query"
8 adminPermissionService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminPermission/service" 8 adminPermissionService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminPermission/service"
9 - adminuserCmd "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminUser/command"  
10 - adminuserquery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminUser/query"  
11 - adminuserservice "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminUser/service" 9 + userCommand "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/users/command"
  10 + userQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/users/query"
  11 + userService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/users/service"
12 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" 12 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
13 ) 13 )
14 14
15 -type AdminUserController struct { 15 +type UserController struct {
16 BaseController 16 BaseController
17 } 17 }
18 18
19 -////Prepare 重写 BaseController 的Prepare方法  
20 -func (c *AdminUserController) Prepare() { 19 +//Prepare 重写 BaseController 的Prepare方法
  20 +func (c *UserController) Prepare() {
21 c.BaseController.Prepare() 21 c.BaseController.Prepare()
22 if ok := c.ValidJWTToken(); !ok { 22 if ok := c.ValidJWTToken(); !ok {
23 return 23 return
@@ -27,87 +27,8 @@ func (c *AdminUserController) Prepare() { @@ -27,87 +27,8 @@ func (c *AdminUserController) Prepare() {
27 } 27 }
28 } 28 }
29 29
30 -type adminDetailParam struct {  
31 - Id int64 `json:"id"`  
32 - PermissionType []int `json:"permissionType"`  
33 - Status int `json:"status"`  
34 - Account string `json:"account"`  
35 - IsAdmin int `json:"isAdmin"`  
36 -}  
37 -  
38 -func (c *AdminUserController) SaveAdminUser() {  
39 - //用与适配前端定义的数据结构  
40 - var (  
41 - param adminDetailParam  
42 - err error  
43 - )  
44 - if err = c.BindJsonData(&param); err != nil {  
45 - logs.Error(err)  
46 - c.ResponseError(errors.New("json数据解析失败"))  
47 - return  
48 - }  
49 - newAdminUserService := adminuserservice.NewAdminUserService(nil)  
50 - cmd := &adminuserCmd.SaveAdminUserCommand{  
51 - Id: param.Id,  
52 - Name: param.Account,  
53 - Account: param.Account,  
54 - PermissionId: param.PermissionType,  
55 - IsUsable: false,  
56 - }  
57 - if param.Status == 1 {  
58 - cmd.IsUsable = true  
59 - }  
60 - _, err = newAdminUserService.SaveAdminUser(cmd)  
61 - if err != nil {  
62 - c.ResponseError(err)  
63 - return  
64 - }  
65 - c.ResponseData(nil)  
66 - return  
67 -}  
68 -  
69 -func (c *AdminUserController) GetAdminUser() {  
70 - //用与适配前端定义的数据结构  
71 - type Paramter struct {  
72 - Id int64 `json:"id"`  
73 - }  
74 - var (  
75 - param Paramter  
76 - err error  
77 - )  
78 - if err = c.BindJsonData(&param); err != nil {  
79 - logs.Error(err)  
80 - c.ResponseError(errors.New("json数据解析失败"))  
81 - return  
82 - }  
83 - newAdminUserService := adminuserservice.NewAdminUserService(nil)  
84 - adminuser, err := newAdminUserService.GetAdminUser(&adminuserquery.GetAdminUserQuery{  
85 - Id: param.Id,  
86 - })  
87 - if err != nil {  
88 - c.ResponseError(err)  
89 - return  
90 - }  
91 - rspData := adminDetailParam{  
92 - Id: adminuser.Id,  
93 - Account: adminuser.Account,  
94 - Status: 0,  
95 - IsAdmin: 0,  
96 - }  
97 - for _, v := range adminuser.Permission {  
98 - rspData.PermissionType = append(rspData.PermissionType, v.Id)  
99 - }  
100 - if adminuser.IsUsable {  
101 - rspData.Status = 1  
102 - }  
103 - if adminuser.IsDefault {  
104 - rspData.IsAdmin = 1  
105 - }  
106 - c.ResponseData(rspData)  
107 - return  
108 -}  
109 -  
110 -func (c *AdminUserController) ListAdminUser() { 30 +//ListUser 获取用户分页列表
  31 +func (c *UserController) ListUser() {
111 //用与适配前端定义的数据结构 32 //用与适配前端定义的数据结构
112 type Paramter struct { 33 type Paramter struct {
113 SearchText string `json:"searchText"` 34 SearchText string `json:"searchText"`
@@ -129,63 +50,54 @@ func (c *AdminUserController) ListAdminUser() { @@ -129,63 +50,54 @@ func (c *AdminUserController) ListAdminUser() {
129 if param.PageNumber == 0 { 50 if param.PageNumber == 0 {
130 param.PageNumber = 1 51 param.PageNumber = 1
131 } 52 }
132 - newAdminUserService := adminuserservice.NewAdminUserService(nil)  
133 - queryOption := &adminuserquery.ListAdminUserQuery{  
134 - AdminAccountMatch: param.SearchText,  
135 - Limit: param.PageSize,  
136 - Offset: param.PageSize * (param.PageNumber - 1), 53 + newUserService := userService.NewUsersService(nil)
  54 + queryOption := userQuery.UserListQuery{
  55 + UserNameMatch: param.SearchText,
  56 + Limit: param.PageSize,
  57 + Offset: param.PageSize * (param.PageNumber - 1),
  58 + CompanyId: c.GetUserCompany(),
137 } 59 }
138 - adminusers, cnt, err := newAdminUserService.PageListAdminUser(queryOption) 60 + cnt, usersData, err := newUserService.GetUserList(queryOption)
139 if err != nil { 61 if err != nil {
140 c.ResponseError(err) 62 c.ResponseError(err)
141 return 63 return
142 } 64 }
  65 + c.ResponsePageList(usersData, cnt, param.PageNumber)
  66 + return
  67 +}
  68 +
  69 +//BeforeEditUser 编辑用户数据的前置接口
  70 +func (c *UserController) BeforeEditUser() {
143 newPermissionSrv := adminPermissionService.NewAdminPermissionService(nil) 71 newPermissionSrv := adminPermissionService.NewAdminPermissionService(nil)
144 allPermission, err := newPermissionSrv.ListAdminPermission(adminPermissionquery.ListAdminPermissionQuery{ 72 allPermission, err := newPermissionSrv.ListAdminPermission(adminPermissionquery.ListAdminPermissionQuery{
145 ParentId: 0, 73 ParentId: 0,
  74 + NotCode: []string{domain.PERMINSSION_ADMIN_USER},
146 }) 75 })
147 if err != nil { 76 if err != nil {
148 logs.Error("获取权限数据失败:%s", err) 77 logs.Error("获取权限数据失败:%s", err)
149 c.ResponseError(errors.New("服务异常")) 78 c.ResponseError(errors.New("服务异常"))
150 return 79 return
151 } 80 }
152 - permissionMap := map[int]domain.AdminPermission{} 81 + var rspData []map[string]interface{}
153 for i := range allPermission { 82 for i := range allPermission {
154 - permissionMap[allPermission[i].Id] = allPermission[i]  
155 - }  
156 - listData := []map[string]interface{}{}  
157 - //前端数据格式适配  
158 - for i := range adminusers {  
159 - permissionTypes := []string{}  
160 - for _, vv := range adminusers[i].Permission {  
161 - if pm, ok := permissionMap[vv.Id]; ok {  
162 - permissionTypes = append(permissionTypes, pm.Name)  
163 - } 83 + if allPermission[i].Code == domain.PERMINSSION_ADMIN_USER {
  84 + continue
164 } 85 }
165 m := map[string]interface{}{ 86 m := map[string]interface{}{
166 - "id": adminusers[i].Id,  
167 - "account": adminusers[i].Account,  
168 - "permission": permissionTypes,  
169 - "statue": 0,  
170 - "isAdmin": 0,  
171 - }  
172 - if adminusers[i].IsUsable {  
173 - m["statue"] = 1  
174 - }  
175 - if adminusers[i].IsDefault {  
176 - m["isAdmin"] = 1 87 + "id": allPermission[i].Id,
  88 + "permissionName": allPermission[i].Name,
177 } 89 }
178 - listData = append(listData, m) 90 + rspData = append(rspData, m)
179 } 91 }
180 - c.ResponsePageList(listData, cnt, param.PageNumber) 92 + c.ResponseData(rspData)
181 return 93 return
182 } 94 }
183 95
184 -func (c *AdminUserController) ForbiddenAdminUser() { 96 +//GetUserData 用户详情页数据
  97 +func (c *UserController) GetUserData() {
185 //用与适配前端定义的数据结构 98 //用与适配前端定义的数据结构
186 type Paramter struct { 99 type Paramter struct {
187 - Id int64 `json:"id"`  
188 - Statue int `json:"statue"` 100 + Id int64 `json:"id"`
189 } 101 }
190 var ( 102 var (
191 param Paramter 103 param Paramter
@@ -196,46 +108,45 @@ func (c *AdminUserController) ForbiddenAdminUser() { @@ -196,46 +108,45 @@ func (c *AdminUserController) ForbiddenAdminUser() {
196 c.ResponseError(errors.New("json数据解析失败")) 108 c.ResponseError(errors.New("json数据解析失败"))
197 return 109 return
198 } 110 }
199 - newAdminUserService := adminuserservice.NewAdminUserService(nil)  
200 - var isUsable bool  
201 - if param.Statue == 1 {  
202 - isUsable = true  
203 - } else if param.Statue == 0 {  
204 - isUsable = false  
205 - } else {  
206 - c.ResponseError(errors.New("参数错误"))  
207 - return  
208 - }  
209 -  
210 - err = newAdminUserService.UpdateAdminIsUsable(param.Id, isUsable) 111 + companyId := c.GetUserCompany()
  112 + newUserService := userService.NewUsersService(nil)
  113 + usersData, err := newUserService.GetUserData(param.Id, companyId)
211 if err != nil { 114 if err != nil {
212 c.ResponseError(err) 115 c.ResponseError(err)
213 return 116 return
214 } 117 }
215 - c.ResponseData(nil) 118 + c.ResponseData(usersData)
216 return 119 return
217 } 120 }
218 121
219 -//BeforeEditAdminUser 编辑管理员操作的前置接口  
220 -func (c *AdminUserController) BeforeEditAdminUser() {  
221 - newPermissionSrv := adminPermissionService.NewAdminPermissionService(nil)  
222 - allPermission, err := newPermissionSrv.ListAdminPermission(adminPermissionquery.ListAdminPermissionQuery{  
223 - ParentId: 0,  
224 - NotCode: []string{domain.PERMINSSION_ADMIN_USER}, 122 +//EditUserPermission 编辑用户的权限数据
  123 +func (c *UserController) EditUserPermission() {
  124 + type UserDetailParam struct {
  125 + Id int64 `json:"id"`
  126 + PermissionType []int64 `json:"permissionType"`
  127 + CheckedPartner []int64 `json:"checkedPartner"` //合伙人
  128 + }
  129 + var (
  130 + param UserDetailParam
  131 + err error
  132 + )
  133 + if err = c.BindJsonData(&param); err != nil {
  134 + logs.Error(err)
  135 + c.ResponseError(errors.New("json数据解析失败"))
  136 + return
  137 + }
  138 + companyId := c.GetUserCompany()
  139 + newUserService := userService.NewUsersService(nil)
  140 + err = newUserService.EditUserPermission(userCommand.EditUserPermissionCommand{
  141 + Id: param.Id,
  142 + CompanyId: companyId,
  143 + PermissionType: param.PermissionType,
  144 + CheckedPartner: param.CheckedPartner,
225 }) 145 })
226 if err != nil { 146 if err != nil {
227 - logs.Error("获取权限数据失败:%s", err)  
228 - c.ResponseError(errors.New("服务异常")) 147 + c.ResponseError(err)
229 return 148 return
230 } 149 }
231 - var rspData []map[string]interface{}  
232 - for i := range allPermission {  
233 - m := map[string]interface{}{  
234 - "id": allPermission[i].Id,  
235 - "permissionName": allPermission[i].Name,  
236 - }  
237 - rspData = append(rspData, m)  
238 - }  
239 - c.ResponseData(rspData) 150 + c.ResponseData(nil)
240 return 151 return
241 } 152 }
@@ -9,28 +9,30 @@ func init() { @@ -9,28 +9,30 @@ func init() {
9 adminRouter := beego.NewNamespace("/v1", 9 adminRouter := beego.NewNamespace("/v1",
10 beego.NSNamespace("/auth", 10 beego.NSNamespace("/auth",
11 beego.NSRouter("/login", &controllers.AdminLoginController{}, "POST:Login"), 11 beego.NSRouter("/login", &controllers.AdminLoginController{}, "POST:Login"),
12 - beego.NSRouter("/captcha-init", &controllers.AdminLoginController{}, "POST:CaptchaInit"),  
13 beego.NSRouter("/profile", &controllers.AdminLoginController{}, "POST:AdminpPofile"), 12 beego.NSRouter("/profile", &controllers.AdminLoginController{}, "POST:AdminpPofile"),
14 - beego.NSRouter("/pwd-update", &controllers.AdminLoginController{}, "POST:PwdUpdate"),  
15 ), 13 ),
16 beego.NSNamespace("/admin", 14 beego.NSNamespace("/admin",
17 - beego.NSRouter("/update", &controllers.AdminUserController{}, "POST:SaveAdminUser"),  
18 - beego.NSRouter("/detail", &controllers.AdminUserController{}, "POST:GetAdminUser"),  
19 - beego.NSRouter("/list", &controllers.AdminUserController{}, "POST:ListAdminUser"),  
20 - beego.NSRouter("/forbidden", &controllers.AdminUserController{}, "POST:ForbiddenAdminUser"),  
21 - beego.NSRouter("/permission", &controllers.AdminUserController{}, "POST:BeforeEditAdminUser"), 15 + beego.NSRouter("/update", &controllers.UserController{}, "POST:EditUserPermission"),
  16 + beego.NSRouter("/detail", &controllers.UserController{}, "POST:GetUserData"),
  17 + beego.NSRouter("/list", &controllers.UserController{}, "POST:ListUser"),
  18 + beego.NSRouter("/permission", &controllers.UserController{}, "POST:BeforeEditUser"),
22 ), 19 ),
23 beego.NSNamespace("/partners", 20 beego.NSNamespace("/partners",
24 beego.NSRouter("/list", &controllers.PartnerInfoController{}, "POST:ListPartnerInfo"), 21 beego.NSRouter("/list", &controllers.PartnerInfoController{}, "POST:ListPartnerInfo"),
25 beego.NSRouter("/add", &controllers.PartnerInfoController{}, "POST:CreatePartnerInfo"), 22 beego.NSRouter("/add", &controllers.PartnerInfoController{}, "POST:CreatePartnerInfo"),
26 beego.NSRouter("/edit", &controllers.PartnerInfoController{}, "POST:UpdatePartnerInfo"), 23 beego.NSRouter("/edit", &controllers.PartnerInfoController{}, "POST:UpdatePartnerInfo"),
27 beego.NSRouter("/detail", &controllers.PartnerInfoController{}, "POST:GetPartnerInfo"), 24 beego.NSRouter("/detail", &controllers.PartnerInfoController{}, "POST:GetPartnerInfo"),
28 - beego.NSRouter("/set-status", &controllers.PartnerInfoController{}, "POST:PartnerInfoSetState"), 25 + //beego.NSRouter("/set-status", &controllers.PartnerInfoController{}, "POST:PartnerInfoSetState"),
  26 + beego.NSRouter("/batchDisabled", &controllers.PartnerInfoController{}, "POST:PartnerInfoSetState"),
29 ), 27 ),
30 beego.NSNamespace("/dividends", 28 beego.NSNamespace("/dividends",
31 beego.NSRouter("/list", &controllers.OrderDividendController{}, "POST:PageListOrderDividend"), 29 beego.NSRouter("/list", &controllers.OrderDividendController{}, "POST:PageListOrderDividend"),
32 beego.NSRouter("/edit", &controllers.OrderDividendController{}, "POST:EditOrderDividend"), 30 beego.NSRouter("/edit", &controllers.OrderDividendController{}, "POST:EditOrderDividend"),
33 beego.NSRouter("/detail", &controllers.OrderDividendController{}, "POST:OrderDividendDetail"), 31 beego.NSRouter("/detail", &controllers.OrderDividendController{}, "POST:OrderDividendDetail"),
  32 +
  33 + beego.NSRouter("/business/detail", &controllers.BusinessBonusController{}, "POST:GetBusinessBonus"),
  34 + beego.NSRouter("/business/edit", &controllers.BusinessBonusController{}, "POST:UpdateBusinessBonus"),
  35 + beego.NSRouter("/business/list", &controllers.BusinessBonusController{}, "POST:ListBusinessBonus"),
34 ), 36 ),
35 beego.NSNamespace("/order", 37 beego.NSNamespace("/order",
36 beego.NSRouter("/purpose/list", &controllers.OrderInfoController{}, "POST:PageListOrderPurpose"), 38 beego.NSRouter("/purpose/list", &controllers.OrderInfoController{}, "POST:PageListOrderPurpose"),
@@ -41,13 +43,17 @@ func init() { @@ -41,13 +43,17 @@ func init() {
41 beego.NSRouter("/actual/list", &controllers.OrderInfoController{}, "POST:PageListOrderReal"), 43 beego.NSRouter("/actual/list", &controllers.OrderInfoController{}, "POST:PageListOrderReal"),
42 beego.NSRouter("/actual/detail", &controllers.OrderInfoController{}, "POST:GetOrderReal"), 44 beego.NSRouter("/actual/detail", &controllers.OrderInfoController{}, "POST:GetOrderReal"),
43 beego.NSRouter("/actual/del", &controllers.OrderInfoController{}, "POST:RemoveOrderReal"), 45 beego.NSRouter("/actual/del", &controllers.OrderInfoController{}, "POST:RemoveOrderReal"),
44 -  
45 beego.NSRouter("/actual/update", &controllers.OrderInfoController{}, "POST:UpdateOrderReal"), 46 beego.NSRouter("/actual/update", &controllers.OrderInfoController{}, "POST:UpdateOrderReal"),
46 beego.NSRouter("/actual/close", &controllers.OrderInfoController{}, "POST:OrderDisable"), 47 beego.NSRouter("/actual/close", &controllers.OrderInfoController{}, "POST:OrderDisable"),
47 ), 48 ),
48 49
49 beego.NSNamespace("/common", 50 beego.NSNamespace("/common",
50 beego.NSRouter("/partner", &controllers.CommonController{}, "POST:GetPartnerList"), 51 beego.NSRouter("/partner", &controllers.CommonController{}, "POST:GetPartnerList"),
  52 + beego.NSRouter("/partnerType", &controllers.CommonController{}, "POST:GetPartnerCategory"),
  53 + ),
  54 +
  55 + beego.NSNamespace("/enterprises",
  56 + beego.NSRouter("/setPhone", &controllers.CompanyController{}, "POST:SetPhone"),
51 ), 57 ),
52 ) 58 )
53 59
  1 +package routers
  2 +
  3 +import (
  4 + "github.com/astaxie/beego"
  5 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/port/beego/controllers"
  6 +)
  7 +
  8 +//外部调用,企业平台,总后台调用
  9 +func init() {
  10 + nsPlatform := beego.NewNamespace("/platform",
  11 + beego.NSRouter("/action", &controllers.SyncDataController{}, "post:SyncData"),
  12 + beego.NSRouter("/admins_change", &controllers.SyncDataController{}, "post:CompanyAdminChance"),
  13 + )
  14 + nsUcenter := beego.NewNamespace("/ucenter",
  15 + beego.NSRouter("/company/allow_forbid", &controllers.SyncDataController{}, "post:AllowForidCompany"),
  16 + //beego.NSRouter("/company/info", &controllers.SyncDataController{}, "post:GetCompanyInfo"),
  17 + )
  18 +
  19 + beego.AddNamespace(nsPlatform) //企业平台调用
  20 + beego.AddNamespace(nsUcenter) //统一用户中心调用
  21 +}
1 package routers 1 package routers
2 2
3 import ( 3 import (
  4 + "net/http"
  5 +
4 "github.com/astaxie/beego" 6 "github.com/astaxie/beego"
  7 + "github.com/astaxie/beego/context"
5 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/constant" 8 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/constant"
6 ) 9 )
7 10
8 func init() { 11 func init() {
9 - beego.SetStaticPath("/log", constant.LOG_File) 12 + //beego.SetStaticPath("/log", constant.LOG_File)
  13 + beego.Get("/log", func(ctx *context.Context) {
  14 + var s string
  15 + ctx.Input.Bind(&s, "id")
  16 + if s != "12345" {
  17 + ctx.Output.SetStatus(http.StatusBadRequest)
  18 + return
  19 + }
  20 + http.ServeFile(ctx.ResponseWriter, ctx.Request, constant.LOG_File)
  21 + return
  22 + })
10 } 23 }