From 4dd35067da2ed962fbc43a1306ca38fc173bf3eb Mon Sep 17 00:00:00 2001 From: DengBiao <2319963317@qq.com> Date: Mon, 11 Sep 2023 14:32:12 +0800 Subject: [PATCH] update --- app/admin/hdl/hdl_role.go | 14 +++++ app/customer/svc/svc_curl_smart_pay.go | 2 +- app/db/db_admin.go | 12 ++++- app/db/db_admin_role_permission_group.go | 10 ++++ app/db/db_admin_with_enterprise.go | 68 ++++++++++++++++++++++++ app/db/model/admin_with_enterprise.go | 7 +++ 6 files changed, 110 insertions(+), 3 deletions(-) create mode 100644 app/db/db_admin_with_enterprise.go create mode 100644 app/db/model/admin_with_enterprise.go diff --git a/app/admin/hdl/hdl_role.go b/app/admin/hdl/hdl_role.go index eb27b8b..f740e35 100644 --- a/app/admin/hdl/hdl_role.go +++ b/app/admin/hdl/hdl_role.go @@ -305,6 +305,20 @@ func AdminList(c *gin.Context) { for _, v1 := range permissionGroupList { roleList = append(roleList, v1.Role.Name) } + + adminEnterpriseList, _, err1 := adminDb.FindAdminWithEnterprise(v.AdmId) + if err != nil { + e.OutErr(c, e.ERR_DB_ORM, err1.Error()) + return + } + var enterpriseList []map[string]interface{} + for _, v1 := range adminEnterpriseList { + enterpriseList = append(enterpriseList, map[string]interface{}{ + "name": v1.Enterprise.Name, + "id": v1.Enterprise.Id, + }) + } + result = append(result, md.AdminListResp{ AdmId: v.AdmId, Username: v.Username, diff --git a/app/customer/svc/svc_curl_smart_pay.go b/app/customer/svc/svc_curl_smart_pay.go index b06c991..0eb0585 100644 --- a/app/customer/svc/svc_curl_smart_pay.go +++ b/app/customer/svc/svc_curl_smart_pay.go @@ -293,7 +293,7 @@ func CurlEducateSceneTokenQuery(args md.CurlEducateSceneTokenReq, userIdentity * info.SchoolFacePaymentStatus = res["school_face_payment_status"] info.ConcentrateSchoolFacePassStatus = concentrateSchoolFacePassStatus info.UpdateAt = now - _, err2 := selfSupportForUserFaceInfoDb.SelfSupportForUserFaceInfoUpdate(info, "parent_user_id", "parent_logon_id", "user_id", "school_face_pass_status", "school_face_payment_status", "update_at") + _, err2 := selfSupportForUserFaceInfoDb.SelfSupportForUserFaceInfoUpdate(info, "parent_user_id", "parent_logon_id", "user_id", "school_face_pass_status", "school_face_payment_status", "concentrate_school_face_pass_status", "update_at") if err2 != nil { return err2, nil } diff --git a/app/db/db_admin.go b/app/db/db_admin.go index 3a8284c..c921f5f 100644 --- a/app/db/db_admin.go +++ b/app/db/db_admin.go @@ -76,8 +76,16 @@ func (adminDb *AdminDb) FindAdminRolePermissionGroup(admId int) (list []*AdminRo total, err = adminDb.Db.Where("admin.adm_id =?", admId). Join("LEFT", "admin_role", "admin.adm_id = admin_role.adm_id"). Join("LEFT", "role", "admin_role.role_id = role.id"). - Join("LEFT", "role_permission_group", "role.id = role_permission_group.role_id"). - Join("LEFT", "permission_group", "role_permission_group.group_id = permission_group.id"). + //Join("LEFT", "role_permission_group", "role.id = role_permission_group.role_id"). + //Join("LEFT", "permission_group", "role_permission_group.group_id = permission_group.id"). + FindAndCount(&list) + return +} + +func (adminDb *AdminDb) FindAdminWithEnterprise(admId int) (list []*AdminEnterprise, total int64, err error) { + total, err = adminDb.Db.Where("admin.adm_id =?", admId). + Join("LEFT", "admin_with_enterprise", "admin.adm_id = admin_with_enterprise.adm_id"). + Join("LEFT", "enterprise", "admin_with_enterprise.enterprise_id = enterprise.id"). FindAndCount(&list) return } diff --git a/app/db/db_admin_role_permission_group.go b/app/db/db_admin_role_permission_group.go index 96fcccc..c07b6f2 100644 --- a/app/db/db_admin_role_permission_group.go +++ b/app/db/db_admin_role_permission_group.go @@ -15,3 +15,13 @@ type AdminRolePermissionGroup struct { func (AdminRolePermissionGroup) TableName() string { return "admin" } + +type AdminEnterprise struct { + model2.Admin `xorm:"extends"` + model2.AdminWithEnterprise `xorm:"extends"` + model2.Enterprise `xorm:"extends"` +} + +func (AdminEnterprise) TableName() string { + return "admin" +} diff --git a/app/db/db_admin_with_enterprise.go b/app/db/db_admin_with_enterprise.go new file mode 100644 index 0000000..734b86e --- /dev/null +++ b/app/db/db_admin_with_enterprise.go @@ -0,0 +1,68 @@ +package db + +import ( + "applet/app/db/model" + "applet/app/utils/logx" + "reflect" + "xorm.io/xorm" +) + +type AdminWithEnterpriseDb struct { + Db *xorm.Engine `json:"db"` +} + +func (adminWithEnterpriseDb *AdminWithEnterpriseDb) Set() { // set方法 + adminWithEnterpriseDb.Db = Db +} + +func (adminWithEnterpriseDb *AdminWithEnterpriseDb) FindAdminRole(id int) (*[]model.AdminRole, error) { + var m []model.AdminRole + if err := adminWithEnterpriseDb.Db.Where("adm_id =?", id).Find(&m); err != nil { + return nil, logx.Error(err) + } + return &m, nil +} + +func (adminWithEnterpriseDb *AdminWithEnterpriseDb) AdminDeleteBySessionForAdmId(session *xorm.Session, admId interface{}) (int64, error) { + if reflect.TypeOf(admId).Kind() == reflect.Slice { + return session.In("adm_id", admId).Delete(model.AdminRole{}) + } else { + return session.Where("adm_id = ?", admId).Delete(model.AdminRole{}) + } +} + +func (adminWithEnterpriseDb *AdminWithEnterpriseDb) GetAdminRoleByRole(id int) (m *model.AdminRole, err error) { + m = new(model.AdminRole) + has, err := adminWithEnterpriseDb.Db.Where("role_id =?", id).Get(m) + if err != nil { + return nil, logx.Error(err) + } + if has == false { + return nil, nil + } + return m, nil +} + +func (adminWithEnterpriseDb *AdminWithEnterpriseDb) AdminRoleDeleteForRoleBySession(session *xorm.Session, roleId interface{}) (int64, error) { + if reflect.TypeOf(roleId).Kind() == reflect.Slice { + return session.In("role_id", roleId).Delete(model.AdminRole{}) + } else { + return session.Where("role_id = ?", roleId).Delete(model.AdminRole{}) + } +} + +func (adminWithEnterpriseDb *AdminWithEnterpriseDb) AdminRoleDeleteBySession(session *xorm.Session, id interface{}) (int64, error) { + if reflect.TypeOf(id).Kind() == reflect.Slice { + return session.In("id", id).Delete(model.AdminRole{}) + } else { + return session.Where("adm_id = ?", id).Delete(model.AdminRole{}) + } +} + +func (adminWithEnterpriseDb *AdminWithEnterpriseDb) BatchAddAdminRoleBySession(session *xorm.Session, mm []*model.AdminRole) (int64, error) { + affected, err := session.Insert(mm) + if err != nil { + return 0, err + } + return affected, nil +} diff --git a/app/db/model/admin_with_enterprise.go b/app/db/model/admin_with_enterprise.go new file mode 100644 index 0000000..4b7738c --- /dev/null +++ b/app/db/model/admin_with_enterprise.go @@ -0,0 +1,7 @@ +package model + +type AdminWithEnterprise struct { + Id int `json:"id" xorm:"not null pk autoincr INT(11)"` + AdmId int `json:"adm_id" xorm:"not null default 0 comment('管理员id') INT(11)"` + EnterpriseId int `json:"enterprise_id" xorm:"not null default 0 comment('校企id') INT(11)"` +}