|
@@ -3,16 +3,22 @@ package com.fdage.controller.app;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.fdage.base.dto.OrderAndCanteenRspDto;
|
|
import com.fdage.base.dto.OrderAndCanteenRspDto;
|
|
import com.fdage.base.dto.OrderAppReqDto;
|
|
import com.fdage.base.dto.OrderAppReqDto;
|
|
|
|
+import com.fdage.base.dto.WechatRefundApiResult;
|
|
import com.fdage.base.entity.TmCanteen;
|
|
import com.fdage.base.entity.TmCanteen;
|
|
import com.fdage.base.entity.TmOrder;
|
|
import com.fdage.base.entity.TmOrder;
|
|
import com.fdage.base.entity.TmUser;
|
|
import com.fdage.base.entity.TmUser;
|
|
|
|
+import com.fdage.base.enums.IdPreEnum;
|
|
|
|
+import com.fdage.base.enums.OrderPayStatusEnum;
|
|
|
|
+import com.fdage.base.enums.OrderStatusEnum;
|
|
import com.fdage.base.service.impl.TmCanteenServiceImpl;
|
|
import com.fdage.base.service.impl.TmCanteenServiceImpl;
|
|
import com.fdage.base.service.impl.TmOrderServiceImpl;
|
|
import com.fdage.base.service.impl.TmOrderServiceImpl;
|
|
import com.fdage.base.utils.DataUtils;
|
|
import com.fdage.base.utils.DataUtils;
|
|
|
|
+import com.fdage.base.utils.WechatUtil;
|
|
import com.fdage.controller.BaseController;
|
|
import com.fdage.controller.BaseController;
|
|
import fdage.back.sdk.base.entity.Result;
|
|
import fdage.back.sdk.base.entity.Result;
|
|
import fdage.back.sdk.base.enums.ResultCodeEnum;
|
|
import fdage.back.sdk.base.enums.ResultCodeEnum;
|
|
import fdage.back.sdk.base.exception.CommonBaseException;
|
|
import fdage.back.sdk.base.exception.CommonBaseException;
|
|
|
|
+import fdage.back.sdk.base.uuid.SnowFlakeUUidUtils;
|
|
import fdage.back.sdk.core.alibabaUtils.AlibabaSmsService;
|
|
import fdage.back.sdk.core.alibabaUtils.AlibabaSmsService;
|
|
import fdage.back.sdk.utils.ResourceUtil;
|
|
import fdage.back.sdk.utils.ResourceUtil;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
@@ -24,8 +30,10 @@ import org.apache.commons.collections.CollectionUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
@@ -101,6 +109,72 @@ public class AppOrderController extends BaseController {
|
|
}
|
|
}
|
|
return Result.success(tmOrder);
|
|
return Result.success(tmOrder);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @PostMapping("/cancelOrder")
|
|
|
|
+ @ApiOperation(value = "取消预定")
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public Result<TmOrder> cancelOrder(@RequestParam(value = "orderId") String orderId){
|
|
|
|
+
|
|
|
|
+ if(StringUtils.isBlank(orderId)){
|
|
|
|
+ return Result.failure("订单号不能为空");
|
|
|
|
+ }
|
|
|
|
+ TmOrder dbOrder = tmOrderService.getById(orderId);
|
|
|
|
+ if(null == dbOrder){
|
|
|
|
+ return Result.failure("订单号不存在");
|
|
|
|
+ }
|
|
|
|
+ //1、检查订单状态
|
|
|
|
+ if(null != dbOrder.getStatus()){
|
|
|
|
+ if(OrderStatusEnum.ORDER_CANCEL.getStatus().compareTo(dbOrder.getStatus()) == 0 ){
|
|
|
|
+ return Result.failure("订单号已经取消");
|
|
|
|
+ }
|
|
|
|
+ if(OrderStatusEnum.ORDER_USED.getStatus().compareTo(dbOrder.getStatus()) == 0){
|
|
|
|
+ return Result.failure("订单号已经使用,无法取消");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //2、检查订单支付状态
|
|
|
|
+ if(null != dbOrder.getPayStatus()){
|
|
|
|
+ if(OrderPayStatusEnum.REFUND_SUCCESS.getStatus().compareTo(dbOrder.getPayStatus()) == 0){
|
|
|
|
+ //这里更新订单的状态??? TODO:先去微信支付查询再反转状态?
|
|
|
|
+ dbOrder.setStatus(OrderStatusEnum.ORDER_CANCEL.getStatus());
|
|
|
|
+ dbOrder.setUpdateTime(LocalDateTime.now());
|
|
|
|
+ //更新订单状态为已经取消
|
|
|
|
+ if(!tmOrderService.updateById(dbOrder)){
|
|
|
|
+ throw new CommonBaseException(ResultCodeEnum.D101 , "更新订单状态失败");
|
|
|
|
+ }
|
|
|
|
+ return Result.failure("订单号已退款成功");
|
|
|
|
+ }else if(OrderPayStatusEnum.REFUND_FAIL.getStatus().compareTo(dbOrder.getPayStatus()) == 0){
|
|
|
|
+ //上次退款失败,需要调用查询接口去查询
|
|
|
|
+ //TODO:
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ String refundId = SnowFlakeUUidUtils.generaUUid(null , null , IdPreEnum.WX_REFUND_PRE.getPre());
|
|
|
|
+ dbOrder.setPayStatus(OrderPayStatusEnum.REFUND_ING.getStatus());
|
|
|
|
+ dbOrder.setUpdateTime(LocalDateTime.now());
|
|
|
|
+ dbOrder.setRefundId(refundId);
|
|
|
|
+ if(!tmOrderService.updateById(dbOrder)){
|
|
|
|
+ throw new CommonBaseException(ResultCodeEnum.D101 , "更新订单状态为退款中失败");
|
|
|
|
+ }
|
|
|
|
+ //执行退款逻辑
|
|
|
|
+ WechatRefundApiResult result = WechatUtil.wxRefund(dbOrder.getId(), refundId ,
|
|
|
|
+ dbOrder.getOrderPrice().doubleValue(), dbOrder.getOrderPrice().doubleValue());
|
|
|
|
+ if (null != result && result.getResult_code().equals("SUCCESS")) {
|
|
|
|
+ dbOrder.setStatus(OrderStatusEnum.ORDER_CANCEL.getStatus());
|
|
|
|
+ dbOrder.setPayStatus(OrderPayStatusEnum.REFUND_SUCCESS.getStatus());
|
|
|
|
+ dbOrder.setUpdateTime(LocalDateTime.now());
|
|
|
|
+ if(!tmOrderService.updateById(dbOrder)){
|
|
|
|
+ throw new CommonBaseException(ResultCodeEnum.D101 , "更新订单状态为退款成功失败");
|
|
|
|
+ }
|
|
|
|
+ return Result.success( "成功退款");
|
|
|
|
+ } else {
|
|
|
|
+ dbOrder.setPayStatus(OrderPayStatusEnum.REFUND_FAIL.getStatus());
|
|
|
|
+ dbOrder.setUpdateTime(LocalDateTime.now());
|
|
|
|
+ if(!tmOrderService.updateById(dbOrder)){
|
|
|
|
+ throw new CommonBaseException(ResultCodeEnum.D101 , "更新订单状态为退款成功失败");
|
|
|
|
+ }
|
|
|
|
+ return Result.failure( "退款失败");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
@PostMapping("/addNew")
|
|
@PostMapping("/addNew")
|
|
@ApiOperation(value = "创建订单")
|
|
@ApiOperation(value = "创建订单")
|
|
public Result<TmOrder> addNew(@RequestBody OrderAppReqDto orderAppReqDto){
|
|
public Result<TmOrder> addNew(@RequestBody OrderAppReqDto orderAppReqDto){
|