Пример #1
0
        public BaseApiResponse UserInvotes([FromBody] UserInvotesRequest request)
        {
            request.CheckNotNull(nameof(request));
            int     totalUserCount        = 0;
            decimal totalStoreOrderAmount = 0M;
            string  parentMobile          = "无";

            //获取用户信息
            var userInfo = _userQueryService.FindUser(request.Id);

            if (userInfo == null)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "没有找到该用户"
                });
            }
            if (userInfo.ParentId != Guid.Empty)
            {
                //获取用户的推荐人信息
                var parentInfo = _userQueryService.FindUser(userInfo.ParentId);
                parentMobile = parentInfo.Mobile;
            }

            //递归获取分类包含子类
            Func <QueryServices.Dtos.UserAlis, int, object> getNodeData = null;

            getNodeData = (user, level) => {
                dynamic node = new ExpandoObject();
                node.Id                = user.Id;
                node.NickName          = user.NickName;
                node.Mobile            = user.Mobile;
                node.CreatedOn         = user.CreatedOn.GetTimeSpan();
                node.Portrait          = user.Portrait;
                node.Role              = user.Role.ToDescription();
                node.Invotes           = new List <dynamic>();
                totalStoreOrderAmount += UserOrdersTotal(user.Id);
                totalUserCount++;
                var invotes = _userQueryService.UserChildrens(user.Id).OrderByDescending(x => x.CreatedOn);
                foreach (var invote in invotes)
                {
                    node.Invotes.Add(getNodeData(invote, level));
                }
                return(node);
            };

            var           myInvotes = _userQueryService.UserChildrens(request.Id).OrderByDescending(x => x.CreatedOn);
            List <object> nodes     = myInvotes.Select(x => getNodeData(x, 0)).ToList();



            return(new UserInvotesResponse
            {
                Invotes = nodes,
                TotalStoreOrderAmount = totalStoreOrderAmount,
                TotalUserCount = totalUserCount,
                ParentMobile = parentMobile
            });
        }
Пример #2
0
        public async Task <BaseApiResponse> ImportCurrency(ImportCurrencyRequest request)
        {
            request.CheckNotNull(nameof(request));
            var currentAccount = _contextService.GetCurrentAccount(HttpContext.Current);
            var userInfo       = _userQueryService.FindUser(currentAccount.UserId.ToGuid());

            var thirdCurrency = _thirdCurrencyQueryService.Find(request.Id);

            if (thirdCurrency == null)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "没有找到该外币"
                });
            }
            if (thirdCurrency.IsLocked)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "外币锁定,无法导入"
                });
            }
            //这里要访问第三方系统账号
            return(new BaseApiResponse {
                Code = 400, Message = "接口未开放,暂时无法导入"
            });

            //外币导入
            var command = new AcceptNewImportCommand(
                userInfo.WalletId,
                userInfo.Id,
                userInfo.Mobile,
                request.Account,
                request.Amount
                )
            {
                AggregateRootId = request.Id
            };
            var result = await ExecuteCommandAsync(command);

            if (!result.IsSuccess())
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage())
                });
            }
            return(new BaseApiResponse());
        }
Пример #3
0
        public async Task <BaseApiResponse> ApplyStore(ApplyStoreRequest request)
        {
            request.CheckNotNull(nameof(request));
            var currentAccount = _contextService.GetCurrentAccount(HttpContext.Current);

            var userInfo = _userQueryService.FindUser(currentAccount.UserId.ToGuid());

            if (userInfo.Role == UserRole.Consumer)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "Vip以上会员才可以申请开店"
                });
            }

            var store = _storeQueryService.InfoByUserId(currentAccount.UserId.ToGuid());

            if (store != null)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "您已开店,无法继续开店"
                });
            }

            var command = new CreateStoreCommand(
                GuidUtil.NewSequentialId(),
                currentAccount.UserId.ToGuid(),
                request.AccessCode,
                request.Name,
                request.Description,
                request.Region,
                request.Address,
                request.Subject.Name,
                request.Subject.Number,
                request.Subject.Pic);
            var result = await ExecuteCommandAsync(command);

            if (!result.IsSuccess())
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage())
                });
            }
            return(new BaseApiResponse());
        }
