package service import ( "context" "fmt" log "github.com/sirupsen/logrus" "time" "youngee_b_api/db" "youngee_b_api/model/gorm_model" "youngee_b_api/model/http_model" ) var SubAccount *subaccount type subaccount struct { } // CreateSubAccount 新增子账号 func (*subaccount) CreateSubAccount(ctx context.Context, request *http_model.AddNewSubAccountRequest) (*gorm_model.YounggeeSubAccount, error) { user := gorm_model.YounggeeUser{ Phone: request.PhoneNumber, User: "1002", Username: request.PhoneNumber, Password: "1002", RealName: "", Role: "7", Email: "", LastLoginTime: time.Now().UTC().Local(), } userId, err := db.CreateUser(ctx, user) if err != nil { log.Infof("[CreateEnterpriseSubUser] fail,err:%+v", err) return nil, err } fmt.Println("userId: ", userId) var curr = int(*userId) var newSubAccount = gorm_model.YounggeeSubAccount{ PhoneNumber: request.PhoneNumber, SubAccountName: request.SubAccountName, JobId: request.JobId, SupplierId: request.SupplierId, AccountStatus: 1, UserId: curr, SubAccountType: 3, } err1 := db.CreateSubAccount(ctx, newSubAccount) if err1 != nil { return nil, err1 } return &newSubAccount, nil } // UpdateSubAccount 修改子账号 func (*subaccount) UpdateSubAccount(ctx context.Context, request http_model.UpdateSubAccountRequest) (*http_model.UpdateSubAccountInfo, error) { //var newSubAccount *gorm_model.YounggeeSubAccount //newSubAccount = &gorm_model.YounggeeSubAccount{} //// 1. 若修改绑定手机号 //if request.Phone != "" { //} return nil, nil } // DeleteSubAccount 删除子账号 func (*subaccount) DeleteSubAccount(ctx context.Context, request http_model.DeleteSubAccountRequest) error { var newSubAccount = gorm_model.YounggeeSubAccount{ SubAccountId: request.SubAccountId, } err := db.DeleteSubAccount(ctx, newSubAccount) if err != nil { return err } return nil } // FindSubAccountBySupplierId 根据服务商ID查找包含的所有子账号信息 func (*subaccount) FindSubAccountBySupplierId(ctx context.Context, request http_model.FindAllSubAccountRequest) (*http_model.FindAllSubAccountData, error) { var subAccountResp *http_model.FindAllSubAccountData subAccountResp = &http_model.FindAllSubAccountData{} // 1. 取出子账号基本信息 newSubAccount, total, subAccountErr := db.FindSubAccountBySupplierId(ctx, request.PageNum, request.PageSize, request.SupplierId, request.JobId, request.AccountStatus, request.Condition) if subAccountErr != nil { return nil, subAccountErr } if newSubAccount != nil { for _, s := range newSubAccount { var subAccountInfo *http_model.FindAllSubAccountInfo subAccountInfo = &http_model.FindAllSubAccountInfo{} // fmt.Println("s:", s.SubAccountId) subAccountInfo.SubAccountId = s.SubAccountId subAccountInfo.SubAccountName = s.SubAccountName subAccountInfo.JobId = s.JobId subAccountInfo.UserId = s.UserId subAccountInfo.PhoneNumber = s.PhoneNumber subAccountInfo.SupplierId = s.SupplierId subAccountInfo.AccountStatus = s.AccountStatus // 2. 岗位信息 jobInfo, jobErr := db.FindJobByJobId(ctx, s.JobId) if jobErr != nil { return nil, jobErr } if jobInfo != nil { subAccountInfo.JobName = jobInfo.JobName } // 3. 服务商信息 supplierInfo, supplierErr := db.GetSupplierById(ctx, s.SupplierId) if supplierErr != nil { return nil, supplierErr } if supplierInfo != nil { subAccountInfo.SupplierName = supplierInfo.SupplierName } subAccountResp.SubAccountInfo = append(subAccountResp.SubAccountInfo, subAccountInfo) } } subAccountResp.Total = total return subAccountResp, nil } // ShutDownSubAccount 停用子账号 func (*subaccount) ShutDownSubAccount(ctx context.Context, request http_model.ShutDownSubAccountRequest) error { var newSubAccount *gorm_model.YounggeeSubAccount newSubAccount = &gorm_model.YounggeeSubAccount{} newSubAccount.SubAccountId = request.SubAccountId newSubAccount.AccountStatus = 2 err := db.UpdateSubAccount(ctx, newSubAccount) if err != nil { return err } return nil }