fix: 修复ordermoney接口返回格式兼容PHP旧版

- OrderCalculationDto字段名调整: goods_info->goods, user_money->money等
- GoodsInfoDto添加shou_zhe_price字段
- OrderService响应构建逻辑同步修改
- 修复前端订单确认弹窗显示undefined问题
This commit is contained in:
gpu 2026-01-21 23:47:36 +08:00
parent 058883c485
commit 2f8eae152e
3 changed files with 105 additions and 46 deletions

View File

@ -105,21 +105,29 @@ public class OrderService : IOrderService
goodsExtend
);
// 6. 构建响应
// 6. 构建响应(兼容 PHP 旧版字段名)
return new OrderCalculationDto
{
OrderTotal = result.OrderTotal.ToString("0.00"),
OrderZheTotal = result.OrderZheTotal.ToString("0.00"),
Price = result.Price.ToString("0.00"),
Zhe = result.Zhe.ToString("0.00"),
UserMoney = user.Money.ToString("0.00"),
UserIntegral = user.Integral.ToString("0.00"),
UserMoney2 = (user.Money2 ?? 0).ToString("0.00"),
// 用户余额信息(兼容旧版字段名)
Money = user.Money.ToString("0.00"),
Integral = user.Integral.ToString("0.00"),
Score = user.Money2 ?? 0,
// 使用金额信息
UseMoney = result.UseMoney.ToString("0.00"),
UseIntegral = result.UseIntegral.ToString("0.00"),
UseMoney2 = result.UseMoney2.ToString("0.00"),
UseCoupon = result.CouponPrice.ToString("0.00"),
GoodsInfo = new GoodsInfoDto
UseIntegralMoney = (result.UseIntegral / 100).ToString("0.00"),
UseScore = result.UseMoney2,
UseMoney2 = result.UseMoney2,
// 优惠券信息
CouponId = result.CouponId,
CouponPrice = result.CouponPrice.ToString("0.00"),
IsShouZhe = result.IsShouZhe ? 1 : 0,
// 商品信息(兼容旧版字段名 goods
Goods = new GoodsInfoDto
{
Id = goods.Id,
Title = goods.Title,
@ -128,7 +136,9 @@ public class OrderService : IOrderService
Type = goods.Type,
IsShouZhe = goods.IsShouZhe,
QuanjuXiangou = goods.QuanjuXiangou,
DailyXiangou = goods.DailyXiangou
DailyXiangou = goods.DailyXiangou,
PrizeNum = request.PrizeNum,
ShouZhePrice = result.ShouZhePrice.ToString("0.00")
},
GoodsExtend = goodsExtend
};
@ -341,7 +351,8 @@ public class OrderService : IOrderService
if (!hasPaidOrder && isShouZhe == 1)
{
shouZhePrice = Math.Round(boxPrice * 0.5m, 2);
result.IsShouZhe = 1;
result.IsShouZhe = true;
result.ShouZhePrice = shouZhePrice;
}
}
@ -585,7 +596,8 @@ public class OrderService : IOrderService
public decimal UseMoney2 { get; set; }
public int CouponId { get; set; }
public decimal CouponPrice { get; set; }
public int IsShouZhe { get; set; }
public bool IsShouZhe { get; set; }
public decimal ShouZhePrice { get; set; }
}
/// <inheritdoc />
@ -665,21 +677,29 @@ public class OrderService : IOrderService
goodsExtend
);
// 7. 构建响应
// 7. 构建响应(兼容 PHP 旧版字段名)
return new OrderCalculationDto
{
OrderTotal = result.OrderTotal.ToString("0.00"),
OrderZheTotal = result.OrderZheTotal.ToString("0.00"),
Price = result.Price.ToString("0.00"),
Zhe = result.Zhe.ToString("0.00"),
UserMoney = user.Money.ToString("0.00"),
UserIntegral = user.Integral.ToString("0.00"),
UserMoney2 = (user.Money2 ?? 0).ToString("0.00"),
// 用户余额信息(兼容旧版字段名)
Money = user.Money.ToString("0.00"),
Integral = user.Integral.ToString("0.00"),
Score = user.Money2 ?? 0,
// 使用金额信息
UseMoney = result.UseMoney.ToString("0.00"),
UseIntegral = result.UseIntegral.ToString("0.00"),
UseMoney2 = result.UseMoney2.ToString("0.00"),
UseCoupon = result.CouponPrice.ToString("0.00"),
GoodsInfo = new GoodsInfoDto
UseIntegralMoney = (result.UseIntegral / 100).ToString("0.00"),
UseScore = result.UseMoney2,
UseMoney2 = result.UseMoney2,
// 优惠券信息
CouponId = result.CouponId,
CouponPrice = result.CouponPrice.ToString("0.00"),
IsShouZhe = result.IsShouZhe ? 1 : 0,
// 商品信息(兼容旧版字段名 goods
Goods = new GoodsInfoDto
{
Id = goods.Id,
Title = goods.Title,
@ -688,7 +708,9 @@ public class OrderService : IOrderService
Type = goods.Type,
IsShouZhe = goods.IsShouZhe,
QuanjuXiangou = goods.QuanjuXiangou,
DailyXiangou = goods.DailyXiangou
DailyXiangou = goods.DailyXiangou,
PrizeNum = request.PrizeNum,
ShouZhePrice = result.ShouZhePrice.ToString("0.00")
},
GoodsExtend = goodsExtend
};
@ -742,20 +764,24 @@ public class OrderService : IOrderService
var integral = price * 100; // 积分价格 = 单价 * 100
var userMoney2 = user.Money2 ?? 0;
// 5. 构建响应 - 商城订单返回格式与PHP一致
// 5. 构建响应(兼容 PHP 旧版字段名)
return new OrderCalculationDto
{
Price = price.ToString("0.00"),
OrderTotal = price.ToString("0.00"),
OrderZheTotal = price.ToString("0.00"),
UserMoney = user.Money.ToString("0.00"),
UserIntegral = user.Integral.ToString("0.00"),
UserMoney2 = userMoney2.ToString("0.00"),
// 用户余额信息(兼容旧版字段名)
Money = user.Money.ToString("0.00"),
Integral = user.Integral.ToString("0.00"),
Score = userMoney2,
// 使用金额信息
UseMoney = "0.00",
UseIntegral = "0.00",
UseMoney2 = integral.ToString("0.00"), // 需要使用的积分数量
UseCoupon = "0.00",
GoodsInfo = new GoodsInfoDto
UseIntegralMoney = "0.00",
UseScore = integral, // 需要使用的积分数量
UseMoney2 = integral,
// 商品信息(兼容旧版字段名 goods
Goods = new GoodsInfoDto
{
Id = goods.Id,
Title = goods.Title,
@ -992,7 +1018,7 @@ public class OrderService : IOrderService
Addtime = (int)currentTimestamp,
CouponId = paymentResult.CouponId > 0 ? paymentResult.CouponId : null,
UseCoupon = paymentResult.CouponPrice,
IsShouZhe = (byte)paymentResult.IsShouZhe,
IsShouZhe = (byte)(paymentResult.IsShouZhe ? 1 : 0),
CreatedAt = DateTime.Now,
UpdatedAt = DateTime.Now
};
@ -1369,7 +1395,7 @@ public class OrderService : IOrderService
Addtime = (int)currentTimestamp,
CouponId = paymentResult.CouponId > 0 ? paymentResult.CouponId : null,
UseCoupon = paymentResult.CouponPrice,
IsShouZhe = (byte)paymentResult.IsShouZhe,
IsShouZhe = (byte)(paymentResult.IsShouZhe ? 1 : 0),
CreatedAt = DateTime.Now,
UpdatedAt = DateTime.Now
};

