Пример #1
0
        public static void Pay(long amountId)
        {
            var amount = PayAmountService.Instance.GetPayAmount(amountId);
            var user   = UserService.GetCurrentUser();

            UserService.Instance.UpdateUserBalance(user.Id, amount.BaseAmount + amount.GiveAmount, "用户充值V币");
        }
Пример #2
0
        /// <summary>
        /// 退款
        /// </summary>
        public void ReturnPrice(int price, IList <User> userList)
        {
            var rule        = ReturnRuleRepository.Instance.Source.FirstOrDefault();
            int updatePrice = 0;

            if (rule != null)
            {
                //按百分比退款
                if (rule.Type == 1)
                {
                    updatePrice = price + (int)(price * rule.Numerical);
                }
                foreach (var user in userList)
                {
                    RechargeRecordService.Instance.AddRecharge
                    (
                        new RechargeRecordDto()
                    {
                        Price    = updatePrice,
                        Operator = UserService.GetCurrentUser().UserName,
                        UserId   = user.Id,
                        UserName = user.UserName,
                        Remark   = string.Format("推介不中退款{0}V币", updatePrice)
                    }
                    );
                    user.Balance = user.Balance + updatePrice;
                    UserRepository.Instance.Save(user);
                }
            }
        }
Пример #3
0
        public bool BuyPromote(int id)
        {
            bool isAddRecord = false;
            var  promote     = promoteRepository.Find(x => x.Id == id).FirstOrDefault();

            if (promote == null)
            {
                throw new ServiceException("不存在此条推介或竞彩");
            }

            var userId = UserService.GetCurrentUser().Id;
            var user   = UserRepository.Instance.Source.FirstOrDefault(x => x.Id == userId);

            if (user == null)
            {
                throw new ServiceException("不存在当前登录用户");
            }

            if (promote.PromoteType == 1 ? user.Balance - promote.Price < 0 : user.Integral - promote.Integral < 0)
            {
                throw new ServiceException("您的余额不足,请充值后再进行购买");
            }

            promote.UserList.Add(user);
            if (promote.PromoteType == 1)
            {
                user.Balance = user.Balance - promote.Price;
                isAddRecord  = true;
            }
            else if (promote.PromoteType == 2)
            {
                user.Integral = user.Integral - promote.Integral;
            }

            promoteRepository.Transaction(() =>
            {
                promoteRepository.Save(promote);
                UserRepository.Instance.Save(user);
                if (isAddRecord)
                {
                    RechargeRecordService.Instance.AddRecharge
                    (
                        new RechargeRecordDto()
                    {
                        Price    = promote.Price,
                        Operator = UserService.GetCurrentUser().UserName,
                        UserId   = user.Id,
                        UserName = user.UserName,
                        Remark   = string.Format("购买推介用户余额扣减{0}V币", promote.Price)
                    }
                    );
                }
            });
            return(true);
        }
Пример #4
0
        public void AddOrder(OrderDto dto)
        {
            var goods = GoodsRepository.Instance.Find(x => x.Id == dto.GoodsId).FirstOrDefault();

            if (goods == null)
            {
                throw new ServiceException("不存在此商品");
            }
            if (Convert.ToInt32(dto.Quantity) > goods.Quantity)
            {
                throw new ServiceException("此商品库存不足");
            }
            var userId = UserService.GetCurrentUser().Id;
            var user   = UserService.Instance.GetUser(userId);

            if (user == null)
            {
                throw new ServiceException("当前用户未登录,不能完成下单操作");
            }
            if (user.Integral < goods.Integral)
            {
                throw new ServiceException("对不起,您的积分暂时不足以兑换此商品,请选择其它商品进行兑换");
            }

            var entity = dto.ToModel <Order>();

            entity.Integral = goods.Integral;
            entity.OrderNo  = OrderHelper.GetOrderNo();
            entity.State    = OrderStateEnum.未发货;
            entity.UserId   = userId;
            //减库存
            goods.Quantity = goods.Quantity - Convert.ToInt32(dto.Quantity);
            orderRepository.Transaction(() =>
            {
                orderRepository.Insert(entity);
                GoodsRepository.Instance.Save(goods);
            });
        }
