示例#1
0
        public string Execute(Hashtable params_ht)
        {
            Hashtable res = params_ht;

            if (res["UID"] == null ||
                res["VehicleID"] == null ||
                res["UID"].ToString().Trim().Length <= 0 ||
                res["VehicleID"].ToString().Trim().Length <= 0)
            {
                return(SiteHelper.GetJsonFromHashTable(null, "faild", "参数不完整"));
            }
            else
            {
                uid       = res["UID"].ToString().Trim();
                vehicleid = res["VehicleID"].ToString().Trim();
                VehicleManager    vm             = new VehicleManager();
                OrdersManager     om             = new OrdersManager();
                UserInfoManager   uim            = new UserInfoManager();
                SysSettingManager settingManager = new SysSettingManager();
                Hashtable         vehicle        = vm.GetVehicleInfoByID(vehicleid);
                if (vehicle == null || vehicle.Keys.Count == 0)
                {
                    //根据车牌号码查询车辆信息
                    vehicle = vm.GetVehicleInfoByLicenseNumber(vehicleid);
                }
                //判断车辆是否存在
                if (vehicle == null || vehicle.Keys.Count == 0)
                {
                    return(SiteHelper.GetJsonFromHashTable(null, "faild", "车辆预约失败,未找到车辆相关信息"));
                }

                vehicleid = SiteHelper.GetHashTableValueByKey(vehicle, "ID");
                //判断预约车辆是否离线
                DateTime lastUpdateTime;
                if (string.IsNullOrEmpty(SiteHelper.GetHashTableValueByKey(vehicle, "LastUpdateTime")))
                {
                    return(SiteHelper.GetJsonFromHashTable(null, "faild", "当前车辆已离线无法约车"));
                }
                else
                {
                    lastUpdateTime = DateTime.Parse(SiteHelper.GetHashTableValueByKey(vehicle, "LastUpdateTime"));
                    if (SiteHelper.ExecDateDiff(lastUpdateTime, DateTime.Now) > 10)
                    {
                        return(SiteHelper.GetJsonFromHashTable(null, "faild", "当前车辆已离线无法约车"));
                    }
                }

                //判断预约车辆电量值
                double electricity = 0.00;
                double.TryParse(SiteHelper.GetHashTableValueByKey(vehicle, "Electricity"), out electricity);
                if (electricity < 30)
                {
                    return(SiteHelper.GetJsonFromHashTable(null, "faild", "当前车辆电量过低无法约车"));
                }

                #region 判断车辆是否在运营区域内
                ServiceAreaManager areaManager = new ServiceAreaManager();
                Hashtable          area_ht     = areaManager.GetServiceAreaByVehicleID(vehicleid);
                if (area_ht != null && area_ht.Keys.Count > 0)
                {
                    List <LatLng> area_pts    = new List <LatLng>();
                    string        coordinates = SiteHelper.GetHashTableValueByKey(area_ht, "Coordinates");
                    foreach (string str in coordinates.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries))
                    {
                        string[] pt_arr = str.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                        LatLng   pt     = new LatLng(double.Parse(pt_arr[1]), double.Parse(pt_arr[0]));
                        area_pts.Add(pt);
                    }
                    string longitude  = SiteHelper.GetHashTableValueByKey(vehicle, "longitude");
                    string latitude   = SiteHelper.GetHashTableValueByKey(vehicle, "latitude");
                    LatLng vehicle_pt = new LatLng(double.Parse(latitude), double.Parse(longitude));
                    //vehicle_pt = SiteHelper.TransformFromWGSToGCJ(vehicle_pt);
                    vehicle_pt = SiteHelper.GPSToGCJ02(longitude, latitude);
                    vehicle_pt = new LatLng(Math.Round(vehicle_pt.latitude, 6), Math.Round(vehicle_pt.longitude, 6));
                    bool isInPoly = SiteHelper.IsPtInPoly(vehicle_pt, area_pts);
                    if (!isInPoly)
                    {
                        return(SiteHelper.GetJsonFromHashTable(null, "faild", "车辆预约失败,车辆处于运营区域外"));
                    }
                }
                #endregion

                #region 判断车辆是否在停车点内

                /*string returnVehicleMode = settingManager.GetValueByKey("ReturnVehicleMode");
                 * Hashtable parking_ht = areaManager.GetNearestParking(SiteHelper.GetHashTableValueByKey(vehicle, "longitude"), SiteHelper.GetHashTableValueByKey(vehicle, "latitude"), vehicleid);
                 * if (returnVehicleMode == "1" && parking_ht != null && parking_ht.Keys.Count > 0)
                 * {
                 *  List<LatLng> parking_pts = new List<LatLng>();
                 *  string coordinates = SiteHelper.GetHashTableValueByKey(parking_ht, "Coordinates");
                 *  foreach (string str in coordinates.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries))
                 *  {
                 *      string[] pt_arr = str.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                 *      LatLng pt = new LatLng(double.Parse(pt_arr[1]), double.Parse(pt_arr[0]));
                 *      parking_pts.Add(pt);
                 *  }
                 *  string longitude = SiteHelper.GetHashTableValueByKey(vehicle, "longitude");
                 *  string latitude = SiteHelper.GetHashTableValueByKey(vehicle, "latitude");
                 *  LatLng vehicle_pt = new LatLng(double.Parse(latitude),double.Parse(longitude));
                 *  //vehicle_pt = SiteHelper.TransformFromWGSToGCJ(vehicle_pt);
                 *  vehicle_pt = SiteHelper.GPSToGCJ02(longitude,latitude);
                 *  vehicle_pt = new LatLng(Math.Round(vehicle_pt.latitude, 6),Math.Round(vehicle_pt.longitude, 6));
                 *  bool isInPoly = SiteHelper.IsPtInPoly(vehicle_pt, parking_pts);
                 *  if (!isInPoly)
                 *  {
                 *      return SiteHelper.GetJsonFromHashTable(null, "faild", "车辆预约失败,车辆处于停车网点外");
                 *  }
                 * }*/
                #endregion

                //判断车辆是否可用
                if (SiteHelper.GetHashTableValueByKey(vehicle, "UseState").Trim() == VehicleUseState.Free.GetHashCode().ToString() && SiteHelper.GetHashTableValueByKey(vehicle, "VehicleState").Trim() == VehicleState.Use.GetHashCode().ToString())
                {
                    //判断用户余额是否充足
                    Hashtable user = uim.GetUserInfoByUserID(uid);
                    if (user == null || user.Keys.Count <= 0)
                    {
                        return(SiteHelper.GetJsonFromHashTable(null, "faild", "您不是有效会员"));
                    }
                    else
                    {
                        if ("2".CompareTo(user["REALNAMECERTIFICATION"].ToString()) == 0)
                        {
                            return(SiteHelper.GetJsonFromHashTable(null, "faild", "当前认证正在审核中,请耐心等待"));
                        }
                        //验证用户是否经过身份认证
                        if ("4".CompareTo(user["REALNAMECERTIFICATION"].ToString()) != 0)
                        {
                            return(SiteHelper.GetJsonFromHashTable(null, "faild", "您当前未完成实名认证,请完成实名认证后重试"));
                        }
                        //验证用户状态是否有效
                        if ("0".CompareTo(user["USERSTATE"].ToString()) == 0)
                        {
                            return(SiteHelper.GetJsonFromHashTable(null, "faild", "您当前已被禁用无法预约车辆,如有问题请与客服联系"));
                        }

                        //判断用户是否缴纳押金
                        decimal deposit = 0.00m;
                        decimal.TryParse(user["DEPOSIT"].ToString(), out deposit);
                        if (user["USERTYPE"].ToString() != UserType.OffDepositUser.GetHashCode().ToString() && deposit <= 0.00m)
                        {
                            return(SiteHelper.GetJsonFromHashTable(null, "faild", "您当前未缴纳用车押金,请完成押金缴纳后重试"));
                        }
                    }

                    //判断用户是否存在未支付订单
                    if (om.IsExistUnPayOrderByUser(uid))
                    {
                        return(SiteHelper.GetJsonFromHashTable(null, "faild", "您当前有未支付订单,请完成支付后重试"));
                    }

                    //判断会员是否有条件预约
                    bool isExist = om.IsExistVehicleOrderByUser(uid);
                    if (isExist)
                    {
                        return(SiteHelper.GetJsonFromHashTable(null, "faild", "您已经预约过车辆了"));
                    }
                    else
                    {
                        //如果是扫码用车
                        if (res["isopen"] != null && res["isopen"].ToString() == "1")
                        {
                            string gpsnum = SiteHelper.GetHashTableValueByKey(vehicle, "VehicleGPSNum");
                            //开车
                            bool isOpen = vm.OpenVehicle(vehicleid);
                            if (!isOpen)//开车失败
                            {
                                return(SiteHelper.GetJsonFromHashTable(null, "faild", "非常抱歉,由于车辆启动失败本次扫码用车失败,请选择其他车辆或稍后重试"));
                            }
                            else//开车成功
                            {
                                string orderID  = string.Empty;
                                string orderNum = string.Empty;
                                //提交订单
                                bool isSuccess = OrderVehicle(res, vehicle, user, out orderID, out orderNum);
                                if (!isSuccess)
                                {
                                    isOpen = vm.CloseVehicle(vehicleid);
                                    return(SiteHelper.GetJsonFromHashTable(null, "faild", "车辆预约失败,请联系管理员"));
                                }
                                else
                                {
                                    return(SiteHelper.GetJsonFromHashTable(null, "success", "车辆预约成功并已开启,欢迎驾驶电斑马"));
                                }
                            }
                        }
                        else //不是扫码用车
                        {
                            string orderID  = string.Empty;
                            string orderNum = string.Empty;
                            //提交订单
                            bool isSuccess = OrderVehicle(res, vehicle, user, out orderID, out orderNum);
                            if (isSuccess)
                            {
                                return(SiteHelper.GetJsonFromHashTable(null, "success", "车辆预约成功"));
                            }
                            else
                            {
                                return(SiteHelper.GetJsonFromHashTable(null, "faild", "车辆预约失败,请联系管理员"));
                            }
                        }
                    }
                }
                else
                {
                    return(SiteHelper.GetJsonFromHashTable(null, "faild", "预约失败,车辆不允许预约"));
                }
            }
        }
