feat:退款退库存
This commit is contained in:
1 parent
1327fac21e
commit
7d038b41ef
13 files changed
+140
-94
No files matched your search
@@ -13,6 +13,11 @@
|
||||
<artifactId>pjcloud-hardware-biz</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>lock4j-redis-template-spring-boot-starter</artifactId>
|
||||
<version>2.2.7</version>
|
||||
</dependency>
|
||||
<!--引入分布式事务-->
|
||||
<dependency>
|
||||
<groupId>com.bsd</groupId>
|
||||
@@ -145,7 +150,7 @@
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
@@ -155,7 +160,7 @@
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>io.fabric8</groupId>
|
||||
<artifactId>docker-maven-plugin</artifactId>
|
||||
|
||||
+4
-1
@@ -2,6 +2,7 @@ package com.bsd.pjcloud.hard.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.bsd.pjcloud.common.core.constant.enums.YesNoEnum;
|
||||
import com.bsd.pjcloud.hard.api.dto.hard.HandCancelCodeDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.hard.HardCreateOrderDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.order.HardOrderDto;
|
||||
@@ -55,8 +56,10 @@ public interface HardOrderService extends IService<HardOrderEntity> {
|
||||
|
||||
/**
|
||||
* 扣减库存
|
||||
*
|
||||
* @param isReduce true 扣件库存 false增加库存
|
||||
*/
|
||||
void fastenerInventory(HardOrderEntity order);
|
||||
void fastenerInventory(HardOrderEntity order, YesNoEnum isReduce);
|
||||
|
||||
/**
|
||||
* 核销硬件二维码
|
||||
|
||||
+3
-9
@@ -12,6 +12,7 @@ import com.bsd.pjcloud.admin.api.entity.SysUser;
|
||||
import com.bsd.pjcloud.admin.api.feign.RemoteDeptService;
|
||||
import com.bsd.pjcloud.admin.api.feign.RemoteUserService;
|
||||
import com.bsd.pjcloud.admin.api.utils.DataUtil;
|
||||
import com.bsd.pjcloud.common.core.constant.enums.YesNoEnum;
|
||||
import com.bsd.pjcloud.common.core.util.BeanUtils;
|
||||
import com.bsd.pjcloud.common.core.util.CollectionUtils;
|
||||
import com.bsd.pjcloud.common.core.util.R;
|
||||
@@ -126,14 +127,6 @@ public class HardAfterSaleServiceImpl extends ServiceImpl<HardAfterSaleMapper, H
|
||||
DataUtil.convertDeptList(list.getRecords(), deptList.getData());
|
||||
}
|
||||
}
|
||||
// 订单
|
||||
List<Long> orderIds = list.getRecords().stream().map(HardAfterSaleVo::getOrderId).filter(ObjectUtil::isNotEmpty).distinct().toList();
|
||||
if (ObjectUtil.isNotEmpty(orderIds)) {
|
||||
HardOrderDto hardOrderDto = new HardOrderDto();
|
||||
hardOrderDto.setOrderIds(orderIds);
|
||||
List<HardOrderEntity> orderList = hardOrderMapper.list(hardOrderDto);
|
||||
HardUtil.convertOrderList(list.getRecords(), CollectionUtils.convertMap(orderList, HardOrderEntity::getId));
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
@@ -212,7 +205,6 @@ public class HardAfterSaleServiceImpl extends ServiceImpl<HardAfterSaleMapper, H
|
||||
}
|
||||
|
||||
@Override
|
||||
@GlobalTransactional
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void refund(Long afterSaleId) {
|
||||
HardAfterSaleEntity afterSale = baseMapper.selectById(afterSaleId);
|
||||
@@ -263,6 +255,8 @@ public class HardAfterSaleServiceImpl extends ServiceImpl<HardAfterSaleMapper, H
|
||||
hardAfterSaleLogMapper.insert(saveLogObj);
|
||||
// 执行退款
|
||||
getSelf().refund(updateRefundObj.getId());
|
||||
// 退库存
|
||||
hardOrderService.fastenerInventory(order, YesNoEnum.NO);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
+2
@@ -2,6 +2,7 @@ package com.bsd.pjcloud.hard.service.impl.order;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.baomidou.lock.annotation.Lock4j;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
@@ -111,6 +112,7 @@ public class HardCarServiceImpl extends ServiceImpl<HardCarMapper, HardCarEntity
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Lock4j(keys = {"#dto.userId"})
|
||||
public void saveOrUpload(HardCarSaveOrUpdateDto dto) {
|
||||
List<HardCreateCarDto> carList = dto.getList().stream().filter(v -> v.getProductCount() > 0).toList();
|
||||
HardParentCarEntity parentCar = getParentCar(dto.getMerchantId(), dto.getUserId(), dto.getHardType());
|
||||
|
||||
+12
-8
@@ -287,6 +287,8 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
|
||||
baseMapper.insert(orderObj);
|
||||
// 钱包扣款
|
||||
if (isPay) getSelf().fastReduceBalance(orderObj);
|
||||
// 扣减库存
|
||||
getSelf().fastenerInventory(orderObj, YesNoEnum.YES);
|
||||
return orderObj.getId();
|
||||
}
|
||||
|
||||
@@ -344,7 +346,7 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
|
||||
// 是否需要创建二维码
|
||||
getSelf().generateCode(orderObj);
|
||||
// 扣减库存
|
||||
getSelf().fastenerInventory(orderObj);
|
||||
getSelf().fastenerInventory(orderObj, YesNoEnum.YES);
|
||||
return orderObj.getId();
|
||||
}
|
||||
|
||||
@@ -449,31 +451,33 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void fastenerInventory(HardOrderEntity order) {
|
||||
public void fastenerInventory(HardOrderEntity order, YesNoEnum isReduce) {
|
||||
HardTypeEnum hardTypeEnum = HardTypeEnum.valueOfByType(order.getSysType());
|
||||
HardOrderTypeEnum orderTypeEnum = HardOrderTypeEnum.valueOfByType(order.getOrderType());
|
||||
if (!ObjectUtil.isAllNotEmpty(hardTypeEnum, orderTypeEnum)) return;
|
||||
String CarErrorMsg = ObjectUtil.equals(isReduce, YesNoEnum.YES.getCode()) ? "扣减库存错误" : "恢复库存错误";
|
||||
int base = ObjectUtil.equals(isReduce, YesNoEnum.YES.getCode()) ? -1 : 1;
|
||||
// 食堂扣件库存
|
||||
if (ObjectUtil.equals(hardTypeEnum, HardTypeEnum.CANTEEN) && ObjectUtil.equals(orderTypeEnum, HardOrderTypeEnum.RESERVE)) {
|
||||
// 查询购物车
|
||||
List<HardCarEntity> carList = hardCarService.getByParentCarId(order.getParentCarId());
|
||||
if (ObjectUtil.isEmpty(carList)) throw new RuntimeException("扣减库存错误,购物车不存在");
|
||||
if (ObjectUtil.isEmpty(carList)) throw new RuntimeException(CarErrorMsg + ",购物车不存在");
|
||||
CanteenSpuUpdateStockReqDTO dto = new CanteenSpuUpdateStockReqDTO();
|
||||
List<CanteenSpuUpdateStockReqDTO.Item> list = carList.stream().map(v -> {
|
||||
CanteenSpuUpdateStockReqDTO.Item item = new CanteenSpuUpdateStockReqDTO.Item();
|
||||
item.setId(v.getProductId());
|
||||
item.setIncrCount(v.getProductCount());
|
||||
item.setIncrCount(v.getProductCount() * base);
|
||||
return item;
|
||||
}).toList();
|
||||
dto.setItems(list);
|
||||
R updateSkuStockRes = onlineCanteenSpuService.updateSkuStock(dto);
|
||||
if (updateSkuStockRes.getCode() != 0) {
|
||||
throw new RuntimeException("库存不足");
|
||||
throw new RuntimeException(CarErrorMsg);
|
||||
}
|
||||
return;
|
||||
}
|
||||
// 超市扣家库存
|
||||
if (ObjectUtil.equals(hardTypeEnum, HardTypeEnum.SUPERMARKET) && ObjectUtil.equals(orderTypeEnum, HardOrderTypeEnum.RESERVE)) {
|
||||
if (ObjectUtil.equals(hardTypeEnum, HardTypeEnum.SUPERMARKET)) {
|
||||
// 查询购物车
|
||||
List<HardCarEntity> carList = hardCarService.getByParentCarId(order.getParentCarId());
|
||||
if (ObjectUtil.isEmpty(carList)) throw new RuntimeException("扣减库存错误,购物车不存在");
|
||||
@@ -481,13 +485,13 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
|
||||
List<SupermarketSpuUpdateStockReqDTO.Item> list = carList.stream().map(v -> {
|
||||
SupermarketSpuUpdateStockReqDTO.Item item = new SupermarketSpuUpdateStockReqDTO.Item();
|
||||
item.setId(v.getProductId());
|
||||
item.setIncrCount(v.getProductCount());
|
||||
item.setIncrCount(v.getProductCount() * base);
|
||||
return item;
|
||||
}).toList();
|
||||
dto.setItems(list);
|
||||
R updateSkuStockRes = supermarketSpuService.updateSpuStock(dto);
|
||||
if (updateSkuStockRes.getCode() != 0) {
|
||||
throw new RuntimeException("扣件库存错误");
|
||||
throw new RuntimeException(CarErrorMsg);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
+20
-2
@@ -53,7 +53,7 @@
|
||||
a.update_by,
|
||||
a.update_time,
|
||||
a.del_flag,
|
||||
a.tenant_id
|
||||
a.tenant_id,
|
||||
</sql>
|
||||
|
||||
<sql id="whereA">
|
||||
@@ -64,14 +64,32 @@
|
||||
<if test="dto.orderId != null">
|
||||
and a.order_id = #{dto.orderId}
|
||||
</if>
|
||||
<if test="dto.status != null and dto.status != '' ">
|
||||
and a.status = #{dto.status}
|
||||
</if>
|
||||
<if test="dto.userIds != null and dto.userIds.size() != 0">
|
||||
and a.user_id IN
|
||||
<foreach collection="dto.userIds" item="v" open="(" close=")" separator=",">
|
||||
#{v}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="dto.createTimeList != null and dto.createTimeList.length == 2">
|
||||
and a.create_time between #{dto.createTimeList[0]} and #{pa.createTimeList[1]}
|
||||
and a.create_time between #{dto.createTimeList[0]} and #{dto.createTimeList[1]}
|
||||
</if>
|
||||
</sql>
|
||||
|
||||
<select id="scopePageJoinList" resultType="com.bsd.pjcloud.hard.api.vo.order.HardAfterSaleVo">
|
||||
<include refid="selectA"/>
|
||||
o.dept_id,
|
||||
o.dept_id as orderDeptId,
|
||||
o.hard_id as orderHardId,
|
||||
o.parent_car_id as orderParentCarId,
|
||||
o.total_price as orderTotalPrice,
|
||||
o.extra_price as orderExtraPrice,
|
||||
o.pay_price as orderPayPrice,
|
||||
o.pay_time as orderPayTime
|
||||
from hard_after_sale a
|
||||
left join hard_order o on o.id = a.order_id
|
||||
<where>
|
||||
<include refid="whereA"/>
|
||||
</where>
|
||||
|
||||
Reference in new issue
Block a user