消费赠券 优惠券
This commit is contained in:
parent
2e69148249
commit
3b53b460fd
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ public class MkCouponGiftDTO implements Serializable {
|
|||
private String couponName;
|
||||
|
||||
/**
|
||||
* 券ID
|
||||
* 券ID 如果是子店铺 则使用主店铺的券ID
|
||||
*/
|
||||
private Long couponId;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,129 @@
|
|||
|
||||
package com.czg.market.dto;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import java.io.Serial;
|
||||
import java.util.List;
|
||||
|
||||
import com.czg.validator.group.InsertGroup;
|
||||
import com.czg.validator.group.UpdateGroup;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Null;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 消费赠券表 实体类。
|
||||
*
|
||||
* @author ww
|
||||
* @since 2025-09-12
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class MkShopConsumerCouponDTO implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 自增主键
|
||||
*/
|
||||
@Null(message = "ID必须为空", groups = InsertGroup.class)
|
||||
@NotNull(message = "ID不能为空", groups = UpdateGroup.class)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 店铺ID
|
||||
*/
|
||||
private Long shopId;
|
||||
|
||||
/**
|
||||
* 同步Id 预留
|
||||
*/
|
||||
// private Long syncId;
|
||||
|
||||
/**
|
||||
* 券名称
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* only-仅本店 all全部 /custom 指定
|
||||
*/
|
||||
// private String useShopType;
|
||||
|
||||
/**
|
||||
* 可用门店
|
||||
*/
|
||||
// private String useShops;
|
||||
|
||||
/**
|
||||
* 可使用类型:dine堂食/pickup自取/deliv配送/express快递
|
||||
*/
|
||||
private String useType;
|
||||
|
||||
/**
|
||||
* 总发放数量,-10086为不限量
|
||||
*/
|
||||
private Integer giveNum;
|
||||
|
||||
/**
|
||||
* 每人领取限量,-10086为不限量
|
||||
*/
|
||||
private Integer getLimit;
|
||||
|
||||
/**
|
||||
* 每人每日使用限量,-10086为不限量
|
||||
*/
|
||||
private Integer useLimit;
|
||||
|
||||
/**
|
||||
* 状态:0-禁用,1-启用
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 已使用数量
|
||||
*/
|
||||
private Integer useNum;
|
||||
|
||||
/**
|
||||
* 剩余数量
|
||||
*/
|
||||
private Integer leftNum;
|
||||
|
||||
/**
|
||||
* 使用门槛:满多少金额
|
||||
*/
|
||||
private BigDecimal fullAmount;
|
||||
|
||||
/**
|
||||
* 券ID
|
||||
*/
|
||||
private Integer couponId;
|
||||
|
||||
/**
|
||||
* 券数量
|
||||
*/
|
||||
private Integer couponNum;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
List<MkCouponGiftDTO> couponGiftList;
|
||||
|
||||
}
|
||||
|
|
@ -11,6 +11,7 @@ import lombok.AllArgsConstructor;
|
|||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 券赠送关联表 实体类。
|
||||
|
|
@ -22,6 +23,7 @@ import lombok.NoArgsConstructor;
|
|||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
@Table("mk_coupon_gift")
|
||||
public class MkCouponGift implements Serializable {
|
||||
|
||||
|
|
@ -52,7 +54,7 @@ public class MkCouponGift implements Serializable {
|
|||
private String couponName;
|
||||
|
||||
/**
|
||||
* 券ID
|
||||
* 券ID 如果是子店铺 则使用主店铺的券ID
|
||||
*/
|
||||
private Long couponId;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,127 @@
|
|||
package com.czg.market.entity;
|
||||
|
||||
import com.mybatisflex.annotation.Column;
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.KeyType;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 消费赠券表 实体类。
|
||||
*
|
||||
* @author ww
|
||||
* @since 2025-09-12
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table("mk_shop_consumer_coupon")
|
||||
public class MkShopConsumerCoupon implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 自增主键
|
||||
*/
|
||||
@Id(keyType = KeyType.Auto)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 店铺ID
|
||||
*/
|
||||
private Long shopId;
|
||||
|
||||
/**
|
||||
* 同步Id 预留
|
||||
*/
|
||||
// private Long syncId;
|
||||
|
||||
/**
|
||||
* 券名称
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* only-仅本店 all全部 /custom 指定
|
||||
*/
|
||||
// private String useShopType;
|
||||
|
||||
/**
|
||||
* 可用门店
|
||||
*/
|
||||
// private String useShops;
|
||||
|
||||
/**
|
||||
* 可使用类型:dine堂食/pickup自取/deliv配送/express快递
|
||||
*/
|
||||
private String useType;
|
||||
|
||||
/**
|
||||
* 总发放数量,-10086为不限量
|
||||
*/
|
||||
private Integer giveNum;
|
||||
|
||||
/**
|
||||
* 每人领取限量,-10086为不限量
|
||||
*/
|
||||
private Integer getLimit;
|
||||
|
||||
/**
|
||||
* 每人每日使用限量,-10086为不限量
|
||||
*/
|
||||
private Integer useLimit;
|
||||
|
||||
/**
|
||||
* 状态:0-禁用,1-启用
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 已使用数量
|
||||
*/
|
||||
private Integer useNum;
|
||||
|
||||
/**
|
||||
* 剩余数量
|
||||
*/
|
||||
private Integer leftNum;
|
||||
|
||||
/**
|
||||
* 使用门槛:满多少金额
|
||||
*/
|
||||
private BigDecimal fullAmount;
|
||||
|
||||
/**
|
||||
* 券ID
|
||||
*/
|
||||
private Integer couponId;
|
||||
|
||||
/**
|
||||
* 券数量
|
||||
*/
|
||||
private Integer couponNum;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@Column(onInsertValue = "now()")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@Column(onUpdateValue = "now()")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
}
|
||||
|
|
@ -15,6 +15,7 @@ import lombok.AllArgsConstructor;
|
|||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 优惠券信息表 实体类。
|
||||
|
|
@ -27,6 +28,7 @@ import lombok.NoArgsConstructor;
|
|||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Table("mk_shop_coupon")
|
||||
@Accessors(chain = true)
|
||||
public class ShopCoupon implements Serializable {
|
||||
|
||||
@Serial
|
||||
|
|
@ -230,4 +232,9 @@ public class ShopCoupon implements Serializable {
|
|||
@Column(onInsertValue = "now()", onUpdateValue = "now()")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 删除状态:0-正常,1-已删除
|
||||
*/
|
||||
private Integer isDel;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ public interface MkCouponGiftService extends IService<MkCouponGift> {
|
|||
*
|
||||
* @param sourceId 来源ID
|
||||
* @param type 类型 1 会员开通赠券 2 会员周活动 3 消费赠券
|
||||
* @param couponGiftList 券ID-数量
|
||||
* @param couponGiftList 券ID 如果是子店铺 则使用主店铺的券ID-数量
|
||||
*/
|
||||
void addCouponGift(Long sourceId, String sourceName, Integer type, List<MkCouponGiftDTO> couponGiftList);
|
||||
|
||||
|
|
@ -43,7 +43,7 @@ public interface MkCouponGiftService extends IService<MkCouponGift> {
|
|||
*
|
||||
* @param sourceId 来源ID
|
||||
* @param type 类型 1 会员开通赠券 2 会员周活动 3 消费赠券
|
||||
* @param couponGiftList 券ID和数量必填
|
||||
* @param couponGiftList 券ID 如果是子店铺 则使用主店铺的券ID和数量必填
|
||||
*/
|
||||
void upCouponGift(Long sourceId, String sourceName, Integer type, List<MkCouponGiftDTO> couponGiftList);
|
||||
|
||||
|
|
@ -54,4 +54,19 @@ public interface MkCouponGiftService extends IService<MkCouponGift> {
|
|||
* @param type 类型 1 会员开通赠券 2 会员周活动 3 消费赠券
|
||||
*/
|
||||
void deleteJoinCouponGift(Long sourceId, Integer type);
|
||||
|
||||
/**
|
||||
* 通过券删除关联
|
||||
*
|
||||
* @param couponId 券ID
|
||||
*/
|
||||
void deleteCoupon(Long couponId);
|
||||
|
||||
/**
|
||||
* 更新券名称
|
||||
*
|
||||
* @param couponId 券ID
|
||||
* @param couponName 券名称
|
||||
*/
|
||||
void upCouponName(Long couponId, String couponName);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
package com.czg.market.service;
|
||||
|
||||
import com.czg.market.dto.MkShopConsumerCouponDTO;
|
||||
import com.czg.market.entity.MkShopConsumerCoupon;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.service.IService;
|
||||
|
||||
/**
|
||||
* 消费赠券表 服务层。
|
||||
*
|
||||
* @author ww
|
||||
* @since 2025-09-12
|
||||
*/
|
||||
public interface MkShopConsumerCouponService extends IService<MkShopConsumerCoupon> {
|
||||
|
||||
Page<MkShopConsumerCouponDTO> getConsumerCouponPage(MkShopConsumerCouponDTO param);
|
||||
MkShopConsumerCouponDTO getConsumerCouponById(Long id);
|
||||
void addConsumerCoupon(MkShopConsumerCouponDTO param);
|
||||
void updateConsumerCouponById(MkShopConsumerCouponDTO param);
|
||||
void deleteConsumerCoupon(Long id);
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package com.czg.service.market.mapper;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.czg.market.entity.MkShopConsumerCoupon;
|
||||
|
||||
/**
|
||||
* 消费赠券表 映射层。
|
||||
*
|
||||
* @author ww
|
||||
* @since 2025-09-12
|
||||
*/
|
||||
public interface MkShopConsumerCouponMapper extends BaseMapper<MkShopConsumerCoupon> {
|
||||
|
||||
}
|
||||
|
|
@ -57,6 +57,7 @@ public class MkCouponGiftServiceImpl extends ServiceImpl<MkCouponGiftMapper, MkC
|
|||
couponGift.setSourceId(sourceId);
|
||||
couponGift.setSourceName(sourceName);
|
||||
couponGift.setType(type);
|
||||
couponGift.setCouponName(coupon.getTitle());
|
||||
couponGift.setCouponId(giftDTO.getCouponId());
|
||||
couponGift.setNum(giftDTO.getNum());
|
||||
newCoupons.add(couponGift);
|
||||
|
|
@ -65,6 +66,7 @@ public class MkCouponGiftServiceImpl extends ServiceImpl<MkCouponGiftMapper, MkC
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void upCouponGift(Long sourceId, String sourceName, Integer type, List<MkCouponGiftDTO> couponGiftList) {
|
||||
deleteJoinCouponGift(sourceId, type);
|
||||
|
|
@ -75,4 +77,14 @@ public class MkCouponGiftServiceImpl extends ServiceImpl<MkCouponGiftMapper, MkC
|
|||
public void deleteJoinCouponGift(Long sourceId, Integer type) {
|
||||
remove(new QueryWrapper().eq(MkCouponGift::getSourceId, sourceId).eq(MkCouponGift::getType, type));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteCoupon(Long couponId) {
|
||||
remove(new QueryWrapper().eq(MkCouponGift::getCouponId, couponId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void upCouponName(Long couponId, String couponName) {
|
||||
update(new MkCouponGift().setCouponName(couponName), new QueryWrapper().eq(MkCouponGift::getCouponId, couponId));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,77 @@
|
|||
package com.czg.service.market.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.czg.market.dto.MkShopConsumerCouponDTO;
|
||||
import com.czg.market.entity.MkShopConsumerCoupon;
|
||||
import com.czg.market.service.MkCouponGiftService;
|
||||
import com.czg.market.service.MkShopConsumerCouponService;
|
||||
import com.czg.service.market.mapper.MkShopConsumerCouponMapper;
|
||||
import com.czg.utils.AssertUtil;
|
||||
import com.czg.utils.PageUtil;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* 消费赠券表 服务层实现。
|
||||
*
|
||||
* @author ww
|
||||
* @since 2025-09-12
|
||||
*/
|
||||
@Service
|
||||
public class MkShopConsumerCouponServiceImpl extends ServiceImpl<MkShopConsumerCouponMapper, MkShopConsumerCoupon> implements MkShopConsumerCouponService {
|
||||
|
||||
@Resource
|
||||
private MkCouponGiftService couponGiftService;
|
||||
|
||||
@Override
|
||||
public Page<MkShopConsumerCouponDTO> getConsumerCouponPage(MkShopConsumerCouponDTO param) {
|
||||
QueryWrapper queryWrapper = new QueryWrapper();
|
||||
queryWrapper.eq(MkShopConsumerCoupon::getShopId, param.getShopId())
|
||||
.orderBy(MkShopConsumerCoupon::getCreateTime).desc();
|
||||
Page<MkShopConsumerCouponDTO> pages = pageAs(PageUtil.buildPage(), queryWrapper, MkShopConsumerCouponDTO.class);
|
||||
pages.getRecords().forEach(item -> {
|
||||
//填充优惠券信息/数量
|
||||
item.setCouponGiftList(couponGiftService.getCouponGiftBySourceId(item.getId(), 3));
|
||||
});
|
||||
return pages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MkShopConsumerCouponDTO getConsumerCouponById(Long id) {
|
||||
AssertUtil.isNull(id, "ID不能为空");
|
||||
MkShopConsumerCouponDTO data = getOneAs(new QueryWrapper().eq(MkShopConsumerCoupon::getId, id), MkShopConsumerCouponDTO.class);
|
||||
//填充优惠券信息/数量
|
||||
data.setCouponGiftList(couponGiftService.getCouponGiftBySourceId(data.getId(), 3));
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void addConsumerCoupon(MkShopConsumerCouponDTO param) {
|
||||
MkShopConsumerCoupon bean = BeanUtil.toBean(param, MkShopConsumerCoupon.class);
|
||||
save(bean);
|
||||
//新增优惠券信息/数量
|
||||
couponGiftService.addCouponGift(bean.getId(), param.getTitle(), 3, param.getCouponGiftList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void updateConsumerCouponById(MkShopConsumerCouponDTO param) {
|
||||
updateById(BeanUtil.toBean(param, MkShopConsumerCoupon.class), true);
|
||||
//更新优惠券信息/数量
|
||||
couponGiftService.addCouponGift(param.getId(), param.getTitle(), 3, param.getCouponGiftList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void deleteConsumerCoupon(Long id) {
|
||||
AssertUtil.isNull(id, "优惠券ID不能为空");
|
||||
removeById(id);
|
||||
//删除优惠券信息
|
||||
couponGiftService.deleteJoinCouponGift(id, 3);
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
|
|||
import cn.hutool.core.exceptions.ValidateException;
|
||||
import com.czg.market.dto.ShopCouponDTO;
|
||||
import com.czg.market.entity.ShopCoupon;
|
||||
import com.czg.market.service.MkCouponGiftService;
|
||||
import com.czg.market.service.ShopCouponService;
|
||||
import com.czg.service.market.mapper.ShopCouponMapper;
|
||||
import com.czg.utils.AssertUtil;
|
||||
|
|
@ -11,8 +12,8 @@ import com.czg.utils.PageUtil;
|
|||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 优惠券信息表 服务层实现。
|
||||
|
|
@ -21,13 +22,16 @@ import org.springframework.stereotype.Service;
|
|||
* @since 2025-09-11
|
||||
*/
|
||||
@DubboService
|
||||
public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCoupon> implements ShopCouponService{
|
||||
public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCoupon> implements ShopCouponService {
|
||||
@Resource
|
||||
private MkCouponGiftService couponGiftService;
|
||||
|
||||
@Override
|
||||
public Page<ShopCouponDTO> getCouponPage(ShopCouponDTO param) {
|
||||
QueryWrapper queryWrapper = new QueryWrapper();
|
||||
queryWrapper.eq(ShopCoupon::getShopId, param.getShopId())
|
||||
.eq(ShopCoupon::getCouponType, param.getCouponType())
|
||||
.eq(ShopCoupon::getIsDel, 0)
|
||||
.orderBy(ShopCoupon::getCreateTime).desc();
|
||||
return pageAs(PageUtil.buildPage(), queryWrapper, ShopCouponDTO.class);
|
||||
}
|
||||
|
|
@ -55,12 +59,13 @@ public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCou
|
|||
}
|
||||
}
|
||||
ShopCoupon coupon = BeanUtil.toBean(param, ShopCoupon.class);
|
||||
updateById(coupon,true);
|
||||
updateById(coupon, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteCoupon(Long id) {
|
||||
AssertUtil.isNull(id, "优惠券ID不能为空");
|
||||
removeById(id);
|
||||
updateById(new ShopCoupon().setIsDel(1).setId(id), true);
|
||||
couponGiftService.deleteJoinCouponGift(id, 3);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.czg.service.market.mapper.MkShopConsumerCouponMapper">
|
||||
|
||||
</mapper>
|
||||
|
|
@ -5,7 +5,6 @@ import cn.hutool.core.collection.CollUtil;
|
|||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.alibaba.fastjson2.JSONWriter;
|
||||
import com.czg.account.entity.ShopConfig;
|
||||
import com.czg.account.entity.ShopInfo;
|
||||
|
|
@ -15,7 +14,6 @@ import com.czg.account.service.ShopInfoService;
|
|||
import com.czg.account.service.ShopUserService;
|
||||
import com.czg.account.service.SyncNoticeService;
|
||||
import com.czg.exception.CzgException;
|
||||
import com.czg.market.dto.ShopCouponDTO;
|
||||
import com.czg.market.entity.ShopCoupon;
|
||||
import com.czg.market.service.ShopCouponService;
|
||||
import com.czg.product.entity.*;
|
||||
|
|
@ -1354,7 +1352,7 @@ public class ShopSyncServiceImpl implements ShopSyncService {
|
|||
}
|
||||
|
||||
private void deleteCouponsBySyncId(Long couponId) {
|
||||
couponService.remove(new QueryWrapper()
|
||||
couponService.update(new ShopCoupon().setIsDel(1), new QueryWrapper()
|
||||
.eq(ShopCoupon::getSyncId, couponId));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue