示例#1
0
        /// <summary>
        /// 卡充值
        /// </summary>
        /// <param name="VisitorID">游客ID</param>
        /// <param name="Amount">充值金额</param>
        /// <param name="PaymentType">付款方式</param>
        /// <returns>生成的OrderID</returns>
        public Stream Recharge(string VisitorID, float Amount, int PaymentType)
        {
            #region 数据完整性检查
            if (VisitorID == null)
            {
                return(ResponseHelper.Failure("游客信息缺失!"));
            }
            if (Amount <= 0)
            {
                return(ResponseHelper.Failure("充值金额无效!"));
            }
            #endregion

            //根据游客ID查询卡ID
            string CardID = "";
            try
            {
                using (var db = new EFDbContext())
                {
                    var card = from v2c in db.Visitor2Cards
                               where v2c.VisitorID == VisitorID
                               select v2c;
                    if (card.Count() == 0)
                    {
                        return(ResponseHelper.Failure("该游客没有绑定游园卡!"));
                    }

                    CardID = card.Single().CardID;//记录卡ID
                }
            }
            catch (Exception ex)
            {
                while (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }
                return(ResponseHelper.Failure(ex.Message));
            }

            #region 新增订单,新增支付信息,新增游客订单映射
            string id = IDHelper.getNextOrderID(DateTime.Now, 3);
            //生成新订单
            Order RechargeOrder = new Order()
            {
                OrderID       = id,
                OrderTime     = DateTime.Now,
                OrderState    = 1, //已支付
                CommodityID   = CardID,
                CommodityType = 3, //卡相关
                CommodityNum  = (int)Amount,
                DoneTime      = Convert.ToDateTime(DateTime.Now)
            };
            //生成新支付信息
            Payment RechargePay = new Payment()
            {
                OrderID       = RechargeOrder.OrderID,
                PaymentType   = PaymentType,
                PaymentTime   = DateTime.Now,
                PaymentAmount = Amount
            };
            //增加游客订单映射
            Visitor2Order v2o = new Visitor2Order()
            {
                VisitorID = VisitorID,
                CardID    = CardID,
                OrderID   = id
            };
            #endregion

            #region 修改数据库,返回订单ID
            //在数据库V2C表中修改卡余额
            try
            {
                using (var db = new EFDbContext())
                {
                    //订单、支付、游客订单映射信息——提交数据库
                    db.Orders.Add(RechargeOrder);
                    db.Payments.Add(RechargePay);
                    db.Visitor2Orders.Add(v2o);

                    //修改余额(增加)
                    Visitor2Card new_v2c = db.Visitor2Cards.Where(v => v.VisitorID == VisitorID).Single();
                    new_v2c.Balance += Amount;

                    db.SaveChanges();
                    return(ResponseHelper.Success(new List <string>()
                    {
                        RechargeOrder.OrderID
                    }));                                                                         //返回OrderID
                }
            }
            catch (Exception ex)
            {
                while (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }
                return(ResponseHelper.Failure(ex.Message));
            }
            #endregion
        }
示例#2
0
        private void TimeProject_Tick(object sender, EventArgs e)
        {
            if (isProjectInventory)
            {
                try
                {
                    var updateItems = from project in projectTemp
                                      group project by project.EPCString into up
                                      select new { CardID = up.Key, Time = up.Max(t => t.Time) };


                    var v2c = from v in EFHelper.GetAll <Visitor2Card>()
                              join u in updateItems on v.CardID equals u.CardID
                              join vi in EFHelper.GetAll <Visitor>() on v.VisitorID equals vi.VisitorID
                              select new { v.VisitorID, vi.Name, u.Time, v.Balance, v.CardID };

                    if (v2c.Count() > 0)
                    {
                        var charge = EFHelper.GetAll <ChargeProject>().First(t => t.ProjectID == ProjectID);

                        foreach (var v in v2c)
                        {
                            if (v.Balance < charge.ProjectPrice)
                            {
                                MessageBox.Show(string.Format("ID:{0},用户:{1} 的余额不足 {2} 元,请充值后再尝试游玩!", v.VisitorID, v.Name, charge.ProjectPrice));
                                continue;
                            }

                            //判断是否重复刷卡
                            var isAgain = EFHelper.GetAll <Operation>().Where(t => t.VisitorID == v.VisitorID && t.PlayState == 1);
                            if (isAgain.Count() > 0)
                            {
                                continue;
                            }

                            using (var db = new EFDbContext())
                            {
                                var operation = db.ProjectOperation.First(t => t.ProjectID == ProjectID && t.VisitorID == v.VisitorID);
                                //改变项目实时信息
                                if (operation != null)
                                {
                                    operation.PlayState = 1;
                                }
                                //增加项目历史记录
                                db.ProjectRecord.Add(new ProRecord()
                                {
                                    ProjectID = ProjectID,
                                    VisitorID = v.VisitorID,
                                    Timestamp = v.Time,
                                    PlayState = 1
                                });
                                //生成消费订单
                                string orderId = IDHelper.getNextOrderID(DateTime.Now, 1);
                                db.Orders.Add(new Order()
                                {
                                    OrderID       = orderId,
                                    OrderState    = 1,
                                    OrderTime     = DateTime.Now,
                                    CommodityID   = charge.ProjectID,
                                    CommodityNum  = 1,
                                    CommodityType = 1,
                                    DoneTime      = DateTime.Now
                                });
                                //成对应的支付信息
                                db.Payments.Add(new Payment()
                                {
                                    OrderID       = orderId,
                                    PaymentAmount = charge.ProjectPrice,
                                    PaymentTime   = DateTime.Now,
                                    PaymentType   = 4
                                });
                                //增加游客支付的映射
                                db.Visitor2Orders.Add(new Visitor2Order()
                                {
                                    CardID    = v.CardID,
                                    OrderID   = orderId,
                                    VisitorID = v.VisitorID
                                });
                                //扣去游客卡上的余额
                                var visitor = db.Visitor2Cards.Where(t => t.VisitorID == v.VisitorID).Single();
                                visitor.Balance -= charge.ProjectPrice;
                                //提交事务
                                db.SaveChanges();
                            }
                        }
                    }

                    projectTemp.Clear();
                }
                catch (Exception ex)
                {
                }
            }
        }