|
|
@@ -1,15 +1,23 @@
|
|
|
package com.cyksj.service.cps.impl;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.lang.Validator;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.cyksj.common.constant.Constant;
|
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
+import com.cyksj.common.util.Jsons;
|
|
|
import com.cyksj.common.util.SmsUtil;
|
|
|
import com.cyksj.common.util.StringUtil;
|
|
|
+import com.cyksj.mapper.manage.coupon.CouponDistributePopularizeMapper;
|
|
|
+import com.cyksj.mapper.manage.coupon.CouponMapper;
|
|
|
import com.cyksj.mapper.manage.distribute.DistributeWaitingSendPointsMapper;
|
|
|
import com.cyksj.mapper.manage.distribute.UserDistributeMapper;
|
|
|
-import com.cyksj.model.entity.User;
|
|
|
+import com.cyksj.mapper.sys.SysConfigMapper;
|
|
|
+import com.cyksj.model.entity.*;
|
|
|
import com.cyksj.model.views.BrokenLineCpsUserWMoneyView;
|
|
|
import com.cyksj.model.views.CpsUserWMoneyStatisticsDataView;
|
|
|
import com.cyksj.redis.RedisService;
|
|
|
@@ -18,6 +26,7 @@ import com.cyksj.service.mail.MailService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
@@ -40,6 +49,12 @@ public class CpsManageServiceImpl implements CpsManageService {
|
|
|
|
|
|
private final UserDistributeMapper userDistributeMapper;
|
|
|
|
|
|
+ private final SysConfigMapper sysConfigMapper;
|
|
|
+
|
|
|
+ private final CouponMapper couponMapper;
|
|
|
+
|
|
|
+ private final CouponDistributePopularizeMapper couponDistributePopularizeMapper;
|
|
|
+
|
|
|
@Override
|
|
|
public void getLoginCode(Integer type, String login, Integer cid) {
|
|
|
if (type > 2) {
|
|
|
@@ -125,6 +140,76 @@ public class CpsManageServiceImpl implements CpsManageService {
|
|
|
return waitingSendPointsMapper.getWMoneyStatisticsDate(cpsUserId, first, end, today);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Throwable.class)
|
|
|
+ public void setCouponCode(long cpsUserId, List<CouponDistributePopularize> couponRelates) throws Exception {
|
|
|
+ SysConfig sysConfig = sysConfigMapper.selectOne(Wrappers.lambdaQuery(SysConfig.class).eq(SysConfig::getSysKey, Constant.COUPON_DISTRIBUTE_RELATE_COUPON_KEY)
|
|
|
+ .last("limit 1"));
|
|
|
+ List<Long> show_coupon_ids = null;
|
|
|
+ if (sysConfig != null && StrUtil.isNotBlank(sysConfig.getSysValue())) {
|
|
|
+ show_coupon_ids = Jsons.parseList(sysConfig.getSysValue(), Long.class);
|
|
|
+ }
|
|
|
+ if (CollUtil.isEmpty(show_coupon_ids)) {
|
|
|
+ throw BusinessRuntimeException.getInstance("设置优惠码异常");
|
|
|
+ }
|
|
|
+ UserDistribute userDistribute = userDistributeMapper.selectOne(Wrappers.lambdaQuery(UserDistribute.class)
|
|
|
+ .eq(UserDistribute::getUserId, cpsUserId)
|
|
|
+ .eq(UserDistribute::getDeleted, true)
|
|
|
+ .last("limit 1"));
|
|
|
+ //处理优惠券关联
|
|
|
+ handlerDistributeCouponRelate(userDistribute.getId(), userDistribute.getUserId(), couponRelates,show_coupon_ids);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void handlerDistributeCouponRelate(Long distributeId, Long userId, List<CouponDistributePopularize> couponRelates, List<Long> show_coupon_ids) {
|
|
|
+ couponRelates.forEach(data -> {
|
|
|
+ data.setDistributeId(distributeId);
|
|
|
+ if (data.getCouponId() == null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("存在错误的优惠券,请刷新页面重试");
|
|
|
+ }
|
|
|
+ if (!show_coupon_ids.contains(data.getCouponId())) {
|
|
|
+ throw BusinessRuntimeException.getInstance("存在错误的优惠券,请刷新页面重试");
|
|
|
+ }
|
|
|
+ Integer exists = couponMapper.selectCount(Wrappers.lambdaQuery(Coupon.class).eq(Coupon::getId, data.getCouponId()).eq(Coupon::getDeleted, 1));
|
|
|
+ if (exists == 0) {
|
|
|
+ throw BusinessRuntimeException.getInstance("存在错误的优惠券,请刷新页面重试");
|
|
|
+ }
|
|
|
+ String exCode = data.getExCode();
|
|
|
+ if (StrUtil.isEmpty(exCode)) {
|
|
|
+ throw BusinessRuntimeException.getInstance("优惠码为空");
|
|
|
+ }
|
|
|
+ List<CouponDistributePopularize> popularizeList = couponDistributePopularizeMapper.selectList(Wrappers.lambdaQuery(CouponDistributePopularize.class)
|
|
|
+ .eq(CouponDistributePopularize::getDeleted, 1)
|
|
|
+ .eq(CouponDistributePopularize::getExCode, exCode));
|
|
|
+ //个人渠道
|
|
|
+ for (CouponDistributePopularize couponDistributePopularize : popularizeList) {
|
|
|
+ Long disId = couponDistributePopularize.getDistributeId();
|
|
|
+ if (disId != null && !ObjectUtil.equal(disId, distributeId)) {
|
|
|
+ throw BusinessRuntimeException.getInstance("优惠码:{0}已存在", exCode);
|
|
|
+ }
|
|
|
+ Long uid = couponDistributePopularize.getUserId();
|
|
|
+ if (uid != null && !ObjectUtil.equal(uid, userId)) {
|
|
|
+ throw BusinessRuntimeException.getInstance("优惠码:{0}已存在", exCode);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Integer count = couponMapper.selectCount(Wrappers.lambdaQuery(Coupon.class).eq(Coupon::getExCode, exCode).eq(Coupon::getDeleted, true));
|
|
|
+ if (count > 0) {
|
|
|
+ throw BusinessRuntimeException.getInstance("优惠码:{0}已存在", exCode);
|
|
|
+ }
|
|
|
+ if (data.getId() != null) {
|
|
|
+// couponDistributePopularizeMapper.updateById(data);
|
|
|
+ } else {
|
|
|
+ Long couponId = data.getCouponId();
|
|
|
+ Integer selectCount = couponDistributePopularizeMapper.selectCount(Wrappers.lambdaQuery(CouponDistributePopularize.class)
|
|
|
+ .eq(CouponDistributePopularize::getDistributeId, distributeId)
|
|
|
+ .eq(CouponDistributePopularize::getCouponId, couponId)
|
|
|
+ .eq(CouponDistributePopularize::getDeleted, true));
|
|
|
+ if (selectCount == 0) {
|
|
|
+ couponDistributePopularizeMapper.insert(data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
public boolean isToday(DateTime first, DateTime end) {
|
|
|
boolean today = false;
|
|
|
if (first != null && end != null) {
|