Explorar o código

店铺商品列表

licailing %!s(int64=5) %!d(string=hai) anos
pai
achega
263d9a81d1
Modificáronse 26 ficheiros con 409 adicións e 164 borrados
  1. BIN=BIN
      libs/TencentLocationSdk_v7.2.6_rdbae62b0_20200322_210334.jar
  2. 11 7
      pom.xml
  3. 2 2
      src/main/java/com/izouma/dingdong/domain/merchant/Goods.java
  4. 4 0
      src/main/java/com/izouma/dingdong/repo/backstage/DeliveryFeeRepo.java
  5. 5 1
      src/main/java/com/izouma/dingdong/repo/merchant/GoodsRepo.java
  6. 9 5
      src/main/java/com/izouma/dingdong/service/AppraisalService.java
  7. 4 4
      src/main/java/com/izouma/dingdong/service/ChatService.java
  8. 4 2
      src/main/java/com/izouma/dingdong/service/CouponService.java
  9. 5 4
      src/main/java/com/izouma/dingdong/service/OrderGoodsSpecService.java
  10. 23 19
      src/main/java/com/izouma/dingdong/service/OrderInfoService.java
  11. 28 16
      src/main/java/com/izouma/dingdong/service/OrderRefundApplyService.java
  12. 6 5
      src/main/java/com/izouma/dingdong/service/WithdrawApplyService.java
  13. 7 5
      src/main/java/com/izouma/dingdong/service/backstage/BlackListService.java
  14. 2 2
      src/main/java/com/izouma/dingdong/service/backstage/CategoryService.java
  15. 48 0
      src/main/java/com/izouma/dingdong/service/backstage/DeliveryFeeService.java
  16. 29 20
      src/main/java/com/izouma/dingdong/service/merchant/GoodsService.java
  17. 10 5
      src/main/java/com/izouma/dingdong/service/merchant/GoodsSpecificationService.java
  18. 8 4
      src/main/java/com/izouma/dingdong/service/merchant/MerchantClassificationService.java
  19. 27 16
      src/main/java/com/izouma/dingdong/service/merchant/MerchantService.java
  20. 37 27
      src/main/java/com/izouma/dingdong/service/merchant/MerchantSettingsService.java
  21. 4 2
      src/main/java/com/izouma/dingdong/service/merchant/SalesService.java
  22. 22 13
      src/main/java/com/izouma/dingdong/service/user/ShoppingCartService.java
  23. 1 1
      src/main/java/com/izouma/dingdong/web/merchant/GoodsController.java
  24. 103 0
      src/test/java/com/izouma/dingdong/MapTest.java
  25. 4 4
      src/test/java/com/izouma/dingdong/contorller/OrderInfoControllerTest.java
  26. 6 0
      src/test/java/com/izouma/dingdong/service/GoodsServiceTest.java

BIN=BIN
libs/TencentLocationSdk_v7.2.6_rdbae62b0_20200322_210334.jar


+ 11 - 7
pom.xml

@@ -265,14 +265,18 @@
             <version>1.0.1</version>
         </dependency>
 
+        <!-- 腾讯定位 -->
+        <dependency>
+            <groupId>com.tencent.map.geolocation</groupId>
+            <artifactId>TencentLocationSdk-openplatform</artifactId>
+            <version>7.1.7</version>
+        </dependency>
+        <dependency>
+            <groupId>com.tencent.map.geolocation</groupId>
+            <artifactId>TencentLocationSdk-meituandispatch</artifactId>
+            <version>6.2.4</version>
+        </dependency>
         <!-- 腾讯地图 -->
-<!--        <dependency>
-            <groupId>club.mrxiao</groupId>
-            <artifactId>map-java-tools</artifactId>
-            <version>2.0.2.B</version>
-            <type>pom</type>
-        </dependency>-->
 
     </dependencies>
-
 </project>

+ 2 - 2
src/main/java/com/izouma/dingdong/domain/merchant/Goods.java

