用户优惠券列表
This commit is contained in:
parent
548f582d49
commit
56a9728f28
|
|
@ -46,102 +46,101 @@ public class ACouponController {
|
|||
/**
|
||||
* 分页
|
||||
*/
|
||||
@GetMapping("page")
|
||||
// @OperationLog("优惠券列表-分页")
|
||||
// @SaAdminCheckPermission("coupon:page")
|
||||
public CzgResult<Page<ShopCouponDTO>> getCouponPage(ShopCouponDTO param) {
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
param.setShopId(shopId);
|
||||
Page<ShopCouponDTO> data = shopCouponService.getCouponPage(param);
|
||||
return CzgResult.success(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 详情
|
||||
*
|
||||
* @param id 主键id
|
||||
*/
|
||||
@GetMapping("{id}")
|
||||
// @OperationLog("优惠券-详情")
|
||||
// @SaAdminCheckPermission("coupon:info")
|
||||
public CzgResult<ShopCouponDTO> getCouponById(@PathVariable("id") Long id) {
|
||||
AssertUtil.isNull(id, "{}不能为空", "id");
|
||||
ShopCouponDTO data = shopCouponService.getCouponById(id);
|
||||
return CzgResult.success(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
@PostMapping
|
||||
@OperationLog("优惠券-新增")
|
||||
// @SaAdminCheckPermission("coupon:add")
|
||||
public CzgResult<Void> addCoupon(@RequestBody @Validated({InsertGroup.class, DefaultGroup.class}) ShopCouponDTO dto) {
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
dto.setShopId(shopId);
|
||||
dto.setLeftNum(dto.getGiveNum());
|
||||
shopCouponService.addCoupon(dto);
|
||||
asyncToBranchShop(dto.getId(), 1);
|
||||
return CzgResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@PutMapping
|
||||
@OperationLog("优惠券-修改")
|
||||
// @SaAdminCheckPermission("coupon:update")
|
||||
public CzgResult<Void> updateCoupon(@RequestBody @Validated({UpdateGroup.class, DefaultGroup.class}) ShopCouponDTO dto) {
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
dto.setShopId(shopId);
|
||||
shopCouponService.updateCouponById(dto);
|
||||
couponGiftService.upCouponName(dto.getId(), dto.getTitle());
|
||||
asyncToBranchShop(dto.getId(), 2);
|
||||
return CzgResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@DeleteMapping
|
||||
@OperationLog("优惠券-删除")
|
||||
// @SaAdminCheckPermission("prodGroup:delete")
|
||||
public CzgResult<String> deleteCoupon(@RequestParam Long id, @RequestParam Integer type) {
|
||||
AssertUtil.isNull(id, "{}不能为空", "id");
|
||||
if (type != 1) {
|
||||
List<MkCouponGiftDTO> gifts = couponGiftService.getCouponGiftBySourceId(id, 3);
|
||||
if (CollUtil.isNotEmpty(gifts)) {
|
||||
String collect = gifts.stream()
|
||||
.map(MkCouponGiftDTO::getSourceName)
|
||||
.filter(name -> name != null && !name.isEmpty())
|
||||
.collect(Collectors.joining(","));
|
||||
return CzgResult.success(collect);
|
||||
}
|
||||
}
|
||||
shopCouponService.deleteCoupon(id);
|
||||
couponGiftService.deleteCoupon(id);
|
||||
asyncToBranchShop(id, 3);
|
||||
return CzgResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取该券关联的功能列表
|
||||
*
|
||||
* @param couponId 如果syncId有值 则为syncId 否则为id
|
||||
*/
|
||||
@GetMapping("/gifts")
|
||||
public CzgResult<Page<MkCouponGiftDTO>> getCouponGiftPage(@RequestParam Long couponId, @RequestParam(required = false) Integer type) {
|
||||
Page<MkCouponGiftDTO> data = couponGiftService.getCouponGiftPage(couponId, type);
|
||||
return CzgResult.success(data);
|
||||
}
|
||||
// @GetMapping("page")
|
||||
//// @OperationLog("优惠券列表-分页")
|
||||
//// @SaAdminCheckPermission("coupon:page")
|
||||
// public CzgResult<Page<ShopCouponDTO>> getCouponPage(ShopCouponDTO param) {
|
||||
// Long shopId = StpKit.USER.getShopId(0L);
|
||||
// param.setShopId(shopId);
|
||||
// Page<ShopCouponDTO> data = shopCouponService.getCouponPage(param);
|
||||
// return CzgResult.success(data);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 详情
|
||||
// *
|
||||
// * @param id 主键id
|
||||
// */
|
||||
// @GetMapping("{id}")
|
||||
//// @OperationLog("优惠券-详情")
|
||||
//// @SaAdminCheckPermission("coupon:info")
|
||||
// public CzgResult<ShopCouponDTO> getCouponById(@PathVariable("id") Long id) {
|
||||
// AssertUtil.isNull(id, "{}不能为空", "id");
|
||||
// ShopCouponDTO data = shopCouponService.getCouponById(id);
|
||||
// return CzgResult.success(data);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 新增
|
||||
// */
|
||||
// @PostMapping
|
||||
// @OperationLog("优惠券-新增")
|
||||
//// @SaAdminCheckPermission("coupon:add")
|
||||
// public CzgResult<Void> addCoupon(@RequestBody @Validated({InsertGroup.class, DefaultGroup.class}) ShopCouponDTO dto) {
|
||||
// Long shopId = StpKit.USER.getShopId(0L);
|
||||
// dto.setShopId(shopId);
|
||||
// dto.setLeftNum(dto.getGiveNum());
|
||||
// shopCouponService.addCoupon(dto);
|
||||
// asyncToBranchShop(dto.getId(), 1);
|
||||
// return CzgResult.success();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 修改
|
||||
// */
|
||||
// @PutMapping
|
||||
// @OperationLog("优惠券-修改")
|
||||
//// @SaAdminCheckPermission("coupon:update")
|
||||
// public CzgResult<Void> updateCoupon(@RequestBody @Validated({UpdateGroup.class, DefaultGroup.class}) ShopCouponDTO dto) {
|
||||
// Long shopId = StpKit.USER.getShopId(0L);
|
||||
// dto.setShopId(shopId);
|
||||
// shopCouponService.updateCouponById(dto);
|
||||
// couponGiftService.upCouponName(dto.getId(), dto.getTitle());
|
||||
// asyncToBranchShop(dto.getId(), 2);
|
||||
// return CzgResult.success();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 删除
|
||||
// */
|
||||
// @DeleteMapping
|
||||
// @OperationLog("优惠券-删除")
|
||||
//// @SaAdminCheckPermission("prodGroup:delete")
|
||||
// public CzgResult<String> deleteCoupon(@RequestParam Long id, @RequestParam Integer type) {
|
||||
// AssertUtil.isNull(id, "{}不能为空", "id");
|
||||
// if (type != 1) {
|
||||
// List<MkCouponGiftDTO> gifts = couponGiftService.getCouponGiftBySourceId(id, 3);
|
||||
// if (CollUtil.isNotEmpty(gifts)) {
|
||||
// String collect = gifts.stream()
|
||||
// .map(MkCouponGiftDTO::getSourceName)
|
||||
// .filter(name -> name != null && !name.isEmpty())
|
||||
// .collect(Collectors.joining(","));
|
||||
// return CzgResult.success(collect);
|
||||
// }
|
||||
// }
|
||||
// shopCouponService.deleteCoupon(id);
|
||||
// couponGiftService.deleteCoupon(id);
|
||||
// asyncToBranchShop(id, 3);
|
||||
// return CzgResult.success();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 获取该券关联的功能列表
|
||||
// *
|
||||
// * @param couponId 如果syncId有值 则为syncId 否则为id
|
||||
// */
|
||||
// @GetMapping("/gifts")
|
||||
// public CzgResult<Page<MkCouponGiftDTO>> getCouponGiftPage(@RequestParam Long couponId, @RequestParam(required = false) Integer type) {
|
||||
// Page<MkCouponGiftDTO> data = couponGiftService.getCouponGiftPage(couponId, type);
|
||||
// return CzgResult.success(data);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 优惠券列表/已领取详情
|
||||
*
|
||||
* @param param 用户的优惠券列表 使用该对象的UserId
|
||||
*/
|
||||
@GetMapping("/record")
|
||||
public CzgResult<Page<MkShopCouponRecordDTO>> getRecord(
|
||||
public CzgResult<Page<MkShopCouponRecordDTO>> getRecordByCoupon(
|
||||
@RequestParam(required = false) String startTime,
|
||||
@RequestParam(required = false) String endTime,
|
||||
MkShopCouponRecordDTO param) {
|
||||
|
|
@ -150,43 +149,57 @@ public class ACouponController {
|
|||
}
|
||||
|
||||
/**
|
||||
* 删除用户优惠券 失效
|
||||
* 优惠券列表/已领取详情
|
||||
*
|
||||
* @param id 优惠券记录Id
|
||||
* @param param 用户的优惠券列表 使用该对象的UserId
|
||||
*/
|
||||
@DeleteMapping("/deleteRecord")
|
||||
public CzgResult<Void> cancelRecord(Long id) {
|
||||
couponRecordService.deleteRecord(id);
|
||||
return CzgResult.success();
|
||||
@GetMapping("/getRecordByUser")
|
||||
public CzgResult<Page<MkShopCouponRecordDTO>> getRecordByUser(
|
||||
@RequestParam(required = false) String startTime,
|
||||
@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(() -> {
|
||||
shopSyncService.syncCouponBySourceShop(shopId, id, type);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 券发放
|
||||
*
|
||||
* @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));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 生成订单后使用
|
||||
* 通过用户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));
|
||||
}
|
||||
// /**
|
||||
// * 删除用户优惠券 失效
|
||||
// *
|
||||
// * @param id 优惠券记录Id
|
||||
// */
|
||||
// @DeleteMapping("/deleteRecord")
|
||||
// public CzgResult<Void> cancelRecord(Long id) {
|
||||
// couponRecordService.deleteRecord(id);
|
||||
// return CzgResult.success();
|
||||
// }
|
||||
//
|
||||
// private void asyncToBranchShop(Long id, Integer type) {
|
||||
// long shopId = StpKit.USER.getShopId(0L);
|
||||
// log.info("优惠券同步,优惠券id:{},类型:{}", id, type);
|
||||
// ThreadUtil.execAsync(() -> {
|
||||
// shopSyncService.syncCouponBySourceShop(shopId, id, type);
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 券发放
|
||||
// *
|
||||
// * @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));
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 生成订单后使用
|
||||
// * 通过用户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));
|
||||
// }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ public interface MkShopCouponRecordService extends IService<MkShopCouponRecord>
|
|||
* 优惠券列表/已领取详情
|
||||
*/
|
||||
Page<MkShopCouponRecordDTO> getRecord(MkShopCouponRecordDTO param, String startTime, String endTime);
|
||||
Page<MkShopCouponRecordDTO> getRecordByUser(MkShopCouponRecordDTO param, String startTime, String endTime);
|
||||
|
||||
/**
|
||||
* 发放券 统一方法
|
||||
|
|
|
|||
|
|
@ -82,10 +82,7 @@ public class MkShopCouponRecordServiceImpl extends ServiceImpl<MkShopCouponRecor
|
|||
@Override
|
||||
public Page<MkShopCouponRecordDTO> getRecord(MkShopCouponRecordDTO mkShopCouponRecordDTO, String startTime, String endTime) {
|
||||
Map<Long, UserInfo> userInfoMap = new HashMap<>();
|
||||
if (mkShopCouponRecordDTO.getCouponId() == null) {
|
||||
throw new CzgException("优惠券Id不能为空");
|
||||
}
|
||||
|
||||
AssertUtil.isNull(mkShopCouponRecordDTO.getCouponId(), "优惠券Id不能为空");
|
||||
ShopCoupon coupon = couponService.selectOneById(mkShopCouponRecordDTO.getCouponId());
|
||||
AssertUtil.isNull(coupon, "优惠券不存在");
|
||||
QueryWrapper recordQueryWrapper = new QueryWrapper();
|
||||
|
|
@ -95,7 +92,7 @@ public class MkShopCouponRecordServiceImpl extends ServiceImpl<MkShopCouponRecor
|
|||
q1.eq(MkShopCouponRecord::getCouponSyncId, coupon.getSyncId());
|
||||
});
|
||||
});
|
||||
}else {
|
||||
} else {
|
||||
recordQueryWrapper.and(q -> {
|
||||
q.eq(MkShopCouponRecord::getCouponId, coupon.getId()).or(q1 -> {
|
||||
q1.eq(MkShopCouponRecord::getCouponSyncId, coupon.getId());
|
||||
|
|
@ -135,6 +132,32 @@ public class MkShopCouponRecordServiceImpl extends ServiceImpl<MkShopCouponRecor
|
|||
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
|
||||
public void receiveCoupon(MkShopCouponGiftDTO giftDTO, Integer number, boolean isLimit) {
|
||||
if (number == null || number <= 0) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue