Răsfoiți Sursa

支付调试

igl 2 luni în urmă
părinte
comite
621b1cae1f

+ 9 - 3
vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/controller/AssetController.java

@@ -3,6 +3,8 @@ package com.chelvc.cloud.vehicle.server.controller;
 import com.chelvc.cloud.vehicle.client.dto.MerchantAssetDTO;
 import com.chelvc.cloud.vehicle.client.param.*;
 import com.chelvc.cloud.vehicle.server.service.AssetService;
+import com.chelvc.framework.common.function.Executor;
+import com.chelvc.framework.database.context.DatabaseContextHolder;
 import lombok.RequiredArgsConstructor;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
@@ -35,7 +37,9 @@ public class AssetController {
      */
     @PostMapping("/asset/withdraw/notify")
     public void withdrawNotify(@RequestBody SxyNotifyParam param) {
-        this.assetService.withdrawNotify(param);
+        DatabaseContextHolder.transactional((Executor) () -> {
+            this.assetService.withdrawNotify(param);
+        });
     }
 
     /**
@@ -44,7 +48,9 @@ public class AssetController {
      */
     @PostMapping("/asset/transfer/notify")
     public void transferNotify(@RequestBody SxyNotifyParam param) {
-        this.assetService.transferNotify(param);
+        DatabaseContextHolder.transactional((Executor) () -> {
+            this.assetService.transferNotify(param);
+        });
     }
 
     /**
@@ -52,6 +58,6 @@ public class AssetController {
      */
     @PostMapping("/asset/transfer")
     public void transfer(@RequestBody TransferParam param){
-        this.assetService.transfer(0L, param.getTargetUserId(), param.getType(), param.getAmount());
+        this.assetService.transfer(0L, param.getTargetUserId(), param.getType(), param.getAmount(), "");
     }
 }

+ 8 - 2
vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/controller/OmsOrderController.java

@@ -10,7 +10,9 @@ import com.chelvc.cloud.vehicle.client.param.OrderPagingParam;
 import com.chelvc.cloud.vehicle.client.param.OrderRefundParam;
 import com.chelvc.cloud.vehicle.client.param.SxyNotifyParam;
 import com.chelvc.cloud.vehicle.server.service.OmsOrderService;
+import com.chelvc.framework.common.function.Executor;
 import com.chelvc.framework.common.model.Pagination;
+import com.chelvc.framework.database.context.DatabaseContextHolder;
 import com.chelvc.framework.wechat.WechatUnifiedOrder;
 import lombok.RequiredArgsConstructor;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -171,7 +173,9 @@ public class OmsOrderController {
      */
     @PostMapping("/order/notify")
     public void orderNotify(@RequestBody SxyNotifyParam param){
-        omsOrderService.orderNotify(param);
+        DatabaseContextHolder.transactional((Executor) () -> {
+            omsOrderService.orderNotify(param);
+        });
     }
 
     /**
@@ -189,6 +193,8 @@ public class OmsOrderController {
      */
     @PostMapping("/order/refund/notify")
     public void orderRefundNotify(@RequestBody SxyNotifyParam param){
-        omsOrderService.orderRefundNotify(param);
+        DatabaseContextHolder.transactional((Executor) () -> {
+            omsOrderService.orderRefundNotify(param);
+        });
     }
 }

+ 1 - 0
vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/handle/CustomConfig.java

