Authored by LUOXC

refactor

@@ -15,6 +15,7 @@ import com.yohobuy.ufo.model.order.req.ManualDealRequest; @@ -15,6 +15,7 @@ import com.yohobuy.ufo.model.order.req.ManualDealRequest;
15 import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO; 15 import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO;
16 import com.yohoufo.common.alarm.CommonAlarmEventPublisher; 16 import com.yohoufo.common.alarm.CommonAlarmEventPublisher;
17 import com.yohoufo.common.caller.UfoServiceCaller; 17 import com.yohoufo.common.caller.UfoServiceCaller;
  18 +import com.yohoufo.common.utils.DateUtil;
18 import com.yohoufo.common.utils.TimeUtils; 19 import com.yohoufo.common.utils.TimeUtils;
19 import com.yohoufo.dal.order.*; 20 import com.yohoufo.dal.order.*;
20 import com.yohoufo.dal.order.model.*; 21 import com.yohoufo.dal.order.model.*;
@@ -36,11 +37,9 @@ import com.yohoufo.order.service.BuyerOrderPaymentService; @@ -36,11 +37,9 @@ import com.yohoufo.order.service.BuyerOrderPaymentService;
36 import com.yohoufo.order.service.IPaymentService; 37 import com.yohoufo.order.service.IPaymentService;
37 import com.yohoufo.order.service.MerchantOrderPaymentService; 38 import com.yohoufo.order.service.MerchantOrderPaymentService;
38 import com.yohoufo.order.service.SellerOrderPaymentService; 39 import com.yohoufo.order.service.SellerOrderPaymentService;
39 -import com.yohoufo.order.service.handler.BuyerCancelCompensateComputeHandler;  
40 import com.yohoufo.order.service.handler.BuyerOrderPayDiffTimeHandler; 40 import com.yohoufo.order.service.handler.BuyerOrderPayDiffTimeHandler;
41 import com.yohoufo.order.service.pay.AbstractPayService; 41 import com.yohoufo.order.service.pay.AbstractPayService;
42 import com.yohoufo.order.service.pay.alipay.AlipayOuyinService; 42 import com.yohoufo.order.service.pay.alipay.AlipayOuyinService;
43 -import com.yohoufo.order.service.pay.alipay.AlipayServiceAbstract;  
44 import com.yohoufo.order.service.pay.wallet.WalletPayService; 43 import com.yohoufo.order.service.pay.wallet.WalletPayService;
45 import com.yohoufo.order.service.pay.weixin.WeixinMiniappPayService; 44 import com.yohoufo.order.service.pay.weixin.WeixinMiniappPayService;
46 import com.yohoufo.order.service.pay.weixin.WeixinPayUFORealAppService; 45 import com.yohoufo.order.service.pay.weixin.WeixinPayUFORealAppService;
@@ -65,6 +64,7 @@ import java.util.Objects; @@ -65,6 +64,7 @@ import java.util.Objects;
65 import java.util.function.BiFunction; 64 import java.util.function.BiFunction;
66 65
67 import static com.yohoufo.order.common.TransferCase.EARNEST_MONEY_TO_BUYER; 66 import static com.yohoufo.order.common.TransferCase.EARNEST_MONEY_TO_BUYER;
  67 +import static com.yohoufo.order.utils.ServiceExceptions.throwServiceExceptionIf;
