コード例 #1
0
        /// <summary>
        /// 处理订单
        /// </summary>
        /// <param name="id"></param>
        public async Task DealWithAsync(int id)
        {
            var model = await this.RechargeRecordRepository.FindAsync(r => r.Id == id && r.Status == 0);

            if (model != null)
            {
                switch (model.Source)
                {
                case "身家充值":
                    using (var ts = await this.DbContext.Database.BeginTransactionAsync())
                    {
                        model.Status = 1;
                        var member = await this.MemberRepository.FindAsync(m => m.Id == model.UserId.ToInt32(0));

                        member.Shenjia = (member.Shenjia ?? 0) + model.RMB.ToDecimal();
                        await this.MemberRepository.UpdateAsync(member);

                        await this.RechargeRecordRepository.UpdateAsync(model);

                        ts.Commit();
                    }
                    break;

                case "会员充值":
                    using (var ts = await this.DbContext.Database.BeginTransactionAsync())
                    {
                        model.Status = 1;
                        var member = await this.MemberRepository.FindAsync(m => m.Id == model.UserId.ToInt32(0));

                        if (model.RMB == "99")                                     //1年会员,10次兑换
                        {
                            DateTime startTime = member.Stime.GetValueOrDefault(); //会员开始时间
                            DateTime endTime   = member.Etime.GetValueOrDefault(); //结束时间
                            DateTime nowTime   = DateTime.Now;
                            if (endTime - nowTime <= TimeSpan.Zero)
                            {
                                startTime = nowTime;
                                endTime   = nowTime.AddYears(1);
                            }
                            else
                            {
                                endTime = endTime.AddYears(1);
                            }
                            member.Stime                = startTime;
                            member.Etime                = endTime;
                            member.Conversions          = member.Conversions.GetValueOrDefault(0) + 10;
                            member.RemainingConversions = member.Conversions.GetValueOrDefault(0) + 10;
                        }

                        await this.MemberRepository.UpdateAsync(member);

                        await this.RechargeRecordRepository.UpdateAsync(model);

                        ts.Commit();
                    }
                    break;
                }
                RongCloudHelper.PublishSystemBySystem(model.UserId, "充值成功,请查看");
            }
        }
コード例 #2
0
        /// <summary>
        /// 修改状态
        /// </summary>
        /// <param name="id">兑换id</param>
        /// <param name="examine">修改标识</param>
        /// <param name="official">最终值</param>
        /// <returns></returns>
        public bool UpdateExamine(int id, string examine, string official)
        {
            var model = this.ExchangeRepository.Find(ex => ex.Id == id);

            switch (examine)
            {
            case "1":                      //审核
                model.Official = official; //设置最终值
                model.Examine  = "5";      //设置为审核完成
                //通知用户
                RongCloudHelper.PublishSystemBySystem(model.UserId, "您的兑换已审核完成,请查看");
                break;

            case "2":                //确认回收
                model.Examine = "3"; //将状态改为可兑换
                _integralChangeService.AddExchange(model.UserId.ToInt32(), model.Official);
                //通知用户
                RongCloudHelper.PublishSystemBySystem(model.UserId, "您的兑换已被确认回收,请查看");
                break;

            case "3":                //上架
                model.Examine = "3"; //将状态改为可兑换
                break;

            case "4":                 //下架
                model.Examine = "10"; //将状态改为已结束
                //通知用户
                RongCloudHelper.PublishSystemBySystem(model.UserId, $"您的兑换已下架,下架原因:{official},请查看");
                break;
            }

            return(this.ExchangeRepository.Update(model));
        }
