예제 #1
0
        public bool UpdatePrepayRecord(PrepayRecord prepayRecord)
        {
            bool result = false;

            try
            {
                DbCommand cmd = null;
                string sql = @"
                                UPDATE [dbo].[PrepayRecord]
                                SET [Uid] = @Uid
                                    ,[PrepayMoney] = @PrepayMoney
                                    ,[PresentMoney] = @PresentMoney
                                    ,[AddMoney] = @AddMoney
                                    ,[PrepayDate] = @PrepayDate
                                    ,[PromotionId] = @PromotionId
                                    ,[PayModel] = @PayModel
                                    ,[UserId] = @UserId
                                    ,[SId] = @SId
                                    ,[BillPayId] = @BillPayId
                                    ,[RstId] = @RstId
                                    ,[ScoreVip] = @ScoreVip
                                    ,[PayByScore] = @PayByScore
                                    ,[RState] = @RState
                                    ,[AsureDate] = @AsureDate
                                    ,[RecMoney] = @RecMoney
                                    ,[DiscountlMoeny] = @DiscountlMoeny
                                WHERE RecordId = @RecordId
                ";

                cmd = db.GetSqlStringCommand(sql);

                db.AddInParameter(cmd, "Uid", DbType.String, prepayRecord.Uid);
                db.AddInParameter(cmd, "PrepayMoney", DbType.Decimal, prepayRecord.PrepayMoney);
                db.AddInParameter(cmd, "PresentMoney", DbType.Decimal, prepayRecord.PresentMoney);
                db.AddInParameter(cmd, "AddMoney", DbType.Decimal, prepayRecord.AddMoney);
                db.AddInParameter(cmd, "PrepayDate", DbType.DateTime, prepayRecord.PrepayDate);
                db.AddInParameter(cmd, "PromotionId", DbType.Int32, prepayRecord.PromotionId);
                db.AddInParameter(cmd, "PayModel", DbType.String, prepayRecord.PayModel);
                db.AddInParameter(cmd, "UserId", DbType.String, prepayRecord.UserId);
                db.AddInParameter(cmd, "SId", DbType.String, prepayRecord.SId);
                db.AddInParameter(cmd, "BillPayId", DbType.Guid, prepayRecord.BillPayId);
                db.AddInParameter(cmd, "RstId", DbType.Guid, prepayRecord.RstId);
                db.AddInParameter(cmd, "ScoreVip", DbType.Int32, prepayRecord.ScoreVip);
                db.AddInParameter(cmd, "PayByScore", DbType.Int32, prepayRecord.PayByScore);
                db.AddInParameter(cmd, "RState", DbType.String, prepayRecord.RState);
                db.AddInParameter(cmd, "AsureDate", DbType.DateTime, prepayRecord.AsureDate);
                db.AddInParameter(cmd, "RecMoney", DbType.Decimal, prepayRecord.RecMoney);
                db.AddInParameter(cmd, "DiscountlMoeny", DbType.Decimal, prepayRecord.DiscountlMoeny);
                db.AddInParameter(cmd, "RecordId", DbType.Int32, prepayRecord.RecordId);

                result = ExecSql(cmd) > 0;
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
            }

            return result;
        }
