|
@@ -6,6 +6,7 @@ import com.caimei365.order.components.OrderCommonService;
|
|
|
import com.caimei365.order.components.ProductService;
|
|
|
import com.caimei365.order.components.WeChatService;
|
|
|
import com.caimei365.order.mapper.BaseMapper;
|
|
|
+import com.caimei365.order.mapper.OrderClubMapper;
|
|
|
import com.caimei365.order.mapper.OrderCommonMapper;
|
|
|
import com.caimei365.order.mapper.PayOrderMapper;
|
|
|
import com.caimei365.order.model.ResponseJson;
|
|
@@ -42,6 +43,9 @@ import java.util.*;
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
|
|
+import static org.bouncycastle.asn1.x500.style.RFC4519Style.c;
|
|
|
+import static org.bouncycastle.asn1.x500.style.RFC4519Style.o;
|
|
|
+
|
|
|
/**
|
|
|
* Description
|
|
|
*
|
|
@@ -64,6 +68,8 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
|
@Resource
|
|
|
private WeChatService weChatService;
|
|
|
@Resource
|
|
|
+ private OrderClubMapper orderClubMapper;
|
|
|
+ @Resource
|
|
|
private RemoteCallService remoteCallService;
|
|
|
@Value("${pay.redirect-link}")
|
|
|
private String redirectLink;
|
|
@@ -124,6 +130,7 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
|
return ResponseJson.success(map);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 订单支付,余额抵扣
|
|
|
*
|
|
@@ -142,6 +149,7 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
|
Double availableMoney = baseMapper.getAbleUserMoney(order.getUserId());
|
|
|
Double balancePayFee = 0d;
|
|
|
if (MathUtil.compare(availableMoney, 0) > 0) {
|
|
|
+ //可用余额>待付
|
|
|
if (MathUtil.compare(availableMoney, order.getPendingPayments()) >= 0) {
|
|
|
if (OrderStatus.UNCONFIRMED.getCode() != order.getStatus()) {
|
|
|
if (1 == order.getSendOutStatus()) {
|
|
@@ -168,8 +176,9 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
|
order.setReceiptStatus(2);
|
|
|
balancePayFee = availableMoney;
|
|
|
}
|
|
|
-
|
|
|
+ //设置余额支付金额
|
|
|
order.setBalancePayFee(MathUtil.add(order.getBalancePayFee(), balancePayFee).doubleValue());
|
|
|
+ //设置真实支付金额
|
|
|
order.setPayableAmount(MathUtil.sub(order.getPayableAmount(), balancePayFee).doubleValue());
|
|
|
Date date = new Date();
|
|
|
String curDateStr = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(date);
|
|
@@ -181,26 +190,67 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
|
// 修改账户余额
|
|
|
double userMoney = baseMapper.getUserMoney(order.getUserId());
|
|
|
if (OrderStatus.UNCONFIRMED.getCode() != order.getStatus()) {
|
|
|
- userMoney = MathUtil.sub(userMoney, balancePayFee).doubleValue();
|
|
|
//保存收款记录
|
|
|
productService.saveDiscernReceipt(balancePayFee, orderId, "【订单支付,余额抵扣】");
|
|
|
}
|
|
|
+ //可用=可用-本次抵扣
|
|
|
availableMoney = MathUtil.sub(availableMoney, balancePayFee).doubleValue();
|
|
|
- payOrderMapper.updateMoneyByUserId(userMoney, availableMoney, order.getUserId());
|
|
|
- log.info("【订单支付,余额抵扣】>>>>>>>>>>>更新用户余额(update[user])userId:" + order.getUserId() + ",orderId:" + orderId);
|
|
|
- //保存余额到余额收支记录
|
|
|
- BalanceRecordPo balanceRecord = new BalanceRecordPo();
|
|
|
- balanceRecord.setUserId(order.getUserId());
|
|
|
- balanceRecord.setType(2);
|
|
|
- balanceRecord.setBalanceType(1);
|
|
|
- balanceRecord.setAddDate(new Date());
|
|
|
- balanceRecord.setAmount(balancePayFee);
|
|
|
- balanceRecord.setOrderId(orderId);
|
|
|
- balanceRecord.setRemark("订单支付,余额抵扣");
|
|
|
- balanceRecord.setDelFlag(0);
|
|
|
- // 保存 余额收支记录
|
|
|
- baseMapper.insertBalanceRecord(balanceRecord);
|
|
|
- log.info("【订单支付,余额抵扣】>>>>>>>>>>>>>>>>>>>>>>>>>>新增用户余额收支记录(insert[cm_user_balance_record])orderId:" + orderId);
|
|
|
+ //区分扣多少线上扣多少线下,优先线上余额
|
|
|
+ Double onlineMoney = baseMapper.getonlineMoney(order.getUserId());
|
|
|
+ //线上余额>本次抵扣,全抵线上
|
|
|
+ if (onlineMoney > balancePayFee) {
|
|
|
+ onlineMoney = MathUtil.sub(onlineMoney, balancePayFee).doubleValue();
|
|
|
+ payOrderMapper.updateOnlineMoneyByUserId(onlineMoney, availableMoney, order.getUserId());
|
|
|
+ log.info("【订单支付,余额抵扣】>>>>>>>>>>>更新用户余额(update[user])userId:" + order.getUserId() + ",orderId:" + orderId);
|
|
|
+ //保存余额到余额收支记录
|
|
|
+ BalanceRecordPo balanceRecord = new BalanceRecordPo();
|
|
|
+ balanceRecord.setUserId(order.getUserId());
|
|
|
+ balanceRecord.setType(2);
|
|
|
+ balanceRecord.setBalanceType(10);
|
|
|
+ balanceRecord.setAddDate(new Date());
|
|
|
+ balanceRecord.setAmount(balancePayFee);
|
|
|
+ balanceRecord.setOrderId(orderId);
|
|
|
+ balanceRecord.setRemark("订单支付,余额抵扣");
|
|
|
+ balanceRecord.setDelFlag(0);
|
|
|
+ // 保存 余额收支记录
|
|
|
+ baseMapper.insertBalanceRecord(balanceRecord);
|
|
|
+ log.info("【订单支付,余额抵扣】>>>>>>>>>>>>>>>>>>>>>>>>>>新增用户余额收支记录(insert[cm_user_balance_record])orderId:" + orderId);
|
|
|
+ } else {//线上不够,线上全抵,剩余线下
|
|
|
+ //线下=原线下-(本次抵扣-线上)
|
|
|
+ userMoney = MathUtil.sub(userMoney, MathUtil.sub(balancePayFee, onlineMoney)).doubleValue();
|
|
|
+ //更新线上/线下余额 线上置为0,全部抵扣
|
|
|
+ payOrderMapper.updateMoneyByUserId(userMoney, availableMoney, 0d, order.getUserId());
|
|
|
+ log.info("【订单支付,余额抵扣】>>>>>>>>>>>更新用户余额(update[user])userId:" + order.getUserId() + ",orderId:" + orderId);
|
|
|
+ if (onlineMoney > 0) {
|
|
|
+ // 线上>0有抵扣的情况下保存线上余额到余额收支记录
|
|
|
+ BalanceRecordPo balanceRecord = new BalanceRecordPo();
|
|
|
+ balanceRecord.setUserId(order.getUserId());
|
|
|
+ balanceRecord.setType(2);
|
|
|
+ balanceRecord.setBalanceType(10);
|
|
|
+ balanceRecord.setAddDate(new Date());
|
|
|
+ balanceRecord.setAmount(onlineMoney);
|
|
|
+ balanceRecord.setOrderId(orderId);
|
|
|
+ balanceRecord.setRemark("订单支付,余额抵扣");
|
|
|
+ balanceRecord.setDelFlag(0);
|
|
|
+ baseMapper.insertBalanceRecord(balanceRecord);
|
|
|
+ log.info("【订单支付,线上/线下余额抵扣】>>>>>>>>>>>>>>>>>>>>>>>>>>新增用户余额收支记录(insert[cm_user_balance_record])orderId:" + orderId);
|
|
|
+ }
|
|
|
+ if (userMoney > 0) {
|
|
|
+ // 保存线下余额到余额收支记录
|
|
|
+ BalanceRecordPo balanceRecord1 = new BalanceRecordPo();
|
|
|
+ balanceRecord1.setUserId(order.getUserId());
|
|
|
+ balanceRecord1.setType(2);
|
|
|
+ balanceRecord1.setBalanceType(1);
|
|
|
+ balanceRecord1.setAddDate(new Date());
|
|
|
+ balanceRecord1.setAmount(userMoney);
|
|
|
+ balanceRecord1.setOrderId(orderId);
|
|
|
+ balanceRecord1.setRemark("订单支付,余额抵扣");
|
|
|
+ balanceRecord1.setDelFlag(0);
|
|
|
+ // 保存 余额收支记录
|
|
|
+ baseMapper.insertBalanceRecord(balanceRecord1);
|
|
|
+ }
|
|
|
+ log.info("【订单支付,线上/线下余额抵扣】>>>>>>>>>>>>>>>>>>>>>>>>>>新增用户余额收支记录(insert[cm_user_balance_record])orderId:" + orderId);
|
|
|
+ }
|
|
|
}
|
|
|
Map<String, Object> map = new HashMap<>(2);
|
|
|
map.put("order", order);
|
|
@@ -249,6 +299,8 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
|
}
|
|
|
order.setReceiptAmount(receiptAmount.get());
|
|
|
}
|
|
|
+ // 总成本
|
|
|
+ AtomicDouble totalCostPrice = new AtomicDouble(0d);
|
|
|
// 商品数据
|
|
|
List<OrderProductVo> orderProductList = orderCommonMapper.getOrderProductByOrderId(orderId);
|
|
|
//过滤运费商品
|
|
@@ -257,27 +309,61 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
|
orderProductList.forEach(orderProduct -> {
|
|
|
// 商品含税未知 or 订单选择开企业发票,商品不含税不能开票
|
|
|
boolean productTaxFlag = (null == orderProduct.getIncludedTax()) || (null == orderProduct.getInvoiceType()) || (Integer.valueOf(2).equals(orderProduct.getIncludedTax()))
|
|
|
- || (Integer.valueOf(2).equals(order.getInvoiceFlag()) && (Integer.valueOf(0).equals(orderProduct.getIncludedTax()) && Integer.valueOf(3).equals(orderProduct.getInvoiceType())));
|
|
|
+ || (Integer.valueOf(2).equals(order.getInvoiceFlag()) && (Integer.valueOf(0).equals(orderProduct.getIncludedTax()) && Integer.valueOf(3).equals(orderProduct.getInvoiceType())));
|
|
|
if (productTaxFlag) {
|
|
|
order.setInvoiceStatus(true);
|
|
|
}
|
|
|
+ //当应付金额小于订单总成本时,不能走线上支付,总成本=商品成本 + 供应商运费 + 供应商税费
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+ List<ShopOrderVo> shopOrderList = orderCommonMapper.getShopOrderListByOrderId(order.getOrderId());
|
|
|
+ for (ShopOrderVo shopOrder : shopOrderList) {
|
|
|
+ // 付供应商运费
|
|
|
+ Double shopPostFee = shopOrder.getShopPostFee();
|
|
|
+ costPrice = MathUtil.add(costPrice, shopPostFee).doubleValue();
|
|
|
+ }
|
|
|
+ totalCostPrice.set(MathUtil.add(costPrice, totalCostPrice.get()).doubleValue());
|
|
|
});
|
|
|
+
|
|
|
// 返回数据
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
map.put("userName", userName);
|
|
|
map.put("order", order);
|
|
|
map.put("discernReceipt", discernReceiptList);
|
|
|
map.put("orderProductList", orderProductList);
|
|
|
-
|
|
|
+ //能否线上判断付供应商是否大于订单金额
|
|
|
+// orderCommonService.getDiscernReceiptAndSetOrder(order);
|
|
|
+// boolean payButton = order.isPayButton();
|
|
|
+ // 总成本>应付 不能线上
|
|
|
+ //todo 判断线上/线下余额
|
|
|
+ Double userMoney = orderCommonMapper.findUserMoney(orderId);
|
|
|
+ Double onlineMoney = orderCommonMapper.findOnlineMoney(orderId);
|
|
|
+ userMoney = userMoney == null ? 0 : userMoney;
|
|
|
+ onlineMoney = onlineMoney == null ? 0 : onlineMoney;
|
|
|
+ if (MathUtil.compare(totalCostPrice, order.getPayableAmount()) > 0 || order.getPayableAmount() <= 0.01) {
|
|
|
+ map.put("onlinePay", 2);
|
|
|
+ } else if (userMoney > 0 && onlineMoney > 0 && !"31".equals(order.getStatus())) {
|
|
|
+ //当线上余额和线下余额两者都抵扣了但只抵扣了部分订单金额,订单只能走线下支付,点击提交订单,跳转到线下支付页面
|
|
|
+ map.put("onlinePay", 2);
|
|
|
+ } else {
|
|
|
+ map.put("onlinePay", 1);
|
|
|
+ }
|
|
|
return ResponseJson.success(map);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
- * 生成网银支付链接
|
|
|
+ * 生成网银支付链接
|
|
|
+ *
|
|
|
* @param payLinkDto {
|
|
|
* orderId 订单ID
|
|
|
* vipRecordId 会员购买记录Id
|
|
|
- * }
|
|
|
+ * }
|
|
|
*/
|
|
|
@Override
|
|
|
public ResponseJson<String> getPayLink(PayLinkDto payLinkDto) {
|
|
@@ -403,7 +489,17 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
|
code = 5;
|
|
|
}
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
- String time = dateFormat.format(orderPayLink.getEffectiveTime());
|
|
|
+ //原24小时有效期,增加2天到72小时
|
|
|
+ String time = "";
|
|
|
+ Date effectiveTime = orderPayLink.getEffectiveTime();
|
|
|
+ Calendar ca = Calendar.getInstance();
|
|
|
+ ca.setTime(effectiveTime);
|
|
|
+ ca.add(Calendar.DAY_OF_MONTH, 2);
|
|
|
+ if (null != orderPayLink.getOrderId()) {
|
|
|
+ time = dateFormat.format(ca.getTime());
|
|
|
+ } else {
|
|
|
+ time = dateFormat.format(orderPayLink.getEffectiveTime());
|
|
|
+ }
|
|
|
Map<String, Object> map = new HashMap<>(5);
|
|
|
map.put("type", type);
|
|
|
map.put("orderPayLink", orderPayLink);
|
|
@@ -453,7 +549,7 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
|
Map<String, Object> map = weChatService.getInfoMapByWeb(payParam.getCode(), "crm");
|
|
|
openId = (String) map.get(WeChatService.Keys.OPEN_ID);
|
|
|
} catch (Exception e) {
|
|
|
- log.error("try-catch:",e);
|
|
|
+ log.error("try-catch:", e);
|
|
|
}
|
|
|
if (StringUtils.isEmpty(openId)) {
|
|
|
return ResponseJson.error("微信公众号获取openId失败!", null);
|
|
@@ -696,7 +792,7 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
|
log.info("【支付异步回调】>>>>>>>>>>>>>>订单(部分支付),修改订单状态:" + order.getStatus() + ",orderId:" + orderId);
|
|
|
}
|
|
|
// 更新付款次数
|
|
|
- Integer paySuccessCounter = (null == order.getPaySuccessCounter()) ? 1 : order.getPaySuccessCounter() +1;
|
|
|
+ Integer paySuccessCounter = (null == order.getPaySuccessCounter()) ? 1 : order.getPaySuccessCounter() + 1;
|
|
|
order.setPaySuccessCounter(paySuccessCounter);
|
|
|
order.setUpdateDate(curDateStr);
|
|
|
// 更新订单支付状态
|
|
@@ -758,22 +854,25 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
|
}
|
|
|
}
|
|
|
if (rechargeFlag > 0) {
|
|
|
- // 账户余额
|
|
|
- double oldUserMoney = baseMapper.getUserMoney(order.getUserId());
|
|
|
+ // 线上账户余额
|
|
|
+ double oldUserMoney = baseMapper.getonlineMoney(order.getUserId());
|
|
|
+ // 充值算线下余额
|
|
|
double userMoney = MathUtil.add(oldUserMoney, amount).doubleValue();
|
|
|
// 可用余额
|
|
|
Double oldAvailableMoney = baseMapper.getAbleUserMoney(order.getUserId());
|
|
|
+ // 可用余额=之前的可用+充值
|
|
|
double availableMoney = MathUtil.add(oldAvailableMoney, amount).doubleValue();
|
|
|
- payOrderMapper.updateMoneyByUserId(userMoney, availableMoney, order.getUserId());
|
|
|
+ //充值线上余额
|
|
|
+ payOrderMapper.updateOnlineMoneyByUserId(userMoney, availableMoney, order.getUserId());
|
|
|
log.info("【支付异步回调】>>>>>>>>>>>更新用户余额(update[user])userId:" + order.getUserId() + ",orderId:" + orderId);
|
|
|
//保存余额到余额收支记录
|
|
|
BalanceRecordPo balanceRecord = new BalanceRecordPo();
|
|
|
balanceRecord.setUserId(order.getUserId());
|
|
|
balanceRecord.setType(1);
|
|
|
if (rechargeFlag == 1) {
|
|
|
- balanceRecord.setBalanceType(6);
|
|
|
+ balanceRecord.setBalanceType(16);
|
|
|
} else {
|
|
|
- balanceRecord.setBalanceType(7);
|
|
|
+ balanceRecord.setBalanceType(17);
|
|
|
}
|
|
|
balanceRecord.setAddDate(new Date());
|
|
|
balanceRecord.setAmount(amount);
|
|
@@ -828,7 +927,7 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
|
}
|
|
|
// 超级会员用户标识
|
|
|
Integer svipUserId = baseMapper.getSvipUserIdByUserId(order.getUserId());
|
|
|
- if (null != svipUserId && svipUserId.equals(order.getUserId())){
|
|
|
+ if (null != svipUserId && svipUserId.equals(order.getUserId())) {
|
|
|
// 超级会员用户采美豆翻倍
|
|
|
num = num * 2;
|
|
|
}
|
|
@@ -842,7 +941,7 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
|
}
|
|
|
}
|
|
|
baseMapper.updateUserBeans(beansHistory.getUserId(), userBeans);
|
|
|
- log.info("【支付异步回调】>>>>>更新用户采美豆(update[user(userBeans:"+ userBeans +")]),userId:" + beansHistory.getUserId());
|
|
|
+ log.info("【支付异步回调】>>>>>更新用户采美豆(update[user(userBeans:" + userBeans + ")]),userId:" + beansHistory.getUserId());
|
|
|
}
|
|
|
// 已支付短信推送(取消推送)
|
|
|
/*boolean smsPushFlag = !orderRequestNo.contains("BETA") && !orderRequestNo.contains("DEV");
|
|
@@ -913,7 +1012,7 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
|
/**
|
|
|
* 延时分账
|
|
|
*
|
|
|
- * @param callUrl 回调地址
|
|
|
+ * @param callUrl 回调地址
|
|
|
*/
|
|
|
@Override
|
|
|
public void delayedSplitting(String callUrl) {
|
|
@@ -925,10 +1024,18 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
|
String currentTime = format.format(calendar.getTime());
|
|
|
// 查询未分账已支付收款
|
|
|
List<OrderReceiptRelationPo> orderRelations = payOrderMapper.getUndividedPaidReceipt(currentTime);
|
|
|
- if (orderRelations != null && orderRelations.size() > 0) {
|
|
|
+ // 上面过滤了余额抵扣, 把线上余额抵扣单补充到list里面,线上余额抵扣的金额视为正常收款金额进行分账
|
|
|
+ List<OrderReceiptRelationPo> onlineRelations = payOrderMapper.getOnlineBalance(currentTime);
|
|
|
+ if (null != onlineRelations && orderRelations.size() > 0) {
|
|
|
+ // 过滤不足分账金额的单
|
|
|
+ onlineRelations.removeIf(o -> o.getAssociateAmount() < 0.01);
|
|
|
+ // 把线上余额抵扣订单加入分账
|
|
|
+ orderRelations.addAll(onlineRelations);
|
|
|
+ }
|
|
|
+ if (null != orderRelations && orderRelations.size() > 0) {
|
|
|
for (OrderReceiptRelationPo orderRelation : orderRelations) {
|
|
|
log.info("【延时分账】>>>>>>>>>>订单id:" + orderRelation.getOrderId() + ",进入延时分账");
|
|
|
- // 订单信息
|
|
|
+ // 收款对应的订单信息
|
|
|
OrderVo order = orderCommonMapper.getOrderByOrderId(orderRelation.getOrderId());
|
|
|
PayParamBo payParam = new PayParamBo();
|
|
|
payParam.setPayAmount(MathUtil.mul(orderRelation.getAssociateAmount(), 100).intValue());
|
|
@@ -944,7 +1051,7 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
|
double shopTotalAmount = 0.00;
|
|
|
String subUserNo = "";
|
|
|
for (SplitAccountPo account : splitBillDetail) {
|
|
|
- if (null!= account.getType() && 4 == account.getType() && shopOrder.getShopId().equals(account.getShopId())) {
|
|
|
+ if (null != account.getType() && 4 == account.getType() && shopOrder.getShopId().equals(account.getShopId())) {
|
|
|
shopTotalAmount = MathUtil.add(shopTotalAmount, account.getSplitAccount()).doubleValue();
|
|
|
subUserNo = account.getSubUserNo();
|
|
|
}
|
|
@@ -952,9 +1059,11 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
|
addMaps(maps, shopTotalAmount, subUserNo);
|
|
|
}
|
|
|
//公账-专票总金额,私账-无票总金额,公账-普票总金额
|
|
|
+ //佣金进网络
|
|
|
double totalAmount1 = 0.00;
|
|
|
double totalAmount2 = 0.00;
|
|
|
double totalAmount3 = 0.00;
|
|
|
+ double totalAmount4 = 0.00;
|
|
|
for (SplitAccountPo account : splitBillDetail) {
|
|
|
if (1 == account.getType()) {
|
|
|
totalAmount1 = MathUtil.add(totalAmount1, account.getSplitAccount()).doubleValue();
|
|
@@ -962,11 +1071,14 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
|
totalAmount2 = MathUtil.add(totalAmount2, account.getSplitAccount()).doubleValue();
|
|
|
} else if (3 == account.getType()) {
|
|
|
totalAmount3 = MathUtil.add(totalAmount3, account.getSplitAccount()).doubleValue();
|
|
|
+ } else if (5 == account.getType()) {
|
|
|
+ totalAmount4 = MathUtil.add(totalAmount4, account.getSplitAccount()).doubleValue();
|
|
|
}
|
|
|
}
|
|
|
addMaps(maps, totalAmount1, PayUtil.publicAccountNo);
|
|
|
addMaps(maps, totalAmount2, PayUtil.privateAccountNo);
|
|
|
addMaps(maps, totalAmount3, PayUtil.commonInvoiceNo);
|
|
|
+ addMaps(maps, totalAmount4, PayUtil.brokerage);
|
|
|
String parameters = JSON.toJSONString(maps);
|
|
|
log.info("【延时分账】>>>>>>>>>>分账参数: " + parameters);
|
|
|
|
|
@@ -1025,6 +1137,7 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * todo 佣金要改进入采美网络
|
|
|
* 分账详情
|
|
|
*/
|
|
|
private List<SplitAccountPo> setSplitAccountDetail(OrderVo order, PayParamBo payParam) {
|
|
@@ -1047,6 +1160,7 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
|
splitAmount = MathUtil.sub(splitAmount, procedureFee).doubleValue();
|
|
|
// 商品数据
|
|
|
List<OrderProductVo> orderProductList = orderCommonMapper.getOrderProductByOrderId(order.getOrderId());
|
|
|
+ orderProductList.removeIf(o -> 998 == o.getShopId() && orderCommonMapper.finduserBean(o.getOrderId()) > 0);
|
|
|
for (OrderProductVo orderProduct : orderProductList) {
|
|
|
double costPrice = MathUtil.mul(orderProduct.getCostPrice(), orderProduct.getNum()).doubleValue();
|
|
|
// 不含税能开发票
|
|
@@ -1059,16 +1173,19 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
|
Double paidAmount = payOrderMapper.getOrderProductPaidAmount(orderProduct.getOrderProductId());
|
|
|
if (paidAmount != null && MathUtil.compare(paidAmount, 0) > 0) {
|
|
|
costPrice = MathUtil.sub(costPrice, paidAmount).doubleValue();
|
|
|
+ splitAmount = MathUtil.sub(splitAmount, costPrice).doubleValue();
|
|
|
}
|
|
|
if (paidAmount == null || MathUtil.compare(paidAmount, costPrice) < 0) {
|
|
|
// 待分账金额>=本次待分账金额
|
|
|
- if (MathUtil.compare(splitAmount, costPrice) > -1) {
|
|
|
+ if (MathUtil.compare(splitAmount, costPrice) > 0) {
|
|
|
splitAmount = MathUtil.sub(splitAmount, costPrice).doubleValue();
|
|
|
} else {
|
|
|
costPrice = splitAmount;
|
|
|
splitAmount = 0.00;
|
|
|
}
|
|
|
- String commercialCode = payOrderMapper.getShopCommercialCode(orderProduct.getShopId());
|
|
|
+ }
|
|
|
+ String commercialCode = payOrderMapper.getShopCommercialCode(orderProduct.getShopId());
|
|
|
+ if (costPrice > 0) {
|
|
|
SplitAccountPo splitAccount = new SplitAccountPo();
|
|
|
splitAccount.setOrderId(order.getOrderId());
|
|
|
splitAccount.setOrderProductId(orderProduct.getOrderProductId());
|
|
@@ -1080,24 +1197,32 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
|
splitAccount.setType(4);
|
|
|
splitAccount.setSubUserNo(commercialCode);
|
|
|
} else {
|
|
|
- if (1 == orderProduct.getInvoiceType()) {
|
|
|
- // 开增值税发票,则分账到公账-专票
|
|
|
- splitAccount.setType(1);
|
|
|
- splitAccount.setSubUserNo(PayUtil.publicAccountNo);
|
|
|
- } else if (2 == orderProduct.getInvoiceType()) {
|
|
|
- // 开普通发票,则分账到公账-普票
|
|
|
- splitAccount.setType(3);
|
|
|
- splitAccount.setSubUserNo(PayUtil.commonInvoiceNo);
|
|
|
+ //含税或者不含税看票
|
|
|
+ if (0 == orderProduct.getIncludedTax() || 1 == orderProduct.getIncludedTax()) {
|
|
|
+ if (1 == orderProduct.getInvoiceType()) {
|
|
|
+ // 开增值税发票,则分账到公账-专票
|
|
|
+ splitAccount.setType(1);
|
|
|
+ splitAccount.setSubUserNo(PayUtil.publicAccountNo);
|
|
|
+ } else if (2 == orderProduct.getInvoiceType()) {
|
|
|
+ // 开普通发票,则分账到公账-普票
|
|
|
+ splitAccount.setType(3);
|
|
|
+ splitAccount.setSubUserNo(PayUtil.commonInvoiceNo);
|
|
|
+ } else {
|
|
|
+ // 不能开票,则分账到私账-无票
|
|
|
+ splitAccount.setType(2);
|
|
|
+ splitAccount.setSubUserNo(PayUtil.privateAccountNo);
|
|
|
+ }
|
|
|
} else {
|
|
|
- // 不能开票,则分账到私账-无票
|
|
|
+ //未知或者其他直接私账
|
|
|
splitAccount.setType(2);
|
|
|
splitAccount.setSubUserNo(PayUtil.privateAccountNo);
|
|
|
}
|
|
|
}
|
|
|
+ log.info("成本分账参数------------->" + splitAccount);
|
|
|
list.add(splitAccount);
|
|
|
- if (MathUtil.compare(splitAmount, 0) == 0) {
|
|
|
- break;
|
|
|
- }
|
|
|
+ }
|
|
|
+ if (MathUtil.compare(splitAmount, 0) == 0) {
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
// 付供应商运费,是以供应商为单位的
|
|
@@ -1141,8 +1266,10 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
|
splitAccount.setOrderId(order.getOrderId());
|
|
|
splitAccount.setSplitAccount(splitAmount);
|
|
|
splitAccount.setProductType(3);
|
|
|
- splitAccount.setType(1);
|
|
|
+ splitAccount.setType(5);
|
|
|
+ //todo 暂时切信息
|
|
|
splitAccount.setSubUserNo(PayUtil.publicAccountNo);
|
|
|
+ log.info("佣金分账参数------------->" + splitAccount);
|
|
|
list.add(splitAccount);
|
|
|
}
|
|
|
return list;
|
|
@@ -1221,6 +1348,7 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
|
// 保存 付供应商记录
|
|
|
PayShopRecordPo shopRecord = new PayShopRecordPo();
|
|
|
shopRecord.setShopId(shopId);
|
|
|
+ shopRecord.setPayShopId(payShop.getId());
|
|
|
shopRecord.setShopOrderId(shopOrderId);
|
|
|
shopRecord.setShopOrderNo(shopOrderNo);
|
|
|
shopRecord.setPayAmount(splitAmount);
|
|
@@ -1254,6 +1382,47 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
|
return "SUCCESS";
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public ResponseJson<JSONObject> bankCode() {
|
|
|
+ List<BankCodeVo> banks = payOrderMapper.findBankCode();
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("list", banks);
|
|
|
+ return ResponseJson.success("获取成功", jsonObject);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void couponCheck() {
|
|
|
+ log.info("------------查询是否有优惠券商品下单------------------------>");
|
|
|
+ List<CouponCheckVo> checks = payOrderMapper.findCouponOrder();
|
|
|
+ log.info("单号列表------------------------>" + checks);
|
|
|
+ if (null != checks && checks.size() > 0) {
|
|
|
+ checks.forEach(checkVo -> {
|
|
|
+ for (int i = 0; i < checkVo.getNum(); i++) {
|
|
|
+ insertCoupon(checkVo);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ log.info("---------------优惠券商品兑换结束--------------------------->");
|
|
|
+ }
|
|
|
+
|
|
|
+ private void insertCoupon(CouponCheckVo check) {
|
|
|
+ Integer couponId = 7174 == check.getProductId() ? 44 : 49;
|
|
|
+ CouponRecordPo couponRecordPo = new CouponRecordPo();
|
|
|
+ couponRecordPo.setOrderId(check.getOrderId());
|
|
|
+ couponRecordPo.setUserId(check.getUserId());
|
|
|
+ couponRecordPo.setCouponId(couponId);
|
|
|
+ //保存已兑换orderid
|
|
|
+ orderClubMapper.insertCouponRecord(couponRecordPo);
|
|
|
+ CouponClubPo couponClubPo = new CouponClubPo();
|
|
|
+ couponClubPo.setSource(5);
|
|
|
+ couponClubPo.setUserId(check.getUserId());
|
|
|
+ couponClubPo.setCouponId(couponId);
|
|
|
+ couponClubPo.setStatus("1");
|
|
|
+ couponClubPo.setDelFlag("0");
|
|
|
+ couponClubPo.setCreateDate(new Date());
|
|
|
+ orderClubMapper.insertCouponClub(couponClubPo);
|
|
|
+ log.info("兑换优惠券订单-------------------->" + couponRecordPo);
|
|
|
+ }
|
|
|
// /**
|
|
|
// * 手动临时分账异步通知回调
|
|
|
// *
|