public Result <PayResult> Create(PayData data) { Result <PayResult> result = new Result <PayResult>(); result.Msg = "生成支付订单失败"; if (data != null && !string.IsNullOrWhiteSpace(data.iduser) && !string.IsNullOrWhiteSpace(data.orderno)) { try { long _iduser = long.Parse(data.iduser); long _orderno = long.Parse(data.orderno); using (TCom.EF.TN db = new TCom.EF.TN()) { TCom.EF.User u = db.Users.Where(m => m.iduser == _iduser && m.inuse == true).FirstOrDefault(); if (u != null) { TCom.EF.MyOrder o = db.MyOrders.Where(m => m.orderno == _orderno && m.inuse == true).FirstOrDefault(); if (o != null) { if (o.paystatus == PayStatus.WeiXin_CLOSED) { o.status = OrderStatus.Close; db.SaveChanges(); result.Msg = "订单已关闭"; } else { o.paystatus = PayStatus.WaitPay; if (o.payway != "weixin") { o.payway = "weixin"; if (db.SaveChanges() <= 0) { result.Msg = "更新支付方式失败"; return(result); } } result.Data = new PayResult { order = JsApiPay.PayOrder(o, u) }; result.Code = R.Ok; } } } } } catch (Exception) { result.Code = R.Error; result.Msg = "拉取订单出错"; } } else { result.Msg = "不存在该订单"; } return(result); }
public static bool crateMsg(string idweixin, string msg, int msgType, string orderno, int otype, TCom.EF.TN db) { TCom.EF.Msg mo = new TCom.EF.Msg(); mo.idweixin = idweixin; mo.idmsg = P.ID().ToString(); mo.msg1 = msg; mo.cretime = DateTime.Now; mo.status = 0; mo.orderno = orderno; mo.otype = otype; mo.type = msgType; mo.inuse = true; if (db == null) { using (db = new TCom.EF.TN()) { db.Msgs.Add(mo); if (db.SaveChanges() > 0) { Post(); return(true); } } } else { db.Msgs.Add(mo); } return(true); }
public void startService() { while (run) { try { bool isPub = false; using (TCom.EF.TN db = new TCom.EF.TN()) { look: try { isPub = false; var mus = (from muo in db.ManageUsers join uo in db.Users on muo.idweixin equals uo.idweixin where (muo.idweixin != null && muo.idweixin.Trim() != string.Empty && muo.inuse == true && uo.inuse == true && (muo.recv_order == true || muo.recv_setup == true || muo.send_setup == true)) select new { idweixin = muo.idweixin, name = uo.name }).ToList(); List <TCom.EF.Msg> ms = db.Msgs.Where(m => m.inuse == true && m.status == 0).ToList(); if (ms != null && mus != null) { for (int i = 0; i < ms.Count; i++) { TCom.EF.Msg m = ms[i]; long _orderno = long.Parse(m.orderno); TCom.EF.MyOrder mo = db.MyOrders.Where(moo => moo.orderno == _orderno).FirstOrDefault(); if (mo != null) { var uo = (from u in db.Users where (u.iduser == mo.iduser) select new { u.iduser, u.name }).FirstOrDefault(); if (uo != null) { if (m.type == MsgType.PostPayFinishOrder)//订单支付完成,等待派发通知 { isPub = true; m.status = 1; for (int j = 0; j < mus.Count; j++) { var mu = mus[j]; MsgMgr.FinishPay(mu.idweixin, mo, uo.iduser + "", uo.name, db); } } else if (m.type == MsgType.PayFinishOrder) { JObject j = Msg.Send(m.msg1); if (j != null && j.Value <int>("errcode") == 0) { m.status = 1; } } if (db.SaveChanges() > 0) { Pub.e("Msg-SaveChanges:" + 1); } else { isPub = false; Pub.e("Msg-SaveChanges:" + 0); } } } } } } catch (Exception) { throw; } if (isPub) { goto look; } } } catch (Exception e) { Pub.e("error=" + e.InnerException + "_+_+_+_+_+" + e.Message); //throw e; } _event.Reset(); Pub.e("WaitOne=" + DateTime.Now); _event.WaitOne(1000 * 60 * 10); Pub.e("WaitOne-f=" + DateTime.Now); } _event = null; }