Skip to content

Commit

Permalink
砍价订单实现
Browse files Browse the repository at this point in the history
  • Loading branch information
lifenlong committed Jul 20, 2021
1 parent eef270f commit 6607506
Show file tree
Hide file tree
Showing 17 changed files with 115 additions and 66 deletions.
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@

##### 官方qq群 961316482,官方公众号/小程序体验,扫描二维码

![image-20210511171611793](https://pickmall.cn/assets/imgs/h5-qrcode.png)

[![star](https://gitee.com/beijing_hongye_huicheng/lilishop/badge/star.svg?theme=dark)](https://gitee.com/beijing_hongye_huicheng/lilishop/stargazers)
  ![github](https://img.shields.io/github/stars/hongyehuicheng/lilishop.svg?style=social&logo=#181717)


### 🔥介绍
**官网**https://pickmall.cn

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,22 @@ public class KanjiaGoodsActivityBuyerController {

@GetMapping
@ApiOperation(value = "分页获取砍价商品")
public ResultMessage<IPage<KanjiaActivityGoodsListVO>> kanJiaActivityGoodsPage(KanjiaActivityGoodsParams kanjiaActivityGoodsParams, PageVO page) {
public ResultMessage<IPage<KanjiaActivityGoodsListVO>> kanjiaActivityGoodsPage(KanjiaActivityGoodsParams kanjiaActivityGoodsParams, PageVO page) {
// 会员端查询到的肯定是已经开始的活动商品
kanjiaActivityGoodsParams.setPromotionStatus(PromotionStatusEnum.START.name());
return ResultUtil.data(kanJiaActivityGoodsService.kanJiaGoodsVOPage(kanjiaActivityGoodsParams, page));
return ResultUtil.data(kanJiaActivityGoodsService.kanjiaGoodsVOPage(kanjiaActivityGoodsParams, page));
}

@GetMapping("/{id}")
@ApiOperation(value = "获取砍价活动商品")
@ApiImplicitParam(name = "id", value = "砍价活动商品ID", required = true, paramType = "path")
public ResultMessage<KanjiaActivityGoodsVO> getPointsGoodsPage(@PathVariable String id) {
public ResultMessage<KanjiaActivityGoodsVO> getKanjiaActivityGoods(@PathVariable String id) {
return ResultUtil.data(kanJiaActivityGoodsService.getKanJiaGoodsVO(id));
}

@GetMapping("/getKanjiaActivity/logs")
@ApiOperation(value = "分页获取砍价活动-帮砍记录")
public ResultMessage<IPage<KanjiaActivityLog>> getPointsGoodsPage(KanJiaActivityLogQuery kanJiaActivityLogQuery, PageVO page) {
public ResultMessage<IPage<KanjiaActivityLog>> getKanjiaActivityLog(KanJiaActivityLogQuery kanJiaActivityLogQuery, PageVO page) {
return ResultUtil.data(kanJiaActivityLogService.getForPage(kanJiaActivityLogQuery, page));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
import cn.lili.modules.promotion.service.PointsGoodsService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

Expand Down Expand Up @@ -44,4 +46,11 @@ public ResultMessage<IPage<PointsGoodsCategory>> page(String name, PageVO page)
return ResultUtil.data(pointsGoodsCategoryService.getCategoryByPage(name, page));
}

@GetMapping("/{id}")
@ApiOperation(value = "获取积分活动商品")
@ApiImplicitParam(name = "id", value = "积分商品ID", required = true, paramType = "path")
public ResultMessage<PointsGoodsVO> getPointsGoodsPage(@PathVariable String id) {
return ResultUtil.data(pointsGoodsService.getPointsGoodsDetail(id));
}

}
3 changes: 0 additions & 3 deletions config/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ spring:
# replica-set-name: mongoreplset
cache:
type: redis
#amqp
# rabbitmq:
# host: 192.168.0.116
jpa:
# 自动生成表结构
generate-ddl: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,15 @@ public class TradeBuilder {
*/
int[] defaultRender = {0, 1, 2, 4, 5, 6, 7};

int[] danbiRender = {0, 2, 4, 5, 6, 7};

/**
* 购物车购物车渲染
* 0-> 校验商品, 1-》 满优惠渲染, 2->渲染优惠, 5->计算价格
*/
int[] cartRender = {0, 1, 2, 5};


/**
* 构造购物车
* 购物车与结算信息不一致的地方主要是优惠券计算和运费计算,其他规则都是一致都
Expand Down Expand Up @@ -98,12 +101,23 @@ public TradeDTO buildTrade(CartTypeEnum checkedWay) {
//将购物车到sku未选择信息过滤
List<CartSkuVO> collect = tradeDTO.getSkuList().parallelStream().filter(i -> Boolean.TRUE.equals(i.getChecked())).collect(Collectors.toList());
tradeDTO.setSkuList(collect);
//按照计划进行渲染
for (int index : defaultRender) {
try {
cartRenderSteps.get(index).render(tradeDTO);
} catch (Exception e) {
log.error("购物车{}渲染异常:", cartRenderSteps.get(index).getClass(), e);
if (checkedWay.equals(CartTypeEnum.CART) || checkedWay.equals(CartTypeEnum.BUY_NOW) || checkedWay.equals(CartTypeEnum.VIRTUAL)) {
//按照计划进行渲染
for (int index : defaultRender) {
try {
cartRenderSteps.get(index).render(tradeDTO);
} catch (Exception e) {
log.error("购物车{}渲染异常:", cartRenderSteps.get(index).getClass(), e);
}
}
} else {
//按照计划进行渲染
for (int index : danbiRender) {
try {
cartRenderSteps.get(index).render(tradeDTO);
} catch (Exception e) {
log.error("购物车{}渲染异常:", cartRenderSteps.get(index).getClass(), e);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ void buildCartPrice(TradeDTO tradeDTO) {
if (Boolean.TRUE.equals(cartSkuVO.getChecked())) {
PriceDetailDTO priceDetailDTO = cartSkuVO.getPriceDetailDTO();
//流水金额(入账 出帐金额) = goodsPrice + freight - discountPrice - couponPrice
double flowPrice = CurrencyUtil.sub(CurrencyUtil.add(priceDetailDTO.getGoodsPrice(), priceDetailDTO.getFreightPrice()), CurrencyUtil.add(priceDetailDTO.getDiscountPrice(), priceDetailDTO.getCouponPrice() != null ? priceDetailDTO.getCouponPrice() : 0));
double flowPrice = CurrencyUtil.sub(
CurrencyUtil.add(priceDetailDTO.getGoodsPrice(), priceDetailDTO.getFreightPrice()),
CurrencyUtil.add(priceDetailDTO.getDiscountPrice(),
priceDetailDTO.getCouponPrice() != null ? priceDetailDTO.getCouponPrice() : 0));
priceDetailDTO.setFlowPrice(flowPrice);

//最终结算金额 = flowPrice - platFormCommission - distributionCommission
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@
import cn.lili.modules.promotion.entity.dos.MemberCoupon;
import cn.lili.modules.promotion.entity.dos.Pintuan;
import cn.lili.modules.promotion.entity.dos.PromotionGoods;
import cn.lili.modules.promotion.entity.enums.CouponScopeTypeEnum;
import cn.lili.modules.promotion.entity.enums.KanJiaStatusEnum;
import cn.lili.modules.promotion.entity.enums.MemberCouponStatusEnum;
import cn.lili.modules.promotion.entity.enums.PromotionTypeEnum;
import cn.lili.modules.promotion.entity.dto.KanjiaActivityGoodsDTO;
import cn.lili.modules.promotion.entity.enums.*;
import cn.lili.modules.promotion.entity.vos.kanjia.KanjiaActivitySearchParams;
import cn.lili.modules.promotion.service.*;
import cn.lili.modules.search.entity.dos.EsGoodsIndex;
Expand Down Expand Up @@ -98,6 +96,8 @@ public class CartServiceImpl implements CartService {
*/
@Autowired
private KanjiaActivityService kanjiaActivityService;
@Autowired
private KanjiaActivityGoodsService kanjiaActivityGoodsService;
/**
* 交易
*/
Expand Down Expand Up @@ -691,25 +691,25 @@ private void checkPintuan(CartSkuVO cartSkuVO) {
*/
private void checkKanjia(CartSkuVO cartSkuVO) {

List<PromotionGoods> currentPromotion = cartSkuVO.getPromotions().stream().filter(
promotionGoods -> (promotionGoods.getPromotionType().equals(PromotionTypeEnum.PINTUAN.name())))
.collect(Collectors.toList());
//根据skuId获取砍价商品
KanjiaActivityGoodsDTO kanjiaActivityGoodsDTO=kanjiaActivityGoodsService.getKanjiaGoodsBySkuId(cartSkuVO.getGoodsSku().getId());

//校验砍价活动是否满足条件
//查找当前会员的砍价商品活动
KanjiaActivitySearchParams kanjiaActivitySearchParams = new KanjiaActivitySearchParams();
kanjiaActivitySearchParams.setKanjiaActivityGoodsId(currentPromotion.get(0).getSkuId());
kanjiaActivitySearchParams.setKanjiaActivityGoodsId(kanjiaActivityGoodsDTO.getId());
kanjiaActivitySearchParams.setMemberId(UserContext.getCurrentUser().getId());
kanjiaActivitySearchParams.setStatus(KanJiaStatusEnum.SUCCESS.name());
KanjiaActivity kanjiaActivity = kanjiaActivityService.getKanjiaActivity(kanjiaActivitySearchParams);

//校验砍价活动是否满足条件
//判断发起砍价活动
if (kanjiaActivity == null) {
throw new ServiceException(ResultCode.KANJIA_ACTIVITY_NOT_FOUND_ERROR);
//判断砍价活动是否已满足条件
} else if (!KanJiaStatusEnum.SUCCESS.name().equals(kanjiaActivity.getStatus())) {
throw new ServiceException(ResultCode.KANJIA_ACTIVITY_NOT_PASS_ERROR);
//判断砍价商品数量
} else if (cartSkuVO.getNum() > 1) {
throw new ServiceException(ResultCode.KANJIA_NUM_BUY_ERROR);
}
//砍价商品默认一件货物
cartSkuVO.setNum(1);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cn.lili.modules.order.order.entity.dos;

import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import cn.lili.base.BaseEntity;
import cn.lili.common.utils.BeanUtil;
Expand Down Expand Up @@ -167,7 +168,7 @@ public class Order extends BaseEntity {
private Boolean needReceipt;

@ApiModelProperty(value = "是否为其他订单下的订单,如果是则为依赖订单的sn,否则为空")
private String parentOrderSn="";
private String parentOrderSn = "";

@ApiModelProperty(value = "是否为某订单类型的订单,如果是则为订单类型的id,否则为空")
private String promotionId;
Expand Down Expand Up @@ -215,7 +216,7 @@ public Order(CartVO cartVO, TradeDTO tradeDTO) {
BeanUtil.copyProperties(cartVO.getPriceDetailDTO(), this);
BeanUtil.copyProperties(cartVO, this);
//填写订单类型
this.setTradeType(cartVO,tradeDTO);
this.setTradeType(cartVO, tradeDTO);
setId(oldId);

//设置默认支付状态
Expand Down Expand Up @@ -253,22 +254,23 @@ public Order(CartVO cartVO, TradeDTO tradeDTO) {
* 2.普通订单进行区分:实物订单、虚拟订单
* 3.促销订单判断货物进行区分实物、虚拟商品。
* 4.拼团订单需要填写父订单ID
* @param cartVO 购物车VO
*
* @param cartVO 购物车VO
* @param tradeDTO 交易DTO
*/
private void setTradeType(CartVO cartVO, TradeDTO tradeDTO){
private void setTradeType(CartVO cartVO, TradeDTO tradeDTO) {

//判断是否为普通订单、促销订单
if (tradeDTO.getCartTypeEnum().equals(CartTypeEnum.CART) || tradeDTO.getCartTypeEnum().equals(CartTypeEnum.BUY_NOW)) {
this.setOrderType(OrderTypeEnum.NORMAL.name());
}else if (tradeDTO.getCartTypeEnum().equals(CartTypeEnum.VIRTUAL)) {
} else if (tradeDTO.getCartTypeEnum().equals(CartTypeEnum.VIRTUAL)) {
this.setOrderType(OrderTypeEnum.VIRTUAL.name());
}else{
} else {
//促销订单(拼团、积分)-判断购买的是虚拟商品还是实物商品
String goodsType=cartVO.getSkuList().get(0).getGoodsSku().getGoodsType();
if(goodsType.equals(GoodsTypeEnum.PHYSICAL_GOODS.name())){
String goodsType = cartVO.getSkuList().get(0).getGoodsSku().getGoodsType();
if (StrUtil.isEmpty(goodsType) || goodsType.equals(GoodsTypeEnum.PHYSICAL_GOODS.name())) {
this.setOrderType(OrderTypeEnum.NORMAL.name());
}else{
} else {
this.setOrderType(OrderTypeEnum.VIRTUAL.name());
}
//填写订单的促销类型
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ public class FullDiscount extends BasePromotion {

private static final long serialVersionUID = 430433787214894166L;

@NotEmpty(message = "活动名称不能为空")
@ApiModelProperty(value = "活动名称", required = true)
private String promotionName;

@NotNull(message = "请填写优惠门槛")
@DecimalMax(value = "99999999.00", message = "优惠券门槛金额超出限制")
@ApiModelProperty(value = "优惠门槛金额", required = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@ApiModel(value = "砍价活动参与记录对象")
public class KanjiaActivityDTO extends KanjiaActivityLog {

@ApiModelProperty(value = "砍价金额")
@ApiModelProperty(value = "砍价商品Id")
private String kanjiaActivityGoodsId;

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@
public class KanjiaActivityVO extends KanjiaActivity {

@ApiModelProperty(value = "是否可以砍价")
private Boolean help = false;
private Boolean help;

@ApiModelProperty(value = "是否已发起砍价")
private Boolean launch = false;
private Boolean launch;

@ApiModelProperty(value = "是否可购买")
private Boolean pass = false;
private Boolean pass;

public KanjiaActivityVO() {
this.setHelp(false);
this.setLaunch(false);
this.setPass(false);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,22 @@ public interface KanjiaActivityGoodsService extends IService<KanjiaActivityGoods
* @param pageVO 分页信息
* @return 砍价商品
*/
IPage<KanjiaActivityGoodsListVO> kanJiaGoodsVOPage(KanjiaActivityGoodsParams kanJiaActivityGoodsParams, PageVO pageVO);
IPage<KanjiaActivityGoodsListVO> kanjiaGoodsVOPage(KanjiaActivityGoodsParams kanJiaActivityGoodsParams, PageVO pageVO);

/**
* 查询砍价活动商品
*
* @param goodsId 砍价活动商品id
* @return 砍价活动商品信息
*/
KanjiaActivityGoodsDTO getKanJiaGoodsDetail(String goodsId);
KanjiaActivityGoodsDTO getKanjiaGoodsDetail(String goodsId);

/**
* 根据SkuId获取正在进行中的砍价商品
* @param skuId 商品规格Id
* @return 砍价商品
*/
KanjiaActivityGoodsDTO getKanjiaGoodsBySkuId(String skuId);

/**
* 查询砍价活动商品VO
Expand All @@ -67,10 +74,10 @@ public interface KanjiaActivityGoodsService extends IService<KanjiaActivityGoods
/**
* 修改看见商品信息
*
* @param kanJiaActivityGoodsDTO 砍价商品信息
* @param kanjiaActivityGoodsDTO 砍价商品信息
* @return 是否修改成功
*/
boolean updateKanJiaActivityGoods(KanjiaActivityGoodsDTO kanJiaActivityGoodsDTO);
boolean updateKanjiaActivityGoods(KanjiaActivityGoodsDTO kanjiaActivityGoodsDTO);

/**
* 删除砍价商品
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public IPage<KanjiaActivityGoodsDTO> getForPage(KanjiaActivityGoodsParams kanJia
}

@Override
public IPage<KanjiaActivityGoodsListVO> kanJiaGoodsVOPage(KanjiaActivityGoodsParams kanjiaActivityGoodsParams, PageVO pageVO) {
public IPage<KanjiaActivityGoodsListVO> kanjiaGoodsVOPage(KanjiaActivityGoodsParams kanjiaActivityGoodsParams, PageVO pageVO) {
return this.baseMapper.kanjiaActivityGoodsVOPage(PageUtil.initPage(pageVO),kanjiaActivityGoodsParams.wrapper());
}

Expand Down Expand Up @@ -225,7 +225,7 @@ private KanjiaActivityGoods checkSkuDuplicate(String skuId, KanjiaActivityGoodsD
}

@Override
public KanjiaActivityGoodsDTO getKanJiaGoodsDetail(String goodsId) {
public KanjiaActivityGoodsDTO getKanjiaGoodsDetail(String goodsId) {
KanjiaActivityGoodsDTO kanJiaActivityGoodsDTO = this.mongoTemplate.findById(goodsId, KanjiaActivityGoodsDTO.class);
if (kanJiaActivityGoodsDTO == null) {
log.error("id为" + goodsId + "的砍价商品不存在!");
Expand All @@ -234,6 +234,16 @@ public KanjiaActivityGoodsDTO getKanJiaGoodsDetail(String goodsId) {
return kanJiaActivityGoodsDTO;
}

@Override
public KanjiaActivityGoodsDTO getKanjiaGoodsBySkuId(String skuId) {

Query query = new Query();
query.addCriteria(Criteria.where("promotionStatus").is(PromotionStatusEnum.START.name()));
query.addCriteria(Criteria.where("skuId").is(skuId));
List<KanjiaActivityGoodsDTO> kanjiaActivityGoodsDTOS = this.mongoTemplate.find(query, KanjiaActivityGoodsDTO.class);
return kanjiaActivityGoodsDTOS.get(0);
}

@Override
public KanjiaActivityGoodsVO getKanJiaGoodsVO(String id) {

Expand All @@ -252,9 +262,9 @@ public KanjiaActivityGoodsVO getKanJiaGoodsVO(String id) {
}

@Override
public boolean updateKanJiaActivityGoods(KanjiaActivityGoodsDTO kanJiaActivityGoodsDTO) {
public boolean updateKanjiaActivityGoods(KanjiaActivityGoodsDTO kanJiaActivityGoodsDTO) {
//校验砍价商品是否存在
KanjiaActivityGoodsDTO dbKanJiaActivityGoods = this.getKanJiaGoodsDetail(kanJiaActivityGoodsDTO.getId());
KanjiaActivityGoodsDTO dbKanJiaActivityGoods = this.getKanjiaGoodsDetail(kanJiaActivityGoodsDTO.getId());
//校验当前活动是否已经开始,只有新建的未开始的活动可以编辑
if (!dbKanJiaActivityGoods.getPromotionStatus().equals(PromotionStatusEnum.NEW.name())) {
throw new ServiceException(ResultCode.PROMOTION_UPDATE_ERROR);
Expand Down Expand Up @@ -297,7 +307,7 @@ public boolean updateKanJiaActivityGoods(KanjiaActivityGoodsDTO kanJiaActivityGo
public boolean deleteKanJiaGoods(List<String> ids) {
List<String> skuIds = new ArrayList<>();
for (String id : ids) {
KanjiaActivityGoodsDTO kanJiaActivityGoodsDTO = this.getKanJiaGoodsDetail(id);
KanjiaActivityGoodsDTO kanJiaActivityGoodsDTO = this.getKanjiaGoodsDetail(id);
this.timeTrigger.delete(TimeExecuteConstant.PROMOTION_EXECUTOR,
kanJiaActivityGoodsDTO.getStartTime().getTime(),
DelayQueueTools.wrapperUniqueKey(DelayTypeEnums.PROMOTION, (PromotionTypeEnum.KANJIA.name() + kanJiaActivityGoodsDTO.getId())),
Expand All @@ -318,8 +328,8 @@ public boolean deleteKanJiaGoods(List<String> ids) {
public KanjiaActivityGoodsDTO getKanJiaGoodsBySku(String skuId) {
//mongo查询条件
Query query = new Query();
query.addCriteria(Criteria.where("skuId").ne(skuId))
.addCriteria(Criteria.where("promotionStatus").ne(PromotionStatusEnum.START.name()));
query.addCriteria(Criteria.where("skuId").is(skuId))
.addCriteria(Criteria.where("promotionStatus").is(PromotionStatusEnum.START.name()));
List<KanjiaActivityGoodsDTO> kanjiaActivityGoodsDTOList=this.mongoTemplate.find(query, KanjiaActivityGoodsDTO.class);
return kanjiaActivityGoodsDTOList.get(0);
}
Expand Down
Loading

0 comments on commit 6607506

Please sign in to comment.