package talent_service

import (
	"github.com/gogf/gf/database/gdb"
	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/net/ghttp"
	"youngmini_server/app/dao"
	"youngmini_server/app/model"
)

func GetRegionInfo(r *ghttp.Request) *TalentHttpResult {
	sPid := r.GetQueryInt("pid", 0)

	var res gdb.Result
	var err error

	if sPid == 0 {
		res, err = g.DB().Model(model.InfoRegion{}).Fields(dao.InfoRegion.Columns.SelfCode,
			dao.InfoRegion.Columns.RegionName).All("parent_code is null")
	} else {
		res, err = g.DB().Model(model.InfoRegion{}).Fields(dao.InfoRegion.Columns.SelfCode,
			dao.InfoRegion.Columns.RegionName).All("parent_code", sPid)
	}

	if err != nil {
		return &TalentHttpResult{Code: -2, Msg: "query data failed"}
	}

	if res == nil {
		return &TalentHttpResult{Code: -3, Msg: "param error"}
	}

	return &TalentHttpResult{Code: 0, Msg: "success", Data: res}
}