|
@@ -565,7 +565,26 @@ func DeleteEmployeeData(data DeleteUserData) error { |
|
@@ -565,7 +565,26 @@ func DeleteEmployeeData(data DeleteUserData) error { |
565
|
log.Error("h获取公司数据失败,user_center_id=%d,err:%s", data.CompanyId, err)
|
565
|
log.Error("h获取公司数据失败,user_center_id=%d,err:%s", data.CompanyId, err)
|
566
|
return errors.New("获取公司数据失败")
|
566
|
return errors.New("获取公司数据失败")
|
567
|
}
|
567
|
}
|
|
|
568
|
+ var (
|
|
|
569
|
+ userCompanyDatas []models.UserCompany
|
|
|
570
|
+ userIdMap = make(map[int64]int64)
|
|
|
571
|
+ )
|
568
|
o := orm.NewOrm()
|
572
|
o := orm.NewOrm()
|
|
|
573
|
+ o.Begin()
|
|
|
574
|
+ _, err = o.QueryTable(&models.UserCompany{}).
|
|
|
575
|
+ Filter("id__in", data.Ids).
|
|
|
576
|
+ Filter("company_id", companyData.Id).
|
|
|
577
|
+ Filter("delete_at", 0).
|
|
|
578
|
+ All(&userCompanyDatas)
|
|
|
579
|
+ if err != nil {
|
|
|
580
|
+ o.Rollback()
|
|
|
581
|
+ log.Error("获取用户数据失败,data=%+v", data)
|
|
|
582
|
+ return errors.New("删除user_company数据失败")
|
|
|
583
|
+ }
|
|
|
584
|
+ for i := range userCompanyDatas {
|
|
|
585
|
+ userID := userCompanyDatas[i].UserId
|
|
|
586
|
+ userIdMap[userID] = userID
|
|
|
587
|
+ }
|
569
|
_, err = o.QueryTable(&models.UserCompany{}).
|
588
|
_, err = o.QueryTable(&models.UserCompany{}).
|
570
|
Filter("id__in", data.Ids).
|
589
|
Filter("id__in", data.Ids).
|
571
|
Filter("company_id", companyData.Id).
|
590
|
Filter("company_id", companyData.Id).
|
|
@@ -574,9 +593,36 @@ func DeleteEmployeeData(data DeleteUserData) error { |
|
@@ -574,9 +593,36 @@ func DeleteEmployeeData(data DeleteUserData) error { |
574
|
"enable": models.USERCOMPANY_ENABLE_NO,
|
593
|
"enable": models.USERCOMPANY_ENABLE_NO,
|
575
|
})
|
594
|
})
|
576
|
if err != nil {
|
595
|
if err != nil {
|
|
|
596
|
+ o.Rollback()
|
577
|
log.Error("更新user_company数据失败:%s", err)
|
597
|
log.Error("更新user_company数据失败:%s", err)
|
578
|
return errors.New("删除user_company数据失败")
|
598
|
return errors.New("删除user_company数据失败")
|
579
|
}
|
599
|
}
|
|
|
600
|
+ var deleteUserIds []int64
|
|
|
601
|
+ for _, userId := range userIdMap {
|
|
|
602
|
+ cnt, err := o.QueryTable(&models.UserCompany{}).
|
|
|
603
|
+ Filter("user_id", userId).
|
|
|
604
|
+ Filter("delete_at", 0).
|
|
|
605
|
+ Count()
|
|
|
606
|
+ if err != nil {
|
|
|
607
|
+ o.Rollback()
|
|
|
608
|
+ log.Error("查询user_company数据出现错误,err=%s", err)
|
|
|
609
|
+ return errors.New("删除user_company数据失败")
|
|
|
610
|
+ }
|
|
|
611
|
+ if cnt == 0 {
|
|
|
612
|
+ deleteUserIds = append(deleteUserIds, userId)
|
|
|
613
|
+ }
|
|
|
614
|
+ }
|
|
|
615
|
+ _, err = o.QueryTable(&models.User{}).
|
|
|
616
|
+ Filter("id__in", deleteUserIds).
|
|
|
617
|
+ Update(orm.Params{
|
|
|
618
|
+ "delete_at": time.Now().Format("2006-01-02 15:04:05"),
|
|
|
619
|
+ })
|
|
|
620
|
+ if err != nil {
|
|
|
621
|
+ o.Rollback()
|
|
|
622
|
+ log.Error("更新user数据失败:%s", err)
|
|
|
623
|
+ return errors.New("删除user_company数据失败")
|
|
|
624
|
+ }
|
|
|
625
|
+ o.Commit()
|
580
|
return nil
|
626
|
return nil
|
581
|
}
|
627
|
}
|
582
|
|
628
|
|
|
@@ -660,41 +706,45 @@ func EmployeeChangePhone(data EmployeeChangePhoneData) error { |
|
@@ -660,41 +706,45 @@ func EmployeeChangePhone(data EmployeeChangePhoneData) error { |
660
|
var (
|
706
|
var (
|
661
|
err error
|
707
|
err error
|
662
|
oldUser *models.User
|
708
|
oldUser *models.User
|
663
|
- newUser *models.User
|
|
|
664
|
userCompanydatas []models.UserCompany
|
709
|
userCompanydatas []models.UserCompany
|
665
|
)
|
710
|
)
|
666
|
- //user 表查询新旧号码用户
|
711
|
+ newUserCompany, _ := models.GetUserCompanyByPhone(data.NewPhone)
|
|
|
712
|
+ if len(newUserCompany) > 0 {
|
|
|
713
|
+ log.Error("新的手机号已被使用,oldPhone=%s ,newPhone=%s", data.OldPhone, data.NewPhone)
|
|
|
714
|
+ return errors.New("新的手机号已被使用")
|
|
|
715
|
+ }
|
|
|
716
|
+ //user 表查询旧号码用户
|
667
|
oldUser, err = models.GetUserByPhone(data.OldPhone)
|
717
|
oldUser, err = models.GetUserByPhone(data.OldPhone)
|
668
|
if err != nil {
|
718
|
if err != nil {
|
669
|
log.Error("获取user数据失败:phone = %s", data.OldPhone)
|
719
|
log.Error("获取user数据失败:phone = %s", data.OldPhone)
|
670
|
return errors.New("获取user数据失败")
|
720
|
return errors.New("获取user数据失败")
|
671
|
}
|
721
|
}
|
672
|
- newUser, err = models.GetUserByPhone(data.NewPhone)
|
|
|
673
|
- if err != nil {
|
|
|
674
|
- log.Error("获取user数据失败:phone = %s", data.NewPhone)
|
|
|
675
|
- return errors.New("获取user数据失败")
|
|
|
676
|
- }
|
|
|
677
|
userCompanydatas, err = models.GetUserCompanyByUserId(oldUser.Id)
|
722
|
userCompanydatas, err = models.GetUserCompanyByUserId(oldUser.Id)
|
678
|
if err != nil {
|
723
|
if err != nil {
|
679
|
log.Error("获取user_company数据失败,user_id=%d", oldUser.Id)
|
724
|
log.Error("获取user_company数据失败,user_id=%d", oldUser.Id)
|
680
|
return errors.New("获取user_company数据失败")
|
725
|
return errors.New("获取user_company数据失败")
|
681
|
}
|
726
|
}
|
682
|
- //user_company表 以旧用户的user_id作条件变更为新用户的对应的user_id,phone,open_id
|
727
|
+ //user_company表 以旧用户的user_id作条件变更为新用户的对应的phone,open_id
|
683
|
o := orm.NewOrm()
|
728
|
o := orm.NewOrm()
|
684
|
o.Begin()
|
729
|
o.Begin()
|
685
|
for i := range userCompanydatas {
|
730
|
for i := range userCompanydatas {
|
686
|
temp := userCompanydatas[i]
|
731
|
temp := userCompanydatas[i]
|
687
|
- temp.UserId = newUser.Id
|
|
|
688
|
- temp.Phone = newUser.Phone
|
|
|
689
|
- temp.OpenId = newUser.UserCenterId
|
732
|
+ temp.Phone = data.NewPhone
|
690
|
temp.UpdateAt = time.Now()
|
733
|
temp.UpdateAt = time.Now()
|
691
|
- err = models.UpdateUserCompanyById(&temp, []string{"UserId", "Phone", "OpenId", "UpdateAt"}, o)
|
734
|
+ err = models.UpdateUserCompanyById(&temp, []string{"Phone", "UpdateAt"}, o)
|
692
|
if err != nil {
|
735
|
if err != nil {
|
693
|
log.Error("更新user_company数据失败,id=%d", temp.Id)
|
736
|
log.Error("更新user_company数据失败,id=%d", temp.Id)
|
694
|
o.Rollback()
|
737
|
o.Rollback()
|
695
|
return errors.New("变更用户手机号操作失败")
|
738
|
return errors.New("变更用户手机号操作失败")
|
696
|
}
|
739
|
}
|
697
|
}
|
740
|
}
|
|
|
741
|
+ oldUser.Phone = data.NewPhone
|
|
|
742
|
+ err = models.UpdateUserById(oldUser, []string{"Phone"}, o)
|
|
|
743
|
+ if err != nil {
|
|
|
744
|
+ log.Error("更新user数据失败,id=%d", oldUser.Id)
|
|
|
745
|
+ o.Rollback()
|
|
|
746
|
+ return errors.New("变更用户手机号操作失败")
|
|
|
747
|
+ }
|
698
|
//user.user_center_id 同 user_company表.open_id
|
748
|
//user.user_center_id 同 user_company表.open_id
|
699
|
//UserAuth注销手机登录
|
749
|
//UserAuth注销手机登录
|
700
|
var oldUserAuthData *models.UserAuth
|
750
|
var oldUserAuthData *models.UserAuth
|