|
|
|
@@ -84,6 +84,13 @@ public class WxCashOutServiceImpl implements WxCashOutService { |
|
|
|
wxCashOutMapper.insert(record); |
|
|
|
} |
|
|
|
|
|
|
|
private boolean hasCashCount(WxMall mall,WxMerchant merchant) { |
|
|
|
if (mall.getCashOutLimit().intValue()<=merchant.getCashOutCount().intValue()) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) |
|
|
|
public ResultData applyCashout(WxMerchantBUser buser, WxCashOut record,EnumPayWay payWay) { |
|
|
|
@@ -96,6 +103,11 @@ public class WxCashOutServiceImpl implements WxCashOutService { |
|
|
|
if (!(buser.getPhone().equals(merchant.getLinkPhone()))) { |
|
|
|
return new ResultData(Result.ERROR,"当前账号非商户管理员,不能进行此操作。"); |
|
|
|
} |
|
|
|
|
|
|
|
if(!hasCashCount(mall,merchant)) { |
|
|
|
return new ResultData(Result.ERROR,"当日提现次数已达限额。"); |
|
|
|
} |
|
|
|
|
|
|
|
if (record.getTotalFee().intValue()<=0) { |
|
|
|
return new ResultData(Result.ERROR,"提现金额非法。"); |
|
|
|
} |
|
|
|
@@ -114,6 +126,7 @@ public class WxCashOutServiceImpl implements WxCashOutService { |
|
|
|
if (cashsetlock) { |
|
|
|
try { |
|
|
|
merchant.setCashOutNumber(record.getTotalFee()); |
|
|
|
//更新金额,并减小次数 |
|
|
|
wxMerchantMapper.reduceCash(merchant); |
|
|
|
redisLock.unlock("merchantLockReduceCashSet_"+merchant.getId(), timeStr); |
|
|
|
}catch(Exception e) { |
|
|
|
@@ -166,7 +179,6 @@ public class WxCashOutServiceImpl implements WxCashOutService { |
|
|
|
sendCashOutMsg(merchant, cashout.getId(),payWay); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return new ResultData("提现提交成功。"); |
|
|
|
} |
|
|
|
|
|
|
|
@@ -199,7 +211,7 @@ public class WxCashOutServiceImpl implements WxCashOutService { |
|
|
|
WxMerchant merchant = wxMerchantMapper.selectById(record.getMerchantId()); |
|
|
|
//增加账户金额 |
|
|
|
//此处需要加锁,防止并发设置 |
|
|
|
long time = System.currentTimeMillis() + RedisLock.TIMEOUT; |
|
|
|
long time = System.currentTimeMillis() + RedisLock.LONG_TIMEOUT; |
|
|
|
String timeStr = String.valueOf(time); |
|
|
|
boolean cashsetlock = redisLock.lock("merchantLockRejectCashSet_"+merchant.getId(), timeStr); |
|
|
|
if (cashsetlock) { |
|
|
|
@@ -243,44 +255,67 @@ public class WxCashOutServiceImpl implements WxCashOutService { |
|
|
|
|
|
|
|
@Override |
|
|
|
public ResultData reCashout(WxMerchantBUser buser, WxCashOut record, EnumPayWay payWay) { |
|
|
|
WxCashOut cashout = this.getById(record.getId(), buser.getTenantId()); |
|
|
|
if (null == cashout ) { |
|
|
|
return new ResultData(Result.ERROR,"该提现记录不存在"); |
|
|
|
} |
|
|
|
|
|
|
|
if( EnumCashOutStatus.FAIL.getCode().intValue() != record.getStatus().intValue()) { |
|
|
|
return new ResultData(Result.ERROR,"提现失败状态才能重新提现。"); |
|
|
|
} |
|
|
|
|
|
|
|
//只有商户管理员才能进行此操作 |
|
|
|
WxMerchant merchant = wxMerchantMapper.selectById(buser.getMerchantId()); |
|
|
|
if (!(buser.getPhone().equals(merchant.getLinkPhone()))) { |
|
|
|
return new ResultData(Result.ERROR,"当前账号非商户管理员,不能进行此操作。"); |
|
|
|
} |
|
|
|
WxAppinfo appInfo = wxAppinfoService.getCAppInfo(buser, payWay); |
|
|
|
if (null == appInfo) { |
|
|
|
return new ResultData(Result.ERROR,"当前账号非商户管理员,不能进行此操作。"); |
|
|
|
} |
|
|
|
WxPayAccount payAccount = wxPayAccountService.getByTenantId(buser.getTenantId()); |
|
|
|
if (null == payAccount) { |
|
|
|
return new ResultData(Result.ERROR,"当前账号非商户管理员,不能进行此操作。"); |
|
|
|
} |
|
|
|
//查询是否已经真实的转过了 |
|
|
|
CashOutAdapterResult qresult = payServiceFactory.getCashOutAdapterService(payWay.getCode()).queryCashOut(appInfo, payAccount, cashout); |
|
|
|
if (qresult.isSuccess()) { |
|
|
|
cashout.setStatus(EnumCashOutStatus.SUCCESS.getCode()); |
|
|
|
wxCashOutMapper.updateStatus(cashout); |
|
|
|
}else { |
|
|
|
CashOutAdapterResult result = payServiceFactory.getCashOutAdapterService(payWay.getCode()).cashOut(appInfo, payAccount, cashout); |
|
|
|
cashout.setUpdateDate(new Date()); |
|
|
|
if (result.isSuccess()) { |
|
|
|
cashout.setStatus(EnumCashOutStatus.SUCCESS.getCode()); |
|
|
|
}else { |
|
|
|
cashout.setStatus(EnumCashOutStatus.FAIL.getCode()); |
|
|
|
cashout.setFailRemark(result.getMsg()); |
|
|
|
} |
|
|
|
wxCashOutMapper.updateById(cashout); |
|
|
|
} |
|
|
|
//不能重复提交操作 |
|
|
|
long time = System.currentTimeMillis() + RedisLock.LONG_TIMEOUT; |
|
|
|
String timeStr = String.valueOf(time); |
|
|
|
boolean cashsetlock = redisLock.lock("merchantLockReCashSet_"+record.getId(), timeStr); |
|
|
|
if (cashsetlock) { |
|
|
|
try { |
|
|
|
WxCashOut cashout = this.getById(record.getId(), buser.getTenantId()); |
|
|
|
if (null == cashout ) { |
|
|
|
return new ResultData(Result.ERROR,"该提现记录不存在"); |
|
|
|
} |
|
|
|
|
|
|
|
if( EnumCashOutStatus.FAIL.getCode().intValue() != record.getStatus().intValue()) { |
|
|
|
return new ResultData(Result.ERROR,"提现失败状态才能重新提现。"); |
|
|
|
} |
|
|
|
|
|
|
|
//只有商户管理员才能进行此操作 |
|
|
|
WxMerchant merchant = wxMerchantMapper.selectById(buser.getMerchantId()); |
|
|
|
if (!(buser.getPhone().equals(merchant.getLinkPhone()))) { |
|
|
|
return new ResultData(Result.ERROR,"当前账号非商户管理员,不能进行此操作。"); |
|
|
|
} |
|
|
|
|
|
|
|
WxMall mall = wxMallMapper.getByTenantId(buser.getTenantId()); |
|
|
|
if(!hasCashCount(mall,merchant)) { |
|
|
|
return new ResultData(Result.ERROR,"当日提现次数已达限额。"); |
|
|
|
} |
|
|
|
|
|
|
|
WxAppinfo appInfo = wxAppinfoService.getCAppInfo(buser, payWay); |
|
|
|
if (null == appInfo) { |
|
|
|
return new ResultData(Result.ERROR,"系统错误,appInfo未查询到。"); |
|
|
|
} |
|
|
|
WxPayAccount payAccount = wxPayAccountService.getByTenantId(buser.getTenantId()); |
|
|
|
if (null == payAccount) { |
|
|
|
return new ResultData(Result.ERROR,"系统错误,payAccount未查询到。"); |
|
|
|
} |
|
|
|
//查询是否已经真实的转过了 |
|
|
|
CashOutAdapterResult qresult = payServiceFactory.getCashOutAdapterService(payWay.getCode()).queryCashOut(appInfo, payAccount, cashout); |
|
|
|
if (qresult.isSuccess()) { |
|
|
|
cashout.setStatus(EnumCashOutStatus.SUCCESS.getCode()); |
|
|
|
wxCashOutMapper.updateStatus(cashout); |
|
|
|
}else { |
|
|
|
CashOutAdapterResult result = payServiceFactory.getCashOutAdapterService(payWay.getCode()).cashOut(appInfo, payAccount, cashout); |
|
|
|
cashout.setUpdateDate(new Date()); |
|
|
|
if (result.isSuccess()) { |
|
|
|
cashout.setStatus(EnumCashOutStatus.SUCCESS.getCode()); |
|
|
|
}else { |
|
|
|
cashout.setStatus(EnumCashOutStatus.FAIL.getCode()); |
|
|
|
cashout.setFailRemark(result.getMsg()); |
|
|
|
} |
|
|
|
wxCashOutMapper.updateById(cashout); |
|
|
|
} |
|
|
|
//更新次数 |
|
|
|
wxMerchantMapper.increaseCashCount(merchant); |
|
|
|
redisLock.unlock("merchantLockReCashSet_"+record.getId(), timeStr); |
|
|
|
}catch(Exception e) { |
|
|
|
redisLock.unlock("merchantLockReCashSet_"+record.getId(), timeStr); |
|
|
|
logger.error("update cashout fail.",e); |
|
|
|
}finally { |
|
|
|
redisLock.unlock("merchantLockReCashSet_"+record.getId(), timeStr); |
|
|
|
} |
|
|
|
} |
|
|
|
return new ResultData(); |
|
|
|
} |
|
|
|
} |