예제 #2
0
        public PrepayRecord GetUserLastUnPaidComsumingPrepayRecordWithin5Minutes(string sourceAccountId)
        {
            PrepayRecord prepayRecord = null;

            try
            {
                string sql = @"select top 1 * from PrepayRecord pr
                                left join CrmMember c on c.Uid = pr.Uid
                                where c.SourceAccountId = @SourceAccountId
                                and pr.PrepayDate > dateadd (MINUTE,-5,GETDATE())
                                and pr.AddMoney < 0
                                and pr.RState = '00'
                                order by RecordId desc";
                DbCommand cmd = db.GetSqlStringCommand(sql);

                db.AddInParameter(cmd, "SourceAccountId", DbType.String, sourceAccountId);

                using (var reader = db.ExecuteReader(cmd))
                {
                    while (reader.Read())
                    {
                        prepayRecord = new PrepayRecord()
                        {
                            AddMoney = reader.TryGetValue<Decimal?>("AddMoney"),
                            AsureDate = reader.TryGetValue<DateTime?>("AsureDate"),
                            BillPayId = reader.TryGetValue<Guid?>("BillPayId"),
                            DiscountlMoeny = reader.TryGetValue<Decimal?>("DiscountlMoeny"),
                            PayByScore = reader.TryGetValue<Int32?>("PayByScore"),
                            PayModel = reader.TryGetValue<String>("PayModel"),
                            PrepayDate = reader.TryGetValue<DateTime?>("PrepayDate"),
                            PrepayMoney = reader.TryGetValue<Decimal?>("PrepayMoney"),
                            PresentMoney = reader.TryGetValue<Decimal?>("PresentMoney"),
                            PromotionId = reader.TryGetValue<Int32?>("PromotionId"),
                            RecMoney = reader.TryGetValue<Decimal?>("RecMoney"),
                            RecordId = reader.TryGetValue<Int32>("RecordId"),
                            RState = reader.TryGetValue<String>("RState"),
                            RstId = reader.TryGetValue<Guid?>("RstId"),
                            ScoreVip = reader.TryGetValue<Int32?>("ScoreVip"),
                            SId = reader.TryGetValue<String>("SId"),
                            Uid = reader.TryGetValue<String>("Uid"),
                            UserId = reader.TryGetValue<String>("UserId")
                        };
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
                return null;
            }

            return prepayRecord;
        }
예제 #3
0
        public PrepayRecord GetPrepayRecordByOrderId(string orderId)
        {
            PrepayRecord prepayRecord = null;

            try
            {
                string sql = @"select top 1 * from PrepayRecord where SId=@orderId;";
                DbCommand cmd = db.GetSqlStringCommand(sql);

                db.AddInParameter(cmd, "orderId", DbType.String, orderId.ToString());

                using (var reader = db.ExecuteReader(cmd))
                {
                    while (reader.Read())
                    {
                        prepayRecord = new PrepayRecord()
                        {
                            AddMoney = reader.TryGetValue<Decimal?>("AddMoney"),
                            AsureDate = reader.TryGetValue<DateTime?>("AsureDate"),
                            BillPayId = reader.TryGetValue<Guid?>("BillPayId"),
                            DiscountlMoeny = reader.TryGetValue<Decimal?>("DiscountlMoeny"),
                            PayByScore = reader.TryGetValue<Int32?>("PayByScore"),
                            PayModel = reader.TryGetValue<String>("PayModel"),
                            PrepayDate = reader.TryGetValue<DateTime?>("PrepayDate"),
                            PrepayMoney = reader.TryGetValue<Decimal?>("PrepayMoney"),
                            PresentMoney = reader.TryGetValue<Decimal?>("PresentMoney"),
                            PromotionId = reader.TryGetValue<Int32?>("PromotionId"),
                            RecMoney = reader.TryGetValue<Decimal?>("RecMoney"),
                            RecordId = reader.TryGetValue<Int32>("RecordId"),
                            RState = reader.TryGetValue<String>("RState"),
                            RstId = reader.TryGetValue<Guid?>("RstId"),
                            ScoreVip = reader.TryGetValue<Int32?>("ScoreVip"),
                            SId = reader.TryGetValue<String>("SId"),
                            Uid = reader.TryGetValue<String>("Uid"),
                            UserId = reader.TryGetValue<String>("UserId")
                        };
                    }
                }
            }
            catch
            {
                throw;
            }

            return prepayRecord;
        }
예제 #4
0
        public ActionResult CancelOrder(string uid, string orderId, bool isEdit)
        {
            ActionResult result = Content("FAILED");

            try
            {
                bool success = true;
                var orderManager = new OrderManager();
                var order = orderManager.GetOrderSummary(Guid.Parse(orderId));

                if (order != null)
                {
                    OrderModel orderModel = new OrderModel();

                    using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                    {
                        PrepayRecordModel prepayRecordModel = new PrepayRecordModel();
                        CrmMemberModel crmMemberModel = new CrmMemberModel();

                        if (isEdit)
                        {
                            if (order.Status == OrderStatus.New)
                            {
                                success = orderModel.UpdateOrderStatus(Guid.Parse(orderId), OrderStatus.Cancelled);

                                var prepayRecord = prepayRecordModel.GetPrepayRecordByOrderId(orderId);

                                if (prepayRecord != null)
                                {
                                    //取消订单,支付失败
                                    prepayRecord.AsureDate = DateTime.Now;
                                    prepayRecord.RState = "99";
                                    success = success && prepayRecordModel.UpdatePrepayRecord(prepayRecord);
                                }
                            }
                            else
                            {
                                success = false;
                            }
                        }
                        else
                        {
                            if (OrderStatus.Paid == order.Status)
                            {
                                PrepayRecord prepayRecord = null;
                                PrepayRecord newPrepayRecord = null;
                                PrepayAccount prepayAccount = null;

                                prepayAccount = crmMemberModel.GetPrepayAccount(uid);
                                prepayRecord = prepayRecordModel.GetPrepayRecordByOrderId(orderId);

                                //已退款
                                prepayRecord.RState = "02";
                                prepayRecord.AsureDate = DateTime.Now;

                                newPrepayRecord = new PrepayRecord();

                                newPrepayRecord.AddMoney = -prepayRecord.AddMoney;
                                newPrepayRecord.AsureDate = DateTime.Now;
                                newPrepayRecord.BillPayId = Guid.NewGuid();
                                newPrepayRecord.DiscountlMoeny = 0;
                                newPrepayRecord.PayByScore = 0;
                                newPrepayRecord.PayModel = "02";
                                newPrepayRecord.PrepayDate = DateTime.Now;
                                newPrepayRecord.PrepayMoney = -0;
                                newPrepayRecord.PresentMoney = 0;
                                newPrepayRecord.PromotionId = 0;
                                newPrepayRecord.RecMoney = 0;
                                newPrepayRecord.RecordId = -1;
                                newPrepayRecord.RState = "";
                                newPrepayRecord.RstId = order.RestaurantId;
                                newPrepayRecord.ScoreVip = 0;
                                newPrepayRecord.SId = "";
                                newPrepayRecord.Uid = uid;
                                newPrepayRecord.UserId = "System";

                                prepayAccount.AccountMoney += newPrepayRecord.AddMoney.Value;
                                newPrepayRecord.PrepayDate = DateTime.Now;
                                newPrepayRecord.AsureDate = DateTime.Now;

                                success = orderModel.UpdateOrderStatus(Guid.Parse(orderId), OrderStatus.Refunded);
                                success = success && prepayRecordModel.AddPrepayRecord(newPrepayRecord);
                                success = success && crmMemberModel.UpdatePrepayAccount(prepayAccount);
                                success = success && prepayRecordModel.UpdatePrepayRecord(prepayRecord);
                            }
                            else
                            {
                                success = false;
                            }
                        }

                        if (success)
                        {
                            result = Content("SUCCESS");
                            scope.Complete();
                        }
                        else
                        {
                            result = Content("FAILED");
                            scope.Dispose();
                        }
                    }
                }
                else
                {
                    result = Content("FAILED");
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
            }

            return result;
        }
예제 #5
0
        public bool JoinOnlineVipGroup(string uid, string verifyCode)
        {
            bool result = false;

            try
            {
                PrepayRecordModel prepayRecordModel = new PrepayRecordModel();
                CrmMemberModel crmMemberModel = new CrmMemberModel();

                PrepayRecord prepayRecord = null;
                PrepayAccount prepayAccount = null;

                prepayRecord = new PrepayRecord();
                prepayRecord.AddMoney = 30m;
                prepayRecord.AsureDate = DateTime.Now;
                prepayRecord.BillPayId = Guid.Empty;
                prepayRecord.DiscountlMoeny = 0;
                prepayRecord.PayByScore = 0;
                prepayRecord.PayModel = "00";
                prepayRecord.PrepayDate = DateTime.Now;
                prepayRecord.PrepayMoney = 0;
                prepayRecord.PresentMoney = 30m;
                prepayRecord.PromotionId = 0;
                prepayRecord.RecMoney = 0;
                prepayRecord.RecordId = -1;
                prepayRecord.RState = "01";
                prepayRecord.RstId = Guid.Empty;
                prepayRecord.ScoreVip = 0;
                prepayRecord.SId = "邀请码:" + verifyCode;
                prepayRecord.Uid = uid;
                prepayRecord.UserId = "JoinVipGroup";

                prepayAccount = crmMemberModel.GetPrepayAccount(uid);
                if (prepayAccount != null)
                {
                    prepayAccount.PresentMoney += 30m;
                    prepayAccount.TotalPresent += 30m;
                    prepayAccount.TotalMoney += 30m;
                }

                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    if (crmMemberModel.UpdatePrepayAccount(prepayAccount) &&
                        prepayRecordModel.AddPrepayRecord(prepayRecord))
                    {
                        result = true;
                        scope.Complete();
                    }
                    else
                    {
                        scope.Dispose();
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
            }

            return result;
        }
예제 #6
0
        public PrepayRecord HasJoinedOnlineVipGroup(string uid)
        {
            PrepayRecord prepayRecord = null;

            try
            {
                string sql = @"select top 1 * from PrepayRecord where Uid=@Uid and UserId='JoinVipGroup';";
                DbCommand cmd = db.GetSqlStringCommand(sql);

                db.AddInParameter(cmd, "Uid", DbType.String, uid);

                using (var reader = db.ExecuteReader(cmd))
                {
                    while (reader.Read())
                    {
                        prepayRecord = new PrepayRecord()
                        {
                            AddMoney = reader.TryGetValue<Decimal?>("AddMoney"),
                            AsureDate = reader.TryGetValue<DateTime?>("AsureDate"),
                            BillPayId = reader.TryGetValue<Guid?>("BillPayId"),
                            DiscountlMoeny = reader.TryGetValue<Decimal?>("DiscountlMoeny"),
                            PayByScore = reader.TryGetValue<Int32?>("PayByScore"),
                            PayModel = reader.TryGetValue<String>("PayModel"),
                            PrepayDate = reader.TryGetValue<DateTime?>("PrepayDate"),
                            PrepayMoney = reader.TryGetValue<Decimal?>("PrepayMoney"),
                            PresentMoney = reader.TryGetValue<Decimal?>("PresentMoney"),
                            PromotionId = reader.TryGetValue<Int32?>("PromotionId"),
                            RecMoney = reader.TryGetValue<Decimal?>("RecMoney"),
                            RecordId = reader.TryGetValue<Int32>("RecordId"),
                            RState = reader.TryGetValue<String>("RState"),
                            RstId = reader.TryGetValue<Guid?>("RstId"),
                            ScoreVip = reader.TryGetValue<Int32?>("ScoreVip"),
                            SId = reader.TryGetValue<String>("SId"),
                            Uid = reader.TryGetValue<String>("Uid"),
                            UserId = reader.TryGetValue<String>("UserId")
                        };

                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
            }

            return prepayRecord;
        }