This commit is contained in:
parent
db50c78049
commit
77ac277856
|
|
@ -4,9 +4,10 @@ import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.thread.ThreadUtil;
|
import cn.hutool.core.thread.ThreadUtil;
|
||||||
import com.czg.log.annotation.OperationLog;
|
import com.czg.log.annotation.OperationLog;
|
||||||
import com.czg.market.dto.MkCouponGiftDTO;
|
import com.czg.market.dto.MkCouponGiftDTO;
|
||||||
|
import com.czg.market.dto.MkShopCouponRecordDTO;
|
||||||
import com.czg.market.dto.ShopCouponDTO;
|
import com.czg.market.dto.ShopCouponDTO;
|
||||||
import com.czg.market.service.MkCouponGiftService;
|
import com.czg.market.service.MkCouponGiftService;
|
||||||
import com.czg.market.service.MkShopConsumerCouponService;
|
import com.czg.market.service.MkShopCouponRecordService;
|
||||||
import com.czg.market.service.ShopCouponService;
|
import com.czg.market.service.ShopCouponService;
|
||||||
import com.czg.product.service.ShopSyncService;
|
import com.czg.product.service.ShopSyncService;
|
||||||
import com.czg.resp.CzgResult;
|
import com.czg.resp.CzgResult;
|
||||||
|
|
@ -39,7 +40,7 @@ public class ACouponController {
|
||||||
@Resource
|
@Resource
|
||||||
private MkCouponGiftService couponGiftService;
|
private MkCouponGiftService couponGiftService;
|
||||||
@Resource
|
@Resource
|
||||||
private MkShopConsumerCouponService consumerCouponService;
|
private MkShopCouponRecordService couponRecordService;
|
||||||
@DubboReference
|
@DubboReference
|
||||||
private ShopSyncService shopSyncService;
|
private ShopSyncService shopSyncService;
|
||||||
|
|
||||||
|
|
@ -135,16 +136,26 @@ public class ACouponController {
|
||||||
return CzgResult.success(data);
|
return CzgResult.success(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * 通过关联Id取消该券的关联
|
* 优惠券列表/已领取详情
|
||||||
// *
|
* @param search 用户Id/昵称/手机号
|
||||||
// * @param id /admin/coupon/gifts的 主键Id
|
* @param param 用户的优惠券列表 使用该对象的UserId
|
||||||
// */
|
*/
|
||||||
// @DeleteMapping("/cancelGift")
|
@GetMapping("/record")
|
||||||
// public CzgResult<Void> cancelGift(Long id) {
|
public CzgResult<Page<MkShopCouponRecordDTO>> getRecord(@RequestParam(required = false) String search, MkShopCouponRecordDTO param) {
|
||||||
// couponGiftService.cancelGift(id);
|
Page<MkShopCouponRecordDTO> data = couponRecordService.getRecord(search, param);
|
||||||
// return CzgResult.success();
|
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) {
|
private void asyncToBranchShop(Long id, Integer type) {
|
||||||
long shopId = StpKit.USER.getShopId(0L);
|
long shopId = StpKit.USER.getShopId(0L);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,135 @@
|
||||||
|
|
||||||
|
package com.czg.market.dto;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.annotation.JSONField;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 优惠券发放记录表 实体类。
|
||||||
|
*
|
||||||
|
* @author ww
|
||||||
|
* @since 2025-09-13
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class MkShopCouponRecordDTO implements Serializable {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 店铺id
|
||||||
|
*/
|
||||||
|
private Long shopId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 店铺用户id
|
||||||
|
*/
|
||||||
|
private Long shopUserId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户Id
|
||||||
|
*/
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 卷Id (校验是否可用)
|
||||||
|
*/
|
||||||
|
private Long couponId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 卷描述 满10减2/商品卷
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 优惠券类型:1-满减券,2-商品兑换券,3-折扣券,4-第二件半价券,5-消费送券,6-买一送一券,7-固定价格券,8-免配送费券
|
||||||
|
*/
|
||||||
|
private Integer type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 满多少金额
|
||||||
|
*/
|
||||||
|
private BigDecimal fullAmount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 减多少金额
|
||||||
|
*/
|
||||||
|
private BigDecimal discountAmount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 折扣率 %
|
||||||
|
*/
|
||||||
|
private Integer discountRate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 来源活动id
|
||||||
|
*/
|
||||||
|
private Long sourceId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 来源记录Id
|
||||||
|
*/
|
||||||
|
private Long sourceFlowId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 领取时间
|
||||||
|
*/
|
||||||
|
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用时间
|
||||||
|
*/
|
||||||
|
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private LocalDateTime useTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 过期时间
|
||||||
|
*/
|
||||||
|
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private LocalDateTime expiredTime;
|
||||||
|
|
||||||
|
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private LocalDateTime updateTime;
|
||||||
|
|
||||||
|
private String couponJson;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 来源描述
|
||||||
|
*/
|
||||||
|
private String source;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 0未使用
|
||||||
|
* 1已使用
|
||||||
|
* 2已过期
|
||||||
|
*/
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用记录Id (订单Id)
|
||||||
|
*/
|
||||||
|
private Long targetId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 头像
|
||||||
|
*/
|
||||||
|
private String headImg;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户昵称
|
||||||
|
*/
|
||||||
|
private String nickName;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,137 @@
|
||||||
|
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;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 优惠券发放记录表 实体类。
|
||||||
|
*
|
||||||
|
* @author ww
|
||||||
|
* @since 2025-09-13
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Table("mk_shop_coupon_record")
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class MkShopCouponRecord implements Serializable {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Id(keyType = KeyType.Auto)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 店铺id
|
||||||
|
*/
|
||||||
|
private Long shopId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 店铺用户id
|
||||||
|
*/
|
||||||
|
private Long shopUserId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户Id
|
||||||
|
*/
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 卷Id (校验是否可用)
|
||||||
|
*/
|
||||||
|
private Long couponId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 卷描述 满10减2/商品卷
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 优惠券类型:1-满减券,2-商品兑换券,3-折扣券,4-第二件半价券, 6-买一送一券,7-固定价格券,8-免配送费券
|
||||||
|
*/
|
||||||
|
private Integer type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 满多少金额
|
||||||
|
*/
|
||||||
|
private BigDecimal fullAmount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 减多少金额
|
||||||
|
*/
|
||||||
|
private BigDecimal discountAmount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 折扣率 %
|
||||||
|
*/
|
||||||
|
private Integer discountRate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 来源活动id
|
||||||
|
*/
|
||||||
|
private Long sourceId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 来源记录Id
|
||||||
|
*/
|
||||||
|
private Long sourceFlowId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 领取时间
|
||||||
|
*/
|
||||||
|
@Column(onInsertValue = "now()")
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用时间
|
||||||
|
*/
|
||||||
|
private LocalDateTime useTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 过期时间
|
||||||
|
*/
|
||||||
|
private LocalDateTime expiredTime;
|
||||||
|
|
||||||
|
@Column(onInsertValue = "now()", onUpdateValue = "now()")
|
||||||
|
private LocalDateTime updateTime;
|
||||||
|
|
||||||
|
private String couponJson;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 来源描述
|
||||||
|
*/
|
||||||
|
private String source;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 0未使用
|
||||||
|
* 1已使用
|
||||||
|
* 2已过期
|
||||||
|
*/
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用记录Id (订单Id)
|
||||||
|
*/
|
||||||
|
private Long targetId;
|
||||||
|
/**
|
||||||
|
* 删除状态 0-正常 1-删除
|
||||||
|
*/
|
||||||
|
private Integer isDel;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
package com.czg.market.service;
|
||||||
|
|
||||||
|
import com.czg.market.dto.MkShopCouponRecordDTO;
|
||||||
|
import com.mybatisflex.core.paginate.Page;
|
||||||
|
import com.mybatisflex.core.service.IService;
|
||||||
|
import com.czg.market.entity.MkShopCouponRecord;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 优惠券发放记录表 服务层。
|
||||||
|
*
|
||||||
|
* @author ww
|
||||||
|
* @since 2025-09-13
|
||||||
|
*/
|
||||||
|
public interface MkShopCouponRecordService extends IService<MkShopCouponRecord> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 优惠券列表/已领取详情
|
||||||
|
* @param search 用户Id/昵称/手机号
|
||||||
|
*/
|
||||||
|
Page<MkShopCouponRecordDTO> getRecord(String search, MkShopCouponRecordDTO param);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发放券 统一方法
|
||||||
|
* @param mkShopCouponRecordDTO 赠送信息 除Id外 几乎全填
|
||||||
|
* @param number 发放数量
|
||||||
|
*/
|
||||||
|
void receiveCoupon(MkShopCouponRecordDTO mkShopCouponRecordDTO,Integer number);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户优惠券 失效/删除
|
||||||
|
*/
|
||||||
|
void deleteRecord(Long id);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.czg.service.market.mapper;
|
||||||
|
|
||||||
|
import com.mybatisflex.core.BaseMapper;
|
||||||
|
import com.czg.market.entity.MkShopCouponRecord;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 优惠券发放记录表 映射层。
|
||||||
|
*
|
||||||
|
* @author ww
|
||||||
|
* @since 2025-09-13
|
||||||
|
*/
|
||||||
|
public interface MkShopCouponRecordMapper extends BaseMapper<MkShopCouponRecord> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,114 @@
|
||||||
|
package com.czg.service.market.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.czg.account.entity.UserInfo;
|
||||||
|
import com.czg.account.service.UserInfoService;
|
||||||
|
import com.czg.exception.CzgException;
|
||||||
|
import com.czg.market.dto.MkShopCouponRecordDTO;
|
||||||
|
import com.czg.market.entity.MkShopCouponRecord;
|
||||||
|
import com.czg.market.service.MkShopCouponRecordService;
|
||||||
|
import com.czg.service.market.mapper.MkShopCouponRecordMapper;
|
||||||
|
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 org.apache.dubbo.config.annotation.DubboReference;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 优惠券发放记录表 服务层实现。
|
||||||
|
*
|
||||||
|
* @author ww
|
||||||
|
* @since 2025-09-13
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class MkShopCouponRecordServiceImpl extends ServiceImpl<MkShopCouponRecordMapper, MkShopCouponRecord> implements MkShopCouponRecordService {
|
||||||
|
|
||||||
|
|
||||||
|
@DubboReference
|
||||||
|
private UserInfoService userInfoService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Page<MkShopCouponRecordDTO> getRecord(String search, MkShopCouponRecordDTO mkShopCouponRecordDTO) {
|
||||||
|
Map<Long, UserInfo> userInfoMap = new HashMap<>();
|
||||||
|
if (StrUtil.isNotBlank(search)) {
|
||||||
|
QueryWrapper queryWrapper = new QueryWrapper();
|
||||||
|
queryWrapper.and(q -> {
|
||||||
|
q.like(UserInfo::getId, search).or(r -> {
|
||||||
|
r.like(UserInfo::getNickName, search);
|
||||||
|
}).or(s -> {
|
||||||
|
s.like(UserInfo::getPhone, search);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
List<UserInfo> userInfos = userInfoService.list(queryWrapper);
|
||||||
|
if (CollUtil.isNotEmpty(userInfos)) {
|
||||||
|
userInfoMap = userInfos.stream().collect(Collectors.toMap(UserInfo::getId, userInfo -> userInfo));
|
||||||
|
} else {
|
||||||
|
return new Page<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
QueryWrapper recordQueryWrapper = new QueryWrapper();
|
||||||
|
recordQueryWrapper.eq(MkShopCouponRecord::getShopId, mkShopCouponRecordDTO.getShopId())
|
||||||
|
.eq(MkShopCouponRecord::getCouponId, mkShopCouponRecordDTO.getCouponId())
|
||||||
|
.eq(MkShopCouponRecord::getIsDel, 0)
|
||||||
|
.eq(MkShopCouponRecord::getStatus, mkShopCouponRecordDTO.getStatus())
|
||||||
|
.orderBy(MkShopCouponRecord::getCreateTime).desc();
|
||||||
|
if (CollUtil.isNotEmpty(userInfoMap)) {
|
||||||
|
recordQueryWrapper.in(MkShopCouponRecord::getUserId, userInfoMap.keySet());
|
||||||
|
} else {
|
||||||
|
recordQueryWrapper.eq(MkShopCouponRecord::getUserId, mkShopCouponRecordDTO.getUserId());
|
||||||
|
}
|
||||||
|
Page<MkShopCouponRecordDTO> recordPage = pageAs(PageUtil.buildPage(), recordQueryWrapper, MkShopCouponRecordDTO.class);
|
||||||
|
if (CollUtil.isNotEmpty(userInfoMap)) {
|
||||||
|
for (MkShopCouponRecordDTO record : recordPage.getRecords()) {
|
||||||
|
UserInfo userInfo = userInfoMap.get(record.getUserId());
|
||||||
|
record.setHeadImg(userInfo.getHeadImg());
|
||||||
|
record.setNickName(userInfo.getNickName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return recordPage;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void receiveCoupon(MkShopCouponRecordDTO mkShopCouponRecordDTO, Integer number) {
|
||||||
|
if (number == null || number <= 0) {
|
||||||
|
throw new CzgException("发放数量不能小于0");
|
||||||
|
}
|
||||||
|
MkShopCouponRecord bean = BeanUtil.toBean(mkShopCouponRecordDTO, MkShopCouponRecord.class);
|
||||||
|
if (bean.getType() == 1) {
|
||||||
|
if (bean.getFullAmount() == null) {
|
||||||
|
throw new CzgException("满减券,满减金额不能为空");
|
||||||
|
}
|
||||||
|
if (bean.getDiscountAmount() == null) {
|
||||||
|
throw new CzgException("满减券,折扣金额不能为空");
|
||||||
|
}
|
||||||
|
} else if (bean.getType() == 2) {
|
||||||
|
// 类型2:fullAmount不能为空
|
||||||
|
if (bean.getFullAmount() == null) {
|
||||||
|
throw new CzgException("商品兑换券,门槛金额不能为空");
|
||||||
|
}
|
||||||
|
} else if (bean.getType() == 3) {
|
||||||
|
// 类型3:discountRate不能为空
|
||||||
|
if (bean.getDiscountRate() == null) {
|
||||||
|
throw new CzgException("折扣券,折扣率不能为空");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < number; i++) {
|
||||||
|
bean.setId(null);
|
||||||
|
save(bean);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteRecord(Long id) {
|
||||||
|
updateById(new MkShopCouponRecord().setId(id).setIsDel(1), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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.MkShopCouponRecordMapper">
|
||||||
|
|
||||||
|
</mapper>
|
||||||
Loading…
Reference in New Issue