private void Submit()
        {
            int orderId       = RequestHelper.GetQueryString <int>("orderId");
            int orderDetailId = RequestHelper.GetQueryString <int>("orderDetailId");

            int     needRefundCount = RequestHelper.GetForm <int>("refund_count");
            decimal needRefundMoney = RequestHelper.GetForm <decimal>("refund_money");
            string  refundRemark    = StringHelper.AddSafe(RequestHelper.GetForm <string>("refund_remark"));

            OrderRefundInfo orderRefund = new OrderRefundInfo();

            orderRefund.RefundNumber = ShopCommon.CreateOrderRefundNumber();
            orderRefund.OrderId      = orderId;
            if (orderDetailId > 0)
            {
                orderRefund.OrderDetailId = orderDetailId;
                orderRefund.RefundCount   = needRefundCount;
            }
            orderRefund.Status       = (int)OrderRefundStatus.Submit;
            orderRefund.TmCreate     = DateTime.Now;
            orderRefund.RefundRemark = refundRemark;
            orderRefund.UserType     = 1;
            orderRefund.UserId       = base.UserId;
            orderRefund.UserName     = base.UserName;

            var refundMsg = JWRefund.VerifySubmitOrderRefund(orderRefund, needRefundMoney);

            if (refundMsg.CanRefund)
            {
                int id = OrderRefundBLL.Add(orderRefund);
                OrderRefundActionBLL.Add(new OrderRefundActionInfo
                {
                    OrderRefundId = id,
                    Status        = (int)BoolType.True,
                    Tm            = DateTime.Now,
                    UserType      = 1,
                    UserId        = base.UserId,
                    UserName      = base.UserName,
                    Remark        = "用户提交退款申请"
                });
                ResponseHelper.Write("ok|" + id);
                ResponseHelper.End();
            }
            else
            {
                ResponseHelper.Write("error|" + refundMsg.ErrorCodeMsg);
                ResponseHelper.End();
            }
        }
        //增加退款操作记录
        private void AddOrderRefundAction(OrderRefundInfo entity, int status)
        {
            OrderRefundActionInfo submitOrderRefundAction = new OrderRefundActionInfo
            {
                OrderRefundId = entity.Id,
                Status        = status,
                Remark        = entity.Remark,
                Tm            = DateTime.Now,
                UserType      = 2,
                UserId        = Cookies.Admin.GetAdminID(false),
                UserName      = Cookies.Admin.GetAdminName(false)
            };

            OrderRefundActionBLL.Add(submitOrderRefundAction);
        }
