From 8e5a0a5d06e8d1db27a048257c1abe0b0d8d123e Mon Sep 17 00:00:00 2001
From: jiangqs <jiangqs>
Date: 星期五, 05 五月 2023 18:48:28 +0800
Subject: [PATCH] 商户端主流程

---
 ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/constant/AppErrorConstant.java             |    3 +
 ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/domain/dto/MerSureConsumerGoodsListDto.java      |    2 
 ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/controller/business/MerConsumerController.java   |    9 ++++
 ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/domain/pojo/order/ConsumerGoods.java             |    2 
 ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/ConsumerGoodsServiceImpl.java |   38 ++++++++++++++++++
 ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/order/ConsumerGoodsService.java          |    6 +++
 ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/OrderServiceImpl.java         |    2 +
 7 files changed, 59 insertions(+), 3 deletions(-)

diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/constant/AppErrorConstant.java b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/constant/AppErrorConstant.java
index 2bc03ef..ca1ad65 100644
--- a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/constant/AppErrorConstant.java
+++ b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/constant/AppErrorConstant.java
@@ -119,4 +119,7 @@
     String SALESPRICE_MIN = "设置价格不能低于最低限价";
 
     String VERIFY_TYPE_MISS = "没有核销类型";
+
+    String BEYOND_SURP_NUM = "超过剩余次数";
+
 }
diff --git a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/controller/business/MerConsumerController.java b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/controller/business/MerConsumerController.java
index 363734a..55f761c 100644
--- a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/controller/business/MerConsumerController.java
+++ b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/controller/business/MerConsumerController.java
@@ -49,4 +49,13 @@
         consumerGoodsService.sureMerConsumerGoods(merSureConsumerGoodsDto);
         return R.ok();
     }
+
+    @RequestMapping(value = "/useMerConsumerGoods", method = RequestMethod.POST)
+    @ApiOperation(value = "消费服务商品")
+    public R useMerConsumerGoods(@RequestBody MerSureConsumerGoodsDto merSureConsumerGoodsDto) {
+        Long userId = SecurityUtils.getUserId();
+        merSureConsumerGoodsDto.setUserId(userId);
+        consumerGoodsService.useMerConsumerGoods(merSureConsumerGoodsDto);
+        return R.ok();
+    }
 }
diff --git a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/domain/dto/MerSureConsumerGoodsListDto.java b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/domain/dto/MerSureConsumerGoodsListDto.java
index cb6c7f4..1d50ef4 100644
--- a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/domain/dto/MerSureConsumerGoodsListDto.java
+++ b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/domain/dto/MerSureConsumerGoodsListDto.java
@@ -18,5 +18,5 @@
     private String consumerGoodsId;
 
     @ApiModelProperty(name = "服务次数")
-    private Integer service_num;
+    private Integer serviceNum;
 }
diff --git a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/domain/pojo/order/ConsumerGoods.java b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/domain/pojo/order/ConsumerGoods.java
index 06e167a..ec2560f 100644
--- a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/domain/pojo/order/ConsumerGoods.java
+++ b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/domain/pojo/order/ConsumerGoods.java
@@ -101,7 +101,7 @@
      * 使用时间
      */
     @TableField("use_time")
