Example #1
0
        private void AddBindInergral(UserMemberInfo member)
        {
            if (context.MemberIntegralRecord.Any((MemberIntegralRecord a) => a.MemberId == member.Id && (int)a.TypeId == 6))
            {
                return;
            }
            try
            {
                MemberIntegralRecord memberIntegralRecord = new MemberIntegralRecord()
                {
                    UserName   = member.UserName,
                    MemberId   = member.Id,
                    RecordDate = new DateTime?(DateTime.Now),
                    TypeId     = MemberIntegral.IntegralType.BindWX,
                    ReMark     = "BiindWeiXin"
                };
                IConversionMemberIntegralBase conversionMemberIntegralBase = Instance <IMemberIntegralConversionFactoryService> .Create.Create(MemberIntegral.IntegralType.BindWX, 0);

                Instance <IMemberIntegralService> .Create.AddMemberIntegral(memberIntegralRecord, conversionMemberIntegralBase);
            }
            catch (Exception exception)
            {
                Log.Error(exception);
            }
        }
Example #2
0
        private void DeductionIntegral(UserMemberInfo member, long Id, int integral)
        {
            if (integral == 0)
            {
                return;
            }
            MemberIntegralRecord memberIntegralRecord = new MemberIntegralRecord()
            {
                UserName   = member.UserName,
                MemberId   = member.Id,
                RecordDate = new DateTime?(DateTime.Now)
            };
            string str = "礼品订单号:";

            memberIntegralRecord.TypeId = MemberIntegral.IntegralType.Exchange;
            str = string.Concat(str, Id.ToString());
            MemberIntegralRecordAction memberIntegralRecordAction = new MemberIntegralRecordAction()
            {
                VirtualItemTypeId = new MemberIntegral.VirtualItemType?(MemberIntegral.VirtualItemType.Exchange),
                VirtualItemId     = Id
            };

            memberIntegralRecord.Himall_MemberIntegralRecordAction.Add(memberIntegralRecordAction);
            memberIntegralRecord.ReMark = str;
            IConversionMemberIntegralBase conversionMemberIntegralBase = Instance <IMemberIntegralConversionFactoryService> .Create.Create(MemberIntegral.IntegralType.Exchange, integral);

            Instance <IMemberIntegralService> .Create.AddMemberIntegral(memberIntegralRecord, conversionMemberIntegralBase);
        }
Example #3
0
        public CouponRecordInfo AddCouponRecord(CouponRecordInfo info)
        {
            string     shopName = base.Context.ShopInfo.FindById <ShopInfo>(info.ShopId).ShopName;
            CouponInfo info2    = base.Context.CouponInfo.FirstOrDefault <CouponInfo>(d => d.Id == info.CouponId);

            if ((info2.IsSyncWeiXin == 1) && (info2.WXAuditStatus != 1))
            {
                throw new HimallException("优惠券状态错误,不可领取");
            }
            if (info2.ReceiveType == CouponInfo.CouponReceiveType.IntegralExchange)
            {
                MemberIntegralRecord model = new MemberIntegralRecord
                {
                    UserName   = info.UserName,
                    MemberId   = info.UserId,
                    RecordDate = new DateTime?(DateTime.Now),
                    TypeId     = MemberIntegral.IntegralType.Exchange,
                    Integral   = info2.NeedIntegral,
                    ReMark     = "兑换优惠券:面值" + info2.Price.ToString("f2")
                };
                IConversionMemberIntegralBase conversionMemberIntegralEntity = Instance <IMemberIntegralConversionFactoryService> .Create.Create(MemberIntegral.IntegralType.Exchange, model.Integral);

                Instance <IMemberIntegralService> .Create.AddMemberIntegral(model, conversionMemberIntegralEntity);
            }
            info.CounponStatus = CouponRecordInfo.CounponStatuses.Unuse;
            info.CounponSN     = Guid.NewGuid().ToString().Replace("-", "");
            info.UsedTime      = null;
            info.CounponTime   = DateTime.Now;
            info.ShopName      = shopName;
            info.OrderId       = null;
            CouponRecordInfo info3 = base.Context.CouponRecordInfo.Add(info);

            base.Context.SaveChanges();
            return(info3);
        }
