diff --git a/apis/admin/ticket.api b/apis/admin/ticket.api index c325bf0..8ae45e7 100644 --- a/apis/admin/ticket.api +++ b/apis/admin/ticket.api @@ -16,11 +16,12 @@ type ( Status *uint8 `json:"status" validate:"required"` } GetTicketListRequest { - Page int64 `form:"page"` - Size int64 `form:"size"` - UserId int64 `form:"user_id,omitempty"` - Status *uint8 `form:"status,omitempty"` - Search string `form:"search,omitempty"` + Page int64 `form:"page"` + Size int64 `form:"size"` + UserId int64 `form:"user_id,omitempty"` + Status *uint8 `form:"status,omitempty"` + IssueType *uint8 `form:"issue_type,omitempty"` + Search string `form:"search,omitempty"` } GetTicketListResponse { Total int64 `json:"total"` diff --git a/apis/public/ticket.api b/apis/public/ticket.api index 0f39304..0f7d2e5 100644 --- a/apis/public/ticket.api +++ b/apis/public/ticket.api @@ -18,12 +18,14 @@ type ( CreateUserTicketRequest { Title string `json:"title"` Description string `json:"description"` + IssueType uint8 `json:"issue_type"` } GetUserTicketListRequest { - Page int `form:"page"` - Size int `form:"size"` - Status *uint8 `form:"status,omitempty"` - Search string `form:"search,omitempty"` + Page int `form:"page"` + Size int `form:"size"` + Status *uint8 `form:"status,omitempty"` + IssueType *uint8 `form:"issue_type,omitempty"` + Search string `form:"search,omitempty"` } GetUserTicketDetailRequest { Id int64 `form:"id" validate:"required"` diff --git a/internal/logic/admin/ticket/getTicketListLogic.go b/internal/logic/admin/ticket/getTicketListLogic.go index c03932a..9a60a19 100644 --- a/internal/logic/admin/ticket/getTicketListLogic.go +++ b/internal/logic/admin/ticket/getTicketListLogic.go @@ -27,7 +27,7 @@ func NewGetTicketListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Get } func (l *GetTicketListLogic) GetTicketList(req *types.GetTicketListRequest) (resp *types.GetTicketListResponse, err error) { - total, list, err := l.svcCtx.TicketModel.QueryTicketList(l.ctx, int(req.Page), int(req.Size), req.UserId, req.Status, req.Search) + total, list, err := l.svcCtx.TicketModel.QueryTicketList(l.ctx, int(req.Page), int(req.Size), req.UserId, req.Status, req.IssueType, req.Search) if err != nil { l.Errorw("[GetTicketList] Query Database Error: ", logger.Field("error", err.Error())) return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "QueryTicketList error: %v", err) diff --git a/internal/logic/public/ticket/createUserTicketLogic.go b/internal/logic/public/ticket/createUserTicketLogic.go index ea6cda1..a00a010 100644 --- a/internal/logic/public/ticket/createUserTicketLogic.go +++ b/internal/logic/public/ticket/createUserTicketLogic.go @@ -41,6 +41,7 @@ func (l *CreateUserTicketLogic) CreateUserTicket(req *types.CreateUserTicketRequ Description: req.Description, UserId: u.Id, Status: ticket.Pending, + IssueType: req.IssueType, }) if err != nil { return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseInsertError), "insert ticket error: %v", err.Error()) diff --git a/internal/logic/public/ticket/getUserTicketListLogic.go b/internal/logic/public/ticket/getUserTicketListLogic.go index 6340259..f3e5a0c 100644 --- a/internal/logic/public/ticket/getUserTicketListLogic.go +++ b/internal/logic/public/ticket/getUserTicketListLogic.go @@ -36,7 +36,7 @@ func (l *GetUserTicketListLogic) GetUserTicketList(req *types.GetUserTicketListR return nil, errors.Wrapf(xerr.NewErrCode(xerr.InvalidAccess), "Invalid Access") } l.Logger.Debugf("Current user: %v", u.Id) - total, list, err := l.svcCtx.TicketModel.QueryTicketList(l.ctx, req.Page, req.Size, u.Id, req.Status, req.Search) + total, list, err := l.svcCtx.TicketModel.QueryTicketList(l.ctx, req.Page, req.Size, u.Id, req.Status, req.IssueType, req.Search) if err != nil { l.Errorw("[GetUserTicketListLogic] Database Error", logger.Field("error", err.Error())) return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "QueryTicketList error: %v", err) diff --git a/internal/model/ticket/model.go b/internal/model/ticket/model.go index 0662aa7..dac125a 100644 --- a/internal/model/ticket/model.go +++ b/internal/model/ticket/model.go @@ -17,6 +17,7 @@ type Details struct { Description string `gorm:"type:text;comment:Description"` UserId int64 `gorm:"type:bigint;not null;default:0;comment:UserId"` Status uint8 `gorm:"type:tinyint(1);not null;default:1;comment:Status"` + IssueType uint8 `gorm:"type:tinyint(1);not null;default:0;comment:Issue Type: 0 ticket, 1 withdraw"` Follows []Follow `gorm:"foreignKey:TicketId;references:Id"` CreatedAt time.Time `gorm:"<-:create;comment:Create Time"` UpdatedAt time.Time `gorm:"comment:Update Time"` @@ -24,7 +25,7 @@ type Details struct { type customTicketLogicModel interface { QueryTicketDetail(ctx context.Context, id int64) (*Details, error) InsertTicketFollow(ctx context.Context, data *Follow) error - QueryTicketList(ctx context.Context, page, size int, userId int64, status *uint8, search string) (int64, []*Ticket, error) + QueryTicketList(ctx context.Context, page, size int, userId int64, status *uint8, issueType *uint8, search string) (int64, []*Ticket, error) UpdateTicketStatus(ctx context.Context, id, userId int64, status uint8) error QueryWaitReplyTotal(ctx context.Context) (int64, error) } @@ -55,7 +56,7 @@ func (m *customTicketModel) InsertTicketFollow(ctx context.Context, data *Follow } // QueryTicketList returns the ticket list. -func (m *customTicketModel) QueryTicketList(ctx context.Context, page, size int, userId int64, status *uint8, search string) (int64, []*Ticket, error) { +func (m *customTicketModel) QueryTicketList(ctx context.Context, page, size int, userId int64, status *uint8, issueType *uint8, search string) (int64, []*Ticket, error) { var data []*Ticket var total int64 err := m.QueryNoCacheCtx(ctx, &data, func(conn *gorm.DB, v interface{}) error { @@ -68,6 +69,9 @@ func (m *customTicketModel) QueryTicketList(ctx context.Context, page, size int, } else { query = query.Where("status != ?", 4) } + if issueType != nil { + query = query.Where("issue_type = ?", issueType) + } if search != "" { query = query.Where("title like ? or description like ?", "%"+search+"%", "%"+search+"%") } diff --git a/internal/model/ticket/ticket.go b/internal/model/ticket/ticket.go index 2c8f47d..a3f09f5 100644 --- a/internal/model/ticket/ticket.go +++ b/internal/model/ticket/ticket.go @@ -12,9 +12,10 @@ const ( type Ticket struct { Id int64 `gorm:"primaryKey"` Title string `gorm:"type:varchar(255);not null;default:'';comment:Title"` - Description string `gorm:"type:text;comment:Description"` + Description string `gorm:"type:longtext;comment:Description"` UserId int64 `gorm:"type:bigint;not null;default:0;comment:UserId"` Status uint8 `gorm:"type:tinyint(1);not null;default:1;comment:Status"` + IssueType uint8 `gorm:"type:tinyint(1);not null;default:0;comment:Issue Type: 0 ticket, 1 withdraw"` CreatedAt time.Time `gorm:"<-:create;comment:Create Time"` UpdatedAt time.Time `gorm:"comment:Update Time"` } diff --git a/internal/types/types.go b/internal/types/types.go index 90f4523..363a6f1 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -529,6 +529,7 @@ type CreateUserTicketFollowRequest struct { type CreateUserTicketRequest struct { Title string `json:"title"` Description string `json:"description"` + IssueType uint8 `json:"issue_type"` } type Currency struct { @@ -905,11 +906,12 @@ type GetSubscriptionResponse struct { } type GetTicketListRequest struct { - Page int64 `form:"page"` - Size int64 `form:"size"` - UserId int64 `form:"user_id,omitempty"` - Status *uint8 `form:"status,omitempty"` - Search string `form:"search,omitempty"` + Page int64 `form:"page"` + Size int64 `form:"size"` + UserId int64 `form:"user_id,omitempty"` + Status *uint8 `form:"status,omitempty"` + IssueType *uint8 `form:"issue_type,omitempty"` + Search string `form:"search,omitempty"` } type GetTicketListResponse struct { @@ -1021,10 +1023,11 @@ type GetUserTicketDetailRequest struct { } type GetUserTicketListRequest struct { - Page int `form:"page"` - Size int `form:"size"` - Status *uint8 `form:"status,omitempty"` - Search string `form:"search,omitempty"` + Page int `form:"page"` + Size int `form:"size"` + Status *uint8 `form:"status,omitempty"` + IssueType *uint8 `form:"issue_type,omitempty"` + Search string `form:"search,omitempty"` } type GetUserTicketListResponse struct { @@ -1769,6 +1772,7 @@ type Ticket struct { UserId int64 `json:"user_id"` Follows []Follow `json:"follow,omitempty"` Status uint8 `json:"status"` + IssueType uint8 `json:"issue_type"` CreatedAt int64 `json:"created_at"` UpdatedAt int64 `json:"updated_at"` }