|
@@ -20,284 +20,284 @@ import java.math.BigDecimal;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
|
-@Service
|
|
|
-@Transactional(readOnly = true)
|
|
|
-public class SplitAccountService {
|
|
|
-
|
|
|
- /**
|
|
|
- * 日志对象
|
|
|
- */
|
|
|
- protected Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
-
|
|
|
- @Resource
|
|
|
- private NewOrderDao newOrderDao;
|
|
|
- @Resource
|
|
|
- private RedisService redisService;
|
|
|
-
|
|
|
- @Transactional(readOnly = false)
|
|
|
- public void SplitAccount() {
|
|
|
- logger.info("【手动分账开始】>>>>>>>>>>手动分账");
|
|
|
- Calendar calendar = Calendar.getInstance();
|
|
|
- calendar.setTime(new Date());
|
|
|
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
- String currentTime = format.format(calendar.getTime());
|
|
|
- // 查询未分账已支付收款
|
|
|
- List<OrderReceiptRelationPo> orderRelations = newOrderDao.getUndividedPaidReceipt(currentTime);
|
|
|
- if (null != orderRelations && orderRelations.size() > 0) {
|
|
|
- for (OrderReceiptRelationPo orderRelation : orderRelations) {
|
|
|
- logger.info("【分账】>>>>>>>>>>子订单id:" + orderRelation.getShopOrderId() + "进入分账");
|
|
|
- // 收款对应的订单信息
|
|
|
- OrderVo order = orderCommonMapper.getOrderByOrderId(orderRelation.getOrderId());
|
|
|
- PayParamBo payParam = new PayParamBo();
|
|
|
- //支付金额
|
|
|
- payParam.setPayAmount(MathUtil.mul(orderRelation.getAssociateAmount(), 100).intValue());
|
|
|
- if (12 == orderRelation.getPayType()) {
|
|
|
- // 网银支付
|
|
|
- payParam.setPayWay("UNIONPAY");
|
|
|
- }
|
|
|
- if (17 == orderRelation.getPayType()) {
|
|
|
- //b2c网银
|
|
|
- payParam.setPayWay("B2C");
|
|
|
- }
|
|
|
- //微信0.65%手续费
|
|
|
- if (8 == orderRelation.getPayType() || 13 == orderRelation.getPayType() || 15 == orderRelation.getPayType()) {
|
|
|
- payParam.setPayWay("WX");
|
|
|
- }
|
|
|
- List<SplitAccountPo> splitBillDetail = setSplitAccountDetail(order, payParam);
|
|
|
- List<Map<String, String>> maps = new ArrayList<>();
|
|
|
- List<ShopOrderVo> shopOrderList = orderCommonMapper.getShopOrderListByOrderId(order.getOrderId());
|
|
|
- for (ShopOrderVo shopOrder : shopOrderList) {
|
|
|
- double shopTotalAmount = 0.00;
|
|
|
- String subUserNo = "";
|
|
|
- for (SplitAccountPo account : splitBillDetail) {
|
|
|
- //供应商有支付平台账户type=4
|
|
|
- if (null != account.getType() && 4 == account.getType() && shopOrder.getShopId().equals(account.getShopId())) {
|
|
|
- shopTotalAmount = MathUtil.add(shopTotalAmount, account.getSplitAccount()).doubleValue();
|
|
|
- subUserNo = account.getSubUserNo();
|
|
|
- }
|
|
|
- }
|
|
|
-// addMaps(maps, shopTotalAmount, subUserNo);
|
|
|
- }
|
|
|
- if (null == splitBillDetail || splitBillDetail.size() == 0) {
|
|
|
- log.info("无满足条件分账单号");
|
|
|
- return;
|
|
|
- }
|
|
|
- //公账-专票总金额,私账-无票总金额,公账-普票总金额
|
|
|
- //Type2,3奥泰,1,5信息
|
|
|
- //todo 正式改
|
|
|
- String sp1 = "";
|
|
|
- BigDecimal totalAmount1 = BigDecimal.ZERO;
|
|
|
- String sp2 = "";
|
|
|
- BigDecimal totalAmount2 = BigDecimal.ZERO;
|
|
|
- for (SplitAccountPo account : splitBillDetail) {
|
|
|
- if (1 == account.getType() || 5 == account.getType()) {
|
|
|
- totalAmount1 = MathUtil.add(totalAmount1, account.getSplitAccount());
|
|
|
- sp1 = account.getSubUserNo();
|
|
|
- }
|
|
|
- if (2 == account.getType() || 3 == account.getType()) {
|
|
|
- totalAmount2 = MathUtil.add(totalAmount2, account.getSplitAccount());
|
|
|
- sp2 = account.getSubUserNo();
|
|
|
- }
|
|
|
- }
|
|
|
- ArrayList<AccountPayOrder.AccountPayOrderExt.SplitBillRule> splitBillRules = new ArrayList<>();
|
|
|
- if (MathUtil.compare(totalAmount1, 0.01) > 0) {
|
|
|
- AccountPayOrder.AccountPayOrderExt.SplitBillRule splitBillRule = new AccountPayOrder.AccountPayOrderExt.SplitBillRule();
|
|
|
- splitBillRule.setSplitBillAmount(totalAmount1);
|
|
|
- splitBillRule.setSplitBillMerchantNo(sp1);
|
|
|
- splitBillRules.add(splitBillRule);
|
|
|
- }
|
|
|
- if (MathUtil.compare(totalAmount2, 0.01) > 0) {
|
|
|
- AccountPayOrder.AccountPayOrderExt.SplitBillRule splitBillRule = new AccountPayOrder.AccountPayOrderExt.SplitBillRule();
|
|
|
- splitBillRule.setSplitBillAmount(totalAmount2);
|
|
|
- splitBillRule.setSplitBillMerchantNo(sp2);
|
|
|
- splitBillRules.add(splitBillRule);
|
|
|
- }
|
|
|
- //第三方分账接口
|
|
|
- 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 + orderRelation.getOrderRequestNo());
|
|
|
- //todo 付款账户商编暂用网络
|
|
|
- accountPayOrder.setP5_customerNumber(Constant.CUSTOMERNUM2);
|
|
|
- AccountPayOrder.AccountPayOrderExt accountPayOrderExt = new AccountPayOrder.AccountPayOrderExt();
|
|
|
- //收款账户商编 填写splitBillRules时候不填写MerchantNo,Amount并且即使填写这两个参数不生效!!
|
|
|
-// accountPayOrderExt.setInMerchantNo(splitMoneyVo.getName());
|
|
|
- accountPayOrderExt.setOrderType(AccountPayOrderType.TRANSFER);
|
|
|
-// accountPayOrderExt.setAmount(splitMoneyVo.getSplitMoney());
|
|
|
- accountPayOrderExt.setServerCallbackUrl(callUrl);
|
|
|
- accountPayOrderExt.setGoodsName("分账");
|
|
|
-
|
|
|
- if (null != splitBillRules && splitBillRules.size() > 0) {
|
|
|
- accountPayOrderExt.setSplitBillRules(splitBillRules);
|
|
|
- }
|
|
|
- String ext = JSON.toJSONString(accountPayOrderExt);
|
|
|
- log.info("分账规则串json串:" + ext);
|
|
|
- accountPayOrder.setP6_ext(ext);
|
|
|
- // 生成签名
|
|
|
- StringBuilder builder = new StringBuilder();
|
|
|
- builder.append(SPLIT)
|
|
|
- .append(accountPayOrder.getP1_bizType()).append(SPLIT)
|
|
|
- .append(accountPayOrder.getP2_signType()).append(SPLIT)
|
|
|
- .append(accountPayOrder.getP3_timestamp()).append(SPLIT)
|
|
|
- .append(accountPayOrder.getP4_orderId()).append(SPLIT)
|
|
|
- .append(accountPayOrder.getP5_customerNumber()).append(SPLIT)
|
|
|
- .append(accountPayOrder.getP6_ext()).append(SPLIT)
|
|
|
- .append(XUNI);
|
|
|
- String sign = Disguiser.disguiseMD5(builder.toString().trim());
|
|
|
- Map<String, String> bean = convertBean(accountPayOrder);
|
|
|
- log.info("--------------------> 发送分账参数: " + bean);
|
|
|
- Map<String, String> map = postForm(bean, Constant.FZ, sign, Map.class);
|
|
|
- log.info("----------------分账返回数据: " + map.toString());
|
|
|
- if (map != null) {
|
|
|
- String code = map.get("rt5_retCode");
|
|
|
- if (!"0000".equals(code)) {
|
|
|
- String msg = map.get("rt6_retMsg");
|
|
|
- log.info("【延时分账】>>>>>>>>>>第三方延迟分账失败>>>>>>>msg:" + msg);
|
|
|
- } else {
|
|
|
- for (SplitAccountPo splitAccount : splitBillDetail) {
|
|
|
- splitAccount.setMbOrderId(orderRelation.getMbOrderId());
|
|
|
- splitAccount.setOrderRequestNo(substring + orderRelation.getOrderRequestNo());
|
|
|
- splitAccount.setPayStatus(1);
|
|
|
- // 保存分账详情
|
|
|
- payOrderMapper.insertSplitAccount(splitAccount);
|
|
|
- }
|
|
|
- log.info("【延时分账】>>>>>>>>>>此订单分账结束");
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("【延时分账】>>>>>>>>>>错误信息", e);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private List<SplitAccountPo> setSplitAccountDetail(OrderVo order, PayParamBo payParam) {
|
|
|
- List<SplitAccountPo> list = new ArrayList<>();
|
|
|
- // 本次支付金额,单位/元
|
|
|
- double payAmount = MathUtil.div(payParam.getPayAmount(), 100).doubleValue();
|
|
|
- // 待分账总金额
|
|
|
- double splitAmount = payAmount;
|
|
|
- // 总手续费
|
|
|
- double procedureFee;
|
|
|
- if ("UNIONPAY".equals(payParam.getPayWay())) {
|
|
|
- procedureFee = 10.00;
|
|
|
- } else if ("B2C".equals(payParam.getPayWay())) {
|
|
|
- //b2c 0.2%
|
|
|
- procedureFee = MathUtil.mul(payAmount, 0.002, 2).doubleValue();
|
|
|
- //b2c最低手续费0.1
|
|
|
- if (procedureFee < 0.1) {
|
|
|
- procedureFee = 0.1;
|
|
|
- }
|
|
|
- } else if ("WX".equals(payParam.getPayWay())) {
|
|
|
- //微信0.65%
|
|
|
- procedureFee = MathUtil.mul(payAmount, 0.0065, 2).doubleValue();
|
|
|
- } else {
|
|
|
- //手续费 其他0.25%
|
|
|
- procedureFee = MathUtil.mul(payAmount, 0.0025, 2).doubleValue();
|
|
|
- }
|
|
|
- if (MathUtil.compare(procedureFee, 0.01) <= 0) {
|
|
|
- procedureFee = 0.01;
|
|
|
- }
|
|
|
- //减去收款手续费
|
|
|
- splitAmount = MathUtil.sub(splitAmount, procedureFee).doubleValue();
|
|
|
- //分账手续费0.1%
|
|
|
- Double amount = Math.max(MathUtil.mul(splitAmount, 0.001, 2).doubleValue(), 0.01);
|
|
|
- splitAmount = MathUtil.sub(splitAmount, amount).doubleValue();
|
|
|
- if (splitAmount <= 0) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- // 商品数据
|
|
|
- List<OrderProductVo> orderProductList = orderCommonMapper.getOrderProductByOrderId(order.getOrderId());
|
|
|
- for (OrderProductVo orderProduct : orderProductList) {
|
|
|
- //成本价*数量
|
|
|
- double costPrice = MathUtil.mul(orderProduct.getCostPrice(), orderProduct.getNum()).doubleValue();
|
|
|
- // 不含税能开发票
|
|
|
- if (Integer.valueOf(0).equals(orderProduct.getIncludedTax()) && !Integer.valueOf(3).equals(orderProduct.getInvoiceType())) {
|
|
|
- //应付总税费
|
|
|
- Double payableTax = MathUtil.mul(orderProduct.getSingleShouldPayTotalTax(), orderProduct.getNum()).doubleValue();
|
|
|
- //成本+税费
|
|
|
- costPrice = MathUtil.add(costPrice, payableTax).doubleValue();
|
|
|
- }
|
|
|
- // 判断是否支付过
|
|
|
- Double paidAmount = payOrderMapper.getOrderProductPaidAmount(orderProduct.getOrderProductId());
|
|
|
- // 支付过金额大于0
|
|
|
- if (paidAmount != null && MathUtil.compare(paidAmount, 0) > 0) {
|
|
|
- //成本-支付过的金额
|
|
|
- costPrice = MathUtil.sub(costPrice, paidAmount).doubleValue();
|
|
|
- }
|
|
|
- // 没支付过或者支付过的金额-成本<0(成本还没分够)
|
|
|
- if (paidAmount == null || MathUtil.compare(paidAmount, costPrice) < 0) {
|
|
|
- // 待分账金额>=本次待分账金额(还要分账的成本)
|
|
|
- if (MathUtil.compare(splitAmount, costPrice) > 0) {
|
|
|
- // 待分账金额=待分账金额-成本
|
|
|
- splitAmount = MathUtil.sub(splitAmount, costPrice).doubleValue();
|
|
|
- } else {
|
|
|
- // 待分账金额小于成本
|
|
|
- costPrice = splitAmount;
|
|
|
- splitAmount = 0.00;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- // 还有钱就付供应商运费
|
|
|
- // 付供应商运费,是以供应商为单位的
|
|
|
- if (MathUtil.compare(splitAmount, 0) > 0) {
|
|
|
- List<ShopOrderVo> shopOrderList = orderCommonMapper.getShopOrderListByOrderId(order.getOrderId());
|
|
|
- for (ShopOrderVo shopOrder : shopOrderList) {
|
|
|
- // 运费
|
|
|
- Double shopPostFee = shopOrder.getShopPostFee();
|
|
|
- if (MathUtil.compare(shopPostFee, 0) > 0) {
|
|
|
- // 查询已支付运费
|
|
|
- Double shipping = payOrderMapper.getPaidShipping(order.getOrderId(), shopOrder.getShopId());
|
|
|
- shopPostFee = MathUtil.sub(shopPostFee, shipping).doubleValue();
|
|
|
- if (MathUtil.compare(splitAmount, shopPostFee) > -1) {
|
|
|
- //减去运费
|
|
|
- splitAmount = MathUtil.sub(splitAmount, shopPostFee).doubleValue();
|
|
|
- } else {
|
|
|
- //钱不够运费就分剩余
|
|
|
- shopPostFee = splitAmount;
|
|
|
- splitAmount = 0.00;
|
|
|
- }
|
|
|
- //todo 暂不考虑供应商有商户号,有分给供应商,没有进私账
|
|
|
- SplitAccountPo splitAccount = new SplitAccountPo();
|
|
|
- splitAccount.setOrderId(order.getOrderId());
|
|
|
- splitAccount.setShopId(shopOrder.getShopId());
|
|
|
- splitAccount.setSplitAccount(shopPostFee);
|
|
|
- splitAccount.setProductType(2);
|
|
|
- splitAccount.setType(2);
|
|
|
- //todo 私账-无票,子商户商编 测试暂入奥泰
|
|
|
- splitAccount.setSubUserNo(CUSTOMERNUM3);
|
|
|
- if (splitAccount.getSplitAccount() > 0) {
|
|
|
- log.info("============设置付供应商运费分账详情对象: " + splitAccount.toString());
|
|
|
- list.add(splitAccount);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- // 如果还有钱则为佣金,分到采美网络
|
|
|
- if (MathUtil.compare(splitAmount, 0) > 0) {
|
|
|
- SplitAccountPo splitAccount = new SplitAccountPo();
|
|
|
- splitAccount.setOrderId(order.getOrderId());
|
|
|
- splitAccount.setSplitAccount(splitAmount);
|
|
|
- splitAccount.setProductType(3);
|
|
|
- splitAccount.setType(5);
|
|
|
- //todo 佣金应入采美网络,测试暂入信息
|
|
|
- splitAccount.setSubUserNo(Constant.CUSTOMERNUM);
|
|
|
- if (splitAccount.getSplitAccount() > 0) {
|
|
|
- log.info("============设置佣金分账详情对象: " + splitAccount.toString());
|
|
|
- list.add(splitAccount);
|
|
|
- }
|
|
|
- }
|
|
|
- return list;
|
|
|
- }
|
|
|
-
|
|
|
+//@Service
|
|
|
+//@Transactional(readOnly = true)
|
|
|
+//public class SplitAccountService {
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 日志对象
|
|
|
+// */
|
|
|
+// protected Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
+//
|
|
|
+// @Resource
|
|
|
+// private NewOrderDao newOrderDao;
|
|
|
+// @Resource
|
|
|
+// private RedisService redisService;
|
|
|
+//
|
|
|
+// @Transactional(readOnly = false)
|
|
|
+// public void SplitAccount() {
|
|
|
+// logger.info("【手动分账开始】>>>>>>>>>>手动分账");
|
|
|
+// Calendar calendar = Calendar.getInstance();
|
|
|
+// calendar.setTime(new Date());
|
|
|
+// SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+// String currentTime = format.format(calendar.getTime());
|
|
|
+// // 查询未分账已支付收款
|
|
|
+// List<OrderReceiptRelationPo> orderRelations = newOrderDao.getUndividedPaidReceipt(currentTime);
|
|
|
+// if (null != orderRelations && orderRelations.size() > 0) {
|
|
|
+// for (OrderReceiptRelationPo orderRelation : orderRelations) {
|
|
|
+// logger.info("【分账】>>>>>>>>>>子订单id:" + orderRelation.getShopOrderId() + "进入分账");
|
|
|
+// // 收款对应的订单信息
|
|
|
+// OrderVo order = orderCommonMapper.getOrderByOrderId(orderRelation.getOrderId());
|
|
|
+// PayParamBo payParam = new PayParamBo();
|
|
|
+// //支付金额
|
|
|
+// payParam.setPayAmount(MathUtil.mul(orderRelation.getAssociateAmount(), 100).intValue());
|
|
|
+// if (12 == orderRelation.getPayType()) {
|
|
|
+// // 网银支付
|
|
|
+// payParam.setPayWay("UNIONPAY");
|
|
|
+// }
|
|
|
+// if (17 == orderRelation.getPayType()) {
|
|
|
+// //b2c网银
|
|
|
+// payParam.setPayWay("B2C");
|
|
|
+// }
|
|
|
+// //微信0.65%手续费
|
|
|
+// if (8 == orderRelation.getPayType() || 13 == orderRelation.getPayType() || 15 == orderRelation.getPayType()) {
|
|
|
+// payParam.setPayWay("WX");
|
|
|
+// }
|
|
|
+// List<SplitAccountPo> splitBillDetail = setSplitAccountDetail(order, payParam);
|
|
|
+// List<Map<String, String>> maps = new ArrayList<>();
|
|
|
+// List<ShopOrderVo> shopOrderList = orderCommonMapper.getShopOrderListByOrderId(order.getOrderId());
|
|
|
+// for (ShopOrderVo shopOrder : shopOrderList) {
|
|
|
+// double shopTotalAmount = 0.00;
|
|
|
+// String subUserNo = "";
|
|
|
+// for (SplitAccountPo account : splitBillDetail) {
|
|
|
+// //供应商有支付平台账户type=4
|
|
|
+// if (null != account.getType() && 4 == account.getType() && shopOrder.getShopId().equals(account.getShopId())) {
|
|
|
+// shopTotalAmount = MathUtil.add(shopTotalAmount, account.getSplitAccount()).doubleValue();
|
|
|
+// subUserNo = account.getSubUserNo();
|
|
|
+// }
|
|
|
+// }
|
|
|
+//// addMaps(maps, shopTotalAmount, subUserNo);
|
|
|
+// }
|
|
|
+// if (null == splitBillDetail || splitBillDetail.size() == 0) {
|
|
|
+// log.info("无满足条件分账单号");
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// //公账-专票总金额,私账-无票总金额,公账-普票总金额
|
|
|
+// //Type2,3奥泰,1,5信息
|
|
|
+// //todo 正式改
|
|
|
+// String sp1 = "";
|
|
|
+// BigDecimal totalAmount1 = BigDecimal.ZERO;
|
|
|
+// String sp2 = "";
|
|
|
+// BigDecimal totalAmount2 = BigDecimal.ZERO;
|
|
|
+// for (SplitAccountPo account : splitBillDetail) {
|
|
|
+// if (1 == account.getType() || 5 == account.getType()) {
|
|
|
+// totalAmount1 = MathUtil.add(totalAmount1, account.getSplitAccount());
|
|
|
+// sp1 = account.getSubUserNo();
|
|
|
+// }
|
|
|
+// if (2 == account.getType() || 3 == account.getType()) {
|
|
|
+// totalAmount2 = MathUtil.add(totalAmount2, account.getSplitAccount());
|
|
|
+// sp2 = account.getSubUserNo();
|
|
|
+// }
|
|
|
+// }
|
|
|
+// ArrayList<AccountPayOrder.AccountPayOrderExt.SplitBillRule> splitBillRules = new ArrayList<>();
|
|
|
+// if (MathUtil.compare(totalAmount1, 0.01) > 0) {
|
|
|
+// AccountPayOrder.AccountPayOrderExt.SplitBillRule splitBillRule = new AccountPayOrder.AccountPayOrderExt.SplitBillRule();
|
|
|
+// splitBillRule.setSplitBillAmount(totalAmount1);
|
|
|
+// splitBillRule.setSplitBillMerchantNo(sp1);
|
|
|
+// splitBillRules.add(splitBillRule);
|
|
|
+// }
|
|
|
+// if (MathUtil.compare(totalAmount2, 0.01) > 0) {
|
|
|
+// AccountPayOrder.AccountPayOrderExt.SplitBillRule splitBillRule = new AccountPayOrder.AccountPayOrderExt.SplitBillRule();
|
|
|
+// splitBillRule.setSplitBillAmount(totalAmount2);
|
|
|
+// splitBillRule.setSplitBillMerchantNo(sp2);
|
|
|
+// splitBillRules.add(splitBillRule);
|
|
|
+// }
|
|
|
+// //第三方分账接口
|
|
|
+// 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 + orderRelation.getOrderRequestNo());
|
|
|
+// //todo 付款账户商编暂用网络
|
|
|
+// accountPayOrder.setP5_customerNumber(Constant.CUSTOMERNUM2);
|
|
|
+// AccountPayOrder.AccountPayOrderExt accountPayOrderExt = new AccountPayOrder.AccountPayOrderExt();
|
|
|
+// //收款账户商编 填写splitBillRules时候不填写MerchantNo,Amount并且即使填写这两个参数不生效!!
|
|
|
+//// accountPayOrderExt.setInMerchantNo(splitMoneyVo.getName());
|
|
|
+// accountPayOrderExt.setOrderType(AccountPayOrderType.TRANSFER);
|
|
|
+//// accountPayOrderExt.setAmount(splitMoneyVo.getSplitMoney());
|
|
|
+// accountPayOrderExt.setServerCallbackUrl(callUrl);
|
|
|
+// accountPayOrderExt.setGoodsName("分账");
|
|
|
+//
|
|
|
+// if (null != splitBillRules && splitBillRules.size() > 0) {
|
|
|
+// accountPayOrderExt.setSplitBillRules(splitBillRules);
|
|
|
+// }
|
|
|
+// String ext = JSON.toJSONString(accountPayOrderExt);
|
|
|
+// log.info("分账规则串json串:" + ext);
|
|
|
+// accountPayOrder.setP6_ext(ext);
|
|
|
+// // 生成签名
|
|
|
+// StringBuilder builder = new StringBuilder();
|
|
|
+// builder.append(SPLIT)
|
|
|
+// .append(accountPayOrder.getP1_bizType()).append(SPLIT)
|
|
|
+// .append(accountPayOrder.getP2_signType()).append(SPLIT)
|
|
|
+// .append(accountPayOrder.getP3_timestamp()).append(SPLIT)
|
|
|
+// .append(accountPayOrder.getP4_orderId()).append(SPLIT)
|
|
|
+// .append(accountPayOrder.getP5_customerNumber()).append(SPLIT)
|
|
|
+// .append(accountPayOrder.getP6_ext()).append(SPLIT)
|
|
|
+// .append(XUNI);
|
|
|
+// String sign = Disguiser.disguiseMD5(builder.toString().trim());
|
|
|
+// Map<String, String> bean = convertBean(accountPayOrder);
|
|
|
+// log.info("--------------------> 发送分账参数: " + bean);
|
|
|
+// Map<String, String> map = postForm(bean, Constant.FZ, sign, Map.class);
|
|
|
+// log.info("----------------分账返回数据: " + map.toString());
|
|
|
+// if (map != null) {
|
|
|
+// String code = map.get("rt5_retCode");
|
|
|
+// if (!"0000".equals(code)) {
|
|
|
+// String msg = map.get("rt6_retMsg");
|
|
|
+// log.info("【延时分账】>>>>>>>>>>第三方延迟分账失败>>>>>>>msg:" + msg);
|
|
|
+// } else {
|
|
|
+// for (SplitAccountPo splitAccount : splitBillDetail) {
|
|
|
+// splitAccount.setMbOrderId(orderRelation.getMbOrderId());
|
|
|
+// splitAccount.setOrderRequestNo(substring + orderRelation.getOrderRequestNo());
|
|
|
+// splitAccount.setPayStatus(1);
|
|
|
+// // 保存分账详情
|
|
|
+// payOrderMapper.insertSplitAccount(splitAccount);
|
|
|
+// }
|
|
|
+// log.info("【延时分账】>>>>>>>>>>此订单分账结束");
|
|
|
+// }
|
|
|
+// }
|
|
|
+// } catch (Exception e) {
|
|
|
+// log.error("【延时分账】>>>>>>>>>>错误信息", e);
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// private List<SplitAccountPo> setSplitAccountDetail(OrderVo order, PayParamBo payParam) {
|
|
|
+// List<SplitAccountPo> list = new ArrayList<>();
|
|
|
+// // 本次支付金额,单位/元
|
|
|
+// double payAmount = MathUtil.div(payParam.getPayAmount(), 100).doubleValue();
|
|
|
+// // 待分账总金额
|
|
|
+// double splitAmount = payAmount;
|
|
|
+// // 总手续费
|
|
|
+// double procedureFee;
|
|
|
+// if ("UNIONPAY".equals(payParam.getPayWay())) {
|
|
|
+// procedureFee = 10.00;
|
|
|
+// } else if ("B2C".equals(payParam.getPayWay())) {
|
|
|
+// //b2c 0.2%
|
|
|
+// procedureFee = MathUtil.mul(payAmount, 0.002, 2).doubleValue();
|
|
|
+// //b2c最低手续费0.1
|
|
|
+// if (procedureFee < 0.1) {
|
|
|
+// procedureFee = 0.1;
|
|
|
+// }
|
|
|
+// } else if ("WX".equals(payParam.getPayWay())) {
|
|
|
+// //微信0.65%
|
|
|
+// procedureFee = MathUtil.mul(payAmount, 0.0065, 2).doubleValue();
|
|
|
+// } else {
|
|
|
+// //手续费 其他0.25%
|
|
|
+// procedureFee = MathUtil.mul(payAmount, 0.0025, 2).doubleValue();
|
|
|
+// }
|
|
|
+// if (MathUtil.compare(procedureFee, 0.01) <= 0) {
|
|
|
+// procedureFee = 0.01;
|
|
|
+// }
|
|
|
+// //减去收款手续费
|
|
|
+// splitAmount = MathUtil.sub(splitAmount, procedureFee).doubleValue();
|
|
|
+// //分账手续费0.1%
|
|
|
+// Double amount = Math.max(MathUtil.mul(splitAmount, 0.001, 2).doubleValue(), 0.01);
|
|
|
+// splitAmount = MathUtil.sub(splitAmount, amount).doubleValue();
|
|
|
+// if (splitAmount <= 0) {
|
|
|
+// return null;
|
|
|
+// }
|
|
|
+// // 商品数据
|
|
|
+// List<OrderProductVo> orderProductList = orderCommonMapper.getOrderProductByOrderId(order.getOrderId());
|
|
|
+// for (OrderProductVo orderProduct : orderProductList) {
|
|
|
+// //成本价*数量
|
|
|
+// double costPrice = MathUtil.mul(orderProduct.getCostPrice(), orderProduct.getNum()).doubleValue();
|
|
|
+// // 不含税能开发票
|
|
|
+// if (Integer.valueOf(0).equals(orderProduct.getIncludedTax()) && !Integer.valueOf(3).equals(orderProduct.getInvoiceType())) {
|
|
|
+// //应付总税费
|
|
|
+// Double payableTax = MathUtil.mul(orderProduct.getSingleShouldPayTotalTax(), orderProduct.getNum()).doubleValue();
|
|
|
+// //成本+税费
|
|
|
+// costPrice = MathUtil.add(costPrice, payableTax).doubleValue();
|
|
|
+// }
|
|
|
+// // 判断是否支付过
|
|
|
+// Double paidAmount = payOrderMapper.getOrderProductPaidAmount(orderProduct.getOrderProductId());
|
|
|
+// // 支付过金额大于0
|
|
|
+// if (paidAmount != null && MathUtil.compare(paidAmount, 0) > 0) {
|
|
|
+// //成本-支付过的金额
|
|
|
+// costPrice = MathUtil.sub(costPrice, paidAmount).doubleValue();
|
|
|
+// }
|
|
|
+// // 没支付过或者支付过的金额-成本<0(成本还没分够)
|
|
|
+// if (paidAmount == null || MathUtil.compare(paidAmount, costPrice) < 0) {
|
|
|
+// // 待分账金额>=本次待分账金额(还要分账的成本)
|
|
|
+// if (MathUtil.compare(splitAmount, costPrice) > 0) {
|
|
|
+// // 待分账金额=待分账金额-成本
|
|
|
+// splitAmount = MathUtil.sub(splitAmount, costPrice).doubleValue();
|
|
|
+// } else {
|
|
|
+// // 待分账金额小于成本
|
|
|
+// costPrice = splitAmount;
|
|
|
+// splitAmount = 0.00;
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 还有钱就付供应商运费
|
|
|
+// // 付供应商运费,是以供应商为单位的
|
|
|
+// if (MathUtil.compare(splitAmount, 0) > 0) {
|
|
|
+// List<ShopOrderVo> shopOrderList = orderCommonMapper.getShopOrderListByOrderId(order.getOrderId());
|
|
|
+// for (ShopOrderVo shopOrder : shopOrderList) {
|
|
|
+// // 运费
|
|
|
+// Double shopPostFee = shopOrder.getShopPostFee();
|
|
|
+// if (MathUtil.compare(shopPostFee, 0) > 0) {
|
|
|
+// // 查询已支付运费
|
|
|
+// Double shipping = payOrderMapper.getPaidShipping(order.getOrderId(), shopOrder.getShopId());
|
|
|
+// shopPostFee = MathUtil.sub(shopPostFee, shipping).doubleValue();
|
|
|
+// if (MathUtil.compare(splitAmount, shopPostFee) > -1) {
|
|
|
+// //减去运费
|
|
|
+// splitAmount = MathUtil.sub(splitAmount, shopPostFee).doubleValue();
|
|
|
+// } else {
|
|
|
+// //钱不够运费就分剩余
|
|
|
+// shopPostFee = splitAmount;
|
|
|
+// splitAmount = 0.00;
|
|
|
+// }
|
|
|
+// //todo 暂不考虑供应商有商户号,有分给供应商,没有进私账
|
|
|
+// SplitAccountPo splitAccount = new SplitAccountPo();
|
|
|
+// splitAccount.setOrderId(order.getOrderId());
|
|
|
+// splitAccount.setShopId(shopOrder.getShopId());
|
|
|
+// splitAccount.setSplitAccount(shopPostFee);
|
|
|
+// splitAccount.setProductType(2);
|
|
|
+// splitAccount.setType(2);
|
|
|
+// //todo 私账-无票,子商户商编 测试暂入奥泰
|
|
|
+// splitAccount.setSubUserNo(CUSTOMERNUM3);
|
|
|
+// if (splitAccount.getSplitAccount() > 0) {
|
|
|
+// log.info("============设置付供应商运费分账详情对象: " + splitAccount.toString());
|
|
|
+// list.add(splitAccount);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// // 如果还有钱则为佣金,分到采美网络
|
|
|
+// if (MathUtil.compare(splitAmount, 0) > 0) {
|
|
|
+// SplitAccountPo splitAccount = new SplitAccountPo();
|
|
|
+// splitAccount.setOrderId(order.getOrderId());
|
|
|
+// splitAccount.setSplitAccount(splitAmount);
|
|
|
+// splitAccount.setProductType(3);
|
|
|
+// splitAccount.setType(5);
|
|
|
+// //todo 佣金应入采美网络,测试暂入信息
|
|
|
+// splitAccount.setSubUserNo(Constant.CUSTOMERNUM);
|
|
|
+// if (splitAccount.getSplitAccount() > 0) {
|
|
|
+// log.info("============设置佣金分账详情对象: " + splitAccount.toString());
|
|
|
+// list.add(splitAccount);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// return list;
|
|
|
+// }
|
|
|
+//
|
|
|
|
|
|
|
|
|
// //正式
|
|
@@ -532,4 +532,4 @@ public class SplitAccountService {
|
|
|
// return list;
|
|
|
// }
|
|
|
|
|
|
-}
|
|
|
+//}
|