|
|
@@ -0,0 +1,87 @@
|
|
|
+package com.ruoyi.app.order;
|
|
|
+
|
|
|
+import com.ruoyi.app.service.WalletService;
|
|
|
+import com.ruoyi.common.core.domain.entity.SysDictData;
|
|
|
+import com.ruoyi.common.utils.DictUtils;
|
|
|
+import com.ruoyi.system.domain.*;
|
|
|
+import com.ruoyi.system.service.*;
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
+import org.junit.jupiter.params.ParameterizedTest;
|
|
|
+import org.junit.jupiter.params.provider.CsvSource;
|
|
|
+import org.mockito.ArgumentCaptor;
|
|
|
+import org.springframework.test.util.ReflectionTestUtils;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.List;
|
|
|
+import static org.junit.jupiter.api.Assertions.*;
|
|
|
+import static org.mockito.ArgumentMatchers.*;
|
|
|
+import static org.mockito.Mockito.*;
|
|
|
+
|
|
|
+/** 已配置非零旧抽成/税率也必须全额入账,并保留摊位钱包和重复结算保护。 */
|
|
|
+class OrderBillingNoDeductionTest {
|
|
|
+ private final IUserBillingService bills = mock(IUserBillingService.class);
|
|
|
+ private final IPosStoreService stores = mock(IPosStoreService.class);
|
|
|
+ private final IInfoUserService users = mock(IInfoUserService.class);
|
|
|
+ private final WalletService wallet = mock(WalletService.class);
|
|
|
+ private final OrderService service = new OrderService();
|
|
|
+
|
|
|
+ OrderBillingNoDeductionTest() {
|
|
|
+ ReflectionTestUtils.setField(service, "userBillingService", bills);
|
|
|
+ ReflectionTestUtils.setField(service, "posStoreService", stores);
|
|
|
+ ReflectionTestUtils.setField(service, "infoUserService", users);
|
|
|
+ ReflectionTestUtils.setField(service, "walletService", wallet);
|
|
|
+ }
|
|
|
+
|
|
|
+ private PosOrder order() {
|
|
|
+ PosOrder o = new PosOrder(); o.setDdId("NO-DEDUCTION"); o.setMdId(9L);
|
|
|
+ o.setShId(10L); o.setQsId(20L); o.setAmount(120); o.setFreight(30.0);
|
|
|
+ return o;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ParameterizedTest
|
|
|
+ @CsvSource({"false,false", "false,true", "true,false", "true,true"})
|
|
|
+ void merchantReceivesFullGoodsAmountForLegacyAndVersionTwo(boolean stall, boolean versionTwo) {
|
|
|
+ PosStore store = new PosStore(); store.setId(9); store.setIsStall(stall ? 1 : 0);
|
|
|
+ store.setNightMarketId(stall ? 10L : null);
|
|
|
+ when(stores.getById(9L)).thenReturn(store);
|
|
|
+ InfoUser merchant = new InfoUser(); merchant.setCommission(0.25);
|
|
|
+ when(users.getById(10L)).thenReturn(merchant);
|
|
|
+ PosOrder o = order();
|
|
|
+ o.setFood("[{\"price\":45,\"otherPrice\":5,\"number\":2}]");
|
|
|
+ if (versionTwo) {
|
|
|
+ o.setPromotionPricingVersion(2); o.setCustomerDeliveryFee(BigDecimal.valueOf(20));
|
|
|
+ o.setMerchantDeliverySubsidy(BigDecimal.TEN);
|
|
|
+ }
|
|
|
+ when(bills.count(any())).thenReturn(0L, 1L);
|
|
|
+ service.setSanghuBilling(o);
|
|
|
+ service.setSanghuBilling(o);
|
|
|
+ var capture = ArgumentCaptor.forClass(UserBilling.class);
|
|
|
+ if (stall) verify(wallet).addStallBalance(eq(9L), eq(BigDecimal.valueOf(100.0)), capture.capture());
|
|
|
+ else verify(wallet).addBalance(eq(10L), eq(BigDecimal.valueOf(100.0)), capture.capture());
|
|
|
+ assertEquals(100.0, capture.getValue().getAmount());
|
|
|
+ assertEquals(0.0, capture.getValue().getDivvy());
|
|
|
+ assertEquals(0.0, capture.getValue().getDivvyRate());
|
|
|
+ verifyNoMoreInteractions(wallet);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void riderReceivesAllFreightDespiteOldTaxAndCommissionAndKeepsCashCollection() {
|
|
|
+ InfoUser rider = new InfoUser(); rider.setCommission(0.25);
|
|
|
+ when(users.getById(20L)).thenReturn(rider);
|
|
|
+ SysDictData tax = new SysDictData(); tax.setDictValue("0.10");
|
|
|
+ try (var dict = mockStatic(DictUtils.class)) {
|
|
|
+ dict.when(() -> DictUtils.getDictCache("sys_qs_freight_bl")).thenReturn(List.of(tax));
|
|
|
+ PosOrder o = order(); o.setCollectPayment("1");
|
|
|
+ when(bills.count(any())).thenReturn(0L, 1L);
|
|
|
+ service.setQishouBilling(o);
|
|
|
+ service.setQishouBilling(o);
|
|
|
+ var capture = ArgumentCaptor.forClass(UserBilling.class);
|
|
|
+ verify(wallet).addBalance(eq(20L), eq(BigDecimal.valueOf(30.0)), capture.capture());
|
|
|
+ UserBilling bill = capture.getValue();
|
|
|
+ assertEquals(30.0, bill.getAmount());
|
|
|
+ assertEquals(0.0, bill.getDivvy()); assertEquals(0.0, bill.getDivvyRate());
|
|
|
+ assertEquals(0, BigDecimal.ZERO.compareTo(bill.getTax())); assertEquals("0", bill.getTaxRate());
|
|
|
+ assertEquals(120.0, bill.getBehalfAmount());
|
|
|
+ verifyNoMoreInteractions(wallet);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|