作者 tangxvhui

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

... ... @@ -295,19 +295,11 @@ func (c RankController) RankRangeAdd() {
}
switch param.RangeType {
case 1:
//员工
// if len(param.RelationId) == 0 {
// param.RangeType = models.RANK_RANGE_TYPE_EMPLAYEEALL
// } else {
param.RangeType = models.RANK_RANGE_TYPE_EMPLAYEE
// }
case 2:
//部门
// if len(param.RelationId) == 0 {
// param.RangeType = models.RANK_RANGE_TYPE_DEPARTMENTALL
// } else {
param.RangeType = models.RANK_RANGE_TYPE_DEPARTMENT
// }
default:
log.Error("param.RangeType err")
msg = protocol.BadRequestParam("1")
... ... @@ -348,19 +340,10 @@ func (c RankController) RankRangeEdit() {
switch param.RangeType {
case 1:
//员工
if len(param.RelationId) == 0 {
param.RangeType = models.RANK_RANGE_TYPE_EMPLAYEEALL
} else {
param.RangeType = models.RANK_RANGE_TYPE_EMPLAYEE
}
param.RangeType = models.RANK_RANGE_TYPE_EMPLAYEE
case 2:
//部门
if len(param.RelationId) == 0 {
param.RangeType = models.RANK_RANGE_TYPE_DEPARTMENTALL
} else {
param.RangeType = models.RANK_RANGE_TYPE_DEPARTMENT
}
param.RangeType = models.RANK_RANGE_TYPE_DEPARTMENT
default:
log.Error("param.RangeType err")
msg = protocol.BadRequestParam("1")
... ...
... ... @@ -184,6 +184,7 @@ func AddCompanyData(data ModuleCompanytData) error {
o := orm.NewOrm()
o.Begin()
//处理用户数据
log.Info("添加user表数据")
newUser, err = AddAdminUser(&data, o)
if err != nil {
o.Rollback()
... ... @@ -259,11 +260,18 @@ func AddCompanyData(data ModuleCompanytData) error {
func AddAdminUser(centerCompany *ModuleCompanytData, o orm.Ormer) (*models.User, error) {
var (
err error
err error
newUser = &models.User{}
)
companyAdminData := centerCompany.User
err = o.QueryTable(&models.User{}).
Filter("phone", companyAdminData.Phone).
One(newUser)
if err == nil {
return newUser, nil
}
//添加用户
newUser := &models.User{
newUser = &models.User{
Id: companyAdminData.Id,
Phone: companyAdminData.Phone,
NickName: companyAdminData.Name,
... ... @@ -274,6 +282,7 @@ func AddAdminUser(centerCompany *ModuleCompanytData, o orm.Ormer) (*models.User,
log.Error("添加用户数据失败:%s", err)
return nil, err
}
return newUser, nil
}
... ... @@ -294,15 +303,24 @@ func AddCompanyBase(centerCompany *ModuleCompanytData, admininfo *models.User, o
log.Error("添加公司数据失败:%s", err)
return nil, err
}
return nil, nil
return newCompany, nil
}
func AddUserCompanyData(centerCompany *ModuleCompanytData, newcompany *models.Company, newuser *models.User, o orm.Ormer) (*models.UserCompany, error) {
var (
err error
uc = &models.UserCompany{}
)
adminUserData := centerCompany.User
uc := &models.UserCompany{
err = o.QueryTable(&models.UserCompany{}).
Filter("company_id", newcompany.Id).
Filter("user_id", newuser.Id).
Filter("delete_at", 0).
One(uc)
if err == nil {
return uc, nil
}
uc = &models.UserCompany{
UserId: newuser.Id,
CompanyId: newcompany.Id,
Enable: models.USERCOMPANY_ENABLE_YES,
... ...