|
@@ -1,17 +1,17 @@
|
|
|
package com.izouma.dingdong.service;
|
|
package com.izouma.dingdong.service;
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
-import cn.hutool.core.bean.copier.CopyOptions;
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.izouma.dingdong.converter.StringArrayConverter;
|
|
import com.izouma.dingdong.converter.StringArrayConverter;
|
|
|
import com.izouma.dingdong.domain.OrderInfo;
|
|
import com.izouma.dingdong.domain.OrderInfo;
|
|
|
-import com.izouma.dingdong.domain.ShoppingCart;
|
|
|
|
|
|
|
+import com.izouma.dingdong.domain.user.ShoppingCart;
|
|
|
import com.izouma.dingdong.domain.User;
|
|
import com.izouma.dingdong.domain.User;
|
|
|
import com.izouma.dingdong.domain.merchant.Goods;
|
|
import com.izouma.dingdong.domain.merchant.Goods;
|
|
|
-import com.izouma.dingdong.domain.merchant.Merchant;
|
|
|
|
|
import com.izouma.dingdong.domain.merchant.MerchantSettings;
|
|
import com.izouma.dingdong.domain.merchant.MerchantSettings;
|
|
|
import com.izouma.dingdong.domain.user.Address;
|
|
import com.izouma.dingdong.domain.user.Address;
|
|
|
-import com.izouma.dingdong.domain.user.Coupon;
|
|
|
|
|
|
|
+import com.izouma.dingdong.domain.Coupon;
|
|
|
|
|
+import com.izouma.dingdong.domain.user.UserCoupon;
|
|
|
import com.izouma.dingdong.dto.UserOrderDTO;
|
|
import com.izouma.dingdong.dto.UserOrderDTO;
|
|
|
import com.izouma.dingdong.enums.MerchantStatus;
|
|
import com.izouma.dingdong.enums.MerchantStatus;
|
|
|
import com.izouma.dingdong.enums.OrderStatus;
|
|
import com.izouma.dingdong.enums.OrderStatus;
|
|
@@ -19,19 +19,18 @@ import com.izouma.dingdong.enums.RiderStatus;
|
|
|
import com.izouma.dingdong.exception.BusinessException;
|
|
import com.izouma.dingdong.exception.BusinessException;
|
|
|
import com.izouma.dingdong.repo.OrderGoodsSpecRepo;
|
|
import com.izouma.dingdong.repo.OrderGoodsSpecRepo;
|
|
|
import com.izouma.dingdong.repo.OrderInfoRepo;
|
|
import com.izouma.dingdong.repo.OrderInfoRepo;
|
|
|
-import com.izouma.dingdong.repo.ShoppingCartRepo;
|
|
|
|
|
|
|
+import com.izouma.dingdong.repo.user.ShoppingCartRepo;
|
|
|
import com.izouma.dingdong.repo.UserRepo;
|
|
import com.izouma.dingdong.repo.UserRepo;
|
|
|
import com.izouma.dingdong.repo.merchant.GoodsRepo;
|
|
import com.izouma.dingdong.repo.merchant.GoodsRepo;
|
|
|
import com.izouma.dingdong.repo.merchant.MerchantRepo;
|
|
import com.izouma.dingdong.repo.merchant.MerchantRepo;
|
|
|
import com.izouma.dingdong.repo.merchant.MerchantSettingsRepo;
|
|
import com.izouma.dingdong.repo.merchant.MerchantSettingsRepo;
|
|
|
import com.izouma.dingdong.repo.user.AddressRepo;
|
|
import com.izouma.dingdong.repo.user.AddressRepo;
|
|
|
-import com.izouma.dingdong.repo.user.CouponRepo;
|
|
|
|
|
|
|
+import com.izouma.dingdong.repo.CouponRepo;
|
|
|
|
|
+import com.izouma.dingdong.repo.user.UserCouponRepo;
|
|
|
import com.izouma.dingdong.service.merchant.GoodsService;
|
|
import com.izouma.dingdong.service.merchant.GoodsService;
|
|
|
import com.izouma.dingdong.service.merchant.MerchantService;
|
|
import com.izouma.dingdong.service.merchant.MerchantService;
|
|
|
-import com.izouma.dingdong.service.merchant.MerchantSettingsService;
|
|
|
|
|
import com.izouma.dingdong.service.merchant.SalesService;
|
|
import com.izouma.dingdong.service.merchant.SalesService;
|
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
|
-import me.chanjar.weixin.mp.bean.card.enums.BusinessServiceType;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.time.DayOfWeek;
|
|
import java.time.DayOfWeek;
|
|
@@ -56,6 +55,7 @@ public class OrderInfoService {
|
|
|
private MerchantService merchantService;
|
|
private MerchantService merchantService;
|
|
|
private SalesService salesService;
|
|
private SalesService salesService;
|
|
|
private MerchantRepo merchantRepo;
|
|
private MerchantRepo merchantRepo;
|
|
|
|
|
+ private UserCouponRepo userCouponRepo;
|
|
|
|
|
|
|
|
/*
|
|
/*
|
|
|
用户下单
|
|
用户下单
|
|
@@ -90,28 +90,38 @@ public class OrderInfoService {
|
|
|
orderInfo.setOrderTime(now);
|
|
orderInfo.setOrderTime(now);
|
|
|
orderInfo.setEnabled(true);
|
|
orderInfo.setEnabled(true);
|
|
|
|
|
|
|
|
- //使用优惠券(满减优惠券)
|
|
|
|
|
- if (ObjectUtil.isNotNull(userOrderDTO.getCouponId())) {
|
|
|
|
|
- Coupon coupon = couponRepo.findById(userOrderDTO.getCouponId()).orElseThrow(new BusinessException("优惠券不存在"));
|
|
|
|
|
|
|
+ //用户地址
|
|
|
|
|
+ Address address = addressRepo.findById(userOrderDTO.getAddressId()).orElseThrow(new BusinessException("地址不存在"));
|
|
|
|
|
+ //orderInfo.setUserAddress(address.getAddressName());
|
|
|
|
|
+ orderInfo.setUserAddress(JSONObject.toJSONString(address));
|
|
|
|
|
+
|
|
|
|
|
+ // 使用优惠券(满减优惠券)
|
|
|
|
|
+ if (ObjectUtil.isNotNull(userOrderDTO.getUserCouponId())) {
|
|
|
|
|
+ //Coupon coupon = couponRepo.findById(userOrderDTO.getCouponId()).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()) && !coupon.getIsUsed()) {
|
|
|
|
|
|
|
+ if (coupon.getEndDate().isAfter(now.toLocalDate()) && !userCoupon.getIsUsed()) {
|
|
|
|
|
+ //判断是否限制手机号
|
|
|
|
|
+ if (ObjectUtil.isNotNull(userCoupon.getPhone())) {
|
|
|
|
|
+ if (!address.getPhone().equals(userCoupon.getPhone())){
|
|
|
|
|
+ throw new BusinessException("限手机"+userCoupon.getPhone()+"使用");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if (coupon.getFullAmount().compareTo(cart.getGoodsTotal()) <= 0) {
|
|
if (coupon.getFullAmount().compareTo(cart.getGoodsTotal()) <= 0) {
|
|
|
//订单金额,优惠券Id
|
|
//订单金额,优惠券Id
|
|
|
orderInfo.setPackingPrice(coupon.getAmount());
|
|
orderInfo.setPackingPrice(coupon.getAmount());
|
|
|
- orderInfo.setCouponId(coupon.getId());
|
|
|
|
|
|
|
+ orderInfo.setUserCouponId(userCoupon.getId());
|
|
|
orderInfo.setRealAmount(orderInfo.getRealAmount().subtract(orderInfo.getPackingPrice()));
|
|
orderInfo.setRealAmount(orderInfo.getRealAmount().subtract(orderInfo.getPackingPrice()));
|
|
|
|
|
|
|
|
- coupon.setIsUsed(true);
|
|
|
|
|
- coupon.setUsedTime(now);
|
|
|
|
|
- couponRepo.save(coupon);
|
|
|
|
|
|
|
+ userCoupon.setIsUsed(true);
|
|
|
|
|
+ userCoupon.setUsedTime(now);
|
|
|
|
|
+ userCouponRepo.save(userCoupon);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- //用户地址
|
|
|
|
|
- Address address = addressRepo.findById(userOrderDTO.getAddressId()).orElseThrow(new BusinessException("地址不存在"));
|
|
|
|
|
- orderInfo.setUserAddress(address.getAddressName());
|
|
|
|
|
-
|
|
|
|
|
OrderInfo save = orderInfoRepo.save(orderInfo);
|
|
OrderInfo save = orderInfoRepo.save(orderInfo);
|
|
|
|
|
|
|
|
cart.getOrderGoodsSpecs().forEach(s -> {
|
|
cart.getOrderGoodsSpecs().forEach(s -> {
|
|
@@ -218,8 +228,10 @@ public class OrderInfoService {
|
|
|
*/
|
|
*/
|
|
|
public void carryOut(Long orderId, Boolean next) {
|
|
public void carryOut(Long orderId, Boolean next) {
|
|
|
if (next) {
|
|
if (next) {
|
|
|
- //userRepo.findById(userId).orElseThrow(new BusinessException("无用户"));
|
|
|
|
|
|
|
+
|
|
|
OrderInfo orderInfo = orderInfoRepo.findById(orderId).orElseThrow(new BusinessException("无订单"));
|
|
OrderInfo orderInfo = orderInfoRepo.findById(orderId).orElseThrow(new BusinessException("无订单"));
|
|
|
|
|
+ //按商户Id找出用户
|
|
|
|
|
+ User userMer = userRepo.findById(merchantRepo.findUserIdById(orderInfo.getMerchantId())).orElseThrow(new BusinessException("无用户"));
|
|
|
|
|
|
|
|
if (MerchantStatus.RECEIVED.equals(orderInfo.getMerchantStatus())) {
|
|
if (MerchantStatus.RECEIVED.equals(orderInfo.getMerchantStatus())) {
|
|
|
RiderStatus riderStatus = orderInfo.getRiderStatus();
|
|
RiderStatus riderStatus = orderInfo.getRiderStatus();
|
|
@@ -239,11 +251,13 @@ public class OrderInfoService {
|
|
|
|
|
|
|
|
//扣除金额
|
|
//扣除金额
|
|
|
|
|
|
|
|
- //商家
|
|
|
|
|
- Merchant merchant = merchantRepo.findById(orderInfo.getMerchantId()).orElseThrow(new BusinessException("商家不存在"));
|
|
|
|
|
- merchant.setMoney(merchant.getMoney().add(orderInfo.getRealAmount().subtract(orderInfo.getDeliveryAmount())));
|
|
|
|
|
|
|
+ //商家应得
|
|
|
|
|
+// Merchant merchant = merchantRepo.findById(orderInfo.getMerchantId()).orElseThrow(new BusinessException("商家不存在"));
|
|
|
|
|
+// merchant.setMoney(merchant.getMoney().add(orderInfo.getRealAmount().subtract(orderInfo.getDeliveryAmount())));
|
|
|
|
|
+ userMer.setMoney(userMer.getMoney().add(orderInfo.getRealAmount().subtract(orderInfo.getDeliveryAmount())));
|
|
|
|
|
+ userRepo.save(userMer);
|
|
|
|
|
|
|
|
- //骑手
|
|
|
|
|
|
|
+ //骑手应得
|
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
break;
|