|
@@ -56,6 +56,8 @@ public class OrderServiceImpl implements IOrderService {
|
|
|
private InsureOrderInfoMapper insureOrderInfoMapper;
|
|
|
@Resource
|
|
|
private AppInsureMapper appInsureMapper;
|
|
|
+ @Resource
|
|
|
+ private AppOrderProInfoMapper appOrderProInfoMapper;
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@@ -212,20 +214,24 @@ public class OrderServiceImpl implements IOrderService {
|
|
|
.setUserPhone(user.getPhone())
|
|
|
.setPayTime(new Date())
|
|
|
.setOrderStatus(0)
|
|
|
+ .setProductIds(createOrderForm.getProductId())
|
|
|
+ .setAmount(createOrderForm.getAmount())
|
|
|
;
|
|
|
|
|
|
+ //合同编号
|
|
|
+
|
|
|
+
|
|
|
+ List<AppOrderProInfo> proInfoList = new ArrayList<>();
|
|
|
+
|
|
|
//订单内容
|
|
|
switch (createOrderForm.getType()) {
|
|
|
//场地
|
|
|
case 0:
|
|
|
- List<AppSitePriceRules> priceRules = appSitePriceRulesMapper.selectList(Wrappers.<AppSitePriceRules>lambdaQuery()
|
|
|
- .in(AppSitePriceRules::getId, List.of(createOrderForm.getProductIds().split(","))));
|
|
|
+ AppSitePriceRules priceRule = appSitePriceRulesMapper.selectById(createOrderForm.getProductId());
|
|
|
//订单金额
|
|
|
- BigDecimal totalPrice = priceRules.stream()
|
|
|
- .map(AppSitePriceRules::getSellingPrice)
|
|
|
- .reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ BigDecimal totalPrice = priceRule.getSellingPrice().setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
|
- if (priceRules.get(0).getType() == 0) {
|
|
|
+ if (priceRule.getType() == 0) {
|
|
|
if (totalPrice.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
appOrder.setPayType(3)
|
|
|
.setOrderStatus(2)
|
|
@@ -235,16 +241,15 @@ public class OrderServiceImpl implements IOrderService {
|
|
|
.setOrderStatus(0);
|
|
|
}
|
|
|
}
|
|
|
- appOrder
|
|
|
- .setOrderCode(priceRules.get(0).getOrgCode())
|
|
|
- .setProductIds(priceRules.get(0).getSitePlaceId())
|
|
|
- .setType(0)
|
|
|
- .setOriginalPrice(totalPrice)
|
|
|
- .setPrice(totalPrice)
|
|
|
- .setCreateTime(new Date())
|
|
|
- .setUpdateTime(new Date())
|
|
|
- .setCreateBy(user.getId())
|
|
|
- .setUpdateBy(user.getId());
|
|
|
+ appOrder
|
|
|
+ .setProductIds(priceRule.getSitePlaceId())
|
|
|
+ .setType(0)
|
|
|
+ .setOriginalPrice(totalPrice)
|
|
|
+ .setPrice(totalPrice)
|
|
|
+ .setCreateTime(new Date())
|
|
|
+ .setUpdateTime(new Date())
|
|
|
+ .setCreateBy(user.getId())
|
|
|
+ .setUpdateBy(user.getId());
|
|
|
break;
|
|
|
//赛事
|
|
|
case 1:
|
|
@@ -253,20 +258,37 @@ public class OrderServiceImpl implements IOrderService {
|
|
|
//课程
|
|
|
case 2:
|
|
|
//如果当前课程商品类目是第一次购买,触发免费政策
|
|
|
- HashMap<String, Boolean> stringBooleanHashMap = new HashMap<>();
|
|
|
- List<String> productId = Arrays.stream(appOrder.getProductIds().split(",")).collect(Collectors.toList());
|
|
|
- List<AppCourses> appCourses = appCoursesMapper.selectList(Wrappers.<AppCourses>lambdaQuery().in(AppCourses::getId, productId));
|
|
|
- for (AppCourses appCours : appCourses) {
|
|
|
- Boolean b = checkOrderOrFree(user.getId(), appCours.getCategoryId());
|
|
|
- stringBooleanHashMap.put(appCours.getCategoryId(), b);
|
|
|
- }
|
|
|
+ //优惠金额
|
|
|
+ BigDecimal sDiscounts = new BigDecimal(0);
|
|
|
+ BigDecimal tDiscounts = new BigDecimal(0);
|
|
|
+ for (int i = 1; i <= createOrderForm.getAmount(); i++) {
|
|
|
|
|
|
+ AppOrderProInfo appOrderProInfo = new AppOrderProInfo();
|
|
|
+
|
|
|
+ AppCourses appCours = appCoursesMapper.selectById(appOrder.getProductIds());
|
|
|
+ Boolean flag = checkOrderOrFree(user.getId(), appCours.getCategoryId());
|
|
|
+ if (!flag && i==1){
|
|
|
+ //订单中的多个商品中的第一个商品触发免费,将金额设置为优惠金额
|
|
|
+ sDiscounts = sDiscounts.add(appCours.getSellingPrice());
|
|
|
+ appOrderProInfo.setOrFreePro(CommonConstant.STATUS_1_INT);
|
|
|
+ }
|
|
|
+ proInfoList.add(appOrderProInfo);
|
|
|
+ tDiscounts = tDiscounts.add(appCours.getOriginalPrice().subtract(appCours.getSellingPrice())).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ }
|
|
|
+ appOrder.setSDiscounts(sDiscounts);
|
|
|
+ appOrder.setTDiscounts(tDiscounts);
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
appOrderMapper.insert(appOrder);
|
|
|
|
|
|
+ //保存订单商品信息
|
|
|
+ for (AppOrderProInfo appOrderProInfo : proInfoList) {
|
|
|
+ appOrderProInfo.setOrderId(appOrder.getId());
|
|
|
+ appOrderProInfoMapper.insert(appOrderProInfo);
|
|
|
+ }
|
|
|
+
|
|
|
//构建保单内容
|
|
|
InsureOrderInfoForm insureOrderInfoForm = createOrderForm.getInsureOrderInfoForm();
|
|
|
if (ObjectUtils.isNotEmpty(insureOrderInfoForm)) {
|
|
@@ -442,20 +464,18 @@ public class OrderServiceImpl implements IOrderService {
|
|
|
|
|
|
/**
|
|
|
* 校验是否为第一次购买当前类目的课程
|
|
|
+ *
|
|
|
* @param userId
|
|
|
* @param categoryId
|
|
|
* @return
|
|
|
*/
|
|
|
- private Boolean checkOrderOrFree(String userId,String categoryId){
|
|
|
+ private Boolean checkOrderOrFree(String userId, String categoryId) {
|
|
|
//查询当前用户的所有课程订单
|
|
|
- List<AppOrder> appOrders = appOrderMapper.selectList(Wrappers.<AppOrder>lambdaQuery().eq(AppOrder::getUserId, userId).eq(AppOrder::getType,CommonConstant.ORDER_TYPE_2));
|
|
|
+ List<AppOrder> appOrders = appOrderMapper.selectList(Wrappers.<AppOrder>lambdaQuery().eq(AppOrder::getUserId, userId).eq(AppOrder::getType, CommonConstant.ORDER_TYPE_2));
|
|
|
for (AppOrder appOrder : appOrders) {
|
|
|
- List<String> productId = Arrays.stream(appOrder.getProductIds().split(",")).collect(Collectors.toList());
|
|
|
- List<AppCourses> appCourses = appCoursesMapper.selectList(Wrappers.<AppCourses>lambdaQuery().in(AppCourses::getId, productId));
|
|
|
- for (AppCourses appCours : appCourses) {
|
|
|
- if (appCours.getCategoryId().equals(categoryId)) {
|
|
|
- return Boolean.TRUE;
|
|
|
- }
|
|
|
+ AppCourses appCours = appCoursesMapper.selectById(appOrder.getProductIds());
|
|
|
+ if (appCours.getCategoryId().equals(categoryId)) {
|
|
|
+ return Boolean.TRUE;
|
|
|
}
|
|
|
}
|
|
|
return Boolean.FALSE;
|