house_rent.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915
  1. package v1
  2. import (
  3. "git.getensh.com/common/gopkgs/logger"
  4. "git.getensh.com/common/gopkgs/tasker/httptasker"
  5. "git.getensh.com/common/gopkgs/util"
  6. "github.com/gin-gonic/gin"
  7. "go.uber.org/zap"
  8. "net/http"
  9. "property-household-gateway/errors"
  10. param_v1 "property-household-gateway/param/v1"
  11. "property-household-gateway/pb"
  12. "property-household-gateway/pb/v1"
  13. "property-household-gateway/utils"
  14. )
  15. func BaseConfToBool(data int64) v1.HouseRentBaseConf {
  16. conf := v1.HouseRentBaseConf{}
  17. one := int64(1)
  18. if data&one > 0 {
  19. conf.Bed = true
  20. }
  21. if data&(one<<1) > 0 {
  22. conf.Gas = true
  23. }
  24. if data&(one<<2) > 0 {
  25. conf.WarmGas = true
  26. }
  27. if data&(one<<3) > 0 {
  28. conf.Broadband = true
  29. }
  30. if data&(one<<4) > 0 {
  31. conf.Refragerator = true
  32. }
  33. if data&(one<<5) > 0 {
  34. conf.Wardobe = true
  35. }
  36. if data&(one<<6) > 0 {
  37. conf.Sofa = true
  38. }
  39. if data&(one<<7) > 0 {
  40. conf.Aircondition = true
  41. }
  42. if data&(one<<8) > 0 {
  43. conf.Tv = true
  44. }
  45. if data&(one<<9) > 0 {
  46. conf.Heater = true
  47. }
  48. if data&(one<<10) > 0 {
  49. conf.Warshing = true
  50. }
  51. return conf
  52. }
  53. func SpecialConfToBool(data int64) v1.HouseRentSpecialConf {
  54. conf := v1.HouseRentSpecialConf{}
  55. one := int64(1)
  56. if data&one > 0 {
  57. conf.IntelligentLock = true
  58. }
  59. if data&(one<<1) > 0 {
  60. conf.Wifi = true
  61. }
  62. if data&(one<<2) > 0 {
  63. conf.Metro = true
  64. }
  65. if data&(one<<3) > 0 {
  66. conf.ParkSpace = true
  67. }
  68. if data&(one<<4) > 0 {
  69. conf.IndependentWc = true
  70. }
  71. if data&(one<<5) > 0 {
  72. conf.PrivateBalcony = true
  73. }
  74. if data&(one<<6) > 0 {
  75. conf.FirstRent = true
  76. }
  77. return conf
  78. }
  79. func BaseConfToBitmap(conf *v1.HouseRentBaseConf) int64 {
  80. ret := int64(0)
  81. one := int64(1)
  82. if conf.Bed {
  83. ret = ret | (one)
  84. }
  85. if conf.Gas {
  86. ret = ret | (one << 1)
  87. }
  88. if conf.WarmGas {
  89. ret = ret | (one << 2)
  90. }
  91. if conf.Broadband {
  92. ret = ret | (one << 3)
  93. }
  94. if conf.Refragerator {
  95. ret = ret | (one << 4)
  96. }
  97. if conf.Wardobe {
  98. ret = ret | (one << 5)
  99. }
  100. if conf.Sofa {
  101. ret = ret | (one << 6)
  102. }
  103. if conf.Aircondition {
  104. ret = ret | (one << 7)
  105. }
  106. if conf.Tv {
  107. ret = ret | (one << 8)
  108. }
  109. if conf.Heater {
  110. ret = ret | (one << 9)
  111. }
  112. if conf.Warshing {
  113. ret = ret | (one << 10)
  114. }
  115. return ret
  116. }
  117. func SpecialConfToBitmap(conf *v1.HouseRentSpecialConf) int64 {
  118. ret := int64(0)
  119. one := int64(1)
  120. if conf.IntelligentLock {
  121. ret = ret | (one)
  122. }
  123. if conf.Wifi {
  124. ret = ret | (one << 1)
  125. }
  126. if conf.Metro {
  127. ret = ret | (one << 2)
  128. }
  129. if conf.ParkSpace {
  130. ret = ret | (one << 3)
  131. }
  132. if conf.IndependentWc {
  133. ret = ret | (one << 4)
  134. }
  135. if conf.PrivateBalcony {
  136. ret = ret | (one << 5)
  137. }
  138. if conf.FirstRent {
  139. ret = ret | (one << 6)
  140. }
  141. return ret
  142. }
  143. ///
  144. // @Summary 租房列表
  145. // @Description 租房列表
  146. // @Tags 房屋租赁
  147. // @Accept json
  148. // @Produce json
  149. // @Param token header string true "token"
  150. // @Param province_code query string false "省份代码"
  151. // @Param city_code query string false "城市代码"
  152. // @Param area_code query string false "区域代码"
  153. // @Param street_code query string false "街道代码"
  154. // @Param room_count query int false "几室"
  155. // @Param hall_count query int false "几厅"
  156. // @Param wc_count query int false "几卫"
  157. // @Param rent_price_greater query string false "租金大于"
  158. // @Param rent_price_less query string false "租金小于"
  159. // @Param approve_status query int false "审核状态 0 不过滤 1 待审核 2 通过 3 未通过"
  160. // @Param page query int false " "
  161. // @Param page_size query int false " "
  162. // @Param base_conf query int false "从低bit到高bit分别表示床 天然气 暖气 宽带 冰箱 衣柜 沙发 空调 电视机 热水器 洗衣机"
  163. // @Param special_conf query int false "从低到高分别表示 智能门锁 wifi 近地铁 停车位 独卫 私人阳台 首次出租"
  164. // @Param garden_id query int false " 小区id"
  165. // @Param garden_name query string false " 小区名字"
  166. // @Param building_type query int false " 1塔楼 2 板楼 3 塔板结合 4 其他"
  167. // @Param building_year_greater query int false " 楼龄年份大于"
  168. // @Param building_year_less query int false " 楼龄小于"
  169. // @Param is_me query bool false "我发布的"
  170. // @Success 200 {object} v1.HouseRentListResponse
  171. // @Failure 500 {object} base.HTTPError
  172. // @Router /api/v1/rent/house [get]
  173. func (c *Controller) HouseRentList(ctx *gin.Context) {
  174. // 解析参数
  175. req := &param_v1.HouseRentListRequest{}
  176. parseParamTask := func() error {
  177. err := util.ShouldBind(ctx, &req.Header, nil, &req.HouseRentListQuery, nil)
  178. if err != nil {
  179. logger.Error("func",
  180. zap.String("call", "util.ShouldBind"),
  181. zap.String("error", err.Error()))
  182. return errors.ParamsError
  183. }
  184. return nil
  185. }
  186. // 业务处理
  187. handleServiceTask := func() error {
  188. tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  189. if err != nil {
  190. return err
  191. }
  192. gardenIds := []int64{}
  193. if req.GardenName != "" || req.BuildingYearLess > 0 || req.BuildingYearGreater > 0 || req.BuildingType > 0 {
  194. rpcReq := &v1.GardenIdsRequest{
  195. //BaseConf:
  196. //SpecialConf
  197. GardenName: req.GardenName,
  198. BuildingYearGreater: req.BuildingYearGreater,
  199. BuildingYearLess: req.BuildingYearLess,
  200. BuildingType: req.BuildingType,
  201. }
  202. rpcRsp, err := pb.System.GardenIds(ctx, rpcReq)
  203. if err != nil {
  204. s, _ := json.MarshalToString(req)
  205. logger.Error("func",
  206. zap.String("call", "pb.System.GardenIds"),
  207. zap.String("params", s),
  208. zap.String("error", err.Error()))
  209. return errors.ErrorTransForm(err)
  210. }
  211. if len(rpcRsp.GardenIds) == 0 {
  212. resp := param_v1.HouseRentListResponse{
  213. Data: v1.HouseRentListReply{
  214. Page: 1,
  215. Total: 0,
  216. List: make([]*v1.HouseRentItem, 0),
  217. },
  218. }
  219. ctx.JSON(http.StatusOK, resp)
  220. return nil
  221. }
  222. gardenIds = make([]int64, len(rpcRsp.GardenIds))
  223. for i, v := range rpcRsp.GardenIds {
  224. gardenIds[i] = v.GardenId
  225. }
  226. }
  227. // 响应数据
  228. resp := param_v1.HouseRentListResponse{}
  229. rpcReq := &v1.HouseRentListRequest{
  230. GardenId: req.GardenId,
  231. ProvinceCode: req.ProvinceCode,
  232. CityCode: req.CityCode,
  233. AreaCode: req.AreaCode,
  234. StreetCode: req.StreetCode,
  235. RoomCount: req.RoomCount,
  236. HallCount: req.HallCount,
  237. WcCount: req.WcCount,
  238. RentPriceGreater: req.RentPriceGreater,
  239. RentPriceLess: req.RentPriceLess,
  240. ApproveStatus: req.ApproveStatus,
  241. Page: req.Page,
  242. PageSize: req.PageSize,
  243. GardenIds: gardenIds,
  244. //BaseConf:
  245. //SpecialConf
  246. }
  247. if req.IsMe {
  248. rpcReq.HouseholdUid = tokenInfo.Uid
  249. }
  250. //baseConf := BaseConfToBool(req.BaseConf)
  251. //specialConf := SpecialConfToBool(req.SpecialConf)
  252. rpcReq.BaseConf = req.BaseConf
  253. rpcReq.SpecialConf = req.SpecialConf
  254. rpcRsp, err := pb.Household.HouseRentList(ctx, rpcReq)
  255. if err != nil {
  256. s, _ := json.MarshalToString(req)
  257. logger.Error("func",
  258. zap.String("call", "pb.Household.HouseRentList"),
  259. zap.String("params", s),
  260. zap.String("error", err.Error()))
  261. return errors.ErrorTransForm(err)
  262. }
  263. if rpcRsp.List == nil {
  264. rpcRsp.List = make([]*v1.HouseRentItem, 0)
  265. }
  266. resp.Data = *rpcRsp
  267. ctx.JSON(http.StatusOK, resp)
  268. return nil
  269. }
  270. // 执行任务
  271. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  272. }
  273. ///
  274. // @Summary 发布房源
  275. // @Description 发布房源
  276. // @Tags 房屋租赁
  277. // @Accept json
  278. // @Produce json
  279. // @Param token header string true "token"
  280. // @Param body body v1.HouseRentApplyBody true " "
  281. // @Success 200 {object} v1.HouseRentApplyResponse
  282. // @Failure 500 {object} base.HTTPError
  283. // @Router /api/v1/rent/house [post]
  284. func (c *Controller) HouseRentApply(ctx *gin.Context) {
  285. // 解析参数
  286. req := &param_v1.HouseRentApplyRequest{}
  287. parseParamTask := func() error {
  288. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.HouseRentApplyBody)
  289. if err != nil {
  290. logger.Error("func",
  291. zap.String("call", "util.ShouldBind"),
  292. zap.String("error", err.Error()))
  293. return errors.ParamsError
  294. }
  295. return nil
  296. }
  297. // 业务处理
  298. handleServiceTask := func() error {
  299. tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  300. if err != nil {
  301. return err
  302. }
  303. // 响应数据
  304. resp := param_v1.HouseRentApplyResponse{}
  305. rpcReq := &v1.HouseRentApplyRequest{
  306. GardenId: req.GardenId,
  307. HouseholdUid: tokenInfo.Uid,
  308. WcCount: req.WcCount,
  309. // 房屋号
  310. HouseId: req.HouseId,
  311. // 朝向
  312. Direction: req.Direction,
  313. // 1 精装 2 简装 3 清水
  314. Decorating: req.Decorating,
  315. // 联系人
  316. Contacter: req.Contacter,
  317. // 联系人电话
  318. ContactPhone: req.ContactPhone,
  319. // 1 月付 2 季付 3 半年付 4 年付
  320. PayTimeType: req.PayTimeType,
  321. // 1 整租 2 合租 3 转租
  322. RentType: req.RentType,
  323. // 1 全部 2 主卧 3 次卧
  324. RoomType: req.RoomType,
  325. // 房间面积
  326. RoomArea: req.RoomArea,
  327. // 月租
  328. RentPrice: req.RentPrice,
  329. // 押金
  330. Desposit: req.Desposit,
  331. // 可入住时间
  332. InTime: req.InTime,
  333. // 服务费
  334. ServicePrice: req.ServicePrice,
  335. // 中介费
  336. IntermediaryPrice: req.IntermediaryPrice,
  337. // 简介
  338. Desc: req.Desc,
  339. // 房屋图片
  340. HousePic: req.HousePic,
  341. // 房屋证件图片
  342. CertPic: req.CertPic,
  343. // 是否直接通过审核
  344. Approve: false,
  345. //BaseConf:
  346. //SpecialConf
  347. }
  348. //baseConf := BaseConfToBool(req.BaseConf)
  349. //specialConf := SpecialConfToBool(req.SpecialConf)
  350. rpcReq.BaseConf = req.BaseConf
  351. rpcReq.SpecialConf = req.SpecialConf
  352. rpcRsp, err := pb.Household.HouseRentApply(ctx, rpcReq)
  353. if err != nil {
  354. s, _ := json.MarshalToString(req)
  355. logger.Error("func",
  356. zap.String("call", "pb.Household.HouseRentApply"),
  357. zap.String("params", s),
  358. zap.String("error", err.Error()))
  359. return errors.ErrorTransForm(err)
  360. }
  361. resp.Data = *rpcRsp
  362. ctx.JSON(http.StatusOK, resp)
  363. return nil
  364. }
  365. // 执行任务
  366. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  367. }
  368. //
  369. // @Summary 修改信息
  370. // @Description 修改信息
  371. // @Tags 房屋租赁
  372. // @Accept json
  373. // @Produce json
  374. // @Param token header string true "token"
  375. // @Param body body v1.HouseRentUpdateBody true " "
  376. // @Success 200 {object} v1.HouseRentUpdateResponse
  377. // @Failure 500 {object} base.HTTPError
  378. // @Router /api/v1/rent/house [put]
  379. func (c *Controller) HouseRentUpdate(ctx *gin.Context) {
  380. // 解析参数
  381. req := &param_v1.HouseRentUpdateRequest{}
  382. parseParamTask := func() error {
  383. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.HouseRentUpdateBody)
  384. if err != nil {
  385. logger.Error("func",
  386. zap.String("call", "util.ShouldBind"),
  387. zap.String("error", err.Error()))
  388. return errors.ParamsError
  389. }
  390. return nil
  391. }
  392. // 业务处理
  393. handleServiceTask := func() error {
  394. //tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  395. //if err != nil {
  396. // return err
  397. //}
  398. // 响应数据
  399. resp := param_v1.HouseRentUpdateResponse{}
  400. rpcReq := &v1.HouseRentUpdateRequest{
  401. Id: req.Id,
  402. GardenId: req.GardenId,
  403. WcCount: req.WcCount,
  404. HouseId: req.HouseId,
  405. // 朝向
  406. Direction: req.Direction,
  407. // 1 精装 2 简装 3 清水
  408. Decorating: req.Decorating,
  409. // 联系人
  410. Contacter: req.Contacter,
  411. // 联系人电话
  412. ContactPhone: req.ContactPhone,
  413. // 1 月付 2 季付 3 半年付 4 年付
  414. PayTimeType: req.PayTimeType,
  415. // 1 整租 2 合租 3 转租
  416. RentType: req.RentType,
  417. // 1 全部 2 主卧 3 次卧
  418. RoomType: req.RoomType,
  419. // 房间面积
  420. RoomArea: req.RoomArea,
  421. // 月租
  422. RentPrice: req.RentPrice,
  423. // 押金
  424. Desposit: req.Desposit,
  425. // 可入住时间
  426. InTime: req.InTime,
  427. // 服务费
  428. ServicePrice: req.ServicePrice,
  429. // 中介费
  430. IntermediaryPrice: req.IntermediaryPrice,
  431. // 简介
  432. Desc: req.Desc,
  433. // 房屋图片
  434. HousePic: req.HousePic,
  435. // 房屋证件图片
  436. CertPic: req.CertPic,
  437. //BaseConf:
  438. //SpecialConf
  439. }
  440. //baseConf := BaseConfToBool(req.BaseConf)
  441. //specialConf := SpecialConfToBool(req.SpecialConf)
  442. rpcReq.BaseConf = req.BaseConf
  443. rpcReq.SpecialConf = req.SpecialConf
  444. _, err := pb.Household.HouseRentUpdate(ctx, rpcReq)
  445. if err != nil {
  446. s, _ := json.MarshalToString(req)
  447. logger.Error("func",
  448. zap.String("call", "pb.Household.HouseRentUpdate"),
  449. zap.String("params", s),
  450. zap.String("error", err.Error()))
  451. return errors.ErrorTransForm(err)
  452. }
  453. ctx.JSON(http.StatusOK, resp)
  454. return nil
  455. }
  456. // 执行任务
  457. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  458. }
  459. //
  460. // @Summary 下架
  461. // @Description 下架
  462. // @Tags 房屋租赁
  463. // @Accept json
  464. // @Produce json
  465. // @Param token header string true "token"
  466. // @Param body body v1.HouseRentDownBody true " "
  467. // @Success 200 {object} v1.HouseRentDownResponse
  468. // @Failure 500 {object} base.HTTPError
  469. // @Router /api/v1/rent/house/down [put]
  470. func (c *Controller) HouseRentDown(ctx *gin.Context) {
  471. // 解析参数
  472. req := &param_v1.HouseRentDownRequest{}
  473. parseParamTask := func() error {
  474. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.HouseRentDownBody)
  475. if err != nil {
  476. logger.Error("func",
  477. zap.String("call", "util.ShouldBind"),
  478. zap.String("error", err.Error()))
  479. return errors.ParamsError
  480. }
  481. return nil
  482. }
  483. // 业务处理
  484. handleServiceTask := func() error {
  485. //tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  486. //if err != nil {
  487. // return err
  488. //}
  489. // 响应数据
  490. resp := param_v1.HouseRentDownResponse{}
  491. rpcReq := &v1.HouseRentDownRequest{
  492. Id: req.Id,
  493. GardenId: req.GardenId,
  494. }
  495. _, err := pb.Household.HouseRentDown(ctx, rpcReq)
  496. if err != nil {
  497. s, _ := json.MarshalToString(req)
  498. logger.Error("func",
  499. zap.String("call", "pb.Household.HouseRentDown"),
  500. zap.String("params", s),
  501. zap.String("error", err.Error()))
  502. return errors.ErrorTransForm(err)
  503. }
  504. ctx.JSON(http.StatusOK, resp)
  505. return nil
  506. }
  507. // 执行任务
  508. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  509. }
  510. //
  511. // @Summary 房屋的经纪人列表
  512. // @Description 房屋的经纪人列表
  513. // @Tags 房屋租赁
  514. // @Accept json
  515. // @Produce json
  516. // @Param token header string true "token"
  517. // @Param rent_id query int true "租房信息id"
  518. // @Param garden_id query int true "小区id"
  519. // @Success 200 {object} v1.HouseRentManagerListResponse
  520. // @Failure 500 {object} base.HTTPError
  521. // @Router /api/v1/rent/house/manager [get]
  522. func (c *Controller) HouseRentManagerList(ctx *gin.Context) {
  523. // 解析参数
  524. req := &param_v1.HouseRentManagerListRequest{}
  525. parseParamTask := func() error {
  526. err := util.ShouldBind(ctx, &req.Header, nil, &req.HouseRentManagerListQuery, nil)
  527. if err != nil {
  528. logger.Error("func",
  529. zap.String("call", "util.ShouldBind"),
  530. zap.String("error", err.Error()))
  531. return errors.ParamsError
  532. }
  533. return nil
  534. }
  535. // 业务处理
  536. handleServiceTask := func() error {
  537. //tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  538. //if err != nil {
  539. // return err
  540. //}
  541. // 响应数据
  542. resp := param_v1.HouseRentManagerListResponse{}
  543. rpcReq := &v1.HouseRentManagerListRequest{
  544. GardenId: req.GardenId,
  545. RentId: req.RentId,
  546. }
  547. rpcRsp, err := pb.Garden.HouseRentManagerList(ctx, rpcReq)
  548. if err != nil {
  549. s, _ := json.MarshalToString(req)
  550. logger.Error("func",
  551. zap.String("call", "pb.Garden.HouseRentManagerList"),
  552. zap.String("params", s),
  553. zap.String("error", err.Error()))
  554. return errors.ErrorTransForm(err)
  555. }
  556. if rpcRsp.List == nil {
  557. rpcRsp.List = make([]*v1.HouseRentManagerItem, 0)
  558. }
  559. resp.Data = *rpcRsp
  560. ctx.JSON(http.StatusOK, resp)
  561. return nil
  562. }
  563. // 执行任务
  564. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  565. }
  566. //
  567. // @Summary 租房预约记录
  568. // @Description 租房预约记录
  569. // @Tags 房屋租赁
  570. // @Accept json
  571. // @Produce json
  572. // @Param token header string true "token"
  573. // @Param page query int false " "
  574. // @Param page_size query int false " "
  575. // @Success 200 {object} v1.HouseRentAppointmentListResponse
  576. // @Failure 500 {object} base.HTTPError
  577. // @Router /api/v1/rent/house/appointment [get]
  578. func (c *Controller) HouseRentAppointmentList(ctx *gin.Context) {
  579. // 解析参数
  580. req := &param_v1.HouseRentAppointmentListRequest{}
  581. parseParamTask := func() error {
  582. err := util.ShouldBind(ctx, &req.Header, nil, &req.HouseRentAppointmentListQuery, nil)
  583. if err != nil {
  584. logger.Error("func",
  585. zap.String("call", "util.ShouldBind"),
  586. zap.String("error", err.Error()))
  587. return errors.ParamsError
  588. }
  589. return nil
  590. }
  591. // 业务处理
  592. handleServiceTask := func() error {
  593. tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  594. if err != nil {
  595. return err
  596. }
  597. // 响应数据
  598. resp := param_v1.HouseRentAppointmentListResponse{}
  599. rpcReq := &v1.HouseRentAppointmentListRequest{
  600. Uid: tokenInfo.Uid,
  601. Page: req.Page,
  602. PageSize: req.PageSize,
  603. }
  604. rpcRsp, err := pb.Household.HouseRentAppointmentList(ctx, rpcReq)
  605. if err != nil {
  606. s, _ := json.MarshalToString(req)
  607. logger.Error("func",
  608. zap.String("call", "pb.Household.HouseRentAppointmentList"),
  609. zap.String("params", s),
  610. zap.String("error", err.Error()))
  611. return errors.ErrorTransForm(err)
  612. }
  613. if rpcRsp.List == nil {
  614. rpcRsp.List = make([]*v1.HouseRentAppointmentItem, 0)
  615. }
  616. resp.Data = *rpcRsp
  617. ctx.JSON(http.StatusOK, resp)
  618. return nil
  619. }
  620. // 执行任务
  621. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  622. }
  623. //
  624. // @Summary 删除租房预约记录
  625. // @Description 删除租房预约记录
  626. // @Tags 房屋租赁
  627. // @Accept json
  628. // @Produce json
  629. // @Param token header string true "token"
  630. // @Param id query int true "记录id"
  631. // @Success 200 {object} v1.HouseRentAppointmentDelResponse
  632. // @Failure 500 {object} base.HTTPError
  633. // @Router /api/v1/rent/house/appointment [delete]
  634. func (c *Controller) HouseRentAppointmentDel(ctx *gin.Context) {
  635. // 解析参数
  636. req := &param_v1.HouseRentAppointmentDelRequest{}
  637. parseParamTask := func() error {
  638. err := util.ShouldBind(ctx, &req.Header, nil, &req.HouseRentAppointmentDelQuery, nil)
  639. if err != nil {
  640. logger.Error("func",
  641. zap.String("call", "util.ShouldBind"),
  642. zap.String("error", err.Error()))
  643. return errors.ParamsError
  644. }
  645. return nil
  646. }
  647. // 业务处理
  648. handleServiceTask := func() error {
  649. //tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  650. //if err != nil {
  651. // return err
  652. //}
  653. // 响应数据
  654. resp := param_v1.HouseRentAppointmentDelResponse{}
  655. rpcReq := &v1.HouseRentAppointmentDelRequest{
  656. Id: req.Id,
  657. }
  658. _, err := pb.Household.HouseRentAppointmentDel(ctx, rpcReq)
  659. if err != nil {
  660. s, _ := json.MarshalToString(req)
  661. logger.Error("func",
  662. zap.String("call", "pb.Household.HouseRentAppointmentDel"),
  663. zap.String("params", s),
  664. zap.String("error", err.Error()))
  665. return errors.ErrorTransForm(err)
  666. }
  667. ctx.JSON(http.StatusOK, resp)
  668. return nil
  669. }
  670. // 执行任务
  671. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  672. }
  673. //
  674. // @Summary 租房预约看房
  675. // @Description 租房预约看房
  676. // @Tags 房屋租赁
  677. // @Accept json
  678. // @Produce json
  679. // @Param token header string true "token"
  680. // @Param body body v1.HouseRentAppointmentAddBody true " "
  681. // @Success 200 {object} v1.HouseRentAppointmentListResponse
  682. // @Failure 500 {object} base.HTTPError
  683. // @Router /api/v1/rent/house/appointment [post]
  684. func (c *Controller) HouseRentAppointmentAdd(ctx *gin.Context) {
  685. // 解析参数
  686. req := &param_v1.HouseRentAppointmentAddRequest{}
  687. parseParamTask := func() error {
  688. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.HouseRentAppointmentAddBody)
  689. if err != nil {
  690. logger.Error("func",
  691. zap.String("call", "util.ShouldBind"),
  692. zap.String("error", err.Error()))
  693. return errors.ParamsError
  694. }
  695. return nil
  696. }
  697. // 业务处理
  698. handleServiceTask := func() error {
  699. tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  700. if err != nil {
  701. return err
  702. }
  703. // 响应数据
  704. resp := param_v1.HouseRentAppointmentAddResponse{}
  705. rpcReq := &v1.HouseRentAppointmentAddRequest{
  706. GardenId: req.GardenId,
  707. RentId: req.RentId,
  708. Uid: tokenInfo.Uid,
  709. Name: req.Name,
  710. Phone: req.Phone,
  711. AppointmentTime: req.AppointmentTime,
  712. Gender: req.Gender,
  713. }
  714. _, err = pb.Household.HouseRentAppointmentAdd(ctx, rpcReq)
  715. if err != nil {
  716. s, _ := json.MarshalToString(req)
  717. logger.Error("func",
  718. zap.String("call", "pb.Household.HouseRentAppointmentAdd"),
  719. zap.String("params", s),
  720. zap.String("error", err.Error()))
  721. return errors.ErrorTransForm(err)
  722. }
  723. ctx.JSON(http.StatusOK, resp)
  724. return nil
  725. }
  726. // 执行任务
  727. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  728. }
  729. ///
  730. // @Summary 均价,已租已售数
  731. // @Description 均价,已租已售数
  732. // @Tags 房屋租赁
  733. // @Accept json
  734. // @Produce json
  735. // @Param token header string true "token"
  736. // @Param garden_id query int true " 小区id"
  737. // @Param is_me query bool false "我发布的"
  738. // @Success 200 {object} v1.GardenHouseRentInfoResponse
  739. // @Failure 500 {object} base.HTTPError
  740. // @Router /api/v1/rent/garden_info [get]
  741. func (c *Controller) GardenHouseRentInfo(ctx *gin.Context) {
  742. // 解析参数
  743. req := &param_v1.GardenHouseRentInfoRequest{}
  744. parseParamTask := func() error {
  745. err := util.ShouldBind(ctx, &req.Header, nil, &req.GardenHouseRentInfoQuery, nil)
  746. if err != nil {
  747. logger.Error("func",
  748. zap.String("call", "util.ShouldBind"),
  749. zap.String("error", err.Error()))
  750. return errors.ParamsError
  751. }
  752. return nil
  753. }
  754. // 业务处理
  755. handleServiceTask := func() error {
  756. //tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  757. //if err != nil {
  758. // return err
  759. //}
  760. // 响应数据
  761. resp := param_v1.GardenHouseRentInfoResponse{}
  762. rpcReq := &v1.GardenHouseRentInfoRequest{
  763. GardenId: req.GardenId,
  764. }
  765. rpcRsp, err := pb.Garden.GardenHouseRentInfo(ctx, rpcReq)
  766. if err != nil {
  767. s, _ := json.MarshalToString(req)
  768. logger.Error("func",
  769. zap.String("call", "pb.Garden.GardenHouseRentInfo"),
  770. zap.String("params", s),
  771. zap.String("error", err.Error()))
  772. return errors.ErrorTransForm(err)
  773. }
  774. mReq := &v1.GardenInfosRequest{
  775. Ids: []int64{req.GardenId},
  776. }
  777. mRsp, err := pb.System.GardenInfos(ctx, mReq)
  778. if err != nil {
  779. s, _ := json.MarshalToString(req)
  780. logger.Error("func",
  781. zap.String("call", "Garden.GardenInfos"),
  782. zap.String("params", s),
  783. zap.String("error", err.Error()))
  784. return errors.ErrorTransForm(err)
  785. }
  786. if len(mRsp.List) > 0 {
  787. rpcRsp.GardenPics = mRsp.List[0].GardenPics
  788. rpcRsp.BuildingStart = mRsp.List[0].BuildingStart
  789. rpcRsp.BuildingEnd = mRsp.List[0].BuildingEnd
  790. rpcRsp.PropertyFeeStart = mRsp.List[0].PropertyFeeStart
  791. rpcRsp.PropertyFeeEnd = mRsp.List[0].PropertyFeeEnd
  792. rpcRsp.GasFeeStart = mRsp.List[0].GasFeeStart
  793. rpcRsp.GasFeeEnd = mRsp.List[0].GasFeeEnd
  794. rpcRsp.BuildingType = mRsp.List[0].BuildingType
  795. rpcRsp.BuildingArea = mRsp.List[0].BuildingArea
  796. rpcRsp.BuildingCompany = mRsp.List[0].BuildingCompany
  797. rpcRsp.GreenPercent = mRsp.List[0].GreenPercent
  798. rpcRsp.AreaPercent = mRsp.List[0].AreaPercent
  799. rpcRsp.WaterType = mRsp.List[0].WaterType
  800. rpcRsp.ElectricType = mRsp.List[0].ElectricType
  801. rpcRsp.HouseTotal = mRsp.List[0].HouseTotal
  802. rpcRsp.SpaceInfo = mRsp.List[0].SpaceInfo
  803. rpcRsp.SpaceTotal = mRsp.List[0].SpaceTotal
  804. }
  805. if rpcRsp.WaterType == nil {
  806. rpcRsp.WaterType = []int32{}
  807. }
  808. if rpcRsp.ElectricType == nil {
  809. rpcRsp.ElectricType = []int32{}
  810. }
  811. if rpcRsp.GardenPics == nil {
  812. rpcRsp.GardenPics = []string{}
  813. }
  814. resp.Data = *rpcRsp
  815. ctx.JSON(http.StatusOK, resp)
  816. return nil
  817. }
  818. // 执行任务
  819. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  820. }