用户优惠券列表

This commit is contained in:
wangw 2025-09-28 09:51:54 +08:00
parent 548f582d49
commit 56a9728f28
3 changed files with 167 additions and 130 deletions

View File

@ -46,102 +46,101 @@ public class ACouponController {
/** /**
* 分页 * 分页
*/ */
@GetMapping("page") // @GetMapping("page")
// @OperationLog("优惠券列表-分页") //// @OperationLog("优惠券列表-分页")
// @SaAdminCheckPermission("coupon:page") //// @SaAdminCheckPermission("coupon:page")
public CzgResult<Page<ShopCouponDTO>> getCouponPage(ShopCouponDTO param) { // public CzgResult<Page<ShopCouponDTO>> getCouponPage(ShopCouponDTO param) {
Long shopId = StpKit.USER.getShopId(0L); // Long shopId = StpKit.USER.getShopId(0L);
param.setShopId(shopId); // param.setShopId(shopId);
Page<ShopCouponDTO> data = shopCouponService.getCouponPage(param); // Page<ShopCouponDTO> data = shopCouponService.getCouponPage(param);
return CzgResult.success(data); // return CzgResult.success(data);
} // }
//
/** // /**
* 详情 // * 详情
* // *
* @param id 主键id // * @param id 主键id
*/ // */
@GetMapping("{id}") // @GetMapping("{id}")
// @OperationLog("优惠券-详情") //// @OperationLog("优惠券-详情")
// @SaAdminCheckPermission("coupon:info") //// @SaAdminCheckPermission("coupon:info")
public CzgResult<ShopCouponDTO> getCouponById(@PathVariable("id") Long id) { // public CzgResult<ShopCouponDTO> getCouponById(@PathVariable("id") Long id) {
AssertUtil.isNull(id, "{}不能为空", "id"); // AssertUtil.isNull(id, "{}不能为空", "id");
ShopCouponDTO data = shopCouponService.getCouponById(id); // ShopCouponDTO data = shopCouponService.getCouponById(id);
return CzgResult.success(data); // return CzgResult.success(data);
} // }
//
/** // /**
* 新增 // * 新增
*/ // */
@PostMapping // @PostMapping
@OperationLog("优惠券-新增") // @OperationLog("优惠券-新增")
// @SaAdminCheckPermission("coupon:add") //// @SaAdminCheckPermission("coupon:add")
public CzgResult<Void> addCoupon(@RequestBody @Validated({InsertGroup.class, DefaultGroup.class}) ShopCouponDTO dto) { // public CzgResult<Void> addCoupon(@RequestBody @Validated({InsertGroup.class, DefaultGroup.class}) ShopCouponDTO dto) {
Long shopId = StpKit.USER.getShopId(0L); // Long shopId = StpKit.USER.getShopId(0L);
dto.setShopId(shopId); // dto.setShopId(shopId);
dto.setLeftNum(dto.getGiveNum()); // dto.setLeftNum(dto.getGiveNum());
shopCouponService.addCoupon(dto); // shopCouponService.addCoupon(dto);
asyncToBranchShop(dto.getId(), 1); // asyncToBranchShop(dto.getId(), 1);
return CzgResult.success(); // return CzgResult.success();
} // }
//
/** // /**
* 修改 // * 修改
*/ // */
@PutMapping // @PutMapping
@OperationLog("优惠券-修改") // @OperationLog("优惠券-修改")
// @SaAdminCheckPermission("coupon:update") //// @SaAdminCheckPermission("coupon:update")
public CzgResult<Void> updateCoupon(@RequestBody @Validated({UpdateGroup.class, DefaultGroup.class}) ShopCouponDTO dto) { // public CzgResult<Void> updateCoupon(@RequestBody @Validated({UpdateGroup.class, DefaultGroup.class}) ShopCouponDTO dto) {
Long shopId = StpKit.USER.getShopId(0L); // Long shopId = StpKit.USER.getShopId(0L);
dto.setShopId(shopId); // dto.setShopId(shopId);
shopCouponService.updateCouponById(dto); // shopCouponService.updateCouponById(dto);
couponGiftService.upCouponName(dto.getId(), dto.getTitle()); // couponGiftService.upCouponName(dto.getId(), dto.getTitle());
asyncToBranchShop(dto.getId(), 2); // asyncToBranchShop(dto.getId(), 2);
return CzgResult.success(); // return CzgResult.success();
} // }
//
/** // /**
* 删除 // * 删除
*/ // */
@DeleteMapping // @DeleteMapping
@OperationLog("优惠券-删除") // @OperationLog("优惠券-删除")
// @SaAdminCheckPermission("prodGroup:delete") //// @SaAdminCheckPermission("prodGroup:delete")
public CzgResult<String> deleteCoupon(@RequestParam Long id, @RequestParam Integer type) { // public CzgResult<String> deleteCoupon(@RequestParam Long id, @RequestParam Integer type) {
AssertUtil.isNull(id, "{}不能为空", "id"); // AssertUtil.isNull(id, "{}不能为空", "id");
if (type != 1) { // if (type != 1) {
List<MkCouponGiftDTO> gifts = couponGiftService.getCouponGiftBySourceId(id, 3); // List<MkCouponGiftDTO> gifts = couponGiftService.getCouponGiftBySourceId(id, 3);
if (CollUtil.isNotEmpty(gifts)) { // if (CollUtil.isNotEmpty(gifts)) {
String collect = gifts.stream() // String collect = gifts.stream()
.map(MkCouponGiftDTO::getSourceName) // .map(MkCouponGiftDTO::getSourceName)
.filter(name -> name != null && !name.isEmpty()) // .filter(name -> name != null && !name.isEmpty())
.collect(Collectors.joining(",")); // .collect(Collectors.joining(","));
return CzgResult.success(collect); // return CzgResult.success(collect);
} // }
} // }
shopCouponService.deleteCoupon(id); // shopCouponService.deleteCoupon(id);
couponGiftService.deleteCoupon(id); // couponGiftService.deleteCoupon(id);
asyncToBranchShop(id, 3); // asyncToBranchShop(id, 3);
return CzgResult.success(); // return CzgResult.success();
} // }
//
/** // /**
* 获取该券关联的功能列表 // * 获取该券关联的功能列表
* // *
* @param couponId 如果syncId有值 则为syncId 否则为id // * @param couponId 如果syncId有值 则为syncId 否则为id
*/ // */
@GetMapping("/gifts") // @GetMapping("/gifts")
public CzgResult<Page<MkCouponGiftDTO>> getCouponGiftPage(@RequestParam Long couponId, @RequestParam(required = false) Integer type) { // public CzgResult<Page<MkCouponGiftDTO>> getCouponGiftPage(@RequestParam Long couponId, @RequestParam(required = false) Integer type) {
Page<MkCouponGiftDTO> data = couponGiftService.getCouponGiftPage(couponId, type); // Page<MkCouponGiftDTO> data = couponGiftService.getCouponGiftPage(couponId, type);
return CzgResult.success(data); // return CzgResult.success(data);
} // }
/** /**
* 优惠券列表/已领取详情 * 优惠券列表/已领取详情
* *
* @param param 用户的优惠券列表 使用该对象的UserId
*/ */
@GetMapping("/record") @GetMapping("/record")
public CzgResult<Page<MkShopCouponRecordDTO>> getRecord( public CzgResult<Page<MkShopCouponRecordDTO>> getRecordByCoupon(
@RequestParam(required = false) String startTime, @RequestParam(required = false) String startTime,
@RequestParam(required = false) String endTime, @RequestParam(required = false) String endTime,
MkShopCouponRecordDTO param) { MkShopCouponRecordDTO param) {
@ -150,43 +149,57 @@ public class ACouponController {
} }
/** /**
* 删除用户优惠券 失效 * 优惠券列表/已领取详情
* *
* @param id 优惠券记录Id * @param param 用户的优惠券列表 使用该对象的UserId
*/ */
@DeleteMapping("/deleteRecord") @GetMapping("/getRecordByUser")
public CzgResult<Void> cancelRecord(Long id) { public CzgResult<Page<MkShopCouponRecordDTO>> getRecordByUser(
couponRecordService.deleteRecord(id); @RequestParam(required = false) String startTime,
return CzgResult.success(); @RequestParam(required = false) String endTime,
MkShopCouponRecordDTO param) {
Page<MkShopCouponRecordDTO> data = couponRecordService.getRecordByUser(param, startTime, endTime);
return CzgResult.success(data);
} }
private void asyncToBranchShop(Long id, Integer type) { // /**
long shopId = StpKit.USER.getShopId(0L); // * 删除用户优惠券 失效
log.info("优惠券同步,优惠券id:{},类型:{}", id, type); // *
ThreadUtil.execAsync(() -> { // * @param id 优惠券记录Id
shopSyncService.syncCouponBySourceShop(shopId, id, type); // */
}); // @DeleteMapping("/deleteRecord")
} // public CzgResult<Void> cancelRecord(Long id) {
// couponRecordService.deleteRecord(id);
/** // return CzgResult.success();
* 券发放 // }
* //
* @return 是否发放成功 // private void asyncToBranchShop(Long id, Integer type) {
*/ // long shopId = StpKit.USER.getShopId(0L);
@PostMapping("/grant") // log.info("优惠券同步,优惠券id:{},类型:{}", id, type);
public CzgResult<Boolean> rewardCoupon(@Validated @RequestBody MkRewardCouponDTO rewardCouponDTO) { // ThreadUtil.execAsync(() -> {
return CzgResult.success(couponRecordService.grant(rewardCouponDTO.getShopId() != null ? rewardCouponDTO.getShopId() : StpKit.USER.getShopId(), rewardCouponDTO)); // shopSyncService.syncCouponBySourceShop(shopId, id, type);
} // });
// }
//
/** // /**
* 生成订单后使用 // * 券发放
* 通过用户Id 查找优惠券 // *
* // * @return 是否发放成功
* @param shopUserId 店铺用户Id // */
*/ // @PostMapping("/grant")
@GetMapping("/findCoupon") // public CzgResult<Boolean> rewardCoupon(@Validated @RequestBody MkRewardCouponDTO rewardCouponDTO) {
public CzgResult<List<UserCouponVo>> findCoupon(@RequestParam Long shopUserId, @RequestParam(required = false) Integer type, @RequestParam(required = false) Integer isFood) { // return CzgResult.success(couponRecordService.grant(rewardCouponDTO.getShopId() != null ? rewardCouponDTO.getShopId() : StpKit.USER.getShopId(), rewardCouponDTO));
return CzgResult.success(shopCouponService.findCoupon(StpKit.USER.getShopId(), shopUserId, type, isFood)); // }
} //
//
// /**
// * 生成订单后使用
// * 通过用户Id 查找优惠券
// *
// * @param shopUserId 店铺用户Id
// */
// @GetMapping("/findCoupon")
// public CzgResult<List<UserCouponVo>> findCoupon(@RequestParam Long shopUserId, @RequestParam(required = false) Integer type, @RequestParam(required = false) Integer isFood) {
// return CzgResult.success(shopCouponService.findCoupon(StpKit.USER.getShopId(), shopUserId, type, isFood));
// }
} }

