Beispiel #1
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);
        }
Beispiel #2
0
        public static bool RejectOrders()
        {
            try
            {
                //CommonUtils.WriteLog("进入到RejectOrders方法内部");
                //调用定单接口
                IOrderBLL templateBLL = BLLFactory <IOrderBLL> .GetBLL("OrderBLL");

                var twoHourAgoTime = DateTime.Now.AddHours(-2);

                //找出所有超过2小时商家没有接单的
                var orders = templateBLL.GetList(o => o.OrderStatus == ConstantParam.OrderStatus_CONFIRM && o.PayDate < twoHourAgoTime).ToList();
                //CommonUtils.WriteLog("成功连接数据库成功");
                //修改订单状态为退单状态

                foreach (var order in orders)
                {
                    order.OrderStatus = ConstantParam.OrderStatus_EXIT;
                    order.RecedeType  = 1;
                    order.RecedeTime  = DateTime.Now;
                    order.Reason      = "商家2小时未接单,系统自动退单";
                    var alert = "您在" + order.Shop.ShopName + "提交的订单因商家2小时未接单已自动退单";

                    if (templateBLL.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);
                        }
                    }
                }

                var twoDayAgoTime = DateTime.Now.AddDays(-2);

                var end   = twoDayAgoTime.AddHours(2);
                var start = end.AddMinutes(-2);
                //获取所有提交订单超过46小时,且没有付款没有提醒的订单
                var noPayAndRemindOrders = templateBLL.GetList(o => o.OrderStatus == ConstantParam.OrderStatus_NOPAY && o.OrderDate < end && o.OrderDate >= start).ToList();
                foreach (var order in noPayAndRemindOrders)
                {
                    var          alert       = "您在" + order.Shop.ShopName + "提交的订单还未付款,2小时后订单会自动关闭";
                    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);
                    }
                }


                //获取所有提交订单超过2天,且没有付款的订单
                var noPayOrders = templateBLL.GetList(o => o.OrderStatus == ConstantParam.OrderStatus_NOPAY && o.OrderDate < twoDayAgoTime).ToList();
                foreach (var order in noPayOrders)
                {
                    order.OrderStatus = ConstantParam.OrderStatus_CLOSE;
                    var alert = "您在" + order.Shop.ShopName + "提交的订单因长时间不付款已自动关闭";

                    if (templateBLL.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(true);
            }
            catch (Exception ex)
            {
                CommonUtils.WriteLogError(ex);
                return(false);
            }
        }
Beispiel #3
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));
            }
        }
 public JsonResult DeleteOrder(OrderInfo order)
 {
     return(orderBLL.CancelOrder(order.UserId));
 }