/// <summary> /// 创建订单扩展信息 /// </summary> /// <returns></returns> public async Task ModifyForm(CustomerFormEditDto input) { var order = await _ordeRepository.FirstOrDefaultAsync(input.OrderId); if (order == null) { throw new UserFriendlyException("订单信息不存在"); } var form = input.MapTo <CustomerForm>(); await _formRepository.InsertOrUpdateAsync(form); await CurrentUnitOfWork.SaveChangesAsync(); order.FormId = form.Id; }
/// <summary> /// 创建订单扩展信息 /// </summary> /// <returns></returns> public async Task ModifyForm(CustomerFormEditDto input) { var customer = await _customerRepository.FirstOrDefaultAsync(c => c.Id == input.CustomerId); if (customer == null) { throw new UserFriendlyException("该账户不存在"); } var order = await _ordeRepository.FirstOrDefaultAsync(input.OrderId); if (order == null) { throw new UserFriendlyException("订单信息不存在"); } var form = input.MapTo <CustomerForm>(); if (input.Id.HasValue) { await _profileRepository.DeleteAsync(c => c.FormId == form.Id); } await _formRepository.InsertOrUpdateAsync(form); if (!order.PayState) { if (customer.Balance < order.TotalPrice) { throw new UserFriendlyException("账户下余额不足,请充值后再试"); } var cost = new CustomerCost() { Balance = customer.Balance, CustomerId = customer.Id }; customer.Balance -= order.TotalPrice; cost.Cost = order.TotalPrice; cost.CurrentBalance = customer.Balance; await _costRepository.InsertAsync(cost); order.PayState = true; } await CurrentUnitOfWork.SaveChangesAsync(); order.FormId = form.Id; }