Browse Source

商家端优惠券管理前端、后台新增优惠券指定店铺功能业务

multiwx
dy-hu 11 months ago
parent
commit
9d09858511
  1. 23
      cereshop-business/src/main/java/com/shop/cereshop/business/controller/ShopCouponController.java
  2. 7
      cereshop-business/src/main/java/com/shop/cereshop/business/dao/tool/CereShopCouponDAO.java
  3. 3
      cereshop-business/src/main/java/com/shop/cereshop/business/page/tool/ToolProduct.java
  4. 2
      cereshop-business/src/main/java/com/shop/cereshop/business/param/tool/ShopCouponSaveParam.java
  5. 6
      cereshop-business/src/main/java/com/shop/cereshop/business/param/tool/ToolProductNewParam.java
  6. 3
      cereshop-business/src/main/java/com/shop/cereshop/business/service/tool/CereShopCouponService.java
  7. 47
      cereshop-business/src/main/java/com/shop/cereshop/business/service/tool/impl/CereShopCouponServiceImpl.java
  8. 49
      cereshop-business/src/main/resources/mybatis/mapper/tool/CereShopCouponDAO.xml
  9. 2
      cereshop-business/src/main/resources/mybatis/mapper/tool/CereShopCouponDetailDAO.xml
  10. 1
      cereshop-commons/src/main/java/com/shop/cereshop/commons/constant/IntegerEnum.java
  11. 2
      cereshop-commons/src/main/java/com/shop/cereshop/commons/domain/tool/CereShopCoupon.java

23
cereshop-business/src/main/java/com/shop/cereshop/business/controller/ShopCouponController.java

@ -13,10 +13,11 @@ import com.shop.cereshop.business.page.tool.ShopCouponData;
import com.shop.cereshop.business.page.tool.ShopCouponDetail;
import com.shop.cereshop.business.page.tool.ToolProduct;
import com.shop.cereshop.business.param.tool.*;
import com.shop.cereshop.business.service.shop.CerePlatformShopService;
import com.shop.cereshop.business.service.tool.CereShopCouponService;
import com.shop.cereshop.commons.domain.business.CerePlatformBusinessUser;
import com.shop.cereshop.commons.domain.common.Page;
import com.shop.cereshop.commons.domain.common.PageParam;
import com.shop.cereshop.commons.domain.shop.CerePlatformShop;
import com.shop.cereshop.commons.exception.CoBusinessException;
import com.shop.cereshop.commons.result.Result;
import com.shop.cereshop.commons.utils.GsonUtil;
@ -45,9 +46,6 @@ public class ShopCouponController {
@Autowired
private CereShopCouponService cereShopCouponService;
@Autowired
private CerePlatformShopService shopService;
/**
* 新增满减券/折扣券
* @param param
@ -161,9 +159,22 @@ public class ShopCouponController {
public Result<Page<ToolProduct>> getProducts(@RequestBody ToolProductNewParam param, HttpServletRequest request) throws CoBusinessException{
//获取当前登录账户
CerePlatformBusinessUser user = (CerePlatformBusinessUser) request.getAttribute("user");
shopService.selectAll(user.getBusinessId());
param.setShopIds(shopService.selectAll(user.getBusinessId()).stream().map(Shop::getShopId).collect(Collectors.toList()));
param.setBusinessId(user.getBusinessId());
Page page=cereShopCouponService.getProducts(param);
return new Result(page);
}
/**
* 选择店铺查询
* @return
*/
@PostMapping(value = "getShops")
@ApiOperation(value = "选择商品查询")
public Result<Page<CerePlatformShop>> getShops(@RequestBody ToolProductNewParam param, HttpServletRequest request) throws CoBusinessException{
//获取当前登录账户
CerePlatformBusinessUser user = (CerePlatformBusinessUser) request.getAttribute("user");
param.setBusinessId(user.getBusinessId());
Page page=cereShopCouponService.getShops(param);
return new Result(page);
}
}