@@ -86,8 +86,8 @@ public class Goods extends BaseEntity implements Serializable {
     @Column(nullable = false)
     private Boolean enabled;
 
-    @ApiModelProperty(value = "通过", name = "isPass")
-    private Boolean isPass;
+//    @ApiModelProperty(value = "通过", name = "isPass")
+//    private Boolean isPass;
 
     @Enumerated(EnumType.STRING)
     @ApiModelProperty(value = "状态", name = "status")

+ 4 - 0
src/main/java/com/izouma/dingdong/repo/backstage/DeliveryFeeRepo.java

@@ -1,16 +1,20 @@
 package com.izouma.dingdong.repo.backstage;
 
 import com.izouma.dingdong.domain.backstage.DeliveryFee;
+import com.izouma.dingdong.enums.DeliveryType;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.data.jpa.repository.Modifying;
 import org.springframework.data.jpa.repository.Query;
 
 import javax.transaction.Transactional;
+import java.util.List;
 
 public interface DeliveryFeeRepo extends JpaRepository<DeliveryFee, Long>, JpaSpecificationExecutor<DeliveryFee> {
     @Query("update DeliveryFee t set t.enabled = false where t.id = ?1")
     @Modifying
     @Transactional
     void deleteById(Long id);
+
+    List<DeliveryFee> findAllByType(DeliveryType type);
 }

+ 5 - 1
src/main/java/com/izouma/dingdong/repo/merchant/GoodsRepo.java

@@ -1,6 +1,7 @@
 package com.izouma.dingdong.repo.merchant;
 
 import com.izouma.dingdong.domain.merchant.Goods;
+import com.izouma.dingdong.enums.ApplyStatus;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.data.jpa.repository.Modifying;
@@ -19,7 +20,10 @@ public interface GoodsRepo extends JpaRepository<Goods, Long>, JpaSpecificationE
     List<Goods> findAllByMerchantId(Long merchantId);
 
     //按商户筛选,并用过审核
-    List<Goods> findAllByMerchantIdAndIsPassTrue(Long merchantId);
+//    List<Goods> findAllByMerchantIdAndIsPassTrue(Long merchantId);
+
+    //按商户筛选,并用过审核
+    List<Goods> findAllByMerchantIdAndStatus(Long merchantId, ApplyStatus status);
 
 //    List<Goods> findAllByMerchantIdAndTotalSalesIsLessThanEqual(Long merchant,Integer num);
 

+ 9 - 5
src/main/java/com/izouma/dingdong/service/AppraisalService.java

@@ -32,10 +32,10 @@ import java.util.stream.Collectors;
 @AllArgsConstructor
 public class AppraisalService {
 
-    private AppraisalRepo appraisalRepo;
-    private OrderInfoRepo orderInfoRepo;
+    private AppraisalRepo      appraisalRepo;
+    private OrderInfoRepo      orderInfoRepo;
     private OrderGoodsSpecRepo orderGoodsSpecRepo;
-    private SalesService salesService;
+    private SalesService       salesService;
 
     /*
     客户评价
@@ -79,7 +79,8 @@ public class AppraisalService {
 //        List<Appraisal> appraisals = CollUtil.newArrayList();
         List<AppraisalMerDTO> appraisals = CollUtil.newArrayList();
         specs.forEach(s -> {
-            Appraisal appraisal = appraisalRepo.findByOrderInfoId(s.getOrderInfoId()).orElseThrow(new BusinessException("无订单"));
+            Appraisal appraisal = appraisalRepo.findByOrderInfoId(s.getOrderInfoId())
+                    .orElseThrow(new BusinessException("无订单"));
             if (ObjectUtil.isNotNull(appraisal)) {
                 appraisals.add(this.toDTO(appraisal));
 //                appraisals.add(appraisal);
@@ -96,7 +97,10 @@ public class AppraisalService {
      */
     public AppraisalMerDTO toDTO(Appraisal appraisal) {
         OrderInfo order = orderInfoRepo.findById(appraisal.getOrderInfoId()).orElseThrow(new BusinessException("无订单"));
-        List<Goods> collect = order.getOrderGoodsSpecs().stream().map(OrderGoodsSpec::getGoods).collect(Collectors.toList());
+        List<Goods> collect = order.getOrderGoodsSpecs()
+                .stream()
+                .map(OrderGoodsSpec::getGoods)
+                .collect(Collectors.toList());
         String goodsName = collect.stream().map(Goods::getName).collect(Collectors.joining(","));
         User user = order.getUser();
         return AppraisalMerDTO.builder()

+ 4 - 4
src/main/java/com/izouma/dingdong/service/ChatService.java

@@ -28,7 +28,7 @@ public class ChatService {
         sends.addAll(receives);
         sends.remove(userId);
 
-        if (CollUtil.isEmpty(sends)){
+        if (CollUtil.isEmpty(sends)) {
             return null;
         }
 
@@ -51,10 +51,10 @@ public class ChatService {
     /*
     超过一天自动删除
      */
-    public void delChat(Long userId){
-        List<Chat> chats = chatRepo.findAllBySendUserIdOrReceiveUserId(userId,userId);
+    public void delChat(Long userId) {
+        List<Chat> chats = chatRepo.findAllBySendUserIdOrReceiveUserId(userId, userId);
         chats.forEach(chat -> {
-            if (LocalDateTime.now().isAfter(chat.getSendTime().plusDays(1))){
+            if (LocalDateTime.now().isAfter(chat.getSendTime().plusDays(1))) {
                 chatRepo.delete(chat);
             }
         });

+ 4 - 2
src/main/java/com/izouma/dingdong/service/CouponService.java

@@ -15,14 +15,16 @@ import java.util.stream.Collectors;
 @AllArgsConstructor
 public class CouponService {
 
-    private CouponRepo couponRepo;
+    private CouponRepo      couponRepo;
     private MerchantService merchantService;
 
     public List<Coupon> my(Long userId, Boolean isAll) {
         Long merchantId = merchantService.findMerchantId(userId);
         List<Coupon> coupons = couponRepo.findAllByMerchantIdAndEnabledTrue(merchantId);
         if (isAll) {
-            return coupons.stream().filter(c -> !c.getStartDate().isBefore(LocalDate.now())).collect(Collectors.toList());
+            return coupons.stream()
+                    .filter(c -> !c.getStartDate().isBefore(LocalDate.now()))
+                    .collect(Collectors.toList());
         }
         return coupons.stream().filter(c -> !c.getEndDate().isBefore(LocalDate.now())).collect(Collectors.toList());
     }

+ 5 - 4
src/main/java/com/izouma/dingdong/service/OrderGoodsSpecService.java

@@ -23,9 +23,9 @@ import java.util.List;
 @AllArgsConstructor
 public class OrderGoodsSpecService {
 
-    private OrderGoodsSpecRepo orderGoodsSpecRepo;
+    private OrderGoodsSpecRepo     orderGoodsSpecRepo;
     private GoodsSpecificationRepo goodsSpecificationRepo;
-    private GoodsRepo goodsRepo;
+    private GoodsRepo              goodsRepo;
 
 
     public OrderGoodsSpec add(Long goodsId, String goodsSpecificationIds, Integer num) {
@@ -48,13 +48,14 @@ public class OrderGoodsSpecService {
             for (Long l : longs) {
                 GoodsSpecification spec = goodsSpecificationRepo.findById(l).orElseThrow(new BusinessException("无规格"));
 
-                if (!spec.getGoodsId().equals(goodsId)){
+                if (!spec.getGoodsId().equals(goodsId)) {
                     throw new BusinessException("不是此商品下规格");
                 }
                 if (ObjectUtil.isEmpty(spec.getParent())) {
                     throw new BusinessException("选择规格分类下的规格商品");
                 } else {
-                    GoodsSpecification parentSpec = goodsSpecificationRepo.findById(spec.getParent()).orElseThrow(new BusinessException("无规格分类"));
+                    GoodsSpecification parentSpec = goodsSpecificationRepo.findById(spec.getParent())
+                            .orElseThrow(new BusinessException("无规格分类"));
                     if (!parentSpec.getMultiple()) {
                         parents.add(spec.getParent());
                     }

+ 23 - 19
src/main/java/com/izouma/dingdong/service/OrderInfoService.java

@@ -43,31 +43,33 @@ import java.util.List;
 @AllArgsConstructor
 public class OrderInfoService {
 
-    private OrderInfoRepo orderInfoRepo;
-    private CouponRepo couponRepo;
-    private OrderGoodsSpecRepo orderGoodsSpecRepo;
-    private GoodsRepo goodsRepo;
-    private GoodsService goodsService;
-    private MerchantSettingsRepo merchantSettingsRepo;
-    private ShoppingCartRepo shoppingCartRepo;
-    private AddressRepo addressRepo;
-    private UserRepo userRepo;
-    private MerchantService merchantService;
-    private SalesService salesService;
-    private MerchantRepo merchantRepo;
-    private UserCouponRepo userCouponRepo;
+    private OrderInfoRepo           orderInfoRepo;
+    private CouponRepo              couponRepo;
+    private OrderGoodsSpecRepo      orderGoodsSpecRepo;
+    private GoodsRepo               goodsRepo;
+    private GoodsService            goodsService;
+    private MerchantSettingsRepo    merchantSettingsRepo;
+    private ShoppingCartRepo        shoppingCartRepo;
+    private AddressRepo             addressRepo;
+    private UserRepo                userRepo;
+    private MerchantService         merchantService;
+    private SalesService            salesService;
+    private MerchantRepo            merchantRepo;
+    private UserCouponRepo          userCouponRepo;
     private OrderRefundApplyService orderRefundApplyService;
-    private RiderRepo riderRepo;
+    private RiderRepo               riderRepo;
 
     /*
     用户下单
      */
     public OrderInfo userOrder(UserOrderDTO userOrderDTO) {
 
-        ShoppingCart cart = shoppingCartRepo.findById(userOrderDTO.getShoppingCartId()).orElseThrow(new BusinessException("不存在"));
+        ShoppingCart cart = shoppingCartRepo.findById(userOrderDTO.getShoppingCartId())
+                .orElseThrow(new BusinessException("不存在"));
 
         //商家
-        MerchantSettings merchantSettings = merchantSettingsRepo.findByMerchantId(cart.getMerchantId()).orElseThrow(new BusinessException("无商家"));
+        MerchantSettings merchantSettings = merchantSettingsRepo.findByMerchantId(cart.getMerchantId())
+                .orElseThrow(new BusinessException("无商家"));
 
         LocalTime startTime = merchantSettings.getStartTime();
         LocalTime endTime = merchantSettings.getEndTime();
@@ -114,12 +116,14 @@ public class OrderInfoService {
         // 使用优惠券(满减优惠券)
         if (ObjectUtil.isNotNull(userOrderDTO.getUserCouponId())) {
             //Coupon coupon = couponRepo.findById(userOrderDTO.getCouponId()).orElseThrow(new BusinessException("优惠券不存在"));
-            UserCoupon userCoupon = userCouponRepo.findById(userOrderDTO.getUserCouponId()).orElseThrow(new BusinessException("无此优惠券"));
+            UserCoupon userCoupon = userCouponRepo.findById(userOrderDTO.getUserCouponId())
+                    .orElseThrow(new BusinessException("无此优惠券"));
             Coupon coupon = couponRepo.findById(userCoupon.getCouponId()).orElseThrow(new BusinessException("优惠券不存在"));
             //未过期,未使用
             if (coupon.getEndDate().isAfter(now.toLocalDate()) && !userCoupon.getIsUsed()) {
                 //限制商家
-                if (ObjectUtil.isNotNull(coupon.getMerchantId()) && !orderInfo.getMerchantId().equals(coupon.getMerchantId())) {
+                if (ObjectUtil.isNotNull(coupon.getMerchantId()) && !orderInfo.getMerchantId()
+                        .equals(coupon.getMerchantId())) {
                     throw new BusinessException("指定商家优惠券");
                 }
 
@@ -359,7 +363,7 @@ public class OrderInfoService {
                 }
             }
         }
-       // orderInfo.setCancel(true);
+        // orderInfo.setCancel(true);
         orderInfo.setReason(reason);
         orderInfo.setStatus(OrderStatus.CANCELLED);
         return orderInfoRepo.save(orderInfo);

+ 28 - 16
src/main/java/com/izouma/dingdong/service/OrderRefundApplyService.java

@@ -31,21 +31,21 @@ import java.util.List;
 public class OrderRefundApplyService {
 
     @Autowired
-    private OrderRefundApplyRepo orderRefundApplyRepo;
+    private OrderRefundApplyRepo    orderRefundApplyRepo;
     @Autowired
-    private OrderInfoRepo orderInfoRepo;
+    private OrderInfoRepo           orderInfoRepo;
     @Autowired
-    private UserRepo userRepo;
+    private UserRepo                userRepo;
     @Autowired
-    private MerchantRepo merchantRepo;
+    private MerchantRepo            merchantRepo;
     @Autowired
     private MerchantSettingsService merchantSettingsService;
     @Autowired
-    private RiderService riderService;
+    private RiderService            riderService;
     @Autowired
-    private RiderRepo riderRepo;
+    private RiderRepo               riderRepo;
     @Autowired
-    private SysConfigRepo sysConfigRepo;
+    private SysConfigRepo           sysConfigRepo;
 
     private OrderStatus status;
 
@@ -60,8 +60,8 @@ public class OrderRefundApplyService {
         OrderInfo order = orderInfoRepo.findById(orderId).orElseThrow(new BusinessException("无记录"));
 
         OrderRefundApply apply = orderRefundApplyRepo.findByOrderId(orderId);
-        if (apply!=null){
-            if (RefundStatus.PENDING.equals(apply.getStatus())){
+        if (apply != null) {
+            if (RefundStatus.PENDING.equals(apply.getStatus())) {
                 throw new BusinessException("申请中");
             } else {
                 throw new BusinessException("已申请过");
@@ -137,11 +137,14 @@ public class OrderRefundApplyService {
                 BigDecimal deliveryAmount = orderInfo.getDeliveryAmount();
                 //骑手收入
                 Long merId = merchantRepo.findUserIdById(orderInfo.getMerchantId());
-                riderService.income(orderInfo.getRiderId(), merId, deliveryAmount, FinancialType.INCOME, apply.getOrderId().toString());
+                riderService.income(orderInfo.getRiderId(), merId, deliveryAmount, FinancialType.INCOME, apply.getOrderId()
+                        .toString());
                 //商家支出
                 //User riderUser = userRepo.findById(riderRepo.findUserIdById(orderInfo.getRiderId())).orElseThrow(new BusinessException("无用户"));
                 Long riderUserId = orderInfo.getRiderId();
-                merchantSettingsService.income(apply.getMerchantId(), riderUserId, deliveryAmount, FinancialType.LOSE_MONEY, apply.getOrderId().toString());
+                merchantSettingsService.income(apply.getMerchantId(), riderUserId, deliveryAmount, FinancialType.LOSE_MONEY, apply
+                        .getOrderId()
+                        .toString());
             }
 
         } else {
@@ -167,7 +170,8 @@ public class OrderRefundApplyService {
      */
     public void cancelRefundApply(Long orderId) {
         orderInfoRepo.findById(orderId).orElseThrow(new BusinessException("无订单"));
-        OrderRefundApply apply = orderRefundApplyRepo.findByOrderIdAndStatus(orderId, RefundStatus.PENDING).orElseThrow(new BusinessException("未申请退款"));
+        OrderRefundApply apply = orderRefundApplyRepo.findByOrderIdAndStatus(orderId, RefundStatus.PENDING)
+                .orElseThrow(new BusinessException("未申请退款"));
         apply.setStatus(RefundStatus.CANCEL);
         apply.getOrderInfo().setStatus((status != null) ? status : OrderStatus.PAID);
         orderInfoRepo.save(apply.getOrderInfo());
@@ -209,13 +213,17 @@ public class OrderRefundApplyService {
             if (!merchantLiability.equals(BigDecimal.ZERO)) {
                 //商家所赔金额
                 BigDecimal merAmount = orderInfo.getRealAmount().multiply(merchantLiability);
-                merchantSettingsService.income(apply.getMerchantId(), orderInfo.getUserId(), merAmount, FinancialType.REFUND, apply.getOrderId().toString());
+                merchantSettingsService.income(apply.getMerchantId(), orderInfo.getUserId(), merAmount, FinancialType.REFUND, apply
+                        .getOrderId()
+                        .toString());
             }
 
             if (!riderLiability.equals(BigDecimal.ZERO)) {
                 //骑手赔付金额
                 BigDecimal riderAmount = orderInfo.getRealAmount().multiply(riderLiability);
-                riderService.income(orderInfo.getRiderId(), orderInfo.getUserId(), riderAmount, FinancialType.REFUND, apply.getOrderId().toString());
+                riderService.income(orderInfo.getRiderId(), orderInfo.getUserId(), riderAmount, FinancialType.REFUND, apply
+                        .getOrderId()
+                        .toString());
             }
 
             //改状态
@@ -251,10 +259,14 @@ public class OrderRefundApplyService {
 
         //商家应得 = 减去骑手应得,减去平台抽成
         BigDecimal deserve = subtractDelivery.subtract(platform);
-        merchantSettingsService.income(orderInfo.getMerchantId(), orderInfo.getUserId(), deserve, FinancialType.INCOME, orderInfo.getId().toString());
+        merchantSettingsService.income(orderInfo.getMerchantId(), orderInfo.getUserId(), deserve, FinancialType.INCOME, orderInfo
+                .getId()
+                .toString());
 
         //骑手应得
-        riderService.income(orderInfo.getRiderId(), orderInfo.getUserId(), orderInfo.getDeliveryAmount(), FinancialType.INCOME, orderInfo.getId().toString());
+        riderService.income(orderInfo.getRiderId(), orderInfo.getUserId(), orderInfo.getDeliveryAmount(), FinancialType.INCOME, orderInfo
+                .getId()
+                .toString());
     }
 
     /*

+ 6 - 5
src/main/java/com/izouma/dingdong/service/WithdrawApplyService.java

@@ -28,10 +28,10 @@ import java.time.LocalDateTime;
 public class WithdrawApplyService {
 
     private WithdrawApplyRepo withdrawalsApplyRepo;
-    private UserRepo userRepo;
-    private BankCardRepo bankCardRepo;
-    private MoneyRecordRepo moneyRecordRepo;
-    private EmailRepo emailRepo;
+    private UserRepo          userRepo;
+    private BankCardRepo      bankCardRepo;
+    private MoneyRecordRepo   moneyRecordRepo;
+    private EmailRepo         emailRepo;
 
     /*
     提现申请
@@ -78,7 +78,8 @@ public class WithdrawApplyService {
     */
     @Transactional
     public WithdrawApply audit(Long withdrawalsId, Boolean consent) {
-        WithdrawApply withdrawals = withdrawalsApplyRepo.findById(withdrawalsId).orElseThrow(new BusinessException("无此申请记录"));
+        WithdrawApply withdrawals = withdrawalsApplyRepo.findById(withdrawalsId)
+                .orElseThrow(new BusinessException("无此申请记录"));
         if (consent == null) {
             throw new BusinessException("操作错误");
         }

+ 7 - 5
src/main/java/com/izouma/dingdong/service/backstage/BlackListService.java

@@ -21,9 +21,9 @@ import java.time.LocalDateTime;
 public class BlackListService {
 
     private BlackListRepo blackListRepo;
-    private UserRepo userRepo;
-    private MerchantRepo merchantRepo;
-    private RiderRepo riderRepo;
+    private UserRepo      userRepo;
+    private MerchantRepo  merchantRepo;
+    private RiderRepo     riderRepo;
 
     /*
     加入黑名单
@@ -99,13 +99,15 @@ public class BlackListService {
                 break;
 
             case MERCHANT:
-                Merchant merchant = merchantRepo.findById(blackList.getOtherId()).orElseThrow(new BusinessException("无商户"));
+                Merchant merchant = merchantRepo.findById(blackList.getOtherId())
+                        .orElseThrow(new BusinessException("无商户"));
                 merchant.setBlacklist(false);
                 merchantRepo.save(merchant);
                 break;
 
             case RIDER:
-                Rider rider = riderRepo.findByJobNumber(blackList.getOtherId()).orElseThrow(new BusinessException("无骑手"));
+                Rider rider = riderRepo.findByJobNumber(blackList.getOtherId())
+                        .orElseThrow(new BusinessException("无骑手"));
                 rider.setBlacklist(false);
                 riderRepo.save(rider);
                 break;

+ 2 - 2
src/main/java/com/izouma/dingdong/service/backstage/CategoryService.java

@@ -23,8 +23,8 @@ import java.util.List;
 @AllArgsConstructor
 public class CategoryService {
 
-    private CategoryRepo categoryRepo;
-    private MerchantRepo merchantRepo;
+    private CategoryRepo         categoryRepo;
+    private MerchantRepo         merchantRepo;
     private MerchantSettingsRepo merchantSettingsRepo;
 
     /*

+ 48 - 0
src/main/java/com/izouma/dingdong/service/backstage/DeliveryFeeService.java

@@ -1,14 +1,62 @@
 package com.izouma.dingdong.service.backstage;
 
+import com.izouma.dingdong.domain.OrderInfo;
 import com.izouma.dingdong.domain.backstage.DeliveryFee;
+import com.izouma.dingdong.domain.merchant.Merchant;
+import com.izouma.dingdong.domain.user.Address;
+import com.izouma.dingdong.enums.DeliveryType;
+import com.izouma.dingdong.exception.BusinessException;
+import com.izouma.dingdong.repo.OrderInfoRepo;
 import com.izouma.dingdong.repo.backstage.DeliveryFeeRepo;
+import com.izouma.dingdong.repo.merchant.MerchantRepo;
+import com.izouma.dingdong.repo.user.AddressRepo;
+import com.izouma.dingdong.utils.MapUtils;
 import lombok.AllArgsConstructor;
 import org.springframework.stereotype.Service;
 
+import java.math.BigDecimal;
+import java.util.List;
+
 @Service
 @AllArgsConstructor
 public class DeliveryFeeService {
 
     private DeliveryFeeRepo deliveryFeeRepo;
+    private OrderInfoRepo orderInfoRepo;
+    private AddressRepo addressRepo;
+    private MerchantRepo merchantRepo;
+
+    public void riderAll(Long riderId, OrderInfo orderInfo, Long addressId) {
+
+        List<OrderInfo> infos = orderInfoRepo.findAllByRiderId(riderId);
+
+        BigDecimal amount = BigDecimal.ZERO;
+
+        //算距离
+        Address address = addressRepo.findById(addressId).orElseThrow(new BusinessException("无地址"));
+        Merchant merchant = merchantRepo.findById(orderInfo.getMerchantId()).orElseThrow(new BusinessException("无商户"));
+        Double distance = MapUtils.distance(address.getLongitude(), address.getLatitude(), merchant.getLongitude(), merchant.getLatitude());
+
+        //基础距离费用
+        DeliveryFee baseFee = deliveryFeeRepo.findAllByType(DeliveryType.BASE_FEE).get(0);
+        //基础距离
+        Double baseRule = new Double(baseFee.getRule());
+        //费用
+        amount = new BigDecimal(baseFee.getValue());
+        if (distance > baseRule) {
+            //超出距离费用
+            DeliveryFee excessCost = deliveryFeeRepo.findAllByType(DeliveryType.EXCESS_COST).get(0);
+            //超出距离规格
+            Double excessRule = new Double(excessCost.getRule());
+            //超出费用值
+            BigDecimal excessFee = new BigDecimal(excessCost.getValue());
+
+            Double rule = (distance - baseRule) / excessRule;
+
+
+        }
+
+
+    }
 
 }

+ 29 - 20
src/main/java/com/izouma/dingdong/service/merchant/GoodsService.java

@@ -34,18 +34,18 @@ import java.util.stream.Collectors;
 @AllArgsConstructor
 public class GoodsService {
 
-    private GoodsRepo goodsRepo;
-    private MerchantSettingsRepo merchantSettingsRepo;
-    private MerchantClassificationRepo merchantClassificationRepo;
+    private GoodsRepo                     goodsRepo;
+    private MerchantSettingsRepo          merchantSettingsRepo;
+    private MerchantClassificationRepo    merchantClassificationRepo;
     private MerchantClassificationService merchantClassificationService;
-    private EmailRepo emailRepo;
-    private MerchantRepo merchantRepo;
-    private AppraisalService appraisalService;
-    private GoodsSpecificationRepo goodsSpecificationRepo;
-    private MerchantService merchantService;
-    private ShoppingCartService shoppingCartService;
-    private OrderGoodsSpecRepo orderGoodsSpecRepo;
-    private ShoppingCartRepo shoppingCartRepo;
+    private EmailRepo                     emailRepo;
+    private MerchantRepo                  merchantRepo;
+    private AppraisalService              appraisalService;
+    private GoodsSpecificationRepo        goodsSpecificationRepo;
+    private MerchantService               merchantService;
+    private ShoppingCartService           shoppingCartService;
+    private OrderGoodsSpecRepo            orderGoodsSpecRepo;
+    private ShoppingCartRepo              shoppingCartRepo;
 
     /**
      * 添加修改商品
@@ -57,7 +57,8 @@ public class GoodsService {
         if (ObjectUtil.isNull(goods.getMerchantId())) {
             throw new BusinessException("缺少商家");
         }
-        MerchantSettings merchantSettings = merchantSettingsRepo.findByMerchantId(goods.getMerchantId()).orElseThrow(new BusinessException("商家不存在"));
+        MerchantSettings merchantSettings = merchantSettingsRepo.findByMerchantId(goods.getMerchantId())
+                .orElseThrow(new BusinessException("商家不存在"));
         if (ObjectUtil.isNull(goods.getInventory()) || goods.getInventory() < 1) {
             throw new BusinessException("商品供应数量不足");
         }
@@ -78,7 +79,8 @@ public class GoodsService {
             throw new BusinessException("折扣价不得大于原价");
         }
 
-        if (goods.getStartTime().isBefore(merchantSettings.getStartTime()) || goods.getEndTime().isAfter(merchantSettings.getEndTime())) {
+        if (goods.getStartTime().isBefore(merchantSettings.getStartTime()) || goods.getEndTime()
+                .isAfter(merchantSettings.getEndTime())) {
             throw new BusinessException("商品销售时间不得早于/晚于营业时间");
         }
 
@@ -104,7 +106,7 @@ public class GoodsService {
             goods.setSignboard(false);
             goods.setEnabled(true);
             //审核
-            goods.setIsPass(false);
+//            goods.setIsPass(false);
             //优先级
             goods.setPriority(1);
             //好评
@@ -199,7 +201,7 @@ public class GoodsService {
         Email email;
 
         if (pass) {
-            goods.setIsPass(true);
+//            goods.setIsPass(true);
             goods.setStatus(ApplyStatus.PASS);
             //发送邮件
             email = Email.builder()
@@ -210,7 +212,7 @@ public class GoodsService {
                     .build();
 
         } else {
-            goods.setIsPass(false);
+//            goods.setIsPass(false);
             goods.setStatus(ApplyStatus.DENY);
             //发送邮件
             email = Email.builder()
@@ -269,8 +271,8 @@ public class GoodsService {
 
         //用户3km以内的商品
         List<Goods> goodsList = new ArrayList<>();
-        for (MerchantDTO d:dtos){
-            goodsList.addAll(goodsRepo.findAllByMerchantIdAndIsPassTrue(d.getMid()));
+        for (MerchantDTO d : dtos) {
+            goodsList.addAll(goodsRepo.findAllByMerchantIdAndStatus(d.getMid(),ApplyStatus.PASS));
         }
 
         List<Goods> all = new ArrayList<>();
@@ -292,8 +294,14 @@ public class GoodsService {
             //从大到小
 //            int i = b.getPriority().compareTo(a.getPriority());
 //            if (i == 0) {
-            MerchantDTO dtoA = dtos.stream().filter(d -> d.getMid().equals(a.getMerchantId())).findFirst().orElseThrow(new BusinessException("无商家"));
-            MerchantDTO dtoB = dtos.stream().filter(d -> d.getMid().equals(b.getMerchantId())).findFirst().orElseThrow(new BusinessException("无商家"));
+            MerchantDTO dtoA = dtos.stream()
+                    .filter(d -> d.getMid().equals(a.getMerchantId()))
+                    .findFirst()
+                    .orElseThrow(new BusinessException("无商家"));
+            MerchantDTO dtoB = dtos.stream()
+                    .filter(d -> d.getMid().equals(b.getMerchantId()))
+                    .findFirst()
+                    .orElseThrow(new BusinessException("无商家"));
             Integer monthSalesA = dtoA.getMonthSales();
             if (monthSalesA > 10000) {
                 monthSalesA = 10000;
@@ -327,6 +335,7 @@ public class GoodsService {
         //如果修改商品名称和图片就重新审核
         if (record.getName() != null || record.getImg() != null) {
             record.setStatus(ApplyStatus.PENDING);
+//            record.setIsPass(false);
         }
         ObjUtils.merge(orig, record);
         Goods save = this.save(orig);

+ 10 - 5
src/main/java/com/izouma/dingdong/service/merchant/GoodsSpecificationService.java

@@ -34,7 +34,9 @@ public class GoodsSpecificationService {
                 goodsRepo.findById(s.getGoodsId()).orElseThrow(new BusinessException("商品不存在"));
                 GoodsSpecification save = goodsSpecificationRepo.save(s);
 //                if (s.getParent() == null) {
-                Set<GoodsSpecification> collect = spec.stream().filter(g -> g.getParent() != null && g.getParent().equals(s.getId())).collect(Collectors.toSet());
+                Set<GoodsSpecification> collect = spec.stream()
+                        .filter(g -> g.getParent() != null && g.getParent().equals(s.getId()))
+                        .collect(Collectors.toSet());
 
                 collect.forEach(c -> {
                     //c.setParent(save.getId());
@@ -53,7 +55,8 @@ public class GoodsSpecificationService {
                 all.add(goodsSpecificationRepo.save(s));
             } else if (s.getId() > 0) {
                 //修改
-                GoodsSpecification goodsSpecification = goodsSpecificationRepo.findById(s.getId()).orElseThrow(new BusinessException("不存在"));
+                GoodsSpecification goodsSpecification = goodsSpecificationRepo.findById(s.getId())
+                        .orElseThrow(new BusinessException("不存在"));
                 ObjUtils.merge(goodsSpecification, s);
                 goodsRepo.findById(goodsSpecification.getGoodsId()).orElseThrow(new BusinessException("商品不存在"));
                 all.add(goodsSpecificationRepo.save(goodsSpecification));
@@ -63,13 +66,14 @@ public class GoodsSpecificationService {
         return all;
     }
 
-    public List<GoodsSpecification> save(List<GoodsSpecification> specifications){
+    public List<GoodsSpecification> save(List<GoodsSpecification> specifications) {
         List<GoodsSpecification> all = new ArrayList<>();
         specifications.forEach(s -> {
             goodsRepo.findById(s.getGoodsId()).orElseThrow(new BusinessException("商品不存在"));
             GoodsSpecification save;
             if (s.getId() != null) {
-                GoodsSpecification specification = goodsSpecificationRepo.findById(s.getId()).orElseThrow(new BusinessException("无记录"));
+                GoodsSpecification specification = goodsSpecificationRepo.findById(s.getId())
+                        .orElseThrow(new BusinessException("无记录"));
                 ObjUtils.merge(specification, s);
                 save = goodsSpecificationRepo.save(specification);
             } else {
@@ -80,7 +84,8 @@ public class GoodsSpecificationService {
                 s.getChildren().forEach(c -> {
                     c.setParent(save.getId());
                     if (c.getId() != null) {
-                        GoodsSpecification specification = goodsSpecificationRepo.findById(s.getId()).orElseThrow(new BusinessException("无记录"));
+                        GoodsSpecification specification = goodsSpecificationRepo.findById(s.getId())
+                                .orElseThrow(new BusinessException("无记录"));
                         ObjUtils.merge(specification, s);
                         all.add(goodsSpecificationRepo.save(specification));
                     } else {

+ 8 - 4
src/main/java/com/izouma/dingdong/service/merchant/MerchantClassificationService.java

@@ -63,7 +63,8 @@ public class MerchantClassificationService {
     显示类别下的商品列表
      */
     public List<Goods> showGoods(Long classificationId) {
-        MerchantClassification merchantClassification = merchantClassificationRepo.findById(classificationId).orElseThrow(new BusinessException("分类不存在"));
+        MerchantClassification merchantClassification = merchantClassificationRepo.findById(classificationId)
+                .orElseThrow(new BusinessException("分类不存在"));
         LongArrayConverter converter = new LongArrayConverter();
         //List<Long> goodsIds = merchantClassification.getGoodsIds();
         List<Long> goodsIds = converter.convertToEntityAttribute(merchantClassification.getGoodsIds());
@@ -84,7 +85,8 @@ public class MerchantClassificationService {
      */
     public MerchantClassification saveGoods(Long classificationId, String string) {
         //查找分类
-        MerchantClassification merchantClassification = merchantClassificationRepo.findById(classificationId).orElseThrow(new BusinessException("无分类"));
+        MerchantClassification merchantClassification = merchantClassificationRepo.findById(classificationId)
+                .orElseThrow(new BusinessException("无分类"));
 
         //List<Long> goodsIds = merchantClassification.getGoodsIds();
         LongArrayConverter converter = new LongArrayConverter();
@@ -107,7 +109,8 @@ public class MerchantClassificationService {
      */
     public void saveOneGoods(Long classificationId, Long goodsId) {
         //查找分类
-        MerchantClassification merchantClassification = merchantClassificationRepo.findById(classificationId).orElseThrow(new BusinessException("无分类"));
+        MerchantClassification merchantClassification = merchantClassificationRepo.findById(classificationId)
+                .orElseThrow(new BusinessException("无分类"));
 
 //        List<Long> ids = merchantClassification.getGoodsIds();
 
@@ -132,7 +135,8 @@ public class MerchantClassificationService {
      */
     public void delGoods(Long classificationId, Long goodId) {
         //查找分类
-        MerchantClassification merchantClassification = merchantClassificationRepo.findById(classificationId).orElseThrow(new BusinessException("无分类"));
+        MerchantClassification merchantClassification = merchantClassificationRepo.findById(classificationId)
+                .orElseThrow(new BusinessException("无分类"));
 
         LongArrayConverter converter = new LongArrayConverter();
         List<Long> goodsIds = converter.convertToEntityAttribute(merchantClassification.getGoodsIds());

+ 27 - 16
src/main/java/com/izouma/dingdong/service/merchant/MerchantService.java

@@ -49,16 +49,16 @@ import static com.izouma.dingdong.web.BaseController.*;
 @AllArgsConstructor
 public class MerchantService {
 
-    private MerchantRepo merchantRepo;
-    private MerchantSettingsRepo merchantSettingsRepo;
-    private UserRepo userRepo;
+    private MerchantRepo               merchantRepo;
+    private MerchantSettingsRepo       merchantSettingsRepo;
+    private UserRepo                   userRepo;
     private MerchantClassificationRepo merchantClassificationRepo;
-    private VerifiedRepo verifiedRepo;
+    private VerifiedRepo               verifiedRepo;
 
     private FullReductionRepo fullReductionRepo;
-    private CouponRepo couponRepo;
-    private UserCouponRepo userCouponRepo;
-    private CategoryRepo categoryRepo;
+    private CouponRepo        couponRepo;
+    private UserCouponRepo    userCouponRepo;
+    private CategoryRepo      categoryRepo;
 
     private GoodsRepo goodsRepo;
 
@@ -180,7 +180,8 @@ public class MerchantService {
         }
 
         Merchant merchant = merchantRepo.findById(merchantDTO.getMid()).orElseThrow(new BusinessException("商户不存在"));
-        MerchantSettings merchantSettings = merchantSettingsRepo.findByMerchantId(merchantDTO.getMid()).orElseThrow(new BusinessException("商户不存在"));
+        MerchantSettings merchantSettings = merchantSettingsRepo.findByMerchantId(merchantDTO.getMid())
+                .orElseThrow(new BusinessException("商户不存在"));
 
         MerchantDTO dto = new MerchantDTO(merchant, merchantSettings);
         ObjUtils.merge(dto, merchantDTO);
@@ -246,7 +247,8 @@ public class MerchantService {
         List<MerchantDTO> merchantDTOS = CollUtil.newArrayList();
         Page<Merchant> merchants = merchantRepo.findAll(toSpecification(pageQuery, Merchant.class), toPageRequest(pageQuery));
         for (Merchant merchant : merchants) {
-            MerchantSettings merchantSettings = merchantSettingsRepo.findByMerchantId(merchant.getId()).orElseThrow(new BusinessException("商户不存在"));
+            MerchantSettings merchantSettings = merchantSettingsRepo.findByMerchantId(merchant.getId())
+                    .orElseThrow(new BusinessException("商户不存在"));
 
             merchantDTOS.add(new MerchantDTO(merchant, merchantSettings));
         }
@@ -326,13 +328,15 @@ public class MerchantService {
 
             //  }
             // for (Merchant m : mers) {
-            MerchantSettings settings = merchantSettingsRepo.findByMerchantId(m.getKey().getId()).orElseThrow(new BusinessException("商户不存在"));
+            MerchantSettings settings = merchantSettingsRepo.findByMerchantId(m.getKey().getId())
+                    .orElseThrow(new BusinessException("商户不存在"));
             MerchantDTO merchantDTO = new MerchantDTO(m.getKey(), settings, m.getValue());
             if (StrUtil.isNotBlank(popularTag)) {
                 merchantDTO.setFullReductions(fullReductionRepo.findAllByMerchantId(merchantDTO.getMid()));
                 switch (popularTag) {
                     case "首单立减":
-                        if ((settings.getFirstOrder() != null ? settings.getFirstOrder().compareTo(BigDecimal.ZERO) : 0) > 0) {
+                        if ((settings.getFirstOrder() != null ? settings.getFirstOrder()
+                                .compareTo(BigDecimal.ZERO) : 0) > 0) {
                             merchantDTOS.add(merchantDTO);
                         }
                         break;
@@ -342,7 +346,8 @@ public class MerchantService {
                         }
                         break;
                     case "折扣商家":
-                        if (StrUtil.isNotEmpty(merchantClassificationRepo.findByMerchantIdAndType(m.getKey().getId(), 2).getGoodsIds())) {
+                        if (StrUtil.isNotEmpty(merchantClassificationRepo.findByMerchantIdAndType(m.getKey().getId(), 2)
+                                .getGoodsIds())) {
                             merchantDTOS.add(merchantDTO);
                         }
                         break;
@@ -354,7 +359,10 @@ public class MerchantService {
                     case "可用红包":
                         List<UserCoupon> coupons = userCouponRepo.findAllByUserIdAndIsUsedFalse(userId);
                         List<UserCoupon> collect = coupons.stream().filter(c ->
-                                !c.getCoupon().getEndDate().isBefore(LocalDate.now()) && (c.getCoupon().getMerchantId() == null || c.getCoupon().getMerchantId().equals(m.getKey().getId()))
+                                !c.getCoupon().getEndDate().isBefore(LocalDate.now()) && (c.getCoupon()
+                                        .getMerchantId() == null || c.getCoupon()
+                                        .getMerchantId()
+                                        .equals(m.getKey().getId()))
                         ).collect(Collectors.toList());
                         if (CollUtil.isNotEmpty(collect)) {
                             merchantDTOS.add(merchantDTO);
@@ -384,7 +392,8 @@ public class MerchantService {
      */
     public MerchantDTO my(Long userId) {
         Merchant merchant = merchantRepo.findByUserId(userId).orElseThrow(new BusinessException("商户不存在"));
-        MerchantSettings merchantSettings = merchantSettingsRepo.findByMerchantId(merchant.getId()).orElseThrow(new BusinessException("商户不存在"));
+        MerchantSettings merchantSettings = merchantSettingsRepo.findByMerchantId(merchant.getId())
+                .orElseThrow(new BusinessException("商户不存在"));
         return new MerchantDTO(merchant, merchantSettings);
     }
 
@@ -403,7 +412,8 @@ public class MerchantService {
     开始/停止营业
      */
     public void closeMer(Long merchantId) {
-        MerchantSettings merchant = merchantSettingsRepo.findByMerchantId(merchantId).orElseThrow(new BusinessException("无商户"));
+        MerchantSettings merchant = merchantSettingsRepo.findByMerchantId(merchantId)
+                .orElseThrow(new BusinessException("无商户"));
         if (merchant.getIsOpening()) {
             merchant.setIsOpening(false);
         } else {
@@ -451,7 +461,8 @@ public class MerchantService {
         Map<Merchant, Double> merchantMap = this.distanceSorting(merchants, longitude, latitude, range);
         List<MerchantDTO> dtos = new ArrayList<>();
         for (Map.Entry<Merchant, Double> m : merchantMap.entrySet()) {
-            merchantSettingsRepo.findByMerchantId(m.getKey().getId()).ifPresent(s -> dtos.add(new MerchantDTO(m.getKey(), s, m.getValue())));
+            merchantSettingsRepo.findByMerchantId(m.getKey().getId())
+                    .ifPresent(s -> dtos.add(new MerchantDTO(m.getKey(), s, m.getValue())));
         }
         return dtos;
     }

+ 37 - 27
src/main/java/com/izouma/dingdong/service/merchant/MerchantSettingsService.java

@@ -39,26 +39,26 @@ import java.util.stream.Collectors;
 @AllArgsConstructor
 public class MerchantSettingsService {
 
-    private MerchantSettingsRepo merchantSettingsRepo;
-    private OrderInfoRepo orderInfoRepo;
-    private TimeTagRepo timeTagRepo;
-    private MerchantRepo merchantRepo;
-    private UserRepo userRepo;
-    private MoneyRecordRepo moneyRecordRepo;
-    private BannerRepo bannerRepo;
-    private CategoryRepo categoryRepo;
-    private CategoryService categoryService;
-    private PromoteRepo promoteRepo;
-    private GoodsRepo goodsRepo;
-    private AppraisalRepo appraisalRepo;
-    private GoodsSpecificationRepo goodsSpecificationRepo;
+    private MerchantSettingsRepo       merchantSettingsRepo;
+    private OrderInfoRepo              orderInfoRepo;
+    private TimeTagRepo                timeTagRepo;
+    private MerchantRepo               merchantRepo;
+    private UserRepo                   userRepo;
+    private MoneyRecordRepo            moneyRecordRepo;
+    private BannerRepo                 bannerRepo;
+    private CategoryRepo               categoryRepo;
+    private CategoryService            categoryService;
+    private PromoteRepo                promoteRepo;
+    private GoodsRepo                  goodsRepo;
+    private AppraisalRepo              appraisalRepo;
+    private GoodsSpecificationRepo     goodsSpecificationRepo;
     private MerchantClassificationRepo merchantClassificationRepo;
-    private FullReductionRepo fullReductionRepo;
-    private MerchantService merchantService;
-    private CouponRepo couponRepo;
-    private UserCouponRepo userCouponRepo;
-    private PriorityRepo priorityRepo;
-    private SalesRepo salesRepo;
+    private FullReductionRepo          fullReductionRepo;
+    private MerchantService            merchantService;
+    private CouponRepo                 couponRepo;
+    private UserCouponRepo             userCouponRepo;
+    private PriorityRepo               priorityRepo;
+    private SalesRepo                  salesRepo;
 
     /*
     时间标签类商家列表
@@ -68,7 +68,8 @@ public class MerchantSettingsService {
         List<MerchantSettings> all = merchantSettingsRepo.findAll();
         List<MerchantSettings> collect = all.stream().filter(a ->
                 //商家开始时间早于结束前的一小时 或者 商家结束时间早于开始后的一小时
-                !a.getStartTime().isAfter(timeTag.getEndTime().minusHours(1)) || !a.getEndTime().isAfter(timeTag.getStartTime().plusHours(1))
+                !a.getStartTime().isAfter(timeTag.getEndTime().minusHours(1)) || !a.getEndTime()
+                        .isAfter(timeTag.getStartTime().plusHours(1))
         ).collect(Collectors.toList());
 
         List<MerchantDTO> list = CollUtil.newArrayList();
@@ -93,7 +94,8 @@ public class MerchantSettingsService {
      */
     public void income(Long merchantId, Long fromUserId, BigDecimal amount, FinancialType type, String remark) {
         //按商户Id找出用户
-        User userMer = userRepo.findById(merchantRepo.findUserIdById(merchantId)).orElseThrow(new BusinessException("无用户"));
+        User userMer = userRepo.findById(merchantRepo.findUserIdById(merchantId))
+                .orElseThrow(new BusinessException("无用户"));
         //商家应得 = 减去骑手应得,减去平台抽成
         userMer.setMoney(userMer.getMoney().add(amount));
         userRepo.save(userMer);
@@ -137,7 +139,9 @@ public class MerchantSettingsService {
         //时间标签
         List<TimeTag> timeTags = timeTagRepo.findAll();
         LocalTime now = LocalTime.now();
-        List<TimeTag> timeTag = timeTags.stream().filter(t -> now.isAfter(t.getStartTime()) && now.isBefore(t.getEndTime())).collect(Collectors.toList());
+        List<TimeTag> timeTag = timeTags.stream()
+                .filter(t -> now.isAfter(t.getStartTime()) && now.isBefore(t.getEndTime()))
+                .collect(Collectors.toList());
 
         //优惠专区
         //主推荐位 2个
@@ -198,7 +202,10 @@ public class MerchantSettingsService {
         merchantRepo.deleteById(merchantId);
         merchantSettingsRepo.deleteByMerchantId(merchantId);
         //删除商品规格
-        List<Long> collect = goodsRepo.findAllByMerchantId(merchantId).stream().map(Goods::getId).collect(Collectors.toList());
+        List<Long> collect = goodsRepo.findAllByMerchantId(merchantId)
+                .stream()
+                .map(Goods::getId)
+                .collect(Collectors.toList());
         collect.forEach(c -> goodsSpecificationRepo.deleteByGoodsId(c));
         //删除商品
         goodsRepo.deleteAllByMerchantId(merchantId);
@@ -213,7 +220,8 @@ public class MerchantSettingsService {
 
     public MerchantDTO getDTO(Long id) {
         Merchant merchant = merchantRepo.findById(id).orElseThrow(new BusinessException("无记录"));
-        MerchantSettings merchantSettings = merchantSettingsRepo.findByMerchantId(id).orElseThrow(new BusinessException("无记录"));
+        MerchantSettings merchantSettings = merchantSettingsRepo.findByMerchantId(id)
+                .orElseThrow(new BusinessException("无记录"));
         MerchantDTO dto = new MerchantDTO(merchant, merchantSettings);
         dto.setFullReductions(fullReductionRepo.findAllByMerchantId(id));
         return dto;
@@ -287,8 +295,8 @@ public class MerchantSettingsService {
                     });
                     break;
                 //case 7:
-                    //距离
-                    //dtos.sort(Comparator.comparing(MerchantDTO::getDistance));
+                //距离
+                //dtos.sort(Comparator.comparing(MerchantDTO::getDistance));
                 case 8:
                     //月销
                     dtos.sort((a, b) -> b.getMonthSales().compareTo(a.getMonthSales()));
@@ -328,7 +336,9 @@ public class MerchantSettingsService {
                         .filter(d ->
                                 ObjectUtil.isNotEmpty(coupons.stream().filter(c ->
                                         !c.getCoupon().getEndDate().isBefore(LocalDate.now())
-                                                && (c.getCoupon().getMerchantId() == null || c.getCoupon().getMerchantId().equals(d.getMid()))
+                                                && (c.getCoupon().getMerchantId() == null || c.getCoupon()
+                                                .getMerchantId()
+                                                .equals(d.getMid()))
                                 ).collect(Collectors.toSet()))
                         )
                         .collect(Collectors.toSet()));

+ 4 - 2
src/main/java/com/izouma/dingdong/service/merchant/SalesService.java

@@ -91,7 +91,8 @@ public class SalesService {
                     //无差评,销量 >=10,有好评
                     if (sales.getDayBad() == 0 && sales.getDaySales() >= 10 && sales.getDayLikes() > 0) {
                         //查找昨天的好评连续值
-                        Integer praise = salesRepo.findByGoodsIdAndDay(sales.getGoodsId(), now.plusDays(-1)).getPraise();
+                        Integer praise = salesRepo.findByGoodsIdAndDay(sales.getGoodsId(), now.plusDays(-1))
+                                .getPraise();
                         //好评连续值+1
                         sales.setPraise(praise + 1);
                     } else {
@@ -101,7 +102,8 @@ public class SalesService {
                     //销量 >50
                     if (sales.getDaySales() >= 50) {
                         //查找昨天的人气连续值
-                        Integer popularity = salesRepo.findByGoodsIdAndDay(sales.getGoodsId(), now.plusDays(-1)).getPopularity();
+                        Integer popularity = salesRepo.findByGoodsIdAndDay(sales.getGoodsId(), now.plusDays(-1))
+                                .getPopularity();
                         //人气连续值+1
                         sales.setPopularity(popularity + 1);
                     } else {

+ 22 - 13
src/main/java/com/izouma/dingdong/service/user/ShoppingCartService.java

@@ -33,13 +33,13 @@ import java.util.Map;
 @AllArgsConstructor
 public class ShoppingCartService {
 
-    private ShoppingCartRepo shoppingCartRepo;
-    private GoodsRepo goodsRepo;
-    private UserRepo userRepo;
-    private OrderInfoRepo orderInfoRepo;
-    private MerchantSettingsRepo merchantSettingsRepo;
-    private FullReductionRepo fullReductionRepo;
-    private OrderGoodsSpecRepo orderGoodsSpecRepo;
+    private ShoppingCartRepo      shoppingCartRepo;
+    private GoodsRepo             goodsRepo;
+    private UserRepo              userRepo;
+    private OrderInfoRepo         orderInfoRepo;
+    private MerchantSettingsRepo  merchantSettingsRepo;
+    private FullReductionRepo     fullReductionRepo;
+    private OrderGoodsSpecRepo    orderGoodsSpecRepo;
     private OrderGoodsSpecService orderGoodsSpecService;
 
     /*
@@ -55,7 +55,8 @@ public class ShoppingCartService {
         Long merchantId = goods.getMerchantId();
 
         //商家信息
-        MerchantSettings merchant = merchantSettingsRepo.findByMerchantId(merchantId).orElseThrow(new BusinessException("无商户"));
+        MerchantSettings merchant = merchantSettingsRepo.findByMerchantId(merchantId)
+                .orElseThrow(new BusinessException("无商户"));
 
         //查找是不是第一次购买
         userRepo.findById(userId).orElseThrow(new BusinessException("无用户"));
@@ -68,7 +69,9 @@ public class ShoppingCartService {
         specs.add(orderGoodsSpec);
 
         //减的金额
-        BigDecimal sub = orderGoodsSpec.getGoodsPrice().subtract(orderGoodsSpec.getGoodsRealPrice()).multiply(BigDecimal.valueOf(orderGoodsSpec.getNum()));
+        BigDecimal sub = orderGoodsSpec.getGoodsPrice()
+                .subtract(orderGoodsSpec.getGoodsRealPrice())
+                .multiply(BigDecimal.valueOf(orderGoodsSpec.getNum()));
 
         //包装费
         BigDecimal packingPrice = BigDecimal.ZERO;
@@ -92,7 +95,8 @@ public class ShoppingCartService {
             shoppingCart.setId(-1L);
         } else {
             //商品总价(原价)
-            shoppingCart.setGoodsTotal(shoppingCart.getGoodsTotal().add(orderGoodsSpec.getGoodsPrice().multiply(BigDecimal.valueOf(orderGoodsSpec.getNum()))));
+            shoppingCart.setGoodsTotal(shoppingCart.getGoodsTotal()
+                    .add(orderGoodsSpec.getGoodsPrice().multiply(BigDecimal.valueOf(orderGoodsSpec.getNum()))));
             //折扣的差价
             shoppingCart.setReducedAmount(shoppingCart.getReducedAmount().add(sub));
             specs.addAll(shoppingCart.getOrderGoodsSpecs());
@@ -144,7 +148,9 @@ public class ShoppingCartService {
         }
 
         //商品总价+配送费+包装费
-        BigDecimal total = shoppingCart.getGoodsTotal().add(shoppingCart.getDeliveryAmount()).add(shoppingCart.getPackingPrice());
+        BigDecimal total = shoppingCart.getGoodsTotal()
+                .add(shoppingCart.getDeliveryAmount())
+                .add(shoppingCart.getPackingPrice());
 
         //需要减去的金额=首单+新用户+折扣/满减
         BigDecimal sub2 = shoppingCart.getReducedAmount();
@@ -238,7 +244,8 @@ public class ShoppingCartService {
         //按商家创建购物车
         // Long merchantId = specs.get(0).getGoods().getMerchantId();
         //商家信息
-        MerchantSettings merchant = merchantSettingsRepo.findByMerchantId(merchantId).orElseThrow(new BusinessException("无商户"));
+        MerchantSettings merchant = merchantSettingsRepo.findByMerchantId(merchantId)
+                .orElseThrow(new BusinessException("无商户"));
 
         if (flag) {
             //参与满减
@@ -293,7 +300,9 @@ public class ShoppingCartService {
     //加规格
     public ShoppingCart add(Long userId, OrderGoodsSpec orderGoodsSpec) {
         //按商家创建购物车
-        Long merchantId = goodsRepo.findById(orderGoodsSpec.getGoodsId()).orElseThrow(new BusinessException("无商品")).getMerchantId();
+        Long merchantId = goodsRepo.findById(orderGoodsSpec.getGoodsId())
+                .orElseThrow(new BusinessException("无商品"))
+                .getMerchantId();
 
         //商家信息
         //MerchantSettings merchant = merchantSettingsRepo.findByMerchantId(merchantId).orElseThrow(new BusinessException("无商户"));

+ 1 - 1
src/main/java/com/izouma/dingdong/web/merchant/GoodsController.java

@@ -121,7 +121,7 @@ public class GoodsController extends BaseController {
 
     @GetMapping("/goods")
     public List<Goods> goods(Long merchantId) {
-        return goodsRepo.findAllByMerchantIdAndIsPassTrue(merchantId);
+        return goodsRepo.findAllByMerchantIdAndStatus(merchantId, ApplyStatus.PASS);
     }
 
 }

+ 103 - 0
src/test/java/com/izouma/dingdong/MapTest.java

@@ -0,0 +1,103 @@
+package com.izouma.dingdong;
+
+import cn.hutool.core.util.ObjectUtil;
+import com.izouma.dingdong.domain.merchant.Merchant;
+import com.izouma.dingdong.repo.merchant.MerchantRepo;
+import com.izouma.dingdong.utils.MapUtils;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.List;
+import java.util.stream.Collectors;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class MapTest {
+
+    @Autowired
+    private MerchantRepo merchantRepo;
+
+    @Test
+    public void test() {
+
+//         TencentLocationManagerOptions.setKey("LQTBZ-EEUCU-UX7V4-4CY7M-NROM7-NLFI5");
+
+//         MapView
+        // System.out.println(b);
+
+        //System.out.println(TencentLocationUtils.distanceBetween(1.0, 1.0, 2.0, 2.0));
+//        TencentLocationRequest tencentLocationRequest = TencentLocationRequest.create();
+//        System.out.println(tencentLocationRequest.getRequestLevel());
+
+//        TencentLocationUtils.distanceBetween(31.981746 ,118.734661,31.990671 , 118.754795);
+
+        List<Merchant> collect = merchantRepo.findAll().stream()
+                .filter(s -> ObjectUtil.isNotNull(s.getLongitude()) && ObjectUtil.isNotNull(s.getLatitude()))
+                .collect(Collectors.toList());
+        for (Merchant m : collect) {
+            System.out.println(m.getId() + "---->" + MapUtils.distance(118.734661, 31.981746, m.getLongitude(), m.getLatitude()));
+        }
+    }
+
+    @Test
+    public void testUrl() {
+        String key = "LQTBZ-EEUCU-UX7V4-4CY7M-NROM7-NLFI5";
+//        Map<String, Object> resultMap = new HashMap<String, Object>();
+
+        List<Merchant> collect = merchantRepo.findAll().stream()
+                .filter(s -> ObjectUtil.isNotNull(s.getLongitude()) && ObjectUtil.isNotNull(s.getLatitude()))
+                .collect(Collectors.toList());
+
+        StringBuilder add = new StringBuilder();
+        for (Merchant m : collect) {
+            System.out.println(m.getId());
+            add.append(m.getLatitude()).append(",").append(m.getLongitude()).append(";");
+        }
+        String substring = add.substring(0, add.length() - 1);
+        System.out.println(substring);
+
+        // 参数解释:lng:经度,lat:维度。KEY:腾讯地图key,get_poi:返回状态。1返回,0不返回
+        String urlString = "http://apis.map.qq.com/ws/distance/v1/matrix?model=walking&from=" + 31.981746 + "," + 118.734661 +
+                "&to=" + substring
+                + "&key=" + key;
+        System.out.println(urlString);
+        String result = "";
+        try {
+            URL url = new URL(urlString);
+            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+            conn.setDoOutput(true);
+            // 腾讯地图使用GET
+            conn.setRequestMethod("GET");
+            BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
+            String line;
+            // 获取地址解析结果
+            while ((line = in.readLine()) != null) {
+                result += line + "\n";
+            }
+            in.close();
+        } catch (Exception e) {
+            e.getMessage();
+        }
+
+        System.out.println(result);
+/*        // 转JSON格式
+        JSONObject jsonObject = JSONObject.parseObject(result);
+        // 获取地址(行政区划信息) 包含有国籍,省份,城市
+        JSONObject adInfo = jsonObject.getJSONObject("ad_info");
+        resultMap.put("nation", adInfo.get("nation"));
+        resultMap.put("nationCode", adInfo.get("nation_code"));
+        resultMap.put("province", adInfo.get("province"));
+        resultMap.put("provinceCode", adInfo.get("adcode"));
+        resultMap.put("city", adInfo.get("city"));
+        resultMap.put("cityCode", adInfo.get("city_code"));
+
+        System.out.println(resultMap);*/
+    }
+}

+ 4 - 4
src/test/java/com/izouma/dingdong/contorller/OrderInfoControllerTest.java

@@ -114,12 +114,12 @@ public class OrderInfoControllerTest {
         UserOrderDTO dto = UserOrderDTO.builder()
                 .addressId(135L)
                 .payMethod(PayMethod.ALI_PAY)
-                .shoppingCartId(1511L)
-                .remark("多加点!")
-                .userCouponId(217L)
+                .shoppingCartId(1704L)
+                //.remark("多加点!")
+                //.userCouponId(217L)
                 .build();
 
-        System.out.println(orderInfoService.userOrder(dto));
+        System.out.println(orderInfoService.userOrder(dto).getId());
     }
 
     @Test

+ 6 - 0
src/test/java/com/izouma/dingdong/service/GoodsServiceTest.java

@@ -6,6 +6,7 @@ import com.izouma.dingdong.domain.merchant.Goods;
 import com.izouma.dingdong.domain.merchant.GoodsSpecification;
 import com.izouma.dingdong.domain.merchant.MerchantClassification;
 import com.izouma.dingdong.dto.AppraisalMerDTO;
+import com.izouma.dingdong.enums.GoodType;
 import com.izouma.dingdong.exception.BusinessException;
 import com.izouma.dingdong.repo.merchant.GoodsRepo;
 import com.izouma.dingdong.repo.merchant.GoodsSpecificationRepo;
@@ -198,4 +199,9 @@ public class GoodsServiceTest {
         goodsController.save(goods);
         //goodsController.save(goods1);
     }
+
+    @Test
+    public void showAllTest(){
+        System.out.println(goodsController.showAll(GoodType.SIGNBOARD_FOOD, 118.734661, 31.981746));
+    }
 }