|
|
@@ -24,6 +24,9 @@ using System.Linq; |
|
|
|
using System.Text; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Org.BouncyCastle.Crypto; |
|
|
|
using BPA.KitChen.GroupMealOrder.Core.Cache; |
|
|
|
using NPOI.XSSF.Streaming.Values; |
|
|
|
using StackExchange.Redis; |
|
|
|
|
|
|
|
namespace BPA.KitChen.GroupMealOrder.Application.Service.WeighOrder.Service |
|
|
|
{ |
|
|
@@ -43,6 +46,8 @@ namespace BPA.KitChen.GroupMealOrder.Application.Service.WeighOrder.Service |
|
|
|
/// <returns></returns> |
|
|
|
public async Task<WeighOrderDto> CreateWeighOrder(WeighOrderCreteDto inputDto) |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
var diningPlateInfo = await GetDiningPlateInfoByQRCode(inputDto.QRCode); |
|
|
|
if (diningPlateInfo == null || diningPlateInfo.Status != 0) |
|
|
|
{ |
|
|
@@ -111,6 +116,7 @@ namespace BPA.KitChen.GroupMealOrder.Application.Service.WeighOrder.Service |
|
|
|
OrderId = order.Id, |
|
|
|
}); |
|
|
|
|
|
|
|
RedisHelper.RedisConn.GetDatabase().StringSet("order" + inputDto.CreateId, JsonConvert.SerializeObject(result)); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
@@ -192,6 +198,11 @@ namespace BPA.KitChen.GroupMealOrder.Application.Service.WeighOrder.Service |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//写入redis |
|
|
|
Task.Run(async () => |
|
|
|
{ |
|
|
|
await AddRedis(ids); |
|
|
|
}); |
|
|
|
return res > 0; |
|
|
|
} |
|
|
|
|
|
|
@@ -264,6 +275,13 @@ namespace BPA.KitChen.GroupMealOrder.Application.Service.WeighOrder.Service |
|
|
|
}); |
|
|
|
|
|
|
|
var res = await db.Insertable(diningPlate).ExecuteCommandAsync(); |
|
|
|
|
|
|
|
///写入redis |
|
|
|
|
|
|
|
Task.Run(async () => |
|
|
|
{ |
|
|
|
await AddRedis(inputDto.OrderId); |
|
|
|
}); |
|
|
|
return res > 0; |
|
|
|
} |
|
|
|
|
|
|
@@ -468,6 +486,8 @@ namespace BPA.KitChen.GroupMealOrder.Application.Service.WeighOrder.Service |
|
|
|
{ |
|
|
|
throw Oops.Oh("请求错误"); |
|
|
|
} |
|
|
|
|
|
|
|
RedisHelper.RedisConn.GetDatabase().KeyDelete("order" + result.CreateId); |
|
|
|
return res > 0; |
|
|
|
} |
|
|
|
catch (Exception e) |
|
|
@@ -486,14 +506,19 @@ namespace BPA.KitChen.GroupMealOrder.Application.Service.WeighOrder.Service |
|
|
|
{ |
|
|
|
var list = new List<BPA_WeighOrderDiningPlateUnbindRecord>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in inputDto) |
|
|
|
{ |
|
|
|
//查询订单 |
|
|
|
var weighOrder = await db.Queryable<BPA_WeighOrder>().FirstAsync(x => x.Id == item.WeighOrderId); |
|
|
|
list.Add(new BPA_WeighOrderDiningPlateUnbindRecord() |
|
|
|
{ |
|
|
|
CreateAt = DateTime.Now, |
|
|
|
DiningPlateId = item.DiningPlateId, |
|
|
|
WeighOrderId = item.WeighOrderId, |
|
|
|
}); |
|
|
|
RedisHelper.RedisConn.GetDatabase().KeyDelete("order" + weighOrder.CreateId); |
|
|
|
} |
|
|
|
|
|
|
|
if (list.Count > 0) |
|
|
@@ -501,7 +526,6 @@ namespace BPA.KitChen.GroupMealOrder.Application.Service.WeighOrder.Service |
|
|
|
var res = await db.Insertable(list).ExecuteCommandAsync(); |
|
|
|
return res > 0; |
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
@@ -611,7 +635,15 @@ namespace BPA.KitChen.GroupMealOrder.Application.Service.WeighOrder.Service |
|
|
|
/// <returns></returns> |
|
|
|
public async Task<WeighOrderDto> GetWeighOrderByOpenId(GetWeighOrderByOpenIdInputDto inputDto) |
|
|
|
{ |
|
|
|
var res = await db.Queryable<BPA_WeighOrder>() |
|
|
|
var res = new WeighOrderDto(); |
|
|
|
var orderRedis = RedisHelper.RedisConn.GetDatabase().StringGet("order" + inputDto.OpenId); |
|
|
|
if (!string.IsNullOrEmpty(orderRedis)) |
|
|
|
{ |
|
|
|
res = JsonConvert.DeserializeObject<WeighOrderDto>(orderRedis); |
|
|
|
return res; |
|
|
|
} |
|
|
|
|
|
|
|
res = await db.Queryable<BPA_WeighOrder>() |
|
|
|
.Where(x => x.CreateId == inputDto.OpenId) |
|
|
|
.OrderBy(x => x.CreateAt, OrderByType.Desc) |
|
|
|
.Select(t => new WeighOrderDto |
|
|
@@ -700,14 +732,12 @@ namespace BPA.KitChen.GroupMealOrder.Application.Service.WeighOrder.Service |
|
|
|
}) |
|
|
|
.ToList(); |
|
|
|
} |
|
|
|
|
|
|
|
RedisHelper.RedisConn.GetDatabase().StringSet("order" + res.CreateId, JsonConvert.SerializeObject(res)); |
|
|
|
return res; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// 称重订单分页 |
|
|
|
/// </summary> |
|
|
@@ -919,5 +949,101 @@ namespace BPA.KitChen.GroupMealOrder.Application.Service.WeighOrder.Service |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public async Task AddRedis( string orderId) |
|
|
|
{ |
|
|
|
var res = new WeighOrderDto(); |
|
|
|
|
|
|
|
res = await db.Queryable<BPA_WeighOrder>() |
|
|
|
.Where(x => x.Id == orderId) |
|
|
|
.OrderBy(x => x.CreateAt, OrderByType.Desc) |
|
|
|
.Select(t => new WeighOrderDto |
|
|
|
{ |
|
|
|
Id = t.Id.SelectAll(), |
|
|
|
}).FirstAsync(); |
|
|
|
if (res == null || res.States == 1) |
|
|
|
{ |
|
|
|
throw Oops.Oh("无数据"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//查询订单商品 |
|
|
|
var orderGoods = await db.Queryable<BPA_WeighOrderGoods>() |
|
|
|
.Where(x => x.OrderId == res.Id) |
|
|
|
.ToListAsync(); |
|
|
|
if (orderGoods != null) |
|
|
|
{ |
|
|
|
res.GoodsInfo = orderGoods.Select(x => new WeighOrderGoodsDto() |
|
|
|
{ |
|
|
|
GoodsId = x.GoodsId, |
|
|
|
GoodsAttribute = string.IsNullOrEmpty(x.GoodsAttribute) ? null : JsonConvert.DeserializeObject<List<GoogsAttribute>>(x.GoodsAttribute), |
|
|
|
GoodsName = x.GoodsName, |
|
|
|
GoodsWeight = x.GoodsWeight, |
|
|
|
GroupId = x.GroupId, |
|
|
|
Id = x.Id, |
|
|
|
OrderId = x.OrderId, |
|
|
|
DiningPlateId = x.DiningPlateId, |
|
|
|
TotalAmount = x.TotalAmount, |
|
|
|
}).ToList(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//查询订单餐盘 |
|
|
|
var diningPlate = await db.Queryable<BPA_WeighOrderDiningPlate>() |
|
|
|
.Where(x => x.WeighOrderId == res.Id) |
|
|
|
.Select(x => new WeighOrderDiningPlateDto() |
|
|
|
{ |
|
|
|
DiningPlateId = x.DiningPlateId, |
|
|
|
OrderId = x.WeighOrderId, |
|
|
|
ChipCode = x.ChipCode, |
|
|
|
QRCode = x.QRCode, |
|
|
|
}).ToListAsync(); |
|
|
|
|
|
|
|
var ids = diningPlate.Select(x => x.DiningPlateId).ToList(); |
|
|
|
//查询解绑产盘 |
|
|
|
var unbindRed = db.Queryable<BPA_WeighOrderDiningPlateUnbindRecord>() |
|
|
|
.Where(x => x.WeighOrderId == res.Id && ids.Contains(x.DiningPlateId)) |
|
|
|
.OrderBy(x => x.CreateAt, OrderByType.Desc) |
|
|
|
.Select(t => new WeighOrderDto |
|
|
|
{ |
|
|
|
Id = t.Id.SelectAll(), |
|
|
|
}).ToList(); |
|
|
|
if (unbindRed.Count > 0) |
|
|
|
{ |
|
|
|
throw Oops.Oh("没有餐盘或已用被解绑"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (diningPlate != null) |
|
|
|
{ |
|
|
|
foreach (var item in diningPlate) |
|
|
|
{ |
|
|
|
var goods = res.GoodsInfo.Where(x => x.DiningPlateId == item.DiningPlateId).ToList(); |
|
|
|
item.GoodsInfo = goods; |
|
|
|
} |
|
|
|
res.DiningPlateInfo = diningPlate; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (res.GoodsInfo != null) |
|
|
|
{ |
|
|
|
res.GoodsInfo = res.GoodsInfo |
|
|
|
.GroupBy(x => x.GoodsId) |
|
|
|
.Select(x => new WeighOrderGoodsDto() |
|
|
|
{ |
|
|
|
GoodsAttribute = x.FirstOrDefault()?.GoodsAttribute, |
|
|
|
GoodsId = x.Key, |
|
|
|
GoodsName = x.FirstOrDefault()?.GoodsName, |
|
|
|
GoodsWeight = x.Sum(p => p.GoodsWeight), |
|
|
|
GroupId = x.FirstOrDefault()?.GroupId, |
|
|
|
OrderId = x.FirstOrDefault()?.OrderId, |
|
|
|
TotalAmount = x.Sum(p => p.TotalAmount), |
|
|
|
}) |
|
|
|
.ToList(); |
|
|
|
} |
|
|
|
RedisHelper.RedisConn.GetDatabase().StringSet("order" + res.CreateId, JsonConvert.SerializeObject(res)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |