예제 #1
0
        private bool Add(ParkDerate model, DbOperator dbOperator)
        {
            model.DataStatus     = DataStatus.Normal;
            model.LastUpdateTime = DateTime.Now;
            model.HaveUpdate     = SystemDefaultConfig.DataUpdateFlag;

            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into ParkDerate(DerateID,SellerID,[Name],DerateSwparate,DerateType,DerateMoney,FreeTime,StartTime,EndTime,FeeRuleID,LastUpdateTime,HaveUpdate,DataStatus)");
            strSql.Append(" values(@DerateID,@SellerID,@Name,@DerateSwparate,@DerateType,@DerateMoney,@FreeTime,@StartTime,@EndTime,@FeeRuleID,@LastUpdateTime,@HaveUpdate,@DataStatus)");
            dbOperator.ClearParameters();
            dbOperator.AddParameter("DerateID", model.DerateID);
            dbOperator.AddParameter("SellerID", model.SellerID);
            dbOperator.AddParameter("Name", model.Name);
            dbOperator.AddParameter("DerateSwparate", (int)model.DerateSwparate);
            dbOperator.AddParameter("DerateType", (int)model.DerateType);
            dbOperator.AddParameter("DerateMoney", model.DerateMoney);
            dbOperator.AddParameter("FreeTime", model.FreeTime);
            dbOperator.AddParameter("StartTime", model.StartTime);
            dbOperator.AddParameter("EndTime", model.EndTime);
            dbOperator.AddParameter("FeeRuleID", model.FeeRuleID);
            dbOperator.AddParameter("LastUpdateTime", model.LastUpdateTime);
            dbOperator.AddParameter("HaveUpdate", model.HaveUpdate);
            dbOperator.AddParameter("DataStatus", (int)model.DataStatus);
            return(dbOperator.ExecuteNonQuery(strSql.ToString()) > 0);
        }
예제 #2
0
        private bool Update(ParkDerate model, DbOperator dbOperator)
        {
            model.LastUpdateTime = DateTime.Now;
            model.HaveUpdate     = SystemDefaultConfig.DataUpdateFlag;

            StringBuilder strSql = new StringBuilder();

            strSql.Append("update ParkDerate set SellerID=@SellerID,[Name]=@Name,DerateSwparate=@DerateSwparate,DerateType=@DerateType,DerateMoney=@DerateMoney,FreeTime=@FreeTime,StartTime=@StartTime");
            strSql.Append(" ,EndTime=@EndTime,FeeRuleID=@FeeRuleID,LastUpdateTime=@LastUpdateTime,HaveUpdate=@HaveUpdate");
            strSql.Append(" where DerateID=@DerateID");
            dbOperator.ClearParameters();
            dbOperator.AddParameter("DerateID", model.DerateID);
            dbOperator.AddParameter("SellerID", model.SellerID);
            dbOperator.AddParameter("Name", model.Name);
            dbOperator.AddParameter("DerateSwparate", (int)model.DerateSwparate);
            dbOperator.AddParameter("DerateType", (int)model.DerateType);
            dbOperator.AddParameter("DerateMoney", model.DerateMoney);
            dbOperator.AddParameter("FreeTime", model.FreeTime);
            dbOperator.AddParameter("StartTime", model.StartTime);
            dbOperator.AddParameter("EndTime", model.EndTime);
            dbOperator.AddParameter("FeeRuleID", model.FeeRuleID);
            dbOperator.AddParameter("LastUpdateTime", model.LastUpdateTime);
            dbOperator.AddParameter("HaveUpdate", model.HaveUpdate);
            return(dbOperator.ExecuteNonQuery(strSql.ToString()) > 0);
        }
예제 #3
0
        public bool Update(ParkDerate model)
        {
            using (DbOperator dbOperator = ConnectionManager.CreateConnection())
            {
                try
                {
                    dbOperator.BeginTransaction();
                    bool result = Update(model, dbOperator);
                    if (!result)
                    {
                        throw new MyException("修改优免信息失败");
                    }

                    CommonDelete("ParkDerateIntervar", "DerateID", model.DerateID, dbOperator);

                    result = AddDerateIntervar(model.DerateIntervar, dbOperator);
                    if (!result)
                    {
                        throw new MyException("添加优免时段信息失败");
                    }

                    dbOperator.CommitTransaction();
                    return(result);
                }
                catch
                {
                    dbOperator.RollbackTransaction();
                    throw;
                }
            }
        }
