|
@@ -1,18 +1,19 @@
|
|
|
package com.chelvc.cloud.vehicle.server.service.impl;
|
|
|
|
|
|
+import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.chelvc.cloud.vehicle.client.constant.PlatformConstant;
|
|
|
-import com.chelvc.cloud.vehicle.client.dto.MerchantAssetDTO;
|
|
|
-import com.chelvc.cloud.vehicle.client.dto.MerchantTeamDTO;
|
|
|
-import com.chelvc.cloud.vehicle.client.dto.OrderDTO;
|
|
|
-import com.chelvc.cloud.vehicle.client.dto.WalletDTO;
|
|
|
+import com.chelvc.cloud.vehicle.client.constant.TradeConstant;
|
|
|
+import com.chelvc.cloud.vehicle.client.dto.*;
|
|
|
+import com.chelvc.cloud.vehicle.client.param.WithdrawParam;
|
|
|
import com.chelvc.cloud.vehicle.server.dao.AssetMapper;
|
|
|
import com.chelvc.cloud.vehicle.server.entity.Asset;
|
|
|
-import com.chelvc.cloud.vehicle.server.service.AssetService;
|
|
|
-import com.chelvc.cloud.vehicle.server.service.BalanceDetailService;
|
|
|
-import com.chelvc.cloud.vehicle.server.service.OmsOrderService;
|
|
|
+import com.chelvc.cloud.vehicle.server.entity.MerchantRelation;
|
|
|
+import com.chelvc.cloud.vehicle.server.handle.TradeHandle;
|
|
|
+import com.chelvc.cloud.vehicle.server.service.*;
|
|
|
+import com.chelvc.framework.base.context.SessionContextHolder;
|
|
|
import com.chelvc.framework.common.exception.ResourceUnavailableException;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -21,12 +22,16 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.util.HashMap;
|
|
|
|
|
|
@Service
|
|
|
@RequiredArgsConstructor(onConstructor = @__({@Autowired,@Lazy}))
|
|
|
public class AssetServiceImpl extends ServiceImpl<AssetMapper, Asset> implements AssetService {
|
|
|
private final BalanceDetailService balanceDetailService;
|
|
|
private final OmsOrderService orderService;
|
|
|
+ private final MerchantService merchantService;
|
|
|
+ private final MerchantRelationService merchantRelationService;
|
|
|
+ private final OmsWithdrawService withdrawService;
|
|
|
|
|
|
@Override
|
|
|
public Asset queryAsset(Long userId, Integer type) {
|
|
@@ -113,4 +118,46 @@ public class AssetServiceImpl extends ServiceImpl<AssetMapper, Asset> implements
|
|
|
dto.setMerchantTeamDTO(merchantTeamDTO);
|
|
|
return dto;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void withdraw(WithdrawParam param) {
|
|
|
+ Integer type = param.getType();
|
|
|
+ BigDecimal amount = param.getAmount();
|
|
|
+ Long userId = SessionContextHolder.getId();
|
|
|
+ if(type == null || (type != 1 && type != 2)){
|
|
|
+ throw new ResourceUnavailableException("提现类型错误");
|
|
|
+ }
|
|
|
+ if(type == 2){
|
|
|
+ //商家体现
|
|
|
+ Long merchantId = param.getMerchantId();
|
|
|
+ MerchantDTO merchantDTO = merchantService.queryCheck(merchantId, userId);
|
|
|
+ if(merchantDTO == null){
|
|
|
+ throw new ResourceUnavailableException("该账户下商家不存在");
|
|
|
+ }
|
|
|
+ userId = merchantId;
|
|
|
+ }
|
|
|
+ Asset asset = queryAsset(userId, type);
|
|
|
+ BigDecimal total = asset.getTotal();
|
|
|
+ if(amount.compareTo(total) > 0){
|
|
|
+ throw new ResourceUnavailableException("账户余额不足");
|
|
|
+ }
|
|
|
+ //查询首信易商户号
|
|
|
+ MerchantRelation merchantRelation = merchantRelationService.queryByUserIdAndType(userId, type);
|
|
|
+ if(merchantRelation == null){
|
|
|
+ throw new ResourceUnavailableException("请联系管理员开通商户号");
|
|
|
+ }
|
|
|
+ //生成提现订单
|
|
|
+ Long withdrawId = withdrawService.createWithdraw(userId, type, amount, 1);
|
|
|
+
|
|
|
+ String sxyMerchantId = merchantRelation.getSxyMerchantId();
|
|
|
+ //生成提现参数
|
|
|
+ HashMap<String, Object> map = new HashMap<>();
|
|
|
+ map.put("merchantId", sxyMerchantId);
|
|
|
+ map.put("requestId", withdrawId);
|
|
|
+ map.put("withdrawAmount", amount.multiply(new BigDecimal("100")));
|
|
|
+ map.put("notifyUrl", TradeConstant.WITHDRAW_NOTIFY_URL);
|
|
|
+ map.put("remark", "");
|
|
|
+ Gson gson = new Gson();
|
|
|
+ TradeHandle.handle(gson.toJson(map), TradeConstant.WITHDRAW_URL, sxyMerchantId, TradeConstant.PARTNER_ID);
|
|
|
+ }
|
|
|
}
|