mirror of
https://github.com/weizhiqiang1995/erp-pro.git
synced 2025-02-01 04:00:54 +08:00
feat:商城优惠券修改部分成员变量相关参数
This commit is contained in:
parent
2b3f3cf271
commit
aae6dbb946
3 changed files with 23 additions and 10 deletions
|
@ -80,7 +80,7 @@ public class Coupon extends BaseGeneralInfo {
|
|||
private String discountLimitPrice;
|
||||
|
||||
@TableField(value = "take_count")
|
||||
@ApiModelProperty(value = "商品范围", required = "required")
|
||||
@ApiModelProperty(value = "已经领取优惠券的数量", required = "required")
|
||||
private Integer takeCount;
|
||||
|
||||
@TableField(value = "use_count")
|
||||
|
@ -88,6 +88,6 @@ public class Coupon extends BaseGeneralInfo {
|
|||
private Integer useCount;
|
||||
|
||||
@TableField(exist = false)
|
||||
@ApiModelProperty(value = "优惠券适用对象列表", required = "required,json")
|
||||
@ApiModelProperty(value = "优惠券适用对象列表", required = "json")
|
||||
private List<CouponMaterial> couponMaterialList;
|
||||
}
|
|
@ -15,11 +15,11 @@ import lombok.Data;
|
|||
public class CouponMaterial extends CommonInfo {
|
||||
|
||||
@TableId("id")
|
||||
@ApiModelProperty("主键id。为空时新增,不为空时编辑")
|
||||
@Property("主键id。为空时新增,不为空时编辑")
|
||||
private String id;
|
||||
|
||||
@TableField(value = "material_id")
|
||||
@ApiModelProperty(value = "商品id", required = "required")
|
||||
@ApiModelProperty(value = "商品id")
|
||||
private String materialId;
|
||||
|
||||
@TableField(value = "coupon_id")
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.skyeye.coupon.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
|
@ -20,6 +20,7 @@ import com.skyeye.coupon.entity.Coupon;
|
|||
import com.skyeye.coupon.entity.CouponMaterial;
|
||||
import com.skyeye.coupon.enums.CouponValidityType;
|
||||
import com.skyeye.coupon.enums.PromotionDiscountType;
|
||||
import com.skyeye.coupon.enums.PromotionMaterialScope;
|
||||
import com.skyeye.coupon.service.CouponMaterialService;
|
||||
import com.skyeye.coupon.service.CouponService;
|
||||
import com.skyeye.exception.CustomException;
|
||||
|
@ -40,9 +41,15 @@ public class CouponServiceImpl extends SkyeyeBusinessServiceImpl<CouponDao, Coup
|
|||
|
||||
@Override
|
||||
public void validatorEntity(Coupon coupon) {
|
||||
if(StrUtil.isNotEmpty(coupon.getId()) && StrUtil.isNotEmpty(coupon.getTemplateId())){
|
||||
if (StrUtil.isNotEmpty(coupon.getId()) && StrUtil.isNotEmpty(coupon.getTemplateId())) {
|
||||
throw new CustomException("更新操作不可上传模板id(templateId)");
|
||||
}
|
||||
// 新增时,商品范围不为全部商品,并且适用对象为空时,不可新增。
|
||||
if (StrUtil.isEmpty(coupon.getId()) &&
|
||||
coupon.getProductScope() != PromotionMaterialScope.ALL.getKey() &&
|
||||
CollectionUtil.isEmpty(coupon.getCouponMaterialList())) {
|
||||
throw new CustomException("需要指定优惠券适用的商品范围,适用全部商品时可为空");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -77,11 +84,16 @@ public class CouponServiceImpl extends SkyeyeBusinessServiceImpl<CouponDao, Coup
|
|||
|
||||
@Override
|
||||
public void writePostpose(Coupon coupon, String userId) {
|
||||
if (ObjectUtil.isNotEmpty(coupon.getCouponMaterialList())) {
|
||||
if (CollectionUtil.isNotEmpty(coupon.getCouponMaterialList())) {
|
||||
// 删除原本的适用商品信息
|
||||
couponMaterialService.deleteByCouponId(coupon.getId());
|
||||
// 设置优惠券id
|
||||
coupon.getCouponMaterialList().forEach(couponMaterial -> couponMaterial.setCouponId(coupon.getId()));
|
||||
coupon.getCouponMaterialList().forEach(couponMaterial -> {
|
||||
if ((StrUtil.isEmpty(couponMaterial.getMaterialId()))) {
|
||||
throw new CustomException("适用对象的商品id(materialId)不能为空");
|
||||
}
|
||||
couponMaterial.setCouponId(coupon.getId());
|
||||
});
|
||||
// 批量新增
|
||||
couponMaterialService.createEntity(coupon.getCouponMaterialList(), userId);
|
||||
}
|
||||
|
@ -108,7 +120,7 @@ public class CouponServiceImpl extends SkyeyeBusinessServiceImpl<CouponDao, Coup
|
|||
}
|
||||
List<Coupon> list = list(queryWrapper);
|
||||
List<String> parentIdList = list.stream().map(Coupon::getId).collect(Collectors.toList());
|
||||
Map<String, List<CouponMaterial>> couponMapMaterialList =couponMaterialService.queryListByCouponId(parentIdList);
|
||||
Map<String, List<CouponMaterial>> couponMapMaterialList = couponMaterialService.queryListByCouponId(parentIdList);
|
||||
for (Coupon coupon : list) {
|
||||
coupon.setCouponMaterialList(couponMapMaterialList.get(coupon.getId()));
|
||||
}
|
||||
|
@ -124,13 +136,14 @@ public class CouponServiceImpl extends SkyeyeBusinessServiceImpl<CouponDao, Coup
|
|||
if (params.containsKey("type") && Objects.equals(params.get("type"), CommonNumConstants.NUM_ZERO)) {
|
||||
queryWrapper.ne(MybatisPlusUtil.toColumns(Coupon::getTemplateId), "");
|
||||
}
|
||||
if(params.containsKey("type") && Objects.equals(params.get("type"), CommonNumConstants.NUM_ONE)){
|
||||
if (params.containsKey("type") && Objects.equals(params.get("type"), CommonNumConstants.NUM_ONE)) {
|
||||
queryWrapper.eq(MybatisPlusUtil.toColumns(Coupon::getTemplateId), "");
|
||||
}
|
||||
List<Coupon> list = list(queryWrapper);
|
||||
outputObject.setBean(list);
|
||||
outputObject.settotal(list.size());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTakeCount(String couponId, Integer takeCount) {
|
||||
UpdateWrapper<Coupon> updateWrapper = new UpdateWrapper<>();
|
||||
|
|
Loading…
Reference in a new issue