分享相关代码 注释掉

优惠券 管理端重写 使用的地方 注释
This commit is contained in:
2025-09-11 16:10:38 +08:00
parent 65ba0e18ce
commit 35d257bc56
23 changed files with 1292 additions and 91 deletions

View File

@@ -0,0 +1,92 @@
//package com.czg.service.account.service.impl;
//
//import cn.hutool.core.bean.BeanUtil;
//import cn.hutool.core.util.StrUtil;
//import com.alibaba.fastjson2.JSONArray;
//import com.alibaba.fastjson2.JSONObject;
//import com.czg.account.dto.ShopShareCouponDTO;
//import com.czg.account.dto.ShopShareDTO;
//import com.czg.account.entity.ShopCoupon;
//import com.czg.account.service.ShopCouponService;
//import com.czg.account.vo.ShopShareRecordVO;
//import com.czg.account.vo.ShopShareVO;
//import com.czg.exception.ApiNotPrintException;
//import com.czg.service.account.mapper.ShopShareRecordMapper;
//import com.czg.utils.PageUtil;
//import com.github.pagehelper.PageHelper;
//import com.github.pagehelper.PageInfo;
//import com.mybatisflex.core.paginate.Page;
//import com.mybatisflex.core.query.QueryWrapper;
//import com.mybatisflex.spring.service.impl.ServiceImpl;
//import com.czg.account.entity.ShopShare;
//import com.czg.account.service.ShopShareService;
//import com.czg.service.account.mapper.ShopShareMapper;
//import jakarta.annotation.Resource;
//import org.springframework.stereotype.Service;
//
///**
// * 店铺分享 服务层实现。
// *
// * @author zs
// * @since 2025-03-05
// */
//@Service
//public class ShopShareServiceImpl extends ServiceImpl<ShopShareMapper, ShopShare> implements ShopShareService{
// @Resource
// private ShopCouponService shopCouponService;
// @Resource
// private ShopShareRecordMapper shopShareRecordMapper;
//
// @Override
// public ShopShareVO get(Long shopId) {
// ShopShare shopShare = getOne(new QueryWrapper().eq(ShopShare::getShopId, shopId));
// ShopShareVO shopShareVO = new ShopShareVO();
// if (shopShare != null) {
// BeanUtil.copyProperties(shopShare, shopShareVO);
// if (StrUtil.isNotBlank(shopShare.getRewardCoupon())) {
//// shopShareVO.setRewardCouponList(shopCouponService.list(new QueryWrapper().eq(ShopCoupon::getShopId, shopId).in(ShopCoupon::getId, JSONArray.parseArray(shopShare.getRewardCoupon()))));
// shopShareVO.setRewardCouponList(JSONArray.parseArray(shopShare.getRewardCoupon(), ShopShareCouponDTO.class));
// }
//
// if (StrUtil.isNotBlank(shopShare.getNewCoupon())) {
//// shopShareVO.setNewCouponList(shopCouponService.list(new QueryWrapper().eq(ShopCoupon::getShopId, shopId).in(ShopCoupon::getId, JSONArray.parseArray(shopShare.getNewCoupon()))));
// shopShareVO.setNewCouponList(JSONArray.parseArray(shopShare.getNewCoupon(), ShopShareCouponDTO.class));
// }
// }
// return shopShareVO;
// }
//
// @Override
// public Boolean add(Long shopId, ShopShareDTO shopShareDTO) {
// ShopShare shopShare = getOne(new QueryWrapper().eq(ShopShare::getShopId, shopId));
// if (shopShare == null) {
// shopShare = new ShopShareVO();
// shopShare.setShopId(shopId);
// }
//
// if (shopShareDTO.getNewCouponList() != null && !shopShareDTO.getNewCouponList().isEmpty()) {
// long count = shopCouponService.count(new QueryWrapper().in(ShopCoupon::getId, shopShareDTO.getNewCouponList().stream().map(ShopShareCouponDTO::getId).toList()).eq(ShopCoupon::getShopId, shopId));
// if (count != shopShareDTO.getNewCouponList().size()) {
// throw new ApiNotPrintException("优惠券不存在");
// }
// shopShare.setNewCoupon(JSONArray.toJSONString(shopShareDTO.getNewCouponList()));
// }
//
// if (shopShareDTO.getRewardCouponList() != null && !shopShareDTO.getRewardCouponList().isEmpty()) {
// long count = shopCouponService.count(new QueryWrapper().in(ShopCoupon::getId, shopShareDTO.getRewardCouponList().stream().map(ShopShareCouponDTO::getId).toList()).eq(ShopCoupon::getShopId, shopId));
// if (count != shopShareDTO.getRewardCouponList().size()) {
// throw new ApiNotPrintException("优惠券不存在");
// }
// shopShare.setRewardCoupon(JSONArray.toJSONString(shopShareDTO.getRewardCouponList()));
// }
// BeanUtil.copyProperties(shopShareDTO, shopShare);
// return saveOrUpdate(shopShare);
// }
//
// @Override
// public Page<ShopShareRecordVO> recordPage(Long shopId, String key, Integer status) {
// Page<Object> page = PageUtil.buildPage();
// PageHelper.startPage(Math.toIntExact(page.getPageNumber()), Math.toIntExact(page.getPageSize()));
// return PageUtil.convert(new PageInfo<>(shopShareRecordMapper.getRecord(shopId, key, status)));
// }
//}

