diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/payment/TransactionMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/payment/TransactionMapper.java index f6b91f73c..2c5b2a05e 100644 --- a/src/main/java/au/com/royalpay/payment/manage/mappers/payment/TransactionMapper.java +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/payment/TransactionMapper.java @@ -96,7 +96,7 @@ public interface TransactionMapper { List listTransactionsForReferrerCommission(@Param("year") int year, @Param("month") int month); - List listTransactionsForAgentCommission(@Param("year") int year, @Param("month") int month,@Param("parent_org_id") int parent_org_id); + List listTransactionsForAgentCommission(@Param("year") int year, @Param("month") int month, @Param("parent_org_id") int parent_org_id); BigDecimal checkBalance(@Param("end") Date endDate); @@ -128,6 +128,6 @@ public interface TransactionMapper { List getClientRank(@Param("begin") Date begin, @Param("end") Date end); - List listClientUnsettleDataByDate(@Param("client_id") int clientId); + List listClientUnsettleDataByDate(@Param("client_id") int clientId, @Param("max_settle_to") Date maxSettleTo); } diff --git a/src/main/java/au/com/royalpay/payment/manage/settlement/core/impls/ManualSettleSupportImpl.java b/src/main/java/au/com/royalpay/payment/manage/settlement/core/impls/ManualSettleSupportImpl.java index 3d34494e0..9f89c83db 100644 --- a/src/main/java/au/com/royalpay/payment/manage/settlement/core/impls/ManualSettleSupportImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/settlement/core/impls/ManualSettleSupportImpl.java @@ -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.payment.TaskManualSettleMapper; 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.settlement.core.ManualSettleSupport; import au.com.royalpay.payment.tools.exceptions.BadRequestException; @@ -18,6 +19,7 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.math.BigDecimal; +import java.util.Calendar; import java.util.Date; import java.util.List; @@ -37,6 +39,8 @@ public class ManualSettleSupportImpl implements ManualSettleSupport { private ClearingLogMapper clearingLogMapper; @Resource private ClientAccountMapper clientAccountMapper; + @Resource + private CalendarMapper calendarMapper; @Override public JSONObject requestManualSettle(Date settleTo, String accountId) { @@ -49,6 +53,9 @@ public class ManualSettleSupportImpl implements ManualSettleSupport { throw new BadRequestException("Cannot settle today's transactions"); } JSONObject currentTask = findCurrentSettle(clientId, false); + if (currentTask.getBooleanValue("locked")) { + throw new BadRequestException("You cannot do this at the moment"); + } String taskId = currentTask.getString("task_id"); currentTask.put("request_time", new Date()); currentTask.put("client_id", clientId); @@ -69,6 +76,9 @@ public class ManualSettleSupportImpl implements ManualSettleSupport { if (!client.getBooleanValue("manual_settle")) { throw new ForbiddenException("Manual Settlement Not Enabled"); } + if (client.getBooleanValue("skip_clearing")) { + throw new ForbiddenException("Manual Settlement Not Enabled"); + } JSONObject todayTask = taskManualSettleMapper.findTodayTask(clientId); if (todayTask != null) { todayTask.put("settle_to", DateFormatUtils.format(todayTask.getDate("settle_to"), "yyyy-MM-dd")); @@ -76,10 +86,12 @@ public class ManualSettleSupportImpl implements ManualSettleSupport { todayTask = new JSONObject(); } List settleLogs = clearingLogMapper.findByDate(new Date()); + List unsettleRequests = taskManualSettleMapper.listActiveTasks(clientId); //今天未清算则锁定 - todayTask.put("locked", settleLogs.isEmpty()); + todayTask.put("locked", settleLogs.isEmpty() || !unsettleRequests.isEmpty()); if (includingUnsettleData) { - List unsettleReports = transactionMapper.listClientUnsettleDataByDate(clientId); + Date end = findSettleTo(clientId); + List unsettleReports = transactionMapper.listClientUnsettleDataByDate(clientId, end); unsettleReports.parallelStream().forEach(report -> { report.put("clearing_amount", CurrencyAmountUtils.scalePlatformCurrency(report.getBigDecimal("clearing_amount"))); BigDecimal settleAmount = report.getBigDecimal("settle_amount"); @@ -96,4 +108,18 @@ public class ManualSettleSupportImpl implements ManualSettleSupport { } 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 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; + } } diff --git a/src/main/resources/au/com/royalpay/payment/manage/mappers/payment/TransactionMapper.xml b/src/main/resources/au/com/royalpay/payment/manage/mappers/payment/TransactionMapper.xml index 0ee0981d6..d2215f2a0 100644 --- a/src/main/resources/au/com/royalpay/payment/manage/mappers/payment/TransactionMapper.xml +++ b/src/main/resources/au/com/royalpay/payment/manage/mappers/payment/TransactionMapper.xml @@ -750,7 +750,7 @@ sum(if(transaction_type = 'Credit', clearing_amount, -clearing_amount)) clearing_amount, sum(if(transaction_type = 'Credit', settle_amount, -settle_amount)) settle_amount 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)<=date(#{max_settle_to}) GROUP BY trans_date ORDER BY trans_date DESC diff --git a/src/main/resources/i18n/addon_en.properties b/src/main/resources/i18n/addon_en.properties index 5fe45b118..7e490e549 100644 --- a/src/main/resources/i18n/addon_en.properties +++ b/src/main/resources/i18n/addon_en.properties @@ -1 +1 @@ -manual_settle.notice=Settlement will be made on second work day after submitted this application. Your balance will not update during this time. \ No newline at end of file +manual_settle.notice=Settlement will be executed on second work day after submitted this application. Your balance will not update during this time. \ No newline at end of file diff --git a/src/main/resources/templates/activity/mondelay/mondelay.html b/src/main/resources/templates/activity/mondelay/mondelay.html index e21edce0b..cdb725043 100644 --- a/src/main/resources/templates/activity/mondelay/mondelay.html +++ b/src/main/resources/templates/activity/mondelay/mondelay.html @@ -131,7 +131,7 @@ } else if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) { window.webkit.messageHandlers.appCmd.postMessage({type:'cmd_join_mondelay'}); } else if (/(Android)/i.test(navigator.userAgent)) { - android.appCmd('{\"type\":\"cmd_join_mondelay\"}'); + android.appCmd('{\"type\":\"cmd_join_mondelay\",\"cancel_waring\":\"'+cancel_waring+'\"}'); } else { } @@ -145,8 +145,7 @@ } else if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) { window.webkit.messageHandlers.appCmd.postMessage({type:'cmd_cancel_mondelay',cancel_waring:cancel_waring}); } else if (/(Android)/i.test(navigator.userAgent)) { - android.appCmd('{\"type\":\"cmd_cancel_mondelay\"}'); - } else { + android.appCmd('{\"type\":\"cmd_cancel_mondelay\",\"cancel_waring\":\"'+cancel_waring+'\"}'); } else { } diff --git a/src/main/ui/static/payment/partner/templates/client_bankaccounts.html b/src/main/ui/static/payment/partner/templates/client_bankaccounts.html index 2f0bac5c0..516953a6d 100644 --- a/src/main/ui/static/payment/partner/templates/client_bankaccounts.html +++ b/src/main/ui/static/payment/partner/templates/client_bankaccounts.html @@ -4,6 +4,11 @@
+

+ If you open it ,system will not execute settlement automatically. + You can withdraw deposit when you need.Settlement amount will be send to your bank account in the next day
+ 如果打开手动提现开关,则系统不自动进行清算。您可以根据您的需要自行提现,提现金额会在T+1到账
+