|
@@ -12,6 +12,7 @@ import com.caimei.module.pay.util.*;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang.ArrayUtils;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
+import org.apache.http.client.utils.DateUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@@ -144,7 +145,7 @@ public class PayServiceImpl implements PayService {
|
|
|
if (MathUtil.compare(MathUtil.mul(order.getPayableAmount(), 100), payment.getPayAmount()) < 0) {
|
|
|
return model.error("付款金额错误");
|
|
|
}
|
|
|
- List<SplitAccountVo> splitBillDetail = null;
|
|
|
+ //List<SplitAccountVo> splitBillDetail = null;
|
|
|
try {
|
|
|
// 时间戳
|
|
|
long time = System.currentTimeMillis() / 1000;
|
|
@@ -158,15 +159,16 @@ public class PayServiceImpl implements PayService {
|
|
|
String attach = order.getOrderID() + "," + payment.getPayType();
|
|
|
json.put("attach", attach);
|
|
|
//分账详情
|
|
|
- splitBillDetail = splitBillDetail(order, payment);
|
|
|
+ /*splitBillDetail = splitBillDetail(order, payment);
|
|
|
String parameters = ledgerParameters(splitBillDetail, order.getOrderID());
|
|
|
- json.put("splitBillDetail", parameters);
|
|
|
+ log.info("分账参数: " + parameters);
|
|
|
+ json.put("splitBillDetail", parameters);*/
|
|
|
String sign = PayUtils.buildSign(json, merKey);
|
|
|
json.put("sign", sign);
|
|
|
String data = PayUtils.buildDataPrivate(json, merKey);
|
|
|
result = PayUtils.httpGet("https://platform.mhxxkj.com/paygateway/mbpay/order/v1", merAccount, data);
|
|
|
} catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
+ log.error("错误信息", e);
|
|
|
return model.error("支付失败");
|
|
|
}
|
|
|
String code = result.getString("code");
|
|
@@ -177,7 +179,7 @@ public class PayServiceImpl implements PayService {
|
|
|
}
|
|
|
|
|
|
//保存分账信息
|
|
|
- saveSplitBillDetail(splitBillDetail, result);
|
|
|
+ //saveSplitBillDetail(splitBillDetail, result);
|
|
|
return model.success(result);
|
|
|
}
|
|
|
|
|
@@ -281,7 +283,7 @@ public class PayServiceImpl implements PayService {
|
|
|
//待分账总金额
|
|
|
BigDecimal splitAmount = payAmount;
|
|
|
//总手续费
|
|
|
- BigDecimal procedureFee;
|
|
|
+ BigDecimal procedureFee = BigDecimal.ZERO;
|
|
|
if ("UNIONPAY".equals(payment.getPayWay())) {
|
|
|
procedureFee = new BigDecimal(8);
|
|
|
} else {
|
|
@@ -291,8 +293,7 @@ public class PayServiceImpl implements PayService {
|
|
|
procedureFee = new BigDecimal("0.01");
|
|
|
}
|
|
|
}
|
|
|
- //剩余手续费
|
|
|
- BigDecimal remainingFee = procedureFee;
|
|
|
+ splitAmount = MathUtil.sub(splitAmount, procedureFee);
|
|
|
List<OrderProductVo> orderProductList = payDao.fandAllOrderProduct(order.getOrderID().intValue());
|
|
|
for (OrderProductVo orderProduct : orderProductList) {
|
|
|
BigDecimal costPrice = MathUtil.mul(orderProduct.getCostPrice(), orderProduct.getNum());
|
|
@@ -308,26 +309,19 @@ public class PayServiceImpl implements PayService {
|
|
|
if (paidAmount != null && MathUtil.compare(paidAmount, 0) > 0) {
|
|
|
costPrice = MathUtil.sub(costPrice, paidAmount);
|
|
|
}
|
|
|
- //本次分账手续费
|
|
|
- BigDecimal handlingFee;
|
|
|
//待分账金额>=本次待分账金额
|
|
|
if (MathUtil.compare(splitAmount, costPrice) > -1) {
|
|
|
- handlingFee = MathUtil.mul(procedureFee, MathUtil.div(costPrice, payAmount, 2), 2);
|
|
|
splitAmount = MathUtil.sub(splitAmount, costPrice);
|
|
|
} else {
|
|
|
costPrice = splitAmount;
|
|
|
- handlingFee = MathUtil.mul(procedureFee, MathUtil.div(costPrice, payAmount, 2), 2);
|
|
|
splitAmount = BigDecimal.ZERO;
|
|
|
}
|
|
|
- costPrice = MathUtil.sub(costPrice, handlingFee);
|
|
|
- remainingFee = MathUtil.sub(remainingFee, handlingFee);
|
|
|
String commercialCode = payDao.findCommercialCode(orderProduct.getShopID());
|
|
|
SplitAccountVo splitAccount = new SplitAccountVo();
|
|
|
splitAccount.setOrderId(order.getOrderID().intValue());
|
|
|
splitAccount.setOrderProductId(orderProduct.getOrderProductID());
|
|
|
splitAccount.setShopId(orderProduct.getShopID().intValue());
|
|
|
splitAccount.setSplitAccount(costPrice);
|
|
|
- splitAccount.setHandlingFee(handlingFee);
|
|
|
splitAccount.setProductType("1");
|
|
|
if (StringUtils.isNotBlank(commercialCode)) {
|
|
|
//供应商拥有子商户号
|
|
@@ -361,27 +355,20 @@ public class PayServiceImpl implements PayService {
|
|
|
for (ShopOrderVo shopOrder : shopOrderList) {
|
|
|
//运费
|
|
|
BigDecimal shopPostFee = shopOrder.getShopPostFee();
|
|
|
- //本次分账手续费
|
|
|
- BigDecimal handlingFee;
|
|
|
if (MathUtil.compare(shopPostFee, 0) > 0) {
|
|
|
BigDecimal shipping = payDao.findShipping(order.getOrderID(), shopOrder.getShopID());
|
|
|
shopPostFee = MathUtil.sub(shopPostFee, shipping);
|
|
|
if (MathUtil.compare(splitAmount, shopPostFee) > -1) {
|
|
|
- handlingFee = MathUtil.mul(procedureFee, MathUtil.div(shopPostFee, payAmount, 2), 2);
|
|
|
splitAmount = MathUtil.sub(splitAmount, shipping);
|
|
|
} else {
|
|
|
shopPostFee = splitAmount;
|
|
|
- handlingFee = MathUtil.mul(procedureFee, MathUtil.div(splitAmount, payAmount, 2), 2);
|
|
|
splitAmount = BigDecimal.ZERO;
|
|
|
}
|
|
|
- shopPostFee = MathUtil.sub(shopPostFee, handlingFee);
|
|
|
- remainingFee = MathUtil.sub(remainingFee, handlingFee);
|
|
|
String commercialCode = payDao.findCommercialCode(Long.valueOf(shopOrder.getShopID()));
|
|
|
SplitAccountVo splitAccount = new SplitAccountVo();
|
|
|
splitAccount.setOrderId(order.getOrderID().intValue());
|
|
|
splitAccount.setShopId(shopOrder.getShopID());
|
|
|
splitAccount.setSplitAccount(shopPostFee);
|
|
|
- splitAccount.setHandlingFee(handlingFee);
|
|
|
splitAccount.setProductType("2");
|
|
|
if (StringUtils.isNotBlank(commercialCode)) {
|
|
|
//供应商拥有子商户号
|
|
@@ -402,77 +389,12 @@ public class PayServiceImpl implements PayService {
|
|
|
SplitAccountVo splitAccount = new SplitAccountVo();
|
|
|
splitAccount.setOrderId(order.getOrderID().intValue());
|
|
|
splitAccount.setSplitAccount(splitAmount);
|
|
|
- splitAccount.setHandlingFee(remainingFee);
|
|
|
splitAccount.setProductType("3");
|
|
|
splitAccount.setType("2");
|
|
|
splitAccount.setSubUserNo(privateAccountNo);
|
|
|
list.add(splitAccount);
|
|
|
}
|
|
|
return list;
|
|
|
-
|
|
|
- /*List<OrderProductVo> orderProductList = payDao.fandAllOrderProduct(order.getOrderID().intValue());
|
|
|
- //私账-无票总金额
|
|
|
- BigDecimal privateAccountAmount = BigDecimal.ZERO;
|
|
|
- //公账-普票总金额
|
|
|
- BigDecimal commonAmount = BigDecimal.ZERO;
|
|
|
- if ("0".equals(order.getSecondHandOrderFlag())) {
|
|
|
- //非二手订单才统计
|
|
|
- for (OrderProductVo orderProduct : orderProductList) {
|
|
|
- //不含税-不能开票,则分账到私账银行卡
|
|
|
- if ("0".equals(orderProduct.getIncludedTax()) && "3".equals(orderProduct.getInvoiceType())) {
|
|
|
- privateAccountAmount = MathUtil.add(privateAccountAmount, orderProduct.getShouldPayFee());
|
|
|
- } else if ("2".equals(orderProduct.getInvoiceType())) {
|
|
|
- //普通发票
|
|
|
- commonAmount = MathUtil.add(commonAmount, orderProduct.getShouldPayFee());
|
|
|
- }
|
|
|
- }
|
|
|
- order.setPayTotalFee(MathUtil.add(order.getPayTotalFee(), order.getPromotionFullReduction()));
|
|
|
- }
|
|
|
- if (MathUtil.compare(privateAccountAmount, order.getPayTotalFee()) == 0 || "1".equals(order.getSecondHandOrderFlag())) {
|
|
|
- //二手订单与不含税-不能开票,全部分给私账
|
|
|
- Map<String, String> map = new HashMap<>(3);
|
|
|
- map.put("subUserNo", privateAccountNo);
|
|
|
- map.put("splitBillType", "2");
|
|
|
- map.put("splitBillValue", MathUtil.mul(fashionableAmount, 100).toString());
|
|
|
- list.add(map);
|
|
|
- } else {
|
|
|
- //分给私账金额
|
|
|
- BigDecimal privateAccount = MathUtil.div(MathUtil.mul(fashionableAmount, privateAccountAmount), order.getPayTotalFee(), 8);
|
|
|
- log.info("分给私账金额>>>>>>>>>>>>>>>>>>>>>>>" + privateAccount);
|
|
|
- privateAccount = MathUtil.div(MathUtil.mul(fashionableAmount, privateAccountAmount), order.getPayTotalFee(), 2);
|
|
|
- //分给公账-普票金额
|
|
|
- BigDecimal commonInvoice = MathUtil.div(MathUtil.mul(fashionableAmount, commonAmount), order.getPayTotalFee(), 2);
|
|
|
- if (MathUtil.compare(privateAccount, 0) != 0) {
|
|
|
- //私账-无票
|
|
|
- Map<String, String> map1 = new HashMap<>(3);
|
|
|
- map1.put("subUserNo", privateAccountNo);
|
|
|
- map1.put("splitBillType", "2");
|
|
|
- //分账金额,单位/分
|
|
|
- BigDecimal splitBillValue = MathUtil.round(MathUtil.mul(privateAccount, 100), 0);
|
|
|
- map1.put("splitBillValue", String.valueOf(splitBillValue));
|
|
|
- list.add(map1);
|
|
|
- }
|
|
|
- if (MathUtil.compare(commonInvoice, 0) != 0) {
|
|
|
- //公账-普票
|
|
|
- Map<String, String> map3 = new HashMap<>(3);
|
|
|
- map3.put("subUserNo", commonInvoiceNo);
|
|
|
- map3.put("splitBillType", "2");
|
|
|
- BigDecimal splitBillValue = MathUtil.round(MathUtil.mul(commonInvoice, 100), 0);
|
|
|
- map3.put("splitBillValue", String.valueOf(splitBillValue));
|
|
|
- list.add(map3);
|
|
|
- }
|
|
|
- BigDecimal publicAccount = MathUtil.add(privateAccount, commonInvoice);
|
|
|
- if (MathUtil.compare(publicAccount, fashionableAmount) != 0) {
|
|
|
- //公账-专票
|
|
|
- Map<String, String> map2 = new HashMap<>(3);
|
|
|
- map2.put("subUserNo", publicAccountNo);
|
|
|
- map2.put("splitBillType", "2");
|
|
|
- BigDecimal splitBillValue = MathUtil.round(MathUtil.mul(MathUtil.sub(fashionableAmount, publicAccount), 100), 0);
|
|
|
- map2.put("splitBillValue", String.valueOf(splitBillValue));
|
|
|
- list.add(map2);
|
|
|
- }
|
|
|
- }*/
|
|
|
- //return JSONObject.toJSONString(list);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -584,10 +506,11 @@ public class PayServiceImpl implements PayService {
|
|
|
relation.setMbOrderId(mbOrderId);
|
|
|
relation.setOrderRequestNo(orderRequestNo);
|
|
|
relation.setDelFlag("0");
|
|
|
+ relation.setSplitStatus("0");
|
|
|
payDao.insertOrderRelation(relation);
|
|
|
log.info(">>>>>>>>>>>>>>>>>>>>>>>保存付款金额到收款记录," + amount);
|
|
|
//修改分账付款状态
|
|
|
- payDao.updateSplitAccountByPay(mbOrderId);
|
|
|
+ //payDao.updateSplitAccountByPay(mbOrderId);
|
|
|
//判断是否是充值商品
|
|
|
getRechargeGoods(order, amount);
|
|
|
return "SUCCESS";
|
|
@@ -757,7 +680,7 @@ public class PayServiceImpl implements PayService {
|
|
|
try {
|
|
|
data = PayUtils.buildDataPrivate(json, merKey);
|
|
|
} catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
+ log.error("错误信息", e);
|
|
|
}
|
|
|
JSONObject result = PayUtils.httpGet("https://platform.mhxxkj.com/paygateway/mbpay/order/query/v1_1", merAccount, data);
|
|
|
String code = result.getString("code");
|
|
@@ -802,7 +725,7 @@ public class PayServiceImpl implements PayService {
|
|
|
String data = PayUtils.buildDataPrivate(json, merKey);
|
|
|
result = PayUtils.httpGet("https://platform.mhxxkj.com/paygateway/mbpay/order/v1", merAccount, data);
|
|
|
} catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
+ log.error("错误信息", e);
|
|
|
return model.error("支付失败");
|
|
|
}
|
|
|
String code = result.getString("code");
|
|
@@ -821,10 +744,8 @@ public class PayServiceImpl implements PayService {
|
|
|
splitAccount.setType("2");
|
|
|
if ("UNIONPAY".equals(payment.getPayWay())) {
|
|
|
splitAccount.setSplitAccount(BigDecimal.valueOf(92));
|
|
|
- splitAccount.setHandlingFee(new BigDecimal(8));
|
|
|
} else {
|
|
|
splitAccount.setSplitAccount(BigDecimal.valueOf(99.62));
|
|
|
- splitAccount.setHandlingFee(new BigDecimal("0.38"));
|
|
|
}
|
|
|
JSONObject data = result.getJSONObject("data");
|
|
|
splitAccount.setMbOrderId(data.getString("mbOrderId"));
|
|
@@ -873,4 +794,157 @@ public class PayServiceImpl implements PayService {
|
|
|
payDao.updateSplitAccountByPay(mbOrderId);
|
|
|
return "SUCCESS";
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void delayedSplitting(String notifyUrl) {
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.setTime(new Date());
|
|
|
+ calendar.add(Calendar.DATE, -1);
|
|
|
+ String currentTime = DateUtils.formatDate(calendar.getTime(), "yyyy-MM-dd HH:mm:ss");
|
|
|
+ List<OrderRelationVo> orderRelations = payDao.findUnallocatedAccount(currentTime);
|
|
|
+ if (orderRelations != null && orderRelations.size() > 0) {
|
|
|
+ for (OrderRelationVo orderRelation : orderRelations) {
|
|
|
+ log.info("订单id" + orderRelation.getOrderID() + ">>>进入延时分账");
|
|
|
+ OrderVo order = payDao.findOrder(orderRelation.getOrderID());
|
|
|
+ Payment payment = new Payment();
|
|
|
+ payment.setPayAmount(MathUtil.mul(orderRelation.getAssociateAmount(), 100).intValue());
|
|
|
+ if ("12".equals(orderRelation.getPayType())) {
|
|
|
+ //网银支付
|
|
|
+ payment.setPayWay("UNIONPAY");
|
|
|
+ }
|
|
|
+ List<SplitAccountVo> splitBillDetail = splitBillDetail(order, payment);
|
|
|
+ String parameters = ledgerParameters(splitBillDetail, order.getOrderID());
|
|
|
+ log.info("分账参数: " + parameters);
|
|
|
+
|
|
|
+ //第三方分账接口
|
|
|
+ JSONObject result = null;
|
|
|
+ try {
|
|
|
+ // 时间戳
|
|
|
+ long time = System.currentTimeMillis() / 1000;
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
+ json.put("merAccount", merAccount);
|
|
|
+ json.put("orderId", orderRelation.getOrderRequestNo());
|
|
|
+ json.put("requestNo", orderRelation.getOrderRequestNo());
|
|
|
+ json.put("mbOrderId", orderRelation.getMbOrderId());
|
|
|
+ json.put("time", time);
|
|
|
+ json.put("splitBillDetail", parameters);
|
|
|
+ json.put("notifyUrl", notifyUrl);
|
|
|
+ log.info("回调接口>>>" + notifyUrl);
|
|
|
+ String sign = PayUtils.buildSign(json, merKey);
|
|
|
+ json.put("sign", sign);
|
|
|
+ String data = PayUtils.buildDataPrivate(json, merKey);
|
|
|
+ result = PayUtils.httpGet("https://platform.mhxxkj.com/paygateway/mbpay/splitOrder/v1", merAccount, data);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("错误信息", e);
|
|
|
+ }
|
|
|
+ if (result != null) {
|
|
|
+ String code = result.getString("code");
|
|
|
+ if (!"000000".equals(code)) {
|
|
|
+ String msg = result.getString("msg");
|
|
|
+ log.info("第三方延迟分账失败>>>>>>>msg:" + msg);
|
|
|
+ } else {
|
|
|
+ //保存分账记录
|
|
|
+ for (SplitAccountVo splitAccount : splitBillDetail) {
|
|
|
+ splitAccount.setMbOrderId(orderRelation.getMbOrderId());
|
|
|
+ splitAccount.setOrderRequestNo(orderRelation.getOrderRequestNo());
|
|
|
+ splitAccount.setPayStatus("1");
|
|
|
+ payDao.insertSplitAccount(splitAccount);
|
|
|
+ }
|
|
|
+ log.info("此订单分账结束");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String delayedSplittingCallback(String data) throws Exception {
|
|
|
+ //公钥解密
|
|
|
+ JSONObject json = PayUtils.decryptDataPublic(data, publicKey);
|
|
|
+ log.info("公钥解密>>>>>>" + json);
|
|
|
+ //公钥验签
|
|
|
+ String signaa = json.getString("sign");
|
|
|
+ json.remove("sign");
|
|
|
+ String signbb = PayUtils.buildSign(json, publicKey);
|
|
|
+ if (!signaa.equals(signbb)) {
|
|
|
+ return "验签失败";
|
|
|
+ }
|
|
|
+ String mbOrderId = json.getString("mbOrderId");
|
|
|
+ String status = json.getString("status");
|
|
|
+ log.info("分账状态>>>" + status);
|
|
|
+ if ("FAILED".equals(status)) {
|
|
|
+ return "分账失败";
|
|
|
+ }
|
|
|
+
|
|
|
+ //修改收款分账状态
|
|
|
+ payDao.updateBySplitStatus(mbOrderId);
|
|
|
+
|
|
|
+ List<SplitAccountVo> splitAccountList = payDao.findByMbOrderId(mbOrderId);
|
|
|
+ if (splitAccountList != null && splitAccountList.size() > 0) {
|
|
|
+ //本次付供应商金额(分账金额)
|
|
|
+ BigDecimal splitAmount = BigDecimal.ZERO;
|
|
|
+ Integer orderId = null;
|
|
|
+ Integer shopId = null;
|
|
|
+ Integer shopOrderId = null;
|
|
|
+ for (SplitAccountVo account : splitAccountList) {
|
|
|
+ splitAmount = MathUtil.add(splitAmount, account.getSplitAccount());
|
|
|
+ orderId = account.getOrderId();
|
|
|
+ shopId = account.getShopId();
|
|
|
+ }
|
|
|
+ //已付供应商金额
|
|
|
+ BigDecimal paidAmount = payDao.findPaidShop(shopOrderId);
|
|
|
+ List<ShopOrderVo> shopOrderList = payDao.findShopOrder(Long.valueOf(orderId));
|
|
|
+ String payStatus = "";
|
|
|
+ //子订单是否全部付款
|
|
|
+ boolean isPay = true;
|
|
|
+ for (ShopOrderVo shopOrder : shopOrderList) {
|
|
|
+ if (shopId.equals(shopOrder.getShopID())) {
|
|
|
+ shopOrderId = shopOrder.getShopOrderID();
|
|
|
+ BigDecimal paidShop = MathUtil.add(paidAmount, splitAmount);
|
|
|
+ if (MathUtil.compare(shopOrder.getShouldPayShopAmount(), paidShop) == 0) {
|
|
|
+ payStatus = "2";
|
|
|
+ } else {
|
|
|
+ payStatus = "3";
|
|
|
+ }
|
|
|
+ //修改子订单付款状态及付款金额
|
|
|
+ payDao.updateShopOrderByPayStatus(shopOrderId, paidShop, payStatus);
|
|
|
+ } else if (!"3".equals(shopOrder.getPayStatus())) {
|
|
|
+ isPay = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String currentTime = DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss");
|
|
|
+ //保存付供应商记录
|
|
|
+ PayShopVo payShop = new PayShopVo();
|
|
|
+ payShop.setShopID(shopId);
|
|
|
+ payShop.setName("线上支付分账");
|
|
|
+ payShop.setTotalAmount(splitAmount);
|
|
|
+ payShop.setPayType("6");
|
|
|
+ payShop.setStatus("1");
|
|
|
+ payShop.setDelFlag("0");
|
|
|
+ payShop.setApplyTime(currentTime);
|
|
|
+ payShop.setReviewTime(currentTime);
|
|
|
+
|
|
|
+ payDao.insertPayShop(payShop);
|
|
|
+ PayShopRecordVo shopRecord = new PayShopRecordVo();
|
|
|
+ shopRecord.setShopID(shopId);
|
|
|
+ shopRecord.setShopOrderID(shopOrderId);
|
|
|
+ shopRecord.setPayAmount(splitAmount);
|
|
|
+ shopRecord.setPayType("6");
|
|
|
+ shopRecord.setPayTime(currentTime);
|
|
|
+ shopRecord.setPayShopID(payShop.getId().intValue());
|
|
|
+ shopRecord.setStatus("2");
|
|
|
+ shopRecord.setDelFlag("0");
|
|
|
+ payDao.insertPayShopRecord(shopRecord);
|
|
|
+
|
|
|
+ //修改主订单修改状态
|
|
|
+ if ("3".equals(payStatus) && isPay) {
|
|
|
+ payDao.updateOrderByPayStatus(orderId, payStatus);
|
|
|
+ } else {
|
|
|
+ payDao.updateOrderByPayStatus(orderId, "2");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return "SUCCESS";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|