//[UnitOfWork(isTransactional:true)] public async Task <bool> CreateOrder(CreateOrderInput input) { long userId = AbpSession.GetUserId(); var cachelist = _customerManager.GetCacheCustomerForUserByList(); var cust = cachelist.Where(m => m.Id == input.CustomerId).FirstOrDefault(); if (cust == null) { throw new UserFriendlyException("未找到对应订单信息,购买失败"); } //更新缓存 lock (_lock) { int tradeCnt = cust.TransTimes ?? 0; tradeCnt++; if (tradeCnt > AppConsts.RecordCanSaleTimes) { throw new UserFriendlyException("超过预定数量,购买失败"); } if (cust.BuyUserIds.IndexOf(userId.ToString()) != -1) { throw new UserFriendlyException("请勿重复购买过此记录"); } cust.TransTimes = (cust.TransTimes ?? 0) + 1; cust.BuyUserIds = cust.BuyUserIds + "," + userId.ToString(); } //下面的代码可以放到队列 var customer = _customerManager.GetCustomer(input.CustomerId); if (customer == null) { throw new UserFriendlyException("未找到对应订单信息,购买失败"); } if (customer.BuyUserIds.IndexOf(userId.ToString()) != -1) { throw new UserFriendlyException("请勿重复购买过此记录"); } var order = new DX.Loan.Order(); order.Age = customer.Age; order.AppEquipment = customer.AppEquipment; order.ApplicationDate = customer.ApplicationDate; order.Area = customer.Area; order.CreditRating = customer.CreditRating; order.CustomerId = customer.Id; order.IdCard = customer.IdCard; order.Interest = customer.Interest; order.Name = customer.Name; order.QQ = customer.QQ; order.SesameScore = customer.SesameScore; order.Source = customer.Source; order.Tel = customer.Tel; order.WeChat = customer.WeChat; order.OrderAmount = customer.RecordCharge ?? 0;//价格 order.OrderNo = GenerateOrderNo(OrderType.FK); order.Status = OrderType.FK.ToString(); //已付款 order.UserId = userId; await _orderRepository.InsertAsync(order); await _tradeManager.CreateTradeForOrderAsync(customer.RecordCharge ?? 0, order.OrderNo); customer.BuyUserIds = customer.BuyUserIds + "," + userId.ToString(); // 更新CustomerInfo 的 BuyUserIds 字段 return(true); }