Ejemplo n.º 1
0
 /// <summary>
 /// 秒退款操作
 /// </summary>
 /// <param name="applyid"></param>
 /// <returns></returns>
 private bool Refund(string applyid)
 {
     try
     {
         bool result = false;
         DepositReturnManager depositManager = new DepositReturnManager();
         Hashtable            ht             = depositManager.GetDataByID(applyid);
         string  state          = SiteHelper.GetHashTableValueByKey(ht, "State");
         string  depositMoney   = SiteHelper.GetHashTableValueByKey(ht, "DepositMoney");
         string  depositPayWay  = SiteHelper.GetHashTableValueByKey(ht, "DepositPayWay");
         string  depositTradeNo = SiteHelper.GetHashTableValueByKey(ht, "DepositTradeNo");
         decimal refundMoney    = 0.00m;
         refundMoney = decimal.Parse(depositMoney);
         string errmsg = "";
         string code   = "";
         if (depositPayWay == "1")
         {
             //查询支付结果 支付宝退款
             AlipayRefund alipay = new AlipayRefund();
             result = alipay.Refund2(depositTradeNo, refundMoney, out errmsg, out code);
         }
         else if (depositPayWay == "2")
         {
             //微信退款
             WxRefund wxpay = new WxRefund();
             result = wxpay.refund2(depositTradeNo, refundMoney, out errmsg);
         }
         else if (depositPayWay == "5")
         {
             //微信公众号退款
             api.weapp.pay.wxpay.WxRefund wxpay = new api.weapp.pay.wxpay.WxRefund();
             result = wxpay.refund2(depositTradeNo, refundMoney, out errmsg);
         }
         if (result)
         {
             result = depositManager.HandleReturnDeposit(applyid, "2", "", "系统");
         }
         return(result);
     }
     catch
     {
         return(false);
     }
 }
        protected void Save_Click(object sender, EventArgs e)
        {
            try
            {
                bool      result         = false;
                int       returnType     = 0;
                Hashtable ht             = depositManager.GetDataByID(_key);
                string    depositMoney   = SiteHelper.GetHashTableValueByKey(ht, "DepositMoney");
                string    depositPayWay  = SiteHelper.GetHashTableValueByKey(ht, "DepositPayWay");
                string    depositTradeNo = SiteHelper.GetHashTableValueByKey(ht, "DepositTradeNo");
                string    realName       = SiteHelper.GetHashTableValueByKey(ht, "RealName");
                string    bindPhone      = SiteHelper.GetHashTableValueByKey(ht, "BindPhone");
                decimal   refundMoney    = 0.00m;
                refundMoney = decimal.Parse(depositMoney);
                if (State.Value == "2")
                {
                    string errmsg = "";
                    string code   = "";
                    if (depositPayWay == "1")
                    {
                        //支付宝退款
                        AlipayRefund alipay = new AlipayRefund();
                        result = alipay.Refund2(depositTradeNo, refundMoney, out errmsg, out code);
                        Logger.Warn(string.Format("{0},{1}支付宝退款:{2}", realName, bindPhone, errmsg));
                        if (!result && "40004".Equals(code))
                        {
                            //ShowMsgHelper.Alert_Error("支付宝退款失败:" + errmsg + "!");
                            //return;

                            //判断是否保存了buyer_id
                            string buyer_id = SiteHelper.GetHashTableValueByKey(ht, "buyer_id");
                            if (string.IsNullOrEmpty(buyer_id))
                            {
                                //buyer_id为空需要查询订单
                                AlipayOrderQuery orderQuery  = new AlipayOrderQuery();
                                OrderQueryResult queryResult = orderQuery.QueryByTradeNO(depositTradeNo);
                                buyer_id = queryResult.buyer_user_id;
                            }

                            if (!string.IsNullOrEmpty(buyer_id))
                            {
                                //执行单笔转账到支付宝账户
                                result = alipay.Transfer(depositTradeNo, buyer_id, refundMoney, out errmsg);
                                Logger.Warn(string.Format("{0},{1}支付宝转账退款:{2}", realName, bindPhone, errmsg));
                                returnType = 1;
                                if (!result)
                                {
                                    ShowMsgHelper.Alert_Error("支付宝转账退款失败:" + errmsg + "!");
                                    return;
                                }
                            }
                        }
                    }
                    else if (depositPayWay == "2")
                    {
                        //微信退款
                        WxRefund wxpay = new WxRefund();
                        result = wxpay.refund2(depositTradeNo, refundMoney, out errmsg);
                        if (!result)
                        {
                            ShowMsgHelper.Alert_Error("微信退款失败:" + errmsg + "!");
                            return;
                        }
                    }
                    else if (depositPayWay == "5")
                    {
                        //微信公众号退款
                        api.weapp.pay.wxpay.WxRefund wxpay = new api.weapp.pay.wxpay.WxRefund();
                        result = wxpay.refund2(depositTradeNo, refundMoney, out errmsg);
                        if (!result)
                        {
                            ShowMsgHelper.Alert_Error("微信公众号退款失败:" + errmsg + "!");
                            return;
                        }
                    }
                }
                else
                {
                    result = true;
                }
                if (result)
                {
                    result = depositManager.HandleReturnDeposit(_key, State.Value, Remark.Text.Trim(), RequestSession.GetSessionUser().UserName.ToString(), returnType);
                    if (result)
                    {
                        ShowMsgHelper.AlertMsgNoFresh("操作成功!");
                    }
                    else
                    {
                        ShowMsgHelper.Alert_Error("操作失败!");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }