예제 #1
0
        public async Task <Result> List()
        {
            var user = await _workContext.GetCurrentUserOrNullAsync();

            var cart = new CartResult();

            if (user != null)
            {
                cart = await _cartService.GetActiveCartDetails(user.Id);
            }
            return(Result.Ok(cart));
        }
예제 #2
0
        public async Task <Result> CollectStatus(int productId)
        {
            var user = await _workContext.GetCurrentUserOrNullAsync();

            if (user != null)
            {
                var any = await _productWishlistRepository.Query()
                          .AnyAsync(c => c.CustomerId == user.Id && c.ProductId == productId);

                return(Result.Ok(any));
            }
            return(Result.Ok(false));
        }
예제 #3
0
        public async Task <Result> Post([FromBody] FeedbackAddParam param)
        {
            var user = await _workContext.GetCurrentUserOrNullAsync();

            var model = new Feedback()
            {
                UserId  = user?.Id,
                Contact = param.Contact,
                Content = param.Content,
                Type    = param.Type.Value
            };

            _feedbackRepository.Add(model);
            await _feedbackRepository.SaveChangesAsync();

            return(Result.Ok());
        }
예제 #4
0
        public async Task <GoodsGetResult> GetGoodsByCache(int id)
        {
            var user = await _workContext.GetCurrentUserOrNullAsync();

            var result = await _staticCacheManager.GetAsync(CatalogKeys.GoodsById + id, async() =>
            {
                return(await GetGoods(id));
            });

            if (user != null)
            {
                await _mqService.Send(QueueKeys.ProductView, new ProductViewed()
                {
                    UserId           = user.Id,
                    EntityId         = result.Id,
                    EntityTypeWithId = EntityTypeWithId.Product
                });
            }
            return(result);
        }
예제 #5
0
        public async Task PaymentReceived(PaymentReceivedParam param)
        {
            if (param == null)
            {
                return;
            }

            var orderSs = new OrderStatus[] { OrderStatus.New, OrderStatus.PendingPayment, OrderStatus.PaymentFailed };
            var user    = await _workContext.GetCurrentUserOrNullAsync();

            var userId = user?.Id ?? (int)UserWithId.System;
            var query  = _orderRepository.Query();

            if (param.OrderId.HasValue && param.OrderId.Value > 0)
            {
                query = query.Where(c => c.Id == param.OrderId.Value);
            }
            else if (!string.IsNullOrWhiteSpace(param.OrderNo))
            {
                var longOrderNo = Convert.ToInt64(param.OrderNo);
                query = query.Where(c => c.No == longOrderNo);
            }
            else
            {
                return;
            }

            var order = await query.Include(c => c.OrderItems).ThenInclude(c => c.Product)
                        .FirstOrDefaultAsync();

            if (order == null || !orderSs.Contains(order.OrderStatus))
            {
                return;
            }

            order.OrderStatus      = OrderStatus.PaymentReceived;
            order.PaymentMethod    = param.PaymentMethod;
            order.PaymentOn        = param.PaymentOn ?? DateTime.Now;
            order.PaymentFeeAmount = param.PaymentFeeAmount ?? order.OrderTotal;
            order.UpdatedOn        = DateTime.Now;
            order.UpdatedById      = userId;

            //标记付款,付款减少库存商品,减少库存
            var productIds = order.OrderItems.Select(c => c.ProductId).Distinct();
            var stocks     = await _stockRepository.Query().Where(c => productIds.Contains(c.ProductId)).ToListAsync();

            var addStockHistories = new List <StockHistory>();

            foreach (var item in order.OrderItems)
            {
                OrderStockDoWorker(stocks, addStockHistories, item.Product, userId, -item.Quantity, order, "标记付款");
            }

            using (var transaction = _orderRepository.BeginTransaction())
            {
                await _orderRepository.SaveChangesAsync();

                await _stockRepository.SaveChangesAsync();

                if (addStockHistories.Count > 0)
                {
                    _stockHistoryRepository.AddRange(addStockHistories);
                    await _stockHistoryRepository.SaveChangesAsync();
                }
                transaction.Commit();
            }
        }