| | |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | |
| | |
| | | CashWithdrawal cashWithdrawal = new CashWithdrawal(); |
| | | cashWithdrawal.setType(2); |
| | | cashWithdrawal.setUserDriverId(driverId); |
| | | cashWithdrawal.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3)); |
| | | cashWithdrawal.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(5)); |
| | | cashWithdrawal.setBusinessType(type == 2 ? 11 : 12); |
| | | cashWithdrawal.setBankId(bankId); |
| | | cashWithdrawal.setAmount(money); |
| | |
| | | |
| | | //增加记录 |
| | | AccountChangeDetail accountChangeDetail = new AccountChangeDetail(); |
| | | accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(3)); |
| | | accountChangeDetail.setCode(System.currentTimeMillis() + UUIDUtil.getNumberRandom(5)); |
| | | accountChangeDetail.setUserType(2); |
| | | accountChangeDetail.setUserId(driver.getId()); |
| | | accountChangeDetail.setType(1); |
| | | accountChangeDetail.setChangeType(type == 1 ? 4 : 6); |
| | | if(type == 1){ |
| | | accountChangeDetail.setOldData(driver.getBalance() + driver.getBackgroundBalance()); |
| | | driver.setBalance(driver.getBalance() - money); |
| | | accountChangeDetail.setNewData(driver.getBalance() + driver.getBackgroundBalance()); |
| | | accountChangeDetail.setOldData(new BigDecimal(driver.getBalance()).add(new BigDecimal(driver.getBackgroundBalance())).setScale(2, RoundingMode.HALF_EVEN).doubleValue()); |
| | | driver.setBalance(new BigDecimal(driver.getBalance()).subtract(new BigDecimal(money)).setScale(2, RoundingMode.HALF_EVEN).doubleValue()); |
| | | accountChangeDetail.setNewData(new BigDecimal(driver.getBalance()).add(new BigDecimal(driver.getBackgroundBalance())).setScale(2, RoundingMode.HALF_EVEN).doubleValue()); |
| | | }else{ |
| | | accountChangeDetail.setOldData(driver.getCommission() + driver.getCouponBalance()); |
| | | driver.setCommission(driver.getCommission() - money); |
| | | accountChangeDetail.setNewData(driver.getCouponBalance() + driver.getCommission()); |
| | | accountChangeDetail.setOldData(new BigDecimal(driver.getCouponBalance()).add(new BigDecimal(driver.getCommission())).setScale(2, RoundingMode.HALF_EVEN).doubleValue()); |
| | | driver.setCommission(new BigDecimal(driver.getCommission()).subtract(new BigDecimal(money)).setScale(2, RoundingMode.HALF_EVEN).doubleValue()); |
| | | accountChangeDetail.setNewData(new BigDecimal(driver.getCouponBalance()).add(new BigDecimal(driver.getCommission())).setScale(2, RoundingMode.HALF_EVEN).doubleValue()); |
| | | } |
| | | accountChangeDetail.setExplain(type == 1 ? "账户余额提现" : "佣金余额提现"); |
| | | driverService.updateById(driver); |
| | |
| | | } |
| | | } |
| | | }else{//佣金提现,直接提现到银行卡 |
| | | Withdraw withdraw = new Withdraw(); |
| | | withdraw.setUserId(driver.getMerchantNumber()); |
| | | withdraw.setAmount(String.valueOf(Double.valueOf(money * 100).intValue())); |
| | | withdraw.setOrderName("账户余额提现"); |
| | | withdraw.setRemark("账户余额提现"); |
| | | withdraw.setNotifyUrl(callbackPath + "/base/driver/withdrawCashCallback"); |
| | | withdraw.setParameter1(cashWithdrawal.getId().toString()); |
| | | TrhRequest<Withdraw> request1 = new TrhRequest(); |
| | | InterfaceResponse execute = request1.execute(withdraw, Withdraw.SERVICE_CODE);//结算(提现) |
| | | if("0000".equals(execute.getCode())){ |
| | | JSONObject jsonObject1 = JSON.parseObject(execute.getResult()); |
| | | String merOrderId1 = jsonObject1.getString("merOrderId"); |
| | | Integer status = jsonObject1.getInteger("status");//0:待处理;1:成功;2:失败 |
| | | if(1 == status){ |
| | | cashWithdrawal.setOrderNumber(merOrderId1); |
| | | cashWithdrawal.setState(2); |
| | | this.updateById(cashWithdrawal); |
| | | Double finalMoney = money; |
| | | new Timer().schedule(new TimerTask() { |
| | | @Override |
| | | public void run() { |
| | | Withdraw withdraw = new Withdraw(); |
| | | withdraw.setUserId(driver.getMerchantNumber()); |
| | | withdraw.setAmount(new BigDecimal(finalMoney).multiply(new BigDecimal(100)).setScale(0, RoundingMode.HALF_EVEN).longValue() + ""); |
| | | withdraw.setOrderName("账户余额提现"); |
| | | withdraw.setRemark("账户余额提现"); |
| | | withdraw.setNotifyUrl(callbackPath + "/base/driver/withdrawCashCallback"); |
| | | withdraw.setParameter1(cashWithdrawal.getId().toString()); |
| | | TrhRequest<Withdraw> request1 = new TrhRequest(); |
| | | InterfaceResponse execute = request1.execute(withdraw, Withdraw.SERVICE_CODE);//结算(提现) |
| | | if("0000".equals(execute.getCode())){ |
| | | JSONObject jsonObject1 = JSON.parseObject(execute.getResult()); |
| | | String merOrderId1 = jsonObject1.getString("merOrderId"); |
| | | Integer status = jsonObject1.getInteger("status");//0:待处理;1:成功;2:失败 |
| | | if(1 == status){ |
| | | cashWithdrawal.setOrderNumber(merOrderId1); |
| | | cashWithdrawal.setState(2); |
| | | CashWithdrawalServiceImpl.this.updateById(cashWithdrawal); |
| | | } |
| | | if(2 == status){ |
| | | System.err.println("结算接口异常【提现】:" + jsonObject1.getString("statusMsg")); |
| | | } |
| | | }else{ |
| | | System.err.println("结算接口异常【提现】:" + execute.getMsg()); |
| | | } |
| | | } |
| | | if(2 == status){ |
| | | System.err.println("结算接口异常【提现】:" + jsonObject1.getString("statusMsg")); |
| | | } |
| | | }else{ |
| | | System.err.println("结算接口异常【提现】:" + execute.getMsg()); |
| | | } |
| | | }, 60000); |
| | | } |
| | | return ResultUtil.success(); |
| | | } |
| | |
| | | List<PamentOrderUser> splitList = new ArrayList<>(); |
| | | PamentOrderUser pamentOrderUser = new PamentOrderUser(); |
| | | pamentOrderUser.setSplitUserId(driver.getMerchantNumber()); |
| | | pamentOrderUser.setSplitAmount(String.valueOf(Double.valueOf(amount * 100).intValue())); |
| | | pamentOrderUser.setSplitAmount(new BigDecimal(amount).multiply(new BigDecimal(100)).setScale(0, RoundingMode.HALF_EVEN).longValue() + ""); |
| | | pamentOrderUser.setSplitType("1"); |
| | | splitList.add(pamentOrderUser); |
| | | complete.setSplitList(splitList); |
| | |
| | | public void run() { |
| | | confirmReceipt(driver, rechargeRecord, divisionRecord, cashWithdrawal); |
| | | } |
| | | }, 15000); |
| | | }, 60000); |
| | | } |
| | | }else{ |
| | | System.err.println("司机提现分账处理异常 :" + execute.getMsg()); |
| | |
| | | List<PamentOrderUser> splitList = new ArrayList<>(); |
| | | PamentOrderUser pamentOrderUser = new PamentOrderUser(); |
| | | pamentOrderUser.setSplitUserId(driver.getMerchantNumber()); |
| | | pamentOrderUser.setSplitAmount(String.valueOf(Double.valueOf(surplusDividedAmount * 100).intValue())); |
| | | pamentOrderUser.setSplitAmount(new BigDecimal(surplusDividedAmount).multiply(new BigDecimal(100)).setScale(0, RoundingMode.HALF_EVEN).longValue() + ""); |
| | | pamentOrderUser.setSplitType("1"); |
| | | splitList.add(pamentOrderUser); |
| | | complete.setSplitList(splitList); |
| | |
| | | public void run() { |
| | | confirmReceipt(driver, rechargeRecord, divisionRecord, cashWithdrawal); |
| | | } |
| | | }, 15000); |
| | | }, 60000); |
| | | } |
| | | }else{ |
| | | System.err.println("司机提现分账处理异常 :" + execute.getMsg()); |
| | |
| | | List<PamentOrderUser> splitList = new ArrayList<>(); |
| | | PamentOrderUser pamentOrderUser = new PamentOrderUser(); |
| | | pamentOrderUser.setSplitUserId(driver.getMerchantNumber()); |
| | | pamentOrderUser.setSplitAmount(String.valueOf(Double.valueOf(amount * 100).intValue())); |
| | | pamentOrderUser.setSplitAmount(new BigDecimal(amount).multiply(new BigDecimal(100)).setScale(0, RoundingMode.HALF_EVEN).longValue() + ""); |
| | | pamentOrderUser.setSplitType("1"); |
| | | splitList.add(pamentOrderUser); |
| | | complete.setSplitList(splitList); |
| | |
| | | public void run() { |
| | | confirmReceipt(driver, rechargeRecord, divisionRecord, cashWithdrawal); |
| | | } |
| | | }, 15000); |
| | | }, 60000); |
| | | } |
| | | }else{ |
| | | System.err.println("司机提现分账处理异常 :" + execute.getMsg()); |
| | |
| | | Receive receive = new Receive(); |
| | | receive.setOriginalMerOrderId(rechargeRecord.getOrderNumber()); |
| | | receive.setAsynMerOrderId(divisionRecord.getMerOrderId()); |
| | | receive.setRcvAmount(String.valueOf(Double.valueOf(divisionRecord.getAmount() * 100).intValue())); |
| | | receive.setRcvAmount(new BigDecimal(divisionRecord.getAmount()).multiply(new BigDecimal(100)).setScale(0, RoundingMode.HALF_EVEN).longValue() + ""); |
| | | List<ReceiveUser> splitList = new ArrayList<>(); |
| | | ReceiveUser receiveUser = new ReceiveUser(); |
| | | receiveUser.setSplitUserId(driver.getMerchantNumber()); |
| | | receiveUser.setRcvSplitAmount(String.valueOf(Double.valueOf(divisionRecord.getAmount() * 100).intValue())); |
| | | receiveUser.setRcvSplitAmount(new BigDecimal(divisionRecord.getAmount()).multiply(new BigDecimal(100)).setScale(0, RoundingMode.HALF_EVEN).longValue() + ""); |
| | | splitList.add(receiveUser); |
| | | receive.setSplitList(splitList); |
| | | TrhRequest<Receive> request = new TrhRequest(); |
| | |
| | | JSONObject jsonObject = JSON.parseObject(execute1.getResult()); |
| | | String merOrderId = jsonObject.getString("merOrderId"); |
| | | if(ToolUtil.isNotEmpty(merOrderId)){ |
| | | Withdraw withdraw = new Withdraw(); |
| | | withdraw.setUserId(driver.getMerchantNumber()); |
| | | withdraw.setAmount(String.valueOf(Double.valueOf(divisionRecord.getAmount() * 100).intValue())); |
| | | withdraw.setOrderName("账户余额提现"); |
| | | withdraw.setRemark("账户余额提现"); |
| | | withdraw.setNotifyUrl(callbackPath + "/base/driver/withdrawCashCallback"); |
| | | withdraw.setParameter1(cashWithdrawal.getId().toString()); |
| | | TrhRequest<Withdraw> request1 = new TrhRequest(); |
| | | InterfaceResponse execute = request1.execute(withdraw, Withdraw.SERVICE_CODE);//结算(提现) |
| | | if("0000".equals(execute.getCode())){ |
| | | JSONObject jsonObject1 = JSON.parseObject(execute.getResult()); |
| | | String merOrderId1 = jsonObject1.getString("merOrderId"); |
| | | Integer status = jsonObject1.getInteger("status");//0:待处理;1:成功;2:失败 |
| | | if(1 == status){ |
| | | cashWithdrawal.setOrderNumber(merOrderId1); |
| | | cashWithdrawal.setState(2); |
| | | this.updateById(cashWithdrawal); |
| | | new Timer().schedule(new TimerTask() { |
| | | @Override |
| | | public void run() { |
| | | Withdraw withdraw = new Withdraw(); |
| | | withdraw.setUserId(driver.getMerchantNumber()); |
| | | withdraw.setAmount(new BigDecimal(divisionRecord.getAmount()).multiply(new BigDecimal(100)).setScale(0, RoundingMode.HALF_EVEN).longValue() + ""); |
| | | withdraw.setOrderName("账户余额提现"); |
| | | withdraw.setRemark("账户余额提现"); |
| | | withdraw.setNotifyUrl(callbackPath + "/base/driver/withdrawCashCallback"); |
| | | withdraw.setParameter1(cashWithdrawal.getId().toString()); |
| | | TrhRequest<Withdraw> request1 = new TrhRequest(); |
| | | InterfaceResponse execute = request1.execute(withdraw, Withdraw.SERVICE_CODE);//结算(提现) |
| | | if("0000".equals(execute.getCode())){ |
| | | JSONObject jsonObject1 = JSON.parseObject(execute.getResult()); |
| | | String merOrderId1 = jsonObject1.getString("merOrderId"); |
| | | Integer status = jsonObject1.getInteger("status");//0:待处理;1:成功;2:失败 |
| | | if(1 == status){ |
| | | cashWithdrawal.setOrderNumber(merOrderId1); |
| | | cashWithdrawal.setState(2); |
| | | CashWithdrawalServiceImpl.this.updateById(cashWithdrawal); |
| | | } |
| | | if(2 == status){ |
| | | System.err.println("结算接口异常【提现】:" + jsonObject1.getString("statusMsg")); |
| | | } |
| | | }else{ |
| | | System.err.println("结算接口异常【提现】:" + execute.getMsg()); |
| | | } |
| | | } |
| | | if(2 == status){ |
| | | System.err.println("结算接口异常【提现】:" + jsonObject1.getString("statusMsg")); |
| | | } |
| | | }else{ |
| | | System.err.println("结算接口异常【提现】:" + execute.getMsg()); |
| | | } |
| | | }, 60000); |
| | | } |
| | | }else{ |
| | | System.err.println("分账确认收货异常【提现】:" + execute1.getMsg()); |
| | |
| | | String parameter1 = jsonObject.getString("parameter1"); |
| | | String parameter2 = jsonObject.getString("parameter2"); |
| | | DivisionRecord divisionRecord = divisionRecordService.selectById(parameter1); |
| | | if(divisionRecord.getState() == 2){ |
| | | return; |
| | | } |
| | | divisionRecord.setMerOrderId(merOrderId); |
| | | divisionRecord.setPayTime(new Date()); |
| | | divisionRecord.setState(2); |
| | |
| | | public void run() { |
| | | confirmReceipt(driver, rechargeRecord, divisionRecord, cashWithdrawal); |
| | | } |
| | | }, 15000); |
| | | }, 60000); |
| | | } |
| | | }else{ |
| | | System.err.println("司机提现分账异常:" + interfaceResponse.getMsg()); |