|
|
@@ -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;
|
|
|
}
|