作者 tangxvhui

同步数据 编辑公司

... ... @@ -17,6 +17,7 @@ type Company struct {
Logo string `orm:"column(logo);size(255)"`
Enable int8 `orm:"column(enable)"`
UserCenterId int64 `orm:"column(user_center_id)"`
Remark string `orm:"column(remark)"`
}
func (t *Company) TableName() string {
... ...
... ... @@ -151,9 +151,9 @@ func init() {
)
nsUcenter := beego.NewNamespace("/ucenter",
beego.NSBefore(middleware.LogRequestData),
beego.NSRouter("/company", &controllers.CompanyController{}, "post:InitCompany"),
//beego.NSRouter("/company", &controllers.CompanyController{}, "post:InitCompany"),(废弃)
beego.NSRouter("/company/info", &controllers.CompanyController{}, "post:GetCompanyForUCenter"),
beego.NSRouter("/company/edit", &controllers.CompanyController{}, "post:EditCompanyForUCenter"),
//beego.NSRouter("/company/edit", &controllers.CompanyController{}, "post:EditCompanyForUCenter"),(废弃)
beego.NSRouter("/user/revoke", &controllers.CompanyController{}, "post:UserRevoke"),
beego.NSRouter("/user/changePhone", &controllers.CompanyController{}, "post:UserChangePhone"),
beego.NSRouter("/company/allow_forbid", &controllers.CompanyController{}, "post:AllowForidCompanyForUCenter"),
... ...
... ... @@ -18,6 +18,7 @@ type CompanyBase struct {
Name string `json:"name"` //公司名称名称
AdminCompanyId int64 `json:"admin_company_id"`
Logo string `json:"logo"`
Remarks string `json:"remarks"`
}
// ModuleCompanytData 主管理平台发送过来的数据
... ... @@ -46,15 +47,15 @@ func (m ModuleCompanytData) DoAction(code string, jsondata []byte) error {
}
return AddCompanyData(data)
case "edit":
// var (
// data ModuleCompanytData
// err error
// )
// err = json.Unmarshal(jsondata, &data)
// if err != nil {
// return fmt.Errorf("数据解析失败:%s", err)
// }
// return UpdateCompanyData(data)
var (
data ModuleCompanytData
err error
)
err = json.Unmarshal(jsondata, &data)
if err != nil {
return fmt.Errorf("数据解析失败:%s", err)
}
return UpdateCompanyData(data)
return nil
case "setCompanyCharge":
var (
... ... @@ -112,22 +113,24 @@ func SetCompanyCharge(data CompanyCharge) error {
}
func UpdateCompanyData(data ModuleCompanytData) error {
// var (
// companyData *models.Company
// err error
// )
// companyData, err = models.GetCompanyByUCenter(data.Id)
// if err != nil {
// log.Error("获取企业数据失败,user_center_id:%d ,err:%s", data.Id, err)
// return errors.New("获取企业数据失败")
// }
// companyData.Logo = data.Logo
// companyData.Name = data.Name
// err = models.UpdateCompanyById(companyData, []string{"Logo", "Name"})
// if err != nil {
// log.Error("更新公司数据失败:%s", err)
// return errors.New("更新公司数据失败")
// }
var (
companyData *models.Company
err error
)
companyBaseData := data.Company
companyData, err = models.GetCompanyByUCenter(companyBaseData.AdminCompanyId)
if err != nil {
log.Error("获取企业数据失败,user_center_id:%d ,err:%s", data.Id, err)
return errors.New("获取企业数据失败")
}
companyData.Logo = companyBaseData.Logo
companyData.Name = companyBaseData.Name
companyData.Remark = companyBaseData.Remarks
err = models.UpdateCompanyById(companyData, []string{"Logo", "Name"})
if err != nil {
log.Error("更新公司数据失败:%s", err)
return errors.New("更新公司数据失败")
}
return nil
}
... ...