|
@@ -32,6 +32,7 @@ import com.yc.ship.module.otc.api.store.dto.StoreInfoReqDTO;
|
|
|
import com.yc.ship.module.otc.api.store.dto.StoreReqDTO;
|
|
|
import com.yc.ship.module.otc.api.store.dto.StoreRespDTO;
|
|
|
import com.yc.ship.module.otc.enums.StoreBalanceTypeEnum;
|
|
|
+import com.yc.ship.module.otc.enums.StoreCreditTypeEnum;
|
|
|
import com.yc.ship.module.otc.enums.TradeModeEnum;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
@@ -423,23 +424,124 @@ public class DistributorRechargeServiceImpl implements DistributorRechargeServic
|
|
|
break;
|
|
|
case 5:
|
|
|
case 10:
|
|
|
- //预付款退款 定向库存退款
|
|
|
+ break;
|
|
|
+ case 20:
|
|
|
+ //预付款退款 定向库存退款 导游代退失败回退预存款
|
|
|
beforeBalance = distributor.getBalance();
|
|
|
//交易后金额
|
|
|
afterBalance = beforeBalance.add(money);
|
|
|
AtomicBoolean isShareBalance = new AtomicBoolean(false);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ AtomicReference<StoreRespDTO> storeRespDTO = new AtomicReference<>();
|
|
|
+// if (rechargeReqDTO.getStoreId() != null){
|
|
|
+// StoreReqDTO reqDTO = this.convertStorePlatBalance(rechargeReqDTO.getStoreId(), tradeMode, money, Long.parseLong(rechargeReqDTO.getOrderId()), tradeType, rechargeReqDTO.getRefundId());
|
|
|
+// TenantUtils.execute(distributor.getAccountTenantId(), () -> {
|
|
|
+// StoreInfoReqDTO storeData = storeApi.getStoreById(rechargeReqDTO.getStoreId()).getCheckedData();
|
|
|
+// if(ObjectUtil.equals(storeData.getBalanceType(), StoreBalanceTypeEnum.FIXED.getType())){
|
|
|
+// CommonResult<StoreRespDTO> storeResult = storeApi.storePlatTrade(reqDTO);
|
|
|
+// Asserts.isTrue(storeResult.isSuccess(), storeResult.getMsg());
|
|
|
+// storeRespDTO.set(storeResult.getCheckedData());
|
|
|
+// }else{
|
|
|
+// isShareBalance.set(true);
|
|
|
+// }
|
|
|
+// });
|
|
|
+// }else{
|
|
|
+// isShareBalance.set(true);
|
|
|
+// }
|
|
|
+
|
|
|
+ if(true){
|
|
|
+ tradeName =(tradeType==10?"定向库存":"")+"余额退款金额:" + money + "元,退款到账后剩余余额" + afterBalance + "元";
|
|
|
+ //操作账户资金
|
|
|
+ flag = distributorService.addBalance(distributor.getId(), money);
|
|
|
+ }else if(storeRespDTO.get()!=null){
|
|
|
+ StoreRespDTO storeRsp = storeRespDTO.get();
|
|
|
+ beforeBalance = storeRsp.getBeforeAmount();
|
|
|
+ afterBalance = storeRsp.getAfterAmount();
|
|
|
+ tradeName = (tradeType==10?"定向库存":"")+"余额退款金额:" + money + "元,退款到账后门店账户剩余余额" + storeRsp.getAfterAmount() + "元;";
|
|
|
+ flag = true;
|
|
|
+ }
|
|
|
break;
|
|
|
case 2:
|
|
|
- //授信账单还款充值
|
|
|
+ AtomicBoolean isShareCredit = new AtomicBoolean(false);
|
|
|
+ storeRespDTO = new AtomicReference<>();
|
|
|
+ if (rechargeReqDTO.getStoreId() != null){
|
|
|
+ //只充门店
|
|
|
+ StoreReqDTO reqDTO = this.convertStorePlatCredit(rechargeReqDTO.getStoreId(), tradeMode, money, Long.parseLong(rechargeReqDTO.getOrderId()), tradeType, rechargeReqDTO.getRefundId());
|
|
|
+ TenantUtils.execute(distributor.getAccountTenantId(), () -> {
|
|
|
+ StoreInfoReqDTO storeData = storeApi.getStoreById(rechargeReqDTO.getStoreId()).getCheckedData();
|
|
|
+ if(ObjectUtil.equals(storeData.getCreditType(), StoreCreditTypeEnum.FIXED.getType())) {
|
|
|
+ CommonResult<StoreRespDTO> storeResult = storeApi.storePlatTrade(reqDTO);
|
|
|
+ Asserts.isTrue(storeResult.isSuccess(), storeResult.getMsg());
|
|
|
+ storeRespDTO.set(storeResult.getCheckedData());
|
|
|
+ }else{
|
|
|
+ isShareCredit.set(true);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ isShareCredit.set(true);
|
|
|
+ }
|
|
|
+ if(isShareCredit.get()){
|
|
|
+ //充平台
|
|
|
+ beforeBalance = distributor.getSurplus();
|
|
|
+ //退款后已用额度 = 当前已用额度 - 退款金额
|
|
|
+ afterBalance = beforeBalance.subtract(money);
|
|
|
+ //分销商授信额度
|
|
|
+ BigDecimal payCredit = distributor.getPayCredit();
|
|
|
+ if (payCredit != null) {
|
|
|
+ BigDecimal creditRemained = payCredit.subtract(afterBalance);
|
|
|
+ tradeName = "授信账单还款充值金额:" + money + "元,授信总额度" + payCredit + "元,充值后剩余额度" + creditRemained + "元;已用额度" + afterBalance + "元";
|
|
|
+
|
|
|
+ } else {
|
|
|
+ tradeName = "授信账单还款充值金额:" + money + "元,授信总额度不限,充值后剩余额度不限;已用额度" + afterBalance + "元";
|
|
|
+ }
|
|
|
+ flag = distributorService.subSurplus(distributor.getId(), money);
|
|
|
+ }else if(storeRespDTO.get()!=null){
|
|
|
+ StoreRespDTO storeRsp = storeRespDTO.get();
|
|
|
+ beforeBalance = storeRsp.getBeforeAmount();
|
|
|
+ afterBalance = storeRsp.getAfterAmount();
|
|
|
+ tradeName = "授信账单还款金额:" + money + "元,退款到账后门店已使用授信从" + storeRsp.getBeforeAmount() + "元;变为"+ storeRsp.getAfterAmount();
|
|
|
+ flag = true;
|
|
|
+ }
|
|
|
break;
|
|
|
case 8:
|
|
|
//授信退款
|
|
|
beforeBalance = distributor.getSurplus();
|
|
|
//退款后已用额度 = 当前已用额度 - 退款金额
|
|
|
afterBalance = beforeBalance.subtract(money);
|
|
|
+ //分销商授信额度
|
|
|
+ BigDecimal payCredit = distributor.getPayCredit();
|
|
|
+ isShareCredit = new AtomicBoolean(false);
|
|
|
+ storeRespDTO = new AtomicReference<>();
|
|
|
+ if (rechargeReqDTO.getStoreId() != null){
|
|
|
+ StoreReqDTO reqDTO = this.convertStorePlatCredit(rechargeReqDTO.getStoreId(), tradeMode, money, Long.parseLong(rechargeReqDTO.getOrderId()), tradeType, rechargeReqDTO.getRefundId());
|
|
|
+ TenantUtils.execute(distributor.getAccountTenantId(), () -> {
|
|
|
+ StoreInfoReqDTO storeData = storeApi.getStoreById(rechargeReqDTO.getStoreId()).getCheckedData();
|
|
|
+ if(ObjectUtil.equals(storeData.getCreditType(), StoreCreditTypeEnum.FIXED.getType())){
|
|
|
+ CommonResult<StoreRespDTO> storeResult = storeApi.storePlatTrade(reqDTO);
|
|
|
+ Asserts.isTrue(storeResult.isSuccess(), storeResult.getMsg());
|
|
|
+ storeRespDTO.set(storeResult.getCheckedData());
|
|
|
+ }else{
|
|
|
+ isShareCredit.set(true);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ isShareCredit.set(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(isShareCredit.get()){
|
|
|
+ if (payCredit != null) {
|
|
|
+ BigDecimal creditRemained = payCredit.subtract(afterBalance);
|
|
|
+ tradeName = "授信退款金额:" + money + "元,授信总额度" + payCredit + "元,退款后剩余额度" + creditRemained + "元;已用额度" + afterBalance + "元";
|
|
|
+ } else {
|
|
|
+ tradeName = "授信退款金额:" + money + "元,授信总额度不限,退款后剩余额度不限;已用额度" + afterBalance + "元";
|
|
|
+ }
|
|
|
+ flag = distributorService.subSurplus(distributor.getId(), money);
|
|
|
+ }else if(storeRespDTO.get()!=null){
|
|
|
+ StoreRespDTO storeRsp = storeRespDTO.get();
|
|
|
+ beforeBalance = storeRsp.getBeforeAmount();
|
|
|
+ afterBalance = storeRsp.getAfterAmount();
|
|
|
+ tradeName = "授信退款金额:" + money + "元,退款到账后门店已使用授信从" + storeRsp.getBeforeAmount() + "元;变为"+ storeRsp.getAfterAmount();
|
|
|
+ flag = true;
|
|
|
+ }
|
|
|
|
|
|
break;
|
|
|
case 9:
|
|
@@ -572,6 +674,57 @@ public class DistributorRechargeServiceImpl implements DistributorRechargeServic
|
|
|
if (tradeType == DistributorTradeTypeEnum.CREDIT_TRANS.getType()) {
|
|
|
|
|
|
tradeMode = 2;
|
|
|
+ //门店平台授信
|
|
|
+ AtomicBoolean isShareCredit = new AtomicBoolean(false);
|
|
|
+ AtomicReference<StoreRespDTO> storeRespDTO = new AtomicReference<>();
|
|
|
+// if (rechargeReqDTO.getStoreId() != null){
|
|
|
+// StoreReqDTO reqDTO = this.convertStorePlatCredit(rechargeReqDTO.getStoreId(), tradeMode, money, Long.parseLong(rechargeReqDTO.getOrderId()), tradeType, null);
|
|
|
+// TenantUtils.execute(distributor.getAccountTenantId(), () -> {
|
|
|
+// StoreInfoReqDTO storeData = storeApi.getStoreById(rechargeReqDTO.getStoreId()).getCheckedData();
|
|
|
+// if(ObjectUtil.equals(storeData.getCreditType(), StoreCreditTypeEnum.FIXED.getType())){
|
|
|
+// CommonResult<StoreRespDTO> storeResult = storeApi.storePlatTrade(reqDTO);
|
|
|
+// Asserts.isTrue(storeResult.isSuccess(), storeResult.getMsg());
|
|
|
+// storeRespDTO.set(storeResult.getCheckedData());
|
|
|
+// }else if(ObjectUtil.equals(storeData.getCreditType(), StoreCreditTypeEnum.SHARE.getType())){
|
|
|
+// isShareCredit.set(true);
|
|
|
+// }else {
|
|
|
+// Asserts.isTrue(true,"该门店禁用授信支付方式");
|
|
|
+// }
|
|
|
+//
|
|
|
+// });
|
|
|
+// }else{
|
|
|
+// isShareCredit.set(true);
|
|
|
+// }
|
|
|
+ if(true){
|
|
|
+ Asserts.isTrue(isUseCredit, "分销商无授信交易权限!");
|
|
|
+ // 授信总额
|
|
|
+ BigDecimal payCredit = distributor.getPayCredit();
|
|
|
+ // 交易前已使用额度
|
|
|
+ beforeBalance = distributor.getSurplus();
|
|
|
+ // 交易后已使用额度
|
|
|
+ afterBalance = beforeBalance.add(money);
|
|
|
+ if (payCredit != null) {
|
|
|
+ if (afterBalance.compareTo(payCredit) > 0) {
|
|
|
+ if(originTradeType == DistributorTradeTypeEnum.BALANCE_TRANS.getType()){
|
|
|
+ throw exception0(11_028, "余额不足,交易失败!");
|
|
|
+ }else {
|
|
|
+ throw exception(CREDIT_INSUFFICIENT_FUNDS);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ BigDecimal creditRemained = payCredit.subtract(afterBalance);
|
|
|
+ tradeName = "授信消费金额:" + money + "元,授信总额度" + payCredit + "元,消费后剩余额度" + creditRemained + "元;已用额度" + afterBalance + "元";
|
|
|
+ } else {
|
|
|
+ tradeName = "授信消费金额:" + money + "元,授信总额度不限,消费后剩余额度不限;已用额度" + afterBalance + "元";
|
|
|
+ }
|
|
|
+ flag = distributorService.addSurplus(distributor.getId(), money);
|
|
|
+ }else if(storeRespDTO.get()!=null){
|
|
|
+ StoreRespDTO storeRsp = storeRespDTO.get();
|
|
|
+ beforeBalance = storeRsp.getBeforeAmount();
|
|
|
+ afterBalance = storeRsp.getAfterAmount();
|
|
|
+ tradeName = "授信支付金额:" + money + "元,支付后门店已使用授信从" + storeRsp.getBeforeAmount() + "元;变为"+ storeRsp.getAfterAmount();
|
|
|
+ flag = true;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
respDTO = new DistributorRechargeRespDTO();
|