regist_service.go 758B

1234567891011121314151617181920212223242526272829303132333435
  1. package service
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/utils"
  6. "time"
  7. )
  8. func RegisterSuperAdmin(mobile string, password string) (*models.AdminUser, *enums.SGJError) {
  9. tx := writeUserDb.Begin()
  10. now := time.Now().Unix()
  11. admin := models.AdminUser{
  12. Mobile: mobile,
  13. Password: password,
  14. IsSuperAdmin: true,
  15. Status: 1,
  16. CreateTime: now,
  17. ModifyTime: now,
  18. }
  19. registerSuccess := false
  20. if createAdminErr := tx.Create(&admin).Error; createAdminErr != nil {
  21. utils.ErrorLog("创建 AdminUser 失败:%v", createAdminErr)
  22. tx.Rollback()
  23. } else {
  24. registerSuccess = true
  25. }
  26. tx.Commit()
  27. if registerSuccess == true {
  28. return &admin, nil
  29. } else {
  30. return nil, &enums.SGJError{Code: enums.ErrorCodeRegisterFail}
  31. }
  32. }