正在显示
3 个修改的文件
包含
50 行增加
和
13 行删除
@@ -29,12 +29,11 @@ type UserCompany struct { | @@ -29,12 +29,11 @@ type UserCompany struct { | ||
29 | EntryTime time.Time `orm:"column(entry_time);type(date);null" description:"入职时间"` | 29 | EntryTime time.Time `orm:"column(entry_time);type(date);null" description:"入职时间"` |
30 | Workspace string `orm:"column(workspace);size(255)" description:"工作地点"` | 30 | Workspace string `orm:"column(workspace);size(255)" description:"工作地点"` |
31 | IsBusiness int8 `orm:"column(is_business)" description:"是否开启业务状态 1是 0否"` | 31 | IsBusiness int8 `orm:"column(is_business)" description:"是否开启业务状态 1是 0否"` |
32 | - //Status int8 `orm:"column(status)" description:"状态 1正常 2禁用"` | ||
33 | - Avatar string `orm:"column(avatar);size(255)" description:"头像"` | ||
34 | - Remarks string `orm:"column(remarks);size(255)" description:"备注"` | ||
35 | - AdminType int8 `orm:"column(admin_type)" description:"1普通用户 2主管理员"` | ||
36 | - ChargeStatus int8 `orm:"column(charge_status)" description:"是否为当前公司主管 1 是2 否"` | ||
37 | - ExtraText string `orm:"column(extra_text);null" description:"自定义参数数据"` | 32 | + Avatar string `orm:"column(avatar);size(255)" description:"头像"` |
33 | + Remarks string `orm:"column(remarks);size(255)" description:"备注"` | ||
34 | + AdminType int8 `orm:"column(admin_type)" description:"1普通用户 2主管理员"` | ||
35 | + ChargeStatus int8 `orm:"column(charge_status)" description:"是否为当前公司主管 1 是2 否"` | ||
36 | + ExtraText string `orm:"column(extra_text);null" description:"自定义参数数据"` | ||
38 | } | 37 | } |
39 | 38 | ||
40 | func (t *UserCompany) TableName() string { | 39 | func (t *UserCompany) TableName() string { |
@@ -47,6 +46,12 @@ const ( | @@ -47,6 +46,12 @@ const ( | ||
47 | USERCOMPANY_ENABLE_NO int8 = 2 // 无效 | 46 | USERCOMPANY_ENABLE_NO int8 = 2 // 无效 |
48 | ) | 47 | ) |
49 | 48 | ||
49 | +//是否为当前公司主管 1 是2 否 | ||
50 | +const ( | ||
51 | + USERCOMPANY_CHARGE_YES int8 = 1 | ||
52 | + USERCOMPANY_CHARGE_NO int8 = 2 | ||
53 | +) | ||
54 | + | ||
50 | func (t *UserCompany) IsEnable() bool { | 55 | func (t *UserCompany) IsEnable() bool { |
51 | switch t.Enable { | 56 | switch t.Enable { |
52 | case USERCOMPANY_ENABLE_YES: | 57 | case USERCOMPANY_ENABLE_YES: |
@@ -210,8 +210,11 @@ func initUserCompany(newcompany *models.Company, newuser *models.User, o orm.Orm | @@ -210,8 +210,11 @@ func initUserCompany(newcompany *models.Company, newuser *models.User, o orm.Orm | ||
210 | } | 210 | } |
211 | } else if err == orm.ErrNoRows { | 211 | } else if err == orm.ErrNoRows { |
212 | uc = &models.UserCompany{ | 212 | uc = &models.UserCompany{ |
213 | - UserId: newuser.Id, | ||
214 | - CompanyId: newcompany.Id, | 213 | + UserId: newuser.Id, |
214 | + CompanyId: newcompany.Id, | ||
215 | + OpenId: newuser.UserCenterId, | ||
216 | + Enable: models.USERCOMPANY_ENABLE_YES, | ||
217 | + ChargeStatus: models.USERCOMPANY_CHARGE_YES, | ||
215 | } | 218 | } |
216 | _, err = models.AddUserCompany(uc, o) | 219 | _, err = models.AddUserCompany(uc, o) |
217 | if err != nil { | 220 | if err != nil { |
@@ -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 | } |
-
请 注册 或 登录 后发表评论