From dafb12299ea078185fca32330c42a329df79530e Mon Sep 17 00:00:00 2001 From: zpc Date: Tue, 3 Feb 2026 02:23:32 +0800 Subject: [PATCH] 32121 --- honey_box/pages/mall/index.vue | 2 +- .../HoneyBox.Core/Services/OrderService.cs | 66 ++++++++++++++++++- 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/honey_box/pages/mall/index.vue b/honey_box/pages/mall/index.vue index 19bbc202..4d1bfbb1 100644 --- a/honey_box/pages/mall/index.vue +++ b/honey_box/pages/mall/index.vue @@ -309,7 +309,7 @@ export default { async pay(type) { var pri = this.orderData.goods.price * 100; - if (this.orderData.use_integral < pri) { + if (this.orderData.score < pri) { uni.showToast({ title: this.$config.getAppSetting("currency2_name") + '不足', icon: 'none', diff --git a/server/HoneyBox/src/HoneyBox.Core/Services/OrderService.cs b/server/HoneyBox/src/HoneyBox.Core/Services/OrderService.cs index 7b3d52ce..90b6f696 100644 --- a/server/HoneyBox/src/HoneyBox.Core/Services/OrderService.cs +++ b/server/HoneyBox/src/HoneyBox.Core/Services/OrderService.cs @@ -2342,7 +2342,71 @@ public class OrderService : IOrderService userEntity.UpdatedAt = DateTime.Now; } - // 11. 标记订单为已支付 + // 11. 执行商城抽奖 - 查找奖品并发放 + // 商城类型(type=10)的奖品 num=1 + var prizeItem = await _dbContext.GoodsItems + .Where(g => g.GoodsId == request.GoodsId && g.Num == num && g.SurplusStock > 0) + .FirstOrDefaultAsync(); + + if (prizeItem == null) + { + throw new InvalidOperationException("暂无奖品信息"); + } + + // 12. 扣减奖品库存 + prizeItem.SurplusStock -= 1; + prizeItem.UpdatedAt = DateTime.Now; + + // 13. 获取当前奖品的luck_no + var luckNo = await _dbContext.OrderItems + .Where(o => o.GoodsId == request.GoodsId && o.Num == num && o.OrderType == goods.Type) + .OrderByDescending(o => o.Id) + .Select(o => o.LuckNo) + .FirstOrDefaultAsync(); + luckNo++; + + // 14. 创建中奖记录 (OrderList/OrderItem) + var saleTimeStamp = prizeItem.SaleTime.HasValue + ? (int)new DateTimeOffset(prizeItem.SaleTime.Value).ToUnixTimeSeconds() + : 0; + + var orderItem = new OrderItem + { + OrderId = order.Id, + UserId = userId, + Status = 0, // 0-未操作 + GoodsId = request.GoodsId, + Num = num, + ShangId = prizeItem.ShangId ?? 0, + GoodslistId = prizeItem.Id, + GoodslistTitle = prizeItem.Title, + GoodslistImgurl = prizeItem.ImgUrl, + GoodslistPrice = prizeItem.Price, + GoodslistMoney = prizeItem.Money, + GoodslistType = prizeItem.GoodsType, + GoodslistSaleTime = saleTimeStamp, + Addtime = (int)currentTimestamp, + PrizeCode = prizeItem.PrizeCode ?? "", + OrderType = goods.Type, + LuckNo = luckNo, + ParentGoodsListId = 0, + ChoiceTime = 0, + FhStatus = 0, + IsChong = 0, + IsLingzhu = 0 + }; + + _dbContext.OrderItems.Add(orderItem); + + // 15. 扣减商品库存(增加已售数量) + var goodsEntity = await _dbContext.Goods.FindAsync(request.GoodsId); + if (goodsEntity != null) + { + goodsEntity.SaleStock += 1; + goodsEntity.UpdatedAt = DateTime.Now; + } + + // 16. 标记订单为已支付 order.Status = 1; order.PayTime = (int)currentTimestamp;