mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-08-17 03:31:54 +08:00
【功能完善】商城: APP 完善积分商城活动下单
This commit is contained in:
@@ -23,4 +23,14 @@ public class PointActivityApiImpl implements PointActivityApi {
|
||||
return pointActivityService.validateJoinPointActivity(activityId, skuId, count);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePointStockDecr(Long id, Long skuId, Integer count) {
|
||||
pointActivityService.updatePointStockDecr(id, skuId, count);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePointStockIncr(Long id, Long skuId, Integer count) {
|
||||
pointActivityService.updatePointStockIncr(id, skuId, count);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,10 +1,12 @@
|
||||
package cn.iocoder.yudao.module.promotion.dal.mysql.point;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.promotion.controller.admin.point.vo.activity.PointActivityPageReqVO;
|
||||
import cn.iocoder.yudao.module.promotion.dal.dataobject.point.PointActivityDO;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
@@ -25,4 +27,33 @@ public interface PointActivityMapper extends BaseMapperX<PointActivityDO> {
|
||||
.orderByDesc(PointActivityDO::getId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新活动库存(减少)
|
||||
*
|
||||
* @param id 活动编号
|
||||
* @param count 扣减的库存数量(正数)
|
||||
* @return 影响的行数
|
||||
*/
|
||||
default int updateStockDecr(Long id, int count) {
|
||||
Assert.isTrue(count > 0);
|
||||
return update(null, new LambdaUpdateWrapper<PointActivityDO>()
|
||||
.eq(PointActivityDO::getId, id)
|
||||
.ge(PointActivityDO::getStock, count)
|
||||
.setSql("stock = stock - " + count));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新活动库存(增加)
|
||||
*
|
||||
* @param id 活动编号
|
||||
* @param count 增加的库存数量(正数)
|
||||
* @return 影响的行数
|
||||
*/
|
||||
default int updateStockIncr(Long id, int count) {
|
||||
Assert.isTrue(count > 0);
|
||||
return update(null, new LambdaUpdateWrapper<PointActivityDO>()
|
||||
.eq(PointActivityDO::getId, id)
|
||||
.setSql("stock = stock + " + count));
|
||||
}
|
||||
|
||||
}
|
@@ -1,5 +1,6 @@
|
||||
package cn.iocoder.yudao.module.promotion.dal.mysql.point;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.promotion.dal.dataobject.point.PointProductDO;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
@@ -34,4 +35,32 @@ public interface PointProductMapper extends BaseMapperX<PointProductDO> {
|
||||
PointProductDO::getSkuId, skuId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新活动库存(减少)
|
||||
*
|
||||
* @param id 活动编号
|
||||
* @param count 扣减的库存数量(减少库存)
|
||||
* @return 影响的行数
|
||||
*/
|
||||
default int updateStockDecr(Long id, int count) {
|
||||
Assert.isTrue(count > 0);
|
||||
return update(null, new LambdaUpdateWrapper<PointProductDO>()
|
||||
.eq(PointProductDO::getId, id)
|
||||
.ge(PointProductDO::getStock, count)
|
||||
.setSql("stock = stock - " + count));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新活动库存(增加)
|
||||
*
|
||||
* @param id 活动编号
|
||||
* @param count 需要增加的库存(增加库存)
|
||||
* @return 影响的行数
|
||||
*/
|
||||
default int updateStockIncr(Long id, int count) {
|
||||
Assert.isTrue(count > 0);
|
||||
return update(null, new LambdaUpdateWrapper<PointProductDO>()
|
||||
.eq(PointProductDO::getId, id)
|
||||
.setSql("stock = stock + " + count));
|
||||
}
|
||||
}
|
@@ -33,6 +33,24 @@ public interface PointActivityService {
|
||||
*/
|
||||
void updatePointActivity(@Valid PointActivitySaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 更新积分商城商品库存(减少)
|
||||
*
|
||||
* @param id 活动编号
|
||||
* @param skuId sku 编号
|
||||
* @param count 数量(正数)
|
||||
*/
|
||||
void updatePointStockDecr(Long id, Long skuId, Integer count);
|
||||
|
||||
/**
|
||||
* 更新积分商城商品库存(增加)
|
||||
*
|
||||
* @param id 活动编号
|
||||
* @param skuId sku 编号
|
||||
* @param count 数量(正数)
|
||||
*/
|
||||
void updatePointStockIncr(Long id, Long skuId, Integer count);
|
||||
|
||||
/**
|
||||
* 关闭积分商城活动
|
||||
*
|
||||
|
@@ -103,6 +103,43 @@ public class PointActivityServiceImpl implements PointActivityService {
|
||||
updateSeckillProduct(updateObj, updateReqVO.getProducts());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updatePointStockDecr(Long id, Long skuId, Integer count) {
|
||||
// 1.1 校验活动库存是否充足
|
||||
PointActivityDO activity = validatePointActivityExists(id);
|
||||
if (count > activity.getStock()) {
|
||||
throw exception(POINT_ACTIVITY_UPDATE_STOCK_FAIL);
|
||||
}
|
||||
// 1.2 校验商品库存是否充足
|
||||
PointProductDO product = pointProductMapper.selectListByActivityIdAndSkuId(id, skuId);
|
||||
if (product == null || count > product.getStock()) {
|
||||
throw exception(POINT_ACTIVITY_UPDATE_STOCK_FAIL);
|
||||
}
|
||||
|
||||
// 2.1 更新活动商品库存
|
||||
int updateCount = pointProductMapper.updateStockDecr(product.getId(), count);
|
||||
if (updateCount == 0) {
|
||||
throw exception(POINT_ACTIVITY_UPDATE_STOCK_FAIL);
|
||||
}
|
||||
|
||||
// 2.2 更新活动库存
|
||||
updateCount = pointActivityMapper.updateStockDecr(id, count);
|
||||
if (updateCount == 0) {
|
||||
throw exception(POINT_ACTIVITY_UPDATE_STOCK_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updatePointStockIncr(Long id, Long skuId, Integer count) {
|
||||
PointProductDO product = pointProductMapper.selectListByActivityIdAndSkuId(id, skuId);
|
||||
// 更新活动商品库存
|
||||
pointProductMapper.updateStockIncr(product.getId(), count);
|
||||
// 更新活动库存
|
||||
pointActivityMapper.updateStockIncr(id, count);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void closePointActivity(Long id) {
|
||||
|
@@ -160,7 +160,7 @@ public class SeckillActivityServiceImpl implements SeckillActivityService {
|
||||
public void updateSeckillStockDecr(Long id, Long skuId, Integer count) {
|
||||
// 1.1 校验活动库存是否充足
|
||||
SeckillActivityDO seckillActivity = validateSeckillActivityExists(id);
|
||||
if (count > seckillActivity.getTotalStock()) {
|
||||
if (count > seckillActivity.getStock()) {
|
||||
throw exception(SECKILL_ACTIVITY_UPDATE_STOCK_FAIL);
|
||||
}
|
||||
// 1.2 校验商品库存是否充足
|
||||
|
Reference in New Issue
Block a user