|
@@ -9,6 +9,7 @@ import com.caimei.modules.order.utils.PayUtil;
|
|
|
import com.caimei.redis.RedisService;
|
|
|
import com.caimei.utils.MathUtil;
|
|
|
import com.thinkgem.jeesite.common.persistence.Page;
|
|
|
+import okhttp3.*;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -16,289 +17,343 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.io.IOException;
|
|
|
+import java.lang.reflect.Field;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
-//@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 {
|
|
|
+
|
|
|
+ public static OkHttpClient client = new OkHttpClient.Builder()
|
|
|
+ .connectTimeout(3, TimeUnit.SECONDS)
|
|
|
+ .readTimeout(20, TimeUnit.SECONDS)
|
|
|
+ .build();
|
|
|
+ /**
|
|
|
+ * 日志对象
|
|
|
+ */
|
|
|
+ private static Logger logger = LoggerFactory.getLogger(Logger.class);
|
|
|
+
|
|
|
+ @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() + "进入分账");
|
|
|
+ // 收款对应的订单信息
|
|
|
+ ShopOrderVo shopOrder = newOrderDao.getShopOrderListByOrderId(orderRelation.getShopOrderId());
|
|
|
+ PayParamBo payParam = new PayParamBo();
|
|
|
+ //支付金额
|
|
|
+ payParam.setAllPay(orderRelation.getAssociateAmount());
|
|
|
+ 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(shopOrder, payParam);
|
|
|
+ HashMap<String, BigDecimal> sbm = new HashMap<>();
|
|
|
+ for (SplitAccountPo splitAccountPo : splitBillDetail) {
|
|
|
+ String subUserNo = splitAccountPo.getSubUserNo();
|
|
|
+ if(sbm.containsKey(subUserNo)){
|
|
|
+ BigDecimal v = MathUtil.add(sbm.get(subUserNo), splitAccountPo.getSplitAccount());
|
|
|
+ sbm.put(subUserNo,v);
|
|
|
+ }else{
|
|
|
+ sbm.put(subUserNo,BigDecimal.valueOf(splitAccountPo.getSplitAccount()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ArrayList<AccountPayOrder.AccountPayOrderExt.SplitBillRule> splitBillRules = new ArrayList<>();
|
|
|
+ sbm.forEach((key, value) -> {
|
|
|
+ AccountPayOrder.AccountPayOrderExt.SplitBillRule splitBillRule = new AccountPayOrder.AccountPayOrderExt.SplitBillRule();
|
|
|
+ splitBillRule.setSplitBillAmount(value);
|
|
|
+ splitBillRule.setSplitBillMerchantNo(key);
|
|
|
+ splitBillRules.add(splitBillRule);
|
|
|
+ });
|
|
|
+ // 自己的不分
|
|
|
+ splitBillRules.removeIf(s->s.getSplitBillMerchantNo().equals(shopOrder.getSplitCode()));
|
|
|
+ //第三方分账接口
|
|
|
+ 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());
|
|
|
+ //付款账户子订单绑定商户号
|
|
|
+ accountPayOrder.setP5_customerNumber(shopOrder.getSplitCode());
|
|
|
+ AccountPayOrder.AccountPayOrderExt accountPayOrderExt = new AccountPayOrder.AccountPayOrderExt();
|
|
|
+ //收款账户商编 填写splitBillRules时候不填写MerchantNo,Amount并且即使填写这两个参数不生效!!
|
|
|
+// accountPayOrderExt.setInMerchantNo(splitMoneyVo.getName());
|
|
|
+ accountPayOrderExt.setOrderType(AccountPayOrderType.TRANSFER);
|
|
|
+// accountPayOrderExt.setAmount(splitMoneyVo.getSplitMoney());
|
|
|
+ accountPayOrderExt.setServerCallbackUrl(Constant.betaSplit);
|
|
|
+ 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 {
|
|
|
+ for (SplitAccountPo splitAccount : splitBillDetail) {
|
|
|
+ splitAccount.setMbOrderId(orderRelation.getMbOrderId());
|
|
|
+ splitAccount.setOrderRequestNo(substring + orderRelation.getOrderRequestNo());
|
|
|
+ splitAccount.setPayStatus(1);
|
|
|
+ // 保存分账详情
|
|
|
+ newOrderDao.insertSplitAccount(splitAccount);
|
|
|
+ }
|
|
|
+ redisService.remove("XSFZMDS");
|
|
|
+ logger.info("【手动分账】>>>>>>>>>>此订单分账结束");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("【手动分账】>>>>>>>>>>错误信息", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private List<SplitAccountPo> setSplitAccountDetail(ShopOrderVo shopOrder, PayParamBo payParam) {
|
|
|
+ List<SplitAccountPo> list = new ArrayList<>();
|
|
|
+ // 本次支付金额,单位/元
|
|
|
+ double payAmount = payParam.getAllPay();
|
|
|
+ // 待分账总金额
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ //手续费承担方 线上支付手续费:默认1采美承担,2供应商承担
|
|
|
+ Integer supportFlag = newOrderDao.findSupport(shopOrder.getShopOrderId());
|
|
|
+ //减去收款手续费
|
|
|
+ splitAmount = MathUtil.sub(splitAmount, procedureFee).doubleValue();
|
|
|
+
|
|
|
+ // 商品数据
|
|
|
+ List<OrderProductVo> orderProductList = newOrderDao.getOrderProductByShopOrderId(shopOrder.getShopOrderId());
|
|
|
+
|
|
|
+ for (OrderProductVo orderProduct : orderProductList) {
|
|
|
+ //成本价*数量
|
|
|
+ double costPrice = MathUtil.mul(orderProduct.getCostPrice(), orderProduct.getNum()).doubleValue();
|
|
|
+ if (2 == supportFlag) {
|
|
|
+ //供应商自己承担手续费
|
|
|
+ costPrice = MathUtil.sub(costPrice, procedureFee).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 = newOrderDao.getOrderProductPaidAmount(orderProduct.getOrderProductId());
|
|
|
+ // 支付过金额大于0
|
|
|
+ //有已付
|
|
|
+ if (null != paidAmount && MathUtil.compare(paidAmount, 0) > 0) {
|
|
|
+ //已付>0,成本-已付
|
|
|
+ costPrice = MathUtil.sub(costPrice, paidAmount).doubleValue();
|
|
|
+ }
|
|
|
+ // 待分账金额>成本
|
|
|
+ if (MathUtil.compare(splitAmount, costPrice) > 0) {
|
|
|
+ // 待分账金额-成本
|
|
|
+ splitAmount = MathUtil.sub(splitAmount, costPrice).doubleValue();
|
|
|
+ } else {
|
|
|
+ costPrice = splitAmount;
|
|
|
+ splitAmount = 0.00;
|
|
|
+ }
|
|
|
+ if (costPrice > 0) {
|
|
|
+ SplitAccountPo splitAccount = new SplitAccountPo();
|
|
|
+ splitAccount.setShopOrderId(shopOrder.getShopOrderId());
|
|
|
+ splitAccount.setOrderId(shopOrder.getOrderId());
|
|
|
+ splitAccount.setOrderProductId(orderProduct.getOrderProductId());
|
|
|
+ splitAccount.setShopId(orderProduct.getShopId());
|
|
|
+ splitAccount.setSplitAccount(costPrice);
|
|
|
+ splitAccount.setProductType(1);
|
|
|
+ if (StringUtils.isNotBlank(orderProduct.getSplitCode())) {
|
|
|
+ // 该商品设置了商户号
|
|
|
+ splitAccount.setType(4);
|
|
|
+ splitAccount.setSubUserNo(orderProduct.getSplitCode());
|
|
|
+ }
|
|
|
+ logger.info("成本分账参数------------->" + splitAccount.toString());
|
|
|
+ list.add(splitAccount);
|
|
|
+ }
|
|
|
+ if (MathUtil.compare(splitAmount, 0) == 0) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 还有钱就付供应商运费
|
|
|
+ // 付供应商运费,是以供应商为单位的
|
|
|
+ if (MathUtil.compare(splitAmount, 0) > 0) {
|
|
|
+ // 运费
|
|
|
+ Double shopPostFee = shopOrder.getShopPostFee();
|
|
|
+ if (MathUtil.compare(shopPostFee, 0) > 0) {
|
|
|
+ // 查询已支付运费
|
|
|
+ Double shipping = newOrderDao.getPaidShipping(shopOrder.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;
|
|
|
+ }
|
|
|
+ SplitAccountPo splitAccount = new SplitAccountPo();
|
|
|
+ splitAccount.setOrderId(shopOrder.getOrderId());
|
|
|
+ splitAccount.setShopId(shopOrder.getShopId());
|
|
|
+ splitAccount.setSplitAccount(shopPostFee);
|
|
|
+ splitAccount.setProductType(2);
|
|
|
+ if (StringUtils.isNotBlank(shopOrder.getSplitCode())) {
|
|
|
+ //供应商拥有子商户号
|
|
|
+ splitAccount.setType(4);
|
|
|
+ splitAccount.setSubUserNo(shopOrder.getSplitCode());
|
|
|
+ }
|
|
|
+ logger.info("付供应商运费分账参数------------->" + splitAccount);
|
|
|
+ list.add(splitAccount);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 如果还有钱则为佣金,分到采美网络
|
|
|
+ if (MathUtil.compare(splitAmount, 0) > 0) {
|
|
|
+ //分账手续费0.1%采美承担,佣金扣除0.1%
|
|
|
+ Double amount = Math.max(MathUtil.mul(splitAmount, 0.001, 2).doubleValue(), 0.01);
|
|
|
+ splitAmount = MathUtil.sub(splitAmount, amount).doubleValue();
|
|
|
+ SplitAccountPo splitAccount = new SplitAccountPo();
|
|
|
+ splitAccount.setOrderId(shopOrder.getOrderId());
|
|
|
+ splitAccount.setShopOrderId(shopOrder.getShopOrderId());
|
|
|
+ splitAccount.setSplitAccount(splitAmount);
|
|
|
+ splitAccount.setProductType(3);
|
|
|
+ splitAccount.setType(5);
|
|
|
+ splitAccount.setSubUserNo(Constant.CUSTOMERNUM);
|
|
|
+ logger.info("佣金分账参数------------->" + splitAccount);
|
|
|
+ list.add(splitAccount);
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static <T> T postForm(Map<String, String> params, String url, String sign, Class<T> clazz) {
|
|
|
+ FormBody.Builder builder = new FormBody.Builder();
|
|
|
+ for (Map.Entry<String, String> entry : params.entrySet()) {
|
|
|
+ builder.add(entry.getKey(), entry.getValue());
|
|
|
+ }
|
|
|
+ builder.add("sign", sign);
|
|
|
+
|
|
|
+ Request request = new Request.Builder() // okHttp post
|
|
|
+ .url(url)
|
|
|
+ .post(builder.build())
|
|
|
+ .build();
|
|
|
+
|
|
|
+ Response response = null;
|
|
|
+ try {
|
|
|
+ response = client.newCall(request).execute();
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new IllegalStateException("请求出错", e);
|
|
|
+ }
|
|
|
+ if (!response.isSuccessful()) {
|
|
|
+ try {
|
|
|
+ logger.info(response.body().string());
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ throw new RuntimeException("请求失败了: http response code: " + response.code());
|
|
|
+ }
|
|
|
+
|
|
|
+ ResponseBody body = response.body();
|
|
|
+ String content = null;
|
|
|
+ try {
|
|
|
+ content = body.string();
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new IllegalStateException("IO异常", e);
|
|
|
+ }
|
|
|
+ JSONObject res = JSON.parseObject(content);
|
|
|
+ if (!res.getBooleanValue("rt4_success")) {
|
|
|
+ logger.error("error: " + res.getString("rt6_retMsg"));
|
|
|
+ }
|
|
|
+ /** rt4_success 为 true,需验签 **/
|
|
|
+ return res.toJavaObject(clazz);
|
|
|
+ }
|
|
|
|
|
|
+ public static Map<String, String> convertBean(Object bean) {
|
|
|
+ Class clazz = bean.getClass();
|
|
|
+ Field[] fields = clazz.getDeclaredFields();
|
|
|
+ for (Field f : fields) {
|
|
|
+ f.setAccessible(true);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ Map<String, String> retMap = new LinkedHashMap<>();
|
|
|
+ for (Field f : fields) {
|
|
|
+ String key = f.toString().substring(f.toString().lastIndexOf(".") + 1);
|
|
|
+ Object value = f.get(bean);
|
|
|
+ if (value == null) {
|
|
|
+ value = "";
|
|
|
+ }
|
|
|
+ retMap.put(key, (String) value);
|
|
|
+ }
|
|
|
+ return retMap;
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.info("分账", e);
|
|
|
+ throw new IllegalStateException("分账异常", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
// //正式
|
|
|
//// public static final String callUrl = "https://core.caimei365.com/order/pay/delay/split/callback";
|
|
@@ -532,4 +587,3 @@ import java.util.*;
|
|
|
// return list;
|
|
|
// }
|
|
|
|
|
|
-//}
|