Example #4
0
        public void AddMemberIntegral(MemberIntegralRecord model, IConversionMemberIntegralBase conversionMemberIntegralEntity = null)
        {
            if (model == null)
            {
                throw new NullReferenceException("添加会员积分记录时,会员积分Model为空.");
            }
            if (0 == model.MemberId)
            {
                throw new NullReferenceException("添加会员积分记录时,会员Id为空.");
            }
            if (!context.UserMemberInfo.Any((UserMemberInfo a) => a.Id == model.MemberId && (a.UserName == model.UserName)))
            {
                throw new HimallException("不存在此会员");
            }
            if (conversionMemberIntegralEntity != null)
            {
                model.Integral = conversionMemberIntegralEntity.ConversionIntegral();
            }
            if (model.Integral == 0)
            {
                return;
            }
            MemberIntegral memberIntegral = context.MemberIntegral.FirstOrDefault((MemberIntegral a) => a.MemberId == model.MemberId);

            if (memberIntegral != null)
            {
                if (model.Integral > 0)
                {
                    MemberIntegral historyIntegrals = memberIntegral;
                    historyIntegrals.HistoryIntegrals = historyIntegrals.HistoryIntegrals + model.Integral;
                }
                else if (memberIntegral.AvailableIntegrals < Math.Abs(model.Integral))
                {
                    throw new HimallException("用户积分不足以扣减该积分!");
                }
                MemberIntegral availableIntegrals = memberIntegral;
                availableIntegrals.AvailableIntegrals = availableIntegrals.AvailableIntegrals + model.Integral;
            }
            else
            {
                memberIntegral = new MemberIntegral()
                {
                    MemberId = new long?(model.MemberId),
                    UserName = model.UserName
                };
                if (model.Integral <= 0)
                {
                    throw new HimallException("用户积分不足以扣减该积分!");
                }
                MemberIntegral historyIntegrals1 = memberIntegral;
                historyIntegrals1.HistoryIntegrals = historyIntegrals1.HistoryIntegrals + model.Integral;
                MemberIntegral availableIntegrals1 = memberIntegral;
                availableIntegrals1.AvailableIntegrals = availableIntegrals1.AvailableIntegrals + model.Integral;
                context.MemberIntegral.Add(memberIntegral);
            }
            context.MemberIntegralRecord.Add(model);
            context.SaveChanges();
        }
Example #5
0
        public void AddMemberIntegral(MemberIntegralRecord model, IConversionMemberIntegralBase conversionMemberIntegralEntity = null)
        {
            if (null == model)
            {
                throw new NullReferenceException("添加会员积分记录时,会员积分Model为空.");
            }
            if (0 == model.MemberId)
            {
                throw new NullReferenceException("添加会员积分记录时,会员Id为空.");
            }
            if (!Context.UserMemberInfo.Any(a => a.Id == model.MemberId && a.UserName == model.UserName))
            {
                throw new Himall.Core.HimallException("不存在此会员");
            }
            if (null != conversionMemberIntegralEntity)
            {
                model.Integral = conversionMemberIntegralEntity.ConversionIntegral();
            }
            if (model.Integral == 0)
            {
                return;
            }
            var userIntegral = Context.MemberIntegral.FirstOrDefault(a => a.MemberId == model.MemberId);

            if (userIntegral == null)
            {
                userIntegral          = new MemberIntegral();
                userIntegral.MemberId = model.MemberId;
                userIntegral.UserName = model.UserName;
                if (model.Integral > 0)
                {
                    userIntegral.HistoryIntegrals += model.Integral;
                }
                else
                {
                    throw new Himall.Core.HimallException("用户积分不足以扣减该积分!");
                }
                userIntegral.AvailableIntegrals += model.Integral;
                Context.MemberIntegral.Add(userIntegral);
            }
            else
            {
                if (model.Integral > 0)
                {
                    userIntegral.HistoryIntegrals += model.Integral;
                }
                else
                {
                    if (userIntegral.AvailableIntegrals < Math.Abs(model.Integral))
                    {
                        throw new Himall.Core.HimallException("用户积分不足以扣减该积分!");
                    }
                }
                userIntegral.AvailableIntegrals += model.Integral;
            }
            Context.MemberIntegralRecord.Add(model);
            Context.SaveChanges();
        }
        public void AddInviteIntegel(UserMemberInfo RegMember, UserMemberInfo InviteMember)
        {
            InviteRuleInfo inviteRule = GetInviteRule();

            if (inviteRule != null)
            {
                int?inviteIntegral = inviteRule.InviteIntegral;
                if ((inviteIntegral.GetValueOrDefault() != 0 ? true : !inviteIntegral.HasValue))
                {
                    if (!HasInviteIntegralRecord(RegMember.Id))
                    {
                        IMemberIntegralConversionFactoryService create = Instance <IMemberIntegralConversionFactoryService> .Create;
                        IMemberIntegralService memberIntegralService   = Instance <IMemberIntegralService> .Create;
                        MemberIntegralRecord   memberIntegralRecord    = new MemberIntegralRecord()
                        {
                            UserName   = RegMember.UserName,
                            MemberId   = RegMember.Id,
                            RecordDate = new DateTime?(DateTime.Now),
                            ReMark     = "被邀请注册",
                            TypeId     = MemberIntegral.IntegralType.Others
                        };
                        IConversionMemberIntegralBase conversionMemberIntegralBase = create.Create(MemberIntegral.IntegralType.Others, inviteRule.RegIntegral.Value);
                        memberIntegralService.AddMemberIntegral(memberIntegralRecord, conversionMemberIntegralBase);
                        MemberIntegralRecord memberIntegralRecord1 = new MemberIntegralRecord()
                        {
                            UserName   = InviteMember.UserName,
                            MemberId   = InviteMember.Id,
                            RecordDate = new DateTime?(DateTime.Now),
                            ReMark     = "邀请会员",
                            TypeId     = MemberIntegral.IntegralType.InvitationMemberRegiste
                        };
                        memberIntegralService.AddMemberIntegral(memberIntegralRecord1, create.Create(MemberIntegral.IntegralType.InvitationMemberRegiste, 0));
                        InviteRecordInfo inviteRecordInfo = new InviteRecordInfo()
                        {
                            RegIntegral    = new int?(inviteRule.RegIntegral.GetValueOrDefault()),
                            InviteIntegral = inviteRule.InviteIntegral.GetValueOrDefault(),
                            RecordTime     = new DateTime?(DateTime.Now),
                            RegTime        = new DateTime?(RegMember.CreateDate),
                            RegUserId      = new long?(RegMember.Id),
                            RegName        = RegMember.UserName,
                            UserId         = new long?(InviteMember.Id),
                            UserName       = InviteMember.UserName
                        };
                        AddInviteRecord(inviteRecordInfo);
                    }
                    return;
                }
            }
        }
