原作废代码 删除

This commit is contained in:
2025-09-11 13:44:28 +08:00
parent e9fa387e02
commit 65ba0e18ce
16 changed files with 234 additions and 1280 deletions

View File

@@ -1,14 +0,0 @@
package com.czg.service.account.mapper;
import com.mybatisflex.core.BaseMapper;
import com.czg.account.entity.ShopCoupon;
/**
* 优惠券 映射层。
*
* @author ww
* @since 2025-02-17
*/
public interface ShopCouponMapper extends BaseMapper<ShopCoupon> {
}

View File

@@ -1,191 +0,0 @@
package com.czg.service.account.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.TypeReference;
import com.czg.account.dto.ShopActivateDTO;
import com.czg.account.dto.shopuser.ShopUserMoneyEditDTO;
import com.czg.account.entity.ShopActivate;
import com.czg.account.entity.ShopActivateCouponRecord;
import com.czg.account.entity.ShopCoupon;
import com.czg.account.entity.ShopUser;
import com.czg.account.service.*;
import com.czg.enums.ShopUserFlowBizEnum;
import com.czg.sa.StpKit;
import com.czg.service.account.mapper.ShopActivateMapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 活动 服务层实现。
*
* @author ww
* @since 2025-02-17
*/
@Slf4j
@DubboService
public class ShopActivateServiceImpl extends ServiceImpl<ShopActivateMapper, ShopActivate> implements ShopActivateService {
@Resource
private ShopCouponService couponService;
@Resource
private ShopActivateCouponRecordService inRecordService;
@Resource
private ShopUserService shopUserService;
@Resource
private MemberPointsService pointsService;
@Override
public List<ShopActivateDTO> getList(Long shopId) {
List<ShopActivateDTO> activateDtoS = queryChain().select()
.eq(ShopActivate::getShopId, shopId == null ? StpKit.USER.getShopId() : shopId)
.orderBy(ShopActivate::getAmount, true)
.listAs(ShopActivateDTO.class);
for (ShopActivateDTO activateDTO : activateDtoS) {
if (StrUtil.isNotBlank(activateDTO.getCoupons())) {
//组装优惠券
activateDTO.setCouponList(getCoupons(activateDTO.getCoupons()));
}
}
return activateDtoS;
}
@Override
public Boolean add(ShopActivateDTO activateDTO) {
ShopActivate shopActivate = new ShopActivate();
BeanUtil.copyProperties(activateDTO, shopActivate);
return save(shopActivate);
}
@Override
public Boolean edit(ShopActivateDTO activateDTO) {
ShopActivate shopActivate = new ShopActivate();
BeanUtil.copyProperties(activateDTO, shopActivate);
return updateById(shopActivate);
}
@Override
public void giveActivate(ShopUser shopUser, BigDecimal memAmount, Long activateId, Long relationId) {
if (activateId == null) {
return;
}
ShopActivate activate = getById(activateId);
if (ObjectUtil.isNull(activate)) {
return;
}
//赠送优惠券
if (activate.getIsGiftCoupon() == 1 && StrUtil.isNotBlank(activate.getCoupons())) {
Map<Long, Integer> couponUseMap = JSONObject.parseObject(activate.getCoupons(), new TypeReference<>() {
});
Map<Long, ShopCoupon> couponMap = new HashMap<>();
couponUseMap.forEach((couponId, giftNumber) -> {
ShopCoupon shopCoupon;
if (couponMap.containsKey(couponId)) {
shopCoupon = couponMap.get(couponId);
} else {
shopCoupon = couponService.queryChain().select().eq(ShopCoupon::getId, couponId).one();
couponMap.put(couponId, shopCoupon);
}
if (shopCoupon != null && shopCoupon.getStatus().equals(1) && shopCoupon.getLeftNumber() > giftNumber) {
LocalDateTime start = LocalDateTime.now().with(LocalTime.MIN);
LocalDateTime end = null;
if ("fixed".equals(shopCoupon.getValidityType())) {
//固定时间
end = LocalDateTimeUtil.offset(start, shopCoupon.getValidDays(), ChronoUnit.DAYS).with(LocalTime.MAX);
} else if ("custom".equals(shopCoupon.getValidityType())) {
//自定义时间
start = shopCoupon.getValidStartTime();
end = shopCoupon.getValidEndTime();
}
List<ShopActivateCouponRecord> actGiveRecords = new ArrayList<>();
ShopActivateCouponRecord record = new ShopActivateCouponRecord();
record.setShopUserId(shopUser.getId());
record.setCouponId(shopCoupon.getId());
record.setShopId(shopUser.getShopId());
record.setSourceActId(activate.getId());
record.setSourceFlowId(relationId);
record.setUseStartTime(start);
record.setUseEndTime(end);
record.setSource("activate");
record.setName(shopCoupon.getTitle());
record.setCouponJson(getCouponJson(activate, shopCoupon));
if (shopCoupon.getType() == 1) {
record.setType(1);
record.setFullAmount(shopCoupon.getFullAmount());
record.setDiscountAmount(shopCoupon.getDiscountAmount());
} else if (shopCoupon.getType() == 2) {
record.setType(2);
record.setProId(shopCoupon.getProId());
}
for (int i = 0; i < giftNumber; i++) {
actGiveRecords.add(record);
}
inRecordService.saveBatch(actGiveRecords);
couponService.updateChain()
.set(ShopCoupon::getLeftNumber, shopCoupon.getLeftNumber() - giftNumber)
.eq(ShopCoupon::getId, shopCoupon.getId())
.update();
}
});
}
//赠送金额
if (activate.getGiftAmount() != null && activate.getGiftAmount().compareTo(BigDecimal.ZERO) > 0) {
ShopUserMoneyEditDTO shopUserMoneyEditDTO = new ShopUserMoneyEditDTO()
.setId(shopUser.getId())
.setMoney(activate.getGiftAmount())
.setType(1)
.setRemark("充值活动赠送")
.setRelationId(relationId)
.setBizEnum(ShopUserFlowBizEnum.AWARD_IN);
//更新会员余额 并生成流水
shopUserService.updateMoney(shopUser.getShopId(), shopUserMoneyEditDTO);
}
if (activate.getGiftPoints() != null && activate.getGiftPoints() > 0) {
pointsService.addPoints(shopUser.getId(), activate.getGiftPoints(), "储值赠送积分", null);
}
}
/**
* 获取优惠券详细信息 目前仅返回 id 名称 剩余数量 赠送数量
*/
private List<ShopCoupon> getCoupons(String couponJson) {
Map<String, Integer> couponMap;
try {
couponMap = JSONObject.parseObject(couponJson, new TypeReference<>() {
});
} catch (Exception e) {
return new ArrayList<>();
}
if (couponMap.isEmpty()) {
return new ArrayList<>();
}
List<ShopCoupon> list = couponService.queryChain()
.select(ShopCoupon::getId, ShopCoupon::getTitle, ShopCoupon::getLeftNumber)
.in(ShopCoupon::getId, couponMap.keySet())
.list();
list.forEach(coupon -> coupon.setNumber(couponMap.get(coupon.getId().toString())));
return list;
}
private String getCouponJson(ShopActivate activate, ShopCoupon tbShopCoupon) {
JSONObject result = new JSONObject();
result.put("activate", JSONObject.toJSONString(activate));
result.put("coupon", JSONObject.toJSONString(tbShopCoupon));
return result.toJSONString();
}
}

