fix(订单中心):新增素材数量为8个的模板剪辑,优惠券了逻辑优化
This commit is contained in:
+89
-23
@@ -19,6 +19,11 @@ import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.central.order.model.CtripCreateOrderRequest;
|
||||
import com.central.order.model.CtripCreateOrderRequest.CtripOrderBody;
|
||||
import com.central.order.model.CtripCreateOrderRequest.CtripOrderItem;
|
||||
import com.central.order.model.CtripCreateOrderRequest.CtripPassenger;
|
||||
import com.central.order.model.CtripCreateOrderRequest.CtripContact;
|
||||
|
||||
/**
|
||||
* 优惠券管理控制器
|
||||
@@ -121,32 +126,93 @@ public class CouponController {
|
||||
*/
|
||||
@Operation(summary = "携程创建优惠券接口")
|
||||
@PostMapping("/ctrip/create")
|
||||
public Result<Boolean> createCouponFromCtrip(
|
||||
@RequestParam String ctripCouponId,
|
||||
@RequestParam String userPhone,
|
||||
@RequestParam String couponName,
|
||||
@RequestParam Integer couponType,
|
||||
@RequestParam BigDecimal amount,
|
||||
@RequestParam(required = false) BigDecimal minAmount,
|
||||
@RequestParam(required = false) Integer discountRate,
|
||||
@RequestParam String validStartTime,
|
||||
@RequestParam String validEndTime) {
|
||||
// 打印请求参数
|
||||
log.info("携程创建券请求参数:ctripCouponId={}, userPhone={}, couponName={}, couponType={}, amount={}, minAmount={}, discountRate={}, validStartTime={}, validEndTime={}",
|
||||
ctripCouponId, userPhone, couponName, couponType, amount, minAmount, discountRate, validStartTime, validEndTime);
|
||||
// 幂等校验
|
||||
if (couponService.existsByUserPhoneAndCtripCouponId(userPhone, ctripCouponId)) {
|
||||
return Result.succeed(true);
|
||||
public Result<Boolean> createCouponFromCtripJson(@RequestBody CtripCreateOrderRequest request) {
|
||||
log.info("携程创建券请求:{}", request);
|
||||
|
||||
try {
|
||||
// 验证请求头
|
||||
if (request.getHeader() == null || request.getBody() == null) {
|
||||
return Result.failed("请求格式错误");
|
||||
}
|
||||
|
||||
// 从body中提取订单信息
|
||||
CtripOrderBody body = request.getBody();
|
||||
if (body.getItems() == null || body.getItems().isEmpty()) {
|
||||
return Result.failed("订单项不能为空");
|
||||
}
|
||||
|
||||
// 获取第一个订单项
|
||||
CtripOrderItem item = body.getItems().get(0);
|
||||
|
||||
// 获取乘客信息
|
||||
String userPhone = null;
|
||||
String userName = null;
|
||||
if (item.getPassengers() != null && !item.getPassengers().isEmpty()) {
|
||||
CtripPassenger passenger = item.getPassengers().get(0);
|
||||
userPhone = passenger.getMobile();
|
||||
userName = passenger.getName();
|
||||
}
|
||||
|
||||
// 获取联系人信息作为备选
|
||||
if (userPhone == null && body.getContacts() != null && !body.getContacts().isEmpty()) {
|
||||
CtripContact contact = body.getContacts().get(0);
|
||||
userPhone = contact.getMobile();
|
||||
userName = contact.getName();
|
||||
}
|
||||
|
||||
if (userPhone == null) {
|
||||
return Result.failed("无法获取用户手机号");
|
||||
}
|
||||
|
||||
// 构建优惠券信息
|
||||
String ctripCouponId = body.getOtaOrderId(); // 使用otaOrderId作为携程券ID
|
||||
String couponName = userName != null ? userName + "的携程优惠券" : "携程订单优惠券"; // 个性化名称
|
||||
Integer couponType = 1; // 默认类型:满减券
|
||||
BigDecimal amount = item.getSalePrice(); // 使用销售价格作为券面额
|
||||
BigDecimal minAmount = item.getPrice(); // 使用原价作为最低消费
|
||||
String validStartTime = item.getUseStartDate();
|
||||
String validEndTime = item.getUseEndDate();
|
||||
|
||||
// 幂等校验
|
||||
if (couponService.existsByUserPhoneAndCtripCouponId(userPhone, ctripCouponId)) {
|
||||
log.info("携程优惠券已存在,userPhone: {}, ctripCouponId: {}", userPhone, ctripCouponId);
|
||||
return Result.succeed(true);
|
||||
}
|
||||
|
||||
// 时间解析
|
||||
Date startTime = parseDate(validStartTime);
|
||||
Date endTime = parseDate(validEndTime);
|
||||
|
||||
// 验证时间
|
||||
if (startTime == null || endTime == null) {
|
||||
return Result.failed("时间格式错误");
|
||||
}
|
||||
|
||||
if (endTime.before(startTime)) {
|
||||
return Result.failed("结束时间不能早于开始时间");
|
||||
}
|
||||
|
||||
// 创建优惠券
|
||||
boolean result = couponService.createCouponFromCtrip(ctripCouponId, userPhone, couponName,
|
||||
couponType, amount, minAmount, null,
|
||||
startTime, endTime);
|
||||
|
||||
if (result) {
|
||||
log.info("携程优惠券创建成功,userPhone: {}, ctripCouponId: {}, amount: {}", userPhone, ctripCouponId, amount);
|
||||
return Result.succeed(true);
|
||||
} else {
|
||||
log.error("携程优惠券创建失败,userPhone: {}, ctripCouponId: {}", userPhone, ctripCouponId);
|
||||
return Result.failed("优惠券创建失败");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("处理携程创建券请求失败", e);
|
||||
return Result.failed("处理请求失败:" + e.getMessage());
|
||||
}
|
||||
// 时间解析
|
||||
Date startTime = parseDate(validStartTime);
|
||||
Date endTime = parseDate(validEndTime);
|
||||
boolean result = couponService.createCouponFromCtrip(ctripCouponId, userPhone, couponName,
|
||||
couponType, amount, minAmount, discountRate,
|
||||
startTime, endTime);
|
||||
return Result.succeed(result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 携程取消优惠券接口
|
||||
*/
|
||||
|
||||
+5
@@ -187,6 +187,7 @@ public class MediaServiceImpl implements IMediaService {
|
||||
Map<String, String> clips = new HashMap<>();
|
||||
List<OrderFile> videoFiles = taskData.getVideoFiles();
|
||||
//@TODO 后期需要通过模板参数进行动态设置clips参数
|
||||
|
||||
clips.put("1", fileCenterService.getViewUrlByPath(videoFiles.get(4).getFilePath()));
|
||||
clips.put("2", fileCenterService.getViewUrlByPath(videoFiles.get(5).getFilePath()));
|
||||
clips.put("3", fileCenterService.getViewUrlByPath(videoFiles.get(6).getFilePath()));
|
||||
@@ -195,6 +196,10 @@ public class MediaServiceImpl implements IMediaService {
|
||||
clips.put("6", fileCenterService.getViewUrlByPath(videoFiles.get(2).getFilePath()));
|
||||
clips.put("7", fileCenterService.getViewUrlByPath(videoFiles.get(3).getFilePath()));
|
||||
|
||||
if (taskData.getVideoFiles().size() > 7) {
|
||||
clips.put("8", fileCenterService.getViewUrlByPath(videoFiles.get(7).getFilePath()));
|
||||
}
|
||||
|
||||
return JSON.toJSONString(clips);
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException("构建剪辑参数失败: " + e.getMessage());
|
||||
|
||||
Reference in New Issue
Block a user