Ejemplo n.º 1
0
        /// <summary>
        /// 停车收费接口
        /// </summary>
        /// <param name="cardID">卡号</param>
        /// <param name="chargeDateTime">计费时间(格式:yyyy-MM-dd HH:mm:ss.fff)</param>
        /// <param name="paid">实付金额</param>
        /// <param name="payMode">支付方式[0代表现金,1代表微信,…]</param>
        /// <param name="memo">费用说明</param>
        /// <param name="reserve1">预留1</param>
        /// <param name="reserve2">预留2</param>
        /// <returns>Result 0:成功,其他:失败</returns>
        public CommandResult CardFeePay(string cardID, string chargeDateTime, string paid, string payMode, string memo, string reserve1, string reserve2)
        {
            try
            {
                #region 先验证输入参数
                if (string.IsNullOrEmpty(cardID.Trim()))
                {
                    return(new CommandResult(ResultCode.ParameterError, "参数卡号错误"));
                }
                DateTime chargeTime = new DateTime(2011, 1, 1);
                if (!DateTime.TryParse(chargeDateTime, out chargeTime))
                {
                    return(new CommandResult(ResultCode.ParameterError, "参数计费时间错误"));
                }
                if (chargeTime > DateTime.Now)
                {
                    return(new CommandResult(ResultCode.ParameterError, "计费时间大于系统当前时间"));
                }
                decimal paidD = 0;
                if (!decimal.TryParse(paid, out paidD))
                {
                    return(new CommandResult(ResultCode.ParameterError, "参数实付金额错误"));
                }
                int payModeI = 0;
                if (!int.TryParse(payMode, out payModeI))
                {
                    return(new CommandResult(ResultCode.ParameterError, "参数支付方式错误"));
                }
                #endregion

                #region 接口日志记录
                if (AppConifg.Current.Log)
                {
                    try
                    {
                        string log = string.Format("卡号:{0} 计费时间:{1} 实付金额:{2} 支付方式:{3} 费用说明:{4} 预留1:{5} 预留2:{6}"
                                                   , cardID
                                                   , chargeDateTime
                                                   , paid
                                                   , payMode
                                                   , memo
                                                   , reserve1
                                                   , reserve2);
                        Ralid.GeneralLibrary.LOG.FileLog.Log(AppConifg.Current.LogPath, "CardFeePay", log);
                    }
                    catch (Exception ex)
                    {
                        Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex);
                    }
                }
                #endregion

                #region 验证卡片信息
                //查找该卡号的卡片
                CardBll cardBll = new CardBll(AppConifg.Current.ParkingConnection);
                QueryResult <CardInfo> cResult = cardBll.GetCardByID(cardID);
                if (cResult.Result != ResultCode.Successful)
                {
                    return(new CommandResult(cResult.Result, "获取卡片信息失败"));
                }
                CardInfo card = cResult.QueryObject;
                if (card == null)
                {
                    return(new CommandResult(ResultCode.NoRecord, "此卡未登记"));
                }
                if (!card.IsInPark)
                {
                    return(new CommandResult(ResultCode.Fail, "此卡已出场"));
                }
                string msg = string.Empty;
                if (!ValidateCard(card, out msg))
                {
                    return(new CommandResult(ResultCode.Fail, msg));
                }
                if (card.LastDateTime > chargeTime)
                {
                    return(new CommandResult(ResultCode.ParameterError, "入场时间晚于计费时间"));
                }
                //获取卡片所在停车场信息
                EntranceBll  entranceBll = new EntranceBll(AppConifg.Current.ParkingConnection);
                EntranceInfo entrance    = entranceBll.GetEntranceInfo(card.LastEntrance).QueryObject;
                if (entrance == null)
                {
                    return(new CommandResult(ResultCode.NoRecord, "没有找到入场通道信息"));
                }
                ParkBll  parkBll = new ParkBll(AppConifg.Current.ParkingConnection);
                ParkInfo park    = parkBll.GetParkInfoByID(entrance.ParkID).QueryObject;
                if (park == null)
                {
                    return(new CommandResult(ResultCode.NoRecord, "没有找到停车场信息"));
                }
                //判断卡片合法性
                if (card.IsCardList && park.IsWriteCardMode && !card.OnlineHandleWhenOfflineMode)
                {
                    //写卡模式时,脱机处理的卡片名单不能缴费
                    return(new CommandResult(ResultCode.Fail, "该卡片为写卡处理卡片,不能进行在线收费"));
                }
                #endregion

                #region 获取费率和节假日
                SysParaSettingsBll ssb    = new SysParaSettingsBll(AppConifg.Current.ParkingConnection);
                TariffSetting      tariff = ssb.GetSetting <TariffSetting>();
                if (tariff == null)
                {
                    return(new CommandResult(ResultCode.Fail, "获取费率失败"));
                }
                TariffSetting.Current = tariff;
                HolidaySetting holiday = ssb.GetSetting <HolidaySetting>();
                if (holiday == null)
                {
                    return(new CommandResult(ResultCode.Fail, "获取节假日失败"));
                }
                HolidaySetting.Current = holiday;
                #endregion

                #region 判断是否已缴过费
                if (card.IsCompletedPaid && tariff.IsInFreeTime(card.PaidDateTime.Value, chargeTime))
                {
                    //已缴费,并且未过免费时间,不允许缴费
                    msg = string.Format("已缴费,请在{0}分钟内离场!", tariff.FreeTimeRemaining(card.PaidDateTime.Value, chargeTime));
                    return(new CommandResult(ResultCode.Fail, msg));
                }
                #endregion

                //生成卡片缴费记录
                CardPaymentInfo chargeRecord = CardPaymentInfoFactory.CreateCardPaymentRecord(park.ParkID, card, tariff, card.CarType, chargeTime);
                //将收费信息重新赋值
                chargeRecord.Paid     = paidD;
                chargeRecord.Discount = chargeRecord.Accounts - paidD;
                if (chargeRecord.Discount < 0)
                {
                    chargeRecord.Discount = 0;
                }
                chargeRecord.PaymentCode    = PaymentCode.Internet;
                chargeRecord.PaymentMode    = payModeI == 1 ? PaymentMode.WeChat : PaymentMode.Cash;
                chargeRecord.IsCenterCharge = true;
                chargeRecord.StationID      = string.Empty;
                chargeRecord.OperatorID     = string.Empty;
                if (!string.IsNullOrEmpty(memo))
                {
                    chargeRecord.Memo = memo;
                }
                if (chargeRecord.Memo == null)
                {
                    chargeRecord.Memo = string.Empty;
                }

                CommandResult result = cardBll.PayParkFee(chargeRecord);
                if (result.Result == ResultCode.Successful)
                {
                    //缴费成功,返回缴费后离场提示信息
                    msg = string.Format("缴费成功,请在{0}分钟内离场!", tariff.FreeTimeRemaining(chargeTime, DateTime.Now));
                }

                return(result);
            }
            catch (Exception ex)
            {
                Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex);
                string msg = string.Format("接口发生异常,异常信息:{0}", ex.Message);
                return(new CommandResult(ResultCode.InterfaceException, msg));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 读取到卡号处理
        /// </summary>
        /// <param name="cardID">卡号</param>
        /// <param name="info">从卡片扇区数据中读取到的卡片信息</param>
        private void ReadCardIDHandler(string cardID, CardInfo info)
        {
            this.txtCardID.Text     = cardID;
            this.txtCardID.ReadOnly = true;
            string   msg  = string.Empty;
            CardInfo card = info;

            if (card == null)
            {
                msg = Resource1.FrmCardCenterCharge_CardDataErr;
            }
            else if (!ValidateCard(card, out msg))
            {
                //卡片无效
            }
            else if (TariffSetting.Current.GetTariff(card.CardType.ID, card.CarType) == null)
            {
                msg = Resource1.FrmCardCenterCharge_NotPaymentCard;
            }
            else if (!card.IsInPark)
            {
                msg = CardInvalidDescripition.GetDescription(EventInvalidType.INV_StillOut);
            }
            else if (card.LastDateTime > DateTime.Now)
            {
                msg = CardInvalidDescripition.GetDescription(EventInvalidType.INV_WrongInTime);
            }
            else
            {
                _cardInfo = card;
                EntranceBll  eBll   = new EntranceBll(AppSettings.CurrentSetting.ParkConnect);
                EntranceInfo eInfo  = eBll.GetEntranceInfo(_cardInfo.LastEntrance).QueryObject;
                int          parkID = 0;
                if (eInfo != null)
                {
                    parkID = eInfo.ParkID;
                }
                this.parkCombobox1.SelectedParkID = parkID;
                this.label1.Visible        = true;
                this.parkCombobox1.Visible = true;
                //_ChargeRecord = CardPaymentInfoFactory.CreateCardPaymentRecord(_cardInfo, TariffSetting.Current, _cardInfo.CarType, DateTime.Now);
                _ChargeRecord          = CardPaymentInfoFactory.CreateCardPaymentRecord(this.parkCombobox1.SelectedParkID, _cardInfo, TariffSetting.Current, _cardInfo.CarType, DateTime.Now);
                _ChargeRecord.CarPlate = _cardInfo.CarPlate;
                ShowCardPaymentInfo(_ChargeRecord);
            }
            if (!string.IsNullOrEmpty(msg))
            {
                if (_ChargeLed != null)
                {
                    _ChargeLed.DisplayMsg(msg);
                }
                if (AppSettings.CurrentSetting.EnableTTS)
                {
                    TTSSpeech.Instance.Speek(msg);
                }
                ClearInput();
                this.txtCardID.Text = cardID;
                this.txtMemo.Text   = msg;
                this.eventList.InsertMessage(msg);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 获取某卡号的停车收费信息接口
        /// </summary>
        /// <param name="cardID">卡号</param>
        /// <param name="discountHour">优惠时长</param>
        /// <param name="discountAmount">优惠金额</param>
        /// <param name="reserve1">预留1</param>
        /// <param name="reserve2">预留2</param>
        /// <returns>Result 0:成功,其他:失败;QueryObject:返回收费信息对象</returns>
        public QueryResult <WSCardPaymentInfo> GetCardPayment(string cardID, string discountHour, string discountAmount, string reserve1, string reserve2)
        {
            try
            {
                #region 先验证输入参数
                if (string.IsNullOrEmpty(cardID.Trim()))
                {
                    return(new QueryResult <WSCardPaymentInfo>(ResultCode.ParameterError, "参数卡号错误", null));
                }
                int discountHourInt = 0;
                if (!string.IsNullOrEmpty(discountHour.Trim()))
                {
                    if (!int.TryParse(discountHour, out discountHourInt))
                    {
                        return(new QueryResult <WSCardPaymentInfo>(ResultCode.ParameterError, "参数优惠时长错误", null));
                    }
                }
                decimal discountAmountD = 0;
                if (!string.IsNullOrEmpty(discountAmount.Trim()))
                {
                    if (!decimal.TryParse(discountAmount, out discountAmountD))
                    {
                        return(new QueryResult <WSCardPaymentInfo>(ResultCode.ParameterError, "参数优惠金额错误", null));
                    }
                }
                #endregion

                #region 接口日志记录
                if (AppConifg.Current.Log)
                {
                    try
                    {
                        string log = string.Format("卡号:{0} 优惠时长:{1} 优惠金额:{2} 预留1:{3} 预留2:{4}"
                                                   , cardID
                                                   , discountHour
                                                   , discountAmount
                                                   , reserve1
                                                   , reserve2);
                        Ralid.GeneralLibrary.LOG.FileLog.Log(AppConifg.Current.LogPath, "GetCardPayment", log);
                    }
                    catch (Exception ex)
                    {
                        Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex);
                    }
                }
                #endregion

                #region 验证卡片信息
                //查找该卡号的卡片
                CardBll cardBll = new CardBll(AppConifg.Current.ParkingConnection);
                QueryResult <CardInfo> cResult = cardBll.GetCardByID(cardID);
                if (cResult.Result != ResultCode.Successful)
                {
                    return(new QueryResult <WSCardPaymentInfo>(cResult.Result, "获取卡片信息失败", null));
                }
                CardInfo card = cResult.QueryObject;
                if (card == null)
                {
                    return(new QueryResult <WSCardPaymentInfo>(ResultCode.NoRecord, "此卡未登记", null));
                }
                if (!card.IsInPark)
                {
                    return(new QueryResult <WSCardPaymentInfo>(ResultCode.Fail, "此卡已出场", null));
                }
                string msg = string.Empty;
                if (!ValidateCard(card, out msg))
                {
                    return(new QueryResult <WSCardPaymentInfo>(ResultCode.Fail, msg, null));
                }
                DateTime chargeDateTime = DateTime.Now;
                if (card.LastDateTime > chargeDateTime)
                {
                    return(new QueryResult <WSCardPaymentInfo>(ResultCode.Fail, "入场时间晚于计费时间", null));
                }

                //获取卡片所在停车场信息
                EntranceBll  entranceBll = new EntranceBll(AppConifg.Current.ParkingConnection);
                EntranceInfo entrance    = entranceBll.GetEntranceInfo(card.LastEntrance).QueryObject;
                if (entrance == null)
                {
                    return(new QueryResult <WSCardPaymentInfo>(ResultCode.NoRecord, "没有找到入场通道信息", null));
                }
                ParkBll  parkBll = new ParkBll(AppConifg.Current.ParkingConnection);
                ParkInfo park    = parkBll.GetParkInfoByID(entrance.ParkID).QueryObject;
                if (park == null)
                {
                    return(new QueryResult <WSCardPaymentInfo>(ResultCode.NoRecord, "没有找到停车场信息", null));
                }
                //判断卡片合法性
                if (card.IsCardList && park.IsWriteCardMode && !card.OnlineHandleWhenOfflineMode)
                {
                    //写卡模式时,脱机处理的卡片名单不能缴费
                    return(new QueryResult <WSCardPaymentInfo>(ResultCode.Fail, "该卡片为写卡处理卡片,不能进行在线缴费", null));
                }
                #endregion

                #region 获取费率和节假日
                SysParaSettingsBll ssb    = new SysParaSettingsBll(AppConifg.Current.ParkingConnection);
                TariffSetting      tariff = ssb.GetSetting <TariffSetting>();
                if (tariff == null)
                {
                    return(new QueryResult <WSCardPaymentInfo>(ResultCode.Fail, "获取费率失败", null));
                }
                TariffSetting.Current = tariff;
                HolidaySetting holiday = ssb.GetSetting <HolidaySetting>();
                if (holiday == null)
                {
                    return(new QueryResult <WSCardPaymentInfo>(ResultCode.Fail, "获取节假日失败", null));
                }
                HolidaySetting.Current = holiday;
                #endregion

                #region 判断是否已缴过费
                if (card.IsCompletedPaid && tariff.IsInFreeTime(card.PaidDateTime.Value, chargeDateTime))
                {
                    //已缴费,并且未过免费时间,不允许缴费
                    msg = string.Format("已缴费,请在{0}分钟内离场!", tariff.FreeTimeRemaining(card.PaidDateTime.Value, chargeDateTime));
                    return(new QueryResult <WSCardPaymentInfo>(ResultCode.Fail, msg, null));
                }
                #endregion

                //重设卡片优惠时长
                card.DiscountHour += discountHourInt;
                if (card.DiscountHour > 0xFF)
                {
                    card.DiscountHour = 0xFF;
                }

                //生成卡片缴费记录
                CardPaymentInfo chargeRecord = CardPaymentInfoFactory.CreateCardPaymentRecord(park.ParkID, card, tariff, card.CarType, chargeDateTime);
                //计算优惠后的缴费费用
                chargeRecord.Discount += discountAmountD;
                if (chargeRecord.Discount > chargeRecord.Accounts)
                {
                    //如果优惠金额比应收费用多,优惠金额为应收费用,这是为了防止实际支付费用为负数的情况出现
                    chargeRecord.Discount = chargeRecord.Accounts;
                }

                WSCardPaymentInfo wsRecord = new WSCardPaymentInfo();
                wsRecord.SetWSCardPaymentInfo(chargeRecord);
                wsRecord.EntranceName = entrance.EntranceName;

                return(new QueryResult <WSCardPaymentInfo>(ResultCode.Successful, wsRecord));
            }
            catch (Exception ex)
            {
                Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex);
                string msg = string.Format("接口发生异常,异常信息:{0}", ex.Message);
                return(new QueryResult <WSCardPaymentInfo>(ResultCode.InterfaceException, msg, null));
            }
        }