public JsonResult CheckOrderStatus(string orderId) { if (string.IsNullOrEmpty(orderId)) { return(Data(ResultCode.PARAMS_IS_NULL)); } wy_wx_pay payOrder = this._order.GetWxPayById(orderId); if (payOrder.STATUS == 2) //已经支付的订单 { return(Data(ResultCode.SCCUESS, true)); } if (payOrder.STATUS == 0) //订单生成,且未支付,需要主动check订单状态 { Dictionary <string, object> Orders = this._order.FindOrder(orderId); if (Orders != null && Orders["return_code"].ToString() == "SUCCESS" && Orders["return_code"].ToString() == "SUCCESS") { //检查支付的订单金额 var totel_fee = Convert.ToInt32(Orders["total_fee"]); var checkStatus = this._order.CheckOrder(orderId, totel_fee); if (checkStatus) { Payed(orderId, totel_fee, JsonConvert.SerializeObject(Orders)); } return(Data(ResultCode.SCCUESS, checkStatus)); } return(Data(ResultCode.SCCUESS, false)); } else //已经失效的订单和支付失败的订单直接返回false; { return(Data(ResultCode.SCCUESS, false)); } }
private bool WaterCost(wy_wx_pay Order) { _log.LogInformation($"【wy_w_pay】准备插入:{Order.ID}"); var Pay = this._order.W_PayCount(Order.ID); if (Pay <= 0) // 未生成过订单 { var Res = this._order.InsertW_Pay(new wy_w_pay() { GUID = Order.ID, MeterID = Order.TYPES_ID, RechargeVolume = Convert.ToDouble(Order.AMOUNT), AddAmount = Convert.ToDouble(Order.TOTAL_FEE / 100.00), UnitPrice = Order.UNIT_PRICE, CreateDate = DateTime.Now }); if (Res > 0) { Task.Run(() => { InsertPayRecord(Order); }); _log.LogInformation($"【wy_w_pay】更新成功:{Order.ID}"); } else { _log.LogError($"【wy_w_pay】更新失败:{Order.ID}"); return(false); } } return(true); }
private bool InsertPayRecord(wy_wx_pay Order) { _log.LogInformation($"【InsertPayRecord】准备插入新增支付记录:{Order.ID}"); if (Order.RECORD_ID.Trim() == "0") //自主缴费 { var record = new wy_pay_record() { RECORD_ID = Order.ID, JFLX = Order.FEE_TYPES.ToString(), FWID = Order.HOUSE_ID, JFJE = (Order.TOTAL_FEE / 100.00), JFZT = 1, SFTZ = 1, JFRQ = Order.PAY_TIME, PAY_WAY = 1, SURPLUSVALUE = GetSurplus(Order.FEE_TYPES, Order.TYPES_ID, Order.TYPES_ID_ELE_COLL), CREATE_TIME = Order.CREATE_TIME, CZ_SHID = Order.USER_ID, OPEN_ID = Order.OPEN_ID, CONFIRM_RECIVEMONEY = 0, JFCS = 0 }; var Res = _order.InsertRecord(record) > 0; if (Res) { _log.LogInformation($"【InsertPayRecord】插入新增支付成功:{Order.ID}"); } else { _log.LogError($"【InsertPayRecord】插入新增支付失败:{Order.ID}"); } } return(true); }
public Dictionary <string, object> GetPrepaySign(wy_wx_pay payModel) { //1.wy_wx_pay生成payModel Dictionary <string, object> pay = ToWeChatPayModel(payModel); //2.排序去重,并将其生成字符串sign string XmlPay = this._Xml.DicToXmlStr(pay); //3.获取PrepayId _log.LogInformation("支付订单创建:" + XmlPay); string ResponseInfo = HttpHelper.PostHttpResponse(CommonFiled.payUrl, XmlPay); string ReprepayId = GetPrepayId(ResponseInfo); if (!string.IsNullOrEmpty(ReprepayId)) { payModel.PREPAYID = ReprepayId; //4.根据prepayId生成JSAPI请求数据 var MchSec = CommonFiled.MchSecret(payModel.FEE_TYPES); return(GetParamStrByPrePayId(payModel.APP_ID, ReprepayId, MchSec, payModel.ORDER_ID, payModel.ID)); } if (CheckPay(ResponseInfo) > 0) { var dic = new Dictionary <string, object>(); dic.Add("OrderErr", payModel.ORDER_ID); dic.Add("OrderErrId", payModel.ID); return(dic); } return(null); }
private bool WXPaidAfter(wy_wx_pay Order) { //根据订单ID try { _log.LogInformation($"支付成功,更新类型:{CommonFiled.FeeTypeName(Order.FEE_TYPES)}"); //更新缴费记录表,如果为自主缴费记录,支付成功后,重新生成新数据 //如果类型为物业费 // recoreId 不为空,证明为提醒订单,需要修改record表中的数据 if (Order != null && (!string.IsNullOrEmpty(Order.RECORD_ID)) && Order.RECORD_ID != SelfPayOrder) { return(PropertyCost(Order)); } //如果类型为水费, if (CommonFiled.EnumFeeTypes(Order.FEE_TYPES) == FeeTypes.Water) { return(WaterCost(Order)); } //如果类型为电费 if (CommonFiled.EnumFeeTypes(Order.FEE_TYPES) == FeeTypes.Electricity) { return(ElectricityCost(Order)); } return(true); } catch (Exception ex) { _log.LogError(ex, "微信支付成功后逻辑处理错误:[OrderID]:" + Order.ORDER_ID); return(false); } }
private bool Payed(string OrderId, int TotelFee, string content) { //验证订单信息金额 wy_wx_pay pay = this._order.GetWxPayById(OrderId); if (pay != null && pay.STATUS == 0 && pay.TOTAL_FEE == Convert.ToInt32(TotelFee)) { pay.STATUS = 2; pay.PAY_TIME = DateTime.Now; pay.STATUS_REMARK = content; if (this._order.Update(pay) > 0) { SendMsg(pay); //返回信息 Task.Run(() => //异步操作,防止返回超时,被调用两次 { WXPaidAfter(pay); }); return(true); } else { _log.LogInformation("微信支付异步回调请求:订单更新失败或已支付!"); } } return(false); }
public int Inert(wy_wx_pay wxpay) { if (string.IsNullOrEmpty(wxpay.ID)) { wxpay.ID = Guid.NewGuid().ToString("N"); } return(this._db.Db().Insertable(wxpay).ExecuteCommand()); }
//[Authorize(Roles ="Admin")] public ActionResult OrderDetail(string id) { if (string.IsNullOrEmpty(id)) { Exception("没有查询到单据信息"); } wy_wx_pay Model = this._order.GetWxOrderDetail(id); ViewBag.Type = CommonFiled.FeeTypeName(Model.FEE_TYPES); ViewBag.MoneyNum = Convert.ToDouble((Model.TOTAL_FEE / 100.00)); return(View(Model)); }
public Dictionary <string, object> FindOrder(string orderId) { wy_wx_pay payOrder = GetWxPayById(orderId); if (null != payOrder) { var resInfo = this._pay.FindOrder(CommonFiled.appID, orderId, payOrder.MECH_ID); var Orders = this._pay.CheckOrder(resInfo); return(Orders); } return(null); }
public int Update(wy_wx_pay wxpay) { int Result = 0; using (var db = this._db.Db()) { //sql锁,正确处理避免死锁 Result = db.Updateable(wxpay).UpdateColumns(c => new { c.STATUS, c.PAY_TIME, c.STATUS_REMARK }) .Where(c => c.STATUS != 2 && (c.ORDER_ID == wxpay.ORDER_ID || c.ID == wxpay.ID)) //订单支付成功,不可修改。 .With(SqlWith.UpdLock) .ExecuteCommand(); } return(Result); }
/// <summary> /// 新单据界面 /// </summary> /// <returns></returns> public ActionResult Receipt(string id) { if (string.IsNullOrEmpty(id)) { Exception("没有查询到单据信息"); } wy_wx_pay Model = this._order.GetWxOrderDetail(id); ViewBag.Type = CommonFiled.FeeTypeName(Model.FEE_TYPES); ViewBag.MoneyNum = Convert.ToDouble((Model.TOTAL_FEE / 100.00)).ToString("0.00"); ViewBag.PayTime = Model.PAY_TIME.HasValue ? Model.PAY_TIME.Value.ToString("yyyy/MM/dd") : "xxxx/xx/xx"; //ViewBag.EffectiveTime = Model. ViewBag.Payee = CommonFiled.MchName(Model.FEE_TYPES); return(View(Model)); }
private async void SendMsg(wy_wx_pay order) { var data = new { openId = OpenID, data = new { first = $"尊敬的业主({order.SHOP_NAME}--{order.HOUSE_ADDRESS})您好,您已缴费成功。信息如下:", keyword1 = order.PAY_TIME.Value.ToString("yyyy-MM-dd HH:mm:ss"), keyword2 = order.REMARK, keyword3 = Convert.ToDouble(order.TOTAL_FEE / 100.00) + "元", remark = "如有疑问,请咨询物业管理处。" } }; await PayMsg.SendMsg(JsonConvert.SerializeObject(data)); }
//1.wy_wx_pay生成payModel private Dictionary <string, object> ToWeChatPayModel(wy_wx_pay wxpay) { //<sign> 0CB01533B8C1EF103065174F50BCA001 </sign> Dictionary <string, object> Paramters = new Dictionary <string, object>(); Paramters.Add("appid", CommonFiled.appID); Paramters.Add("body", wxpay.REMARK); Paramters.Add("mch_id", CommonFiled.MchId(wxpay.FEE_TYPES)); Paramters.Add("nonce_str", wxpay.ID); Paramters.Add("notify_url", CommonFiled.payCallBack); Paramters.Add("openid", wxpay.OPEN_ID); Paramters.Add("out_trade_no", wxpay.ORDER_ID); Paramters.Add("spbill_create_ip", wxpay.USER_IP); Paramters.Add("total_fee", wxpay.TOTAL_FEE); Paramters.Add("trade_type", "JSAPI"); var MchSec = CommonFiled.MchSecret(wxpay.FEE_TYPES); Paramters.Add("sign", this._Sign.WePaySign(Paramters, MchSec)); return(Paramters); }
private bool ElectricityCost(wy_wx_pay Order) { _log.LogInformation($"【wy_ele_recharge】准备插入:{Order.ID}"); var Pay = this._order.ElectricityCount(Order.ID); if (Pay <= 0) { double unitPrice = GetUnitPriceOfElectric(); var Res = this._order.InsertElectricity(new wy_ele_recharge() { id = Order.ID, CreateDate = DateTime.Now, address = Order.TYPES_ID, cid = Order.TYPES_ID_ELE_COLL, EleAmount = Order.AMOUNT, Cost = Order.AMOUNT * unitPrice, WYCost = Convert.ToDecimal(Order.TOTAL_FEE / 100.00), }); if (Res > 0) { Task.Run(() => { InsertPayRecord(Order); }); _log.LogInformation($"【wy_ele_recharge】更新成功:{Order.ID}"); } else { _log.LogError($"【wy_ele_recharge】更新失败:{Order.ID}"); return(false); } } else { _log.LogInformation($"【wy_ele_recharge】订单已存在,过滤重复插入"); return(false); } return(true); }
public wy_wx_pay GetWxPay(OrderDto oder) { v_pay_record record = oder.Record; var pay = new wy_wx_pay(); pay.ID = CommonFiled.guid; pay.APP_ID = CommonFiled.appID; pay.ORDER_ID = CommonFiled.ABC + CommonFiled.orderId; pay.RECORD_ID = record.RECORD_ID; pay.HOUSE_ID = oder.Houseinfo.FWID; pay.USER_ID = oder.Shopinfo.CZ_SHID; //用户ID pay.OPEN_ID = record.OPEN_ID; pay.FEE_TYPES = Convert.ToInt32(record.JFLX); pay.TOTAL_FEE = record.JFJE.HasValue ? Convert.ToInt32(record.JFJE.Value * 100) : 0; pay.REMARK = $"自助缴费_{Fee.Types.SingleOrDefault(c => c.Value == Convert.ToInt32(record.JFLX)).Key}"; pay.STATUS = 0; pay.CREATE_TIME = DateTime.Now; pay.MECH_ID = CommonFiled.MchId(record.JFLX); pay.NONCE_STR = CommonFiled.guid; pay.PREPAY_TIME = DateTime.Now; pay.PREPAY_ENDTIME = DateTime.Now.AddHours(2); pay.TRADE_TYPE = CommonFiled.JSAPI; pay.HOUSE_NAME = oder.Houseinfo.FWMC; pay.HOUSE_ADDRESS = oder.Houseinfo.ZLWZ; pay.HOUSE_AREA = oder.Houseinfo.JZMJ; pay.HOUSE_SERVICEEFFCTIVE = pay.FEE_TYPES != 0 ? "" : $"{toDate(oder.Record.YXQS,"yyyy/MM/dd")}-{toDate(oder.Record.YXQZ,"yyyy/MM/dd")}"; //物业费单价 pay.HOUSE_SERVICE_UNITPRICE = Convert.ToDecimal(oder.Costs.WYDJ); pay.USER_NAME = oder.Shopinfo.ZHXM; pay.SHOP_NAME = oder.Shopinfo.SHOP_NAME; pay.TOTAL_FEE_CH = CommonFiled.CmycurD(Convert.ToDecimal((pay.TOTAL_FEE / 100.00))); pay.MECH_NAME = CommonFiled.MchName(pay.FEE_TYPES); pay.TYPES_ID = pay.FEE_TYPES == 0 ? "" : (pay.FEE_TYPES == 1 ? oder.Houseinfo.WATER_NUMBER : oder.Houseinfo.ELE_NUMBER); pay.TYPES_ID_ELE_COLL = oder.Houseinfo.CID; return(pay); }
private bool PropertyCost(wy_wx_pay Order) { _log.LogInformation($"【wy_pay_record】准备更新:{Order.RECORD_ID}"); FeeTypes type = CommonFiled.EnumFeeTypes(Order.FEE_TYPES); var Res = this._order.UpdateRecoredJFZT(new wy_pay_record() { RECORD_ID = Order.RECORD_ID, JFZT = 1, JFRQ = Order.PAY_TIME, PAY_WAY = 1, JFJE = (Order.TOTAL_FEE / 100.00) }); if (Res > 0) { _log.LogInformation($"【wy_pay_record】更新成功:{Order.RECORD_ID}"); } else { _log.LogError($"【wy_pay_record】更新失败:{Order.RECORD_ID},订单:{Order.ID}"); return(false); } return(true); }
public Dictionary <string, object> GetPayParamsByWxModel(wy_wx_pay wxpay) { return(this._pay.GetPrepaySign(wxpay)); }
public JsonResult CreateOrder(string recordId, string houseId, string UId, int WNum, double EPrice, string Type) { if (string.IsNullOrEmpty(houseId) || string.IsNullOrEmpty(UId)) { return(Data(ResultCode.PARAMS_IS_NULL, null, ResultCode.PARAMS_IS_NULL.GetEnumDescription())); } //1.订单查询有无此数据,无数据默认创建新数据 wy_wx_pay pay = null; if (!string.IsNullOrEmpty(recordId)) { pay = this._order.FindSingle(recordId, houseId, UId, OpenID); //自助缴费订单,每次都是新订单 } //原订单失效,异步更改状态 bool UpdateTime = pay != null && DateTime.Now > pay.PREPAY_ENDTIME; if (pay == null || UpdateTime) { if (UpdateTime) //异步更新过期订单信息,并生成新的订单信息 { Task.Run(() => { pay.STATUS = 1; this._order.Update(pay); }); } //获取提醒订单信息 OrderDto PayRecord = null; if (string.IsNullOrEmpty(recordId)) { PayRecord = this._order.GetWxPay(UId, houseId); } else { PayRecord = this._order.GetWxPay(UId, recordId, houseId); } //校验是否为自助缴费订单 if (PayRecord.Record == null || PayRecord.Record.RECORD_ID == null) { PayRecord.Record = new v_pay_record() { OPEN_ID = OpenID, JFLX = Type, JFJE = EPrice, //默认物业费 RECORD_ID = SelfPayOrder //默认0为自助订单,非缴费提醒 }; } pay = this._order.GetWxPay(PayRecord); pay.USER_IP = UserIP; //存储水量以及电量 if (pay.FEE_TYPES != 0) //非物业费 { //非物业默认记录电的价格 pay.UNIT_PRICE = Convert.ToInt32(this._order.GetUnitPrice(CommonFiled.UnitPriceElectricSetKey) * 100); pay.AMOUNT = Convert.ToInt32(EPrice); pay.TOTAL_FEE = Convert.ToInt32(pay.UNIT_PRICE * pay.AMOUNT); pay.TOTAL_FEE_CH = CommonFiled.CmycurD(Convert.ToDecimal((pay.UNIT_PRICE * pay.AMOUNT) / 100.00)); if (pay.FEE_TYPES == 1) { // 为水的时候需要记录单价 pay.UNIT_PRICE = Convert.ToInt32(this._order.GetUnitPrice(CommonFiled.UnitPriceWaterKey) * 100); pay.AMOUNT = WNum; pay.TOTAL_FEE = Convert.ToInt32(pay.UNIT_PRICE * pay.AMOUNT); pay.TOTAL_FEE_CH = CommonFiled.CmycurD(Convert.ToDecimal((pay.UNIT_PRICE * pay.AMOUNT) / 100.00)); } } if (pay.TOTAL_FEE <= 0) //如果订单生成为0元,直接视为无效订单,禁止生成。 { return(Data(ResultCode.PARAMS_IS_INVALID)); } //将订单存到数据库 if (this._order.Inert(pay) <= 0) { return(Data(ResultCode.DATA_IS_WRONG)); } ; } // 这里需要过滤订单信息 return(Data(ResultCode.SCCUESS, new { sign = this._order.GetPayParamsByWxModel(pay) })); }