1234567891011121314151617181920212223242526272829303132333435 |
- package service
-
- import (
- "Xcx_New/enums"
- "Xcx_New/models"
- "Xcx_New/utils"
- "time"
- )
-
- func RegisterSuperAdmin(mobile string, password string) (*models.AdminUser, *enums.SGJError) {
- tx := writeUserDb.Begin()
- now := time.Now().Unix()
- admin := models.AdminUser{
- Mobile: mobile,
- Password: password,
- IsSuperAdmin: true,
- Status: 1,
- CreateTime: now,
- ModifyTime: now,
- }
- registerSuccess := false
- if createAdminErr := tx.Create(&admin).Error; createAdminErr != nil {
- utils.ErrorLog("创建 AdminUser 失败:%v", createAdminErr)
- tx.Rollback()
- } else {
- registerSuccess = true
- }
- tx.Commit()
- if registerSuccess == true {
- return &admin, nil
- } else {
- return nil, &enums.SGJError{Code: enums.ErrorCodeRegisterFail}
- }
- }
|