1
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -23,4 +23,14 @@ public interface GiftCouponMapper {
|
||||
*/
|
||||
GiftCoupon selectGiftCouponStatistics(GiftCoupon giftCoupon);
|
||||
|
||||
/**
|
||||
* 新增礼金信息
|
||||
*/
|
||||
int insertGiftCoupon(GiftCoupon giftCoupon);
|
||||
|
||||
/**
|
||||
* 根据礼金Key更新礼金信息
|
||||
*/
|
||||
int updateGiftCoupon(GiftCoupon giftCoupon);
|
||||
|
||||
}
|
||||
|
||||
@@ -23,4 +23,13 @@ public interface IGiftCouponService {
|
||||
*/
|
||||
GiftCoupon selectGiftCouponStatistics(GiftCoupon giftCoupon);
|
||||
|
||||
/**
|
||||
* 新增礼金信息
|
||||
*/
|
||||
int insertGiftCoupon(GiftCoupon giftCoupon);
|
||||
|
||||
/**
|
||||
* 更新礼金信息
|
||||
*/
|
||||
int updateGiftCoupon(GiftCoupon giftCoupon);
|
||||
}
|
||||
|
||||
@@ -32,4 +32,13 @@ public class GiftCouponServiceImpl implements IGiftCouponService {
|
||||
return giftCouponMapper.selectGiftCouponStatistics(giftCoupon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insertGiftCoupon(GiftCoupon giftCoupon) {
|
||||
return giftCouponMapper.insertGiftCoupon(giftCoupon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateGiftCoupon(GiftCoupon giftCoupon) {
|
||||
return giftCouponMapper.updateGiftCoupon(giftCoupon);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,26 +23,27 @@
|
||||
MAX(sku_id) as sku_id,
|
||||
MAX(sku_name) as sku_name,
|
||||
MAX(owner) as owner,
|
||||
COUNT(DISTINCT order_id) as use_count,
|
||||
SUM(gift_coupon_ocs_amount) as total_ocs_amount,
|
||||
MIN(order_time) as create_time,
|
||||
COALESCE(SUM(use_count), 0) as use_count,
|
||||
COALESCE(SUM(total_ocs_amount), 0) as total_ocs_amount,
|
||||
MIN(create_time) as create_time,
|
||||
MAX(expire_time) as expire_time,
|
||||
CASE
|
||||
WHEN MAX(expire_time) IS NOT NULL AND MAX(expire_time) < NOW() THEN 1
|
||||
ELSE 0
|
||||
END as is_expired
|
||||
FROM (
|
||||
-- 从order_rows表聚合已使用的礼金数据
|
||||
SELECT
|
||||
or_rows.gift_coupon_key,
|
||||
or_rows.sku_id,
|
||||
CAST(or_rows.sku_id AS CHAR) as sku_id,
|
||||
or_rows.sku_name,
|
||||
CASE
|
||||
WHEN or_rows.pop_id IS NULL OR or_rows.pop_id = '' THEN 'g'
|
||||
ELSE 'pop'
|
||||
END as owner,
|
||||
or_rows.order_id,
|
||||
or_rows.gift_coupon_ocs_amount,
|
||||
or_rows.order_time,
|
||||
COUNT(DISTINCT or_rows.order_id) as use_count,
|
||||
COALESCE(SUM(or_rows.gift_coupon_ocs_amount), 0) as total_ocs_amount,
|
||||
MIN(or_rows.order_time) as create_time,
|
||||
NULL as expire_time
|
||||
FROM order_rows or_rows
|
||||
WHERE or_rows.gift_coupon_key IS NOT NULL AND or_rows.gift_coupon_key != ''
|
||||
@@ -50,7 +51,7 @@
|
||||
AND or_rows.gift_coupon_key like concat('%', #{giftCouponKey}, '%')
|
||||
</if>
|
||||
<if test="skuId != null and skuId != ''">
|
||||
AND or_rows.sku_id like concat('%', #{skuId}, '%')
|
||||
AND CAST(or_rows.sku_id AS CHAR) like concat('%', #{skuId}, '%')
|
||||
</if>
|
||||
<if test="skuName != null and skuName != ''">
|
||||
AND or_rows.sku_name like concat('%', #{skuName}, '%')
|
||||
@@ -67,6 +68,40 @@
|
||||
<if test="params.endTime != null and params.endTime != ''">
|
||||
AND or_rows.order_time <= #{params.endTime}
|
||||
</if>
|
||||
GROUP BY or_rows.gift_coupon_key
|
||||
|
||||
UNION ALL
|
||||
|
||||
-- 从gift_coupon表获取所有创建的礼金(包括未使用的)
|
||||
SELECT
|
||||
gc.gift_coupon_key,
|
||||
gc.sku_id,
|
||||
gc.sku_name,
|
||||
gc.owner,
|
||||
0 as use_count,
|
||||
0 as total_ocs_amount,
|
||||
gc.create_time,
|
||||
gc.expire_time
|
||||
FROM gift_coupon gc
|
||||
WHERE 1=1
|
||||
<if test="giftCouponKey != null and giftCouponKey != ''">
|
||||
AND gc.gift_coupon_key like concat('%', #{giftCouponKey}, '%')
|
||||
</if>
|
||||
<if test="skuId != null and skuId != ''">
|
||||
AND gc.sku_id like concat('%', #{skuId}, '%')
|
||||
</if>
|
||||
<if test="skuName != null and skuName != ''">
|
||||
AND gc.sku_name like concat('%', #{skuName}, '%')
|
||||
</if>
|
||||
<if test="owner != null and owner != ''">
|
||||
AND gc.owner = #{owner}
|
||||
</if>
|
||||
<if test="params.beginTime != null and params.beginTime != ''">
|
||||
AND gc.create_time >= #{params.beginTime}
|
||||
</if>
|
||||
<if test="params.endTime != null and params.endTime != ''">
|
||||
AND gc.create_time <= #{params.endTime}
|
||||
</if>
|
||||
) gc
|
||||
GROUP BY gift_coupon_key
|
||||
<if test="isExpired != null">
|
||||
@@ -125,4 +160,46 @@
|
||||
) stats
|
||||
</select>
|
||||
|
||||
<insert id="insertGiftCoupon" parameterType="GiftCoupon">
|
||||
INSERT INTO gift_coupon (
|
||||
gift_coupon_key,
|
||||
sku_id,
|
||||
sku_name,
|
||||
owner,
|
||||
amount,
|
||||
quantity,
|
||||
create_time,
|
||||
expire_time
|
||||
) VALUES (
|
||||
#{giftCouponKey},
|
||||
#{skuId},
|
||||
#{skuName},
|
||||
#{owner},
|
||||
#{amount},
|
||||
#{quantity},
|
||||
#{createTime},
|
||||
#{expireTime}
|
||||
)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
sku_id = VALUES(sku_id),
|
||||
sku_name = VALUES(sku_name),
|
||||
owner = VALUES(owner),
|
||||
amount = VALUES(amount),
|
||||
quantity = VALUES(quantity),
|
||||
expire_time = VALUES(expire_time)
|
||||
</insert>
|
||||
|
||||
<update id="updateGiftCoupon" parameterType="GiftCoupon">
|
||||
UPDATE gift_coupon
|
||||
<set>
|
||||
<if test="skuId != null and skuId != ''">sku_id = #{skuId},</if>
|
||||
<if test="skuName != null and skuName != ''">sku_name = #{skuName},</if>
|
||||
<if test="owner != null and owner != ''">owner = #{owner},</if>
|
||||
<if test="amount != null">amount = #{amount},</if>
|
||||
<if test="quantity != null">quantity = #{quantity},</if>
|
||||
<if test="expireTime != null">expire_time = #{expireTime},</if>
|
||||
</set>
|
||||
WHERE gift_coupon_key = #{giftCouponKey}
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
|
||||
16
sql/gift_coupon_table.sql
Normal file
16
sql/gift_coupon_table.sql
Normal file
@@ -0,0 +1,16 @@
|
||||
-- 礼金表:存储所有创建的礼金信息
|
||||
CREATE TABLE IF NOT EXISTS `gift_coupon` (
|
||||
`gift_coupon_key` varchar(100) NOT NULL COMMENT '礼金Key(主键)',
|
||||
`sku_id` varchar(50) DEFAULT NULL COMMENT '商品SKU ID',
|
||||
`sku_name` varchar(500) DEFAULT NULL COMMENT '商品名称',
|
||||
`owner` varchar(10) DEFAULT 'g' COMMENT '商品类型(g:自营, pop:POP)',
|
||||
`amount` decimal(10,2) DEFAULT NULL COMMENT '礼金金额(元)',
|
||||
`quantity` int(11) DEFAULT NULL COMMENT '礼金数量',
|
||||
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`expire_time` datetime DEFAULT NULL COMMENT '过期时间',
|
||||
PRIMARY KEY (`gift_coupon_key`),
|
||||
KEY `idx_sku_id` (`sku_id`),
|
||||
KEY `idx_create_time` (`create_time`),
|
||||
KEY `idx_owner` (`owner`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='礼金信息表';
|
||||
|
||||
Reference in New Issue
Block a user