From d3a12b192afc54eb51f640a8050644d4fddd9100 Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期五, 28 七月 2023 15:16:08 +0800
Subject: [PATCH] 后台代码
---
cloud-server-other/src/main/java/com/dsh/other/controller/SiteController.java | 329 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 323 insertions(+), 6 deletions(-)
diff --git a/cloud-server-other/src/main/java/com/dsh/other/controller/SiteController.java b/cloud-server-other/src/main/java/com/dsh/other/controller/SiteController.java
index ff84b6c..3d3f7e9 100644
--- a/cloud-server-other/src/main/java/com/dsh/other/controller/SiteController.java
+++ b/cloud-server-other/src/main/java/com/dsh/other/controller/SiteController.java
@@ -1,19 +1,33 @@
package com.dsh.other.controller;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.dsh.other.entity.Site;
+import com.dsh.other.entity.SiteBooking;
+import com.dsh.other.entity.SiteType;
+import com.dsh.other.feignclient.activity.UserCouponClient;
+import com.dsh.other.feignclient.activity.model.UserCoupon;
+import com.dsh.other.feignclient.model.SiteVo;
import com.dsh.other.model.*;
+import com.dsh.other.service.ISiteBookingService;
import com.dsh.other.service.ISiteService;
import com.dsh.other.service.ISiteTypeService;
+import com.dsh.other.util.PayMoneyUtil;
import com.dsh.other.util.ResultUtil;
+import com.dsh.other.util.TokenUtil;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Date;
import java.util.List;
+import java.util.Map;
/**
* @author zhibing.pu
@@ -28,6 +42,18 @@
@Autowired
private ISiteTypeService siteTypeService;
+
+ @Autowired
+ private TokenUtil tokenUtil;
+
+ @Autowired
+ private PayMoneyUtil payMoneyUtil;
+
+ @Autowired
+ private ISiteBookingService siteBookingService;
+
+ @Resource
+ private UserCouponClient userCouponClient;
@@ -71,10 +97,12 @@
@ApiOperation(value = "获取场地详情", tags = {"用户—预约场地"})
@ApiImplicitParams({
@ApiImplicitParam(value = "场地id", name = "id", dataType = "int", required = true),
+ @ApiImplicitParam(value = "经度", name = "lon", dataType = "string", required = false),
+ @ApiImplicitParam(value = "纬度", name = "lat", dataType = "string", required = false),
})
- public ResultUtil<QuerySiteInfoVo> querySiteInfo(Integer id){
+ public ResultUtil<QuerySiteInfoVo> querySiteInfo(Integer id, String lon, String lat){
try {
- QuerySiteInfoVo querySiteInfoVo = siteService.querySiteInfo(id);
+ QuerySiteInfoVo querySiteInfoVo = siteService.querySiteInfo(id, lon, lat);
return ResultUtil.success(querySiteInfoVo);
}catch (Exception e){
e.printStackTrace();
@@ -100,4 +128,293 @@
return ResultUtil.runErr();
}
}
+
+
+ /**
+ * 根据id获取数据
+ * @param id
+ * @return
+ */
+ @ResponseBody
+ @PostMapping("/site/querySiteById")
+ public Site querySiteById(@RequestBody Integer id){
+ try {
+ return siteService.getById(id);
+ }catch (Exception e){
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+
+
+ @ResponseBody
+ @PostMapping("/api/site/reservationSite")
+ @ApiOperation(value = "预约场地操作", tags = {"用户—预约场地"})
+ @ApiImplicitParams({
+ @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
+ })
+ public ResultUtil reservationSite(ReservationSite reservationSite){
+ try {
+ Integer uid = tokenUtil.getUserIdFormRedis();
+ if(null == uid){
+ return ResultUtil.tokenErr();
+ }
+ return siteService.reservationSite(uid, reservationSite);
+ }catch (Exception e){
+ e.printStackTrace();
+ return ResultUtil.runErr();
+ }
+ }
+
+
+
+
+
+ /**
+ * 购买课程微信支付回调
+ * @param request
+ * @param response
+ */
+ @ResponseBody
+ @PostMapping("/base/site/weChatPaymentSiteCallback")
+ public void weChatPaymentSiteCallback(HttpServletRequest request, HttpServletResponse response){
+ try {
+ Map<String, String> map = payMoneyUtil.weixinpayCallback(request);
+ if(null != map){
+ String code = map.get("out_trade_no");
+ String transaction_id = map.get("transaction_id");
+ String result = map.get("result");
+ SiteBooking siteBooking = siteBookingService.getOne(new QueryWrapper<SiteBooking>().eq("orderNo", code).eq("state", 1));
+ if(siteBooking.getStatus() == 0){
+ siteBooking.setPayTime(new Date());
+ siteBooking.setStatus(1);
+ siteBooking.setPayOrderNo(transaction_id);
+ siteBookingService.updateById(siteBooking);
+ }
+ PrintWriter out = response.getWriter();
+ out.write(result);
+ out.flush();
+ out.close();
+ }
+ }catch (Exception e){
+ e.printStackTrace();
+ }
+ }
+
+
+ /**
+ * 购买课程支付宝回调
+ * @param request
+ * @param response
+ */
+ @ResponseBody
+ @PostMapping("/base/site/aliPaymentSiteCallback")
+ public void aliPaymentSiteCallback(HttpServletRequest request, HttpServletResponse response){
+ try {
+ Map<String, String> map = payMoneyUtil.alipayCallback(request);
+ if(null != map){
+ String code = map.get("out_trade_no");
+ String trade_no = map.get("trade_no");
+ SiteBooking siteBooking = siteBookingService.getOne(new QueryWrapper<SiteBooking>().eq("orderNo", code).eq("state", 1));
+ if(siteBooking.getStatus() == 0){
+ siteBooking.setPayTime(new Date());
+ siteBooking.setStatus(1);
+ siteBooking.setPayOrderNo(trade_no);
+ siteBookingService.updateById(siteBooking);
+ }
+ PrintWriter out = response.getWriter();
+ out.write("success");
+ out.flush();
+ out.close();
+ }
+ }catch (Exception e){
+ e.printStackTrace();
+ }
+ }
+
+
+
+
+ @ResponseBody
+ @PostMapping("/api/site/queryMySite")
+ @ApiOperation(value = "获取我的预约场地列表", tags = {"用户—预约场地"})
+ @ApiImplicitParams({
+ @ApiImplicitParam(value = "状态(0=待支付,1=待核销,2=已到店,3=已完成,4=已过期,5=已取消)", name = "status", dataType = "int", required = false),
+ @ApiImplicitParam(value = "页码,首页1", name = "pageNo", dataType = "int", required = true),
+ @ApiImplicitParam(value = "页条数", name = "pageSize", dataType = "int", required = true),
+ @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
+ })
+ public ResultUtil<List<QueryMySiteVo>> queryMySite(Integer status, Integer pageNo, Integer pageSize){
+ try {
+ Integer uid = tokenUtil.getUserIdFormRedis();
+ if(null == uid){
+ return ResultUtil.tokenErr();
+ }
+ List<QueryMySiteVo> queryMySiteVos = siteService.queryMySite(uid, status, pageNo, pageSize);
+ return ResultUtil.success(queryMySiteVos);
+ }catch (Exception e){
+ e.printStackTrace();
+ return ResultUtil.runErr();
+ }
+ }
+
+
+ @ResponseBody
+ @PostMapping("/api/site/cancelMySite")
+ @ApiOperation(value = "取消我的预约场地", tags = {"用户—预约场地"})
+ @ApiImplicitParams({
+ @ApiImplicitParam(value = "预约数据id", name = "id", dataType = "int", required = true),
+ @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
+ })
+ public ResultUtil cancelMySite(Integer id){
+ try {
+ Integer uid = tokenUtil.getUserIdFormRedis();
+ if(null == uid){
+ return ResultUtil.tokenErr();
+ }
+ return siteService.cancelMySite(uid, id);
+ }catch (Exception e){
+ e.printStackTrace();
+ return ResultUtil.runErr();
+ }
+ }
+
+
+ /**
+ * 微信退款回调
+ * @param request
+ * @param response
+ */
+ @ResponseBody
+ @PostMapping("/base/site/cancelMySiteCallback")
+ public void cancelMySiteCallback(HttpServletRequest request, HttpServletResponse response){
+ try {
+ Map<String, String> map = payMoneyUtil.wxRefundCallback(request);
+ if(null != map){
+ String code = map.get("out_refund_no");
+ String refund_id = map.get("refund_id");
+ String result = map.get("result");
+
+ SiteBooking siteBooking = siteBookingService.getOne(new QueryWrapper<SiteBooking>().eq("orderNo", code).eq("state", 1));
+ siteBooking.setStatus(5);
+ siteBooking.setCancelTime(new Date());
+ siteBooking.setRefundOrderNo(refund_id);
+ siteBookingService.updateById(siteBooking);
+ if(null != siteBooking.getUserCouponId()){
+ UserCoupon userCoupon = userCouponClient.queryUserCouponById(siteBooking.getUserCouponId());
+ userCoupon.setStatus(1);
+ userCouponClient.updateUserCoupon(userCoupon);
+ }
+ PrintWriter out = response.getWriter();
+ out.write(result);
+ out.flush();
+ out.close();
+ }
+ }catch (Exception e){
+ e.printStackTrace();
+ }
+ }
+
+
+
+ @ResponseBody
+ @PostMapping("/api/site/continuePaymentMySite")
+ @ApiOperation(value = "继续支付我预约的场地", tags = {"用户—预约场地"})
+ @ApiImplicitParams({
+ @ApiImplicitParam(value = "预约数据id", name = "id", dataType = "int", required = true),
+ @ApiImplicitParam(value = "支付方式(1=微信,2=支付宝,3=玩湃币)", name = "payType", dataType = "int", required = true),
+ @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
+ })
+ public ResultUtil continuePaymentMySite(Integer id, Integer payType){
+ try {
+ Integer uid = tokenUtil.getUserIdFormRedis();
+ if(null == uid){
+ return ResultUtil.tokenErr();
+ }
+ return siteService.continuePaymentMySite(uid, id, payType);
+ }catch (Exception e){
+ e.printStackTrace();
+ return ResultUtil.runErr();
+ }
+ }
+
+
+
+ @ResponseBody
+ @PostMapping("/api/site/queryContinuePaymentMySitePrice")
+ @ApiOperation(value = "获取继续支付场地金额", tags = {"用户—预约场地"})
+ @ApiImplicitParams({
+ @ApiImplicitParam(value = "预约数据id", name = "id", dataType = "int", required = true),
+ })
+ public ResultUtil<Map<String, Double>> queryContinuePaymentMySitePrice(Integer id){
+ try {
+ return siteService.queryContinuePaymentMySitePrice(id);
+ }catch (Exception e){
+ e.printStackTrace();
+ return ResultUtil.runErr();
+ }
+ }
+
+ /**
+ * 查询所有现金支付的预约记录
+ * @param appUserId
+ * @return
+ */
+ @PostMapping("/base/site/queryPaymentSiteDetail")
+ public List<SiteBooking> getAllSiteBookingList(@RequestBody Integer appUserId){
+ ArrayList<Integer> integers = new ArrayList<>();
+ integers.add(1);
+ integers.add(2);
+ integers.add(3);
+ integers.add(4);
+ integers.add(5);
+ return siteBookingService.list(new QueryWrapper<SiteBooking>()
+ .in("status",integers)
+ .ne("payType",3)
+ .eq("appUserId",appUserId));
+ }
+
+ /**
+ * 查询所有玩湃币支付的预约记录
+ * @param appUserId
+ * @return
+ */
+ @PostMapping("/base/site/queryPlaypaiGoldSiteDetail")
+ public List<SiteBooking> wanpaiGoldSiteBookingList(@RequestBody Integer appUserId){
+ ArrayList<Integer> integers = new ArrayList<>();
+ integers.add(1);
+ integers.add(2);
+ integers.add(3);
+ integers.add(4);
+ integers.add(5);
+ return siteBookingService.list(new QueryWrapper<SiteBooking>()
+ .in("status",integers)
+ .eq("payType",3)
+ .eq("appUserId",appUserId));
+ }
+
+
+ @PostMapping("/base/site/getNewAddSiteList")
+ public List<SiteVo> getAppUserSiteList(){
+ List<SiteVo> siteVos = new ArrayList<>();
+
+ List<Site> list = siteService.list(new QueryWrapper<Site>()
+ .orderByDesc("insertTime"));
+ if (list.size() > 0 ){
+ for (Site site : list) {
+ SiteVo vo = new SiteVo();
+ vo.setSiteId(site.getId());
+ vo.setSiteName(site.getName());
+ vo.setSiteTime(site.getAppointmentStartTime() + "-" + site.getAppointmentEndTime());
+ SiteType byId = siteTypeService.getById(site.getSiteTypeId());
+ vo.setSiteType(byId.getName());
+ vo.setPrice(site.getCashPrice());
+ siteVos.add(vo);
+ }
+ }
+ return siteVos;
+
+ }
+
}
--
Gitblit v1.7.1