src/main/java/com/mzl/flower/mapper/customer/FollowMapper.java
@@ -12,4 +12,6 @@ @Repository public interface FollowMapper extends BaseMapper<Follow> { List<FollowDTO> myFollow(Page page, @Param("userId") String userId); Integer getStatisFansCount(@Param("supplierId") Long supplierId); } src/main/java/com/mzl/flower/service/customer/FollowService.java
@@ -2,13 +2,11 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.mzl.flower.config.exception.ValidationException; import com.mzl.flower.config.security.SecurityUtils; import com.mzl.flower.dto.request.customer.CreateFollowDTO; import com.mzl.flower.dto.response.customer.FollowDTO; import com.mzl.flower.entity.customer.Follow; import com.mzl.flower.mapper.customer.FollowMapper; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -65,4 +63,12 @@ .eq(Follow::getSupplierId, supplierId)); return count; } public Integer getStatisFansCount(Long supplierId) { Integer count = followMapper.getStatisFansCount(supplierId); return count; } } src/main/java/com/mzl/flower/service/impl/coupon/CouponRecordServiceImpl.java
@@ -168,7 +168,7 @@ // 领取后有段时间 领取后有效时间 // 根据发放后有效期来设置时间 if (couponTemplateDO.getUsageTimeNum() == null || couponTemplateDO.getUsageTimeNum() <= 0) { throw new IllegalArgumentException("使用时间数量必须为正整数"); throw new ValidationException("使用时间数量必须为正整数"); } LocalDateTime currentTime = LocalDateTime.now(); couponRecordDO.setEffectiveStart(currentTime); @@ -437,50 +437,50 @@ public boolean useCoupon(String couponId, String orderId, BigDecimal orderMount) { // 优惠券为空 if(StringUtils.isBlank(couponId)){ throw new IllegalArgumentException("无效的优惠券"); throw new ValidationException("无效的优惠券"); } if(StringUtils.isBlank(orderId)){ throw new IllegalArgumentException("订单id不能为空"); throw new ValidationException("订单id不能为空"); } if(orderMount.compareTo(BigDecimal.ZERO)<=0){ throw new IllegalArgumentException("订单金额不能小于0"); throw new ValidationException("订单金额不能小于0"); } // 验证优惠券存在且有效 final CouponRecordDO couponRecordDO = baseMapper.selectById(couponId); if(null==couponRecordDO || StringUtils.isNotBlank(couponRecordDO.getOrderId()) ){ throw new IllegalArgumentException("无效的优惠券"); throw new ValidationException("无效的优惠券"); } if(couponRecordDO.getStatus().equals(CouponUsedStatusEnum.USED.getType())){ throw new IllegalArgumentException("优惠券已经被使用"); throw new ValidationException("优惠券已经被使用"); } if(couponRecordDO.getStatus().equals(CouponUsedStatusEnum.EXPIRED.getType()) || LocalDateTime.now().isAfter(couponRecordDO.getEffectiveEnd())){ throw new IllegalArgumentException("优惠券已过期"); throw new ValidationException("优惠券已过期"); } // 根据类型判断是无门槛还是满减,如果是无门槛 if(couponRecordDO.getCouponDiscountType().equals(CouponTypeEnum.ZERO.getType())){ // 无门槛,查看金额是否大于满减值 if(orderMount.compareTo(couponRecordDO.getCouponDiscountValue())<0){ throw new IllegalArgumentException(String.format("订单金额(%s)小于无门槛的金额(%s)", orderMount, couponRecordDO.getCouponDiscountValue())); throw new ValidationException(String.format("订单金额(%s)小于无门槛的金额(%s)", orderMount, couponRecordDO.getCouponDiscountValue())); } } if(couponRecordDO.getCouponDiscountType().equals(CouponTypeEnum.DISCOUNT.getType())){ //满减,查看金额是否满足最小订单额 if(orderMount.compareTo(couponRecordDO.getMinOrderAmount())<0){ throw new IllegalArgumentException(String.format("订单金额(%s)小于最低折扣订单金额(%s)", orderMount, couponRecordDO.getMinOrderAmount())); throw new ValidationException(String.format("订单金额(%s)小于最低折扣订单金额(%s)", orderMount, couponRecordDO.getMinOrderAmount())); } if(orderMount.compareTo(couponRecordDO.getCouponDiscountValue())<0){ throw new IllegalArgumentException(String.format("订单金额(%s)小于折扣的金额(%s)", orderMount, couponRecordDO.getCouponDiscountValue())); throw new ValidationException(String.format("订单金额(%s)小于折扣的金额(%s)", orderMount, couponRecordDO.getCouponDiscountValue())); } } // 查看当前的优惠券是否是当前人员的 if(!SecurityUtils.getUserId().equals(couponRecordDO.getUserId())){ throw new IllegalArgumentException("优惠券不属于当前人员"); throw new ValidationException("优惠券不属于当前人员"); } // 优惠券使用操作 src/main/java/com/mzl/flower/service/impl/coupon/CouponTemplateServiceImpl2.java
@@ -241,7 +241,7 @@ // 根据发放后有效期来设置时间 if (couponTemplateDO.getUsageTimeNum() == null || couponTemplateDO.getUsageTimeNum() <= 0) { throw new IllegalArgumentException("使用时间数量必须为正整数"); throw new ValidationException("使用时间数量必须为正整数"); } LocalDateTime currentTime = LocalDateTime.now(); couponTemplateDO.setUsageStartDate(currentTime); src/main/java/com/mzl/flower/web/customer/FollowController.java
@@ -5,12 +5,8 @@ import com.mzl.flower.base.R; import com.mzl.flower.base.ReturnDataDTO; import com.mzl.flower.config.security.SecurityUtils; import com.mzl.flower.dto.request.customer.CreateAddressDTO; import com.mzl.flower.dto.request.customer.CreateFollowDTO; import com.mzl.flower.dto.request.customer.UpdateAddressDTO; import com.mzl.flower.dto.response.customer.FollowDTO; import com.mzl.flower.dto.response.supplier.SupplierDTO; import com.mzl.flower.entity.customer.Address; import com.mzl.flower.service.customer.FollowService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -20,7 +16,6 @@ import org.springframework.web.bind.annotation.*; import javax.validation.constraints.NotNull; import java.util.List; @RestController @RequestMapping("/api/follow") @@ -56,4 +51,11 @@ public ResponseEntity<ReturnDataDTO<Page<FollowDTO>>> myFollow(Page page) { return returnData(R.SUCCESS.getCode(),followService.myFollow(page,SecurityUtils.getUserId())); } @GetMapping("/fans/statis/{supplierId}") @ApiOperation(value = "我的关注列表", notes = "我的关注列表") public ResponseEntity<ReturnDataDTO<Integer>> myFansStatis(@NotNull(message = "supplierId不能为空") @PathVariable("supplierId") Long supplierId) { return returnData(R.SUCCESS.getCode(),followService.getStatisFansCount(supplierId)); } } src/main/resources/mapper/customer/FollowMapper.xml
@@ -21,4 +21,11 @@ </if> ORDER BY f.create_time DESC </select> <select id="getStatisFansCount" resultType="java.lang.Integer"> SELECT IFNULL(COUNT(DISTINCT f.user_id), 0) FROM t_follow_supplier f WHERE f.deleted = 0 AND f.supplier_id = #{supplierId}; </select> </mapper>