|
@@ -910,5 +910,307 @@ public class TOrderController {
|
|
}
|
|
}
|
|
return altInfo;
|
|
return altInfo;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 退款
|
|
|
|
+ * @param
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @PostMapping("/oldRefund")
|
|
|
|
+ public ResponseEntity<?> oldRefund(@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)
|
|
|
|
+ .body(new ResultMessage()
|
|
|
|
+ .setCode(false)
|
|
|
|
+ .setData("")
|
|
|
|
+ .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充值")) {
|
|
|
|
+ return ResponseEntity
|
|
|
|
+ .status(HttpStatus.OK)
|
|
|
|
+ .body(new ResultMessage()
|
|
|
|
+ .setCode(false)
|
|
|
|
+ .setData("订单不退款")
|
|
|
|
+ .setMessage("订单不退款"));
|
|
|
|
+ }
|
|
|
|
+ if (order.getStatus().equals("0")) {
|
|
|
|
+ return ResponseEntity
|
|
|
|
+ .status(HttpStatus.OK)
|
|
|
|
+ .body(new ResultMessage()
|
|
|
|
+ .setCode(false)
|
|
|
|
+ .setData("订单非支付状态")
|
|
|
|
+ .setMessage("订单非支付状态"));
|
|
|
|
+ }
|
|
|
|
+ //判断是不是直连微信退款
|
|
|
|
+ if(StringUtils.isNotEmpty(order.getPayPlatform())&&order.getPayPlatform().equals("3")){
|
|
|
|
+ String ifSuccess = R.getDataIfSuccess(payFeign.refund(order.getSn(),refusePrice));
|
|
|
|
+ return ResponseEntity
|
|
|
|
+ .status(HttpStatus.OK)
|
|
|
|
+ .body(new ResultMessage()
|
|
|
|
+ .setCode(true)
|
|
|
|
+ .setData(ifSuccess)
|
|
|
|
+ .setMessage(ifSuccess));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String notifyUrl = JoinpayConstant.OLD_Notify_Refund_Url;
|
|
|
|
+
|
|
|
|
+ JSONArray altInfoArray = JSONArray.parseArray(order.getAltInfo());
|
|
|
|
+ JSONArray altRefInfo = new JSONArray();
|
|
|
|
+ BigDecimal p = BigDecimal.ZERO;
|
|
|
|
+ BigDecimal price = BigDecimal.ZERO;
|
|
|
|
+ //订单总金额
|
|
|
|
+ BigDecimal sumPrice = BigDecimal.ZERO;
|
|
|
|
+ if(order.getRefundAmount()!=null){
|
|
|
|
+ sumPrice=sumPrice.add(order.getPrice()).add(order.getRefundAmount()).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
|
+ }else {
|
|
|
|
+ sumPrice=sumPrice.add(order.getPrice()).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ BigDecimal p8_MarketRefAmount = BigDecimal.ZERO;
|
|
|
|
+ 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(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(order.getPrice(),2,BigDecimal.ROUND_HALF_UP)).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
|
+ }
|
|
|
|
+ }else {
|
|
|
|
+ //退全部的钱
|
|
|
|
+ BigDecimal altAmountPrice = new BigDecimal(altAmount).setScale(2, 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(order.getPrice(),2,BigDecimal.ROUND_HALF_UP)).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ price = price.add(altInfoObject.getBigDecimal("altAmount"));
|
|
|
|
+ if (!altInfoObject.getBigDecimal("altAmount").toString().equals("0.00")) {
|
|
|
|
+ altRefInfo.add(refInfo);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 特殊处理下:添加多一个平台方分销的金额
|
|
|
|
+ // 平台获得的收益
|
|
|
|
+// BigDecimal adminPrice = new BigDecimal(order.getPrice().toString()).subtract(price);
|
|
|
|
+ BigDecimal adminPrice = refusePrice.subtract(p).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
|
+ JSONObject refInfo = new JSONObject();
|
|
|
|
+ refInfo.put("altMchNo", JoinpayConstant.mch_no);
|
|
|
|
+ refInfo.put("altRefAmount", adminPrice.toString());
|
|
|
|
+ price = price.add(adminPrice);
|
|
|
|
+ if (!adminPrice.toString().equals("0.00")) {
|
|
|
|
+ altRefInfo.add(refInfo);
|
|
|
|
+ }
|
|
|
|
+ String text = "";
|
|
|
|
+
|
|
|
|
+ //需要知道订单是哪一个平台的,不能以账号的为标准 0或null为汇聚,1为杉德支付
|
|
|
|
+ String payPlatform = order.getPayPlatform();
|
|
|
|
+ if (StringUtils.isNotEmpty(payPlatform) && payPlatform.equals("1")) {
|
|
|
|
+ try {
|
|
|
|
+ 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");
|
|
|
|
+ //订单号
|
|
|
|
+ if (StringUtils.isNotEmpty(sub_code)&&sub_code.equals("REFUND_SUCCESS")) {
|
|
|
|
+ order.setStatus(3);
|
|
|
|
+ String refund_settle_amount = jsonObject.getString("refund_settle_amount");
|
|
|
|
+ String refund_plat_trx_no = jsonObject.getString("refund_plat_trx_no");
|
|
|
|
+ order.setRefundTrxNo(refund_plat_trx_no);
|
|
|
|
+ order.setRefundAmount(new BigDecimal(refund_settle_amount));
|
|
|
|
+ order.setRefundDate(new Date());
|
|
|
|
+ payFeign.updateOrder(order);
|
|
|
|
+ //金额表今日金额要改 要分类型
|
|
|
|
+ TAdmin admin = tAdminService.getById(order.getAdminId());
|
|
|
|
+ Integer orderType = order.getType();
|
|
|
|
+ switch (orderType) {
|
|
|
|
+ case 0:
|
|
|
|
+ BigDecimal agencyProportion = order.getAgencyProportion();
|
|
|
|
+ // 代理分销获得利润
|
|
|
|
+ BigDecimal agencyPrice = price.multiply(agencyProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
|
+ //修改金额表的今日金额
|
|
|
|
+ LambdaQueryWrapper<TShandeMch> query = Wrappers.lambdaQuery();
|
|
|
|
+ query.eq(TShandeMch::getAdminId,order.getAdminId());
|
|
|
|
+ List<TShandeMch> list = tShandeMchService.list(query);
|
|
|
|
+ if(list.size()>0){
|
|
|
|
+ TShandeMch shandeMch = list.get(0);
|
|
|
|
+ BigDecimal todayBalance = shandeMch.getTodayBalance();
|
|
|
|
+ todayBalance = todayBalance.subtract(agencyPrice).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
|
+ shandeMch.setTodayBalance(todayBalance);
|
|
|
|
+ shandeMch.setModifyDate(new Date());
|
|
|
|
+ tShandeMchService.updateById(shandeMch);
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case 1:
|
|
|
|
+ BigDecimal agencyProportion1 = order.getAgencyProportion();
|
|
|
|
+ BigDecimal merchantProportion1 = order.getMerchantProportion();
|
|
|
|
+ // 代理分销获得利润
|
|
|
|
+ BigDecimal agencyPrice1 = price.multiply(agencyProportion1.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
|
+ // 经销商分销获得利润
|
|
|
|
+ BigDecimal merchantAmount1 = price.multiply(merchantProportion1.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
|
+ //修改代理金额表的今日金额
|
|
|
|
+
|
|
|
|
+ LambdaQueryWrapper<TShandeMch> query1 = Wrappers.lambdaQuery();
|
|
|
|
+ query1.eq(TShandeMch::getAdminId,order.getAgencyId());
|
|
|
|
+ List<TShandeMch> list1 = tShandeMchService.list(query1);
|
|
|
|
+ if(list1.size()>0){
|
|
|
|
+ TShandeMch shandeMch = list1.get(0);
|
|
|
|
+ BigDecimal todayBalance = shandeMch.getTodayBalance();
|
|
|
|
+ todayBalance = todayBalance.subtract(agencyPrice1).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
|
+ shandeMch.setTodayBalance(todayBalance);
|
|
|
|
+ shandeMch.setModifyDate(new Date());
|
|
|
|
+ tShandeMchService.updateById(shandeMch);
|
|
|
|
+ }
|
|
|
|
+ //修改经销商金额表的今日金额;
|
|
|
|
+ LambdaQueryWrapper<TShandeMch> query2 = Wrappers.lambdaQuery();
|
|
|
|
+ query2.eq(TShandeMch::getAdminId,admin.getId());
|
|
|
|
+ List<TShandeMch> list2 = tShandeMchService.list(query2);
|
|
|
|
+ if(list2.size()>0){
|
|
|
|
+ TShandeMch shandeMch = list2.get(0);
|
|
|
|
+ BigDecimal todayBalance = shandeMch.getTodayBalance();
|
|
|
|
+ todayBalance = todayBalance.subtract(merchantAmount1).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
|
+ shandeMch.setTodayBalance(todayBalance);
|
|
|
|
+ shandeMch.setModifyDate(new Date());
|
|
|
|
+ tShandeMchService.updateById(shandeMch);
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case 2:
|
|
|
|
+
|
|
|
|
+ BigDecimal agencyProportion2 = order.getAgencyProportion();
|
|
|
|
+ BigDecimal merchantProportion2 = order.getMerchantProportion();
|
|
|
|
+ BigDecimal personageProportion2 = order.getPersonageProportion();
|
|
|
|
+ // 代理分销获得利润
|
|
|
|
+ BigDecimal agencyAmount = price.multiply(agencyProportion2.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
|
+ // 经销商分销获得利润
|
|
|
|
+ BigDecimal merchantAmount = price.multiply(merchantProportion2.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
|
+ // 经销商分销获得利润
|
|
|
|
+ BigDecimal personageAmount = price.multiply(personageProportion2.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
|
+ //修改代理金额表的今日金额
|
|
|
|
+ LambdaQueryWrapper<TShandeMch> query3 = Wrappers.lambdaQuery();
|
|
|
|
+ query3.eq(TShandeMch::getAdminId,order.getAgencyId());
|
|
|
|
+ List<TShandeMch> list3 = tShandeMchService.list(query3);
|
|
|
|
+ if(list3.size()>0){
|
|
|
|
+ TShandeMch shandeMch = list3.get(0);
|
|
|
|
+ BigDecimal todayBalance = shandeMch.getTodayBalance();
|
|
|
|
+ todayBalance = todayBalance.subtract(agencyAmount).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
|
+ shandeMch.setTodayBalance(todayBalance);
|
|
|
|
+ shandeMch.setModifyDate(new Date());
|
|
|
|
+ tShandeMchService.updateById(shandeMch);
|
|
|
|
+ }
|
|
|
|
+ //修改经销商金额表的今日金额
|
|
|
|
+ LambdaQueryWrapper<TShandeMch> query4 = Wrappers.lambdaQuery();
|
|
|
|
+ query4.eq(TShandeMch::getAdminId,order.getMerchantId());
|
|
|
|
+ List<TShandeMch> list4 = tShandeMchService.list(query4);
|
|
|
|
+ if(list4.size()>0){
|
|
|
|
+ TShandeMch shandeMch = list4.get(0);
|
|
|
|
+ BigDecimal todayBalance = shandeMch.getTodayBalance();
|
|
|
|
+ todayBalance = todayBalance.subtract(merchantAmount).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
|
+ shandeMch.setTodayBalance(todayBalance);
|
|
|
|
+ shandeMch.setModifyDate(new Date());
|
|
|
|
+ tShandeMchService.updateById(shandeMch);
|
|
|
|
+ }
|
|
|
|
+ //修改终端金额表的今日金额
|
|
|
|
+ LambdaQueryWrapper<TShandeMch> query5 = Wrappers.lambdaQuery();
|
|
|
|
+ query5.eq(TShandeMch::getAdminId,admin.getId());
|
|
|
|
+ List<TShandeMch> list5 = tShandeMchService.list(query5);
|
|
|
|
+ if(list5.size()>0){
|
|
|
|
+ TShandeMch shandeMch = list5.get(0);
|
|
|
|
+ BigDecimal todayBalance = shandeMch.getTodayBalance();
|
|
|
|
+ todayBalance = todayBalance.subtract(personageAmount).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
|
+ shandeMch.setTodayBalance(todayBalance);
|
|
|
|
+ shandeMch.setModifyDate(new Date());
|
|
|
|
+ tShandeMchService.updateById(shandeMch);
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ TOrder order1 = R.getDataIfSuccess(payFeign.getOrder(String.valueOf(torder.getId())));
|
|
|
|
+ order1.setModifyDate(new Date());
|
|
|
|
+ esTOrderService.updateDataById(order1);
|
|
|
|
+ return ResponseEntity
|
|
|
|
+ .status(HttpStatus.OK)
|
|
|
|
+ .body(new ResultMessage()
|
|
|
|
+ .setCode(true)
|
|
|
|
+ .setData("申请退款已成功")
|
|
|
|
+ .setMessage("申请退款已成功"));
|
|
|
|
+ } else {
|
|
|
|
+ return ResponseEntity
|
|
|
|
+ .status(HttpStatus.OK)
|
|
|
|
+ .body(new ResultMessage()
|
|
|
|
+ .setCode(false)
|
|
|
|
+ .setData("申请退款失败")
|
|
|
|
+ .setMessage(refund));
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ try {
|
|
|
|
+ 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())){
|
|
|
|
+ //设置退款营销金额
|
|
|
|
+ if(order.getRefundMarketingAmount()!=null){
|
|
|
|
+ //累加
|
|
|
|
+ order.setRefundMarketingAmount(order.getRefundMarketingAmount().add(p8_MarketRefAmount));
|
|
|
|
+ }else {
|
|
|
|
+ order.setRefundMarketingAmount(p8_MarketRefAmount);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ order.setRefundTrxNo(String.valueOf(refusePrice));
|
|
|
|
+ payFeign.updateOrder(order);
|
|
|
|
+ return ResponseEntity
|
|
|
|
+ .status(HttpStatus.OK)
|
|
|
|
+ .body(new ResultMessage()
|
|
|
|
+ .setCode(true)
|
|
|
|
+ .setData("申请退款已成功")
|
|
|
|
+ .setMessage("申请退款已成功"));
|
|
|
|
+ }else {
|
|
|
|
+ return ResponseEntity
|
|
|
|
+ .status(HttpStatus.OK)
|
|
|
|
+ .body(new ResultMessage()
|
|
|
|
+ .setCode(false)
|
|
|
|
+ .setData("申请退款失败")
|
|
|
|
+ .setMessage("申请退款失败"));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ return ResponseEntity
|
|
|
|
+ .status(HttpStatus.OK)
|
|
|
|
+ .body(new ResultMessage()
|
|
|
|
+ .setCode(true)
|
|
|
|
+ .setData("申请退款已成功")
|
|
|
|
+ .setMessage("申请退款已成功"));
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|