示例#1
0
        public ApiResultModel DeleteOrder(DetailSearchModel model)
        {
            ApiResultModel resultModel = new ApiResultModel();

            try
            {
                //获取当前商家用户
                IShopUserBLL shopUserBll = BLLFactory <IShopUserBLL> .GetBLL("ShopUserBLL");

                var user = shopUserBll.GetEntity(u => u.Id == model.UserId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT);
                if (user == null)
                {
                    resultModel.Msg = APIMessage.NO_USER;
                    return(resultModel);
                }
                //如果验证Token不通过或已过期
                if (DateTime.Now > user.TokenInvalidTime || model.Token != user.Token)
                {
                    resultModel.Msg = APIMessage.TOKEN_INVALID;
                    return(resultModel);
                }
                //更新最近登录时间和Token失效时间
                user.LatelyLoginTime  = DateTime.Now;
                user.TokenInvalidTime = DateTime.Now.AddDays(Convert.ToInt32(PropertyUtils.GetConfigParamValue("TokenInvalid")));
                shopUserBll.Update(user);

                //获取指定订单
                IOrderBLL orderBll = BLLFactory <IOrderBLL> .GetBLL("OrderBLL");

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

                if (order != null)
                {
                    if (order.OrderStatus == ConstantParam.OrderStatus_FINISH || order.OrderStatus == ConstantParam.OrderStatus_EXIT || order.OrderStatus == ConstantParam.OrderStatus_CLOSE)
                    {
                        order.IsStoreHided = ConstantParam.DEL_FLAG_DELETE;
                        //删除订单
                        if (!orderBll.Update(order))
                        {
                            resultModel.Msg = "订单删除失败";
                        }
                    }
                    else
                    {
                        resultModel.Msg = "当前状态的订单不能被删除";
                    }
                }
                else
                {
                    resultModel.Msg = APIMessage.ORDER_NOEXIST;
                }
            }
            catch
            {
                resultModel.Msg = APIMessage.REQUEST_EXCEPTION;
            }

            return(resultModel);
        }
示例#2
0
        public ActionResult UpdateOrderStatus(OrderStatusUpdateModel model)
        {
            JsonModel jm = new JsonModel();

            //如果表单模型验证成功
            if (ModelState.IsValid)
            {
                //获取指定订单
                IOrderBLL orderBll = BLLFactory <IOrderBLL> .GetBLL("OrderBLL");

                var 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 (model.OrderStatus == ConstantParam.OrderStatus_RECEIPT)
                    {
                        alert             = "您在" + order.Shop.ShopName + "提交的订单商家已接单,请您耐心等待收货";
                        order.OrderStatus = model.OrderStatus;
                    }
                    else if (model.OrderStatus == ConstantParam.OrderStatus_FINISH)
                    {
                        alert              = "您在" + order.Shop.ShopName + "提交的订单交易已完成";
                        order.OrderStatus  = ConstantParam.OrderStatus_FINISH;
                        order.CompleteTime = DateTime.Now;
                    }
                    //如果订单修改成功
                    if (orderBll.Update(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);
                        }
                    }
                }
                else
                {
                    jm.Msg = "该订单已不存在";
                }
            }
            else
            {
                jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR;
            }
            return(Json(jm, JsonRequestBehavior.AllowGet));
        }
示例#3
0
        public ActionResult AlipayPayNotifyUrl()
        {
            SortedDictionary <string, string> sArray = new SortedDictionary <string, string>();
            NameValueCollection coll;

            coll = Request.Form;
            String[] requestItem = coll.AllKeys;

            for (int i = 0; i < requestItem.Length; i++)
            {
                sArray.Add(requestItem[i], Request.Form[requestItem[i]]);
            }

            //判断是否有带返回参数
            if (sArray.Count > 0)
            {
                Notify aliNotify    = new Notify();
                bool   verifyResult = aliNotify.Verify(sArray, Request.Form["notify_id"], Request.Form["sign"]);
                verifyResult = true;
                //如果验证成功
                if (verifyResult)
                {
                    //如果支付成功
                    if (Request.Form["trade_status"] == "TRADE_SUCCESS")
                    {
                        IOrderBLL orderBll = BLLFactory <IOrderBLL> .GetBLL("OrderBLL");

                        string orderNo = Request.Form["out_trade_no"];
                        var    order   = orderBll.GetEntity(o => o.OrderNo == orderNo);
                        if (order != null)
                        {
                            order.OrderStatus = ConstantParam.OrderStatus_RECEIPT;
                            order.PayTradeNo  = Request.Form["trade_no"];
                            orderBll.Update(order);
                        }
                    }
                    return(Content("success"));
                }
                else//验证失败
                {
                    return(Content("fail"));
                }
            }
            else
            {
                return(Content("无通知参数"));
            }
        }
