Преглед изворни кода

修正销售量以及优化订单退款

soobin пре 2 година
родитељ
комит
e0b027e2cf
1 измењених фајлова са 197 додато и 133 уклоњено
  1. 197 133
      src/main/java/com/szwl/controller/TOrderController.java

+ 197 - 133
src/main/java/com/szwl/controller/TOrderController.java

@@ -29,6 +29,7 @@ import io.swagger.annotations.ApiOperation;
 import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.ResponseEntity;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.servlet.view.RedirectView;
 
@@ -299,9 +300,6 @@ public class TOrderController {
                 adminProportion = proportion.getAdminProportion();
                 selfProportion = proportion.getProportion();
                 orderType = "2";
-//            if(totalMoney.compareTo(refuseAmount) == 0){
-////                System.out.println("a等于b");
-//            }
                 BigDecimal refuseAmount = new BigDecimal(0.00);
                 if(agencyProportion.compareTo(refuseAmount) == 0||agencyProportion==null){
 //                System.out.println("a等于b");
@@ -373,13 +371,6 @@ public class TOrderController {
                     merchantJson.put("isGuar", "12");
                     altInfo.add(merchantJson);
                 }
-                // 自己分销获得利润
-//                personageAmount = cutPrice.multiply(personageProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
-//                personageJson = new JSONObject();
-//                personageJson.put("altMchNo", personageMch.getAltMchNo());
-//                personageJson.put("altAmount", personageAmount.toString());
-//                personageJson.put("isGuar", "12");
-//                altInfo.add(personageJson);
                 // 商家自己分销获得利润
                 selfAmount = cutPrice.multiply(selfProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
                 merchantJson = new JSONObject();
@@ -548,23 +539,6 @@ public class TOrderController {
                 //不存在
                 return JsonMessage.success("1");
             }
-//            IPage<TPromoCode> pagePromoCode = R.getDataIfSuccess(szwlFeign.getTPromoCode(code));
-//            List<TPromoCode> codeList = pagePromoCode.getRecords();
-//            if (codeList.size() == 0) {
-//                //不存在
-//                return JsonMessage.success("1");
-//            }
-//            for (TPromoCode cod : codeList) {
-//                if(!cod.getAdminId().equals("1")){
-//                    String adminId = cod.getAdminId();
-//                    String adminId1 = String.valueOf(equipment.getAdminId());
-//                    if (adminId.equals(adminId1)) {
-//                        promoCode = cod;
-//                    }
-//                }else{
-//                    promoCode = cod;
-//                }
-//            }
             if (promoCode.getId() == null) {
                 //不存在
                 return JsonMessage.success("1");
@@ -781,13 +755,6 @@ public class TOrderController {
                     merchantJson.put("isGuar", "12");
                     altInfo.add(merchantJson);
                 }
-                // 自己分销获得利润
-//                personageAmount = cutPrice.multiply(personageProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
-//                personageJson = new JSONObject();
-//                personageJson.put("altMchNo", personageMch.getAltMchNo());
-//                personageJson.put("altAmount", personageAmount.toString());
-//                personageJson.put("isGuar", "12");
-//                altInfo.add(personageJson);
                 // 商家自己分销获得利润
                 selfAmount = cutPrice.multiply(selfProportion.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_DOWN);
                 merchantJson = new JSONObject();
@@ -960,23 +927,6 @@ public class TOrderController {
                 //不存在
                 return JsonMessage.success("1");
             }
-//            IPage<TPromoCode> pagePromoCode = R.getDataIfSuccess(szwlFeign.getTPromoCode(code));
-//            List<TPromoCode> codeList = pagePromoCode.getRecords();
-//            if (codeList.size() == 0) {
-//                //不存在
-//                return JsonMessage.success("1");
-//            }
-//            for (TPromoCode cod : codeList) {
-//                if(!cod.getAdminId().equals("1")){
-//                    String adminId = cod.getAdminId();
-//                    String adminId1 = String.valueOf(equipment.getAdminId());
-//                    if (adminId.equals(adminId1)) {
-//                        promoCode = cod;
-//                    }
-//                }else{
-//                    promoCode = cod;
-//                }
-//            }
             if (promoCode.getId() == null) {
                 //不存在
                 return JsonMessage.success("1");
@@ -1044,6 +994,9 @@ public class TOrderController {
         }
 
         Integer type = proportion.getType();
+        if (type == null) {
+            return JsonMessage.error("设备商家未完成分销设置");
+        }
         JSONArray altInfo = new JSONArray();
         JSONArray altNewInfo = new JSONArray();
 
@@ -1054,9 +1007,6 @@ public class TOrderController {
 
         String orderType = null;
 
-        if (type == null) {
-            return JsonMessage.error("设备商家未完成分销设置");
-        }
 
         BigDecimal agencyAmount = null;
         BigDecimal merchantAmount = null;
@@ -1283,7 +1233,7 @@ public class TOrderController {
         order2.setPrice(price);
         order2.setClientId(equipment.getClientId());
         order2.setEquipmentId(equipmentId);
-        order2.setFrpCode(frpCode1);
+        order2.setFrpCode(frpCode2);
         order2.setAltInfo(altInfo.toString());
         order2.setStatus(0);
         order2.setPayPlatform(payPlatform);
@@ -1369,61 +1319,40 @@ public class TOrderController {
     @ApiOperation(value = "购物车 请求在线支付 二码合一")
     @PostMapping("/carsPay")
     public Object carsPay(String clientId, @RequestBody Map<String,String> productNameMap) {
-//        IPage<?> iPage = R.getDataIfSuccess(szwlFeign.testPay("1"));
-//        productName = "玫瑰精灵";
         if(productNameMap==null){
             return  JsonMessage.error("数据出错");
         }
+
         StringBuffer productName1 = new StringBuffer();
         StringBuffer note = new StringBuffer();
         StringBuffer productName = new StringBuffer();
+        Integer productNumber = 0;
+
         TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(clientId));
         if(equipment==null||equipment.getId()==null){
             return JsonMessage.error("找不到设备");
         }
+
         BigDecimal price = new BigDecimal("0.00");
-//        JSONObject mapList = JSON.parseObject(productNameMap);
         TEquipmentDesc equipmentDesc = R.getDataIfSuccess(szwlFeign.findEquipmentById(equipment.getId()));
         if(equipmentDesc==null||equipmentDesc.getEquipmentId()==null||equipmentDesc.getPayType()==null||equipmentDesc.getPayType().equals("0")){
-            //1,type=0,原始设定,没有第二件半价
+            // 1、type=0,原始设定,没有第二件半价
             for (String key : productNameMap.keySet()) {
-//                System.out.println("key= "+ key + " and value= " + productNameMap.get(key));
                 String entryValue = String.valueOf(productNameMap.get(key));
-//                String key = String.valueOf(entry.getKey());
-//                String entryValue = String.valueOf(entry.getValue());
                 List<String> value = JSON.parseArray(entryValue, String.class);
                 List<TPromoCode> promoCodeList = new ArrayList<>();
-                //1,校验优惠码
+                // 1、校验优惠码
                 if(value.size()>0){
                     for(String code:value){
                         if(!code.equals("0")){
-                            TPromoCode promoCode = new TPromoCode();
+                            TPromoCode promoCode;
                             ResponseModel<TPromoCode> tPromoCodeResponseModel = szwlFeign.selectTPromoCode(code, equipment.getAdminId().toString());
                             TPromoCode tPromoCode = tPromoCodeResponseModel.getData();
-//                            TPromoCode tPromoCode = R.getDataIfSuccess(szwlFeign.selectTPromoCode(code, equipment.getAdminId().toString()));
                             promoCode = tPromoCode;
                             if (tPromoCode == null||tPromoCode.getId()==null) {
                                 //不存在
                                 return JsonMessage.success("1");
                             }
-//                            IPage<TPromoCode> pagePromoCode = R.getDataIfSuccess(szwlFeign.getTPromoCode(code));
-//                            List<TPromoCode> codeList = pagePromoCode.getRecords();
-//
-//                            if (codeList.size() == 0) {
-//                                //不存在
-//                                return JsonMessage.success("1");
-//                            }
-//                            for (TPromoCode cod : codeList) {
-//                                if(!cod.getAdminId().equals("1")){
-//                                    String adminId = cod.getAdminId();
-//                                    String adminId1 = String.valueOf(equipment.getAdminId());
-//                                    if (adminId.equals(adminId1)) {
-//                                        promoCode = cod;
-//                                    }
-//                                }else{
-//                                    promoCode = cod;
-//                                }
-//                            }
                             Date lastUseDate = null;
                             if (promoCode != null) {
                                 lastUseDate = promoCode.getLastUseDate();
@@ -1466,10 +1395,11 @@ public class TOrderController {
                 String[] productNum = key.split("-");
                 String productNamea = productNum[0];
                 String num = productNum[1];
+                productNumber += Integer.valueOf(num);
                 productName.append(productNamea).append(num);
                 note.append(productNamea).append(num).append(":");
                 productName1.append(productNamea).append(num);
-                //确定价格,然后叠加R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipmentId), productName));
+                //确定价格,然后叠加
                 TProduct product = R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipment.getId()), productNamea));
                 if (product == null) {
                     return JsonMessage.error("找不到商品");
@@ -1504,7 +1434,6 @@ public class TOrderController {
             //2,type=1,第二件半价
             //2.1 判定是否有第二件,有多少个第二件半价
             for (String key : productNameMap.keySet()) {
-//                System.out.println("key= "+ key + " and value= " + productNameMap.get(key));
                 String entryValue = String.valueOf(productNameMap.get(key));
                 List<String> value = JSON.parseArray(entryValue, String.class);
                 String[] productNum = key.split("-");
@@ -1561,11 +1490,6 @@ public class TOrderController {
 
         Long equipmentId = equipment.getId();
         //查找商品
-//        TProduct product =  R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipmentId), productName.toString()));
-//        if (product == null) {
-//            return JsonMessage.error("找不到商品");
-//        }
-
         if (BigDecimal.ZERO.compareTo(price) >= 0) {
             return JsonMessage.error("商品价格异常");
         }
@@ -1583,6 +1507,9 @@ public class TOrderController {
         }
 
         Integer type = proportion.getType();
+        if (type == null) {
+            return JsonMessage.error("设备商家未完成分销设置");
+        }
         JSONArray altInfo = new JSONArray();
         JSONArray altNewInfo = new JSONArray();
 
@@ -1593,9 +1520,6 @@ public class TOrderController {
 
         String orderType = null;
 
-        if (type == null) {
-            return JsonMessage.error("设备商家未完成分销设置");
-        }
 
         BigDecimal agencyAmount = null;
         BigDecimal merchantAmount = null;
@@ -1740,8 +1664,6 @@ public class TOrderController {
                 merchantJson.put("isGuar", "12");
                 altInfo.add(merchantJson);
                 break;
-
-
         }
 
 
@@ -1781,6 +1703,7 @@ public class TOrderController {
         order.setAltInfo(altInfo.toString());
         order.setStatus(0);
         order.setType(type);
+        order.setProductNumber(productNumber);
         if(type==0){
             order.setAdminProportion(adminProportion);
             order.setAgencyProportion(agencyProportion);
@@ -1820,10 +1743,11 @@ public class TOrderController {
         order2.setPrice(price);
         order2.setClientId(equipment.getClientId());
         order2.setEquipmentId(equipmentId);
-        order2.setFrpCode(frpCode1);
+        order2.setFrpCode(frpCode2);
         order2.setAltInfo(altInfo.toString());
         order2.setStatus(0);
         order2.setType(type);
+        order2.setProductNumber(productNumber);
         if(type==0){
             order2.setAdminProportion(adminProportion);
             order2.setAgencyProportion(agencyProportion);
@@ -1934,6 +1858,7 @@ public class TOrderController {
         StringBuffer productName1 = new StringBuffer();
         StringBuffer note = new StringBuffer();
         StringBuffer productName = new StringBuffer();
+        Integer productNumber = 0;
         TEquipment equipment = R.getDataIfSuccess(szwlFeign.findEquipmentByClientId(clientId));
         if(equipment==null||equipment.getId()==null){
             return JsonMessage.error("找不到设备");
@@ -2012,6 +1937,7 @@ public class TOrderController {
                 String[] productNum = key.split("-");
                 String productNamea = productNum[0];
                 String num = productNum[1];
+                productNumber += Integer.valueOf(num);
                 TProduct product = R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipment.getId()), productNamea));
                 if (product == null) {
                     return JsonMessage.error("找不到商品");
@@ -2384,6 +2310,7 @@ public class TOrderController {
         order.setStatus(0);
         order.setType(type);
         order.setMarketingAmount(marketingAmount);
+        order.setProductNumber(productNumber);
         if(couponList.size()>0){
             order.setCoupons(couponList.toString());
         }
@@ -3033,6 +2960,11 @@ public class TOrderController {
 
         // 订单号
         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();
         query.eq(TOrder::getSn,sn);
         if(StringUtils.isEmpty(sn)){
@@ -3047,44 +2979,71 @@ public class TOrderController {
             return "success";
         }
 
+        // 订单商品数量
+        Integer productNumber = order.getProductNumber();
         if (JoinpayConstant.r6_Status_100.equals(r6_Status)) {
 
             // 已退款
-            order.setStatus(3);
+            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(0);
                 if(refundAmount!=null){
                     order.setRefundAmount(refundAmount.add(r4_refundAmount));
-                    order.setPrice(order.getPrice().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);
+                }
             }
-            // 退款金额
-//            order.setRefundAmount(new BigDecimal(request.getParameter("r4_RefundAmount_str")));
+
             // 支付平台产生的退款流水号
             String r5_RefundTrxNo = request.getParameter("r5_RefundTrxNo");
             order.setRefundTrxNo(r5_RefundTrxNo);
             order.setRefundDate(new Date());
             order.setModifyDate(new Date());
-            orderService.updateById(order);
+//            orderService.updateById(order);
             String orderStatus = order.getOrderStatus();
             if(StringUtils.isNotEmpty(orderStatus)&&orderStatus.equals("0")){
                 if(order.getStatus().toString().equals("3")){
@@ -3103,6 +3062,8 @@ public class TOrderController {
                 esTOrderService.updateDataById(order);
             }catch (Exception e) {
                 e.printStackTrace();
+            }finally {
+                orderService.updateById(order);
             }
             return "success";
         }
@@ -3124,7 +3085,6 @@ public class TOrderController {
         LambdaQueryWrapper<TOrderTask> query = Wrappers.lambdaQuery();
         query.eq(TOrderTask::getSn,order.getSn());
         TOrderTask orderTask = orderTaskService.getOne(query);
-//        TOrderTask orderTask = orderTaskService.getById(order.getId());
         orderTask.setStatus(order.getStatus());
         orderTaskService.updateById(orderTask);
         return R.ok();
@@ -3192,21 +3152,11 @@ public class TOrderController {
             }
 
             orderService.updateById(order);
-//            TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(order.getAdminId())));
             JSONObject kindData = new JSONObject();
             kindData.put("sn", order.getSn());
             kindData.put("productName", order.getProductName());
-//            List<String> codes = new ArrayList<>();
-//            for (int i = 0; i < number; i++) {
-//                String code = orderService.initSn(order.getEquipmentId());
-//                StringBuffer str = new StringBuffer();
-//                str.append(code.substring(0, 6));
-//                codes.add(str.toString());
-//            }
             String mont = order.getRefundTrxNo();
             Long data = Calendar.getInstance().getTimeInMillis();
-//            Long month = 30L * 24L * 60L * 60L * 1000L;
-//            Long d = data + month;
             Float month = Float.valueOf(mont);
             Float mm = month*10;
             String m = String.valueOf(mm);
@@ -3219,17 +3169,6 @@ public class TOrderController {
             String sd = sdf.format(new Date(Long.parseLong(String.valueOf(d))));
             Date lastUseDate = new Date(Long.parseLong(String.valueOf(d)));
             szwlFeign.addPromoCode(String.valueOf(order.getAdminId()),lastUseDate,number);
-//            for (String code : codes) {
-//                TPromoCode promoCode = new TPromoCode();
-//                promoCode.setCode(Long.parseLong(code));
-//                promoCode.setAdminId(String.valueOf(order.getAdminId()));
-//                promoCode.setIsUse("0");
-//                promoCode.setDiscount(0f);
-//                promoCode.setLastUseDate(lastUseDate);
-//                promoCode.setCreateDate(new Date());
-//                promoCode.setUserName(admin.getUsername());
-//                promoCodeService.save(promoCode);
-//            }
 
             return "支付成功";
         }
@@ -3334,7 +3273,6 @@ public class TOrderController {
         }
         Long equipmentId = equipment.getId();
         BigDecimal price = new BigDecimal(pri);
-//        TAdmin admin = adminService.find(equipment.getAdminId());
         TAdmin admin = R.getDataIfSuccess(szwlFeign.getAdmin(String.valueOf(equipment.getAdminId())));
         if (admin == null) {
             return JsonMessage.error("找不到设备商家");
@@ -3342,11 +3280,7 @@ public class TOrderController {
         JSONArray altInfo = new JSONArray();
 
 
-//        Long agencyId = admin.getAgencyId();
-//        Long merchantId = admin.getMerchantId();
-//        Long personageId = admin.getPersonageId();
-//        Admin.Type type = admin.getType();
-//        Order.Type orderType = null;
+
         String orderType = null;
         TProportion proportion = R.getDataIfSuccess(szwlFeign.getProportion(String.valueOf(equipment.getId())));
         Integer type = proportion.getType();
@@ -3362,9 +3296,6 @@ public class TOrderController {
                 orderType = "3";
                 break;
         }
-//        TOrder order = new TOrder(sn, null, productName, price, equipment.getClientId(), equipmentId,
-//                orderType, admin.getId(), agencyId, merchantId, personageId,
-//                null, altInfo.toString(), null, null, null, null, Order.Status.pay);
 
         TProduct product =  R.getDataIfSuccess(szwlFeign.getProduct(String.valueOf(equipmentId), productName));
         TOrder order = new TOrder();
@@ -3393,5 +3324,138 @@ public class TOrderController {
         }
         return JsonMessage.success("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();
+    }
 }