1
This commit is contained in:
@@ -69,7 +69,6 @@ public class JDUtil {
|
|||||||
private static final String LL_SECRET_KEY_DG = "3ceddff403e544a8a2eacc727cf05dab";
|
private static final String LL_SECRET_KEY_DG = "3ceddff403e544a8a2eacc727cf05dab";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private static final String SERVER_URL = "https://api.jd.com/routerjson";
|
private static final String SERVER_URL = "https://api.jd.com/routerjson";
|
||||||
//accessToken
|
//accessToken
|
||||||
private static final String ACCESS_TOKEN = "";
|
private static final String ACCESS_TOKEN = "";
|
||||||
@@ -88,8 +87,6 @@ public class JDUtil {
|
|||||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 构造函数中注入StringRedisTemplate
|
// 构造函数中注入StringRedisTemplate
|
||||||
@Autowired
|
@Autowired
|
||||||
public JDUtil(StringRedisTemplate redisTemplate, ProductOrderRepository productOrderRepository, OrderRowRepository orderRowRepository, WXUtil wxUtil, OrderUtil orderUtil) {
|
public JDUtil(StringRedisTemplate redisTemplate, ProductOrderRepository productOrderRepository, OrderRowRepository orderRowRepository, WXUtil wxUtil, OrderUtil orderUtil) {
|
||||||
@@ -131,32 +128,24 @@ public class JDUtil {
|
|||||||
return new OrderStats(orders.size(), orders.size() - canceled, paid, orders.stream().filter(o -> o.getValidCode() == 16).mapToDouble(OrderRow::getEstimateFee).sum(), pending, orders.stream().filter(o -> o.getValidCode() == 15).mapToDouble(OrderRow::getEstimateFee).sum(), canceled, completed, orders.stream().filter(o -> o.getValidCode() == 17).mapToDouble(OrderRow::getEstimateFee).sum(), getStreamForWeiGui(orders).count(), getStreamForWeiGui(orders).mapToDouble(o -> o.getEstimateCosPrice() * o.getCommissionRate() * 0.01).sum());
|
return new OrderStats(orders.size(), orders.size() - canceled, paid, orders.stream().filter(o -> o.getValidCode() == 16).mapToDouble(OrderRow::getEstimateFee).sum(), pending, orders.stream().filter(o -> o.getValidCode() == 15).mapToDouble(OrderRow::getEstimateFee).sum(), canceled, completed, orders.stream().filter(o -> o.getValidCode() == 17).mapToDouble(OrderRow::getEstimateFee).sum(), getStreamForWeiGui(orders).count(), getStreamForWeiGui(orders).mapToDouble(o -> o.getEstimateCosPrice() * o.getCommissionRate() * 0.01).sum());
|
||||||
}
|
}
|
||||||
|
|
||||||
private StringBuilder buildStatsContent(String title, OrderStats stats) {
|
private StringBuilder buildStatsContent(String title, OrderStats stats) {
|
||||||
StringBuilder content = new StringBuilder();
|
StringBuilder content = new StringBuilder();
|
||||||
content//[爱心][Wow][Packet][Party][Broken][心碎][亲亲][色]
|
content//[爱心][Wow][Packet][Party][Broken][心碎][亲亲][色]
|
||||||
.append("* ").append(title).append(" *\n")
|
.append("* ").append(title).append(" *\n").append("━━━━━━━━━━━━\n").append("[爱心] 订单总数:").append(stats.getTotalOrders()).append("\n") // [文件]
|
||||||
.append("━━━━━━━━━━━━\n")
|
.append("[Party] 有效订单:").append(stats.getValidOrders()).append("\n") // [OK]
|
||||||
.append("[爱心] 订单总数:").append(stats.getTotalOrders()).append("\n") // [文件]
|
.append("[心碎]已取消:").append(stats.getCanceledOrders()).append("\n") // [禁止]
|
||||||
.append("[Party] 有效订单:").append(stats.getValidOrders()).append("\n") // [OK]
|
|
||||||
.append("[心碎]已取消:").append(stats.getCanceledOrders()).append("\n") // [禁止]
|
|
||||||
|
|
||||||
.append("────────────\n")
|
|
||||||
.append("[爱心]已付款:").append(stats.getPaidOrders()).append("\n") // [钱袋]
|
|
||||||
.append("[Packet] 已付款佣金:").append(String.format("%.2f", stats.getPaidCommission())).append("\n") // [钞票]
|
|
||||||
.append("────────────\n")
|
|
||||||
.append("[Wow] 待付款:").append(stats.getPendingOrders()).append("\n") // [时钟]
|
|
||||||
.append("[Packet] 待付款佣金:").append(String.format("%.2f", stats.getPendingCommission())).append("\n") // [钱]
|
|
||||||
.append("────────────\n")
|
|
||||||
.append("[亲亲] 已完成:").append(stats.getCompletedOrders()).append("\n") // [旗帜]
|
|
||||||
.append("[Packet] 已完成佣金:").append(String.format("%.2f", stats.getCompletedCommission())).append("\n") // [信用卡]
|
|
||||||
.append("────────────\n")
|
|
||||||
.append("[Emm] 违规订单:").append(stats.getViolations()).append("\n") // [警告]
|
|
||||||
.append("[Broken] 违规佣金:").append(String.format("%.2f", stats.getViolationCommission())).append("\n") // [炸弹]
|
|
||||||
.append("━━━━━━━━━━━━");
|
|
||||||
return content;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
.append("────────────\n").append("[爱心]已付款:").append(stats.getPaidOrders()).append("\n") // [钱袋]
|
||||||
|
.append("[Packet] 已付款佣金:").append(String.format("%.2f", stats.getPaidCommission())).append("\n") // [钞票]
|
||||||
|
.append("────────────\n").append("[Wow] 待付款:").append(stats.getPendingOrders()).append("\n") // [时钟]
|
||||||
|
.append("[Packet] 待付款佣金:").append(String.format("%.2f", stats.getPendingCommission())).append("\n") // [钱]
|
||||||
|
.append("────────────\n").append("[亲亲] 已完成:").append(stats.getCompletedOrders()).append("\n") // [旗帜]
|
||||||
|
.append("[Packet] 已完成佣金:").append(String.format("%.2f", stats.getCompletedCommission())).append("\n") // [信用卡]
|
||||||
|
.append("────────────\n").append("[Emm] 违规订单:").append(stats.getViolations()).append("\n") // [警告]
|
||||||
|
.append("[Broken] 违规佣金:").append(String.format("%.2f", stats.getViolationCommission())).append("\n") // [炸弹]
|
||||||
|
.append("━━━━━━━━━━━━");
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -669,256 +658,246 @@ private StringBuilder buildStatsContent(String title, OrderStats stats) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 新增礼金流程处理方法
|
// 新增礼金流程处理方法
|
||||||
private void handleGiftMoneyFlow(String fromWxid, String message, UserInteractionState state) {
|
private void handleGiftMoneyFlow(String fromWxid, String message, UserInteractionState state) {
|
||||||
if ("礼金".equals(message)) {
|
if (state.getCurrentStep() == null) {
|
||||||
state.reset();
|
state.setCurrentStep(STEP_PRODUCT_LINK);
|
||||||
logger.debug("用户 {} 重置礼金流程", fromWxid); // 新增
|
wxUtil.sendTextMessage(fromWxid, "流程异常,已重置。请输入商品链接:", 1, fromWxid);
|
||||||
wxUtil.sendTextMessage(fromWxid, "流程已重置,请重新开始", 1, fromWxid);
|
return;
|
||||||
return;
|
}
|
||||||
}
|
if ("礼金".equals(message)) {
|
||||||
|
state.reset();
|
||||||
try {
|
logger.debug("用户 {} 重置礼金流程", fromWxid); // 新增
|
||||||
String skuId = "";
|
wxUtil.sendTextMessage(fromWxid, "流程已重置,请重新开始", 1, fromWxid);
|
||||||
double amount = 0.0;
|
return;
|
||||||
String owner = "自营";
|
}
|
||||||
switch (state.getCurrentStep()) {
|
|
||||||
case STEP_PRODUCT_LINK:
|
try {
|
||||||
skuId = parseSkuFromUrl(message);
|
String skuId = "";
|
||||||
logger.debug("用户 {} 输入商品链接:{}, 解析出SKU: {}", fromWxid, message, skuId); // 新增
|
double amount = 0.0;
|
||||||
if (skuId == null) {
|
String owner = "自营";
|
||||||
wxUtil.sendTextMessage(fromWxid, "❌ 商品链接格式错误,请重新输入", 1, fromWxid);
|
switch (state.getCurrentStep()) {
|
||||||
return;
|
case STEP_PRODUCT_LINK:
|
||||||
}
|
skuId = parseSkuFromUrl(message);
|
||||||
//BigfieldQueryResult queryResult = queryProductInfo(skuId);
|
logger.debug("用户 {} 输入商品链接:{}, 解析出SKU: {}", fromWxid, message, skuId); // 新增
|
||||||
//logger.debug("商品ID {} 查询结果:{}", skuId, queryResult); // 新增
|
if (skuId == null) {
|
||||||
//if (queryResult == null) {
|
wxUtil.sendTextMessage(fromWxid, "❌ 商品链接格式错误,请重新输入", 1, fromWxid);
|
||||||
// wxUtil.sendTextMessage(fromWxid, "⚠️ 商品信息查询失败,可能链接无效", 1, fromWxid);
|
return;
|
||||||
// return;
|
}
|
||||||
//}
|
//BigfieldQueryResult queryResult = queryProductInfo(skuId);
|
||||||
|
//logger.debug("商品ID {} 查询结果:{}", skuId, queryResult); // 新增
|
||||||
//BigFieldGoodsResp productInfo = queryResult.getData()[0];
|
//if (queryResult == null) {
|
||||||
//owner = productInfo.getOwner();
|
// wxUtil.sendTextMessage(fromWxid, "⚠️ 商品信息查询失败,可能链接无效", 1, fromWxid);
|
||||||
//state.getCollectedFields().put("skuId", skuId);
|
// return;
|
||||||
//state.getCollectedFields().put("productInfo", productInfo.getBaseBigFieldInfo().getWdis());
|
//}
|
||||||
//state.getCollectedFields().put("owner", owner);
|
|
||||||
//
|
//BigFieldGoodsResp productInfo = queryResult.getData()[0];
|
||||||
//logger.debug("商品信息已收集:SKU={}, Owner={}, WDIS={}", skuId, owner, productInfo.getBaseBigFieldInfo().getWdis()); // 新增
|
//owner = productInfo.getOwner();
|
||||||
String productInfo = skuId;
|
//state.getCollectedFields().put("skuId", skuId);
|
||||||
state.setCurrentStep(STEP_AMOUNT);
|
//state.getCollectedFields().put("productInfo", productInfo.getBaseBigFieldInfo().getWdis());
|
||||||
String prompt = String.format("商品信息:\n%s请输入开通金额(元):",
|
//state.getCollectedFields().put("owner", owner);
|
||||||
productInfo);
|
//
|
||||||
wxUtil.sendTextMessage(fromWxid, prompt, 1, fromWxid);
|
//logger.debug("商品信息已收集:SKU={}, Owner={}, WDIS={}", skuId, owner, productInfo.getBaseBigFieldInfo().getWdis()); // 新增
|
||||||
break;
|
String productInfo = skuId;
|
||||||
|
state.setCurrentStep(STEP_AMOUNT);
|
||||||
case STEP_AMOUNT:
|
String prompt = String.format("商品SKU:\n %s\n 请输入开通金额(元):", productInfo);
|
||||||
logger.debug("用户 {} 输入金额:{}", fromWxid, message);
|
wxUtil.sendTextMessage(fromWxid, prompt, 1, fromWxid);
|
||||||
// 新增:先检查 message 是否为 null 或空字符串
|
break;
|
||||||
if (message == null || message.trim().isEmpty()) {
|
|
||||||
wxUtil.sendTextMessage(fromWxid, "❌ 金额不能为空,请输入数字", 1, fromWxid);
|
case STEP_AMOUNT:
|
||||||
return;
|
logger.debug("用户 {} 输入金额:{}", fromWxid, message);
|
||||||
}
|
// 强制检查空值
|
||||||
if (!isValidAmount(message)) {
|
if (message == null || message.trim().isEmpty()) {
|
||||||
wxUtil.sendTextMessage(fromWxid, "❌ 金额格式错误,请输入数字(如:100.00)", 1, fromWxid);
|
wxUtil.sendTextMessage(fromWxid, "❌ 金额不能为空,请输入数字(如:100.00)", 1, fromWxid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
amount = Double.parseDouble(message);
|
// 校验格式
|
||||||
// 格式化后输出日志
|
if (!isValidAmount(message)) {
|
||||||
String formattedAmount = String.format("%.2f", amount);
|
wxUtil.sendTextMessage(fromWxid, "❌ 金额格式错误,请输入数字(如:100.00)", 1, fromWxid);
|
||||||
logger.debug("校验金额:{} 元(商品价格的80%:{})", formattedAmount, 0.8 * Double.parseDouble(state.getCollectedFields().get("price"))); // 新增
|
return;
|
||||||
if (amount < 1 || amount > 0.8 * Double.parseDouble(state.getCollectedFields().get("price"))) {
|
}
|
||||||
wxUtil.sendTextMessage(fromWxid, "❌ 金额需≥1元且≤商品价格的80%", 1, fromWxid);
|
// 转换并保留两位小数
|
||||||
return;
|
amount = Double.parseDouble(message);
|
||||||
}
|
String formattedAmount = String.format("%.2f", amount);
|
||||||
|
state.getCollectedFields().put("amount", formattedAmount);
|
||||||
state.getCollectedFields().put("amount", formattedAmount);
|
state.setCurrentStep(STEP_QUANTITY);
|
||||||
state.setCurrentStep(STEP_QUANTITY);
|
wxUtil.sendTextMessage(fromWxid, "请输入数量(1-1000):", 1, fromWxid);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STEP_QUANTITY:
|
|
||||||
logger.debug("用户 {} 输入数量:{}", fromWxid, message); // 新增
|
case STEP_QUANTITY:
|
||||||
if (!isValidQuantity(message)) {
|
logger.debug("用户 {} 输入数量:{}", fromWxid, message); // 新增
|
||||||
wxUtil.sendTextMessage(fromWxid, "❌ 数量格式错误,请输入整数", 1, fromWxid);
|
if (!isValidQuantity(message)) {
|
||||||
return;
|
wxUtil.sendTextMessage(fromWxid, "❌ 数量格式错误,请输入整数", 1, fromWxid);
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
int quantity = Integer.parseInt(message);
|
|
||||||
if (quantity < 1 || quantity > 1000) {
|
int quantity = Integer.parseInt(message);
|
||||||
wxUtil.sendTextMessage(fromWxid, "❌ 数量需在1-1000之间", 1, fromWxid);
|
if (quantity < 1 || quantity > 1000) {
|
||||||
return;
|
wxUtil.sendTextMessage(fromWxid, "❌ 数量需在1-1000之间", 1, fromWxid);
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
logger.debug("礼金参数准备完成:SKU={},金额={}元,数量={},Owner={}",
|
|
||||||
state.getCollectedFields().get("skuId"),
|
logger.debug("礼金参数准备完成:SKU={},金额={}元,数量={},Owner={}", state.getCollectedFields().get("skuId"), amount, quantity, state.getCollectedFields().get("owner")); // 新增
|
||||||
amount,
|
|
||||||
quantity,
|
String giftKey = createGiftCoupon(skuId, amount, quantity, owner);
|
||||||
state.getCollectedFields().get("owner")); // 新增
|
if (giftKey == null) {
|
||||||
|
logger.error("用户 {} 礼金创建失败:SKU={}, 金额={}, 数量={}, Owner={}", fromWxid, skuId, amount, quantity, owner); // 新增
|
||||||
String giftKey = createGiftCoupon(skuId, amount, quantity, owner);
|
wxUtil.sendTextMessage(fromWxid, "❌ 礼金创建失败,请检查商品是否符合要求", 1, fromWxid);
|
||||||
if (giftKey == null) {
|
state.reset();
|
||||||
logger.error("用户 {} 礼金创建失败:SKU={}, 金额={}, 数量={}, Owner={}",
|
return;
|
||||||
fromWxid, skuId, amount, quantity, owner); // 新增
|
}
|
||||||
wxUtil.sendTextMessage(fromWxid, "❌ 礼金创建失败,请检查商品是否符合要求", 1, fromWxid);
|
|
||||||
state.reset();
|
logger.info("用户 {} 礼金创建成功:批次ID={}, 参数:SKU={}, 金额={}元,数量={}, Owner={}", fromWxid, giftKey, skuId, amount, quantity, owner); // 新增关键成功日志
|
||||||
return;
|
state.getCollectedFields().put("giftKey", giftKey);
|
||||||
}
|
break;
|
||||||
|
}
|
||||||
logger.info("用户 {} 礼金创建成功:批次ID={}, 参数:SKU={}, 金额={}元,数量={}, Owner={}",
|
} catch (Exception e) {
|
||||||
fromWxid, giftKey, skuId, amount, quantity, owner); // 新增关键成功日志
|
logger.error("礼金流程异常,用户 {} 当前步骤:{}", fromWxid, state.getCurrentStep(), e); // 新增
|
||||||
state.getCollectedFields().put("giftKey", giftKey);
|
wxUtil.sendTextMessage(fromWxid, "❌ 系统异常,请稍后重试", 1, fromWxid);
|
||||||
break;
|
state.reset();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error("礼金流程异常,用户 {} 当前步骤:{}", fromWxid, state.getCurrentStep(), e); // 新增
|
|
||||||
wxUtil.sendTextMessage(fromWxid, "❌ 系统异常,请稍后重试", 1, fromWxid);
|
|
||||||
state.reset();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// 在JDUtil类中新增方法实现商品详情查询接口
|
// 在JDUtil类中新增方法实现商品详情查询接口
|
||||||
public UnionOpenGoodsBigfieldQueryResponse getUnionOpenGoodsBigfieldQueryResponse(String skuId) throws Exception {
|
public UnionOpenGoodsBigfieldQueryResponse getUnionOpenGoodsBigfieldQueryResponse(String skuId) throws Exception {
|
||||||
JdClient client = new DefaultJdClient(SERVER_URL, ACCESS_TOKEN, LPF_APP_KEY_WZ, LPF_APP_KEY_WZ);
|
JdClient client = new DefaultJdClient(SERVER_URL, ACCESS_TOKEN, LPF_APP_KEY_WZ, LPF_APP_KEY_WZ);
|
||||||
|
|
||||||
UnionOpenGoodsBigfieldQueryRequest request = new UnionOpenGoodsBigfieldQueryRequest();
|
UnionOpenGoodsBigfieldQueryRequest request = new UnionOpenGoodsBigfieldQueryRequest();
|
||||||
BigFieldGoodsReq goodsReq = new BigFieldGoodsReq();
|
BigFieldGoodsReq goodsReq = new BigFieldGoodsReq();
|
||||||
goodsReq.setSkuIds(List.of(Long.parseLong(skuId)).toArray(new Long[0])); // 传入skuId集合
|
goodsReq.setSkuIds(List.of(Long.parseLong(skuId)).toArray(new Long[0])); // 传入skuId集合
|
||||||
/**
|
/**
|
||||||
* 查询域集合,不填写则查询全部,目目前支持:categoryInfo(类目信息),imageInfo(图片信息),
|
* 查询域集合,不填写则查询全部,目目前支持:categoryInfo(类目信息),imageInfo(图片信息),
|
||||||
* baseBigFieldInfo(基础大字段信息),bookBigFieldInfo(图书大字段信息),
|
* baseBigFieldInfo(基础大字段信息),bookBigFieldInfo(图书大字段信息),
|
||||||
* videoBigFieldInfo(影音大字段信息),detailImages(商详图)*/
|
* videoBigFieldInfo(影音大字段信息),detailImages(商详图)*/
|
||||||
//goodsReq.setFields(new String[]{"categoryInfo", "imageInfo", "baseBigFieldInfo"}); // 设置需要查询的字段
|
//goodsReq.setFields(new String[]{"categoryInfo", "imageInfo", "baseBigFieldInfo"}); // 设置需要查询的字段
|
||||||
goodsReq.setSceneId(2); // 设置场景ID
|
goodsReq.setSceneId(2); // 设置场景ID
|
||||||
|
|
||||||
request.setGoodsReq(goodsReq);
|
request.setGoodsReq(goodsReq);
|
||||||
request.setVersion("1.0");
|
request.setVersion("1.0");
|
||||||
request.setSignmethod("md5");
|
request.setSignmethod("md5");
|
||||||
request.setTimestamp(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
|
request.setTimestamp(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
|
||||||
|
|
||||||
return client.execute(request);
|
return client.execute(request);
|
||||||
}
|
|
||||||
|
|
||||||
// 修改parseSkuFromUrl方法提取SKU
|
|
||||||
private String parseSkuFromUrl(String url) {
|
|
||||||
Matcher m = Pattern.compile("item.jd.com/(\\d+).html").matcher(url);
|
|
||||||
return m.find() ? m.group(1) : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BigfieldQueryResult queryProductInfo(String skuId) throws Exception {
|
|
||||||
UnionOpenGoodsBigfieldQueryResponse response = getUnionOpenGoodsBigfieldQueryResponse(skuId);
|
|
||||||
if (response == null || response.getQueryResult() == null) {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
BigfieldQueryResult queryResult = response.getQueryResult();
|
|
||||||
if (queryResult.getCode() != 200) {
|
// 修改parseSkuFromUrl方法提取SKU
|
||||||
|
private String parseSkuFromUrl(String url) {
|
||||||
|
Matcher m = Pattern.compile("item.jd.com/(\\d+).html").matcher(url);
|
||||||
|
return m.find() ? m.group(1) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigfieldQueryResult queryProductInfo(String skuId) throws Exception {
|
||||||
|
UnionOpenGoodsBigfieldQueryResponse response = getUnionOpenGoodsBigfieldQueryResponse(skuId);
|
||||||
|
if (response == null || response.getQueryResult() == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
BigfieldQueryResult queryResult = response.getQueryResult();
|
||||||
|
if (queryResult.getCode() != 200) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return queryResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 新增礼金创建方法
|
||||||
|
public String createGiftCoupon(String skuId, double amount, int quantity, String owner) throws Exception {
|
||||||
|
|
||||||
|
logger.debug("准备创建礼金:SKU={}, 金额={}元,数量={}, Owner={}", skuId, amount, quantity, owner); // 新增
|
||||||
|
|
||||||
|
JdClient client = new DefaultJdClient(SERVER_URL, ACCESS_TOKEN, LPF_APP_KEY_WZ, LPF_APP_KEY_WZ);
|
||||||
|
|
||||||
|
UnionOpenCouponGiftGetRequest request = new UnionOpenCouponGiftGetRequest();
|
||||||
|
CreateGiftCouponReq couponReq = new CreateGiftCouponReq();
|
||||||
|
couponReq.setSkuMaterialId(skuId); // 使用SKU或链接
|
||||||
|
couponReq.setDiscount(amount);
|
||||||
|
couponReq.setAmount(quantity);
|
||||||
|
//owner g=自营,p=pop
|
||||||
|
// 自营的只能设置一天,pop的只能设置7天,默认为自营
|
||||||
|
String startTime;
|
||||||
|
String endTime;
|
||||||
|
if ("pop".equals(owner)) {
|
||||||
|
startTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH"));
|
||||||
|
endTime = LocalDateTime.now().plusDays(6).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH"));
|
||||||
|
} else {
|
||||||
|
startTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH"));
|
||||||
|
endTime = LocalDateTime.now().plusDays(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH"));
|
||||||
|
|
||||||
|
}
|
||||||
|
couponReq.setReceiveStartTime(startTime);
|
||||||
|
couponReq.setReceiveEndTime(endTime);
|
||||||
|
couponReq.setEffectiveDays(7);
|
||||||
|
couponReq.setIsSpu(1);
|
||||||
|
couponReq.setExpireType(1);
|
||||||
|
couponReq.setShare(-1);
|
||||||
|
couponReq.setCouponTitle(skuId);
|
||||||
|
couponReq.setContentMatch(1);
|
||||||
|
|
||||||
|
request.setCouponReq(couponReq);
|
||||||
|
request.setVersion("1.0");
|
||||||
|
request.setSignmethod("md5");
|
||||||
|
request.setTimestamp(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
|
||||||
|
|
||||||
|
logger.debug("请求参数:{}", request); // 新增
|
||||||
|
|
||||||
|
UnionOpenCouponGiftGetResponse response = client.execute(request);
|
||||||
|
logger.debug("API响应:{}", response); // 新增
|
||||||
|
|
||||||
|
if ("200".equals(response.getCode())) {
|
||||||
|
String giftKey = response.getGetResult().getData().getGiftCouponKey();
|
||||||
|
logger.debug("礼金创建成功:批次ID={}, 返回数据:{}", giftKey, response.getGetResult().getData()); // 新增
|
||||||
|
return giftKey;
|
||||||
|
} else {
|
||||||
|
logger.error("礼金创建失败:错误码={}, 错误信息={}", response.getCode(), response.getMsg()); // 新增
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return queryResult;
|
// 修改activateGiftMoney方法调用真实接口
|
||||||
}
|
private boolean activateGiftMoney(String skuId, double amount, int quantity, String owner) {
|
||||||
|
try {
|
||||||
|
String giftKey = createGiftCoupon(skuId, amount, quantity, owner);
|
||||||
// 新增礼金创建方法
|
if (giftKey != null) {
|
||||||
public String createGiftCoupon(String skuId, double amount, int quantity,String owner) throws Exception {
|
// 可在此处保存礼金批次ID到用户状态
|
||||||
|
return true;
|
||||||
logger.debug("准备创建礼金:SKU={}, 金额={}元,数量={}, Owner={}", skuId, amount, quantity, owner); // 新增
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
JdClient client = new DefaultJdClient(SERVER_URL, ACCESS_TOKEN, LPF_APP_KEY_WZ, LPF_APP_KEY_WZ);
|
logger.error("礼金创建失败", e);
|
||||||
|
|
||||||
UnionOpenCouponGiftGetRequest request = new UnionOpenCouponGiftGetRequest();
|
|
||||||
CreateGiftCouponReq couponReq = new CreateGiftCouponReq();
|
|
||||||
couponReq.setSkuMaterialId(skuId); // 使用SKU或链接
|
|
||||||
couponReq.setDiscount(amount);
|
|
||||||
couponReq.setAmount(quantity);
|
|
||||||
//owner g=自营,p=pop
|
|
||||||
// 自营的只能设置一天,pop的只能设置7天,默认为自营
|
|
||||||
String startTime;
|
|
||||||
String endTime;
|
|
||||||
if ("pop".equals(owner)){
|
|
||||||
startTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH"));
|
|
||||||
endTime = LocalDateTime.now().plusDays(6).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH"));
|
|
||||||
} else {
|
|
||||||
startTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH"));
|
|
||||||
endTime = LocalDateTime.now().plusDays(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH"));
|
|
||||||
|
|
||||||
}
|
|
||||||
couponReq.setReceiveStartTime(startTime);
|
|
||||||
couponReq.setReceiveEndTime(endTime);
|
|
||||||
couponReq.setEffectiveDays(7);
|
|
||||||
couponReq.setIsSpu(1);
|
|
||||||
couponReq.setExpireType(1);
|
|
||||||
couponReq.setShare(-1);
|
|
||||||
couponReq.setCouponTitle(skuId);
|
|
||||||
couponReq.setContentMatch(1);
|
|
||||||
|
|
||||||
request.setCouponReq(couponReq);
|
|
||||||
request.setVersion("1.0");
|
|
||||||
request.setSignmethod("md5");
|
|
||||||
request.setTimestamp(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
|
|
||||||
|
|
||||||
logger.debug("请求参数:{}", request); // 新增
|
|
||||||
|
|
||||||
UnionOpenCouponGiftGetResponse response = client.execute(request);
|
|
||||||
logger.debug("API响应:{}", response); // 新增
|
|
||||||
|
|
||||||
if ("200".equals(response.getCode())) {
|
|
||||||
String giftKey = response.getGetResult().getData().getGiftCouponKey();
|
|
||||||
logger.debug("礼金创建成功:批次ID={}, 返回数据:{}", giftKey, response.getGetResult().getData()); // 新增
|
|
||||||
return giftKey;
|
|
||||||
} else {
|
|
||||||
logger.error("礼金创建失败:错误码={}, 错误信息={}", response.getCode(), response.getMsg()); // 新增
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 修改activateGiftMoney方法调用真实接口
|
|
||||||
private boolean activateGiftMoney(String skuId, double amount, int quantity,String owner) {
|
|
||||||
try {
|
|
||||||
String giftKey = createGiftCoupon(skuId, amount, quantity,owner);
|
|
||||||
if (giftKey != null) {
|
|
||||||
// 可在此处保存礼金批次ID到用户状态
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
return false;
|
||||||
logger.error("礼金创建失败", e);
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 新增礼金停止方法(可选)
|
// 新增礼金停止方法(可选)
|
||||||
public boolean stopGiftCoupon(String giftKey) throws Exception {
|
public boolean stopGiftCoupon(String giftKey) throws Exception {
|
||||||
JdClient client = new DefaultJdClient(SERVER_URL, ACCESS_TOKEN, LPF_APP_KEY_WZ, LPF_APP_KEY_WZ);
|
JdClient client = new DefaultJdClient(SERVER_URL, ACCESS_TOKEN, LPF_APP_KEY_WZ, LPF_APP_KEY_WZ);
|
||||||
|
|
||||||
|
|
||||||
UnionOpenCouponGiftStopRequest request = new UnionOpenCouponGiftStopRequest();
|
UnionOpenCouponGiftStopRequest request = new UnionOpenCouponGiftStopRequest();
|
||||||
StopGiftCouponReq couponReq = new StopGiftCouponReq();
|
StopGiftCouponReq couponReq = new StopGiftCouponReq();
|
||||||
couponReq.setGiftCouponKey(giftKey);
|
couponReq.setGiftCouponKey(giftKey);
|
||||||
|
|
||||||
request.setCouponReq(couponReq);
|
request.setCouponReq(couponReq);
|
||||||
request.setVersion("1.0");
|
request.setVersion("1.0");
|
||||||
request.setSignmethod("md5");
|
request.setSignmethod("md5");
|
||||||
request.setTimestamp(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
|
request.setTimestamp(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
|
||||||
|
|
||||||
UnionOpenCouponGiftStopResponse response = client.execute(request);
|
UnionOpenCouponGiftStopResponse response = client.execute(request);
|
||||||
return "200".equals(response.getCode());
|
return "200".equals(response.getCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private boolean isValidAmount(String input) {
|
||||||
private boolean isValidAmount(String input) {
|
// 新增:直接处理 null 或空字符串
|
||||||
if (Util.isNotEmpty(input)) {
|
if (input == null || input.trim().isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
double amount = Double.parseDouble(input);
|
double amount = Double.parseDouble(input);
|
||||||
// 校验是否为两位小数(可选)
|
return amount > 1 && amount <= 50;
|
||||||
BigDecimal bd = new BigDecimal(input);
|
|
||||||
if (bd.scale() > 2) return false; // 精度超过两位返回 false
|
|
||||||
return amount >= 1 && amount <= 50;
|
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private boolean isValidQuantity(String input) {
|
private boolean isValidQuantity(String input) {
|
||||||
@@ -1027,6 +1006,7 @@ private boolean isValidAmount(String input) {
|
|||||||
private Map<String, String> collectedFields; // 用于存储收集到的字段值
|
private Map<String, String> collectedFields; // 用于存储收集到的字段值
|
||||||
private String currentField; // 当前正在询问的字段
|
private String currentField; // 当前正在询问的字段
|
||||||
private ProductOrderStep currentProductOrderStep;
|
private ProductOrderStep currentProductOrderStep;
|
||||||
|
|
||||||
public UserInteractionState() {
|
public UserInteractionState() {
|
||||||
this.lastInteractionTime = LocalDateTime.now().format(DATE_TIME_FORMATTER);
|
this.lastInteractionTime = LocalDateTime.now().format(DATE_TIME_FORMATTER);
|
||||||
this.currentState = INIT;
|
this.currentState = INIT;
|
||||||
@@ -1039,13 +1019,14 @@ private boolean isValidAmount(String input) {
|
|||||||
this.lastInteractionTime = LocalDateTime.now().format(DATE_TIME_FORMATTER);
|
this.lastInteractionTime = LocalDateTime.now().format(DATE_TIME_FORMATTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
// UserInteractionState类缺少reset方法
|
public void reset() {
|
||||||
public void reset() {
|
this.currentState = INIT;
|
||||||
this.currentState = INIT;
|
this.collectedFields.clear();
|
||||||
this.collectedFields.clear();
|
this.currentStep = STEP_PRODUCT_LINK; // 明确重置步骤
|
||||||
this.currentStep = null;
|
this.currentProductOrderStep = null;
|
||||||
updateLastInteractionTime();
|
updateLastInteractionTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 推荐使用枚举管理状态
|
// 推荐使用枚举管理状态
|
||||||
public enum ProcessState {
|
public enum ProcessState {
|
||||||
@@ -1058,11 +1039,7 @@ private boolean isValidAmount(String input) {
|
|||||||
|
|
||||||
// 在UserInteractionState类中新增步骤枚举
|
// 在UserInteractionState类中新增步骤枚举
|
||||||
public enum ProductOrderStep {
|
public enum ProductOrderStep {
|
||||||
STEP_ORDER_ID,
|
STEP_ORDER_ID, STEP_PRODUCT_INFO, STEP_RECIPIENT_INFO, STEP_REVIEW_CONFIRM, STEP_CASHBACK_TRACK
|
||||||
STEP_PRODUCT_INFO,
|
|
||||||
STEP_RECIPIENT_INFO,
|
|
||||||
STEP_REVIEW_CONFIRM,
|
|
||||||
STEP_CASHBACK_TRACK
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user