作者 tangxuhui

增加 :同步数据时的操作,变更用户的手机账号

@@ -404,55 +404,55 @@ func (c *CompanyController) UserList() { @@ -404,55 +404,55 @@ func (c *CompanyController) UserList() {
404 404
405 //InitCompany 初始化企业 405 //InitCompany 初始化企业
406 //@router /ucenter/company [post] 406 //@router /ucenter/company [post]
407 -func (c *CompanyController) InitCompany() {  
408 - var msg *protocol.ResponseMessage  
409 - defer func() {  
410 - c.ResposeJson(msg)  
411 - }() 407 +// func (c *CompanyController) InitCompany() {
  408 +// var msg *protocol.ResponseMessage
  409 +// defer func() {
  410 +// c.ResposeJson(msg)
  411 +// }()
412 412
413 - var param protocol.CenterCompanyInfo  
414 - if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {  
415 - log.Error("json 解析失败 err:%s", err)  
416 - msg = protocol.BadRequestParam("1")  
417 - return  
418 - }  
419 - if param.CompanyId <= 0 {  
420 - log.Error("公司id为0")  
421 - msg = protocol.BadRequestParam("1")  
422 - return  
423 - }  
424 - var (  
425 - err error  
426 - )  
427 - param.CompanyName = strings.TrimSpace(param.CompanyName)  
428 - param.AdminAccount = strings.TrimSpace(param.AdminAccount)  
429 - param.AdminName = strings.TrimSpace(param.AdminName)  
430 - if ok := param.IsEnable(); ok {  
431 - if len(param.CompanyName) == 0 {  
432 - log.Error("公司名称空")  
433 - msg = protocol.BadRequestParam("1")  
434 - return  
435 - }  
436 - if len(param.AdminAccount) == 0 {  
437 - log.Error("人员账号空")  
438 - msg = protocol.BadRequestParam("1")  
439 - return  
440 - }  
441 - if len(param.AdminName) == 0 {  
442 - log.Error("人员名称空")  
443 - msg = protocol.BadRequestParam("1")  
444 - return  
445 - }  
446 - err = servecompany.InitCompanyInfo(param)  
447 - } else if ok := param.IsForbid(); ok {  
448 - err = servecompany.ForbidCompany(param.CompanyId)  
449 - } else {  
450 - err = protocol.NewErrWithMessage("1")  
451 - } 413 +// var param protocol.CenterCompanyInfo
  414 +// if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
  415 +// log.Error("json 解析失败 err:%s", err)
  416 +// msg = protocol.BadRequestParam("1")
  417 +// return
  418 +// }
  419 +// if param.CompanyId <= 0 {
  420 +// log.Error("公司id为0")
  421 +// msg = protocol.BadRequestParam("1")
  422 +// return
  423 +// }
  424 +// var (
  425 +// err error
  426 +// )
  427 +// param.CompanyName = strings.TrimSpace(param.CompanyName)
  428 +// param.AdminAccount = strings.TrimSpace(param.AdminAccount)
  429 +// param.AdminName = strings.TrimSpace(param.AdminName)
  430 +// if ok := param.IsEnable(); ok {
  431 +// if len(param.CompanyName) == 0 {
  432 +// log.Error("公司名称空")
  433 +// msg = protocol.BadRequestParam("1")
  434 +// return
  435 +// }
  436 +// if len(param.AdminAccount) == 0 {
  437 +// log.Error("人员账号空")
  438 +// msg = protocol.BadRequestParam("1")
  439 +// return
  440 +// }
  441 +// if len(param.AdminName) == 0 {
  442 +// log.Error("人员名称空")
  443 +// msg = protocol.BadRequestParam("1")
  444 +// return
  445 +// }
  446 +// err = servecompany.InitCompanyInfo(param)
  447 +// } else if ok := param.IsForbid(); ok {
  448 +// err = servecompany.ForbidCompany(param.CompanyId)
  449 +// } else {
  450 +// err = protocol.NewErrWithMessage("1")
  451 +// }
452 452
453 - msg = protocol.NewReturnResponse(nil, err)  
454 - return  
455 -} 453 +// msg = protocol.NewReturnResponse(nil, err)
  454 +// return
  455 +// }
456 456
457 // EditCompanyForUCenter 总后台调用 457 // EditCompanyForUCenter 总后台调用
458 //@router /ucenter/company/edit [post] 458 //@router /ucenter/company/edit [post]
@@ -62,8 +62,13 @@ func GetUserAuthById(id int64) (v *UserAuth, err error) { @@ -62,8 +62,13 @@ func GetUserAuthById(id int64) (v *UserAuth, err error) {
62 62
63 // UpdateUserAuth updates UserAuth by Id and returns error if 63 // UpdateUserAuth updates UserAuth by Id and returns error if
64 // the record to be updated doesn't exist 64 // the record to be updated doesn't exist
65 -func UpdateUserAuthById(m *UserAuth, col []string) (err error) {  
66 - o := orm.NewOrm() 65 +func UpdateUserAuthById(m *UserAuth, col []string, om ...orm.Ormer) (err error) {
  66 + var o orm.Ormer
  67 + if len(om) > 0 {
  68 + o = om[0]
  69 + } else {
  70 + o = orm.NewOrm()
  71 + }
67 // ascertain id exists in the database 72 // ascertain id exists in the database
68 var num int64 73 var num int64
69 if num, err = o.Update(m, col...); err == nil { 74 if num, err = o.Update(m, col...); err == nil {
@@ -195,3 +195,11 @@ func GetUserCompanyAll(companyId int64) (v []*UserCompany, err error) { @@ -195,3 +195,11 @@ func GetUserCompanyAll(companyId int64) (v []*UserCompany, err error) {
195 } 195 }
196 return nil, err 196 return nil, err
197 } 197 }
  198 +
  199 +func GetUserCompanyByUserId(userId int64) (v []UserCompany, err error) {
  200 + o := orm.NewOrm()
  201 + _, err = o.QueryTable(&UserCompany{}).
  202 + Filter("user_id", userId).
  203 + All(&v)
  204 + return
  205 +}
@@ -165,8 +165,8 @@ func init() { @@ -165,8 +165,8 @@ func init() {
165 //beego.NSRouter("/company", &controllers.CompanyController{}, "post:InitCompany"),(废弃) 165 //beego.NSRouter("/company", &controllers.CompanyController{}, "post:InitCompany"),(废弃)
166 beego.NSRouter("/company/info", &controllers.CompanyController{}, "post:GetCompanyForUCenter"), 166 beego.NSRouter("/company/info", &controllers.CompanyController{}, "post:GetCompanyForUCenter"),
167 //beego.NSRouter("/company/edit", &controllers.CompanyController{}, "post:EditCompanyForUCenter"),(废弃) 167 //beego.NSRouter("/company/edit", &controllers.CompanyController{}, "post:EditCompanyForUCenter"),(废弃)
168 - beego.NSRouter("/user/revoke", &controllers.CompanyController{}, "post:UserRevoke"),  
169 - beego.NSRouter("/user/changePhone", &controllers.CompanyController{}, "post:UserChangePhone"), 168 + // beego.NSRouter("/user/revoke", &controllers.CompanyController{}, "post:UserRevoke"),
  169 + // beego.NSRouter("/user/changePhone", &controllers.CompanyController{}, "post:UserChangePhone"),
170 beego.NSRouter("/company/allow_forbid", &controllers.CompanyController{}, "post:AllowForidCompanyForUCenter"), 170 beego.NSRouter("/company/allow_forbid", &controllers.CompanyController{}, "post:AllowForidCompanyForUCenter"),
171 ) 171 )
172 172
1 package company 1 package company
2 2
3 import ( 3 import (
4 - "encoding/json"  
5 - "fmt"  
6 "oppmg/common/log" 4 "oppmg/common/log"
7 "oppmg/models" 5 "oppmg/models"
8 "oppmg/protocol" 6 "oppmg/protocol"
9 - "oppmg/services/ucenter"  
10 "oppmg/utils" 7 "oppmg/utils"
11 "strings" 8 "strings"
12 "time" 9 "time"
@@ -15,445 +12,445 @@ import ( @@ -15,445 +12,445 @@ import (
15 ) 12 )
16 13
17 //InitCompanyInfo 初始化公司 14 //InitCompanyInfo 初始化公司
18 -func InitCompanyInfo(centerCompany protocol.CenterCompanyInfo) error {  
19 - var (  
20 - newDeparment *models.Department  
21 - newRoleGroup *models.Role  
22 - newRole *models.Role  
23 - newUser *models.User  
24 - newCompany *models.Company  
25 - newUserCompany *models.UserCompany  
26 - err error  
27 - )  
28 - o := orm.NewOrm()  
29 - o.Begin()  
30 - //处理用户数据  
31 - newUser, err = initAdminUser(centerCompany, o)  
32 - if err != nil {  
33 - o.Rollback()  
34 - log.Error("处理公司主管数据失败:%s", err)  
35 - return protocol.NewErrWithMessage("1")  
36 - }  
37 - //处理公司数据  
38 - newCompany, err = initCompany(centerCompany, newUser, o)  
39 - if err != nil {  
40 - o.Rollback()  
41 - log.Error("处理公司数据失败:%s", err)  
42 - return protocol.NewErrWithMessage("1")  
43 - }  
44 - err = iniSysConfig(int(newCompany.Id), o)  
45 - if err != nil {  
46 - o.Rollback()  
47 - log.Error("处理评分配置数据失败:%s", err)  
48 - return protocol.NewErrWithMessage("1")  
49 - }  
50 - //添加user_company  
51 - newUserCompany, err = initUserCompany(newCompany, newUser, o)  
52 - if err != nil {  
53 - o.Rollback()  
54 - log.Error("处理user_company数据失败:%s", err)  
55 - return protocol.NewErrWithMessage("1")  
56 - }  
57 - //添加部门  
58 - newDeparment, err = initDepartment(newCompany, newUserCompany, o)  
59 - if err != nil {  
60 - o.Rollback()  
61 - log.Error("处理部门数据失败:%s", err)  
62 - return protocol.NewErrWithMessage("1")  
63 - }  
64 - //添加用户部门数据  
65 - _, err = initUserDedaprtmet(newDeparment, newUserCompany, o)  
66 - if err != nil {  
67 - o.Rollback()  
68 - log.Error("处理user_department数据失败:%s", err)  
69 - return protocol.NewErrWithMessage("1")  
70 - }  
71 - //添加角色组  
72 - newRoleGroup, err = initRoleGroup(newCompany, o)  
73 - if err != nil {  
74 - o.Rollback()  
75 - log.Error("处理角色组数据失败:%s", err)  
76 - return protocol.NewErrWithMessage("1")  
77 - }  
78 - //添加角色  
79 - newRole, err = initRole(newCompany, newRoleGroup, o)  
80 - if err != nil {  
81 - o.Rollback()  
82 - log.Error("处理角色数据失败:%s", err)  
83 - return protocol.NewErrWithMessage("1")  
84 - }  
85 - //添加用户的角色  
86 - _, err = initUserRole(newUserCompany, newRole, o)  
87 - if err != nil {  
88 - o.Rollback()  
89 - log.Error("处理user_role数据失败:%s", err)  
90 - return protocol.NewErrWithMessage("1")  
91 - }  
92 - o.Commit()  
93 - return nil  
94 -} 15 +// func InitCompanyInfo(centerCompany protocol.CenterCompanyInfo) error {
  16 +// var (
  17 +// newDeparment *models.Department
  18 +// newRoleGroup *models.Role
  19 +// newRole *models.Role
  20 +// newUser *models.User
  21 +// newCompany *models.Company
  22 +// newUserCompany *models.UserCompany
  23 +// err error
  24 +// )
  25 +// o := orm.NewOrm()
  26 +// o.Begin()
  27 +// //处理用户数据
  28 +// newUser, err = initAdminUser(centerCompany, o)
  29 +// if err != nil {
  30 +// o.Rollback()
  31 +// log.Error("处理公司主管数据失败:%s", err)
  32 +// return protocol.NewErrWithMessage("1")
  33 +// }
  34 +// //处理公司数据
  35 +// newCompany, err = initCompany(centerCompany, newUser, o)
  36 +// if err != nil {
  37 +// o.Rollback()
  38 +// log.Error("处理公司数据失败:%s", err)
  39 +// return protocol.NewErrWithMessage("1")
  40 +// }
  41 +// err = iniSysConfig(int(newCompany.Id), o)
  42 +// if err != nil {
  43 +// o.Rollback()
  44 +// log.Error("处理评分配置数据失败:%s", err)
  45 +// return protocol.NewErrWithMessage("1")
  46 +// }
  47 +// //添加user_company
  48 +// newUserCompany, err = initUserCompany(newCompany, newUser, o)
  49 +// if err != nil {
  50 +// o.Rollback()
  51 +// log.Error("处理user_company数据失败:%s", err)
  52 +// return protocol.NewErrWithMessage("1")
  53 +// }
  54 +// //添加部门
  55 +// newDeparment, err = initDepartment(newCompany, newUserCompany, o)
  56 +// if err != nil {
  57 +// o.Rollback()
  58 +// log.Error("处理部门数据失败:%s", err)
  59 +// return protocol.NewErrWithMessage("1")
  60 +// }
  61 +// //添加用户部门数据
  62 +// _, err = initUserDedaprtmet(newDeparment, newUserCompany, o)
  63 +// if err != nil {
  64 +// o.Rollback()
  65 +// log.Error("处理user_department数据失败:%s", err)
  66 +// return protocol.NewErrWithMessage("1")
  67 +// }
  68 +// //添加角色组
  69 +// newRoleGroup, err = initRoleGroup(newCompany, o)
  70 +// if err != nil {
  71 +// o.Rollback()
  72 +// log.Error("处理角色组数据失败:%s", err)
  73 +// return protocol.NewErrWithMessage("1")
  74 +// }
  75 +// //添加角色
  76 +// newRole, err = initRole(newCompany, newRoleGroup, o)
  77 +// if err != nil {
  78 +// o.Rollback()
  79 +// log.Error("处理角色数据失败:%s", err)
  80 +// return protocol.NewErrWithMessage("1")
  81 +// }
  82 +// //添加用户的角色
  83 +// _, err = initUserRole(newUserCompany, newRole, o)
  84 +// if err != nil {
  85 +// o.Rollback()
  86 +// log.Error("处理user_role数据失败:%s", err)
  87 +// return protocol.NewErrWithMessage("1")
  88 +// }
  89 +// o.Commit()
  90 +// return nil
  91 +// }
95 92
96 -func initCompany(centerCompany protocol.CenterCompanyInfo, admininfo *models.User, o orm.Ormer) (*models.Company, error) {  
97 - var (  
98 - err error  
99 - newCompany = &models.Company{}  
100 - )  
101 - err = o.QueryTable(&models.Company{}).  
102 - Filter("user_center_id", centerCompany.CompanyId).  
103 - One(newCompany)  
104 - if err == nil {  
105 - _, err = o.QueryTable(&models.Company{}).  
106 - Filter("user_center_id", centerCompany.CompanyId).  
107 - Update(orm.Params{  
108 - "name": centerCompany.CompanyName,  
109 - "admin_id": admininfo.Id,  
110 - "delete_at": 0,  
111 - "enable": models.COMPANY_ENABLE_YES,  
112 - })  
113 - if err != nil {  
114 - log.Error("更新公司数据失败:%s", err)  
115 - return nil, err  
116 - }  
117 - } else if err == orm.ErrNoRows {  
118 - newCompany = &models.Company{  
119 - Id: centerCompany.CompanyId,  
120 - Name: centerCompany.CompanyName,  
121 - AdminId: admininfo.Id,  
122 - UserCenterId: centerCompany.CompanyId,  
123 - }  
124 - _, err = models.AddCompany(newCompany, o)  
125 - if err != nil {  
126 - log.Error("添加公司数据失败:%s", err)  
127 - return nil, err  
128 - } 93 +// func initCompany(centerCompany protocol.CenterCompanyInfo, admininfo *models.User, o orm.Ormer) (*models.Company, error) {
  94 +// var (
  95 +// err error
  96 +// newCompany = &models.Company{}
  97 +// )
  98 +// err = o.QueryTable(&models.Company{}).
  99 +// Filter("user_center_id", centerCompany.CompanyId).
  100 +// One(newCompany)
  101 +// if err == nil {
  102 +// _, err = o.QueryTable(&models.Company{}).
  103 +// Filter("user_center_id", centerCompany.CompanyId).
  104 +// Update(orm.Params{
  105 +// "name": centerCompany.CompanyName,
  106 +// "admin_id": admininfo.Id,
  107 +// "delete_at": 0,
  108 +// "enable": models.COMPANY_ENABLE_YES,
  109 +// })
  110 +// if err != nil {
  111 +// log.Error("更新公司数据失败:%s", err)
  112 +// return nil, err
  113 +// }
  114 +// } else if err == orm.ErrNoRows {
  115 +// newCompany = &models.Company{
  116 +// Id: centerCompany.CompanyId,
  117 +// Name: centerCompany.CompanyName,
  118 +// AdminId: admininfo.Id,
  119 +// UserCenterId: centerCompany.CompanyId,
  120 +// }
  121 +// _, err = models.AddCompany(newCompany, o)
  122 +// if err != nil {
  123 +// log.Error("添加公司数据失败:%s", err)
  124 +// return nil, err
  125 +// }
129 126
130 - } else {  
131 - log.Error("查询公司数据失败:%s", err)  
132 - return nil, err  
133 - }  
134 - return newCompany, nil  
135 -} 127 +// } else {
  128 +// log.Error("查询公司数据失败:%s", err)
  129 +// return nil, err
  130 +// }
  131 +// return newCompany, nil
  132 +// }
136 133
137 -func initAdminUser(centerCompany protocol.CenterCompanyInfo, o orm.Ormer) (*models.User, error) {  
138 - var (  
139 - err error  
140 - newUser = &models.User{}  
141 - )  
142 - err = o.QueryTable(&models.User{}).  
143 - Filter("phone", centerCompany.AdminAccount).  
144 - Filter("delete_at", 0).  
145 - One(newUser)  
146 - if err == nil {  
147 - // 更新数据  
148 - _, err = o.QueryTable(&models.User{}).  
149 - Filter("user_center_id", centerCompany.CompanyId).  
150 - Filter("delete_at", 0).  
151 - Update(orm.Params{  
152 - "nick_name": centerCompany.AdminName,  
153 - "phone": centerCompany.AdminAccount,  
154 - "enable_status": models.USER_ENABLE_YES,  
155 - })  
156 - if err != nil {  
157 - log.Error("数据操作失败:%s", err)  
158 - return nil, err  
159 - }  
160 - } else if err == orm.ErrNoRows {  
161 - var (  
162 - ucenterUser = &ucenter.ResponseAddUser{}  
163 - err error  
164 - )  
165 - ucenterUser, err = ucenter.RequestUCenterAddUser(centerCompany.AdminAccount, centerCompany.AdminName, "")  
166 - if err != nil {  
167 - log.Error("获取统一用户中心数据失败 :%s", err)  
168 - return nil, err  
169 - }  
170 - //添加用户  
171 - newUser = &models.User{  
172 - Phone: centerCompany.AdminAccount,  
173 - NickName: centerCompany.AdminName,  
174 - Icon: ucenterUser.Data.Avatar,  
175 - Accid: ucenterUser.Data.Accid,  
176 - UserCenterId: ucenterUser.Data.Id,  
177 - CsAccount: ucenterUser.Data.CustomerAccount,  
178 - }  
179 - _, err = models.AddUser(newUser, o)  
180 - if err != nil {  
181 - log.Error("添加用户数据失败:%s", err)  
182 - return nil, err  
183 - }  
184 - } else {  
185 - log.Error("查询用户数据失败:%s", err)  
186 - return nil, err  
187 - }  
188 - return newUser, nil  
189 -} 134 +// func initAdminUser(centerCompany protocol.CenterCompanyInfo, o orm.Ormer) (*models.User, error) {
  135 +// var (
  136 +// err error
  137 +// newUser = &models.User{}
  138 +// )
  139 +// err = o.QueryTable(&models.User{}).
  140 +// Filter("phone", centerCompany.AdminAccount).
  141 +// Filter("delete_at", 0).
  142 +// One(newUser)
  143 +// if err == nil {
  144 +// // 更新数据
  145 +// _, err = o.QueryTable(&models.User{}).
  146 +// Filter("user_center_id", centerCompany.CompanyId).
  147 +// Filter("delete_at", 0).
  148 +// Update(orm.Params{
  149 +// "nick_name": centerCompany.AdminName,
  150 +// "phone": centerCompany.AdminAccount,
  151 +// "enable_status": models.USER_ENABLE_YES,
  152 +// })
  153 +// if err != nil {
  154 +// log.Error("数据操作失败:%s", err)
  155 +// return nil, err
  156 +// }
  157 +// } else if err == orm.ErrNoRows {
  158 +// var (
  159 +// ucenterUser = &ucenter.ResponseAddUser{}
  160 +// err error
  161 +// )
  162 +// ucenterUser, err = ucenter.RequestUCenterAddUser(centerCompany.AdminAccount, centerCompany.AdminName, "")
  163 +// if err != nil {
  164 +// log.Error("获取统一用户中心数据失败 :%s", err)
  165 +// return nil, err
  166 +// }
  167 +// //添加用户
  168 +// newUser = &models.User{
  169 +// Phone: centerCompany.AdminAccount,
  170 +// NickName: centerCompany.AdminName,
  171 +// Icon: ucenterUser.Data.Avatar,
  172 +// Accid: ucenterUser.Data.Accid,
  173 +// UserCenterId: ucenterUser.Data.Id,
  174 +// CsAccount: ucenterUser.Data.CustomerAccount,
  175 +// }
  176 +// _, err = models.AddUser(newUser, o)
  177 +// if err != nil {
  178 +// log.Error("添加用户数据失败:%s", err)
  179 +// return nil, err
  180 +// }
  181 +// } else {
  182 +// log.Error("查询用户数据失败:%s", err)
  183 +// return nil, err
  184 +// }
  185 +// return newUser, nil
  186 +// }
190 187
191 -func initUserCompany(newcompany *models.Company, newuser *models.User, o orm.Ormer) (*models.UserCompany, error) {  
192 - var (  
193 - err error  
194 - uc = &models.UserCompany{}  
195 - )  
196 - err = o.QueryTable(&models.UserCompany{}).  
197 - Filter("user_id", newuser.Id).  
198 - Filter("company_id", newcompany.Id).  
199 - Filter("delete_at", 0).  
200 - One(uc)  
201 - if err == nil {  
202 - _, err = o.QueryTable(&models.UserCompany{}).  
203 - Filter("id", uc.Id).  
204 - Update(orm.Params{  
205 - "enable": models.USERCOMPANY_ENABLE_YES,  
206 - })  
207 - if err != nil {  
208 - log.Error("更新user_company数据失败:%s", err)  
209 - return nil, err  
210 - }  
211 - } else if err == orm.ErrNoRows {  
212 - uc = &models.UserCompany{  
213 - UserId: newuser.Id,  
214 - CompanyId: newcompany.Id,  
215 - OpenId: newuser.UserCenterId,  
216 - Enable: models.USERCOMPANY_ENABLE_YES,  
217 - ChargeStatus: models.USERCOMPANY_CHARGE_YES,  
218 - }  
219 - _, err = models.AddUserCompany(uc, o)  
220 - if err != nil {  
221 - log.Error("添加user_company数据失败:%s", err)  
222 - return nil, err  
223 - }  
224 - } else {  
225 - log.Error("获取user_company数据失败:%s", err)  
226 - return nil, err  
227 - }  
228 - return uc, nil  
229 -} 188 +// func initUserCompany(newcompany *models.Company, newuser *models.User, o orm.Ormer) (*models.UserCompany, error) {
  189 +// var (
  190 +// err error
  191 +// uc = &models.UserCompany{}
  192 +// )
  193 +// err = o.QueryTable(&models.UserCompany{}).
  194 +// Filter("user_id", newuser.Id).
  195 +// Filter("company_id", newcompany.Id).
  196 +// Filter("delete_at", 0).
  197 +// One(uc)
  198 +// if err == nil {
  199 +// _, err = o.QueryTable(&models.UserCompany{}).
  200 +// Filter("id", uc.Id).
  201 +// Update(orm.Params{
  202 +// "enable": models.USERCOMPANY_ENABLE_YES,
  203 +// })
  204 +// if err != nil {
  205 +// log.Error("更新user_company数据失败:%s", err)
  206 +// return nil, err
  207 +// }
  208 +// } else if err == orm.ErrNoRows {
  209 +// uc = &models.UserCompany{
  210 +// UserId: newuser.Id,
  211 +// CompanyId: newcompany.Id,
  212 +// OpenId: newuser.UserCenterId,
  213 +// Enable: models.USERCOMPANY_ENABLE_YES,
  214 +// ChargeStatus: models.USERCOMPANY_CHARGE_YES,
  215 +// }
  216 +// _, err = models.AddUserCompany(uc, o)
  217 +// if err != nil {
  218 +// log.Error("添加user_company数据失败:%s", err)
  219 +// return nil, err
  220 +// }
  221 +// } else {
  222 +// log.Error("获取user_company数据失败:%s", err)
  223 +// return nil, err
  224 +// }
  225 +// return uc, nil
  226 +// }
230 227
231 -func initDepartment(newCompany *models.Company, newusercompany *models.UserCompany, o orm.Ormer) (*models.Department, error) {  
232 - var (  
233 - newDepartment = &models.Department{}  
234 - err error  
235 - )  
236 - err = o.QueryTable(&models.Department{}).  
237 - Filter("company_id", newCompany.Id).  
238 - Filter("is_top", 1).  
239 - One(newDepartment)  
240 - if err == nil {  
241 - newDepartment.Name = newCompany.Name  
242 - err = models.UpdateDepartmentById(newDepartment, []string{"Name"}, o)  
243 - if err != nil {  
244 - log.Error("更新部门关系树数据失败:%s", err)  
245 - return nil, err  
246 - }  
247 - return newDepartment, nil  
248 - } else if err == orm.ErrNoRows {  
249 - //添加部门  
250 - newDepartment = &models.Department{  
251 - CompanyId: newCompany.Id,  
252 - Name: newCompany.Name,  
253 - IsTop: 1,  
254 - ParentId: 0,  
255 - Relation: fmt.Sprint(utils.GenerateIDBySonyflake()),  
256 - }  
257 - newDepartment.SetManages([]int64{newusercompany.Id})  
258 - _, err = models.AddDepartment(newDepartment, o)  
259 - if err != nil {  
260 - log.Error("添加部门数据失败:%s", err)  
261 - return nil, err  
262 - }  
263 - newDepartment.SetRelation(nil)  
264 - err = models.UpdateDepartmentById(newDepartment, []string{"Relation"}, o)  
265 - if err != nil {  
266 - log.Error("更新部门关系树数据失败:%s", err)  
267 - return nil, err  
268 - }  
269 - } else {  
270 - log.Error("查询部门数据失败:%s", err)  
271 - return nil, err  
272 - } 228 +// func initDepartment(newCompany *models.Company, newusercompany *models.UserCompany, o orm.Ormer) (*models.Department, error) {
  229 +// var (
  230 +// newDepartment = &models.Department{}
  231 +// err error
  232 +// )
  233 +// err = o.QueryTable(&models.Department{}).
  234 +// Filter("company_id", newCompany.Id).
  235 +// Filter("is_top", 1).
  236 +// One(newDepartment)
  237 +// if err == nil {
  238 +// newDepartment.Name = newCompany.Name
  239 +// err = models.UpdateDepartmentById(newDepartment, []string{"Name"}, o)
  240 +// if err != nil {
  241 +// log.Error("更新部门关系树数据失败:%s", err)
  242 +// return nil, err
  243 +// }
  244 +// return newDepartment, nil
  245 +// } else if err == orm.ErrNoRows {
  246 +// //添加部门
  247 +// newDepartment = &models.Department{
  248 +// CompanyId: newCompany.Id,
  249 +// Name: newCompany.Name,
  250 +// IsTop: 1,
  251 +// ParentId: 0,
  252 +// Relation: fmt.Sprint(utils.GenerateIDBySonyflake()),
  253 +// }
  254 +// newDepartment.SetManages([]int64{newusercompany.Id})
  255 +// _, err = models.AddDepartment(newDepartment, o)
  256 +// if err != nil {
  257 +// log.Error("添加部门数据失败:%s", err)
  258 +// return nil, err
  259 +// }
  260 +// newDepartment.SetRelation(nil)
  261 +// err = models.UpdateDepartmentById(newDepartment, []string{"Relation"}, o)
  262 +// if err != nil {
  263 +// log.Error("更新部门关系树数据失败:%s", err)
  264 +// return nil, err
  265 +// }
  266 +// } else {
  267 +// log.Error("查询部门数据失败:%s", err)
  268 +// return nil, err
  269 +// }
273 270
274 - return newDepartment, nil  
275 -} 271 +// return newDepartment, nil
  272 +// }
276 273
277 -func initUserDedaprtmet(newDepartment *models.Department, newUserCompany *models.UserCompany, o orm.Ormer) (*models.UserDepartment, error) {  
278 - var (  
279 - newUserDepartment = &models.UserDepartment{}  
280 - err error  
281 - )  
282 - err = o.QueryTable(&models.UserDepartment{}).  
283 - Filter("department_id", newDepartment.Id).  
284 - Filter("user_company_id", newUserCompany.Id).  
285 - Filter("enable_status", models.USER_DEPARTMENT_ENABLE_YES).  
286 - One(newUserDepartment)  
287 - if err == nil {  
288 - return newUserDepartment, nil  
289 - } else if err == orm.ErrNoRows {  
290 - //添加部门  
291 - newUserDepartment = &models.UserDepartment{  
292 - UserCompanyId: newUserCompany.Id,  
293 - //UserId: newUserCompany.UserId,  
294 - CompanyId: newUserCompany.CompanyId,  
295 - DepartmentId: newDepartment.Id,  
296 - }  
297 - _, err = models.AddUserDepartment(newUserDepartment, o)  
298 - if err != nil {  
299 - log.Error("添加部门数据失败:%s", err)  
300 - return nil, err  
301 - }  
302 - } else {  
303 - log.Error("查询部门数据失败:%s", err)  
304 - return nil, err  
305 - } 274 +// func initUserDedaprtmet(newDepartment *models.Department, newUserCompany *models.UserCompany, o orm.Ormer) (*models.UserDepartment, error) {
  275 +// var (
  276 +// newUserDepartment = &models.UserDepartment{}
  277 +// err error
  278 +// )
  279 +// err = o.QueryTable(&models.UserDepartment{}).
  280 +// Filter("department_id", newDepartment.Id).
  281 +// Filter("user_company_id", newUserCompany.Id).
  282 +// Filter("enable_status", models.USER_DEPARTMENT_ENABLE_YES).
  283 +// One(newUserDepartment)
  284 +// if err == nil {
  285 +// return newUserDepartment, nil
  286 +// } else if err == orm.ErrNoRows {
  287 +// //添加部门
  288 +// newUserDepartment = &models.UserDepartment{
  289 +// UserCompanyId: newUserCompany.Id,
  290 +// //UserId: newUserCompany.UserId,
  291 +// CompanyId: newUserCompany.CompanyId,
  292 +// DepartmentId: newDepartment.Id,
  293 +// }
  294 +// _, err = models.AddUserDepartment(newUserDepartment, o)
  295 +// if err != nil {
  296 +// log.Error("添加部门数据失败:%s", err)
  297 +// return nil, err
  298 +// }
  299 +// } else {
  300 +// log.Error("查询部门数据失败:%s", err)
  301 +// return nil, err
  302 +// }
306 303
307 - return newUserDepartment, nil  
308 -} 304 +// return newUserDepartment, nil
  305 +// }
309 306
310 -func initRoleGroup(newCompany *models.Company, o orm.Ormer) (*models.Role, error) {  
311 - var (  
312 - newRoleGroup = &models.Role{}  
313 - err error  
314 - )  
315 - err = o.QueryTable(&models.Role{}).  
316 - Filter("delete_at", 0).  
317 - Filter("is_default", models.ROLE_DEFAULR).  
318 - Filter("types", models.ROLETYPES_GROUP).  
319 - Filter("company_id", newCompany.Id).  
320 - One(newRoleGroup)  
321 - if err == nil {  
322 - return newRoleGroup, nil  
323 - } else if err == orm.ErrNoRows {  
324 - //添加部门  
325 - newRoleGroup = &models.Role{  
326 - Types: models.ROLETYPES_GROUP,  
327 - CompanyId: newCompany.Id,  
328 - IsDefault: models.ROLE_DEFAULR,  
329 - Name: "管理员",  
330 - }  
331 - _, err = models.AddRole(newRoleGroup, o)  
332 - if err != nil {  
333 - log.Error("添加角色组数据失败:%s", err)  
334 - return nil, err  
335 - }  
336 - } else {  
337 - log.Error("查询角色组数据失败:%s", err)  
338 - return nil, err  
339 - } 307 +// func initRoleGroup(newCompany *models.Company, o orm.Ormer) (*models.Role, error) {
  308 +// var (
  309 +// newRoleGroup = &models.Role{}
  310 +// err error
  311 +// )
  312 +// err = o.QueryTable(&models.Role{}).
  313 +// Filter("delete_at", 0).
  314 +// Filter("is_default", models.ROLE_DEFAULR).
  315 +// Filter("types", models.ROLETYPES_GROUP).
  316 +// Filter("company_id", newCompany.Id).
  317 +// One(newRoleGroup)
  318 +// if err == nil {
  319 +// return newRoleGroup, nil
  320 +// } else if err == orm.ErrNoRows {
  321 +// //添加部门
  322 +// newRoleGroup = &models.Role{
  323 +// Types: models.ROLETYPES_GROUP,
  324 +// CompanyId: newCompany.Id,
  325 +// IsDefault: models.ROLE_DEFAULR,
  326 +// Name: "管理员",
  327 +// }
  328 +// _, err = models.AddRole(newRoleGroup, o)
  329 +// if err != nil {
  330 +// log.Error("添加角色组数据失败:%s", err)
  331 +// return nil, err
  332 +// }
  333 +// } else {
  334 +// log.Error("查询角色组数据失败:%s", err)
  335 +// return nil, err
  336 +// }
340 337
341 - return newRoleGroup, nil  
342 -} 338 +// return newRoleGroup, nil
  339 +// }
343 340
344 -func initRole(newCompany *models.Company, newRoleGroup *models.Role, o orm.Ormer) (*models.Role, error) {  
345 - var (  
346 - newRole = &models.Role{}  
347 - err error  
348 - )  
349 - err = o.QueryTable(&models.Role{}).  
350 - Filter("delete_at", 0).  
351 - Filter("is_default", models.ROLE_DEFAULR).  
352 - Filter("types", models.ROLETYPES_ROLE).  
353 - Filter("company_id", newCompany.Id).  
354 - One(newRole)  
355 - if err == nil {  
356 - return newRole, nil  
357 - } else if err == orm.ErrNoRows {  
358 - //添加部门  
359 - newRole = &models.Role{  
360 - Types: models.ROLETYPES_ROLE,  
361 - CompanyId: newCompany.Id,  
362 - IsDefault: models.ROLE_DEFAULR,  
363 - Name: "主管理员",  
364 - Pid: newRoleGroup.Id,  
365 - }  
366 - _, err = models.AddRole(newRole, o)  
367 - if err != nil {  
368 - log.Error("添加角色数据失败:%s", err)  
369 - return nil, err  
370 - }  
371 - } else {  
372 - log.Error("查询角色数据失败:%s", err)  
373 - return nil, err  
374 - } 341 +// func initRole(newCompany *models.Company, newRoleGroup *models.Role, o orm.Ormer) (*models.Role, error) {
  342 +// var (
  343 +// newRole = &models.Role{}
  344 +// err error
  345 +// )
  346 +// err = o.QueryTable(&models.Role{}).
  347 +// Filter("delete_at", 0).
  348 +// Filter("is_default", models.ROLE_DEFAULR).
  349 +// Filter("types", models.ROLETYPES_ROLE).
  350 +// Filter("company_id", newCompany.Id).
  351 +// One(newRole)
  352 +// if err == nil {
  353 +// return newRole, nil
  354 +// } else if err == orm.ErrNoRows {
  355 +// //添加部门
  356 +// newRole = &models.Role{
  357 +// Types: models.ROLETYPES_ROLE,
  358 +// CompanyId: newCompany.Id,
  359 +// IsDefault: models.ROLE_DEFAULR,
  360 +// Name: "主管理员",
  361 +// Pid: newRoleGroup.Id,
  362 +// }
  363 +// _, err = models.AddRole(newRole, o)
  364 +// if err != nil {
  365 +// log.Error("添加角色数据失败:%s", err)
  366 +// return nil, err
  367 +// }
  368 +// } else {
  369 +// log.Error("查询角色数据失败:%s", err)
  370 +// return nil, err
  371 +// }
375 372
376 - return newRole, nil  
377 -} 373 +// return newRole, nil
  374 +// }
378 375
379 -func initUserRole(newUserCompany *models.UserCompany, newRole *models.Role, o orm.Ormer) (*models.UserRole, error) {  
380 - var (  
381 - newUserRole = &models.UserRole{}  
382 - err error  
383 - )  
384 - err = o.QueryTable(&models.UserRole{}).  
385 - Filter("enable_status", models.USER_ROLE_ENABLE_YES).  
386 - Filter("user_company_id", newUserCompany.Id).  
387 - Filter("role_id", newRole.Id).  
388 - One(newUserRole)  
389 - if err == nil {  
390 - return newUserRole, nil  
391 - } else if err == orm.ErrNoRows {  
392 - //添加UserRole  
393 - newUserRole = &models.UserRole{  
394 - RoleId: newRole.Id,  
395 - UserCompanyId: newUserCompany.Id,  
396 - CompanyId: newUserCompany.CompanyId,  
397 - }  
398 - _, err = models.AddUserRole(newUserRole, o)  
399 - if err != nil {  
400 - log.Error("添加user_role数据失败:%s", err)  
401 - return nil, err  
402 - }  
403 - } else {  
404 - log.Error("查询user_role数据失败:%s", err)  
405 - return nil, err  
406 - } 376 +// func initUserRole(newUserCompany *models.UserCompany, newRole *models.Role, o orm.Ormer) (*models.UserRole, error) {
  377 +// var (
  378 +// newUserRole = &models.UserRole{}
  379 +// err error
  380 +// )
  381 +// err = o.QueryTable(&models.UserRole{}).
  382 +// Filter("enable_status", models.USER_ROLE_ENABLE_YES).
  383 +// Filter("user_company_id", newUserCompany.Id).
  384 +// Filter("role_id", newRole.Id).
  385 +// One(newUserRole)
  386 +// if err == nil {
  387 +// return newUserRole, nil
  388 +// } else if err == orm.ErrNoRows {
  389 +// //添加UserRole
  390 +// newUserRole = &models.UserRole{
  391 +// RoleId: newRole.Id,
  392 +// UserCompanyId: newUserCompany.Id,
  393 +// CompanyId: newUserCompany.CompanyId,
  394 +// }
  395 +// _, err = models.AddUserRole(newUserRole, o)
  396 +// if err != nil {
  397 +// log.Error("添加user_role数据失败:%s", err)
  398 +// return nil, err
  399 +// }
  400 +// } else {
  401 +// log.Error("查询user_role数据失败:%s", err)
  402 +// return nil, err
  403 +// }
407 404
408 - return newUserRole, nil  
409 -} 405 +// return newUserRole, nil
  406 +// }
410 407
411 -func iniSysConfig(companyid int, o orm.Ormer) error {  
412 - var (  
413 - m *models.SysConfig  
414 - err error  
415 - )  
416 - m, err = models.GetSysConfigByCompanyId(companyid, models.KeyScore)  
417 - if err == nil {  
418 - return nil  
419 - }  
420 - v := protocol.ScoreConfig{  
421 - DiscoveryScore: &protocol.DiscoveryScore{  
422 - BasicFactor: 1,  
423 - ExtraFactor: 1,  
424 - ValueFactor: 1,  
425 - },  
426 - SumScore: &protocol.SumScore{  
427 - DiscoveryFactor: 1,  
428 - CatchFactor: 1,  
429 - },  
430 - BasicScore: &protocol.ScoreRange{  
431 - Max: 10000,  
432 - Min: 0,  
433 - Step: 1,  
434 - },  
435 - ExtraScore: &protocol.ScoreRange{  
436 - Max: 10000,  
437 - Min: 0,  
438 - Step: 1,  
439 - },  
440 - ValueScore: &protocol.ScoreRange{  
441 - Max: 10000,  
442 - Min: 0,  
443 - Step: 1,  
444 - },  
445 - }  
446 - bt, _ := json.Marshal(v)  
447 - m = &models.SysConfig{  
448 - Key: models.KeyScore,  
449 - CompanyId: companyid,  
450 - CreateAt: time.Now(),  
451 - UpdateAt: time.Now(),  
452 - Content: string(bt),  
453 - }  
454 - _, err = models.AddSysConfig(m, o)  
455 - return err  
456 -} 408 +// func iniSysConfig(companyid int, o orm.Ormer) error {
  409 +// var (
  410 +// m *models.SysConfig
  411 +// err error
  412 +// )
  413 +// m, err = models.GetSysConfigByCompanyId(companyid, models.KeyScore)
  414 +// if err == nil {
  415 +// return nil
  416 +// }
  417 +// v := protocol.ScoreConfig{
  418 +// DiscoveryScore: &protocol.DiscoveryScore{
  419 +// BasicFactor: 1,
  420 +// ExtraFactor: 1,
  421 +// ValueFactor: 1,
  422 +// },
  423 +// SumScore: &protocol.SumScore{
  424 +// DiscoveryFactor: 1,
  425 +// CatchFactor: 1,
  426 +// },
  427 +// BasicScore: &protocol.ScoreRange{
  428 +// Max: 10000,
  429 +// Min: 0,
  430 +// Step: 1,
  431 +// },
  432 +// ExtraScore: &protocol.ScoreRange{
  433 +// Max: 10000,
  434 +// Min: 0,
  435 +// Step: 1,
  436 +// },
  437 +// ValueScore: &protocol.ScoreRange{
  438 +// Max: 10000,
  439 +// Min: 0,
  440 +// Step: 1,
  441 +// },
  442 +// }
  443 +// bt, _ := json.Marshal(v)
  444 +// m = &models.SysConfig{
  445 +// Key: models.KeyScore,
  446 +// CompanyId: companyid,
  447 +// CreateAt: time.Now(),
  448 +// UpdateAt: time.Now(),
  449 +// Content: string(bt),
  450 +// }
  451 +// _, err = models.AddSysConfig(m, o)
  452 +// return err
  453 +// }
457 454
458 func CompanyInfoEdit(companyid int64, logo string) error { 455 func CompanyInfoEdit(companyid int64, logo string) error {
459 data := models.Company{ 456 data := models.Company{
@@ -15,7 +15,7 @@ import ( @@ -15,7 +15,7 @@ import (
15 ) 15 )
16 16
17 //同步 人员数据 17 //同步 人员数据
18 - 18 +//UserDepartData 用户的部门数据
19 type UserDepartData struct { 19 type UserDepartData struct {
20 Id int64 `json:"id"` 20 Id int64 `json:"id"`
21 CompanyId int64 `json:"company_id"` 21 CompanyId int64 `json:"company_id"`
@@ -23,6 +23,7 @@ type UserDepartData struct { @@ -23,6 +23,7 @@ type UserDepartData struct {
23 UserId int64 `json:"user_id"` 23 UserId int64 `json:"user_id"`
24 } 24 }
25 25
  26 +// UserPositionData 用户的职位数据
26 type UserPositionData struct { 27 type UserPositionData struct {
27 Id int64 `json:"id"` 28 Id int64 `json:"id"`
28 CompanyId int64 `json:"company_id"` 29 CompanyId int64 `json:"company_id"`
@@ -31,6 +32,7 @@ type UserPositionData struct { @@ -31,6 +32,7 @@ type UserPositionData struct {
31 } 32 }
32 33
33 //-------------------- 34 //--------------------
  35 +//ModuleEmployee 同步用户数据
34 type ModuleEmployee struct { 36 type ModuleEmployee struct {
35 Id int64 `json:"id"` //用户的id,对应本地的user_company_id 37 Id int64 `json:"id"` //用户的id,对应本地的user_company_id
36 OpenId int64 `json:"open_id"` //同一用户中心的用户id 38 OpenId int64 `json:"open_id"` //同一用户中心的用户id
@@ -55,28 +57,38 @@ type ModuleEmployee struct { @@ -55,28 +57,38 @@ type ModuleEmployee struct {
55 UserPositions []UserPositionData `json:"user_positions"` 57 UserPositions []UserPositionData `json:"user_positions"`
56 } 58 }
57 59
  60 +//DeleteUserData 删除用户
58 type DeleteUserData struct { 61 type DeleteUserData struct {
59 CompanyId int64 `json:"companyId"` 62 CompanyId int64 `json:"companyId"`
60 Ids []int64 `json:"ids"` 63 Ids []int64 `json:"ids"`
61 } 64 }
62 65
  66 +//ForbidAllowUserData 启用禁用用户
63 type ForbidAllowUserData struct { 67 type ForbidAllowUserData struct {
64 CompanyId int64 `json:"companyId"` 68 CompanyId int64 `json:"companyId"`
65 Ids []int64 `json:"ids"` 69 Ids []int64 `json:"ids"`
66 Status int8 `json:"status"` 70 Status int8 `json:"status"`
67 } 71 }
68 72
  73 +//RemoveUserDepartmentData 移动通讯录用户部门
69 type RemoveUserDepartmentData struct { 74 type RemoveUserDepartmentData struct {
70 CompanyId int64 `json:"company_id"` 75 CompanyId int64 `json:"company_id"`
71 UserIds []int64 `json:"user_ids"` 76 UserIds []int64 `json:"user_ids"`
72 DepartmentIds []int64 `json:"department_ids"` 77 DepartmentIds []int64 `json:"department_ids"`
73 } 78 }
74 79
  80 +//ImportEmployeeData 批量导入用户数据
75 type ImportEmployeeData struct { 81 type ImportEmployeeData struct {
76 Add []ModuleEmployee `json:"add"` 82 Add []ModuleEmployee `json:"add"`
77 Edit []ModuleEmployee `json:"edit"` 83 Edit []ModuleEmployee `json:"edit"`
78 } 84 }
79 85
  86 +//EmployeeChangePhoneData 修改用户的账号
  87 +type EmployeeChangePhoneData struct {
  88 + OldPhone string `json:"oldPhone"`
  89 + NewPhone string `json:"newPhone"`
  90 +}
  91 +
80 var _ PlatformAction = ModuleEmployee{} 92 var _ PlatformAction = ModuleEmployee{}
81 93
82 //DoAction PlatformAction 的接口实现 94 //DoAction PlatformAction 的接口实现
@@ -150,6 +162,18 @@ func (m ModuleEmployee) DoAction(code string, jsondata []byte) error { @@ -150,6 +162,18 @@ func (m ModuleEmployee) DoAction(code string, jsondata []byte) error {
150 UpdateEmployeeData(data.Edit[i]) 162 UpdateEmployeeData(data.Edit[i])
151 } 163 }
152 return nil 164 return nil
  165 + case "changePhone":
  166 + //修改用户的手机账号
  167 + var (
  168 + data EmployeeChangePhoneData
  169 + err error
  170 + )
  171 + err = json.Unmarshal(jsondata, &data)
  172 + if err != nil {
  173 + return fmt.Errorf("数据解析失败:%s", err)
  174 + }
  175 + _ = EmployeeChangePhone(data)
  176 + return nil
153 default: 177 default:
154 return errors.New("action not found") 178 return errors.New("action not found")
155 } 179 }
@@ -630,3 +654,67 @@ func RemoveUserDepartment(data RemoveUserDepartmentData) error { @@ -630,3 +654,67 @@ func RemoveUserDepartment(data RemoveUserDepartmentData) error {
630 o.Commit() 654 o.Commit()
631 return nil 655 return nil
632 } 656 }
  657 +
  658 +//EmployeeChangePhone 变更用户的手机账号
  659 +func EmployeeChangePhone(data EmployeeChangePhoneData) error {
  660 + var (
  661 + err error
  662 + oldUser *models.User
  663 + newUser *models.User
  664 + userCompanydatas []models.UserCompany
  665 + )
  666 + //user 表查询新旧号码用户
  667 + oldUser, err = models.GetUserByPhone(data.OldPhone)
  668 + if err != nil {
  669 + log.Error("获取user数据失败:phone = %s", data.OldPhone)
  670 + return errors.New("获取user数据失败")
  671 + }
  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)
  678 + if err != nil {
  679 + log.Error("获取user_company数据失败,user_id=%d", oldUser.Id)
  680 + return errors.New("获取user_company数据失败")
  681 + }
  682 + //user_company表 以旧用户的user_id作条件变更为新用户的对应的user_id,phone,open_id
  683 + o := orm.NewOrm()
  684 + o.Begin()
  685 + for i := range userCompanydatas {
  686 + temp := userCompanydatas[i]
  687 + temp.UserId = newUser.Id
  688 + temp.Phone = newUser.Phone
  689 + temp.OpenId = newUser.UserCenterId
  690 + temp.UpdateAt = time.Now()
  691 + err = models.UpdateUserCompanyById(&temp, []string{"UserId", "Phone", "OpenId", "UpdateAt"}, o)
  692 + if err != nil {
  693 + log.Error("更新user_company数据失败,id=%d", temp.Id)
  694 + o.Rollback()
  695 + return errors.New("变更用户手机号操作失败")
  696 + }
  697 + }
  698 + //user.user_center_id 同 user_company表.open_id
  699 + //UserAuth注销手机登录
  700 + var oldUserAuthData *models.UserAuth
  701 + oldUserAuthData, err = models.GetUserAuthByUser(oldUser.Id)
  702 + if err != nil {
  703 + log.Warn("为找到userAuth数据,user_id=%d", oldUser.Id)
  704 + } else {
  705 + oldUserAuthData.AccessToken = ""
  706 + oldUserAuthData.RefreshToken = ""
  707 + oldUserAuthData.AuthCode = ""
  708 + oldUserAuthData.UpdateAt = time.Now()
  709 + //更新userAuth数据
  710 + err = models.UpdateUserAuthById(oldUserAuthData,
  711 + []string{"AccessToken", "RefreshToken", "AuthCode", "UpdateAt"},
  712 + o,
  713 + )
  714 + if err != nil {
  715 + log.Warn("更新user_auth数据失败,id=%d", oldUserAuthData.Id)
  716 + }
  717 + }
  718 + o.Commit()
  719 + return nil
  720 +}