53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
package controller
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/gogf/gf/v2/database/gdb"
|
|
|
|
"36wisdom/biz/model/dto"
|
|
"36wisdom/biz/service"
|
|
)
|
|
|
|
type prize struct{}
|
|
|
|
var Prize = &prize{}
|
|
|
|
func (c *prize) Get(ctx context.Context, req *dto.PrizeGetReq) (*dto.PrizeGetRes, error) {
|
|
rec, err := service.Prize.GetByPk(ctx, req.Id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
res := &dto.PrizeGetRes{}
|
|
if !rec.IsEmpty() {
|
|
res.Prize = prizeItem(rec)
|
|
}
|
|
return res, nil
|
|
}
|
|
|
|
func (c *prize) List(ctx context.Context, req *dto.PrizeListReq) (*dto.PrizeListRes, error) {
|
|
recs, err := service.Prize.ListEnabled(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
res := &dto.PrizeListRes{List: make([]dto.PrizeItem, 0, len(recs))}
|
|
for _, r := range recs {
|
|
res.List = append(res.List, prizeItem(r))
|
|
}
|
|
return res, nil
|
|
}
|
|
|
|
func prizeItem(r gdb.Record) dto.PrizeItem {
|
|
return dto.PrizeItem{
|
|
Id: r["id"].Int64(),
|
|
Name: r["name"].String(),
|
|
Description: r["description"].String(),
|
|
Icon: r["icon"].String(),
|
|
PType: r["p_type"].Int(),
|
|
PointsCost: r["points_cost"].Int(),
|
|
Stock: r["stock"].Int(),
|
|
Status: r["status"].Int(),
|
|
SortOrder: r["sort_order"].Int(),
|
|
}
|
|
}
|