CmsGoodsDonServiceImpl.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package com.cyksj.service.mange.goods;
  2. import cn.hutool.core.collection.CollUtil;
  3. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  4. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  5. import com.cyksj.mapper.GoodsDonMapper;
  6. import com.cyksj.mapper.GoodsDonSkuMapper;
  7. import com.cyksj.model.entity.GoodsDon;
  8. import com.cyksj.model.entity.GoodsDonSku;
  9. import com.cyksj.service.mange.CmsGoodsDonService;
  10. import com.ejlchina.searcher.BeanSearcher;
  11. import lombok.RequiredArgsConstructor;
  12. import org.springframework.stereotype.Service;
  13. import java.util.List;
  14. import java.util.Optional;
  15. /**
  16. * @author chan
  17. * @date 2022/9/27 5:31 PM
  18. */
  19. @Service
  20. @RequiredArgsConstructor
  21. public class CmsGoodsDonServiceImpl extends ServiceImpl<GoodsDonMapper, GoodsDon> implements CmsGoodsDonService {
  22. private final BeanSearcher beanSearcher;
  23. private final GoodsDonMapper goodsDonMapper;
  24. private final GoodsDonSkuMapper goodsDonSkuMapper;
  25. @Override
  26. public void updateGoodsSkuPrice(Long goodsId, GoodsDon goods) {
  27. goods = Optional.ofNullable(goods).orElse(goodsDonMapper.selectById(goodsId));
  28. List<GoodsDonSku> skuViews = goodsDonSkuMapper.selectList(Wrappers.lambdaQuery(GoodsDonSku.class)
  29. .eq(GoodsDonSku::getGoodsId, goodsId)
  30. .eq(GoodsDonSku::getStatus, true)
  31. .orderByAsc(GoodsDonSku::getPrice));
  32. //是否有特殊属性
  33. if (CollUtil.isEmpty(skuViews)) {
  34. if (goods.getIsSp()) {
  35. goods.setIsSp(false);
  36. }
  37. if (goods.getIsOwns()) {
  38. goods.setIsOwns(false);
  39. }
  40. goodsDonMapper.updateById(goods);
  41. }
  42. if (!skuViews.isEmpty()) {
  43. //是否有特定价格规格
  44. int spSkuCount = goodsDonSkuMapper.selectCount(Wrappers.lambdaQuery(GoodsDonSku.class)
  45. .eq(GoodsDonSku::getGoodsId, goodsId)
  46. .gt(GoodsDonSku::getSpecificPrice, 0)
  47. .eq(GoodsDonSku::getStatus, true));
  48. int userOwnsSkuCount = goodsDonSkuMapper.selectCount(Wrappers.lambdaQuery(GoodsDonSku.class)
  49. .eq(GoodsDonSku::getGoodsId, goodsId)
  50. .isNotNull(GoodsDonSku::getUserOwns)
  51. .eq(GoodsDonSku::getStatus, true));
  52. goods.setIsSp(spSkuCount > 0 ? true : false);
  53. goods.setIsOwns(userOwnsSkuCount > 0 ? true : false);
  54. GoodsDonSku min = skuViews.get(0);
  55. goods.setMinPrice(min.getPrice());
  56. if (min.getDays() == null) {
  57. min.setDays(0);
  58. }
  59. if (min.getMonths() == null) {
  60. min.setMonths(0);
  61. }
  62. goods.setMinMonths(min.getMonths());
  63. goods.setMinDays(min.getDays());
  64. if (skuViews.size() == 1) {
  65. goods.setMaxPrice(min.getPrice());
  66. goods.setMaxMonths(min.getMonths());
  67. goods.setMaxDays(min.getDays());
  68. } else {
  69. GoodsDonSku max = skuViews.get(skuViews.size() - 1);
  70. if (max.getDays() == null) {
  71. max.setDays(0);
  72. }
  73. if (max.getMonths() == null) {
  74. max.setMonths(0);
  75. }
  76. goods.setMaxPrice(max.getPrice());
  77. goods.setMaxMonths(max.getMonths());
  78. goods.setMaxDays(max.getDays());
  79. }
  80. goodsDonMapper.updateById(goods);
  81. }
  82. }
  83. }