|
@@ -5,6 +5,7 @@ import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.izouma.dingdong.converter.StringArrayConverter;
|
|
import com.izouma.dingdong.converter.StringArrayConverter;
|
|
|
import com.izouma.dingdong.domain.*;
|
|
import com.izouma.dingdong.domain.*;
|
|
|
import com.izouma.dingdong.domain.merchant.Merchant;
|
|
import com.izouma.dingdong.domain.merchant.Merchant;
|
|
|
|
|
+import com.izouma.dingdong.domain.rider.Rider;
|
|
|
import com.izouma.dingdong.domain.user.ShoppingCart;
|
|
import com.izouma.dingdong.domain.user.ShoppingCart;
|
|
|
import com.izouma.dingdong.domain.merchant.Goods;
|
|
import com.izouma.dingdong.domain.merchant.Goods;
|
|
|
import com.izouma.dingdong.domain.merchant.MerchantSettings;
|
|
import com.izouma.dingdong.domain.merchant.MerchantSettings;
|
|
@@ -15,6 +16,7 @@ import com.izouma.dingdong.dto.UserOrderDTO;
|
|
|
import com.izouma.dingdong.enums.*;
|
|
import com.izouma.dingdong.enums.*;
|
|
|
import com.izouma.dingdong.exception.BusinessException;
|
|
import com.izouma.dingdong.exception.BusinessException;
|
|
|
import com.izouma.dingdong.repo.*;
|
|
import com.izouma.dingdong.repo.*;
|
|
|
|
|
+import com.izouma.dingdong.repo.rider.RiderRepo;
|
|
|
import com.izouma.dingdong.repo.user.ShoppingCartRepo;
|
|
import com.izouma.dingdong.repo.user.ShoppingCartRepo;
|
|
|
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;
|
|
@@ -23,7 +25,9 @@ import com.izouma.dingdong.repo.user.AddressRepo;
|
|
|
import com.izouma.dingdong.repo.user.UserCouponRepo;
|
|
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 com.izouma.dingdong.service.rider.RiderService;
|
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
@@ -54,6 +58,9 @@ public class OrderInfoService {
|
|
|
private MoneyRecordRepo moneyRecordRepo;
|
|
private MoneyRecordRepo moneyRecordRepo;
|
|
|
private OrderRefundApplyService orderRefundApplyService;
|
|
private OrderRefundApplyService orderRefundApplyService;
|
|
|
private SysConfigRepo sysConfigRepo;
|
|
private SysConfigRepo sysConfigRepo;
|
|
|
|
|
+ private RiderRepo riderRepo;
|
|
|
|
|
+ private RiderService riderService;
|
|
|
|
|
+ private MerchantSettingsService merchantSettingsService;
|
|
|
|
|
|
|
|
/*
|
|
/*
|
|
|
用户下单
|
|
用户下单
|
|
@@ -216,7 +223,7 @@ public class OrderInfoService {
|
|
|
orderInfo.setReason(RefundReason.MERCHANT_REJECTION);
|
|
orderInfo.setReason(RefundReason.MERCHANT_REJECTION);
|
|
|
//退款流程
|
|
//退款流程
|
|
|
OrderRefundApply apply = orderRefundApplyService.apply(orderId, RefundReason.MERCHANT_REJECTION, null);
|
|
OrderRefundApply apply = orderRefundApplyService.apply(orderId, RefundReason.MERCHANT_REJECTION, null);
|
|
|
- orderRefundApplyService.audit(apply.getId(), true);
|
|
|
|
|
|
|
+ orderRefundApplyService.audit(apply.getId(), true, false);
|
|
|
}
|
|
}
|
|
|
return orderInfoRepo.save(orderInfo);
|
|
return orderInfoRepo.save(orderInfo);
|
|
|
}
|
|
}
|
|
@@ -282,7 +289,8 @@ public class OrderInfoService {
|
|
|
orderInfo.setUserReceivedTime(LocalDateTime.now());
|
|
orderInfo.setUserReceivedTime(LocalDateTime.now());
|
|
|
orderInfo.setStatus(OrderStatus.RATED);
|
|
orderInfo.setStatus(OrderStatus.RATED);
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+ //支付价钱
|
|
|
|
|
+ this.orderCarryOut(orderId);
|
|
|
|
|
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
@@ -311,7 +319,9 @@ public class OrderInfoService {
|
|
|
case MERCHANT:
|
|
case MERCHANT:
|
|
|
Long merchantId = merchantService.findMerchantId(userId);
|
|
Long merchantId = merchantService.findMerchantId(userId);
|
|
|
return orderInfoRepo.findAllByMerchantId(merchantId);
|
|
return orderInfoRepo.findAllByMerchantId(merchantId);
|
|
|
- // case RIDER:
|
|
|
|
|
|
|
+ case RIDER:
|
|
|
|
|
+ Rider rider = riderRepo.findByUserId(userId).orElseThrow(new BusinessException("无用户"));
|
|
|
|
|
+ return orderInfoRepo.findAllByRiderId(rider.getId());
|
|
|
}
|
|
}
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
@@ -338,18 +348,19 @@ public class OrderInfoService {
|
|
|
/*
|
|
/*
|
|
|
用户取消订单
|
|
用户取消订单
|
|
|
*/
|
|
*/
|
|
|
- public void cancel(Long id, RefundReason reason) {
|
|
|
|
|
|
|
+ public OrderInfo cancel(Long id, RefundReason reason) {
|
|
|
OrderInfo orderInfo = orderInfoRepo.findById(id).orElseThrow(new BusinessException("无订单"));
|
|
OrderInfo orderInfo = orderInfoRepo.findById(id).orElseThrow(new BusinessException("无订单"));
|
|
|
|
|
|
|
|
if (orderInfo.getStatus().equals(OrderStatus.UNPAID)) {
|
|
if (orderInfo.getStatus().equals(OrderStatus.UNPAID)) {
|
|
|
- //未支付,无退款
|
|
|
|
|
|
|
+ //未支付,无退款,直接取消
|
|
|
orderInfo.setCancel(true);
|
|
orderInfo.setCancel(true);
|
|
|
orderInfo.setReason(reason);
|
|
orderInfo.setReason(reason);
|
|
|
orderInfo.setStatus(OrderStatus.CANCELLED);
|
|
orderInfo.setStatus(OrderStatus.CANCELLED);
|
|
|
- orderInfoRepo.save(orderInfo);
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+ return orderInfoRepo.save(orderInfo);
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ //订单待评价/已完成
|
|
|
if (orderInfo.getStatus().equals(OrderStatus.RATED) || orderInfo.getStatus().equals(OrderStatus.COMPLETED)) {
|
|
if (orderInfo.getStatus().equals(OrderStatus.RATED) || orderInfo.getStatus().equals(OrderStatus.COMPLETED)) {
|
|
|
throw new BusinessException("订单已完成");
|
|
throw new BusinessException("订单已完成");
|
|
|
}
|
|
}
|
|
@@ -360,12 +371,12 @@ public class OrderInfoService {
|
|
|
OrderRefundApply apply = orderRefundApplyService.apply(id, reason, null);
|
|
OrderRefundApply apply = orderRefundApplyService.apply(id, reason, null);
|
|
|
//商家未接单,直接退
|
|
//商家未接单,直接退
|
|
|
if (MerchantStatus.NOT_RECEIVED.equals(orderInfo.getMerchantStatus())) {
|
|
if (MerchantStatus.NOT_RECEIVED.equals(orderInfo.getMerchantStatus())) {
|
|
|
- orderRefundApplyService.audit(apply.getId(), true);
|
|
|
|
|
|
|
+ orderRefundApplyService.audit(apply.getId(), true, false);
|
|
|
|
|
|
|
|
} else {//商家已接单
|
|
} else {//商家已接单
|
|
|
//骑手未接单 直接退
|
|
//骑手未接单 直接退
|
|
|
if (RiderStatus.NOT_RECEIVED.equals(orderInfo.getRiderStatus())) {
|
|
if (RiderStatus.NOT_RECEIVED.equals(orderInfo.getRiderStatus())) {
|
|
|
- orderRefundApplyService.audit(apply.getId(), true);
|
|
|
|
|
|
|
+ orderRefundApplyService.audit(apply.getId(), true, false);
|
|
|
} else {
|
|
} else {
|
|
|
//已接单,已完成,不能退 只能投诉
|
|
//已接单,已完成,不能退 只能投诉
|
|
|
if (RiderStatus.CARRY_OUT.equals(orderInfo.getRiderStatus())) {
|
|
if (RiderStatus.CARRY_OUT.equals(orderInfo.getRiderStatus())) {
|
|
@@ -378,14 +389,19 @@ public class OrderInfoService {
|
|
|
orderInfo.setCancel(true);
|
|
orderInfo.setCancel(true);
|
|
|
orderInfo.setReason(reason);
|
|
orderInfo.setReason(reason);
|
|
|
orderInfo.setStatus(OrderStatus.CANCELLED);
|
|
orderInfo.setStatus(OrderStatus.CANCELLED);
|
|
|
- orderInfoRepo.save(orderInfo);
|
|
|
|
|
|
|
+ return orderInfoRepo.save(orderInfo);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void orderCarryOut(Long orderId){
|
|
|
|
|
- OrderInfo orderInfo = orderInfoRepo.findById(orderId).orElseThrow(new BusinessException("无订单"));
|
|
|
|
|
|
|
+ /*
|
|
|
|
|
+ 用户取消 取消订单
|
|
|
|
|
+ */
|
|
|
|
|
+// public void
|
|
|
|
|
|
|
|
- //按商户Id找出用户
|
|
|
|
|
- User userMer = userRepo.findById(merchantRepo.findUserIdById(orderInfo.getMerchantId())).orElseThrow(new BusinessException("无用户"));
|
|
|
|
|
|
|
+ /*
|
|
|
|
|
+ 订单完成结算钱
|
|
|
|
|
+ */
|
|
|
|
|
+ public void orderCarryOut(Long orderId) {
|
|
|
|
|
+ OrderInfo orderInfo = orderInfoRepo.findById(orderId).orElseThrow(new BusinessException("无订单"));
|
|
|
|
|
|
|
|
//添加销量数据
|
|
//添加销量数据
|
|
|
salesService.addSale(orderInfo);
|
|
salesService.addSale(orderInfo);
|
|
@@ -394,27 +410,12 @@ public class OrderInfoService {
|
|
|
SysConfig sysConfig = sysConfigRepo.findByName("commission").orElseThrow(new BusinessException("无设置"));
|
|
SysConfig sysConfig = sysConfigRepo.findByName("commission").orElseThrow(new BusinessException("无设置"));
|
|
|
//平台抽成
|
|
//平台抽成
|
|
|
BigDecimal platform = orderInfo.getRealAmount().multiply(new BigDecimal(sysConfig.getValue()));
|
|
BigDecimal platform = orderInfo.getRealAmount().multiply(new BigDecimal(sysConfig.getValue()));
|
|
|
- //商家应得 = 减去骑手应得,减去平台抽成
|
|
|
|
|
- userMer.setMoney(userMer.getMoney().add(orderInfo.getRealAmount().subtract(orderInfo.getDeliveryAmount()).subtract(platform)));
|
|
|
|
|
- userRepo.save(userMer);
|
|
|
|
|
-
|
|
|
|
|
- //购买的user
|
|
|
|
|
- User user = userRepo.findById(orderInfo.getUserId()).orElseThrow(new BusinessException("无商户"));
|
|
|
|
|
- //记录到对账单
|
|
|
|
|
- moneyRecordRepo.save(
|
|
|
|
|
- MoneyRecord.builder()
|
|
|
|
|
- .avatar(user.getAvatar())
|
|
|
|
|
- .name(user.getNickname() + "购买")
|
|
|
|
|
- .type(FinancialType.INCOME)
|
|
|
|
|
- .time(LocalDateTime.now())
|
|
|
|
|
- .amount(orderInfo.getRealAmount())
|
|
|
|
|
- .userId(merchantRepo.findUserIdById(orderInfo.getMerchantId()))
|
|
|
|
|
- .build()
|
|
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
+ //商家应得 = 减去骑手应得,减去平台抽成
|
|
|
|
|
+ BigDecimal deserve = orderInfo.getRealAmount().subtract(orderInfo.getDeliveryAmount()).subtract(platform);
|
|
|
|
|
+ merchantSettingsService.income(orderInfo.getMerchantId(), orderInfo.getUserId(), deserve, FinancialType.INCOME);
|
|
|
|
|
|
|
|
//骑手应得
|
|
//骑手应得
|
|
|
|
|
+ riderService.income(orderInfo.getRiderId(), orderInfo.getUserId(), orderInfo.getDeliveryAmount(), FinancialType.INCOME);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|