|
@@ -60,7 +60,10 @@ public class TOrderController {
|
|
|
*/
|
|
|
@PostMapping("/refund")
|
|
|
public ResponseEntity<?> refund(@RequestBody TOrder torder) {
|
|
|
+ // 退款金额: refusePrice
|
|
|
BigDecimal refusePrice = torder.getPrice().setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+ // 退款数量: refundNumber
|
|
|
+ Integer refundNumber = torder.getProductNumber();
|
|
|
if(refusePrice.compareTo(new BigDecimal("0.00"))<=0){
|
|
|
return ResponseEntity
|
|
|
.status(HttpStatus.OK)
|
|
@@ -70,6 +73,8 @@ public class TOrderController {
|
|
|
.setMessage("退款金额非法"));
|
|
|
}
|
|
|
TOrder order = R.getDataIfSuccess(payFeign.getOrder(String.valueOf(torder.getId())));
|
|
|
+ // 已退款的金额: refundAmount
|
|
|
+ BigDecimal refundAmount = order.getRefundAmount();
|
|
|
TEquipment equipment = tEquipmentService.getById(order.getEquipmentId());
|
|
|
Long equipmentId = equipment.getId();
|
|
|
if (order.getProductName().equals("280充值")) {
|
|
@@ -98,19 +103,11 @@ public class TOrderController {
|
|
|
.setData(ifSuccess)
|
|
|
.setMessage(ifSuccess));
|
|
|
}
|
|
|
-// TAdmin admin = tAdminService.selectEntityById(order.getAdminId());
|
|
|
-// if(admin.getIsRefund()!=null&&admin.getIsRefund().equals("0")){
|
|
|
-//// return JsonMessage.error("机器设定不退款");
|
|
|
-// }
|
|
|
|
|
|
String notifyUrl = JoinpayConstant.Notify_Refund_Url;
|
|
|
|
|
|
JSONArray altInfoArray = JSONArray.parseArray(order.getAltInfo());
|
|
|
JSONArray altRefInfo = new JSONArray();
|
|
|
-// BigDecimal refusePrice = torder.getRefundAmount().setScale(2, RoundingMode.HALF_DOWN);
|
|
|
-// if(refusePrice.compareTo(new BigDecimal("0.00"))==0){
|
|
|
-// refusePrice = torder.getPrice();
|
|
|
-// }
|
|
|
BigDecimal p = BigDecimal.ZERO;
|
|
|
BigDecimal price = BigDecimal.ZERO;
|
|
|
//订单总金额
|
|
@@ -120,34 +117,7 @@ public class TOrderController {
|
|
|
}else {
|
|
|
sumPrice=sumPrice.add(order.getPrice()).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
}
|
|
|
-// for (int i = 0; i < altInfoArray.size(); i++) {
|
|
|
-// JSONObject altInfoObject = altInfoArray.getJSONObject(i);
|
|
|
-//
|
|
|
-// JSONObject refInfo = new JSONObject();
|
|
|
-// refInfo.put("altMchNo", altInfoObject.getString("altMchNo"));
|
|
|
-// String altAmount = altInfoObject.getString("altAmount");
|
|
|
-//
|
|
|
-// BigDecimal pri = new BigDecimal(order.getPrice().toString()).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
-//
|
|
|
-// if(refusePrice.compareTo(pri)<0){
|
|
|
-// //退部分的钱
|
|
|
-// BigDecimal altAmountPrice = new BigDecimal(altAmount);
|
|
|
-// altAmountPrice = altAmountPrice.multiply(refusePrice.divide(pri)).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
-// p = p.add(altAmountPrice);
|
|
|
-// refInfo.put("altRefAmount", altAmountPrice.toString());
|
|
|
-// }else {
|
|
|
-// //退全部的钱
|
|
|
-// BigDecimal altAmountPrice = new BigDecimal(altAmount);
|
|
|
-// p = p.add(altAmountPrice);
|
|
|
-// refInfo.put("altRefAmount", altInfoObject.getString("altAmount"));
|
|
|
-// }
|
|
|
-//
|
|
|
-//
|
|
|
-// price = price.add(altInfoObject.getBigDecimal("altAmount"));
|
|
|
-// if (!altInfoObject.getBigDecimal("altAmount").toString().equals("0.00")) {
|
|
|
-// altRefInfo.add(refInfo);
|
|
|
-// }
|
|
|
-// }
|
|
|
+
|
|
|
BigDecimal p8_MarketRefAmount = BigDecimal.ZERO;
|
|
|
for (int i = 0; i < altInfoArray.size(); i++) {
|
|
|
JSONObject altInfoObject = altInfoArray.getJSONObject(i);
|
|
@@ -161,36 +131,22 @@ public class TOrderController {
|
|
|
if(refusePrice.compareTo(pri)<0){
|
|
|
//退部分的钱
|
|
|
BigDecimal altAmountPrice = new BigDecimal(altAmount);
|
|
|
-// if(order.getRefundAmount()!=null){
|
|
|
-// altAmountPrice = altAmountPrice.multiply(refusePrice.divide(sumPrice.subtract(BigDecimal.valueOf(order.getRefundAmount())))).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
-// }else {
|
|
|
-//
|
|
|
-//// altAmountPrice = altAmountPrice.multiply(refusePrice.divide(pri)).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
-// };altAmountPrice
|
|
|
- altAmountPrice = altAmountPrice.multiply(refusePrice.divide(sumPrice,2,BigDecimal.ROUND_HALF_UP)).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+
|
|
|
+ altAmountPrice = altAmountPrice.multiply(refusePrice.divide(order.getPrice(),2,BigDecimal.ROUND_HALF_UP)).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
p = p.add(altAmountPrice);
|
|
|
refInfo.put("altRefAmount", altAmountPrice.toString());
|
|
|
if(order.getMarketingAmount()!=null){
|
|
|
- p8_MarketRefAmount = order.getMarketingAmount().multiply(refusePrice.divide(sumPrice,2,BigDecimal.ROUND_HALF_UP)).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+ p8_MarketRefAmount = order.getMarketingAmount().multiply(refusePrice.divide(order.getPrice(),2,BigDecimal.ROUND_HALF_UP)).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
}
|
|
|
}else {
|
|
|
//退全部的钱
|
|
|
-// if(order.getRefundAmount()!=null){
|
|
|
-// BigDecimal altAmountPrice = new BigDecimal(altAmount);
|
|
|
-// p = p.add(altAmountPrice);
|
|
|
-// refInfo.put("altRefAmount", altInfoObject.getString("altAmount"));
|
|
|
-// }else{
|
|
|
-// BigDecimal altAmountPrice = new BigDecimal(altAmount);
|
|
|
-// p = p.add(altAmountPrice);
|
|
|
-// refInfo.put("altRefAmount", altInfoObject.getString("altAmount"));
|
|
|
-// }
|
|
|
BigDecimal altAmountPrice = new BigDecimal(altAmount).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
- BigDecimal divide = altAmountPrice.divide(sumPrice,3,BigDecimal.ROUND_HALF_UP).setScale(3, RoundingMode.HALF_DOWN);
|
|
|
+ BigDecimal divide = altAmountPrice.divide(order.getPrice(),3,BigDecimal.ROUND_HALF_UP).setScale(3, RoundingMode.HALF_DOWN);
|
|
|
altAmountPrice = refusePrice.multiply(divide).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
p = p.add(altAmountPrice);
|
|
|
refInfo.put("altRefAmount", altAmountPrice.toString());
|
|
|
if(order.getMarketingAmount()!=null){
|
|
|
- p8_MarketRefAmount = order.getMarketingAmount().multiply(refusePrice.divide(sumPrice,2,BigDecimal.ROUND_HALF_UP)).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+ p8_MarketRefAmount = order.getMarketingAmount().multiply(refusePrice.divide(order.getPrice(),2,BigDecimal.ROUND_HALF_UP)).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -218,7 +174,7 @@ public class TOrderController {
|
|
|
String payPlatform = order.getPayPlatform();
|
|
|
if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
|
|
|
try {
|
|
|
- String refund = tShandeMchService.refund(order.getId(), orderService.initRefundSn(equipmentId).toString(), price, "", altRefInfo.toString());
|
|
|
+ String refund = tShandeMchService.refund(order.getId(), orderService.initRefundSn(equipmentId, refundNumber).toString(), price, "", altRefInfo.toString());
|
|
|
com.gexin.fastjson.JSONObject jsonObject = com.gexin.fastjson.JSON.parseObject(refund);
|
|
|
String sub_code = jsonObject.getString("sub_code");
|
|
|
//订单号
|
|
@@ -374,7 +330,7 @@ public class TOrderController {
|
|
|
}
|
|
|
} else {
|
|
|
try {
|
|
|
- String result = orderService.refund(order.getSn(), orderService.initRefundSn(equipmentId), refusePrice.subtract(p8_MarketRefAmount), p8_MarketRefAmount,"", notifyUrl, altRefInfo.toString());
|
|
|
+ String result = orderService.refund(order.getSn(), orderService.initRefundSn(equipmentId, refundNumber), refusePrice.subtract(p8_MarketRefAmount), p8_MarketRefAmount,"", notifyUrl, altRefInfo.toString());
|
|
|
if ("退款申请成功".equals(result)) {
|
|
|
order.setStatus(2);
|
|
|
if(StringUtils.isNotEmpty(order.getCoupons())){
|
|
@@ -425,6 +381,7 @@ public class TOrderController {
|
|
|
public ResponseEntity<?> refuseByXcu(String id) {
|
|
|
TOrder order = R.getDataIfSuccess(payFeign.getOrder(id));
|
|
|
String orderStatus = order.getOrderStatus();
|
|
|
+ Integer refundNumber = order.getProductNumber();
|
|
|
if(StringUtils.isNotEmpty(orderStatus)){
|
|
|
if(orderStatus.equals("1")||orderStatus.equals("2")){
|
|
|
return ResponseEntity
|
|
@@ -583,7 +540,7 @@ public class TOrderController {
|
|
|
String payPlatform = order.getPayPlatform();
|
|
|
if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
|
|
|
try {
|
|
|
- String refund = tShandeMchService.refund(order.getId(), orderService.initRefundSn(equipmentId).toString(), price, "", altRefInfo.toString());
|
|
|
+ String refund = tShandeMchService.refund(order.getId(), orderService.initRefundSn(equipmentId, refundNumber).toString(), price, "", altRefInfo.toString());
|
|
|
com.gexin.fastjson.JSONObject jsonObject = com.gexin.fastjson.JSON.parseObject(refund);
|
|
|
String sub_code = jsonObject.getString("sub_code");
|
|
|
//订单号
|
|
@@ -739,7 +696,7 @@ public class TOrderController {
|
|
|
}
|
|
|
} else {
|
|
|
try {
|
|
|
- String result = orderService.refund(order.getSn(), orderService.initRefundSn(equipmentId), refusePrice.subtract(p8_MarketRefAmount), p8_MarketRefAmount,"", notifyUrl, altRefInfo.toString());
|
|
|
+ String result = orderService.refund(order.getSn(), orderService.initRefundSn(equipmentId, refundNumber), refusePrice.subtract(p8_MarketRefAmount), p8_MarketRefAmount,"", notifyUrl, altRefInfo.toString());
|
|
|
if ("退款申请成功".equals(result)) {
|
|
|
order.setStatus(2);
|
|
|
if(StringUtils.isNotEmpty(order.getCoupons())){
|