promotion:完善限时折扣的添加逻辑
parent
544597d6e2
commit
6d48bd1ed8
|
@ -1,14 +1,57 @@
|
||||||
package cn.iocoder.yudao.module.product.controller.admin.sku;
|
package cn.iocoder.yudao.module.product.controller.admin.sku;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||||
|
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
|
||||||
|
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuOptionRespVO;
|
||||||
|
import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert;
|
||||||
|
import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
|
||||||
|
import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
|
||||||
|
import cn.iocoder.yudao.module.product.service.sku.ProductSkuService;
|
||||||
|
import cn.iocoder.yudao.module.product.service.spu.ProductSpuService;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||||
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
||||||
|
|
||||||
@Api(tags = "管理后台 - 商品 sku")
|
@Api(tags = "管理后台 - 商品 sku")
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/product/sku")
|
@RequestMapping("/product/sku")
|
||||||
@Validated
|
@Validated
|
||||||
public class ProductSkuController {
|
public class ProductSkuController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ProductSkuService productSkuService;
|
||||||
|
@Resource
|
||||||
|
private ProductSpuService productSpuService;
|
||||||
|
|
||||||
|
@GetMapping("/get-option-list")
|
||||||
|
@ApiOperation("获得商品 SKU 选项的列表")
|
||||||
|
// @PreAuthorize("@ss.hasPermission('product:sku:query')")
|
||||||
|
public CommonResult<List<ProductSkuOptionRespVO>> getSkuOptionList() {
|
||||||
|
// 获得 SKU 列表
|
||||||
|
List<ProductSkuDO> skus = productSkuService.getSkuList();
|
||||||
|
if (CollUtil.isEmpty(skus)) {
|
||||||
|
return success(Collections.emptyList());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获得对应的 SPU 映射
|
||||||
|
Map<Long, ProductSpuDO> spuMap = productSpuService.getSpuMap(convertSet(skus, ProductSkuDO::getSpuId));
|
||||||
|
// 转换为返回结果
|
||||||
|
List<ProductSkuOptionRespVO> skuVOs = ProductSkuConvert.INSTANCE.convertList05(skus);
|
||||||
|
skuVOs.forEach(sku -> MapUtils.findAndThen(spuMap, sku.getSpuId(),
|
||||||
|
spu -> sku.setSpuId(spu.getId()).setSpuName(spu.getName())));
|
||||||
|
return success(skuVOs);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
package cn.iocoder.yudao.module.product.controller.admin.sku.vo;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@ApiModel(value = "管理后台 - 商品 SKU 选项 Response VO", description = "用于前端 SELECT 选项")
|
||||||
|
@Data
|
||||||
|
public class ProductSkuOptionRespVO {
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "主键", required = true, example = "1024")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "商品 SKU 名字", example = "红色")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "销售价格", required = true, example = "100", notes = "单位:分")
|
||||||
|
private String price;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "库存", required = true, example = "100")
|
||||||
|
private Integer stock;
|
||||||
|
|
||||||
|
// ========== 商品 SPU 信息 ==========
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "商品 SPU 编号", required = true, example = "1")
|
||||||
|
private Long spuId;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "商品 SPU 名字", required = true, example = "iPhone 11")
|
||||||
|
private String spuName;
|
||||||
|
|
||||||
|
}
|
|
@ -9,7 +9,7 @@ import lombok.ToString;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ApiModel("管理后台 - 商品sku Response VO")
|
@ApiModel("管理后台 - 商品 SKU Response VO")
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@ToString(callSuper = true)
|
@ToString(callSuper = true)
|
||||||
|
|
|
@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.product.convert.sku;
|
||||||
|
|
||||||
import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO;
|
import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO;
|
||||||
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateOrUpdateReqVO;
|
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateOrUpdateReqVO;
|
||||||
|
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuOptionRespVO;
|
||||||
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO;
|
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO;
|
||||||
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuDetailRespVO;
|
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuDetailRespVO;
|
||||||
import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
|
import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
|
||||||
|
@ -11,7 +12,7 @@ import org.mapstruct.factory.Mappers;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品sku Convert
|
* 商品 SKU Convert
|
||||||
*
|
*
|
||||||
* @author 芋道源码
|
* @author 芋道源码
|
||||||
*/
|
*/
|
||||||
|
@ -36,4 +37,6 @@ public interface ProductSkuConvert {
|
||||||
|
|
||||||
List<ProductSkuRespDTO> convertList04(List<ProductSkuDO> list);
|
List<ProductSkuRespDTO> convertList04(List<ProductSkuDO> list);
|
||||||
|
|
||||||
|
List<ProductSkuOptionRespVO> convertList05(List<ProductSkuDO> skus);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,6 +97,7 @@ public class ProductSkuDO extends BaseDO {
|
||||||
* 商品属性
|
* 商品属性
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public static class Property {
|
public static class Property {
|
||||||
|
|
||||||
|
@ -130,19 +131,5 @@ public class ProductSkuDO extends BaseDO {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO ========== 待定字段:yv =========
|
|
||||||
// TODO brokerage:一级返佣
|
|
||||||
// TODO brokerage_two:二级返佣
|
|
||||||
// TODO pink_price:拼团价
|
|
||||||
// TODO pink_stock:拼团库存
|
|
||||||
// TODO seckill_price:秒杀价
|
|
||||||
// TODO seckill_stock:秒杀库存
|
|
||||||
// TODO integral:需要积分
|
|
||||||
|
|
||||||
// TODO ========== 待定字段:cf =========
|
|
||||||
// TODO type 活动显示排序 0=默认 1=秒 2=砍价 3=拼团
|
|
||||||
// TODO quota 活动限购数量
|
|
||||||
// TODO quota_show 活动限购数量显示
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,22 +14,29 @@ import java.util.List;
|
||||||
public interface ProductSkuService {
|
public interface ProductSkuService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除商品sku
|
* 删除商品 SKU
|
||||||
*
|
*
|
||||||
* @param id 编号
|
* @param id 编号
|
||||||
*/
|
*/
|
||||||
void deleteSku(Long id);
|
void deleteSku(Long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得商品sku
|
* 获得商品 SKU 信息
|
||||||
*
|
*
|
||||||
* @param id 编号
|
* @param id 编号
|
||||||
* @return 商品sku
|
* @return 商品 SKU 信息
|
||||||
*/
|
*/
|
||||||
ProductSkuDO getSku(Long id);
|
ProductSkuDO getSku(Long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得商品sku列表
|
* 获得商品 SKU 列表
|
||||||
|
*
|
||||||
|
* @return 商品sku列表
|
||||||
|
*/
|
||||||
|
List<ProductSkuDO> getSkuList();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得商品 SKU 列表
|
||||||
*
|
*
|
||||||
* @param ids 编号
|
* @param ids 编号
|
||||||
* @return 商品sku列表
|
* @return 商品sku列表
|
||||||
|
|
|
@ -61,6 +61,11 @@ public class ProductSkuServiceImpl implements ProductSkuService {
|
||||||
return productSkuMapper.selectById(id);
|
return productSkuMapper.selectById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ProductSkuDO> getSkuList() {
|
||||||
|
return productSkuMapper.selectList();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ProductSkuDO> getSkuList(Collection<Long> ids) {
|
public List<ProductSkuDO> getSkuList(Collection<Long> ids) {
|
||||||
return productSkuMapper.selectBatchIds(ids);
|
return productSkuMapper.selectBatchIds(ids);
|
||||||
|
|
|
@ -9,6 +9,9 @@ import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品 SPU Service 接口
|
* 商品 SPU Service 接口
|
||||||
|
@ -63,6 +66,16 @@ public interface ProductSpuService {
|
||||||
*/
|
*/
|
||||||
List<ProductSpuDO> getSpuList(Collection<Long> ids);
|
List<ProductSpuDO> getSpuList(Collection<Long> ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得商品 SPU 映射
|
||||||
|
*
|
||||||
|
* @param ids 编号数组
|
||||||
|
* @return 商品 SPU 映射
|
||||||
|
*/
|
||||||
|
default Map<Long, ProductSpuDO> getSpuMap(Collection<Long> ids) {
|
||||||
|
return convertMap(getSpuList(ids), ProductSpuDO::getId);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得所有商品 SPU 列表
|
* 获得所有商品 SPU 列表
|
||||||
*
|
*
|
||||||
|
|
|
@ -130,11 +130,11 @@ public class CouponTemplateBaseVO {
|
||||||
|| fixedEndTerm != null;
|
|| fixedEndTerm != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "折扣百分比需要大于等于 1")
|
@AssertTrue(message = "折扣百分比需要大于等于 1,小于等于 99")
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
public boolean isDiscountPercentValid() {
|
public boolean isDiscountPercentValid() {
|
||||||
return ObjectUtil.notEqual(discountType, PromotionDiscountTypeEnum.PERCENT.getType())
|
return ObjectUtil.notEqual(discountType, PromotionDiscountTypeEnum.PERCENT.getType())
|
||||||
|| (discountPercent != null && discountPercent >= 1);
|
|| (discountPercent != null && discountPercent >= 1 && discountPercent<= 99);
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssertTrue(message = "优惠金额不能为空")
|
@AssertTrue(message = "优惠金额不能为空")
|
||||||
|
|
|
@ -1,10 +1,15 @@
|
||||||
package cn.iocoder.yudao.module.promotion.controller.admin.discount.vo;
|
package cn.iocoder.yudao.module.promotion.controller.admin.discount.vo;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.iocoder.yudao.framework.common.validation.InEnum;
|
||||||
|
import cn.iocoder.yudao.module.promotion.enums.common.PromotionDiscountTypeEnum;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import io.swagger.annotations.ApiModel;
|
import io.swagger.annotations.ApiModel;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
|
import javax.validation.constraints.AssertTrue;
|
||||||
import javax.validation.constraints.Min;
|
import javax.validation.constraints.Min;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -47,10 +52,31 @@ public class DiscountActivityBaseVO {
|
||||||
@NotNull(message = "商品 SKU 编号不能为空")
|
@NotNull(message = "商品 SKU 编号不能为空")
|
||||||
private Long skuId;
|
private Long skuId;
|
||||||
|
|
||||||
@ApiModelProperty(value = "折扣价格,单位:分", required = true, example = "1000")
|
@ApiModelProperty(value = "优惠类型", required = true, example = "1", notes = "参见 PromotionDiscountTypeEnum 枚举")
|
||||||
@NotNull(message = "折扣价格不能为空")
|
@NotNull(message = "优惠类型不能为空")
|
||||||
@Min(value = 1, message = "折扣价格必须大于 0")
|
@InEnum(PromotionDiscountTypeEnum.class)
|
||||||
|
private Integer discountType;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "折扣百分比", example = "80", notes = "例如说,80% 为 80")
|
||||||
|
private Integer discountPercent;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "优惠金额", example = "10", notes = "单位:分")
|
||||||
|
@Min(value = 0, message = "优惠金额需要大于等于 0")
|
||||||
private Integer discountPrice;
|
private Integer discountPrice;
|
||||||
|
|
||||||
|
@AssertTrue(message = "折扣百分比需要大于等于 1,小于等于 99")
|
||||||
|
@JsonIgnore
|
||||||
|
public boolean isDiscountPercentValid() {
|
||||||
|
return ObjectUtil.notEqual(discountType, PromotionDiscountTypeEnum.PERCENT.getType())
|
||||||
|
|| (discountPercent != null && discountPercent >= 1 && discountPercent<= 99);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AssertTrue(message = "优惠金额不能为空")
|
||||||
|
@JsonIgnore
|
||||||
|
public boolean isDiscountPriceValid() {
|
||||||
|
return ObjectUtil.notEqual(discountType, PromotionDiscountTypeEnum.PRICE.getType())
|
||||||
|
|| discountPrice != null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,8 @@ import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.Valid;
|
||||||
|
import javax.validation.constraints.NotEmpty;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ApiModel("管理后台 - 限时折扣活动创建 Request VO")
|
@ApiModel("管理后台 - 限时折扣活动创建 Request VO")
|
||||||
|
@ -17,7 +18,8 @@ public class DiscountActivityCreateReqVO extends DiscountActivityBaseVO {
|
||||||
/**
|
/**
|
||||||
* 商品列表
|
* 商品列表
|
||||||
*/
|
*/
|
||||||
@NotNull(message = "商品列表不能为空")
|
@NotEmpty(message = "商品列表不能为空")
|
||||||
|
@Valid
|
||||||
private List<Product> products;
|
private List<Product> products;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,8 @@ import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import javax.validation.constraints.NotEmpty;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -22,7 +24,8 @@ public class DiscountActivityUpdateReqVO extends DiscountActivityBaseVO {
|
||||||
/**
|
/**
|
||||||
* 商品列表
|
* 商品列表
|
||||||
*/
|
*/
|
||||||
@NotNull(message = "商品列表不能为空")
|
@NotEmpty(message = "商品列表不能为空")
|
||||||
|
@Valid
|
||||||
private List<DiscountActivityCreateReqVO.Product> products;
|
private List<DiscountActivityCreateReqVO.Product> products;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package cn.iocoder.yudao.module.promotion.dal.dataobject.discount;
|
package cn.iocoder.yudao.module.promotion.dal.dataobject.discount;
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||||
|
import cn.iocoder.yudao.module.promotion.enums.common.PromotionDiscountTypeEnum;
|
||||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
@ -41,8 +42,23 @@ public class DiscountProductDO extends BaseDO {
|
||||||
* 关联 ProductSkuDO 的 id 编号
|
* 关联 ProductSkuDO 的 id 编号
|
||||||
*/
|
*/
|
||||||
private Long skuId;
|
private Long skuId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 优惠价格,单位:分
|
* 折扣类型
|
||||||
|
*
|
||||||
|
* 枚举 {@link PromotionDiscountTypeEnum}
|
||||||
|
*/
|
||||||
|
private Integer discountType;
|
||||||
|
/**
|
||||||
|
* 折扣百分比
|
||||||
|
*
|
||||||
|
* 例如,80% 为 80
|
||||||
|
*/
|
||||||
|
private Integer discountPercent;
|
||||||
|
/**
|
||||||
|
* 优惠金额,单位:分
|
||||||
|
*
|
||||||
|
* 当 {@link #discountType} 为 {@link PromotionDiscountTypeEnum#PRICE} 生效
|
||||||
*/
|
*/
|
||||||
private Integer discountPrice;
|
private Integer discountPrice;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
import request from '@/utils/request'
|
||||||
|
|
||||||
|
// 获得商品 SKU 选项的列表
|
||||||
|
export function getSkuOptionList() {
|
||||||
|
return request({
|
||||||
|
url: '/product/sku/get-option-list',
|
||||||
|
method: 'get',
|
||||||
|
})
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
import request from '@/utils/request'
|
import request from '@/utils/request'
|
||||||
|
|
||||||
// 创建商品spu
|
// 创建商品 SPU
|
||||||
export function createSpu(data) {
|
export function createSpu(data) {
|
||||||
return request({
|
return request({
|
||||||
url: '/product/spu/create',
|
url: '/product/spu/create',
|
||||||
|
@ -9,7 +9,7 @@ export function createSpu(data) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新商品spu
|
// 更新商品 SPU
|
||||||
export function updateSpu(data) {
|
export function updateSpu(data) {
|
||||||
return request({
|
return request({
|
||||||
url: '/product/spu/update',
|
url: '/product/spu/update',
|
||||||
|
@ -18,7 +18,7 @@ export function updateSpu(data) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除商品spu
|
// 删除商品 SPU
|
||||||
export function deleteSpu(id) {
|
export function deleteSpu(id) {
|
||||||
return request({
|
return request({
|
||||||
url: '/product/spu/delete?id=' + id,
|
url: '/product/spu/delete?id=' + id,
|
||||||
|
@ -34,7 +34,7 @@ export function getSpu(id) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获得商品spu详情
|
// 获得商品 SPU 详情
|
||||||
export function getSpuDetail(id) {
|
export function getSpuDetail(id) {
|
||||||
return request({
|
return request({
|
||||||
url: '/product/spu/get/detail?id=' + id,
|
url: '/product/spu/get/detail?id=' + id,
|
||||||
|
@ -42,7 +42,7 @@ export function getSpuDetail(id) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获得商品spu分页
|
// 获得商品 SPU 分页
|
||||||
export function getSpuPage(query) {
|
export function getSpuPage(query) {
|
||||||
return request({
|
return request({
|
||||||
url: '/product/spu/page',
|
url: '/product/spu/page',
|
||||||
|
|
|
@ -70,7 +70,7 @@
|
||||||
@pagination="getList"/>
|
@pagination="getList"/>
|
||||||
|
|
||||||
<!-- 对话框(添加 / 修改) -->
|
<!-- 对话框(添加 / 修改) -->
|
||||||
<el-dialog :title="title" :visible.sync="open" width="600px" v-dialogDrag append-to-body>
|
<el-dialog :title="title" :visible.sync="open" width="1000px" v-dialogDrag append-to-body>
|
||||||
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
|
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
|
||||||
<el-form-item label="活动名称" prop="name">
|
<el-form-item label="活动名称" prop="name">
|
||||||
<el-input v-model="form.name" placeholder="请输入活动名称" />
|
<el-input v-model="form.name" placeholder="请输入活动名称" />
|
||||||
|
@ -80,7 +80,54 @@
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="活动时间" prop="startAndEndTime">
|
<el-form-item label="活动时间" prop="startAndEndTime">
|
||||||
<el-date-picker clearable v-model="form.startAndEndTime" type="datetimerange" :default-time="['00:00:00', '23:59:59']"
|
<el-date-picker clearable v-model="form.startAndEndTime" type="datetimerange" :default-time="['00:00:00', '23:59:59']"
|
||||||
value-format="timestamp" placeholder="选择开始时间" style="width: 480px" />
|
value-format="timestamp" placeholder="选择开始时间" style="width: 880px" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="商品选择">
|
||||||
|
<el-select v-model="form.skuIds" placeholder="请选择活动商品" clearable size="small"
|
||||||
|
multiple filterable style="width: 400px" @change="changeFormSku">
|
||||||
|
<el-option v-for="item in productSkus" :key="item.id" :label="item.name" :value="item.id">
|
||||||
|
<span style="float: left">{{ item.spuName }} {{ item.name}}</span>
|
||||||
|
<span style="float: right; color: #8492a6; font-size: 13px">¥{{ (item.price / 100.0).toFixed(2) }}</span>
|
||||||
|
</el-option>
|
||||||
|
</el-select>
|
||||||
|
<el-table v-loading="loading" :data="form.products">
|
||||||
|
<el-table-column label="商品名称" align="center" width="200">
|
||||||
|
<template slot-scope="scope">
|
||||||
|
{{ scope.row.spuName }} {{ scope.row.name}}
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="商品价格" align="center" prop="price">
|
||||||
|
<template slot-scope="scope">
|
||||||
|
¥{{ (scope.row.price / 100.0).toFixed(2) }}
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="库存" align="center" prop="stock" />
|
||||||
|
<el-table-column label="优惠类型" align="center">
|
||||||
|
<template slot-scope="scope">
|
||||||
|
<el-select v-model="scope.row.discountType" placeholder="请选择优惠类型">
|
||||||
|
<el-option v-for="dict in getDictDatas(DICT_TYPE.PROMOTION_DISCOUNT_TYPE)"
|
||||||
|
:key="dict.value" :label="dict.label" :value="parseInt(dict.value)"/>
|
||||||
|
</el-select>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="优惠" align="center" prop="startTime" width="250">
|
||||||
|
<template slot-scope="scope">
|
||||||
|
<el-form-item v-if="scope.row.discountType === PromotionDiscountTypeEnum.PRICE.type" prop="discountPrice">
|
||||||
|
减 <el-input-number v-model="scope.row.discountPrice" placeholder="请输入优惠金额"
|
||||||
|
style="width: 190px" :precision="2" :min="0" /> 元
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item v-if="scope.row.discountType === PromotionDiscountTypeEnum.PERCENT.type" prop="discountPercent">
|
||||||
|
打 <el-input-number v-model="scope.row.discountPercent" placeholder="请输入优惠折扣"
|
||||||
|
style="width: 190px" :precision="1" :min="1" :max="9.9" /> 折
|
||||||
|
</el-form-item>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||||
|
<template slot-scope="scope">
|
||||||
|
<el-button size="mini" type="text" icon="el-icon-delete" @click="removeFormSku(scope.row.skuId)">删除</el-button>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
<div slot="footer" class="dialog-footer">
|
<div slot="footer" class="dialog-footer">
|
||||||
|
@ -93,8 +140,11 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { createDiscountActivity, updateDiscountActivity, deleteDiscountActivity, getDiscountActivity, getDiscountActivityPage } from "@/api/mall/promotion/discountActivity";
|
import { createDiscountActivity, updateDiscountActivity, deleteDiscountActivity, getDiscountActivity, getDiscountActivityPage } from "@/api/mall/promotion/discountActivity";
|
||||||
import {PromotionActivityStatusEnum, PromotionProductScopeEnum} from "@/utils/constants";
|
import {
|
||||||
import {closeRewardActivity} from "@/api/mall/promotion/rewardActivity";
|
PromotionActivityStatusEnum, PromotionDiscountTypeEnum,
|
||||||
|
PromotionProductScopeEnum
|
||||||
|
} from "@/utils/constants";
|
||||||
|
import { getSkuOptionList } from "@/api/mall/product/sku";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "DiscountActivity",
|
name: "DiscountActivity",
|
||||||
|
@ -115,7 +165,7 @@ export default {
|
||||||
// 弹出层名称
|
// 弹出层名称
|
||||||
title: "",
|
title: "",
|
||||||
// 是否显示弹出层
|
// 是否显示弹出层
|
||||||
open: false,
|
open: true,
|
||||||
// 查询参数
|
// 查询参数
|
||||||
queryParams: {
|
queryParams: {
|
||||||
pageNo: 1,
|
pageNo: 1,
|
||||||
|
@ -125,17 +175,38 @@ export default {
|
||||||
createTime: [],
|
createTime: [],
|
||||||
},
|
},
|
||||||
// 表单参数
|
// 表单参数
|
||||||
form: {},
|
form: {
|
||||||
|
skuIds: [], // 选中的 SKU
|
||||||
|
products: [], // 商品信息
|
||||||
|
// products: [{
|
||||||
|
// id: 2,
|
||||||
|
// name: '白色',
|
||||||
|
// price: 500,
|
||||||
|
// stock: 20,
|
||||||
|
// spuId: 1,
|
||||||
|
// spuName: 'iPhone 14 Pro',
|
||||||
|
// discountType: 1,
|
||||||
|
// }, {
|
||||||
|
// id: 10,
|
||||||
|
// name: '蓝色',
|
||||||
|
// price: 1000,
|
||||||
|
// stock: 100,
|
||||||
|
// spuId: 20,
|
||||||
|
// spuName: 'iPhone 14 Pro',
|
||||||
|
// discountType: 2,
|
||||||
|
// }]
|
||||||
|
},
|
||||||
// 表单校验
|
// 表单校验
|
||||||
rules: {
|
rules: {
|
||||||
name: [{ required: true, message: "活动名称不能为空", trigger: "blur" }],
|
name: [{ required: true, message: "活动名称不能为空", trigger: "blur" }],
|
||||||
startAndEndTime: [{ required: true, message: "活动时间不能为空", trigger: "blur" }],
|
startAndEndTime: [{ required: true, message: "活动时间不能为空", trigger: "blur" }],
|
||||||
},
|
},
|
||||||
// 商品列表
|
// 商品 SKU 列表
|
||||||
productSpus: [], // TODO 芋艿:需要重新写下
|
productSkus: [],
|
||||||
// 如下的变量,主要为了 v-if 判断可以使用到
|
// 如下的变量,主要为了 v-if 判断可以使用到
|
||||||
PromotionProductScopeEnum: PromotionProductScopeEnum,
|
PromotionProductScopeEnum: PromotionProductScopeEnum,
|
||||||
PromotionActivityStatusEnum: PromotionActivityStatusEnum,
|
PromotionActivityStatusEnum: PromotionActivityStatusEnum,
|
||||||
|
PromotionDiscountTypeEnum: PromotionDiscountTypeEnum,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
|
@ -151,6 +222,10 @@ export default {
|
||||||
this.total = response.data.total;
|
this.total = response.data.total;
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
});
|
});
|
||||||
|
// 获得 SKU 商品列表
|
||||||
|
getSkuOptionList().then(response => {
|
||||||
|
this.productSkus = response.data;
|
||||||
|
});
|
||||||
},
|
},
|
||||||
/** 取消按钮 */
|
/** 取消按钮 */
|
||||||
cancel() {
|
cancel() {
|
||||||
|
@ -166,6 +241,8 @@ export default {
|
||||||
startTime: undefined,
|
startTime: undefined,
|
||||||
endTime: undefined,
|
endTime: undefined,
|
||||||
remark: undefined,
|
remark: undefined,
|
||||||
|
skuIds: [],
|
||||||
|
products: [],
|
||||||
};
|
};
|
||||||
this.resetForm("form");
|
this.resetForm("form");
|
||||||
},
|
},
|
||||||
|
@ -240,7 +317,49 @@ export default {
|
||||||
this.getList();
|
this.getList();
|
||||||
this.$modal.msgSuccess("关闭成功");
|
this.$modal.msgSuccess("关闭成功");
|
||||||
}).catch(() => {});
|
}).catch(() => {});
|
||||||
|
},
|
||||||
|
/** 当 Form 的 SKU 发生变化时 */
|
||||||
|
changeFormSku(skuIds) {
|
||||||
|
// 处理【新增】
|
||||||
|
skuIds.forEach(skuId => {
|
||||||
|
// 获得对应的 SKU 信息
|
||||||
|
const sku = this.productSkus.find(item => item.id === skuId);
|
||||||
|
if (!sku) {
|
||||||
|
// debugger
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
// 判断已存在,直接跳过
|
||||||
|
const product = this.form.products.find(item => item.skuId === skuId);
|
||||||
|
if (product) {
|
||||||
|
// debugger
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
};
|
this.form.products.push({
|
||||||
|
skuId: sku.id,
|
||||||
|
name: sku.name,
|
||||||
|
price: sku.price,
|
||||||
|
stock: sku.stock,
|
||||||
|
spuId: sku.spuId,
|
||||||
|
spuName: sku.spuName,
|
||||||
|
discountType: PromotionDiscountTypeEnum.PRICE.type,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
// 处理【移除】
|
||||||
|
this.form.products.map((product, index) => {
|
||||||
|
if (!skuIds.includes(product.skuId)) {
|
||||||
|
this.form.products.splice(index, 1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
/** 移除 Form 的 SKU */
|
||||||
|
removeFormSku(skuId) {
|
||||||
|
this.form.skuIds.map((id, index) => {
|
||||||
|
if (skuId === id) {
|
||||||
|
this.form.skuIds.splice(index, 1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.changeFormSku(this.form.skuIds);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in New Issue