Ejemplo n.º 1
0
 /// <summary>
 /// 开车指令
 /// </summary>
 /// <param name="vehicleid"></param>
 /// <returns></returns>
 public bool Open(string vehicleid, out string returnResult)
 {
     returnResult = "";
     try
     {
         bool           result            = false;
         VehicleManager vm                = new VehicleManager();
         Hashtable      vehicle_ht        = vm.GetVehicleInfoByID(vehicleid);
         Dictionary <string, object> dict = new Dictionary <string, object>();
         dict.Add("carId", SiteHelper.GetHashTableValueByKey(vehicle_ht, "VehicleGPSNum"));
         dict.Add("type", 1);
         dict.Add("command", 90);
         dict.Add("cmd", "carControl");
         dict.Add("directRt", "false");
         //string sign = ZCloudSignUtil.getSign(dict, XiaoAnCloudConfig.md5_key);
         //dict.Add("sign",sign);
         //string postData=ZCloudCore.createLinkString(dict);
         string postData = JsonConvert.SerializeObject(dict);
         string retstr   = PostJson(XiaoAnCloudConfig.api_url, postData, "utf-8");
         returnResult = retstr;
         dynamic retObj = DynamicJson.Parse(retstr);
         if (retObj.rtCode == "0")
         {
             result = true;
         }
         Logger.Debug("开锁:" + "carId:" + dict["carId"] + "," + retstr);
         return(result);
     }
     catch (Exception ex)
     {
         Logger.Error("开锁异常:" + ex.Message);
         return(false);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 锁车指令
        /// </summary>
        /// <param name="vehicleid"></param>
        /// <returns></returns>
        public bool Close(string vehicleid)
        {
            try
            {
                bool           result     = false;
                VehicleManager vm         = new VehicleManager();
                Hashtable      vehicle_ht = vm.GetVehicleInfoByID(vehicleid);

                Dictionary <string, string> dict = new Dictionary <string, string>();
                dict.Add("carId", SiteHelper.GetHashTableValueByKey(vehicle_ht, "VehicleGPSNum"));
                dict.Add("cmd", "doorControl");
                dict.Add("type ", "8");
                dict.Add("directRt", "true");

                string sign = ZCloudSignUtil.getSign(dict, ZCloudConfig.md5_key);
                dict.Add("sign", sign);

                string  postData = ZCloudCore.createLinkString(dict);
                string  retstr   = HttpUtil.Post(ZCloudConfig.api_url, postData, "utf-8");
                dynamic retObj   = DynamicJson.Parse(retstr);
                if (retObj.sysCode == "suc" && retObj.rtCode == "0")
                {
                    result = true;
                }

                return(result);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 根据用户和车辆id获取车辆计费规则
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="vehicleid"></param>
        /// <returns></returns>
        public Hashtable GetVehiclePrice(string vehicleid)
        {
            Hashtable result = new Hashtable();

            UserInfoManager   userManager    = new UserInfoManager();
            VehicleManager    vehicleManager = new VehicleManager();
            SysSettingManager settingManager = new SysSettingManager();
            Hashtable         vehicle_ht     = vehicleManager.GetVehicleInfoByID(vehicleid);

            if (vehicle_ht != null)
            {
                decimal minutePrice = 0.00m;
                decimal kmPrice     = 0.00m;
                decimal minPrice    = 0.00m;
                decimal maxPrice    = 0.00m;

                DataTable price_dt = GetPriceInfo(SiteHelper.GetHashTableValueByKey(vehicle_ht, "CityID"), SiteHelper.GetHashTableValueByKey(vehicle_ht, "Model"));
                if (price_dt != null && price_dt.Rows.Count > 0)
                {
                    decimal.TryParse(price_dt.Rows[0]["MinutePrice"].ToString(), out minutePrice);
                    decimal.TryParse(price_dt.Rows[0]["KmPrice"].ToString(), out kmPrice);
                    decimal.TryParse(price_dt.Rows[0]["MinPrice"].ToString(), out minPrice);
                    decimal.TryParse(price_dt.Rows[0]["MaxPrice"].ToString(), out maxPrice);
                }
                result["MinutePrice"] = minutePrice;
                result["KmPrice"]     = kmPrice;
                result["MinPrice"]    = minPrice;
                result["MaxPrice"]    = maxPrice;
            }

            return(result);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 锁车指令
        /// </summary>
        /// <param name="vehicleid"></param>
        /// <returns></returns>
        public bool Close(string vehicleid)
        {
            try
            {
                VehicleManager vm         = new VehicleManager();
                Hashtable      vehicle_ht = vm.GetVehicleInfoByID(vehicleid);

                string vehicleGPSNum = SiteHelper.GetHashTableValueByKey(vehicle_ht, "VehicleGPSNum");

                bool   returnTrue = false;
                byte[] sendcmd    = new byte[13];
                //数据包类型两位
                sendcmd[0] = 0x68;
                sendcmd[1] = 0x68;
                //命令类型一位
                sendcmd[2] = 0x02;//关
                //数据包长度,数据包长度2位+IMIE号8位
                int       datalen  = 10;
                string    strlen   = datalen.ToString("X4");
                TcpClient client   = new TcpClient();
                byte[]    bytelen  = client.strToToHexByte(strlen);
                byte[]    byteimie = client.StringToBytes(vehicleGPSNum);
                Array.Copy(bytelen, 0, sendcmd, 3, 2);
                Array.Copy(byteimie, 0, sendcmd, 5, 8);

                string serverIp   = SiteHelper.GetAppsetString("server_ip");
                string serverPort = SiteHelper.GetAppsetString("server_port");
                if (vehicle_ht != null && vehicle_ht.Keys.Count > 0)
                {
                    if (!string.IsNullOrEmpty(vehicle_ht["BIZSOCKETIP"].ToString()))
                    {
                        serverIp = vehicle_ht["BIZSOCKETIP"].ToString();
                    }
                    if (!string.IsNullOrEmpty(vehicle_ht["BIZSOCKETPORT"].ToString()))
                    {
                        serverPort = vehicle_ht["BIZSOCKETPORT"].ToString();
                    }
                }
                bool result = client.Connect(serverIp, int.Parse(serverPort));
                if (result)
                {
                    client.Send(sendcmd);
                    string response = client.ReceiveString();
                    if (response != null && response.Contains("ok"))
                    {
                        returnTrue = true;
                    }
                    client.Disconnect();
                }
                return(returnTrue);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// 锁车指令
 /// </summary>
 /// <param name="vehicleid"></param>
 /// <returns></returns>
 public bool Close(string vehicleid, out string returnResult)
 {
     returnResult = "";
     try
     {
         bool           result            = false;
         VehicleManager vm                = new VehicleManager();
         Hashtable      vehicle_ht        = vm.GetVehicleInfoByID(vehicleid);
         Dictionary <string, object> dict = new Dictionary <string, object>();
         dict.Add("carId", SiteHelper.GetHashTableValueByKey(vehicle_ht, "VehicleGPSNum"));
         dict.Add("type", 1);
         dict.Add("command", 4);
         dict.Add("cmd", "carControl");
         dict.Add("directRt", "false");
         string postData = JsonConvert.SerializeObject(dict);
         string retstr   = PostJson(XiaoAnCloudConfig.api_url, postData, "utf-8");
         returnResult = retstr;
         dynamic retObj = DynamicJson.Parse(retstr);
         if (retObj.rtCode == "0")
         {
             /*
              * //播放还车语音
              * dict = new Dictionary<string, object>();
              * dict.Add("carId", SiteHelper.GetHashTableValueByKey(vehicle_ht, "VehicleGPSNum"));
              * dict.Add("type", 11);
              * dict.Add("command", 14);
              * dict.Add("cmd", "carControl");
              * dict.Add("directRt", "false");
              * postData = JsonConvert.SerializeObject(dict);
              * retstr = PostJson(XiaoAnCloudConfig.api_url, postData, "utf-8");
              */
             result = true;
         }
         Logger.Debug("锁车:" + "carId:" + dict["carId"] + "," + retstr);
         return(result);
     }
     catch (Exception ex)
     {
         Logger.Error("锁车异常:" + ex.Message);
         return(false);
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// 获取订单结算信息
        /// </summary>
        /// <param name="orderid"></param>
        /// <returns></returns>
        public Hashtable GetOrderSettlement(string orderid)
        {
            Hashtable result = new Hashtable();

            UserInfoManager   userManager    = new UserInfoManager();
            OrdersManager     ordersManager  = new OrdersManager();
            VehicleManager    vehicleManager = new VehicleManager();
            SysSettingManager settingManager = new SysSettingManager();
            Hashtable         order_ht       = ordersManager.GetOrderInfoByID(orderid);

            string orderState = SiteHelper.GetHashTableValueByKey(order_ht, "OrderState");
            string userID     = SiteHelper.GetHashTableValueByKey(order_ht, "UserID");

            if (OrderState.Valid.GetHashCode().ToString() == orderState)
            {
                #region 未结算订单

                int     minutes     = 0;
                float   mileage     = 0.00f;
                decimal minutePrice = 0.00m;
                decimal kmPrice     = 0.00m;
                decimal minPrice    = 0.00m;
                decimal maxPrice    = 0.00m;
                decimal totalMoney  = 0.00m;

                int orderFreeMinutes = 0;
                int.TryParse(settingManager.GetValueByKey("OrderFreeMinutes"), out orderFreeMinutes);
                double orderFreeKm = 0;
                double.TryParse(settingManager.GetValueByKey("OrderFreeKm"), out orderFreeKm);

                float.TryParse(SiteHelper.GetHashTableValueByKey(order_ht, "Mileage"), out mileage);

                Hashtable vehicle_ht = vehicleManager.GetVehicleInfoByID(SiteHelper.GetHashTableValueByKey(order_ht, "VehicleID"));
                Hashtable user_ht    = userManager.GetUserInfoByUserID(userID);
                DataTable price_dt   = GetPriceInfo(SiteHelper.GetHashTableValueByKey(order_ht, "CityID"), SiteHelper.GetHashTableValueByKey(vehicle_ht, "Model"));
                if (price_dt != null && price_dt.Rows.Count > 0)
                {
                    decimal.TryParse(price_dt.Rows[0]["MinutePrice"].ToString(), out minutePrice);
                    decimal.TryParse(price_dt.Rows[0]["KmPrice"].ToString(), out kmPrice);
                    decimal.TryParse(price_dt.Rows[0]["MinPrice"].ToString(), out minPrice);
                    decimal.TryParse(price_dt.Rows[0]["MaxPrice"].ToString(), out maxPrice);
                }
                minutes = ordersManager.GetOrderBillingTime(SiteHelper.GetHashTableValueByKey(order_ht, "OrderNum"));
                if (minutes > 0)
                {
                    //totalMoney = minutePrice * minutes + kmPrice * (decimal)mileage;
                    totalMoney = minutePrice * (minutes - (minutes > orderFreeMinutes ? orderFreeMinutes : 0)) + kmPrice * (decimal)(mileage - (mileage > orderFreeKm ? orderFreeKm : 0));
                    if (totalMoney < minPrice)
                    {
                        totalMoney = minPrice;
                    }
                    if (totalMoney > maxPrice)
                    {
                        totalMoney = maxPrice;
                    }
                }

                //用车5分钟以内或骑行100米以内还车都不收费
                if (minutes < orderFreeMinutes || mileage < orderFreeKm)
                {
                    totalMoney = 0.00m;
                }

                result["MinutePrice"] = minutePrice;
                result["KmPrice"]     = kmPrice;
                result["Minutes"]     = minutes;
                result["TotalMoney"]  = totalMoney;

                #endregion
            }
            else
            {
                #region 已结算订单

                result["MinutePrice"] = SiteHelper.GetHashTableValueByKey(order_ht, "MinutePrice");
                result["KmPrice"]     = SiteHelper.GetHashTableValueByKey(order_ht, "KMPrice");
                result["Minutes"]     = SiteHelper.GetHashTableValueByKey(order_ht, "Minutes");
                result["TotalMoney"]  = SiteHelper.GetHashTableValueByKey(order_ht, "TotalMoney");

                #endregion
            }

            return(result);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 根据订单号取消订单
        /// </summary>
        /// <param name="OrderNum"></param>
        /// <returns></returns>
        public bool CancelOrder(string orderNum, int type)
        {
            Log Logger = LogFactory.GetLogger(typeof(OrdersManager));

            try
            {
                VehicleManager vehicleManager = new VehicleManager();
                Hashtable      orderInfo      = GetOrderByNum(orderNum);
                string         orderState     = SiteHelper.GetHashTableValueByKey(orderInfo, "OrderState");
                string         startTime      = SiteHelper.GetHashTableValueByKey(orderInfo, "StartTime");
                if (orderInfo != null && orderInfo.Keys.Count > 0 && orderState == "1" && string.IsNullOrEmpty(startTime))
                {
                    string    orderid      = SiteHelper.GetHashTableValueByKey(orderInfo, "ID");
                    string    vid          = SiteHelper.GetHashTableValueByKey(orderInfo, "VehicleID");
                    Hashtable vehicleInfo  = vehicleManager.GetVehicleInfoByID(vid);
                    string    currentSpeed = SiteHelper.GetHashTableValueByKey(vehicleInfo, "CurrentSpeed");
                    decimal   speed        = 0m;
                    decimal.TryParse(currentSpeed, out speed);
                    Logger.Warn("订单ID:" + orderid + ",订单号:" + orderNum + ",车辆ID:" + vid + ",StartTime 为空,速度:" + speed + ",自动取消订单");
                    vehicleManager.CloseVehicle(vid);

                    if (!string.IsNullOrEmpty(orderid))
                    {
                        List <StringBuilder> sqls = new List <StringBuilder>();
                        List <object>        objs = new List <object>();

                        //更改车辆状态
                        StringBuilder sbUpdateVehicle = new StringBuilder();
                        sbUpdateVehicle.Append("UPDATE yr_vehicles SET UseState=@UseState from yr_orders WHERE yr_orders.VehicleID=yr_vehicles.ID and yr_orders.ID=@ID");
                        SqlParam[] updateVehicleParam = new SqlParam[] {
                            new SqlParam("@ID", orderid),
                            new SqlParam("@UseState", VehicleUseState.Free.GetHashCode())
                        };
                        sqls.Add(sbUpdateVehicle);
                        objs.Add(updateVehicleParam);

                        string remark = "客户取消订单";
                        if (type == 1)
                        {
                            remark = "系统自动取消订单";
                        }
                        //更改订单状态
                        StringBuilder sbUpdateOrder = new StringBuilder();
                        sbUpdateOrder.Append(@"UPDATE yr_orders SET TotalMoney=@TotalMoney,Minutes=@Minutes,SettlementMoney=@SettlementMoney,PayMoney=@PayMoney,PayState=@PayState,OrderState=@OrderState,EndTime=@EndTime,FinishedTime=@FinishedTime,OrderRemark=@OrderRemark where ID=@ID and OrderState=" + OrderState.Valid.GetHashCode());
                        SqlParam[] updateOrderParam = new SqlParam[] {
                            new SqlParam("@TotalMoney", "0.00"),
                            new SqlParam("@Minutes", "0"),
                            new SqlParam("@SettlementMoney", "0.00"),
                            new SqlParam("@PayMoney", "0.00"),
                            new SqlParam("@EndTime", DateTime.Now),
                            new SqlParam("@PayState", OrderPayState.NotPay.GetHashCode()),
                            new SqlParam("@OrderState", OrderState.Invalid.GetHashCode()),
                            new SqlParam("@FinishedTime", DateTime.Now),
                            new SqlParam("@OrderRemark", remark),
                            new SqlParam("@ID", orderid)
                        };
                        sqls.Add(sbUpdateOrder);
                        objs.Add(updateOrderParam);

                        return(DataFactory.SqlDataBase().BatchExecuteBySqlWithTrans(sqls.ToArray(), objs.ToArray()));
                    }
                }
                return(false);
            }
            catch
            {
                return(false);
            }
        }