master
wangning 7 years ago
commit 24b76d3fd5

@ -6,6 +6,7 @@ import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.github.miemiedev.mybatis.paginator.domain.PageList;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
/**
@ -32,4 +33,6 @@ public interface CashbackService {
JSONObject analysisCashback(JSONObject params);
void drawDeposits(BigDecimal drawAmount, int clientId, JSONObject operator);
void saveSurchargeDiscountCashback(int clientId, String clientMoniker, String transactionOrderId, BigDecimal cashbackAmount, Date date, String remark);
}

@ -1,11 +1,14 @@
package au.com.royalpay.payment.manage.cashback.core.impl;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import au.com.royalpay.payment.core.PmtCashbackService;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSONObject;
@ -111,7 +114,25 @@ public class CashbackServiceImp implements CashbackService {
@Override
public void drawDeposits(BigDecimal drawAmount, int clientId, JSONObject operator) {
pmtCashbackService.drawDeposits(drawAmount,clientId,operator);
pmtCashbackService.drawDeposits(drawAmount, clientId, operator);
}
@Override
public void saveSurchargeDiscountCashback(int clientId, String clientMoniker, String transactionOrderId, BigDecimal cashbackAmount, Date date, String remark) {
if (!cashbackRecordsMapper.findBySurchargeDiscountLog(clientId, date).isEmpty()) {
return;
}
String cashback_id = 'R' + clientMoniker + "-" + DateFormatUtils.format(date, "yyyyMMddHHmmssSSS") + "-" + RandomStringUtils.random(3, true, false).toUpperCase();
//营销账户
JSONObject cashback = new JSONObject();
cashback.put("cashback_id", cashback_id);
cashback.put("client_id", clientId);
cashback.put("cashback_amount", cashbackAmount);
cashback.put("order_id", transactionOrderId);
cashback.put("cashback_type", 2);
cashback.put("remark", remark);
cashback.put("create_time", date);
cashbackRecordsMapper.save(cashback);
}
}

@ -3,7 +3,9 @@ package au.com.royalpay.payment.manage.management.clearing.core;
import au.com.royalpay.payment.manage.management.clearing.beans.SettleDelayConfig;
import com.alibaba.fastjson.JSONObject;
import com.github.miemiedev.mybatis.paginator.domain.PageList;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
/**
@ -20,4 +22,6 @@ public interface SettleDelayConfigurer {
PageList<JSONObject> getClientRank(JSONObject params);
@Transactional
void addCashback(Date date);
}

@ -1,39 +1,41 @@
package au.com.royalpay.payment.manage.management.clearing.core.impl;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSONObject;
import com.github.miemiedev.mybatis.paginator.domain.Order;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.github.miemiedev.mybatis.paginator.domain.PageList;
import au.com.royalpay.payment.core.exceptions.InvalidShortIdException;
import au.com.royalpay.payment.manage.appclient.core.RetailAppService;
import au.com.royalpay.payment.manage.cashback.core.CashbackService;
import au.com.royalpay.payment.manage.management.clearing.beans.SettleDelayConfig;
import au.com.royalpay.payment.manage.management.clearing.core.SettleDelayConfigurer;
import au.com.royalpay.payment.manage.mappers.log.ClearingDetailMapper;
import au.com.royalpay.payment.manage.mappers.log.ClearingLogMapper;
import au.com.royalpay.payment.manage.mappers.payment.TransactionMapper;
import au.com.royalpay.payment.manage.mappers.system.ClientSettleDelayConfMapper;
import au.com.royalpay.payment.manage.merchants.core.ClientManager;
import au.com.royalpay.payment.tools.CommonConsts;
import au.com.royalpay.payment.tools.env.PlatformEnvironment;
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
import au.com.royalpay.payment.tools.lock.Locker;
import au.com.royalpay.payment.tools.utils.CurrencyAmountUtils;
import au.com.royalpay.payment.tools.utils.PageListUtils;
import com.alibaba.fastjson.JSONObject;
import com.github.miemiedev.mybatis.paginator.domain.Order;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.github.miemiedev.mybatis.paginator.domain.PageList;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.joda.time.DateTime;
import org.joda.time.DateTimeConstants;
import org.joda.time.LocalDate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* Create by yixian at 2017-09-08 15:06
@ -50,6 +52,12 @@ public class SettleDelayConfigurerImpl implements SettleDelayConfigurer {
private TransactionMapper transactionMapper;
@Resource
private ClearingLogMapper clearingLogMapper;
@Resource
private ClearingDetailMapper clearingDetailMapper;
@Resource
private Locker locker;
@Resource
private RetailAppService retailAppService;
private Logger logger = LoggerFactory.getLogger(getClass());
@Override
@ -147,9 +155,9 @@ public class SettleDelayConfigurerImpl implements SettleDelayConfigurer {
DateTime dt = new DateTime(jsonObject.getDate("create_time"));
int weekOfYear = dt.getWeekOfWeekyear();
JSONObject cashBackMapElement = cashBackMap.get(weekOfYear);
if(cashBackMapElement!=null){
cashBackMapElement.put("cashback_amount",cashBackMapElement.getBigDecimal("cashback_amount").add(jsonObject.getBigDecimal("cashback_amount")));
}else {
if (cashBackMapElement != null) {
cashBackMapElement.put("cashback_amount", cashBackMapElement.getBigDecimal("cashback_amount").add(jsonObject.getBigDecimal("cashback_amount")));
} else {
cashBackMap.put(weekOfYear, jsonObject);
}
}
@ -167,11 +175,11 @@ public class SettleDelayConfigurerImpl implements SettleDelayConfigurer {
if (resultEntry.getBigDecimal("settle_amount") == null) {
continue;
}
resultEntry.put("weekend",resultEntry.getIntValue("weekend")+2);
resultEntry.put("weekend", resultEntry.getIntValue("weekend") + 2);
resultEntry.put("settle_amount", resultEntry.getBigDecimal("settle_amount").add(sunday.getBigDecimal("settle_amount")));
resultEntry.put("transaction_amount", resultEntry.getBigDecimal("transaction_amount").add(sunday.getBigDecimal("transaction_amount")));
if (cashBackMap.containsKey(new DateTime(saturday).getWeekOfWeekyear()+1)) {
resultEntry.put("cashback", cashBackMap.get(new DateTime(saturday).getWeekOfWeekyear()+1).getBigDecimal("cashback_amount"));
if (cashBackMap.containsKey(new DateTime(saturday).getWeekOfWeekyear() + 1)) {
resultEntry.put("cashback", cashBackMap.get(new DateTime(saturday).getWeekOfWeekyear() + 1).getBigDecimal("cashback_amount"));
} else {
resultEntry.put("cashback", 0);
}
@ -190,4 +198,75 @@ public class SettleDelayConfigurerImpl implements SettleDelayConfigurer {
public PageList<JSONObject> getClientRank(JSONObject params) {
return cashbackService.getSettleDelayRank(params, new PageBounds(params.getIntValue("page"), params.getIntValue("limit")));
}
@Override
@Transactional
public void addCashback(Date date) {
String key = "settle_delay_cashback";
if (!locker.lock(key, 600_000)) {
return;
}
try {
date = DateUtils.truncate(date, Calendar.DATE);
LocalDate processDate = LocalDate.fromDateFields(date);
if (processDate.getDayOfWeek() != DateTimeConstants.TUESDAY) {
throw new BadRequestException("Not tuesday");
}
LocalDate sunday = processDate.minusDays(processDate.getDayOfWeek());
LocalDate saturday = sunday.minusDays(1);
List<JSONObject> clientAttends = clientSettleDelayConfMapper.listClients(new JSONObject(), new PageBounds());
for (JSONObject attend : clientAttends) {
Date monday = DateUtils.addDays(date, -1);
if (attend.getDate("from_date").after(monday) || attend.getDate("to_date").before(monday)) {
continue;
}
int clientId = attend.getIntValue("client_id");
JSONObject client = clientManager.getClientInfo(clientId);
if (client == null) {
continue;
}
String clientMoniker = client.getString("client_moniker");
JSONObject clearing = clearingDetailMapper.listReport(date, clientId);
if (clearing == null) {
continue;
}
int detailId = clearing.getIntValue("clear_detail_id");
List<JSONObject> settleTrans = transactionMapper.listSettlementTransactions(detailId);
Assert.notEmpty(settleTrans, "No Settle History");
String transactionOrderId = settleTrans.get(0).getString("order_id");
List<JSONObject> transactions = transactionMapper.listTransactionsOfClearingOrder(detailId, new PageBounds());
BigDecimal totalSurcharge = BigDecimal.ZERO;
for (JSONObject transaction : transactions) {
Date day = transaction.getDate("transaction_time");
LocalDate transactionDate = LocalDate.fromDateFields(day);
if (transactionDate.equals(sunday) || transactionDate.equals(saturday)) {
continue;
}
BigDecimal surcharge = transaction.getBigDecimal("clearing_amount").subtract(transaction.getBigDecimal("settle_amount"));
if ("Debit".equals(transaction.getString("transaction_type"))) {
surcharge = surcharge.multiply(BigDecimal.valueOf(-1));
}
totalSurcharge = totalSurcharge.add(surcharge);
}
BigDecimal cashbackAmount = CurrencyAmountUtils.scale(totalSurcharge.multiply(attend.getBigDecimal("surcharge_discount")).divide(CommonConsts.HUNDRED, 2, BigDecimal.ROUND_HALF_UP), PlatformEnvironment.getEnv().getForeignCurrency());
String remark = "Surcharge cashback for " + saturday.toString("dd/MMM/yyyy", Locale.ENGLISH) + " ~ " + sunday.toString("dd/MMM/yyyy", Locale.ENGLISH);
if (cashbackAmount.compareTo(BigDecimal.ZERO) > 0) {
cashbackService.saveSurchargeDiscountCashback(clientId, clientMoniker, transactionOrderId, cashbackAmount, date, remark);
try {
if (!PlatformEnvironment.getEnv().isDebug()) {
JSONObject order = new JSONObject();
order.put("order_id", transactionOrderId);
order.put("client_id", clientId);
retailAppService.sendCashbackMessage(cashbackAmount.toPlainString(), order);// app message
}
} catch (Exception e) {
logger.error("发送App消息失败", e);
}
}
}
} finally {
locker.unlock(key);
}
}
}

@ -0,0 +1,26 @@
package au.com.royalpay.payment.manage.management.clearing.handlers;
import au.com.royalpay.payment.core.events.SettleNotifySendingEvent;
import au.com.royalpay.payment.manage.management.clearing.core.SettleDelayConfigurer;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Calendar;
import java.util.Date;
/**
* Create by yixian at 2017-12-25 13:48
*/
@Service
public class SendWeekendDelayCashbackSaver implements ApplicationListener<SettleNotifySendingEvent> {
@Resource
private SettleDelayConfigurer settleDelayConfigurer;
@Override
public void onApplicationEvent(SettleNotifySendingEvent event) {
Date eventTime = new Date(event.getEventTime());
settleDelayConfigurer.addCashback(DateUtils.truncate(eventTime, Calendar.DATE));
}
}

