|
@@ -1,35 +1,30 @@
|
|
package com.llisoft.service.pay.controller;
|
|
package com.llisoft.service.pay.controller;
|
|
|
|
|
|
-import java.util.Objects;
|
|
|
|
-
|
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
+import javax.validation.Valid;
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
-import org.springframework.beans.BeanUtils;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
-import org.springframework.stereotype.Controller;
|
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
-import org.springframework.web.bind.annotation.PathVariable;
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
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.RequestMapping;
|
|
-import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
-import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import com.llisoft.common.exception.MtaException;
|
|
import com.llisoft.common.exception.MtaException;
|
|
import com.llisoft.common.util.JsonUtil;
|
|
import com.llisoft.common.util.JsonUtil;
|
|
-import com.llisoft.service.pay.entity.Order;
|
|
|
|
-import com.llisoft.service.pay.service.AppService;
|
|
|
|
|
|
+import com.llisoft.common.vo.ResponseVo;
|
|
import com.llisoft.service.pay.service.OrderService;
|
|
import com.llisoft.service.pay.service.OrderService;
|
|
-import com.llisoft.service.pay.service.PayService;
|
|
|
|
-import com.llisoft.service.pay.vo.OrderRequestVo;
|
|
|
|
-import com.llisoft.service.pay.vo.OrderResponseVo;
|
|
|
|
-
|
|
|
|
|
|
+import com.llisoft.service.pay.vo.OrderAddRequestVo;
|
|
|
|
+import com.llisoft.service.pay.vo.OrderAddResponseVo;
|
|
|
|
+import com.llisoft.service.pay.vo.OrderInfoRequestVo;
|
|
|
|
+import com.llisoft.service.pay.vo.OrderInfoResponseVo;
|
|
|
|
+import com.llisoft.service.pay.vo.OrderPayRequestVo;
|
|
|
|
+import com.llisoft.service.pay.vo.OrderPayResponseVo;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 订单
|
|
* 订单
|
|
*/
|
|
*/
|
|
-@Controller
|
|
|
|
|
|
+@RestController
|
|
@RequestMapping("/order")
|
|
@RequestMapping("/order")
|
|
public class OrderController{
|
|
public class OrderController{
|
|
|
|
|
|
@@ -37,88 +32,33 @@ public class OrderController{
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private OrderService orderService;
|
|
private OrderService orderService;
|
|
- @Autowired
|
|
|
|
- private PayService payService;
|
|
|
|
- @Autowired
|
|
|
|
- private AppService appService;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 添加订单
|
|
|
|
- * 暂时不加认证签名
|
|
|
|
- * @param request
|
|
|
|
- */
|
|
|
|
- @PostMapping
|
|
|
|
- public @ResponseBody OrderResponseVo add(OrderRequestVo vo) throws MtaException{
|
|
|
|
- logger.info("添加订单请求: {}", JsonUtil.toJson(vo));
|
|
|
|
- if(Objects.isNull(vo.getAppkey()) || vo.getAppkey().trim().isEmpty() || vo.getMoney()<=0) {
|
|
|
|
- throw new MtaException("添加订单: 非法入参: " + JsonUtil.toJson(vo));
|
|
|
|
- }
|
|
|
|
- String ordernum = orderService.add(vo.getAppkey(), vo.getMoney(), vo.getOrdernum(), vo.getTitle());
|
|
|
|
- return this.get(ordernum);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 支付
|
|
|
|
- * @param orderId
|
|
|
|
- * @param type
|
|
|
|
- * @return
|
|
|
|
|
|
+ * 订单添加
|
|
*/
|
|
*/
|
|
- @GetMapping("/{orderId}/pay")
|
|
|
|
- public String pay(@PathVariable int orderId, // 默认支付宝
|
|
|
|
- @RequestParam(required=false,defaultValue="1") byte type) throws MtaException{
|
|
|
|
- if(orderId <= 0) {
|
|
|
|
- throw new MtaException("订单号非法: " + orderId);
|
|
|
|
- }
|
|
|
|
- Order order = orderService.get(orderId);
|
|
|
|
- if(order.getOrderStatus() == OrderService.STATUS_PAYED){
|
|
|
|
- logger.info("订单支付: 订单已经支付过: {}", orderId);
|
|
|
|
- return "redirect:/order/"+orderId+"/ok"; // 已经支付过
|
|
|
|
- }
|
|
|
|
- logger.info("订单支付: {}, 支付类型: {}", orderId, type==1 ? "支付宝" : "微信");
|
|
|
|
- String paynum = payService.add(orderId, type);
|
|
|
|
- return "redirect:/pay/" + paynum;
|
|
|
|
|
|
+ @PostMapping("/add")
|
|
|
|
+ public ResponseVo<OrderAddResponseVo> add(@Valid @RequestBody OrderAddRequestVo vo) throws MtaException{
|
|
|
|
+ logger.info("收到订单添加请求: {}", JsonUtil.toJson(vo));
|
|
|
|
+ return ResponseVo.success(orderService.add(vo.getAppKey(), vo.getMoney(), vo.getTitle()));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 支付成功
|
|
|
|
- * @return
|
|
|
|
- * @throws MtaException
|
|
|
|
|
|
+ * 订单支付
|
|
*/
|
|
*/
|
|
- @GetMapping(value="/{orderId}/ok")
|
|
|
|
- public String ok(@PathVariable int orderId, HttpServletRequest request) throws MtaException{
|
|
|
|
- Order order = orderService.get(orderId);
|
|
|
|
- if (order.getOrderStatus() == OrderService.STATUS_PAYED) {
|
|
|
|
- // 重定向到业务回调地址
|
|
|
|
- String returnUrl = appService.getReturnUrl(order.getAppId(), order.getOrderNum());
|
|
|
|
- if (Objects.nonNull(returnUrl)) {
|
|
|
|
- return "redirect:" + returnUrl;
|
|
|
|
- }
|
|
|
|
- // 未配置成功地址的返回默认
|
|
|
|
- request.setAttribute("order", order);
|
|
|
|
- return "/payok.jsp";
|
|
|
|
- }
|
|
|
|
- return null;
|
|
|
|
|
|
+ @PostMapping("/pay")
|
|
|
|
+ public ResponseVo<OrderPayResponseVo> pay(@Valid @RequestBody OrderPayRequestVo vo) throws MtaException{
|
|
|
|
+ logger.info("收到订单支付请求: {}", JsonUtil.toJson(vo));
|
|
|
|
+ return ResponseVo.success(orderService.pay(vo.getOrderNum(), vo.getPayType(), vo.isMobile()));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 获取订单
|
|
|
|
- * @param paynum
|
|
|
|
- * @return
|
|
|
|
- * @throws MtaException
|
|
|
|
|
|
+ * 订单信息
|
|
*/
|
|
*/
|
|
- @GetMapping("/{orderNum}")
|
|
|
|
- public @ResponseBody OrderResponseVo get(@PathVariable String orderNum) throws MtaException{
|
|
|
|
- OrderResponseVo responseBean = null;
|
|
|
|
- if(Objects.nonNull(orderNum) && !orderNum.trim().isEmpty()){
|
|
|
|
- Order order = orderService.getByOrderNum(orderNum);
|
|
|
|
- responseBean = new OrderResponseVo();
|
|
|
|
- BeanUtils.copyProperties(order, responseBean);
|
|
|
|
- responseBean.setPayed(order.getOrderStatus()==OrderService.STATUS_PAYED);
|
|
|
|
- responseBean.setPayUrl("/order/"+orderNum+"/pay");
|
|
|
|
- }
|
|
|
|
- logger.info("获取订单请求: {}, 返回结果: {}", orderNum, JsonUtil.toJson(responseBean));
|
|
|
|
- return responseBean;
|
|
|
|
|
|
+ @PostMapping("/info")
|
|
|
|
+ public ResponseVo<OrderInfoResponseVo> get(@Valid @RequestBody OrderInfoRequestVo vo) throws MtaException{
|
|
|
|
+ logger.info("收到订单详情请求: {}", JsonUtil.toJson(vo));
|
|
|
|
+ return ResponseVo.success(orderService.info(vo.getOrderNum()));
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|