Compare commits

...

2 Commits

Author SHA1 Message Date
张松 2d9c1b4815 Merge remote-tracking branch 'origin/test' into test 2025-09-18 15:09:05 +08:00
张松 537aeb09a1 优惠券发放 2025-09-18 15:08:58 +08:00
6 changed files with 51 additions and 3 deletions

View File

@ -3,9 +3,7 @@ package com.czg.controller.admin;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.thread.ThreadUtil;
import com.czg.log.annotation.OperationLog;
import com.czg.market.dto.MkCouponGiftDTO;
import com.czg.market.dto.MkShopCouponRecordDTO;
import com.czg.market.dto.ShopCouponDTO;
import com.czg.market.dto.*;
import com.czg.market.service.MkCouponGiftService;
import com.czg.market.service.MkShopCouponRecordService;
import com.czg.market.service.ShopCouponService;
@ -170,4 +168,13 @@ public class ACouponController {
});
}
/**
* 券发放
* @return 是否发放成功
*/
@PostMapping("/grant")
public CzgResult<Boolean> rewardCoupon(@Validated @RequestBody MkRewardCouponDTO rewardCouponDTO) {
return CzgResult.success(couponRecordService.grant(rewardCouponDTO.getShopId() != null ? rewardCouponDTO.getShopId() : StpKit.USER.getShopId(), rewardCouponDTO));
}
}

View File

@ -70,6 +70,7 @@ public class SaTokenConfigure implements WebMvcConfigurer {
.notMatch("/notify/**")
.notMatch("/admin/auth/**")
.notMatch("/admin/shopMsgPush/subscribe/**")
.notMatch("/admin/coupon/grant")
.check(r -> MyStpLogic.ADMIN_LOGIC.checkLogin());
})).addPathPatterns("/**");

View File

@ -0,0 +1,20 @@
package com.czg.market.dto;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import java.io.Serializable;
@Data
public class MkRewardCouponDTO implements Serializable {
@NotNull(message = "用户ID不能为空")
private Long userId;
@NotNull(message = "优惠券ID不能为空")
private Long couponId;
@NotNull(message = "数量不能为空")
@Min(value = 1, message = "数量不能小于1")
private Integer num;
private Long shopId;
}

View File

@ -1,6 +1,7 @@
package com.czg.market.dto;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serial;
import java.io.Serializable;
@ -11,6 +12,7 @@ import java.io.Serializable;
* @description
*/
@Data
@Accessors(chain = true)
public class MkShopCouponGiftDTO implements Serializable {
@Serial

View File

@ -3,6 +3,7 @@ package com.czg.market.service;
import com.czg.account.dto.QueryReceiveDto;
import com.czg.account.vo.CouponReceiveVo;
import com.czg.account.vo.UserCouponVo;
import com.czg.market.dto.MkRewardCouponDTO;
import com.czg.market.dto.MkShopCouponGiftDTO;
import com.czg.market.dto.MkShopCouponRecordDTO;
import com.mybatisflex.core.paginate.Page;
@ -42,8 +43,13 @@ public interface MkShopCouponRecordService extends IService<MkShopCouponRecord>
*/
void receiveCoupon(MkShopCouponGiftDTO giftDTO, Integer number, boolean isLimit);
/**
* 用户优惠券 失效/删除
*/
void deleteRecord(Long id);
Boolean grant(Long shopId, MkRewardCouponDTO rewardCouponDTO);
}

View File

@ -14,6 +14,7 @@ import com.czg.account.service.UserInfoService;
import com.czg.account.vo.CouponReceiveVo;
import com.czg.account.vo.UserCouponVo;
import com.czg.exception.CzgException;
import com.czg.market.dto.MkRewardCouponDTO;
import com.czg.market.dto.MkShopCouponGiftDTO;
import com.czg.market.dto.MkShopCouponRecordDTO;
import com.czg.market.entity.MkShopCouponRecord;
@ -199,4 +200,15 @@ public class MkShopCouponRecordServiceImpl extends ServiceImpl<MkShopCouponRecor
public void deleteRecord(Long id) {
updateById(new MkShopCouponRecord().setId(id).setIsDel(1), true);
}
@Override
public Boolean grant(Long shopId, MkRewardCouponDTO rewardCouponDTO) {
ShopUser shopUser = shopUserService.getOne(new QueryWrapper().eq(ShopUser::getShopId, shopId).eq(ShopUser::getUserId, rewardCouponDTO.getUserId()));
MkShopCouponGiftDTO giftDTO = new MkShopCouponGiftDTO().setCouponId(rewardCouponDTO.getCouponId())
.setShopId(shopId)
.setShopUserId(shopUser == null ? null : shopUser.getId())
.setSource("后台发放");
receiveCoupon(giftDTO, rewardCouponDTO.getNum(), false);
return true;
}
}