예제 #4
0
        public bool Add(ParkDerate model)
        {
            using (DbOperator dbOperator = ConnectionManager.CreateConnection())
            {
                try
                {
                    dbOperator.BeginTransaction();
                    bool result = Add(model, dbOperator);
                    if (!result)
                    {
                        throw new MyException("保存优免信息失败");
                    }

                    result = AddDerateIntervar(model.DerateIntervar, dbOperator);
                    if (!result)
                    {
                        throw new MyException("保存优免时段信息失败");
                    }

                    dbOperator.CommitTransaction();
                    return(result);
                }
                catch {
                    dbOperator.RollbackTransaction();
                    throw;
                }
            }
        }
예제 #5
0
        /// <summary>
        /// 获取商户打折信息
        /// </summary>
        /// <param name="sellerID"></param>
        /// <param name="VID"></param>
        /// <returns></returns>
        public static string GetParkDerate(string sellerID, string VID)
        {
            string            strderate = "";
            List <ParkDerate> list      = new List <ParkDerate>();

            try
            {
                using (DbOperator dbOperator = ConnectionManager.CreateReadConnection())
                {
                    string strsql = string.Format(@"select * from ParkDerate where SellerID='{0}' and DataStatus!=2 ", sellerID);;
                    dbOperator.ClearParameters();
                    using (DbDataReader reader = dbOperator.ExecuteReader(strsql.ToString()))
                    {
                        while (reader.Read())
                        {
                            ParkDerate model = DataReaderToModel <ParkDerate> .ToModel(reader);

                            list.Add(model);
                        }
                        strderate = JsonHelper.GetJsonString(list);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Fatal("获取商户打折信息回调异常!GetParkDerateCallback()" + ex.Message + "\r\n");
            }
            return(strderate);
        }
예제 #6
0
 public JsonResult SaveParkDerate(ParkDerate model)
 {
     try
     {
         model = CheckParkDerate(model);
         List <ParkDerateIntervar> derateintervars = CheckParkDerateIntervar(model.DerateType, model.DerateID);
         model.DerateIntervar = derateintervars;
         if (string.IsNullOrWhiteSpace(model.DerateID))
         {
             bool result = ParkDerateServices.Add(model);
             if (!result)
             {
                 throw new MyException("添加失败");
             }
         }
         else
         {
             bool result = ParkDerateServices.Update(model);
             if (!result)
             {
                 throw new MyException("修改失败");
             }
         }
         return(Json(MyResult.Success()));
     }
     catch (MyException ex)
     {
         return(Json(MyResult.Error(ex.Message)));
     }
     catch (Exception ex)
     {
         ExceptionsServices.AddExceptions(ex, "保存商家优免信息失败");
         return(Json(MyResult.Error("保存失败")));
     }
 }
예제 #7
0
        /// <summary>
        /// 扫码优免进入
        /// </summary>
        /// <param name="vid">小区编号</param>
        /// <param name="qid">二维码编号</param>
        /// <param name="type">0-长久二维码 1-临时二维码</param>
        /// <param name="sign">签名</param>
        /// <returns></returns>
        public ActionResult Index(string vid, string qid, string sign)
        {
            TxtLogServices.WriteTxtLogEx("QRCodeDerate", "进入扫码打折:vid={0},qid={1},sign={2}", vid, qid, sign);
            try
            {
                if (SourceClient != RequestSourceClient.WeiXin)
                {
                    throw new MyException("请在微信中打开");
                }
                if (!CheckSignature(vid, qid, sign))
                {
                    throw new MyException("验证签名失败");
                }

                if (SourceClient == RequestSourceClient.WeiXin)
                {
                    if (string.IsNullOrWhiteSpace(WeiXinOpenId))
                    {
                        ParkDerate derate = ParkDerateServices.Query(qid);
                        if (derate == null)
                        {
                            throw new MyException("获取优免券信息失败");
                        }

                        ParkSeller seller = ParkSellerServices.QueryBySellerId(derate.SellerID);
                        if (seller == null)
                        {
                            throw new MyException("获取商家信息失败");
                        }

                        BaseVillage village = VillageServices.QueryVillageByRecordId(seller.VID);
                        if (village == null)
                        {
                            throw new MyException("获取小区信息失败");
                        }

                        string id = string.Format("QRCodeDerate_Index_vid={0}^qid={1}^sign={2}^companyId={3}", vid, qid, sign, village.CPID);
                        return(RedirectToAction("Index", "WeiXinAuthorize", new { id = id }));
                    }
                }
                ViewBag.PlateNumber = OnlineOrderServices.QueryLastPaymentPlateNumber(PaymentChannel.WeiXinPay, WeiXinOpenId);
                ViewBag.VillageId   = vid;
                ViewBag.QId         = qid;
                return(View());
            }
            catch (MyException ex) {
                TxtLogServices.WriteTxtLogEx("QRCodeDerate", "扫码打折异常:描述:{0}", ex.Message);
                return(RedirectToAction("Index", "ErrorPrompt", new { message = ex.Message }));
            }
            catch (Exception ex)
            {
                TxtLogServices.WriteTxtLogEx("QRCodeDerate", "扫码打折异常:描述:{0},明细:{1}", ex.Message, ex.StackTrace);
                return(RedirectToAction("Index", "ErrorPrompt", new { message = "扫码失败,未知异常" }));
            }
        }
예제 #8
0
        public static bool Update(ParkDerate model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            if (model.DerateIntervar != null && model.DerateIntervar.Count > 0)
            {
                model.DerateIntervar.ForEach(p => { p.DerateIntervarID = GuidGenerator.GetGuidString(); p.DerateID = model.DerateID; });
            }
            IParkDerate factory = ParkDerateFactory.GetFactory();
            bool        result  = factory.Update(model);

            if (result)
            {
                OperateLogServices.AddOperateLog <ParkDerate>(model, OperateType.Update);
            }
            return(result);
        }
예제 #9
0
        public ParkDerate Query(string derateId)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select * from ParkDerate  where DerateID= @DerateID and DataStatus!=@DataStatus");

            using (DbOperator dbOperator = ConnectionManager.CreateReadConnection())
            {
                dbOperator.ClearParameters();
                dbOperator.AddParameter("DerateID", derateId);
                dbOperator.AddParameter("DataStatus", (int)DataStatus.Delete);
                using (DbDataReader reader = dbOperator.ExecuteReader(strSql.ToString()))
                {
                    if (reader.Read())
                    {
                        ParkDerate model = DataReaderToModel <ParkDerate> .ToModel(reader);

                        model.DerateIntervar = QueryParkDerateIntervar(model.DerateID);
                        return(model);
                    }
                    return(null);
                }
            }
        }
예제 #10
0
        public JsonResult GrantCarDerate(string vid, string qid, string sellerName, string derateName, int number)
        {
            try
            {
                if (number <= 0)
                {
                    throw new MyException("发放优免券数量不正确");
                }

                if (string.IsNullOrWhiteSpace(SystemDefaultConfig.SystemDomain))
                {
                    throw new MyException("获取系统域名失败");
                }
                ParkDerateQRcode qrCode = ParkDerateQRcodeServices.QueryByRecordId(qid);
                if (qrCode == null)
                {
                    throw new MyException("优免券规则不存在");
                }

                ParkDerate derate = ParkDerateServices.Query(qrCode.DerateID);
                if (derate == null)
                {
                    throw new MyException("获取优免规则失败");
                }

                if (derate.DerateType == DerateType.SpecialTimePeriodPayment)
                {
                    string     errorMsg = string.Empty;
                    ParkSeller seller   = ParkSellerServices.GetSeller(derate.SellerID, out errorMsg);
                    if (derate == null)
                    {
                        throw new MyException("获取优免规则失败");
                    }

                    decimal totalAmount = qrCode.DerateValue * number;
                    if ((seller.Creditline + seller.Balance) < totalAmount)
                    {
                        throw new MyException("商家余额不足");
                    }
                }

                BaseVillage village = VillageServices.QueryVillageByRecordId(vid);
                if (village == null)
                {
                    throw new MyException("获取小区信息失败");
                }

                string        folderName   = string.Format("{0}_{1}_{2}", sellerName, derateName, IdGenerator.Instance.GetId().ToString());
                List <string> carDerateIds = new List <string>();
                for (int i = 0; i < number; i++)
                {
                    string carDerateId = GuidGenerator.GetGuidString();
                    string content     = string.Format("{0}/QRCodeDerate/Index?vid={1}&qid={2}&did={3}&sign={4}", SystemDefaultConfig.SystemDomain, vid, qid, carDerateId, GetSignature(vid, qid, carDerateId));
                    string result      = QRCodeServices.GenerateQRCode(village.CPID, content, 430, carDerateId, folderName);
                    if (string.IsNullOrWhiteSpace(result))
                    {
                        throw new MyException("创建二维码失败");
                    }
                    carDerateIds.Add(carDerateId);
                }
                string filePath    = string.Format("/Uploads/{0}", folderName);
                string zipFilePath = string.Format("{0}/{1}_{2}.zip", filePath, sellerName, derateName);
                string mapPath     = Server.MapPath("~/");

                ZipHelper.ZipFiles(string.Format("{0}/{1}", mapPath, filePath), string.Format("{0}/{1}", mapPath, zipFilePath));
                if (carDerateIds.Count != number)
                {
                    throw new MyException("二维码数量与待创建的数量不匹配");
                }

                bool grantResult = ParkDerateQRcodeServices.GrantCarDerate(carDerateIds, zipFilePath, qid);
                if (!grantResult)
                {
                    throw new MyException("发放券失败");
                }

                return(Json(MyResult.Success("", zipFilePath)));
            }
            catch (MyException ex)
            {
                return(Json(MyResult.Error(ex.Message)));
            }
            catch (Exception ex)
            {
                ExceptionsServices.AddExceptions(ex, "发放优免券失败");
                return(Json(MyResult.Error("发放优免券失败")));
            }
        }
예제 #11
0
        public ActionResult DerateQRCode(string recordId)
        {
            try
            {
                ParkDerateQRcode derateQRcode = ParkDerateQRcodeServices.QueryByRecordId(recordId);
                if (derateQRcode == null)
                {
                    throw new MyException("该二维码不存在");
                }

                ParkDerate derate = ParkDerateServices.Query(derateQRcode.DerateID);
                if (derate == null)
                {
                    throw new MyException("优免规则不存在");
                }
                derateQRcode.DerateName = derate.Name;

                ParkSeller seller = ParkSellerServices.QueryBySellerId(derate.SellerID);
                if (seller == null)
                {
                    throw new MyException("商家不存在");
                }
                derateQRcode.SellerName = seller.SellerName;

                if (string.IsNullOrWhiteSpace(SystemDefaultConfig.SystemDomain))
                {
                    throw new MyException("获取系统域名失败");
                }
                BaseVillage village = VillageServices.QueryVillageByRecordId(seller.VID);
                if (village == null)
                {
                    throw new MyException("获取小区信息失败");
                }

                string content = string.Format("{0}/QRCodeDerate/Index?vid={1}&qid={2}&sign={3}", SystemDefaultConfig.SystemDomain, seller.VID, recordId, GetSignature(seller.VID, recordId));
                using (System.Drawing.Image image = QRCodeServices.GenerateQRCode(content, 430))
                {
                    ImageFormat format = image.RawFormat;
                    byte[]      buffer;
                    using (MemoryStream ms = new MemoryStream())
                    {
                        image.Save(ms, ImageFormat.Jpeg);
                        buffer = new byte[ms.Length];
                        ms.Seek(0, SeekOrigin.Begin);
                        ms.Read(buffer, 0, buffer.Length);
                    }
                    derateQRcode.ImageData = System.Convert.ToBase64String(buffer);
                }
                ViewBag.CompanyID   = village.CPID;
                ViewBag.ShareAction = "XFJMDerateQRCode/DerateQRCode?recordId=" + recordId;
                return(View(derateQRcode));
            }
            catch (MyException ex)
            {
                return(RedirectToAction("Index", "XFJMDerateQRCode", new { RemindUserContent = ex.Message }));
            }
            catch (Exception ex)
            {
                ExceptionsServices.AddExceptions(ex, "微信获取二维码失败", LogFrom.WeiXin);
                return(RedirectToAction("Index", "XFJMDerateQRCode", new { RemindUserContent = "获取二维码失败" }));
            }
        }
예제 #12
0
        /// <summary>
        /// 下发有免费券
        /// </summary>
        /// <param name="carDerateIds"></param>
        /// <param name="qrCodeZipFilePath">压缩二维码的文件路径</param>
        /// <param name="qrCodeId"></param>
        /// <returns></returns>
        public static bool GrantCarDerate(List <string> carDerateIds, string qrCodeZipFilePath, string qrCodeId)
        {
            if (carDerateIds == null || carDerateIds.Count == 0)
            {
                throw new ArgumentNullException("carDerateIds");
            }
            if (string.IsNullOrWhiteSpace(qrCodeZipFilePath))
            {
                throw new ArgumentNullException("qrCodeFilePath");
            }

            string absolutePath = System.Web.HttpContext.Current.Server.MapPath("~/");
            string s            = string.Format("{0}{1}", absolutePath, qrCodeZipFilePath);

            if (!File.Exists(s))
            {
                throw new MyException("压缩二维码的文件不存在");
            }

            IParkDerateQRcode factory = ParkDerateQRcodeFactory.GetFactory();
            ParkDerateQRcode  qrCode  = factory.QueryByRecordId(qrCodeId);

            if (qrCode == null)
            {
                throw new MyException("优免券规则不存在");
            }

            if (qrCode.EndTime < DateTime.Now)
            {
                throw new MyException("该优免券规则已过期");
            }

            ParkDerate derate = ParkDerateServices.Query(qrCode.DerateID);

            if (derate == null)
            {
                throw new MyException("获取优免规则失败");
            }

            decimal totalAmount = 0;

            if (derate.DerateType == DerateType.SpecialTimePeriodPayment)
            {
                string     errorMsg = string.Empty;
                ParkSeller seller   = ParkSellerServices.GetSeller(derate.SellerID, out errorMsg);
                if (derate == null)
                {
                    throw new MyException("获取优免规则失败");
                }

                totalAmount = qrCode.DerateValue * carDerateIds.Count;
                if ((seller.Creditline + seller.Balance) < totalAmount)
                {
                    throw new MyException("商家余额不足");
                }
            }

            List <ParkCarDerate> carDerates = new List <ParkCarDerate>();

            foreach (var item in carDerateIds)
            {
                ParkCarDerate model = new ParkCarDerate();
                model.CarDerateID = item;
                model.CarDerateNo = IdGenerator.Instance.GetId().ToString();
                model.DerateID    = qrCode.DerateID;
                model.PlateNumber = "";
                model.AreaID      = "";
                model.PKID        = qrCode.PKID;
                if (derate.DerateType != DerateType.ReliefTime && derate.DerateType != DerateType.VotePayment && derate.DerateType != DerateType.DayFree)
                {
                    model.FreeMoney = qrCode.DerateValue;
                }
                else if (derate.DerateType == DerateType.DayFree)
                {
                    model.FreeMoney = qrCode.DerateValue * derate.DerateMoney;
                }
                else
                {
                    model.FreeTime = (int)qrCode.DerateValue;
                }
                model.Status         = CarDerateStatus.Used;
                model.CreateTime     = DateTime.Now;
                model.ExpiryTime     = qrCode.EndTime;
                model.DerateQRCodeID = qrCode.RecordID;
                carDerates.Add(model);
            }
            IParkCarDerate factoryCarDerate = ParkCarDerateFactory.GetFactory();

            using (DbOperator dbOperator = ConnectionManager.CreateConnection())
            {
                try
                {
                    dbOperator.BeginTransaction();
                    //添加券
                    foreach (var item in carDerates)
                    {
                        bool result = factoryCarDerate.Add(item, dbOperator);
                        if (!result)
                        {
                            throw new MyException("发券失败");
                        }
                    }
                    //修改发放总张数据,修改最后压缩包路径
                    int  totalNumbers = qrCode.CanUseTimes + carDerateIds.Count;
                    bool updateResult = factory.Update(qrCodeId, qrCodeZipFilePath, totalNumbers, dbOperator);
                    if (!updateResult)
                    {
                        throw new MyException("修改券总数失败");
                    }

                    //商家扣款
                    if (totalAmount > 0)
                    {
                        IParkSeller factorySeller = ParkSellerFactory.GetFactory();
                        updateResult = factorySeller.SellerDebit(derate.SellerID, totalAmount, dbOperator);
                        if (!updateResult)
                        {
                            throw new MyException("商家扣款失败");
                        }
                    }
                    dbOperator.CommitTransaction();
                    return(true);
                }
                catch
                {
                    dbOperator.RollbackTransaction();
                    throw;
                }
            }
        }
예제 #13
0
        /// <summary>
        /// 消费打折
        /// </summary>
        /// <param name="IORecordID"></param>
        /// <param name="DerateID"></param>
        /// <param name="VID"></param>
        /// <param name="SellerID"></param>
        /// <param name="DerateMoney"></param>
        /// <returns></returns>
        public static string DiscountPlateNumber(string IORecordID, string DerateID, string VID, string SellerID, decimal DerateMoney)
        {
            ConsumerDiscountResult result = new ConsumerDiscountResult();

            try
            {
                using (DbOperator dbOperator = ConnectionManager.CreateReadConnection())
                {
                    ParkIORecord IOmodel = null;
                    string       strsql  = "select * from ParkIORecord where RecordID=@RecordID and DataStatus<2";
                    dbOperator.ClearParameters();
                    dbOperator.AddParameter("RecordID", IORecordID);
                    using (DbDataReader reader = dbOperator.ExecuteReader(strsql.ToString()))
                    {
                        if (reader.Read())
                        {
                            IOmodel = DataReaderToModel <ParkIORecord> .ToModel(reader);
                        }
                    }
                    if (IOmodel != null)
                    {
                        if (IOmodel.IsExit)
                        {
                            result.Result = 3;

                            return(JsonHelper.GetJsonString(result));//车辆已出场
                        }

                        strsql = "select a.*,b.SellerID from ParkCarDerate a left join ParkDerate b on a.DerateID=b.DerateID where IORecordID=@IORecordID and b.SellerID=@SellerID  and a.DataStatus<2  and Status!=3";
                        dbOperator.ClearParameters();
                        dbOperator.AddParameter("IORecordID", IORecordID);
                        dbOperator.AddParameter("SellerID", SellerID);
                        using (DbDataReader reader = dbOperator.ExecuteReader(strsql.ToString()))
                        {
                            if (reader.Read())
                            {
                                result.Result = 4;
                                return(JsonHelper.GetJsonString(result));//已打折
                            }
                        }
                        ParkDerate derate = null;
                        strsql = "select * from ParkDerate where DataStatus<2 and DerateID=@DerateID";
                        dbOperator.ClearParameters();
                        dbOperator.AddParameter("DerateID", DerateID);
                        using (DbDataReader reader = dbOperator.ExecuteReader(strsql.ToString()))
                        {
                            if (reader.Read())
                            {
                                derate = DataReaderToModel <ParkDerate> .ToModel(reader);
                            }
                            else
                            {
                                result.Result = 5;
                                return(JsonHelper.GetJsonString(result));//找不到优免规则
                            }
                        }

                        ParkSeller seller = null;
                        strsql = "select * from ParkSeller where DataStatus<2 and SellerID=@SellerID";
                        dbOperator.ClearParameters();
                        dbOperator.AddParameter("SellerID", SellerID);
                        using (DbDataReader reader = dbOperator.ExecuteReader(strsql.ToString()))
                        {
                            if (reader.Read())
                            {
                                seller = DataReaderToModel <ParkSeller> .ToModel(reader);
                            }
                            else
                            {
                                result.Result = 6;
                                return(JsonHelper.GetJsonString(result));//找不到商家信息
                            }
                        }

                        decimal SumFreeMoney = 0;
                        strsql = "select SUM(FreeMoney) as SumFreeMoney from ParkCarDerate a left join ParkDerate b on a.DerateID=b.DerateID  where a.DataStatus<2 and a.Status=1 and b.SellerID=@SellerID ";
                        dbOperator.ClearParameters();
                        dbOperator.AddParameter("SellerID", SellerID);
                        using (DbDataReader reader = dbOperator.ExecuteReader(strsql.ToString()))
                        {
                            if (reader.Read())
                            {
                                SumFreeMoney = reader["SumFreeMoney"].ToDecimal();
                            }
                        }

                        if (derate.DerateType == DerateType.TimesPayment || derate.DerateType == DerateType.TimePeriodAndTimesPayment)
                        {
                            DerateMoney = (decimal)derate.DerateMoney;
                        }
                        if (derate.DerateType != DerateType.ReliefTime && derate.DerateType != DerateType.VotePayment && derate.DerateType != DerateType.DayFree)
                        {
                            if (seller.Balance + seller.Creditline < DerateMoney + SumFreeMoney)
                            {
                                result.Result = 7;
                                return(JsonHelper.GetJsonString(result));//商家余额不足
                            }
                        }
                        else if (derate.DerateType == DerateType.DayFree)
                        {
                            if (seller.Balance + seller.Creditline < (DerateMoney * derate.DerateMoney) + SumFreeMoney)
                            {
                                result.Result = 7;
                                return(JsonHelper.GetJsonString(result));//商家余额不足
                            }
                        }

                        ParkCarDerate Carderate = new ParkCarDerate();
                        Carderate.AreaID      = IOmodel.AreaID;
                        Carderate.CarDerateID = System.Guid.NewGuid().ToString();
                        Carderate.CarDerateNo = IdGenerator.Instance.GetId().ToString();
                        Carderate.CardNo      = IOmodel.CardNo;
                        Carderate.CreateTime  = DateTime.Now;
                        Carderate.DerateID    = DerateID;
                        Carderate.ExpiryTime  = DateTime.Now.AddDays(7);
                        Carderate.Status      = CarDerateStatus.Used;
                        if (derate.DerateType != DerateType.ReliefTime && derate.DerateType != DerateType.VotePayment && derate.DerateType != DerateType.DayFree)
                        {
                            Carderate.FreeMoney = DerateMoney;
                        }
                        else if (derate.DerateType == DerateType.DayFree)
                        {
                            Carderate.FreeMoney  = DerateMoney * derate.DerateMoney;
                            Carderate.ExpiryTime = IOmodel.EntranceTime.AddDays((int)DerateMoney);
                        }
                        else
                        {
                            Carderate.FreeTime = (int)DerateMoney;
                        }


                        Carderate.IORecordID  = IOmodel.RecordID;
                        Carderate.HaveUpdate  = 1;
                        Carderate.PKID        = IOmodel.ParkingID;
                        Carderate.PlateNumber = IOmodel.PlateNumber;
                        Carderate.DataStatus  = 0;

                        Carderate.LastUpdateTime = DateTime.Now;
                        dbOperator.BeginTransaction();
                        strsql  = "insert into ParkCarDerate (CarDerateID,CarDerateNo,DerateID,FreeTime,PlateNumber,IORecordID,CardNo,ExpiryTime,CreateTime,Status,FreeMoney,AreaID,PKID,LastUpdateTime,HaveUpdate,DataStatus)";
                        strsql += "values(@CarDerateID,@CarDerateNo,@DerateID,@FreeTime,@PlateNumber,@IORecordID,@CardNo,@ExpiryTime,@CreateTime,@Status,@FreeMoney,@AreaID,@PKID,@LastUpdateTime,@HaveUpdate,@DataStatus)";
                        dbOperator.ClearParameters();
                        dbOperator.AddParameter("CarDerateID", Carderate.CarDerateID);

                        dbOperator.AddParameter("CarDerateNo", Carderate.CarDerateNo);
                        dbOperator.AddParameter("DerateID", Carderate.DerateID);
                        dbOperator.AddParameter("FreeTime", Carderate.FreeTime);
                        dbOperator.AddParameter("PlateNumber", Carderate.PlateNumber);
                        dbOperator.AddParameter("IORecordID", Carderate.IORecordID);
                        dbOperator.AddParameter("CardNo", Carderate.CardNo);
                        dbOperator.AddParameter("ExpiryTime", Carderate.ExpiryTime);
                        dbOperator.AddParameter("CreateTime", Carderate.CreateTime);
                        dbOperator.AddParameter("Status", Carderate.Status);
                        dbOperator.AddParameter("FreeMoney", Carderate.FreeMoney);

                        dbOperator.AddParameter("AreaID", Carderate.AreaID);
                        dbOperator.AddParameter("PKID", Carderate.PKID);
                        dbOperator.AddParameter("LastUpdateTime", Carderate.LastUpdateTime);
                        dbOperator.AddParameter("HaveUpdate", Carderate.HaveUpdate);
                        dbOperator.AddParameter("DataStatus", Carderate.DataStatus);
                        if (dbOperator.ExecuteNonQuery(strsql) <= 0)
                        {
                            dbOperator.RollbackTransaction();
                            result.Result = 8;
                            return(JsonHelper.GetJsonString(result));//打折失败
                        }
                        if (derate.DerateType == DerateType.DayFree)
                        {
                            strsql = "update ParkSeller set Balance=Balance-" + Carderate.FreeMoney + "where SellerID=@SellerID";
                            dbOperator.ClearParameters();
                            dbOperator.AddParameter("SellerID", seller.SellerID);
                            if (dbOperator.ExecuteNonQuery(strsql) <= 0)
                            {
                                dbOperator.RollbackTransaction();
                                result.Result = 8;
                                return(JsonHelper.GetJsonString(result));//打折失败
                            }
                        }
                        dbOperator.CommitTransaction();
                        result.Result   = 1;
                        result.ResModel = Carderate;
                        return(JsonHelper.GetJsonString(result));
                    }
                    else
                    {
                        result.Result = 2;
                        return(JsonHelper.GetJsonString(result));//找不到进出记录信息
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Fatal("消费打折回调异常!DiscountPlateNumberCallback()" + ex.Message + "\r\n");
                result.Result = -1;
                return(JsonHelper.GetJsonString(result));//异常
            }
        }
예제 #14
0
        private ParkDerate CheckParkDerate(ParkDerate derate)
        {
            if (string.IsNullOrWhiteSpace(derate.Name))
            {
                throw new MyException("优免名称不能为空");
            }
            if (string.IsNullOrWhiteSpace(derate.SellerID))
            {
                throw new MyException("您未选择商家");
            }

            ParkDerate newDerate = new ParkDerate();

            newDerate.ID         = derate.ID;
            newDerate.DerateID   = derate.DerateID;
            newDerate.Name       = derate.Name;
            newDerate.SellerID   = derate.SellerID;
            newDerate.DerateType = derate.DerateType;
            switch (derate.DerateType)
            {
            case DerateType.PaymentOnTime:
            case DerateType.NoPayment:
            case DerateType.SpecialTimePeriodPayment:
            {
                break;
            }

            case DerateType.TimesPayment:
            {
                if (string.IsNullOrWhiteSpace(derate.FeeRuleID))
                {
                    throw new MyException("请选择收费标准");
                }

                if (derate.DerateMoney <= 0)
                {
                    throw new MyException("一次消费收消费场所金额不正确");
                }

                newDerate.DerateSwparate = derate.DerateSwparate;
                newDerate.FeeRuleID      = derate.FeeRuleID;
                newDerate.DerateMoney    = derate.DerateMoney;
                newDerate.FreeTime       = (int)(float.Parse(Request.Params["FreeTimeHour"].ToString()) * 60);
                break;
            }

            case DerateType.VotePayment:
            case DerateType.ReliefTime:
            {
                newDerate.DerateSwparate = derate.DerateSwparate;
                break;
            }

            case DerateType.TimePeriodPayment:
            {
                newDerate.DerateSwparate = derate.DerateSwparate;
                if (string.IsNullOrWhiteSpace(Request.Params["MaxFreeHour"]))
                {
                    throw new MyException("车主最高免时间不能为空");
                }
                newDerate.FreeTime = (int)(float.Parse(Request.Params["MaxFreeHour"].ToString()) * 60);
                break;
            }

            case DerateType.StandardPayment:
            {
                if (string.IsNullOrWhiteSpace(derate.FeeRuleID))
                {
                    throw new MyException("请选择收费标准");
                }

                newDerate.FeeRuleID = derate.FeeRuleID;
                break;
            }

            case DerateType.TimePeriodAndTimesPayment:
            {
                newDerate.DerateSwparate = derate.DerateSwparate;
                newDerate.DerateMoney    = derate.DerateMoney;
                newDerate.FreeTime       = (int)(float.Parse(Request.Params["FreeTimeHour"].ToString()) * 60);
                newDerate.StartTime      = derate.StartTime;
                newDerate.EndTime        = derate.EndTime;
                break;
            }

            case DerateType.VoteSpecialPayment:
            {
                newDerate.DerateSwparate = derate.DerateSwparate;
                break;
            }

            case DerateType.DayFree:
            {
                newDerate.DerateMoney = derate.DayMoney;
                break;
            }

            default: throw new MyException("优免类型不存在");
            }
            return(newDerate);
        }
예제 #15
0
        public static bool QRCodeDiscount(string sellerId, string derateId, string carDerateId, string parkingId, string ioRecordId, string plateNumber)
        {
            if (string.IsNullOrWhiteSpace(sellerId))
            {
                throw new ArgumentNullException("sellerId");
            }
            if (string.IsNullOrWhiteSpace(derateId))
            {
                throw new ArgumentNullException("derateId");
            }
            if (string.IsNullOrWhiteSpace(carDerateId))
            {
                throw new ArgumentNullException("carDerateId");
            }
            if (string.IsNullOrWhiteSpace(parkingId))
            {
                throw new ArgumentNullException("parkingId");
            }
            if (string.IsNullOrWhiteSpace(plateNumber))
            {
                throw new ArgumentNullException("plateNumber");
            }

            List <ParkCarDerate> carDerates = ParkCarDerateServices.QueryByDerateId(carDerateId);

            if (carDerates == null || carDerates.Count == 0)
            {
                throw new MyException("该优免券不存在");
            }
            if (!string.IsNullOrWhiteSpace(carDerates.First().PlateNumber))
            {
                throw new MyException("该优免券已使用过了[001]");
            }
            if (carDerates.First().Status == CarDerateStatus.Settlementd)
            {
                throw new MyException("该优免券已使用过了[002]");
            }
            if (carDerates.First().Status != CarDerateStatus.Used)
            {
                throw new MyException("该优免券不是有效状态");
            }

            IParkCarDerate factory   = ParkCarDerateFactory.GetFactory();
            ParkCarDerate  carDerate = factory.QueryBySellerIdAndIORecordId(sellerId, ioRecordId);

            if (carDerate != null)
            {
                throw new MyException("该车辆已优免了");
            }

            ParkDerate derate = ParkDerateServices.Query(derateId);

            if (derate == null)
            {
                throw new MyException("找不到优免规则");
            }

            ParkSeller seller = ParkSellerServices.QueryBySellerId(derate.SellerID);

            if (seller == null)
            {
                throw new MyException("找不到商家信息");
            }

            return(factory.QRCodeDiscount(carDerateId, parkingId, ioRecordId, plateNumber));
        }