|
@@ -0,0 +1,68 @@
|
|
|
+package com.hys.app.controller.erp.use;
|
|
|
+
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.hys.app.framework.exception.ServiceException;
|
|
|
+import com.hys.app.model.erp.dos.OrderDO;
|
|
|
+import com.hys.app.model.erp.dto.PayTypeUrl;
|
|
|
+import com.hys.app.pay.ali.AliPayService;
|
|
|
+import com.hys.app.pay.ali.PayOrder;
|
|
|
+import com.hys.app.pay.ali.WxService;
|
|
|
+import com.hys.app.service.erp.OrderManager;
|
|
|
+import com.wechat.pay.java.core.auth.WechatPay2Validator;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/admin/erp/pay")
|
|
|
+@Api(tags = "订单支付")
|
|
|
+@Validated
|
|
|
+@AllArgsConstructor
|
|
|
+public class PayController {
|
|
|
+ private OrderManager orderManager;
|
|
|
+ private AliPayService aliPayService;
|
|
|
+ private WxService wxService;
|
|
|
+
|
|
|
+ @ApiOperation(value = "扫描完获取拉起支付的url")
|
|
|
+ @PostMapping("/getPayUrl")
|
|
|
+ public Object getListByScan(@RequestBody @Validated PayTypeUrl payTypeUrl) {
|
|
|
+ OrderDO aDo = orderManager.getById(payTypeUrl.getOrderId());
|
|
|
+ if (ObjectUtil.isNull(aDo)) {
|
|
|
+ throw new ServiceException("未查询到订单信息");
|
|
|
+ }
|
|
|
+ PayOrder payOrder = new PayOrder();
|
|
|
+ payOrder.setTraceNo(aDo.getId().toString());
|
|
|
+ payOrder.setTotalAmount(aDo.getRealPrice());
|
|
|
+ payOrder.setSubject("租赁订单支付金额");
|
|
|
+ payOrder.setTimeExpire(LocalDateTime.now().plusMinutes(30));
|
|
|
+
|
|
|
+ switch (payTypeUrl.getPayType()) {
|
|
|
+ case "ali":
|
|
|
+ return aliPayService.pay(payOrder);
|
|
|
+ case "wx":
|
|
|
+ return wxService.pay(payOrder);
|
|
|
+ default:
|
|
|
+ return "不支持的支付方式";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/aliReturnCall")
|
|
|
+ public void aliReturnCall(HttpServletRequest request, HttpServletResponse response, Map<String, String> map) {
|
|
|
+ if (aliPayService.checkReturnParam(map)) {
|
|
|
+ response.setContentType("type=text/html;charset=UTF-8");
|
|
|
+ OrderDO aDo = orderManager.getById(map.get("out_trade_no"));
|
|
|
+ aDo.setHasPayReturn(true);
|
|
|
+ orderManager.updateById(aDo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|