Exemplo n.º 1
0
        public ActionResult RecedeOrder(int id)
        {
            IOrderBLL orderBll = BLLFactory <IOrderBLL> .GetBLL("OrderBLL");

            T_Order order = orderBll.GetEntity(o => o.Id == id && o.DelFlag == ConstantParam.DEL_FLAG_DEFAULT && o.IsStoreHided == ConstantParam.DEL_FLAG_DEFAULT);

            if (order != null)
            {
                RecedeReasonModel model = new RecedeReasonModel()
                {
                    OrderId = order.Id,
                    OrderNo = order.OrderNo
                };
                return(View(model));
            }
            else
            {
                return(RedirectToAction("OrderList"));
            }
        }
Exemplo n.º 2
0
        public ActionResult RecedeOrder(RecedeReasonModel model)
        {
            if (ModelState.IsValid)
            {
                IOrderBLL orderBll = BLLFactory <IOrderBLL> .GetBLL("OrderBLL");

                T_Order order = orderBll.GetEntity(o => o.Id == model.OrderId && o.DelFlag == ConstantParam.DEL_FLAG_DEFAULT && o.IsStoreHided == ConstantParam.DEL_FLAG_DEFAULT);

                if (order != null)
                {
                    string alert = "";
                    //如果订单状态为待收货
                    if (order.OrderStatus == ConstantParam.OrderStatus_RECEIPT)
                    {
                        //如果订单支付方式为微信在线支付
                        if (order.PayWay == 1)
                        {
                            //微信退款
                            //获取商家信息
                            var wxAccount = order.Shop.ShopAccounts.Where(a => a.AccountType == ConstantParam.PROPERTY_ACCOUNT_WeChat).FirstOrDefault();
                            if (wxAccount != null)
                            {
                                //获取商家账户信息
                                string WeixinAppId  = wxAccount.Number;
                                string WeixinMchId  = wxAccount.MerchantNo;
                                string WeixinPayKey = wxAccount.AccountKey;

                                //申请退款
                                string result = ApplyRefund(order, WeixinAppId, WeixinMchId, WeixinPayKey);
                                //如果请求失败
                                if (result == null)
                                {
                                    ModelState.AddModelError("OrderId", "订单退款申请失败");
                                    return(View(model));
                                }
                                //解析返回数据
                                XmlDocument doc = new XmlDocument();
                                doc.LoadXml(result);
                                string return_code = doc.GetElementsByTagName("return_code")[0].InnerText;

                                //如果返回成功
                                if (return_code == "SUCCESS")
                                {
                                    string result_code = doc.GetElementsByTagName("result_code")[0].InnerText;
                                    if (result_code == "SUCCESS")
                                    {
                                        order.RecedeType = 2;
                                    }
                                    else
                                    {
                                        ModelState.AddModelError("OrderId", "订单退款申请失败");
                                        return(View(model));
                                    }
                                }
                                else
                                {
                                    ModelState.AddModelError("OrderId", "订单退款申请失败");
                                    return(View(model));
                                }
                            }
                            else
                            {
                                ModelState.AddModelError("OrderId", "该订单所属商家未设置账户信息");
                                return(View(model));
                            }
                        }
                        //支付宝支付退款
                        else if (order.PayWay == 2)
                        {
                            order.Reason = model.Reason;
                            orderBll.Update(order);

                            var    r           = new Random();
                            string batch_no    = DateTime.Now.ToString("yyyyMMddHHmmssfff") + r.Next(1000);
                            string detail_data = order.PayTradeNo + "^" + order.OrderPrice + "^" + model.Reason;

                            //把请求参数打包成数组
                            SortedDictionary <string, string> sParaTemp = new SortedDictionary <string, string>();
                            sParaTemp.Add("service", Alipay.Config.service);
                            sParaTemp.Add("partner", Alipay.Config.partner);
                            sParaTemp.Add("_input_charset", Alipay.Config.input_charset.ToLower());
                            sParaTemp.Add("notify_url", PropertyUtils.GetConfigParamValue("HostUrl") + "/Common/AlipayRefundNotifyUrl");
                            sParaTemp.Add("seller_user_id", Alipay.Config.seller_user_id);
                            sParaTemp.Add("refund_date", Alipay.Config.refund_date);
                            sParaTemp.Add("batch_no", batch_no);
                            sParaTemp.Add("batch_num", "1");
                            sParaTemp.Add("detail_data", detail_data);

                            //建立请求
                            string html = Alipay.Submit.BuildRequest(sParaTemp, "get", "确定");
                            return(Content(html));
                        }
                        else
                        {
                            order.RecedeType = 0;
                        }
                    }
                    //订单状态为待确认
                    else if (order.OrderStatus == ConstantParam.OrderStatus_CONFIRM)
                    {
                        order.RecedeType = 0;
                    }

                    order.OrderStatus = ConstantParam.OrderStatus_EXIT;
                    order.Reason      = model.Reason;
                    order.RecedeTime  = DateTime.Now;
                    alert             = "您在" + order.Shop.ShopName + "提交的订单已被商家退单";

                    //如果退单成功
                    if (orderBll.CancelOrder(order))
                    {
                        //推送给订单所属用户
                        IUserPushBLL userPushBLL = BLLFactory <IUserPushBLL> .GetBLL("UserPushBLL");

                        var userPush = userPushBLL.GetEntity(p => p.UserId == order.AppUserId);
                        if (userPush != null)
                        {
                            string registrationId = userPush.RegistrationId;

                            //通知信息
                            PropertyUtils.SendPush("订单最新状态", alert, ConstantParam.MOBILE_TYPE_OWNER, registrationId);
                        }
                    }
                    return(RedirectToAction("OrderList"));
                }
                else
                {
                    return(RedirectToAction("OrderList"));
                }
            }
            else
            {
                ModelState.AddModelError("OrderId", ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR);
                return(View(model));
            }
        }