pg_login_services.go
25.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
package domain_service
import (
"fmt"
"github.com/tiptok/gocomm/xa/eda"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/constant"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/dao"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/repository"
http_gateway "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/svr"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol"
protocolx "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol/auth"
"strings"
"time"
)
type PgLoginService struct {
Phone string
eda.EventCenterPublisher
PartnerInfo []*domain.PartnerInfo // 所有公司有效合伙人
GuestPartnerInfo []*domain.PartnerInfo // 游客公司合伙人
GuestPartnerInfoAvailable []*domain.PartnerInfo // 游客公司有效合伙人
NormalPartnerInfo []*domain.PartnerInfo // 所有公司合伙人
IsPartnerInfo []*domain.PartnerInfo // 真实公司有效合伙人
Users []*domain.Users // 所有公司有效用户
NormalUsers []*domain.Users // 所有公司用户
IsSenior []*domain.Users // 所有公司有效高管
IsRealSenior []*domain.Users // 真实公司的有效高管
transactionContext *transaction.TransactionContext
// 标识:登录的账号信息是否有可用的公司, true:有 false:没有
HasAvailableCompany bool // 是否有可访问的合伙公司
HasAvailableManagerCompany bool // 是否有可访问的高管公司
}
func (svr *PgLoginService) Init(phone string) (err error) {
var (
PartnerInfoService, _ = repository.NewPartnerInfoRepository(svr.transactionContext)
UsersRepository, _ = repository.NewUsersRepository(svr.transactionContext)
)
svr.Phone = phone
// 所有公司合伙人
_, svr.NormalPartnerInfo, err = PartnerInfoService.Find(map[string]interface{}{"account": phone, "sortByCreateTime": "ASC"})
// 所有公司有效合伙人
_, svr.PartnerInfo, err = PartnerInfoService.Find(map[string]interface{}{"account": phone, "status": 1, "sortByCreateTime": "ASC"})
// 真实公司有效合伙人
_, svr.IsPartnerInfo, err = PartnerInfoService.Find(map[string]interface{}{"account": phone, "status": 1, "sortByCreateTime": "ASC", "isNot": constant.DEFAULT_GUEST_COMPANY})
// 游客公司合伙人
_, svr.GuestPartnerInfo, err = PartnerInfoService.Find(map[string]interface{}{"account": phone, "sortByCreateTime": "ASC", "companyId": constant.DEFAULT_GUEST_COMPANY})
// 游客公司有效合伙人
_, svr.GuestPartnerInfoAvailable, err = PartnerInfoService.Find(map[string]interface{}{"account": phone, "status": 1, "sortByCreateTime": "ASC", "companyId": constant.DEFAULT_GUEST_COMPANY})
// 所有公司非删除用户
_, svr.NormalUsers, err = UsersRepository.Find(map[string]interface{}{"phone": phone, "sortByCreateTime": "ASC", "deleteAtIsNull": true})
// 所有公司非删除非禁用用户
_, svr.Users, err = UsersRepository.Find(map[string]interface{}{"phone": phone, "status": 1, "sortByCreateTime": "ASC", "deleteAtIsNull": true})
// 所有公司有效高管
_, svr.IsSenior, err = UsersRepository.Find(map[string]interface{}{"phone": phone, "status": 1, "sortByCreateTime": "ASC", "deleteAtIsNull": true, "isSenior": 1})
// 真实公司非禁用非删除高管
_, svr.IsRealSenior, err = UsersRepository.Find(map[string]interface{}{"phone": phone, "status": 1, "sortByCreateTime": "ASC", "deleteAtIsNull": true, "isSenior": 1, "isNot": constant.DEFAULT_GUEST_COMPANY})
return nil
}
func (svr *PgLoginService) InitNormal(phone string) (err error) {
var (
PartnerInfoService, _ = repository.NewPartnerInfoRepository(svr.transactionContext)
)
svr.Phone = phone
_, svr.NormalPartnerInfo, err = PartnerInfoService.Find(map[string]interface{}{"account": phone, "sortByCreateTime": "ASC"})
return nil
}
func (svr *PgLoginService) InitSenior(phone string) (err error) {
var (
UsersRepository, _ = repository.NewUsersRepository(svr.transactionContext)
)
svr.Phone = phone
_, svr.IsSenior, err = UsersRepository.Find(map[string]interface{}{"phone": phone, "status": 1, "sortByCreateTime": "ASC", "deleteAtIsNull": true, "isSenior": 1})
return nil
}
func (svr *PgLoginService) InitPartner(phone string) (err error) {
var (
PartnerInfoService, _ = repository.NewPartnerInfoRepository(svr.transactionContext)
)
svr.Phone = phone
_, svr.IsPartnerInfo, err = PartnerInfoService.Find(map[string]interface{}{"account": phone, "status": 1, "sortByCreateTime": "ASC", "isNot": constant.DEFAULT_GUEST_COMPANY})
return nil
}
/**
* @Author SteveChan
* @Description // 判断是否是高管
* @Date 10:44 2021/1/12
* @Param
* @return
**/
func (svr *PgLoginService) CheckIsSenior(phone string, companyId int64) (ok bool, err error) {
var (
UsersRepository, _ = repository.NewUsersRepository(svr.transactionContext)
)
svr.Phone = phone
user, err := UsersRepository.FindOne(map[string]interface{}{"phone": phone, "status": 1, "companyId": companyId, "deleteAtIsNull": true})
if err != nil {
return false, err
} else {
if user.IsSenior == 1 {
ok = true
} else if user.IsSenior == 2 {
ok = false
}
}
return ok, nil
}
/**
* @Author SteveChan
* @Description // 判断是否合伙人
* @Date 13:25 2021/1/13
* @Param
* @return
**/
func (svr *PgLoginService) CheckIsPartner(phone string, companyId int64) (ok bool, err error) {
var (
PartnerInfoRepository, _ = repository.NewPartnerInfoRepository(svr.transactionContext)
)
svr.Phone = phone
user, err := PartnerInfoRepository.FindOne(map[string]interface{}{"account": phone, "status": 1})
if err != nil {
return false, err
}
if user != nil {
ok = true
} else {
ok = false
}
return ok, nil
}
// 合伙人登录
func (svr *PgLoginService) PartnerLogin(phone string, password string) (err error) {
if len(svr.PartnerInfo) == 0 {
//子账号
err = protocol.NewErrWithMessage(502, err) //账号不存在
return
}
var misMatch bool
for _, partnerInfo := range svr.PartnerInfo {
if !strings.EqualFold(partnerInfo.Password, password) {
misMatch = true
} else {
misMatch = false
break
}
}
if misMatch {
err = protocol.NewCustomMessage(1, "密码输入错误!")
return
}
return
}
//管理层登录
func (svr *PgLoginService) ManagerLogin(phone string, password string) (err error) {
if len(svr.Users) == 0 {
//子账号
err = protocol.NewErrWithMessage(502, err) //账号不存在
return
}
var openid int64
ucenerSvr := http_gateway.NewHttplibUCenterApiServiceGateway()
openid, err = ucenerSvr.ServerLogin(phone, password, 1)
if err == nil && openid > 0 {
_, err = svr.transactionContext.PgTx.Exec("update users set open_id=? where phone=?", openid, phone)
}
return
}
//合伙人统计信息
func (svr *PgLoginService) PartnerStaticInfo() (interface{}, error) {
response := make(map[string]interface{})
response["id"] = protocolx.AdminTypePartner
response["name"] = protocolx.AdminTypePartnerName
if len(svr.PartnerInfo) == 0 {
response["companys"] = make([]struct{}, 0)
return response, nil
}
var (
OrderDao, _ = dao.NewOrderBaseDao(svr.transactionContext)
BusinessBonusDao, _ = dao.NewBusinessBonusDao(svr.transactionContext)
PartnerCategoryInfoRepository, _ = repository.NewPartnerCategoryInfoRepository(svr.transactionContext)
companyList []*domain.Company
allPartnerCategory []*domain.PartnerCategoryInfo
BusinessBonusRepository, _ = repository.NewBusinessBonusRepository(svr.transactionContext)
UsersRepository, _ = repository.NewUsersRepository(svr.transactionContext)
adminApiGateway = http_gateway.NewHttplibBusinessAdminApiServiceGateway()
)
doGetCompanyIds := func() []int64 {
var companies []int64
for i := range svr.PartnerInfo {
companies = append(companies, svr.PartnerInfo[i].CompanyId)
}
return companies
}
doGetPartnerIds := func() []int64 {
var array []int64
for i := range svr.PartnerInfo {
array = append(array, svr.PartnerInfo[i].Id)
}
return array
}
companyList = svr.GetCompanyList(doGetCompanyIds)
if len(companyList) == 0 {
return response, nil
}
totalBonus, e := OrderDao.OrderBonusStatics(domain.OrderBonusQuery{InPartnerIds: doGetPartnerIds(), OrderTypes: domain.UserOrderTypes(domain.Career), EndTime: utils.GetDayEnd().Unix() * 1000})
if e != nil {
return response, e
}
if businessBonus, e := BusinessBonusDao.OrderBonusStatics(domain.OrderBonusQuery{InPartnerIds: doGetPartnerIds(), IsDisable: 1, EndTime: utils.GetDayEnd().Unix() * 1000}); e == nil {
totalBonus.Bonus += businessBonus.Bonus
}
_, allPartnerCategory, e = PartnerCategoryInfoRepository.Find(map[string]interface{}{"sortById": domain.ASC})
var mapPartnerBussinessBonus = make(map[int64]*domain.BusinessBonus)
if _, bussinessBonus, e := BusinessBonusRepository.Find(map[string]interface{}{"inPartnerIds": doGetPartnerIds(), "isDisable": 1}); e == nil {
for _, v := range bussinessBonus {
mapPartnerBussinessBonus[v.PartnerInfoId] = v
}
}
if e != nil {
log.Error(e)
return response, e
}
var mapCompanyAdminUsers map[int64]*domain.Users = make(map[int64]*domain.Users) //key:company_id value:domain.users
if _, adminUsers, e := UsersRepository.Find(map[string]interface{}{"inCompanyIds": doGetCompanyIds(), "adminType": 2, "deleteAtIsNull": true}); e == nil {
for i := range adminUsers {
mapCompanyAdminUsers[adminUsers[i].CompanyId] = adminUsers[i]
}
}
var companys = make([]*Company, 0)
for i := range companyList {
c := companyList[i]
var partner *domain.PartnerInfo
for j := range svr.PartnerInfo {
if svr.PartnerInfo[j].CompanyId == c.Id {
partner = svr.PartnerInfo[j]
break
}
}
if partner == nil {
continue
}
if au, ok := mapCompanyAdminUsers[partner.CompanyId]; ok {
if code, e := adminApiGateway.UserAuth(au.Id, constant.BUSINESS_ADMIN_PLATFORM_ID); e != nil || code != 0 {
log.Debug("【合伙人检查权限】", svr.Phone, "【公司】", c.Id, au.Id, code, e.Error())
continue
} else {
log.Debug("【合伙人检查权限】", svr.Phone, "【公司】", c.Id, au.Id, code, e)
}
} else {
log.Debug("【合伙人检查权限】", svr.Phone, "【公司】", c.Id, partner.Id, "公司管理员不存在")
continue
}
bonus, _ := OrderDao.OrderBonusStatics(domain.OrderBonusQuery{PartnerId: partner.Id, OrderTypes: domain.UserOrderTypes(domain.Career), EndTime: utils.GetDayEnd().Unix() * 1000})
if v, ok := mapPartnerBussinessBonus[partner.Id]; ok {
bonus.Bonus += v.Bonus
}
item := &Company{
CompanyBase: newCompanyBase(c),
IncomePercent: computeBonusPercent(totalBonus.Bonus, bonus.Bonus*100),
DividendMoney: utils.Decimal(bonus.Bonus),
JoinWays: svr.GetJoinWays(allPartnerCategory, partner, bonus.Bonus),
}
companys = append(companys, item)
}
if len(companys) > 0 {
svr.HasAvailableCompany = true
}
if len(companys) > 1 || len(svr.IsRealSenior) > 0 { // 有真实合伙公司或高管公司时,过滤游客公司
var companies = make([]*Company, 0)
for _, company := range companys {
if company.CompanyBase.Id != int64(constant.DEFAULT_GUEST_COMPANY) {
companies = append(companies, company)
}
}
companys = companies
}
response["companys"] = companys
return response, nil
}
// 高管统计信息
func (svr *PgLoginService) ManagerStaticInfo() (interface{}, error) {
response := make(map[string]interface{})
response["id"] = protocolx.AdminTypeManager
response["name"] = protocolx.AdminTypeManagerName
if len(svr.Users) == 0 {
response["companys"] = make([]struct{}, 0)
return response, nil
}
var (
companyList []*domain.Company
adminApiGateway = http_gateway.NewHttplibBusinessAdminApiServiceGateway()
)
doGetCompanyIds := func() []int64 {
var companies []int64
for i := range svr.IsSenior {
companies = append(companies, svr.IsSenior[i].CompanyId)
}
return companies
}
companyList = svr.GetCompanyList(doGetCompanyIds)
var companys = make([]protocol.CompanyBase, 0)
for i := range companyList {
c := companyList[i]
if constant.POSTGRESQL_DB_NAME != "partner_dev" {
//通过企业平台 校验模块权限
var user *domain.Users
for j := range svr.IsSenior {
if svr.IsSenior[j].CompanyId == c.Id {
user = svr.IsSenior[j]
break
}
}
if user != nil {
if code, e := adminApiGateway.UserAuth(user.Id, constant.BUSINESS_ADMIN_PLATFORM_ID); e != nil || code != 0 {
log.Debug("【检查权限】", svr.Phone, "【公司】", c.Id, user.Id, code, e.Error())
continue
} else {
log.Debug("【检查权限】", svr.Phone, "【公司】", c.Id, user.Id, code, e)
}
}
}
item := newCompanyBase(c)
companys = append(companys, item)
}
if len(companys) > 0 {
svr.HasAvailableManagerCompany = true
}
if len(companys) > 1 || len(svr.IsPartnerInfo) > 0 { // 有真实合伙公司或高管公司时,过滤游客公司
var companies = make([]protocol.CompanyBase, 0)
for _, company := range companys {
if company.Id != int64(constant.DEFAULT_GUEST_COMPANY) {
companies = append(companies, company)
}
}
companys = companies
}
response["companys"] = companys
return response, nil
}
func (svr *PgLoginService) GetCompanyList(funcGetCompanyIds func() []int64) []*domain.Company {
var (
CompanyRepository, _ = repository.NewCompanyRepository(svr.transactionContext)
companyList []*domain.Company
)
var companies []int64 = funcGetCompanyIds()
if len(companies) == 0 {
return companyList
}
if _, v, e := CompanyRepository.Find(map[string]interface{}{"inCompanyIds": companies, "enable": 1, "sortByCreateTime": domain.DESC}); e != nil {
log.Error(e)
return companyList
} else {
companyList = v
}
return companyList
}
func (svr *PgLoginService) GetJoinWays(partnerCategory []*domain.PartnerCategoryInfo, partnerInfo *domain.PartnerInfo, bonus float64) []joinWay {
searchCategory := func(partnerCategory []*domain.PartnerCategoryInfo, id int64) *domain.PartnerCategoryInfo {
for i := range partnerCategory {
if partnerCategory[i].Id == id {
return partnerCategory[i]
}
}
return nil
}
var joinWays []joinWay
for i := range partnerCategory {
c := partnerCategory[i]
searchC := searchCategory(partnerInfo.PartnerCategoryInfos, c.Id)
if searchC != nil {
item := joinWay{
Type: int(c.Id),
Name: c.Name,
}
joinWays = append(joinWays, item)
}
}
for i := range joinWays {
joinWays[i].Percent = computeBonusPercent(float64(len(joinWays)), 1) * 100
}
return joinWays
}
func newCompanyBase(company *domain.Company) protocol.CompanyBase {
return protocol.CompanyBase{
Id: company.Id,
Name: company.Name,
ShortName: company.Abbreviation,
Image: protocol.NewImage(company.Logo),
Phone: company.Phone,
}
}
func computeBonusPercent(totalBonus float64, bonus float64) float64 {
if totalBonus == 0 {
return 0
}
return utils.Decimal(bonus / totalBonus)
}
/**
* @Author SteveChan
* @Description // 注册用户到合伙人
* @Date 13:52 2021/1/13
* @Param
* @return
**/
func (svr *PgLoginService) RegistryUser(phone string) error {
var (
PartnerInfoService, _ = repository.NewPartnerInfoRepository(svr.transactionContext)
UsersRepository, _ = repository.NewUsersRepository(svr.transactionContext)
isPartner bool
isPartnerAvailable bool
isGuestPartner bool
isGuestPartnerAvailable bool
isUser bool
isUserAvailable bool
isUserSenior bool
)
partnerInfo, errPartner := PartnerInfoService.FindOne(map[string]interface{}{"account": phone, "isNot": constant.DEFAULT_GUEST_COMPANY}) // 合伙人在正常公司是否存在
if partnerInfo == nil {
isPartner = false
} else {
isPartner = true
}
partnerAvailableInfo, errPartner := PartnerInfoService.FindOne(map[string]interface{}{"account": phone, "status": 1, "isNot": constant.DEFAULT_GUEST_COMPANY}) // 合伙人在正常公司是否有效
if partnerAvailableInfo == nil {
isPartnerAvailable = false
} else {
isPartnerAvailable = true
}
guestInfo, _ := PartnerInfoService.FindOne(map[string]interface{}{"account": phone, "companyId": constant.DEFAULT_GUEST_COMPANY}) // 合伙人是否存在游客公司
if guestInfo == nil {
isGuestPartner = false
} else {
isGuestPartner = true
}
guestAvailableInfo, _ := PartnerInfoService.FindOne(map[string]interface{}{"account": phone, "status": 1, "companyId": constant.DEFAULT_GUEST_COMPANY}) // 合伙人在游客公司是否有效
if guestAvailableInfo == nil {
isGuestPartnerAvailable = false
} else {
isGuestPartnerAvailable = true
}
user, errUser := UsersRepository.FindOne(map[string]interface{}{"phone": phone, "deleteAtIsNull": true}) // 用户是否存在
if user == nil {
isUser = false
} else {
isUser = true
}
userAvailable, _ := UsersRepository.FindOne(map[string]interface{}{"phone": phone, "status": 1, "deleteAtIsNull": true}) // 用户是否有效
if userAvailable == nil {
isUserAvailable = false
} else {
isUserAvailable = true
}
senior, _ := UsersRepository.FindOne(map[string]interface{}{"phone": phone, "status": 1, "isSenior": 1, "deleteAtIsNull": true}) // 用户是否是高管
if senior == nil {
isUserSenior = false
} else {
isUserSenior = true
}
fmt.Print("合伙人在正常公司存在?", isPartner, "\n")
fmt.Print("合伙人在正常公司有效?", isPartnerAvailable, "\n")
fmt.Print("合伙人在游客公司存在?", isGuestPartner, "\n")
fmt.Print("合伙人在游客公司有效?", isGuestPartnerAvailable, "\n")
fmt.Print("用户存在?", isUser, "\n")
fmt.Print("用户有效?", isUserAvailable, "\n")
fmt.Print("用户高管?", isUserSenior, "\n")
// 用户在正常公司存在且无效或者不存在、合伙人在正常公司存在且无效或者不存在、合伙人在游客公司存在且无效,更新游客公司合伙人状态
//if (isUser && !isUserAvailable || !isUser) && (isPartner && !isPartnerAvailable || !isPartner) && (isGuestPartner && !isGuestPartnerAvailable) {
// _, err := svr.transactionContext.PgTx.Model(&models.PartnerInfo{
// CompanyId: int64(constant.DEFAULT_GUEST_COMPANY),
// PartnerName: phone,
// Account: phone,
// Password: "7c4a8d09ca3762af61e59520943dc26494f8941b",
// PartnerCategory: 1,
// RegionInfo: &domain.RegionInfo{
// RegionName: "客户区域",
// RegionId: 0,
// },
// Status: 1,
// CooperateTime: time.Now(),
// CreateAt: time.Now(),
// UpdateAt: time.Now(),
// PartnerCategoryInfos: []*models.PartnerCategoryInfo{&models.PartnerCategoryInfo{Id: 1, Code: phone}},
// Salesman: []*domain.Salesman{&domain.Salesman{Name: phone, Telephone: phone}}}).
// Where("partner_info.account = ?", phone).
// Where("partner_info.company_id = ?", constant.DEFAULT_GUEST_COMPANY).
// Update()
// if err != nil {
// return err
// }
//}
// 合伙人存在、用户存在、是高管(高管合伙人)
// 合伙人不存在、用户存在、是高管(高管)|| partnerInfo == nil && user != nil && senior != nil
// 合伙人存在、用户存在、非高管(合伙人)
// 游客公司合伙人存在
//if partnerInfo != nil && user != nil && senior != nil || partnerInfo != nil && user != nil && senior == nil || guestInfo != nil {
// return nil
//}
if guestInfo != nil {
return nil
}
// 用户在正常公司存在且无效或者存在非高管或者不存在、合伙人在正常公司存在且无效或者不存在、合伙人在游客公司不存在、注册合伙人到游客公司
if !isGuestPartner && (isUser && !isUserAvailable || isUser && !isUserSenior || !isUser) && (isPartner && !isPartnerAvailable || !isPartner) {
id := time.Now().Unix()
errPartner = svr.transactionContext.PgDd.Insert(&models.PartnerInfo{
Id: id,
CompanyId: int64(constant.DEFAULT_GUEST_COMPANY),
PartnerName: phone,
Account: phone,
Password: "7c4a8d09ca3762af61e59520943dc26494f8941b",
Status: 1,
PartnerCategory: 1,
RegionInfo: &domain.RegionInfo{
RegionName: "客户区域",
RegionId: 0,
},
CooperateTime: time.Now(),
CreateAt: time.Now(),
UpdateAt: time.Now(),
PartnerCategoryInfos: []*domain.PartnerCategoryInfo{{Id: 1, Code: phone}},
Salesman: []*domain.Salesman{{Name: phone, Telephone: phone}},
})
}
// 合伙人不存在、用户存在、非高管(普通用户)-> 注册用户
// 合伙人不存在、用户不存在(游客)-> 注册用户
if errPartner != nil && errUser == nil {
id := time.Now().Unix()
errPartner = svr.transactionContext.PgDd.Insert(&models.PartnerInfo{
Id: id,
CompanyId: int64(constant.DEFAULT_GUEST_COMPANY),
PartnerName: phone,
Account: phone,
Password: "7c4a8d09ca3762af61e59520943dc26494f8941b",
Status: 1,
PartnerCategory: 1,
RegionInfo: &domain.RegionInfo{
RegionName: "客户区域",
RegionId: 0,
},
CooperateTime: time.Now(),
CreateAt: time.Now(),
UpdateAt: time.Now(),
PartnerCategoryInfos: []*domain.PartnerCategoryInfo{{Id: 1, Code: phone}},
Salesman: []*domain.Salesman{{Name: phone, Telephone: phone}},
})
}
return errPartner
}
/**
* @Author SteveChan
* @Description //TODO 操作游客
* @Date 15:20 2021/2/7
* @Param
* @return
**/
func (svr *PgLoginService) OperateGuest(phone string) error {
var (
PartnerInfoService, _ = repository.NewPartnerInfoRepository(svr.transactionContext)
UsersRepository, _ = repository.NewUsersRepository(svr.transactionContext)
)
// 真实公司检索合伙人身份(账号未禁用)
partnerInfo, errPartner := PartnerInfoService.FindOne(map[string]interface{}{"account": phone, "status": 1, "isNot": constant.DEFAULT_GUEST_COMPANY})
// 真实公司检索用户身份(账号未删除且是高管)
user, errUser := UsersRepository.FindOne(map[string]interface{}{"phone": phone, "isSenior": 1, "deleteAtIsNull": true, "isNot": constant.DEFAULT_GUEST_COMPANY})
// 存在合伙人或者用户身份,不进行游客注册操作
if partnerInfo != nil || user != nil {
return nil
}
if errUser != nil && errPartner != nil { // 合伙人身份和用户身份均不存在,注册游客合伙人
id := time.Now().Unix()
_, errInsert := svr.transactionContext.PgDd.Model(models.PartnerInfo{
Id: id,
CompanyId: int64(constant.DEFAULT_GUEST_COMPANY),
PartnerName: phone,
Account: phone,
Password: "7c4a8d09ca3762af61e59520943dc26494f8941b",
Status: 1,
PartnerCategory: 1,
RegionInfo: &domain.RegionInfo{
RegionName: "客户区域",
RegionId: 0,
},
CooperateTime: time.Now(),
CreateAt: time.Now(),
UpdateAt: time.Now(),
PartnerCategoryInfos: []*domain.PartnerCategoryInfo{{Id: 1, Code: phone}},
Salesman: []*domain.Salesman{{Name: phone, Telephone: phone}},
}).Insert()
if errInsert != nil {
return errInsert
}
} else { // 真实公司存在合伙人或者高管用户,删除游客合伙人
_, errDelete := svr.transactionContext.PgDd.Model((*models.PartnerInfo)(nil)).
Where("account = ?", phone).
Where("company_id = ?", constant.DEFAULT_GUEST_COMPANY).
Delete()
if errDelete != nil {
return errDelete
}
}
return nil
}
// 注册游客到指定的公司
func (svr *PgLoginService) RegistryGuest(phone string) error {
var (
PartnerInfoService, _ = repository.NewPartnerInfoRepository(svr.transactionContext)
UsersRepository, _ = repository.NewUsersRepository(svr.transactionContext)
)
partnerInfo, errPartner := PartnerInfoService.FindOne(map[string]interface{}{"account": phone})
user, errUser := UsersRepository.FindOne(map[string]interface{}{"phone": phone, "deleteAtIsNull": true})
if partnerInfo != nil || user != nil {
return nil
}
// 注册用户
if errUser != nil && errPartner != nil {
id := time.Now().Unix()
errPartner = svr.transactionContext.PgDd.Insert(&models.PartnerInfo{
Id: id,
CompanyId: int64(constant.DEFAULT_GUEST_COMPANY),
PartnerName: phone,
Account: phone,
Password: "7c4a8d09ca3762af61e59520943dc26494f8941b",
Status: 1,
PartnerCategory: 1,
RegionInfo: &domain.RegionInfo{
RegionName: "客户区域",
RegionId: 0,
},
CooperateTime: time.Now(),
CreateAt: time.Now(),
UpdateAt: time.Now(),
PartnerCategoryInfos: []*domain.PartnerCategoryInfo{{Id: 1, Code: phone}},
Salesman: []*domain.Salesman{{Name: phone, Telephone: phone}},
})
}
// 删除用户
return errPartner
}
type Company struct {
protocol.CompanyBase
// 收入占比
IncomePercent float64 `json:"incomePercent"`
// 分红金额
DividendMoney float64 `json:"dividendMoney"`
JoinWays []joinWay `json:"joinWays"`
}
type incomeInfo struct {
// 收入占比
IncomePercent float64 `json:"incomePercent"`
// 分红金额
DividendMoney float64 `json:"dividendMoney"`
}
type joinWay struct {
Type int `json:"type"`
Name string `json:"name"`
Percent float64 `json:"percent"`
}
func NewPgLoginService(ctx *transaction.TransactionContext) *PgLoginService {
return &PgLoginService{
transactionContext: ctx,
HasAvailableCompany: false,
}
}