Example #7
0
        private void AddIntegel(UserMemberInfo member)
        {
            if (!Instance <IMemberIntegralService> .Create.HasLoginIntegralRecord(member.Id))
            {
                MemberIntegralRecord memberIntegralRecord = new MemberIntegralRecord()
                {
                    UserName   = member.UserName,
                    MemberId   = member.Id,
                    RecordDate = new DateTime?(DateTime.Now),
                    ReMark     = "每天登录",
                    TypeId     = MemberIntegral.IntegralType.Login
                };
                IConversionMemberIntegralBase conversionMemberIntegralBase = Instance <IMemberIntegralConversionFactoryService> .Create.Create(MemberIntegral.IntegralType.Login, 0);

                Instance <IMemberIntegralService> .Create.AddMemberIntegral(memberIntegralRecord, conversionMemberIntegralBase);
            }
        }
Example #8
0
        public void AddOrderComment(OrderCommentInfo info)
        {
            OrderInfo orderInfo = (
                from a in context.OrderInfo
                where a.Id == info.OrderId && a.UserId == info.UserId
                select a).FirstOrDefault();

            if (orderInfo == null)
            {
                throw new HimallException("该订单不存在,或者不属于该用户!");
            }
            if ((
                    from a in context.OrderCommentInfo
                    where a.OrderId == info.OrderId && a.UserId == info.UserId
                    select a).Count() > 0)
            {
                throw new HimallException("您已经评论过该订单!");
            }
            info.ShopId      = orderInfo.ShopId;
            info.ShopName    = orderInfo.ShopName;
            info.UserName    = orderInfo.UserName;
            info.CommentDate = DateTime.Now;
            context.OrderCommentInfo.Add(info);
            context.SaveChanges();
            MemberIntegralRecord memberIntegralRecord = new MemberIntegralRecord()
            {
                UserName   = info.UserName,
                ReMark     = string.Concat("订单号:", info.OrderId),
                MemberId   = info.UserId,
                RecordDate = new DateTime?(DateTime.Now),
                TypeId     = MemberIntegral.IntegralType.Comment
            };
            MemberIntegralRecordAction memberIntegralRecordAction = new MemberIntegralRecordAction()
            {
                VirtualItemTypeId = new MemberIntegral.VirtualItemType?(MemberIntegral.VirtualItemType.Comment),
                VirtualItemId     = info.OrderId
            };

            memberIntegralRecord.ChemCloud_MemberIntegralRecordAction.Add(memberIntegralRecordAction);
            IConversionMemberIntegralBase conversionMemberIntegralBase = Instance <IMemberIntegralConversionFactoryService> .Create.Create(MemberIntegral.IntegralType.Comment, 0);

            Instance <IMemberIntegralService> .Create.AddMemberIntegral(memberIntegralRecord, conversionMemberIntegralBase);
        }
