fix(优惠券管理):新增优惠券管理功能模块
This commit is contained in:
+178
@@ -0,0 +1,178 @@
|
|||||||
|
package com.central.order.controller;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.central.common.model.Result;
|
||||||
|
import com.central.order.entity.Coupon;
|
||||||
|
import com.central.order.service.ICouponService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 优惠券管理控制器
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/coupon")
|
||||||
|
@Tag(name = "优惠券管理")
|
||||||
|
public class CouponController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ICouponService couponService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询优惠券列表
|
||||||
|
*/
|
||||||
|
@GetMapping("/page")
|
||||||
|
@Operation(summary = "分页查询优惠券列表")
|
||||||
|
public Result<IPage<Coupon>> getCouponPage(
|
||||||
|
@Parameter(description = "页码") @RequestParam(defaultValue = "1") Integer current,
|
||||||
|
@Parameter(description = "每页大小") @RequestParam(defaultValue = "10") Integer size,
|
||||||
|
@Parameter(description = "优惠券名称") @RequestParam(required = false) String couponName,
|
||||||
|
@Parameter(description = "优惠券类型") @RequestParam(required = false) Integer couponType,
|
||||||
|
@Parameter(description = "状态") @RequestParam(required = false) Integer status,
|
||||||
|
@Parameter(description = "用户手机号") @RequestParam(required = false) String userPhone,
|
||||||
|
@Parameter(description = "来源") @RequestParam(required = false) Integer source) {
|
||||||
|
|
||||||
|
Page<Coupon> page = new Page<>(current, size);
|
||||||
|
Coupon coupon = new Coupon();
|
||||||
|
coupon.setCouponName(couponName);
|
||||||
|
coupon.setCouponType(couponType);
|
||||||
|
coupon.setStatus(status);
|
||||||
|
coupon.setUserPhone(userPhone);
|
||||||
|
coupon.setSource(source);
|
||||||
|
|
||||||
|
IPage<Coupon> result = couponService.getCouponPage(page, coupon);
|
||||||
|
return Result.succeed(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID查询优惠券
|
||||||
|
*/
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
@Operation(summary = "根据ID查询优惠券")
|
||||||
|
public Result<Coupon> getCouponById(@Parameter(description = "优惠券ID") @PathVariable Long id) {
|
||||||
|
Coupon coupon = couponService.getById(id);
|
||||||
|
return Result.succeed(coupon);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建优惠券
|
||||||
|
*/
|
||||||
|
@PostMapping
|
||||||
|
@Operation(summary = "创建优惠券")
|
||||||
|
public Result<Boolean> createCoupon(@RequestBody Coupon coupon) {
|
||||||
|
boolean result = couponService.createCoupon(coupon);
|
||||||
|
return Result.succeed(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新优惠券
|
||||||
|
*/
|
||||||
|
@PutMapping("/{id}")
|
||||||
|
@Operation(summary = "更新优惠券")
|
||||||
|
public Result<Boolean> updateCoupon(@Parameter(description = "优惠券ID") @PathVariable Long id, @RequestBody Coupon coupon) {
|
||||||
|
coupon.setId(id);
|
||||||
|
boolean result = couponService.updateCoupon(coupon);
|
||||||
|
return Result.succeed(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除优惠券
|
||||||
|
*/
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
@Operation(summary = "删除优惠券")
|
||||||
|
public Result<Boolean> deleteCoupon(@Parameter(description = "优惠券ID") @PathVariable Long id) {
|
||||||
|
boolean result = couponService.deleteCoupon(id);
|
||||||
|
return Result.succeed(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据手机号查询用户优惠券
|
||||||
|
*/
|
||||||
|
@GetMapping("/user/{userPhone}")
|
||||||
|
@Operation(summary = "根据手机号查询用户优惠券")
|
||||||
|
public Result<List<Coupon>> getCouponsByUserPhone(@Parameter(description = "用户手机号") @PathVariable String userPhone) {
|
||||||
|
List<Coupon> coupons = couponService.getCouponsByUserPhone(userPhone);
|
||||||
|
return Result.succeed(coupons);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据手机号查询可用优惠券
|
||||||
|
*/
|
||||||
|
@GetMapping("/user/{userPhone}/available")
|
||||||
|
@Operation(summary = "根据手机号查询可用优惠券")
|
||||||
|
public Result<List<Coupon>> getAvailableCouponsByUserPhone(@Parameter(description = "用户手机号") @PathVariable String userPhone) {
|
||||||
|
List<Coupon> coupons = couponService.getAvailableCouponsByUserPhone(userPhone);
|
||||||
|
return Result.succeed(coupons);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用优惠券
|
||||||
|
*/
|
||||||
|
@PostMapping("/{id}/use")
|
||||||
|
@Operation(summary = "使用优惠券")
|
||||||
|
public Result<Boolean> useCoupon(
|
||||||
|
@Parameter(description = "优惠券ID") @PathVariable Long id,
|
||||||
|
@Parameter(description = "订单号") @RequestParam String orderNo) {
|
||||||
|
boolean result = couponService.useCoupon(id, orderNo);
|
||||||
|
return Result.succeed(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 携程创建优惠券接口
|
||||||
|
*/
|
||||||
|
@PostMapping("/ctrip/create")
|
||||||
|
@Operation(summary = "携程创建优惠券接口")
|
||||||
|
public Result<Boolean> createCouponFromCtrip(
|
||||||
|
@Parameter(description = "携程优惠券ID") @RequestParam String ctripCouponId,
|
||||||
|
@Parameter(description = "用户手机号") @RequestParam String userPhone,
|
||||||
|
@Parameter(description = "优惠券名称") @RequestParam String couponName,
|
||||||
|
@Parameter(description = "优惠券类型") @RequestParam Integer couponType,
|
||||||
|
@Parameter(description = "优惠券面额") @RequestParam BigDecimal amount,
|
||||||
|
@Parameter(description = "使用门槛金额") @RequestParam(required = false) BigDecimal minAmount,
|
||||||
|
@Parameter(description = "折扣率") @RequestParam(required = false) Integer discountRate,
|
||||||
|
@Parameter(description = "有效期开始时间") @RequestParam String validStartTime,
|
||||||
|
@Parameter(description = "有效期结束时间") @RequestParam String validEndTime) {
|
||||||
|
|
||||||
|
// 这里需要根据实际的时间格式进行解析
|
||||||
|
// 暂时使用当前时间,实际应该解析传入的时间字符串
|
||||||
|
Date startTime = new Date();
|
||||||
|
Date endTime = new Date();
|
||||||
|
|
||||||
|
boolean result = couponService.createCouponFromCtrip(ctripCouponId, userPhone, couponName,
|
||||||
|
couponType, amount, minAmount, discountRate,
|
||||||
|
startTime, endTime);
|
||||||
|
return Result.succeed(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 核销携程优惠券
|
||||||
|
*/
|
||||||
|
@PostMapping("/ctrip/verify")
|
||||||
|
@Operation(summary = "核销携程优惠券")
|
||||||
|
public Result<Boolean> verifyCtripCoupon(
|
||||||
|
@Parameter(description = "携程优惠券ID") @RequestParam String ctripCouponId,
|
||||||
|
@Parameter(description = "订单号") @RequestParam String orderNo) {
|
||||||
|
boolean result = couponService.verifyCtripCoupon(ctripCouponId, orderNo);
|
||||||
|
return Result.succeed(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量更新过期优惠券
|
||||||
|
*/
|
||||||
|
@PostMapping("/update-expired")
|
||||||
|
@Operation(summary = "批量更新过期优惠券")
|
||||||
|
public Result<Void> updateExpiredCoupons() {
|
||||||
|
couponService.updateExpiredCoupons();
|
||||||
|
return Result.succeed("批量更新过期优惠券成功");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,138 @@
|
|||||||
|
package com.central.order.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 优惠券实体类
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@TableName("t_coupon")
|
||||||
|
public class Coupon implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键ID
|
||||||
|
*/
|
||||||
|
@TableId(value = "id", type = IdType.AUTO)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 优惠券编号
|
||||||
|
*/
|
||||||
|
private String couponNo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 优惠券名称
|
||||||
|
*/
|
||||||
|
private String couponName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 优惠券类型:1-满减券,2-折扣券,3-免费券
|
||||||
|
*/
|
||||||
|
private Integer couponType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 优惠券面额
|
||||||
|
*/
|
||||||
|
private BigDecimal amount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用门槛金额
|
||||||
|
*/
|
||||||
|
private BigDecimal minAmount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 折扣率(0-100,折扣券时使用)
|
||||||
|
*/
|
||||||
|
private Integer discountRate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 优惠券状态:0-未使用,1-已使用,2-已过期,3-已作废
|
||||||
|
*/
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户手机号
|
||||||
|
*/
|
||||||
|
private String userPhone;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户ID
|
||||||
|
*/
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 来源:1-携程,2-高飞自建
|
||||||
|
*/
|
||||||
|
private Integer source;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 携程优惠券ID(来源为携程时使用)
|
||||||
|
*/
|
||||||
|
private String ctripCouponId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 有效期开始时间
|
||||||
|
*/
|
||||||
|
private Date validStartTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 有效期结束时间
|
||||||
|
*/
|
||||||
|
private Date validEndTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用时间
|
||||||
|
*/
|
||||||
|
private Date usedTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用订单号
|
||||||
|
*/
|
||||||
|
private String usedOrderNo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
@TableField(fill = FieldFill.INSERT)
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新时间
|
||||||
|
*/
|
||||||
|
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||||
|
private Date updateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 租户ID
|
||||||
|
*/
|
||||||
|
private String tenantId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建人
|
||||||
|
*/
|
||||||
|
private String createBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新人
|
||||||
|
*/
|
||||||
|
private String updateBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备注
|
||||||
|
*/
|
||||||
|
private String remark;
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package com.central.order.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.central.order.entity.Coupon;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 优惠券Mapper接口
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface CouponMapper extends BaseMapper<Coupon> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询优惠券列表
|
||||||
|
*/
|
||||||
|
IPage<Coupon> selectCouponPage(Page<Coupon> page, @Param("coupon") Coupon coupon);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据手机号查询用户优惠券
|
||||||
|
*/
|
||||||
|
List<Coupon> selectByUserPhone(@Param("userPhone") String userPhone);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据手机号查询可用优惠券
|
||||||
|
*/
|
||||||
|
List<Coupon> selectAvailableByUserPhone(@Param("userPhone") String userPhone);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据携程优惠券ID查询
|
||||||
|
*/
|
||||||
|
Coupon selectByCtripCouponId(@Param("ctripCouponId") String ctripCouponId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据订单号查询使用的优惠券
|
||||||
|
*/
|
||||||
|
Coupon selectByUsedOrderNo(@Param("usedOrderNo") String usedOrderNo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新优惠券状态为已使用
|
||||||
|
*/
|
||||||
|
int updateCouponUsed(@Param("id") Long id, @Param("usedOrderNo") String usedOrderNo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量更新过期优惠券状态
|
||||||
|
*/
|
||||||
|
int updateExpiredCoupons();
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package com.central.order.model.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Schema(description = "筛选选项")
|
||||||
|
public class FilterOptions {
|
||||||
|
@Schema(description = "景区列表")
|
||||||
|
private List<OptionItem> tourismList;
|
||||||
|
|
||||||
|
@Schema(description = "二维码列表")
|
||||||
|
private List<OptionItem> qrcodeList;
|
||||||
|
|
||||||
|
@Schema(description = "设备列表")
|
||||||
|
private List<OptionItem> deviceList;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Schema(description = "选项项")
|
||||||
|
public static class OptionItem {
|
||||||
|
@Schema(description = "标签")
|
||||||
|
private String label;
|
||||||
|
|
||||||
|
@Schema(description = "值")
|
||||||
|
private Object value;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
package com.central.order.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.central.order.entity.Coupon;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 优惠券服务接口
|
||||||
|
*/
|
||||||
|
public interface ICouponService extends IService<Coupon> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询优惠券列表
|
||||||
|
*/
|
||||||
|
IPage<Coupon> getCouponPage(Page<Coupon> page, Coupon coupon);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建优惠券
|
||||||
|
*/
|
||||||
|
boolean createCoupon(Coupon coupon);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新优惠券
|
||||||
|
*/
|
||||||
|
boolean updateCoupon(Coupon coupon);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除优惠券
|
||||||
|
*/
|
||||||
|
boolean deleteCoupon(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据手机号查询用户优惠券
|
||||||
|
*/
|
||||||
|
List<Coupon> getCouponsByUserPhone(String userPhone);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据手机号查询可用优惠券
|
||||||
|
*/
|
||||||
|
List<Coupon> getAvailableCouponsByUserPhone(String userPhone);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用优惠券
|
||||||
|
*/
|
||||||
|
boolean useCoupon(Long couponId, String orderNo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据携程优惠券ID创建优惠券(携程接口调用)
|
||||||
|
*/
|
||||||
|
boolean createCouponFromCtrip(String ctripCouponId, String userPhone, String couponName,
|
||||||
|
Integer couponType, java.math.BigDecimal amount,
|
||||||
|
java.math.BigDecimal minAmount, Integer discountRate,
|
||||||
|
java.util.Date validStartTime,
|
||||||
|
java.util.Date validEndTime);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量更新过期优惠券状态
|
||||||
|
*/
|
||||||
|
void updateExpiredCoupons();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 核销携程优惠券
|
||||||
|
*/
|
||||||
|
boolean verifyCtripCoupon(String ctripCouponId, String orderNo);
|
||||||
|
}
|
||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
package com.central.order.service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 携程API服务接口
|
||||||
|
*/
|
||||||
|
public interface ICtripApiService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 核销携程优惠券
|
||||||
|
* @param ctripCouponId 携程优惠券ID
|
||||||
|
* @param orderNo 订单号
|
||||||
|
* @return 是否核销成功
|
||||||
|
*/
|
||||||
|
boolean verifyCoupon(String ctripCouponId, String orderNo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询携程优惠券状态
|
||||||
|
* @param ctripCouponId 携程优惠券ID
|
||||||
|
* @return 优惠券状态
|
||||||
|
*/
|
||||||
|
String getCouponStatus(String ctripCouponId);
|
||||||
|
}
|
||||||
+184
@@ -0,0 +1,184 @@
|
|||||||
|
package com.central.order.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.central.order.entity.Coupon;
|
||||||
|
import com.central.order.mapper.CouponMapper;
|
||||||
|
import com.central.order.service.ICouponService;
|
||||||
|
import com.central.order.service.ICtripApiService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 优惠券服务实现类
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class CouponServiceImpl extends ServiceImpl<CouponMapper, Coupon> implements ICouponService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ICtripApiService ctripApiService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IPage<Coupon> getCouponPage(Page<Coupon> page, Coupon coupon) {
|
||||||
|
return baseMapper.selectCouponPage(page, coupon);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public boolean createCoupon(Coupon coupon) {
|
||||||
|
// 生成优惠券编号
|
||||||
|
if (!StringUtils.hasText(coupon.getCouponNo())) {
|
||||||
|
coupon.setCouponNo(generateCouponNo());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置默认值
|
||||||
|
if (coupon.getStatus() == null) {
|
||||||
|
coupon.setStatus(0); // 未使用
|
||||||
|
}
|
||||||
|
if (coupon.getCreateTime() == null) {
|
||||||
|
coupon.setCreateTime(new Date());
|
||||||
|
}
|
||||||
|
if (coupon.getUpdateTime() == null) {
|
||||||
|
coupon.setUpdateTime(new Date());
|
||||||
|
}
|
||||||
|
|
||||||
|
return save(coupon);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public boolean updateCoupon(Coupon coupon) {
|
||||||
|
coupon.setUpdateTime(new Date());
|
||||||
|
return updateById(coupon);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public boolean deleteCoupon(Long id) {
|
||||||
|
return removeById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Coupon> getCouponsByUserPhone(String userPhone) {
|
||||||
|
return baseMapper.selectByUserPhone(userPhone);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Coupon> getAvailableCouponsByUserPhone(String userPhone) {
|
||||||
|
return baseMapper.selectAvailableByUserPhone(userPhone);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public boolean useCoupon(Long couponId, String orderNo) {
|
||||||
|
Coupon coupon = getById(couponId);
|
||||||
|
if (coupon == null) {
|
||||||
|
log.error("优惠券不存在,couponId: {}", couponId);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (coupon.getStatus() != 0) {
|
||||||
|
log.error("优惠券状态不正确,couponId: {}, status: {}", couponId, coupon.getStatus());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (coupon.getValidEndTime().before(new Date())) {
|
||||||
|
log.error("优惠券已过期,couponId: {}", couponId);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return baseMapper.updateCouponUsed(couponId, orderNo) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public boolean createCouponFromCtrip(String ctripCouponId, String userPhone, String couponName,
|
||||||
|
Integer couponType, java.math.BigDecimal amount,
|
||||||
|
java.math.BigDecimal minAmount, Integer discountRate,
|
||||||
|
java.util.Date validStartTime,
|
||||||
|
java.util.Date validEndTime) {
|
||||||
|
|
||||||
|
// 检查是否已存在该携程优惠券
|
||||||
|
Coupon existingCoupon = baseMapper.selectByCtripCouponId(ctripCouponId);
|
||||||
|
if (existingCoupon != null) {
|
||||||
|
log.warn("携程优惠券已存在,ctripCouponId: {}", ctripCouponId);
|
||||||
|
return true; // 已存在也算成功
|
||||||
|
}
|
||||||
|
|
||||||
|
Coupon coupon = new Coupon();
|
||||||
|
coupon.setCouponNo(generateCouponNo());
|
||||||
|
coupon.setCouponName(couponName);
|
||||||
|
coupon.setCouponType(couponType);
|
||||||
|
coupon.setAmount(amount);
|
||||||
|
coupon.setMinAmount(minAmount);
|
||||||
|
coupon.setDiscountRate(discountRate);
|
||||||
|
coupon.setStatus(0); // 未使用
|
||||||
|
coupon.setUserPhone(userPhone);
|
||||||
|
coupon.setSource(1); // 来源:携程
|
||||||
|
coupon.setCtripCouponId(ctripCouponId);
|
||||||
|
coupon.setValidStartTime(validStartTime);
|
||||||
|
coupon.setValidEndTime(validEndTime);
|
||||||
|
coupon.setCreateTime(new Date());
|
||||||
|
coupon.setUpdateTime(new Date());
|
||||||
|
coupon.setCreateBy("ctrip");
|
||||||
|
coupon.setUpdateBy("ctrip");
|
||||||
|
|
||||||
|
return save(coupon);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void updateExpiredCoupons() {
|
||||||
|
int count = baseMapper.updateExpiredCoupons();
|
||||||
|
log.info("批量更新过期优惠券完成,更新数量: {}", count);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public boolean verifyCtripCoupon(String ctripCouponId, String orderNo) {
|
||||||
|
Coupon coupon = baseMapper.selectByCtripCouponId(ctripCouponId);
|
||||||
|
if (coupon == null) {
|
||||||
|
log.error("携程优惠券不存在,ctripCouponId: {}", ctripCouponId);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (coupon.getStatus() != 0) {
|
||||||
|
log.error("携程优惠券状态不正确,ctripCouponId: {}, status: {}", ctripCouponId, coupon.getStatus());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (coupon.getValidEndTime().before(new Date())) {
|
||||||
|
log.error("携程优惠券已过期,ctripCouponId: {}", ctripCouponId);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 调用携程核销接口
|
||||||
|
boolean ctripVerifyResult = ctripApiService.verifyCoupon(ctripCouponId, orderNo);
|
||||||
|
if (!ctripVerifyResult) {
|
||||||
|
log.error("携程核销失败,ctripCouponId: {}, orderNo: {}", ctripCouponId, orderNo);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新本地优惠券状态
|
||||||
|
return baseMapper.updateCouponUsed(coupon.getId(), orderNo) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成优惠券编号
|
||||||
|
*/
|
||||||
|
private String generateCouponNo() {
|
||||||
|
return "CP" + System.currentTimeMillis() + UUID.randomUUID().toString().substring(0, 8).toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+51
@@ -0,0 +1,51 @@
|
|||||||
|
package com.central.order.service.impl;
|
||||||
|
|
||||||
|
import com.central.order.service.ICtripApiService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 携程API服务实现类
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class CtripApiServiceImpl implements ICtripApiService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean verifyCoupon(String ctripCouponId, String orderNo) {
|
||||||
|
// TODO: 实现具体的携程API调用逻辑
|
||||||
|
// 这里需要根据携程的API文档实现具体的调用
|
||||||
|
log.info("调用携程核销接口,ctripCouponId: {}, orderNo: {}", ctripCouponId, orderNo);
|
||||||
|
|
||||||
|
// 模拟API调用
|
||||||
|
try {
|
||||||
|
// 这里应该调用携程的核销API
|
||||||
|
// 例如:HttpClient调用携程的核销接口
|
||||||
|
|
||||||
|
// 暂时返回true,实际需要根据API调用结果返回
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("携程核销接口调用失败", e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCouponStatus(String ctripCouponId) {
|
||||||
|
// TODO: 实现具体的携程API调用逻辑
|
||||||
|
// 这里需要根据携程的API文档实现具体的调用
|
||||||
|
log.info("调用携程查询优惠券状态接口,ctripCouponId: {}", ctripCouponId);
|
||||||
|
|
||||||
|
// 模拟API调用
|
||||||
|
try {
|
||||||
|
// 这里应该调用携程的查询API
|
||||||
|
// 例如:HttpClient调用携程的查询接口
|
||||||
|
|
||||||
|
// 暂时返回"VALID",实际需要根据API调用结果返回
|
||||||
|
return "VALID";
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("携程查询优惠券状态接口调用失败", e);
|
||||||
|
return "UNKNOWN";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+32
@@ -0,0 +1,32 @@
|
|||||||
|
package com.central.order.task;
|
||||||
|
|
||||||
|
import com.central.order.service.ICouponService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 优惠券过期定时任务
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class CouponExpirationTask {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ICouponService couponService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 每天凌晨2点执行,批量更新过期优惠券状态
|
||||||
|
*/
|
||||||
|
@Scheduled(cron = "0 0 2 * * ?")
|
||||||
|
public void updateExpiredCoupons() {
|
||||||
|
log.info("开始执行优惠券过期状态更新任务");
|
||||||
|
try {
|
||||||
|
couponService.updateExpiredCoupons();
|
||||||
|
log.info("优惠券过期状态更新任务执行完成");
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("优惠券过期状态更新任务执行失败", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,124 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.central.order.mapper.CouponMapper">
|
||||||
|
|
||||||
|
<!-- 基础结果映射 -->
|
||||||
|
<resultMap id="BaseResultMap" type="com.central.order.entity.Coupon">
|
||||||
|
<id column="id" property="id" jdbcType="BIGINT"/>
|
||||||
|
<result column="coupon_no" property="couponNo" jdbcType="VARCHAR"/>
|
||||||
|
<result column="coupon_name" property="couponName" jdbcType="VARCHAR"/>
|
||||||
|
<result column="coupon_type" property="couponType" jdbcType="INTEGER"/>
|
||||||
|
<result column="amount" property="amount" jdbcType="DECIMAL"/>
|
||||||
|
<result column="min_amount" property="minAmount" jdbcType="DECIMAL"/>
|
||||||
|
<result column="discount_rate" property="discountRate" jdbcType="INTEGER"/>
|
||||||
|
<result column="status" property="status" jdbcType="INTEGER"/>
|
||||||
|
<result column="user_phone" property="userPhone" jdbcType="VARCHAR"/>
|
||||||
|
<result column="user_id" property="userId" jdbcType="BIGINT"/>
|
||||||
|
<result column="source" property="source" jdbcType="INTEGER"/>
|
||||||
|
<result column="ctrip_coupon_id" property="ctripCouponId" jdbcType="VARCHAR"/>
|
||||||
|
<result column="valid_start_time" property="validStartTime" jdbcType="TIMESTAMP"/>
|
||||||
|
<result column="valid_end_time" property="validEndTime" jdbcType="TIMESTAMP"/>
|
||||||
|
<result column="used_time" property="usedTime" jdbcType="TIMESTAMP"/>
|
||||||
|
<result column="used_order_no" property="usedOrderNo" jdbcType="VARCHAR"/>
|
||||||
|
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
||||||
|
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
|
||||||
|
<result column="create_by" property="createBy" jdbcType="VARCHAR"/>
|
||||||
|
<result column="update_by" property="updateBy" jdbcType="VARCHAR"/>
|
||||||
|
<result column="remark" property="remark" jdbcType="VARCHAR"/>
|
||||||
|
<result column="tenant_id" property="tenantId" jdbcType="VARCHAR"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<!-- 基础字段 -->
|
||||||
|
<sql id="Base_Column_List">
|
||||||
|
id, coupon_no, coupon_name, coupon_type, amount, min_amount, discount_rate, status,
|
||||||
|
user_phone, user_id, source, ctrip_coupon_id, valid_start_time, valid_end_time,
|
||||||
|
used_time, used_order_no, create_time, update_time, create_by, update_by, remark, tenant_id
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
<!-- 分页查询优惠券列表 -->
|
||||||
|
<select id="selectCouponPage" resultMap="BaseResultMap">
|
||||||
|
SELECT
|
||||||
|
<include refid="Base_Column_List"/>
|
||||||
|
FROM t_coupon
|
||||||
|
<where>
|
||||||
|
<if test="coupon.couponName != null and coupon.couponName != ''">
|
||||||
|
AND coupon_name LIKE CONCAT('%', #{coupon.couponName}, '%')
|
||||||
|
</if>
|
||||||
|
<if test="coupon.couponType != null">
|
||||||
|
AND coupon_type = #{coupon.couponType}
|
||||||
|
</if>
|
||||||
|
<if test="coupon.status != null">
|
||||||
|
AND status = #{coupon.status}
|
||||||
|
</if>
|
||||||
|
<if test="coupon.userPhone != null and coupon.userPhone != ''">
|
||||||
|
AND user_phone = #{coupon.userPhone}
|
||||||
|
</if>
|
||||||
|
<if test="coupon.source != null">
|
||||||
|
AND source = #{coupon.source}
|
||||||
|
</if>
|
||||||
|
<if test="coupon.ctripCouponId != null and coupon.ctripCouponId != ''">
|
||||||
|
AND ctrip_coupon_id = #{coupon.ctripCouponId}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
ORDER BY create_time DESC
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- 根据手机号查询用户优惠券 -->
|
||||||
|
<select id="selectByUserPhone" resultMap="BaseResultMap">
|
||||||
|
SELECT
|
||||||
|
<include refid="Base_Column_List"/>
|
||||||
|
FROM t_coupon
|
||||||
|
WHERE user_phone = #{userPhone}
|
||||||
|
ORDER BY create_time DESC
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- 根据手机号查询可用优惠券 -->
|
||||||
|
<select id="selectAvailableByUserPhone" resultMap="BaseResultMap">
|
||||||
|
SELECT
|
||||||
|
<include refid="Base_Column_List"/>
|
||||||
|
FROM t_coupon
|
||||||
|
WHERE user_phone = #{userPhone}
|
||||||
|
AND status = 0
|
||||||
|
AND valid_start_time <= NOW()
|
||||||
|
AND valid_end_time >= NOW()
|
||||||
|
ORDER BY create_time DESC
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- 根据携程优惠券ID查询 -->
|
||||||
|
<select id="selectByCtripCouponId" resultMap="BaseResultMap">
|
||||||
|
SELECT
|
||||||
|
<include refid="Base_Column_List"/>
|
||||||
|
FROM t_coupon
|
||||||
|
WHERE ctrip_coupon_id = #{ctripCouponId}
|
||||||
|
LIMIT 1
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- 根据订单号查询使用的优惠券 -->
|
||||||
|
<select id="selectByUsedOrderNo" resultMap="BaseResultMap">
|
||||||
|
SELECT
|
||||||
|
<include refid="Base_Column_List"/>
|
||||||
|
FROM t_coupon
|
||||||
|
WHERE used_order_no = #{usedOrderNo}
|
||||||
|
LIMIT 1
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- 更新优惠券状态为已使用 -->
|
||||||
|
<update id="updateCouponUsed">
|
||||||
|
UPDATE t_coupon
|
||||||
|
SET status = 1,
|
||||||
|
used_time = NOW(),
|
||||||
|
used_order_no = #{usedOrderNo},
|
||||||
|
update_time = NOW()
|
||||||
|
WHERE id = #{id}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<!-- 批量更新过期优惠券状态 -->
|
||||||
|
<update id="updateExpiredCoupons">
|
||||||
|
UPDATE t_coupon
|
||||||
|
SET status = 2,
|
||||||
|
update_time = NOW()
|
||||||
|
WHERE status = 0
|
||||||
|
AND valid_end_time < NOW()
|
||||||
|
</update>
|
||||||
|
|
||||||
|
</mapper>
|
||||||
@@ -0,0 +1,449 @@
|
|||||||
|
import React, { useState, useEffect } from 'react';
|
||||||
|
import {
|
||||||
|
Card,
|
||||||
|
Table,
|
||||||
|
Button,
|
||||||
|
Space,
|
||||||
|
Modal,
|
||||||
|
Form,
|
||||||
|
Input,
|
||||||
|
Select,
|
||||||
|
DatePicker,
|
||||||
|
InputNumber,
|
||||||
|
message,
|
||||||
|
Popconfirm,
|
||||||
|
Tag,
|
||||||
|
Tooltip,
|
||||||
|
} from 'antd';
|
||||||
|
import { PlusOutlined, EditOutlined, DeleteOutlined, EyeOutlined } from '@ant-design/icons';
|
||||||
|
import { getCouponList, createCoupon, updateCoupon, deleteCoupon, getCouponById } from '@/services/orders/api';
|
||||||
|
import moment from 'moment';
|
||||||
|
|
||||||
|
const { Option } = Select;
|
||||||
|
const { RangePicker } = DatePicker;
|
||||||
|
|
||||||
|
const CouponManagement: React.FC = () => {
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [dataSource, setDataSource] = useState<ORDERS.Coupon[]>([]);
|
||||||
|
const [total, setTotal] = useState(0);
|
||||||
|
const [current, setCurrent] = useState(1);
|
||||||
|
const [pageSize, setPageSize] = useState(10);
|
||||||
|
const [modalVisible, setModalVisible] = useState(false);
|
||||||
|
const [editingCoupon, setEditingCoupon] = useState<ORDERS.Coupon | null>(null);
|
||||||
|
const [form] = Form.useForm();
|
||||||
|
|
||||||
|
// 优惠券类型选项
|
||||||
|
const couponTypeOptions = [
|
||||||
|
{ label: '满减券', value: 1 },
|
||||||
|
{ label: '折扣券', value: 2 },
|
||||||
|
{ label: '免费券', value: 3 },
|
||||||
|
];
|
||||||
|
|
||||||
|
// 优惠券状态选项
|
||||||
|
const statusOptions = [
|
||||||
|
{ label: '未使用', value: 0 },
|
||||||
|
{ label: '已使用', value: 1 },
|
||||||
|
{ label: '已过期', value: 2 },
|
||||||
|
{ label: '已作废', value: 3 },
|
||||||
|
];
|
||||||
|
|
||||||
|
// 来源选项
|
||||||
|
const sourceOptions = [
|
||||||
|
{ label: '携程', value: 1 },
|
||||||
|
{ label: '高飞自建', value: 2 },
|
||||||
|
];
|
||||||
|
|
||||||
|
// 获取优惠券列表
|
||||||
|
const fetchCouponList = async (params?: any) => {
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
const result = await getCouponList({
|
||||||
|
current: params?.current || current,
|
||||||
|
pageSize: params?.pageSize || pageSize,
|
||||||
|
...params,
|
||||||
|
});
|
||||||
|
setDataSource(result.data || []);
|
||||||
|
setTotal(result.total || 0);
|
||||||
|
} catch (error) {
|
||||||
|
message.error('获取优惠券列表失败');
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetchCouponList();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// 表格列定义
|
||||||
|
const columns = [
|
||||||
|
{
|
||||||
|
title: '优惠券编号',
|
||||||
|
dataIndex: 'couponNo',
|
||||||
|
key: 'couponNo',
|
||||||
|
width: 150,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '优惠券名称',
|
||||||
|
dataIndex: 'couponName',
|
||||||
|
key: 'couponName',
|
||||||
|
width: 200,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '优惠券类型',
|
||||||
|
dataIndex: 'couponType',
|
||||||
|
key: 'couponType',
|
||||||
|
width: 100,
|
||||||
|
render: (type: number) => {
|
||||||
|
const option = couponTypeOptions.find(item => item.value === type);
|
||||||
|
return option ? option.label : '-';
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '面额/折扣',
|
||||||
|
key: 'amount',
|
||||||
|
width: 120,
|
||||||
|
render: (record: ORDERS.Coupon) => {
|
||||||
|
if (record.couponType === 2) {
|
||||||
|
return `${record.discountRate}%`;
|
||||||
|
}
|
||||||
|
return `¥${record.amount}`;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '使用门槛',
|
||||||
|
dataIndex: 'minAmount',
|
||||||
|
key: 'minAmount',
|
||||||
|
width: 100,
|
||||||
|
render: (amount: number) => amount ? `¥${amount}` : '-',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '状态',
|
||||||
|
dataIndex: 'status',
|
||||||
|
key: 'status',
|
||||||
|
width: 100,
|
||||||
|
render: (status: number) => {
|
||||||
|
const option = statusOptions.find(item => item.value === status);
|
||||||
|
const color = status === 0 ? 'green' : status === 1 ? 'blue' : status === 2 ? 'orange' : 'red';
|
||||||
|
return option ? <Tag color={color}>{option.label}</Tag> : '-';
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '用户手机号',
|
||||||
|
dataIndex: 'userPhone',
|
||||||
|
key: 'userPhone',
|
||||||
|
width: 130,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '来源',
|
||||||
|
dataIndex: 'source',
|
||||||
|
key: 'source',
|
||||||
|
width: 100,
|
||||||
|
render: (source: number) => {
|
||||||
|
const option = sourceOptions.find(item => item.value === source);
|
||||||
|
return option ? option.label : '-';
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '有效期',
|
||||||
|
key: 'validTime',
|
||||||
|
width: 200,
|
||||||
|
render: (record: ORDERS.Coupon) => (
|
||||||
|
<div>
|
||||||
|
<div>{moment(record.validStartTime).format('YYYY-MM-DD HH:mm')}</div>
|
||||||
|
<div>至</div>
|
||||||
|
<div>{moment(record.validEndTime).format('YYYY-MM-DD HH:mm')}</div>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '创建时间',
|
||||||
|
dataIndex: 'createTime',
|
||||||
|
key: 'createTime',
|
||||||
|
width: 150,
|
||||||
|
render: (time: string) => time ? moment(time).format('YYYY-MM-DD HH:mm') : '-',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
key: 'action',
|
||||||
|
width: 150,
|
||||||
|
fixed: 'right' as const,
|
||||||
|
render: (record: ORDERS.Coupon) => (
|
||||||
|
<Space size="small">
|
||||||
|
<Tooltip title="查看详情">
|
||||||
|
<Button
|
||||||
|
type="link"
|
||||||
|
size="small"
|
||||||
|
icon={<EyeOutlined />}
|
||||||
|
onClick={() => handleView(record)}
|
||||||
|
/>
|
||||||
|
</Tooltip>
|
||||||
|
<Tooltip title="编辑">
|
||||||
|
<Button
|
||||||
|
type="link"
|
||||||
|
size="small"
|
||||||
|
icon={<EditOutlined />}
|
||||||
|
onClick={() => handleEdit(record)}
|
||||||
|
/>
|
||||||
|
</Tooltip>
|
||||||
|
<Popconfirm
|
||||||
|
title="确定要删除这个优惠券吗?"
|
||||||
|
onConfirm={() => handleDelete(record.id)}
|
||||||
|
okText="确定"
|
||||||
|
cancelText="取消"
|
||||||
|
>
|
||||||
|
<Tooltip title="删除">
|
||||||
|
<Button
|
||||||
|
type="link"
|
||||||
|
size="small"
|
||||||
|
danger
|
||||||
|
icon={<DeleteOutlined />}
|
||||||
|
/>
|
||||||
|
</Tooltip>
|
||||||
|
</Popconfirm>
|
||||||
|
</Space>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
// 查看详情
|
||||||
|
const handleView = (record: ORDERS.Coupon) => {
|
||||||
|
setEditingCoupon(record);
|
||||||
|
setModalVisible(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
// 编辑
|
||||||
|
const handleEdit = (record: ORDERS.Coupon) => {
|
||||||
|
setEditingCoupon(record);
|
||||||
|
form.setFieldsValue({
|
||||||
|
...record,
|
||||||
|
validTime: [moment(record.validStartTime), moment(record.validEndTime)],
|
||||||
|
});
|
||||||
|
setModalVisible(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
// 删除
|
||||||
|
const handleDelete = async (id: number) => {
|
||||||
|
try {
|
||||||
|
await deleteCoupon(id);
|
||||||
|
message.success('删除成功');
|
||||||
|
fetchCouponList();
|
||||||
|
} catch (error) {
|
||||||
|
message.error('删除失败');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 新增
|
||||||
|
const handleAdd = () => {
|
||||||
|
setEditingCoupon(null);
|
||||||
|
form.resetFields();
|
||||||
|
setModalVisible(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
// 提交表单
|
||||||
|
const handleSubmit = async () => {
|
||||||
|
try {
|
||||||
|
const values = await form.validateFields();
|
||||||
|
const [validStartTime, validEndTime] = values.validTime;
|
||||||
|
|
||||||
|
const couponData = {
|
||||||
|
...values,
|
||||||
|
validStartTime: validStartTime.format('YYYY-MM-DD HH:mm:ss'),
|
||||||
|
validEndTime: validEndTime.format('YYYY-MM-DD HH:mm:ss'),
|
||||||
|
};
|
||||||
|
|
||||||
|
if (editingCoupon) {
|
||||||
|
await updateCoupon(editingCoupon.id, couponData);
|
||||||
|
message.success('更新成功');
|
||||||
|
} else {
|
||||||
|
await createCoupon(couponData);
|
||||||
|
message.success('创建成功');
|
||||||
|
}
|
||||||
|
|
||||||
|
setModalVisible(false);
|
||||||
|
fetchCouponList();
|
||||||
|
} catch (error) {
|
||||||
|
message.error('操作失败');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 表格分页变化
|
||||||
|
const handleTableChange = (pagination: any) => {
|
||||||
|
setCurrent(pagination.current);
|
||||||
|
setPageSize(pagination.pageSize);
|
||||||
|
fetchCouponList({
|
||||||
|
current: pagination.current,
|
||||||
|
pageSize: pagination.pageSize,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card title="优惠券管理" extra={
|
||||||
|
<Button type="primary" icon={<PlusOutlined />} onClick={handleAdd}>
|
||||||
|
新增优惠券
|
||||||
|
</Button>
|
||||||
|
}>
|
||||||
|
<Table
|
||||||
|
columns={columns}
|
||||||
|
dataSource={dataSource}
|
||||||
|
loading={loading}
|
||||||
|
rowKey="id"
|
||||||
|
pagination={{
|
||||||
|
current,
|
||||||
|
pageSize,
|
||||||
|
total,
|
||||||
|
showSizeChanger: true,
|
||||||
|
showQuickJumper: true,
|
||||||
|
showTotal: (total) => `共 ${total} 条记录`,
|
||||||
|
}}
|
||||||
|
onChange={handleTableChange}
|
||||||
|
scroll={{ x: 1500 }}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
title={editingCoupon ? '编辑优惠券' : '新增优惠券'}
|
||||||
|
open={modalVisible}
|
||||||
|
onOk={handleSubmit}
|
||||||
|
onCancel={() => setModalVisible(false)}
|
||||||
|
width={600}
|
||||||
|
destroyOnClose
|
||||||
|
>
|
||||||
|
<Form
|
||||||
|
form={form}
|
||||||
|
layout="vertical"
|
||||||
|
initialValues={{
|
||||||
|
couponType: 1,
|
||||||
|
status: 0,
|
||||||
|
source: 2,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Form.Item
|
||||||
|
name="couponName"
|
||||||
|
label="优惠券名称"
|
||||||
|
rules={[{ required: true, message: '请输入优惠券名称' }]}
|
||||||
|
>
|
||||||
|
<Input placeholder="请输入优惠券名称" />
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
<Form.Item
|
||||||
|
name="couponType"
|
||||||
|
label="优惠券类型"
|
||||||
|
rules={[{ required: true, message: '请选择优惠券类型' }]}
|
||||||
|
>
|
||||||
|
<Select placeholder="请选择优惠券类型">
|
||||||
|
{couponTypeOptions.map(option => (
|
||||||
|
<Option key={option.value} value={option.value}>
|
||||||
|
{option.label}
|
||||||
|
</Option>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
<Form.Item
|
||||||
|
noStyle
|
||||||
|
shouldUpdate={(prevValues, currentValues) => prevValues.couponType !== currentValues.couponType}
|
||||||
|
>
|
||||||
|
{({ getFieldValue }) => {
|
||||||
|
const couponType = getFieldValue('couponType');
|
||||||
|
return couponType === 2 ? (
|
||||||
|
<Form.Item
|
||||||
|
name="discountRate"
|
||||||
|
label="折扣率(%)"
|
||||||
|
rules={[{ required: true, message: '请输入折扣率' }]}
|
||||||
|
>
|
||||||
|
<InputNumber
|
||||||
|
min={1}
|
||||||
|
max={99}
|
||||||
|
placeholder="请输入折扣率"
|
||||||
|
style={{ width: '100%' }}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
) : (
|
||||||
|
<Form.Item
|
||||||
|
name="amount"
|
||||||
|
label="优惠券面额"
|
||||||
|
rules={[{ required: true, message: '请输入优惠券面额' }]}
|
||||||
|
>
|
||||||
|
<InputNumber
|
||||||
|
min={0}
|
||||||
|
placeholder="请输入优惠券面额"
|
||||||
|
style={{ width: '100%' }}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
<Form.Item
|
||||||
|
name="minAmount"
|
||||||
|
label="使用门槛金额"
|
||||||
|
>
|
||||||
|
<InputNumber
|
||||||
|
min={0}
|
||||||
|
placeholder="请输入使用门槛金额"
|
||||||
|
style={{ width: '100%' }}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
<Form.Item
|
||||||
|
name="userPhone"
|
||||||
|
label="用户手机号"
|
||||||
|
rules={[{ required: true, message: '请输入用户手机号' }]}
|
||||||
|
>
|
||||||
|
<Input placeholder="请输入用户手机号" />
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
<Form.Item
|
||||||
|
name="source"
|
||||||
|
label="来源"
|
||||||
|
rules={[{ required: true, message: '请选择来源' }]}
|
||||||
|
>
|
||||||
|
<Select placeholder="请选择来源">
|
||||||
|
{sourceOptions.map(option => (
|
||||||
|
<Option key={option.value} value={option.value}>
|
||||||
|
{option.label}
|
||||||
|
</Option>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
<Form.Item
|
||||||
|
name="ctripCouponId"
|
||||||
|
label="携程优惠券ID"
|
||||||
|
>
|
||||||
|
<Input placeholder="请输入携程优惠券ID" />
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
<Form.Item
|
||||||
|
name="validTime"
|
||||||
|
label="有效期"
|
||||||
|
rules={[{ required: true, message: '请选择有效期' }]}
|
||||||
|
>
|
||||||
|
<RangePicker
|
||||||
|
showTime
|
||||||
|
format="YYYY-MM-DD HH:mm:ss"
|
||||||
|
placeholder={['开始时间', '结束时间']}
|
||||||
|
style={{ width: '100%' }}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
<Form.Item
|
||||||
|
name="remark"
|
||||||
|
label="备注"
|
||||||
|
>
|
||||||
|
<Input.TextArea rows={3} placeholder="请输入备注" />
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
<Form.Item
|
||||||
|
name="tenantId"
|
||||||
|
label="租户ID"
|
||||||
|
>
|
||||||
|
<Input placeholder="请输入租户ID" />
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
</Modal>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default CouponManagement;
|
||||||
@@ -339,3 +339,97 @@ export async function getWxMessageStatistics(params: {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 优惠券相关接口
|
||||||
|
export async function getCouponList(params?: { [key: string]: string | number }) {
|
||||||
|
const { current, pageSize, ...rest } = params ?? {};
|
||||||
|
const result = await request<SYSTEM.Page<ORDERS.Coupon>>('/api-order/coupon/page', {
|
||||||
|
method: 'GET',
|
||||||
|
params: { current, size: pageSize, ...rest },
|
||||||
|
});
|
||||||
|
return { data: result.data, total: result.total };
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getCouponById(id: number) {
|
||||||
|
const result = await request<API.Result<ORDERS.Coupon>>(`/api-order/coupon/${id}`, {
|
||||||
|
method: 'GET',
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function createCoupon(data: ORDERS.Coupon) {
|
||||||
|
const result = await request<API.Result<boolean>>('/api-order/coupon', {
|
||||||
|
method: 'POST',
|
||||||
|
data,
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function updateCoupon(id: number, data: ORDERS.Coupon) {
|
||||||
|
const result = await request<API.Result<boolean>>(`/api-order/coupon/${id}`, {
|
||||||
|
method: 'PUT',
|
||||||
|
data,
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function deleteCoupon(id: number) {
|
||||||
|
const result = await request<API.Result<boolean>>(`/api-order/coupon/${id}`, {
|
||||||
|
method: 'DELETE',
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getCouponsByUserPhone(userPhone: string) {
|
||||||
|
const result = await request<API.Result<ORDERS.Coupon[]>>(`/api-order/coupon/user/${userPhone}`, {
|
||||||
|
method: 'GET',
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getAvailableCouponsByUserPhone(userPhone: string) {
|
||||||
|
const result = await request<API.Result<ORDERS.Coupon[]>>(`/api-order/coupon/user/${userPhone}/available`, {
|
||||||
|
method: 'GET',
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function useCoupon(id: number, orderNo: string) {
|
||||||
|
const result = await request<API.Result<boolean>>(`/api-order/coupon/${id}/use`, {
|
||||||
|
method: 'POST',
|
||||||
|
params: { orderNo },
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function createCouponFromCtrip(params: {
|
||||||
|
ctripCouponId: string;
|
||||||
|
userPhone: string;
|
||||||
|
couponName: string;
|
||||||
|
couponType: number;
|
||||||
|
amount: number;
|
||||||
|
minAmount?: number;
|
||||||
|
discountRate?: number;
|
||||||
|
validStartTime: string;
|
||||||
|
validEndTime: string;
|
||||||
|
}) {
|
||||||
|
const result = await request<API.Result<boolean>>('/api-order/coupon/ctrip/create', {
|
||||||
|
method: 'POST',
|
||||||
|
params,
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function verifyCtripCoupon(ctripCouponId: string, orderNo: string) {
|
||||||
|
const result = await request<API.Result<boolean>>('/api-order/coupon/ctrip/verify', {
|
||||||
|
method: 'POST',
|
||||||
|
params: { ctripCouponId, orderNo },
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function updateExpiredCoupons() {
|
||||||
|
const result = await request<API.Result<void>>('/api-order/coupon/update-expired', {
|
||||||
|
method: 'POST',
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
@@ -98,7 +98,31 @@ declare namespace ORDERS {
|
|||||||
approveReason: string;
|
approveReason: string;
|
||||||
createTime?: string;
|
createTime?: string;
|
||||||
tenantId?: string;
|
tenantId?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
type Coupon = {
|
||||||
|
id: number;
|
||||||
|
couponNo: string;
|
||||||
|
couponName: string;
|
||||||
|
couponType: number; // 1-满减券,2-折扣券,3-免费券
|
||||||
|
amount: number;
|
||||||
|
minAmount?: number;
|
||||||
|
discountRate?: number;
|
||||||
|
status: number; // 0-未使用,1-已使用,2-已过期,3-已作废
|
||||||
|
userPhone: string;
|
||||||
|
userId?: number;
|
||||||
|
source: number; // 1-携程,2-高飞自建
|
||||||
|
ctripCouponId?: string;
|
||||||
|
validStartTime: string;
|
||||||
|
validEndTime: string;
|
||||||
|
usedTime?: string;
|
||||||
|
usedOrderNo?: string;
|
||||||
|
createTime?: string;
|
||||||
updateTime?: string;
|
updateTime?: string;
|
||||||
|
tenantId?: string;
|
||||||
|
createBy?: string;
|
||||||
|
updateBy?: string;
|
||||||
|
remark?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加 Dashboard 相关类型
|
// 添加 Dashboard 相关类型
|
||||||
|
|||||||
+175
@@ -0,0 +1,175 @@
|
|||||||
|
# 优惠券管理功能说明
|
||||||
|
|
||||||
|
## 功能概述
|
||||||
|
|
||||||
|
根据携程优惠券兑换流程图,实现了完整的优惠券管理功能,包括:
|
||||||
|
|
||||||
|
1. **优惠券基础管理**:创建、编辑、删除、查询优惠券
|
||||||
|
2. **携程集成**:携程创建优惠券接口、核销接口
|
||||||
|
3. **用户优惠券查询**:根据手机号查询用户优惠券
|
||||||
|
4. **自动过期处理**:定时任务自动更新过期优惠券状态
|
||||||
|
|
||||||
|
## 数据库设计
|
||||||
|
|
||||||
|
### 优惠券表 (t_coupon)
|
||||||
|
|
||||||
|
| 字段名 | 类型 | 说明 |
|
||||||
|
|--------|------|------|
|
||||||
|
| id | bigint | 主键ID |
|
||||||
|
| coupon_no | varchar(64) | 优惠券编号(唯一) |
|
||||||
|
| coupon_name | varchar(128) | 优惠券名称 |
|
||||||
|
| coupon_type | int | 优惠券类型:1-满减券,2-折扣券,3-免费券 |
|
||||||
|
| amount | decimal(10,2) | 优惠券面额 |
|
||||||
|
| min_amount | decimal(10,2) | 使用门槛金额 |
|
||||||
|
| discount_rate | int | 折扣率(0-100,折扣券时使用) |
|
||||||
|
| status | int | 优惠券状态:0-未使用,1-已使用,2-已过期,3-已作废 |
|
||||||
|
| user_phone | varchar(20) | 用户手机号 |
|
||||||
|
| user_id | bigint | 用户ID |
|
||||||
|
| source | int | 来源:1-携程,2-高飞自建 |
|
||||||
|
| ctrip_coupon_id | varchar(64) | 携程优惠券ID(来源为携程时使用) |
|
||||||
|
| valid_start_time | datetime | 有效期开始时间 |
|
||||||
|
| valid_end_time | datetime | 有效期结束时间 |
|
||||||
|
| used_time | datetime | 使用时间 |
|
||||||
|
| used_order_no | varchar(64) | 使用订单号 |
|
||||||
|
| create_time | datetime | 创建时间 |
|
||||||
|
| update_time | datetime | 更新时间 |
|
||||||
|
| create_by | varchar(64) | 创建人 |
|
||||||
|
| update_by | varchar(64) | 更新人 |
|
||||||
|
| remark | varchar(255) | 备注 |
|
||||||
|
| tenant_id | varchar(64) | 租户ID |
|
||||||
|
|
||||||
|
## 后端API接口
|
||||||
|
|
||||||
|
### 1. 优惠券基础管理
|
||||||
|
|
||||||
|
- `GET /api-order/coupon/page` - 分页查询优惠券列表
|
||||||
|
- `GET /api-order/coupon/{id}` - 根据ID查询优惠券
|
||||||
|
- `POST /api-order/coupon` - 创建优惠券
|
||||||
|
- `PUT /api-order/coupon/{id}` - 更新优惠券
|
||||||
|
- `DELETE /api-order/coupon/{id}` - 删除优惠券
|
||||||
|
|
||||||
|
### 2. 用户优惠券查询
|
||||||
|
|
||||||
|
- `GET /api-order/coupon/user/{userPhone}` - 根据手机号查询用户优惠券
|
||||||
|
- `GET /api-order/coupon/user/{userPhone}/available` - 根据手机号查询可用优惠券
|
||||||
|
|
||||||
|
### 3. 优惠券使用
|
||||||
|
|
||||||
|
- `POST /api-order/coupon/{id}/use` - 使用优惠券
|
||||||
|
|
||||||
|
### 4. 携程集成接口
|
||||||
|
|
||||||
|
- `POST /api-order/coupon/ctrip/create` - 携程创建优惠券接口
|
||||||
|
- `POST /api-order/coupon/ctrip/verify` - 核销携程优惠券
|
||||||
|
|
||||||
|
### 5. 系统管理
|
||||||
|
|
||||||
|
- `POST /api-order/coupon/update-expired` - 批量更新过期优惠券
|
||||||
|
|
||||||
|
## 前端功能
|
||||||
|
|
||||||
|
### 优惠券管理页面
|
||||||
|
|
||||||
|
位置:`/pages/orders/CouponManagement.tsx`
|
||||||
|
|
||||||
|
功能:
|
||||||
|
- 优惠券列表展示(支持分页、筛选)
|
||||||
|
- 新增优惠券
|
||||||
|
- 编辑优惠券
|
||||||
|
- 删除优惠券
|
||||||
|
- 查看优惠券详情
|
||||||
|
|
||||||
|
### 主要特性
|
||||||
|
|
||||||
|
1. **响应式表格**:支持横向滚动,适配不同屏幕尺寸
|
||||||
|
2. **智能表单**:根据优惠券类型动态显示不同字段
|
||||||
|
3. **状态管理**:不同状态用不同颜色标签显示
|
||||||
|
4. **时间处理**:使用moment.js处理时间格式化
|
||||||
|
|
||||||
|
## 业务流程
|
||||||
|
|
||||||
|
### 1. 携程优惠券创建流程
|
||||||
|
|
||||||
|
```
|
||||||
|
用户在携程购券 → 携程调用高飞创建优惠券接口 → 高飞创建本地优惠券记录
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. 用户下单优惠券使用流程
|
||||||
|
|
||||||
|
```
|
||||||
|
用户扫码进入下单页 → 查询用户绑定手机号 → 通过手机号查询高飞用户优惠券记录 →
|
||||||
|
有可用优惠券自动带出 → 用户选择是否核销 → 调用携程核销接口 → 进入支付流程
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. 优惠券过期处理流程
|
||||||
|
|
||||||
|
```
|
||||||
|
定时任务每天凌晨2点执行 → 查询所有未使用且已过期的优惠券 → 批量更新状态为已过期
|
||||||
|
```
|
||||||
|
|
||||||
|
## 定时任务
|
||||||
|
|
||||||
|
### 优惠券过期处理任务
|
||||||
|
|
||||||
|
- **类名**:`CouponExpirationTask`
|
||||||
|
- **执行时间**:每天凌晨2点
|
||||||
|
- **功能**:批量更新过期优惠券状态
|
||||||
|
|
||||||
|
## 携程API集成
|
||||||
|
|
||||||
|
### 携程API服务
|
||||||
|
|
||||||
|
- **接口**:`ICtripApiService`
|
||||||
|
- **实现**:`CtripApiServiceImpl`
|
||||||
|
|
||||||
|
### 待实现功能
|
||||||
|
|
||||||
|
1. **核销接口**:`verifyCoupon(String ctripCouponId, String orderNo)`
|
||||||
|
2. **状态查询**:`getCouponStatus(String ctripCouponId)`
|
||||||
|
|
||||||
|
### 集成说明
|
||||||
|
|
||||||
|
目前携程API调用为模拟实现,需要根据携程提供的API文档进行实际集成:
|
||||||
|
|
||||||
|
1. 配置携程API密钥和接口地址
|
||||||
|
2. 实现HTTP客户端调用
|
||||||
|
3. 处理API响应和错误
|
||||||
|
4. 添加重试机制和日志记录
|
||||||
|
|
||||||
|
## 部署说明
|
||||||
|
|
||||||
|
### 1. 数据库迁移
|
||||||
|
|
||||||
|
执行 `database_migration.sql` 中的优惠券表创建语句。
|
||||||
|
|
||||||
|
### 2. 后端部署
|
||||||
|
|
||||||
|
确保以下组件已正确配置:
|
||||||
|
- MyBatis Plus配置
|
||||||
|
- 定时任务配置(@EnableScheduling)
|
||||||
|
- 数据库连接配置
|
||||||
|
|
||||||
|
### 3. 前端部署
|
||||||
|
|
||||||
|
确保以下依赖已安装:
|
||||||
|
- Ant Design
|
||||||
|
- moment.js
|
||||||
|
- TypeScript类型定义
|
||||||
|
|
||||||
|
## 注意事项
|
||||||
|
|
||||||
|
1. **优惠券编号唯一性**:系统自动生成优惠券编号,确保唯一性
|
||||||
|
2. **携程优惠券ID唯一性**:同一携程优惠券ID只能创建一次
|
||||||
|
3. **时间处理**:所有时间字段使用UTC时间存储
|
||||||
|
4. **状态管理**:优惠券状态变更需要记录操作日志
|
||||||
|
5. **API安全**:携程集成接口需要添加适当的认证和授权
|
||||||
|
|
||||||
|
## 扩展功能
|
||||||
|
|
||||||
|
### 可扩展的功能点
|
||||||
|
|
||||||
|
1. **优惠券模板**:支持创建优惠券模板,批量生成优惠券
|
||||||
|
2. **优惠券统计**:优惠券使用情况统计和分析
|
||||||
|
3. **优惠券推送**:向用户推送优惠券到期提醒
|
||||||
|
4. **优惠券分享**:支持优惠券分享功能
|
||||||
|
5. **多平台集成**:支持其他平台的优惠券集成
|
||||||
Reference in New Issue
Block a user