|
- package svc
-
- import (
- "applet/app/admin/md"
- "applet/app/db"
- "applet/app/db/model"
- )
-
- func BindAdminWithEnterprise(req md.BindAdminWithEnterpriseReq) (err error) {
- session := db.Db.NewSession()
- defer session.Close()
- session.Begin()
-
- //1、删除 `admin_with_enterprise`
- adminWithEnterpriseDb := db.AdminWithEnterpriseDb{}
- adminWithEnterpriseDb.Set()
- _, err = adminWithEnterpriseDb.AdminWithEnterpriseDeleteBySession(session, req.AdmId)
- if err != nil {
- _ = session.Rollback()
- return
- }
-
- //2、新增 `admin_with_enterprise``
- var mm []*model.AdminWithEnterprise
- for _, v := range req.Ids {
- mm = append(mm, &model.AdminWithEnterprise{
- AdmId: req.AdmId,
- EnterpriseId: v,
- })
- }
- _, err = adminWithEnterpriseDb.BatchAddAdminWithEnterpriseBySession(session, mm)
- if err != nil {
- _ = session.Rollback()
- return
- }
-
- return session.Commit()
- }
|