75 lines
1.8 KiB
Go
75 lines
1.8 KiB
Go
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
|
|
|
package tickets
|
|
|
|
import (
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
|
"github.com/iwind/TeaGo/actions"
|
|
"github.com/iwind/TeaGo/maps"
|
|
)
|
|
|
|
type CreatePopupAction struct {
|
|
actionutils.ParentAction
|
|
}
|
|
|
|
func (this *CreatePopupAction) Init() {
|
|
this.Nav("", "", "")
|
|
}
|
|
|
|
func (this *CreatePopupAction) RunGet(params struct{}) {
|
|
// 分类
|
|
categoriesResp, err := this.RPC().UserTicketCategoryRPC().FindAllAvailableUserTicketCategories(this.UserContext(), &pb.FindAllAvailableUserTicketCategoriesRequest{})
|
|
if err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
var categories = categoriesResp.UserTicketCategories
|
|
var categoryMaps = []maps.Map{}
|
|
for _, category := range categories {
|
|
categoryMaps = append(categoryMaps, maps.Map{
|
|
"id": category.Id,
|
|
"name": category.Name,
|
|
})
|
|
}
|
|
this.Data["categories"] = categoryMaps
|
|
|
|
this.Show()
|
|
}
|
|
|
|
func (this *CreatePopupAction) RunPost(params struct {
|
|
CategoryId int64
|
|
Subject string
|
|
Body string
|
|
|
|
Must *actions.Must
|
|
CSRF *actionutils.CSRF
|
|
}) {
|
|
var ticketId int64
|
|
defer func() {
|
|
this.CreateLogInfo(codes.UserTicket_LogCreateUserTicket, ticketId)
|
|
}()
|
|
|
|
params.Must.
|
|
Field("subject", params.Subject).
|
|
Require("请输入工单标题").
|
|
MaxCharacters(100, "标题最大长度不能超过100").
|
|
Field("body", params.Body).
|
|
Require("请输入工单内容")
|
|
|
|
createResp, err := this.RPC().UserTicketRPC().CreateUserTicket(this.UserContext(), &pb.CreateUserTicketRequest{
|
|
UserTicketCategoryId: params.CategoryId,
|
|
Subject: params.Subject,
|
|
Body: params.Body,
|
|
})
|
|
if err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
|
|
ticketId = createResp.UserTicketId
|
|
|
|
this.Success()
|
|
}
|