修改下单
This commit is contained in:
@@ -49,6 +49,9 @@ public class OrderController {
|
|||||||
BookEntity bookEntity = bookService.getById(buyOrder.getAbroadBookId());
|
BookEntity bookEntity = bookService.getById(buyOrder.getAbroadBookId());
|
||||||
BigDecimal totalPrice = buyOrder.getOrderMoney();
|
BigDecimal totalPrice = buyOrder.getOrderMoney();
|
||||||
//校验价格
|
//校验价格
|
||||||
|
if (totalPrice.compareTo(new BigDecimal(0))<=0){
|
||||||
|
return R.error("订单价格不能为0");
|
||||||
|
}
|
||||||
if (totalPrice.compareTo(bookEntity.getAbroadPrice())!=0){
|
if (totalPrice.compareTo(bookEntity.getAbroadPrice())!=0){
|
||||||
return R.error("订单价格异常");
|
return R.error("订单价格异常");
|
||||||
}
|
}
|
||||||
@@ -77,8 +80,7 @@ public class OrderController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Map<String, Object> result = new HashMap<>();
|
Map<String, Object> result = new HashMap<>();
|
||||||
result.put("orderSn", buyOrder.getOrderSn());
|
result.put("orderId", buyOrder.getOrderId());
|
||||||
result.put("money", totalPrice);
|
|
||||||
return R.ok(result);
|
return R.ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,31 +3,20 @@ package com.peanut.modules.pay.paypal.controller;
|
|||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
||||||
import com.github.promeg.pinyinhelper.Pinyin;
|
|
||||||
import com.peanut.common.utils.R;
|
import com.peanut.common.utils.R;
|
||||||
import com.peanut.common.utils.ShiroUtils;
|
|
||||||
import com.peanut.config.DelayQueueConfig;
|
|
||||||
import com.peanut.modules.book.service.BuyOrderService;
|
import com.peanut.modules.book.service.BuyOrderService;
|
||||||
import com.peanut.modules.book.service.UserEbookBuyService;
|
import com.peanut.modules.book.service.UserEbookBuyService;
|
||||||
import com.peanut.modules.common.entity.BookEntity;
|
|
||||||
import com.peanut.modules.common.entity.BuyOrder;
|
import com.peanut.modules.common.entity.BuyOrder;
|
||||||
import com.peanut.modules.common.entity.PayPaypalOrder;
|
import com.peanut.modules.common.entity.PayPaypalOrder;
|
||||||
import com.peanut.modules.common.service.BookService;
|
|
||||||
import com.peanut.modules.pay.paypal.config.PaypalConfig;
|
import com.peanut.modules.pay.paypal.config.PaypalConfig;
|
||||||
import com.peanut.modules.pay.paypal.service.PayPaypalOrderService;
|
import com.peanut.modules.pay.paypal.service.PayPaypalOrderService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.amqp.core.MessagePostProcessor;
|
|
||||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
||||||
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.RequestBody;
|
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.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -38,8 +27,6 @@ import java.util.*;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class PaypalController {
|
public class PaypalController {
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private BookService bookService;
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private PaypalConfig paypalConfig;
|
private PaypalConfig paypalConfig;
|
||||||
@Autowired
|
@Autowired
|
||||||
@@ -47,43 +34,17 @@ public class PaypalController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private PayPaypalOrderService payPaypalOrderService;
|
private PayPaypalOrderService payPaypalOrderService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private RabbitTemplate rabbitTemplate;
|
|
||||||
@Autowired
|
|
||||||
private UserEbookBuyService userEbookBuyService;
|
private UserEbookBuyService userEbookBuyService;
|
||||||
|
|
||||||
@RequestMapping("/createOrder")
|
@RequestMapping("/createOrder")
|
||||||
@Transactional
|
|
||||||
public R createOrder(@RequestBody Map<String,Object> params){
|
public R createOrder(@RequestBody Map<String,Object> params){
|
||||||
BuyOrder buyOrder = new BuyOrder();
|
BuyOrder buyOrder = buyOrderService.getById(params.get("orderId").toString());
|
||||||
buyOrder.setUserId(ShiroUtils.getUId());
|
if ("3".equals(buyOrder.getOrderStatus())){
|
||||||
buyOrder.setCome(3);//3 海外读书
|
return R.error("订单已完成");
|
||||||
buyOrder.setPaymentMethod("5"); //5 paypal
|
|
||||||
int bookId = Integer.parseInt(params.get("abroadBookId").toString());
|
|
||||||
BookEntity bookEntity = bookService.getById(bookId);
|
|
||||||
BigDecimal orderMoney = new BigDecimal(params.get("orderMoney").toString());
|
|
||||||
//校验价格
|
|
||||||
if (orderMoney.compareTo(bookEntity.getAbroadPrice())!=0){
|
|
||||||
return R.error("订单价格异常");
|
|
||||||
}
|
}
|
||||||
buyOrder.setOrderMoney(orderMoney);
|
|
||||||
buyOrder.setRealMoney(orderMoney);
|
|
||||||
buyOrder.setRemark("Purchase the e-book '"+ Pinyin.toPinyin(bookEntity.getName(), " ").toLowerCase()+"'");
|
|
||||||
buyOrder.setOrderStatus("0");
|
|
||||||
buyOrder.setOrderType("abroadBook");
|
|
||||||
buyOrder.setAbroadBookId(bookId);
|
|
||||||
String timeId = IdWorker.getTimeId().substring(0, 32);
|
|
||||||
buyOrder.setOrderSn(timeId);
|
|
||||||
JSONObject res = paypalConfig.createOrder(buyOrder);
|
JSONObject res = paypalConfig.createOrder(buyOrder);
|
||||||
if (res.containsKey("links")&&res.containsKey("status")){
|
if (res.containsKey("links")&&res.containsKey("status")){
|
||||||
if ("CREATED".equals(res.get("status").toString())){
|
if ("CREATED".equals(res.get("status").toString())){
|
||||||
buyOrderService.save(buyOrder);
|
|
||||||
String url = "";
|
|
||||||
List<JSONObject> links = (List)res.get("links");
|
|
||||||
for (JSONObject o:links) {
|
|
||||||
if ("approve".equals(o.get("rel").toString())){
|
|
||||||
url = o.get("href").toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
PayPaypalOrder payPaypalOrder = new PayPaypalOrder();
|
PayPaypalOrder payPaypalOrder = new PayPaypalOrder();
|
||||||
payPaypalOrder.setOrderId(buyOrder.getOrderId());
|
payPaypalOrder.setOrderId(buyOrder.getOrderId());
|
||||||
payPaypalOrder.setOrderSn(buyOrder.getOrderSn());
|
payPaypalOrder.setOrderSn(buyOrder.getOrderSn());
|
||||||
@@ -91,24 +52,11 @@ public class PaypalController {
|
|||||||
payPaypalOrder.setPaypalOrderId(res.get("id").toString());
|
payPaypalOrder.setPaypalOrderId(res.get("id").toString());
|
||||||
payPaypalOrder.setDescription(buyOrder.getRemark());
|
payPaypalOrder.setDescription(buyOrder.getRemark());
|
||||||
payPaypalOrderService.save(payPaypalOrder);
|
payPaypalOrderService.save(payPaypalOrder);
|
||||||
rabbitTemplate.convertAndSend(
|
return R.ok().put("id",res.get("id").toString());
|
||||||
DelayQueueConfig.ORDER_TO_BE_PAY_EXCHANGE,
|
|
||||||
DelayQueueConfig.ORDER_TO_BE_PAY_ROUTING_KEY,
|
|
||||||
buyOrder.getOrderId(),
|
|
||||||
messagePostProcessor()
|
|
||||||
);
|
|
||||||
return R.ok().put("url",url).put("id",res.get("id").toString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return R.error(res.get("error").toString());
|
return R.error(res.get("error").toString());
|
||||||
}
|
}
|
||||||
private MessagePostProcessor messagePostProcessor() {
|
|
||||||
return message -> {
|
|
||||||
//设置有效期30分钟
|
|
||||||
message.getMessageProperties().setExpiration(String.valueOf(30 * 60 * 1000));
|
|
||||||
return message;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequestMapping("/orderInfo")
|
@RequestMapping("/orderInfo")
|
||||||
public R orderInfo(@RequestBody Map<String,Object> params) throws Exception{
|
public R orderInfo(@RequestBody Map<String,Object> params) throws Exception{
|
||||||
|
|||||||
Reference in New Issue
Block a user