68 68
69 @Service 69 @Service
70 public class PaymentServiceImpl implements IPaymentService { 70 public class PaymentServiceImpl implements IPaymentService {
@@ -385,13 +385,9 @@ public class PaymentServiceImpl implements IPaymentService { @@ -385,13 +385,9 @@ public class PaymentServiceImpl implements IPaymentService {
385 385
386 logger.info("transferSuccess 旧流水更新成功,准备加新流水 tradeBillsId={}, tradeBillsId={}, orderCode={}", tradeBillsId, tradeBillsId, orderCode); 386 logger.info("transferSuccess 旧流水更新成功,准备加新流水 tradeBillsId={}, tradeBillsId={}, orderCode={}", tradeBillsId, tradeBillsId, orderCode);
387 // 加新流水 387 // 加新流水
388 - tradeBills.setDealRelateId(tradeBills.getId());  
389 - tradeBills.setId(null);  
390 - tradeBills.setTradeStatus(100);  
391 - tradeBills.setCreateTime(now);  
392 - addTradeBills(tradeBills);  
393 -  
394 - logger.info("transferSuccess 加新流水成功,准备修改转账状态 tradeBillsId={}, tradeBillsId={}, orderCode={}", tradeBillsId, tradeBillsId, orderCode); 388 + addSuccessTradeBills(tradeBills);
  389 +
  390 + logger.info("transferSuccess 加新流水成功,准备修改转账状态 tradeBillsId={}, tradeBillsId={}, orderCode={}", tradeBillsId, tradeBillsId, orderCode);
395 OrdersPayTransfer newTransfer = new OrdersPayTransfer(); 391 OrdersPayTransfer newTransfer = new OrdersPayTransfer();
396 newTransfer.setId(transfer.getId()); 392 newTransfer.setId(transfer.getId());
397 newTransfer.setStatus(1); 393 newTransfer.setStatus(1);
@@ -981,78 +977,73 @@ public class PaymentServiceImpl implements IPaymentService { @@ -981,78 +977,73 @@ public class PaymentServiceImpl implements IPaymentService {
981 public void manualDeal(ManualDealRequest req) { 977 public void manualDeal(ManualDealRequest req) {
982 logger.info("manualDeal人工打款开始参数req={}", req); 978 logger.info("manualDeal人工打款开始参数req={}", req);
983 Integer tradeBillsId = req.getTradeBillsId(); 979 Integer tradeBillsId = req.getTradeBillsId();
984 - if (tradeBillsId == null || tradeBillsId < 1) {  
985 - throw new ServiceException(400, "manualDeal:流水Id不合法");  
986 - }  
987 - if (req.getOperateUid() == null || req.getOperateUid() < 1) {  
988 - throw new ServiceException(400, "manualDeal:客服uid不合法");  
989 - }  
990 - if (StringUtils.isBlank(req.getOperateUname())) {  
991 - throw new ServiceException(400, "manualDeal:客服名称不合法");  
992 - }  
993 - TradeBills tradeBills = tradeBillsMapper.selectByPrimaryKey(tradeBillsId);  
994 - if (tradeBills == null) {  
995 - throw new ServiceException(400, "manualDeal:流水不存在");  
996 - }  
997 - if (tradeBills.getTradeStatus() == 100) {  
998 - throw new ServiceException(400, "manualDeal:该流水不是失败的");  
999 - }  
1000 - if (tradeBills.getIncomeOutcome()==null || tradeBills.getIncomeOutcome()!=1) {  
1001 - throw new ServiceException(400, "manualDeal:该流水不是退款类型");  
1002 - }  
1003 - // 查询处理过的  
1004 - if (tradeBillsMapper.selectByDealRelateId(tradeBillsId) != null) {  
1005 - throw new ServiceException(400, "manualDeal:该流水已经处理过");  
1006 - }  
1007 - long orderCode = tradeBills.getOrderCode();  
1008 - String logTag = "manualDeal orderCode is " + orderCode + "tradeBillId is " + tradeBillsId;  
1009 - AuthorizeResultRespVO account = getAlipayAccount(tradeBills.getUid());  
1010 - if (account == null ||  
1011 - (StringUtils.isBlank(account.getAlipayAccount()) && StringUtils.isBlank(account.getAlipayId()))) {  
1012 - logger.warn("manualDealErr uid {} 没有获取到有效的支付宝账号", tradeBills.getUid());  
1013 - throw new ServiceException(400, "uid[" + tradeBills.getUid() + "]没有获取到有效的支付宝账号");  
1014 - }  
1015 - String alipayAccount = null;  
1016 - if(StringUtils.isNotBlank(account.getAlipayId())) {  
1017 - logger.info("manualDeal uid {} 支付宝账号uid有值优先使用{}", tradeBills.getUid(), account.getAlipayId());  
1018 - alipayAccount = account.getAlipayId();  
1019 - } else if(StringUtils.isNotBlank(account.getAlipayAccount())) {  
1020 - logger.info("manualDeal uid {} 支付宝账号uid无值使用账号{}", tradeBills.getUid(), account.getAlipayAccount());  
1021 - alipayAccount = account.getAlipayAccount();  
1022 - } 980 + throwServiceExceptionIf(tradeBillsId == null || tradeBillsId < 1, 400, "流水Id不合法");
  981 + throwServiceExceptionIf(req.getOperateUid() == null || req.getOperateUid() < 1, 400, "客服uid不合法");
  982 + throwServiceExceptionIf(StringUtils.isBlank(req.getOperateUname()), 400, "客服名称不合法");
  983 + TradeBills tradeBills = tradeBillsMapper.selectByPrimaryKey(tradeBillsId);
  984 + throwServiceExceptionIf(tradeBills == null, 400, "流水不存在");
  985 + throwServiceExceptionIf(tradeBills.getTradeStatus() == 100, 400, "该流水不是失败的");
  986 + throwServiceExceptionIf(tradeBills.getIncomeOutcome() == null || tradeBills.getIncomeOutcome() != 1, 400, "该流水不是退款类型");
  987 + // 是否处理过的
  988 + throwServiceExceptionIf(Objects.nonNull(tradeBillsMapper.selectByDealRelateId(tradeBillsId)), 400, "该流水已经处理过");
1023 989
1024 990
1025 - BigDecimal amount = null; 991 + String logTag = String.format("manual deal orderCode is %s tradeBillId is %s uid is %s",tradeBills.getOrderCode(),tradeBillsId,tradeBills.getUid());
  992 + BigDecimal amount;
1026 try { 993 try {
1027 amount = new BigDecimal(req.getAmount()).setScale(2, BigDecimal.ROUND_HALF_DOWN); 994 amount = new BigDecimal(req.getAmount()).setScale(2, BigDecimal.ROUND_HALF_DOWN);
1028 } catch (Exception e) { 995 } catch (Exception e) {
1029 - throw new ServiceException(400, "manualDeal:金额不合法"); 996 + throw new ServiceException(400, "转账金额不合法");
1030 } 997 }
1031 if (amount.compareTo(new BigDecimal("0.1")) < 0) { 998 if (amount.compareTo(new BigDecimal("0.1")) < 0) {
1032 - throw new ServiceException(400, "manualDeal:金额小于0.1"); 999 + throw new ServiceException(400, "转账金额小于0.1");
1033 } 1000 }
1034 if (tradeBills.getAmount().compareTo(amount) != 0) { 1001 if (tradeBills.getAmount().compareTo(amount) != 0) {
1035 - throw new ServiceException(400, "manualDeal:金额有误"); 1002 + throw new ServiceException(400, "转账金额有误");
1036 } 1003 }
1037 1004
1038 - int now = (int) (System.currentTimeMillis() / 1000);  
1039 - // 预标记成功  
1040 - TradeBills preSuccess = new TradeBills();  
1041 - preSuccess.setId(tradeBills.getId());  
1042 - preSuccess.setDealTime(now);  
1043 - preSuccess.setDealStatus(1);  
1044 - preSuccess.setDealUid(req.getOperateUid());  
1045 - preSuccess.setDealUserName(req.getOperateUname());  
1046 -  
1047 tradeBills.setDealUid(req.getOperateUid()); 1005 tradeBills.setDealUid(req.getOperateUid());
1048 tradeBills.setDealUserName(req.getOperateUname()); 1006 tradeBills.setDealUserName(req.getOperateUname());
1049 1007
1050 - if (tradeBillsMapper.updateSelectiveByPrimaryKey(preSuccess) == 0) {  
1051 - throw new ServiceException(400, "manualDeal:流水已经处理过id=" + tradeBills.getId()); 1008 + TradeBills lockKey = new TradeBills();
  1009 + lockKey.setId(tradeBills.getId());
  1010 + lockKey.setDealTime((int) (System.currentTimeMillis() / 1000));
  1011 + lockKey.setDealStatus(1);
  1012 + lockKey.setDealUid(req.getOperateUid());
  1013 + lockKey.setDealUserName(req.getOperateUname());
  1014 + if (!tryLock(logTag, lockKey)) {
  1015 + throw new ServiceException(400, "流水已经处理过id=" + tradeBills.getId());
1052 } 1016 }
1053 -  
1054 - boolean isMerchantExit = false;  
1055 - // 是否为退出入驻订单 1017 +
  1018 + // 退货款或普通用户退保证金
  1019 + if (isRefundGoodsMoneyTradeBills(tradeBills) || isRefundEarnestMoneyTradeBills(tradeBills)) {
  1020 + refund(logTag, tradeBills, amount, lockKey);
  1021 + }
  1022 + // 转账
  1023 + else {
  1024 + transfer(logTag, tradeBills, amount, lockKey);
  1025 + }
  1026 + }
  1027 +
  1028 + // '1:买家uid; 2:卖家uid','1:保证金;2:货款;3:补偿款', '1:用户收入; 2:用户支出'
  1029 + private boolean isRefundGoodsMoneyTradeBills(TradeBills tradeBills) {
  1030 + return tradeBills.getUserType() == 1
  1031 + && tradeBills.getTradeType() == 2
  1032 + && tradeBills.getIncomeOutcome() == 1;
  1033 + }
  1034 +
  1035 + // '1:买家uid; 2:卖家uid','1:保证金;2:货款;3:补偿款', '1:用户收入; 2:用户支出'
  1036 + private boolean isRefundEarnestMoneyTradeBills(TradeBills tradeBills) {
  1037 + long orderCode = tradeBills.getOrderCode();
  1038 + return tradeBills.getUserType() == 2
  1039 + && tradeBills.getTradeType() == 1
  1040 + && tradeBills.getIncomeOutcome() == 1
  1041 + && !isMerchantExit(orderCode);
  1042 + }
  1043 +
  1044 + private boolean isMerchantExit(long orderCode) {
  1045 + boolean isMerchantExit = false;
  1046 + // 是否为退出入驻订单
1056 CodeMeta codeMeta = orderCodeGenerator.expId(orderCode); 1047 CodeMeta codeMeta = orderCodeGenerator.expId(orderCode);
1057 if(codeMeta.getType() == OrderCodeType.SELLER_RECHARGE_EARNEST_TYPE.getType()) { 1048 if(codeMeta.getType() == OrderCodeType.SELLER_RECHARGE_EARNEST_TYPE.getType()) {
1058 EntrySellerRechargeOrder order = entrySellerRechargeOrderMapper.selectByOrderCode(orderCode); 1049 EntrySellerRechargeOrder order = entrySellerRechargeOrderMapper.selectByOrderCode(orderCode);
@@ -1060,82 +1051,110 @@ public class PaymentServiceImpl implements IPaymentService { @@ -1060,82 +1051,110 @@ public class PaymentServiceImpl implements IPaymentService {
1060 if (order.getStatus() == 0) { 1051 if (order.getStatus() == 0) {
1061 isMerchantExit = true; 1052 isMerchantExit = true;
1062 } else { 1053 } else {
1063 - throw new ServiceException(400, "manualDeal:退款已成功,id=" + tradeBills.getId()); 1054 + throw new ServiceException(400, "退款已成功");
1064 } 1055 }
1065 } else { 1056 } else {
1066 - throw new ServiceException(400, "manualDeal:商家退出入驻订单异常,id=" + tradeBills.getId()); 1057 + throw new ServiceException(400, "商家退出入驻订单异常");
1067 } 1058 }
1068 } 1059 }
1069 -  
1070 - // '1:买家uid; 2:卖家uid','1:保证金;2:货款;3:补偿款', '1:用户收入; 2:用户支出' 1060 + return isMerchantExit;
  1061 + }
  1062 +
  1063 + private void refund(String logTag, TradeBills tradeBills, BigDecimal amount, TradeBills lockKey) {
  1064 + long orderCode = tradeBills.getOrderCode();
1071 PayRefundBo refundBo = null; 1065 PayRefundBo refundBo = null;
1072 - try {  
1073 - if (/* 退货款 */((tradeBills.getUserType() == 1 && tradeBills.getTradeType() == 2 && tradeBills.getIncomeOutcome() == 1)  
1074 - /* 退保证金(普通用户) */  
1075 - || (tradeBills.getUserType() == 2 && tradeBills.getTradeType() == 1 && tradeBills.getIncomeOutcome() == 1 && !isMerchantExit))) {  
1076 - logger.warn("manualDeal人工退款 , tradeBills is {}", tradeBills);  
1077 - refundBo = manualRefund(orderCode, amount);  
1078 - if (refundBo.getRefundStatus() == RefundContant.PAYMENT_REFUND_RESULTCODE_SUCCESS) {  
1079 - // 加新流水  
1080 - tradeBills.setDealRelateId(tradeBills.getId());  
1081 - tradeBills.setId(null);  
1082 - tradeBills.setTradeStatus(100);  
1083 - tradeBills.setCreateTime(now);  
1084 - addTradeBills(tradeBills);  
1085 - return;  
1086 - } else {  
1087 - throw new ServiceException(500, "退款失败:" + refundBo.getRefundMsg());  
1088 - }  
1089 - }  
1090 - } catch (Exception e) {  
1091 - logger.warn("manualDealErr 退款失败 , tradeBillsId is {}, msg is {}", tradeBillsId, e.getMessage());  
1092 - String alarmMsg = "订单号:" + orderCode + ",操作类型(退款),流水id=" + tradeBillsId + ",msg=" + e.getMessage();  
1093 - if (refundBo != null) {  
1094 - alarmMsg += ",DETAIL=" + JSON.toJSONString(refundBo);  
1095 - }  
1096 - logger.info("manualDealErr 退款失败 , alarmMsg is {}", alarmMsg);  
1097 - alarm("人工处理退款失败", "ufo.order.manualDeal", alarmMsg );  
1098 - preSuccess.setDealStatus(0);  
1099 - tradeBillsMapper.updateToFailByPrimaryKey(preSuccess);  
1100 - if (e instanceof ServiceException) {  
1101 - throw new ServiceException(((ServiceException) e).getCode(), "退款失败id=" + tradeBillsId + "," + e.getMessage());  
1102 - } else {  
1103 - throw new ServiceException(500, "退款失败id=" + tradeBillsId);  
1104 - }  
1105 - }  
1106 try { 1066 try {
  1067 +
  1068 + logger.warn("{}, refund money is {}", logTag, tradeBills);
  1069 + refundBo = manualRefund(orderCode, amount);
  1070 + if (refundBo.getRefundStatus() == RefundContant.PAYMENT_REFUND_RESULTCODE_SUCCESS) {
  1071 + // 加新流水
  1072 + addSuccessTradeBills(tradeBills);
  1073 + } else {
  1074 + throw new ServiceException(500, "退款失败:" + refundBo.getRefundMsg());
  1075 + }
  1076 + return;
  1077 + } catch (Exception e) {
  1078 + logger.warn("{}, refund fail.", logTag, e);
  1079 + String alarmMsg = "订单号:" + orderCode + ",操作类型(退款),流水id=" + tradeBills.getId() + ",msg=" + e.getMessage();
  1080 + if (refundBo != null) {
  1081 + alarmMsg += ",DETAIL=" + JSON.toJSONString(refundBo);
  1082 + }
  1083 + alarm("人工处理退款失败", "ufo.order.manualDeal", alarmMsg);
  1084 + releaseLock(logTag, lockKey);
  1085 + if (e instanceof ServiceException) {
  1086 + throw e;
  1087 + } else {
  1088 + throw new ServiceException(500, "退款失败[" + tradeBills.getId() + "]");
  1089 + }
  1090 + }
  1091 + }
  1092 +
  1093 + private void transfer(String logTag, TradeBills tradeBills, BigDecimal amount, TradeBills lockKey) {
  1094 + long orderCode = tradeBills.getOrderCode();
  1095 + try {
  1096 + AuthorizeResultRespVO account = getAlipayAccount(tradeBills.getUid());
  1097 + if (account == null ||
  1098 + (StringUtils.isBlank(account.getAlipayAccount()) && StringUtils.isBlank(account.getAlipayId()))) {
  1099 + logger.warn("{}, can not find a alipay account", logTag);
  1100 + throw new ServiceException(400, "uid[" + tradeBills.getUid() + "]没有获取到有效的支付宝账号");
  1101 + }
1107 OrdersPayTransfer transfer = ordersPayTransferMapper.selectByBuyerOrderCode(orderCode); 1102 OrdersPayTransfer transfer = ordersPayTransferMapper.selectByBuyerOrderCode(orderCode);
1108 - ServiceExceptions.throwServiceExceptionIf(() -> Objects.isNull(transfer),  
1109 - 400, "转账记录不存在[" + tradeBillsId + "]");  
1110 - ServiceExceptions.throwServiceExceptionIf(() -> transfer.getStatus() == 1, 1103 + throwServiceExceptionIf(() -> Objects.isNull(transfer),
  1104 + 400, "转账记录不存在[" + tradeBills.getId() + "]");
  1105 + throwServiceExceptionIf(() -> transfer.getStatus() == 1,
1111 400, "转账记录已成功转账,请不要重复操作。"); 1106 400, "转账记录已成功转账,请不要重复操作。");
1112 Integer interfaceType = transfer.getInterfaceType(); 1107 Integer interfaceType = transfer.getInterfaceType();
1113 logger.info("{}, transfer channel router {}", logTag, interfaceType); 1108 logger.info("{}, transfer channel router {}", logTag, interfaceType);
1114 if (OrdersPayTransfer.INTERFACE_TYPE_TRANSFER_WHEN_EXCEED_MILLION.equals(interfaceType)) { 1109 if (OrdersPayTransfer.INTERFACE_TYPE_TRANSFER_WHEN_EXCEED_MILLION.equals(interfaceType)) {
1115 transferWithAlipayExceedMillionTransfer(tradeBills, orderCode, logTag, account, amount, transfer); 1110 transferWithAlipayExceedMillionTransfer(tradeBills, orderCode, logTag, account, amount, transfer);
1116 } else { 1111 } else {
1117 - transferWithAlipayTransfer(logTag, tradeBills, orderCode, account, amount, now, transfer); 1112 + transferWithAlipayTransfer(logTag, tradeBills, orderCode, account, amount, transfer);
1118 } 1113 }
1119 } catch (Exception e) { 1114 } catch (Exception e) {
1120 logger.warn("{}, transfer fail", logTag, e); 1115 logger.warn("{}, transfer fail", logTag, e);
1121 alarm("人工处理转账失败", 1116 alarm("人工处理转账失败",
1122 "ufo.order.manualDeal", 1117 "ufo.order.manualDeal",
1123 - "订单号:" + orderCode + ",操作类型(转账),流水id=" + tradeBillsId + ",msg=" + e.getMessage());  
1124 - logger.info("{}, rollback lock", logTag);  
1125 - preSuccess.setDealStatus(0);  
1126 - tradeBillsMapper.updateToFailByPrimaryKey(preSuccess);  
1127 - logger.info("{}, rollback lock success", logTag); 1118 + "订单号:" + orderCode + ",操作类型(转账),流水id=" + tradeBills.getId() + ",msg=" + e.getMessage());
  1119 +
  1120 + releaseLock(logTag, lockKey);
  1121 +
1128 if (e instanceof ServiceException) { 1122 if (e instanceof ServiceException) {
1129 throw e; 1123 throw e;
1130 } else { 1124 } else {
1131 - ServiceExceptions.throwServiceException(500, "转账失败id=" + tradeBillsId); 1125 + ServiceExceptions.throwServiceException(500, "转账失败[" + tradeBills.getId() + "]");
1132 } 1126 }
1133 - } finally {  
1134 - logger.info("{}, complete", logTag);  
1135 } 1127 }
1136 - } 1128 + }
  1129 +
  1130 + private boolean tryLock(String logTag, TradeBills key) {
  1131 + logger.info("{}, try lock", logTag);
  1132 + int row = tradeBillsMapper.updateSelectiveByPrimaryKey(key);
  1133 + if (row == 0) {
  1134 + logger.info("{}, i not got the lock", logTag);
  1135 + return false;
  1136 + } else {
  1137 + logger.info("{}, i got the lock", logTag);
  1138 + return true;
  1139 + }
  1140 + }
  1141 +
  1142 + private void releaseLock(String logTag, TradeBills key) {
  1143 + logger.info("{}, release lock", logTag);
  1144 + key.setDealStatus(0);
  1145 + tradeBillsMapper.updateToFailByPrimaryKey(key);
  1146 + logger.info("{}, release lock success", logTag);
  1147 + }
  1148 +
  1149 + private void addSuccessTradeBills(TradeBills tradeBills) {
  1150 + tradeBills.setDealRelateId(tradeBills.getId());
  1151 + tradeBills.setId(null);
  1152 + tradeBills.setTradeStatus(100);
  1153 + tradeBills.setCreateTime(DateUtil.getCurrentTimeSecond());
  1154 + addTradeBills(tradeBills);
  1155 + }
1137 1156
1138 - private void transferWithAlipayTransfer(String logTag, TradeBills tradeBills, long orderCode, AuthorizeResultRespVO account, BigDecimal amount, int now, OrdersPayTransfer transfer) { 1157 + private void transferWithAlipayTransfer(String logTag, TradeBills tradeBills, long orderCode, AuthorizeResultRespVO account, BigDecimal amount, OrdersPayTransfer transfer) {
1139 TransferResult transferResult = alipayService.newAlipayTransfer() 1158 TransferResult transferResult = alipayService.newAlipayTransfer()
1140 .transferOrderCode(Long.toString(orderCode)) 1159 .transferOrderCode(Long.toString(orderCode))
1141 .alipayUid(account.getAlipayId()) 1160 .alipayUid(account.getAlipayId())
@@ -1145,17 +1164,13 @@ public class PaymentServiceImpl implements IPaymentService { @@ -1145,17 +1164,13 @@ public class PaymentServiceImpl implements IPaymentService {
1145 if (transferResult.getCode() == 200) { 1164 if (transferResult.getCode() == 200) {
1146 logger.info("{}, transfer success and out trade no is {}", logTag, orderCode); 1165 logger.info("{}, transfer success and out trade no is {}", logTag, orderCode);
1147 // 加新流水 1166 // 加新流水
1148 - tradeBills.setDealRelateId(tradeBills.getId());  
1149 - tradeBills.setId(null);  
1150 - tradeBills.setTradeStatus(100);  
1151 - tradeBills.setCreateTime(now);  
1152 - addTradeBills(tradeBills); 1167 + addSuccessTradeBills(tradeBills);
1153 // ? 1168 // ?
1154 OrdersPayTransfer transferSuccess = new OrdersPayTransfer(); 1169 OrdersPayTransfer transferSuccess = new OrdersPayTransfer();
1155 transferSuccess.setId(transfer.getId()); 1170 transferSuccess.setId(transfer.getId());
1156 transferSuccess.setAlipayTradeId(transferResult.getTradeNo()); 1171 transferSuccess.setAlipayTradeId(transferResult.getTradeNo());
1157 transferSuccess.setStatus(1); 1172 transferSuccess.setStatus(1);
1158 - transferSuccess.setUpdateTime(now); 1173 + transferSuccess.setUpdateTime(DateUtil.getCurrentTimeSecond());
1159 ordersPayTransferMapper.updateByPrimaryKeySelective(transferSuccess); 1174 ordersPayTransferMapper.updateByPrimaryKeySelective(transferSuccess);
1160 }else { 1175 }else {
1161 logger.warn("{}, transfer fail {}", logTag,transferResult); 1176 logger.warn("{}, transfer fail {}", logTag,transferResult);
@@ -29,6 +29,12 @@ public class ServiceExceptions { @@ -29,6 +29,12 @@ public class ServiceExceptions {
29 } 29 }
30 } 30 }
31 31
  32 + public static void throwServiceExceptionIf(boolean condition, int code, String message) {
  33 + if (condition) {
  34 + throw new ServiceException(code, message);
  35 + }
  36 + }
  37 +
32 public static void throwServiceException(int code, String message) { 38 public static void throwServiceException(int code, String message) {
33 throw new ServiceException(code, message); 39 throw new ServiceException(code, message);
34 } 40 }