server/aspnetapp/Controllers/WebApi/OrdersController.cs
(开头部分) 8KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
#nullable disable
using aspnetapp.Models;
using aspnetapp.Services;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System.Text.Json;
namespace aspnetapp.Controllers.WebApi
{
[Route("api/[controller]")]
[ApiController]
public class OrdersController : ControllerBase
{
private readonly CounterContext _context;
private readonly IProductService _IProductService;
public OrdersController(CounterContext context, IProductService iProductService)
{
_context = context;
_IProductService = iProductService;
}
// GET: api/Orders
[HttpGet]
public async Task<ActionResult<OrderEntity>> GetOrder(string building, string goodsJsonStr, string peisongType, string remark, string wxid)
{
BuyrUserEntity thisu = await _context.BuyrUsers.FirstOrDefaultAsync(s => s.WeChatOpenid == wxid).ConfigureAwait(false);
List<item> goodsList = JsonSerializer.Deserialize<List<item>>(goodsJsonStr);
foreach (var item in goodsList)
{
OrderEntity orderEntity = new OrderEntity() { Building = building, BuyUserId = thisu.Id, BuyUserName = thisu.Name, BuyUserWxId = wxid, Remark = remark, ShowId = DateTime.Now.ToString("yyyyMMddHHmmssffff"), Department = thisu.Department, DepartmentId = thisu.DepartmentId, Company = thisu.Company, CompanyId = thisu.CompanyId, FoodsId = item.id, FoodsName = item.name, OrderForDate = DateTime.Now.Date.AddDays(item.dir).Date, OrderType = item.ordertype, Card = thisu.Card, CardType = thisu.CardType };
switch (peisongType)
{
case "yk":
orderEntity.PayType = (int)EnumCode.PayType.用卡;
break;
case "yq":
orderEntity.PayType = (int)EnumCode.PayType.用券;
break;
}
if (item.price.HasValue)
{
if (_IProductService.SubStock(item.id))
{
_context.Orders.Add(orderEntity);
await _context.SaveChangesAsync();
}
else
{
return BadRequest(item.name + "已售罄,请您重新点餐。");
}
}
else
{
_context.Orders.Add(orderEntity);
await _context.SaveChangesAsync();
}
}
后面还有 165 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。