智慧食堂
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
871 B

  1. package svc
  2. import (
  3. "applet/app/admin/md"
  4. "applet/app/db"
  5. "applet/app/db/model"
  6. )
  7. func BindAdminWithEnterprise(req md.BindAdminWithEnterpriseReq) (err error) {
  8. session := db.Db.NewSession()
  9. defer session.Close()
  10. session.Begin()
  11. //1、删除 `admin_with_enterprise`
  12. adminWithEnterpriseDb := db.AdminWithEnterpriseDb{}
  13. adminWithEnterpriseDb.Set()
  14. _, err = adminWithEnterpriseDb.AdminWithEnterpriseDeleteBySession(session, req.AdmId)
  15. if err != nil {
  16. _ = session.Rollback()
  17. return
  18. }
  19. //2、新增 `admin_with_enterprise``
  20. var mm []*model.AdminWithEnterprise
  21. for _, v := range req.Ids {
  22. mm = append(mm, &model.AdminWithEnterprise{
  23. AdmId: req.AdmId,
  24. EnterpriseId: v,
  25. })
  26. }
  27. _, err = adminWithEnterpriseDb.BatchAddAdminWithEnterpriseBySession(session, mm)
  28. if err != nil {
  29. _ = session.Rollback()
  30. return
  31. }
  32. return session.Commit()
  33. }