You've already forked FrameTour-BE
							
							优惠券、通知加参数
This commit is contained in:
		
							
								
								
									
										91
									
								
								src/main/java/com/ycwl/basic/biz/CouponBiz.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										91
									
								
								src/main/java/com/ycwl/basic/biz/CouponBiz.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,91 @@ | ||||
| package com.ycwl.basic.biz; | ||||
|  | ||||
| import com.ycwl.basic.mapper.CouponMapper; | ||||
| import com.ycwl.basic.mapper.CouponRecordMapper; | ||||
| import com.ycwl.basic.model.pc.coupon.entity.CouponEntity; | ||||
| import com.ycwl.basic.model.pc.couponRecord.entity.CouponRecordEntity; | ||||
| import com.ycwl.basic.model.pc.couponRecord.resp.CouponRecordQueryResp; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.stereotype.Component; | ||||
|  | ||||
| import java.util.Date; | ||||
| import java.util.List; | ||||
| import java.util.Optional; | ||||
|  | ||||
| @Component | ||||
| public class CouponBiz { | ||||
|     @Autowired | ||||
|     private CouponMapper couponMapper; | ||||
|     @Autowired | ||||
|     private CouponRecordMapper couponRecordMapper; | ||||
|  | ||||
|     public CouponRecordQueryResp queryUserCouponRecord(Long scenicId, Long memberId, Long faceId, String goodsId) { | ||||
|         CouponRecordQueryResp resp = new CouponRecordQueryResp(); | ||||
|         List<CouponRecordEntity> recordList = couponRecordMapper.queryByUserWithGoodsId(scenicId, memberId, goodsId); | ||||
|         if (recordList != null && !recordList.isEmpty()) { | ||||
|             Optional<CouponRecordEntity> record = recordList.stream().filter(item -> item.getStatus() == 0).filter(item -> item.getFaceId() == null || item.getFaceId().equals(faceId)).findAny(); | ||||
|             if (record.isPresent()) { | ||||
|                 CouponRecordEntity recordEntity = record.get(); | ||||
|                 resp.setExist(true); | ||||
|                 resp.setId(recordEntity.getId()); | ||||
|                 resp.setCouponId(recordEntity.getCouponId()); | ||||
|                 CouponEntity coupon = couponMapper.getById(recordEntity.getCouponId()); | ||||
|                 if (coupon != null) { | ||||
|                     resp.setMemberId(recordEntity.getMemberId()); | ||||
|                     resp.setFaceId(recordEntity.getFaceId()); | ||||
|                     resp.setStatus(recordEntity.getStatus()); | ||||
|                     resp.setCreateTime(recordEntity.getCreateTime()); | ||||
|                     resp.setUsedTime(recordEntity.getUsedTime()); | ||||
|                     resp.setUsedOrderId(recordEntity.getUsedOrderId()); | ||||
|                     resp.setCoupon(coupon); | ||||
|                 } else { | ||||
|                     resp.setExist(false); | ||||
|                 } | ||||
|             } else { | ||||
|                 Optional<CouponRecordEntity> usedRecord = recordList.stream().filter(item -> item.getStatus() != 0).filter(item -> item.getFaceId() == null || item.getFaceId().equals(faceId)).findAny(); | ||||
|                 if (usedRecord.isPresent()) { | ||||
|                     CouponRecordEntity recordEntity = usedRecord.get(); | ||||
|                     resp.setExist(true); | ||||
|                     resp.setId(recordEntity.getId()); | ||||
|                     resp.setCouponId(recordEntity.getCouponId()); | ||||
|                     CouponEntity coupon = couponMapper.getById(recordEntity.getCouponId()); | ||||
|                     if (coupon != null) { | ||||
|                         resp.setMemberId(recordEntity.getMemberId()); | ||||
|                         resp.setFaceId(recordEntity.getFaceId()); | ||||
|                         resp.setStatus(recordEntity.getStatus()); | ||||
|                         resp.setCreateTime(recordEntity.getCreateTime()); | ||||
|                         resp.setUsedTime(recordEntity.getUsedTime()); | ||||
|                         resp.setUsedOrderId(recordEntity.getUsedOrderId()); | ||||
|                         resp.setCoupon(coupon); | ||||
|                     } else { | ||||
|                         resp.setExist(false); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         return resp; | ||||
|     } | ||||
|  | ||||
|     public boolean userGetCoupon(Long memberId, Long faceId, Integer couponId) { | ||||
|         CouponEntity coupon = couponMapper.getById(couponId); | ||||
|         if (coupon == null) { | ||||
|             return false; | ||||
|         } | ||||
|         CouponRecordEntity entity = new CouponRecordEntity(); | ||||
|         entity.setCouponId(couponId); | ||||
|         entity.setFaceId(faceId); | ||||
|         entity.setMemberId(memberId); | ||||
|         entity.setStatus(0); | ||||
|         entity.setCreateTime(new Date()); | ||||
|         return couponRecordMapper.insert(entity) > 0; | ||||
|     } | ||||
|  | ||||
|     public boolean userUseCoupon(Long memberId, Long faceId, Integer couponRecordId, Long orderId) { | ||||
|         CouponRecordEntity entity = new CouponRecordEntity(); | ||||
|         entity.setId(couponRecordId); | ||||
|         entity.setStatus(1); | ||||
|         entity.setUsedTime(new Date()); | ||||
|         entity.setUsedOrderId(orderId); | ||||
|         return couponRecordMapper.updateById(entity) > 0; | ||||
|     } | ||||
| } | ||||
| @@ -8,6 +8,8 @@ import com.ycwl.basic.mapper.VideoMapper; | ||||
| import com.ycwl.basic.model.mobile.order.IsBuyRespVO; | ||||
| import com.ycwl.basic.model.mobile.order.PriceObj; | ||||
| import com.ycwl.basic.model.mobile.statistic.req.StatisticsRecordAddReq; | ||||
| import com.ycwl.basic.model.pc.coupon.entity.CouponEntity; | ||||
| import com.ycwl.basic.model.pc.couponRecord.resp.CouponRecordQueryResp; | ||||
| import com.ycwl.basic.model.pc.face.entity.FaceEntity; | ||||
| import com.ycwl.basic.model.pc.order.entity.OrderEntity; | ||||
| import com.ycwl.basic.model.pc.order.entity.OrderItemEntity; | ||||
| @@ -70,6 +72,8 @@ public class OrderBiz { | ||||
|     private VideoTaskRepository videoTaskRepository; | ||||
|     @Autowired | ||||
|     private BrokerBiz brokerBiz; | ||||
|     @Autowired | ||||
|     private CouponBiz couponBiz; | ||||
|  | ||||
|     public PriceObj queryPrice(Long scenicId, int goodsType, Long goodsId) { | ||||
|         PriceObj priceObj = new PriceObj(); | ||||
| @@ -172,8 +176,8 @@ public class OrderBiz { | ||||
|                 respVO.setOrderId(orderEntity.getId()); | ||||
|             } | ||||
|         } | ||||
|         // 还是没买 | ||||
|         respVO.setBuy(isBuy); | ||||
|         // 还是没买 | ||||
|         if (!isBuy) { | ||||
|             PriceObj priceObj = queryPrice(scenicId, goodsType, goodsId); | ||||
|             if (priceObj == null) { | ||||
| @@ -184,6 +188,36 @@ public class OrderBiz { | ||||
|             respVO.setGoodsId(goodsId); | ||||
|             respVO.setOrigPrice(priceObj.getPrice()); | ||||
|             respVO.setSlashPrice(priceObj.getSlashPrice()); | ||||
|             switch (goodsType) { | ||||
|                 case 0: // vlog | ||||
|                     VideoEntity video = videoRepository.getVideo(goodsId); | ||||
|                     TaskEntity taskById = videoTaskRepository.getTaskById(video.getTaskId()); | ||||
|                     if (taskById != null) { | ||||
|                         CouponRecordQueryResp recordQueryResp = couponBiz.queryUserCouponRecord(scenicId, userId, taskById.getFaceId(), taskById.getTemplateId().toString()); | ||||
|                         if (recordQueryResp.isUsable()) { | ||||
|                             respVO.setCouponId(recordQueryResp.getCouponId()); | ||||
|                             respVO.setCouponRecordId(recordQueryResp.getId()); | ||||
|                             CouponEntity coupon = recordQueryResp.getCoupon(); | ||||
|                             if (coupon != null) { | ||||
|                                 respVO.setCouponPrice(coupon.calculateDiscountPrice(priceObj.getPrice())); | ||||
|                             } | ||||
|                         } | ||||
|                     } | ||||
|                     break; | ||||
|                 case 1: | ||||
|                 case 2: | ||||
|                     CouponRecordQueryResp recordQueryResp = couponBiz.queryUserCouponRecord(scenicId, userId, goodsId, String.valueOf(goodsType)); | ||||
|                     if (recordQueryResp.isUsable()) { | ||||
|                         respVO.setCouponId(recordQueryResp.getCouponId()); | ||||
|                         respVO.setCouponRecordId(recordQueryResp.getId()); | ||||
|                         CouponEntity coupon = recordQueryResp.getCoupon(); | ||||
|                         if (coupon != null) { | ||||
|                             respVO.setCouponPrice(coupon.calculateDiscountPrice(priceObj.getPrice())); | ||||
|                         } | ||||
|                     } | ||||
|                     break; | ||||
|  | ||||
|             } | ||||
|         } | ||||
|         return respVO; | ||||
|     } | ||||
| @@ -206,6 +240,9 @@ public class OrderBiz { | ||||
|             } | ||||
|         }); | ||||
|         orderRepository.clearOrderCache(orderId); // 更新完了,清理下 | ||||
|         if (order.getCouponRecordId() != null) { | ||||
|             couponBiz.userUseCoupon(order.getMemberId(), order.getFaceId(), order.getCouponRecordId(), orderId); | ||||
|         } | ||||
|  | ||||
|         //支付时间 | ||||
|         OrderAppRespVO orderDetail = orderMapper.appDetail(orderId); | ||||
|   | ||||
| @@ -1,7 +1,8 @@ | ||||
| package com.ycwl.basic.biz; | ||||
|  | ||||
| import com.ycwl.basic.model.mobile.order.IsBuyBatchRespVO; | ||||
| import com.ycwl.basic.model.mobile.order.IsBuyRespVO; | ||||
| import com.ycwl.basic.model.pc.coupon.entity.CouponEntity; | ||||
| import com.ycwl.basic.model.pc.couponRecord.resp.CouponRecordQueryResp; | ||||
| import com.ycwl.basic.model.pc.face.entity.FaceEntity; | ||||
| import com.ycwl.basic.model.pc.order.entity.OrderEntity; | ||||
| import com.ycwl.basic.model.pc.price.entity.PriceConfigEntity; | ||||
| @@ -34,6 +35,8 @@ public class PriceBiz { | ||||
|     private OrderBiz orderBiz; | ||||
|     @Autowired | ||||
|     private FaceRepository faceRepository; | ||||
|     @Autowired | ||||
|     private CouponBiz couponBiz; | ||||
|  | ||||
|     public List<GoodsListRespVO> listGoodsByScenic(Long scenicId) { | ||||
|         List<GoodsListRespVO> goodsList = new ArrayList<>(); | ||||
| @@ -96,6 +99,30 @@ public class PriceBiz { | ||||
|                 return respVO; | ||||
|             } | ||||
|         } | ||||
|         switch (type) { | ||||
|             case 0: // 单个定价 | ||||
|                 CouponRecordQueryResp recordQueryResp = couponBiz.queryUserCouponRecord(scenicId, userId, faceId, goodsIds); | ||||
|                 if (recordQueryResp.isUsable()) { | ||||
|                     respVO.setCouponId(recordQueryResp.getCouponId()); | ||||
|                     respVO.setCouponRecordId(recordQueryResp.getId()); | ||||
|                     CouponEntity coupon = recordQueryResp.getCoupon(); | ||||
|                     if (coupon != null) { | ||||
|                         respVO.setCouponPrice(coupon.calculateDiscountPrice(priceConfig.getPrice())); | ||||
|                     } | ||||
|                 } | ||||
|                 break; | ||||
|             case -1: | ||||
|                 CouponRecordQueryResp oneCouponRecordQueryResp = couponBiz.queryUserCouponRecord(scenicId, userId, faceId, "-1"); | ||||
|                 if (oneCouponRecordQueryResp.isUsable()) { | ||||
|                     respVO.setCouponId(oneCouponRecordQueryResp.getCouponId()); | ||||
|                     respVO.setCouponRecordId(oneCouponRecordQueryResp.getId()); | ||||
|                     CouponEntity coupon = oneCouponRecordQueryResp.getCoupon(); | ||||
|                     if (coupon != null) { | ||||
|                         respVO.setCouponPrice(coupon.calculateDiscountPrice(priceConfig.getPrice())); | ||||
|                     } | ||||
|                 } | ||||
|                 break; | ||||
|         } | ||||
|         respVO.setConfigId(priceConfig.getId()); | ||||
|         respVO.setGoodsIds(goodsIds); | ||||
|         respVO.setType(type); | ||||
|   | ||||
| @@ -1,9 +1,11 @@ | ||||
| package com.ycwl.basic.controller.pc; | ||||
| import com.github.pagehelper.PageHelper; | ||||
| import com.github.pagehelper.PageInfo; | ||||
| import com.ycwl.basic.biz.PriceBiz; | ||||
| import com.ycwl.basic.model.pc.coupon.entity.CouponEntity; | ||||
| import com.ycwl.basic.model.pc.coupon.req.CouponQueryReq; | ||||
| import com.ycwl.basic.model.pc.coupon.resp.CouponRespVO; | ||||
| import com.ycwl.basic.model.pc.price.resp.GoodsListRespVO; | ||||
| import com.ycwl.basic.service.pc.CouponService; | ||||
| import com.ycwl.basic.utils.ApiResponse; | ||||
| import io.swagger.annotations.Api; | ||||
| @@ -19,6 +21,15 @@ import java.util.List; | ||||
| public class CouponController { | ||||
|     @Autowired | ||||
|     private CouponService couponService; | ||||
|     @Autowired | ||||
|     private PriceBiz priceBiz; | ||||
|  | ||||
|     @GetMapping("/{scenicId}/goodsList") | ||||
|     public ApiResponse<List<GoodsListRespVO>> scenicGoodsList(@PathVariable Long scenicId) { | ||||
|         List<GoodsListRespVO> data = priceBiz.listGoodsByScenic(scenicId); | ||||
|         data.add(new GoodsListRespVO(-1L, "一口价")); | ||||
|         return ApiResponse.success(data); | ||||
|     } | ||||
|  | ||||
|     @ApiOperation("新增优惠券") | ||||
|     @PostMapping("/add") | ||||
|   | ||||
| @@ -12,4 +12,6 @@ public interface CouponMapper extends BaseMapper<CouponEntity> { | ||||
|     List<CouponRespVO> selectByQuery(CouponQueryReq query); | ||||
|  | ||||
|     int updateStatus(Integer id); | ||||
|  | ||||
|     CouponEntity getById(Integer couponId); | ||||
| } | ||||
							
								
								
									
										12
									
								
								src/main/java/com/ycwl/basic/mapper/CouponRecordMapper.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								src/main/java/com/ycwl/basic/mapper/CouponRecordMapper.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | ||||
| package com.ycwl.basic.mapper; | ||||
|  | ||||
| import com.baomidou.mybatisplus.core.mapper.BaseMapper; | ||||
| import com.ycwl.basic.model.pc.couponRecord.entity.CouponRecordEntity; | ||||
| import org.apache.ibatis.annotations.Mapper; | ||||
|  | ||||
| import java.util.List; | ||||
|  | ||||
| @Mapper | ||||
| public interface CouponRecordMapper extends BaseMapper<CouponRecordEntity> { | ||||
|     List<CouponRecordEntity> queryByUserWithGoodsId(Long scenicId, Long memberId, String goodsId); | ||||
| } | ||||
| @@ -49,7 +49,10 @@ public interface OrderMapper { | ||||
|  | ||||
|     OrderItemEntity getOrderItem(Long orderItemId); | ||||
|  | ||||
|     int updateOrderPrice(OrderEntity updateEntity); | ||||
|     int updateOrder(OrderEntity updateEntity); | ||||
|  | ||||
|     OrderEntity queryTypeOrder(Long userId, Long scenicId, int orderType, Integer priceConfigId); | ||||
|  | ||||
|     OrderEntity getUserOrderItem(Long userId, Long scenicId, int orderType, Long configId, Integer goodsType, Long goodsId); | ||||
| } | ||||
|   | ||||
| @@ -13,10 +13,21 @@ public class IsBuyBatchRespVO { | ||||
|     private int type; | ||||
|     private String goodsIds; | ||||
|     private BigDecimal origPrice = BigDecimal.ZERO; | ||||
|     private Integer couponId; | ||||
|     private Integer couponRecordId; | ||||
|     private BigDecimal couponPrice = BigDecimal.ZERO; | ||||
|     private BigDecimal slashPrice = BigDecimal.ZERO; | ||||
|     private BigDecimal slashPrice; | ||||
|  | ||||
|     public BigDecimal getPrice() { | ||||
|         return origPrice.subtract(couponPrice); | ||||
|     } | ||||
|     public BigDecimal getDiscountPrice() { | ||||
|         if (slashPrice == null) { | ||||
|             return BigDecimal.ZERO; | ||||
|         } | ||||
|         if (slashPrice.compareTo(BigDecimal.ZERO) <= 0) { | ||||
|             return BigDecimal.ZERO; | ||||
|         } | ||||
|         return slashPrice.subtract(origPrice); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -12,10 +12,21 @@ public class IsBuyRespVO { | ||||
|     private int goodsType; | ||||
|     private Long goodsId; | ||||
|     private BigDecimal origPrice = BigDecimal.ZERO; | ||||
|     private Integer couponId; | ||||
|     private Integer couponRecordId; | ||||
|     private BigDecimal couponPrice = BigDecimal.ZERO; | ||||
|     private BigDecimal slashPrice = BigDecimal.ZERO; | ||||
|     private BigDecimal slashPrice; | ||||
|  | ||||
|     public BigDecimal getPrice() { | ||||
|         return origPrice.subtract(couponPrice); | ||||
|     } | ||||
|     public BigDecimal getDiscountPrice() { | ||||
|         if (slashPrice == null) { | ||||
|             return BigDecimal.ZERO; | ||||
|         } | ||||
|         if (slashPrice.compareTo(BigDecimal.ZERO) <= 0) { | ||||
|             return BigDecimal.ZERO; | ||||
|         } | ||||
|         return slashPrice.subtract(origPrice); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.annotation.TableName; | ||||
| import lombok.Data; | ||||
|  | ||||
| import java.math.BigDecimal; | ||||
| import java.math.RoundingMode; | ||||
| import java.util.Date; | ||||
|  | ||||
| @Data | ||||
| @@ -36,4 +37,12 @@ public class CouponEntity { | ||||
|      */ | ||||
|     private Integer status; | ||||
|     private Date createAt; | ||||
|  | ||||
|     public BigDecimal calculateDiscountPrice(BigDecimal originalPrice) { | ||||
|         if (discountType == 0) { | ||||
|             return discountPrice; | ||||
|         } else { | ||||
|             return originalPrice.divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_DOWN).multiply(discountPrice); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,20 @@ | ||||
| package com.ycwl.basic.model.pc.couponRecord.entity; | ||||
|  | ||||
| import com.baomidou.mybatisplus.annotation.IdType; | ||||
| import com.baomidou.mybatisplus.annotation.TableId; | ||||
| import lombok.Data; | ||||
|  | ||||
| import java.util.Date; | ||||
|  | ||||
| @Data | ||||
| public class CouponRecordEntity { | ||||
|     @TableId(value = "id", type = IdType.AUTO) | ||||
|     private Integer id; | ||||
|     private Integer couponId; | ||||
|     private Long memberId; | ||||
|     private Long faceId; | ||||
|     private Integer status; | ||||
|     private Date createTime; | ||||
|     private Date usedTime; | ||||
|     private Long usedOrderId; | ||||
| } | ||||
| @@ -0,0 +1,11 @@ | ||||
| package com.ycwl.basic.model.pc.couponRecord.req; | ||||
|  | ||||
| import lombok.Data; | ||||
|  | ||||
| @Data | ||||
| public class CouponRecordUserQueryReq { | ||||
|     private Long scenicId; | ||||
|     private Long memberId; | ||||
|     private Long faceId; | ||||
|     private Integer couponType; | ||||
| } | ||||
| @@ -0,0 +1,26 @@ | ||||
| package com.ycwl.basic.model.pc.couponRecord.resp; | ||||
|  | ||||
| import com.ycwl.basic.model.pc.coupon.entity.CouponEntity; | ||||
| import lombok.Data; | ||||
|  | ||||
| import java.math.BigDecimal; | ||||
| import java.util.Date; | ||||
|  | ||||
| @Data | ||||
| public class CouponRecordQueryResp { | ||||
|     private boolean exist = false; | ||||
|     private Integer id; | ||||
|     private Long scenicId; | ||||
|     private Integer couponId; | ||||
|     private Long memberId; | ||||
|     private Long faceId; | ||||
|     private Integer status; | ||||
|     private Date createTime; | ||||
|     private Date usedTime; | ||||
|     private Long usedOrderId; | ||||
|     private CouponEntity coupon; | ||||
|  | ||||
|     public boolean isUsable() { | ||||
|         return Integer.valueOf(0).equals(status); | ||||
|     } | ||||
| } | ||||
| @@ -35,6 +35,9 @@ public class OrderEntity { | ||||
|      * 划线价 | ||||
|      */ | ||||
|     private BigDecimal slashPrice; | ||||
|     private BigDecimal couponPrice = BigDecimal.ZERO; | ||||
|     private Integer couponId; | ||||
|     private Integer couponRecordId; | ||||
|     /** | ||||
|      * 优惠价格 | ||||
|      */ | ||||
| @@ -88,4 +91,13 @@ public class OrderEntity { | ||||
|      */ | ||||
|     private Date refundAt; | ||||
|  | ||||
|     public BigDecimal getDiscountPrice() { | ||||
|         if (slashPrice == null) { | ||||
|             return BigDecimal.ZERO; | ||||
|         } | ||||
|         if (slashPrice.compareTo(BigDecimal.ZERO) <= 0) { | ||||
|             return BigDecimal.ZERO; | ||||
|         } | ||||
|         return slashPrice.subtract(price); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -89,4 +89,14 @@ public class OrderAppRespVO { | ||||
|     private Integer goodsType; | ||||
|     @ApiModelProperty("订单明细") | ||||
|     private List<OrderItemVO> orderItemList; | ||||
|  | ||||
|     public BigDecimal getDiscountPrice() { | ||||
|         if (slashPrice == null) { | ||||
|             return BigDecimal.ZERO; | ||||
|         } | ||||
|         if (slashPrice.compareTo(BigDecimal.ZERO) <= 0) { | ||||
|             return BigDecimal.ZERO; | ||||
|         } | ||||
|         return slashPrice.subtract(price); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -108,4 +108,14 @@ public class OrderRespVO { | ||||
|     private List<OrderItemVO> orderItemList; | ||||
|     private Long scenicId; | ||||
|     private String scenicName; | ||||
|  | ||||
|     public BigDecimal getDiscountPrice() { | ||||
|         if (slashPrice == null) { | ||||
|             return BigDecimal.ZERO; | ||||
|         } | ||||
|         if (slashPrice.compareTo(BigDecimal.ZERO) <= 0) { | ||||
|             return BigDecimal.ZERO; | ||||
|         } | ||||
|         return slashPrice.subtract(price); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -63,4 +63,14 @@ public class VideoRespVO { | ||||
|     private Integer height; | ||||
|     private Integer width; | ||||
|     private BigDecimal duration; | ||||
|  | ||||
|     public BigDecimal getDiscountPrice() { | ||||
|         if (slashPrice == null) { | ||||
|             return BigDecimal.ZERO; | ||||
|         } | ||||
|         if (slashPrice.compareTo(BigDecimal.ZERO) <= 0) { | ||||
|             return BigDecimal.ZERO; | ||||
|         } | ||||
|         return slashPrice.subtract(templatePrice); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -2,6 +2,7 @@ package com.ycwl.basic.service.pc.impl; | ||||
|  | ||||
| import com.github.pagehelper.PageHelper; | ||||
| import com.github.pagehelper.PageInfo; | ||||
| import com.ycwl.basic.biz.CouponBiz; | ||||
| import com.ycwl.basic.biz.OrderBiz; | ||||
| import com.ycwl.basic.biz.PriceBiz; | ||||
| import com.ycwl.basic.constant.BaseContextHandler; | ||||
| @@ -13,6 +14,7 @@ import com.ycwl.basic.model.mobile.order.IsBuyRespVO; | ||||
| import com.ycwl.basic.model.mobile.order.OrderAppPageReq; | ||||
| import com.ycwl.basic.model.mobile.order.PriceObj; | ||||
| import com.ycwl.basic.model.mobile.order.RefundOrderReq; | ||||
| import com.ycwl.basic.model.pc.couponRecord.resp.CouponRecordQueryResp; | ||||
| import com.ycwl.basic.model.pc.face.entity.FaceEntity; | ||||
| import com.ycwl.basic.model.pc.member.resp.MemberRespVO; | ||||
| import com.ycwl.basic.model.pc.order.entity.OrderEntity; | ||||
| @@ -28,6 +30,7 @@ import com.ycwl.basic.model.pc.orderOp.entity.OrderOperationEntity; | ||||
| import com.ycwl.basic.model.pc.price.entity.PriceConfigEntity; | ||||
| import com.ycwl.basic.model.pc.price.resp.GoodsListRespVO; | ||||
| import com.ycwl.basic.model.pc.source.entity.SourceEntity; | ||||
| import com.ycwl.basic.model.pc.task.entity.TaskEntity; | ||||
| import com.ycwl.basic.model.pc.video.entity.VideoEntity; | ||||
| import com.ycwl.basic.model.wx.WXPayOrderReqVO; | ||||
| import com.ycwl.basic.model.wx.WxPayRespVO; | ||||
| @@ -84,6 +87,8 @@ public class OrderServiceImpl implements OrderService { | ||||
|     private PriceBiz priceBiz; | ||||
|     @Autowired | ||||
|     private FaceRepository faceRepository; | ||||
|     @Autowired | ||||
|     private CouponBiz couponBiz; | ||||
|  | ||||
|     @Override | ||||
|     public ApiResponse<PageInfo<OrderRespVO>> pageQuery(OrderReqQuery query) { | ||||
| @@ -147,12 +152,12 @@ public class OrderServiceImpl implements OrderService { | ||||
|         if (orderItems.size() > 1) { | ||||
|             goodsName = "多项景区Vlog商品"; | ||||
|         } else { | ||||
|             int type = orderItems.get(NumberConstant.ZERO).getGoodsType(); | ||||
|             if (type == NumberConstant.ZERO) { | ||||
|             int type = orderItems.get(0).getGoodsType(); | ||||
|             if (type == 0) { | ||||
|                 goodsName = "景区Vlog视频"; | ||||
|             } else if (type == NumberConstant.ONE) { | ||||
|             } else if (type == 1) { | ||||
|                 goodsName = "景区录像包"; | ||||
|             } else if (type == NumberConstant.TWO) { | ||||
|             } else if (type == 2) { | ||||
|                 goodsName = "景区照片包"; | ||||
|             } | ||||
|         } | ||||
| @@ -310,19 +315,17 @@ public class OrderServiceImpl implements OrderService { | ||||
|         if (isBuy.isBuy()) { | ||||
|             return ApiResponse.fail("您已购买此内容,无需重复购买!"); | ||||
|         } | ||||
|         OrderEntity order = new OrderEntity(); | ||||
|         Long orderId = SnowFlakeUtil.getLongId(); | ||||
|         order.setId(orderId); | ||||
|         // 看看有没有之前购买的订单 | ||||
|         OrderEntity order = orderMapper.getUserOrderItem(userId, createOrderReqVO.getScenicId(), 0, null, createOrderReqVO.getGoodsType(), createOrderReqVO.getGoodsId()); | ||||
|         boolean haveOldOrder = order != null; | ||||
|         if (!haveOldOrder) { | ||||
|             order = new OrderEntity(); | ||||
|             order.setId(SnowFlakeUtil.getLongId()); | ||||
|             order.setMemberId(userId); | ||||
|             MemberRespVO member = memberMapper.getById(userId); | ||||
|             order.setOpenId(member.getOpenId()); | ||||
|             order.setScenicId(createOrderReqVO.getScenicId()); | ||||
|         List<OrderItemEntity> orderItems = new ArrayList<>(); | ||||
|         OrderItemEntity orderItem = new OrderItemEntity(); | ||||
|         orderItem.setGoodsId(createOrderReqVO.getGoodsId()); | ||||
|         orderItem.setGoodsType(createOrderReqVO.getGoodsType()); | ||||
|         orderItem.setOrderId(orderId); | ||||
|         orderItems.add(orderItem); | ||||
|  | ||||
|             PriceObj priceObj = orderBiz.queryPrice(order.getScenicId(), createOrderReqVO.getGoodsType(), createOrderReqVO.getGoodsId()); | ||||
|             order.setSlashPrice(priceObj.getSlashPrice()); | ||||
|             order.setPrice(priceObj.getPrice()); | ||||
| @@ -332,8 +335,12 @@ public class OrderServiceImpl implements OrderService { | ||||
|                 return ApiResponse.fail("您无权购买此内容!"); | ||||
|             } | ||||
|             // promo code | ||||
|         // coupon | ||||
|             order.setPayPrice(priceObj.getPrice()); | ||||
|             order.setPayPrice(order.getPayPrice().subtract(order.getCouponPrice())); | ||||
|             if (order.getPayPrice().compareTo(BigDecimal.ZERO) < NumberConstant.ZERO) { | ||||
|                 // 至少需要支付0.01 | ||||
|                 order.setPayPrice(BigDecimal.valueOf(0.01)); | ||||
|             } | ||||
|             order.setFaceId(priceObj.getFaceId()); | ||||
|             if (order.getPayPrice().equals(BigDecimal.ZERO)) { | ||||
|                 order.setStatus(OrderStateEnum.PAID.getState()); | ||||
| @@ -341,13 +348,48 @@ public class OrderServiceImpl implements OrderService { | ||||
|             } else { | ||||
|                 order.setStatus(OrderStateEnum.UNPAID.getState()); | ||||
|             } | ||||
|         } | ||||
|         // coupon | ||||
|         CouponRecordQueryResp couponRecord = null; | ||||
|         switch (createOrderReqVO.getGoodsType()) { | ||||
|             case 0: // vlog | ||||
|                 VideoEntity video = videoRepository.getVideo(createOrderReqVO.getGoodsId()); | ||||
|                 TaskEntity taskById = videoTaskRepository.getTaskById(video.getTaskId()); | ||||
|                 if (taskById != null) { | ||||
|                     couponRecord = couponBiz.queryUserCouponRecord(order.getScenicId(), userId, order.getFaceId(), taskById.getTemplateId().toString()); | ||||
|                 } | ||||
|                 break; | ||||
|             case 1: | ||||
|             case 2: | ||||
|                 couponRecord = couponBiz.queryUserCouponRecord(order.getScenicId(), userId, order.getFaceId(), String.valueOf(createOrderReqVO.getGoodsType())); | ||||
|                 break; | ||||
|         } | ||||
|         order.setCouponPrice(BigDecimal.ZERO); | ||||
|         order.setCouponRecordId(null); | ||||
|         order.setCouponId(null); | ||||
|         if (couponRecord != null) { | ||||
|             if (couponRecord.isUsable()) { | ||||
|                 order.setCouponId(couponRecord.getCouponId()); | ||||
|                 order.setCouponRecordId(couponRecord.getId()); | ||||
|                 order.setCouponPrice(couponRecord.getCoupon().calculateDiscountPrice(order.getPrice())); | ||||
|             } | ||||
|         } | ||||
|         List<OrderItemEntity> orderItems = new ArrayList<>(); | ||||
|         OrderItemEntity orderItem = new OrderItemEntity(); | ||||
|         orderItem.setGoodsId(createOrderReqVO.getGoodsId()); | ||||
|         orderItem.setGoodsType(createOrderReqVO.getGoodsType()); | ||||
|         orderItem.setOrderId(order.getId()); | ||||
|         orderItems.add(orderItem); | ||||
|         if (!haveOldOrder) { | ||||
|             orderMapper.add(order); | ||||
|             int addOrderItems = orderMapper.addOrderItems(orderItems); | ||||
|             if (addOrderItems == NumberConstant.ZERO) { | ||||
|                 log.error("订单明细添加失败"); | ||||
|                 return ApiResponse.fail("订单添加失败"); | ||||
|             } | ||||
|         //点击支付按钮统计 | ||||
|         } else { | ||||
|             orderMapper.updateOrderPrice(order); | ||||
|         } | ||||
|         if (order.getPayPrice().compareTo(BigDecimal.ZERO) <= 0) { | ||||
|             orderBiz.paidOrder(order.getId()); | ||||
|             return ApiResponse.success(new WxPayRespVO()); | ||||
|   | ||||
| @@ -716,7 +716,7 @@ public class TaskTaskServiceImpl implements TaskService { | ||||
|             } | ||||
|             ScenicEntity scenic = scenicRepository.getScenic(item.getScenicId()); | ||||
|             String title = "您在【" + scenic.getName() + "】的专属影像"; | ||||
|             String page = "pages/videoSynthesis/index?scenicId=" + item.getScenicId() + "&faceId=" + item.getFaceId(); | ||||
|             String page = "pages/videoSynthesis/index?type=1&scenicId=" + item.getScenicId() + "&faceId=" + item.getFaceId(); | ||||
|             /** | ||||
|              * 视频名称 {{thing1.DATA}} | ||||
|              * 生成时间 {{time4.DATA}} | ||||
|   | ||||
| @@ -59,7 +59,7 @@ public class DownloadNotificationTasker { | ||||
|                     log.info("发送模板消息"); | ||||
|                     ScenicEntity scenic = scenicRepository.getScenic(item.getScenicId()); | ||||
|                     String title = "您在【" + scenic.getName() + "】的专属影像"; | ||||
|                     String page = "pages/videoSynthesis/index?scenicId=" + item.getScenicId() + "&faceId=" + item.getFaceId(); | ||||
|                     String page = "pages/videoSynthesis/index?type=2&scenicId=" + item.getScenicId() + "&faceId=" + item.getFaceId(); | ||||
|                     /** | ||||
|                      * 景区 {{thing1.DATA}} | ||||
|                      * 备注 {{thing3.DATA}} | ||||
| @@ -105,7 +105,7 @@ public class DownloadNotificationTasker { | ||||
|                     log.info("发送模板消息"); | ||||
|                     ScenicEntity scenic = scenicRepository.getScenic(item.getScenicId()); | ||||
|                     String title = "您在【" + scenic.getName() + "】的专属影像"; | ||||
|                     String page = "pages/videoSynthesis/index?scenicId=" + item.getScenicId() + "&faceId=" + item.getFaceId(); | ||||
|                     String page = "pages/videoSynthesis/index?type=3&scenicId=" + item.getScenicId() + "&faceId=" + item.getFaceId(); | ||||
|                     /** | ||||
|                      * 影像名称 {{thing1.DATA}} | ||||
|                      * 过期时间 {{time2.DATA}} | ||||
|   | ||||
| @@ -29,4 +29,7 @@ | ||||
|         </where> | ||||
|         ORDER BY create_time DESC | ||||
|     </select> | ||||
|     <select id="getById" resultType="com.ycwl.basic.model.pc.coupon.entity.CouponEntity"> | ||||
|         select * from coupon where id = #{id} | ||||
|     </select> | ||||
| </mapper> | ||||
							
								
								
									
										8
									
								
								src/main/resources/mapper/CouponRecordMapper.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								src/main/resources/mapper/CouponRecordMapper.xml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | ||||
| <?xml version="1.0" encoding="UTF-8" ?> | ||||
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > | ||||
| <mapper namespace="com.ycwl.basic.mapper.CouponRecordMapper"> | ||||
|     <select id="queryByUserWithGoodsId" | ||||
|             resultType="com.ycwl.basic.model.pc.couponRecord.entity.CouponRecordEntity"> | ||||
|         select * from coupon_record where member_id = #{memberId} and coupon_id in (select id from coupon where scenic_id = #{scenicId} and FIND_IN_SET(#{goodsId},config_ids)) | ||||
|     </select> | ||||
| </mapper> | ||||
| @@ -144,8 +144,8 @@ | ||||
|     </select> | ||||
|  | ||||
|     <insert id="add"> | ||||
|         insert into `order`(id, member_id, openid, face_id, `type`, `price_config_id`, slash_price, price, pay_price, remark, broker_id, promo_code, scenic_id, status) | ||||
|         VALUES (#{id}, #{memberId}, #{openId}, #{faceId}, #{type}, #{priceConfigId}, #{slashPrice}, #{price}, #{payPrice}, #{remark}, #{brokerId}, #{promoCode}, #{scenicId}, #{status}) | ||||
|         insert into `order`(id, member_id, openid, face_id, `type`, `price_config_id`, slash_price, price, pay_price, remark, broker_id, promo_code, scenic_id, status, coupon_price, coupon_id, coupon_record_id) | ||||
|         VALUES (#{id}, #{memberId}, #{openId}, #{faceId}, #{type}, #{priceConfigId}, #{slashPrice}, #{price}, #{payPrice}, #{remark}, #{brokerId}, #{promoCode}, #{scenicId}, #{status}, #{couponPrice}, #{couponId}, #{couponRecordId}) | ||||
|     </insert> | ||||
|     <insert id="addOrderItems"> | ||||
|         insert into order_item(order_id,goods_type, goods_id) VALUES | ||||
| @@ -186,6 +186,7 @@ | ||||
|         </set> | ||||
|         where id = #{id} | ||||
|     </update> | ||||
|  | ||||
|     <update id="updateOrder"> | ||||
|         update `order` | ||||
|         <set> | ||||
| @@ -213,11 +214,21 @@ | ||||
|         </set> | ||||
|         where id = #{id} | ||||
|     </update> | ||||
|     <update id="updateOrderPrice"> | ||||
|         update `order` | ||||
|         set | ||||
|             coupon_price = #{couponPrice}, | ||||
|             coupon_id = #{couponId}, | ||||
|             coupon_record_id = #{couponRecordId}, | ||||
|             pay_price = `price` - `coupon_price` | ||||
|         where id = #{id} | ||||
|     </update> | ||||
|     <delete id="deleteById"> | ||||
|         delete from `order` where id = #{id} | ||||
|     </delete> | ||||
|     <select id="list" resultMap="PCBaseResultListMap"> | ||||
|         select o.id, o.scenic_id, s.name as scenic_name, o.member_id,m.nickname ,m.real_name, o.type, o.openid, o.face_id, f.face_url, o.price, pay_price, remark, o.broker_id, o.promo_code, | ||||
|                o.coupon_price, | ||||
|                refund_reason, refund_status, o.`status`, refund_at, pay_at, cancel_at, o.create_at | ||||
|         from `order`  AS o | ||||
|         left join face f on o.face_id = f.id | ||||
| @@ -289,6 +300,7 @@ | ||||
|     </select> | ||||
|     <select id="listDetail" resultMap="PCBaseResultMap"> | ||||
|         select o.id, o.scenic_id, s.name as scenic_name, o.member_id,m.nickname ,m.real_name, o.type, o.openid, o.face_id, f.face_url, o.price, pay_price, remark, o.broker_id, o.promo_code, | ||||
|         o.coupon_price, | ||||
|         refund_reason, refund_status, o.`status`, refund_at, pay_at, cancel_at, o.create_at | ||||
|         from `order`  AS o | ||||
|         left join face f on o.face_id = f.id | ||||
| @@ -360,6 +372,7 @@ | ||||
|     </select> | ||||
|     <select id="getById" resultMap="PCBaseResultMap"> | ||||
|         select o.id, o.scenic_id, s.name as scenic_name, o.member_id, o.type, o.openid, o.face_id, f.face_url, o.price, o.pay_price, o.remark, o.broker_id, o.promo_code, o.refund_reason, | ||||
|                o.coupon_price, | ||||
|                o.refund_status, o.status, o.create_at, o.update_at, o.pay_at, o.cancel_at, o.refund_at, | ||||
|                m.nickname , m.real_name | ||||
|             from `order` o | ||||
| @@ -375,6 +388,7 @@ | ||||
|     </select> | ||||
|     <select id="appList" resultMap="AppBaseResultMap"> | ||||
|         select  o.id, o.member_id,o.openid, o.type, o.face_id, f.face_url, o.price, pay_price, remark, o.broker_id, o.promo_code, | ||||
|         o.coupon_price, | ||||
|         refund_reason, refund_status, o.`status`, o.create_at, refund_at, pay_at, cancel_at, | ||||
|         sc.name scenicName | ||||
|         from `order` AS o | ||||
| @@ -389,6 +403,7 @@ | ||||
|     </select> | ||||
|     <select id="appDetail" resultMap="AppBaseResultMap"> | ||||
|         select o.id, o.member_id,o.openid, o.type, o.price, o.slash_price, pay_price, remark, o.broker_id, o.promo_code, | ||||
|                o.coupon_price, | ||||
|                         refund_reason, refund_status, o.`status`, o.create_at, refund_at, pay_at, cancel_at, | ||||
|                         o.scenic_id, sc.name scenicName | ||||
|         from `order`  AS o | ||||
| @@ -487,4 +502,19 @@ | ||||
|         select * from `order` where member_id = #{userId} and type = #{orderType} and price_config_id = #{priceConfigId} | ||||
|         limit 1 | ||||
|     </select> | ||||
|     <select id="getUserOrderItem" resultType="com.ycwl.basic.model.pc.order.entity.OrderEntity"> | ||||
|         select o.* | ||||
|         from order_item oi | ||||
|         left join `order` o on o.id = oi.order_id | ||||
|         where o.member_id = #{userId} and o.scenic_id = #{scenicId} and o.type = #{orderType} | ||||
|         <if test="configId != null"> | ||||
|             and o.price_config_id = #{configId} | ||||
|         </if> | ||||
|         <if test="goodsType != null"> | ||||
|             and oi.goods_type = #{goodsType} | ||||
|         </if> | ||||
|         <if test="goodsId != null"> | ||||
|             and oi.goods_id = #{goodsId} | ||||
|         </if> | ||||
|     </select> | ||||
| </mapper> | ||||
		Reference in New Issue
	
	Block a user