This commit is contained in:
2025-11-01 12:42:03 +08:00
parent f24cc851f0
commit b5f74c465d
6 changed files with 183 additions and 9 deletions

View File

@@ -11,6 +11,8 @@ import com.ruoyi.jarvis.domain.JDOrder;
import com.ruoyi.jarvis.domain.OrderRows;
import com.ruoyi.jarvis.service.IJDOrderService;
import com.ruoyi.jarvis.service.IOrderRowsService;
import com.ruoyi.jarvis.service.IGiftCouponService;
import com.ruoyi.jarvis.domain.GiftCoupon;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -34,10 +36,12 @@ public class JDOrderController extends BaseController {
private final IJDOrderService jdOrderService;
private final IOrderRowsService orderRowsService;
private final IGiftCouponService giftCouponService;
public JDOrderController(IJDOrderService jdOrderService, IOrderRowsService orderRowsService) {
public JDOrderController(IJDOrderService jdOrderService, IOrderRowsService orderRowsService, IGiftCouponService giftCouponService) {
this.jdOrderService = jdOrderService;
this.orderRowsService = orderRowsService;
this.giftCouponService = giftCouponService;
}
private final static String skey = "2192057370ef8140c201079969c956a3";
@@ -216,6 +220,55 @@ public class JDOrderController extends BaseController {
}
logger.info("创建礼金成功 - giftCouponKey: {}, 请求参数: owner={}, skuId={}", giftKey, body.get("owner"), body.get("skuId"));
// 保存礼金信息到数据库,以便立即在列表中显示
try {
GiftCoupon giftCoupon = new GiftCoupon();
giftCoupon.setGiftCouponKey((String) giftKey);
// 优先使用skuId如果没有则尝试从materialUrl提取
String skuId = (String) body.get("skuId");
if (skuId == null || skuId.trim().isEmpty()) {
String materialUrl = (String) body.get("materialUrl");
if (materialUrl != null && !materialUrl.trim().isEmpty()) {
// 尝试从URL中提取SKU ID简单提取如 item.jd.com/123456.html
java.util.regex.Pattern pattern = java.util.regex.Pattern.compile("(?:item\\.jd\\.com|jd\\.com)/(\\d+)", java.util.regex.Pattern.CASE_INSENSITIVE);
java.util.regex.Matcher matcher = pattern.matcher(materialUrl);
if (matcher.find()) {
skuId = matcher.group(1);
} else if (materialUrl.matches("^\\d+$")) {
// 如果是纯数字直接作为SKU ID
skuId = materialUrl;
}
}
}
giftCoupon.setSkuId(skuId);
giftCoupon.setSkuName((String) body.get("skuName"));
giftCoupon.setOwner((String) body.get("owner"));
Object amountObj = body.get("amount");
if (amountObj != null) {
giftCoupon.setAmount(Double.parseDouble(String.valueOf(amountObj)));
}
Object quantityObj = body.get("quantity");
if (quantityObj != null) {
giftCoupon.setQuantity(Integer.parseInt(String.valueOf(quantityObj)));
}
giftCoupon.setCreateTime(new java.util.Date());
// 设置过期时间自营1天POP 7天
java.util.Calendar cal = java.util.Calendar.getInstance();
if ("pop".equalsIgnoreCase((String) body.get("owner"))) {
cal.add(java.util.Calendar.DAY_OF_YEAR, 7);
} else {
cal.add(java.util.Calendar.DAY_OF_YEAR, 1);
}
giftCoupon.setExpireTime(cal.getTime());
giftCouponService.insertGiftCoupon(giftCoupon);
logger.info("礼金信息已保存到数据库: giftCouponKey={}", giftKey);
} catch (Exception e) {
logger.error("保存礼金信息到数据库失败", e);
// 不中断流程,继续返回成功
}
}
return AjaxResult.success(parsed);