|
@@ -3344,5 +3344,277 @@ public class TOrderController {
|
|
|
return acctSplitBunch;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 旧版退款成功回调
|
|
|
+ *
|
|
|
+ * @param request
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/oldNotifyRefund", method = RequestMethod.GET)
|
|
|
+ @ResponseBody
|
|
|
+ public Object oldNotifyRefund(HttpServletRequest request) {
|
|
|
+
|
|
|
+ String r6_Status = request.getParameter("ra_Status");
|
|
|
+
|
|
|
+ // 订单号
|
|
|
+ String sn = request.getParameter("r2_OrderNo");
|
|
|
+ // 退款订单号
|
|
|
+ String refundSn = request.getParameter("r3_RefundOrderNo");
|
|
|
+ String num = refundSn.substring(refundSn.length() - 1);
|
|
|
+ Integer refundNumber = Integer.valueOf(num);
|
|
|
+
|
|
|
+// LambdaQueryWrapper<TOrder> query = Wrappers.lambdaQuery();
|
|
|
+ LambdaQueryWrapper<TOrder> query = new LambdaQueryWrapper<>();
|
|
|
+ query.eq(TOrder::getSn,sn);
|
|
|
+ if(StringUtils.isEmpty(sn)){
|
|
|
+ return "error";
|
|
|
+ }
|
|
|
+// List<TOrder> list = orderService.list(query);
|
|
|
+// TOrder order = list.get(0);
|
|
|
+ TOrder order = orderService.getOne(query);
|
|
|
+ if (order == null) {
|
|
|
+ return "success";
|
|
|
+ }
|
|
|
+ if (order.getStatus() == 3) {
|
|
|
+ return "success";
|
|
|
+ }
|
|
|
+ // 判断退款版本号是否存在
|
|
|
+ String refundOrderNo = order.getRefundOrderNo();
|
|
|
+ if(StringUtils.isNotEmpty(refundOrderNo)) {
|
|
|
+ if(refundSn.equals(refundOrderNo)) {
|
|
|
+ try {
|
|
|
+ esTOrderService.updateDataById(order);
|
|
|
+ }catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return "success";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 订单商品数量
|
|
|
+ Integer productNumber = order.getProductNumber();
|
|
|
+ if (JoinpayConstant.r6_Status_100.equals(r6_Status)) {
|
|
|
+ // 设置退款版本号
|
|
|
+ order.setRefundOrderNo(refundSn);
|
|
|
+ // 已退款
|
|
|
+ if(productNumber >= refundNumber){
|
|
|
+ productNumber -= refundNumber;
|
|
|
+ order.setProductNumber(productNumber);
|
|
|
+ }
|
|
|
+ // r4_refundAmount: 退款金额
|
|
|
+ BigDecimal r4_refundAmount = new BigDecimal(request.getParameter("r4_RefundAmount_str"));
|
|
|
+ if(order.getRefundMarketingAmount()!=null){
|
|
|
+ r4_refundAmount =r4_refundAmount.add(order.getRefundMarketingAmount());
|
|
|
+ }
|
|
|
+ // price: 当前订单退完款剩余的金额
|
|
|
+ BigDecimal price = order.getPrice();
|
|
|
+ // 判断退款金额是否小于订单余额
|
|
|
+ if(r4_refundAmount.compareTo(price)==-1){
|
|
|
+ // refundAmount: 已退款金额
|
|
|
+ BigDecimal refundAmount = order.getRefundAmount();
|
|
|
+ if(refundAmount!=null){
|
|
|
+ // 如果已退款金额不为空,则加上退款金额
|
|
|
+ order.setRefundAmount(refundAmount.add(r4_refundAmount));
|
|
|
+ }else {
|
|
|
+ // 已退款金额
|
|
|
+ order.setRefundAmount(r4_refundAmount);
|
|
|
+ }
|
|
|
+ // 订单设置为支付状态
|
|
|
+ order.setStatus(1);
|
|
|
+ // 改变订单的金额,原先金额减去退款金额
|
|
|
+ order.setPrice(price.subtract(r4_refundAmount));
|
|
|
+ // 重置分销
|
|
|
+ if(order.getAltInfo()!=null) {
|
|
|
+ TEquipment tEquipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(order.getClientId()));
|
|
|
+ String altInfo = altInfoReset(tEquipment.getId(), price.subtract(r4_refundAmount));
|
|
|
+ order.setAltInfo(altInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 判断退款金额是否等于订单余额
|
|
|
+ if(r4_refundAmount.compareTo(price)==0){
|
|
|
+ BigDecimal refundAmount = order.getRefundAmount();
|
|
|
+// order.setAltInfo("");
|
|
|
+ order.setProductNumber(1);
|
|
|
+ if(refundAmount!=null){
|
|
|
+ order.setRefundAmount(refundAmount.add(r4_refundAmount));
|
|
|
+ // 全部退完款重新加回已退款的金额
|
|
|
+ order.setPrice(order.getPrice().add(refundAmount));
|
|
|
+ }else {
|
|
|
+ // 退款金额
|
|
|
+ order.setRefundAmount(r4_refundAmount);
|
|
|
+ }
|
|
|
+ order.setStatus(3);
|
|
|
+ if(order.getAltInfo()!=null) {
|
|
|
+ TEquipment tEquipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(order.getClientId()));
|
|
|
+ String altInfo = altInfoReset(tEquipment.getId(), order.getRefundAmount());
|
|
|
+ order.setAltInfo(altInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 支付平台产生的退款流水号
|
|
|
+ String r5_RefundTrxNo = request.getParameter("r5_RefundTrxNo");
|
|
|
+ order.setRefundTrxNo(r5_RefundTrxNo);
|
|
|
+ order.setRefundDate(new Date());
|
|
|
+ order.setModifyDate(new Date());
|
|
|
+// orderService.updateById(order);
|
|
|
+ String orderStatus = order.getOrderStatus();
|
|
|
+ if(StringUtils.isNotEmpty(orderStatus)&&orderStatus.equals("0")){
|
|
|
+ if(order.getStatus().toString().equals("3")){
|
|
|
+ TEquipment byClientId = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(order.getClientId()));
|
|
|
+ JSONObject kindData = new JSONObject();
|
|
|
+ String s = order.getId().toString();
|
|
|
+ if(s.length()>6){
|
|
|
+ s = s.substring(s.length()-6,s.length());
|
|
|
+ }
|
|
|
+ kindData.put("mealCode", s);
|
|
|
+ equipmentService.sentMessage(byClientId.getClientId(), PushUtils.buildJson("refuse_success", kindData.toString()).toString());
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ esTOrderService.updateDataById(order);
|
|
|
+ }catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }finally {
|
|
|
+ orderService.updateById(order);
|
|
|
+ }
|
|
|
+ return "success";
|
|
|
+ }
|
|
|
+
|
|
|
+ return "success";
|
|
|
+ }
|
|
|
+
|
|
|
+ public String altInfoReset(Long equipmentId, BigDecimal price) {
|
|
|
+ //获取分销 关联设备
|
|
|
+ TProportion proportion = R.getDataIfSuccess(szwlFeign.getProportion(String.valueOf(equipmentId)));
|
|
|
+
|
|
|
+ Integer type = proportion.getType();
|
|
|
+ JSONArray altInfo = new JSONArray();
|
|
|
+ JSONArray altNewInfo = new JSONArray();
|
|
|
+
|
|
|
+ BigDecimal adminProportion = null, agencyProportion = null, merchantProportion = null, personageProportion = null, selfProportion = null;
|
|
|
+ Long agencyId = proportion.getAgencyId();
|
|
|
+ Long merchantId = proportion.getMerchantId();
|
|
|
+ Long personageId = proportion.getPersonageId();
|
|
|
+
|
|
|
+ String orderType = null;
|
|
|
+
|
|
|
+
|
|
|
+ BigDecimal agencyAmount = null;
|
|
|
+ BigDecimal merchantAmount = null;
|
|
|
+ BigDecimal personageAmount = null;
|
|
|
+ BigDecimal selfAmount = null;
|
|
|
+
|
|
|
+ TJoinpayMch agencyMch = null;
|
|
|
+ TJoinpayMch merchantMch = null;
|
|
|
+ TJoinpayMch personageMch = null;
|
|
|
+ TJoinpayMch selfMch = null;
|
|
|
+
|
|
|
+ JSONObject agencyJson = null;
|
|
|
+ JSONObject merchantJson = null;
|
|
|
+ JSONObject personageJson = null;
|
|
|
+ JSONObject selfJson = null;
|
|
|
+
|
|
|
+ // 砍掉千6手续费
|
|
|
+// BigDecimal cutPrice = price.multiply(new BigDecimal(99.4)).divide(new BigDecimal(100));
|
|
|
+ //取消平台扣手续费
|
|
|
+ BigDecimal cutPrice = price.multiply(new BigDecimal(100)).divide(new BigDecimal(100));
|
|
|
+
|
|
|
+ switch (type) {
|
|
|
+
|
|
|
+ case 0:
|
|
|
+ agencyMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getAdminId())));
|
|
|
+
|
|
|
+ agencyProportion = proportion.getProportion();
|
|
|
+ adminProportion = proportion.getAdminProportion();
|
|
|
+ orderType = "1";
|
|
|
+ // 代理分销获得利润
|
|
|
+ agencyAmount = cutPrice.multiply(agencyProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+ agencyJson = new JSONObject();
|
|
|
+ agencyJson.put("altMchNo", agencyMch.getAltMchNo());
|
|
|
+ agencyJson.put("altAmount", agencyAmount.toString());
|
|
|
+ agencyJson.put("isGuar", "12");
|
|
|
+ altInfo.add(agencyJson);
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ agencyMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getAgencyId())));
|
|
|
+
|
|
|
+ selfMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getAdminId())));
|
|
|
+
|
|
|
+ agencyProportion = proportion.getAgencyProportion();
|
|
|
+ adminProportion = proportion.getAdminProportion();
|
|
|
+ selfProportion = proportion.getProportion();
|
|
|
+ orderType = "2";
|
|
|
+
|
|
|
+ BigDecimal refuseAmount = new BigDecimal(0.00);
|
|
|
+ if(agencyProportion.compareTo(refuseAmount) == 0||agencyProportion==null){
|
|
|
+// System.out.println("a等于b");
|
|
|
+ }else {
|
|
|
+ // 一级分销获得利润
|
|
|
+ agencyAmount = cutPrice.multiply(agencyProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+ agencyJson = new JSONObject();
|
|
|
+ agencyJson.put("altMchNo", agencyMch.getAltMchNo());
|
|
|
+ agencyJson.put("altAmount", agencyAmount.toString());
|
|
|
+ agencyJson.put("isGuar", "12");
|
|
|
+ altInfo.add(agencyJson);
|
|
|
+ }
|
|
|
+ // 商家自己分销获得利润
|
|
|
+ selfAmount = cutPrice.multiply(selfProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+ merchantJson = new JSONObject();
|
|
|
+ merchantJson.put("altMchNo", selfMch.getAltMchNo());
|
|
|
+ merchantJson.put("altAmount", selfAmount.toString());
|
|
|
+ merchantJson.put("isGuar", "12");
|
|
|
+ altInfo.add(merchantJson);
|
|
|
+
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ agencyMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getAgencyId())));
|
|
|
+
|
|
|
+ merchantMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getMerchantId())));
|
|
|
+
|
|
|
+ selfMch = R.getDataIfSuccess(szwlFeign.getMch(String.valueOf(proportion.getAdminId())));
|
|
|
+
|
|
|
+ agencyProportion = proportion.getAgencyProportion();
|
|
|
+ adminProportion = proportion.getAdminProportion();
|
|
|
+ merchantProportion = proportion.getMerchantProportion();
|
|
|
+ personageProportion = proportion.getPersonageProportion();
|
|
|
+ selfProportion = proportion.getProportion();
|
|
|
+ orderType = "3";
|
|
|
+ BigDecimal refuseAmount1 = new BigDecimal(0.00);
|
|
|
+ if(agencyProportion.compareTo(refuseAmount1) == 0||agencyProportion==null){
|
|
|
+// System.out.println("a等于b");
|
|
|
+ }else {
|
|
|
+ // 代理分销获得利润
|
|
|
+ agencyAmount = cutPrice.multiply(agencyProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+ agencyJson = new JSONObject();
|
|
|
+ agencyJson.put("altMchNo", agencyMch.getAltMchNo());
|
|
|
+ agencyJson.put("altAmount", agencyAmount.toString());
|
|
|
+ agencyJson.put("isGuar", "12");
|
|
|
+ altInfo.add(agencyJson);
|
|
|
+
|
|
|
+ }
|
|
|
+ if(merchantProportion.compareTo(refuseAmount1) == 0||merchantProportion==null){
|
|
|
+// System.out.println("a等于b");
|
|
|
+ }else {
|
|
|
+ // 经销商分销获得利润
|
|
|
+ merchantAmount = cutPrice.multiply(merchantProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+ merchantJson = new JSONObject();
|
|
|
+ merchantJson.put("altMchNo", merchantMch.getAltMchNo());
|
|
|
+ merchantJson.put("altAmount", merchantAmount.toString());
|
|
|
+ merchantJson.put("isGuar", "12");
|
|
|
+ altInfo.add(merchantJson);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 商家自己分销获得利润
|
|
|
+ selfAmount = cutPrice.multiply(selfProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
|
|
|
+ merchantJson = new JSONObject();
|
|
|
+ merchantJson.put("altMchNo", selfMch.getAltMchNo());
|
|
|
+ merchantJson.put("altAmount", selfAmount.toString());
|
|
|
+ merchantJson.put("isGuar", "12");
|
|
|
+ altInfo.add(merchantJson);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return altInfo.toString();
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|