View File

@ -382,6 +382,9 @@ public class GoodsInfoDto
[JsonPropertyName("prize_num")]
public int PrizeNum { get; set; }
[JsonPropertyName("shou_zhe_price")]
public string ShouZhePrice { get; set; } = "0";
}

View File

@ -286,34 +286,34 @@ public class OrderCalculationDto
public string Price { get; set; } = "0.00";
/// <summary>
/// 商品信息
/// 商品信息(兼容旧版字段名 goods
/// </summary>
[JsonPropertyName("goods_info")]
public GoodsInfoDto? GoodsInfo { get; set; }
[JsonPropertyName("goods")]
public GoodsInfoDto? Goods { get; set; }
/// <summary>
/// 商品扩展配置
/// 商品扩展配置(兼容旧版字段名 goods_extend
/// </summary>
[JsonPropertyName("goodsExtend")]
[JsonPropertyName("goods_extend")]
public GoodsExtendDto? GoodsExtend { get; set; }
/// <summary>
/// 用户余额
/// 用户余额(兼容旧版字段名 money
/// </summary>
[JsonPropertyName("user_money")]
public string UserMoney { get; set; } = "0.00";
[JsonPropertyName("money")]
public string Money { get; set; } = "0.00";
/// <summary>
/// 用户积分
/// 用户积分(兼容旧版字段名 integral
/// </summary>
[JsonPropertyName("user_integral")]
public string UserIntegral { get; set; } = "0.00";
[JsonPropertyName("integral")]
public string Integral { get; set; } = "0.00";
/// <summary>
/// 用户哈尼券
/// 用户哈尼券(兼容旧版字段名 score
/// </summary>
[JsonPropertyName("user_money2")]
public string UserMoney2 { get; set; } = "0.00";
[JsonPropertyName("score")]
public decimal Score { get; set; } = 0;
/// <summary>
/// 使用余额金额
@ -322,22 +322,40 @@ public class OrderCalculationDto
public string UseMoney { get; set; } = "0.00";
/// <summary>
/// 使用积分金额
/// 使用积分原始值1:100比例
/// </summary>
[JsonPropertyName("use_integral")]
public string UseIntegral { get; set; } = "0.00";
/// <summary>
/// 使用哈尼券金额
/// 使用积分换算成金额
/// </summary>
[JsonPropertyName("use_integral_money")]
public string UseIntegralMoney { get; set; } = "0.00";
/// <summary>
/// 使用哈尼券(兼容旧版字段名 use_score
/// </summary>
[JsonPropertyName("use_score")]
public decimal UseScore { get; set; } = 0;
/// <summary>
/// 使用哈尼券(保留兼容)
/// </summary>
[JsonPropertyName("use_money2")]
public string UseMoney2 { get; set; } = "0.00";
public decimal UseMoney2 { get; set; } = 0;
/// <summary>
/// 优惠券ID
/// </summary>
[JsonPropertyName("coupon_id")]
public int CouponId { get; set; } = 0;
/// <summary>
/// 优惠券抵扣金额
/// </summary>
[JsonPropertyName("use_coupon")]
public string UseCoupon { get; set; } = "0.00";
[JsonPropertyName("coupon_price")]
public string CouponPrice { get; set; } = "0.00";
/// <summary>
/// 可用优惠券列表
@ -345,6 +363,18 @@ public class OrderCalculationDto
[JsonPropertyName("available_coupons")]
public List<AvailableCouponDto>? AvailableCoupons { get; set; }
/// <summary>
/// 每日优惠券限制
/// </summary>
[JsonPropertyName("daily_coupon_limit")]
public int DailyCouponLimit { get; set; } = 0;
/// <summary>
/// 是否首抽五折
/// </summary>
[JsonPropertyName("is_shou_zhe")]
public int IsShouZhe { get; set; } = 0;
/// <summary>
/// 折扣比例
/// </summary>