コード例 #3
0
        /// <summary>
        /// 处理订单
        /// </summary>
        /// <param name="id"></param>
        /// <param name="paymentWay">付款方式</param>
        /// <returns></returns>
        public async Task <bool> DealWithAsync(int id, string paymentWay)
        {
            var model = await this.ExchangeEventRepository.FindAsync(ee => ee.Id == id && ee.Status == 0);

            if (model == null)
            {
                return(true);
            }
            bool b = false;

            using (var ts = await this.DbContext.Database.BeginTransactionAsync())
            {
                //添加兑换人员表
                var ep = new ExchangePerson()
                {
                    UserId     = model.UserId.ToString(),
                    ExId       = model.ExId.ToString(),
                    AddTime    = DateTime.Now,
                    PaymentWay = paymentWay,
                    Address    = model.AddressId.ToString(),
                    Status     = 1,
                    SerialNum  = model.OrderNo.SplitLeft("-"),
                    Postage    = model.Postage.GetValueOrDefault(),
                    ShenJia    = model.ShenJia.GetValueOrDefault()
                };
                if (model.Examine == "身家兑换")
                {
                    ep.Examine = "1";
                    ep         = await this.ExchangePersonRepository.AddAsync(ep);

                    //更新兑换表
                    var ex = await this.ExchangeRepository.FindAsync(e => e.Id == model.ExId);

                    ex.Examine        = "10"; //修改为已结束
                    ex.ExchangePerson = model.UserId.ToString();
                    b = await this.ExchangeRepository.UpdateAsync(ex);

                    //更新会员表
                    var member = await this.MemberRepository.FindAsync(m => m.Id == model.UserId);

                    member.Shenjia -= ex.Price.ToDecimal();
                    b = await this.MemberRepository.UpdateAsync(member);
                }
                if (model.Examine == "会员租赁")
                {
                    ep.Examine = "2";
                    ep         = await this.ExchangePersonRepository.AddAsync(ep);

                    //更新兑换表
                    var ex = await this.ExchangeRepository.FindAsync(e => e.Id == model.ExId);

                    ex.Examine        = "4"; //修改为已兑换
                    ex.ExchangePerson = model.UserId.ToString();
                    b = await this.ExchangeRepository.UpdateAsync(ex);

                    //更新会员表
                    var member = await this.MemberRepository.FindAsync(m => m.Id == model.UserId);

                    member.Deposit += model.Deposit;
                    member.RemainingConversions--;
                    b = await this.MemberRepository.UpdateAsync(member);
                }
                if (model.Examine == "单次租赁")
                {
                    ep.Examine = "3";
                    ep         = await this.ExchangePersonRepository.AddAsync(ep);

                    //更新兑换表
                    var ex = await this.ExchangeRepository.FindAsync(e => e.Id == model.ExId);

                    ex.Examine        = "4"; //修改为已兑换
                    ex.ExchangePerson = model.UserId.ToString();
                    b = await this.ExchangeRepository.UpdateAsync(ex);

                    //更新会员表
                    var member = await this.MemberRepository.FindAsync(m => m.Id == model.UserId);

                    member.Deposit += model.Deposit;
                    b = await this.MemberRepository.UpdateAsync(member);
                }
                if (model.Examine == "兑换券")
                {
                    ep.Examine = "4";
                    ep         = await this.ExchangePersonRepository.AddAsync(ep);

                    //更新兑换表
                    var ex = await this.ExchangeRepository.FindAsync(e => e.Id == model.ExId);

                    ex.Examine        = "4"; //修改为已兑换
                    ex.ExchangePerson = model.UserId.ToString();
                    b = await this.ExchangeRepository.UpdateAsync(ex);

                    //更新会员表
                    var member = await this.MemberRepository.FindAsync(m => m.Id == model.UserId);

                    member.Deposit += model.Deposit;
                    b = await this.MemberRepository.UpdateAsync(member);

                    //更新兑换码表
                    var voucher = await this.VoucherRepository.FindAsync(m => m.Id == model.VouId);

                    voucher.State = 3;
                    b             = await this.VoucherRepository.UpdateAsync(voucher);
                }
                model.Status = 1;
                b            = await this.ExchangeEventRepository.UpdateAsync(model);

                ts.Commit();
            }
            RongCloudHelper.PublishSystemBySystem(model.UserId.ToString(), "兑换成功,请查看");
            return(b);
        }