예제 #1
0
        public ActionResult RefundAmount(string OrderID, decimal?Amount = null)
        {
            var recordEntity = new RecordService().SelectByID(OrderID);
            var refundEntity = new RefundService().SelectByID(OrderID);

            if (recordEntity != null)
            {
                JsApiPay jsApiPay = new JsApiPay(this);

                var userEntity = new UserService().SelectByID(recordEntity.UserID);
                jsApiPay.op_user_id = userEntity != null ? userEntity.WeiXin_Openid : "";

                jsApiPay.order_no      = recordEntity.OrderNo;
                jsApiPay.out_refund_no = refundEntity != null ? refundEntity.RefundNo : WxPayApi.GenerateOutTradeNo();
                jsApiPay.total_fee     = Convert.ToInt32(recordEntity.Amount * 100);
                jsApiPay.refund_fee    = Amount != null?Convert.ToInt32(Amount * 100) :
                                             (refundEntity != null ? Convert.ToInt32(refundEntity.Amount * 100) : 0);

                try
                {
                    WxPayData result = jsApiPay.GetRefundOrderResult();
                    if (result.IsSet("result_code") && result.GetValue("result_code").ToString() == "SUCCESS")
                    {
                        return(Content(JsonHelper.SerializeObject(Common.MessageRes.OperateSuccess.SetResult("SUCCESS"))));
                    }
                    else
                    {
                        MYLog.Error("退款申请失败:" + SessionTools.UserName, JsonHelper.SerializeObject(result.GetValues()));
                        return(Content(JsonHelper.SerializeObject(result.GetValue("err_code_des").ToString().SetResult(null))));
                    }
                }
                catch (Exception ex)
                {
                    MYLog.Error("退款申请失败,请返回重试:" + SessionTools.UserName, ex.ToString());
                    return(Content(JsonHelper.SerializeObject("退款申请失败,请返回重试".SetResult(null))));
                }
            }
            return(Content(JsonHelper.SerializeObject(Common.MessageRes.OperateFailed.SetResult(null))));
        }