Example #9
0
        public JsonResult Management(string Operation, int Integral, string userName, int?userId, string reMark)
        {
            if (string.IsNullOrWhiteSpace(userName))
            {
                throw new HimallException("该用户不存在");
            }
            UserMemberInfo memberByName = ServiceHelper.Create <IMemberService>().GetMemberByName(userName);

            if (memberByName == null)
            {
                throw new HimallException("该用户不存在");
            }
            if (Integral <= 0)
            {
                throw new HimallException("积分必须为大于0的整数");
            }
            MemberIntegralRecord memberIntegralRecord = new MemberIntegralRecord()
            {
                UserName   = userName,
                MemberId   = memberByName.Id,
                RecordDate = new DateTime?(DateTime.Now),
                TypeId     = MemberIntegral.IntegralType.SystemOper,
                ReMark     = reMark
            };

            if (Operation == "sub")
            {
                Integral = -Integral;
            }
            IConversionMemberIntegralBase conversionMemberIntegralBase = ServiceHelper.Create <IMemberIntegralConversionFactoryService>().Create(MemberIntegral.IntegralType.SystemOper, Integral);

            ServiceHelper.Create <IMemberIntegralService>().AddMemberIntegral(memberIntegralRecord, conversionMemberIntegralBase);
            Result result = new Result()
            {
                success = true,
                msg     = "操作成功"
            };

            return(Json(result));
        }
        public JsonResult AddComment(long subOrderId, int star, string content)
        {
            ProductCommentInfo productCommentInfo = new ProductCommentInfo()
            {
                ReviewDate    = DateTime.Now,
                ReviewContent = content,
                UserId        = base.CurrentUser.Id,
                UserName      = base.CurrentUser.UserName,
                Email         = base.CurrentUser.Email,
                SubOrderId    = new long?(subOrderId),
                ReviewMark    = star
            };

            ServiceHelper.Create <ICommentService>().AddComment(productCommentInfo);
            MemberIntegralRecord memberIntegralRecord = new MemberIntegralRecord()
            {
                UserName   = base.CurrentUser.UserName,
                MemberId   = base.CurrentUser.Id,
                RecordDate = new DateTime?(DateTime.Now),
                TypeId     = MemberIntegral.IntegralType.Comment
            };
            MemberIntegralRecordAction memberIntegralRecordAction = new MemberIntegralRecordAction()
            {
                VirtualItemTypeId = new MemberIntegral.VirtualItemType?(MemberIntegral.VirtualItemType.Comment),
                VirtualItemId     = productCommentInfo.ProductId
            };

            memberIntegralRecord.ChemCloud_MemberIntegralRecordAction.Add(memberIntegralRecordAction);
            IConversionMemberIntegralBase conversionMemberIntegralBase = ServiceHelper.Create <IMemberIntegralConversionFactoryService>().Create(MemberIntegral.IntegralType.Comment, 0);

            ServiceHelper.Create <IMemberIntegralService>().AddMemberIntegral(memberIntegralRecord, conversionMemberIntegralBase);
            Result result = new Result()
            {
                success = true,
                msg     = "发表成功"
            };

            return(Json(result));
        }
Example #11
0
        public void AddCouponRecord(CouponRecordInfo info)
        {
            string     shopName   = context.ShopInfo.FindById <ShopInfo>(info.ShopId).ShopName;
            CouponInfo couponInfo = context.CouponInfo.FirstOrDefault((CouponInfo d) => d.Id == info.CouponId);

            if (couponInfo.IsSyncWeiXin == 1 && couponInfo.WXAuditStatus != 1)
            {
                throw new HimallException("优惠券状态错误,不可领取");
            }
            if (couponInfo.ReceiveType == CouponInfo.CouponReceiveType.IntegralExchange)
            {
                MemberIntegralRecord memberIntegralRecord = new MemberIntegralRecord()
                {
                    UserName   = info.UserName,
                    MemberId   = info.UserId,
                    RecordDate = new DateTime?(DateTime.Now),
                    TypeId     = MemberIntegral.IntegralType.Exchange,
                    Integral   = couponInfo.NeedIntegral
                };
                decimal price = couponInfo.Price;
                memberIntegralRecord.ReMark = string.Concat("兑换优惠券:面值", price.ToString("f2"));
                IConversionMemberIntegralBase conversionMemberIntegralBase = Instance <IMemberIntegralConversionFactoryService> .Create.Create(MemberIntegral.IntegralType.Exchange, memberIntegralRecord.Integral);

                Instance <IMemberIntegralService> .Create.AddMemberIntegral(memberIntegralRecord, conversionMemberIntegralBase);
            }
            info.CounponStatus = CouponRecordInfo.CounponStatuses.Unuse;
            CouponRecordInfo couponRecordInfo = info;
            Guid             guid             = Guid.NewGuid();

            couponRecordInfo.CounponSN = guid.ToString().Replace("-", "");
            info.UsedTime    = null;
            info.CounponTime = DateTime.Now;
            info.ShopName    = shopName;
            info.OrderId     = null;
            context.CouponRecordInfo.Add(info);
            context.SaveChanges();
        }
