|
|
@@ -1,19 +1,28 @@
|
|
|
package org.jeecg.modules.hlgpayment.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import org.jeecg.common.api.vo.Result;
|
|
|
+import org.jeecg.common.util.StringUtils;
|
|
|
+import org.jeecg.common.util.businessAccountUtils;
|
|
|
import org.jeecg.modules.hlgcompany.entity.HlgCompany;
|
|
|
import org.jeecg.modules.hlgcompany.entity.HlgCompanySubcontractor;
|
|
|
import org.jeecg.modules.hlgcompany.service.IHlgCompanyService;
|
|
|
import org.jeecg.modules.hlgcompany.service.IHlgCompanySubcontractorService;
|
|
|
import org.jeecg.modules.hlgpayment.entity.HlgPayment;
|
|
|
+import org.jeecg.modules.hlgpayment.entity.HlgPaymentDetail;
|
|
|
import org.jeecg.modules.hlgpayment.mapper.HlgPaymentMapper;
|
|
|
+import org.jeecg.modules.hlgpayment.service.IHlgPaymentDetailService;
|
|
|
import org.jeecg.modules.hlgpayment.service.IHlgPaymentService;
|
|
|
import org.jeecg.modules.hlgplatform.entity.HlgPlatform;
|
|
|
import org.jeecg.modules.hlgplatform.entity.HlgPlatformSubcontractor;
|
|
|
import org.jeecg.modules.hlgplatform.service.IHlgPlatformService;
|
|
|
import org.jeecg.modules.hlgplatform.service.IHlgPlatformSubcontractorService;
|
|
|
+import org.jeecg.modules.hlgtax.entity.HlgTax;
|
|
|
+import org.jeecg.modules.hlgtax.entity.HlgTaxRate;
|
|
|
+import org.jeecg.modules.hlgtax.service.IHlgTaxRateService;
|
|
|
+import org.jeecg.modules.hlgtax.service.IHlgTaxService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
@@ -21,6 +30,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.text.DecimalFormat;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* @Description: 付款信息表
|
|
|
@@ -39,6 +50,12 @@ public class HlgPaymentServiceImpl extends ServiceImpl<HlgPaymentMapper, HlgPaym
|
|
|
private IHlgCompanyService hlgCompanyService;
|
|
|
@Autowired
|
|
|
private IHlgPlatformService hlgPlatformService;
|
|
|
+ @Autowired
|
|
|
+ private IHlgPaymentDetailService hlgPaymentDetailService;
|
|
|
+ @Autowired
|
|
|
+ private IHlgTaxRateService hlgTaxRateService;
|
|
|
+ @Autowired
|
|
|
+ private IHlgTaxService hlgTaxService;
|
|
|
|
|
|
@Override
|
|
|
public Page<HlgPayment> pageList(Page<HlgPayment> pageList, HlgPayment hlgPayment, QueryWrapper<HlgPayment> queryWrapper) {
|
|
|
@@ -98,9 +115,102 @@ public class HlgPaymentServiceImpl extends ServiceImpl<HlgPaymentMapper, HlgPaym
|
|
|
result.error500("余额不足,请充值");
|
|
|
return result;
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 开始复核
|
|
|
+ */
|
|
|
+ //通过paymentId查询该付款单所有明细
|
|
|
+ QueryWrapper<HlgPaymentDetail> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("payment_id", hlgPayment.getId());
|
|
|
+ List<HlgPaymentDetail> hlgPaymentDetailList = hlgPaymentDetailService.list(queryWrapper);
|
|
|
+ //总付款金额
|
|
|
+ Double totalPayment = 0.00;
|
|
|
+ //未找到税率区间的用户集合
|
|
|
+ String users = "";
|
|
|
+ //超过第一级税率区间的用户集合
|
|
|
+ String usersFirst = "";
|
|
|
+ for (HlgPaymentDetail hlgPaymentDetail : hlgPaymentDetailList) {
|
|
|
+ /**
|
|
|
+ * 计算个人所得税
|
|
|
+ */
|
|
|
+ //1.该付款明细用户本月累计已打款(包含:1:付款中 2:付款成功)
|
|
|
+ List<HlgPaymentDetail> userList = hlgPaymentDetailService.findMonthListByUserId(hlgPaymentDetail);
|
|
|
+ //已付总额
|
|
|
+ Double totalOldPayment = 0.00;
|
|
|
+ //已付总税额
|
|
|
+ Double totalOldTaxFee = 0.00;
|
|
|
+ for (int j = 0; j < userList.size(); j++) {
|
|
|
+ HlgPaymentDetail hlgPaymentDetail1 = userList.get(j);
|
|
|
+ //已付总额
|
|
|
+ totalOldPayment = businessAccountUtils.add(totalOldPayment, hlgPaymentDetail1.getPayment());
|
|
|
+ //已付总税额
|
|
|
+ totalOldTaxFee = businessAccountUtils.add(totalOldTaxFee, hlgPaymentDetail1.getTaxFee());
|
|
|
+ }
|
|
|
+ //该用户本月累计付款
|
|
|
+ Double currentTotalPayment = businessAccountUtils.add(totalOldPayment, hlgPaymentDetail.getPayment());
|
|
|
+ //查询当前付款的服务商的税务信息
|
|
|
+ HlgTax hlgTax = hlgTaxService.getBySubId(hlgPayment.getSubcontractorId());
|
|
|
+ //查询当前付款所处的税率区间
|
|
|
+ HlgTaxRate hlgTaxRate = hlgTaxRateService.getByTaxFee(hlgPayment.getSubcontractorId(), currentTotalPayment);
|
|
|
+ if (hlgTaxRate != null) {
|
|
|
+ //超过第一级税率区间的用户
|
|
|
+ if (hlgTaxRate.getStartInterval() != 0) {
|
|
|
+ if (StringUtils.isBlank(usersFirst)) {
|
|
|
+ usersFirst = hlgPaymentDetail.getUserName();
|
|
|
+ }
|
|
|
+ hlgPayment.getList().add(hlgPaymentDetail);
|
|
|
+ } else {
|
|
|
+ //开始算税
|
|
|
+ hlgPaymentDetail.setTaxRate(hlgTaxRate.getRate());
|
|
|
+ hlgPaymentDetail.setTaxType(hlgTax.getTaxType());
|
|
|
+ //本月总税额
|
|
|
+ Double currentTaxFee = 0.00;
|
|
|
+ //0:应付计税 1:实付计税
|
|
|
+ if (hlgTax.getTaxType() == 0) {
|
|
|
+ //本月总税额=[本月总金额/(1-tax_rate*0.01)]*(tax_rate*0.01)
|
|
|
+ currentTaxFee = businessAccountUtils.mul(businessAccountUtils.div(currentTotalPayment, businessAccountUtils.sub(1, hlgTaxRate.getRate() * 0.01)), hlgTaxRate.getRate() * 0.01);
|
|
|
+ } else if (hlgTax.getTaxType() == 1) {
|
|
|
+ //本月总税额=本月总金额*tax_rate*0.01
|
|
|
+ currentTaxFee = businessAccountUtils.mul(currentTotalPayment, hlgTaxRate.getRate() * 0.01);
|
|
|
+ }
|
|
|
+ //本次应缴税额,四舍五入俩位小数
|
|
|
+ hlgPaymentDetail.setTaxFee(businessAccountUtils.round(businessAccountUtils.sub(currentTaxFee, totalOldTaxFee), 2));
|
|
|
+ hlgPaymentDetailService.updateById(hlgPaymentDetail);
|
|
|
+ //付款总额
|
|
|
+ totalPayment = businessAccountUtils.add(totalPayment, hlgPaymentDetail.getPayment());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //查不到该用户所处的税率区间
|
|
|
+ if (StringUtils.isBlank(users)) {
|
|
|
+ users = hlgPaymentDetail.getUserName();
|
|
|
+ }
|
|
|
+ hlgPayment.getList().add(hlgPaymentDetail);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //判断是否有用户付款时找不到税率区间
|
|
|
+ if (StringUtils.isNotBlank(users) && hlgPayment.getList() != null && hlgPayment.getList().size() > 0) {
|
|
|
+ result.error500("当月累计金额找不到配置的税率");
|
|
|
+ result.setResult(hlgPayment);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ //判断是否有用户超过第一级税率
|
|
|
+ if (StringUtils.isNotBlank(usersFirst) && hlgPayment.getList() != null && hlgPayment.getList().size() > 0) {
|
|
|
+ result.error500("超出第一级税率");
|
|
|
+ result.setResult(hlgPayment);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ //四舍五入,保留俩位小数
|
|
|
+ DecimalFormat df = new DecimalFormat("#.00");
|
|
|
+ String totalPaymenStr = df.format(totalPayment);
|
|
|
|
|
|
+ //银行业务接口(代发工资)
|
|
|
+// JSONObject jsonObjectBody = PayCommon.DCAGPOPR(hwPaymentDetailList, totalPaymenStr);
|
|
|
+
|
|
|
+
|
|
|
+ } else {
|
|
|
+ updateById(hlgPayment);
|
|
|
+ result.success("复核不通过");
|
|
|
+ }
|
|
|
return result;
|
|
|
}
|
|
|
|