示例#4
0
        public ActionResult OrderDetail(int id)
        {
            IOrderBLL orderBll = BLLFactory <IOrderBLL> .GetBLL("OrderBLL");

            //获取要查看的订单
            T_Order order = orderBll.GetEntity(u => u.Id == id && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT && u.IsStoreHided == ConstantParam.DEL_FLAG_DEFAULT);

            if (order != null)
            {
                return(View(order));
            }
            else
            {
                return(RedirectToAction("OrderList"));
            }
        }
示例#5
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"));
            }
        }
示例#6
0
        public ApiResultModel UpdateOrderStatus(OrderUpdateStatusModel model)
        {
            ApiResultModel resultModel = new ApiResultModel();

            try
            {
                //获取当前商家用户
                IShopUserBLL shopUserBll = BLLFactory <IShopUserBLL> .GetBLL("ShopUserBLL");

                var user = shopUserBll.GetEntity(u => u.Id == model.UserId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT);
                if (user == null)
                {
                    resultModel.Msg = APIMessage.NO_USER;
                    return(resultModel);
                }
                //如果验证Token不通过或已过期
                if (DateTime.Now > user.TokenInvalidTime || model.Token != user.Token)
                {
                    resultModel.Msg = APIMessage.TOKEN_INVALID;
                    return(resultModel);
                }
                //更新最近登录时间和Token失效时间
                user.LatelyLoginTime  = DateTime.Now;
                user.TokenInvalidTime = DateTime.Now.AddDays(Convert.ToInt32(PropertyUtils.GetConfigParamValue("TokenInvalid")));
                shopUserBll.Update(user);

                //获取指定订单
                IOrderBLL orderBll = BLLFactory <IOrderBLL> .GetBLL("OrderBLL");

                var 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 (model.OrderStatus == ConstantParam.OrderStatus_EXIT)
                    {
                        order.Reason = model.Reason;
                        //如果订单状态为待收货
                        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)
                                {
                                    resultModel.Msg = "该订单所属商家未设置账户信息";
                                    return(resultModel);
                                }
                                //获取商家账户信息
                                string WeixinAppId  = wxAccount.Number;
                                string WeixinMchId  = wxAccount.MerchantNo;
                                string WeixinPayKey = wxAccount.AccountKey;
                                //申请退款
                                string result = ApplyRefund(order, WeixinAppId, WeixinMchId, WeixinPayKey);
                                //如果请求失败
                                if (result == null)
                                {
                                    resultModel.Msg = APIMessage.WEIXIN_REFUND_FAIL;
                                    return(resultModel);
                                }
                                //解析返回数据
                                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.OrderStatus  = model.OrderStatus;
                                        order.RecedeType   = 2;
                                        resultModel.result = "订单退款申请成功";
                                    }
                                    else
                                    {
                                        resultModel.Msg = APIMessage.WEIXIN_REFUND_FAIL;
                                        return(resultModel);
                                    }
                                }
                                else
                                {
                                    resultModel.Msg = APIMessage.WEIXIN_REFUND_FAIL;
                                    return(resultModel);
                                }
                            }
                            //支付宝支付退款
                            else if (order.PayWay == 2)
                            {
                            }
                            else
                            {
                                order.OrderStatus = model.OrderStatus;
                                order.RecedeType  = 0;
                            }
                        }
                        else if (order.OrderStatus == ConstantParam.OrderStatus_CONFIRM)
                        {
                            order.OrderStatus = model.OrderStatus;
                            order.RecedeType  = 0;
                        }
                        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);
                            }
                        }
                    }
                    else
                    {
                        if (model.OrderStatus == ConstantParam.OrderStatus_RECEIPT)
                        {
                            alert             = "您在" + order.Shop.ShopName + "提交的订单商家已接单,请您耐心等待收货";
                            order.OrderStatus = model.OrderStatus;
                        }
                        else if (model.OrderStatus == ConstantParam.OrderStatus_FINISH)
                        {
                            alert              = "您在" + order.Shop.ShopName + "提交的订单交易已完成";
                            order.OrderStatus  = ConstantParam.OrderStatus_FINISH;
                            order.CompleteTime = DateTime.Now;
                        }
                        //如果订单修改成功
                        if (orderBll.Update(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);
                            }
                        }
                    }
                }
                else
                {
                    resultModel.Msg = APIMessage.ORDER_NOEXIST;
                }
            }
            catch
            {
                resultModel.Msg = APIMessage.REQUEST_EXCEPTION;
            }
            return(resultModel);
        }