View File

@@ -0,0 +1,15 @@
package com.czg.service.market.mapper;
import com.czg.market.entity.ShopCoupon;
import com.mybatisflex.core.BaseMapper;
/**
* 优惠券信息表 映射层。
*
* @author ww
* @since 2025-09-11
*/
public interface ShopCouponMapper extends BaseMapper<ShopCoupon> {
}

View File

@@ -0,0 +1,66 @@
package com.czg.service.market.service.impl;
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.ShopCouponService;
import com.czg.service.market.mapper.ShopCouponMapper;
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 org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;
/**
* 优惠券信息表 服务层实现。
*
* @author ww
* @since 2025-09-11
*/
@DubboService
public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCoupon> implements ShopCouponService{
@Override
public Page<ShopCouponDTO> getCouponPage(ShopCouponDTO param) {
QueryWrapper queryWrapper = PageUtil.buildSortQueryWrapper();
queryWrapper.eq(ShopCoupon::getShopId, param.getShopId())
.eq(ShopCoupon::getCouponType, param.getCouponType())
.orderBy(ShopCoupon::getCreateTime).desc();
return pageAs(PageUtil.buildPage(), queryWrapper, ShopCouponDTO.class);
}
@Override
public ShopCouponDTO getCouponById(Long id) {
AssertUtil.isNull(id, "优惠券ID不能为空");
return getOneAs(new QueryWrapper().eq(ShopCoupon::getId, id), ShopCouponDTO.class);
}
@Override
public void addCoupon(ShopCouponDTO param) {
ShopCoupon coupon = BeanUtil.toBean(param, ShopCoupon.class);
save(coupon);
}
@Override
public void updateCouponById(ShopCouponDTO param) {
if (param.getGiveNum() != null && param.getGiveNum() != -10086) {
ShopCoupon tbShopCoupon = getById(param.getId());
if (param.getGiveNum() < tbShopCoupon.getGiveNum()) {
throw new ValidateException("修改失败 发放数量不可减少");
} else {
param.setLeftNum(tbShopCoupon.getLeftNum() + tbShopCoupon.getGiveNum() - param.getGiveNum());
}
}
ShopCoupon coupon = BeanUtil.toBean(param, ShopCoupon.class);
updateById(coupon,true);
}
@Override
public void deleteCoupon(Long id) {
AssertUtil.isNull(id, "优惠券ID不能为空");
removeById(id);
}
}

View File

@@ -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.ShopCouponMapper">
</mapper>

View File

@@ -0,0 +1,13 @@
package com.ysk.marketservice;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class MarketServiceApplicationTests {
@Test
void contextLoads() {
}
}

View File

@@ -107,12 +107,12 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
private ShopUserFlowService flowService;
@DubboReference
private ShopTableService shopTableService;
@DubboReference
private ShopActivateService activateService;
// @DubboReference
// private ShopActivateService activateService;
@DubboReference
private PointsBasicSettingService pointsBasicService;
@DubboReference
private ShopCouponService couponService;
// @DubboReference
// private ShopCouponService couponService;
@DubboReference
private ShopActivateCouponRecordService couponRecordService;
// 延迟 5 秒
@@ -692,9 +692,9 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
.set(OrderInfo::getPayAmount, 0)
.update();
} else {
//会员活动
activateService.giveActivate(shopUser, new BigDecimal(czgCallBackDto.getAmount()).divide(new BigDecimal(100), 2, RoundingMode.DOWN),
payment.getRelatedId(), flowId);
// //会员活动
// activateService.giveActivate(shopUser, new BigDecimal(czgCallBackDto.getAmount()).divide(new BigDecimal(100), 2, RoundingMode.DOWN),
// payment.getRelatedId(), flowId);
}
}
@@ -785,7 +785,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
//券消耗
List<Long> coupons = JSON.parseArray(orderInfo.getCouponInfoList(), Long.class);
if (CollUtil.isNotEmpty(coupons)) {
couponService.use(coupons, shopUser.getId(), orderInfo.getId());
// couponService.use(coupons, shopUser.getId(), orderInfo.getId());
}
}
String[] payTypes = {PayEnums.VIP_PAY.getValue(), PayEnums.CREDIT_PAY.getValue()};
@@ -972,7 +972,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
//券消耗
List<Long> coupons = JSON.parseArray(orderInfo.getCouponInfoList(), Long.class);
if (CollUtil.isNotEmpty(coupons)) {
couponService.use(coupons, shopUser.getId(), orderInfo.getId());
// couponService.use(coupons, shopUser.getId(), orderInfo.getId());
}
}
}

