Ejemplo n.º 1
0
        public JsonResult AddMessageEmail(UserMessageEmailModel userMessageEmailModel)
        {
            AjaxResponse ajaxResponse;
            try
            {
                if (userMessageEmailModel != null)
                {
                    userMessageEmailModel.EmployeeID = this.SystemUserSession.EmployeeID;
                    userMessageEmailModel.CreateTime = DateTime.Now;
                    this.userMessageEmailService = new UserMessageEmailService();

                    var userMessageEmail = DataTransfer.Transfer<User_Message_Email>(userMessageEmailModel, typeof(UserMessageEmailModel));

                    userMessageEmailModel.ID = this.userMessageEmailService.Add(userMessageEmail);
                    ajaxResponse = new AjaxResponse(1, "添加成功!", userMessageEmailModel);
                    LogUtils.Log("用户" + this.SystemUserSession.LoginName + "成功添加邮件信息", "AddMessageEmail", Category.Info, Session.SessionID);
                    return this.Json(ajaxResponse);
                }

                ajaxResponse = new AjaxResponse(-1, "添加失败!");
                return this.Json(ajaxResponse);
            }
            catch (Exception exception)
            {
                ajaxResponse = new AjaxResponse(-1, exception.Message);
                LogUtils.Log(
                    "用户" + this.SystemUserSession.LoginName + "添加邮件信息错误:" + exception.Message,
                    "AddMessageEmail",
                    Category.Error,
                    Session.SessionID);
                return this.Json(ajaxResponse);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 获取操作权限信息
 /// </summary>
 /// <param name="action">
 /// The action.
 /// </param>
 /// <param name="controller">
 /// The controller.
 /// </param>
 /// <param name="requestMethod">
 /// 请求类型:Get或Post
 /// </param>
 /// <returns>
 /// The <see cref="ActionResult"/>.
 /// </returns>
 public ActionResult GetRightInfo(string action, string controller, string requestMethod)
 {
     this.systemRightsService = new SystemRightsService();
     var key = this.systemRightsService.BuildResourceKey(controller, action, requestMethod);
     var permissions = this.SystemUserSession.Permissions;
     var response = new AjaxResponse(this.systemRightsService.ValidateRight(key, permissions) ? 0 : -403);
     return this.Json(response, JsonRequestBehavior.AllowGet);
 }
        /// <summary>
        /// 取消未发货未付款订单
        /// </summary>
        /// <param name="orderCancelModel">
        /// The order cancel model.
        /// </param>
        /// <returns>
        /// The <see cref="ActionResult"/>.
        /// </returns>
        public ActionResult CancelOrder(OrderCancelModel orderCancelModel)
        {
            var response = new AjaxResponse();
            if (orderCancelModel == null || orderCancelModel.OrderID < 1 || orderCancelModel.OrderCancelCauseID < 1)
            {
                response.State = -1;
                response.Message = "参数错误";
                return this.Json(response, JsonRequestBehavior.AllowGet);
            }

            try
            {
                var orderCancel = DataTransfer.Transfer<Order_Cancel>(orderCancelModel, typeof(OrderCancelModel));
                orderCancel.EmployeeID = this.SystemUserSession.EmployeeID;
                int state = new OrderService(this.SystemUserSession.EmployeeID).OrderCancelByBackstage(orderCancel);

                // 0-订单状态异常,1-操作成功,2-已发货,3-订单已取消、损失或者作废
                if (state == 0)
                {
                    response.State = 0;
                    response.Message = "订单状态异常";
                }
                else if (state == 1)
                {
                    response.State = 1;
                    response.Message = "订单取消成功";
                }
                else if (state == 2)
                {
                    response.State = 2;
                    response.Message = "已发货,取消订单操作取消";
                }
                else if (state == 3)
                {
                    response.State = 3;
                    response.Message = "订单已取消、已损失或者已作废";
                }
                else if (state == 4)
                {
                    response.State = 4;
                    response.Message = "订单已付款";
                }

                return this.Json(response, JsonRequestBehavior.AllowGet);
            }
            catch (Exception exception)
            {
                TextLogger.Instance.Log("订单取消操作发生错误", Category.Error, exception);

                response.State = -2;
                response.Message = exception.Message;
                return this.Json(response, JsonRequestBehavior.AllowGet);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// The put shelf.
        /// </summary>
        /// <param name="productID">
        /// The product id.
        /// </param>
        /// <returns>
        /// The <see cref="ActionResult"/>.
        /// </returns>
        public ActionResult DownShelf(string productID)
        {
            AjaxResponse ajaxResponse;

            try
            {
                this.ProductService.ModifyProductStatus(productID, 3);

                ajaxResponse = new AjaxResponse(1);
            }
            catch (Exception exception)
            {
                throw new Exception(exception.Message, exception);
            }

            return this.Json(ajaxResponse);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// The put recycle.
        /// </summary>
        /// <param name="productID">
        /// The product id.
        /// </param>
        /// <returns>
        /// The <see cref="ActionResult"/>.
        /// </returns>
        public ActionResult PutRecycle(string productID)
        {
            AjaxResponse ajaxResponse;

            try
            {
                this.ProductService.ModifyProductStatus(productID, 4);

                ajaxResponse = new AjaxResponse(1);
            }
            catch (global::System.Exception exception)
            {
                throw new Exception(exception.Message, exception);
            }

            return this.Json(ajaxResponse);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// The modify picture category.
        /// </summary>
        /// <param name="pictures">
        /// The pictures.
        /// </param>
        /// <param name="parentCategoryID">
        /// The parent category id.
        /// </param>
        /// <param name="productCategoryID">
        /// The product category id.
        /// </param>
        /// <param name="parentBrandID">
        /// The parent brand id.
        /// </param>
        /// <param name="productBrandID">
        /// The product brand id.
        /// </param>
        /// <returns>
        /// The <see cref="ActionResult"/>.
        /// </returns>
        public ActionResult ModifyPictureCategory(List<string> pictures, string parentCategoryID, string productCategoryID, string parentBrandID, string productBrandID)
        {
            AjaxResponse jsonResponse;

            try
            {
                this.pictureService = new PictureService();

                foreach (var picture in pictures)
                {
                    this.pictureService.ModifyPictureCategory(Convert.ToInt32(picture), parentCategoryID, productCategoryID, parentBrandID, productBrandID);
                }

                jsonResponse = new AjaxResponse(1);
            }
            catch (Exception exception)
            {
                throw new Exception(exception.Message, exception);
            }

            return this.Json(jsonResponse);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// The remove.
        /// </summary>
        /// <param name="productID">
        /// The product id.
        /// </param>
        /// <returns>
        /// The <see cref="ActionResult"/>.
        /// </returns>
        public ActionResult Remove(string productID)
        {
            AjaxResponse ajaxResponse;

            try
            {
                this.ProductService.RemoveByID(productID);

                ajaxResponse = new AjaxResponse(1);
            }
            catch (global::System.Exception exception)
            {
                throw new Exception(exception.Message, exception);
            }

            return this.Json(ajaxResponse);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 查询所有CPS数据
        /// </summary>
        /// <returns>
        /// The <see cref="ActionResult"/>.
        /// </returns>
        public ActionResult QueryCpsList()
        {
            var response = new AjaxResponse();
            try
            {
                var cpsList = new CpsService().QueryAll();

                if (cpsList == null)
                {
                    response.State = 2;
                    response.Message = "没有获取到CPS数据";
                    return this.Json(response, JsonRequestBehavior.AllowGet);
                }

                var items = new List<SelectListItem>();
                foreach (var cps in cpsList)
                {
                    items.Add(new SelectListItem { Text = cps.Name, Value = cps.ID.ToString() });
                }

                response.State = 1;
                response.Data = items;
                return this.Json(response, JsonRequestBehavior.AllowGet);
            }
            catch (Exception exception)
            {
                response.State = -1;
                response.Message = exception.Message;
                return this.Json(response, JsonRequestBehavior.AllowGet);
                throw;
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// The get order invoic info.
        /// </summary>
        /// <param name="orderId">
        /// The order id.
        /// </param>
        /// <returns>
        /// The <see cref="ActionResult"/>.
        /// </returns>
        public ActionResult GetOrderInvoicInfo(int orderId)
        {
            var orderInvoiceService = new OrderInvoiceService();
            var result = new AjaxResponse();
            try
            {
                var orderInvoice = orderInvoiceService.SelectByOrderID(orderId);
                if (orderInvoice == null)
                {
                    result.State = 2;
                }
                else
                {
                    result.State = 1;
                    if (string.IsNullOrWhiteSpace(orderInvoice.InvoiceTitle))
                    {
                        orderInvoice.InvoiceTitle = "个人";
                    }

                    result.Data = DataTransfer.Transfer<OrderInvoiceModel>(orderInvoice, typeof(Order_Invoice));
                }
            }
            catch (Exception exception)
            {
                result.State = -1;
                result.Message = exception.Message;
            }

            return this.Json(result, JsonRequestBehavior.AllowGet);
        }
Ejemplo n.º 10
0
 /// <summary>
 /// 设置订单为废单
 /// </summary>
 /// <param name="orderId">
 /// 订单编码
 /// </param>
 /// <param name="reason">
 /// The reason.
 /// </param>
 /// <returns>
 /// The <see cref="ActionResult"/>.
 /// </returns>
 public ActionResult SetOrderToInvalid(int orderId, string reason)
 {
     var result = new AjaxResponse();
     try
     {
         var orderService = new OrderService(this.SystemUserSession.EmployeeID);
         orderService.SetInvalidByGJW(orderId, reason);
         result.State = 1;
         result.Message = "修改成功!";
         return this.Json(result, JsonRequestBehavior.AllowGet);
     }
     catch (Exception ex)
     {
         result.State = -1;
         result.Message = ex.Message;
         LogUtils.Log("将订单作废操作失败(订单编码:" + orderId + "),错误消息:"+ex.Message+";"+ex.InnerException+";"+ex.StackTrace, "后台作废订单", Category.Error, this.SystemUserSession.SessionID, 0, "Order/SetOrderToInvalid");
         return this.Json(result, JsonRequestBehavior.AllowGet);
     }
 }
Ejemplo n.º 11
0
        /// <summary>
        /// 取消订单
        /// </summary>
        /// <param name="ono"></param>
        /// <param name="orderCancelCauseID"></param>
        /// <returns></returns>
        public ActionResult Cancel(string ono, int orderCancelCauseID)
        {
            var response = new AjaxResponse();
            //if (orderID < 1 || orderCancelCauseID < 1)
            //{
            //    response.State = -1;
            //    response.Message = "参数错误";
            //    return this.Json(response, JsonRequestBehavior.AllowGet);
            //}

            var order = new OrderService(this.UserSession.UserID, false).QueryByOrderCode(ono);
            if (order == null || order.UserID != this.UserSession.UserID)
            {
                response.State = -1;
                response.Message = "订单编号错误";
                LogUtils.Log(
                    "用户取消订单时订单编号(" + ono + ")错误或者获取对应订单数据为空",
                    "前台取消订单",
                    Category.Error,
                    this.UserSession.SessionId,
                    this.UserSession.UserID,
                    "/Order/Cancel");
                return this.Json(response, JsonRequestBehavior.AllowGet);
            }

            //可取消条件:
            // 1.只有在线支付且未支付
            // 2.订单货到付款且未确认
            if (order.Status != 100 && (order.Status == 0 && order.PaymentMethodID == 0))
            {
                LogUtils.Log(
                    "前台尝试取消不符合取消条件的订单(订单号:" + ono + ")",
                    "前台取消订单",
                    Category.Warn,
                    this.UserSession.SessionId,
                    this.UserSession.UserID,
                    "/Order/Cancel");
                TextLogger.Instance.Log("前台尝试取消不符合取消条件的订单(订单号:" + ono + ",用户名:"+this.UserSession.UserID+")", Category.Warn, null);

                response.State = -1;
                response.Message = "此订单不符合取消条件";
                return this.Json(response);
            }

            try
            {
                var orderCancel = new Order_Cancel
                                      {
                                          OrderID = order.ID,
                                          CreateTime = DateTime.Now,
                                          OrderCancelCauseID = orderCancelCauseID,
                                          UserID = this.UserSession.UserID
                                      };

                int state = new OrderService(this.UserSession.UserID,false).OrderCancelByBackstage(orderCancel);

                // 0-订单状态异常,1-操作成功,2-已发货,3-订单已取消、损失或者作废
                if (state == 0)
                {
                    response.State = 0;
                    response.Message = "订单状态异常";
                }
                else if (state == 1)
                {
                    response.State = 1;
                    response.Message = "订单取消成功";
                }
                else if (state == 2)
                {
                    response.State = 2;
                    response.Message = "已发货,取消订单操作取消";
                }
                else if (state == 3)
                {
                    response.State = 3;
                    response.Message = "订单已取消、已损失或者已作废";
                }
                else if (state == 4)
                {
                    response.State = 4;
                    response.Message = "订单已付款";
                }
                else
                {
                    response.State = 0;
                    response.Message = "订单状态异常";
                }

                LogUtils.Log(
                    "前台尝试取消订单(订单号:" + ono + "),结果:(状态:" + response.State + ";消息:" + response.Message + ")",
                    "前台取消订单",
                    Category.Info,
                    this.UserSession.SessionId,
                    this.UserSession.UserID,
                    "/Order/Cancel");

                return this.Json(response, JsonRequestBehavior.AllowGet);
            }
            catch (Exception exception)
            {
                TextLogger.Instance.Log("订单取消操作发生错误", Category.Error, exception);

                response.State = -2;
                response.Message = exception.Message;
                return this.Json(response, JsonRequestBehavior.AllowGet);
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 检查特殊全局促销信息
        /// </summary>
        /// <param name="product"></param>
        /// <param name="updateQuantity"></param>
        /// <returns></returns>
        private AjaxResponse CheckSpecialPromote(int productId, ref int updateQuantity)
        {
            //验证是否是特殊活动的商品
            if (this.UserSession.UserID > 0)
            {
                var specialPromotes = MongoDBHelper.GetModels<SpecialPromote>(p => p.GiftProductID == productId && p.ID > 0);

                if (specialPromotes != null && specialPromotes.Count > 0) //若不是,则直接跳过
                {
                    var specialPromote = specialPromotes[0]; //一个赠品只能参加一个活动
                    AjaxResponse ajaxResponse = null;
                    if (specialPromote.IsValid == false)
                    {
                        updateQuantity = 0;
                        ajaxResponse = new AjaxResponse(0, "为活动赠品,活动已失效,不能领取。");
                        return ajaxResponse;
                    }

                    if (specialPromote.EndTime < DateTime.Now)
                    {
                        updateQuantity = 0;
                        ajaxResponse = new AjaxResponse(0, "为活动赠品,活动已结束,不能领取。");
                        return ajaxResponse;
                    }

                    if (specialPromote.StartTime > DateTime.Now)
                    {
                        updateQuantity = 0;
                        ajaxResponse = new AjaxResponse(0, "为活动赠品,活动尚未开始,不能领取。");
                        return ajaxResponse;
                    }

                    var userPromote = specialPromote.UserPromotes.FirstOrDefault(p => p.UserID == this.UserSession.UserID);

                    //判断是否已参加活动,未参加,则直接跳过
                    if (userPromote == null)
                    {
                        updateQuantity = 0;
                        ajaxResponse = new AjaxResponse(0, "为活动赠品,您未参加此活动,不能领取。");
                        return ajaxResponse;
                    }

                    //判断是否已领取活动,已领取,则直接跳过
                    if (userPromote.HasGetGift)
                    {
                        updateQuantity = 0;
                        ajaxResponse = new AjaxResponse(0, "为活动赠品,您已领取过来,不能多次领取。");
                        return ajaxResponse;
                    }

                    //判断参加活动是否超过一天
                    if ((DateTime.Now - userPromote.ParticipateTime).TotalDays > 1)
                    {
                        updateQuantity = 0;
                        ajaxResponse = new AjaxResponse(0, "为活动赠品,您今日未参加此活动,不能领取。");
                        return ajaxResponse;
                    }

                    updateQuantity = 1;
                    ajaxResponse = new AjaxResponse(1, "活动商品");
                    return ajaxResponse;
                }
            }

            return null;
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 检查库存、限购信息并设置购买数量
        /// </summary>
        /// <param name="product"></param>
        /// <param name="updateQuantity"></param>
        /// <returns></returns>
        private AjaxResponse SetUpdateQuantity(ProductSearchResult product, ref int updateQuantity)
        {
            AjaxResponse ajaxResponse = null;

            ajaxResponse = CheckSpecialPromote(product.ID, ref updateQuantity);

            //此商品参加了特殊全局促销活动
            if (ajaxResponse != null)
            {
                return ajaxResponse;
            }

            var billProduct = new OrderBillServices().QueryCartProduct(product.ID, updateQuantity, this.UserSession.UserID);

            //不允许购买情况
            if (billProduct.DenyFlag > 0)
            {
                switch (billProduct.DenyFlag)
                {
                    case 1:
                        ajaxResponse = new AjaxResponse(
                            11,
                            "对不起,此商品只允许新会员购买!");
                        updateQuantity = 0;
                        return ajaxResponse;
                    case 2:
                        ajaxResponse = new AjaxResponse(
                            12,
                            "对不起,此商品只允许老会员购买!");
                        updateQuantity = 0;
                        return ajaxResponse;
                    case 3:
                        ajaxResponse = new AjaxResponse(
                            13,
                            "对不起,此商品只允许通过手机验证会员购买。");
                        updateQuantity = 0;
                        return ajaxResponse;
                    case 4:
                        ajaxResponse = new AjaxResponse(
                            14,
                            "对不起,此商品只允许通过邮箱验证会员购买。");
                        updateQuantity = 0;
                        return ajaxResponse;
                    case 5:
                        ajaxResponse = new AjaxResponse(
                            15,
                            "对不起,此商品仅限新会员购买,请先注册或登录。");
                        updateQuantity = 0;
                        return ajaxResponse;
                    case 6:
                        ajaxResponse = new AjaxResponse(
                            16,
                            "对不起,您已参加过此活动。");
                        updateQuantity = 0;
                        return ajaxResponse;
                    default:
                        ajaxResponse = new AjaxResponse(
                            0,
                            "对不起,您不满足此商品的购买条件。");
                        updateQuantity = 0;
                        return ajaxResponse;
                }
            }

            var promnoteItems = billProduct.PromoteTypes.Split(',');

            //验证多选一互斥促销
            if (promnoteItems.Contains("4")&&!string.IsNullOrWhiteSpace(billProduct.Exclude))
            {
                var userCart = MongoDBHelper.GetModel<UserCartModel>(u => u.VisitorKey == this.UserSession.VisitorKey);
                if (userCart != null && userCart.ProductItems.Count > 0)
                {
                    var excludes = billProduct.Exclude.Split(',');
                    if (excludes.Length > 0)
                    {
                        foreach (var item in userCart.ProductItems)
                        {
                            if (item.ProductID != billProduct.ProductID && excludes.Contains(item.ProductID.ToString()))
                            {
                                ajaxResponse = new AjaxResponse(
                                    0,
                                    string.Format("对不起,【{0}】与【{1}】不能同时购买。", item.ProductName, billProduct.ProductName));
                                updateQuantity = 0;
                                return ajaxResponse;
                            }
                        }
                    }
                }
            }

            var islimited = promnoteItems.Contains("1"); // 是否参加限时抢购
            if (islimited)
            {
                if (product.InventoryNumber <= 0)
                {
                    ajaxResponse = new AjaxResponse(
                        0,
                        "对不起,商品已售完!",
                        new { quantity = updateQuantity, totalDiscount = billProduct.FavorablePrice });
                    updateQuantity = 0;
                }
                else if (billProduct.PromoteResidueQuantity <= 0)
                {
                    ajaxResponse = new AjaxResponse(
                        0,
                        "对不起,活动商品库存不足!",
                        new { quantity = updateQuantity, totalDiscount = billProduct.FavorablePrice });
                    updateQuantity = 0;
                }
                else
                {
                    // 检查此商品是否限购件数(不限购)
                    if (billProduct.LimitedBuyQuantity <= 0)
                    {
                        if (billProduct.PromoteResidueQuantity < updateQuantity)
                        {
                            // 购物车数量必须小于活动库存
                            ajaxResponse = new AjaxResponse(
                                0,
                                "对不起,此商品库存不足!你最多可购买" + billProduct.PromoteResidueQuantity + "件",
                                new { quantity = updateQuantity, totalDiscount = billProduct.FavorablePrice });
                            updateQuantity = billProduct.PromoteResidueQuantity;
                        }
                    }
                    else
                    {
                        // 每人限购
                        if (billProduct.MaxBuyQuantity < updateQuantity)
                        {

                            ajaxResponse = new AjaxResponse(
                                0,
                                string.Format("对不起,此商品每人限购{0}件", billProduct.LimitedBuyQuantity),
                                new { quantity = updateQuantity, totalDiscount = billProduct.FavorablePrice });
                            updateQuantity = billProduct.MaxBuyQuantity;
                        }
                    }
                }
            }
            else if (product.InventoryNumber < updateQuantity) // 检查库存
            {
                if (product.InventoryNumber > 0)
                {
                    ajaxResponse = new AjaxResponse(
                        0,
                        "对不起,此商品的库存不足,您最多可购买" + product.InventoryNumber + "件",
                        new { quantity = product.InventoryNumber, totalDiscount = billProduct.FavorablePrice });
                    //cart.ProductItems.Add(this.ConvertToCartProduct(product, product.InventoryNumber)); //库存不够,则设置库存值
                    updateQuantity = product.InventoryNumber;
                }
                else
                {
                    ajaxResponse = new AjaxResponse(
                        0,
                        "对不起,此商品已售完",
                        new { quantity = product.InventoryNumber, totalDiscount = billProduct.FavorablePrice });
                    //cart.ProductItems.Add(this.ConvertToCartProduct(product, product.InventoryNumber)); //库存不够,则设置库存值
                    updateQuantity = 0;
                }
            }

            return ajaxResponse;
        }
Ejemplo n.º 14
0
        /// <summary>
        /// The remove.
        /// </summary>
        /// <param name="pictures">
        /// The pictures.
        /// </param>
        /// <returns>
        /// The <see cref="ActionResult"/>.
        /// </returns>
        public ActionResult Remove(List<string> pictures)
        {
            AjaxResponse jsonResponse;

            try
            {
                this.pictureService = new PictureService();

                foreach (var picture in pictures)
                {
                    this.pictureService.RemovePictureByID(Convert.ToInt32(picture));
                }

                jsonResponse = new AjaxResponse(1);
            }
            catch (Exception exception)
            {
                throw new Exception(exception.Message, exception);
            }

            return this.Json(jsonResponse);
        }
Ejemplo n.º 15
0
        public JsonResult ModifyMessageEmail(UserMessageEmailModel userMessageEmailModel)
        {
            AjaxResponse ajaxResponse;
            try
            {
                if (userMessageEmailModel != null)
                {
                    this.userMessageEmailService = new UserMessageEmailService();

                    var userMessageEmail = DataTransfer.Transfer<User_Message_Email>(
                        userMessageEmailModel,
                        typeof(UserMessageEmailModel));

                    this.userMessageEmailService.Modify(userMessageEmail);
                    userMessageEmailModel.StatusName = userMessageEmailModel.Status == 0 ? "正常" : "停止";
                    ajaxResponse = new AjaxResponse(1, "修改成功!", userMessageEmailModel);
                    LogUtils.Log("用户" + this.SystemUserSession.LoginName + "成功修改邮件信息", "ModifyMessageEmail", Category.Info, Session.SessionID);
                    return this.Json(ajaxResponse);
                }

                ajaxResponse = new AjaxResponse(-1, "添加失败!");
                return this.Json(ajaxResponse);
            }
            catch (Exception exception)
            {
                ajaxResponse = new AjaxResponse(-1, exception.Message);
                LogUtils.Log("用户" + this.SystemUserSession.LoginName + "修改邮件信息:" + exception.Message, "ModifyMessageEmail", Category.Error, Session.SessionID);
                return this.Json(ajaxResponse);
            }
        }
Ejemplo n.º 16
0
        public ActionResult SearchUserInfo(string searchStr)
        {
            AjaxResponse response = null;
            try
            {
                var userService = new UserService();
                var user = userService.QueryUserByMobileOrEmail(searchStr);
                if (user == null)
                {
                    response = new AjaxResponse(2, "用户不存在");
                    return this.Json(response);
                }

                var userAddressService = new UserReceiveAddressService();
                var userDefaultAddress = userAddressService.QueryDefaultReceiveAddressByUserID(user.ID);

                if (userDefaultAddress != null)
                {
                    var addressModel = DataTransfer.Transfer<UserReceiveAddressModel>(
                        userDefaultAddress,
                        typeof(User_RecieveAddress));
                    addressModel.UserID = user.ID;
                    addressModel.UserName = user.Name;
                    response = new AjaxResponse(1, string.Empty, addressModel);
                    return this.Json(response);
                }
                else
                {
                    var userModel = DataTransfer.Transfer<UserModel>(user, typeof(User));
                    response = new AjaxResponse(3, "没有地址信息", userModel);
                    return this.Json(response);
                }
            }
            catch (Exception exception)
            {
                response = new AjaxResponse(-1, exception.Message);
                return this.Json(response);
            }
        }
Ejemplo n.º 17
0
        public ActionResult AddOrder(
            List<ProductModel> products,
            int userID,
            int receiveAddressID,
            int paymentMethodID,
            bool isRequireInvoice,
            OrderInvoiceModel invoiceInfo,
            string description = null)
        {
            try
            {
                if (products == null || products.Count < 1)
                {
                    var data = new AjaxResponse(-1, "订单商品为空!");
                    return this.Json(data);
                }

                if (userID < 1)
                {
                    var data = new AjaxResponse(-1, "用户编码错误!");
                    return this.Json(data);
                }

                if (receiveAddressID < 1)
                {
                    var data = new AjaxResponse(-1, "收货信息地址编码错误!");
                    return this.Json(data);
                }

                if (paymentMethodID < 0)
                {
                    var data = new AjaxResponse(-1, "支付地址错误!");
                    return this.Json(data);
                }

                Order_Invoice invoice = null;
                if (isRequireInvoice)
                {
                    if (invoiceInfo.InvoiceContentID < 0)
                    {
                        var data = new AjaxResponse(-1, "发票消费类别错误!");
                        return this.Json(data);
                    }
                    else if (string.IsNullOrWhiteSpace(invoiceInfo.InvoiceTitle))
                    {
                        var data = new AjaxResponse(-1, "发票抬头为空!");
                        return this.Json(data);
                    }
                    else if (invoiceInfo.InvoiceCost < 0)
                    {
                        var data = new AjaxResponse(-1, "开票金额不能小于或等于0!");
                        return this.Json(data);
                    }

                    invoice = DataTransfer.Transfer<Order_Invoice>(invoiceInfo, typeof(OrderInvoiceModel));
                }

                DateTime createTime;
                var orderCode = MadeCodeService.GetOrderCode(out createTime);

                var orderService = new OrderService(this.SystemUserSession.EmployeeID);
                var order = new Order
                                {
                                    UserID = userID,
                                    RecieveAddressID = receiveAddressID,
                                    CpsID = 0,
                                    PaymentMethodID = paymentMethodID,
                                    OrderCode = orderCode,
                                    OrderNumber = MadeCodeService.ReverseOrderCode(orderCode, createTime),
                                    TotalMoney = 0,
                                    TotalIntegral = 0,
                                    PaymentStatus = 0,
                                    IsRequireInvoice = isRequireInvoice,
                                    Status = paymentMethodID == 0 ? 100 : 0,
                                    Description = string.IsNullOrWhiteSpace(description) ? "后台添加订单" : description,
                                    CreateTime = createTime
                                };

                var orderProducts = new List<Order_Product>();

                foreach (var productModel in products)
                {
                    if (productModel.Quantity > 0)
                    {
                        orderProducts.Add(
                            new Order_Product
                                {
                                    ProductID = productModel.ID,
                                    Quantity = productModel.Quantity,
                                    ProductName = productModel.Name,
                                    TransactPrice = productModel.GoujiuPrice,
                                    CreateTime = DateTime.Now
                                });
                    }
                }

                // 判断是否能够由系统自动确认订单,若能,则自动确认。
                orderService.Add(order, orderProducts, invoice);

                if (orderService.ValidateConfirmOrderBySystem(order))
                {
                    orderService.ConfirmOrderBySystem(order);
                }

                return this.Json(new AjaxResponse(1, "执行成功"));
            }
            catch (Exception exception)
            {
                var data = new AjaxResponse(-1, exception.Message);
                TextLogger.Instance.Log("后台添加订单发生错误", Category.Error, exception);
                return this.Json(data);
            }
        }
        /// <summary>
        /// The cancel order with refund.
        /// </summary>
        /// <param name="orderCancelCauseID">
        /// The order Cancel Cause ID.
        /// </param>
        /// <param name="orderCancelDescription">
        /// The order Cancel Description.
        /// </param>
        /// <param name="refundModel">
        /// The refund model.
        /// </param>
        /// <returns>
        /// The <see cref="ActionResult"/>.
        /// </returns>
        public ActionResult CancelOrderRefund(int orderCancelCauseID, string Description, AftersaleRefundModel refundModel, int type)
        {
            if (type == 0)
            {
                return
                    this.CancelOrder(
                        new OrderCancelModel()
                            {
                                OrderID = refundModel.OrderID,
                                OrderCancelCauseID = orderCancelCauseID,
                                Description = Description
                            });
            }

            var response = new AjaxResponse();
            if (orderCancelCauseID < 1 || refundModel == null || refundModel.OrderID < 1
                || refundModel.ActualRefundMoney < 0 || refundModel.RefundMethodID < 1)
            {
                response.State = -1;
                response.Message = "参数错误";
                return this.Json(response, JsonRequestBehavior.AllowGet);
            }

            var orderService = new OrderService(this.SystemUserSession.EmployeeID);

            var actualPayment = orderService.GetOrderActualPayment(refundModel.OrderID);
            if (refundModel.ActualRefundMoney > actualPayment)
            {
                response.State = -2;
                response.Message = "退款金额不能大于已支付金额";
                return this.Json(response, JsonRequestBehavior.AllowGet);
            }

            try
            {
                refundModel.EmployeeID = this.SystemUserSession.EmployeeID;
                int state = orderService.OrderCancelRefundByBackstage(
                    orderCancelCauseID,
                    Description,
                    DataTransfer.Transfer<Aftersale_Refund>(refundModel, typeof(AftersaleRefundModel)));

                // 0-订单状态异常,1-操作成功,2-已发货,3-订单已取消、损失或者作废,4-订单未付款
                if (state == 0)
                {
                    response.State = 0;
                    response.Message = "订单状态异常";
                }
                else if (state == 1)
                {
                    response.State = 1;
                    response.Message = "订单取消成功";
                }
                else if (state == 2)
                {
                    response.State = 2;
                    response.Message = "已发货,操作取消";
                }
                else if (state == 3)
                {
                    response.State = 3;
                    response.Message = "订单已取消、已损失或者已作废";
                }
                else if (state == 4)
                {
                    response.State = 4;
                    response.Message = "订单未付款";
                }

                return this.Json(response, JsonRequestBehavior.AllowGet);
            }
            catch (Exception exception)
            {
                TextLogger.Instance.Log("订单取消操作发生错误", Category.Error, exception);

                response.State = -2;
                response.Message = exception.Message;
                return this.Json(response, JsonRequestBehavior.AllowGet);
            }
        }