Пример #4
0
        public async Task <BaseApiResponse> Create(CreateOfflineStoreRequest request)
        {
            request.CheckNotNull(nameof(request));

            var user = _userQueryService.FindUser(request.Mobile);

            if (user == null)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "没有找到用户"
                });
            }
            var newofflinestoreid = GuidUtil.NewSequentialId();
            var command           = new CreateOfflineStoreCommand(
                newofflinestoreid,
                user.Id,
                request.Name,
                request.Thumb,
                request.Phone,
                request.Description,
                request.Labels,
                request.Region,
                request.Address,
                request.Persent,
                request.Longitude,
                request.Latitude,
                request.IsLocked);

            var result = await ExecuteCommandAsync(command);

            if (!result.IsSuccess())
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage())
                });
            }

            //添加操作记录
            var currentAdmin = _contextService.GetCurrentAdmin(HttpContext.Current);

            RecordOperat(currentAdmin.AdminId.ToGuid(), "添加线下店铺", newofflinestoreid, request.Name);
            return(new BaseApiResponse());
        }
Пример #5
0
        public async Task <BaseApiResponse> Add(AddPartnerRequest request)
        {
            request.CheckNotNull(nameof(request));

            var userInfo = _userQueryService.FindUser(request.Mobile);

            if (userInfo == null)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "没找到该用户"
                });
            }
            var newpartnerid = GuidUtil.NewSequentialId();
            var command      = new CreatePartnerCommand(
                newpartnerid,
                userInfo.Id,
                userInfo.WalletId,
                request.Mobile,
                request.Region,
                request.Level,
                request.Persent,
                request.CashPersent,
                request.BalanceInterval,
                request.Remark,
                request.IsLocked
                );
            var result = await ExecuteCommandAsync(command);

            if (!result.IsSuccess())
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage())
                });
            }
            //添加操作记录
            var currentAdmin = _contextService.GetCurrentAdmin(HttpContext.Current);

            RecordOperat(currentAdmin.AdminId.ToGuid(), "添加代理", newpartnerid, "{0}代理地区{1}".FormatWith(userInfo.Mobile, request.Region));

            return(new BaseApiResponse());
        }
Пример #6
0
        public async Task <BaseApiResponse> Create([FromBody] CreateOfflineStoreRequest request)
        {
            request.CheckNotNull(nameof(request));

            var user = _userQueryService.FindUser(request.Mobile);

            if (user == null)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "没有找到用户"
                });
            }

            var command = new CreateOfflineStoreCommand(
                GuidUtil.NewSequentialId(),
                user.Id,
                request.Name,
                request.Thumb,
                request.Phone,
                request.Description,
                request.Labels,
                request.Region,
                request.Address,
                request.Persent,
                request.Longitude,
                request.Latitude,
                request.IsLocked);

            var result = await ExecuteCommandAsync(command);

            if (!result.IsSuccess())
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage())
                });
            }
            return(new BaseApiResponse());
        }
Пример #7
0
        public async Task <BaseApiResponse> Add([FromBody] AddPartnerRequest request)
        {
            request.CheckNotNull(nameof(request));

            var userInfo = _userQueryService.FindUser(request.Mobile);

            if (userInfo == null)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "没找到该用户"
                });
            }

            var command = new CreatePartnerCommand(
                GuidUtil.NewSequentialId(),
                userInfo.Id,
                userInfo.WalletId,
                request.Mobile,
                request.Region,
                request.Level,
                request.Persent,
                request.CashPersent,
                request.BalanceInterval,
                request.Remark,
                request.IsLocked
                );
            var result = await ExecuteCommandAsync(command);

            if (!result.IsSuccess())
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage())
                });
            }
            return(new BaseApiResponse());
        }