Example #3
0
        protected void SubmitButton_Click(object sender, EventArgs e)
        {
            CheckAdminPower("OrderRefundApply", PowerCheckType.Single);

            int     orderId         = RequestHelper.GetQueryString <int>("orderId");
            int     orderDetailId   = RequestHelper.GetQueryString <int>("orderDetailId");
            decimal needRefundMoney = Convert.ToDecimal(RefundMoney.Text);

            OrderRefundInfo orderRefund = new OrderRefundInfo();

            orderRefund.RefundNumber = ShopCommon.CreateOrderRefundNumber();
            orderRefund.OrderId      = orderId;
            if (orderDetailId > 0)
            {
                orderRefund.OrderDetailId = orderDetailId;
                orderRefund.RefundCount   = Convert.ToInt32(RefundCount.Text);
            }
            orderRefund.Status       = (int)OrderRefundStatus.Submit;
            orderRefund.TmCreate     = DateTime.Now;
            orderRefund.RefundRemark = RefundRemark.Text;
            orderRefund.UserType     = 2;
            orderRefund.UserId       = Cookies.Admin.GetAdminID(false);
            orderRefund.UserName     = Cookies.Admin.GetAdminName(false);

            var refundMsg = JWRefund.VerifySubmitOrderRefund(orderRefund, needRefundMoney);

            if (refundMsg.CanRefund)
            {
                int id = OrderRefundBLL.Add(orderRefund);
                OrderRefundActionBLL.Add(new OrderRefundActionInfo
                {
                    OrderRefundId = id,
                    Status        = (int)BoolType.True,
                    Tm            = DateTime.Now,
                    UserType      = 2,
                    UserId        = orderRefund.UserId,
                    UserName      = orderRefund.UserName,
                    Remark        = "系统提交退款申请"
                });
                AdminLogBLL.Add(ShopLanguage.ReadLanguage("AddRecord"), ShopLanguage.ReadLanguage("OrderRefund"), id);
                ScriptHelper.Alert("退款申请成功", RequestHelper.RawUrl);
            }
            else
            {
                ScriptHelper.Alert(refundMsg.ErrorCodeMsg);
            }
        }
        private void CancelRefund()
        {
            int id = RequestHelper.GetQueryString <int>("id");
            var submitOrderRefund = OrderRefundBLL.Read(id);

            if (submitOrderRefund.OwnerId != base.UserId)
            {
                ResponseHelper.Write("error|无效的请求");
                ResponseHelper.End();
            }

            if (OrderRefundBLL.CanToReturn(submitOrderRefund.Status))
            {
                submitOrderRefund.Status = (int)OrderRefundStatus.Cancel;
                submitOrderRefund.Remark = "用户取消了退款";
                OrderRefundBLL.Update(submitOrderRefund);

                OrderRefundActionInfo submitOrderRefundAction = new OrderRefundActionInfo
                {
                    OrderRefundId = submitOrderRefund.Id,
                    Status        = (int)BoolType.False,
                    Remark        = submitOrderRefund.Remark,
                    Tm            = DateTime.Now,
                    UserType      = 1,
                    UserId        = base.UserId,
                    UserName      = base.UserName
                };

                OrderRefundActionBLL.Add(submitOrderRefundAction);

                ResponseHelper.Write("ok|");
                ResponseHelper.End();
            }
            else
            {
                ResponseHelper.Write("error|无效的请求");
                ResponseHelper.End();
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            Log.Info(this.GetType().ToString(), "page load");

            if (Page.IsPostBack)
            {
                return;
            }

            /*******************请求参数验证 start*****************************************************************/
            int orderRefundId = RequestHelper.GetQueryString <int>("order_refund_id");
            var orderRefund   = OrderRefundBLL.Read(orderRefundId);

            if (orderRefund.Id < 1)
            {
                Response.Write("<p style=\"margin-left:130px\">无效的退款服务工单</p>");
                Response.End();
            }

            decimal refundMoney = orderRefund.RefundMoney;

            if (refundMoney <= 0)
            {
                Response.Write("<p style=\"margin-left:130px\">无效的退款金额,退款金额必须大于0</p>");
                Response.End();
            }

            if (orderRefund.Status == (int)OrderRefundStatus.HasReturn)
            {
                Response.Write("<p style=\"margin-left:130px\">无效的退款请求,该服务工单已处理退款</p>");
                Response.End();
            }
            if (orderRefund.Status != (int)OrderRefundStatus.Returning)
            {
                Response.Write("<p style=\"margin-left:130px\">无效的退款请求,请等待管理员审核</p>");
                Response.End();
            }

            var order = OrderBLL.Read(orderRefund.OrderId);

            if (order.Id < 1)
            {
                Response.Write("<p style=\"margin-left:130px\">无效的订单</p>");
                Response.End();
            }

            string tradeNo = order.WxPayTradeNo;

            if (string.IsNullOrEmpty(tradeNo))
            {
                Response.Write("<p style=\"margin-left:130px\">无效的微信支付交易号</p>");
                Response.End();
            }

            decimal totalMoney = order.ProductMoney - order.FavorableMoney + order.ShippingMoney + order.OtherMoney - order.Balance - order.CouponMoney - order.PointMoney;

            if (refundMoney > totalMoney)
            {
                Response.Write("<p style=\"margin-left:130px\">退款金额不能超过订单金额</p>");
                Response.End();
            }

            //商户退款单号
            //商户系统内部的退款单号,商户系统内部唯一,同一退款单号多次请求只退一笔
            string batch_no = orderRefund.BatchNo;

            if (string.IsNullOrEmpty(batch_no))
            {
                batch_no = DateTime.Now.ToString("yyyyMMddhhmmssfff");

                //记录退款批次号存入订单退款表
                OrderRefundBLL.UpdateBatchNo(orderRefundId, batch_no);
            }

            /*******************请求参数验证 end*****************************************************************/


            //订单总金额
            string total_fee = Convert.ToInt32(totalMoney * 100).ToString();
            //退款金额
            string refund_fee = Convert.ToInt32(refundMoney * 100).ToString();

            //申请退款

            /***
             * 申请退款完整业务流程逻辑
             * @param transaction_id 微信订单号(优先使用)
             * @param out_trade_no 商户订单号
             * @param out_refund_no 商户退款单号
             * @param total_fee 订单总金额
             * @param refund_fee 退款金额
             * @return 退款结果(xml格式)
             */
            string result = "";

            try
            {
                result = RefundBusiness.Run(tradeNo, "", batch_no, total_fee, refund_fee);

                //退款成功
                bool   isSuccess = true;
                string msg       = "";
                //退款到余额
                if (orderRefund.RefundBalance > 0)
                {
                    //在这里写自己的逻辑
                }

                if (isSuccess)
                {
                    orderRefund.Remark = "退款完成";
                    #region 发送订单退款成功通知
                    int       isSendNotice  = ShopConfig.ReadConfigInfo().RefundOrder;
                    int       isSendEmail   = ShopConfig.ReadConfigInfo().RefundOrderEmail;
                    int       isSendMessage = ShopConfig.ReadConfigInfo().RefundOrderMsg;
                    string    key           = "RefundOrder";
                    OrderInfo order         = OrderBLL.Read(orderRefund.OrderId);
                    if (isSendNotice == (int)BoolType.True && key != string.Empty)
                    {
                        if (isSendEmail == (int)BoolType.True)
                        {//发邮件
                            try
                            {
                                EmailContentInfo    emailContent    = EmailContentHelper.ReadSystemEmailContent(key);
                                EmailSendRecordInfo emailSendRecord = new EmailSendRecordInfo();
                                emailSendRecord.Title     = emailContent.EmailTitle;
                                emailSendRecord.Content   = emailContent.EmailContent.Replace("$UserName$", order.UserName).Replace("$OrderNumber$", order.OrderNumber).Replace("$PayName$", order.PayName).Replace("$ShippingName$", ShippingBLL.Read(order.ShippingId).Name).Replace("$ShippingNumber$", order.ShippingNumber).Replace("$ShippingDate$", order.ShippingDate.ToString("yyyy-MM-dd"));
                                emailSendRecord.IsSystem  = (int)BoolType.True;
                                emailSendRecord.EmailList = order.Email;
                                emailSendRecord.IsStatisticsOpendEmail = (int)BoolType.False;
                                emailSendRecord.SendStatus             = (int)SendStatus.No;
                                emailSendRecord.AddDate  = RequestHelper.DateNow;
                                emailSendRecord.SendDate = RequestHelper.DateNow;
                                emailSendRecord.ID       = EmailSendRecordBLL.AddEmailSendRecord(emailSendRecord);
                                EmailSendRecordBLL.SendEmail(emailSendRecord);
                                //result = "通知邮件已发送。";
                            }
                            catch
                            {
                                //result = "未发送通知邮件。";
                            }
                        }
                        if (isSendMessage == (int)BoolType.True)
                        {//发短信
                         //result += "未发送通知短信。";
                        }
                    }
                    #endregion
                }
                else
                {
                    orderRefund.Remark = orderRefund.RefundPayKey + " 已退款完成,余额退款失败,失败信息:" + msg + ",请线下处理。";
                }

                orderRefund.Status   = (int)OrderRefundStatus.HasReturn;
                orderRefund.TmRefund = DateTime.Now;
                OrderRefundBLL.Update(orderRefund);

                OrderRefundActionBLL.Add(new OrderRefundActionInfo
                {
                    OrderRefundId = orderRefund.Id,
                    Status        = isSuccess ? 1 : 0,
                    Tm            = DateTime.Now,
                    UserType      = 2,
                    UserId        = 0,
                    UserName      = "******",
                    Remark        = orderRefund.Remark
                });

                Response.Redirect("/Admin/OrderRefundAdd.aspx?Id=" + orderRefundId);
            }
            catch
            {
                Response.Write("<p style=\"margin-left:130px\">退款遇到问题</p>");
            }

            //Response.Write(result);
        }