From af25ae6a29b38b1a6ad53dbbebc2da8897757bbd Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Mon, 28 Jun 2021 10:09:54 +0800
Subject: [PATCH] modify
---
gc-shop/src/main/java/com/xzx/gc/shop/service/OrderService.java | 103 +++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 95 insertions(+), 8 deletions(-)
diff --git a/gc-shop/src/main/java/com/xzx/gc/shop/service/OrderService.java b/gc-shop/src/main/java/com/xzx/gc/shop/service/OrderService.java
index 8cb02dd..b63101c 100644
--- a/gc-shop/src/main/java/com/xzx/gc/shop/service/OrderService.java
+++ b/gc-shop/src/main/java/com/xzx/gc/shop/service/OrderService.java
@@ -8,15 +8,14 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
+import com.xzx.gc.common.utils.StringUtils;
import com.xzx.gc.common.constant.Constants;
import com.xzx.gc.common.exception.RestException;
import com.xzx.gc.common.utils.IdUtils;
import com.xzx.gc.entity.*;
import com.xzx.gc.shop.dto.*;
import com.xzx.gc.shop.mapper.*;
-import com.xzx.gc.shop.vo.ExpressInfoVo;
-import com.xzx.gc.shop.vo.QueryOrderListVo;
-import com.xzx.gc.shop.vo.ViewOrderVo;
+import com.xzx.gc.shop.vo.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -69,6 +68,12 @@
Date createdTimeEnd = model.getCreatedTimeEnd();
PageHelper.startPage(model.getPage(), model.getLimit());
List<QueryOrderListVo> maps = scoreOrderMapper.queryOrderList(name,orderNo,status,createdTimeStart,createdTimeEnd);
+ if(CollUtil.isNotEmpty(maps)){
+ for(QueryOrderListVo queryOrderListVo : maps){
+ String decode = StringUtils.decode(queryOrderListVo.getName());
+ queryOrderListVo.setName(decode);
+ }
+ }
PageInfo pageInfo = new PageInfo(maps);
int count = Convert.toInt(pageInfo.getTotal());
Map<String, Object> map = new HashMap<>();
@@ -96,17 +101,17 @@
viewOrderVo.setVoucherImgs(lists);
//2-待收货3-已收货4-已完成5-已评价,获取物流信息
Integer status = scoreOrder.getStatus() == null ? 0:scoreOrder.getStatus();
- if(ScoreOrder.STATUS_DOING == status
- || ScoreOrder.STATUS_DONE == status
- || ScoreOrder.STATUS_ON == status
- || ScoreOrder.STATUS_EVALUATE == status){
+// if(ScoreOrder.STATUS_DOING == status
+// || ScoreOrder.STATUS_DONE == status
+// || ScoreOrder.STATUS_ON == status
+// || ScoreOrder.STATUS_EVALUATE == status){
Example exampleExpress = new Example(ScoreExpressInfo.class);
Example.Criteria criteriaExpress = exampleExpress.createCriteria();
criteriaExpress.andEqualTo("orderId",id);
ScoreExpressInfo scoreExpressInfo = scoreExpressInfoMapper.selectOneByExample(exampleExpress);
ExpressInfoVo expressInfoVo = objectMapper.convertValue(scoreExpressInfo, ExpressInfoVo.class);
viewOrderVo.setExpressInfoVo(expressInfoVo);
- }
+// }
//订单详情
Example exampleDetails = new Example(ScoreOrderDetails.class);
Example.Criteria criteriaDetails = exampleDetails.createCriteria();
@@ -238,6 +243,10 @@
scoreDetails.setCurrentScore(remianScore);
scoreDetails.setChangeScore(totalPrice);
scoreDetailsMapper.insert(scoreDetails);
+
+ sku.setStock(sku.getStock() - addGoodsOrderDto.getCnt());
+ sku.setQuantity(sku.getQuantity() - addGoodsOrderDto.getCnt());
+ scoreGoodsSkuMapper.updateByPrimaryKey(sku);
}
public Long cancelOrder(CancelOrderDto model) {
@@ -250,4 +259,82 @@
scoreOrderMapper.updateByPrimaryKeySelective(scoreOrder);
return scoreOrder.getId();
}
+
+ public PageInfo<XcxOrderListVo> orderList(XcxOrderListDto xcxOrderListDto) {
+ PageHelper.startPage(xcxOrderListDto.getPageNo(), xcxOrderListDto.getPageSize());
+ List<XcxOrderListVo> data = scoreOrderMapper.selectXcxOrderList(xcxOrderListDto);
+ return new PageInfo<>(data);
+ }
+
+ public XcxOrderDetailsVo orderDetails(Long id) {
+ return scoreOrderMapper.selectXcxOrderDetails(id);
+ }
+
+ public void confirmOrder(Long id, String userId) {
+ ScoreOrder order = scoreOrderMapper.selectByPrimaryKey(id);
+ if (order == null) {
+ throw new RestException(-3, "订单不存在");
+ }
+
+ if (!order.getUserId().equals(userId)) {
+ throw new RestException(-3, "订单不存在");
+ }
+
+ if (!ScoreOrder.STATUS_ON.equals(order.getStatus())) {
+ throw new RestException(-3, "暂不能确认收货");
+ }
+
+ scoreOrderMapper.updateOrderStatus(id, ScoreOrder.STATUS_DOING, userId);
+ }
+
+ public void cancelOrder(Long id, String userId) {
+ ScoreOrder order = scoreOrderMapper.selectByPrimaryKey(id);
+ if (order == null) {
+ throw new RestException(-3, "订单不存在");
+ }
+
+ if (!order.getUserId().equals(userId)) {
+ throw new RestException(-3, "订单不存在");
+ }
+
+ if (!ScoreOrder.STATUS_READY.equals(order.getStatus())) {
+ throw new RestException(-3, "订单不能取消");
+ }
+
+ scoreOrderMapper.updateOrderStatus(id, ScoreOrder.STATUS_CANCEL, userId);
+
+
+ // 退积分
+ AccountInfo accountInfo = accountInfoMapper.selectAccountInfoByUserId(userId);
+ BigDecimal score = new BigDecimal(accountInfo.getCollectScore()).add(order.getTotalPrice()).setScale(0, BigDecimal.ROUND_DOWN);
+
+ ScoreDetails scoreDetails = new ScoreDetails();
+ scoreDetails.setOriginalScore(new BigDecimal(accountInfo.getCollectScore()));
+ scoreDetails.setCurrentScore(score);
+ scoreDetails.setChangeScore(order.getTotalPrice());
+ scoreDetails.setOrderNo(order.getOrderNo());
+ scoreDetails.setType(ScoreDetails.SCORE_TYPE_SHOPPING_RETURN);
+ scoreDetails.setCreatedTime(new Date());
+ scoreDetailsMapper.insert(scoreDetails);
+
+ accountInfo.setCollectScore(score.toString());
+ accountInfoMapper.updateByPrimaryKey(accountInfo);
+
+
+
+ // 减销量 加库存
+ List<ScoreOrderDetails> details = scoreOrderDetailsMapper.selectOrderDetailsByOrderId(order.getId());
+ if (CollUtil.isNotEmpty(details)) {
+ for (ScoreOrderDetails detail : details) {
+ ScoreGoodsSku sku = scoreGoodsSkuMapper.selectByPrimaryKey(detail.getSkuId());
+ if (sku == null) {
+ continue;
+ }
+
+ sku.setQuantity(sku.getQuantity() - detail.getCnt());
+ sku.setStock(sku.getStock() + detail.getCnt());
+ scoreGoodsSkuMapper.updateByPrimaryKey(sku);
+ }
+ }
+ }
}
--
Gitblit v1.9.1