View File

@ -32,6 +32,7 @@ public interface MkShopCouponRecordService extends IService<MkShopCouponRecord>
* 优惠券列表/已领取详情 * 优惠券列表/已领取详情
*/ */
Page<MkShopCouponRecordDTO> getRecord(MkShopCouponRecordDTO param, String startTime, String endTime); Page<MkShopCouponRecordDTO> getRecord(MkShopCouponRecordDTO param, String startTime, String endTime);
Page<MkShopCouponRecordDTO> getRecordByUser(MkShopCouponRecordDTO param, String startTime, String endTime);
/** /**
* 发放券 统一方法 * 发放券 统一方法

View File

@ -82,10 +82,7 @@ public class MkShopCouponRecordServiceImpl extends ServiceImpl<MkShopCouponRecor
@Override @Override
public Page<MkShopCouponRecordDTO> getRecord(MkShopCouponRecordDTO mkShopCouponRecordDTO, String startTime, String endTime) { public Page<MkShopCouponRecordDTO> getRecord(MkShopCouponRecordDTO mkShopCouponRecordDTO, String startTime, String endTime) {
Map<Long, UserInfo> userInfoMap = new HashMap<>(); Map<Long, UserInfo> userInfoMap = new HashMap<>();
if (mkShopCouponRecordDTO.getCouponId() == null) { AssertUtil.isNull(mkShopCouponRecordDTO.getCouponId(), "优惠券Id不能为空");
throw new CzgException("优惠券Id不能为空");
}
ShopCoupon coupon = couponService.selectOneById(mkShopCouponRecordDTO.getCouponId()); ShopCoupon coupon = couponService.selectOneById(mkShopCouponRecordDTO.getCouponId());
AssertUtil.isNull(coupon, "优惠券不存在"); AssertUtil.isNull(coupon, "优惠券不存在");
QueryWrapper recordQueryWrapper = new QueryWrapper(); QueryWrapper recordQueryWrapper = new QueryWrapper();
@ -95,7 +92,7 @@ public class MkShopCouponRecordServiceImpl extends ServiceImpl<MkShopCouponRecor
q1.eq(MkShopCouponRecord::getCouponSyncId, coupon.getSyncId()); q1.eq(MkShopCouponRecord::getCouponSyncId, coupon.getSyncId());
}); });
}); });
}else { } else {
recordQueryWrapper.and(q -> { recordQueryWrapper.and(q -> {
q.eq(MkShopCouponRecord::getCouponId, coupon.getId()).or(q1 -> { q.eq(MkShopCouponRecord::getCouponId, coupon.getId()).or(q1 -> {
q1.eq(MkShopCouponRecord::getCouponSyncId, coupon.getId()); q1.eq(MkShopCouponRecord::getCouponSyncId, coupon.getId());
@ -135,6 +132,32 @@ public class MkShopCouponRecordServiceImpl extends ServiceImpl<MkShopCouponRecor
return recordPage; return recordPage;
} }
@Override
public Page<MkShopCouponRecordDTO> getRecordByUser(MkShopCouponRecordDTO mkShopCouponRecordDTO, String startTime, String endTime) {
AssertUtil.isNull(mkShopCouponRecordDTO.getShopId(), "店铺ID不能为空");
AssertUtil.isNull(mkShopCouponRecordDTO.getUserId(), "用户ID不能为空");
QueryWrapper recordQueryWrapper = new QueryWrapper();
recordQueryWrapper.eq(MkShopCouponRecord::getShopId, mkShopCouponRecordDTO.getShopId())
.eq(MkShopCouponRecord::getIsDel, 0)
.eq(MkShopCouponRecord::getStatus, mkShopCouponRecordDTO.getStatus())
.eq(MkShopCouponRecord::getUserId, mkShopCouponRecordDTO.getUserId())
.orderBy(MkShopCouponRecord::getCreateTime).desc();
if (StrUtil.isNotBlank(startTime) && StrUtil.isNotBlank(endTime)) {
recordQueryWrapper.between(MkShopCouponRecord::getCreateTime, startTime, endTime);
}
Page<MkShopCouponRecordDTO> recordPage = pageAs(PageUtil.buildPage(), recordQueryWrapper, MkShopCouponRecordDTO.class);
if (mkShopCouponRecordDTO.getUserId() != null) {
UserInfo userInfo = userInfoService.getById(mkShopCouponRecordDTO.getUserId());
for (MkShopCouponRecordDTO record : recordPage.getRecords()) {
record.setHeadImg(userInfo.getHeadImg());
record.setNickName(userInfo.getNickName());
}
}
return recordPage;
}
@Override @Override
public void receiveCoupon(MkShopCouponGiftDTO giftDTO, Integer number, boolean isLimit) { public void receiveCoupon(MkShopCouponGiftDTO giftDTO, Integer number, boolean isLimit) {
if (number == null || number <= 0) { if (number == null || number <= 0) {