示例#7
0
        public ApiResultModel OrderDetail([FromUri] DetailSearchModel model)
        {
            ApiResultModel resultModel = new ApiResultModel();

            try
            {
                //获取当前商家用户
                IShopUserBLL shopUserBll = BLLFactory <IShopUserBLL> .GetBLL("ShopUserBLL");

                var user = shopUserBll.GetEntity(u => u.Id == model.UserId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT);
                if (user == null)
                {
                    resultModel.Msg = APIMessage.NO_USER;
                    return(resultModel);
                }
                //如果验证Token不通过或已过期
                if (DateTime.Now > user.TokenInvalidTime || model.Token != user.Token)
                {
                    resultModel.Msg = APIMessage.TOKEN_INVALID;
                    return(resultModel);
                }
                //更新最近登录时间和Token失效时间
                user.LatelyLoginTime  = DateTime.Now;
                user.TokenInvalidTime = DateTime.Now.AddDays(Convert.ToInt32(PropertyUtils.GetConfigParamValue("TokenInvalid")));
                shopUserBll.Update(user);

                //获取指定订单
                IOrderBLL orderBll = BLLFactory <IOrderBLL> .GetBLL("OrderBLL");

                var order = orderBll.GetEntity(o => o.Id == model.Id && o.DelFlag == ConstantParam.DEL_FLAG_DEFAULT && o.IsStoreHided == ConstantParam.DEL_FLAG_DEFAULT);
                if (order != null)
                {
                    resultModel.result = new
                    {
                        Id                                           = order.Id,
                        OrderNo                                      = order.OrderNo,
                        ShopName                                     = order.Shop.ShopName,
                        ShopPhone                                    = string.IsNullOrEmpty(order.Shop.Phone) ? "" : order.Shop.Phone,
                        OrderTime                                    = order.OrderDate.ToString("yyyy-MM-dd HH:mm:ss"),
                        OrderStatus                                  = order.OrderStatus,
                        Shipper                                      = order.ShippingAddress.ShipperName + "(" + order.ShippingAddress.Telephone + ")",
                        SendAddress                                  = order.ShippingAddress.County.City.Province.ProvinceName + order.ShippingAddress.County.City.CityName + order.ShippingAddress.County.CountyName + "  " + order.ShippingAddress.AddressDetails,
                        PayWay                                       = order.PayWay,
                        BuyUserName                                  = order.User.UserName,
                        BuyUserHeadPic                               = order.User.HeadPath,
                        BuyUserPhone                                 = order.User.Phone,
                        Memo                                         = order.Memo,
                        RecedeType                                   = order.RecedeType,
                        RemainingTime                                = order.PayDate == null || order.PayDate.Value.AddHours(2) < DateTime.Now ? "0小时0分" : (order.PayDate.Value.AddHours(2) - DateTime.Now).Hours + "小时" + (order.PayDate.Value.AddHours(2) - DateTime.Now).Minutes + "分",
                        ExitOrderReason                              = order.Reason,
                        RefundStatus                                 = GetRefundResult(order.Id),
                        RecedeTime                                   = order.RecedeTime != null?order.RecedeTime.Value.ToString("yyyy-MM-dd HH:mm:ss") : "",
                                                          TotalPrice = Convert.ToDouble(Convert.ToDecimal(order.OrderDetails.Select(d => d.Price).ToArray().Sum())),
                                                          Freight    = Convert.ToDouble(Convert.ToDecimal(order.OrderPrice) - Convert.ToDecimal(order.OrderDetails.Select(d => d.Price).ToArray().Sum())),
                                                          GoodsList  = order.OrderDetails.Select(d => new
                        {
                            SaleName    = d.ShopSale.Title,
                            SaleImg     = string.IsNullOrEmpty(d.ShopSale.ImgThumbnail) ? "" : d.ShopSale.ImgThumbnail.Split(';')[0],
                            SaledAmount = d.SaledAmount,
                            Price       = Convert.ToDouble(Convert.ToDecimal(d.Price / d.SaledAmount))
                        })
                    };
                }
                else
                {
                    resultModel.Msg = "订单已不存在";
                }
            }
            catch
            {
                resultModel.Msg = APIMessage.REQUEST_EXCEPTION;
            }
            return(resultModel);
        }