-    private String useTime;
+    private Date useTime;
 
     /**
      * 商品类型1周期2服务3体验
diff --git a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/ConsumerGoodsServiceImpl.java b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/ConsumerGoodsServiceImpl.java
index ef6f2e0..a57d362 100644
--- a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/ConsumerGoodsServiceImpl.java
+++ b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/ConsumerGoodsServiceImpl.java
@@ -3,6 +3,7 @@
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.common.core.exception.ServiceException;
 import com.ruoyi.order.domain.dto.AppConsumerPageDto;
 import com.ruoyi.order.domain.dto.MerConsumerGoodsDto;
 import com.ruoyi.order.domain.dto.MerSureConsumerGoodsDto;
@@ -13,9 +14,11 @@
 import com.ruoyi.order.domain.vo.MerConsumerGoodsVo;
 import com.ruoyi.order.mapper.order.ConsumerGoodsMapper;
 import com.ruoyi.order.service.order.ConsumerGoodsService;
+import com.ruoyi.system.api.constant.AppErrorConstant;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -72,7 +75,40 @@
             for(MerSureConsumerGoodsListDto merSureConsumerGoodsListDto : merSureConsumerGoodsListDtoList){
                 consumerGoods = this.getById(merSureConsumerGoodsListDto.getConsumerGoodsId());
                 consumerGoods.setCycleNumFlag(1);
-                consumerGoods.setServiceNum(merSureConsumerGoodsListDto.getService_num());
+                consumerGoods.setServiceNum(merSureConsumerGoodsListDto.getServiceNum());
+                this.saveOrUpdate(consumerGoods);
+            }
+        }
+    }
+
+    /**
+     * 确认商品次数
+     * @param merSureConsumerGoodsDto
+     */
+    @Override
+    public void useMerConsumerGoods(MerSureConsumerGoodsDto merSureConsumerGoodsDto){
+        List<MerSureConsumerGoodsListDto> merSureConsumerGoodsListDtoList = merSureConsumerGoodsDto.getMerSureConsumerGoodsListDtoList();
+        if(merSureConsumerGoodsListDtoList!=null && !merSureConsumerGoodsListDtoList.isEmpty()){
+            ConsumerGoods consumerGoods;
+            Integer serviceNum;
+            Integer usedNum;
+            Integer useNum;
+            Integer surpNum;
+            for(MerSureConsumerGoodsListDto merSureConsumerGoodsListDto : merSureConsumerGoodsListDtoList){
+                consumerGoods = this.getById(merSureConsumerGoodsListDto.getConsumerGoodsId());
+                serviceNum = consumerGoods.getServiceNum();
+                usedNum = consumerGoods.getUsedNum();
+                surpNum = serviceNum - usedNum;
+                useNum = merSureConsumerGoodsListDto.getServiceNum();
+                if(useNum>surpNum){
+                    throw new ServiceException(AppErrorConstant.BEYOND_SURP_NUM);
+                }
+                consumerGoods.setUsedNum(usedNum+useNum);
+                consumerGoods.setUseTime(new Date());
+                if(consumerGoods.getUsedNum()==serviceNum){
+                    consumerGoods.setServiceStatus(2);
+                    consumerGoods.setCompleteTime(new Date());
+                }
                 this.saveOrUpdate(consumerGoods);
             }
         }
diff --git a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/OrderServiceImpl.java b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/OrderServiceImpl.java
index ee5a004..126199b 100644
--- a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/OrderServiceImpl.java
+++ b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/OrderServiceImpl.java
@@ -542,6 +542,7 @@
             consumerGoods.setGoodsName(appUserOrderGoodsPageVo.getGoodsName());
             consumerGoods.setCycleNumFlag(appUserOrderGoodsPageVo.getCycleNumFlag());
             consumerGoods.setServiceNum(appUserOrderGoodsPageVo.getServiceNum());
+            consumerGoods.setUsedNum(0);
             consumerGoods.setGoodsType(appUserOrderGoodsPageVo.getGoodsType());
             consumerGoods.setCreateTime(nowTime);
             consumerGoodsService.save(consumerGoods);
@@ -744,6 +745,7 @@
             consumerGoods.setGoodsName(appUserOrderGoodsPageVo.getGoodsName());
             consumerGoods.setCycleNumFlag(appUserOrderGoodsPageVo.getCycleNumFlag());
             consumerGoods.setServiceNum(appUserOrderGoodsPageVo.getServiceNum());
+            consumerGoods.setUsedNum(0);
             consumerGoods.setGoodsType(appUserOrderGoodsPageVo.getGoodsType());
             consumerGoods.setCreateTime(new Date());
             consumerGoodsService.save(consumerGoods);
diff --git a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/order/ConsumerGoodsService.java b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/order/ConsumerGoodsService.java
index ed3abba..cb663a8 100644
--- a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/order/ConsumerGoodsService.java
+++ b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/order/ConsumerGoodsService.java
@@ -41,4 +41,10 @@
      * @param merSureConsumerGoodsDto
      */
     void sureMerConsumerGoods(MerSureConsumerGoodsDto merSureConsumerGoodsDto);
+
+    /**
+     * 确认商品次数
+     * @param merSureConsumerGoodsDto
+     */
+    void useMerConsumerGoods(MerSureConsumerGoodsDto merSureConsumerGoodsDto);
 }

--
Gitblit v1.7.1