|
|
@@ -40,6 +40,7 @@ import org.springblade.core.mp.base.BaseServiceImpl;
|
|
|
import org.springblade.modules.guosen.debtDaliyStat.entity.BusinessDeptDaliyStat;
|
|
|
import org.springblade.modules.guosen.debtDaliyStat.service.IBusinessDeptDaliyStatService;
|
|
|
import org.springblade.modules.obs.service.ObsService;
|
|
|
+import org.springblade.modules.system.service.IParamService;
|
|
|
import org.springblade.yeePay.entity.BatchTransferDto;
|
|
|
import org.springblade.yeePay.entity.PayOrderDto;
|
|
|
import org.springblade.yeePay.service.YeePayService;
|
|
|
@@ -52,9 +53,9 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.text.DecimalFormat;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
/**
|
|
|
* 服务实现类
|
|
|
@@ -71,18 +72,16 @@ public class BussinessDebitRequestServiceImpl extends BaseServiceImpl<BussinessD
|
|
|
private IBussinessService bussinessService;
|
|
|
@Autowired
|
|
|
private ObsService obsService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private IBussinessDebitService bussinessDebitService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private YeePayService yeePayService;
|
|
|
-
|
|
|
@Value("${pay.noticeUrl}")
|
|
|
private String payNoticeUrl;
|
|
|
-
|
|
|
@Autowired
|
|
|
IBusinessDeptDaliyStatService businessDeptDaliyStatService;
|
|
|
+ @Autowired
|
|
|
+ private IParamService paramService;
|
|
|
|
|
|
@Override
|
|
|
public IPage<BussinessDebitRequestVO> selectBussinessDebitRequestPage(IPage<BussinessDebitRequestVO> page, BussinessDebitRequestVO bussinessDebitRequest) {
|
|
|
@@ -160,6 +159,7 @@ public class BussinessDebitRequestServiceImpl extends BaseServiceImpl<BussinessD
|
|
|
bussinessDebit.setReceiverBankCode(debitRequestExcel.getReceiverBankCode());
|
|
|
bussinessDebit.setRequestId(bussinessDebitRequest.getId());
|
|
|
bussinessDebit.setMethod(1); //xml导入方式
|
|
|
+ bussinessDebit.setRequestNo(UUID.randomUUID().toString().replaceAll("-","").toUpperCase());
|
|
|
if(bussinessDebitService.save(bussinessDebit)){
|
|
|
|
|
|
}else{
|
|
|
@@ -187,6 +187,107 @@ public class BussinessDebitRequestServiceImpl extends BaseServiceImpl<BussinessD
|
|
|
return R.status(false);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public R payOrder(PayOrderDto payOrderDto, String requestIp) {
|
|
|
+ String maintain = paramService.getValue("maintain");
|
|
|
+ if(StringUtil.isNotBlank(maintain)){
|
|
|
+ if(maintain.equals("0")){ //进入维护时间
|
|
|
+ return R.fail("系统维护时间为每天晚上22:00-凌晨07:00");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Bussiness bussiness = this.bussinessService.getById(payOrderDto.getBussinessId());
|
|
|
+ if(bussiness == null){
|
|
|
+ log.error("=================代付请求前校验,平台采购商不存在=================");
|
|
|
+ return R.fail("商户不存在");
|
|
|
+ }
|
|
|
+ if(bussiness.getRegisterStatus() == null || bussiness.getRegisterStatus().intValue() != SystemConstant.BussinessRegisterStatus.SUCCESS.getValue()){
|
|
|
+ log.error("=================代付请求前校验,商户未完成进件审核=================");
|
|
|
+ return R.fail("请先完成商户进件审核");
|
|
|
+ }
|
|
|
+ payOrderDto.setMerchantNo(bussiness.getMerchantNo());
|
|
|
+ //检查采购商余额
|
|
|
+ R<BigDecimal> remainR = this.bussinessService.queryBalance(bussiness.getMerchantNo());
|
|
|
+ BigDecimal remain = remainR.getData();
|
|
|
+ if(remain.compareTo(new BigDecimal(payOrderDto.getOrderAmount()).add(new BigDecimal(1))) == -1){
|
|
|
+ log.error("=================代付请求前校验,商户余额不足,请重新下单采购=================");
|
|
|
+ return R.fail("商户余额不足,请重新下单采购");
|
|
|
+ }
|
|
|
+ if(BigDecimal.valueOf(payOrderDto.getOrderAmount()).compareTo(bussiness.getMaxLimit()) == 1){ //大于的时候返回1,等于返回0,小于返回-1
|
|
|
+ log.error("=================代付请求前校验,提现金额不能超过商户每日限额=================");
|
|
|
+ return R.fail("提现金额不能超过商户每日限额" + payOrderDto.getOrderAmount());
|
|
|
+ }else{
|
|
|
+ //获取今日采购商已分润金额
|
|
|
+ BusinessDeptDaliyStat todayStat = businessDeptDaliyStatService.getTodayStat(bussiness.getId());
|
|
|
+ if(todayStat == null) {
|
|
|
+ businessDeptDaliyStatService.createTodayStat(bussiness.getId(), null);
|
|
|
+ }else{
|
|
|
+ //今日已分润金额
|
|
|
+ BigDecimal todayAmount = todayStat.getStatAmount();
|
|
|
+ if(todayAmount.add(new BigDecimal(payOrderDto.getOrderAmount())).compareTo(bussiness.getMaxLimit()) == 1){ //如果当日已分润金额+本次订单分润金额大于商户每日上限分润金额
|
|
|
+ log.error("=================代付请求前校验,今日提现金额已超过商户每日限额=================");
|
|
|
+ return R.fail("今日提现金额已超过商户每日限额");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //保存采购商单笔分佣请求对象
|
|
|
+ BussinessDebitRequest bussinessDebitRequest = new BussinessDebitRequest();
|
|
|
+ bussinessDebitRequest.setBussinessId(bussiness.getId());
|
|
|
+ bussinessDebitRequest.setOrderCount(1);//订单总笔数
|
|
|
+ bussinessDebitRequest.setStatus(0);//0为易宝未回调状态
|
|
|
+ BussinessDebit debit = null;
|
|
|
+ if(this.save(bussinessDebitRequest)){
|
|
|
+ debit = this.generateDebit(payOrderDto);
|
|
|
+ debit.setBussinessId(bussiness.getId());
|
|
|
+ debit.setRequestIp(requestIp);
|
|
|
+ debit.setRequestId(bussinessDebitRequest.getId());
|
|
|
+ String requestNo = UUID.randomUUID().toString().replaceAll("-","").toUpperCase();
|
|
|
+ debit.setRequestNo(requestNo);
|
|
|
+ payOrderDto.setRequestNo(requestNo);
|
|
|
+ if(!bussinessDebitService.save(debit)){
|
|
|
+ log.error("=================代付请求前校验,明细保存失败=================");
|
|
|
+ return R.fail("明细保存失败");
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ log.error("=================代付请求前校验,请求实例保存失败=================");
|
|
|
+ return R.fail("请求实例保存失败");
|
|
|
+ }
|
|
|
+ R result = this.yeePayService.payToCard(payOrderDto);
|
|
|
+ cn.hutool.json.JSONObject data = JSONUtil.parseObj(result.getData());
|
|
|
+ String returnCode = data.getStr("returnCode");
|
|
|
+ String returnMsg = data.getStr("returnMsg");
|
|
|
+ String orderNo = data.getStr("orderNo");
|
|
|
+ String msg = returnMsg;
|
|
|
+ if(StringUtil.isNotBlank(returnCode) && returnCode.equals("UA00000")) { //代付发起成功
|
|
|
+ log.info("========================单笔代付发起成功====================");
|
|
|
+ debit.setCurrentRemain(MoneyDesUtil.decrypt(remain.toString(), MoneyDesUtil.KEY_FOR_UC));
|
|
|
+ debit.setFailReason(returnMsg);
|
|
|
+ debit.setThirdPayLog(JSONUtil.toJsonStr(data));
|
|
|
+ debit.setThirdOrderNo(orderNo);
|
|
|
+ bussinessDebitService.saveOrUpdate(debit);
|
|
|
+ return R.data(data, msg);
|
|
|
+ }else{
|
|
|
+ debit.setStatus(SystemConstant.BussinessDebitStatus.FAIL.getValue());
|
|
|
+ debit.setFailReason(returnMsg);
|
|
|
+ debit.setThirdPayLog(JSONUtil.toJsonStr(data));
|
|
|
+ bussinessDebitService.saveOrUpdate(debit);
|
|
|
+ return R.data(400, data, msg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private BussinessDebit generateDebit(PayOrderDto payOrderDto){
|
|
|
+ BussinessDebit bussinessDebit = new BussinessDebit();
|
|
|
+ bussinessDebit.setFee(BigDecimal.valueOf(1));
|
|
|
+ bussinessDebit.setPrice(BigDecimal.valueOf(payOrderDto.getOrderAmount()));
|
|
|
+ bussinessDebit.setType(SystemConstant.BussinessDebitType.COMMISSION.getValue());
|
|
|
+ bussinessDebit.setBankAccountType(payOrderDto.getBankAccountType());
|
|
|
+ bussinessDebit.setReceiverAccountName(payOrderDto.getReceiverAccountName());
|
|
|
+ bussinessDebit.setReceiverAccountNo(payOrderDto.getReceiverAccountNo());
|
|
|
+ bussinessDebit.setReceiverBankCode(payOrderDto.getReceiverBankCode());
|
|
|
+ bussinessDebit.setBussinessOrderId(payOrderDto.getBussinessOrderId());
|
|
|
+ bussinessDebit.setMethod(2);//表示api对接
|
|
|
+ return bussinessDebit;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
private BatchTransferDto getBatchPayObject(List<BussinessDebit> bussinessDebits){
|
|
|
|
|
|
//批次号
|
|
|
@@ -230,7 +331,7 @@ public class BussinessDebitRequestServiceImpl extends BaseServiceImpl<BussinessD
|
|
|
payOrderDto.setReceiverAccountName(bussinessDebit.getReceiverAccountName());
|
|
|
payOrderDto.setReceiverBankCode(bussinessDebit.getReceiverBankCode());
|
|
|
payOrderDto.setBankAccountType(bussinessDebit.getBankAccountType());
|
|
|
- payOrderDto.setRequestNo(bussinessDebit.getId().toString());
|
|
|
+ payOrderDto.setRequestNo(bussinessDebit.getRequestNo());
|
|
|
R result = this.yeePayService.payToCard(payOrderDto);
|
|
|
cn.hutool.json.JSONObject data = JSONUtil.parseObj(result.getData());
|
|
|
String returnCode = data.getStr("returnCode");
|