消费赠券 优惠券
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
package com.czg.controller.admin;
|
||||
|
||||
import com.czg.market.dto.MkShopConsumerCouponDTO;
|
||||
import com.czg.market.service.MkShopConsumerCouponService;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.validator.group.DefaultGroup;
|
||||
import com.czg.validator.group.UpdateGroup;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* 消费赠券
|
||||
* @author ww
|
||||
* @description
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/admin/consumerCoupon")
|
||||
public class AConsumerCouponController {
|
||||
|
||||
@Resource
|
||||
private MkShopConsumerCouponService mkShopConsumerCouponService;
|
||||
|
||||
/**
|
||||
* 分页
|
||||
*/
|
||||
@GetMapping("/getConsumerCouponPage")
|
||||
public CzgResult<Page<MkShopConsumerCouponDTO>> getConsumerCouponPage(MkShopConsumerCouponDTO param) {
|
||||
return CzgResult.success(mkShopConsumerCouponService.getConsumerCouponPage(param));
|
||||
}
|
||||
|
||||
/**
|
||||
* 详情
|
||||
*/
|
||||
@GetMapping("/getConsumerCouponById")
|
||||
public CzgResult<MkShopConsumerCouponDTO> getConsumerCouponById(Long id) {
|
||||
return CzgResult.success(mkShopConsumerCouponService.getConsumerCouponById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
@PostMapping("/addConsumerCoupon")
|
||||
public CzgResult<Void> addConsumerCoupon(@RequestBody @Validated({UpdateGroup.class, DefaultGroup.class}) MkShopConsumerCouponDTO param) {
|
||||
mkShopConsumerCouponService.addConsumerCoupon(param);
|
||||
return CzgResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新
|
||||
*/
|
||||
@PutMapping("/updateConsumerCouponById")
|
||||
public CzgResult<Void> updateConsumerCouponById(@RequestBody @Validated({UpdateGroup.class, DefaultGroup.class}) MkShopConsumerCouponDTO param) {
|
||||
mkShopConsumerCouponService.updateConsumerCouponById(param);
|
||||
return CzgResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@DeleteMapping("/deleteConsumerCoupon")
|
||||
public CzgResult<Void> deleteConsumerCoupon(Long id) {
|
||||
mkShopConsumerCouponService.deleteConsumerCoupon(id);
|
||||
return CzgResult.success();
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.czg.controller.admin;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import com.czg.annotation.SaAdminCheckPermission;
|
||||
import com.czg.log.annotation.OperationLog;
|
||||
import com.czg.market.dto.MkCouponGiftDTO;
|
||||
import com.czg.market.dto.ShopCouponDTO;
|
||||
import com.czg.market.service.MkCouponGiftService;
|
||||
import com.czg.market.service.ShopCouponService;
|
||||
import com.czg.product.service.ShopSyncService;
|
||||
import com.czg.resp.CzgResult;
|
||||
@@ -19,6 +21,9 @@ import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 优惠券
|
||||
*
|
||||
@@ -30,6 +35,8 @@ import org.springframework.web.bind.annotation.*;
|
||||
public class ACouponController {
|
||||
@Resource
|
||||
private ShopCouponService shopCouponService;
|
||||
@Resource
|
||||
private MkCouponGiftService couponGiftService;
|
||||
@DubboReference
|
||||
private ShopSyncService shopSyncService;
|
||||
|
||||
@@ -37,7 +44,7 @@ public class ACouponController {
|
||||
* 分页
|
||||
*/
|
||||
@GetMapping("page")
|
||||
@OperationLog("优惠券列表-分页")
|
||||
// @OperationLog("优惠券列表-分页")
|
||||
// @SaAdminCheckPermission("coupon:page")
|
||||
public CzgResult<Page<ShopCouponDTO>> getCouponPage(ShopCouponDTO param) {
|
||||
Page<ShopCouponDTO> data = shopCouponService.getCouponPage(param);
|
||||
@@ -47,10 +54,10 @@ public class ACouponController {
|
||||
/**
|
||||
* 详情
|
||||
*
|
||||
* @param id 分组id
|
||||
* @param id 主键id
|
||||
*/
|
||||
@GetMapping("{id}")
|
||||
@OperationLog("优惠券-详情")
|
||||
// @OperationLog("优惠券-详情")
|
||||
// @SaAdminCheckPermission("coupon:info")
|
||||
public CzgResult<ShopCouponDTO> getCouponById(@PathVariable("id") Long id) {
|
||||
AssertUtil.isNull(id, "{}不能为空", "id");
|
||||
@@ -83,6 +90,7 @@ public class ACouponController {
|
||||
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();
|
||||
}
|
||||
@@ -90,16 +98,38 @@ public class ACouponController {
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@DeleteMapping("{id}")
|
||||
@DeleteMapping
|
||||
@OperationLog("优惠券-删除")
|
||||
// @SaAdminCheckPermission("prodGroup:delete")
|
||||
public CzgResult<Void> deleteCoupon(@PathVariable("id") Long id) {
|
||||
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>> getCouponPage(Long couponId) {
|
||||
Page<MkCouponGiftDTO> data = couponGiftService.getCouponGiftPage(couponId);
|
||||
return CzgResult.success(data);
|
||||
}
|
||||
|
||||
|
||||
private void asyncToBranchShop(Long id, Integer type) {
|
||||
long shopId = StpKit.USER.getShopId(0L);
|
||||
log.info("优惠券同步,优惠券id:{},类型:{}", id, type);
|
||||
|
||||
Reference in New Issue
Block a user