示例#8
0
        /// <summary>
        /// 获取退款结果数据
        /// </summary>
        /// <param name="OrderId">订单ID</param>
        /// <returns></returns>
        private string GetRefundResult(int OrderId)
        {
            string RefundResult = "";
            //获取订单数据
            IOrderBLL orderBll = BLLFactory <IOrderBLL> .GetBLL("OrderBLL");

            var order = orderBll.GetEntity(o => o.Id == OrderId);

            //如果已经生成了微信支付订单号且退单类型为退单退款
            if (!string.IsNullOrEmpty(order.PayTradeNo) && order.RecedeType == 2)
            {
                //如果是微信在线支付
                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;

                        Random r = new Random();

                        #region 组装参数

                        //组装签名字符串
                        StringBuilder signStr = new StringBuilder();
                        //组装xml格式
                        StringBuilder varBody = new StringBuilder();

                        varBody.Append("<xml>");
                        //APP应用ID
                        varBody.Append("<appid>" + WeixinAppId + "</appid>");
                        signStr.Append("appid=" + WeixinAppId + "&");
                        //商户号
                        varBody.Append("<mch_id>" + WeixinMchId + "</mch_id>");
                        signStr.Append("mch_id=" + WeixinMchId + "&");
                        //随机字符串
                        string str       = "1234567890abcdefghijklmnopqrstuvwxyz";
                        string randomStr = "";
                        for (int i = 0; i < 32; i++)
                        {
                            randomStr = randomStr + str[r.Next(str.Length)].ToString();
                        }
                        varBody.Append("<nonce_str>" + randomStr + "</nonce_str>");
                        signStr.Append("nonce_str=" + randomStr + "&");

                        //支付订单号
                        varBody.Append("<out_trade_no>" + order.PayTradeNo + "</out_trade_no>");
                        signStr.Append("out_trade_no=" + order.PayTradeNo + "&");
                        //签名
                        signStr.Append("key=" + WeixinPayKey);
                        varBody.Append("<sign>" + PropertyUtils.GetMD5Str(signStr.ToString()).ToUpper() + "</sign>");
                        varBody.Append("</xml>");
                        #endregion

                        //发送HTTP POST请求
                        string url = "https://api.mch.weixin.qq.com/pay/refundquery";

                        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                        request.Method      = "POST";
                        request.ContentType = "text/xml";
                        // 信任证书
                        ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);

                        byte[] bytes = Encoding.UTF8.GetBytes(varBody.ToString());
                        request.ContentLength = bytes.Length;
                        using (Stream writer = request.GetRequestStream())
                        {
                            writer.Write(bytes, 0, bytes.Length);
                            writer.Flush();
                            writer.Close();
                        }
                        //处理返回结果
                        string          result   = null;
                        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                        if (response.StatusCode == HttpStatusCode.OK)
                        {
                            using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
                            {
                                result = reader.ReadToEnd();
                                reader.Close();
                            }
                        }

                        //解析返回数据
                        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")
                            {
                                String RefundStatus = doc.GetElementsByTagName("refund_status_0")[0].InnerText;
                                switch (RefundStatus)
                                {
                                case "SUCCESS":
                                    RefundResult = "退款成功";
                                    break;

                                case "FAIL":
                                    RefundResult = "退款失败";
                                    break;

                                case "PROCESSING":
                                    RefundResult = "退款处理中";
                                    break;

                                default:
                                    RefundResult = "退款失败";
                                    break;
                                }
                            }
                        }
                    }
                }
                //如果是支付宝在线支付
                else if (order.PayWay == 2)
                {
                    RefundResult = order.RefundResult;
                }
            }
            return(RefundResult);
        }
示例#9
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));
            }
        }
