作者 yangfu

用户信息修改

@@ -102,7 +102,8 @@ func GetUserCompanyBy(id int64, companyId int64) (v *UserCompany, err error) { @@ -102,7 +102,8 @@ func GetUserCompanyBy(id int64, companyId int64) (v *UserCompany, err error) {
102 //获取用户第一个有效公司 102 //获取用户第一个有效公司
103 func GetUserCompanysFirst(uid int64) (v *UserCompany, err error) { 103 func GetUserCompanysFirst(uid int64) (v *UserCompany, err error) {
104 o := orm.NewOrm() 104 o := orm.NewOrm()
105 - sql := "select * from user_company where user_id=? and enable=1 order by create_at desc limit 1" // 105 + sql := `select a.* from user_company a inner join company b on a.company_id=b.id where a.user_id=? and a.enable=1 and b.enable=1
  106 + order by a.create_at desc limit 1` //
106 if err = o.Raw(sql, uid).QueryRow(&v); err == nil { 107 if err = o.Raw(sql, uid).QueryRow(&v); err == nil {
107 return v, nil 108 return v, nil
108 } 109 }
@@ -122,7 +123,7 @@ func GetUserCompanyIdAll(companyId int) (v []int64, err error) { @@ -122,7 +123,7 @@ func GetUserCompanyIdAll(companyId int) (v []int64, err error) {
122 //@uid 表user.id 123 //@uid 表user.id
123 func GetUserAllCompany(uid int64) (v []*UserCompany, err error) { 124 func GetUserAllCompany(uid int64) (v []*UserCompany, err error) {
124 o := orm.NewOrm() 125 o := orm.NewOrm()
125 - sql := "select * from user_company where user_id=? and enable=1" //and enable=1 126 + sql := "select * from user_company a inner join company b on a.company_id=b.id where a.user_id=? and a.enable=1 and b.enable=1" //and enable=1
126 if _, err = o.Raw(sql, uid).QueryRows(&v); err == nil { 127 if _, err = o.Raw(sql, uid).QueryRows(&v); err == nil {
127 return v, nil 128 return v, nil
128 } 129 }