Example #12
0
        public UserMemberInfo Register(string username, string password, string email = "", long introducer = 0L)
        {
            UserMemberInfo nullable;

            if (string.IsNullOrWhiteSpace(username))
            {
                throw new ArgumentNullException("用户名不能为空");
            }
            if (CheckMemberExist(username))
            {
                throw new HimallException(string.Concat("用户名 ", username, " 已经被其它会员注册"));
            }
            if (string.IsNullOrWhiteSpace(password))
            {
                throw new ArgumentNullException("密码不能为空");
            }
            if (!string.IsNullOrEmpty(email) && CheckEmailExist(email))
            {
                throw new HimallException("邮箱已经被其它会员注册");
            }
            password = password.Trim();
            Guid   guid = Guid.NewGuid();
            string str  = guid.ToString("N").Substring(12);

            password = GetPasswrodWithTwiceEncode(password, str);
            using (TransactionScope transactionScope = new TransactionScope())
            {
                UserMemberInfo userMemberInfo = new UserMemberInfo()
                {
                    UserName      = username,
                    PasswordSalt  = str,
                    CreateDate    = DateTime.Now,
                    LastLoginDate = DateTime.Now,
                    Nick          = username,
                    RealName      = username,
                    Email         = email
                };
                nullable = userMemberInfo;
                if (introducer != 0)
                {
                    nullable.InviteUserId = new long?(introducer);
                }
                nullable.Password = password;
                nullable          = context.UserMemberInfo.Add(nullable);
                context.SaveChanges();
                if (!string.IsNullOrEmpty(email))
                {
                    IMessageService    create             = Instance <IMessageService> .Create;
                    MemberContactsInfo memberContactsInfo = new MemberContactsInfo()
                    {
                        Contact         = email,
                        ServiceProvider = "Himall.Plugin.Message.Email",
                        UserId          = nullable.Id,
                        UserType        = MemberContactsInfo.UserTypes.General
                    };
                    create.UpdateMemberContacts(memberContactsInfo);
                    MemberIntegralRecord memberIntegralRecord = new MemberIntegralRecord()
                    {
                        UserName   = username,
                        MemberId   = nullable.Id,
                        RecordDate = new DateTime?(DateTime.Now),
                        TypeId     = MemberIntegral.IntegralType.Reg,
                        ReMark     = "Bind Email"
                    };
                    IConversionMemberIntegralBase conversionMemberIntegralBase = Instance <IMemberIntegralConversionFactoryService> .Create.Create(MemberIntegral.IntegralType.Reg, 0);

                    Instance <IMemberIntegralService> .Create.AddMemberIntegral(memberIntegralRecord, conversionMemberIntegralBase);

                    IMemberInviteService memberInviteService = Instance <IMemberInviteService> .Create;
                    if (introducer != 0)
                    {
                        UserMemberInfo member = GetMember(introducer);
                        if (member != null)
                        {
                            memberInviteService.AddInviteIntegel(nullable, member);
                        }
                    }
                }
                transactionScope.Complete();
            }
            return(nullable);
        }
Example #13
0
 /// <summary>
 ///  //用户积分记录增加
 /// </summary>
 /// <param name="model"></param>
 /// <param name="conversionMemberIntegralEntity"></param>
 public static void AddMemberIntegral(MemberIntegralRecordInfo model, IConversionMemberIntegralBase conversionMemberIntegralEntity = null)
 {
     _iMemberIntegralService.AddMemberIntegral(model, conversionMemberIntegralEntity);
 }
        public void AddMemberIntegralNotAddHistoryIntegrals(MemberIntegralRecordInfo model, IConversionMemberIntegralBase conversionMemberIntegralEntity = null)
        {
            if (null == model)
            {
                throw new NullReferenceException("添加会员积分记录时,会员积分Model为空.");
            }
            if (0 == model.MemberId)
            {
                throw new NullReferenceException("添加会员积分记录时,会员Id为空.");
            }
            //if (!Context.UserMemberInfo.Any(a => a.Id == model.MemberId && a.UserName == model.UserName))
            if (!DbFactory.Default.Get <MemberInfo>().Where(a => a.Id == model.MemberId && a.UserName == model.UserName).Exist())
            {
                throw new Himall.Core.HimallException("不存在此会员");
            }
            if (null != conversionMemberIntegralEntity)
            {
                model.Integral = conversionMemberIntegralEntity.ConversionIntegral();
            }
            if (model.Integral == 0)
            {
                return;
            }
            //var userIntegral = Context.MemberIntegral.FirstOrDefault(a => a.MemberId == model.MemberId);
            var userIntegral = DbFactory.Default.Get <MemberIntegralInfo>().Where(a => a.MemberId == model.MemberId).FirstOrDefault();

            if (userIntegral == null)
            {
                userIntegral          = new MemberIntegralInfo();
                userIntegral.MemberId = model.MemberId;
                userIntegral.UserName = model.UserName;
                if (model.Integral <= 0)
                {
                    throw new Himall.Core.HimallException("用户积分不足以扣减该积分!");
                }
                userIntegral.AvailableIntegrals += model.Integral;
                //Context.MemberIntegral.Add(userIntegral);
                DbFactory.Default.Add(userIntegral);
            }
            else
            {
                if (model.Integral <= 0)
                {
                    if (userIntegral.AvailableIntegrals < Math.Abs(model.Integral))
                    {
                        throw new Himall.Core.HimallException("用户积分不足以扣减该积分!");
                    }
                }
                userIntegral.AvailableIntegrals += model.Integral;
                DbFactory.Default.Update(userIntegral);
            }

            DbFactory.Default.Add(model);
            if (model.MemberIntegralRecordActionInfo != null)
            {
                model.MemberIntegralRecordActionInfo.ForEach(p => p.IntegralRecordId = model.Id);
                DbFactory.Default.AddRange(model.MemberIntegralRecordActionInfo);
            }
        }
