|
@@ -4,13 +4,20 @@ import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
import com.cyksj.common.util.Jsons;
|
|
import com.cyksj.common.util.Jsons;
|
|
|
|
|
+import com.cyksj.config.corp.YHLXWxCorpConfig;
|
|
|
import com.cyksj.mapper.GoodsDonSkuMapper;
|
|
import com.cyksj.mapper.GoodsDonSkuMapper;
|
|
|
|
|
+import com.cyksj.mapper.UserMapper;
|
|
|
|
|
+import com.cyksj.mapper.corp.CorpUserMapper;
|
|
|
import com.cyksj.mapper.manage.coupon.*;
|
|
import com.cyksj.mapper.manage.coupon.*;
|
|
|
import com.cyksj.model.entity.*;
|
|
import com.cyksj.model.entity.*;
|
|
|
|
|
+import com.cyksj.model.request.CorpCouponSendReq;
|
|
|
import com.cyksj.model.request.CouponActiveReq;
|
|
import com.cyksj.model.request.CouponActiveReq;
|
|
|
import com.cyksj.model.request.CouponDistributeReq;
|
|
import com.cyksj.model.request.CouponDistributeReq;
|
|
|
|
|
+import com.cyksj.service.corp.msg.CorpEventActionService;
|
|
|
import com.cyksj.service.mange.coupon.CouponCommonService;
|
|
import com.cyksj.service.mange.coupon.CouponCommonService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.springframework.dao.DuplicateKeyException;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
@@ -26,6 +33,7 @@ import java.util.stream.Collectors;
|
|
|
*/
|
|
*/
|
|
|
@Service
|
|
@Service
|
|
|
@RequiredArgsConstructor
|
|
@RequiredArgsConstructor
|
|
|
|
|
+@Slf4j
|
|
|
public class CouponCommonServiceImpl implements CouponCommonService {
|
|
public class CouponCommonServiceImpl implements CouponCommonService {
|
|
|
private final GoodsDonSkuMapper goodsDonSkuMapper;
|
|
private final GoodsDonSkuMapper goodsDonSkuMapper;
|
|
|
|
|
|
|
@@ -39,6 +47,16 @@ public class CouponCommonServiceImpl implements CouponCommonService {
|
|
|
|
|
|
|
|
private final CouponSkuMapper couponSkuMapper;
|
|
private final CouponSkuMapper couponSkuMapper;
|
|
|
|
|
|
|
|
|
|
+ private final CorpUserMapper corpUserMapper;
|
|
|
|
|
+
|
|
|
|
|
+ private final CorpEventActionService corpEventActionService;
|
|
|
|
|
+
|
|
|
|
|
+ private final YHLXWxCorpConfig yhlXWxCorpConfig;
|
|
|
|
|
+
|
|
|
|
|
+ private final UserMapper userMapper;
|
|
|
|
|
+
|
|
|
|
|
+ private final CouponUserMapper couponUserMapper;
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional(rollbackFor = Throwable.class)
|
|
@Transactional(rollbackFor = Throwable.class)
|
|
|
public void saveCoupon(Coupon coupon) throws Exception {
|
|
public void saveCoupon(Coupon coupon) throws Exception {
|
|
@@ -134,6 +152,46 @@ public class CouponCommonServiceImpl implements CouponCommonService {
|
|
|
couponDistributePopularizeMapper.updateById(entity);
|
|
couponDistributePopularizeMapper.updateById(entity);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void corpSendCoupon(CorpCouponSendReq corpCouponSendReq) throws Exception {
|
|
|
|
|
+ String externalUserId = corpCouponSendReq.getExternalUserId();
|
|
|
|
|
+ CorpUser corpUser = corpUserMapper.selectOne(Wrappers.lambdaQuery(CorpUser.class).eq(CorpUser::getExternalUserid, externalUserId).last("limit 1"));
|
|
|
|
|
+ if (corpUser == null) {
|
|
|
|
|
+ //尝试添加客户
|
|
|
|
|
+ corpEventActionService.addExternalContact(yhlXWxCorpConfig.getCorpId(), null, externalUserId, null, null);
|
|
|
|
|
+ corpUser = corpUserMapper.selectOne(Wrappers.lambdaQuery(CorpUser.class).eq(CorpUser::getExternalUserid, externalUserId).last("limit 1"));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (corpUser == null) {
|
|
|
|
|
+ log.info("该客户{}不存在", externalUserId);
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("该企业微信用户不存在..");
|
|
|
|
|
+ }
|
|
|
|
|
+ String unionid = corpUser.getUnionid();
|
|
|
|
|
+ if (StrUtil.isEmpty(unionid)) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("该用户不是微信用户");
|
|
|
|
|
+ }
|
|
|
|
|
+ User user = userMapper.selectOne(Wrappers.lambdaQuery(User.class).eq(User::getUnionid, unionid).select(User::getId).last("limit 1"));
|
|
|
|
|
+ if (user == null) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("该用户未在银河录像注册");
|
|
|
|
|
+ }
|
|
|
|
|
+ Long couponId = corpCouponSendReq.getCouponId();
|
|
|
|
|
+ Coupon coupon = couponMapper.selectById(couponId);
|
|
|
|
|
+ if (coupon == null || !coupon.getDeleted()) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("该优惠卷已被删除");
|
|
|
|
|
+ }
|
|
|
|
|
+ CouponUser couponUser = new CouponUser();
|
|
|
|
|
+ couponUser.setUserId(user.getId());
|
|
|
|
|
+ couponUser.setCouponId(corpCouponSendReq.getCouponId());
|
|
|
|
|
+ //领卷中心
|
|
|
|
|
+ couponUser.setChannel(CouponUser.Channel.wxCorp);
|
|
|
|
|
+ couponUser.setStatus(CouponUser.Status.unused);
|
|
|
|
|
+ try {
|
|
|
|
|
+ couponUserMapper.insert(couponUser);
|
|
|
|
|
+ } catch (DuplicateKeyException e) {
|
|
|
|
|
+ log.info("用户:{}重复领取优惠卷{}插入数据错误", user.getId(), corpCouponSendReq.getCouponId());
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("已发放该优惠卷");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
public void checkCouponParamsAndSaveOrUpdate(Coupon coupon) throws Exception {
|
|
public void checkCouponParamsAndSaveOrUpdate(Coupon coupon) throws Exception {
|
|
|
List<Coupon.CouponGoodsSku> goodsSkuList = null;
|
|
List<Coupon.CouponGoodsSku> goodsSkuList = null;
|