优惠券
This commit is contained in:
parent
56a9728f28
commit
34089ce86d
|
|
@ -46,94 +46,94 @@ 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 优惠券列表/已领取详情
|
||||
|
|
@ -162,44 +162,44 @@ public class ACouponController {
|
|||
return CzgResult.success(data);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 删除用户优惠券 失效
|
||||
// *
|
||||
// * @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));
|
||||
// }
|
||||
/**
|
||||
* 删除用户优惠券 失效
|
||||
*
|
||||
* @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));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue