|
@@ -3,10 +3,15 @@ package org.jeecg.modules.app.service.impl;
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import lombok.extern.log4j.Log4j2;
|
|
import lombok.extern.log4j.Log4j2;
|
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.shiro.SecurityUtils;
|
|
import org.apache.shiro.SecurityUtils;
|
|
|
|
+import org.jeecg.common.constant.CommonConstant;
|
|
import org.jeecg.common.exception.JeecgBootException;
|
|
import org.jeecg.common.exception.JeecgBootException;
|
|
import org.jeecg.common.system.vo.LoginUser;
|
|
import org.jeecg.common.system.vo.LoginUser;
|
|
|
|
+import org.jeecg.modules.app.form.CreateOrderForm;
|
|
|
|
+import org.jeecg.modules.app.form.InsureOrderInfoForm;
|
|
|
|
+import org.jeecg.modules.app.form.UserPayForm;
|
|
import org.jeecg.modules.app.service.IOrderService;
|
|
import org.jeecg.modules.app.service.IOrderService;
|
|
import org.jeecg.modules.app.vo.OrderVO;
|
|
import org.jeecg.modules.app.vo.OrderVO;
|
|
import org.jeecg.modules.system.app.entity.*;
|
|
import org.jeecg.modules.system.app.entity.*;
|
|
@@ -20,11 +25,9 @@ import javax.annotation.Resource;
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
import java.time.ZoneId;
|
|
import java.time.ZoneId;
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.Arrays;
|
|
|
|
-import java.util.Date;
|
|
|
|
-import java.util.List;
|
|
|
|
|
|
+import java.util.*;
|
|
import java.util.concurrent.ThreadLocalRandom;
|
|
import java.util.concurrent.ThreadLocalRandom;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
@Log4j2
|
|
@Log4j2
|
|
@@ -49,6 +52,10 @@ public class OrderServiceImpl implements IOrderService {
|
|
private FamilyMembersMapper familyMembersMapper;
|
|
private FamilyMembersMapper familyMembersMapper;
|
|
@Resource
|
|
@Resource
|
|
private AppTeachingTimeMapper appTeachingTimeMapper;
|
|
private AppTeachingTimeMapper appTeachingTimeMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private InsureOrderInfoMapper insureOrderInfoMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private AppInsureMapper appInsureMapper;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@@ -56,7 +63,7 @@ public class OrderServiceImpl implements IOrderService {
|
|
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
List<String> list = Arrays.asList(rulesId.split(","));
|
|
List<String> list = Arrays.asList(rulesId.split(","));
|
|
AppOrder order = createOrder(list, 0, user.getId(), userIds);
|
|
AppOrder order = createOrder(list, 0, user.getId(), userIds);
|
|
- if(null == order) throw new JeecgBootException("创建订单失败!");
|
|
|
|
|
|
+ if (null == order) throw new JeecgBootException("创建订单失败!");
|
|
AppSitePriceRules appSitePriceRules = appSitePriceRulesMapper.selectById(list.get(0));
|
|
AppSitePriceRules appSitePriceRules = appSitePriceRulesMapper.selectById(list.get(0));
|
|
AppSitePlace appSitePlace = appSitePlaceMapper.selectById(appSitePriceRules.getSitePlaceId());
|
|
AppSitePlace appSitePlace = appSitePlaceMapper.selectById(appSitePriceRules.getSitePlaceId());
|
|
AppSite appSite = appSiteMapper.selectById(appSitePlace.getSiteId());
|
|
AppSite appSite = appSiteMapper.selectById(appSitePlace.getSiteId());
|
|
@@ -112,7 +119,7 @@ public class OrderServiceImpl implements IOrderService {
|
|
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
OrderVO.PreviewOrderCourse previousOrderCourse = new OrderVO.PreviewOrderCourse();
|
|
OrderVO.PreviewOrderCourse previousOrderCourse = new OrderVO.PreviewOrderCourse();
|
|
AppCourses appCourses = appCoursesMapper.selectById(courseId);
|
|
AppCourses appCourses = appCoursesMapper.selectById(courseId);
|
|
- if (appCourses==null|| StringUtils.isEmpty(appCourses.getCover())){
|
|
|
|
|
|
+ if (appCourses == null || StringUtils.isEmpty(appCourses.getCover())) {
|
|
throw new JeecgBootException("未查询到课程数据");
|
|
throw new JeecgBootException("未查询到课程数据");
|
|
}
|
|
}
|
|
List<String> list = Arrays.asList(appCourses.getCover().split(","));
|
|
List<String> list = Arrays.asList(appCourses.getCover().split(","));
|
|
@@ -123,12 +130,12 @@ public class OrderServiceImpl implements IOrderService {
|
|
.setSellingPrice(appCourses.getSellingPrice())
|
|
.setSellingPrice(appCourses.getSellingPrice())
|
|
.setReminder(appCourses.getReminder())
|
|
.setReminder(appCourses.getReminder())
|
|
.setHasDiscount(checkCourseDiscount);
|
|
.setHasDiscount(checkCourseDiscount);
|
|
- if(checkCourseDiscount){
|
|
|
|
|
|
+ if (checkCourseDiscount) {
|
|
previousOrderCourse.setDiscountPrice(appCourses.getSellingPrice());
|
|
previousOrderCourse.setDiscountPrice(appCourses.getSellingPrice());
|
|
previousOrderCourse.setTotalDiscount(appCourses.getSellingPrice());
|
|
previousOrderCourse.setTotalDiscount(appCourses.getSellingPrice());
|
|
previousOrderCourse.setSubtotal(appCourses.getSellingPrice().subtract(appCourses.getSellingPrice()));
|
|
previousOrderCourse.setSubtotal(appCourses.getSellingPrice().subtract(appCourses.getSellingPrice()));
|
|
previousOrderCourse.setTotalPrice(appCourses.getSellingPrice().subtract(appCourses.getSellingPrice()));
|
|
previousOrderCourse.setTotalPrice(appCourses.getSellingPrice().subtract(appCourses.getSellingPrice()));
|
|
- }else {
|
|
|
|
|
|
+ } else {
|
|
previousOrderCourse.setDiscountPrice(BigDecimal.ZERO);
|
|
previousOrderCourse.setDiscountPrice(BigDecimal.ZERO);
|
|
previousOrderCourse.setTotalDiscount(BigDecimal.ZERO);
|
|
previousOrderCourse.setTotalDiscount(BigDecimal.ZERO);
|
|
previousOrderCourse.setSubtotal(appCourses.getSellingPrice());
|
|
previousOrderCourse.setSubtotal(appCourses.getSellingPrice());
|
|
@@ -184,11 +191,122 @@ public class OrderServiceImpl implements IOrderService {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
+ * 创建订单
|
|
|
|
+ *
|
|
|
|
+ * @param createOrderForm
|
|
|
|
+ * @return 支付订单对象
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public UserPayForm schoolPlaceOrder(CreateOrderForm createOrderForm) {
|
|
|
|
+ //获取登录用户
|
|
|
|
+ LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
|
+
|
|
|
|
+ String orderCode = generateOrderNumber(0);
|
|
|
|
+
|
|
|
|
+ //创建订单
|
|
|
|
+ AppOrder appOrder = new AppOrder();
|
|
|
|
+ appOrder
|
|
|
|
+ .setOrderCode(orderCode)
|
|
|
|
+ .setUserId(user.getId())
|
|
|
|
+ .setOrgCode(user.getOrgCode())
|
|
|
|
+ .setUserPhone(user.getPhone())
|
|
|
|
+ .setPayTime(new Date())
|
|
|
|
+ .setOrderStatus(0)
|
|
|
|
+ ;
|
|
|
|
+
|
|
|
|
+ //订单内容
|
|
|
|
+ switch (createOrderForm.getType()) {
|
|
|
|
+ //场地
|
|
|
|
+ case 0:
|
|
|
|
+ List<AppSitePriceRules> priceRules = appSitePriceRulesMapper.selectList(Wrappers.<AppSitePriceRules>lambdaQuery()
|
|
|
|
+ .in(AppSitePriceRules::getId, List.of(createOrderForm.getProductIds().split(","))));
|
|
|
|
+ //订单金额
|
|
|
|
+ BigDecimal totalPrice = priceRules.stream()
|
|
|
|
+ .map(AppSitePriceRules::getSellingPrice)
|
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
|
+
|
|
|
|
+ if (priceRules.get(0).getType() == 0) {
|
|
|
|
+ if (totalPrice.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
|
+ appOrder.setPayType(3)
|
|
|
|
+ .setOrderStatus(2)
|
|
|
|
+ .setPayTime(new Date());
|
|
|
|
+ } else {
|
|
|
|
+ appOrder.setPayType(2)
|
|
|
|
+ .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());
|
|
|
|
+ break;
|
|
|
|
+ //赛事
|
|
|
|
+ case 1:
|
|
|
|
+
|
|
|
|
+ break;
|
|
|
|
+ //课程
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ appOrderMapper.insert(appOrder);
|
|
|
|
+
|
|
|
|
+ //构建保单内容
|
|
|
|
+ InsureOrderInfoForm insureOrderInfoForm = createOrderForm.getInsureOrderInfoForm();
|
|
|
|
+ if (ObjectUtils.isNotEmpty(insureOrderInfoForm)) {
|
|
|
|
+ List<String> ids = Arrays.stream(insureOrderInfoForm.getFamilyMembersIds().split(",")).collect(Collectors.toList());
|
|
|
|
+ AppInsure appInsure = appInsureMapper.selectById(insureOrderInfoForm.getInsureId());
|
|
|
|
+ for (String id : ids) {
|
|
|
|
+ //创建保单
|
|
|
|
+ InsureOrderInfo insureOrderInfo = new InsureOrderInfo();
|
|
|
|
+ insureOrderInfo
|
|
|
|
+ .setOrderId(appOrder.getId())
|
|
|
|
+ .setBdOrderNo("0000000000")
|
|
|
|
+ .setInsureName(appInsure.getInsuranceType_dictText())
|
|
|
|
+ .setInsureCompany(appInsure.getInsuranceName_dictText())
|
|
|
|
+ .setInsureId(appInsure.getId())
|
|
|
|
+ .setMoney(insureOrderInfoForm.getMoney())
|
|
|
|
+ .setUserId(id)
|
|
|
|
+ .setAssertStartTime(insureOrderInfoForm.getAssertStartTime())
|
|
|
|
+ .setAssertEndTime(insureOrderInfoForm.getAssertEndTime())
|
|
|
|
+ .setIsEnterSystem(CommonConstant.STATUS_0_INT)
|
|
|
|
+ ;
|
|
|
|
+ insureOrderInfoMapper.insert(insureOrderInfo);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //构建支付表单返回给前端支撑支付调用
|
|
|
|
+ UserPayForm payForm = new UserPayForm();
|
|
|
|
+ payForm
|
|
|
|
+ .setOrderCode(orderCode)
|
|
|
|
+ ;
|
|
|
|
+ return payForm;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @return boolean
|
|
* @Author SheepHy
|
|
* @Author SheepHy
|
|
* @Description 查询用户对该类型课程是否有试听资格
|
|
* @Description 查询用户对该类型课程是否有试听资格
|
|
* @Date 16:45 2025/7/14
|
|
* @Date 16:45 2025/7/14
|
|
* @Param courseId userId
|
|
* @Param courseId userId
|
|
- * @return boolean
|
|
|
|
**/
|
|
**/
|
|
private boolean checkCourseDiscount(String categoryId, String userId) {
|
|
private boolean checkCourseDiscount(String categoryId, String userId) {
|
|
boolean success = Boolean.TRUE;
|
|
boolean success = Boolean.TRUE;
|
|
@@ -198,7 +316,7 @@ public class OrderServiceImpl implements IOrderService {
|
|
.ne(AppOrder::getOrderStatus, 5)
|
|
.ne(AppOrder::getOrderStatus, 5)
|
|
.eq(AppOrder::getStatus, 0)
|
|
.eq(AppOrder::getStatus, 0)
|
|
.eq(AppOrder::getDelFlag, 0)
|
|
.eq(AppOrder::getDelFlag, 0)
|
|
- .eq(AppOrder::getType,2));
|
|
|
|
|
|
+ .eq(AppOrder::getType, 2));
|
|
if (appOrders.isEmpty()) return true;
|
|
if (appOrders.isEmpty()) return true;
|
|
for (AppOrder appOrder : appOrders) {
|
|
for (AppOrder appOrder : appOrders) {
|
|
if (!appOrder.getProductIds().contains(categoryId)) {
|
|
if (!appOrder.getProductIds().contains(categoryId)) {
|
|
@@ -210,30 +328,30 @@ public class OrderServiceImpl implements IOrderService {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
+ * @return
|
|
* @Author SheepHy
|
|
* @Author SheepHy
|
|
* @Description 根据不同的类型生成订单及订单明细
|
|
* @Description 根据不同的类型生成订单及订单明细
|
|
* @Date 15:09 2025/7/15
|
|
* @Date 15:09 2025/7/15
|
|
* @Param id type userId
|
|
* @Param id type userId
|
|
- * @return
|
|
|
|
**/
|
|
**/
|
|
@Transactional
|
|
@Transactional
|
|
public AppOrder createOrder(List<String> id, int type, String userId, String userIds) {
|
|
public AppOrder createOrder(List<String> id, int type, String userId, String userIds) {
|
|
//todo 保险 闸机待接入
|
|
//todo 保险 闸机待接入
|
|
//订单类型;0场地1赛事2课程
|
|
//订单类型;0场地1赛事2课程
|
|
AppOrder appOrder = new AppOrder();
|
|
AppOrder appOrder = new AppOrder();
|
|
- switch(type){
|
|
|
|
|
|
+ switch (type) {
|
|
case 0:
|
|
case 0:
|
|
List<AppSitePriceRules> priceRules = appSitePriceRulesMapper.selectList(Wrappers.<AppSitePriceRules>lambdaQuery()
|
|
List<AppSitePriceRules> priceRules = appSitePriceRulesMapper.selectList(Wrappers.<AppSitePriceRules>lambdaQuery()
|
|
.in(AppSitePriceRules::getId, id));
|
|
.in(AppSitePriceRules::getId, id));
|
|
BigDecimal totalPrice = priceRules.stream()
|
|
BigDecimal totalPrice = priceRules.stream()
|
|
.map(AppSitePriceRules::getSellingPrice)
|
|
.map(AppSitePriceRules::getSellingPrice)
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
- if(priceRules.get(0).getType() == 0){
|
|
|
|
- if(totalPrice.compareTo(BigDecimal.ZERO) == 0){
|
|
|
|
|
|
+ if (priceRules.get(0).getType() == 0) {
|
|
|
|
+ if (totalPrice.compareTo(BigDecimal.ZERO) == 0) {
|
|
appOrder.setPayType(3)
|
|
appOrder.setPayType(3)
|
|
.setOrderStatus(2)
|
|
.setOrderStatus(2)
|
|
.setPayTime(new Date());
|
|
.setPayTime(new Date());
|
|
- }else {
|
|
|
|
|
|
+ } else {
|
|
appOrder.setPayType(2)
|
|
appOrder.setPayType(2)
|
|
.setOrderStatus(1);
|
|
.setOrderStatus(1);
|
|
}
|
|
}
|
|
@@ -255,6 +373,7 @@ public class OrderServiceImpl implements IOrderService {
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
case 1:
|
|
case 1:
|
|
|
|
+
|
|
break;
|
|
break;
|
|
case 2:
|
|
case 2:
|
|
|
|
|
|
@@ -264,27 +383,27 @@ public class OrderServiceImpl implements IOrderService {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
+ * @return String 订单号
|
|
* @Author SheepHy
|
|
* @Author SheepHy
|
|
* @Description 订单编号生成逻辑
|
|
* @Description 订单编号生成逻辑
|
|
* @Date 17:18 2025/7/15
|
|
* @Date 17:18 2025/7/15
|
|
- * @return String 订单号
|
|
|
|
**/
|
|
**/
|
|
private String generateOrderNumber(int type) {
|
|
private String generateOrderNumber(int type) {
|
|
String format = DateUtil.format(new Date(), "yyyyMMddHHmmss");
|
|
String format = DateUtil.format(new Date(), "yyyyMMddHHmmss");
|
|
int nextInt = ThreadLocalRandom.current().nextInt(1000, 10000);
|
|
int nextInt = ThreadLocalRandom.current().nextInt(1000, 10000);
|
|
- if(type == 0){
|
|
|
|
|
|
+ if (type == 0) {
|
|
return "D" + format + nextInt;
|
|
return "D" + format + nextInt;
|
|
- }else {
|
|
|
|
|
|
+ } else {
|
|
return "T" + format + nextInt;
|
|
return "T" + format + nextInt;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
+ * @return
|
|
* @Author SheepHy
|
|
* @Author SheepHy
|
|
* @Description 根据订单及购买人数生成对应券码
|
|
* @Description 根据订单及购买人数生成对应券码
|
|
* @Date 10:20 2025/7/16
|
|
* @Date 10:20 2025/7/16
|
|
* @Param
|
|
* @Param
|
|
- * @return
|
|
|
|
**/
|
|
**/
|
|
private void createOrderCoupon(String orderId, String userIds) {
|
|
private void createOrderCoupon(String orderId, String userIds) {
|
|
String lastFourDigits = orderId.substring(orderId.length() - 4);
|
|
String lastFourDigits = orderId.substring(orderId.length() - 4);
|
|
@@ -307,7 +426,7 @@ public class OrderServiceImpl implements IOrderService {
|
|
* @Date 11:57 2025/7/16
|
|
* @Date 11:57 2025/7/16
|
|
* @Param appOrder id
|
|
* @Param appOrder id
|
|
**/
|
|
**/
|
|
- private void createOrderProduct(AppOrder appOrder, List<String> id){
|
|
|
|
|
|
+ private void createOrderProduct(AppOrder appOrder, List<String> id) {
|
|
id.forEach(productId -> {
|
|
id.forEach(productId -> {
|
|
AppOrderProduct appOrderProduct = new AppOrderProduct();
|
|
AppOrderProduct appOrderProduct = new AppOrderProduct();
|
|
appOrderProduct.setOrderId(appOrder.getId())
|
|
appOrderProduct.setOrderId(appOrder.getId())
|
|
@@ -320,4 +439,25 @@ public class OrderServiceImpl implements IOrderService {
|
|
appOrderProductMapper.insert(appOrderProduct);
|
|
appOrderProductMapper.insert(appOrderProduct);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 校验是否为第一次购买当前类目的课程
|
|
|
|
+ * @param userId
|
|
|
|
+ * @param categoryId
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ 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));
|
|
|
|
+ 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;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return Boolean.FALSE;
|
|
|
|
+ }
|
|
}
|
|
}
|