Пример #5
0
        private static void Init()
        {
            AutoMapper.Mapper.CreateMap <User, UserDto>()
            .ForMember(x => x.PromoteList, x => x.MapFrom(src => src.PromoteList));
            AutoMapper.Mapper.CreateMap <UserDto, User>()
            .ForMember(x => x.CreateTime, x => x.MapFrom(src => DateTime.Now))
            .ForMember(x => x.Password, x => x.MapFrom(src => MD5Helper.MD5Encrypt64(src.Password)));

            AutoMapper.Mapper.CreateMap <Match, MatchDto>()
            .ForMember(x => x.MatchState, x => x.MapFrom(src => src.MatchState.ToString()))
            .ForMember(x => x.MatchName, x => x.MapFrom(src => src.TeamA + "VS" + src.TeamB));
            AutoMapper.Mapper.CreateMap <MatchDto, Match>()
            .ForMember(x => x.MatchState, x => x.MapFrom(src => MatchStateEnum.未开始))
            .ForMember(x => x.Operator, x => x.MapFrom(src => UserService.GetCurrentUser().UserName))
            .ForMember(x => x.CreateTime, x => x.MapFrom(src => DateTime.Now));

            AutoMapper.Mapper.CreateMap <News, NewsDto>()
            .ForMember(x => x.NewsType, x => x.MapFrom(src => src.NewsType.ToString()));
            AutoMapper.Mapper.CreateMap <NewsDto, News>()
            .ForMember(x => x.Operator, x => x.MapFrom(src => UserService.GetCurrentUser().UserName))
            .ForMember(x => x.CreateTime, x => x.MapFrom(src => DateTime.Now))
            .ForMember(x => x.NewsType, x => x.MapFrom(src => EnumHelper.Parse <NewsTypeEnum>(src.NewsType)));

            AutoMapper.Mapper.CreateMap <Promote, PromoteDto>()
            .ForMember(x => x.BuyState, x => x.MapFrom(src => src.UserList.Any(y => y.Id == UserService.GetCurrentUser().Id)))
            .ForMember(x => x.RaceType, x => x.MapFrom(src => src.RaceType.ToString()))
            .ForMember(x => x.State, x => x.MapFrom(src => src.State.ToString()))
            .ForMember(x => x.IsSend, x => x.MapFrom(src => src.IsSend ? "是" : "否"))
            .ForMember(x => x.IsReturn, x => x.MapFrom(src => src.IsReturn ? "是" : "否"))
            .ForMember(x => x.SendType, x => x.MapFrom(src => src.SendType.ToString()))
            .ForMember(x => x.MatchTime, x => x.MapFrom(src => src.Match.MatchTime))
            .ForMember(x => x.MatchName, x => x.MapFrom(src => src.Match.TeamA + "VS" + src.Match.TeamB));
            AutoMapper.Mapper.CreateMap <PromoteDto, Promote>()
            .ForMember(x => x.CreateTime, x => x.MapFrom(src => DateTime.Now))
            .ForMember(x => x.RaceType, x => x.MapFrom(src => EnumHelper.Parse <RaceTypeEnum>(src.RaceType)))
            .ForMember(x => x.State, x => x.MapFrom(src => EnumHelper.Parse <PromoteStateEnum>(src.State)))
            .ForMember(x => x.SendType, x => x.MapFrom(src => EnumHelper.Parse <SendTypeEnum>(src.SendType)));



            AutoMapper.Mapper.CreateMap <RechargeRecord, RechargeRecordDto>();
            AutoMapper.Mapper.CreateMap <RechargeRecordDto, RechargeRecord>()
            .ForMember(x => x.CreateTime, x => x.MapFrom(src => DateTime.Now));

            AutoMapper.Mapper.CreateMap <Goods, GoodsDto>()
            .ForMember(x => x.SizeList, x => x.MapFrom(src => src.Size.Split(',').ToList()));

            AutoMapper.Mapper.CreateMap <GoodsDto, Goods>().ForMember(x => x.CreateTime, x => x.MapFrom(src => DateTime.Now));

            AutoMapper.Mapper.CreateMap <Order, OrderDto>()
            .ForMember(x => x.GoodsName, x => x.MapFrom(src => src.Goods.GoodsName))
            .ForMember(x => x.GoodsImage, x => x.MapFrom(src => src.Goods.GoodsImage));
            AutoMapper.Mapper.CreateMap <OrderDto, Order>()
            .ForMember(x => x.OrderNo, x => x.MapFrom(src => OrderHelper.GetOrderNo()))
            .ForMember(x => x.CreateTime, x => x.MapFrom(src => DateTime.Now));

            AutoMapper.Mapper.CreateMap <Customer, CustomerDto>()
            .ForMember(x => x.AnswerTime, x => x.MapFrom(src => src.AnswerTime));
            AutoMapper.Mapper.CreateMap <CustomerDto, Customer>().ForMember(x => x.CreateTime, x => x.MapFrom(src => DateTime.Now));

            AutoMapper.Mapper.CreateMap <PayAmount, PayAmountDto>();
            AutoMapper.Mapper.CreateMap <PayAmountDto, PayAmount>()
            .ForMember(x => x.CalType, x => x.MapFrom(src => EnumHelper.Parse <CalTypeEnum>(src.CalType)))
            .ForMember(x => x.CreateTime, x => x.MapFrom(src => DateTime.Now));

            AutoMapper.Mapper.CreateMap <ReturnRule, ReturnRuleDto>().ForMember(x => x.Numerical, x => x.MapFrom(src => src.Numerical * 100));
        }