Example #15
0
        public void ConfirmRefund(long refundId, string managerRemark, string managerName)
        {
            decimal?        nullable;
            OrderRefundInfo now = context.OrderRefundInfo.FindById <OrderRefundInfo>(refundId);

            if (now.RefundPayType.HasValue)
            {
                switch (now.RefundPayType.Value)
                {
                case OrderRefundInfo.OrderRefundPayType.BackOut:
                {
                    if (now.RefundPayStatus.HasValue && now.RefundPayStatus.Value == OrderRefundInfo.OrderRefundPayStatus.PaySuccess)
                    {
                        break;
                    }
                    string paymentTypeGateway = now.OrderItemInfo.OrderInfo.PaymentTypeGateway;
                    IEnumerable <Plugin <IPaymentPlugin> > plugins =
                        from item in PluginsManagement.GetPlugins <IPaymentPlugin>(true)
                        where item.PluginInfo.PluginId == paymentTypeGateway
                        select item;
                    if (plugins.Count <Plugin <IPaymentPlugin> >() <= 0)
                    {
                        throw new HimallException("退款时,未找到支付方式!");
                    }
                    OrderPayInfo      orderPayInfo = context.OrderPayInfo.FirstOrDefault((OrderPayInfo e) => e.PayState && e.OrderId == now.OrderId);
                    IQueryable <long> nums         =
                        from item in context.OrderPayInfo
                        where item.PayId == orderPayInfo.PayId && item.PayState
                        select item into e
                        select e.OrderId;
                    decimal num = (
                        from o in context.OrderInfo
                        where nums.Contains(o.Id)
                        select o).ToList().Sum <OrderInfo>((OrderInfo e) => e.OrderTotalAmount);
                    if (orderPayInfo == null)
                    {
                        throw new HimallException("退款时,未找到原支付订单信息!");
                    }
                    PaymentPara paymentPara = new PaymentPara()
                    {
                        out_refund_no = now.Id.ToString(),
                        out_trade_no  = orderPayInfo.PayId.ToString(),
                        refund_fee    = now.Amount,
                        total_fee     = num
                    };
                    PaymentPara paymentPara1 = paymentPara;
                    PaymentInfo paymentInfo  = plugins.FirstOrDefault <Plugin <IPaymentPlugin> >().Biz.ProcessRefundFee(paymentPara1);
                    if (paymentInfo.OrderIds == null || paymentInfo.OrderIds.Count() <= 0)
                    {
                        break;
                    }
                    now.RefundPayStatus = new OrderRefundInfo.OrderRefundPayStatus?(OrderRefundInfo.OrderRefundPayStatus.PaySuccess);
                    context.SaveChanges();
                    break;
                }

                case OrderRefundInfo.OrderRefundPayType.BackCapital:
                {
                    if (now.RefundPayStatus.HasValue && now.RefundPayStatus.Value == OrderRefundInfo.OrderRefundPayStatus.PaySuccess)
                    {
                        break;
                    }
                    CapitalInfo capitalInfo = context.CapitalInfo.FirstOrDefault((CapitalInfo e) => e.MemId == now.UserId);
                    OrderBO     orderBO     = new OrderBO();
                    if (capitalInfo != null)
                    {
                        CapitalDetailInfo capitalDetailInfo = new CapitalDetailInfo()
                        {
                            Amount     = now.Amount,
                            CapitalID  = capitalInfo.Id,
                            CreateTime = new DateTime?(DateTime.Now),
                            SourceType = CapitalDetailInfo.CapitalDetailType.Refund,
                            SourceData = now.Id.ToString(),
                            Id         = orderBO.GenerateOrderNumber()
                        };
                        CapitalDetailInfo capitalDetailInfo1 = capitalDetailInfo;
                        CapitalInfo       capitalInfo1       = capitalInfo;
                        decimal?          balance            = capitalInfo1.Balance;
                        decimal           amount             = now.Amount;
                        if (balance.HasValue)
                        {
                            nullable = new decimal?(balance.GetValueOrDefault() + amount);
                        }
                        else
                        {
                            nullable = null;
                        }
                        capitalInfo1.Balance = nullable;
                        context.CapitalDetailInfo.Add(capitalDetailInfo1);
                    }
                    else
                    {
                        CapitalInfo capitalInfo2 = new CapitalInfo()
                        {
                            Balance      = new decimal?(now.Amount),
                            MemId        = now.UserId,
                            FreezeAmount = new decimal?(new decimal(0)),
                            ChargeAmount = new decimal?(new decimal(0))
                        };
                        List <CapitalDetailInfo> capitalDetailInfos = new List <CapitalDetailInfo>();
                        CapitalDetailInfo        capitalDetailInfo2 = new CapitalDetailInfo()
                        {
                            Amount     = now.Amount,
                            CreateTime = new DateTime?(DateTime.Now),
                            SourceData = now.Id.ToString(),
                            SourceType = CapitalDetailInfo.CapitalDetailType.Refund,
                            Id         = orderBO.GenerateOrderNumber()
                        };
                        capitalDetailInfos.Add(capitalDetailInfo2);
                        capitalInfo2.ChemCloud_CapitalDetail = capitalDetailInfos;
                        capitalInfo = capitalInfo2;
                        context.CapitalInfo.Add(capitalInfo);
                    }
                    now.RefundPayStatus = new OrderRefundInfo.OrderRefundPayStatus?(OrderRefundInfo.OrderRefundPayStatus.PaySuccess);
                    context.SaveChanges();
                    break;
                }
                }
            }
            if (now.ManagerConfirmStatus != OrderRefundInfo.OrderRefundConfirmStatus.UnConfirm)
            {
                throw new HimallException("只有未确认状态的退款/退货才能进行确认操作");
            }
            now.ManagerConfirmStatus = OrderRefundInfo.OrderRefundConfirmStatus.Confirmed;
            now.ManagerConfirmDate   = DateTime.Now;
            now.ManagerRemark        = managerRemark;
            OrderOperationLogInfo orderOperationLogInfo = new OrderOperationLogInfo()
            {
                Operator       = managerName,
                OrderId        = now.OrderId,
                OperateDate    = DateTime.Now,
                OperateContent = "确认退款/退货"
            };

            context.OrderOperationLogInfo.Add(orderOperationLogInfo);
            UserMemberInfo userMemberInfo   = context.UserMemberInfo.FindById <UserMemberInfo>(now.UserId);
            OrderInfo      orderInfo        = context.OrderInfo.FindById <OrderInfo>(now.OrderId);
            decimal        orderTotalAmount = orderInfo.OrderTotalAmount - orderInfo.Freight;
            decimal        amount1          = now.Amount - (orderInfo.IntegralDiscount * (now.Amount / orderTotalAmount));

            amount1 = Math.Round(amount1, 2);
            if (amount1 > new decimal(0))
            {
                OrderInfo refundTotalAmount = orderInfo;
                refundTotalAmount.RefundTotalAmount = refundTotalAmount.RefundTotalAmount + amount1;
                if (orderInfo.RefundTotalAmount > orderTotalAmount)
                {
                    orderInfo.RefundTotalAmount = orderTotalAmount;
                }
            }
            if (now.RefundMode != OrderRefundInfo.OrderRefundMode.OrderRefund)
            {
                MemberIntegralExchangeRules integralChangeRule = Instance <IMemberIntegralService> .Create.GetIntegralChangeRule();

                if (integralChangeRule != null)
                {
                    int            moneyPerIntegral = integralChangeRule.MoneyPerIntegral;
                    int            num1             = (int)Math.Floor(now.Amount / moneyPerIntegral);
                    MemberIntegral memberIntegral   = userMemberInfo.ChemCloud_MemberIntegral.FirstOrDefault();
                    int            num2             = (memberIntegral == null ? 0 : memberIntegral.AvailableIntegrals);
                    if (num1 > 0 && num2 > 0 && orderInfo.OrderStatus == OrderInfo.OrderOperateStatus.Finish)
                    {
                        MemberIntegralRecord memberIntegralRecord = new MemberIntegralRecord()
                        {
                            UserName   = userMemberInfo.UserName,
                            MemberId   = userMemberInfo.Id,
                            RecordDate = new DateTime?(DateTime.Now),
                            TypeId     = MemberIntegral.IntegralType.Others
                        };
                        object[] id = new object[] { "售后编号【", now.Id, "】退款应扣除积分", num1.ToString() };
                        memberIntegralRecord.ReMark = string.Concat(id);
                        num1 = (num1 > num2 ? num2 : num1);
                        num1 = -num1;
                        IConversionMemberIntegralBase conversionMemberIntegralBase = Instance <IMemberIntegralConversionFactoryService> .Create.Create(MemberIntegral.IntegralType.Others, num1);

                        Instance <IMemberIntegralService> .Create.AddMemberIntegral(memberIntegralRecord, conversionMemberIntegralBase);
                    }
                }
            }
            context.SaveChanges();
            MessageOrderInfo messageOrderInfo = new MessageOrderInfo()
            {
                OrderId     = orderInfo.Id.ToString(),
                ShopId      = orderInfo.ShopId,
                ShopName    = orderInfo.ShopName,
                RefundMoney = now.Amount,
                SiteName    = Instance <ISiteSettingService> .Create.GetSiteSettings().SiteName,
                TotalMoney  = orderInfo.OrderTotalAmount
            };

            Task.Factory.StartNew(() => Instance <IMessageService> .Create.SendMessageOnOrderRefund(orderInfo.UserId, messageOrderInfo));
            if (orderInfo.PayDate.HasValue)
            {
                UpdateShopVisti(now, orderInfo.PayDate.Value);
                UpdateProductVisti(now, orderInfo.PayDate.Value);
            }
        }
