|
@@ -1,29 +1,36 @@
|
|
|
package com.caimei365.commodity.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.caimei365.commodity.components.PriceUtilService;
|
|
|
-import com.caimei365.commodity.mapper.CouponMapper;
|
|
|
-import com.caimei365.commodity.mapper.PageMapper;
|
|
|
-import com.caimei365.commodity.mapper.PriceMapper;
|
|
|
-import com.caimei365.commodity.mapper.ShopMapper;
|
|
|
+import com.caimei365.commodity.feign.ToolsFeign;
|
|
|
+import com.caimei365.commodity.mapper.*;
|
|
|
import com.caimei365.commodity.model.ResponseJson;
|
|
|
import com.caimei365.commodity.model.dto.CollarCouponsDto;
|
|
|
import com.caimei365.commodity.model.dto.RedeemCouponsDto;
|
|
|
import com.caimei365.commodity.model.po.CouponClubPo;
|
|
|
import com.caimei365.commodity.model.po.CouponRedemptionCodePo;
|
|
|
-import com.caimei365.commodity.model.vo.ActivityCouponVo;
|
|
|
-import com.caimei365.commodity.model.vo.CouponVo;
|
|
|
-import com.caimei365.commodity.model.vo.ProductItemVo;
|
|
|
-import com.caimei365.commodity.model.vo.ShopVo;
|
|
|
+import com.caimei365.commodity.model.vo.*;
|
|
|
import com.caimei365.commodity.service.CouponService;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
+import lombok.SneakyThrows;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.Executors;
|
|
|
+import java.util.concurrent.ScheduledExecutorService;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
|
|
/**
|
|
|
* Description
|
|
@@ -33,6 +40,10 @@ import java.util.*;
|
|
|
*/
|
|
|
@Service
|
|
|
public class CouponServiceImpl implements CouponService {
|
|
|
+ @Value("${spring.cloud.config.profile}")
|
|
|
+ private String profile;
|
|
|
+ @Resource
|
|
|
+ private ToolsFeign toolsFeign;
|
|
|
@Resource
|
|
|
private CouponMapper couponMapper;
|
|
|
@Resource
|
|
@@ -43,6 +54,8 @@ public class CouponServiceImpl implements CouponService {
|
|
|
private PriceMapper priceMapper;
|
|
|
@Resource
|
|
|
private PriceUtilService priceUtilService;
|
|
|
+ @Resource
|
|
|
+ private MessageCenterMapper messageCenterMapper;
|
|
|
|
|
|
/**
|
|
|
* 已领取优惠券中心
|
|
@@ -131,7 +144,7 @@ public class CouponServiceImpl implements CouponService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public ResponseJson<String> collarCoupons(CollarCouponsDto couponsDto) {
|
|
|
+ public ResponseJson<String> collarCoupons(CollarCouponsDto couponsDto) throws ParseException {
|
|
|
Integer id = couponMapper.findCouponClubByUserId(couponsDto.getUserId(), couponsDto.getCouponId());
|
|
|
if (id != null && id > 0) {
|
|
|
return ResponseJson.error("已经领取过了", null);
|
|
@@ -153,6 +166,13 @@ public class CouponServiceImpl implements CouponService {
|
|
|
return ResponseJson.success("领取成功");
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public ResponseJson<CouponVo> redeemCoupons(RedeemCouponsDto redeemCouponsDto) {
|
|
@@ -222,7 +242,7 @@ public class CouponServiceImpl implements CouponService {
|
|
|
//未领取
|
|
|
List<CouponVo> notCouponList = couponMapper.findCouponList(userId, registerTime);
|
|
|
filterCoupon(source, product, notCouponList);
|
|
|
- notCouponList.forEach(n->n.setCouponBtnType(0));
|
|
|
+ notCouponList.forEach(n -> n.setCouponBtnType(0));
|
|
|
//超级会员优惠券移除
|
|
|
if (notCouponList != null && notCouponList.size() > 0) {
|
|
|
notCouponList.removeIf(couponVo -> vipCoupon.contains(couponVo.getCouponId()));
|
|
@@ -230,7 +250,7 @@ public class CouponServiceImpl implements CouponService {
|
|
|
map.put("notCouponNum", notCouponList == null ? 0 : notCouponList.size());
|
|
|
//已领取
|
|
|
List<CouponVo> couponList = couponMapper.findCouponClub(userId, 1);
|
|
|
- couponList.forEach(c->c.setCouponBtnType(1));
|
|
|
+ couponList.forEach(c -> c.setCouponBtnType(1));
|
|
|
//超级会员优惠券移除
|
|
|
if (couponList != null && couponList.size() > 0) {
|
|
|
couponList.removeIf(couponVo -> vipCoupon.contains(couponVo.getCouponId()));
|
|
@@ -258,32 +278,33 @@ public class CouponServiceImpl implements CouponService {
|
|
|
|
|
|
/**
|
|
|
* 用户可查看的价值优惠券
|
|
|
+ *
|
|
|
* @param userId
|
|
|
* @param pageNum
|
|
|
* @param pageSize
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public ResponseJson<PageInfo<CouponVo>> findMoneyCoupons(Integer userId,int pageNum, int pageSize) {
|
|
|
+ public ResponseJson<PageInfo<CouponVo>> findMoneyCoupons(Integer userId, int pageNum, int pageSize) {
|
|
|
Date registerTime = couponMapper.findUserRegisterTime(userId);
|
|
|
PageHelper.startPage(pageNum, pageSize);
|
|
|
- List<CouponVo> cop = couponMapper.findMoneyCoupons(userId,registerTime);
|
|
|
+ List<CouponVo> cop = couponMapper.findMoneyCoupons(userId, registerTime);
|
|
|
PageInfo<CouponVo> pageInfo = new PageInfo<>(cop);
|
|
|
return ResponseJson.success(pageInfo);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public ResponseJson<CouponVo> findCouponDetail(Integer couponId) {
|
|
|
- CouponVo couponVo=couponMapper.findCouponDetail(couponId);
|
|
|
+ CouponVo couponVo = couponMapper.findCouponDetail(couponId);
|
|
|
return ResponseJson.success(couponVo);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public ResponseJson<PageInfo<CouponVo>> collarCenterList(Integer userId, int pageNum, int pageSize) {
|
|
|
Date registerTime = couponMapper.findUserRegisterTime(userId);
|
|
|
- Integer permission=couponMapper.findUserPermission(userId);
|
|
|
+ Integer permission = couponMapper.findUserPermission(userId);
|
|
|
//如果是协销,userid置为0查所有
|
|
|
- if(1==permission){
|
|
|
+ if (1 == permission) {
|
|
|
userId = 0;
|
|
|
}
|
|
|
PageHelper.startPage(pageNum, pageSize);
|
|
@@ -325,4 +346,44 @@ public class CouponServiceImpl implements CouponService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 请求发短信接口
|
|
|
+ *
|
|
|
+ * @param markId 跳转类型
|
|
|
+ * @param mobile 手机号
|
|
|
+ * @param content 内容
|
|
|
+ */
|
|
|
+ public boolean getSendSms(int markId, String mobile, String content) {
|
|
|
+ AtomicBoolean returnValue = new AtomicBoolean(false);
|
|
|
+ try {
|
|
|
+ //测试环境手机号允许发短信
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
+ list.add("15917362709");
|
|
|
+ list.add("15814011616");
|
|
|
+ list.add("13100721916");
|
|
|
+ list.add("15113936829");
|
|
|
+ list.add("18175515644");
|
|
|
+ list.add("18476937515");
|
|
|
+ if ("prod".equals(profile) || list.contains(mobile)) {
|
|
|
+ if (StringUtils.isNotBlank(mobile) && mobile.length() == 11) {
|
|
|
+ String regex = "^(1[3-9]\\d{9}$)";
|
|
|
+ Pattern pattern = Pattern.compile(regex);
|
|
|
+ Matcher matcher = pattern.matcher(mobile);
|
|
|
+ if (matcher.matches()) {
|
|
|
+ // 调用 ToolsFeign 发送短信
|
|
|
+ String jsonStr = toolsFeign.getSendSms(mobile, content);
|
|
|
+ JSONObject parseObject = JSONObject.parseObject(jsonStr);
|
|
|
+ if (0 == parseObject.getInteger("code")){
|
|
|
+ returnValue.set(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ }
|
|
|
+ return returnValue.get();
|
|
|
+ }
|
|
|
+
|
|
|
}
|