Browse Source

feat(app):
1.增加子订单表及实体
2.部分订单逻辑

wzq 3 ngày trước cách đây
mục cha
commit
d798e1193c

+ 4 - 1
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/app/form/CreateOrderForm.java

@@ -21,7 +21,10 @@ public class CreateOrderForm implements Serializable {
     public Integer type;
 
     //商品IDs
-    private String productIds;
+    private String productId;
+
+    //数量
+    private Integer amount;
 
     //使用人IDs
     private String familyIds;

+ 51 - 31
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/app/service/impl/OrderServiceImpl.java

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

+ 7 - 3
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/system/app/entity/AppOrder.java

@@ -73,9 +73,13 @@ public class AppOrder implements Serializable {
     @Schema(description = "实际支付价")
     private BigDecimal price;
 	/**优惠信息*/
-	@Excel(name = "优惠信息", width = 15)
-    @Schema(description = "优惠信息")
-    private String discounts;
+	@Excel(name = "试听优惠金额", width = 15)
+    @Schema(description = "试听优惠金额")
+    private BigDecimal sDiscounts;
+    /**优惠信息*/
+    @Excel(name = "团购优惠金额", width = 15)
+    @Schema(description = "团购优惠金额")
+    private BigDecimal tDiscounts;
 	/**支付流水号*/
 	@Excel(name = "支付流水号", width = 15)
     @Schema(description = "支付流水号")

+ 97 - 0
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/system/app/entity/AppOrderProInfo.java

@@ -0,0 +1,97 @@
+package org.jeecg.modules.system.app.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableLogic;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import org.jeecgframework.poi.excel.annotation.Excel;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+
+@Data
+@TableName("nm_order_pro_info")
+@Accessors(chain = true)
+@EqualsAndHashCode(callSuper = false)
+@Schema(description="订单商品信息")
+public class AppOrderProInfo  implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    /**id*/
+    @TableId(type = IdType.ASSIGN_ID)
+    @Schema(description = "id")
+    private String id;
+
+    /**订单id*/
+    @Excel(name = "订单id", width = 15)
+    @Schema(description = "订单id")
+    private String orderId;
+
+    /**产品id;场地/赛事/课程*/
+    @Excel(name = "商品id;场地/赛事/课程", width = 15)
+    @Schema(description = "产品id;场地/赛事/课程")
+    private String productId;
+
+    /**商品名称*/
+    @Excel(name = "商品名称", width = 15)
+    @Schema(description = "商品名称")
+    private String productName;
+
+    @Schema(description = "商品类型(1-场地 2-赛事 3-课程 4-保险)")
+    private Integer type;
+    @Schema(description = "日期")
+    private Date useDate;
+    @Schema(description = "时间段")
+    private String frameTimeStr;
+    @Schema(description = "比赛日期")
+    private String gameTimeStr;
+    @Schema(description = "券号")
+    private String ticketNo;
+    @Schema(description = "原价/元")
+    private BigDecimal price;
+    @Schema(description = "订单状态")
+    private Integer orderStatus;
+    @Schema(description = "数量")
+    private Integer quantity;
+    @Schema(description = "使用人ID")
+    private String familyUserId;
+    @Schema(description = "使用人")
+    private String userName;
+    @Schema(description = "手机号")
+    private String userPhone;
+    @Schema(description = "是否试听课(0-否 1-是)")
+    private Integer orFreePro;
+
+    /**创建人;创建人*/
+    @Schema(description = "创建人;创建人")
+    private String createBy;
+    /**创建时间;创建时间*/
+    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
+    @Schema(description = "创建时间;创建时间")
+    private Date createTime;
+    /**更新人;更新人*/
+    @Schema(description = "更新人;更新人")
+    private String updateBy;
+    /**更新时间;更新时间*/
+    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
+    @Schema(description = "更新时间;更新时间")
+    private Date updateTime;
+    /**系统状态;状态(0-正常,1-冻结)*/
+    @Excel(name = "系统状态;状态(0-正常,1-冻结)", width = 15)
+    @Schema(description = "系统状态;状态(0-正常,1-冻结)")
+    private Integer status;
+    /**删除标志;删除状态(0-正常,1-已删除)*/
+    @Excel(name = "删除标志;删除状态(0-正常,1-已删除)", width = 15)
+    @Schema(description = "删除标志;删除状态(0-正常,1-已删除)")
+    @TableLogic
+    private Integer delFlag;
+}

+ 9 - 0
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/system/app/mapper/AppOrderProInfoMapper.java

@@ -0,0 +1,9 @@
+package org.jeecg.modules.system.app.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+import org.jeecg.modules.system.app.entity.AppOrderProInfo;
+
+@Mapper
+public interface AppOrderProInfoMapper extends BaseMapper<AppOrderProInfo> {
+}

+ 5 - 0
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/system/app/mapper/xml/AppOrderProInfoMapper.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="org.jeecg.modules.system.app.mapper.AppOrderProInfoMapper">
+
+</mapper>

+ 7 - 0
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/system/app/service/IAppOrderProInfoService.java

@@ -0,0 +1,7 @@
+package org.jeecg.modules.system.app.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import org.jeecg.modules.system.app.entity.AppOrderProInfo;
+
+public interface IAppOrderProInfoService extends IService<AppOrderProInfo> {
+}

+ 11 - 0
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/system/app/service/impl/AppOrderProInfoServiceImpl.java

@@ -0,0 +1,11 @@
+package org.jeecg.modules.system.app.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.jeecg.modules.system.app.entity.AppOrderProInfo;
+import org.jeecg.modules.system.app.mapper.AppOrderProInfoMapper;
+import org.jeecg.modules.system.app.service.IAppOrderProInfoService;
+import org.springframework.stereotype.Service;
+
+@Service
+public class AppOrderProInfoServiceImpl extends ServiceImpl<AppOrderProInfoMapper, AppOrderProInfo> implements IAppOrderProInfoService {
+}