123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915 |
- package v1
- import (
- "git.getensh.com/common/gopkgs/logger"
- "git.getensh.com/common/gopkgs/tasker/httptasker"
- "git.getensh.com/common/gopkgs/util"
- "github.com/gin-gonic/gin"
- "go.uber.org/zap"
- "net/http"
- "property-household-gateway/errors"
- param_v1 "property-household-gateway/param/v1"
- "property-household-gateway/pb"
- "property-household-gateway/pb/v1"
- "property-household-gateway/utils"
- )
- func BaseConfToBool(data int64) v1.HouseRentBaseConf {
- conf := v1.HouseRentBaseConf{}
- one := int64(1)
- if data&one > 0 {
- conf.Bed = true
- }
- if data&(one<<1) > 0 {
- conf.Gas = true
- }
- if data&(one<<2) > 0 {
- conf.WarmGas = true
- }
- if data&(one<<3) > 0 {
- conf.Broadband = true
- }
- if data&(one<<4) > 0 {
- conf.Refragerator = true
- }
- if data&(one<<5) > 0 {
- conf.Wardobe = true
- }
- if data&(one<<6) > 0 {
- conf.Sofa = true
- }
- if data&(one<<7) > 0 {
- conf.Aircondition = true
- }
- if data&(one<<8) > 0 {
- conf.Tv = true
- }
- if data&(one<<9) > 0 {
- conf.Heater = true
- }
- if data&(one<<10) > 0 {
- conf.Warshing = true
- }
- return conf
- }
- func SpecialConfToBool(data int64) v1.HouseRentSpecialConf {
- conf := v1.HouseRentSpecialConf{}
- one := int64(1)
- if data&one > 0 {
- conf.IntelligentLock = true
- }
- if data&(one<<1) > 0 {
- conf.Wifi = true
- }
- if data&(one<<2) > 0 {
- conf.Metro = true
- }
- if data&(one<<3) > 0 {
- conf.ParkSpace = true
- }
- if data&(one<<4) > 0 {
- conf.IndependentWc = true
- }
- if data&(one<<5) > 0 {
- conf.PrivateBalcony = true
- }
- if data&(one<<6) > 0 {
- conf.FirstRent = true
- }
- return conf
- }
- func BaseConfToBitmap(conf *v1.HouseRentBaseConf) int64 {
- ret := int64(0)
- one := int64(1)
- if conf.Bed {
- ret = ret | (one)
- }
- if conf.Gas {
- ret = ret | (one << 1)
- }
- if conf.WarmGas {
- ret = ret | (one << 2)
- }
- if conf.Broadband {
- ret = ret | (one << 3)
- }
- if conf.Refragerator {
- ret = ret | (one << 4)
- }
- if conf.Wardobe {
- ret = ret | (one << 5)
- }
- if conf.Sofa {
- ret = ret | (one << 6)
- }
- if conf.Aircondition {
- ret = ret | (one << 7)
- }
- if conf.Tv {
- ret = ret | (one << 8)
- }
- if conf.Heater {
- ret = ret | (one << 9)
- }
- if conf.Warshing {
- ret = ret | (one << 10)
- }
- return ret
- }
- func SpecialConfToBitmap(conf *v1.HouseRentSpecialConf) int64 {
- ret := int64(0)
- one := int64(1)
- if conf.IntelligentLock {
- ret = ret | (one)
- }
- if conf.Wifi {
- ret = ret | (one << 1)
- }
- if conf.Metro {
- ret = ret | (one << 2)
- }
- if conf.ParkSpace {
- ret = ret | (one << 3)
- }
- if conf.IndependentWc {
- ret = ret | (one << 4)
- }
- if conf.PrivateBalcony {
- ret = ret | (one << 5)
- }
- if conf.FirstRent {
- ret = ret | (one << 6)
- }
- return ret
- }
- ///
- // @Summary 租房列表
- // @Description 租房列表
- // @Tags 房屋租赁
- // @Accept json
- // @Produce json
- // @Param token header string true "token"
- // @Param province_code query string false "省份代码"
- // @Param city_code query string false "城市代码"
- // @Param area_code query string false "区域代码"
- // @Param street_code query string false "街道代码"
- // @Param room_count query int false "几室"
- // @Param hall_count query int false "几厅"
- // @Param wc_count query int false "几卫"
- // @Param rent_price_greater query string false "租金大于"
- // @Param rent_price_less query string false "租金小于"
- // @Param approve_status query int false "审核状态 0 不过滤 1 待审核 2 通过 3 未通过"
- // @Param page query int false " "
- // @Param page_size query int false " "
- // @Param base_conf query int false "从低bit到高bit分别表示床 天然气 暖气 宽带 冰箱 衣柜 沙发 空调 电视机 热水器 洗衣机"
- // @Param special_conf query int false "从低到高分别表示 智能门锁 wifi 近地铁 停车位 独卫 私人阳台 首次出租"
- // @Param garden_id query int false " 小区id"
- // @Param garden_name query string false " 小区名字"
- // @Param building_type query int false " 1塔楼 2 板楼 3 塔板结合 4 其他"
- // @Param building_year_greater query int false " 楼龄年份大于"
- // @Param building_year_less query int false " 楼龄小于"
- // @Param is_me query bool false "我发布的"
- // @Success 200 {object} v1.HouseRentListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/rent/house [get]
- func (c *Controller) HouseRentList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.HouseRentListRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.HouseRentListQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- tokenInfo, err := utils.GetJwtTokenInfo(ctx)
- if err != nil {
- return err
- }
- gardenIds := []int64{}
- if req.GardenName != "" || req.BuildingYearLess > 0 || req.BuildingYearGreater > 0 || req.BuildingType > 0 {
- rpcReq := &v1.GardenIdsRequest{
- //BaseConf:
- //SpecialConf
- GardenName: req.GardenName,
- BuildingYearGreater: req.BuildingYearGreater,
- BuildingYearLess: req.BuildingYearLess,
- BuildingType: req.BuildingType,
- }
- rpcRsp, err := pb.System.GardenIds(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.System.GardenIds"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if len(rpcRsp.GardenIds) == 0 {
- resp := param_v1.HouseRentListResponse{
- Data: v1.HouseRentListReply{
- Page: 1,
- Total: 0,
- List: make([]*v1.HouseRentItem, 0),
- },
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- gardenIds = make([]int64, len(rpcRsp.GardenIds))
- for i, v := range rpcRsp.GardenIds {
- gardenIds[i] = v.GardenId
- }
- }
- // 响应数据
- resp := param_v1.HouseRentListResponse{}
- rpcReq := &v1.HouseRentListRequest{
- GardenId: req.GardenId,
- ProvinceCode: req.ProvinceCode,
- CityCode: req.CityCode,
- AreaCode: req.AreaCode,
- StreetCode: req.StreetCode,
- RoomCount: req.RoomCount,
- HallCount: req.HallCount,
- WcCount: req.WcCount,
- RentPriceGreater: req.RentPriceGreater,
- RentPriceLess: req.RentPriceLess,
- ApproveStatus: req.ApproveStatus,
- Page: req.Page,
- PageSize: req.PageSize,
- GardenIds: gardenIds,
- //BaseConf:
- //SpecialConf
- }
- if req.IsMe {
- rpcReq.HouseholdUid = tokenInfo.Uid
- }
- //baseConf := BaseConfToBool(req.BaseConf)
- //specialConf := SpecialConfToBool(req.SpecialConf)
- rpcReq.BaseConf = req.BaseConf
- rpcReq.SpecialConf = req.SpecialConf
- rpcRsp, err := pb.Household.HouseRentList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Household.HouseRentList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if rpcRsp.List == nil {
- rpcRsp.List = make([]*v1.HouseRentItem, 0)
- }
- resp.Data = *rpcRsp
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- ///
- // @Summary 发布房源
- // @Description 发布房源
- // @Tags 房屋租赁
- // @Accept json
- // @Produce json
- // @Param token header string true "token"
- // @Param body body v1.HouseRentApplyBody true " "
- // @Success 200 {object} v1.HouseRentApplyResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/rent/house [post]
- func (c *Controller) HouseRentApply(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.HouseRentApplyRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.HouseRentApplyBody)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- tokenInfo, err := utils.GetJwtTokenInfo(ctx)
- if err != nil {
- return err
- }
- // 响应数据
- resp := param_v1.HouseRentApplyResponse{}
- rpcReq := &v1.HouseRentApplyRequest{
- GardenId: req.GardenId,
- HouseholdUid: tokenInfo.Uid,
- WcCount: req.WcCount,
- // 房屋号
- HouseId: req.HouseId,
- // 朝向
- Direction: req.Direction,
- // 1 精装 2 简装 3 清水
- Decorating: req.Decorating,
- // 联系人
- Contacter: req.Contacter,
- // 联系人电话
- ContactPhone: req.ContactPhone,
- // 1 月付 2 季付 3 半年付 4 年付
- PayTimeType: req.PayTimeType,
- // 1 整租 2 合租 3 转租
- RentType: req.RentType,
- // 1 全部 2 主卧 3 次卧
- RoomType: req.RoomType,
- // 房间面积
- RoomArea: req.RoomArea,
- // 月租
- RentPrice: req.RentPrice,
- // 押金
- Desposit: req.Desposit,
- // 可入住时间
- InTime: req.InTime,
- // 服务费
- ServicePrice: req.ServicePrice,
- // 中介费
- IntermediaryPrice: req.IntermediaryPrice,
- // 简介
- Desc: req.Desc,
- // 房屋图片
- HousePic: req.HousePic,
- // 房屋证件图片
- CertPic: req.CertPic,
- // 是否直接通过审核
- Approve: false,
- //BaseConf:
- //SpecialConf
- }
- //baseConf := BaseConfToBool(req.BaseConf)
- //specialConf := SpecialConfToBool(req.SpecialConf)
- rpcReq.BaseConf = req.BaseConf
- rpcReq.SpecialConf = req.SpecialConf
- rpcRsp, err := pb.Household.HouseRentApply(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Household.HouseRentApply"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = *rpcRsp
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- //
- // @Summary 修改信息
- // @Description 修改信息
- // @Tags 房屋租赁
- // @Accept json
- // @Produce json
- // @Param token header string true "token"
- // @Param body body v1.HouseRentUpdateBody true " "
- // @Success 200 {object} v1.HouseRentUpdateResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/rent/house [put]
- func (c *Controller) HouseRentUpdate(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.HouseRentUpdateRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.HouseRentUpdateBody)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- //tokenInfo, err := utils.GetJwtTokenInfo(ctx)
- //if err != nil {
- // return err
- //}
- // 响应数据
- resp := param_v1.HouseRentUpdateResponse{}
- rpcReq := &v1.HouseRentUpdateRequest{
- Id: req.Id,
- GardenId: req.GardenId,
- WcCount: req.WcCount,
- HouseId: req.HouseId,
- // 朝向
- Direction: req.Direction,
- // 1 精装 2 简装 3 清水
- Decorating: req.Decorating,
- // 联系人
- Contacter: req.Contacter,
- // 联系人电话
- ContactPhone: req.ContactPhone,
- // 1 月付 2 季付 3 半年付 4 年付
- PayTimeType: req.PayTimeType,
- // 1 整租 2 合租 3 转租
- RentType: req.RentType,
- // 1 全部 2 主卧 3 次卧
- RoomType: req.RoomType,
- // 房间面积
- RoomArea: req.RoomArea,
- // 月租
- RentPrice: req.RentPrice,
- // 押金
- Desposit: req.Desposit,
- // 可入住时间
- InTime: req.InTime,
- // 服务费
- ServicePrice: req.ServicePrice,
- // 中介费
- IntermediaryPrice: req.IntermediaryPrice,
- // 简介
- Desc: req.Desc,
- // 房屋图片
- HousePic: req.HousePic,
- // 房屋证件图片
- CertPic: req.CertPic,
- //BaseConf:
- //SpecialConf
- }
- //baseConf := BaseConfToBool(req.BaseConf)
- //specialConf := SpecialConfToBool(req.SpecialConf)
- rpcReq.BaseConf = req.BaseConf
- rpcReq.SpecialConf = req.SpecialConf
- _, err := pb.Household.HouseRentUpdate(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Household.HouseRentUpdate"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- //
- // @Summary 下架
- // @Description 下架
- // @Tags 房屋租赁
- // @Accept json
- // @Produce json
- // @Param token header string true "token"
- // @Param body body v1.HouseRentDownBody true " "
- // @Success 200 {object} v1.HouseRentDownResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/rent/house/down [put]
- func (c *Controller) HouseRentDown(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.HouseRentDownRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.HouseRentDownBody)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- //tokenInfo, err := utils.GetJwtTokenInfo(ctx)
- //if err != nil {
- // return err
- //}
- // 响应数据
- resp := param_v1.HouseRentDownResponse{}
- rpcReq := &v1.HouseRentDownRequest{
- Id: req.Id,
- GardenId: req.GardenId,
- }
- _, err := pb.Household.HouseRentDown(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Household.HouseRentDown"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- //
- // @Summary 房屋的经纪人列表
- // @Description 房屋的经纪人列表
- // @Tags 房屋租赁
- // @Accept json
- // @Produce json
- // @Param token header string true "token"
- // @Param rent_id query int true "租房信息id"
- // @Param garden_id query int true "小区id"
- // @Success 200 {object} v1.HouseRentManagerListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/rent/house/manager [get]
- func (c *Controller) HouseRentManagerList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.HouseRentManagerListRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.HouseRentManagerListQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- //tokenInfo, err := utils.GetJwtTokenInfo(ctx)
- //if err != nil {
- // return err
- //}
- // 响应数据
- resp := param_v1.HouseRentManagerListResponse{}
- rpcReq := &v1.HouseRentManagerListRequest{
- GardenId: req.GardenId,
- RentId: req.RentId,
- }
- rpcRsp, err := pb.Garden.HouseRentManagerList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Garden.HouseRentManagerList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if rpcRsp.List == nil {
- rpcRsp.List = make([]*v1.HouseRentManagerItem, 0)
- }
- resp.Data = *rpcRsp
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- //
- // @Summary 租房预约记录
- // @Description 租房预约记录
- // @Tags 房屋租赁
- // @Accept json
- // @Produce json
- // @Param token header string true "token"
- // @Param page query int false " "
- // @Param page_size query int false " "
- // @Success 200 {object} v1.HouseRentAppointmentListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/rent/house/appointment [get]
- func (c *Controller) HouseRentAppointmentList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.HouseRentAppointmentListRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.HouseRentAppointmentListQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- tokenInfo, err := utils.GetJwtTokenInfo(ctx)
- if err != nil {
- return err
- }
- // 响应数据
- resp := param_v1.HouseRentAppointmentListResponse{}
- rpcReq := &v1.HouseRentAppointmentListRequest{
- Uid: tokenInfo.Uid,
- Page: req.Page,
- PageSize: req.PageSize,
- }
- rpcRsp, err := pb.Household.HouseRentAppointmentList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Household.HouseRentAppointmentList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if rpcRsp.List == nil {
- rpcRsp.List = make([]*v1.HouseRentAppointmentItem, 0)
- }
- resp.Data = *rpcRsp
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- //
- // @Summary 删除租房预约记录
- // @Description 删除租房预约记录
- // @Tags 房屋租赁
- // @Accept json
- // @Produce json
- // @Param token header string true "token"
- // @Param id query int true "记录id"
- // @Success 200 {object} v1.HouseRentAppointmentDelResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/rent/house/appointment [delete]
- func (c *Controller) HouseRentAppointmentDel(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.HouseRentAppointmentDelRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.HouseRentAppointmentDelQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- //tokenInfo, err := utils.GetJwtTokenInfo(ctx)
- //if err != nil {
- // return err
- //}
- // 响应数据
- resp := param_v1.HouseRentAppointmentDelResponse{}
- rpcReq := &v1.HouseRentAppointmentDelRequest{
- Id: req.Id,
- }
- _, err := pb.Household.HouseRentAppointmentDel(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Household.HouseRentAppointmentDel"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- //
- // @Summary 租房预约看房
- // @Description 租房预约看房
- // @Tags 房屋租赁
- // @Accept json
- // @Produce json
- // @Param token header string true "token"
- // @Param body body v1.HouseRentAppointmentAddBody true " "
- // @Success 200 {object} v1.HouseRentAppointmentListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/rent/house/appointment [post]
- func (c *Controller) HouseRentAppointmentAdd(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.HouseRentAppointmentAddRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.HouseRentAppointmentAddBody)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- tokenInfo, err := utils.GetJwtTokenInfo(ctx)
- if err != nil {
- return err
- }
- // 响应数据
- resp := param_v1.HouseRentAppointmentAddResponse{}
- rpcReq := &v1.HouseRentAppointmentAddRequest{
- GardenId: req.GardenId,
- RentId: req.RentId,
- Uid: tokenInfo.Uid,
- Name: req.Name,
- Phone: req.Phone,
- AppointmentTime: req.AppointmentTime,
- Gender: req.Gender,
- }
- _, err = pb.Household.HouseRentAppointmentAdd(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Household.HouseRentAppointmentAdd"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- ///
- // @Summary 均价,已租已售数
- // @Description 均价,已租已售数
- // @Tags 房屋租赁
- // @Accept json
- // @Produce json
- // @Param token header string true "token"
- // @Param garden_id query int true " 小区id"
- // @Param is_me query bool false "我发布的"
- // @Success 200 {object} v1.GardenHouseRentInfoResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/rent/garden_info [get]
- func (c *Controller) GardenHouseRentInfo(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GardenHouseRentInfoRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.GardenHouseRentInfoQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- //tokenInfo, err := utils.GetJwtTokenInfo(ctx)
- //if err != nil {
- // return err
- //}
- // 响应数据
- resp := param_v1.GardenHouseRentInfoResponse{}
- rpcReq := &v1.GardenHouseRentInfoRequest{
- GardenId: req.GardenId,
- }
- rpcRsp, err := pb.Garden.GardenHouseRentInfo(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Garden.GardenHouseRentInfo"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- mReq := &v1.GardenInfosRequest{
- Ids: []int64{req.GardenId},
- }
- mRsp, err := pb.System.GardenInfos(ctx, mReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "Garden.GardenInfos"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if len(mRsp.List) > 0 {
- rpcRsp.GardenPics = mRsp.List[0].GardenPics
- rpcRsp.BuildingStart = mRsp.List[0].BuildingStart
- rpcRsp.BuildingEnd = mRsp.List[0].BuildingEnd
- rpcRsp.PropertyFeeStart = mRsp.List[0].PropertyFeeStart
- rpcRsp.PropertyFeeEnd = mRsp.List[0].PropertyFeeEnd
- rpcRsp.GasFeeStart = mRsp.List[0].GasFeeStart
- rpcRsp.GasFeeEnd = mRsp.List[0].GasFeeEnd
- rpcRsp.BuildingType = mRsp.List[0].BuildingType
- rpcRsp.BuildingArea = mRsp.List[0].BuildingArea
- rpcRsp.BuildingCompany = mRsp.List[0].BuildingCompany
- rpcRsp.GreenPercent = mRsp.List[0].GreenPercent
- rpcRsp.AreaPercent = mRsp.List[0].AreaPercent
- rpcRsp.WaterType = mRsp.List[0].WaterType
- rpcRsp.ElectricType = mRsp.List[0].ElectricType
- rpcRsp.HouseTotal = mRsp.List[0].HouseTotal
- rpcRsp.SpaceInfo = mRsp.List[0].SpaceInfo
- rpcRsp.SpaceTotal = mRsp.List[0].SpaceTotal
- }
- if rpcRsp.WaterType == nil {
- rpcRsp.WaterType = []int32{}
- }
- if rpcRsp.ElectricType == nil {
- rpcRsp.ElectricType = []int32{}
- }
- if rpcRsp.GardenPics == nil {
- rpcRsp.GardenPics = []string{}
- }
- resp.Data = *rpcRsp
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
|