|
@@ -4,16 +4,19 @@ import ( |
|
@@ -4,16 +4,19 @@ import ( |
4
|
"fmt"
|
4
|
"fmt"
|
5
|
"oppmg/common/log"
|
5
|
"oppmg/common/log"
|
6
|
"oppmg/models"
|
6
|
"oppmg/models"
|
|
|
7
|
+
|
|
|
8
|
+ "github.com/astaxie/beego/orm"
|
7
|
)
|
9
|
)
|
8
|
|
10
|
|
9
|
-// AdminChance
|
11
|
+// AdminChance g更换公司主管
|
10
|
//companyid 总管理后台的公司id
|
12
|
//companyid 总管理后台的公司id
|
11
|
func AdminChance(companyid int64, phone string) error {
|
13
|
func AdminChance(companyid int64, phone string) error {
|
12
|
var (
|
14
|
var (
|
13
|
companyData *models.Company
|
15
|
companyData *models.Company
|
14
|
userData *models.User
|
16
|
userData *models.User
|
15
|
- // userCompanyData *models.UserCompany
|
|
|
16
|
err error
|
17
|
err error
|
|
|
18
|
+ newCharge *models.UserCompany
|
|
|
19
|
+ oldCharge *models.UserCompany
|
17
|
)
|
20
|
)
|
18
|
companyData, err = models.GetCompanyByUCenter(companyid)
|
21
|
companyData, err = models.GetCompanyByUCenter(companyid)
|
19
|
if err != nil {
|
22
|
if err != nil {
|
|
@@ -27,18 +30,44 @@ func AdminChance(companyid int64, phone string) error { |
|
@@ -27,18 +30,44 @@ func AdminChance(companyid int64, phone string) error { |
27
|
log.Error(err.Error())
|
30
|
log.Error(err.Error())
|
28
|
return e
|
31
|
return e
|
29
|
}
|
32
|
}
|
30
|
- _, err = models.GetUserCompanyBy(userData.Id, companyData.Id)
|
33
|
+ newCharge, err = models.GetUserCompanyBy(userData.Id, companyData.Id)
|
31
|
if err != nil {
|
34
|
if err != nil {
|
32
|
e := fmt.Errorf("获取用户和公司的对应关系数据失败,user_id:%d,company_id:%d", userData.Id, companyData.Id)
|
35
|
e := fmt.Errorf("获取用户和公司的对应关系数据失败,user_id:%d,company_id:%d", userData.Id, companyData.Id)
|
33
|
log.Error(e.Error())
|
36
|
log.Error(e.Error())
|
34
|
return e
|
37
|
return e
|
35
|
}
|
38
|
}
|
|
|
39
|
+ oldCharge, err = models.GetUserCompanyBy(companyData.AdminId, companyData.Id)
|
|
|
40
|
+ if err != nil {
|
|
|
41
|
+ e := fmt.Errorf("获取公司原来的主管对应数据失败,user_id:%d,company_id:%d", companyData.AdminId, companyData.Id)
|
|
|
42
|
+ log.Error(e.Error())
|
|
|
43
|
+ return e
|
|
|
44
|
+ }
|
|
|
45
|
+ o := orm.NewOrm()
|
|
|
46
|
+ o.Begin()
|
36
|
companyData.AdminId = userData.Id
|
47
|
companyData.AdminId = userData.Id
|
37
|
- err = models.UpdateCompanyById(companyData, []string{"AdminId"})
|
48
|
+ err = models.UpdateCompanyById(companyData, []string{"AdminId"}, o)
|
38
|
if err != nil {
|
49
|
if err != nil {
|
|
|
50
|
+ o.Rollback()
|
39
|
e := fmt.Errorf("更新公司数据失败,err:%s", err)
|
51
|
e := fmt.Errorf("更新公司数据失败,err:%s", err)
|
40
|
log.Error(e.Error())
|
52
|
log.Error(e.Error())
|
41
|
return e
|
53
|
return e
|
42
|
}
|
54
|
}
|
|
|
55
|
+ newCharge.ChargeStatus = models.USERCOMPANY_CHARGE_YES
|
|
|
56
|
+ oldCharge.ChargeStatus = models.USERCOMPANY_CHARGE_NO
|
|
|
57
|
+ err = models.UpdateUserCompanyById(newCharge, []string{"ChargeStatus"}, o)
|
|
|
58
|
+ if err != nil {
|
|
|
59
|
+ o.Rollback()
|
|
|
60
|
+ e := fmt.Errorf("更新原公司主管理员数据失败,user_company_id=%d,err:%s", oldCharge.Id, err)
|
|
|
61
|
+ log.Error(e.Error())
|
|
|
62
|
+ return e
|
|
|
63
|
+ }
|
|
|
64
|
+ err = models.UpdateUserCompanyById(oldCharge, []string{"ChargeStatus"}, o)
|
|
|
65
|
+ if err != nil {
|
|
|
66
|
+ o.Rollback()
|
|
|
67
|
+ e := fmt.Errorf("更新新公司主管理员数据失败,user_company_id=%d , err:%s", newCharge.Id, err)
|
|
|
68
|
+ log.Error(e.Error())
|
|
|
69
|
+ return e
|
|
|
70
|
+ }
|
|
|
71
|
+ o.Commit()
|
43
|
return nil
|
72
|
return nil
|
44
|
} |
73
|
} |