View File

@@ -75,14 +75,14 @@ public class PayServiceImpl implements PayService {
private UserInfoService userInfoService;
@DubboReference
private ShopInfoService shopInfoService;
@DubboReference
private ShopActivateService shopActivateService;
// @DubboReference
// private ShopActivateService shopActivateService;
@DubboReference
private ShopUserFlowService userFlowService;
@DubboReference
private ShopActivateCouponRecordService inRecordService;
@DubboReference
private ShopCouponService couponService;
// @DubboReference
// private ShopCouponService couponService;
@DubboReference
private MemberPointsService pointsService;
@DubboReference
@@ -371,7 +371,7 @@ public class PayServiceImpl implements PayService {
//更新会员余额 并生成流水
Long flowId = shopUserService.updateMoney(shopUser.getShopId(), shopUserMoneyEditDTO);
//会员活动
shopActivateService.giveActivate(shopUser, payParam.getAmount(), payParam.getActivateId(), flowId);
// shopActivateService.giveActivate(shopUser, payParam.getAmount(), payParam.getActivateId(), flowId);
return CzgResult.success();
}

View File

@@ -15,6 +15,9 @@ 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.*;
import com.czg.product.service.*;
import com.czg.product.vo.ProductGroupVo;
@@ -73,6 +76,8 @@ public class ShopSyncServiceImpl implements ShopSyncService {
private ShopUserService shopUserService;
@Resource
private ShopVendorService vendorService;
@Resource
private ShopCouponService couponService;
@DubboReference
private SyncNoticeService syncNoticeService;
@@ -1284,4 +1289,66 @@ public class ShopSyncServiceImpl implements ShopSyncService {
throw new CzgException("主店数据同步方式不是自动同步");
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public void syncCouponBySourceShop(Long sourceShopId, Long couponId, Integer type) {
AssertUtil.isNull(sourceShopId, "{}不能为空", "源店铺ID");
AssertUtil.isNull(couponId, "{}不能为空", "优惠券ID");
AssertUtil.isNull(type, "{}不能为空", "操作类型");
ShopInfo sourceShop = shopInfoService.getById(sourceShopId);
if (StrUtil.isBlank(sourceShop.getShopType()) || "only".equals(sourceShop.getShopType())
|| sourceShop.getIsHeadShop() == null || sourceShop.getIsHeadShop() != 1) {
// 主店不是主店铺或主店是单店,不进行优惠券同步
return;
}
ShopCoupon couponSource = couponService.getById(couponId);
List<Long> ids = new ArrayList<>();
if ("all".equals(couponSource.getUseShopType())) {
QueryWrapper queryWrapper = new QueryWrapper();
queryWrapper.select(column(ShopConfig::getId));
queryWrapper.eq(ShopConfig::getMainId, sourceShopId);
ids = shopConfigService.listAs(queryWrapper, Long.class);
} else {
if (StrUtil.isBlank(couponSource.getUseShops())) {
return;
}
ids = Arrays.stream(couponSource.getUseShops().split(","))
.map(Long::parseLong)
.collect(Collectors.toList());
}
if (CollUtil.isEmpty(ids)) {
return;
}
couponSource.setId(null);
switch (type) {
case 1://新增
saveCouponsForShops(ids, couponSource, couponId);
break;
case 2://先删除再新增
deleteCouponsBySyncId(couponId);
saveCouponsForShops(ids, couponSource, couponId);
break;
case 3:// 删除
deleteCouponsBySyncId(couponId);
break;
default:
// 处理未知类型,可根据业务需求抛出异常或忽略
throw new IllegalArgumentException("不支持的操作类型: " + type);
}
}
private void saveCouponsForShops(List<Long> ids, ShopCoupon coupon, Long couponId) {
ids.forEach(id -> {
coupon.setShopId(id);
coupon.setSyncId(couponId);
coupon.setId(null); // 确保是新增操作
couponService.save(coupon);
});
}
private void deleteCouponsBySyncId(Long couponId) {
couponService.remove(new QueryWrapper()
.eq(ShopCoupon::getSyncId, couponId));
}
}