作者 tangxvhui

同步数据 修复添加公司的错误

@@ -295,19 +295,11 @@ func (c RankController) RankRangeAdd() { @@ -295,19 +295,11 @@ func (c RankController) RankRangeAdd() {
295 } 295 }
296 switch param.RangeType { 296 switch param.RangeType {
297 case 1: 297 case 1:
298 - //员工  
299 - // if len(param.RelationId) == 0 {  
300 - // param.RangeType = models.RANK_RANGE_TYPE_EMPLAYEEALL  
301 - // } else {  
302 param.RangeType = models.RANK_RANGE_TYPE_EMPLAYEE 298 param.RangeType = models.RANK_RANGE_TYPE_EMPLAYEE
303 - // }  
304 case 2: 299 case 2:
305 - //部门  
306 - // if len(param.RelationId) == 0 {  
307 - // param.RangeType = models.RANK_RANGE_TYPE_DEPARTMENTALL  
308 - // } else { 300 +
309 param.RangeType = models.RANK_RANGE_TYPE_DEPARTMENT 301 param.RangeType = models.RANK_RANGE_TYPE_DEPARTMENT
310 - // } 302 +
311 default: 303 default:
312 log.Error("param.RangeType err") 304 log.Error("param.RangeType err")
313 msg = protocol.BadRequestParam("1") 305 msg = protocol.BadRequestParam("1")
@@ -348,19 +340,10 @@ func (c RankController) RankRangeEdit() { @@ -348,19 +340,10 @@ func (c RankController) RankRangeEdit() {
348 340
349 switch param.RangeType { 341 switch param.RangeType {
350 case 1: 342 case 1:
351 - //员工  
352 - if len(param.RelationId) == 0 {  
353 - param.RangeType = models.RANK_RANGE_TYPE_EMPLAYEEALL  
354 - } else {  
355 - param.RangeType = models.RANK_RANGE_TYPE_EMPLAYEE  
356 - } 343 + param.RangeType = models.RANK_RANGE_TYPE_EMPLAYEE
357 case 2: 344 case 2:
358 - //部门  
359 - if len(param.RelationId) == 0 {  
360 - param.RangeType = models.RANK_RANGE_TYPE_DEPARTMENTALL  
361 - } else {  
362 - param.RangeType = models.RANK_RANGE_TYPE_DEPARTMENT  
363 - } 345 + param.RangeType = models.RANK_RANGE_TYPE_DEPARTMENT
  346 +
364 default: 347 default:
365 log.Error("param.RangeType err") 348 log.Error("param.RangeType err")
366 msg = protocol.BadRequestParam("1") 349 msg = protocol.BadRequestParam("1")
@@ -184,6 +184,7 @@ func AddCompanyData(data ModuleCompanytData) error { @@ -184,6 +184,7 @@ func AddCompanyData(data ModuleCompanytData) error {
184 o := orm.NewOrm() 184 o := orm.NewOrm()
185 o.Begin() 185 o.Begin()
186 //处理用户数据 186 //处理用户数据
  187 + log.Info("添加user表数据")
187 newUser, err = AddAdminUser(&data, o) 188 newUser, err = AddAdminUser(&data, o)
188 if err != nil { 189 if err != nil {
189 o.Rollback() 190 o.Rollback()
@@ -259,11 +260,18 @@ func AddCompanyData(data ModuleCompanytData) error { @@ -259,11 +260,18 @@ func AddCompanyData(data ModuleCompanytData) error {
259 260
260 func AddAdminUser(centerCompany *ModuleCompanytData, o orm.Ormer) (*models.User, error) { 261 func AddAdminUser(centerCompany *ModuleCompanytData, o orm.Ormer) (*models.User, error) {
261 var ( 262 var (
262 - err error 263 + err error
  264 + newUser = &models.User{}
263 ) 265 )
264 companyAdminData := centerCompany.User 266 companyAdminData := centerCompany.User
  267 + err = o.QueryTable(&models.User{}).
  268 + Filter("phone", companyAdminData.Phone).
  269 + One(newUser)
  270 + if err == nil {
  271 + return newUser, nil
  272 + }
265 //添加用户 273 //添加用户
266 - newUser := &models.User{ 274 + newUser = &models.User{
267 Id: companyAdminData.Id, 275 Id: companyAdminData.Id,
268 Phone: companyAdminData.Phone, 276 Phone: companyAdminData.Phone,
269 NickName: companyAdminData.Name, 277 NickName: companyAdminData.Name,
@@ -274,6 +282,7 @@ func AddAdminUser(centerCompany *ModuleCompanytData, o orm.Ormer) (*models.User, @@ -274,6 +282,7 @@ func AddAdminUser(centerCompany *ModuleCompanytData, o orm.Ormer) (*models.User,
274 log.Error("添加用户数据失败:%s", err) 282 log.Error("添加用户数据失败:%s", err)
275 return nil, err 283 return nil, err
276 } 284 }
  285 +
277 return newUser, nil 286 return newUser, nil
278 } 287 }
279 288
@@ -294,15 +303,24 @@ func AddCompanyBase(centerCompany *ModuleCompanytData, admininfo *models.User, o @@ -294,15 +303,24 @@ func AddCompanyBase(centerCompany *ModuleCompanytData, admininfo *models.User, o
294 log.Error("添加公司数据失败:%s", err) 303 log.Error("添加公司数据失败:%s", err)
295 return nil, err 304 return nil, err
296 } 305 }
297 - return nil, nil 306 + return newCompany, nil
298 } 307 }
299 308
300 func AddUserCompanyData(centerCompany *ModuleCompanytData, newcompany *models.Company, newuser *models.User, o orm.Ormer) (*models.UserCompany, error) { 309 func AddUserCompanyData(centerCompany *ModuleCompanytData, newcompany *models.Company, newuser *models.User, o orm.Ormer) (*models.UserCompany, error) {
301 var ( 310 var (
302 err error 311 err error
  312 + uc = &models.UserCompany{}
303 ) 313 )
304 adminUserData := centerCompany.User 314 adminUserData := centerCompany.User
305 - uc := &models.UserCompany{ 315 + err = o.QueryTable(&models.UserCompany{}).
  316 + Filter("company_id", newcompany.Id).
  317 + Filter("user_id", newuser.Id).
  318 + Filter("delete_at", 0).
  319 + One(uc)
  320 + if err == nil {
  321 + return uc, nil
  322 + }
  323 + uc = &models.UserCompany{
306 UserId: newuser.Id, 324 UserId: newuser.Id,
307 CompanyId: newcompany.Id, 325 CompanyId: newcompany.Id,
308 Enable: models.USERCOMPANY_ENABLE_YES, 326 Enable: models.USERCOMPANY_ENABLE_YES,