@ -96,6 +96,3 @@ app.foreign-currency=AUD
app.ofei.md5-key=Khjx6wejblaJzmG0JBWFlPFKAUxhFIXQ
app.ofei.pwd=aomi@8888
app.ofei.sp-code=A1407200
android.message.secret=2b96d9bc6169c9554218aab1
android.message.appkey=3f33a10d0a7d4ac94d8f2431

@ -13,8 +13,11 @@ define(['angular', 'angularSanitize', 'angularAnimate', 'angularMessages', 'uiRo
$httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache';
$httpProvider.defaults.headers.get['Pragma'] = 'no-cache';
}]);
app.controller('managerIndexCtrl', ['$scope', '$rootScope', '$http', '$log', '$timeout', '$interval', '$uibModal','$filter', 'myLoginLogView', 'commonDialog',
function ($scope, $rootScope, $http, $log, $timeout, $interval, $uibModal,$filter, myLoginLogView, commonDialog) {
app.controller('managerIndexCtrl', ['$scope', '$rootScope', '$http', '$log', '$timeout', '$interval', '$uibModal', '$filter', 'myLoginLogView', 'commonDialog',
function ($scope, $rootScope, $http, $log, $timeout, $interval, $uibModal, $filter, myLoginLogView, commonDialog) {
$http.get('/sysconfig/base').then(function (resp) {
$rootScope.sysParams = resp.data;
});
var stompClient = null;
$scope.loadCurrentUser = function () {
$http.get('/global/userstatus/current_manager').then(function (resp) {
@ -31,9 +34,9 @@ define(['angular', 'angularSanitize', 'angularAnimate', 'angularMessages', 'uiRo
// $scope.loadPartnerApplyNotice();
// }
if ($rootScope.currentUser.wx_openid == null) {
if($filter('withRole')('100')){
if ($filter('withRole')('100')) {
$scope.managerBindWechat('static');
}else {
} else {
$scope.managerBindWechat(true);
}
@ -103,7 +106,7 @@ define(['angular', 'angularSanitize', 'angularAnimate', 'angularMessages', 'uiRo
$scope.hideSideBar = !$scope.hideSideBar;
};
$scope.showQrCode = function (data,backdrop) {
$scope.showQrCode = function (data, backdrop) {
return $uibModal.open({
template: '<div style="width: 100%;padding: 10px;">请使用微信扫描<br><div style="width:100%" qrcode="url"></div><p class="text-center"><img class="img-circle img-bordered" style="width: 45px" ng-show="{{wx_headimg}}" ng-src="{{wx_headimg}}">{{wx_nickname}}</p></div>',
controller: ['$scope', 'data', function ($scope, data) {
@ -117,8 +120,8 @@ define(['angular', 'angularSanitize', 'angularAnimate', 'angularMessages', 'uiRo
return data;
}
},
keyboard:false,
backdrop:backdrop
keyboard: false,
backdrop: backdrop
})
};
@ -166,10 +169,10 @@ define(['angular', 'angularSanitize', 'angularAnimate', 'angularMessages', 'uiRo
$scope.managerBindWechat = function (backdrop) {
$http.post('/system/manager_wechat_binds').then(function (resp) {
$scope.checkCode = resp.data.bind_id;
if(resp.data.wx_nickname){
if (resp.data.wx_nickname) {
backdrop = true;
}
$scope.checkModal = $scope.showQrCode(resp.data,backdrop);
$scope.checkModal = $scope.showQrCode(resp.data, backdrop);
// $scope.showQrCode(resp.data.url);
})
}

@ -0,0 +1,60 @@
package au.com.royalpay.payment.manage.management.clearing.core;
import au.com.royalpay.payment.manage.appclient.core.RetailAppService;
import au.com.royalpay.payment.manage.cashback.core.CashbackService;
import au.com.royalpay.payment.manage.mappers.payment.TransactionMapper;
import au.com.royalpay.payment.manage.mappers.system.ClientSettleDelayConfMapper;
import au.com.royalpay.payment.manage.merchants.core.ClientManager;
import au.com.royalpay.payment.tools.CommonConsts;
import au.com.royalpay.payment.tools.env.PlatformEnvironment;
import au.com.royalpay.payment.tools.utils.CurrencyAmountUtils;
import com.alibaba.fastjson.JSONObject;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.joda.time.DateTime;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.test.annotation.Commit;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.ParseException;
import java.util.*;
/**
* Create by yixian at 2018-01-15 16:03
*/
@ActiveProfiles("proxy")
@TestPropertySource(properties = "app.debug=false")
@Commit
public class SettleDelayCashbackForNewYearDay {
@Resource
private ClientManager clientManager;
@Resource
private TransactionMapper transactionMapper;
@Resource
private CashbackService cashbackService;
@Resource
private RetailAppService retailAppService;
@Resource
private ClientSettleDelayConfMapper clientSettleDelayConfMapper;
private Logger logger = LoggerFactory.getLogger(getClass());
@Test
@Transactional
public void addCashback() throws ParseException {
}
private void processCashback(Date date, List<JSONObject> cashbackNotices, String clientMoniker, int clientId, List<JSONObject> transactions) {
}
}

@ -0,0 +1,33 @@
package au.com.royalpay.payment.manage.management.clearing.core;
import org.joda.time.DateTime;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.Commit;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
import static org.junit.Assert.*;
/**
* Create by yixian at 2018-01-15 15:59
*/
@SpringBootTest
@RunWith(SpringRunner.class)
@ActiveProfiles("proxy")
@TestPropertySource(properties = "app.debug=false")
@Commit
public class SettleDelayConfigurerTest {
@Resource
private SettleDelayConfigurer settleDelayConfigurer;
@Test
public void addCashback() {
settleDelayConfigurer.addCashback(DateTime.parse("2018-01-09").toDate());
}
}
Loading…
Cancel
Save