Files
im_manager/server/internal/logic/sys/im_tenant_application.go
T

118 lines
3.2 KiB
Go

// Package sys
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2026 HotGo
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package sys
import (
"context"
"hotgo/internal/model/input/sysin"
"hotgo/internal/service"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
)
type sSysImTenantApplication struct{}
func NewSysImTenantApplication() *sSysImTenantApplication {
return &sSysImTenantApplication{}
}
func init() {
service.RegisterSysImTenantApplication(NewSysImTenantApplication())
}
// List 获取企业注册申请列表
func (s *sSysImTenantApplication) List(ctx context.Context, in *sysin.ImTenantApplicationListInp) (list []*sysin.ImTenantApplicationListModel, totalCount int, err error) {
if err = in.Filter(ctx); err != nil {
return
}
mod := s.listModel(ctx)
mod = s.applyWhere(mod, in)
mod = mod.Page(in.Page, in.PerPage).OrderDesc("created_at").OrderDesc("id")
if err = mod.ScanAndCount(&list, &totalCount, false); err != nil {
return nil, 0, gerror.Wrap(err, "获取企业注册申请列表失败,请稍后重试!")
}
return
}
func (s *sSysImTenantApplication) listModel(ctx context.Context) *gdb.Model {
return g.DB().Model("im_tenant_applications").Safe().Ctx(ctx).Fields(
"id",
"application_id",
"credit_code",
"enterprise_email",
"license_file_id",
"tenant_code_hint",
"status",
"estimated_review_hour",
"submitted_at",
"created_at",
"updated_at",
)
}
func (s *sSysImTenantApplication) applyWhere(mod *gdb.Model, in *sysin.ImTenantApplicationListInp) *gdb.Model {
if in.ApplicationId != "" {
mod = mod.WhereLike("application_id", "%"+in.ApplicationId+"%")
}
if in.CreditCode != "" {
mod = mod.WhereLike("credit_code", "%"+in.CreditCode+"%")
}
if in.EnterpriseEmail != "" {
mod = mod.WhereLike("enterprise_email", "%"+in.EnterpriseEmail+"%")
}
if in.TenantCodeHint != "" {
mod = mod.WhereLike("tenant_code_hint", "%"+in.TenantCodeHint+"%")
}
if in.Status != "" {
mod = mod.Where("status", in.Status)
}
if in.Keyword != "" {
like := "%" + in.Keyword + "%"
mod = mod.Where("(application_id LIKE ? OR credit_code LIKE ? OR enterprise_email LIKE ? OR tenant_code_hint LIKE ?)", like, like, like, like)
}
if len(in.CreatedAt) == 2 {
mod = mod.WhereBetween("created_at", in.CreatedAt[0], in.CreatedAt[1])
}
return mod
}
// View 获取企业注册申请指定信息
func (s *sSysImTenantApplication) View(ctx context.Context, in *sysin.ImTenantApplicationViewInp) (res *sysin.ImTenantApplicationViewModel, err error) {
if err = in.Filter(ctx); err != nil {
return
}
if err = g.DB().Model("im_tenant_applications").Safe().Ctx(ctx).
Fields(
"id",
"application_id",
"credit_code",
"enterprise_email",
"license_file_id",
"tenant_code_hint",
"CAST(client_context AS CHAR) client_context",
"idempotency_key",
"status",
"estimated_review_hour",
"submitted_at",
"created_at",
"updated_at",
).
Where("id", in.Id).
Scan(&res); err != nil {
return nil, gerror.Wrap(err, "获取企业注册申请信息失败,请稍后重试!")
}
if res == nil {
return
}
res.LicenseFile, err = firstImPublicUpload(ctx, res.LicenseFileId)
return
}