View File

@@ -1,222 +1,216 @@
package com.czg.service.account.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.exceptions.ValidateException;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.czg.account.dto.QueryReceiveDto;
import com.czg.account.dto.ShopCouponDTO;
import com.czg.account.entity.ShopActivateCouponRecord;
import com.czg.account.entity.ShopCoupon;
import com.czg.account.entity.ShopUser;
import com.czg.account.service.ShopActivateCouponRecordService;
import com.czg.account.service.ShopCouponService;
import com.czg.account.service.ShopInfoService;
import com.czg.account.service.ShopUserService;
import com.czg.account.vo.CouponReceiveVo;
import com.czg.account.vo.UserCouponVo;
import com.czg.product.entity.Product;
import com.czg.product.service.ProductService;
import com.czg.service.account.mapper.ShopCouponMapper;
import com.czg.utils.AssertUtil;
import com.czg.utils.PageUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import java.math.BigDecimal;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
/**
* 优惠券 服务层实现。
*
* @author ww
* @since 2025-02-17
*/
@Slf4j
@DubboService
public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCoupon> implements ShopCouponService {
@Resource
private ShopActivateCouponRecordService couponRecordService;
@Resource
private ShopUserService shopUserService;
@Resource
private ShopInfoService shopInfoService;
@DubboReference
private ProductService productService;
@Override
public List<ShopCouponDTO> getList(Long shopId, Integer type, Integer status) {
List<ShopCouponDTO> coupons = queryChain().select()
.eq(ShopCoupon::getShopId, shopId)
.eq(ShopCoupon::getType, type)
.eq(ShopCoupon::getStatus, status)
.orderBy(ShopCoupon::getCreateTime).desc()
.listAs(ShopCouponDTO.class);
System.out.println(coupons);
coupons.forEach(coupon -> {
if (coupon.getProId() != null) {
Product product = productService.getById(coupon.getProId());
coupon.setProName(product.getName());
}
});
return coupons;
}
@Override
public Boolean add(ShopCouponDTO couponDTO) {
ShopCoupon shopCoupon = new ShopCoupon();
BeanUtil.copyProperties(couponDTO, shopCoupon);
shopCoupon.setLeftNumber(shopCoupon.getNumber());
return save(shopCoupon);
}
@Override
public Boolean edit(ShopCouponDTO couponDTO) {
ShopCoupon shopCoupon = new ShopCoupon();
BeanUtil.copyProperties(couponDTO, shopCoupon);
if (couponDTO.getNumber() != null) {
ShopCoupon tbShopCoupon = getById(couponDTO.getId());
if (shopCoupon.getNumber() < tbShopCoupon.getNumber()) {
throw new ValidateException("修改失败 发放数量不可减少");
} else {
shopCoupon.setLeftNumber(shopCoupon.getLeftNumber() + shopCoupon.getNumber() - tbShopCoupon.getNumber());
}
}
return updateById(shopCoupon);
}
@Override
public Page<CouponReceiveVo> queryReceive(QueryReceiveDto param) {
Page<Object> page = PageUtil.buildPage();
PageHelper.startPage(Math.toIntExact(page.getPageNumber()), Math.toIntExact(page.getPageSize()));
return PageUtil.convert(new PageInfo<>(couponRecordService.queryReceive(param)));
}
@Override
public Page<ShopActivateCouponRecord> find(Long userId, Long shopId, Integer status) {
Page<Object> page = PageUtil.buildPage();
List<Long> shopUserIds = shopUserService.queryChain()
.eq(ShopUser::getUserId, userId)
.eq(ShopUser::getShopId, shopId)
.select(ShopUser::getId).listAs(Long.class);
if (CollectionUtil.isNotEmpty(shopUserIds)) {
PageHelper.startPage(Math.toIntExact(page.getPageNumber()), Math.toIntExact(page.getPageSize()));
return PageUtil.convert(new PageInfo<>(couponRecordService.findByUser(shopUserIds, status)));
}
return new Page<>();
}
@Override
public List<UserCouponVo> findCoupon(Long shopId, Long shopUserId, Integer type) {
List<UserCouponVo> tbUserCouponVos = couponRecordService.queryByVipIdAndShopId(shopId, shopUserId, type);
if (CollectionUtil.isNotEmpty(tbUserCouponVos)) {
String week = DateUtil.dayOfWeekEnum(new Date()).toChinese("");
LocalTime now = LocalTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss");
//券id 券使用描述
Map<Long, JSONObject> coupons = new HashMap<>();
for (UserCouponVo tbUserCouponVo : tbUserCouponVos) {
if (!coupons.containsKey(tbUserCouponVo.getCouponId())) {
setCouponInfo(coupons, tbUserCouponVo, null, week, now, formatter);
}
JSONObject couponJson = coupons.get(tbUserCouponVo.getCouponId());
tbUserCouponVo.setUseRestrictions(couponJson.getString("useRestrictions"));
tbUserCouponVo.setUse(couponJson.getBoolean("isUse"));
}
tbUserCouponVos.sort(Comparator.comparing(UserCouponVo::isUse).reversed());
return tbUserCouponVos;
}
return null;
}
@Override
public Boolean use(List<Long> ids, Long shopUserId, Long orderId) {
List<ShopActivateCouponRecord> records = couponRecordService.listByIds(ids);
if (records.isEmpty()) {
log.error("优惠券使用失败订单Id:{}", orderId);
return false;
}
// 使用流来统计 couponId 出现的次数
Map<Long, Long> couponIdCountMap = records.stream()
.collect(Collectors.groupingBy(ShopActivateCouponRecord::getCouponId,
Collectors.counting()
));
couponIdCountMap.forEach((couponId, count) -> {
ShopCoupon tbShopCoupon = getById(couponId);
tbShopCoupon.setUseNumber(tbShopCoupon.getUseNumber() + count.intValue());
ShopCoupon coupon1 = new ShopCoupon();
coupon1.setId(couponId);
coupon1.setUseNumber(tbShopCoupon.getUseNumber());
updateById(coupon1);
});
return couponRecordService.updateChain()
.set(ShopActivateCouponRecord::getStatus, 1)
.set(ShopActivateCouponRecord::getTargetId, orderId)
.eq(ShopActivateCouponRecord::getShopUserId, shopUserId)
.in(ShopActivateCouponRecord::getId, ids).update();
}
/**
* 退还券
*/
@Override
public Boolean refund(Long orderId, Long shopUserId) {
return couponRecordService.updateChain()
.set(ShopActivateCouponRecord::getStatus, 0)
.eq(ShopActivateCouponRecord::getShopUserId, shopUserId)
.eq(ShopActivateCouponRecord::getTargetId, orderId)
.update();
}
private void setCouponInfo(Map<Long, JSONObject> coupons, UserCouponVo tbUserCouponVo, BigDecimal amount, String week, LocalTime now, DateTimeFormatter formatter) {
JSONObject json = new JSONObject();
boolean isUse = true;
ShopCoupon tbShopCoupon = getById(tbUserCouponVo.getCouponId());
StringBuilder useRestrictions = new StringBuilder("每天 ");
if (amount != null && tbShopCoupon.getType().equals(1)) {
if (amount.compareTo(tbShopCoupon.getFullAmount()) < 0) {
isUse = false;
}
}
if (StrUtil.isNotBlank(tbShopCoupon.getUserDays())) {
String[] split = tbShopCoupon.getUserDays().split(",");
if (split.length != 7) {
useRestrictions = new StringBuilder(STR."\{tbShopCoupon.getUserDays()} ");
}
if (!tbShopCoupon.getUserDays().contains(week)) {
isUse = false;
}
}
if ("custom".equals(tbShopCoupon.getUseTimeType())) {
if (now.isBefore(tbShopCoupon.getUseStartTime()) || now.isAfter(tbShopCoupon.getUseEndTime())) {
isUse = false;
}
useRestrictions.append(
STR."\{tbShopCoupon.getUseStartTime().format(formatter)}-\{tbShopCoupon.getUseEndTime().format(formatter)}");
} else {
useRestrictions.append("全时段");
}
useRestrictions.append(" 可用");
json.put("isUse", isUse);
json.put("useRestrictions", useRestrictions);
coupons.put(tbUserCouponVo.getCouponId(), json);
}
}
//package com.czg.service.account.service.impl;
//
//import cn.hutool.core.bean.BeanUtil;
//import cn.hutool.core.collection.CollectionUtil;
//import cn.hutool.core.date.DateUtil;
//import cn.hutool.core.exceptions.ValidateException;
//import cn.hutool.core.util.StrUtil;
//import com.alibaba.fastjson2.JSONObject;
//import com.czg.account.dto.QueryReceiveDto;
//import com.czg.account.entity.ShopActivateCouponRecord;
//import com.czg.account.entity.ShopUser;
//import com.czg.account.service.ShopActivateCouponRecordService;
//import com.czg.account.service.ShopInfoService;
//import com.czg.account.service.ShopUserService;
//import com.czg.account.vo.CouponReceiveVo;
//import com.czg.account.vo.UserCouponVo;
//import com.czg.product.entity.Product;
//import com.czg.product.service.ProductService;
//import com.czg.utils.PageUtil;
//import com.github.pagehelper.PageHelper;
//import com.github.pagehelper.PageInfo;
//import com.mybatisflex.core.paginate.Page;
//import com.mybatisflex.spring.service.impl.ServiceImpl;
//import jakarta.annotation.Resource;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.dubbo.config.annotation.DubboReference;
//import org.apache.dubbo.config.annotation.DubboService;
//
//import java.math.BigDecimal;
//import java.time.LocalTime;
//import java.time.format.DateTimeFormatter;
//import java.util.*;
//import java.util.stream.Collectors;
//
///**
// * 优惠券 服务层实现。
// *
// * @author ww
// * @since 2025-02-17
// */
//@Slf4j
//@DubboService
//public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCoupon> implements ShopCouponService {
//
// @Resource
// private ShopActivateCouponRecordService couponRecordService;
// @Resource
// private ShopUserService shopUserService;
// @Resource
// private ShopInfoService shopInfoService;
// @DubboReference
// private ProductService productService;
//
// @Override
// public List<ShopCouponDTO> getList(Long shopId, Integer type, Integer status) {
// List<ShopCouponDTO> coupons = queryChain().select()
// .eq(ShopCoupon::getShopId, shopId)
// .eq(ShopCoupon::getType, type)
// .eq(ShopCoupon::getStatus, status)
// .orderBy(ShopCoupon::getCreateTime).desc()
// .listAs(ShopCouponDTO.class);
// System.out.println(coupons);
// coupons.forEach(coupon -> {
// if (coupon.getProId() != null) {
// Product product = productService.getById(coupon.getProId());
// coupon.setProName(product.getName());
// }
// });
// return coupons;
// }
//
// @Override
// public Boolean add(ShopCouponDTO couponDTO) {
// ShopCoupon shopCoupon = new ShopCoupon();
// BeanUtil.copyProperties(couponDTO, shopCoupon);
// shopCoupon.setLeftNumber(shopCoupon.getNumber());
// return save(shopCoupon);
// }
//
// @Override
// public Boolean edit(ShopCouponDTO couponDTO) {
// ShopCoupon shopCoupon = new ShopCoupon();
// BeanUtil.copyProperties(couponDTO, shopCoupon);
// if (couponDTO.getNumber() != null) {
// ShopCoupon tbShopCoupon = getById(couponDTO.getId());
// if (shopCoupon.getNumber() < tbShopCoupon.getNumber()) {
// throw new ValidateException("修改失败 发放数量不可减少");
// } else {
// shopCoupon.setLeftNumber(shopCoupon.getLeftNumber() + shopCoupon.getNumber() - tbShopCoupon.getNumber());
// }
// }
// return updateById(shopCoupon);
// }
//
// @Override
// public Page<CouponReceiveVo> queryReceive(QueryReceiveDto param) {
// Page<Object> page = PageUtil.buildPage();
// PageHelper.startPage(Math.toIntExact(page.getPageNumber()), Math.toIntExact(page.getPageSize()));
// return PageUtil.convert(new PageInfo<>(couponRecordService.queryReceive(param)));
// }
//
//
// @Override
// public Page<ShopActivateCouponRecord> find(Long userId, Long shopId, Integer status) {
// Page<Object> page = PageUtil.buildPage();
// List<Long> shopUserIds = shopUserService.queryChain()
// .eq(ShopUser::getUserId, userId)
// .eq(ShopUser::getShopId, shopId)
// .select(ShopUser::getId).listAs(Long.class);
// if (CollectionUtil.isNotEmpty(shopUserIds)) {
// PageHelper.startPage(Math.toIntExact(page.getPageNumber()), Math.toIntExact(page.getPageSize()));
// return PageUtil.convert(new PageInfo<>(couponRecordService.findByUser(shopUserIds, status)));
// }
// return new Page<>();
// }
//
// @Override
// public List<UserCouponVo> findCoupon(Long shopId, Long shopUserId, Integer type) {
// List<UserCouponVo> tbUserCouponVos = couponRecordService.queryByVipIdAndShopId(shopId, shopUserId, type);
// if (CollectionUtil.isNotEmpty(tbUserCouponVos)) {
// String week = DateUtil.dayOfWeekEnum(new Date()).toChinese("周");
// LocalTime now = LocalTime.now();
// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss");
//
// //券id 券使用描述
// Map<Long, JSONObject> coupons = new HashMap<>();
// for (UserCouponVo tbUserCouponVo : tbUserCouponVos) {
// if (!coupons.containsKey(tbUserCouponVo.getCouponId())) {
// setCouponInfo(coupons, tbUserCouponVo, null, week, now, formatter);
// }
// JSONObject couponJson = coupons.get(tbUserCouponVo.getCouponId());
// tbUserCouponVo.setUseRestrictions(couponJson.getString("useRestrictions"));
// tbUserCouponVo.setUse(couponJson.getBoolean("isUse"));
//
// }
// tbUserCouponVos.sort(Comparator.comparing(UserCouponVo::isUse).reversed());
// return tbUserCouponVos;
// }
// return null;
// }
//
// @Override
// public Boolean use(List<Long> ids, Long shopUserId, Long orderId) {
// List<ShopActivateCouponRecord> records = couponRecordService.listByIds(ids);
// if (records.isEmpty()) {
// log.error("优惠券使用失败订单Id:{}", orderId);
// return false;
// }
// // 使用流来统计 couponId 出现的次数
// Map<Long, Long> couponIdCountMap = records.stream()
// .collect(Collectors.groupingBy(ShopActivateCouponRecord::getCouponId,
// Collectors.counting()
// ));
// couponIdCountMap.forEach((couponId, count) -> {
// ShopCoupon tbShopCoupon = getById(couponId);
// tbShopCoupon.setUseNumber(tbShopCoupon.getUseNumber() + count.intValue());
// ShopCoupon coupon1 = new ShopCoupon();
// coupon1.setId(couponId);
// coupon1.setUseNumber(tbShopCoupon.getUseNumber());
// updateById(coupon1);
// });
// return couponRecordService.updateChain()
// .set(ShopActivateCouponRecord::getStatus, 1)
// .set(ShopActivateCouponRecord::getTargetId, orderId)
// .eq(ShopActivateCouponRecord::getShopUserId, shopUserId)
// .in(ShopActivateCouponRecord::getId, ids).update();
// }
//
// /**
// * 退还券
// */
// @Override
// public Boolean refund(Long orderId, Long shopUserId) {
// return couponRecordService.updateChain()
// .set(ShopActivateCouponRecord::getStatus, 0)
// .eq(ShopActivateCouponRecord::getShopUserId, shopUserId)
// .eq(ShopActivateCouponRecord::getTargetId, orderId)
// .update();
// }
//
// private void setCouponInfo(Map<Long, JSONObject> coupons, UserCouponVo tbUserCouponVo, BigDecimal amount, String week, LocalTime now, DateTimeFormatter formatter) {
// JSONObject json = new JSONObject();
// boolean isUse = true;
// ShopCoupon tbShopCoupon = getById(tbUserCouponVo.getCouponId());
// StringBuilder useRestrictions = new StringBuilder("每天 ");
// if (amount != null && tbShopCoupon.getType().equals(1)) {
// if (amount.compareTo(tbShopCoupon.getFullAmount()) < 0) {
// isUse = false;
// }
// }
// if (StrUtil.isNotBlank(tbShopCoupon.getUserDays())) {
// String[] split = tbShopCoupon.getUserDays().split(",");
// if (split.length != 7) {
// useRestrictions = new StringBuilder(STR."\{tbShopCoupon.getUserDays()} ");
// }
// if (!tbShopCoupon.getUserDays().contains(week)) {
// isUse = false;
// }
// }
// if ("custom".equals(tbShopCoupon.getUseTimeType())) {
// if (now.isBefore(tbShopCoupon.getUseStartTime()) || now.isAfter(tbShopCoupon.getUseEndTime())) {
// isUse = false;
// }
// useRestrictions.append(
// STR."\{tbShopCoupon.getUseStartTime().format(formatter)}-\{tbShopCoupon.getUseEndTime().format(formatter)}");
// } else {
// useRestrictions.append("全时段");
// }
// useRestrictions.append(" 可用");
// json.put("isUse", isUse);
// json.put("useRestrictions", useRestrictions);
//
// coupons.put(tbUserCouponVo.getCouponId(), json);
// }
//
//}

View File

@@ -1,92 +0,0 @@
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

@@ -1,7 +0,0 @@
<?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.account.mapper.ShopCouponMapper">
</mapper>

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.czg</groupId>
<artifactId>cash-service</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>market-service</artifactId>
<name>market-service</name>
<dependencies>
</dependencies>
</project>