7
cereshop-business/src/main/java/com/shop/cereshop/business/dao/tool/CereShopCouponDAO.java

@ -11,6 +11,7 @@ import com.shop.cereshop.business.page.tool.*;
import com.shop.cereshop.business.param.canvas.CanvasCouponParam;
import com.shop.cereshop.business.param.tool.OperateCouponParam;
import com.shop.cereshop.business.param.tool.ShopCouponGetAllParam;
import com.shop.cereshop.commons.domain.shop.CerePlatformShop;
import com.shop.cereshop.commons.domain.tool.CereShopCoupon;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
@ -31,6 +32,8 @@ public interface CereShopCouponDAO extends BaseMapper<CereShopCoupon> {
List<Long> findProductIdsByShopIdAndIds(@Param("shopId") Long shopId,@Param("ids") List<Long> ids);
List<Long> findProductIdsByShopIds(@Param("shopIds") List<Long> shopIds);
ShopCouponDetail getById(@Param("shopCouponId") Long shopCouponId);
List<ShopCoupon> getAll(ShopCouponGetAllParam param);
@ -71,7 +74,9 @@ public interface CereShopCouponDAO extends BaseMapper<CereShopCoupon> {
List<CouponProduct> findDataProductsLimitProducts(@Param("shopCouponId") Long shopCouponId,
@Param("orderIdList") List<Long> orderIdList);
List<ToolProduct> getProductsNew(@Param("shopIds") List<Long> shopIds,
List<ToolProduct> getProductsNew(@Param("businessId") Long businessId,
@Param("shopCouponId") Long shopCouponId,
@Param("queryType") Integer queryType);
List<CerePlatformShop> getShops(@Param("businessId") Long businessId);
}

3
cereshop-business/src/main/java/com/shop/cereshop/business/page/tool/ToolProduct.java

@ -18,6 +18,9 @@ import java.math.BigDecimal;
@ApiModel(value = "ToolProduct", description = "营销活动商品数据实体类")
public class ToolProduct {
@ApiModelProperty(value = "店铺id")
private Long shopId;
/**
* 商品id
*/

2
cereshop-business/src/main/java/com/shop/cereshop/business/param/tool/ShopCouponSaveParam.java

@ -140,7 +140,7 @@ public class ShopCouponSaveParam implements Serializable {
private Integer type;
/**
* 选中的商品id数组
* 选中的商品id数组或选中的店铺id数组
*/
@ApiModelProperty(value = "选中的商品id数组",required = true)
private List<Long> ids;

6
cereshop-business/src/main/java/com/shop/cereshop/business/param/tool/ToolProductNewParam.java

@ -20,10 +20,10 @@ import java.util.List;
public class ToolProductNewParam extends PageParam {
/**
* 店铺id集合
* 商家id
*/
@ApiModelProperty(value = "店铺id集合")
private List<Long> shopIds;
@ApiModelProperty(value = "商家id")
private Long businessId;
/**
* 活动id

3
cereshop-business/src/main/java/com/shop/cereshop/business/service/tool/CereShopCouponService.java

@ -12,6 +12,7 @@ import com.shop.cereshop.business.param.canvas.CanvasCouponParam;
import com.shop.cereshop.business.param.tool.*;
import com.shop.cereshop.commons.domain.business.CerePlatformBusinessUser;
import com.shop.cereshop.commons.domain.common.Page;
import com.shop.cereshop.commons.domain.common.PageParam;
import com.shop.cereshop.commons.domain.tool.CereShopCoupon;
import com.shop.cereshop.commons.exception.CoBusinessException;
@ -45,4 +46,6 @@ public interface CereShopCouponService {
List<CereShopCoupon> findAllByShopId(Long shopId);
Page getShopCoupons(CanvasCouponParam param) throws CoBusinessException;
Page getShops(ToolProductNewParam param) throws CoBusinessException;
}

47
cereshop-business/src/main/java/com/shop/cereshop/business/service/tool/impl/CereShopCouponServiceImpl.java

@ -5,6 +5,7 @@
*/
package com.shop.cereshop.business.service.tool.impl;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
@ -18,6 +19,7 @@ import com.shop.cereshop.business.param.tool.*;
import com.shop.cereshop.business.redis.service.api.StringRedisService;
import com.shop.cereshop.business.service.log.CerePlatformLogService;
import com.shop.cereshop.business.service.redis.CereRedisKeyServcice;
import com.shop.cereshop.business.service.shop.CerePlatformShopService;
import com.shop.cereshop.business.service.tool.CereShopCouponDetailService;
import com.shop.cereshop.business.service.tool.CereShopCouponService;
import com.shop.cereshop.commons.constant.CoReturnFormat;
@ -25,6 +27,9 @@ import com.shop.cereshop.commons.constant.IntegerEnum;
import com.shop.cereshop.commons.constant.StringEnum;
import com.shop.cereshop.commons.domain.business.CerePlatformBusinessUser;
import com.shop.cereshop.commons.domain.common.Page;
import com.shop.cereshop.commons.domain.common.PageParam;
import com.shop.cereshop.commons.domain.live.CereLiveProduct;
import com.shop.cereshop.commons.domain.shop.CerePlatformShop;
import com.shop.cereshop.commons.domain.tool.CereShopCoupon;
import com.shop.cereshop.commons.domain.tool.CereShopCouponDetail;
import com.shop.cereshop.commons.domain.tool.CereShopCouponExclude;
@ -65,6 +70,9 @@ public class CereShopCouponServiceImpl implements CereShopCouponService {
@Autowired
private CereShopCouponExcludeDAO cereShopCouponExcludeDAO;
@Autowired
private CerePlatformShopService platformShopService;
@Override
@Transactional(isolation= Isolation.DEFAULT,propagation= Propagation.REQUIRED,rollbackFor = {CoBusinessException.class, Exception.class})
public void save(ShopCouponSaveParam param, CerePlatformBusinessUser user) throws CoBusinessException,Exception {
@ -72,13 +80,16 @@ public class CereShopCouponServiceImpl implements CereShopCouponService {
List<Long> ids=null;
List<Long> excludeIds = null;
if(IntegerEnum.APPLY_TYPE_ALL.getCode().equals(param.getApplyType())){
//如果是全部商品,查询本店所有有效商品id
//如果是全部商品,查询商家所有有效商品id
ids=cereShopCouponDAO.findProductIdsByShopId(param.getShopId());
}else if(IntegerEnum.APPLY_TYPE_SHOP.getCode().equals(param.getApplyType())){
//如果是指定店铺获取指定店铺下所有商品
ids=cereShopCouponDAO.findProductIdsByShopIds(param.getIds());
}else if(IntegerEnum.APPLY_TYPE_YES.getCode().equals(param.getApplyType())){
//如果是指定商品可用
ids=param.getIds();
}else {
//如果是指定商品不可用,查询本所有不在这个范围内的有效商品id
//如果是指定商品不可用,查询本商家所有不在这个范围内的有效商品id
ids=cereShopCouponDAO.findProductIdsByShopIdAndIds(param.getShopId(),param.getIds());
excludeIds = param.getIds();
}
@ -210,6 +221,9 @@ public class CereShopCouponServiceImpl implements CereShopCouponService {
if(IntegerEnum.APPLY_TYPE_ALL.getCode().equals(param.getApplyType())){
//如果是全部商品,查询本店所有有效商品id
ids=cereShopCouponDAO.findProductIdsByShopId(param.getShopId());
}else if(IntegerEnum.APPLY_TYPE_SHOP.getCode().equals(param.getApplyType())){
//如果是指定店铺获取指定店铺下所有商品
ids=cereShopCouponDAO.findProductIdsByShopIds(param.getIds());
}else if(IntegerEnum.APPLY_TYPE_YES.getCode().equals(param.getApplyType())){
//如果是指定商品可用
ids=param.getIds();
@ -331,7 +345,14 @@ public class CereShopCouponServiceImpl implements CereShopCouponService {
ShopCouponDetail detail=cereShopCouponDAO.getById(shopCouponId);
if(detail!=null){
//查询商品明细数据
detail.setProducts(cereShopCouponDetailService.findProducts(shopCouponId));
List<ToolProduct> products = cereShopCouponDetailService.findProducts(shopCouponId);
detail.setProducts(products);
if (IntegerEnum.APPLY_TYPE_SHOP.getCode().equals(detail.getApplyType())){
//指定店铺获取店铺id
List<Long> shopIds = products.stream().map(ToolProduct::getShopId).distinct().collect(Collectors.toList());
detail.setIds(shopIds);
}
if (IntegerEnum.APPLY_TYPE_NO.getCode().equals(detail.getApplyType())) {
detail.setExcludeIds(cereShopCouponExcludeDAO.selectList(Wrappers.<CereShopCouponExclude>lambdaQuery()
.eq(CereShopCouponExclude::getShopCouponId, shopCouponId)).stream().map(CereShopCouponExclude::getProductId)
@ -396,7 +417,7 @@ public class CereShopCouponServiceImpl implements CereShopCouponService {
@Override
public Page getProducts(ToolProductNewParam param) throws CoBusinessException {
PageHelper.startPage(param.getPage(),param.getPageSize());
List<ToolProduct> list=cereShopCouponDAO.getProductsNew(param.getShopIds(), param.getActivityId(), param.getQueryType());
List<ToolProduct> list=cereShopCouponDAO.getProductsNew(param.getBusinessId(), param.getActivityId(), param.getQueryType());
PageInfo<ToolProduct> pageInfo=new PageInfo<>(list);
Page page=new Page(pageInfo.getList(),pageInfo.getTotal());
return page;
@ -528,4 +549,22 @@ public class CereShopCouponServiceImpl implements CereShopCouponService {
Page page=new Page(pageInfo.getList(),pageInfo.getTotal());
return page;
}
@Override
public Page getShops(ToolProductNewParam param) throws CoBusinessException {
PageHelper.startPage(param.getPage(),param.getPageSize());
List<CerePlatformShop> list;
if (ObjectUtils.isNotEmpty(param.getActivityId())){
//查看店铺获取全部已设置优惠券的商品过滤商品的店铺id去获取店铺信息
List<ToolProduct> prodList = cereShopCouponDAO.getProductsNew(param.getBusinessId(), param.getActivityId(), param.getQueryType());
//去重获取店铺id
List<Long> shopIds = prodList.stream().map(ToolProduct::getShopId).distinct().collect(Collectors.toList());
list = platformShopService.getByIdList(shopIds);
}else {
list = cereShopCouponDAO.getShops(param.getBusinessId());
}
PageInfo<CerePlatformShop> pageInfo=new PageInfo<>(list);
Page page=new Page(pageInfo.getList(),pageInfo.getTotal());
return page;
}
}

49
cereshop-business/src/main/resources/mybatis/mapper/tool/CereShopCouponDAO.xml

@ -107,17 +107,38 @@
UPDATE cere_shop_coupon SET `state` = #{state} where shop_coupon_id=#{shopCouponId}
</update>
<select id="findProductIdsByShopId" parameterType="java.lang.Object" resultType="java.lang.Long">
<!-- <select id="findProductIdsByShopId" parameterType="java.lang.Object" resultType="java.lang.Long">
SELECT product_id from cere_shop_product where shop_id=#{shopId} and shelve_state=1
</select>-->
<select id="findProductIdsByShopId" parameterType="java.lang.Object" resultType="java.lang.Long">
SELECT product_id from cere_shop_product where shelve_state=1 and shop_id in (select shop_id from cere_platform_shop where business_id = #{shopId})
</select>
<select id="findProductIdsByShopIdAndIds" parameterType="java.lang.Object" resultType="java.lang.Long">
<!-- <select id="findProductIdsByShopIdAndIds" parameterType="java.lang.Object" resultType="java.lang.Long">
SELECT product_id from cere_shop_product where shop_id=#{shopId} and shelve_state=1
and product_id NOT in (
<foreach collection="ids" item="id" index="index" separator=",">
#{id}
</foreach>
)
</select>-->
<select id="findProductIdsByShopIdAndIds" parameterType="java.lang.Object" resultType="java.lang.Long">
SELECT product_id from cere_shop_product where shelve_state=1 and shop_id in (select shop_id from cere_platform_shop where business_id = #{shopId})
and product_id NOT in (
<foreach collection="ids" item="id" index="index" separator=",">
#{id}
</foreach>
)
</select>
<select id="findProductIdsByShopIds" parameterType="java.lang.Object" resultType="java.lang.Long">
SELECT product_id from cere_shop_product where shelve_state=1 and shop_id in (
<foreach collection="shopIds" item="shopId" index="index" separator=",">
#{shopId}
</foreach>
)
</select>
<select id="getById" parameterType="java.lang.Object" resultType="com.shop.cereshop.business.page.tool.ShopCouponDetail">
@ -183,7 +204,7 @@
</select>
<select id="getProductsNew" parameterType="java.lang.Object" resultType="com.shop.cereshop.business.page.tool.ToolProduct">
SELECT a.product_id,a.product_name,b.minMoney originalPrice,d.product_image image,g.stock_number from cere_shop_product a
SELECT a.product_id,a.product_name,a.shop_id,b.minMoney originalPrice,d.product_image image,g.stock_number from cere_shop_product a
<if test="shopCouponId != null and queryType == 2">
join cere_shop_coupon_detail cscd on cscd.product_id = a.product_id
</if>
@ -196,14 +217,7 @@
ON a.product_id=d.product_id
LEFT JOIN cere_product_classify e ON a.classify_id=e.classify_id
LEFT JOIN (SELECT SUM(stock_number) stock_number,product_id from cere_product_sku GROUP BY product_id) g ON b.product_id=g.product_id
where a.shelve_state = 1
<if test="shopIds!=null and shopIds.size()>0">
and a.shop_id in (
<foreach collection="shopIds" item="shopId" index="index" separator=",">
#{shopId}
</foreach>
)
</if>
where a.shelve_state = 1 and a.shop_id in (select shop_id from cere_platform_shop where business_id = #{businessId})
<if test="shopCouponId != null and queryType == 2">
and cscd.shop_coupon_id = #{shopCouponId}
</if>
@ -221,7 +235,7 @@
IFNULL(SUM(a.price), 0)
FROM cere_shop_order a
LEFT JOIN cere_buyer_shop_coupon b ON a.id = b.id
where a.state in (2,3,4,6) and a.shop_id = #{shopId} and b.shop_coupon_id = #{shopCouponId}
where a.state in (2,3,4,6) and a.project = #{shopId} and b.shop_coupon_id = #{shopCouponId}
and a.create_time &lt; #{time}
</select>
@ -232,7 +246,7 @@
JOIN cere_order_product op on op.order_id = a.order_id
JOIN cere_buyer_shop_coupon b ON a.id = b.id
JOIN cere_shop_coupon_detail scd on scd.product_id = op.product_id and scd.shop_coupon_id = b.shop_coupon_id
where a.state in (2,3,4,6) and a.shop_id = #{shopId} and b.shop_coupon_id = #{shopCouponId}
where a.state in (2,3,4,6) and a.project = #{shopId} and b.shop_coupon_id = #{shopCouponId}
and a.create_time &lt; #{time}
</select>
@ -246,7 +260,7 @@
SELECT IFNULL(SUM(a.number), 0) FROM cere_order_product a
LEFT JOIN cere_shop_order b ON a.order_id = b.order_id
LEFT JOIN cere_buyer_shop_coupon c ON b.id = c.id
where b.shop_id = #{shopId} and b.state in (2,3,4,6) and c.shop_coupon_id = #{shopCouponId}
where b.project = #{shopId} and b.state in (2,3,4,6) and c.shop_coupon_id = #{shopCouponId}
and b.create_time &lt; #{time}
</select>
@ -255,7 +269,7 @@
JOIN cere_shop_order b ON a.order_id = b.order_id
JOIN cere_buyer_shop_coupon c ON b.id = c.id
JOIN cere_shop_coupon_detail scd on scd.product_id = a.product_id and scd.shop_coupon_id = c.shop_coupon_id
where b.shop_id = #{shopId} and b.state in (2,3,4,6) and c.shop_coupon_id = #{shopCouponId}
where b.project = #{shopId} and b.state in (2,3,4,6) and c.shop_coupon_id = #{shopCouponId}
and b.create_time &lt; #{time}
</select>
@ -285,7 +299,7 @@
<select id="findOrderIdList" resultType="java.lang.Long">
SELECT a.order_id from cere_shop_order a
JOIN cere_buyer_shop_coupon b ON a.id = b.id
where a.shop_id = #{shopId} and b.shop_coupon_id = #{shopCouponId} and a.state in (2,3,4,6) and a.create_time &lt; #{time}
where a.project = #{shopId} and b.shop_coupon_id = #{shopCouponId} and a.state in (2,3,4,6) and a.create_time &lt; #{time}
</select>
<select id="findDataProducts" parameterType="java.lang.Object" resultType="com.shop.cereshop.business.page.tool.CouponProduct">
@ -310,4 +324,7 @@
group by a.product_id
</select>
<select id="getShops" parameterType="java.lang.Object" resultType="com.shop.cereshop.commons.domain.shop.CerePlatformShop">
SELECT * FROM cere_platform_shop where business_id=#{businessId}
</select>
</mapper>

2
cereshop-business/src/main/resources/mybatis/mapper/tool/CereShopCouponDetailDAO.xml

@ -40,7 +40,7 @@
</delete>
<select id="findProducts" parameterType="java.lang.Object" resultType="com.shop.cereshop.business.page.tool.ToolProduct">
SELECT b.product_id,b.product_name,c.minMoney originalPrice,e.product_image image,g.stock_number from cere_shop_coupon_detail a
SELECT b.product_id,b.product_name,b.shop_id,c.minMoney originalPrice,e.product_image image,g.stock_number from cere_shop_coupon_detail a
LEFT JOIN cere_shop_product b ON a.product_id=b.product_id
LEFT JOIN (SELECT product_id,MIN(price) minMoney from cere_product_sku GROUP BY product_id) c ON b.product_id=c.product_id
LEFT JOIN (SELECT product_id,MAX(price) maxMoney from cere_product_sku GROUP BY product_id) d ON b.product_id=d.product_id

1
cereshop-commons/src/main/java/com/shop/cereshop/commons/constant/IntegerEnum.java

@ -189,6 +189,7 @@ public enum IntegerEnum {
APPLY_TYPE_ALL("优惠券-适用商品-全部",1),
APPLY_TYPE_YES("优惠券-适用商品-指定可用",2),
APPLY_TYPE_NO("优惠券-适用商品-指定不可用",3),
APPLY_TYPE_SHOP("优惠券-适用店铺-指定可用",4),
TIME_TYPE_FIXED("优惠券-用券时间-固定时间",1),
COUPON_TYPE_REDUTION("优惠券类型-满减",1),
COUPON_TYPE_DISCOUNT("优惠券类型-折扣",2),

2
cereshop-commons/src/main/java/com/shop/cereshop/commons/domain/tool/CereShopCoupon.java

@ -27,7 +27,7 @@ public class CereShopCoupon implements Serializable {
private Long shopCouponId;
/**
* 店铺id
* 店铺id(实际存商家id)
*/
@ApiModelProperty(value = "店铺id")
private Long shopId;

Loading…
Cancel
Save