示例#10
0
        public ActionResult AlipayRefundNotifyUrl()
        {
            SortedDictionary <string, string> sArray = new SortedDictionary <string, string>();
            NameValueCollection coll;

            coll = Request.Form;
            String[] requestItem = coll.AllKeys;

            for (int i = 0; i < requestItem.Length; i++)
            {
                sArray.Add(requestItem[i], Request.Form[requestItem[i]]);
            }

            //判断是否有带返回参数
            if (sArray.Count > 0)
            {
                Notify aliNotify    = new Notify();
                bool   verifyResult = aliNotify.Verify(sArray, Request.Form["notify_id"], Request.Form["sign"]);
                verifyResult = true;
                if (verifyResult)//验证成功
                {
                    string    TradeNo  = Request.Form["result_details"].Split('^')[0];
                    IOrderBLL orderBll = BLLFactory <IOrderBLL> .GetBLL("OrderBLL");

                    var order = orderBll.GetEntity(o => o.PayTradeNo == TradeNo);
                    if (order != null)
                    {
                        order.OrderStatus = ConstantParam.OrderStatus_EXIT;
                        order.RecedeType  = 2;
                        order.RecedeTime  = DateTime.Now;

                        if (Request.Form["result_details"].Split('^')[2] == "SUCCESS")
                        {
                            order.RefundResult = "退款成功";
                        }
                        else
                        {
                            order.RefundResult = "退款失败";
                        }
                        string alert = "您在" + order.Shop.ShopName + "提交的订单已被商家退单";

                        //如果修改成功
                        if (orderBll.Update(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(Content("success"));
                }
                else//验证失败
                {
                    return(Content("fail"));
                }
            }
            else
            {
                return(Content("无通知参数"));
            }
        }
示例#11
0
        public ActionResult WeixinPayNotifyUrl()
        {
            Stream       st       = Request.InputStream;
            StreamReader sr       = new StreamReader(st);
            string       SRstring = sr.ReadToEnd();

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(SRstring);
            sr.Close();

            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")
                {
                    IOrderBLL orderBll = BLLFactory <IOrderBLL> .GetBLL("OrderBLL");

                    string orderNo = doc.GetElementsByTagName("out_trade_no")[0].InnerText;
                    var    order   = orderBll.GetEntity(o => o.PayTradeNo == orderNo);
                    if (order != null && order.OrderStatus == ConstantParam.OrderStatus_NOPAY)
                    {
                        //获取商家账户信息
                        var wxAccount = order.Shop.ShopAccounts.Where(a => a.AccountType == ConstantParam.PROPERTY_ACCOUNT_WeChat).FirstOrDefault();
                        if (wxAccount != null)
                        {
                            //获取商家账户信息
                            string WeixinPayKey = wxAccount.AccountKey;
                            //组装签名字符串
                            StringBuilder signStr = new StringBuilder();
                            signStr.Append("appid=" + doc.GetElementsByTagName("appid")[0].InnerText + "&");
                            signStr.Append("bank_type=" + doc.GetElementsByTagName("bank_type")[0].InnerText + "&");
                            signStr.Append("cash_fee=" + doc.GetElementsByTagName("cash_fee")[0].InnerText + "&");
                            signStr.Append("fee_type=" + doc.GetElementsByTagName("fee_type")[0].InnerText + "&");
                            signStr.Append("is_subscribe=" + doc.GetElementsByTagName("is_subscribe")[0].InnerText + "&");
                            signStr.Append("mch_id=" + doc.GetElementsByTagName("mch_id")[0].InnerText + "&");
                            signStr.Append("nonce_str=" + doc.GetElementsByTagName("nonce_str")[0].InnerText + "&");
                            signStr.Append("openid=" + doc.GetElementsByTagName("openid")[0].InnerText + "&");
                            signStr.Append("out_trade_no=" + orderNo + "&");
                            signStr.Append("result_code=" + result_code + "&");
                            signStr.Append("return_code=" + return_code + "&");
                            signStr.Append("time_end=" + doc.GetElementsByTagName("time_end")[0].InnerText + "&");
                            signStr.Append("total_fee=" + doc.GetElementsByTagName("total_fee")[0].InnerText + "&");
                            signStr.Append("trade_type=" + doc.GetElementsByTagName("trade_type")[0].InnerText + "&");
                            signStr.Append("transaction_id=" + doc.GetElementsByTagName("transaction_id")[0].InnerText + "&");
                            signStr.Append("key=" + WeixinPayKey);
                            string sign = PropertyUtils.GetMD5Str(signStr.ToString()).ToUpper();
                            //签名验证成功
                            if (doc.GetElementsByTagName("sign")[0].InnerText == sign)
                            {
                                //更新订单状态
                                order.OrderStatus = ConstantParam.OrderStatus_RECEIPT;
                                order.PayWay      = 1;
                                order.PayDate     = DateTime.Now;
                                if (orderBll.Update(order))
                                {
                                    IShopBLL shopBLL = BLLFactory <IShopBLL> .GetBLL("ShopBLL");

                                    var ShopUserId = shopBLL.GetEntity(s => s.Id == order.ShopId).ShopUserId;

                                    //推送给订单所属商家
                                    IShopUserPushBLL userPushBLL = BLLFactory <IShopUserPushBLL> .GetBLL("ShopUserPushBLL");

                                    var userPush = userPushBLL.GetEntity(p => p.UserId == ShopUserId);
                                    if (userPush != null)
                                    {
                                        string registrationId = userPush.RegistrationId;
                                        string alert          = "订单号为" + order.OrderNo + "的订单已支付,点击查看详情";
                                        //通知信息
                                        PropertyUtils.SendPush("订单支付通知", alert, ConstantParam.MOBILE_TYPE_SHOP, registrationId);
                                    }
                                }
                            }
                        }
                    }
                    return(Content("success"));
                }
            }
            return(Content("fail"));
        }