示例#2
0
        /// <summary>
        /// 车辆下单
        /// </summary>
        /// <param name="out_order_no"></param>
        /// <param name="plate_no"></param>
        /// <param name="username"></param>
        /// <param name="mobile"></param>
        /// <param name="cardno"></param>
        /// <param name="errmsg"></param>
        /// <returns></returns>
        private bool CreateOrder(string out_order_no, string plate_no, string username, string mobile, string cardno, out string errmsg)
        {
            VehicleManager    vm             = new VehicleManager();
            BaoJiaManager     mgr            = new BaoJiaManager();
            SysSettingManager settingManager = new SysSettingManager();
            Hashtable         vehicle        = vm.GetVehicleInfoByID(plate_no);

            if (vehicle == null || vehicle.Keys.Count == 0)
            {
                //根据车牌号码查询车辆信息
                vehicle = vm.GetVehicleInfoByLicenseNumber(plate_no);
            }
            //判断车辆是否存在
            if (vehicle == null || vehicle.Keys.Count == 0)
            {
                errmsg = "车辆预约失败,未找到车辆相关信息";
                return(false);
            }

            string vehicleid = SiteHelper.GetHashTableValueByKey(vehicle, "ID");
            //判断预约车辆是否离线
            DateTime lastUpdateTime;

            if (string.IsNullOrEmpty(SiteHelper.GetHashTableValueByKey(vehicle, "LastUpdateTime")))
            {
                errmsg = "当前车辆已离线无法约车";
                return(false);
            }
            else
            {
                lastUpdateTime = DateTime.Parse(SiteHelper.GetHashTableValueByKey(vehicle, "LastUpdateTime"));
                if (SiteHelper.ExecDateDiff(lastUpdateTime, DateTime.Now) > 10)
                {
                    errmsg = "当前车辆已离线无法约车";
                    return(false);
                }
            }

            //判断预约车辆电量值
            double electricity = 0.00;

            double.TryParse(SiteHelper.GetHashTableValueByKey(vehicle, "Electricity"), out electricity);
            if (electricity < 20)
            {
                errmsg = "当前车辆电量过低无法约车";
                return(false);
            }

            #region 判断车辆是否在运营区域内
            ServiceAreaManager areaManager = new ServiceAreaManager();
            Hashtable          area_ht     = areaManager.GetServiceAreaByVehicleID(vehicleid);
            if (area_ht != null && area_ht.Keys.Count > 0)
            {
                List <LatLng> area_pts    = new List <LatLng>();
                string        coordinates = SiteHelper.GetHashTableValueByKey(area_ht, "Coordinates");
                foreach (string str in coordinates.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries))
                {
                    string[] pt_arr = str.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    LatLng   pt     = new LatLng(double.Parse(pt_arr[1]), double.Parse(pt_arr[0]));
                    area_pts.Add(pt);
                }
                string longitude  = SiteHelper.GetHashTableValueByKey(vehicle, "longitude");
                string latitude   = SiteHelper.GetHashTableValueByKey(vehicle, "latitude");
                LatLng vehicle_pt = new LatLng(double.Parse(latitude), double.Parse(longitude));
                //vehicle_pt = SiteHelper.TransformFromWGSToGCJ(vehicle_pt);
                vehicle_pt = SiteHelper.GPSToGCJ02(longitude, latitude);
                vehicle_pt = new LatLng(Math.Round(vehicle_pt.latitude, 6), Math.Round(vehicle_pt.longitude, 6));
                bool isInPoly = SiteHelper.IsPtInPoly(vehicle_pt, area_pts);
                if (!isInPoly)
                {
                    errmsg = "车辆预约失败,车辆处于运营区域外";
                    return(false);
                }
            }
            #endregion

            #region 判断车辆是否在停车点内
            string    returnVehicleMode = settingManager.GetValueByKey("ReturnVehicleMode");
            Hashtable parking_ht        = areaManager.GetNearestParking(SiteHelper.GetHashTableValueByKey(vehicle, "longitude"), SiteHelper.GetHashTableValueByKey(vehicle, "latitude"), vehicleid);
            if (returnVehicleMode == "1" && parking_ht != null && parking_ht.Keys.Count > 0)
            {
                List <LatLng> parking_pts = new List <LatLng>();
                string        coordinates = SiteHelper.GetHashTableValueByKey(parking_ht, "Coordinates");
                foreach (string str in coordinates.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries))
                {
                    string[] pt_arr = str.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    LatLng   pt     = new LatLng(double.Parse(pt_arr[1]), double.Parse(pt_arr[0]));
                    parking_pts.Add(pt);
                }
                string longitude  = SiteHelper.GetHashTableValueByKey(vehicle, "longitude");
                string latitude   = SiteHelper.GetHashTableValueByKey(vehicle, "latitude");
                LatLng vehicle_pt = new LatLng(double.Parse(latitude), double.Parse(longitude));
                //vehicle_pt = SiteHelper.TransformFromWGSToGCJ(vehicle_pt);
                vehicle_pt = SiteHelper.GPSToGCJ02(longitude, latitude);
                vehicle_pt = new LatLng(Math.Round(vehicle_pt.latitude, 6), Math.Round(vehicle_pt.longitude, 6));
                bool isInPoly = SiteHelper.IsPtInPoly(vehicle_pt, parking_pts);
                if (!isInPoly)
                {
                    errmsg = "车辆预约失败,车辆处于停车网点外";
                    return(false);
                }
            }
            #endregion

            //判断车辆是否可用
            if (SiteHelper.GetHashTableValueByKey(vehicle, "UseState").Trim() == VehicleUseState.Free.GetHashCode().ToString() && SiteHelper.GetHashTableValueByKey(vehicle, "VehicleState").Trim() == VehicleState.Use.GetHashCode().ToString())
            {
                //判断用户是否存在未支付订单
                if (mgr.IsExistUnPayOrderByUser(mobile))
                {
                    errmsg = "您当前有未支付订单,请完成支付后重试";
                    return(false);
                }

                //判断会员是否有条件预约
                bool isExist = mgr.IsExistVehicleOrderByUser(mobile);
                if (isExist)
                {
                    errmsg = "您已经预约过车辆了";
                    return(false);
                }
                else
                {
                    string orderID  = string.Empty;
                    string orderNum = string.Empty;
                    //提交订单
                    bool isSuccess = OrderVehicle(out_order_no, username, mobile, cardno, vehicleid, out orderID, out orderNum);
                    if (isSuccess)
                    {
                        //vm.OpenVehicle(vehicleid);
                        errmsg = "";
                        return(true);
                    }
                    else
                    {
                        errmsg = "车辆预约失败,请联系管理员";
                        return(false);
                    }
                }
            }
            else
            {
                errmsg = "预约失败,车辆不允许预约";
                return(false);
            }
        }