|
@@ -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("【手动分账开始】>>>>>>>>>>手动分账");
|