|
@@ -170,7 +170,7 @@ public class AppPayController extends BaseController {
|
|
|
@ApiImplicitParam(name = "orderId", value = "订单号", paramType = "query", required = true, dataType = "String")
|
|
|
})
|
|
|
public Object refund(@RequestParam(name = "orderId") String orderId) {
|
|
|
-
|
|
|
+ log.info("==============进入微信退款结果查询接口==============");
|
|
|
if(StringUtils.isBlank(orderId)){
|
|
|
return Result.failure("订单号不能为空");
|
|
|
}
|
|
@@ -314,14 +314,20 @@ public class AppPayController extends BaseController {
|
|
|
@PostMapping("query")
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Object orderQuery(@RequestParam(name = "orderId") String orderId) {
|
|
|
+ log.info("==============进入微信支付结果查询接口==============");
|
|
|
if (orderId == null) {
|
|
|
return Result.failure("订单不存在");
|
|
|
}
|
|
|
|
|
|
- TmOrder orderDetail = tmOrderService.getById(orderId);
|
|
|
+ TmOrder orderDetail = tmOrderService.getSelectByUpdate(orderId);
|
|
|
if(null == orderDetail){
|
|
|
- return Result.failure("订单获取失败");
|
|
|
+ return Result.failure("抢锁失败,订单获取失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ if(null != orderDetail.getPayStatus() && OrderPayStatusEnum.PAY_SUCCESS.getStatus().compareTo(orderDetail.getPayStatus()) == 0){
|
|
|
+ return Result.success("支付成功");
|
|
|
}
|
|
|
+
|
|
|
Map<Object, Object> parame = new TreeMap<Object, Object>();
|
|
|
parame.put("appid", ResourceUtil.getConfigByName("wx.appId"));
|
|
|
// 商家账号。
|
|
@@ -359,16 +365,20 @@ public class AppPayController extends BaseController {
|
|
|
tmOrderService.updateOrderStatusAndPayStatus(orderDetail ,
|
|
|
OrderPayStatusEnum.PAY_SUCCESS.getStatus() , OrderStatusEnum.ORDER_SUCCESS.getStatus());
|
|
|
if(StringUtils.isNotBlank(orderDetail.getDeskId())){
|
|
|
- TmDesk tmDesk = tmDeskService.getById(orderDetail.getDeskId());
|
|
|
+ //上锁,抢锁成功才可以
|
|
|
+ TmDesk tmDesk = tmDeskService.getBySelectForUpdate(orderDetail.getDeskId());
|
|
|
if(null != tmDesk){
|
|
|
if(null != tmDesk.getStatus() && tmDesk.getStatus().compareTo(1) != 0){
|
|
|
tmDesk.setStatus(1);
|
|
|
tmDesk.setUpdateTime(LocalDateTime.now());
|
|
|
- if(!tmDeskService.updateById(tmDesk)){
|
|
|
+ if(tmDeskService.updateWithId(tmDesk) != 1){
|
|
|
throw new CommonBaseException(ResultCodeEnum.D101 , "更细桌子/包厢状态失败");
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+ }else{
|
|
|
+ log.info("抢锁失败,订单[{}]无法预定桌子:[{}]" , orderDetail.getOrderNo() , orderDetail.getDeskName());
|
|
|
+ throw new CommonBaseException(ResultCodeEnum.D101 , "抢锁失败");
|
|
|
}
|
|
|
}
|
|
|
return Result.success("支付成功");
|
|
@@ -402,6 +412,7 @@ public class AppPayController extends BaseController {
|
|
|
@ApiIgnore
|
|
|
@RequestMapping(value = "/notify", method = RequestMethod.POST, produces = "text/html;charset=UTF-8")
|
|
|
public void notify(HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ log.info("==============收到微信支付的回调==============");
|
|
|
try {
|
|
|
request.setCharacterEncoding("UTF-8");
|
|
|
response.setCharacterEncoding("UTF-8");
|
|
@@ -423,15 +434,48 @@ public class AppPayController extends BaseController {
|
|
|
String result_code = result.getResult_code();
|
|
|
if (result_code.equalsIgnoreCase("FAIL")) {
|
|
|
//订单编号
|
|
|
- String out_trade_no = result.getOut_trade_no();
|
|
|
- log.info("订单" + out_trade_no + "支付失败");
|
|
|
+ String orderNo = result.getOut_trade_no();
|
|
|
+ log.info("订单" + orderNo + "支付失败");
|
|
|
+ //更新订单的状态为支付失败,并更新库存
|
|
|
+ TmOrder dbOrder = tmOrderService.getSelectByUpdateByOrderSn(orderNo);
|
|
|
+ if(null == dbOrder){
|
|
|
+ //抢锁失败
|
|
|
+ log.info("收到支付通知为支付失败,但是抢锁失败,不做操作,待查询的时候做更新");
|
|
|
+ }else{
|
|
|
+ tmOrderService.updateOrderStatusAndPayStatus(dbOrder ,
|
|
|
+ OrderPayStatusEnum.PAY_FAIL.getStatus() , OrderStatusEnum.ORDER_ING.getStatus());
|
|
|
+ }
|
|
|
response.getWriter().write(DataUtils.setXml("SUCCESS", "OK"));
|
|
|
} else if (result_code.equalsIgnoreCase("SUCCESS")) {
|
|
|
//订单编号
|
|
|
- String out_trade_no = result.getOut_trade_no();
|
|
|
- log.info("订单" + out_trade_no + "支付成功");
|
|
|
+ String orderNo = result.getOut_trade_no();
|
|
|
+ log.info("订单" + orderNo + "支付成功");
|
|
|
//更新订单的状态为已支付,并更新库存
|
|
|
-
|
|
|
+ TmOrder dbOrder = tmOrderService.getSelectByUpdateByOrderSn(orderNo);
|
|
|
+ if(null == dbOrder){
|
|
|
+ //抢锁失败
|
|
|
+ log.info("收到支付通知为支付成功,但是抢锁失败,不做操作,待查询的时候做更新");
|
|
|
+ }else{
|
|
|
+ //TODO:收归重复代码
|
|
|
+ tmOrderService.updateOrderStatusAndPayStatus(dbOrder ,
|
|
|
+ OrderPayStatusEnum.PAY_SUCCESS.getStatus() , OrderStatusEnum.ORDER_SUCCESS.getStatus());
|
|
|
+ if(StringUtils.isNotBlank(dbOrder.getDeskId())){
|
|
|
+ //上锁,抢锁成功才可以
|
|
|
+ TmDesk tmDesk = tmDeskService.getBySelectForUpdate(dbOrder.getDeskId());
|
|
|
+ if(null != tmDesk){
|
|
|
+ if(null != tmDesk.getStatus() && tmDesk.getStatus().compareTo(1) != 0){
|
|
|
+ tmDesk.setStatus(1);
|
|
|
+ tmDesk.setUpdateTime(LocalDateTime.now());
|
|
|
+ if(tmDeskService.updateWithId(tmDesk) != 1){
|
|
|
+ throw new CommonBaseException(ResultCodeEnum.D101 , "更细桌子/包厢状态失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ log.info("抢锁失败,订单[{}]无法预定桌子:[{}]" , dbOrder.getOrderNo() , dbOrder.getDeskName());
|
|
|
+ throw new CommonBaseException(ResultCodeEnum.D101 , "抢锁失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
response.getWriter().write(DataUtils.setXml("SUCCESS", "OK"));
|
|
|
}
|