|
@@ -23,12 +23,14 @@ import com.ruoyi.web.work.api.util.AppUtil;
|
|
|
import com.ruoyi.web.work.domain.Pay;
|
|
|
import com.ruoyi.web.work.domain.Platform;
|
|
|
import com.ruoyi.web.work.domain.User;
|
|
|
+import com.ruoyi.web.work.domain.dto.PayAddDto;
|
|
|
import com.ruoyi.web.work.domain.dto.PayAuditDto;
|
|
|
import com.ruoyi.web.work.domain.dto.PayCashOutDto;
|
|
|
import com.ruoyi.web.work.mapper.PayMapper;
|
|
|
import com.ruoyi.web.work.service.IPayService;
|
|
|
import com.ruoyi.web.work.service.IUserService;
|
|
|
import com.ruoyi.web.work.wxpay.WxPayBean;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.core.env.Environment;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -86,7 +88,10 @@ public class PayServiceImpl extends ServiceImpl<PayMapper, Pay> implements IPayS
|
|
|
return AjaxResult.error("银行卡信息未完善,无法提现");
|
|
|
}
|
|
|
if (dto.getMoney().compareTo(platform.getCashOutMoney()) < 0) {
|
|
|
- return AjaxResult.error("最少提现金额:" + platform.getCashOutMoney() + "起");
|
|
|
+ return AjaxResult.error("最少提现金额(¥):" + platform.getCashOutMoney() + "起");
|
|
|
+ }
|
|
|
+ if (platform.getCashOutMaxMoney() != null && dto.getMoney().compareTo(platform.getCashOutMaxMoney()) > 0) {
|
|
|
+ return AjaxResult.error("提现金额超过最大提现金额(¥):" + platform.getCashOutMaxMoney());
|
|
|
}
|
|
|
if (dto.getMoney().compareTo(user.getMoney()) > 0) {
|
|
|
return AjaxResult.error("提现金额超过账户余额");
|
|
@@ -129,7 +134,7 @@ public class PayServiceImpl extends ServiceImpl<PayMapper, Pay> implements IPayS
|
|
|
if (pay == null || pay.getType() != 2) {
|
|
|
return AjaxResult.error("提现信息不存在");
|
|
|
}
|
|
|
- if (pay.getState() == 1) {
|
|
|
+ if (pay.getState() != 0) {
|
|
|
return AjaxResult.error("不能重复操作");
|
|
|
}
|
|
|
pay.setState(dto.getState());
|
|
@@ -148,7 +153,7 @@ public class PayServiceImpl extends ServiceImpl<PayMapper, Pay> implements IPayS
|
|
|
}
|
|
|
//转账到微信零钱
|
|
|
if (pay.getWay() == 1 && pay.getState() == 1) {
|
|
|
- BigDecimal money =(pay.getMoney().subtract(pay.getServiceMoney())).multiply(new BigDecimal("100"));
|
|
|
+ BigDecimal money = (pay.getMoney().subtract(pay.getServiceMoney())).multiply(new BigDecimal("100"));
|
|
|
BatchTransferModel batchTransferModel = new BatchTransferModel().setAppid(wxPayV3Bean.getAppId()).setOut_batch_no(PayKit.generateStr()).setBatch_name("账户余额提现到零钱").setBatch_remark("账户余额提现到零钱").setTotal_amount(money.intValue()).setTotal_num(1).setTransfer_detail_list(Collections.singletonList(new TransferDetailInput().setOut_detail_no(PayKit.generateStr()).setTransfer_amount(money.intValue()).setTransfer_remark("账户余额提现到零钱").setOpenid(user.getOpenId())));
|
|
|
IJPayHttpResponse response = WxPayApi.v3(RequestMethodEnum.POST, WxDomainEnum.CHINA.toString(), TransferApiEnum.TRANSFER_BATCHES.toString(), wxPayV3Bean.getMchId(), getSerialNumber(), null, wxPayV3Bean.getKeyPath(), JSONUtil.toJsonStr(batchTransferModel));
|
|
|
String body = response.getBody();
|
|
@@ -199,6 +204,50 @@ public class PayServiceImpl extends ServiceImpl<PayMapper, Pay> implements IPayS
|
|
|
System.out.println("小程序订阅消息:" + result);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public AjaxResult add(PayAddDto dto) throws ServerException {
|
|
|
+ Pay pay = new Pay();
|
|
|
+ BeanUtils.copyProperties(dto, pay);
|
|
|
+ pay.setUserId(AppUtil.getUser().getId());
|
|
|
+ pay.setState(0);
|
|
|
+ pay.setTitle("转账充值");
|
|
|
+ pay.setType(0);
|
|
|
+ pay.setPayWay(1);
|
|
|
+ pay.setNums(PayKit.generateStr());
|
|
|
+ if (!save(pay)) {
|
|
|
+ throw new ServerException("金额充值失败,请联系平台客服");
|
|
|
+ }
|
|
|
+ return AjaxResult.success();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public AjaxResult confirm(PayAuditDto dto) throws ServerException {
|
|
|
+ Pay pay = getById(dto.getId());
|
|
|
+ if (pay == null || pay.getPayWay() != 1) {
|
|
|
+ return AjaxResult.error("充值信息不存在");
|
|
|
+ }
|
|
|
+ if (pay.getState() != 0) {
|
|
|
+ return AjaxResult.error("不能重复操作");
|
|
|
+ }
|
|
|
+ pay.setState(dto.getState());
|
|
|
+ pay.setMsg(dto.getMsg());
|
|
|
+ pay.setCompleteTime(new Date());
|
|
|
+ if (!updateById(pay)) {
|
|
|
+ throw new ServerException("充值失败,请联系平台");
|
|
|
+ }
|
|
|
+ User user = userService.getById(pay.getUserId());
|
|
|
+ //充值确认给用户账户充值
|
|
|
+ if (user != null && dto.getState() == 1) {
|
|
|
+ user.setMoney(user.getMoney().add(pay.getMoney()));
|
|
|
+ if (!userService.updateById(user)) {
|
|
|
+ throw new ServerException("更新用户账户余额失败,请联系平台");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return AjaxResult.success();
|
|
|
+ }
|
|
|
+
|
|
|
private String getSerialNumber() {
|
|
|
if (StrUtil.isEmpty(serialNo)) {
|
|
|
X509Certificate certificate = PayKit.getCertificate(wxPayV3Bean.getCertPath());
|