Merge branch 'master' of https://git.dayouqiantu.cn/develop/yshop
This commit is contained in:
@ -29,24 +29,6 @@ public interface YxStoreCombinationService extends BaseService<YxStoreCombinati
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 减库存增加销量
|
||||
* @param num 数量
|
||||
* @param combinationId 拼团产品id
|
||||
*/
|
||||
void decStockIncSales(int num,Long combinationId);
|
||||
|
||||
/**
|
||||
* 增加库存 减少销量
|
||||
* @param num 数量
|
||||
* @param combinationId 拼团产品id
|
||||
*/
|
||||
void incStockDecSales(int num,Long combinationId);
|
||||
|
||||
YxStoreCombination getCombination(int id);
|
||||
|
||||
//boolean judgeCombinationStock(Long combinationId,Integer cartNum);
|
||||
|
||||
/**
|
||||
* 拼团列表
|
||||
* @param page page
|
||||
|
@ -27,21 +27,6 @@ import java.util.Map;
|
||||
*/
|
||||
public interface YxStoreSeckillService extends BaseService<YxStoreSeckill>{
|
||||
|
||||
/**
|
||||
* 退回库存减少销量
|
||||
* @param num 数量
|
||||
* @param seckillId 秒杀产品id
|
||||
*/
|
||||
void incStockDecSales(int num,Long seckillId);
|
||||
|
||||
/**
|
||||
* 减库存增加销量
|
||||
* @param num 数量
|
||||
* @param seckillId 秒杀产品id
|
||||
*/
|
||||
void decStockIncSales(int num,Long seckillId);
|
||||
|
||||
//YxStoreSeckill getSeckill(int id);
|
||||
|
||||
/**
|
||||
* 产品详情
|
||||
|
@ -134,6 +134,6 @@ public class YxStoreCombinationDto implements Serializable {
|
||||
private List<FromatDetailDto> items;
|
||||
|
||||
//sku结果集
|
||||
private List<Map<String,Object>> attrs;
|
||||
private List<ProductFormatDto> attrs;
|
||||
|
||||
}
|
||||
|
@ -131,6 +131,6 @@ public class YxStoreSeckillDto implements Serializable {
|
||||
private List<FromatDetailDto> items;
|
||||
|
||||
//sku结果集
|
||||
private List<Map<String,Object>> attrs;
|
||||
private List<ProductFormatDto> attrs;
|
||||
|
||||
}
|
||||
|
@ -58,13 +58,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
@ -97,52 +91,6 @@ public class YxStoreCombinationServiceImpl extends BaseServiceImpl<YxStoreCombin
|
||||
private YxShippingTemplatesService shippingTemplatesService;
|
||||
|
||||
|
||||
/**
|
||||
* 减库存增加销量
|
||||
* @param num 数量
|
||||
* @param combinationId 拼团产品id
|
||||
*/
|
||||
@Override
|
||||
public void decStockIncSales(int num, Long combinationId) {
|
||||
int res = yxStoreCombinationMapper.decStockIncSales(num,combinationId);
|
||||
if(res == 0) {
|
||||
throw new YshopException("拼团产品库存不足");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加库存 减少销量
|
||||
* @param num 数量
|
||||
* @param combinationId 拼团产品id
|
||||
*/
|
||||
@Override
|
||||
public void incStockDecSales(int num, Long combinationId) {
|
||||
yxStoreCombinationMapper.incStockDecSales(num,combinationId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public YxStoreCombination getCombination(int id) {
|
||||
QueryWrapper<YxStoreCombination> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("id",id).eq("is_del",0).eq("is_show",1);
|
||||
return yxStoreCombinationMapper.selectOne(wrapper);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 判断库存是否足够
|
||||
// * @param combinationId 平团产品id
|
||||
// * @param cartNum 购物车数量
|
||||
// * @return boolean
|
||||
// */
|
||||
// @Override
|
||||
// public boolean judgeCombinationStock(Long combinationId, Integer cartNum) {
|
||||
// YxStoreCombination storeCombination = this.getById(combinationId);
|
||||
// return storeCombination.getStock() >= cartNum;
|
||||
// }
|
||||
|
||||
// @Override
|
||||
// public YxStoreCombinationQueryVo getCombinationT(int id) {
|
||||
// return yxStoreCombinationMapper.getCombDetail(id);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 获取拼团详情
|
||||
@ -322,6 +270,7 @@ public class YxStoreCombinationServiceImpl extends BaseServiceImpl<YxStoreCombin
|
||||
}
|
||||
|
||||
yxStoreCombination.setPrice(BigDecimal.valueOf(resultDTO.getMinPrice()));
|
||||
yxStoreCombination.setProductPrice(BigDecimal.valueOf(resultDTO.getMinOtPrice()));
|
||||
yxStoreCombination.setCost(resultDTO.getMinCost().intValue());
|
||||
yxStoreCombination.setStock(resultDTO.getStock());
|
||||
yxStoreCombination.setImages(String.join(",", resources.getImages()));
|
||||
@ -336,14 +285,14 @@ public class YxStoreCombinationServiceImpl extends BaseServiceImpl<YxStoreCombin
|
||||
.attrHidden("")
|
||||
.detail(ListUtil.toList("默认"))
|
||||
.build();
|
||||
List<Map<String,Object>> attrs = resources.getAttrs();
|
||||
Map<String,Object> map = attrs.get(0);
|
||||
map.put("value1","规格");
|
||||
map.put("detail", MapUtil.of(new String[][] {
|
||||
{"规格", "默认"}
|
||||
}));
|
||||
List<ProductFormatDto> attrs = resources.getAttrs();
|
||||
ProductFormatDto productFormatDto = attrs.get(0);
|
||||
productFormatDto.setValue1("规格");
|
||||
Map<String,String> map = new HashMap<>();
|
||||
map.put("规格","默认");
|
||||
productFormatDto.setDetail(map);
|
||||
yxStoreProductAttrService.insertYxStoreProductAttr(ListUtil.toList(fromatDetailDto),
|
||||
ListUtil.toList(map),resources.getProductId());
|
||||
ListUtil.toList(productFormatDto),resources.getProductId());
|
||||
}else{
|
||||
yxStoreProductAttrService.insertYxStoreProductAttr(resources.getItems(),
|
||||
resources.getAttrs(),resources.getProductId());
|
||||
@ -357,27 +306,27 @@ public class YxStoreCombinationServiceImpl extends BaseServiceImpl<YxStoreCombin
|
||||
* @param attrs attrs
|
||||
* @return ProductResultDto
|
||||
*/
|
||||
private ProductResultDto computedProduct(List<Map<String,Object>> attrs){
|
||||
private ProductResultDto computedProduct(List<ProductFormatDto> attrs){
|
||||
//取最小价格
|
||||
Double minPrice = ListMapToListBean(attrs)
|
||||
Double minPrice = attrs
|
||||
.stream()
|
||||
.map(ProductFormatDto::getPinkPrice)
|
||||
.min(Comparator.naturalOrder())
|
||||
.orElse(0d);
|
||||
|
||||
Double minOtPrice = ListMapToListBean(attrs)
|
||||
Double minOtPrice = attrs
|
||||
.stream()
|
||||
.map(ProductFormatDto::getOtPrice)
|
||||
.min(Comparator.naturalOrder())
|
||||
.orElse(0d);
|
||||
|
||||
Double minCost = ListMapToListBean(attrs)
|
||||
Double minCost = attrs
|
||||
.stream()
|
||||
.map(ProductFormatDto::getCost)
|
||||
.min(Comparator.naturalOrder())
|
||||
.orElse(0d);
|
||||
//计算库存
|
||||
Integer stock = ListMapToListBean(attrs)
|
||||
Integer stock = attrs
|
||||
.stream()
|
||||
.map(ProductFormatDto::getPinkStock)
|
||||
.reduce(Integer::sum)
|
||||
|
@ -78,28 +78,7 @@ public class YxStoreSeckillServiceImpl extends BaseServiceImpl<YxStoreSeckillMap
|
||||
|
||||
@Autowired
|
||||
private YxShippingTemplatesService shippingTemplatesService;
|
||||
/**
|
||||
* 退回库存减少销量
|
||||
* @param num 数量
|
||||
* @param seckillId 秒杀产品id
|
||||
*/
|
||||
@Override
|
||||
public void incStockDecSales(int num, Long seckillId) {
|
||||
yxStoreSeckillMapper.incStockDecSales(num,seckillId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 减库存增加销量
|
||||
* @param num 数量
|
||||
* @param seckillId 秒杀产品id
|
||||
*/
|
||||
@Override
|
||||
public void decStockIncSales(int num, Long seckillId) {
|
||||
int res = yxStoreSeckillMapper.decStockIncSales(num,seckillId);
|
||||
if(res == 0) {
|
||||
throw new YshopException("秒杀产品库存不足");
|
||||
}
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public YxStoreSeckill getSeckill(int id) {
|
||||
@ -274,6 +253,7 @@ public class YxStoreSeckillServiceImpl extends BaseServiceImpl<YxStoreSeckillMap
|
||||
}
|
||||
|
||||
yxStoreSeckill.setStock(resultDTO.getStock());
|
||||
yxStoreSeckill.setOtPrice(BigDecimal.valueOf(resultDTO.getMinOtPrice()));
|
||||
yxStoreSeckill.setPostage(BigDecimal.valueOf(resultDTO.getMinPrice()));
|
||||
yxStoreSeckill.setCost(BigDecimal.valueOf(resultDTO.getMinCost()));
|
||||
yxStoreSeckill.setStock(resultDTO.getStock());
|
||||
@ -289,14 +269,14 @@ public class YxStoreSeckillServiceImpl extends BaseServiceImpl<YxStoreSeckillMap
|
||||
.attrHidden("")
|
||||
.detail(ListUtil.toList("默认"))
|
||||
.build();
|
||||
List<Map<String,Object>> attrs = resources.getAttrs();
|
||||
Map<String,Object> map = attrs.get(0);
|
||||
map.put("value1","规格");
|
||||
map.put("detail", MapUtil.of(new String[][] {
|
||||
{"规格", "默认"}
|
||||
}));
|
||||
List<ProductFormatDto> attrs = resources.getAttrs();
|
||||
ProductFormatDto productFormatDto = attrs.get(0);
|
||||
productFormatDto.setValue1("规格");
|
||||
Map<String,String> map = new HashMap<>();
|
||||
map.put("规格","默认");
|
||||
productFormatDto.setDetail(map);
|
||||
yxStoreProductAttrService.insertYxStoreProductAttr(ListUtil.toList(fromatDetailDto),
|
||||
ListUtil.toList(map),resources.getProductId());
|
||||
ListUtil.toList(productFormatDto),resources.getProductId());
|
||||
}else{
|
||||
yxStoreProductAttrService.insertYxStoreProductAttr(resources.getItems(),
|
||||
resources.getAttrs(),resources.getProductId());
|
||||
@ -309,27 +289,27 @@ public class YxStoreSeckillServiceImpl extends BaseServiceImpl<YxStoreSeckillMap
|
||||
* @param attrs attrs
|
||||
* @return ProductResultDto
|
||||
*/
|
||||
private ProductResultDto computedProduct(List<Map<String,Object>> attrs){
|
||||
private ProductResultDto computedProduct(List<ProductFormatDto> attrs){
|
||||
//取最小价格
|
||||
Double minPrice = ListMapToListBean(attrs)
|
||||
Double minPrice = attrs
|
||||
.stream()
|
||||
.map(ProductFormatDto::getSeckillPrice)
|
||||
.min(Comparator.naturalOrder())
|
||||
.orElse(0d);
|
||||
|
||||
Double minOtPrice = ListMapToListBean(attrs)
|
||||
Double minOtPrice = attrs
|
||||
.stream()
|
||||
.map(ProductFormatDto::getOtPrice)
|
||||
.min(Comparator.naturalOrder())
|
||||
.orElse(0d);
|
||||
|
||||
Double minCost = ListMapToListBean(attrs)
|
||||
Double minCost = attrs
|
||||
.stream()
|
||||
.map(ProductFormatDto::getCost)
|
||||
.min(Comparator.naturalOrder())
|
||||
.orElse(0d);
|
||||
//计算库存
|
||||
Integer stock = ListMapToListBean(attrs)
|
||||
Integer stock = attrs
|
||||
.stream()
|
||||
.map(ProductFormatDto::getSeckillStock)
|
||||
.reduce(Integer::sum)
|
||||
@ -347,17 +327,4 @@ public class YxStoreSeckillServiceImpl extends BaseServiceImpl<YxStoreSeckillMap
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* mapTobean
|
||||
* @param listMap listMap
|
||||
* @return list
|
||||
*/
|
||||
private List<ProductFormatDto> ListMapToListBean(List<Map<String, Object>> listMap){
|
||||
List<ProductFormatDto> list = new ArrayList<>();
|
||||
// 循环遍历出map对象
|
||||
for (Map<String, Object> m : listMap) {
|
||||
list.add(BeanUtil.mapToBean(m,ProductFormatDto.class,true));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
@ -26,13 +26,6 @@ import java.util.List;
|
||||
*/
|
||||
@Repository
|
||||
public interface YxStoreCombinationMapper extends CoreMapper<YxStoreCombination> {
|
||||
@Update("update yx_store_combination set stock=stock-#{num}, sales=sales+#{num}" +
|
||||
" where id=#{combinationId} and stock >= #{num}")
|
||||
int decStockIncSales(@Param("num") int num, @Param("combinationId") Long combinationId);
|
||||
|
||||
@Update("update yx_store_combination set stock=stock+#{num}, sales=sales-#{num}" +
|
||||
" where id=#{combinationId}")
|
||||
int incStockDecSales(@Param("num") int num,@Param("combinationId") Long combinationId);
|
||||
|
||||
@Select("SELECT c.id,c.effective_time as effectiveTime,c.image,c.people,c.price, s.sales as sales," +
|
||||
"c.title,c.unit_name as unitName,s.price as productPrice FROM yx_store_combination c " +
|
||||
|
@ -22,13 +22,6 @@ import org.springframework.stereotype.Repository;
|
||||
*/
|
||||
@Repository
|
||||
public interface YxStoreSeckillMapper extends CoreMapper<YxStoreSeckill> {
|
||||
@Update("update yx_store_seckill set stock=stock+#{num}, sales=sales-#{num}" +
|
||||
" where id=#{seckillId}")
|
||||
int incStockDecSales(@Param("num") int num, @Param("seckillId") Long seckillId);
|
||||
|
||||
@Update("update yx_store_seckill set stock=stock-#{num}, sales=sales+#{num}" +
|
||||
" where id=#{seckillId} and stock >= #{num}")
|
||||
int decStockIncSales(@Param("num") int num,@Param("seckillId") Long seckillId);
|
||||
|
||||
@Select("SELECT c.id,c.image,c.price,c.title as storeName,c.is_show as isShow,c.cost," +
|
||||
"c.is_postage as isPostage,c.postage,c.sales,c.stock,c.is_del as isDel" +
|
||||
|
@ -639,9 +639,6 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<StoreOrderMapper, Y
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 确认订单退款
|
||||
* @param orderId 单号
|
||||
@ -1162,6 +1159,7 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<StoreOrderMapper, Y
|
||||
Date today = DateUtil.beginOfDay(new Date());
|
||||
Date yesterday = DateUtil.beginOfDay(DateUtil.yesterday());
|
||||
Date nowMonth = DateUtil.beginOfMonth(new Date());
|
||||
Date lastWeek = DateUtil.beginOfDay(DateUtil.lastWeek());
|
||||
|
||||
ShoperOrderTimeDataVo orderTimeDataVo = new ShoperOrderTimeDataVo();
|
||||
|
||||
@ -1196,6 +1194,17 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<StoreOrderMapper, Y
|
||||
//本月订单数
|
||||
orderTimeDataVo.setMonthCount(yxStoreOrderMapper.selectCount(wrapperThree));
|
||||
|
||||
//上周成交额
|
||||
QueryWrapper<YxStoreOrder> wrapperLastWeek = new QueryWrapper<>();
|
||||
wrapperLastWeek.lambda()
|
||||
.lt(YxStoreOrder::getPayTime,today)
|
||||
.ge(YxStoreOrder::getPayTime,lastWeek)
|
||||
.eq(YxStoreOrder::getPaid,OrderInfoEnum.PAY_STATUS_1.getValue())
|
||||
.eq(YxStoreOrder::getRefundStatus,OrderInfoEnum.REFUND_STATUS_0.getValue());
|
||||
orderTimeDataVo.setLastWeekPrice(yxStoreOrderMapper.todayPrice(wrapperLastWeek));
|
||||
//上周订单数
|
||||
orderTimeDataVo.setLastWeekCount(yxStoreOrderMapper.selectCount(wrapperLastWeek));
|
||||
|
||||
|
||||
return orderTimeDataVo;
|
||||
}
|
||||
@ -1581,7 +1590,7 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<StoreOrderMapper, Y
|
||||
storeCartVO.getProductAttrUnique(),combinationId,"combination");
|
||||
}else if(seckillId != null && seckillId > 0){
|
||||
productService.decProductStock(storeCartVO.getCartNum(),storeCartVO.getProductId(),
|
||||
storeCartVO.getProductAttrUnique(),combinationId,"seckill");
|
||||
storeCartVO.getProductAttrUnique(),seckillId,"seckill");
|
||||
}else if(bargainId != null && bargainId > 0){
|
||||
storeBargainService.decStockIncSales(storeCartVO.getCartNum(),bargainId);
|
||||
} else {
|
||||
@ -1673,14 +1682,14 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<StoreOrderMapper, Y
|
||||
YxStoreCartQueryVo cart = JSONObject.parseObject(cartInfo.getCartInfo()
|
||||
,YxStoreCartQueryVo.class);
|
||||
if(order.getCombinationId() != null && order.getCombinationId() > 0){//拼团
|
||||
combinationService.incStockDecSales(cart.getCartNum(),order.getCombinationId());
|
||||
productService.incProductStock(cart.getCartNum(),cart.getProductId(),cart.getProductAttrUnique(),order.getCombinationId(),"combination");
|
||||
}else if(order.getSeckillId() != null && order.getSeckillId() > 0){//秒杀
|
||||
storeSeckillService.incStockDecSales(cart.getCartNum(),order.getSeckillId());
|
||||
productService.incProductStock(cart.getCartNum(),cart.getProductId(),cart.getProductAttrUnique(),order.getSeckillId(),"seckill");
|
||||
}else if(order.getBargainId() != null && order.getBargainId() > 0){//砍价
|
||||
storeBargainService.incStockDecSales(cart.getCartNum(),order.getBargainId());
|
||||
}else{
|
||||
productService.incProductStock(cart.getCartNum(),cart.getProductId()
|
||||
,cart.getProductAttrUnique());
|
||||
,cart.getProductAttrUnique(),0L,null);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,10 +11,28 @@ import java.io.Serializable;
|
||||
**/
|
||||
@Data
|
||||
public class ShoperOrderTimeDataVo implements Serializable {
|
||||
private Double todayPrice; //今日成交额
|
||||
private Integer todayCount; //今日订单数
|
||||
private Double proPrice; //昨日成交额
|
||||
private Integer proCount;//昨日订单数
|
||||
private Double monthPrice;//本月成交额
|
||||
private Integer monthCount;//本月订单数
|
||||
|
||||
/**今日成交额*/
|
||||
private Double todayPrice;
|
||||
|
||||
/**今日订单数*/
|
||||
private Integer todayCount;
|
||||
|
||||
/**昨日成交额*/
|
||||
private Double proPrice;
|
||||
|
||||
/**昨日订单数*/
|
||||
private Integer proCount;
|
||||
|
||||
/**本月成交额*/
|
||||
private Double monthPrice;
|
||||
|
||||
/**本月订单数*/
|
||||
private Integer monthCount;
|
||||
|
||||
/**上周订单数*/
|
||||
private Integer lastWeekCount;
|
||||
|
||||
/**上周成交额*/
|
||||
private Double lastWeekPrice;
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import co.yixiang.common.service.BaseService;
|
||||
import co.yixiang.modules.product.domain.YxStoreProductAttr;
|
||||
import co.yixiang.modules.product.domain.YxStoreProductAttrValue;
|
||||
import co.yixiang.modules.product.service.dto.FromatDetailDto;
|
||||
import co.yixiang.modules.product.service.dto.ProductFormatDto;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -29,7 +30,7 @@ public interface YxStoreProductAttrService extends BaseService<YxStoreProductAt
|
||||
* @param productId 商品id
|
||||
* @param unique sku唯一值
|
||||
*/
|
||||
void incProductAttrStock(Integer num, Long productId, String unique);
|
||||
void incProductAttrStock(Integer num, Long productId, String unique,String type);
|
||||
|
||||
/**
|
||||
* 减少库存增加销量
|
||||
@ -60,6 +61,6 @@ public interface YxStoreProductAttrService extends BaseService<YxStoreProductAt
|
||||
* @param attrs value
|
||||
* @param productId 商品id
|
||||
*/
|
||||
void insertYxStoreProductAttr(List<FromatDetailDto> items, List<Map<String,Object>> attrs,
|
||||
void insertYxStoreProductAttr(List<FromatDetailDto> items, List<ProductFormatDto> attrs,
|
||||
Long productId);
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ public interface YxStoreProductService extends BaseService<YxStoreProduct>{
|
||||
* @param productId 商品id
|
||||
* @param unique sku唯一值
|
||||
*/
|
||||
void incProductStock(Integer num, Long productId, String unique);
|
||||
void incProductStock(Integer num, Long productId, String unique,Long activityId, String type);
|
||||
|
||||
/**
|
||||
* 减少库存与增加销量
|
||||
|
@ -12,7 +12,7 @@ import java.util.Map;
|
||||
|
||||
/**
|
||||
* 商品对象VO
|
||||
*
|
||||
*
|
||||
* @author hupeng
|
||||
* @date 2020-04-25
|
||||
*/
|
||||
@ -138,7 +138,7 @@ public class ProductDto
|
||||
|
||||
private List<FromatDetailDto> items;
|
||||
|
||||
private List<Map<String,Object>> attrs;
|
||||
private List<ProductFormatDto> attrs;
|
||||
|
||||
|
||||
|
||||
|
@ -13,7 +13,7 @@ import java.util.Map;
|
||||
|
||||
/**
|
||||
* 商品对象DTO
|
||||
*
|
||||
*
|
||||
* @author hupeng
|
||||
* @date 2020-04-23
|
||||
*/
|
||||
@ -140,7 +140,7 @@ public class StoreProductDto
|
||||
private List<FromatDetailDto> items;
|
||||
|
||||
//sku结果集
|
||||
private List<Map<String,Object>> attrs;
|
||||
private List<ProductFormatDto> attrs;
|
||||
|
||||
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ import co.yixiang.api.BusinessException;
|
||||
import co.yixiang.api.YshopException;
|
||||
import co.yixiang.common.service.impl.BaseServiceImpl;
|
||||
import co.yixiang.dozer.service.IGenerator;
|
||||
import co.yixiang.exception.BadRequestException;
|
||||
import co.yixiang.modules.product.domain.YxStoreProductAttr;
|
||||
import co.yixiang.modules.product.domain.YxStoreProductAttrValue;
|
||||
import co.yixiang.modules.product.service.YxStoreProductAttrResultService;
|
||||
@ -72,7 +73,7 @@ public class YxStoreProductAttrServiceImpl extends BaseServiceImpl<StoreProductA
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void insertYxStoreProductAttr(List<FromatDetailDto> items, List<Map<String,Object>> attrs,
|
||||
public void insertYxStoreProductAttr(List<FromatDetailDto> items, List<ProductFormatDto> attrs,
|
||||
Long productId)
|
||||
{
|
||||
List<YxStoreProductAttr> attrGroup = new ArrayList<>();
|
||||
@ -88,11 +89,11 @@ public class YxStoreProductAttrServiceImpl extends BaseServiceImpl<StoreProductA
|
||||
|
||||
|
||||
List<YxStoreProductAttrValue> valueGroup = new ArrayList<>();
|
||||
for (Map<String, Object> m : attrs) {
|
||||
ProductFormatDto productFormatDto = BeanUtil.mapToBean(m,ProductFormatDto.class,true);
|
||||
// List<String> stringList = productFormatDto.getDetail().values()
|
||||
// .stream()
|
||||
// .collect(Collectors.toList());
|
||||
for (ProductFormatDto productFormatDto : attrs) {
|
||||
|
||||
if(productFormatDto.getPinkStock()>productFormatDto.getStock() || productFormatDto.getSeckillStock()>productFormatDto.getStock()){
|
||||
throw new BadRequestException("活动商品库存不能大于原有商品库存");
|
||||
}
|
||||
List<String> stringList = new ArrayList<>(productFormatDto.getDetail().values());
|
||||
Collections.sort(stringList);
|
||||
|
||||
@ -162,12 +163,19 @@ public class YxStoreProductAttrServiceImpl extends BaseServiceImpl<StoreProductA
|
||||
* @param unique sku唯一值
|
||||
*/
|
||||
@Override
|
||||
public void incProductAttrStock(Integer num, Long productId, String unique) {
|
||||
yxStoreProductAttrValueMapper.incStockDecSales(num,productId,unique);
|
||||
public void incProductAttrStock(Integer num, Long productId, String unique, String type ) {
|
||||
|
||||
if("combination".equals(type)){
|
||||
yxStoreProductAttrValueMapper.incCombinationStockDecSales(num,productId,unique);
|
||||
}else if("seckill".equals(type)){
|
||||
yxStoreProductAttrValueMapper.incSeckillStockDecSales(num,productId,unique);
|
||||
}else {
|
||||
yxStoreProductAttrValueMapper.incStockDecSales(num,productId,unique);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 减少库存增加销量
|
||||
* 减少库存增加销量(针对sku操作)
|
||||
* @param num 数量
|
||||
* @param productId 商品id
|
||||
* @param unique sku唯一值
|
||||
|
@ -89,11 +89,8 @@ public class YxStoreProductServiceImpl extends BaseServiceImpl<StoreProductMappe
|
||||
|
||||
@Autowired
|
||||
private IGenerator generator;
|
||||
|
||||
@Autowired
|
||||
private StoreProductMapper storeProductMapper;
|
||||
|
||||
|
||||
@Autowired
|
||||
private YxStoreCategoryService yxStoreCategoryService;
|
||||
@Autowired
|
||||
@ -120,11 +117,20 @@ public class YxStoreProductServiceImpl extends BaseServiceImpl<StoreProductMappe
|
||||
* @param unique sku唯一值
|
||||
*/
|
||||
@Override
|
||||
public void incProductStock(Integer num, Long productId, String unique) {
|
||||
public void incProductStock(Integer num, Long productId, String unique,Long activityId, String type) {
|
||||
//处理属性sku
|
||||
if(StrUtil.isNotEmpty(unique)){
|
||||
yxStoreProductAttrService.incProductAttrStock(num,productId,unique);
|
||||
yxStoreProductAttrService.incProductAttrStock(num,productId,unique,type);
|
||||
}
|
||||
storeProductMapper.incStockDecSales(num,productId);
|
||||
//先处理商品库存,活动商品也要处理,因为共享库存
|
||||
storeProductMapper.incStockDecSales(num, productId);
|
||||
//处理商品外层显示的库存
|
||||
if("combination".equals(type)){
|
||||
storeProductMapper.incCombinationStockIncSales(num,productId,activityId);
|
||||
}else if("seckill".equals(type)){
|
||||
storeProductMapper.incSeckillStockIncSales(num,productId,activityId);
|
||||
}
|
||||
//todo 处理砍价商品库存
|
||||
}
|
||||
|
||||
/**
|
||||
@ -135,18 +141,23 @@ public class YxStoreProductServiceImpl extends BaseServiceImpl<StoreProductMappe
|
||||
*/
|
||||
@Override
|
||||
public void decProductStock(int num, Long productId, String unique,Long activityId,String type) {
|
||||
//处理属性sku
|
||||
if(StrUtil.isNotEmpty(unique)){
|
||||
yxStoreProductAttrService.decProductAttrStock(num,productId,unique, type);
|
||||
}
|
||||
//先处理商品库存,活动商品也要处理,因为共享库存
|
||||
int product = storeProductMapper.decStockIncSales(num,productId);
|
||||
if(product == 0) {
|
||||
throw new YshopException("商品库存不足");
|
||||
}
|
||||
//处理商品外层显示的库存
|
||||
int res = 0;
|
||||
if("combination".equals(type)){
|
||||
res = storeProductMapper.decCombinationStockIncSales(num,productId,activityId);
|
||||
}else if("seckill".equals(type)){
|
||||
res = storeProductMapper.decSeckillStockIncSales(num,productId,activityId);
|
||||
}else {
|
||||
res = storeProductMapper.decStockIncSales(num,productId);
|
||||
}
|
||||
|
||||
//todo 处理砍价库存
|
||||
if(res == 0) {
|
||||
throw new YshopException("商品库存不足");
|
||||
}
|
||||
@ -523,17 +534,17 @@ public class YxStoreProductServiceImpl extends BaseServiceImpl<StoreProductMappe
|
||||
.attrHidden("")
|
||||
.detail(ListUtil.toList("默认"))
|
||||
.build();
|
||||
List<Map<String,Object>> attrs = storeProductDto.getAttrs();
|
||||
Map<String,Object> map = attrs.get(0);
|
||||
map.put("value1","规格");
|
||||
map.put("detail", MapUtil.of(new String[][] {
|
||||
{"规格", "默认"}
|
||||
}));
|
||||
List<ProductFormatDto> attrs = storeProductDto.getAttrs();
|
||||
ProductFormatDto productFormatDto = attrs.get(0);
|
||||
productFormatDto.setValue1("规格");
|
||||
Map<String,String> map = new HashMap<>();
|
||||
map.put("规格","默认");
|
||||
productFormatDto.setDetail(map);
|
||||
yxStoreProductAttrService.insertYxStoreProductAttr(ListUtil.toList(fromatDetailDto),
|
||||
ListUtil.toList(map),yxStoreProduct.getId());
|
||||
ListUtil.toList(productFormatDto),storeProductDto.getId());
|
||||
}else{
|
||||
yxStoreProductAttrService.insertYxStoreProductAttr(storeProductDto.getItems(),
|
||||
storeProductDto.getAttrs(),yxStoreProduct.getId());
|
||||
storeProductDto.getAttrs(),storeProductDto.getId());
|
||||
}
|
||||
|
||||
|
||||
@ -677,27 +688,27 @@ public class YxStoreProductServiceImpl extends BaseServiceImpl<StoreProductMappe
|
||||
* @param attrs attrs
|
||||
* @return ProductResultDto
|
||||
*/
|
||||
private ProductResultDto computedProduct(List<Map<String,Object>> attrs){
|
||||
private ProductResultDto computedProduct(List<ProductFormatDto> attrs){
|
||||
//取最小价格
|
||||
Double minPrice = ListMapToListBean(attrs)
|
||||
Double minPrice = attrs
|
||||
.stream()
|
||||
.map(ProductFormatDto::getPrice)
|
||||
.min(Comparator.naturalOrder())
|
||||
.orElse(0d);
|
||||
|
||||
Double minOtPrice = ListMapToListBean(attrs)
|
||||
Double minOtPrice = attrs
|
||||
.stream()
|
||||
.map(ProductFormatDto::getOtPrice)
|
||||
.min(Comparator.naturalOrder())
|
||||
.orElse(0d);
|
||||
|
||||
Double minCost = ListMapToListBean(attrs)
|
||||
Double minCost = attrs
|
||||
.stream()
|
||||
.map(ProductFormatDto::getCost)
|
||||
.min(Comparator.naturalOrder())
|
||||
.orElse(0d);
|
||||
//计算库存
|
||||
Integer stock = ListMapToListBean(attrs)
|
||||
Integer stock = attrs
|
||||
.stream()
|
||||
.map(ProductFormatDto::getStock)
|
||||
.reduce(Integer::sum)
|
||||
|
@ -22,24 +22,77 @@ import org.springframework.stereotype.Repository;
|
||||
@Repository
|
||||
public interface StoreProductAttrValueMapper extends CoreMapper<YxStoreProductAttrValue> {
|
||||
|
||||
@Select("select sum(stock) from yx_store_product_attr_value " +
|
||||
"where product_id = #{productId}")
|
||||
Integer sumStock(long productId);
|
||||
|
||||
/**
|
||||
* 正常商品 加库存 减销量
|
||||
* @param num
|
||||
* @param productId
|
||||
* @param unique
|
||||
* @return
|
||||
*/
|
||||
@Update("update yx_store_product_attr_value set stock=stock+#{num}, sales=sales-#{num}" +
|
||||
" where product_id=#{productId} and `unique`=#{unique}")
|
||||
int incStockDecSales(@Param("num") int num,@Param("productId") Long productId,
|
||||
@Param("unique") String unique);
|
||||
|
||||
|
||||
/**
|
||||
* 拼团商品 加库存 减销量
|
||||
* @param num
|
||||
* @param productId
|
||||
* @param unique
|
||||
* @return
|
||||
*/
|
||||
|
||||
@Update("update yx_store_product_attr_value set stock=stock+#{num}, pink_stock=pink_stock+#{num}, sales=sales-#{num}" +
|
||||
" where product_id=#{productId} and and `unique`=#{unique}")
|
||||
int incCombinationStockDecSales(@Param("num") int num,@Param("productId") Long productId,
|
||||
@Param("unique") String unique);
|
||||
|
||||
|
||||
/**
|
||||
* 秒杀 加库存 减销量
|
||||
* @param num
|
||||
* @param productId
|
||||
* @param unique
|
||||
* @return
|
||||
*/
|
||||
@Update("update yx_store_product_attr_value set stock=stock+#{num},seckill_stock=seckill_stock+#{num}, sales=sales-#{num}" +
|
||||
" where product_id=#{productId} and `unique`=#{unique}")
|
||||
int incSeckillStockDecSales(@Param("num") int num,@Param("productId") Long productId,
|
||||
@Param("unique") String unique);
|
||||
|
||||
|
||||
/**
|
||||
* 普通商品 减库存 加销量
|
||||
* @param num
|
||||
* @param productId
|
||||
* @param unique
|
||||
* @return
|
||||
*/
|
||||
@Update("update yx_store_product_attr_value set stock=stock-#{num}, sales=sales+#{num}" +
|
||||
" where product_id=#{productId} and `unique`=#{unique} and stock >= #{num}")
|
||||
int decStockIncSales(@Param("num") int num, @Param("productId") Long productId,
|
||||
@Param("unique") String unique);
|
||||
|
||||
@Update("update yx_store_product_attr_value set stock=stock+#{num}, sales=sales-#{num}" +
|
||||
" where product_id=#{productId} and `unique`=#{unique}")
|
||||
int incStockDecSales(@Param("num") int num,@Param("productId") Long productId,
|
||||
@Param("unique") String unique);
|
||||
|
||||
/**
|
||||
* 拼团产品 减库存 加销量
|
||||
* @param num
|
||||
* @param productId
|
||||
* @param unique
|
||||
* @return
|
||||
*/
|
||||
@Update("update yx_store_product_attr_value set stock=stock-#{num}, pink_stock=pink_stock-#{num} ,sales=sales+#{num}" +
|
||||
" where product_id=#{productId} and `unique`=#{unique} and stock >= #{num} and pink_stock>=#{num}")
|
||||
int decCombinationStockIncSales(int num, Long productId, String unique);
|
||||
|
||||
/**
|
||||
* 秒杀产品 减库存 加销量
|
||||
* @param num
|
||||
* @param productId
|
||||
* @param unique
|
||||
* @return
|
||||
*/
|
||||
@Update("update yx_store_product_attr_value set stock=stock-#{num}, seckill_stock=seckill_stock-#{num},sales=sales+#{num}" +
|
||||
" where product_id=#{productId} and `unique`=#{unique} and stock >= #{num} and seckill_stock>=#{num}")
|
||||
int decSeckillStockIncSales(int num, Long productId, String unique);
|
||||
|
@ -21,35 +21,70 @@ import org.springframework.stereotype.Repository;
|
||||
@Repository
|
||||
public interface StoreProductMapper extends CoreMapper<YxStoreProduct> {
|
||||
|
||||
/**
|
||||
* 正常商品库存 减库存 加销量
|
||||
* @param num
|
||||
* @param productId
|
||||
* @return
|
||||
*/
|
||||
@Update("update yx_store_product set stock=stock-#{num}, sales=sales+#{num}" +
|
||||
" where id=#{productId} and stock >= #{num}")
|
||||
int decStockIncSales(@Param("num") int num,@Param("productId") Long productId);
|
||||
|
||||
/**
|
||||
* 正常商品库存 加库存 减销量
|
||||
* @param num
|
||||
* @param productId
|
||||
* @return
|
||||
*/
|
||||
@Update("update yx_store_product set stock=stock+#{num}, sales=sales-#{num}" +
|
||||
" where id=#{productId}")
|
||||
int incStockDecSales(@Param("num") int num,@Param("productId") Long productId);
|
||||
|
||||
@Update("update yx_store_product set sales=sales+#{num}" +
|
||||
" where id=#{productId}")
|
||||
int incSales(@Param("num") int num,@Param("productId") int productId);
|
||||
|
||||
@Update("update yx_store_product set sales=sales-#{num}" +
|
||||
" where id=#{productId}")
|
||||
int decSales(@Param("num") int num,@Param("productId") Long productId);
|
||||
|
||||
|
||||
@Update("update yx_store_product set is_del = #{status} where id = #{id}")
|
||||
void updateDel(@Param("status")int status,@Param("id") Integer id);
|
||||
|
||||
@Update("update yx_store_product set is_show = #{status} where id = #{id}")
|
||||
void updateOnsale(@Param("status") Integer status, @Param("id") Long id);
|
||||
|
||||
//todo 拼团商品库存+—
|
||||
/**
|
||||
* 拼团商品库存,减库存 加销量
|
||||
* @param num
|
||||
* @param productId
|
||||
* @param activityId
|
||||
* @return
|
||||
*/
|
||||
@Update("update yx_store_combination set stock=stock-#{num}, sales=sales+#{num}" +
|
||||
" where id=#{activityId} and stock >= #{num}")
|
||||
int decCombinationStockIncSales(int num, Long productId,Long activityId);
|
||||
//todo 秒杀商品库存+—
|
||||
|
||||
/**
|
||||
* 秒杀产品库存 减库存,加销量
|
||||
* @param num
|
||||
* @param productId
|
||||
* @param activityId
|
||||
* @return
|
||||
*/
|
||||
@Update("update yx_store_seckill set stock=stock-#{num}, sales=sales+#{num}" +
|
||||
" where id=#{activityId} and stock >= #{num}")
|
||||
int decSeckillStockIncSales(int num, Long productId,Long activityId);
|
||||
|
||||
/**
|
||||
* 拼团商品库存,加库存 减销量
|
||||
* @param num
|
||||
* @param productId
|
||||
* @param activityId
|
||||
*/
|
||||
@Update("update yx_store_combination set stock=stock+#{num}, sales=sales-#{num}" +
|
||||
" where id=#{activityId} and stock >= #{num}")
|
||||
void incCombinationStockIncSales(Integer num, Long productId, Long activityId);
|
||||
|
||||
/**
|
||||
* 秒杀产品库存 加库存,减销量
|
||||
* @param num
|
||||
* @param productId
|
||||
* @param activityId
|
||||
* @return
|
||||
*/
|
||||
@Update("update yx_store_seckill set stock=stock+#{num}, sales=sales-#{num}" +
|
||||
" where id=#{activityId} and stock >= #{num}")
|
||||
void incSeckillStockIncSales(Integer num, Long productId, Long activityId);
|
||||
}
|
||||
|
Reference in New Issue
Block a user