@@ -23,6 +23,7 @@ public class CustomConfig {
         map.put("onlinepay.order.url", "https://apis.5upay.com/onlinePay/order");
         map.put("onlinepay.refund.url", "https://apis.5upay.com/onlinePay/refund");
         map.put("transferAccount.order.url", "https://apis.5upay.com/transferAccount/order");
+        map.put("wallet.withdraw.url", "https://apis.5upay.com/wallet/withdraw");
         map.put("onlinepay.query.url", "https://apis.5upay.com/onlinePay/query");
         map.put("ehking.sdk.net.client.defaultConnectTimeout", "30000");
         map.put("ehking.sdk.net.client.defaultReadTimeout", "30000");

+ 1 - 1
vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/service/AssetService.java

@@ -39,7 +39,7 @@ public interface AssetService {
     void transferNotify(SxyNotifyParam param);
     void withdraw(Long userId, Integer type, BigDecimal amount);
 
-    void transfer(Long sourceUserId, Long targetUserId, Integer type, BigDecimal amount);
+    void transfer(Long sourceUserId, Long targetUserId, Integer type, BigDecimal amount, String remark);
 
     /**
      *

+ 1 - 1
vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/service/MerchantApplyRecordService.java

@@ -8,5 +8,5 @@ public interface MerchantApplyRecordService {
 
     int insert(MerchantApplyRecord record);
 
-    void updateByNotify(SxyNotifyParam param);
+    void updateSxyMerchantIdByNotify(SxyNotifyParam param);
 }

+ 0 - 4
vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/service/impl/AssessServiceImpl.java

@@ -60,12 +60,8 @@ import java.util.stream.Collectors;
 @Service
 @RequiredArgsConstructor(onConstructor = @__(@Autowired))
 public class AssessServiceImpl extends ServiceImpl<GoodsAssessMapper, GoodsAssess> implements AssessService {
-
     private final UserClient userService;
-    private final EmployeeClient employeeClient;
-
     private static final SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd");
-
     private final AssessRecoverMapper assessRecoverMapper;
     private final AssessScoreMapper assessScoreMapper;
     private final OmsOrderItemService omsOrderItemService;

+ 18 - 22
vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/service/impl/AssetServiceImpl.java

@@ -168,13 +168,7 @@ public class AssetServiceImpl extends ServiceImpl<AssetMapper, Asset> implements
         Long finalUserId = userId;
         DatabaseContextHolder.transactional((Executor) () -> {
             //生成提现订单
-            if(type == 2){
-                //商户直接提现
-                withdraw(finalUserId, type, amount);
-            } else {
-                //用户先转账后提现
-                transfer(0L, finalUserId, type, amount);
-            }
+            withdraw(finalUserId, type, amount);
         });
     }
 
@@ -218,17 +212,19 @@ public class AssetServiceImpl extends ServiceImpl<AssetMapper, Asset> implements
             return;
         } catch (ResponseException e) {
             JSONObject responseData = e.getResponseData();
-            cause = responseData.getString("cause");
+            cause = responseData.getString("error");
             log.error("transfer order error:", e);
         } catch (HmacVerifyException e) {
             cause = "签名验证异常";
             log.error("transfer order error:", e);
         } catch (RequestException e) {
             JSONObject responseData = e.getResponseData();
-            cause = responseData.getString("cause");
+            cause = responseData.getString("error");
             log.error("transfer order error:", e);
         } catch (UnknownException e) {
-            cause = "未知异常";
+            String message = e.getMessage();
+            JSONObject jsonObject = JSONObject.parseObject(message);
+            cause = jsonObject.getString("error");
             log.error("transfer order error:", e);
         }
         transferWithdrawService.updateStatusById(withdrawId, 2, cause);
@@ -254,7 +250,7 @@ public class AssetServiceImpl extends ServiceImpl<AssetMapper, Asset> implements
      * @param amount
      */
     @Override
-    public void transfer(Long sourceUserId, Long targetUserId, Integer type, BigDecimal amount){
+    public void transfer(Long sourceUserId, Long targetUserId, Integer type, BigDecimal amount, String remark){
         Long transferId = transferWithdrawService.createTransferWithdraw(targetUserId, type, amount, 1, 1);
         //查询首信易商户号
         MerchantRelation relation = merchantRelationService.queryByUserIdAndType(targetUserId, type);
@@ -268,6 +264,7 @@ public class AssetServiceImpl extends ServiceImpl<AssetMapper, Asset> implements
                 .setNotifyUrl(TradeConstant.TRANSFER_NOTIFY_URL)
                 .setCurrency("CNY")
                 .setReceiverId(relation.getSxyMerchantId())
+                .setRemark(remark)
                 .setReceiverType("MERCHANT_ACC")
                 .setDeputeMark("NOT_DO_DEPUTE");
         TransferAccountOrderExecuter executer = new TransferAccountOrderExecuter();
@@ -423,18 +420,17 @@ public class AssetServiceImpl extends ServiceImpl<AssetMapper, Asset> implements
                 //记录平台转账余额明细
                 balanceDetailService.recordFlow(id, 0, 0L, amount, BigDecimal.ZERO,
                         amount, platformTotal, 1, 7, transfer.getUserId());
-                if(type == 2){
-                    //商户转账-更新余额
-                    baseMapper.addAmount(transfer.getUserId(), transfer.getType(), amount, LocalDateTime.now());
-                    BigDecimal merchantTotal = queryTotal(transfer.getUserId(), transfer.getType());
-                    //记录平台转账余额明细
-                    balanceDetailService.recordFlow(id, 0, 0L, amount, BigDecimal.ZERO,
-                            amount, merchantTotal, 0, 7, 0L);
-                } else {
-                    //用户不需要添加金额
-                    //用户转账-继续提现操作
-                    withdraw(transfer.getUserId(), transfer.getType(), amount);
+                String remark = responseData.getString("remark");
+                if(type == 1 && "0".equals(remark)){
+                    //用户第一次转账
+                    return;
                 }
+                //转账-更新余额
+                baseMapper.addAmount(transfer.getUserId(), type, amount, LocalDateTime.now());
+                BigDecimal merchantTotal = queryTotal(transfer.getUserId(), transfer.getType());
+                //记录余额明细
+                balanceDetailService.recordFlow(id, type, transfer.getUserId(), amount, BigDecimal.ZERO,
+                        amount, merchantTotal, 0, 7, 0L);
             }
         }
     }

+ 20 - 10
vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/service/impl/MerchantApplyRecordServiceImpl.java

@@ -9,15 +9,13 @@ import com.chelvc.cloud.vehicle.client.param.SxyNotifyParam;
 import com.chelvc.cloud.vehicle.server.dao.MerchantApplyRecordMapper;
 import com.chelvc.cloud.vehicle.server.entity.MerchantApplyRecord;
 import com.chelvc.cloud.vehicle.server.handle.TradeHandle;
-import com.chelvc.cloud.vehicle.server.service.MerchantApplyRecordService;
-import com.chelvc.cloud.vehicle.server.service.MerchantAuthService;
-import com.chelvc.cloud.vehicle.server.service.MerchantRelationService;
-import com.chelvc.cloud.vehicle.server.service.UserAuthService;
+import com.chelvc.cloud.vehicle.server.service.*;
 import com.upay.sdk.Constants;
 import lombok.RequiredArgsConstructor;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.math.BigDecimal;
 import java.util.Date;
 
 @Service
@@ -28,6 +26,7 @@ public class MerchantApplyRecordServiceImpl extends
     private final MerchantRelationService merchantRelationService;
     private final UserAuthService userAuthService;
     private final MerchantAuthService merchantAuthService;
+    private final AssetService assetService;
 
     @Override
     public int insert(MerchantApplyRecord record) {
@@ -35,7 +34,7 @@ public class MerchantApplyRecordServiceImpl extends
     }
 
     @Override
-    public void updateByNotify(SxyNotifyParam param) {
+    public void updateSxyMerchantIdByNotify(SxyNotifyParam param) {
         JSONObject responseData = TradeHandle.decrypt(param);
         String status = responseData.getString("subMerchantReviewStatus");
         if (Constants.ERROR.equals(status)) {
@@ -46,27 +45,38 @@ public class MerchantApplyRecordServiceImpl extends
         LambdaQueryWrapper<MerchantApplyRecord> wrapper = Wrappers.lambdaQuery();
         wrapper.eq(MerchantApplyRecord::getRequestId, requestId);
         MerchantApplyRecord record = baseMapper.selectOne(wrapper);
+        Integer recordStatus = record.getStatus();
+        if(recordStatus == 2){
+            return;
+        }
+        String subMerchantId = responseData.getString("subMerchantId");
+        Integer type = record.getType();
+        Integer resultStatus = MerchantApplyStatus.getStatus(status);
+        record.setStatus(resultStatus);
         record.setExamineStatus(status);
         record.setCertificateSupplementUrl(responseData.getString("certificateSupplementUrl"));
         record.setElectronicContractingUrl(responseData.getString("electronicContractingUrl"));
         record.setMerchantReviewRemarks(responseData.getString("merchantReviewRemarks"));
         record.setPostReviewRemark(responseData.getString("postReviewRemark"));
         record.setPostReviewStatus(responseData.getString("postReviewStatus"));
-        String subMerchantId = responseData.getString("subMerchantId");
         record.setSubMerchantId(subMerchantId);
         record.setUpdateTime(new Date());
         baseMapper.updateById(record);
-        Integer type = record.getType();
         if(type == 1){
             //更改个人认证状态
-            userAuthService.updateStatus(record.getUserId(), MerchantApplyStatus.getStatus(status));
+            userAuthService.updateStatus(record.getUserId(), resultStatus);
         }
         if(type == 2){
             //更改个人认证状态
-            merchantAuthService.updateStatus(record.getUserId(), MerchantApplyStatus.getStatus(status));
+            merchantAuthService.updateStatus(record.getUserId(), resultStatus);
         }
         if("SUCCESS".equals(status)){
-            merchantRelationService.insert(record.getUserId(), record.getType(), subMerchantId);
+            int i = merchantRelationService.insert(record.getUserId(), record.getType(), subMerchantId);
+            if(i == 1 && record.getType() == 1){
+                //用户申请商户号成功,平台转账给用户
+                BigDecimal total = assetService.queryTotal(record.getUserId(), 1);
+                assetService.transfer(0L, record.getUserId(), 1, total, "0");
+            }
         }
     }
 }

+ 4 - 1
vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/service/impl/MerchantServiceImpl.java

@@ -21,6 +21,7 @@ import com.chelvc.cloud.vehicle.server.entity.Region;
 import com.chelvc.cloud.vehicle.server.service.*;
 import com.chelvc.cloud.vehicle.server.task.DateUtil;
 import com.chelvc.framework.base.context.SessionContextHolder;
+import com.chelvc.framework.common.function.Executor;
 import com.chelvc.framework.common.model.Pagination;
 import com.chelvc.framework.common.util.AssertUtils;
 import com.chelvc.framework.common.util.ObjectUtils;
@@ -557,7 +558,9 @@ public class MerchantServiceImpl extends ServiceImpl<MerchantMapper, Merchant> i
 
     @Override
     public void merchantApplyNotify(SxyNotifyParam param) {
-        merchantApplyRecordService.updateByNotify(param);
+        DatabaseContextHolder.transactional((Executor) () -> {
+            merchantApplyRecordService.updateSxyMerchantIdByNotify(param);
+        });
     }
 
     @Override

+ 24 - 16
vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/service/impl/OderHandleServiceImpl.java

@@ -4,10 +4,12 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.chelvc.cloud.vehicle.client.constant.PlatformConstant;
 import com.chelvc.cloud.vehicle.server.dao.OmsOrderMapper;
+import com.chelvc.cloud.vehicle.server.entity.MerchantRelation;
 import com.chelvc.cloud.vehicle.server.entity.OmsOrder;
 import com.chelvc.cloud.vehicle.server.service.*;
 import com.chelvc.framework.common.exception.ResourceUnavailableException;
 import lombok.RequiredArgsConstructor;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -36,6 +38,7 @@ public class OderHandleServiceImpl implements OrderHandleService {
     private final AssetService assetService;
     private final BalanceDetailService balanceDetailService;
     private final OmsOrderOperateHistoryService omsOrderOperateHistoryService;
+    private final MerchantRelationService merchantRelationService;
 
     @Override
     public void orderPay(Long orderId) {
@@ -126,23 +129,31 @@ public class OderHandleServiceImpl implements OrderHandleService {
         balanceDetailService.recordFlow(orderId, 2, merchantId, operateAmount, merchantDeduct,
                 merchantRealityAmount, surplusAmount, 0, 0, userId);
         //给商家转账
-        assetService.transfer(0L, merchantId, 2, merchantRealityAmount);
+        assetService.transfer(0L, merchantId, 2, merchantRealityAmount, "");
         //邀请用户---分得佣金
         if (userAmount.compareTo(BigDecimal.ZERO) > 0) {
             platformAmount = platformAmount.subtract(userAmount);
             BigDecimal deduct = BigDecimal.ZERO;  //扣税
             BigDecimal realityAmount = userAmount.subtract(deduct);
-            //更新用户资产
-            BigDecimal userTotal = assetService.updateAsset(0, realityAmount, inviteUserId, 1, 1);
-            //邀请用户余额明细
-            balanceDetailService.recordFlow(orderId, 1, inviteUserId, userAmount, deduct,
-                    realityAmount, userTotal, 0, 1, userId);
-            //currencyRecordService.recordFlow(inviteUserId, 1, 0, orderId, userId, 1, userAmount, deduct, realityAmount);
-            //用户资产记录到平台名下
-            BigDecimal platformTotal = assetService.updateAsset(0, realityAmount, 0L, 0, 1);
-            //用户佣金记录到平台余额名下
-            balanceDetailService.recordFlow(orderId, 0, 0L, userAmount, deduct,
-                    realityAmount, platformTotal, 0, 1, userId);
+            MerchantRelation relation = merchantRelationService.queryByUserIdAndType(inviteUserId, 1);
+            if(relation != null && StringUtils.isNotBlank(relation.getSxyMerchantId())){
+                //开通商户号,转账操作
+                assetService.transfer(0L, inviteUserId, 1, realityAmount, "");
+                //记录用户余额明细
+                balanceDetailService.recordFlow(orderId, 1, inviteUserId, userAmount, deduct,
+                        realityAmount, surplusAmount, 0, 1, userId);
+            } else {
+                //更新用户资产
+                BigDecimal userTotal = assetService.updateAsset(0, realityAmount, inviteUserId, 1, 1);
+                //邀请用户余额明细
+                balanceDetailService.recordFlow(orderId, 1, inviteUserId, userAmount, deduct,
+                        realityAmount, userTotal, 0, 1, userId);
+                //用户资产记录到平台名下
+                BigDecimal platformTotal = assetService.updateAsset(0, realityAmount, 0L, 0, 1);
+                //用户佣金记录到平台余额名下
+                balanceDetailService.recordFlow(orderId, 0, 0L, userAmount, deduct,
+                        realityAmount, platformTotal, 0, 1, userId);
+            }
         }
         //邀请商家---分得佣金
         if (merchantAmount.compareTo(BigDecimal.ZERO) > 0) {
@@ -154,10 +165,8 @@ public class OderHandleServiceImpl implements OrderHandleService {
             //记录商户分佣余额明细
             balanceDetailService.recordFlow(omsOrder.getId(), 2, inviteMerchantId, merchantAmount, deduct,
                     realityAmount, merchantTotal, 0, 2, userId);
-            //邀请商家流水
-            //currencyRecordService.recordFlow(inviteMerchantId, 1, 0, orderId, userId, 2, merchantAmount, deduct, realityAmount);
             //商家佣金转账
-            assetService.transfer(0L, inviteMerchantId, 2, realityAmount);
+            assetService.transfer(0L, inviteMerchantId, 2, realityAmount, "");
         }
         //平台流水
         BigDecimal deduct = BigDecimal.ZERO;  //扣税
@@ -167,7 +176,6 @@ public class OderHandleServiceImpl implements OrderHandleService {
         //记录平台抽成余额明细
         balanceDetailService.recordFlow(omsOrder.getId(), 0, 0L, platformAmount, deduct,
                 platformRealityAmount, platformTotal, 0, 2, userId);
-
         omsOrderOperateHistoryService.insertOmsOrderOperateHistory(omsOrder.getId(), userId, omsOrder.getStatus());
         //以下注释为以前逻辑,先不用管
         /*BigDecimal platformSurplusAmount = assetService.updateAsset(1, operateAmount, 0L, 0);