Commit 56eade07 by 吕明尚

Merge branch 'dev' into test

parents 6b86b2dd 5bbff7b3
...@@ -176,6 +176,7 @@ ...@@ -176,6 +176,7 @@
<artifactId>xstream</artifactId> <artifactId>xstream</artifactId>
<version>1.4.9</version> <version>1.4.9</version>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>
\ No newline at end of file
package share.common.utils;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Objects;
/**
* @ClassName RedisLockUtil
* @Description 使用redis做锁
* @Author Wangyujie
* @Version V1.1.0
*/
@Component
public class RedisLockUtil {
@Resource
RedisTemplate<String, Object> redisTemplate;
/**
* 获取锁Key
*
* @param prefix 前缀
* @param name 名称
* @return
*/
public static String getFullKey(String prefix, String name) {
return prefix + "_" + name;
}
/**
* 获取锁,true 则得到锁,false 已被锁定
*
* @param lockName 锁名称
* @param lockExoire 锁时间毫秒
* @return
*/
public Boolean getLock(String lockName, Integer lockExoire) {
return (Boolean) redisTemplate.execute((RedisCallback<?>) connection -> {
// 获取时间毫秒值
long expireAt = System.currentTimeMillis() + lockExoire + 1;
// 获取锁
Boolean acquire = connection.setNX(lockName.getBytes(), String.valueOf(expireAt).getBytes());
if (acquire) {
return true;
} else {
byte[] bytes = connection.get(lockName.getBytes());
// 非空判断
if (Objects.nonNull(bytes) && bytes.length > 0) {
long expireTime = Long.parseLong(new String(bytes));
// 如果锁已经过期
if (expireTime < System.currentTimeMillis()) {
// 重新加锁,防止死锁
byte[] set = connection.getSet(lockName.getBytes(),
String.valueOf(System.currentTimeMillis() + lockExoire + 1).getBytes());
return Long.parseLong(new String(set)) < System.currentTimeMillis();
}
}
}
return false;
});
}
/**
* 删除锁
*
* @param lockName
*/
public void delLock(String lockName) {
redisTemplate.delete(lockName);
}
}
...@@ -32,6 +32,7 @@ import share.common.core.redis.RedisUtil; ...@@ -32,6 +32,7 @@ import share.common.core.redis.RedisUtil;
import share.common.enums.*; import share.common.enums.*;
import share.common.exception.base.BaseException; import share.common.exception.base.BaseException;
import share.common.utils.DateUtils; import share.common.utils.DateUtils;
import share.common.utils.RedisLockUtil;
import share.system.domain.SConsumer; import share.system.domain.SConsumer;
import share.system.domain.SConsumerCoupon; import share.system.domain.SConsumerCoupon;
import share.system.domain.SCoupon; import share.system.domain.SCoupon;
...@@ -77,6 +78,9 @@ public class QPServiceImpl implements QPService { ...@@ -77,6 +78,9 @@ public class QPServiceImpl implements QPService {
private RedisUtil redisUtil; private RedisUtil redisUtil;
@Autowired @Autowired
private RedisLockUtil redisLockUtil;
@Autowired
private ISStoreService storeService; private ISStoreService storeService;
//默认门槛时长 //默认门槛时长
...@@ -106,108 +110,112 @@ public class QPServiceImpl implements QPService { ...@@ -106,108 +110,112 @@ public class QPServiceImpl implements QPService {
if (ObjectUtil.isNull(user)) { if (ObjectUtil.isNull(user)) {
throw new BaseException("您的登录已过期,请先登录"); throw new BaseException("您的登录已过期,请先登录");
} }
LambdaQueryWrapper<SStore> sStoreLambdaQueryWrapper = new LambdaQueryWrapper<>(); Boolean lock = redisLockUtil.getLock(String.valueOf(user.getId()), 1000);
sStoreLambdaQueryWrapper.eq(SStore::getId, storeId); if (lock) {
SStore sStore = storeService.getOne(sStoreLambdaQueryWrapper); LambdaQueryWrapper<SStore> sStoreLambdaQueryWrapper = new LambdaQueryWrapper<>();
if (ObjectUtils.isEmpty(sStore) || StoreStatusEnum.STOP.getIndex().equals(sStore.getStatus())) { sStoreLambdaQueryWrapper.eq(SStore::getId, storeId);
throw new Exception("门店维护中,请联系客服"); SStore sStore = storeService.getOne(sStoreLambdaQueryWrapper);
} if (ObjectUtils.isEmpty(sStore) || StoreStatusEnum.STOP.getIndex().equals(sStore.getStatus())) {
if (StringUtils.isEmpty(sStore.getOpenShopUuid())) { throw new Exception("门店维护中,请联系客服");
throw new Exception("门店未授权,请联系客服");
}
//验券准备
TuangouReceiptPrepareResponseEntity prepare = prepare(code.trim(), sStore.getOpenShopUuid(), status);
//查询领取记录表
LambdaQueryWrapper<SConsumerCoupon> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SConsumerCoupon::getCouponCode, code);
queryWrapper.eq(SConsumerCoupon::getUseStatus, UserStatusEnum.UNUSED.getCode());
queryWrapper.eq(SConsumerCoupon::getIsDelete, YesNoEnum.no.getIndex());
SConsumerCoupon unUsedCoupon = isConsumerCouponService.getOne(queryWrapper);
if (ObjectUtils.isNotEmpty(unUsedCoupon)) {
throw new Exception("该券码已被使用");
}
//根据优惠卷名称查询优惠劵配置 查询list,取第一个
SConsumerCoupon sConsumerCoupon = new SConsumerCoupon();
sConsumerCoupon.setConsumerId(user.getId());
sConsumerCoupon.setDealId(prepare.getDeal_id());
sConsumerCoupon.setStoreId(sStore.getId());
sConsumerCoupon.setCouponCode(code);
sConsumerCoupon.setName(prepare.getDeal_title());
sConsumerCoupon.setSourceType(SourceTypeEnum.CHECK.getCode());
sConsumerCoupon.setPlatformType(PlatformTypeEnum.MEITUAN.getCode());
sConsumerCoupon.setUseStatus(UserStatusEnum.UNUSED.getCode());
sConsumerCoupon.setCreateBy(String.valueOf(user.getId()));
sConsumerCoupon.setCreateTime(new Date());
sConsumerCoupon.setOriginalPrice(BigDecimal.valueOf(prepare.getDeal_marketprice()));
Stream<TuangouReceiptPreparePaymentDetail> tuangouReceiptPreparePaymentDetailStream = prepare.getPayment_detail().stream().filter(o -> o.getAmount_type().equals(10L) || o.getAmount_type().equals(23L) || o.getAmount_type().equals(25L) || o.getAmount_type().equals(26L) || o.getAmount_type().equals(29L));
BigDecimal couponPayPrice = tuangouReceiptPreparePaymentDetailStream.map(o -> o.getAmount()).reduce(BigDecimal.ZERO, BigDecimal::add);
sConsumerCoupon.setCouponPayPrice(couponPayPrice);
//查询美团团购信息
List<TuangouDealQueryShopDealResponseEntity> groupActivities = queryshopdeal(sStore.getOpenShopUuid());
groupActivities.forEach(o -> {
//套餐名称相同并且在售卖中
if (prepare.getDealgroup_id().equals(o.getDealgroup_id())) {
Date receiptEndDate = DateUtil.parse(o.getReceipt_end_date(), DatePattern.NORM_DATETIME_MINUTE_PATTERN);
Date receiptBeginDate = DateUtil.parse(o.getReceipt_begin_date(), DatePattern.NORM_DATETIME_MINUTE_PATTERN);
sConsumerCoupon.setStartDate(receiptBeginDate);
sConsumerCoupon.setEndDate(receiptEndDate);
} }
}); if (StringUtils.isEmpty(sStore.getOpenShopUuid())) {
if (ObjectUtils.isEmpty(sConsumerCoupon.getStartDate())) { throw new Exception("门店未授权,请联系客服");
//获取本日的00:00:00 }
Calendar calendar = Calendar.getInstance(); //查询领取记录表
calendar.set(Calendar.HOUR_OF_DAY, 0); LambdaQueryWrapper<SConsumerCoupon> queryWrapper = new LambdaQueryWrapper<>();
calendar.set(Calendar.MINUTE, 0); queryWrapper.eq(SConsumerCoupon::getCouponCode, code);
calendar.set(Calendar.SECOND, 0); queryWrapper.eq(SConsumerCoupon::getUseStatus, UserStatusEnum.UNUSED.getCode());
calendar.set(Calendar.MILLISECOND, 0); queryWrapper.eq(SConsumerCoupon::getIsDelete, YesNoEnum.no.getIndex());
Date startOfDay = calendar.getTime(); SConsumerCoupon unUsedCoupon = isConsumerCouponService.getOne(queryWrapper);
sConsumerCoupon.setStartDate(startOfDay); if (ObjectUtils.isNotEmpty(unUsedCoupon)) {
} throw new Exception("该券码已被使用");
if (ObjectUtils.isEmpty(sConsumerCoupon.getEndDate())) { }
//当前时间加上一年 //验券准备
sConsumerCoupon.setEndDate(DateUtils.addYears(new Date(), 1)); TuangouReceiptPrepareResponseEntity prepare = prepare(code.trim(), sStore.getOpenShopUuid(), status);
} //根据优惠卷名称查询优惠劵配置 查询list,取第一个
List<SCoupon> sCoupons = isCouponService.selectSCouponByDealgroupId(prepare.getDealgroup_id()); SConsumerCoupon sConsumerCoupon = new SConsumerCoupon();
SCoupon sCoupon = null; sConsumerCoupon.setConsumerId(user.getId());
if (!CollectionUtils.isEmpty(sCoupons)) { sConsumerCoupon.setDealId(prepare.getDeal_id());
sCoupon = sCoupons.get(0); sConsumerCoupon.setStoreId(sStore.getId());
} sConsumerCoupon.setCouponCode(code);
if (ObjectUtils.isEmpty(sCoupon)) { sConsumerCoupon.setName(prepare.getDeal_title());
sConsumerCoupon.setDealgroupId(prepare.getDealgroup_id()); sConsumerCoupon.setSourceType(SourceTypeEnum.CHECK.getCode());
sConsumerCoupon.setCouponType(CouponTypeEnum.CASH.getCode()); sConsumerCoupon.setPlatformType(PlatformTypeEnum.MEITUAN.getCode());
sConsumerCoupon.setStoreType(StoreType.getCodeList()); sConsumerCoupon.setUseStatus(UserStatusEnum.UNUSED.getCode());
sConsumerCoupon.setRoomType(RoomType.getCodeList());
sConsumerCoupon.setCreateBy(String.valueOf(user.getId())); sConsumerCoupon.setCreateBy(String.valueOf(user.getId()));
sConsumerCoupon.setMinDuration(DEFAULT_MIN_DURATION); sConsumerCoupon.setCreateTime(new Date());
sConsumerCoupon.setMaxDuration(DEFAULT_MAX_DURATION); sConsumerCoupon.setOriginalPrice(BigDecimal.valueOf(prepare.getDeal_marketprice()));
sConsumerCoupon.setDuration(DEFAULT_DURATION); Stream<TuangouReceiptPreparePaymentDetail> tuangouReceiptPreparePaymentDetailStream = prepare.getPayment_detail().stream().filter(o -> o.getAmount_type().equals(10L) || o.getAmount_type().equals(23L) || o.getAmount_type().equals(25L) || o.getAmount_type().equals(26L) || o.getAmount_type().equals(29L));
sConsumerCoupon.setMinPrice(DEFAULT_MIN_PRICE); BigDecimal couponPayPrice = tuangouReceiptPreparePaymentDetailStream.map(o -> o.getAmount()).reduce(BigDecimal.ZERO, BigDecimal::add);
sConsumerCoupon.setCouponTimeStart(DEFAULT_START_TIME); sConsumerCoupon.setCouponPayPrice(couponPayPrice);
sConsumerCoupon.setCouponTimeEnd(DEFAULT_END_TIME); //查询美团团购信息
sConsumerCoupon.setSalePrice(sConsumerCoupon.getCouponPayPrice()); List<TuangouDealQueryShopDealResponseEntity> groupActivities = queryshopdeal(sStore.getOpenShopUuid());
} else { groupActivities.forEach(o -> {
sConsumerCoupon.setCouponId(sCoupon.getId()); //套餐名称相同并且在售卖中
sConsumerCoupon.setCouponType(sCoupon.getCouponType()); if (prepare.getDealgroup_id().equals(o.getDealgroup_id())) {
sConsumerCoupon.setStoreType(sCoupon.getStoreType()); Date receiptEndDate = DateUtil.parse(o.getReceipt_end_date(), DatePattern.NORM_DATETIME_MINUTE_PATTERN);
sConsumerCoupon.setRoomType(sCoupon.getRoomType()); Date receiptBeginDate = DateUtil.parse(o.getReceipt_begin_date(), DatePattern.NORM_DATETIME_MINUTE_PATTERN);
sConsumerCoupon.setMinDuration(sCoupon.getMinDuration()); sConsumerCoupon.setStartDate(receiptBeginDate);
sConsumerCoupon.setMaxDuration(sCoupon.getMaxDuration()); sConsumerCoupon.setEndDate(receiptEndDate);
sConsumerCoupon.setDuration(sCoupon.getDuration()); }
sConsumerCoupon.setMinPrice(sCoupon.getMinPrice()); });
sConsumerCoupon.setCouponTimeStart(sCoupon.getValidStartTime()); if (ObjectUtils.isEmpty(sConsumerCoupon.getStartDate())) {
sConsumerCoupon.setCouponTimeEnd(sCoupon.getValidEndTime()); //获取本日的00:00:00
sConsumerCoupon.setOrderType(sCoupon.getOrderType()); Calendar calendar = Calendar.getInstance();
sConsumerCoupon.setDealgroupId(sCoupon.getDealgroupId()); calendar.set(Calendar.HOUR_OF_DAY, 0);
sConsumerCoupon.setStoreIds(sCoupon.getStoreIds()); calendar.set(Calendar.MINUTE, 0);
sConsumerCoupon.setPackIds(sCoupon.getPackIds()); calendar.set(Calendar.SECOND, 0);
sConsumerCoupon.setWeeks(sCoupon.getWeeks()); calendar.set(Calendar.MILLISECOND, 0);
sConsumerCoupon.setRemark(sCoupon.getRemark()); Date startOfDay = calendar.getTime();
sConsumerCoupon.setSalePrice(sCoupon.getSalePrice()); sConsumerCoupon.setStartDate(startOfDay);
}
if (ObjectUtils.isEmpty(sConsumerCoupon.getEndDate())) {
//当前时间加上一年
sConsumerCoupon.setEndDate(DateUtils.addYears(new Date(), 1));
}
List<SCoupon> sCoupons = isCouponService.selectSCouponByDealgroupId(prepare.getDealgroup_id());
SCoupon sCoupon = null;
if (!CollectionUtils.isEmpty(sCoupons)) {
sCoupon = sCoupons.get(0);
}
if (ObjectUtils.isEmpty(sCoupon)) {
sConsumerCoupon.setDealgroupId(prepare.getDealgroup_id());
sConsumerCoupon.setCouponType(CouponTypeEnum.CASH.getCode());
sConsumerCoupon.setStoreType(StoreType.getCodeList());
sConsumerCoupon.setRoomType(RoomType.getCodeList());
sConsumerCoupon.setCreateBy(String.valueOf(user.getId()));
sConsumerCoupon.setMinDuration(DEFAULT_MIN_DURATION);
sConsumerCoupon.setMaxDuration(DEFAULT_MAX_DURATION);
sConsumerCoupon.setDuration(DEFAULT_DURATION);
sConsumerCoupon.setMinPrice(DEFAULT_MIN_PRICE);
sConsumerCoupon.setCouponTimeStart(DEFAULT_START_TIME);
sConsumerCoupon.setCouponTimeEnd(DEFAULT_END_TIME);
sConsumerCoupon.setSalePrice(sConsumerCoupon.getCouponPayPrice());
} else {
sConsumerCoupon.setCouponId(sCoupon.getId());
sConsumerCoupon.setCouponType(sCoupon.getCouponType());
sConsumerCoupon.setStoreType(sCoupon.getStoreType());
sConsumerCoupon.setRoomType(sCoupon.getRoomType());
sConsumerCoupon.setMinDuration(sCoupon.getMinDuration());
sConsumerCoupon.setMaxDuration(sCoupon.getMaxDuration());
sConsumerCoupon.setDuration(sCoupon.getDuration());
sConsumerCoupon.setMinPrice(sCoupon.getMinPrice());
sConsumerCoupon.setCouponTimeStart(sCoupon.getValidStartTime());
sConsumerCoupon.setCouponTimeEnd(sCoupon.getValidEndTime());
sConsumerCoupon.setOrderType(sCoupon.getOrderType());
sConsumerCoupon.setDealgroupId(sCoupon.getDealgroupId());
sConsumerCoupon.setStoreIds(sCoupon.getStoreIds());
sConsumerCoupon.setPackIds(sCoupon.getPackIds());
sConsumerCoupon.setWeeks(sCoupon.getWeeks());
sConsumerCoupon.setRemark(sCoupon.getRemark());
sConsumerCoupon.setSalePrice(sCoupon.getSalePrice());
}
isConsumerCouponService.insertSConsumerCoupon(sConsumerCoupon);
//核销美团券
qpService.consume(code.trim(), 1, sStore.getOpenShopUuid(), status);
return "验劵成功";
} }
isConsumerCouponService.insertSConsumerCoupon(sConsumerCoupon); throw new RuntimeException("验劵失败");
//核销美团券
qpService.consume(code.trim(), 1, sStore.getOpenShopUuid(), status);
return "验劵成功";
} }
@Override @Override
......
...@@ -2304,12 +2304,11 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -2304,12 +2304,11 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
// } // }
// 是否满足退款 // 是否满足退款
boolean isRefunds; boolean isRefunds;
SConsumerCoupon coupon = null;
if (ObjectUtil.isNotNull(sOrder.getCouponId())) { if (ObjectUtil.isNotNull(sOrder.getCouponId())) {
SConsumerCoupon coupon = consumerCouponService.getById(sOrder.getCouponId()); coupon = consumerCouponService.getById(sOrder.getCouponId());
// 判断是否可以退款 // 判断是否可以退款
isRefunds = isRefund(sOrder, coupon); isRefunds = isRefund(sOrder, coupon);
coupon.setUseStatus(UserStatusEnum.UNUSED.getCode());
consumerCouponService.updateById(coupon);
} else { } else {
// 判断是否可以退款 // 判断是否可以退款
isRefunds = isRefund(sOrder, null); isRefunds = isRefund(sOrder, null);
...@@ -2375,8 +2374,13 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -2375,8 +2374,13 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
//微信退款 //微信退款
// if (sOrder.getPayType().equals(PayTypeEnum.WECHAT.getCode()) && request.getAmount().compareTo(BigDecimal.ZERO) == 0) { // if (sOrder.getPayType().equals(PayTypeEnum.WECHAT.getCode()) && request.getAmount().compareTo(BigDecimal.ZERO) == 0) {
// 退款task, 定时任务退优惠券 // 退款task, 定时任务退优惠券
redisUtil.lPush(Constants.ORDER_TASK_REDIS_KEY_AFTER_REFUND_BY_USER, sOrder.getId()); // redisUtil.lPush(Constants.ORDER_TASK_REDIS_KEY_AFTER_REFUND_BY_USER, sOrder.getId());
// } // }
// 退优惠券
if (coupon != null) {
coupon.setUseStatus(UserStatusEnum.UNUSED.getCode());
consumerCouponService.updateById(coupon);
}
execute = Boolean.TRUE; execute = Boolean.TRUE;
} catch (Exception e) { } catch (Exception e) {
logger.error(e.toString()); logger.error(e.toString());
......
...@@ -20,6 +20,7 @@ import org.springframework.util.CollectionUtils; ...@@ -20,6 +20,7 @@ import org.springframework.util.CollectionUtils;
import share.common.core.redis.RedisUtil; import share.common.core.redis.RedisUtil;
import share.common.enums.*; import share.common.enums.*;
import share.common.exception.base.BaseException; import share.common.exception.base.BaseException;
import share.common.utils.RedisLockUtil;
import share.system.domain.SConsumer; import share.system.domain.SConsumer;
import share.system.domain.SConsumerCoupon; import share.system.domain.SConsumerCoupon;
import share.system.domain.SCoupon; import share.system.domain.SCoupon;
...@@ -54,6 +55,9 @@ public class TiktokServiceImpl implements TiktokService { ...@@ -54,6 +55,9 @@ public class TiktokServiceImpl implements TiktokService {
private RedisUtil redisUtil; private RedisUtil redisUtil;
@Autowired @Autowired
private RedisLockUtil redisLockUtil;
@Autowired
private ISStoreService storeService; private ISStoreService storeService;
@Autowired @Autowired
...@@ -356,33 +360,35 @@ public class TiktokServiceImpl implements TiktokService { ...@@ -356,33 +360,35 @@ public class TiktokServiceImpl implements TiktokService {
if (ObjectUtil.isNull(user)) { if (ObjectUtil.isNull(user)) {
throw new BaseException("您的登录已过期,请先登录"); throw new BaseException("您的登录已过期,请先登录");
} }
LambdaQueryWrapper<SStore> sStoreLambdaQueryWrapper = new LambdaQueryWrapper<>(); Boolean lock = redisLockUtil.getLock(String.valueOf(user.getId()), 1000);
sStoreLambdaQueryWrapper.eq(SStore::getId, storeId); if (lock) {
SStore sStore = storeService.getOne(sStoreLambdaQueryWrapper); LambdaQueryWrapper<SStore> sStoreLambdaQueryWrapper = new LambdaQueryWrapper<>();
if (ObjectUtils.isEmpty(sStore) || StoreStatusEnum.STOP.getIndex().equals(sStore.getStatus())) { sStoreLambdaQueryWrapper.eq(SStore::getId, storeId);
throw new Exception("门店维护中,请联系客服"); SStore sStore = storeService.getOne(sStoreLambdaQueryWrapper);
} if (ObjectUtils.isEmpty(sStore) || StoreStatusEnum.STOP.getIndex().equals(sStore.getStatus())) {
if (StringUtils.isEmpty(sStore.getTiktokPoiId())) { throw new Exception("门店维护中,请联系客服");
throw new Exception("门店未授权,请联系客服"); }
} if (StringUtils.isEmpty(sStore.getTiktokPoiId())) {
if (code.startsWith("https://v.douyin.com/") | code.length() == 15 | code.length() == 12) { throw new Exception("门店未授权,请联系客服");
try { }
TiktokCouponDto tiktokCouponDto = new TiktokCouponDto(); if (code.startsWith("https://v.douyin.com/") | code.length() == 15 | code.length() == 12) {
if (code.startsWith("https://v.douyin.com/")) { try {
tiktokCouponDto.setEncryptedData(code); TiktokCouponDto tiktokCouponDto = new TiktokCouponDto();
} else { if (code.startsWith("https://v.douyin.com/")) {
tiktokCouponDto.setCode(code); tiktokCouponDto.setEncryptedData(code);
} } else {
tiktokCouponDto.setPoiId(sStore.getTiktokPoiId()); tiktokCouponDto.setCode(code);
JSONObject prepare = prepare(tiktokCouponDto); }
JSONArray certificates = prepare.getJSONArray("certificates"); tiktokCouponDto.setPoiId(sStore.getTiktokPoiId());
if (CollectionUtils.isEmpty(certificates)) { JSONObject prepare = prepare(tiktokCouponDto);
throw new Exception("该券码已被使用"); JSONArray certificates = prepare.getJSONArray("certificates");
} if (CollectionUtils.isEmpty(certificates)) {
Object o = certificates.get(0); throw new Exception("该券码已被使用");
JSONObject entries = new JSONObject(o); }
JSONObject sku = entries.getJSONObject("sku"); Object o = certificates.get(0);
JSONObject amount = entries.getJSONObject("amount"); JSONObject entries = new JSONObject(o);
JSONObject sku = entries.getJSONObject("sku");
JSONObject amount = entries.getJSONObject("amount");
// //查询领取记录表 // //查询领取记录表
// LambdaQueryWrapper<SConsumerCoupon> queryWrapper = new LambdaQueryWrapper<>(); // LambdaQueryWrapper<SConsumerCoupon> queryWrapper = new LambdaQueryWrapper<>();
// queryWrapper.eq(SConsumerCoupon::getCouponCode, entries.getStr("encrypted_code")); // queryWrapper.eq(SConsumerCoupon::getCouponCode, entries.getStr("encrypted_code"));
...@@ -392,93 +398,95 @@ public class TiktokServiceImpl implements TiktokService { ...@@ -392,93 +398,95 @@ public class TiktokServiceImpl implements TiktokService {
// if (ObjectUtils.isNotEmpty(unUsedCoupon)) { // if (ObjectUtils.isNotEmpty(unUsedCoupon)) {
// throw new RuntimeException("该券已被领取"); // throw new RuntimeException("该券已被领取");
// } // }
TiktokCouponDto couponDto = new TiktokCouponDto(); TiktokCouponDto couponDto = new TiktokCouponDto();
couponDto.setVerifyToken(prepare.getStr("verify_token")); couponDto.setVerifyToken(prepare.getStr("verify_token"));
couponDto.setPoiId(sStore.getTiktokPoiId()); couponDto.setPoiId(sStore.getTiktokPoiId());
List<String> codes = new ArrayList<>(); List<String> codes = new ArrayList<>();
List<JSONObject> list = certificates.toList(JSONObject.class); List<JSONObject> list = certificates.toList(JSONObject.class);
//获取List中的encrypted_code //获取List中的encrypted_code
list.stream().forEach(e -> { list.stream().forEach(e -> {
codes.add(e.getStr("encrypted_code")); codes.add(e.getStr("encrypted_code"));
}); });
couponDto.setEncryptedCodes(codes); couponDto.setEncryptedCodes(codes);
JSONObject verify = verify(couponDto); JSONObject verify = verify(couponDto);
JSONArray verifyResults = verify.getJSONArray("verify_results"); JSONArray verifyResults = verify.getJSONArray("verify_results");
verifyResults.forEach(item -> { verifyResults.forEach(item -> {
JSONObject verifyResult = new JSONObject(item); JSONObject verifyResult = new JSONObject(item);
String originCode = verifyResult.getStr("origin_code"); String originCode = verifyResult.getStr("origin_code");
SConsumerCoupon sConsumerCoupon = new SConsumerCoupon(); SConsumerCoupon sConsumerCoupon = new SConsumerCoupon();
sConsumerCoupon.setConsumerId(user.getId()); sConsumerCoupon.setConsumerId(user.getId());
sConsumerCoupon.setStoreId(sStore.getId()); sConsumerCoupon.setStoreId(sStore.getId());
sConsumerCoupon.setCouponCode(originCode); sConsumerCoupon.setCouponCode(originCode);
sConsumerCoupon.setEncryptedCode(entries.getStr("encrypted_code")); sConsumerCoupon.setEncryptedCode(entries.getStr("encrypted_code"));
sConsumerCoupon.setName(sku.getStr("title")); sConsumerCoupon.setName(sku.getStr("title"));
sConsumerCoupon.setSourceType(SourceTypeEnum.CHECK.getCode()); sConsumerCoupon.setSourceType(SourceTypeEnum.CHECK.getCode());
sConsumerCoupon.setPlatformType(PlatformTypeEnum.TIKTOK.getCode()); sConsumerCoupon.setPlatformType(PlatformTypeEnum.TIKTOK.getCode());
sConsumerCoupon.setUseStatus(UserStatusEnum.UNUSED.getCode()); sConsumerCoupon.setUseStatus(UserStatusEnum.UNUSED.getCode());
sConsumerCoupon.setCreateBy(String.valueOf(user.getId()));
sConsumerCoupon.setCreateTime(new Date());
Integer originalAmount = amount.getInt("list_market_amount");
sConsumerCoupon.setOriginalPrice(BigDecimal.valueOf(originalAmount / 100));
sConsumerCoupon.setCouponPayPrice(BigDecimal.valueOf(amount.getInt("pay_amount") / 100));
//时间戳转年月日时分秒
sConsumerCoupon.setEndDate(new Date(entries.getInt("expire_time") * 1000L));
//获取本日的00:00:00
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
Date startOfDay = calendar.getTime();
sConsumerCoupon.setStartDate(startOfDay);
LambdaQueryWrapper<SCoupon> sCouponLambdaQueryWrapper = new LambdaQueryWrapper<>();
sCouponLambdaQueryWrapper.eq(SCoupon::getTiktokSkuId, sku.getStr("sku_id"));
List<SCoupon> sCoupons = isCouponService.list(sCouponLambdaQueryWrapper);
SCoupon sCoupon = null;
if (!CollectionUtils.isEmpty(sCoupons)) {
sCoupon = sCoupons.get(0);
}
if (ObjectUtils.isEmpty(sCoupon)) {
sConsumerCoupon.setTiktokSkuId(sku.getStr("sku_id"));
sConsumerCoupon.setCouponType(CouponTypeEnum.CASH.getCode());
sConsumerCoupon.setStoreType(StoreType.getCodeList());
sConsumerCoupon.setRoomType(RoomType.getCodeList());
sConsumerCoupon.setCreateBy(String.valueOf(user.getId())); sConsumerCoupon.setCreateBy(String.valueOf(user.getId()));
sConsumerCoupon.setMinDuration(DEFAULT_MIN_DURATION); sConsumerCoupon.setCreateTime(new Date());
sConsumerCoupon.setMaxDuration(DEFAULT_MAX_DURATION); Integer originalAmount = amount.getInt("list_market_amount");
sConsumerCoupon.setDuration(DEFAULT_DURATION); sConsumerCoupon.setOriginalPrice(BigDecimal.valueOf(originalAmount / 100));
sConsumerCoupon.setMinPrice(DEFAULT_MIN_PRICE); sConsumerCoupon.setCouponPayPrice(BigDecimal.valueOf(amount.getInt("pay_amount") / 100));
sConsumerCoupon.setCouponTimeStart(DEFAULT_START_TIME); //时间戳转年月日时分秒
sConsumerCoupon.setCouponTimeEnd(DEFAULT_END_TIME); sConsumerCoupon.setEndDate(new Date(entries.getInt("expire_time") * 1000L));
sConsumerCoupon.setSalePrice(sConsumerCoupon.getCouponPayPrice()); //获取本日的00:00:00
} else { Calendar calendar = Calendar.getInstance();
sConsumerCoupon.setCouponId(sCoupon.getId()); calendar.set(Calendar.HOUR_OF_DAY, 0);
sConsumerCoupon.setCouponType(sCoupon.getCouponType()); calendar.set(Calendar.MINUTE, 0);
sConsumerCoupon.setStoreType(sCoupon.getStoreType()); calendar.set(Calendar.SECOND, 0);
sConsumerCoupon.setRoomType(sCoupon.getRoomType()); calendar.set(Calendar.MILLISECOND, 0);
sConsumerCoupon.setMinDuration(sCoupon.getMinDuration()); Date startOfDay = calendar.getTime();
sConsumerCoupon.setMaxDuration(sCoupon.getMaxDuration()); sConsumerCoupon.setStartDate(startOfDay);
sConsumerCoupon.setDuration(sCoupon.getDuration()); LambdaQueryWrapper<SCoupon> sCouponLambdaQueryWrapper = new LambdaQueryWrapper<>();
sConsumerCoupon.setMinPrice(sCoupon.getMinPrice()); sCouponLambdaQueryWrapper.eq(SCoupon::getTiktokSkuId, sku.getStr("sku_id"));
sConsumerCoupon.setCouponTimeStart(sCoupon.getValidStartTime()); List<SCoupon> sCoupons = isCouponService.list(sCouponLambdaQueryWrapper);
sConsumerCoupon.setCouponTimeEnd(sCoupon.getValidEndTime()); SCoupon sCoupon = null;
sConsumerCoupon.setOrderType(sCoupon.getOrderType()); if (!CollectionUtils.isEmpty(sCoupons)) {
sConsumerCoupon.setTiktokSkuId(sCoupon.getTiktokSkuId()); sCoupon = sCoupons.get(0);
sConsumerCoupon.setStoreIds(sCoupon.getStoreIds()); }
sConsumerCoupon.setPackIds(sCoupon.getPackIds()); if (ObjectUtils.isEmpty(sCoupon)) {
sConsumerCoupon.setWeeks(sCoupon.getWeeks()); sConsumerCoupon.setTiktokSkuId(sku.getStr("sku_id"));
sConsumerCoupon.setRemark(sCoupon.getRemark()); sConsumerCoupon.setCouponType(CouponTypeEnum.CASH.getCode());
sConsumerCoupon.setSalePrice(sCoupon.getSalePrice()); sConsumerCoupon.setStoreType(StoreType.getCodeList());
} sConsumerCoupon.setRoomType(RoomType.getCodeList());
isConsumerCouponService.insertSConsumerCoupon(sConsumerCoupon); sConsumerCoupon.setCreateBy(String.valueOf(user.getId()));
}); sConsumerCoupon.setMinDuration(DEFAULT_MIN_DURATION);
} catch (RuntimeException e) { sConsumerCoupon.setMaxDuration(DEFAULT_MAX_DURATION);
throw new RuntimeException(e); sConsumerCoupon.setDuration(DEFAULT_DURATION);
sConsumerCoupon.setMinPrice(DEFAULT_MIN_PRICE);
sConsumerCoupon.setCouponTimeStart(DEFAULT_START_TIME);
sConsumerCoupon.setCouponTimeEnd(DEFAULT_END_TIME);
sConsumerCoupon.setSalePrice(sConsumerCoupon.getCouponPayPrice());
} else {
sConsumerCoupon.setCouponId(sCoupon.getId());
sConsumerCoupon.setCouponType(sCoupon.getCouponType());
sConsumerCoupon.setStoreType(sCoupon.getStoreType());
sConsumerCoupon.setRoomType(sCoupon.getRoomType());
sConsumerCoupon.setMinDuration(sCoupon.getMinDuration());
sConsumerCoupon.setMaxDuration(sCoupon.getMaxDuration());
sConsumerCoupon.setDuration(sCoupon.getDuration());
sConsumerCoupon.setMinPrice(sCoupon.getMinPrice());
sConsumerCoupon.setCouponTimeStart(sCoupon.getValidStartTime());
sConsumerCoupon.setCouponTimeEnd(sCoupon.getValidEndTime());
sConsumerCoupon.setOrderType(sCoupon.getOrderType());
sConsumerCoupon.setTiktokSkuId(sCoupon.getTiktokSkuId());
sConsumerCoupon.setStoreIds(sCoupon.getStoreIds());
sConsumerCoupon.setPackIds(sCoupon.getPackIds());
sConsumerCoupon.setWeeks(sCoupon.getWeeks());
sConsumerCoupon.setRemark(sCoupon.getRemark());
sConsumerCoupon.setSalePrice(sCoupon.getSalePrice());
}
isConsumerCouponService.insertSConsumerCoupon(sConsumerCoupon);
});
} catch (RuntimeException e) {
throw new RuntimeException(e);
}
} else {
throw new RuntimeException("券码格式错误");
} }
} else { return "验卷成功";
throw new RuntimeException("券码格式错误");
} }
return "验卷成功"; throw new RuntimeException("验劵失败");
} }
@Override @Override
......
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="AdditionalModuleElements">
<content url="file://$MODULE_DIR$" dumb="true">
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
</component>
</module>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment