public ActionResult WithdrawalsOrder() { int total_fee = Request["total_fee"].TryToInt(0); if (total_fee <= 0) { return(RedirectToAction("WithdrawalsFailed", new { msg = "提现金额不能小于0" })); } //PsychtestBuyLogBll pbuylogbll = new PsychtestBuyLogBll(); UserWithdrawalsLogBll wilbll = new UserWithdrawalsLogBll(); //decimal PbuyAmt = pbuylogbll.GetMoneyByUserid(User.ID); decimal PbuyAmt = 100;//用户总金额 decimal withAmt = wilbll.GetWithdrawalsAMT(User.ID); if (total_fee > (PbuyAmt - withAmt)) { return(RedirectToAction("WithdrawalsFailed", new { msg = "余额不足" })); } WithdrawalsOrderBll wobll = new WithdrawalsOrderBll(); string OnlineOrder = wobll.GetOnlineOrder(); WeChatUserBll wuserbll = new WeChatUserBll(); WeChatUser wuser = wuserbll.GetWeChatUserByUnionID(User.Openid); A: WxPayData pdata = new WxPayData(); pdata.SetValue("partner_trade_no", OnlineOrder); pdata.SetValue("openid", wuser.ServiceOpenID); pdata.SetValue("check_name", "NO_CHECK"); pdata.SetValue("amount", total_fee * 100); pdata.SetValue("desc", "提现"); pdata.SetValue("spbill_create_ip", "192.168.0.1"); WxPayData result = WxPayApi.transfers(pdata); WithdrawalsOrder wo = new Model.WithdrawalsOrder(); wo.CreateTime = DateTime.Now; wo.OnlineOrder = OnlineOrder; wo.openid = User.Openid; wo.total_fee = total_fee * 100; wo.UserID = User.ID; wo.wsdesc = "提现"; if (result.GetValue("return_code").TryToString() != "SUCCESS") { ClassLoger.Fail("UserCoreController.WithdrawalsOrder用户提现失败", result.GetValue("return_msg").TryToString(), result.GetValue("err_code").TryToString()); // 系统繁忙,请稍后再试错误。使用原单号以及原请求参数重试,否则可能造成重复支付等资金风险 if (result.GetValue("err_code").TryToString() == "SYSTEMERROR") { goto A; } wo.result_code = result.GetValue("result_code").TryToString(); wo.return_code = result.GetValue("return_code").TryToString(); wobll.AddWithdrawalsOrder(wo); return(RedirectToAction("WithdrawalsFailed", new { msg = "提现失败" })); } wo.payment_no = result.GetValue("payment_no").TryToString(); wo.result_code = result.GetValue("result_code").TryToString(); wo.return_code = result.GetValue("return_code").TryToString(); wobll.AddWithdrawalsOrder(wo); UserWithdrawalsLog uwlog = new UserWithdrawalsLog(); uwlog.AMT = total_fee; uwlog.CreateTime = DateTime.Now; uwlog.UserID = User.ID; wilbll.AddUserWithdrawalsLog(uwlog); return(RedirectToAction("WithdrawalsSuccess")); }
public JsonResult <PayOrder> Post(UnifiedOrder obj) { ClassLoger.Info("PayController.Post", obj.PayTyp.ToString(), obj.product_id, obj.productType.TryToString()); JsonResult <PayOrder> result = new JsonResult <PayOrder>(); result.code = 1; result.msg = "OK"; PayOrderBll porderbll = new PayOrderBll(); try { if (obj.PayTyp == 1) { JsApiPay jsApiPay = new JsApiPay(); jsApiPay.openid = ""; if (!obj.openid.IsNull()) { WeChatUserBll wuserbll = new WeChatUserBll(); WeChatUser wuser = wuserbll.GetWeChatUserByUnionID(obj.openid); jsApiPay.openid = wuser.ServiceOpenID; } else if (!obj.userid.IsNull()) { UserInfoBll ubll = new UserInfoBll(); var user = ubll.GetUserinfoByID(obj.userid); if (!user.Openid.IsNull()) { WeChatUserBll wuserbll = new WeChatUserBll(); WeChatUser wuser = wuserbll.GetWeChatUserByUnionID(user.Openid); jsApiPay.openid = wuser.ServiceOpenID; } } jsApiPay.total_fee = 1; jsApiPay.trade_type = obj.trade_type; if (obj.productType == 1) { //查询商品信息,获取商品价格 double Price = 0.1; jsApiPay.total_fee = (Price * 100).TryToInt(); jsApiPay.body = "商品名称"; } jsApiPay.attach = "北京xx"; string out_trade_no = porderbll.GetOnlineOrder(PayTypeEnum.WeChart); jsApiPay.out_trade_no = out_trade_no; jsApiPay.product_id = obj.product_id; ClassLoger.Info("api/Pay/UnifiedOrder", "total_fee", jsApiPay.total_fee.ToString()); WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(); PayOrder porder = new PayOrder(); if (unifiedOrderResult.GetValue("return_code").TryToString() == "SUCCESS" && unifiedOrderResult.GetValue("result_code").TryToString() == "SUCCESS") { if (unifiedOrderResult.IsSet("code_url")) { string code_url = unifiedOrderResult.GetValue("code_url").TryToString(); string filename = string.Format("WXPY{0}.png", code_url.MD5()); string filepath = Path.Combine(SystemSet.ResourcesPath, SystemSet.QrCodePic, filename); if (!File.Exists(filepath)) { QrCodeHelper.CreateImgCode(code_url, filepath); } porder.code_url = Path.Combine(SystemSet.WebResourcesSite, SystemSet.QrCodePic, filename); } porder.OnlineOrder = out_trade_no; porder.openid = obj.openid; porder.PayState = PayStateEnum.Unpaid; porder.PayType = PayTypeEnum.WeChart; porder.prepay_id = unifiedOrderResult.GetValue("prepay_id").TryToString(); porder.product_id = obj.product_id; porder.total_fee = jsApiPay.total_fee; porder.trade_type = obj.trade_type; porder.CreateTime = DateTime.Now; porder.UserID = obj.userid; porder.ID = porderbll.AddPayOrder(porder); result.Result = porder; return(result); } else { result.code = 0; result.msg = unifiedOrderResult.GetValue("return_code").TryToString(); result.ResultMsg = unifiedOrderResult.GetValue("result_code").TryToString(); } } } catch (Exception ex) { result.code = -1; result.msg = "PayController.unifiedorder:" + ex.Message; } return(result); }