zhijiezhao před 6 měsíci
rodič
revize
aa1a8f9c25

+ 169 - 0
src/main/java/com/caimei/modules/order/service/SplitAccountService.java

@@ -45,6 +45,175 @@ public class SplitAccountService extends BaseService {
     @Resource
     private CmReportingClubMapper cmReportingClubMapper;
 
+    /**
+     *  !!!!注意:分帐时合利宝收费规则为谁分收谁0.1%手续费,这里是供应商承担的,如果要采美,服务商承担各自的费用,要提前计算好!!!
+     *
+     * 当前版本分帐逻辑变更,前台传入分帐帐号及金额,直接分帐
+     * splits : "E123456,10;E123456,20;E123456,30"
+     *
+     * @param shopOrderId
+     */
+    @Transactional(readOnly = false, rollbackFor = Exception.class)
+    public void SplitByHand(String shopOrderId, String splits) {
+        logger.info("【手动分账开始】>>>>>>>>>>手动分账");
+        /** todo
+         * 校验splits参数总金额是否正确
+         */
+
+        String[] split = splits.split(";");
+        if (split.length <= 0) {
+            logger.info("分帐帐号及金额输入不正确!");
+            return;
+        }
+        ArrayList<AccountPayOrder.AccountPayOrderExt.SplitBillRule> splitBillRules = new ArrayList<>();
+        // 保存分帐参数,固定三方:成本,采美,服务商
+        List<SplitAccountPo> splitBillDetail = new ArrayList<>();
+        ShopOrderVo shopOrder = newOrderDao.getShopOrderListByOrderId(Integer.valueOf(shopOrderId));
+        Double costPrice = 0d;
+        for (int i = 0; i < split.length; i++) {
+            AccountPayOrder.AccountPayOrderExt.SplitBillRule splitBillRule = new AccountPayOrder.AccountPayOrderExt.SplitBillRule();
+            String[] rules = split[i].split(",");
+            /**
+             * splits : "E123456,10;E123456,20;E123456,30"
+             */
+            if (i > 0) {
+                BigDecimal cost = BigDecimal.valueOf(Double.parseDouble(rules[1]));
+                splitBillRule.setSplitBillAmount(cost);
+                splitBillRule.setSplitBillMerchantNo(rules[0]);
+                splitBillRules.add(splitBillRule);
+            }
+            /**
+             * cm_split_account 分帐详情参数
+             */
+            Integer productType = 0 == i ? 1 : 1 == i ? 3 : 5;
+            Integer type = 0 == i ? 4 : 5;
+            SplitAccountPo splitAccount = new SplitAccountPo();
+            splitAccount.setOrderId(shopOrder.getOrderId());
+            splitAccount.setShopOrderId(shopOrder.getShopOrderId());
+            // 前台获取金额
+            splitAccount.setSplitAccount(Double.parseDouble(rules[1]));
+            splitAccount.setProductType(productType);
+            splitAccount.setType(type);
+            // 前台获取
+            splitAccount.setSubUserNo(rules[0]);
+            splitBillDetail.add(splitAccount);
+
+            if (0 == i) {
+                costPrice = Double.parseDouble(rules[1]);
+            }
+        }
+
+        if (null != splitBillRules && splitBillRules.size() > 0) {
+            //第三方分账接口
+            try {
+                AccountPayOrder accountPayOrder = new AccountPayOrder();
+                accountPayOrder.setP1_bizType("AccountPaySub");
+                accountPayOrder.setP2_signType("MD5");
+                String format1 = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss.SSS").format(new Date());
+                accountPayOrder.setP3_timestamp(format1);
+                String substring = format1.substring(20);
+                // fz+当前微秒时间+原唯一订单号
+                accountPayOrder.setP4_orderId("FZ" + substring + shopOrderId);
+                //付款账户子订单绑定商户号(付款商户商编)
+                accountPayOrder.setP5_customerNumber(shopOrder.getSplitCode());
+                AccountPayOrder.AccountPayOrderExt accountPayOrderExt = new AccountPayOrder.AccountPayOrderExt();
+                //收款账户商编  填写splitBillRules时候不填写MerchantNo,Amount并且即使填写这两个参数不生效!!
+                //accountPayOrderExt.setInMerchantNo(splitMoneyVo.getName());
+                //accountPayOrderExt.setAmount(splitMoneyVo.getSplitMoney());
+                accountPayOrderExt.setOrderType(AccountPayOrderType.TRANSFER);
+                accountPayOrderExt.setServerCallbackUrl(Constant.prodSplit);
+                accountPayOrderExt.setGoodsName("分账");
+                if (null != splitBillRules && splitBillRules.size() > 0) {
+                    accountPayOrderExt.setSplitBillRules(splitBillRules);
+                }
+                String ext = JSON.toJSONString(accountPayOrderExt);
+                logger.info("分账规则串json串:" + ext);
+                accountPayOrder.setP6_ext(ext);
+                // 生成签名
+                StringBuilder builder = new StringBuilder();
+                builder.append(Constant.SPLIT)
+                        .append(accountPayOrder.getP1_bizType()).append(Constant.SPLIT)
+                        .append(accountPayOrder.getP2_signType()).append(Constant.SPLIT)
+                        .append(accountPayOrder.getP3_timestamp()).append(Constant.SPLIT)
+                        .append(accountPayOrder.getP4_orderId()).append(Constant.SPLIT)
+                        .append(accountPayOrder.getP5_customerNumber()).append(Constant.SPLIT)
+                        .append(accountPayOrder.getP6_ext()).append(Constant.SPLIT)
+                        .append(Constant.XUNI);
+                String sign = Disguiser.disguiseMD5(builder.toString().trim());
+                Map<String, String> bean = convertBean(accountPayOrder);
+                logger.info("--------------------> 发送分账参数:  " + bean);
+                Map<String, String> map = postForm(bean, Constant.FZ, sign, Map.class);
+                logger.info("----------------分账返回数据: " + map.toString());
+                if (map != null) {
+                    String code = map.get("rt5_retCode");
+                    if (!"0000".equals(code)) {
+                        String msg = map.get("rt6_retMsg");
+                        logger.info("【手动分账】>>>>>>>>>>手动分账失败>>>>>>>msg:" + msg);
+                    } else {
+                        // 返回值0000分帐成功
+                        for (SplitAccountPo splitAccount : splitBillDetail) {
+                            splitAccount.setPayStatus(1);
+                            // 保存分账详情
+                            newOrderDao.insertSplitAccount(splitAccount);
+                        }
+                        /**
+                         * 付款单
+                         */
+                        // 修改子订单付款状态及付款金额
+                        newOrderDao.updateShopOrderByPayStatus(Integer.valueOf(shopOrderId), costPrice, shopOrder.getPayStatus());
+                        SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+                        String currentTime2 = format2.format(new Date());
+                        // 保存付款单表
+                        PayShopPo payShop = new PayShopPo();
+                        payShop.setShopId(shopOrder.getShopId());
+                        payShop.setName("线上支付分账");
+                        payShop.setTotalAmount(costPrice);
+                        payShop.setWipePayment(0d);
+                        payShop.setPayType(6);
+                        payShop.setStatus(1);
+                        payShop.setDelFlag(0);
+                        payShop.setApplyTime(currentTime2);
+                        payShop.setReviewTime(currentTime2);
+                        payShop.setPayTime(currentTime2);
+                        newOrderDao.insertPayShop(payShop);
+                        // 保存 付供应商记录
+                        PayShopRecordPo shopRecord = new PayShopRecordPo();
+                        shopRecord.setShopId(shopOrder.getShopId());
+                        shopRecord.setShopOrderId(shopOrder.getShopOrderId());
+                        shopRecord.setShopOrderNo(shopOrder.getShopOrderNo());
+                        shopRecord.setPayAmount(costPrice);
+                        shopRecord.setWipePayment(0d);
+                        shopRecord.setPayType(6);
+                        shopRecord.setPayTime(currentTime2);
+                        shopRecord.setPayShopId(payShop.getId());
+                        shopRecord.setStatus(1);
+                        shopRecord.setDelFlag(0);
+                        newOrderDao.insertPayShopRecord(shopRecord);
+                        // 子订单是否全部付款
+                        List<String> payStatus = newShopOrderDao.findPayStatusByOrderID(shopOrder.getOrderId());
+                        boolean isPay = true;
+                        for (String shops : payStatus) {
+                            if (!"3".equals(shops)) {
+                                isPay = false;
+                                break;
+                            }
+                        }
+                        // 修改主订单付款状态
+                        if (isPay) {
+                            newOrderDao.updateOrderByPayStatus(shopOrder.getOrderId(), 3);
+                        } else {
+                            newOrderDao.updateOrderByPayStatus(shopOrder.getOrderId(), 2);
+                        }
+                        redisService.remove("XSFZMDS");
+                        logger.info("【手动分账】>>>>>>>>>>此订单分账结束");
+                    }
+                }
+            } catch (Exception e) {
+                logger.error("【手动分账】>>>>>>>>>>错误信息", e);
+            }
+        }
+    }
+
     @Transactional(readOnly = false, rollbackFor = Exception.class)
     public void SplitAccount(String[] shopOrderIds) {
         logger.info("【手动分账开始】>>>>>>>>>>手动分账");

+ 8 - 1
src/main/java/com/caimei/modules/order/web/CmPayShopController.java

@@ -783,6 +783,13 @@ public class CmPayShopController extends BaseController {
         return "redirect:" + Global.getAdminPath() + "/shopOrder/splitList";
     }
 
+    @RequestMapping("new/splitEdit")
+    public String splitEdit(String shopOrderId, String splits, RedirectAttributes redirectAttributes) {
+//        splitAccountService.SplitByHand(shopOrderId, splits);
+        addMessage(redirectAttributes, "分账成功!");
+        return "redirect:" + Global.getAdminPath() + "/shopOrder/splitList";
+    }
+
     /**
      * 去编辑页面 信息回显
      */
@@ -1078,7 +1085,7 @@ public class CmPayShopController extends BaseController {
         addMessage(redirectAttributes, "保存成功");
         if (null != payShopOther.getOtherType() && 1 == payShopOther.getOtherType()) {
             return "redirect:" + Global.getAdminPath() + "/order/cmPayShop/payOtherList?repage";
-        }else{
+        } else {
             if ((null != payShopOther.getPayType() && 2 == payShopOther.getPayType()) || 2 == payShopOther.getRedirectType()) {
                 return "redirect:" + Global.getAdminPath() + "/order/cmPayShop/payList?repage";
             }

+ 104 - 16
src/main/webapp/WEB-INF/views/modules/order/cmSplitAccountList.jsp

@@ -175,7 +175,7 @@
             margin-bottom: 0px
         }
 
-        .popup-cfm-btn, .tips-cfm-btn {
+        .popup-cfm-btn, .tips-cfm-btn, .sub-popup-cfm-btn {
             background: #3daae9;
             color: #fff;
             border: none
@@ -191,7 +191,7 @@
             border-radius: 5px
         }
 
-        .popup-cancel-btn {
+        .popup-cancel-btn, .sub-popup-cancel-btn {
             background: #fff;
             color: #555;
             border: 1px solid #ddd;
@@ -203,7 +203,7 @@
             display: none
         }
 
-        #close-btn, #close-btn1 {
+        #close-btn, #close-btn1, #sub-close-btn {
             top: 8px;
             right: 10px;
             width: 18px;
@@ -546,7 +546,69 @@
         </div>
     </c:forEach>
 </div>
-<div class="mask revise-popup">
+<%--子订单分账弹窗--%>
+<div class="mask revise-popup" id="sub-revise-popup">
+    <div class="revise-popup-content" style="width: 540px;">
+        <h4>确认提示</h4>
+        <div class="tab-content">
+            <%--            <div>--%>
+            <%--                <div style="display: inline-block">--%>
+            <%--                    <p>--%>
+            <%--                        <span>子订单金额:<span id="">45454545</span></span>--%>
+            <%--                    </p>--%>
+            <%--                </div>--%>
+            <%--                <div style="display: inline-block">--%>
+            <%--                    <p>--%>
+            <%--                        <span>子订单金额:<span id="">45454545</span></span>--%>
+            <%--                    </p>--%>
+            <%--                </div>--%>
+            <%--            </div>--%>
+            <div>
+                <div style="display: inline-block">
+                    <p>
+                        <span>供应商分账号:<input id="div-shop-accounts"></span>
+                    </p>
+                </div>
+                <div style="display: inline-block;margin-left: 30px;">
+                    <p>
+                        <span>供应商成本分账金额:<input id="div-shop-money"></span>
+                    </p>
+                </div>
+            </div>
+            <div>
+                <div style="display: inline-block">
+                    <p>
+                        <span>采美分账号:<input id="div-caimei-accounts"></span>
+                    </p>
+                </div>
+                <div style="display: inline-block;margin-left: 30px;">
+                    <p>
+                        <span>采美分账金额:<input id="div-caimei-money"></span>
+                    </p>
+                </div>
+            </div>
+            <div>
+                <div style="display: inline-block">
+                    <p>
+                        <span>服务商分账号:<input id="div-service-accounts"></span>
+                    </p>
+                </div>
+                <div style="display: inline-block;margin-left: 30px;">
+                    <p>
+                        <span>服务商分账金额:<input id="div-service-money"></span>
+                    </p>
+                </div>
+            </div>
+        </div>
+        <div class="popup-tips">不能为空</div>
+        <div style="margin-top: 50px;">
+            <button class="sub-popup-cancel-btn">取消</button>
+            <button class="sub-popup-cfm-btn">确认分账</button>
+        </div>
+        <img id="sub-close-btn" src="/static/images/close-btn.png" alt="close-btn">
+    </div>
+</div>
+<div class="mask revise-popup" id="revise-popup">
     <div class="revise-popup-content">
         <h4>确认提示</h4>
         <ul class="nav nav-tabs" id="myTab">
@@ -632,12 +694,12 @@
 <script>
     function changeCheck(el) {
         var checked = $('input[type=checkbox]:checked');
-        // if (checked.length > 1) {
-        //     // $(".checkShop").attr('disabled','true');
-        //     alertx("请最多选择一个子订单进行分账");
-        //     $(el).prop('checked',false);
-        //     return false;
-        // }
+        if (checked.length > 1) {
+            $(".checkShop").attr('disabled', 'true');
+            alertx("请最多选择一个子订单进行分账");
+            $(el).prop('checked', false);
+            return false;
+        }
     }
 
     (function () {
@@ -788,8 +850,8 @@
                 productAmount = wrapper.find('.productAmount').val(),
                 costType = wrapper.find('.costType').val(),
                 modifyShouldPayNote = wrapper.find('.modifyShouldPayNote').val();
-            $('.revise-popup').attr('data-shoporderid', $(this).attr('data-shoporderid'));
-            $('.revise-popup').show();
+            $('#revise-popup').attr('data-shoporderid', $(this).attr('data-shoporderid'));
+            $('#revise-popup').show();
             $('#div-freight').attr('value', freight);
             $('#div-freight').attr('data-ov', freight);
             $('#div-third-party-fee').attr('value', thirdPartyFee);
@@ -828,6 +890,7 @@
         });
 
         $('#apply').on('click', function () {
+
             top.$.jBox.confirm('确定对该子订单申请分账吗?', '系统提示', function (v, h, f) {
                 if (v == "ok") {
                     var checked = $('.pay-wrapper input[type=checkbox]:checked'), params = '?';
@@ -845,13 +908,35 @@
                         alertx('请至少选择一个订单');
                         return false;
                     }
-                    window.location.href = '${ctx}/order/cmPayShop/splitEdit' + params;
+                    $('#sub-revise-popup').show();
+
+                    <%--window.location.href = '${ctx}/order/cmPayShop/new/splitEdit' + params;--%>
                 }
             });
 
 
         });
 
+        $('.sub-popup-cfm-btn').on('click', function () {
+            var checked = $('.pay-wrapper input[type=checkbox]:checked');
+            var shoporderId = $(checked[0]).attr('data-shoporderid');
+            var shopCode = $('#div-shop-accounts').val();
+            var shopMoney = $('#div-shop-money').val();
+            var cmCode = $('#div-caimei-accounts').val();
+            var cmMoney = $('#div-caimei-money').val();
+            var serviceCode = $('#div-service-accounts').val();
+            var serviceMoney = $('#div-service-money').val();
+            var splits = shopCode + ',' + shopMoney + ';' + cmCode + ',' + cmMoney + ';' + serviceCode + ',' + serviceMoney;
+            console.log("splits--------------->" + splits);
+            console.log("shoporderId--------------->" + shoporderId);
+            $.ajax({
+                url: "${ctx}/order/cmPayShop/new/splitEdit",
+                data: {'shopOrderId': shoporderId, 'splits': splits},
+                type: "POST"
+            });
+            <%--window.location.href = '${ctx}/order/cmPayShop/new/splitEdit?shopOrderId=' + shoporderId + "&splits =" + splits;--%>
+        });
+
         <%--//付第三方--%>
         <%--$('#applyShopOtherFee').on('click', function () {--%>
         <%--    var checked = $('.pay-wrapper input[type=checkbox]:checked');--%>
@@ -895,9 +980,12 @@
         });
 
         $('#close-btn, .popup-cancel-btn').on('click', function () {
-            $('.revise-popup').hide();
+            $('#revise-popup').hide();
             renderPopup('', '', '', '', '', '', '');
         })
+        $('#sub-close-btn, .sub-popup-cancel-btn').on('click', function () {
+            $('#sub-revise-popup').hide();
+        })
 
         $("#popup-product-fee").on("input propertychange", function () {
             toZero($(this));
@@ -931,7 +1019,7 @@
         $('.popup-cfm-btn').on('click', function () {
             var freight = Number($('#div-freight').attr('value')), //运费
                 third_party_fee = Number($('#div-third-party-fee').attr('value')), //运费
-                shopOrderID = $(this).parents('.revise-popup').attr('data-shoporderid'),//子订单ID
+                shopOrderID = $(this).parents('#revise-popup').attr('data-shoporderid'),//子订单ID
                 params = '?shopOrderID=' + shopOrderID + '&freight=' + freight + '&thirdPartyFee=' + third_party_fee;
             if ($('#fixed-cost').css('display') == 'block') { //固定成本显示
                 params += '&costType=1';
@@ -959,7 +1047,7 @@
                 data: {'modifyShouldPayNote': remark},
                 success: function (res) {
                     if (res.success) {
-                        $('.revise-popup').hide();
+                        $('#revise-popup').hide();
                         $('#searchForm').submit();
                     } else {
                         alertx(res.msg);