|
@@ -1,11 +1,11 @@
|
|
|
package cn.com.ty.lift.quan.pay.service.impl;
|
|
|
|
|
|
import cn.com.ty.lift.common.aliservice.alipay.AlipayUtil;
|
|
|
-import cn.com.ty.lift.quan.pay.dao.entity.Pay;
|
|
|
import cn.com.ty.lift.quan.pay.dao.entity.PayRecord;
|
|
|
+import cn.com.ty.lift.quan.pay.dao.entity.UserInfo;
|
|
|
import cn.com.ty.lift.quan.pay.dao.entity.model.PayReq;
|
|
|
-import cn.com.ty.lift.quan.pay.dao.mapper.PayMapper;
|
|
|
-import cn.com.ty.lift.quan.pay.service.PayService;
|
|
|
+import cn.com.ty.lift.quan.pay.dao.mapper.UserInfoMapper;
|
|
|
+import cn.com.ty.lift.quan.pay.service.UserInfoService;
|
|
|
import cn.com.xwy.boot.web.dto.RestResponse;
|
|
|
import com.alipay.api.AlipayApiException;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
@@ -13,7 +13,6 @@ import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.time.LocalDate;
|
|
@@ -23,32 +22,21 @@ import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
|
- * 用户资金表 服务实现类
|
|
|
+ * 用户表 服务实现类
|
|
|
* </p>
|
|
|
*
|
|
|
* @author wang-hai-cheng
|
|
|
- * @since 2019-12-26
|
|
|
+ * @since 2020-01-05
|
|
|
*/
|
|
|
-@Transactional
|
|
|
@Service
|
|
|
@AllArgsConstructor
|
|
|
-public class PayServiceImpl extends ServiceImpl<PayMapper, Pay> implements PayService {
|
|
|
+public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> implements UserInfoService {
|
|
|
|
|
|
private final PayRecordServiceImpl recordService;
|
|
|
|
|
|
- public RestResponse bind(Pay pay) {
|
|
|
- //查询用户表,如果用户不存在就返回 "用户不存在"
|
|
|
- if (this.getBaseMapper().selectUserByUserId(pay.getUserId()).get("count") < 1L) {
|
|
|
- return RestResponse.fail("用户不存在");
|
|
|
- }
|
|
|
- //如果用户资金表不存在这个记录,就新增一个记录
|
|
|
- Pay byId = this.getById(pay.getUserId());
|
|
|
- if (byId == null) {
|
|
|
- byId = new Pay();
|
|
|
- byId.setUserId(pay.getUserId());
|
|
|
- }
|
|
|
- //获取前端传过来的用户账号
|
|
|
- byId.setAlipayAccount(pay.getAlipayAccount());
|
|
|
+ public RestResponse bind(UserInfo userInfo) {
|
|
|
+ UserInfo byId = this.getById(userInfo.getUserId());
|
|
|
+ //获取前端传过来的支付宝账号
|
|
|
if (this.saveOrUpdate(byId)) {
|
|
|
return RestResponse.success(null, "成功");
|
|
|
}
|
|
@@ -63,7 +51,7 @@ public class PayServiceImpl extends ServiceImpl<PayMapper, Pay> implements PaySe
|
|
|
if (req.getTotalAmount().compareTo(BigDecimal.ZERO) < 1) {
|
|
|
return RestResponse.fail("金额必须大于0");
|
|
|
}
|
|
|
- Pay byId = this.getById(req.getUserId());
|
|
|
+ UserInfo byId = this.getById(req.getUserId());
|
|
|
String outTradeNo = IdWorker.getIdStr();
|
|
|
PayRecord record = new PayRecord();
|
|
|
//设置用户id
|
|
@@ -80,8 +68,8 @@ public class PayServiceImpl extends ServiceImpl<PayMapper, Pay> implements PaySe
|
|
|
record.setStatus(0);
|
|
|
//设置支付宝订单号
|
|
|
String tradeNo;
|
|
|
- //type 1 创建充值订单
|
|
|
- if (req.getType().equals(1)) {
|
|
|
+ //task 1 创建充值订单
|
|
|
+ if (req.getTask().equals(1)) {
|
|
|
//向支付宝发创建充值订单请求
|
|
|
tradeNo = AlipayUtil
|
|
|
.create(byId.getAlipayAccount(), outTradeNo, req.getSubject(), req.getBody(), req.getTotalAmount());
|
|
@@ -96,9 +84,9 @@ public class PayServiceImpl extends ServiceImpl<PayMapper, Pay> implements PaySe
|
|
|
return RestResponse.fail();
|
|
|
}
|
|
|
|
|
|
- //type 2 创建提现审核订单
|
|
|
- if (req.getType().equals(2)) {
|
|
|
- if (req.getTotalAmount().compareTo(byId.getMoney()) > 0) {
|
|
|
+ //task 2 创建提现审核订单
|
|
|
+ if (req.getTask().equals(2)) {
|
|
|
+ if (req.getTotalAmount().compareTo(byId.getBalance()) > 0) {
|
|
|
return RestResponse.fail("账号余额不足");
|
|
|
}
|
|
|
if (recordService.getOne(new QueryWrapper<PayRecord>()
|
|
@@ -114,8 +102,8 @@ public class PayServiceImpl extends ServiceImpl<PayMapper, Pay> implements PaySe
|
|
|
return RestResponse.fail("每天仅支持提现3次");
|
|
|
}
|
|
|
//创建提现订单
|
|
|
- byId.setFreezeMoney(req.getTotalAmount());
|
|
|
- byId.setMoney(byId.getMoney().subtract(req.getTotalAmount()));
|
|
|
+ byId.setFreezeBalance(req.getTotalAmount());
|
|
|
+ byId.setBalance(byId.getBalance().subtract(req.getTotalAmount()));
|
|
|
record.setType(2);
|
|
|
//保存订单信息到数据库
|
|
|
if (this.updateById(byId) && recordService.save(record)) {
|
|
@@ -143,12 +131,12 @@ public class PayServiceImpl extends ServiceImpl<PayMapper, Pay> implements PaySe
|
|
|
}
|
|
|
//如果记录是充值
|
|
|
if (recordByOutTradeNo.getType() == 1) {
|
|
|
- Pay payById = this.getById(recordByOutTradeNo.getUserId());
|
|
|
+ UserInfo payById = this.getById(recordByOutTradeNo.getUserId());
|
|
|
//调用支付宝订单查询接口,查询充值订单是否完成
|
|
|
Map<String, Object> orderInfo = AlipayUtil.order(recordByOutTradeNo.getTradeNo());
|
|
|
if ((boolean) orderInfo.get("status")) {
|
|
|
//完成就设置用户在平台中的余额
|
|
|
- payById.setMoney(payById.getMoney()
|
|
|
+ payById.setBalance(payById.getBalance()
|
|
|
.add(recordByOutTradeNo.getTotalAmount()));
|
|
|
//设置订单状态为1完成,订单完成时间为当前
|
|
|
if (this.updateById(payById)) {
|
|
@@ -166,7 +154,7 @@ public class PayServiceImpl extends ServiceImpl<PayMapper, Pay> implements PaySe
|
|
|
}
|
|
|
//如果记录是提现
|
|
|
if (recordByOutTradeNo.getType() == 2) {
|
|
|
- Pay byId = this.getById(recordByOutTradeNo.getUserId());
|
|
|
+ UserInfo byId = this.getById(recordByOutTradeNo.getUserId());
|
|
|
//调用支付宝企业转账到个人 接口
|
|
|
String tradeNo = AlipayUtil.withdraw(
|
|
|
byId.getAlipayId(),
|
|
@@ -176,7 +164,7 @@ public class PayServiceImpl extends ServiceImpl<PayMapper, Pay> implements PaySe
|
|
|
//如果有订单码说明转账成功
|
|
|
if (tradeNo != null) {
|
|
|
//设置冻结金额为0
|
|
|
- byId.setFreezeMoney(new BigDecimal(0));
|
|
|
+ byId.setFreezeBalance(new BigDecimal(0));
|
|
|
//设置支付宝订单id,订单状态,订单完成时间
|
|
|
recordByOutTradeNo.setTradeNo(tradeNo);
|
|
|
recordByOutTradeNo.setStatus(1);
|
|
@@ -195,7 +183,7 @@ public class PayServiceImpl extends ServiceImpl<PayMapper, Pay> implements PaySe
|
|
|
List<PayRecord> payRecords = recordService.list(
|
|
|
new QueryWrapper<PayRecord>()
|
|
|
.eq("user_id", req.getUserId())
|
|
|
- .eq(req.getType() != null, "type", req.getType())
|
|
|
+ .eq(req.getTask() != null, "type", req.getTask())
|
|
|
.eq(req.getStatus() != null, "status", req.getStatus()));
|
|
|
if (payRecords.isEmpty()) {
|
|
|
return RestResponse.success();
|
|
@@ -225,9 +213,9 @@ public class PayServiceImpl extends ServiceImpl<PayMapper, Pay> implements PaySe
|
|
|
}
|
|
|
//如果订单是提现类型
|
|
|
if (recordByOutTradeNo.getType() == 2) {
|
|
|
- Pay byId = this.getById(recordByOutTradeNo.getUserId());
|
|
|
- byId.setMoney(byId.getMoney().add(byId.getFreezeMoney()));
|
|
|
- byId.setFreezeMoney(BigDecimal.ZERO);
|
|
|
+ UserInfo byId = this.getById(recordByOutTradeNo.getUserId());
|
|
|
+ byId.setBalance(byId.getBalance().add(byId.getFreezeBalance()));
|
|
|
+ byId.setFreezeBalance(BigDecimal.ZERO);
|
|
|
recordByOutTradeNo.setStatus(2);
|
|
|
if (this.updateById(byId) && recordService.updateById(recordByOutTradeNo)) {
|
|
|
return RestResponse.success(null, "成功");
|
|
@@ -236,4 +224,4 @@ public class PayServiceImpl extends ServiceImpl<PayMapper, Pay> implements PaySe
|
|
|
}
|
|
|
return RestResponse.fail();
|
|
|
}
|
|
|
-}
|
|
|
+}
|