|
@@ -4,19 +4,27 @@ import java.math.BigDecimal;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
|
+import com.fs.company.constant.PaymentStatus;
|
|
|
import com.fs.company.domain.Company;
|
|
|
import com.fs.company.domain.CompanyMoneyLogs;
|
|
|
+import com.fs.company.domain.CompanyRechargeOrder;
|
|
|
+import com.fs.company.dto.RechargeDTO;
|
|
|
import com.fs.company.mapper.CompanyMapper;
|
|
|
import com.fs.company.mapper.CompanyMoneyLogsMapper;
|
|
|
+import com.fs.company.mapper.CompanyRechargeOrderMapper;
|
|
|
+import com.fs.company.service.CompanyRechargeOrderService;
|
|
|
import com.fs.company.vo.CompanyRechargeExportVO;
|
|
|
import com.fs.company.vo.CompanyRechargeVO;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.fs.company.mapper.CompanyRechargeMapper;
|
|
|
import com.fs.company.domain.CompanyRecharge;
|
|
|
import com.fs.company.service.ICompanyRechargeService;
|
|
|
+import org.springframework.transaction.annotation.Propagation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
/**
|
|
@@ -25,6 +33,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
* @author fs
|
|
|
* @date 2021-10-04
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class CompanyRechargeServiceImpl implements ICompanyRechargeService
|
|
|
{
|
|
@@ -34,6 +43,8 @@ public class CompanyRechargeServiceImpl implements ICompanyRechargeService
|
|
|
private CompanyMoneyLogsMapper moneyLogsMapper;
|
|
|
@Autowired
|
|
|
private CompanyMapper companyMapper;
|
|
|
+ @Autowired
|
|
|
+ private CompanyRechargeOrderService companyRechargeOrderService;
|
|
|
/**
|
|
|
* 查询充值
|
|
|
*
|
|
@@ -120,13 +131,13 @@ public class CompanyRechargeServiceImpl implements ICompanyRechargeService
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Transactional
|
|
|
+ @Transactional(rollbackFor = Throwable.class,propagation = Propagation.REQUIRED)
|
|
|
public R payNotify(CompanyRecharge recharge) {
|
|
|
//修改状态
|
|
|
recharge.setPayTime(new Date());
|
|
|
recharge.setStatus(1);
|
|
|
companyRechargeMapper.updateCompanyRecharge(recharge);
|
|
|
- Company company=companyMapper.selectCompanyById(recharge.getCompanyId());
|
|
|
+ Company company=companyMapper.selectCompanyByIdForUpdate(recharge.getCompanyId());
|
|
|
company.setMoney(company.getMoney().add(recharge.getMoney()));
|
|
|
//写入日志
|
|
|
CompanyMoneyLogs log=new CompanyMoneyLogs();
|
|
@@ -134,7 +145,7 @@ public class CompanyRechargeServiceImpl implements ICompanyRechargeService
|
|
|
log.setMoney(recharge.getMoney());
|
|
|
log.setRemark("充值金额:"+recharge.getMoney()+"元");
|
|
|
log.setCreateTime(new Date());
|
|
|
- log.setLogsType(1);
|
|
|
+ log.setLogsType(3);
|
|
|
log.setBalance(company.getMoney());
|
|
|
moneyLogsMapper.insertCompanyMoneyLogs(log);
|
|
|
//修改余额
|
|
@@ -144,6 +155,38 @@ public class CompanyRechargeServiceImpl implements ICompanyRechargeService
|
|
|
return R.ok();
|
|
|
}
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private CompanyRechargeOrderMapper companyRechargeOrderMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public synchronized R payNotify(String orderNo,String transactionId) {
|
|
|
+ CompanyRechargeOrder order = companyRechargeOrderMapper.selectByOrderNo(orderNo);
|
|
|
+
|
|
|
+ if(ObjectUtil.equal(order.getPayStatus(), PaymentStatus.SUCCESS.getCode())){
|
|
|
+ log.info("订单已支付!重复付款 {} {}", orderNo,transactionId);
|
|
|
+ R.ok();
|
|
|
+ }
|
|
|
+ //修改状态
|
|
|
+ order.setPayStatus(PaymentStatus.SUCCESS.getCode());
|
|
|
+ order.setTransactionId(transactionId);
|
|
|
+ companyRechargeOrderMapper.updateByOrderNo(order);
|
|
|
+
|
|
|
+ Company company=companyMapper.selectCompanyByIdForUpdate(order.getCompanyId());
|
|
|
+ //写入日志
|
|
|
+ CompanyMoneyLogs log=new CompanyMoneyLogs();
|
|
|
+ log.setCompanyId(order.getCompanyId());
|
|
|
+ log.setMoney(order.getPayAmount());
|
|
|
+ log.setRemark("充值金额:"+order.getPayAmount()+"元");
|
|
|
+ log.setCreateTime(new Date());
|
|
|
+ log.setLogsType(3);
|
|
|
+ log.setBalance(company.getMoney());
|
|
|
+ moneyLogsMapper.insertCompanyMoneyLogs(log);
|
|
|
+ //修改余额
|
|
|
+ company.setMoney(company.getMoney().add(order.getPayAmount()));
|
|
|
+ companyMapper.updateCompany(company);
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public BigDecimal selectCompanyRechargeMoney() {
|
|
|
return companyRechargeMapper.selectCompanyRechargeMoney();
|
|
@@ -153,4 +196,19 @@ public class CompanyRechargeServiceImpl implements ICompanyRechargeService
|
|
|
public List<CompanyRechargeExportVO> selectCompanyRechargeExportList(CompanyRecharge companyRecharge) {
|
|
|
return companyRechargeMapper.selectCompanyRechargeExportList(companyRecharge);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Throwable.class)
|
|
|
+ public CompanyRechargeOrder recharge(RechargeDTO dto) throws Exception {
|
|
|
+ CompanyRechargeOrder order = new CompanyRechargeOrder();
|
|
|
+ order.setPayAmount(dto.getAmount());
|
|
|
+ order.setCompanyId(dto.getCompanyId());
|
|
|
+ order.setUserId(dto.getUserId());
|
|
|
+ return companyRechargeOrderService.createOrder(order);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CompanyRechargeOrder queryOrder(String orderNo) {
|
|
|
+ return companyRechargeOrderService.queryOrder(orderNo);
|
|
|
+ }
|
|
|
}
|