Example #16
0
        public ActionResult CheckCode(string pluginId, string code, string destination)
        {
            string         str         = CacheKeyCollection.MemberPluginCheck(base.CurrentUser.UserName, pluginId);
            object         obj         = Cache.Get(str);
            UserMemberInfo currentUser = base.CurrentUser;
            string         str1        = "";

            if (obj == null || !(obj.ToString() == code))
            {
                Result result = new Result()
                {
                    success = false,
                    msg     = "验证码不正确或者已经超时"
                };
                return(Json(result));
            }
            IMessageService messageService = ServiceHelper.Create <IMessageService>();

            if (messageService.GetMemberContactsInfo(pluginId, destination, MemberContactsInfo.UserTypes.General) != null)
            {
                Result result1 = new Result()
                {
                    success = false,
                    msg     = string.Concat(destination, "已经绑定过了!")
                };
                return(Json(result1));
            }
            if (pluginId.ToLower().Contains("email"))
            {
                currentUser.Email = destination;
                str1 = "邮箱";
            }
            else if (pluginId.ToLower().Contains("sms"))
            {
                currentUser.CellPhone = destination;
                str1 = "手机";
            }
            ServiceHelper.Create <IMemberService>().UpdateMember(currentUser);
            MemberContactsInfo memberContactsInfo = new MemberContactsInfo()
            {
                Contact         = destination,
                ServiceProvider = pluginId,
                UserId          = base.CurrentUser.Id,
                UserType        = MemberContactsInfo.UserTypes.General
            };

            messageService.UpdateMemberContacts(memberContactsInfo);
            Cache.Remove(CacheKeyCollection.MemberPluginCheck(base.CurrentUser.UserName, pluginId));
            Cache.Remove(CacheKeyCollection.Member(base.CurrentUser.Id));
            Cache.Remove(string.Concat("Rebind", base.CurrentUser.Id));
            UserMemberInfo member = null;

            if (currentUser.InviteUserId.HasValue)
            {
                member = ServiceHelper.Create <IMemberService>().GetMember(currentUser.InviteUserId.Value);
            }
            Task.Factory.StartNew(() => {
                MemberIntegralRecord memberIntegralRecord = new MemberIntegralRecord()
                {
                    UserName   = currentUser.UserName,
                    MemberId   = currentUser.Id,
                    RecordDate = new DateTime?(DateTime.Now),
                    TypeId     = MemberIntegral.IntegralType.Reg,
                    ReMark     = string.Concat("绑定", str1)
                };
                IConversionMemberIntegralBase conversionMemberIntegralBase = ServiceHelper.Create <IMemberIntegralConversionFactoryService>().Create(MemberIntegral.IntegralType.Reg, 0);
                ServiceHelper.Create <IMemberIntegralService>().AddMemberIntegral(memberIntegralRecord, conversionMemberIntegralBase);
                if (member != null)
                {
                    ServiceHelper.Create <IMemberInviteService>().AddInviteIntegel(currentUser, member);
                }
            });
            Result result2 = new Result()
            {
                success = true,
                msg     = "验证正确"
            };

            return(Json(result2));
        }