Commit c8b8b80e by 吕明尚

增加根据优惠券券码获取适用门店

parent 80feb08e
......@@ -8,6 +8,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import share.common.core.domain.R;
import share.common.enums.ConsumerCouponStatusEnum;
import share.system.domain.SStore;
import share.system.service.QPService;
import share.system.service.TiktokService;
......@@ -75,4 +76,16 @@ public class QPController {
public R<List<TuangouDealQueryShopDealResponseEntity>> queryshopdeal(String openShopUuid) {
return R.ok(qpService.queryshopdeal(openShopUuid));
}
//查询当前优惠券适用门店
@GetMapping("/queryshop")
public R<List<SStore>> queryshop(String code) {
if (code.length() == 10) {
return R.ok(qpService.queryshop(code));
} else if (code.startsWith("https://v.douyin.com/") | code.length() == 15 | code.length() == 12) {
return R.ok(tiktokService.queryshop(code));
} else {
return R.fail("请输入正确的券码");
}
}
}
......@@ -3,6 +3,8 @@ package share.system.service;
import com.dianping.openapi.sdk.api.customerauth.session.entity.CustomerKeyShopScopeResponseEntity;
import com.dianping.openapi.sdk.api.oauth.entity.CustomerRefreshTokenResponse;
import com.dianping.openapi.sdk.api.tuangou.entity.*;
import share.system.domain.SCoupon;
import share.system.domain.SStore;
import share.system.domain.vo.SessionVo;
import java.util.List;
......@@ -29,4 +31,8 @@ public interface QPService {
SessionVo queryKey();
List<CustomerKeyShopScopeResponseEntity> scope();
List<SStore> queryshop(String code);
List<SStore> getsStores(List<SStore> sStoreList, SCoupon sCoupon);
}
package share.system.service;
import cn.hutool.json.JSONObject;
import share.system.domain.SStore;
import share.system.domain.tiktok.TiktokCouponDto;
import share.system.domain.tiktok.TiktokPoi;
import share.system.domain.vo.OnlineQueryDto;
......@@ -27,4 +28,6 @@ public interface TiktokService {
String consumeByUser(String code, String storeId);
List<TiktokPoi> poiList();
List<SStore> queryshop(String code);
}
......@@ -46,6 +46,7 @@ import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@Service
public class QPServiceImpl implements QPService {
......@@ -239,7 +240,7 @@ public class QPServiceImpl implements QPService {
logger.error("验卷准备失败:{}", invoke.getMsg());
throw new RuntimeException(invoke.getMsg());
}
logger.info("验卷准备结束:{}", invoke.getData());
logger.info("验卷准备结束:{}", invoke.getData().toString());
return invoke.getData();
}
......@@ -418,4 +419,50 @@ public class QPServiceImpl implements QPService {
return collect;
}
@Override
public List<SStore> queryshop(String code) {
LambdaQueryWrapper<SStore> sStoreLambdaQueryWrapper = new LambdaQueryWrapper<>(SStore.class);
sStoreLambdaQueryWrapper.eq(SStore::getStoreType, StoreType.HOTEL.getCode());
List<SStore> sStoreList = storeService.list(sStoreLambdaQueryWrapper);
//验券准备
TuangouReceiptPrepareResponseEntity prepare = prepare(code.trim(), sStoreList.get(0).getOpenShopUuid(), "");
sStoreList = storeService.list(new LambdaQueryWrapper<>(SStore.class).isNotNull(SStore::getOpenShopUuid));
SCoupon sCoupon = isCouponService.getOne(new LambdaQueryWrapper<>(SCoupon.class).
eq(SCoupon::getCouponType, CouponTypeEnum.CASH.getCode()).
eq(SCoupon::getDealgroupId, prepare.getDealgroup_id()).
eq(SCoupon::getPlatformType, PlatformTypeEnum.MEITUAN.getCode()));
if (!ObjectUtils.isEmpty(sCoupon)) {
//过滤不存在sCoupon.getstoreIds()的门店
return getsStores(sStoreList, sCoupon);
} else {
List<SCoupon> coupons = isCouponService.queryShopDeal();
SCoupon scoupon = coupons.stream().filter(o -> o.getDealgroupId().equals(prepare.getDealgroup_id())).findFirst().get();
if (ObjectUtils.isEmpty(scoupon)) {
throw new RuntimeException("当前优惠券异常,请联系客服");
}
isCouponService.save(scoupon);
//过滤不存在sCoupon.getstoreIds()的门店
return getsStores(sStoreList, scoupon);
}
}
public List<SStore> getsStores(List<SStore> sStoreList, SCoupon sCoupon) {
List<SStore> collect = sStoreList.stream().filter(o -> {
String storeIds = sCoupon.getStoreIds();
if (StringUtils.isEmpty(storeIds)) {
return true;
}
String[] split = storeIds.split(",");
for (String s : split) {
if (o.getId().equals(Long.valueOf(s))) {
return true;
}
}
return false;
}).collect(Collectors.toList());
if (CollectionUtils.isEmpty(collect)) {
return sStoreList;
}
return collect;
}
}
......@@ -220,6 +220,7 @@ public class SCouponServiceImpl extends ServiceImpl<SCouponMapper, SCoupon> impl
} catch (ParseException e) {
throw new RuntimeException(e);
}
sCoupon.setPlatformType(PlatformTypeEnum.MEITUAN.getCode());
sCoupon.setRoomType(RoomType.getCodeList());
sCoupon.setStoreType(StoreType.getCodeList());
sCoupon.setValidStartTime(DEFAULT_START_TIME);
......@@ -318,6 +319,7 @@ public class SCouponServiceImpl extends ServiceImpl<SCouponMapper, SCoupon> impl
sCoupon.setEndDate(new Date(product.getInt("sold_end_time") * 1000L));
sCoupon.setSubPrice(sku.getBigDecimal("origin_amount").divide(new BigDecimal("100")));
sCoupon.setRoomType(RoomType.getCodeList());
sCoupon.setPlatformType(PlatformTypeEnum.TIKTOK.getCode());
sCoupon.setStoreType(StoreType.getCodeList());
sCoupon.setValidStartTime(DEFAULT_START_TIME);
sCoupon.setValidEndTime(DEFAULT_END_TIME);
......
......@@ -27,10 +27,7 @@ import share.system.domain.tiktok.TiktokCouponDto;
import share.system.domain.tiktok.TiktokPoi;
import share.system.domain.vo.FrontTokenComponent;
import share.system.domain.vo.OnlineQueryDto;
import share.system.service.ISConsumerCouponService;
import share.system.service.ISCouponService;
import share.system.service.ISStoreService;
import share.system.service.TiktokService;
import share.system.service.*;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
......@@ -62,6 +59,9 @@ public class TiktokServiceImpl implements TiktokService {
@Autowired
private ISCouponService isCouponService;
@Autowired
private QPService qpService;
//默认门槛时长
private static final String DEFAULT_MIN_DURATION = "0";
//默认时长
......@@ -467,6 +467,48 @@ public class TiktokServiceImpl implements TiktokService {
return collect;
}
@Override
public List<SStore> queryshop(String code) {
LambdaQueryWrapper<SStore> sStoreLambdaQueryWrapper = new LambdaQueryWrapper<>(SStore.class);
sStoreLambdaQueryWrapper.eq(SStore::getStoreType, StoreType.HOTEL.getCode());
List<SStore> sStoreList = storeService.list(sStoreLambdaQueryWrapper);
if (code.startsWith("https://v.douyin.com/") | code.length() == 15 | code.length() == 12) {
try {
TiktokCouponDto tiktokCouponDto = new TiktokCouponDto();
if (code.startsWith("https://v.douyin.com/")) {
tiktokCouponDto.setEncryptedData(code);
} else {
tiktokCouponDto.setCode(code);
}
tiktokCouponDto.setPoiId(sStoreList.get(0).getTiktokPoiId());
JSONObject prepare = prepare(tiktokCouponDto);
JSONArray certificates = prepare.getJSONArray("certificates");
Object o = certificates.get(0);
JSONObject entries = new JSONObject(o);
JSONObject sku = entries.getJSONObject("sku");
SCoupon sCoupon = isCouponService.getOne(new LambdaQueryWrapper<>(SCoupon.class).
eq(SCoupon::getCouponType, CouponTypeEnum.CASH.getCode()).
eq(SCoupon::getTiktokSkuId, sku.getStr("sku_id")).
eq(SCoupon::getPlatformType, PlatformTypeEnum.TIKTOK.getCode()));
sStoreList = storeService.list(new LambdaQueryWrapper<>(SStore.class).isNotNull(SStore::getTiktokPoiId));
if (!ObjectUtils.isEmpty(sCoupon)) {
return qpService.getsStores(sStoreList, sCoupon);
} else {
List<SCoupon> coupons = isCouponService.querySkuPoiList();
SCoupon scoupon = coupons.stream().filter(s -> s.getTiktokSkuId().equals(sku.getStr("sku_id"))).findFirst().get();
if (ObjectUtils.isEmpty(scoupon)) {
throw new RuntimeException("当前优惠券异常,请联系客服");
}
isCouponService.save(scoupon);
return qpService.getsStores(sStoreList, scoupon);
}
} catch (RuntimeException e) {
throw new RuntimeException(e);
}
}
return Collections.emptyList();
}
public String obtain() {
String o;
o = redisUtil.get(ReceiptRdeisEnum.TIKTOK_CLIENT_TOKEN.getValue());
......
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