Пример #8
0
        public BaseApiResponse Info()
        {
            var currentAccount = _contextService.GetCurrentAccount(HttpContext.Current);
            var userInfo       = _userQueryService.FindUser(currentAccount.UserId.ToGuid());

            if (userInfo == null)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "没找到用户"
                });
            }
            var cartGoodses      = _cartQueryService.CartGoodses(userInfo.CartId);
            var storeCartGoodses = cartGoodses.GroupBy(x => x.StoreId).Select(g => new
            {
                StoreId = g.Key,
                Goodses = g.Select(gs => new
                {
                    Id                = gs.Id,
                    GoodsId           = gs.GoodsId,
                    StoreId           = gs.StoreId,
                    SpecificationId   = gs.SpecificationId,
                    StoreName         = gs.StoreName,
                    SpecificationName = gs.SpecificationName,
                    GoodsName         = gs.GoodsName,
                    GoodsPic          = gs.GoodsPic,
                    Stock             = gs.Stock,
                    Price             = gs.Price,
                    OriginalPrice     = gs.OriginalPrice,
                    Quantity          = gs.Quantity,
                    Benevolence       = gs.Benevolence,
                    IsGoodsPublished  = gs.IsGoodsPublished,
                    GoodsStatus       = gs.GoodsStatus
                })
            });

            return(new CartInfoResponse
            {
                GoodsCount = cartGoodses.Sum(x => x.Quantity),
                StoreCartGoods = storeCartGoodses.Select(x => new StoreCartGoods
                {
                    StoreId = x.StoreId,
                    StoreName = x.Goodses.First().StoreName,
                    CartGoodses = x.Goodses.Select(cg => new CartGoods
                    {
                        Id = cg.Id,
                        StoreId = cg.StoreId,
                        GoodsId = cg.GoodsId,
                        SpecificationId = cg.SpecificationId,
                        GoodsName = cg.GoodsName,
                        GoodsPic = cg.GoodsPic,
                        SpecificationName = cg.SpecificationName,
                        Price = cg.Price,
                        OriginalPrice = cg.OriginalPrice,
                        Quantity = cg.Quantity,
                        Stock = cg.Stock,
                        Benevolence = cg.Benevolence,
                        IsGoodsPublished = cg.IsGoodsPublished,
                        GoodsStatus = cg.GoodsStatus.ToString(),
                        Checked = false
                    }).ToList()
                }).ToList()
            });
        }
Пример #9
0
        public async Task <BaseApiResponse> Register([FromBody] RegisterRequest request)
        {
            request.CheckNotNull(nameof(request));
            //验证码验证
            if (request.Token.IsNullOrEmpty() || _apiSession.GetMsgCode(request.Token) == null)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "验证码过期"
                });
            }
            if (_apiSession.GetMsgCode(request.Token) != request.MsgCode)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "验证码错误"
                });
            }

            if (!request.Mobile.IsMobileNumber())
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "手机号不正确"
                });
            }
            if (request.Password.Length > 20)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "密码长度不能大于20字符"
                });
            }
            if (request.Password.Contains(" "))
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "密码不能包含空格."
                });
            }

            //检查手机号是否可用
            if (!_userQueryService.CheckMobileIsAvliable(request.Mobile))
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "该手机号已注册."
                });
            }
            //验证推荐人
            var parentId = Guid.Empty;

            if (request.ParentId != Guid.Empty)
            {
                var parent = _userQueryService.FindUser(request.ParentId);
                if (parent == null)
                {
                    return(new BaseApiResponse {
                        Code = 400, Message = "没有找到该推荐人."
                    });
                }
                parentId = request.ParentId;
            }
            if (!request.ParentMobile.IsNullOrEmpty())
            {
                if (!request.ParentMobile.IsMobileNumber())
                {
                    return(new BaseApiResponse {
                        Code = 400, Message = "推荐人手机号不正确"
                    });
                }
                if (request.ParentMobile == request.Mobile)
                {
                    return(new BaseApiResponse {
                        Code = 400, Message = "推荐人不能是自己"
                    });
                }
                var parent = _userQueryService.FindUser(request.ParentMobile);
                if (parent == null)
                {
                    return(new BaseApiResponse {
                        Code = 400, Message = "没有找到该推荐人."
                    });
                }
                parentId = parent.Id;
            }
            //创建用户command
            var userViewModel = new UserViewModel {
                Id       = GuidUtil.NewSequentialId(),
                ParentId = parentId,
                Mobile   = request.Mobile,
                NickName = "用户" + StringGenerator.Generate(4),//创建随机昵称
                Password = request.Password,
                Portrait = "http://wftx-goods-img-details.oss-cn-shanghai.aliyuncs.com/default-userpic/userpic.png",
                Region   = "北京",
                Gender   = "保密"
            };
            var command = userViewModel.ToCreateUserCommand();
            var result  = await ExecuteCommandAsync(command);

            if (!result.IsSuccess())
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage())
                });
            }

            return(new RegisterResponse
            {
                Result = new RegisterResult
                {
                    Id = command.AggregateRootId.ToString()
                }
            });
        }