コード例 #1
0
        public async Task <IActionResult> NotifyByOrderNo(string no)
        {
            try
            {
                var notify = await _client.ExecuteAsync <WeChatPayUnifiedOrderNotify>(Request);

                if (notify.ReturnCode == "SUCCESS")
                {
                    if (notify.ResultCode == "SUCCESS")
                    {
                        await _mqService.DirectSend(QueueKeys.PaymentReceived, new PaymentReceived()
                        {
                            Note             = "微信支付成功结果通知",
                            OrderNo          = no,
                            PaymentFeeAmount = int.Parse(notify.TotalFee) / 100M,
                            PaymentMethod    = PaymentMethod.WeChat,
                            PaymentOn        = DateTime.ParseExact(notify.TimeEnd, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture)
                        });

                        return(WeChatPayNotifyResult.Success);
                    }
                }
                return(NoContent());
            }
            catch
            {
                return(NoContent());
            }
        }
コード例 #2
0
ファイル: ProductService.cs プロジェクト: zyu/module-shop
        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.DirectSend(QueueKeys.ProductView, new ProductViewed()
                {
                    UserId           = user.Id,
                    EntityId         = result.Id,
                    EntityTypeWithId = EntityTypeWithId.Product
                });
            }
            return(result);
        }
コード例 #3
0
ファイル: ReplyApiController.cs プロジェクト: zyu/module-shop
        public async Task <Result> Post([FromBody] ReplyAddParam param)
        {
            var user = await _workContext.GetCurrentOrThrowAsync();

            var reply = new Reply
            {
                ReviewId    = param.ReviewId,
                Comment     = param.Comment,
                IsAnonymous = param.IsAnonymous,
                ParentId    = null,
                UserId      = user.Id,
                ReplierName = param.IsAnonymous ? $"{user.FullName.First()}***{user.FullName.Last()}" : user.FullName,
            };

            if (param.ToReplyId != null)
            {
                var toReply = await _replyRepository.FirstOrDefaultAsync(param.ToReplyId.Value);

                if (toReply == null)
                {
                    throw new Exception("回复信息不存在");
                }
                reply.ToUserId   = toReply.UserId;
                reply.ToUserName = toReply.ReplierName;
                reply.ParentId   = toReply.ParentId ?? toReply.Id;
            }
            _replyRepository.Add(reply);
            await _replyRepository.SaveChangesAsync();

            var isAuto = await _appSettingService.Get <bool>(ReviewKeys.IsReplyAutoApproved);

            if (isAuto)
            {
                await _mqService.DirectSend(QueueKeys.ReplyAutoApproved, new ReplyAutoApprovedEvent()
                {
                    ReplyId = reply.Id
                });
            }
            return(Result.Ok());
        }
コード例 #4
0
        public async Task <Result> AddReview([FromBody] ReviewAddParam param)
        {
            var user = await _workContext.GetCurrentOrThrowAsync();

            var anyType = entityTypeIds.Any(c => c == param.EntityTypeId);

            if (!anyType)
            {
                throw new Exception("参数异常");
            }

            if (param.SourceType == null && param.SourceId != null)
            {
                throw new Exception("评论来源类型异常");
            }
            else if (param.SourceType != null && param.SourceId != null)
            {
                if (param.SourceType == ReviewSourceType.Order && param.EntityTypeId == EntityTypeWithId.Product)
                {
                    var anyProduct = _orderRepository.Query().Any(c => c.Id == param.SourceId.Value && c.OrderItems.Any(x => x.ProductId == param.EntityId));
                    if (!anyProduct)
                    {
                        throw new Exception("评论商品不存在");
                    }
                    var order = await _orderRepository.Query().FirstOrDefaultAsync(c => c.Id == param.SourceId);

                    if (order == null)
                    {
                        throw new Exception("订单不存在");
                    }
                    if (order.OrderStatus != OrderStatus.Complete)
                    {
                        throw new Exception("订单未完成,无法进行评价");
                    }
                }
            }

            // 一个用户
            // 评论 某订单 某商品只能一次
            // 评论 无订单关联 评论商品只能一次
            var any = await _reviewRepository.Query()
                      .AnyAsync(c => c.UserId == user.Id && c.EntityTypeId == (int)param.EntityTypeId && c.EntityId == param.EntityId && c.SourceId == param.SourceId && c.SourceType == param.SourceType);

            if (any)
            {
                throw new Exception("您已评论");
            }

            var review = new Review
            {
                Rating       = param.Rating,
                Title        = param.Title,
                Comment      = param.Comment,
                EntityId     = param.EntityId,
                EntityTypeId = (int)param.EntityTypeId,
                IsAnonymous  = param.IsAnonymous,
                UserId       = user.Id,
                ReviewerName = param.IsAnonymous ? $"{user.FullName.First()}***{user.FullName.Last()}" : user.FullName,
                SourceId     = param.SourceId,
                SourceType   = param.SourceType
            };

            if (param?.MediaIds.Count > 0)
            {
                var mediaIds = param.MediaIds.Distinct();
                int i        = 0;
                foreach (var mediaId in mediaIds)
                {
                    review.Medias.Add(new ReviewMedia()
                    {
                        DisplayOrder = i,
                        MediaId      = mediaId,
                        Review       = review
                    });
                    i++;
                }
            }
            _reviewRepository.Add(review);
            _reviewRepository.SaveChanges();

            var isAuto = await _appSettingService.Get <bool>(ReviewKeys.IsReviewAutoApproved);

            if (isAuto)
            {
                await _mqService.DirectSend(QueueKeys.ReviewAutoApproved, new ReviewAutoApprovedEvent()
                {
                    ReviewId = review.Id
                });
            }
            return(Result.Ok());
        }