charge.go 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962
  1. package v1
  2. import (
  3. "fmt"
  4. "git.getensh.com/common/gopkgs/logger"
  5. "git.getensh.com/common/gopkgs/tasker/httptasker"
  6. "git.getensh.com/common/gopkgs/util"
  7. "github.com/gin-gonic/gin"
  8. "go.uber.org/zap"
  9. "google.golang.org/grpc/status"
  10. "net/http"
  11. "property-household-gateway/errors"
  12. param_v1 "property-household-gateway/param/v1"
  13. "property-household-gateway/pb"
  14. "property-household-gateway/pb/v1"
  15. "property-household-gateway/utils"
  16. "time"
  17. )
  18. const (
  19. ObjTypeHouse = 1
  20. ObjTypeSpace = 2
  21. ObjTypeVehicle = 3
  22. )
  23. const (
  24. ChargeTypeProperty = 1
  25. ChargeTypeWater = 2
  26. ChargeTypeElectricity = 3
  27. ChargeTypeGas = 4
  28. ChargeTypeSpace = 5
  29. ChargeTypeVehicle = 6
  30. ChargeTypeOther = 99
  31. )
  32. //
  33. // @Summary 支付测试
  34. // @Description 支付测试
  35. // @Tags 支付测试
  36. // @Accept json
  37. // @Produce json
  38. // @Param token header string true "token"
  39. // @Param body body v1.ChargeWxPayTestBody true " "
  40. // @Success 200 {object} v1.ChargeWxPayTestResponse
  41. // @Failure 500 {object} base.HTTPError
  42. // @Router /api/v1/charge/pay_test [put]
  43. func (c *Controller) ChargeWxPayTest(ctx *gin.Context) {
  44. // 解析参数
  45. req := &param_v1.ChargeWxPayTestRequest{}
  46. parseParamTask := func() error {
  47. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.ChargeWxPayTestBody)
  48. if err != nil {
  49. logger.Error("func",
  50. zap.String("call", "util.ShouldBind"),
  51. zap.String("error", err.Error()))
  52. return errors.ParamsError
  53. }
  54. return nil
  55. }
  56. // 业务处理
  57. handleServiceTask := func() error {
  58. tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  59. if err != nil {
  60. return err
  61. }
  62. // 响应数据
  63. resp := param_v1.ChargeWxPayTestResponse{}
  64. rpcReq := &v1.WxAppletPrepayRequest{
  65. InputIp: ctx.ClientIP(),
  66. //HouseholdUid:tokenInfo.Uid,
  67. OpenId: tokenInfo.OpenId,
  68. Order: fmt.Sprintf("paytests%d", time.Now().Unix()),
  69. Product: "pay tests",
  70. Amount: req.PayAmount,
  71. MchId: "1628975670",
  72. }
  73. rpcRsp, err := pb.Thirdparty.WxAppletPrepay(ctx, rpcReq)
  74. if err != nil {
  75. s, _ := json.MarshalToString(req)
  76. logger.Error("func",
  77. zap.String("call", "pb.Thirdparty.WxAppletPrepay"),
  78. zap.String("params", s),
  79. zap.String("error", err.Error()))
  80. return errors.ErrorTransForm(err)
  81. }
  82. resp.Data = *rpcRsp
  83. ctx.JSON(http.StatusOK, resp)
  84. return nil
  85. }
  86. // 执行任务
  87. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  88. }
  89. //
  90. // @Summary 欠费线上缴费
  91. // @Description 欠费线上缴费
  92. // @Tags 生活缴费
  93. // @Accept json
  94. // @Produce json
  95. // @Param token header string true "token"
  96. // @Param body body v1.ChargeBillPayByHouseholdBody true " "
  97. // @Success 200 {object} v1.ChargeBillPayByHouseholdResponse
  98. // @Failure 500 {object} base.HTTPError
  99. // @Router /api/v1/charge/pay [put]
  100. func (c *Controller) ChargeBillPayByHousehold(ctx *gin.Context) {
  101. // 解析参数
  102. req := &param_v1.ChargeBillPayByHouseholdRequest{}
  103. parseParamTask := func() error {
  104. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.ChargeBillPayByHouseholdBody)
  105. if err != nil {
  106. logger.Error("func",
  107. zap.String("call", "util.ShouldBind"),
  108. zap.String("error", err.Error()))
  109. return errors.ParamsError
  110. }
  111. return nil
  112. }
  113. // 业务处理
  114. handleServiceTask := func() error {
  115. tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  116. if err != nil {
  117. return err
  118. }
  119. // 响应数据
  120. resp := param_v1.ChargeBillPayByHouseholdResponse{}
  121. rpcReq := &v1.ChargeBillPayByHouseholdRequest{
  122. GardenId: req.GardenId,
  123. BindIds: req.BindIds,
  124. ShouldPayAmount: req.ShouldPayAmount,
  125. PayAmount: req.PayAmount,
  126. PayType: 6,
  127. Comment: req.Comment,
  128. InputIp: ctx.ClientIP(),
  129. HouseholdUid: tokenInfo.Uid,
  130. OpenId: tokenInfo.OpenId,
  131. BillIds: req.BillIds,
  132. }
  133. rpcRsp, err := pb.Garden.ChargeBillPayByHousehold(ctx, rpcReq)
  134. if err != nil {
  135. s, _ := json.MarshalToString(req)
  136. logger.Error("func",
  137. zap.String("call", "pb.Garden.ChargeBillPayByHousehold"),
  138. zap.String("params", s),
  139. zap.String("error", err.Error()))
  140. return errors.ErrorTransForm(err)
  141. }
  142. resp.Data = *rpcRsp
  143. ctx.JSON(http.StatusOK, resp)
  144. return nil
  145. }
  146. // 执行任务
  147. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  148. }
  149. //
  150. // @Summary 待缴费的费项列表
  151. // @Description 待缴费的费项列表
  152. // @Tags 生活缴费
  153. // @Accept json
  154. // @Produce json
  155. // @Param token header string true "token"
  156. // @Param garden_id query int true "小区id"
  157. // @Param house_id query int true "房屋id"
  158. // @Param page query int false " "
  159. // @Param page_size query int false " "
  160. // @Success 200 {object} v1.ChargeUnpayListResponse
  161. // @Failure 500 {object} base.HTTPError
  162. // @Router /api/v1/charge/unpay_list [get]
  163. func (c *Controller) ChargeUnpayList(ctx *gin.Context) {
  164. // 解析参数
  165. req := &param_v1.ChargeUnpayListRequest{}
  166. parseParamTask := func() error {
  167. err := util.ShouldBind(ctx, &req.Header, nil, &req.ChargeUnpayListQuery, nil)
  168. if err != nil {
  169. logger.Error("func",
  170. zap.String("call", "util.ShouldBind"),
  171. zap.String("error", err.Error()))
  172. return errors.ParamsError
  173. }
  174. return nil
  175. }
  176. // 业务处理
  177. handleServiceTask := func() error {
  178. //tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  179. //if err != nil {
  180. // return err
  181. //}
  182. // 响应数据
  183. resp := param_v1.ChargeUnpayListResponse{}
  184. rpcReq := &v1.ChargeUnpayListRequest{
  185. GardenId: req.GardenId,
  186. PageSize: req.PageSize,
  187. Page: req.Page,
  188. HouseId: req.HouseId,
  189. Status: 1,
  190. }
  191. rpcRsp, err := pb.Garden.ChargeUnpayList(ctx, rpcReq)
  192. if err != nil {
  193. s, _ := json.MarshalToString(req)
  194. logger.Error("func",
  195. zap.String("call", "pb.Garden.ChargeUnpayList"),
  196. zap.String("params", s),
  197. zap.String("error", err.Error()))
  198. return errors.ErrorTransForm(err)
  199. }
  200. if rpcRsp.List == nil {
  201. rpcRsp.List = make([]*v1.ChargeUnpayItem, 0)
  202. }
  203. resp.Data = *rpcRsp
  204. ctx.JSON(http.StatusOK, resp)
  205. return nil
  206. }
  207. // 执行任务
  208. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  209. }
  210. //
  211. // @Summary 已缴费的账单列表
  212. // @Description 已缴费的账单列表
  213. // @Tags 生活缴费
  214. // @Accept json
  215. // @Produce json
  216. // @Param token header string true "token"
  217. // @Param garden_id query int true "小区id"
  218. // @Param house_id query int true "房屋id"
  219. // @Param pay_time query int false "支付时间"
  220. // @Param page query int false " "
  221. // @Param page_size query int false " "
  222. // @Success 200 {object} v1.ChargeUnpayListResponse
  223. // @Failure 500 {object} base.HTTPError
  224. // @Router /api/v1/charge/payed_bill_list [get]
  225. func (c *Controller) ChargePayedBillList(ctx *gin.Context) {
  226. // 解析参数
  227. req := &param_v1.ChargePayedBillListRequest{}
  228. parseParamTask := func() error {
  229. err := util.ShouldBind(ctx, &req.Header, nil, &req.ChargePayedBillListQuery, nil)
  230. if err != nil {
  231. logger.Error("func",
  232. zap.String("call", "util.ShouldBind"),
  233. zap.String("error", err.Error()))
  234. return errors.ParamsError
  235. }
  236. return nil
  237. }
  238. // 业务处理
  239. handleServiceTask := func() error {
  240. //tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  241. //if err != nil {
  242. // return err
  243. //}
  244. // 响应数据
  245. resp := param_v1.ChargePayedBillListResponse{}
  246. rpcReq := &v1.ChargePayedBillListRequest{
  247. GardenId: req.GardenId,
  248. PageSize: req.PageSize,
  249. Page: req.Page,
  250. HouseId: req.HouseId,
  251. PayTime: req.PayTime,
  252. }
  253. rpcRsp, err := pb.Garden.ChargePayedBillList(ctx, rpcReq)
  254. if err != nil {
  255. s, _ := json.MarshalToString(req)
  256. logger.Error("func",
  257. zap.String("call", "pb.Garden.ChargePayedBillList"),
  258. zap.String("params", s),
  259. zap.String("error", err.Error()))
  260. return errors.ErrorTransForm(err)
  261. }
  262. if rpcRsp.List == nil {
  263. rpcRsp.List = make([]*v1.ChargePayedBillItem, 0)
  264. }
  265. resp.Data = *rpcRsp
  266. ctx.JSON(http.StatusOK, resp)
  267. return nil
  268. }
  269. // 执行任务
  270. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  271. }
  272. //
  273. // @Summary 待缴费某个费项的账单列表
  274. // @Description 待缴费某个费项的账单列表
  275. // @Tags 生活缴费
  276. // @Accept json
  277. // @Produce json
  278. // @Param token header string true "token"
  279. // @Param garden_id query int true "小区id"
  280. // @Param bind_id query int true "绑定关系id"
  281. // @Param page query int false " "
  282. // @Param page_size query int false " "
  283. // @Success 200 {object} v1.ChargeBillListResponse
  284. // @Failure 500 {object} base.HTTPError
  285. // @Router /api/v1/charge/bill_list [get]
  286. func (c *Controller) ChargeBillList(ctx *gin.Context) {
  287. // 解析参数
  288. req := &param_v1.ChargeBillListRequest{}
  289. parseParamTask := func() error {
  290. err := util.ShouldBind(ctx, &req.Header, nil, &req.ChargeBillListQuery, nil)
  291. if err != nil {
  292. logger.Error("func",
  293. zap.String("call", "util.ShouldBind"),
  294. zap.String("error", err.Error()))
  295. return errors.ParamsError
  296. }
  297. return nil
  298. }
  299. // 业务处理
  300. handleServiceTask := func() error {
  301. //tokenInfo, err := utils.GetSubjectValue(ctx)
  302. //if err != nil {
  303. // return err
  304. //}
  305. // 响应数据
  306. resp := param_v1.ChargeBillListResponse{}
  307. rpcReq := &v1.ChargeBillListRequest{
  308. GardenId: req.GardenId,
  309. PageSize: req.PageSize,
  310. Page: req.Page,
  311. BindId: req.BindId,
  312. Status: 1,
  313. }
  314. rpcRsp, err := pb.Garden.ChargeBillList(ctx, rpcReq)
  315. if err != nil {
  316. s, _ := json.MarshalToString(req)
  317. logger.Error("func",
  318. zap.String("call", "pb.Garden.ChargeBillList"),
  319. zap.String("params", s),
  320. zap.String("error", err.Error()))
  321. return errors.ErrorTransForm(err)
  322. }
  323. if rpcRsp.List == nil {
  324. rpcRsp.List = make([]*v1.ChargeBillItem, 0)
  325. }
  326. resp.Data = *rpcRsp
  327. ctx.JSON(http.StatusOK, resp)
  328. return nil
  329. }
  330. // 执行任务
  331. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  332. }
  333. // @Summary 未支付订单列表
  334. // @Description 未支付订单列表
  335. // @Tags 生活缴费
  336. // @Accept json
  337. // @Produce json
  338. // @Param token header string true "token"
  339. // @Param page query int false " "
  340. // @Param page_size query int false " "
  341. // @Param garden_id query int true "小区id"
  342. // @Success 200 {object} v1.ChargeOrderListResponse
  343. // @Failure 500 {object} base.HTTPError
  344. // @Router /api/v1/charge/order/list [get]
  345. func (c *Controller) ChargeOrderList(ctx *gin.Context) {
  346. // 解析参数
  347. req := &param_v1.ChargeOrderListRequest{}
  348. parseParamTask := func() error {
  349. err := util.ShouldBind(ctx, &req.Header, nil, &req.ChargeOrderListQuery, nil)
  350. if err != nil {
  351. logger.Error("func",
  352. zap.String("call", "util.ShouldBind"),
  353. zap.String("error", err.Error()))
  354. return errors.ParamsError
  355. }
  356. return nil
  357. }
  358. // 业务处理
  359. handleServiceTask := func() error {
  360. tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  361. if err != nil {
  362. return err
  363. }
  364. // 响应数据
  365. resp := param_v1.ChargeOrderListResponse{}
  366. rpcReq := &v1.ChargeOrderListRequest{
  367. GardenId: req.GardenId,
  368. PageSize: req.PageSize,
  369. Page: req.Page,
  370. PayStatus: 1,
  371. Uid: tokenInfo.Uid,
  372. }
  373. if tokenInfo.Uid == 0 {
  374. return errors.TokenFailedError
  375. }
  376. rpcRsp, err := pb.Garden.ChargeOrderList(ctx, rpcReq)
  377. if err != nil {
  378. s, _ := json.MarshalToString(req)
  379. logger.Error("func",
  380. zap.String("call", "pb.Garden.ChargeOrderList"),
  381. zap.String("params", s),
  382. zap.String("error", err.Error()))
  383. return errors.ErrorTransForm(err)
  384. }
  385. if rpcRsp.List == nil {
  386. rpcRsp.List = make([]*v1.ChargeOrderItem, 0)
  387. }
  388. resp.Data = *rpcRsp
  389. ctx.JSON(http.StatusOK, resp)
  390. return nil
  391. }
  392. // 执行任务
  393. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  394. }
  395. // @Summary 未支付订单的订单详情
  396. // @Description 未支付订单的订单详情
  397. // @Tags 生活缴费
  398. // @Accept json
  399. // @Produce json
  400. // @Param token header string true "token"
  401. // @Param garden_id query int true "小区id"
  402. // @Param order_id query string true "订单详情"
  403. // @Success 200 {object} v1.ChargeOrderInfoResponse
  404. // @Failure 500 {object} base.HTTPError
  405. // @Router /api/v1/charge/order/info [get]
  406. func (c *Controller) ChargeOrderInfo(ctx *gin.Context) {
  407. // 解析参数
  408. req := &param_v1.ChargeOrderInfoRequest{}
  409. parseParamTask := func() error {
  410. err := util.ShouldBind(ctx, &req.Header, nil, &req.ChargeOrderInfoQuery, nil)
  411. if err != nil {
  412. logger.Error("func",
  413. zap.String("call", "util.ShouldBind"),
  414. zap.String("error", err.Error()))
  415. return errors.ParamsError
  416. }
  417. return nil
  418. }
  419. // 业务处理
  420. handleServiceTask := func() error {
  421. // 响应数据
  422. resp := param_v1.ChargeOrderInfoResponse{}
  423. rpcReq := &v1.ChargeOrderInfoRequest{
  424. GardenId: req.GardenId,
  425. OrderId: req.OrderId,
  426. }
  427. rpcRsp, err := pb.Garden.ChargeOrderInfo(ctx, rpcReq)
  428. if err != nil {
  429. s, _ := json.MarshalToString(req)
  430. logger.Error("func",
  431. zap.String("call", "pb.Garden.ChargeOrderInfo"),
  432. zap.String("params", s),
  433. zap.String("error", err.Error()))
  434. return errors.ErrorTransForm(err)
  435. }
  436. if rpcRsp.List == nil {
  437. rpcRsp.List = make([]*v1.ChargeOrderBillItem, 0)
  438. }
  439. resp.Data = *rpcRsp
  440. ctx.JSON(http.StatusOK, resp)
  441. return nil
  442. }
  443. // 执行任务
  444. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  445. }
  446. // @Summary 预缴物业费前获取月数和赠送信息
  447. // @Description 预缴物业费前获取月数和赠送信息
  448. // @Tags 预缴
  449. // @Accept json
  450. // @Produce json
  451. // @Param token header string true "token"
  452. // @Param garden_id query int true "小区id"
  453. // @Param house_id query int true "房屋id"
  454. // @Success 200 {object} v1.ChargePropertyMonthInfoResponse
  455. // @Failure 500 {object} base.HTTPError
  456. // @Router /api/v1/charge/months/property [get]
  457. func (c *Controller) ChargePropertyMonthInfo(ctx *gin.Context) {
  458. // 解析参数
  459. req := &param_v1.ChargePropertyMonthInfoRequest{}
  460. parseParamTask := func() error {
  461. err := util.ShouldBind(ctx, &req.Header, nil, &req.ChargePropertyMonthInfoQuery, nil)
  462. if err != nil {
  463. logger.Error("func",
  464. zap.String("call", "util.ShouldBind"),
  465. zap.String("error", err.Error()))
  466. return errors.ParamsError
  467. }
  468. return nil
  469. }
  470. // 业务处理
  471. handleServiceTask := func() error {
  472. //tokenInfo, err := utils.GetSubjectValue(ctx)
  473. //if err != nil {
  474. // return err
  475. //}
  476. // 响应数据
  477. resp := param_v1.ChargePropertyMonthInfoResponse{}
  478. rpcReq := &v1.ChargeMonthInfoRequest{
  479. GardenId: req.GardenId,
  480. ObjId: req.HouseId,
  481. ObjType: ObjTypeHouse,
  482. ChargeType: ChargeTypeProperty,
  483. }
  484. rpcRsp, err := pb.Garden.ChargeMonthInfo(ctx, rpcReq)
  485. if err != nil {
  486. s, _ := json.MarshalToString(req)
  487. logger.Error("func",
  488. zap.String("call", "pb.Garden.ChargeMonthInfo"),
  489. zap.String("params", s),
  490. zap.String("error", err.Error()))
  491. return errors.ErrorTransForm(err)
  492. }
  493. resp.Data = *rpcRsp
  494. ctx.JSON(http.StatusOK, resp)
  495. return nil
  496. }
  497. // 执行任务
  498. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  499. }
  500. // @Summary 预缴车位管理费前获取月数和赠送信息
  501. // @Description 预缴车位管理前获取月数和赠送信息
  502. // @Tags 预缴
  503. // @Accept json
  504. // @Produce json
  505. // @Param token header string true "token"
  506. // @Param garden_id query int true "小区id"
  507. // @Param space_id query int true "车位id"
  508. // @Success 200 {object} v1.ChargeSpaceMonthInfoResponse
  509. // @Failure 500 {object} base.HTTPError
  510. // @Router /api/v1/charge/months/space [get]
  511. func (c *Controller) ChargeSpaceMonthInfo(ctx *gin.Context) {
  512. // 解析参数
  513. req := &param_v1.ChargeSpaceMonthInfoRequest{}
  514. parseParamTask := func() error {
  515. err := util.ShouldBind(ctx, &req.Header, nil, &req.ChargeSpaceMonthInfoQuery, nil)
  516. if err != nil {
  517. logger.Error("func",
  518. zap.String("call", "util.ShouldBind"),
  519. zap.String("error", err.Error()))
  520. return errors.ParamsError
  521. }
  522. return nil
  523. }
  524. // 业务处理
  525. handleServiceTask := func() error {
  526. //tokenInfo, err := utils.GetSubjectValue(ctx)
  527. //if err != nil {
  528. // return err
  529. //}
  530. // 响应数据
  531. resp := param_v1.ChargeSpaceMonthInfoResponse{}
  532. rpcReq := &v1.ChargeMonthInfoRequest{
  533. GardenId: req.GardenId,
  534. ObjId: req.SpaceId,
  535. ObjType: ObjTypeSpace,
  536. ChargeType: ChargeTypeSpace,
  537. }
  538. rpcRsp, err := pb.Garden.ChargeMonthInfo(ctx, rpcReq)
  539. if err != nil {
  540. s, _ := json.MarshalToString(req)
  541. logger.Error("func",
  542. zap.String("call", "pb.Garden.ChargeMonthInfo"),
  543. zap.String("params", s),
  544. zap.String("error", err.Error()))
  545. return errors.ErrorTransForm(err)
  546. }
  547. resp.Data = *rpcRsp
  548. ctx.JSON(http.StatusOK, resp)
  549. return nil
  550. }
  551. // 执行任务
  552. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  553. }
  554. // @Summary 预缴月租停车费前获取月数和赠送信息
  555. // @Description 预缴月租停车费前获取月数和赠送信息
  556. // @Tags 预缴
  557. // @Accept json
  558. // @Produce json
  559. // @Param token header string true "token"
  560. // @Param garden_id query int true "小区id"
  561. // @Param vehicle_id query int true "车辆id"
  562. // @Success 200 {object} v1.ChargeVehicleMonthInfoResponse
  563. // @Failure 500 {object} base.HTTPError
  564. // @Router /api/v1/charge/months/vehicle [get]
  565. func (c *Controller) ChargeVehicleMonthInfo(ctx *gin.Context) {
  566. // 解析参数
  567. req := &param_v1.ChargeVehicleMonthInfoRequest{}
  568. parseParamTask := func() error {
  569. err := util.ShouldBind(ctx, &req.Header, nil, &req.ChargeVehicleMonthInfoQuery, nil)
  570. if err != nil {
  571. logger.Error("func",
  572. zap.String("call", "util.ShouldBind"),
  573. zap.String("error", err.Error()))
  574. return errors.ParamsError
  575. }
  576. return nil
  577. }
  578. // 业务处理
  579. handleServiceTask := func() error {
  580. //tokenInfo, err := utils.GetSubjectValue(ctx)
  581. //if err != nil {
  582. // return err
  583. //}
  584. // 响应数据
  585. resp := param_v1.ChargeVehicleMonthInfoResponse{}
  586. rpcReq := &v1.ChargeMonthInfoRequest{
  587. GardenId: req.GardenId,
  588. ObjId: req.VehicleId,
  589. ObjType: ObjTypeVehicle,
  590. ChargeType: ChargeTypeVehicle,
  591. }
  592. rpcRsp, err := pb.Garden.ChargeMonthInfo(ctx, rpcReq)
  593. if err != nil {
  594. s, _ := json.MarshalToString(req)
  595. logger.Error("func",
  596. zap.String("call", "pb.Garden.ChargeMonthInfo"),
  597. zap.String("params", s),
  598. zap.String("error", err.Error()))
  599. return errors.ErrorTransForm(err)
  600. }
  601. resp.Data = *rpcRsp
  602. ctx.JSON(http.StatusOK, resp)
  603. return nil
  604. }
  605. // 执行任务
  606. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  607. }
  608. // @Summary 预缴物业费或车位费前获取对应的金额信息
  609. // @Description 预缴物业费或车位费前获取对应的金额信息
  610. // @Tags 预缴
  611. // @Accept json
  612. // @Produce json
  613. // @Param token header string true "token"
  614. // @Param garden_id query int true "小区id"
  615. // @Param bind_id query int true "关系id"
  616. // @Param months query int true "缴费月数"
  617. // @Success 200 {object} v1.ChargePrePayInfoResponse
  618. // @Failure 500 {object} base.HTTPError
  619. // @Router /api/v1/charge/pre_pay_info [get]
  620. func (c *Controller) ChargePrePayInfo(ctx *gin.Context) {
  621. // 解析参数
  622. req := &param_v1.ChargePrePayInfoRequest{}
  623. parseParamTask := func() error {
  624. err := util.ShouldBind(ctx, &req.Header, nil, &req.ChargePrePayInfoQuery, nil)
  625. if err != nil {
  626. logger.Error("func",
  627. zap.String("call", "util.ShouldBind"),
  628. zap.String("error", err.Error()))
  629. return errors.ParamsError
  630. }
  631. return nil
  632. }
  633. // 业务处理
  634. handleServiceTask := func() error {
  635. //tokenInfo, err := utils.GetSubjectValue(ctx)
  636. //if err != nil {
  637. // return err
  638. //}
  639. // 响应数据
  640. resp := param_v1.ChargePrePayInfoResponse{}
  641. rpcReq := &v1.ChargePrePayInfoRequest{
  642. GardenId: req.GardenId,
  643. BindId: req.BindId,
  644. Months: req.Months,
  645. }
  646. if req.BindId == 0 {
  647. return status.Error(10003, "没有绑定费用")
  648. }
  649. rpcRsp, err := pb.Garden.ChargePrePayInfo(ctx, rpcReq)
  650. if err != nil {
  651. s, _ := json.MarshalToString(req)
  652. logger.Error("func",
  653. zap.String("call", "pb.Garden.ChargePrePayInfo"),
  654. zap.String("params", s),
  655. zap.String("error", err.Error()))
  656. return errors.ErrorTransForm(err)
  657. }
  658. resp.Data = *rpcRsp
  659. ctx.JSON(http.StatusOK, resp)
  660. return nil
  661. }
  662. // 执行任务
  663. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  664. }
  665. //
  666. // @Summary 线上预缴物业费、停车费
  667. // @Description 线上预缴物业费、停车费
  668. // @Tags 预缴
  669. // @Accept json
  670. // @Produce json
  671. // @Param token header string true "token"
  672. // @Param body body v1.ChargePrePayByHouseholdBody true " "
  673. // @Success 200 {object} v1.ChargePrePayByHouseholdResponse
  674. // @Failure 500 {object} base.HTTPError
  675. // @Router /api/v1/charge/pre_pay [put]
  676. func (c *Controller) ChargePrePayByHousehold(ctx *gin.Context) {
  677. // 解析参数
  678. req := &param_v1.ChargePrePayByHouseholdRequest{}
  679. parseParamTask := func() error {
  680. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.ChargePrePayByHouseholdBody)
  681. if err != nil {
  682. logger.Error("func",
  683. zap.String("call", "util.ShouldBind"),
  684. zap.String("error", err.Error()))
  685. return errors.ParamsError
  686. }
  687. return nil
  688. }
  689. // 业务处理
  690. handleServiceTask := func() error {
  691. tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  692. if err != nil {
  693. return err
  694. }
  695. // 响应数据
  696. resp := param_v1.ChargePrePayByHouseholdResponse{}
  697. rpcReq := &v1.ChargePrePayByHouseholdRequest{
  698. GardenId: req.GardenId,
  699. BindId: req.BindId,
  700. ShouldPayAmount: req.ShouldPayAmount,
  701. PayAmount: req.PayAmount,
  702. PayType: 6,
  703. Comment: "",
  704. Months: req.Months,
  705. InputIp: ctx.ClientIP(),
  706. OpenId: tokenInfo.OpenId,
  707. HouseholdUid: tokenInfo.Uid,
  708. PackageId: req.PackageId,
  709. }
  710. rpcRsp, err := pb.Garden.ChargePrePayByHousehold(ctx, rpcReq)
  711. if err != nil {
  712. s, _ := json.MarshalToString(req)
  713. logger.Error("func",
  714. zap.String("call", "pb.Garden.ChargePrePayByHousehold"),
  715. zap.String("params", s),
  716. zap.String("error", err.Error()))
  717. return errors.ErrorTransForm(err)
  718. }
  719. resp.Data = *rpcRsp
  720. ctx.JSON(http.StatusOK, resp)
  721. return nil
  722. }
  723. // 执行任务
  724. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  725. }
  726. //
  727. // @Summary 取消支付
  728. // @Description 取消支付
  729. // @Tags 取消支付
  730. // @Accept json
  731. // @Produce json
  732. // @Param token header string true "token"
  733. // @Param body body v1.ChargeOrderCancelBody true " "
  734. // @Success 200 {object} v1.ChargeOrderCancelResponse
  735. // @Failure 500 {object} base.HTTPError
  736. // @Router /api/v1/charge/order/cancel [put]
  737. func (c *Controller) ChargeOrderCancel(ctx *gin.Context) {
  738. // 解析参数
  739. req := &param_v1.ChargeOrderCancelRequest{}
  740. parseParamTask := func() error {
  741. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.ChargeOrderCancelBody)
  742. if err != nil {
  743. logger.Error("func",
  744. zap.String("call", "util.ShouldBind"),
  745. zap.String("error", err.Error()))
  746. return errors.ParamsError
  747. }
  748. return nil
  749. }
  750. // 业务处理
  751. handleServiceTask := func() error {
  752. //tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  753. //if err != nil {
  754. // return err
  755. //}
  756. // 响应数据
  757. resp := param_v1.ChargeOrderCancelResponse{}
  758. rpcReq := &v1.ChargeOrderCancelRequest{
  759. GardenId: req.GardenId,
  760. OrderId: req.OrderId,
  761. ByUser: req.ByUser,
  762. }
  763. _, err := pb.Garden.ChargeOrderCancel(ctx, rpcReq)
  764. if err != nil {
  765. s, _ := json.MarshalToString(req)
  766. logger.Error("func",
  767. zap.String("call", "pb.Garden.ChargeOrderCancel"),
  768. zap.String("params", s),
  769. zap.String("error", err.Error()))
  770. return errors.ErrorTransForm(err)
  771. }
  772. ctx.JSON(http.StatusOK, resp)
  773. return nil
  774. }
  775. // 执行任务
  776. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  777. }
  778. //
  779. // @Summary 查看对象下的费项
  780. // @Description 查看对象下的费项
  781. // @Tags 预缴
  782. // @Accept json
  783. // @Produce json
  784. // @Param token header string true "token"
  785. // @Param obj_id query int true "房屋/车位/车辆id"
  786. // @Param obj_type query int true "1 房屋 2 车位 3 车辆 "
  787. // @Param charge_type query int true "费用类型1 物业费 2 水费 3 电费 4 气费 5 车位管理费 6 月租停车费 99 其他"
  788. // @Param page query int false " "
  789. // @Param page_size query int false " "
  790. // @Success 200 {object} v1.ChargeListResponse
  791. // @Failure 500 {object} base.HTTPError
  792. // @Router /api/v1/charge/obj_charge/charge_list [get]
  793. func (c *Controller) ChargeList(ctx *gin.Context) {
  794. // 解析参数
  795. req := &param_v1.ChargeListRequest{}
  796. parseParamTask := func() error {
  797. err := util.ShouldBind(ctx, &req.Header, nil, &req.ChargeListQuery, nil)
  798. if err != nil {
  799. logger.Error("func",
  800. zap.String("call", "util.ShouldBind"),
  801. zap.String("error", err.Error()))
  802. return errors.ParamsError
  803. }
  804. return nil
  805. }
  806. // 业务处理
  807. handleServiceTask := func() error {
  808. //tokenInfo, err := utils.GetSubjectValue(ctx)
  809. //if err != nil {
  810. // return err
  811. //}
  812. // 响应数据
  813. resp := param_v1.ChargeListResponse{}
  814. rpcReq := &v1.ChargeListRequest{
  815. GardenId: req.GardenId,
  816. PageSize: req.PageSize,
  817. Page: req.Page,
  818. ObjType: req.ObjType,
  819. ObjId: req.ObjId,
  820. ChargeType: req.ChargeType,
  821. }
  822. rpcRsp, err := pb.Garden.ChargeList(ctx, rpcReq)
  823. if err != nil {
  824. s, _ := json.MarshalToString(req)
  825. logger.Error("func",
  826. zap.String("call", "pb.Garden.ChargeList"),
  827. zap.String("params", s),
  828. zap.String("error", err.Error()))
  829. return errors.ErrorTransForm(err)
  830. }
  831. if rpcRsp.List == nil {
  832. rpcRsp.List = make([]*v1.ChargeItem, 0)
  833. }
  834. resp.Data = *rpcRsp
  835. ctx.JSON(http.StatusOK, resp)
  836. return nil
  837. }
  838. // 执行任务
  839. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  840. }