|
@@ -1,5 +1,7 @@
|
|
|
package com.caimei.module.pay.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.caimei.module.base.entity.bo.JsonModel;
|
|
|
import com.caimei.module.base.entity.bo.Payment;
|
|
@@ -124,6 +126,7 @@ public class PayServiceImpl implements PayService {
|
|
|
if (MathUtil.compare(MathUtil.mul(order.getPayableAmount(), 100), payment.getPayAmount()) < 0) {
|
|
|
return model.error("付款金额错误");
|
|
|
}
|
|
|
+ String splitBillDetail = null;
|
|
|
try {
|
|
|
// 时间戳
|
|
|
long time = System.currentTimeMillis() / 1000;
|
|
@@ -137,7 +140,7 @@ public class PayServiceImpl implements PayService {
|
|
|
String attach = order.getOrderID() + "," + payment.getPayType();
|
|
|
json.put("attach", attach);
|
|
|
//分账详情
|
|
|
- String splitBillDetail = splitBillDetail(order, payment);
|
|
|
+ splitBillDetail = splitBillDetail(order, payment);
|
|
|
if ("分账失败".equals(splitBillDetail)) {
|
|
|
return model.error("本次付款金额过小,分账失败");
|
|
|
}
|
|
@@ -157,9 +160,49 @@ public class PayServiceImpl implements PayService {
|
|
|
log.info("第三方支付失败>>>>>>>msg:" + msg);
|
|
|
return model.error(msg);
|
|
|
}
|
|
|
+
|
|
|
+ //保存分账信息
|
|
|
+ saveSplitBillDetail(splitBillDetail, result, payment);
|
|
|
return model.success(result);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 保存分账信息
|
|
|
+ */
|
|
|
+ private void saveSplitBillDetail(String splitBillDetail, JSONObject result, Payment payment) {
|
|
|
+ JSONArray parseArray = JSON.parseArray(splitBillDetail);
|
|
|
+ JSONObject data = result.getJSONObject("data");
|
|
|
+ String mbOrderId = data.getString("mbOrderId");
|
|
|
+ String orderRequestNo = data.getString("orderId");
|
|
|
+ for (int i = 0; i < parseArray.size(); i++) {
|
|
|
+ String subUserNo = parseArray.getJSONObject(i).getString("subUserNo");
|
|
|
+ String splitBillType = parseArray.getJSONObject(i).getString("splitBillType");
|
|
|
+ String splitBillValue = parseArray.getJSONObject(i).getString("splitBillValue");
|
|
|
+ SplitAccount splitAccount = new SplitAccount();
|
|
|
+ splitAccount.setMbOrderId(mbOrderId);
|
|
|
+ if (subUserNo.equals(publicAccountNo)) {
|
|
|
+ splitAccount.setType("1");
|
|
|
+ } else {
|
|
|
+ splitAccount.setType("2");
|
|
|
+ }
|
|
|
+ splitAccount.setSubUserNo(subUserNo);
|
|
|
+ if ("1".equals(splitBillType)) {
|
|
|
+ splitAccount.setProductId(payment.getProductId());
|
|
|
+ if ("UNIONPAY".equals(payment.getPayWay())) {
|
|
|
+ splitAccount.setSplitAccount(BigDecimal.valueOf(92));
|
|
|
+ } else {
|
|
|
+ splitAccount.setSplitAccount(BigDecimal.valueOf(99.62));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ splitAccount.setOrderId(payment.getOrderId());
|
|
|
+ splitAccount.setSplitAccount(MathUtil.div(splitBillValue, 100));
|
|
|
+ }
|
|
|
+ splitAccount.setOrderRequestNo(orderRequestNo);
|
|
|
+ splitAccount.setPayStatus("0");
|
|
|
+ payDao.insertSplitAccount(splitAccount);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 设置第三方支付参数
|
|
|
*/
|
|
@@ -362,6 +405,8 @@ public class PayServiceImpl implements PayService {
|
|
|
relation.setDelFlag("0");
|
|
|
payDao.insertOrderRelation(relation);
|
|
|
log.info(">>>>>>>>>>>>>>>>>>>>>>>保存付款金额到收款记录," + amount);
|
|
|
+ //修改分账付款状态
|
|
|
+ payDao.updateSplitAccountByPay(mbOrderId);
|
|
|
return "SUCCESS";
|
|
|
}
|
|
|
|
|
@@ -497,6 +542,7 @@ public class PayServiceImpl implements PayService {
|
|
|
@Override
|
|
|
public JsonModel secondHandPay(Payment payment, HttpServletRequest request) {
|
|
|
JSONObject result = null;
|
|
|
+ String splitBillDetail = null;
|
|
|
try {
|
|
|
// 时间戳
|
|
|
long time = System.currentTimeMillis() / 1000;
|
|
@@ -516,7 +562,7 @@ public class PayServiceImpl implements PayService {
|
|
|
map.put("splitBillType", "1");
|
|
|
map.put("splitBillValue", "1");
|
|
|
list.add(map);
|
|
|
- String splitBillDetail = JSONObject.toJSONString(list);
|
|
|
+ splitBillDetail = JSONObject.toJSONString(list);
|
|
|
json.put("splitBillDetail", splitBillDetail);
|
|
|
String sign = PayUtils.buildSign(json, merKey);
|
|
|
json.put("sign", sign);
|
|
@@ -532,6 +578,7 @@ public class PayServiceImpl implements PayService {
|
|
|
log.info("第三方支付失败>>>>>>>msg:" + msg);
|
|
|
return model.error(msg);
|
|
|
}
|
|
|
+ saveSplitBillDetail(splitBillDetail, result, payment);
|
|
|
return model.success(result);
|
|
|
}
|
|
|
|
|
@@ -549,6 +596,8 @@ public class PayServiceImpl implements PayService {
|
|
|
}
|
|
|
//订单状态
|
|
|
String orderStatus = json.getString("orderStatus");
|
|
|
+ //平台唯一流水号
|
|
|
+ String mbOrderId = json.getString("mbOrderId");
|
|
|
//附加数据,下单时若有传输则原样返回,下单时为空,则不返回该数据
|
|
|
String attach = json.getString("attach");
|
|
|
//订单金额,以元为单位
|
|
@@ -568,6 +617,8 @@ public class PayServiceImpl implements PayService {
|
|
|
seconHandProduct.setPayType(getPayType(payType));
|
|
|
seconHandProduct.setProductID(productId);
|
|
|
payDao.updateSeconHand(seconHandProduct);
|
|
|
+ //修改分账付款状态
|
|
|
+ payDao.updateSplitAccountByPay(mbOrderId);
|
|
|
return "SUCCESS";
|
|
|
}
|
|
|
}
|