/// <summary> /// 注册 /// </summary> public void register() { new driverService().Register(); new MessgeService().Register(); new orderService().Register(); var ws = UseSocket.CreateSocket(); ws.Message = (username, message) => { var request = Newtonsoft.Json.JsonConvert.DeserializeObject <Request>(message); request.Head.Add("wxcount", username); if (request.ClientType.Other.Equals("uploadLocation")) { request.AddService = () => { IDbConnection con = new MySqlConnection(this.Configuration["mysql"]); var driverState = con.ExecuteScalar <long>("select count(1) from orders where driverid=" + request.Head["KeyID"] + " and state=2"); return(driverState.ToString()); } } ; var result = Hup.CreateMsg.Run(request); }; } void outTimeOrders() { var t = Startup.GlobConfiguration["mysql"]; IDbConnection db = new MySql.Data.MySqlClient.MySqlConnection(this.Configuration["mysql"]); db.Open(); JObject obj = new JObject(); obj.Add("state", 3); var lists = db.Query <orders>("select * from orders where state='0' "); TaskManagerService tak = TaskManagerService.Factory(); TokenService token = new TokenService(this.Configuration["appsecret"], this.Configuration["AppID"]); foreach (var key in lists) { Task.Run(async() => { await tak.AutoRun(key.StartTime, keys => { IDbConnection _db = new MySql.Data.MySqlClient.MySqlConnection(this.Configuration["mysql"]); JObject js = JObject.Parse(key.ordersInfo); string sql = uilt.uiltT.Update(obj, "orders", " where id='" + key.id + "' "); _db.Execute(sql); uilt.uiltT.SendWxMessage(token, "您的订单从" + js["startingPoint"] + "到" + js["endingPoint"] + "的 行程,由于长时间没有司机接单已经超时,请重新创建行程。", js["openid"].ToString()); _db.Close(); return(Task.CompletedTask); }); }); } db.Close(); } }
public int payOrder(string sing) { if (ActionList.ContainsKey(sing)) { ActionList[sing](); ActionList.Remove(sing); TaskManagerService.Factory().deleteJob(sing); return(1); } return(0); }
public bool Put(int id, [FromBody] JObject value, string openid = null) { if (value["state"] != null) { TaskManagerService.Factory().deleteJob("task" + id); } if (value["state"].ToString() == "2") { Task.Run(async() => { string wxcount = HttpContext.Session.GetString("openid"); if (driverService.driverinfo.ContainsKey(wxcount)) { driverService.driverinfo[wxcount].status = 0; } await TaskManagerService.Factory().AutoRun(DateTime.Now.AddMinutes(5), key => { _list.Remove(id.ToString()); return(Task.CompletedTask); }); }); } if (value["state"].ToString() == "-1" && _list.Contains(id.ToString())) { return(false); } if (value["state"].ToString() == "-1") { var order = Get(id); var info = order.ordersInfo; if (!string.IsNullOrEmpty(info)) { string wxcount = HttpContext.Session.GetString("openid"); if (driverService.driverinfo.ContainsKey(wxcount)) { driverService.driverinfo[wxcount].status = 1; } else { var obj = JObject.Parse(info); var driver = this.Uc.readById(obj["userid"].ToString()); if (driverService.driverinfo.ContainsKey(wxcount)) { driverService.driverinfo[wxcount].status = 1; } } } } int n = this.db.Execute(uiltT.Update(value, "orders", "where id=" + id)); return(n > 0 ? true : false); }
public bool meetOrder(int id, [FromBody] JObject value) { lock (this) { string wxcount = HttpContext.Session.GetString("openid"); long t = (long)this.db.ExecuteScalar("select count(1) from orders where id=" + id + " and state =0"); if (t == 0) { return(false); } int n = this.db.Execute(uiltT.Update(value, "orders", "where id=" + id)); TaskManagerService.Factory().deleteJob("task" + id); return(n > 0 ? true : false); } }
public string complete(int id, [FromBody] JObject value) { var result = Guid.NewGuid().ToString(); Action task = () => { if (this.db.State != ConnectionState.Open) { this.db.Open(); } var trn = this.db.BeginTransaction(); try { var order = this.db.QueryFirst <orders>("select * from orders where id=" + id); var flv = order.userprice - order.driverprice; var fy = Math.Round(flv * double.Parse(CostService.Config["sharePrice"]), 2); var users = this.Uc.readById(order.userid.ToString()); users.bill = Math.Round(users.bill - order.userprice, 2); if (!string.IsNullOrWhiteSpace(users.recommender)) { setShareBill(order.id, users, fy); } this.db.Execute("UPDATE userinfo set bill=" + users.bill + " where id=" + order.userid); userinfo drivers = null; if (order.driverid == order.userid.ToString()) { drivers = users; } else { drivers = this.Uc.readById(order.driverid); } Task.Run(() => { this.Uc.rmove(users.wxCount); this.Uc.rmove(drivers.wxCount); }); if (!string.IsNullOrWhiteSpace(drivers.recommender)) { setShareBill(order.id, drivers, fy); } drivers.bill = Math.Round(drivers.bill + order.driverprice); this.db.Execute("UPDATE userinfo set bill=" + drivers.bill + " where id=" + order.driverid); int n = this.db.Execute(uiltT.Update(value, "orders", "where id=" + id)); trn.Commit(); SendTz(order); //return n > 0 ? true : false; } catch (Exception e) { var t = e.Message; trn.Rollback(); } //return false; }; Task.Run(async() => { await TaskManagerService.Factory().AutoRun(DateTime.Now.AddDays(3), res => { if (ActionList.ContainsKey(result)) { //ActionList[result](); ActionList.Remove(result); } return(Task.CompletedTask); }, result); }); ActionList.Add(result, task); return(result); }
public Result Post([FromBody] orderinfo value) { lock (this) { var str = HttpContext.Session.GetInt32("order"); if (str != null && DateTime.Now.Minute == str) { return(Result.Run(res => throw new Exception("不能频繁提交订单"))); } } return(Result.Run(ress => { var openid = HttpContext.Session.GetString("openid"); HttpContext.Session.SetInt32("order", DateTime.Now.Minute); if (value.riderType != 4 && value.startDate.AddMinutes(2) <= DateTime.Now.AddHours(2)) { throw new Exception("乘坐时间必须在2小时后"); } if (value.riderType == 4) { value.startDate.AddMinutes(5); } orders result = Hup.CreateMsg.Run(value).Content; var user = this.Uc.read(openid); if (user.bill < value.price) { ress.code = 2; ress.data = value.price; throw new Exception("账户余额不足。"); } result.userid = user.id; var sql = result.Insert(); var cmd = this.db.CreateCommand(); this.db.Open(); cmd.CommandText = sql; cmd.ExecuteNonQuery(); cmd.CommandText = "select LAST_INSERT_ID()"; //var n = this.db.Execute(sql); var id = (ulong)cmd.ExecuteScalar(); //this.db.ExecuteScalar<long>(""); if (value.riderType == 4) { string locationInfo = "insert into locationInfo(orderid,longitude,latitude)values('" + id + "','" + value.longitude + "','" + value.latitude + "')"; int n = this.db.Execute(locationInfo, value); } value.startDate = value.startDate.AddMinutes(5); this.db.Close(); string[] eumslist = new string[] { "", "顺风车", "专车", "速递", "快车" }; Task.Run(async() => { await TaskManagerService.Factory().AutoRun(value.startDate, key => { JObject obj = new JObject(); obj.Add("state", 3); string upsql = uilt.uiltT.Update(obj, "orders", " where id='" + id + "' "); db.Execute(upsql); uilt.uiltT.SendWxMessage(token, "您的订单从" + value.startingPoint + "到" + value.endingPoint + "的行程,由于长时间没有司机接单已经超时,请重新创建行程。", openid); return Task.CompletedTask; }, "task" + id); }); Task.Run(() => { if (value.riderType == 4) { foreach (var key in driverService.driverinfo) { var t = (((key.Value.pointy - value.longitude) * Math.PI * 12656 * Math.Cos(((key.Value.pointx + value.latitude) / 2) * Math.PI / 180) / 180) * ((key.Value.pointy - value.longitude) * Math.PI * 12656 * Math.Cos(((key.Value.pointx + value.latitude) / 2) * Math.PI / 180) / 180)); var t2 = (((key.Value.pointx - value.latitude) * Math.PI * 12656 / 180) * ((key.Value.pointx - value.latitude) * Math.PI * 12656 / 180)); if (Math.Sqrt(t + t2) < 3 && key.Value.status == 1) { uilt.uiltT.SendWxMessage(token, "有新的从" + value.startingPoint + "到" + value.endingPoint + "的" + eumslist[value.riderType] + "订单。", key.Key); } } return; } string noticeSql = "select wxCount from userinfo join driverinfo on userinfo.id=driverinfo.userid where driverstate=1"; noticeSql += " and route like '%" + value.riderType + "%' "; var list = this.db.Query <string>(noticeSql); foreach (var key in list) { uilt.uiltT.SendWxMessage(token, "有新的从" + value.startingPoint + "到" + value.endingPoint + "的" + eumslist[value.riderType] + "订单。", key); } }).Wait(); ress.data = id; })); //return id.ToString();// n > 0 ? "" : "订单创建失败"; }