find settle to

master
yixian 7 years ago
parent d2ee955ca8
commit d47830f7f9

@ -96,7 +96,7 @@ public interface TransactionMapper {
List<JSONObject> listTransactionsForReferrerCommission(@Param("year") int year, @Param("month") int month); List<JSONObject> listTransactionsForReferrerCommission(@Param("year") int year, @Param("month") int month);
List<JSONObject> listTransactionsForAgentCommission(@Param("year") int year, @Param("month") int month,@Param("parent_org_id") int parent_org_id); List<JSONObject> listTransactionsForAgentCommission(@Param("year") int year, @Param("month") int month, @Param("parent_org_id") int parent_org_id);
BigDecimal checkBalance(@Param("end") Date endDate); BigDecimal checkBalance(@Param("end") Date endDate);
@ -128,6 +128,6 @@ public interface TransactionMapper {
List<JSONObject> getClientRank(@Param("begin") Date begin, @Param("end") Date end); List<JSONObject> getClientRank(@Param("begin") Date begin, @Param("end") Date end);
List<JSONObject> listClientUnsettleDataByDate(@Param("client_id") int clientId); List<JSONObject> listClientUnsettleDataByDate(@Param("client_id") int clientId, @Param("max_settle_to") Date maxSettleTo);
} }

@ -3,6 +3,7 @@ package au.com.royalpay.payment.manage.settlement.core.impls;
import au.com.royalpay.payment.manage.mappers.log.ClearingLogMapper; import au.com.royalpay.payment.manage.mappers.log.ClearingLogMapper;
import au.com.royalpay.payment.manage.mappers.payment.TaskManualSettleMapper; import au.com.royalpay.payment.manage.mappers.payment.TaskManualSettleMapper;
import au.com.royalpay.payment.manage.mappers.payment.TransactionMapper; import au.com.royalpay.payment.manage.mappers.payment.TransactionMapper;
import au.com.royalpay.payment.manage.mappers.system.CalendarMapper;
import au.com.royalpay.payment.manage.mappers.system.ClientAccountMapper; import au.com.royalpay.payment.manage.mappers.system.ClientAccountMapper;
import au.com.royalpay.payment.manage.settlement.core.ManualSettleSupport; import au.com.royalpay.payment.manage.settlement.core.ManualSettleSupport;
import au.com.royalpay.payment.tools.exceptions.BadRequestException; import au.com.royalpay.payment.tools.exceptions.BadRequestException;
@ -18,6 +19,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -37,6 +39,8 @@ public class ManualSettleSupportImpl implements ManualSettleSupport {
private ClearingLogMapper clearingLogMapper; private ClearingLogMapper clearingLogMapper;
@Resource @Resource
private ClientAccountMapper clientAccountMapper; private ClientAccountMapper clientAccountMapper;
@Resource
private CalendarMapper calendarMapper;
@Override @Override
public JSONObject requestManualSettle(Date settleTo, String accountId) { public JSONObject requestManualSettle(Date settleTo, String accountId) {
@ -69,6 +73,9 @@ public class ManualSettleSupportImpl implements ManualSettleSupport {
if (!client.getBooleanValue("manual_settle")) { if (!client.getBooleanValue("manual_settle")) {
throw new ForbiddenException("Manual Settlement Not Enabled"); throw new ForbiddenException("Manual Settlement Not Enabled");
} }
if (client.getBooleanValue("skip_clearing")){
throw new ForbiddenException("Manual Settlement Not Enabled");
}
JSONObject todayTask = taskManualSettleMapper.findTodayTask(clientId); JSONObject todayTask = taskManualSettleMapper.findTodayTask(clientId);
if (todayTask != null) { if (todayTask != null) {
todayTask.put("settle_to", DateFormatUtils.format(todayTask.getDate("settle_to"), "yyyy-MM-dd")); todayTask.put("settle_to", DateFormatUtils.format(todayTask.getDate("settle_to"), "yyyy-MM-dd"));
@ -79,7 +86,8 @@ public class ManualSettleSupportImpl implements ManualSettleSupport {
//今天未清算则锁定 //今天未清算则锁定
todayTask.put("locked", settleLogs.isEmpty()); todayTask.put("locked", settleLogs.isEmpty());
if (includingUnsettleData) { if (includingUnsettleData) {
List<JSONObject> unsettleReports = transactionMapper.listClientUnsettleDataByDate(clientId); Date end = findSettleTo(clientId);
List<JSONObject> unsettleReports = transactionMapper.listClientUnsettleDataByDate(clientId, end);
unsettleReports.parallelStream().forEach(report -> { unsettleReports.parallelStream().forEach(report -> {
report.put("clearing_amount", CurrencyAmountUtils.scalePlatformCurrency(report.getBigDecimal("clearing_amount"))); report.put("clearing_amount", CurrencyAmountUtils.scalePlatformCurrency(report.getBigDecimal("clearing_amount")));
BigDecimal settleAmount = report.getBigDecimal("settle_amount"); BigDecimal settleAmount = report.getBigDecimal("settle_amount");
@ -96,4 +104,18 @@ public class ManualSettleSupportImpl implements ManualSettleSupport {
} }
return todayTask; return todayTask;
} }
private Date findSettleTo(int clientId) {
Date today = DateUtils.truncate(new Date(), Calendar.DATE);
JSONObject rateConfig = merchantInfoProvider.clientCurrentRate(clientId, today, "Wechat");
int cleanDays = rateConfig.getIntValue("clean_days");
List<Date> settleDateRange = calendarMapper.findClearingDateRange(today, cleanDays - 1);
Date end;
if (settleDateRange.size() < 2) {
end = DateUtils.addDays(today, -cleanDays);
} else {
end = DateUtils.addDays(settleDateRange.get(0), -1);
}
return end;
}
} }

@ -750,7 +750,7 @@
sum(if(transaction_type = 'Credit', clearing_amount, -clearing_amount)) clearing_amount, sum(if(transaction_type = 'Credit', clearing_amount, -clearing_amount)) clearing_amount,
sum(if(transaction_type = 'Credit', settle_amount, -settle_amount)) settle_amount sum(if(transaction_type = 'Credit', settle_amount, -settle_amount)) settle_amount
FROM pmt_transactions t FROM pmt_transactions t
WHERE t.client_id = #{client_id} AND t.clearing_status = 0 WHERE t.client_id = #{client_id} AND t.clearing_status = 0 AND date(t.transaction_time)&lt;=date(#{max_settle_to})
GROUP BY trans_date GROUP BY trans_date
ORDER BY trans_date DESC ORDER BY trans_date DESC
</select> </select>

Loading…
Cancel
Save