|
|
@@ -24,11 +24,11 @@ public class OrderCloseEventHandler implements AwoaraEventHandler<OrderInfoObjec
|
|
|
private final WashOrderService washOrderService;
|
|
|
private final WalletDetailService walletDetailService;
|
|
|
private final AccountService accountService;
|
|
|
- private final InvestorAccountService investorAccountService;
|
|
|
+ private final StationAccountService investorAccountService;
|
|
|
private final SplitRecordService splitRecordService;
|
|
|
|
|
|
public OrderCloseEventHandler(WashOrderService washOrderService, WalletDetailService walletDetailService,
|
|
|
- AccountService accountService, InvestorAccountService investorAccountService, SplitRecordService splitRecordService) {
|
|
|
+ AccountService accountService, StationAccountService investorAccountService, SplitRecordService splitRecordService) {
|
|
|
this.washOrderService = washOrderService;
|
|
|
this.walletDetailService = walletDetailService;
|
|
|
this.accountService = accountService;
|
|
|
@@ -83,18 +83,17 @@ public class OrderCloseEventHandler implements AwoaraEventHandler<OrderInfoObjec
|
|
|
washOrderService.updateById(washOrder);
|
|
|
|
|
|
|
|
|
- // todo t_account减(上面已完成),t_investor_account冻结户减,t_investor_account商户加,t_split_record记录
|
|
|
+ // todo t_account减(上面已完成),t_station_account冻结户减,t_station_account商户加,t_split_record记录
|
|
|
// todo 需要判断是否跨网点,分开处理;跨网点结算比例是消费站点分订单额的30%,充值站点分70%
|
|
|
if (washOrder.getIsCross()) {
|
|
|
// 跨网点订单结算比例是消费站点分订单额的30%,充值站点分70%
|
|
|
- doCrossSplit(washOrder, KymCache.INSTANCE.getInvestorAdminUserIdByUserId(washOrder.getUserId()));
|
|
|
+ doCrossSplit(washOrder, KymCache.INSTANCE.getUserStationId(washOrder.getUserId()));
|
|
|
} else {
|
|
|
// 不跨网点订单结算比例是消费站点分订单额的100%,消费金额*商家消费分润比例30%-消费金额*平台分润10%=消费金额*(商家消费分润比例-平台分润)
|
|
|
doLocalSplit(washOrder);
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
var walletDetail = new WalletDetail();
|
|
|
walletDetail.setUserId(washOrder.getUserId());
|
|
|
walletDetail.setType(WalletDetail.TYPE_消费);
|
|
|
@@ -120,24 +119,24 @@ public class OrderCloseEventHandler implements AwoaraEventHandler<OrderInfoObjec
|
|
|
* @param washOrder
|
|
|
*/
|
|
|
private void doLocalSplit(WashOrder washOrder) {
|
|
|
- var investorAccount = investorAccountService.getInvestorAccount(washOrder.getStationId());
|
|
|
+ var stationAccount = investorAccountService.getStationAccount(washOrder.getStationId());
|
|
|
var amount = (int) (washOrder.getAmount() * (0.3 - 0.1));
|
|
|
investorAccountService.lambdaUpdate()
|
|
|
.setSql("frozen_amount = frozen_amount - {0}", amount)
|
|
|
- .eq(InvestorAccount::getId, investorAccount.getId())
|
|
|
+ .eq(StationAccount::getId, stationAccount.getId())
|
|
|
.update();
|
|
|
// 冻结户解冻
|
|
|
var splitRecord1 = new SplitRecord()
|
|
|
- .setFromAccount(investorAccount.getAdminUserId())
|
|
|
- .setToAccount(investorAccount.getAdminUserId())
|
|
|
+ .setFromStationId(stationAccount.getStationId())
|
|
|
+ .setToStationId(stationAccount.getStationId())
|
|
|
.setTradeNo(washOrder.getOrderId())
|
|
|
.setAmount(amount)
|
|
|
.setType(SplitRecord.TYPE_UNFREEZE);
|
|
|
|
|
|
// 基本户入账
|
|
|
var splitRecord2 = new SplitRecord()
|
|
|
- .setFromAccount(investorAccount.getAdminUserId())
|
|
|
- .setToAccount(investorAccount.getAdminUserId())
|
|
|
+ .setFromStationId(stationAccount.getStationId())
|
|
|
+ .setToStationId(stationAccount.getStationId())
|
|
|
.setTradeNo(washOrder.getOrderId())
|
|
|
.setAmount(amount)
|
|
|
.setType(SplitRecord.TYPE_CONSUME);
|
|
|
@@ -151,10 +150,10 @@ public class OrderCloseEventHandler implements AwoaraEventHandler<OrderInfoObjec
|
|
|
* 执行跨店分账操作
|
|
|
*
|
|
|
* @param washOrder
|
|
|
- * @param InvestorAdminUserId 用户归属的站点的商户投资者adminUserId
|
|
|
+ * @param stationId 用户归属的站点Id
|
|
|
*/
|
|
|
- private void doCrossSplit(WashOrder washOrder, Long InvestorAdminUserId) {
|
|
|
- var investorAccount = investorAccountService.getInvestorAccount(washOrder.getStationId());
|
|
|
+ private void doCrossSplit(WashOrder washOrder, String stationId) {
|
|
|
+ var investorAccount = investorAccountService.getStationAccount(washOrder.getStationId());
|
|
|
var splitAmount = (int) (washOrder.getAmount() * (0.3 - 0.1));
|
|
|
var localAmount = (int) (splitAmount * 0.7);
|
|
|
var crossAmount = splitAmount - localAmount;
|
|
|
@@ -162,7 +161,7 @@ public class OrderCloseEventHandler implements AwoaraEventHandler<OrderInfoObjec
|
|
|
// 当前消费站点收入(跨店消费,原充值站点要分订单的70%)
|
|
|
investorAccountService.lambdaUpdate()
|
|
|
.setSql("balance = balance + {0}", crossAmount)
|
|
|
- .eq(InvestorAccount::getId, investorAccount.getId())
|
|
|
+ .eq(StationAccount::getId, investorAccount.getId())
|
|
|
.update();
|
|
|
|
|
|
// // 充值站点收入
|
|
|
@@ -181,28 +180,28 @@ public class OrderCloseEventHandler implements AwoaraEventHandler<OrderInfoObjec
|
|
|
// 充值站点收入
|
|
|
investorAccountService.lambdaUpdate()
|
|
|
.setSql("balance = balance + {0}, frozen_amount = frozen_amount - {1}", localAmount - crossAmount, splitAmount)
|
|
|
- .eq(InvestorAccount::getId, investorAccount.getId())
|
|
|
+ .eq(StationAccount::getId, investorAccount.getId())
|
|
|
.update();
|
|
|
|
|
|
|
|
|
// t_split_record 1.消费站点收入 2.归属站点收入 3.充值站点支出
|
|
|
var splitRecord1 = new SplitRecord()
|
|
|
- .setFromAccount(InvestorAdminUserId)
|
|
|
- .setToAccount(investorAccount.getAdminUserId())
|
|
|
+ .setFromStationId(stationId)
|
|
|
+ .setToStationId(investorAccount.getStationId())
|
|
|
.setTradeNo(washOrder.getOrderId())
|
|
|
.setAmount(crossAmount)
|
|
|
.setType(SplitRecord.TYPE_CONSUME);
|
|
|
|
|
|
var splitRecord2 = new SplitRecord()
|
|
|
- .setFromAccount(InvestorAdminUserId)
|
|
|
- .setToAccount(InvestorAdminUserId)
|
|
|
+ .setFromStationId(stationId)
|
|
|
+ .setToStationId(stationId)
|
|
|
.setTradeNo(washOrder.getOrderId())
|
|
|
.setAmount(localAmount)
|
|
|
.setType(SplitRecord.TYPE_CONSUME);
|
|
|
|
|
|
var splitRecord3 = new SplitRecord()
|
|
|
- .setFromAccount(investorAccount.getAdminUserId())
|
|
|
- .setToAccount(investorAccount.getAdminUserId())
|
|
|
+ .setFromStationId(investorAccount.getStationId())
|
|
|
+ .setToStationId(investorAccount.getStationId())
|
|
|
.setTradeNo(washOrder.getOrderId())
|
|
|
.setAmount(splitAmount)
|
|
|
.setType(SplitRecord.TYPE_UNFREEZE);
|