55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"strconv"
|
|
|
|
"lone-services/pkg/modelbase"
|
|
"lone-services/pkg/utils"
|
|
chore "lone-services/rpc/chore/pb"
|
|
"lone-services/services/chore/internal/dao"
|
|
"lone-services/services/chore/internal/model"
|
|
"lone-services/services/chore/internal/svc"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type RegionsLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewRegionsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RegionsLogic {
|
|
return &RegionsLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *RegionsLogic) Regions(in *chore.RegionsReq) (*chore.Response, error) {
|
|
params := modelbase.Params{
|
|
Order: "id ASC",
|
|
}
|
|
|
|
parentID := in.GetParentId()
|
|
if parentID < utils.NumberOne {
|
|
params.Eq = map[string]string{"level": strconv.Itoa(int(utils.NumberOne))}
|
|
} else {
|
|
params.Eq = map[string]string{"parent_id": strconv.Itoa(int(parentID))}
|
|
}
|
|
|
|
var list []dao.Region
|
|
if err := (model.RegionModel{}.Init().Items(params, &list)); err != nil {
|
|
l.Errorf("regions list: %v", err)
|
|
return failResponse(utils.Fail), nil
|
|
}
|
|
|
|
if list == nil {
|
|
list = []dao.Region{}
|
|
}
|
|
|
|
return okResponse(list), nil
|
|
}
|