未使用券 不可用删除

This commit is contained in:
wangw 2024-11-14 13:53:10 +08:00
parent 08351e6260
commit 42775cae36
2 changed files with 9 additions and 0 deletions

View File

@ -44,6 +44,11 @@ public interface TbActivateInRecordMapper extends BaseMapper<TbActivateInRecord>
" order by inRecord.use_end_time asc")
List<TbUserCouponVo> queryByVipIdAndShopId(@Param("vipUserId") Integer vipUserId, @Param("shopId") Integer shopId);
@Select("SELECT sum( over_num ) from tb_activate_in_record" +
" where coupon_id = #{couponId} and now() &lt; use_end_time group by coupon_id ")
int countNoUseCoupon(@Param("couponId") Integer couponId);
@Update("update tb_activate_in_record" +
" set over_num = #{overNum}" +
" where id = #{id}")

View File

@ -160,6 +160,10 @@ public class TbShopCouponServiceImpl extends ServiceImpl<TbShopCouponMapper, TbS
if(CollectionUtil.isNotEmpty(tbActivates)){
throw new BadRequestException("该优惠券已关联活动,请解绑后删除");
}
int i = inRecordMapper.countNoUseCoupon(id);
if (i > 0) {
throw new BadRequestException("该优惠券有发放后未使用,无法删除");
}
}
tbShopCouponmapper.deleteBatchIds(Arrays.asList(ids));
for (Integer id : ids) {