/// <summary>
 /// 设置门店标签
 /// </summary>
 /// <param name="shopIds"></param>
 /// <param name="tagIds"></param>
 /// <returns></returns>
 public JsonResult SetShopBranchTags(string shopIds, string tagIds)
 {
     try
     {
         string[] strs1 = shopIds.Split(new char[1]
         {
             ','
         }, StringSplitOptions.RemoveEmptyEntries);
         string[] strArray;
         if (!string.IsNullOrEmpty(tagIds))
         {
             strArray = tagIds.Split(new char[1]
             {
                 ','
             }, StringSplitOptions.RemoveEmptyEntries);
         }
         else
         {
             strArray = new string[0];
         }
         string[] strs2 = strArray;
         ShopBranchApplication.SetShopBrandTagInfos(this.convertLongs(strs1), this.convertLongs(strs2));
         return(this.Json((object)new
         {
             success = true
         }));
     }
     catch (Exception ex)
     {
         return(this.Json((object)new
         {
             success = false,
             msg = ex.Message
         }));
     }
 }
Beispiel #2
0
        /// <summary>
        /// 获取周边门店
        /// </summary>
        /// <param name="fromLatLng"></param>
        /// <param name="shopId"></param>
        /// <param name="pageNo"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public object GetStoreList(
            string fromLatLng = "", /* 用户当前位置经纬度 */
            string shopId     = "", /* 诊所ID */
            int pageNo        = 1,  /*页码*/
            int pageSize      = 10  /*每页显示数据量*/
            )
        {
            ShopBranchQuery query = new ShopBranchQuery();

            query.PageNo     = pageNo;
            query.PageSize   = pageSize;
            query.Status     = ShopBranchStatus.Normal;
            query.CityId     = -1;
            query.FromLatLng = fromLatLng;
            query.OrderKey   = 2;
            query.OrderType  = true;
            if (query.FromLatLng.Split(',').Length != 2)
            {
                return(Json(new { Success = false, Message = "无法获取您的当前位置,请确认是否开启定位服务!" }));
            }

            if (!string.IsNullOrWhiteSpace(shopId))//如果传入了诊所ID,则只取诊所下门店
            {
                query.ShopId = TypeHelper.ObjectToInt(shopId, 0);
                if (query.ShopId <= 0)
                {
                    return(Json(new { Success = false, Message = "无法定位到诊所!" }));
                }
            }
            else//否则取用户同城门店
            {
                string address = "", province = "", city = "", district = "", street = "";
                ShopbranchHelper.GetAddressByLatLng(query.FromLatLng, ref address, ref province, ref city, ref district, ref street);
                if (string.IsNullOrWhiteSpace(city))
                {
                    return(Json(new { Success = false, Message = "无法定位到城市!" }));
                }

                Region cityInfo = RegionApplication.GetRegionByName(city, Region.RegionLevel.City);
                if (cityInfo != null)
                {
                    query.CityId = cityInfo.Id;
                }
            }
            var shopBranchs = ShopBranchApplication.GetNearShopBranchs(query);
            var storelist   = shopBranchs.Models.ToList().Select(item =>
            {
                return(new
                {
                    Id = item.Id,
                    Latitude = item.Latitude,
                    Longitude = item.Longitude,
                    DistanceUnit = item.DistanceUnit,
                    ShopBranchName = item.ShopBranchName,
                    ContactPhone = item.ContactPhone,
                    AddressDetail = item.AddressDetail
                });
            });
            var result = new
            {
                Success   = true,
                Storelist = storelist,
                total     = shopBranchs.Total
            };

            return(Json(result));
        }
Beispiel #3
0
 public ActionResult Add(ShopBranch shopBranch)
 {
     try
     {
         long num;
         if (!string.Equals(shopBranch.PasswordOne, shopBranch.PasswordTwo))
         {
             throw new HimallException("两次密码输入不一致!");
         }
         if (string.IsNullOrWhiteSpace(shopBranch.PasswordOne) || string.IsNullOrWhiteSpace(shopBranch.PasswordTwo))
         {
             throw new HimallException("密码不能为空!");
         }
         if (shopBranch.ShopBranchName.Length > 15)
         {
             throw new HimallException("门店名称不能超过15个字!");
         }
         if (shopBranch.AddressDetail.Length > 50)
         {
             throw new HimallException("详细地址不能超过50个字!");
         }
         if ((shopBranch.Latitude <= 0f) || (shopBranch.Longitude <= 0f))
         {
             throw new HimallException("请搜索地址地图定位!");
         }
         shopBranch.ShopId     = base.CurrentSellerManager.ShopId;
         shopBranch.CreateDate = DateTime.Now;
         ShopBranchApplication.AddShopBranch(shopBranch, out num);
         try
         {
             string[] strs      = new string[] { num.ToString() };
             string[] strArray2 = string.IsNullOrEmpty(shopBranch.ShopBranchTagId) ? new string[0] : shopBranch.ShopBranchTagId.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
             ShopBranchApplication.SetShopBrandTagInfos(this.convertLongs(strs), this.convertLongs(strArray2));
         }
         catch
         {
         }
         List <ShopBranchTagModel> allShopBranchTagInfos = ShopBranchApplication.GetAllShopBranchTagInfos();
         List <SelectListItem>     list2 = new List <SelectListItem>();
         foreach (ShopBranchTagModel model in allShopBranchTagInfos)
         {
             SelectListItem item = new SelectListItem
             {
                 Selected = (shopBranch.ShopBranchTagId == null) ? false : (shopBranch.ShopBranchTagId.Split(new char[] { ',' }).Contains <string>(model.Id.ToString()) ? true : false),
                 Value    = model.Id.ToString(),
                 Text     = model.Title
             };
             list2.Add(item);
         }
         ((dynamic)base.ViewBag).ShopBranchTags = list2;
     }
     catch (Exception exception)
     {
         BaseController.Result result = new BaseController.Result
         {
             success = false,
             msg     = exception.Message
         };
         return(base.Json(result));
     }
     BaseController.Result data = new BaseController.Result
     {
         success = true
     };
     return(base.Json(data));
 }
 public JsonResult EditTag(long id, string title)
 {
     ShopBranchApplication.UpdateShopBranchTagInfo(id, title);
     return(Json(new { success = true }));
 }
        public ActionResult Management(long?shopBranchTagId)
        {
            var shopBranchTagInfos        = ShopBranchApplication.GetAllShopBranchTagInfos();
            List <SelectListItem> tagList = new List <SelectListItem>()
            {
                new SelectListItem
                {
                    Selected = true,
                    Value    = 0.ToString(),
                    Text     = "请选择..."
                }
            };

            foreach (var item in shopBranchTagInfos)
            {
                tagList.Add(new SelectListItem
                {
                    Selected = false,
                    Value    = item.Id.ToString(),
                    Text     = item.Title
                });
            }

            if (shopBranchTagId.HasValue)
            {
                var item = tagList.FirstOrDefault(t => t.Value == shopBranchTagId.ToString());
                if (item != null)
                {
                    item.Selected = true;
                }
            }

            ViewBag.ShopBranchTags = tagList;


            var shops = EngineContext.Current.Resolve <IShopService>().GetAllShops();

            List <SelectListItem> shopList = new List <SelectListItem> {
                new SelectListItem
                {
                    Selected = true,
                    Value    = 0.ToString(),
                    Text     = "请选择..."
                }
            };

            foreach (var item in shops)
            {
                if (!string.IsNullOrEmpty(item.ShopName))
                {
                    shopList.Add(new SelectListItem
                    {
                        Selected = false,
                        Value    = item.Id.ToString(),
                        Text     = item.ShopName
                    });
                }
            }

            ViewBag.Shops = shopList;

            return(View());
        }
        public object GetShopBranchHome()
        {
            try
            {
                CheckUserLogin();

                var now = DateTime.Now;

                var orderQuery = new OrderCountStatisticsQuery()
                {
                    ShopBranchId = CurrentShopBranch.Id,
                    Fields       = new List <OrderCountStatisticsFields> {
                        OrderCountStatisticsFields.ActualPayAmount
                    }
                };
                //三月内
                orderQuery.OrderDateBegin = new DateTime(now.Year, now.Month, 1).AddMonths(-2);
                var threeMonthAmount = StatisticApplication.GetOrderCount(orderQuery).TotalActualPayAmount;
                //本周
                orderQuery.OrderDateBegin = now.Date.AddDays(-(int)now.DayOfWeek);
                var weekAmount = StatisticApplication.GetOrderCount(orderQuery).TotalActualPayAmount;
                //今天
                orderQuery.OrderDateBegin = now.Date;
                var todayAmount = StatisticApplication.GetOrderCount(orderQuery).TotalActualPayAmount;


                //待自提订单数
                orderQuery = new OrderCountStatisticsQuery()
                {
                    ShopBranchId       = CurrentShopBranch.Id,
                    OrderOperateStatus = Entities.OrderInfo.OrderOperateStatus.WaitSelfPickUp,
                    Fields             = new List <OrderCountStatisticsFields> {
                        OrderCountStatisticsFields.OrderCount
                    }
                };
                var pickUpOrderCount = StatisticApplication.GetOrderCount(orderQuery).OrderCount;

                //近三天发布商品数
                var productCount = ProductManagerApplication.GetProductCount(new ProductQuery
                {
                    ShopBranchId = CurrentShopBranch.Id,
                    AuditStatus  = new[] { Entities.ProductInfo.ProductAuditStatus.Audited },
                    StartDate    = now.Date.AddDays(-2)
                });


                var vshop = ServiceProvider.Instance <IVShopService> .Create.GetVShopByShopId(CurrentShopBranch.ShopId);

                var logo = "/Images/branchapp.jpg";
                if (vshop != null && vshop.State == Entities.VShopInfo.VShopStates.Normal && !string.IsNullOrEmpty(vshop.WXLogo))
                {
                    logo = vshop.WXLogo;
                }
                var shopBranch       = ShopBranchApplication.GetShopBranchById(CurrentShopBranch.Id);
                var isShelvesProduct = false;
                if (shopBranch != null && shopBranch.Status == ShopBranchStatus.Normal)
                {
                    isShelvesProduct = shopBranch.IsShelvesProduct;
                }
                return(new
                {
                    success = true,
                    data = new
                    {
                        shopName = CurrentShopBranch.ShopBranchName,
                        todayAmount = todayAmount,
                        weekAmount = weekAmount,
                        threeMonthAmounht = threeMonthAmount,
                        createProductCount = productCount,
                        pickUpOrderCount = pickUpOrderCount,
                        logo = logo,
                        shopBranchId = CurrentShopBranch.Id,
                        IsShelvesProduct = isShelvesProduct
                    }
                });
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
                return(new { success = false, data = new { } });
            }
        }
        public object GetShopBranchs(long shopId, bool getParent, string skuIds, string counts, int page, int rows, long shippingAddressId, long regionId)
        {
            string[] _skuIds = skuIds.Split(',');
            int[] _counts = counts.Split(',').Select(p => Mall.Core.Helper.TypeHelper.ObjectToInt(p)).ToArray();

            var shippingAddressInfo = ShippingAddressApplication.GetUserShippingAddress(shippingAddressId);
            int streetId = 0, districtId = 0;//收货地址的街道、区域

            var query = new ShopBranchQuery()
            {
                ShopId = shopId,
                PageNo = page,
                PageSize = rows,
                Status = CommonModel.ShopBranchStatus.Normal,
                ShopBranchProductStatus = ShopBranchSkuStatus.Normal
            };
            if (shippingAddressInfo != null)
            {
                query.FromLatLng = string.Format("{0},{1}", shippingAddressInfo.Latitude, shippingAddressInfo.Longitude);//需要收货地址的经纬度
                streetId = shippingAddressInfo.RegionId;
                var parentAreaInfo = RegionApplication.GetRegion(shippingAddressInfo.RegionId, Region.RegionLevel.Town);//判断当前区域是否为第四级
                if (parentAreaInfo != null && parentAreaInfo.ParentId > 0) districtId = parentAreaInfo.ParentId;
                else { districtId = streetId; streetId = 0; }
            }
            bool hasLatLng = false;
            if (!string.IsNullOrWhiteSpace(query.FromLatLng)) hasLatLng = query.FromLatLng.Split(',').Length == 2;

            var region = RegionApplication.GetRegion(regionId, getParent ? CommonModel.Region.RegionLevel.City : CommonModel.Region.RegionLevel.County);//同城内门店
            if (region != null) query.AddressPath = region.GetIdPath();

            #region 3.0版本排序规则
            var skuInfos = ProductManagerApplication.GetSKUs(_skuIds);
            query.ProductIds = skuInfos.Select(p => p.ProductId).ToArray();
            var data = ShopBranchApplication.GetShopBranchsAll(query);
            var shopBranchSkus = ShopBranchApplication.GetSkus(shopId, data.Models.Select(p => p.Id).ToList());//获取该商家下具有订单内所有商品的门店状态正常数据,不考虑库存
            data.Models.ForEach(p =>
            {
                p.Enabled = skuInfos.All(skuInfo => shopBranchSkus.Any(sbSku => sbSku.ShopBranchId == p.Id && sbSku.Stock >= _counts[skuInfos.IndexOf(skuInfo)] && sbSku.SkuId == skuInfo.Id));
            });

            List<Mall.DTO.ShopBranch> newList = new List<Mall.DTO.ShopBranch>();
            List<long> fillterIds = new List<long>();
            var currentList = data.Models.Where(p => hasLatLng && p.Enabled && (p.Latitude > 0 && p.Longitude > 0)).OrderBy(p => p.Distance).ToList();
            if (currentList != null && currentList.Count() > 0)
            {
                fillterIds.AddRange(currentList.Select(p => p.Id));
                newList.AddRange(currentList);
            }
            var currentList2 = data.Models.Where(p => !fillterIds.Contains(p.Id) && p.Enabled && p.AddressPath.Contains(CommonConst.ADDRESS_PATH_SPLIT + streetId + CommonConst.ADDRESS_PATH_SPLIT)).ToList();
            if (currentList2 != null && currentList2.Count() > 0)
            {
                fillterIds.AddRange(currentList2.Select(p => p.Id));
                newList.AddRange(currentList2);
            }
            var currentList3 = data.Models.Where(p => !fillterIds.Contains(p.Id) && p.Enabled && p.AddressPath.Contains(CommonConst.ADDRESS_PATH_SPLIT + districtId + CommonConst.ADDRESS_PATH_SPLIT)).ToList();
            if (currentList3 != null && currentList3.Count() > 0)
            {
                fillterIds.AddRange(currentList3.Select(p => p.Id));
                newList.AddRange(currentList3);
            }
            var currentList4 = data.Models.Where(p => !fillterIds.Contains(p.Id) && p.Enabled).ToList();//非同街、非同区,但一定会同市
            if (currentList4 != null && currentList4.Count() > 0)
            {
                fillterIds.AddRange(currentList4.Select(p => p.Id));
                newList.AddRange(currentList4);
            }
            var currentList5 = data.Models.Where(p => !fillterIds.Contains(p.Id)).ToList();//库存不足的排最后
            if (currentList5 != null && currentList5.Count() > 0)
            {
                newList.AddRange(currentList5);
            }
            if (newList.Count() != data.Models.Count())//如果新组合的数据与原数据数量不一致
            {
                return new
                {
                    success = false
                };
            }
            var needDistance = false;
            if (shippingAddressInfo != null && shippingAddressInfo.Latitude!=0 && shippingAddressInfo.Longitude!=0)
            {
                needDistance = true;
            }
            var storeList = newList.Select(sb =>
            {
                return new
                {
                    ContactUser = sb.ContactUser,
                    ContactPhone = sb.ContactPhone,
                    AddressDetail = sb.AddressDetail,
                    ShopBranchName = sb.ShopBranchName,
                    Id = sb.Id,
                    Enabled = sb.Enabled,
                    Distance = needDistance ? RegionApplication.GetDistance(sb.Latitude, sb.Longitude, shippingAddressInfo.Latitude, shippingAddressInfo.Longitude) : 0
                };
            });

            #endregion

            var result = new
            {
                success = true,
                StoreList = storeList
            };
            return result;
        }
        public object GetOrderDetail(long id)
        {
            CheckUserLogin();
            long shopid = CurrentUser.ShopId;

            var ordser = ServiceProvider.Instance <IOrderService> .Create;

            OrderInfo order = ordser.GetOrder(id);

            if (order == null || order.ShopId != shopid)
            {
                throw new HimallApiException("错误的预约单编号");
            }
            var bonusService       = ServiceProvider.Instance <IShopBonusService> .Create;
            var orderRefundService = ServiceProvider.Instance <IRefundService> .Create;
            var shopService        = ServiceProvider.Instance <IShopService> .Create;
            var productService     = ServiceProvider.Instance <IProductService> .Create;
            var vshop = ServiceProvider.Instance <IVShopService> .Create.GetVShopByShopId(order.ShopId);

            bool isCanApply = false;

            DTO.ShopBranch ShopBranchInfo = null;
            if (order.ShopBranchId.HasValue && order.ShopBranchId.Value > 0)
            {
                ShopBranchInfo = ShopBranchApplication.GetShopBranchById(order.ShopBranchId.Value);
            }
            //获取预约单诊疗项目项数据
            var orderDetail = new
            {
                ShopName   = shopService.GetShop(order.ShopId).ShopName,
                ShopId     = order.ShopId,
                OrderItems = order.OrderItemInfo.Select(item =>
                {
                    var productinfo = productService.GetProduct(item.ProductId);
                    if (order.OrderStatus == OrderInfo.OrderOperateStatus.WaitDelivery)
                    {
                        isCanApply = orderRefundService.CanApplyRefund(id, item.Id);
                    }
                    else
                    {
                        isCanApply = orderRefundService.CanApplyRefund(id, item.Id, false);
                    }

                    ProductTypeInfo typeInfo = ServiceProvider.Instance <ITypeService> .Create.GetType(productinfo.TypeId);
                    string colorAlias        = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
                    string sizeAlias         = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
                    string versionAlias      = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
                    return(new
                    {
                        ItemId = item.Id,
                        ProductId = item.ProductId,
                        ProductName = item.ProductName,
                        Count = item.Quantity,
                        Price = item.SalePrice,
                        //ProductImage = "http://" + Url.Request.RequestUri.Host + productService.GetProduct(item.ProductId).GetImage(ProductInfo.ImageSize.Size_100),
                        ProductImage = Core.HimallIO.GetRomoteProductSizeImage(productService.GetProduct(item.ProductId).RelativePath, 1, (int)Himall.CommonModel.ImageSize.Size_100),
                        color = item.Color,
                        size = item.Size,
                        version = item.Version,
                        IsCanRefund = isCanApply,
                        ColorAlias = colorAlias,
                        SizeAlias = sizeAlias,
                        VersionAlias = versionAlias
                    });
                })
            };
            var orderModel = new
            {
                Id                 = order.Id,
                OrderType          = order.OrderType,
                OrderTypeName      = order.OrderType.ToDescription(),
                Status             = order.OrderStatus.ToDescription(),
                ShipTo             = order.ShipTo,
                Phone              = order.CellPhone,
                Address            = order.RegionFullName + " " + order.Address,
                HasExpressStatus   = !string.IsNullOrWhiteSpace(order.ShipOrderNumber),
                ExpressCompanyName = order.ExpressCompanyName,
                Freight            = order.Freight,
                IntegralDiscount   = order.IntegralDiscount,
                RealTotalAmount    = order.OrderTotalAmount - order.RefundTotalAmount,
                OrderDate          = order.OrderDate.ToString("yyyy-MM-dd HH:mm:ss"),
                ShopName           = order.ShopName,
                ShopBranchName     = (ShopBranchInfo != null ? ShopBranchInfo.ShopBranchName : ""),
                VShopId            = vshop == null ? 0 : vshop.Id,
                commentCount       = order.OrderCommentInfo.Count(),
                ShopId             = order.ShopId,
                orderStatus        = (int)order.OrderStatus,
                Invoice            = order.InvoiceType.ToDescription(),
                InvoiceValue       = (int)order.InvoiceType,
                InvoiceContext     = order.InvoiceContext,
                InvoiceTitle       = order.InvoiceTitle,
                PaymentType        = order.PaymentType.ToDescription(),
                PaymentTypeValue   = (int)order.PaymentType,
                FullDiscount       = order.FullDiscount,
                DiscountAmount     = order.DiscountAmount,
                OrderRemarks       = order.OrderRemarks,
                DeliveryType       = order.DeliveryType
            };

            return(Json(new { Success = "true", Order = orderModel, OrderItem = orderDetail.OrderItems }));
        }
        public ActionResult Detail(long id)
        {
            OrderInfo order = _iOrderService.GetOrder(id, CurrentUser.Id);//限制到用户
            //补充诊疗项目货号
            IEnumerable <long> proids = order.OrderItemInfo.Select(d => d.ProductId).AsEnumerable();
            var procodelist           = _iProductService.GetProductByIds(proids).Select(d => new { d.Id, d.ProductCode, d.FreightTemplateId }).ToList();
            var orderiItems           = order.OrderItemInfo.ToList();

            foreach (var item in orderiItems)
            {
                var _tmp = procodelist.Find(d => d.Id == item.ProductId);
                if (_tmp != null)
                {
                    item.ProductCode = _tmp.ProductCode;
                    item.FreightId   = _tmp.FreightTemplateId;
                }
            }
            var service       = Himall.Web.Framework.ServiceHelper.Create <Himall.IServices.IProductService>();
            var regionService = Himall.Web.Framework.ServiceHelper.Create <Himall.IServices.IRegionService>();
            //  string RegionIdPath = regionService.GetRegionPath(order.RegionId);
            int cityId = regionService.GetRegion(order.RegionId).Id;
            var freightProductGroup = orderiItems.GroupBy(a => a.FreightId);

            if (order.DeliveryType != CommonModel.Enum.DeliveryType.SelfTake)
            {
                foreach (var f in freightProductGroup)
                {
                    var     productIds = f.Select(a => a.ProductId);
                    var     counts     = f.Select(a => Convert.ToInt32(a.Quantity));
                    decimal freight    = service.GetFreight(productIds, counts, cityId);

                    foreach (var item in f)
                    {
                        item.Freight = freight;
                    }
                }
            }

            ViewBag.freightProductGroup = freightProductGroup;

            ViewBag.Coupon = 0;
            var coupon = _iCouponService.GetCouponRecordInfo(order.UserId, order.Id);
            var bonus  = _iShopBonusService.GetUsedPrice(order.Id, order.UserId);

            if (coupon != null)
            {
                ViewBag.Coupon = coupon.Himall_Coupon.Price;
            }
            else if (bonus != null)
            {
                ViewBag.Coupon = bonus;
            }

            if (order.OrderType == OrderInfo.OrderTypes.FightGroup)
            {
                var fgord = _iFightGroupService.GetFightGroupOrderStatusByOrderId(order.Id);
                order.FightGroupOrderJoinStatus = fgord.GetJoinStatus;
                order.FightGroupCanRefund       = fgord.CanRefund;
            }
            //使用OrderListModel
            AutoMapper.Mapper.CreateMap <OrderInfo, OrderListModel>();
            AutoMapper.Mapper.CreateMap <OrderItemInfo, OrderItemListModel>();
            var orderModel = AutoMapper.Mapper.Map <OrderInfo, OrderListModel>(order);

            orderModel.OrderItemList = AutoMapper.Mapper.Map <IEnumerable <OrderItemInfo>, IEnumerable <OrderItemListModel> >(order.OrderItemInfo);
            if (order.ShopBranchId.HasValue && order.ShopBranchId.Value != 0)
            {//补充数据
                var branch = ShopBranchApplication.GetShopBranchById(order.ShopBranchId.Value);
                if (branch != null)
                {
                    orderModel.ShopBranchName         = branch.ShopBranchName;
                    orderModel.ShopBranchAddress      = branch.AddressFullName;
                    orderModel.ShopBranchContactPhone = branch.ContactPhone;
                }
            }
            if (order.FightGroupOrderJoinStatus.HasValue)
            {
                orderModel.FightGroupJoinStatus = order.FightGroupOrderJoinStatus.Value;
            }
            orderModel.UserRemark = order.OrderRemarks;
            return(View(orderModel));
        }
        /// <summary>
        /// 退款申请
        /// </summary>
        /// <param name="id"></param>
        /// <param name="itemId"></param>
        /// <returns></returns>
        public ActionResult RefundApply(long orderid, long?itemId, long?refundid)
        {
            RefundApplyModel model = new RefundApplyModel();

            model.RefundMode  = null;
            model.OrderItemId = null;
            var order = _iOrderService.GetOrder(orderid, CurrentUser.Id);

            if (order == null)
            {
                throw new Himall.Core.HimallException("该预约单已删除或不属于该用户");
            }
            if ((int)order.OrderStatus < 2)
            {
                throw new Himall.Core.HimallException("错误的售后申请,预约单状态有误");
            }
            if (itemId == null && order.OrderStatus != OrderInfo.OrderOperateStatus.WaitDelivery && order.OrderStatus != OrderInfo.OrderOperateStatus.WaitSelfPickUp)
            {
                throw new Himall.Core.HimallException("错误的预约单退款申请,预约单状态有误");
            }
            //售后时间限制
            if (_iOrderService.IsRefundTimeOut(orderid))
            {
                throw new Himall.Core.HimallException("预约单已超过售后期");
            }


            //计算可退金额 预留
            _iOrderService.CalculateOrderItemRefund(orderid);

            OrderItemInfo item = new OrderItemInfo();

            model.MaxRefundGoodsNumber = 0;
            model.MaxRefundAmount      = order.OrderEnabledRefundAmount;
            if (itemId == null)
            {
                model.OrderItems = order.OrderItemInfo.ToList();
                if (model.OrderItems.Count == 1)
                {
                    item = model.OrderItems.FirstOrDefault();
                }
            }
            else
            {
                item = order.OrderItemInfo.Where(a => a.Id == itemId).FirstOrDefault();
                model.OrderItems.Add(item);
                model.MaxRefundGoodsNumber = item.Quantity - item.ReturnQuantity;
                model.MaxRefundAmount      = item.EnabledRefundAmount - item.RefundPrice;
            }
            foreach (var orderItem in model.OrderItems)
            {
                ProductTypeInfo typeInfo = _iTypeService.GetTypeByProductId(orderItem.ProductId);
                orderItem.ColorAlias   = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
                orderItem.SizeAlias    = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
                orderItem.VersionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
            }
            if (!model.MaxRefundAmount.HasValue)
            {
                model.MaxRefundAmount = 0;
            }
            bool            isCanApply = false;
            var             refundser  = _iRefundService;
            OrderRefundInfo refunddata;

            if (order.OrderStatus == OrderInfo.OrderOperateStatus.WaitDelivery)
            {
                isCanApply = refundser.CanApplyRefund(orderid, item.Id);
            }
            else
            {
                isCanApply = refundser.CanApplyRefund(orderid, item.Id, false);
            }
            if (!refundid.HasValue)
            {
                if (!isCanApply)
                {
                    var orderRefunds = OrderApplication.GetOrderRefunds(new long[] { item.Id });
                    if (orderRefunds.Count == 1)
                    {
                        Response.Redirect("/OrderRefund/Detail/" + orderRefunds[0].Id);
                    }

                    throw new Himall.Core.HimallException("您已申请过售后,不可重复申请");
                }

                model.ContactPerson    = CurrentUser.RealName;
                model.ContactCellPhone = CurrentUser.CellPhone;
                model.OrderItemId      = itemId;
                if (!model.OrderItemId.HasValue)
                {
                    model.IsOrderAllRefund = true;
                    model.RefundMode       = OrderRefundInfo.OrderRefundMode.OrderRefund;
                }
            }
            else
            {
                refunddata = refundser.GetOrderRefund(refundid.Value, CurrentUser.Id);
                if (refunddata == null)
                {
                    throw new Himall.Core.HimallException("错误的售后数据");
                }
                if (refunddata.SellerAuditStatus != OrderRefundInfo.OrderRefundAuditStatus.UnAudit)
                {
                    throw new Himall.Core.HimallException("错误的售后状态,不可激活");
                }
                model.ContactPerson      = refunddata.ContactPerson;
                model.ContactCellPhone   = refunddata.ContactCellPhone;
                model.OrderItemId        = refunddata.OrderItemId;
                model.IsOrderAllRefund   = (refunddata.RefundMode == OrderRefundInfo.OrderRefundMode.OrderRefund);
                model.RefundMode         = refunddata.RefundMode;
                model.RefundReasonValue  = refunddata.Reason;
                model.RefundReasonDetail = refunddata.ReasonDetail;
                model.RefundWayValue     = refunddata.RefundPayType;
                model.CertPic1           = refunddata.CertPic1;
                model.CertPic2           = refunddata.CertPic2;
                model.CertPic3           = refunddata.CertPic3;
            }
            if (!model.IsOrderAllRefund && item.EnabledRefundAmount.HasValue)
            {
                model.RefundGoodsPrice = item.EnabledRefundAmount.Value / item.Quantity;
            }
            model.OrderInfo = order;
            model.OrderId   = orderid;
            model.RefundId  = refundid;

            var reasons = refundser.GetRefundReasons();

            foreach (var _ir in reasons)
            {
                _ir.AfterSalesText = _ir.AfterSalesText.Trim();
            }
            List <SelectListItem> reasel = new List <SelectListItem>();
            SelectListItem        _tmpsel;

            _tmpsel = new SelectListItem {
                Text = "选择售后原因", Value = ""
            };
            reasel.Add(_tmpsel);
            foreach (var _i in reasons)
            {
                _tmpsel = new SelectListItem {
                    Text = _i.AfterSalesText, Value = _i.AfterSalesText
                };
                if (!string.IsNullOrWhiteSpace(model.RefundReasonValue))
                {
                    if (_i.AfterSalesText == model.RefundReasonValue)
                    {
                        _tmpsel.Selected = true;
                    }
                }
                reasel.Add(_tmpsel);
            }
            model.RefundReasons = reasel;

            List <SelectListItem> list = new List <SelectListItem> {
                new SelectListItem {
                    Text  = OrderRefundInfo.OrderRefundPayType.BackCapital.ToDescription(),
                    Value = ((int)OrderRefundInfo.OrderRefundPayType.BackCapital).ToString()
                }
            };

            if (order.CanBackOut())
            {
                _tmpsel = new SelectListItem
                {
                    Text  = OrderRefundInfo.OrderRefundPayType.BackOut.ToDescription(),
                    Value = ((int)OrderRefundInfo.OrderRefundPayType.BackOut).ToString()
                };
                //if (model.RefundWayValue.HasValue)
                //{
                //    if (_tmpsel.Value == model.RefundWayValue.ToString())
                //    {
                //        _tmpsel.Selected = true;
                //    }
                //}
                _tmpsel.Selected = true;  //若预约单支付方式为支付宝、微信支付则退款方式默认选中“退款原路返回”
                list.Add(_tmpsel);
            }
            model.RefundWay = list;

            if (order.DeliveryType == CommonModel.Enum.DeliveryType.SelfTake)
            {
                var shopBranch = ShopBranchApplication.GetShopBranchById(order.ShopBranchId.Value);
                model.ReturnGoodsAddress  = RegionApplication.GetFullName(shopBranch.AddressId);
                model.ReturnGoodsAddress += " " + shopBranch.AddressDetail;
                model.ReturnGoodsAddress += " " + shopBranch.ContactPhone;
            }

            return(View(model));
        }
        /// <summary>
        /// 显示售后记录
        /// </summary>
        /// <param name="applyDate"></param>
        /// <param name="auditStatus"></param>
        /// <param name="pageNo"></param>
        /// <param name="pageSize"></param>
        /// <param name="showtype">0 所有 1 订单退款 2 仅退款(包含订单退款) 3 退货 4 仅退款</param>
        /// <returns></returns>
        public JsonResult List(int pageNo = 1, int pageSize = 10)
        {
            DateTime?startDate = null;
            DateTime?endDate   = null;

            var queryModel = new RefundQuery()
            {
                StartDate      = startDate,
                EndDate        = endDate,
                UserId         = CurrentUser.Id,
                PageSize       = pageSize,
                PageNo         = pageNo,
                ShowRefundType = 0
            };
            var refunds = _iRefundService.GetOrderRefunds(queryModel);
            var list    = refunds.Models.Select(item =>
            {
                var vshop = _iVShopService.GetVShopByShopId(item.ShopId) ?? new Entities.VShopInfo()
                {
                    Id = 0
                };
                bool IsSelfTake = false;
                var order       = _iOrderService.GetOrder(item.OrderId, CurrentUser.Id);
                if (order.DeliveryType == CommonModel.DeliveryType.SelfTake)
                {
                    IsSelfTake = true;
                }
                var status = string.Empty;
                if (IsSelfTake || order.ShopBranchId > 0)//分配门店订单与自提订单一致
                {
                    status = item.RefundStatus.Replace("商家", "门店");
                }
                var shopBranch = ShopBranchApplication.GetShopBranchById(order.ShopBranchId);
                var branchName = shopBranch == null ? "" : shopBranch.ShopBranchName;
                var orderItem  = OrderApplication.GetOrderItem(item.OrderItemId);
                var orderItems = new List <Entities.OrderItemInfo>();
                if (item.RefundMode == OrderRefundInfo.OrderRefundMode.OrderRefund)
                {
                    orderItems = _iOrderService.GetOrderItemsByOrderId(item.OrderId);
                }
                else
                {
                    orderItems.Add(orderItem);
                }
                return(new
                {
                    ShopName = item.ShopName,
                    Vshopid = vshop.Id,
                    ShopBranchId = order.ShopBranchId,
                    ShopBranchName = branchName,
                    RefundStatus = string.IsNullOrEmpty(status) ? item.RefundStatus : status,
                    Id = item.Id,
                    ProductName = orderItem.ProductName,
                    EnabledRefundAmount = item.EnabledRefundAmount,
                    Amount = item.Amount,
                    Img = MallIO.GetProductSizeImage(orderItem.ThumbnailsUrl, 1, (int)ImageSize.Size_100),
                    ShopId = item.ShopId,
                    RefundMode = item.RefundMode,
                    OrderId = item.OrderId,
                    OrderTotal = order.OrderTotalAmount.ToString("f2"),
                    OrderItems = orderItems != null ? orderItems.Select(e => new
                    {
                        ThumbnailsUrl = MallIO.GetProductSizeImage(e.ThumbnailsUrl, 1, (int)ImageSize.Size_100),
                        ProductName = e.ProductName,
                        SkuText = e.Color + " " + e.Size + " " + e.Version,
                    }) : null,
                    SellerAuditStatus = item.SellerAuditStatus
                });
            });

            return(SuccessResult <dynamic>(data: list));
        }
Beispiel #12
0
        public ActionResult Detail(long id)
        {
            var order = _iOrderService.GetOrder(id);

            if (order == null)
            {
                throw new MallException("错误的订单信息");
            }
            if (order.OrderType == Entities.OrderInfo.OrderTypes.FightGroup)
            {
                var fgord = _iFightGroupService.GetFightGroupOrderStatusByOrderId(order.Id);
                order.FightGroupOrderJoinStatus = fgord.GetJoinStatus;
                order.FightGroupCanRefund       = fgord.CanRefund;
            }
            var orderItems = _iOrderService.GetOrderItemsByOrderId(order.Id);
            //处理平台佣金
            var orderRefunds = RefundApplication.GetOrderRefundList(id);

            foreach (var item in orderItems)
            {
                var refund = orderRefunds.Where(e => e.OrderItemId == item.Id).Sum(e => e.ReturnPlatCommission);
                item.PlatCommission = Math.Round(item.CommisRate * (item.RealTotalPrice - item.FullDiscount - item.CouponDiscount), 2);
                if (refund > 0)
                {
                    item.PlatCommission = item.PlatCommission - refund;
                }
                item.PlatCommission = (item.PlatCommission < 0) ? 0 : item.PlatCommission;
            }
            ViewBag.OrderItems = orderItems;
            ViewBag.Logs       = _iOrderService.GetOrderLogs(order.Id);
            ViewBag.Coupon     = 0;
            string shipperAddress = string.Empty, shipperTelPhone = string.Empty;

            #region 门店信息
            if (order.ShopBranchId > 0)
            {
                var shopBranchInfo = ShopBranchApplication.GetShopBranchById(order.ShopBranchId);
                if (shopBranchInfo != null)
                {
                    ViewBag.ShopBranchInfo = shopBranchInfo;
                    if (order.OrderStatus == Entities.OrderInfo.OrderOperateStatus.Finish)
                    {
                        ViewBag.ShopBranchContactUser = shopBranchInfo.UserName;
                    }
                    if (order.OrderType == OrderInfo.OrderTypes.Virtual)
                    {
                        shipperAddress  = RegionApplication.GetFullName(shopBranchInfo.AddressId) + " " + shopBranchInfo.AddressDetail;
                        shipperTelPhone = shopBranchInfo.ContactPhone;
                    }
                }
            }
            #endregion
            if (order.OrderType == OrderInfo.OrderTypes.Virtual)
            {
                ViewBag.VirtualOrderItemInfos      = OrderApplication.GetVirtualOrderItemInfosByOrderId(order.Id);
                ViewBag.OrderVerificationCodeInfos = OrderApplication.GetOrderVerificationCodeInfosByOrderIds(new List <long>()
                {
                    order.Id
                });
                if (order.ShopBranchId == 0)
                {
                    var verificationShipper = ShopShippersApplication.GetDefaultVerificationShipper(order.ShopId);
                    if (verificationShipper != null)
                    {
                        shipperAddress  = RegionApplication.GetFullName(verificationShipper.RegionId) + " " + verificationShipper.Address;
                        shipperTelPhone = verificationShipper.TelPhone;
                    }
                }
            }
            ViewBag.ShipperAddress  = shipperAddress;
            ViewBag.ShipperTelPhone = shipperTelPhone;
            //发票信息
            ViewBag.OrderInvoiceInfo = OrderApplication.GetOrderInvoiceInfo(order.Id);
            //统一显示支付方式名称
            order.PaymentTypeName = PaymentApplication.GetPaymentTypeDescById(order.PaymentTypeGateway) ?? order.PaymentTypeName;
            return(View(order));
        }
Beispiel #13
0
        public JsonResult GetUserOrders(int?orderStatus, int pageNo, int pageSize = 8)
        {
            if (orderStatus.HasValue && orderStatus == 0)
            {
                orderStatus = null;
            }
            var queryModel = new OrderQuery()
            {
                Status   = (Entities.OrderInfo.OrderOperateStatus?)orderStatus,
                UserId   = CurrentUser.Id,
                PageSize = pageSize,
                PageNo   = pageNo,
                IsFront  = true
            };

            if (queryModel.Status.HasValue && queryModel.Status.Value == Entities.OrderInfo.OrderOperateStatus.WaitReceiving)
            {
                if (queryModel.MoreStatus == null)
                {
                    queryModel.MoreStatus = new List <Entities.OrderInfo.OrderOperateStatus>()
                    {
                    };
                }
                queryModel.MoreStatus.Add(Entities.OrderInfo.OrderOperateStatus.WaitSelfPickUp);
            }
            if (orderStatus.GetValueOrDefault() == (int)OrderInfo.OrderOperateStatus.Finish)
            {
                queryModel.Commented = false;//只查询未评价的订单
            }
            var orders        = OrderApplication.GetOrders(queryModel);
            var orderItems    = OrderApplication.GetOrderItemsByOrderId(orders.Models.Select(p => p.Id));
            var orderComments = OrderApplication.GetOrderCommentCount(orders.Models.Select(p => p.Id));
            var orderRefunds  = OrderApplication.GetOrderRefunds(orderItems.Select(p => p.Id));
            var products      = ProductManagerApplication.GetProductsByIds(orderItems.Select(p => p.ProductId));
            var vshops        = VshopApplication.GetVShopsByShopIds(products.Select(p => p.ShopId));
            //查询结果的门店ID
            var branchIds = orders.Models.Where(e => e.ShopBranchId > 0).Select(p => p.ShopBranchId).ToList();
            //根据门店ID获取门店信息
            var shopBranchs            = ShopBranchApplication.GetShopBranchByIds(branchIds);
            var orderVerificationCodes = OrderApplication.GetOrderVerificationCodeInfosByOrderIds(orders.Models.Select(p => p.Id).ToList());
            var result = orders.Models.Select(item =>
            {
                var codes      = orderVerificationCodes.Where(a => a.OrderId == item.Id);
                var _ordrefobj = _iRefundService.GetOrderRefundByOrderId(item.Id) ?? new Entities.OrderRefundInfo {
                    Id = 0
                };
                if (item.OrderStatus != Entities.OrderInfo.OrderOperateStatus.WaitDelivery && item.OrderStatus != Entities.OrderInfo.OrderOperateStatus.WaitSelfPickUp)
                {
                    _ordrefobj = new Entities.OrderRefundInfo {
                        Id = 0
                    };
                }
                int?ordrefstate   = (_ordrefobj == null ? null : (int?)_ordrefobj.SellerAuditStatus);
                ordrefstate       = (ordrefstate > 4 ? (int?)_ordrefobj.ManagerConfirmStatus : ordrefstate);
                var branchObj     = shopBranchs.FirstOrDefault(e => item.ShopBranchId > 0 && e.Id == item.ShopBranchId);
                string branchName = branchObj == null ? string.Empty : branchObj.ShopBranchName;
                return(new
                {
                    id = item.Id,
                    status = item.OrderStatus.ToDescription(),
                    orderStatus = item.OrderStatus,
                    shopname = item.ShopName,
                    orderTotalAmount = item.OrderTotalAmount,
                    capitalAmount = item.CapitalAmount,
                    productCount = orderItems.Where(oi => oi.OrderId == item.Id).Sum(a => a.Quantity),
                    commentCount = orderComments.ContainsKey(item.Id) ? orderComments[item.Id] : 0,
                    PaymentType = item.PaymentType,
                    RefundStats = ordrefstate,
                    OrderRefundId = _ordrefobj.Id,
                    OrderType = item.OrderType,
                    PickUp = item.PickupCode,
                    ShopBranchId = item.ShopBranchId,
                    ShopBranchName = branchName,
                    DeliveryType = item.DeliveryType,
                    ShipOrderNumber = item.ShipOrderNumber,
                    EnabledRefundAmount = item.OrderEnabledRefundAmount,
                    itemInfo = orderItems.Where(oi => oi.OrderId == item.Id).Select(a =>
                    {
                        var prodata = products.FirstOrDefault(p => p.Id == a.ProductId);
                        VShop vshop = null;
                        if (prodata != null)
                        {
                            vshop = vshops.FirstOrDefault(vs => vs.ShopId == prodata.ShopId);
                        }
                        if (vshop == null)
                        {
                            vshop = new VShop {
                                Id = 0
                            }
                        }
                        ;

                        var itemrefund = orderRefunds.Where(or => or.OrderItemId == a.Id).FirstOrDefault(d => d.RefundMode != OrderRefundInfo.OrderRefundMode.OrderRefund);
                        int?itemrefstate = (itemrefund == null ? null : (int?)itemrefund.SellerAuditStatus);
                        itemrefstate = (itemrefstate > 4 ? (int?)itemrefund.ManagerConfirmStatus : itemrefstate);
                        return new
                        {
                            itemid = a.Id,
                            productId = a.ProductId,
                            productName = a.ProductName,
                            image = HimallIO.GetProductSizeImage(a.ThumbnailsUrl, 1, (int)ImageSize.Size_100),
                            count = a.Quantity,
                            price = a.SalePrice,
                            Unit = prodata == null ? "" : prodata.MeasureUnit,
                            vshopid = vshop.Id,
                            color = a.Color,
                            size = a.Size,
                            version = a.Version,
                            RefundStats = itemrefstate,
                            OrderRefundId = (itemrefund == null ? 0 : itemrefund.Id),
                            EnabledRefundAmount = a.EnabledRefundAmount
                        };
                    }),
                    HasAppendComment = HasAppendComment(orderItems.Where(oi => oi.OrderId == item.Id).FirstOrDefault()),
                    CanRefund = OrderApplication.CanRefund(item, ordrefstate),
                    IsVirtual = item.OrderType == OrderInfo.OrderTypes.Virtual ? 1 : 0,
                    IsPay = item.PayDate.HasValue ? 1 : 0
                });
            });
Beispiel #14
0
        public object GetBranchCartProducts(long shopBranchId)
        {
            long userId = 0;
            //会员折扣
            decimal discount = 1.0M;//默认折扣为1(没有折扣)

            if (CurrentUser != null)
            {
                userId   = CurrentUser.Id;
                discount = CurrentUser.MemberDiscount;
            }
            var cart = GetCart(userId, shopBranchId);
            //var shopBranch = _iShopBranchService.GetShopBranchById(shopBranchId);
            var         shopBranch     = ShopBranchApplication.GetShopBranchById(shopBranchId);
            var         productService = _iProductService;
            var         shopService    = _iShopService;
            var         vshopService   = _iVShopService;
            List <long> pids           = new List <long>();
            decimal     prodPrice      = 0.0M;//优惠价格
            var         products       = cart.Items.Select(item =>
            {
                var product       = productService.GetProduct(item.ProductId);
                var shopbranchsku = _iShopBranchService.GetSkusByIds(shopBranchId, new List <string> {
                    item.SkuId
                }).FirstOrDefault();
                var shop = shopService.GetShop(product.ShopId);
                //Entities.SKUInfo sku = null;
                string skuDetails = "";
                if (null != shop)
                {
                    var vshop = vshopService.GetVShopByShopId(shop.Id);
                    //sku = productService.GetSku(item.SkuId);
                    DTO.SKU sku = ProductManagerApplication.GetSKU(item.SkuId);
                    if (sku == null)
                    {
                        return(null);
                    }
                    prodPrice = sku.SalePrice;
                    if (shop.IsSelf)
                    {//官方自营店才计算会员折扣
                        prodPrice = sku.SalePrice * discount;
                    }

                    var typeInfo = TypeApplication.GetProductType(product.TypeId);
                    skuDetails   = "";
                    if (!string.IsNullOrWhiteSpace(sku.Size))
                    {
                        skuDetails += sku.Size + "&nbsp;&nbsp;";
                    }
                    if (!string.IsNullOrWhiteSpace(sku.Color))
                    {
                        skuDetails += sku.Color + "&nbsp;&nbsp;";
                    }
                    if (!string.IsNullOrWhiteSpace(sku.Version))
                    {
                        skuDetails += sku.Version + "&nbsp;&nbsp;";
                    }
                    return(new
                    {
                        bId = shopBranchId,
                        cartItemId = item.Id,
                        skuId = item.SkuId,
                        id = product.Id,
                        name = product.ProductName,
                        price = prodPrice,
                        count = item.Quantity,
                        stock = shopbranchsku == null ? 0 : shopbranchsku.Stock,
                        //阶梯价商品在门店购物车自动下架
                        //status = product.IsOpenLadder ? 1 : (shopbranchsku == null ? 1 : (shopbranchsku.Status == ShopBranchSkuStatus.Normal) ? (item.Quantity > shopbranchsku.Stock ? 2 : 0) : 1),//0:正常;1:冻结;2:库存不足
                        status = ProductManagerApplication.GetProductShowStatus(product, sku, 1, shopBranch, shopbranchsku),//0:正常;1:冻结;2:库存不足;3:已下架;
                        skuDetails = skuDetails,
                        AddTime = item.AddTime
                    });
                }
                else
                {
                    return(null);
                }
            }).Where(d => d != null).OrderBy(s => s.status).ThenByDescending(o => o.AddTime);

            var cartModel = new
            {
                success          = true,
                products         = products,
                amount           = products.Where(x => x.status == 0).Sum(item => item.price * item.count),
                totalCount       = products.Where(x => x.status == 0).Sum(item => item.count),
                DeliveFee        = shopBranch.DeliveFee,
                DeliveTotalFee   = shopBranch.DeliveTotalFee,
                FreeMailFee      = shopBranch.FreeMailFee,
                shopBranchStatus = (int)shopBranch.Status
            };

            return(cartModel);
        }
Beispiel #15
0
        /// <summary>
        /// 进入立即购买提交页面
        /// </summary>
        /// <param name="skuIds">库存ID集合</param>
        /// <param name="counts">库存ID对应的数量</param>
        /// <param name="GroupActionId">拼团活动编号</param>
        /// <param name="GroupId">拼团编号</param>
        public ActionResult Submit(string skuIds, string counts, int islimit = 0, long shippingAddressId = 0, string couponIds = "", sbyte productType = 0, long shopBranchId = 0)
        {
            if (productType == 0)
            {
                throw new MallException("门店订单不支持立即购买");
            }

            var coupons = CouponApplication.ConvertUsedCoupon(couponIds);
            var result  = OrderApplication.GetMobileSubmit(UserId, skuIds, counts, shippingAddressId, coupons, shopBranchId);

            ViewBag.InvoiceContext   = result.InvoiceContext;
            ViewBag.InvoiceTitle     = result.InvoiceTitle;
            ViewBag.skuIds           = skuIds;
            ViewBag.counts           = counts;
            ViewBag.IsCashOnDelivery = result.IsCashOnDelivery;
            ViewBag.address          = null == result.Address || result.Address.NeedUpdate ? null : result.Address;
            if (result.products != null)
            {
                var bid = result.products.FirstOrDefault().ShopBranchId;
                result.shopBranchInfo = ShopBranchApplication.GetShopBranchInfoById(bid);
            }
            ViewBag.ConfirmModel = result;
            ViewBag.Islimit      = islimit == 1 ? true : false;

            string orderTag = Guid.NewGuid().ToString("N");

            ViewBag.OrderTag = orderTag;
            //Session["OrderTag"] = orderTag;

            base.HttpContext.Session.Set <string>("OrderTag", orderTag);

            InitOrderSubmitModel(result);
            #region 是否开启门店授权
            ViewBag.IsOpenStore = SiteSettingApplication.SiteSettings != null && SiteSettingApplication.SiteSettings.IsOpenStore;
            #endregion

            #region 是否提供发票
            bool ProvideInvoice = false;
            if (result.products != null)
            {
                ProvideInvoice = ShopApplication.HasProvideInvoice(result.products.Select(p => p.shopId).ToList());
            }
            ViewBag.ProvideInvoice = ProvideInvoice;
            #endregion

            bool canIntegralPerMoney = true, canCapital = true;
            CanDeductible(out canIntegralPerMoney, out canCapital);
            ViewBag.CanIntegralPerMoney = canIntegralPerMoney;
            ViewBag.CanCapital          = canCapital;
            ViewBag.productType         = productType;
            ViewBag.shopBranchId        = shopBranchId;
            string shipperAddress = string.Empty, shipperTelPhone = string.Empty;
            if (productType == 1)
            {
                var virtualProductInfo = ProductManagerApplication.GetVirtualProductInfoByProductId(result.ProductId);
                if (virtualProductInfo != null && virtualProductInfo.ValidityType && DateTime.Now > virtualProductInfo.EndDate.Value)
                {
                    throw new MallException("该虚拟商品已过期,不支持下单");
                }
                if (result.shopBranchInfo != null)
                {
                    shipperAddress  = RegionApplication.GetFullName(result.shopBranchInfo.AddressId) + result.shopBranchInfo.AddressDetail;
                    shipperTelPhone = result.shopBranchInfo.ContactPhone;
                }
            }
            ViewBag.ShipperAddress  = shipperAddress;
            ViewBag.ShipperTelPhone = shipperTelPhone;
            return(View());
        }
Beispiel #16
0
        /// <summary>
        /// 退款申请
        /// </summary>
        /// <param name="id"></param>
        /// <param name="itemId"></param>
        /// <returns></returns>
        public ActionResult RefundApply(long orderid, long?itemId, long?refundid)
        {
            RefundApplyModel model = new RefundApplyModel();

            model.RefundMode  = null;
            model.OrderItemId = null;
            var order = _iOrderService.GetOrder(orderid, CurrentUser.Id);

            if (order == null)
            {
                throw new Mall.Core.MallException("该订单已删除或不属于该用户");
            }
            if (order.OrderType != OrderInfo.OrderTypes.Virtual && (int)order.OrderStatus < 2)
            {
                throw new Mall.Core.MallException("错误的售后申请,订单状态有误");
            }
            if (order.OrderType != OrderInfo.OrderTypes.Virtual && itemId == null && order.OrderStatus != Entities.OrderInfo.OrderOperateStatus.WaitDelivery && order.OrderStatus != Entities.OrderInfo.OrderOperateStatus.WaitSelfPickUp)
            {
                throw new Mall.Core.MallException("错误的订单退款申请,订单状态有误");
            }
            //售后时间限制
            if (order.OrderType != OrderInfo.OrderTypes.Virtual && _iOrderService.IsRefundTimeOut(orderid))
            {
                throw new Mall.Core.MallException("订单已超过售后期");
            }
            if (order.OrderType == OrderInfo.OrderTypes.Virtual)
            {
                //如果为虚拟商品,则要判断该商品是否允许退款,且该订单中是否至少有一个待核销的核销码
                var orderItemInfo = OrderApplication.GetOrderItemsByOrderId(order.Id).FirstOrDefault();
                if (orderItemInfo != null)
                {
                    itemId = orderItemInfo.Id;
                    var virtualProductInfo = ProductManagerApplication.GetVirtualProductInfoByProductId(orderItemInfo.ProductId);
                    if (virtualProductInfo != null)
                    {
                        if (virtualProductInfo.SupportRefundType == 3)
                        {
                            throw new Mall.Core.MallException("该商品不支持退款");
                        }
                        if (virtualProductInfo.SupportRefundType == 1 && DateTime.Now > virtualProductInfo.EndDate.Value)
                        {
                            throw new Mall.Core.MallException("该商品不支持过期退款");
                        }
                        var orderVerificationCodes = OrderApplication.GetOrderVerificationCodeInfosByOrderIds(new List <long>()
                        {
                            order.Id
                        });
                        long num = orderVerificationCodes.Where(a => a.Status == OrderInfo.VerificationCodeStatus.WaitVerification).Count();
                        if (num == 0)
                        {
                            throw new Mall.Core.MallException("该商品没有可退的核销码");
                        }
                    }
                }
            }

            //计算可退金额 预留
            _iOrderService.CalculateOrderItemRefund(orderid);

            var item = new Entities.OrderItemInfo();

            model.MaxRefundGoodsNumber = 0;
            model.MaxRefundAmount      = order.OrderEnabledRefundAmount;
            if (itemId == null)
            {
                model.OrderItems = _iOrderService.GetOrderItemsByOrderId(order.Id);
                if (model.OrderItems.Count == 1)
                {
                    item = model.OrderItems.FirstOrDefault();
                }
            }
            else
            {
                item = _iOrderService.GetOrderItem(itemId.Value);
                model.OrderItems.Add(item);
                model.MaxRefundGoodsNumber = item.Quantity - item.ReturnQuantity;
                model.MaxRefundAmount      = item.EnabledRefundAmount - item.RefundPrice;
            }
            if (order.OrderType == OrderInfo.OrderTypes.Virtual)
            {
                var count = OrderApplication.GetOrderVerificationCodeInfosByOrderIds(new List <long>()
                {
                    order.Id
                }).Where(a => a.Status != OrderInfo.VerificationCodeStatus.WaitVerification).ToList().Count;
                if (item.EnabledRefundAmount.HasValue)
                {
                    decimal price = item.EnabledRefundAmount.Value / item.Quantity;
                    model.MaxRefundAmount = item.EnabledRefundAmount.Value - Math.Round(count * price, 2, MidpointRounding.AwayFromZero);
                }
            }
            foreach (var orderItem in model.OrderItems)
            {
                Entities.TypeInfo typeInfo = _iTypeService.GetTypeByProductId(orderItem.ProductId);
                var productInfo            = ProductManagerApplication.GetProduct(orderItem.ProductId);
                orderItem.ColorAlias   = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
                orderItem.SizeAlias    = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
                orderItem.VersionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
                if (productInfo != null)
                {
                    orderItem.ColorAlias   = !string.IsNullOrWhiteSpace(productInfo.ColorAlias) ? productInfo.ColorAlias : orderItem.ColorAlias;
                    orderItem.SizeAlias    = !string.IsNullOrWhiteSpace(productInfo.SizeAlias) ? productInfo.SizeAlias : orderItem.SizeAlias;
                    orderItem.VersionAlias = !string.IsNullOrWhiteSpace(productInfo.VersionAlias) ? productInfo.VersionAlias : orderItem.VersionAlias;
                }
            }
            if (!model.MaxRefundAmount.HasValue)
            {
                model.MaxRefundAmount = 0;
            }
            bool isCanApply = false;
            var  refundser  = _iRefundService;

            Entities.OrderRefundInfo refunddata;

            if (order.OrderStatus == Entities.OrderInfo.OrderOperateStatus.WaitDelivery)
            {
                isCanApply = refundser.CanApplyRefund(orderid, item.Id);
            }
            else
            {
                isCanApply = refundser.CanApplyRefund(orderid, item.Id, false);
            }
            if (!refundid.HasValue)
            {
                if (order.OrderType != OrderInfo.OrderTypes.Virtual)
                {
                    if (!isCanApply)
                    {
                        var orderRefunds = OrderApplication.GetOrderRefunds(new long[] { item.Id });
                        if (orderRefunds.Count == 1)
                        {
                            Response.Redirect("/OrderRefund/Detail/" + orderRefunds[0].Id);
                        }

                        throw new Mall.Core.MallException("您已申请过售后,不可重复申请");
                    }
                }
                //model.ContactPerson = CurrentUser.RealName;
                //model.ContactCellPhone = CurrentUser.CellPhone;
                //model.ContactCellPhone = order.CellPhone;

                model.ContactPerson    = string.IsNullOrEmpty(order.ShipTo) ? CurrentUser.RealName : order.ShipTo;
                model.ContactCellPhone = string.IsNullOrEmpty(order.CellPhone) ? CurrentUser.CellPhone : order.CellPhone;
                model.OrderItemId      = itemId;
                if (!model.OrderItemId.HasValue)
                {
                    model.IsOrderAllRefund = true;
                    model.RefundMode       = Entities.OrderRefundInfo.OrderRefundMode.OrderRefund;
                }
            }
            else
            {
                refunddata = refundser.GetOrderRefund(refundid.Value, CurrentUser.Id);
                if (refunddata == null)
                {
                    throw new Mall.Core.MallException("错误的售后数据");
                }
                if (order.OrderType != OrderInfo.OrderTypes.Virtual && refunddata.SellerAuditStatus != Entities.OrderRefundInfo.OrderRefundAuditStatus.UnAudit)
                {
                    throw new Mall.Core.MallException("错误的售后状态,不可激活");
                }
                model.ContactPerson      = refunddata.ContactPerson;
                model.ContactCellPhone   = refunddata.ContactCellPhone;
                model.OrderItemId        = refunddata.OrderItemId;
                model.IsOrderAllRefund   = (refunddata.RefundMode == Entities.OrderRefundInfo.OrderRefundMode.OrderRefund);
                model.RefundMode         = refunddata.RefundMode;
                model.RefundReasonValue  = refunddata.Reason;
                model.RefundReasonDetail = refunddata.ReasonDetail;
                model.RefundWayValue     = refunddata.RefundPayType;
                model.CertPic1           = refunddata.CertPic1;
                model.CertPic2           = refunddata.CertPic2;
                model.CertPic3           = refunddata.CertPic3;
            }
            if (!model.IsOrderAllRefund && item.EnabledRefundAmount.HasValue)
            {
                model.RefundGoodsPrice = item.EnabledRefundAmount.Value / item.Quantity;
            }
            model.OrderInfo = order;
            model.OrderId   = orderid;
            model.RefundId  = refundid;

            var reasons = refundser.GetRefundReasons();

            foreach (var _ir in reasons)
            {
                _ir.AfterSalesText = _ir.AfterSalesText.Trim();
            }
            List <SelectListItem> reasel = new List <SelectListItem>();
            SelectListItem        _tmpsel;

            _tmpsel = new SelectListItem {
                Text = "选择售后理由", Value = ""
            };
            reasel.Add(_tmpsel);
            foreach (var _i in reasons)
            {
                _tmpsel = new SelectListItem {
                    Text = _i.AfterSalesText, Value = _i.AfterSalesText
                };
                if (!string.IsNullOrWhiteSpace(model.RefundReasonValue))
                {
                    if (_i.AfterSalesText == model.RefundReasonValue)
                    {
                        _tmpsel.Selected = true;
                    }
                }
                reasel.Add(_tmpsel);
            }
            model.RefundReasons = reasel;

            List <SelectListItem> list = new List <SelectListItem> {
                new SelectListItem {
                    Text  = OrderRefundInfo.OrderRefundPayType.BackCapital.ToDescription(),
                    Value = ((int)OrderRefundInfo.OrderRefundPayType.BackCapital).ToString()
                }
            };

            if (order.CanBackOut())
            {
                _tmpsel = new SelectListItem
                {
                    Text  = OrderRefundInfo.OrderRefundPayType.BackOut.ToDescription(),
                    Value = ((int)OrderRefundInfo.OrderRefundPayType.BackOut).ToString()
                };
                //if (model.RefundWayValue.HasValue)
                //{
                //    if (_tmpsel.Value == model.RefundWayValue.ToString())
                //    {
                //        _tmpsel.Selected = true;
                //    }
                //}
                _tmpsel.Selected = true;  //若订单支付方式为支付宝、微信支付则退款方式默认选中“退款原路返回”
                list.Add(_tmpsel);
            }
            model.RefundWay = list;

            if (order.DeliveryType == CommonModel.DeliveryType.SelfTake)
            {
                var shopBranch = ShopBranchApplication.GetShopBranchById(order.ShopBranchId);
                model.ReturnGoodsAddress  = RegionApplication.GetFullName(shopBranch.AddressId);
                model.ReturnGoodsAddress += " " + shopBranch.AddressDetail;
                model.ReturnGoodsAddress += " " + shopBranch.ContactPhone;
            }

            ViewBag.Keyword  = string.IsNullOrWhiteSpace(SiteSettings.SearchKeyword) ? SiteSettings.Keyword : SiteSettings.SearchKeyword;
            ViewBag.Keywords = SiteSettings.HotKeyWords;
            #region 虚拟订单退款
            ViewBag.orderVerificationCode = OrderApplication.GetOrderVerificationCodeInfosByOrderIds(new List <long>()
            {
                order.Id
            }).Where(a => a.Status == OrderInfo.VerificationCodeStatus.WaitVerification).ToList();
            #endregion
            ViewBag.IsVirtual = order.OrderType == OrderInfo.OrderTypes.Virtual ? 1 : 0;
            return(View(model));
        }
Beispiel #17
0
        public JsonResult GetShopBranchs(long shopId, long regionId, bool getParent, string[] skuIds, int[] counts, int page, int rows, long shippingAddressId)
        {
            var shippingAddressInfo = ShippingAddressApplication.GetUserShippingAddress(shippingAddressId);
            int streetId = 0, districtId = 0;//收货地址的街道、区域

            var query = new ShopBranchQuery()
            {
                ShopId   = shopId,
                PageNo   = page,
                PageSize = rows,
                Status   = ShopBranchStatus.Normal,
                ShopBranchProductStatus = ShopBranchSkuStatus.Normal
            };

            if (shippingAddressInfo != null)
            {
                query.FromLatLng = string.Format("{0},{1}", shippingAddressInfo.Latitude, shippingAddressInfo.Longitude); //需要收货地址的经纬度
                streetId         = shippingAddressInfo.RegionId;
                var parentAreaInfo = RegionApplication.GetRegion(shippingAddressInfo.RegionId, Region.RegionLevel.Town);  //判断当前区域是否为第四级
                if (parentAreaInfo != null && parentAreaInfo.ParentId > 0)
                {
                    districtId = parentAreaInfo.ParentId;
                }
                else
                {
                    districtId = streetId; streetId = 0;
                }
            }
            bool hasLatLng = false;

            if (!string.IsNullOrWhiteSpace(query.FromLatLng))
            {
                hasLatLng = query.FromLatLng.Split(',').Length == 2;
            }

            var region = RegionApplication.GetRegion(regionId, getParent ? Region.RegionLevel.City : Region.RegionLevel.County);

            if (region != null)
            {
                query.AddressPath = region.GetIdPath();
            }

            #region 旧排序规则
            //var skuInfos = ProductManagerApplication.GetSKUs(skuIds);

            //query.ProductIds = skuInfos.Select(p => p.ProductId).ToArray();
            //var data = ShopBranchApplication.GetShopBranchs(query);

            //var shopBranchSkus = ShopBranchApplication.GetSkus(shopId, data.Models.Select(p => p.Id));

            //var models = new
            //{
            //    Rows = data.Models.Select(sb => new
            //    {
            //        sb.ContactUser,
            //        sb.ContactPhone,
            //        sb.AddressDetail,
            //        sb.ShopBranchName,
            //        sb.Id,
            //        Enabled = skuInfos.All(skuInfo => shopBranchSkus.Any(sbSku => sbSku.ShopBranchId == sb.Id && sbSku.Stock >= counts[skuInfos.IndexOf(skuInfo)] && sbSku.SkuId == skuInfo.Id))
            //    }).OrderByDescending(p => p.Enabled).ToArray(),
            //    data.Total
            //};
            #endregion
            #region 3.0版本排序规则
            var skuInfos = ProductManagerApplication.GetSKUs(skuIds);
            query.ProductIds = skuInfos.Select(p => p.ProductId).ToArray();
            var data           = ShopBranchApplication.GetShopBranchsAll(query);
            var shopBranchSkus = ShopBranchApplication.GetSkus(shopId, data.Models.Select(p => p.Id).ToList());//获取该商家下具有订单内所有商品的门店状态正常数据,不考虑库存
            data.Models.ForEach(p =>
            {
                p.Enabled = skuInfos.All(skuInfo => shopBranchSkus.Any(sbSku => sbSku.ShopBranchId == p.Id && sbSku.Stock >= counts[skuInfos.IndexOf(skuInfo)] && sbSku.SkuId == skuInfo.Id));
            });

            List <ShopBranch> newList    = new List <ShopBranch>();
            List <long>       fillterIds = new List <long>();
            var currentList = data.Models.Where(p => hasLatLng && p.Enabled && (p.Latitude > 0 && p.Longitude > 0)).OrderBy(p => p.Distance).ToList();
            if (currentList != null && currentList.Count() > 0)
            {
                fillterIds.AddRange(currentList.Select(p => p.Id));
                newList.AddRange(currentList);
            }
            var currentList2 = data.Models.Where(p => !fillterIds.Contains(p.Id) && p.Enabled && p.AddressPath.Contains(CommonConst.ADDRESS_PATH_SPLIT + streetId + CommonConst.ADDRESS_PATH_SPLIT)).ToList();
            if (currentList2 != null && currentList2.Count() > 0)
            {
                fillterIds.AddRange(currentList2.Select(p => p.Id));
                newList.AddRange(currentList2);
            }
            var currentList3 = data.Models.Where(p => !fillterIds.Contains(p.Id) && p.Enabled && p.AddressPath.Contains(CommonConst.ADDRESS_PATH_SPLIT + districtId + CommonConst.ADDRESS_PATH_SPLIT)).ToList();
            if (currentList3 != null && currentList3.Count() > 0)
            {
                fillterIds.AddRange(currentList3.Select(p => p.Id));
                newList.AddRange(currentList3);
            }
            var currentList4 = data.Models.Where(p => !fillterIds.Contains(p.Id) && p.Enabled).ToList();//非同街、非同区,但一定会同市
            if (currentList4 != null && currentList4.Count() > 0)
            {
                fillterIds.AddRange(currentList4.Select(p => p.Id));
                newList.AddRange(currentList4);
            }
            var currentList5 = data.Models.Where(p => !fillterIds.Contains(p.Id)).ToList();//库存不足的排最后
            if (currentList5 != null && currentList5.Count() > 0)
            {
                newList.AddRange(currentList5);
            }
            if (newList.Count() != data.Models.Count())//如果新组合的数据与原数据数量不一致,则异常
            {
                return(Json <dynamic>(true, data: new { Rows = "" }, camelCase: true));
            }
            var needDistance = false;
            if (shippingAddressInfo != null && shippingAddressInfo.Latitude != 0 && shippingAddressInfo.Longitude != 0)
            {
                needDistance = true;
            }
            var models = new
            {
                Rows = newList.Select(sb => new
                {
                    sb.ContactUser,
                    sb.ContactPhone,
                    sb.AddressDetail,
                    sb.ShopBranchName,
                    sb.Id,
                    Enabled  = sb.Enabled,
                    Distance = needDistance ? RegionApplication.GetDistance(sb.Latitude, sb.Longitude, shippingAddressInfo.Latitude, shippingAddressInfo.Longitude) : 0
                }).ToArray(),
                Total = newList.Count
            };
            #endregion
            return(SuccessResult <dynamic>(data: models, camelCase: true));
        }
Beispiel #18
0
        public JsonResult GetBranchCartProducts(long shopBranchId)
        {
            var  branchCartHelper = new BranchCartHelper();
            long userId           = 0;
            //会员折扣
            decimal discount = 1.0M;//默认折扣为1(没有折扣)

            if (CurrentUser != null)
            {
                userId   = CurrentUser.Id;
                discount = CurrentUser.MemberDiscount;
            }
            var cart = branchCartHelper.GetCart(userId, shopBranchId);
            //var shopBranch = _iShopBranchService.GetShopBranchById(shopBranchId);
            var shopBranch = ShopBranchApplication.GetShopBranchById(shopBranchId);
            Dictionary <long, long> buyedCounts = null;

            if (userId > 0)
            {
                buyedCounts = new Dictionary <long, long>();
                buyedCounts = OrderApplication.GetProductBuyCount(userId, cart.Items.Select(x => x.ProductId));
            }
            decimal prodPrice         = 0.0M;//优惠价格
            var     shopBranchSkuList = _iShopBranchService.GetSkusByIds(shopBranchId, cart.Items.Select(x => x.SkuId).ToList());

            var products = cart.Items.Select(item =>
            {
                var product       = _iProductService.GetProduct(item.ProductId);
                var shopbranchsku = shopBranchSkuList.FirstOrDefault(x => x.SkuId == item.SkuId);
                long stock        = shopbranchsku == null ? 0 : shopbranchsku.Stock;

                if (stock > product.MaxBuyCount && product.MaxBuyCount != 0)
                {
                    stock = product.MaxBuyCount;
                }
                if (product.MaxBuyCount > 0 && buyedCounts != null && buyedCounts.ContainsKey(item.ProductId))
                {
                    long buynum = buyedCounts[item.ProductId];
                    stock       = stock - buynum;
                }

                var shop = _iShopService.GetShop(product.ShopId);
                //Entities.SKUInfo sku = null;
                string skuDetails = "";
                if (null != shop)
                {
                    var vshop = _iVShopService.GetVShopByShopId(shop.Id);
                    //sku = _iProductService.GetSku(item.SkuId);
                    DTO.SKU sku = ProductManagerApplication.GetSKU(item.SkuId);
                    if (sku == null)
                    {
                        return(null);
                    }
                    prodPrice = sku.SalePrice;
                    if (shop.IsSelf)
                    {//官方自营店才计算会员折扣
                        prodPrice = sku.SalePrice * discount;
                    }

                    var typeInfo = TypeApplication.GetProductType(product.TypeId);
                    skuDetails   = "";
                    if (!string.IsNullOrWhiteSpace(sku.Size))
                    {
                        skuDetails += sku.Size + "&nbsp;&nbsp;";
                    }
                    if (!string.IsNullOrWhiteSpace(sku.Color))
                    {
                        skuDetails += sku.Color + "&nbsp;&nbsp;";
                    }
                    if (!string.IsNullOrWhiteSpace(sku.Version))
                    {
                        skuDetails += sku.Version + "&nbsp;&nbsp;";
                    }
                    return(new
                    {
                        bId = shopBranchId,
                        cartItemId = item.Id,
                        skuId = item.SkuId,
                        id = product.Id,
                        name = product.ProductName,
                        price = prodPrice,
                        count = item.Quantity,
                        stock = shopbranchsku == null ? 0 : stock,
                        //阶梯价商品在门店购物车自动下架
                        //status = product.IsOpenLadder ? 1 : (shopbranchsku == null ? 1 : (shopbranchsku.Status == ShopBranchSkuStatus.Normal) ? (item.Quantity > stock ? 2 : 0) : 1),//0:正常;1:冻结;2:库存不足
                        status = ProductManagerApplication.GetProductShowStatus(product, sku, 1, shopBranch, shopbranchsku),//0:正常;1:冻结;2:库存不足;3:已下架;
                        skuDetails = skuDetails,
                        AddTime = item.AddTime
                    });
                }
                else
                {
                    return(null);
                }
            }).Where(d => d != null).OrderBy(s => s.status).ThenByDescending(o => o.AddTime);

            var cartModel = new { products = products, amount = products.Where(x => x.status == 0).Sum(item => item.price * item.count), totalCount = products.Where(x => x.status == 0).Sum(item => item.count), DeliveFee = shopBranch.DeliveFee, DeliveTotalFee = shopBranch.DeliveTotalFee, FreeMailFee = shopBranch.FreeMailFee, IsFreeMail = shopBranch.IsFreeMail, shopBranchStatus = (int)shopBranch.Status };

            return(SuccessResult <dynamic>(data: cartModel));
        }
        public object GetShopManager()
        {
            var branch = ShopBranchApplication.GetShopBranchById(CurrentShopBranch.Id);

            return(new { success = true, enable = branch.EnableSellerManager });
        }
Beispiel #20
0
        public JsonResult List(DateTime?startDate, DateTime?endDate, long?orderId, int?auditStatus, long?shopBranchId, string userName, string ProductName, int page, int rows, int showtype = 0)
        {
            var queryModel = new RefundQuery()
            {
                StartDate      = startDate,
                EndDate        = endDate,
                OrderId        = orderId,
                ProductName    = ProductName,
                AuditStatus    = (Model.OrderRefundInfo.OrderRefundAuditStatus?)auditStatus,
                ShopId         = CurrentSellerManager.ShopId,
                UserName       = userName,
                PageSize       = rows,
                PageNo         = page,
                ShowRefundType = showtype
            };

            if (shopBranchId.HasValue && shopBranchId.Value > 0)
            {
                queryModel.ShopBranchId = shopBranchId.Value;
            }

            var refunds      = Application.RefundApplication.GetOrderRefunds(queryModel);
            var orders       = Application.OrderApplication.GetOrders(refunds.Models.Select(p => p.OrderId));
            var orderItems   = Application.OrderApplication.GetOrderItemsByOrderItemId(refunds.Models.Select(p => p.OrderItemId));
            var refundModels = refunds.Models.Select(item =>
            {
                //以下查询代码要做优化
                var order     = orders.FirstOrDefault(p => p.Id == item.OrderId);
                var orderItem = orderItems.FirstOrDefault(p => p.Id == item.OrderItemId);
                string spec   = ((string.IsNullOrWhiteSpace(orderItem.Color) ? "" : orderItem.Color + ",")
                                 + (string.IsNullOrWhiteSpace(orderItem.Size) ? "" : orderItem.Size + ",")
                                 + (string.IsNullOrWhiteSpace(orderItem.Version) ? "" : orderItem.Version + ",")).TrimEnd(',');
                if (!string.IsNullOrWhiteSpace(spec))
                {
                    spec = "  【" + spec + " 】";
                }
                string shopBranchName = "总店";
                if (order.ShopBranchId.HasValue && order.ShopBranchId.Value > 0)
                {
                    var shopBranchInfo = ShopBranchApplication.GetShopBranchById(order.ShopBranchId.Value);
                    if (shopBranchInfo != null)
                    {
                        shopBranchName = shopBranchInfo.ShopBranchName;
                    }
                }
                return(new OrderRefundModel()
                {
                    RefundId = item.Id,
                    OrderId = item.OrderId,
                    AuditStatus = (order.DeliveryType == CommonModel.Enum.DeliveryType.SelfTake || (order.ShopBranchId.HasValue && order.ShopBranchId.Value > 0)) ? ((CommonModel.Enum.OrderRefundShopAuditStatus)(int) item.SellerAuditStatus).ToDescription() : item.SellerAuditStatus.ToDescription(),
                    ConfirmStatus = item.ManagerConfirmStatus.ToDescription(),
                    ApplyDate = item.ApplyDate.ToShortDateString(),
                    ShopId = item.ShopId,
                    ShopName = item.ShopName.Replace("'", "‘").Replace("\"", "”"),
                    UserId = item.UserId,
                    UserName = item.Applicant,
                    ContactPerson = HTMLEncode(item.ContactPerson),
                    ContactCellPhone = HTMLEncode(item.ContactCellPhone),
                    RefundAccount = string.IsNullOrEmpty(item.RefundAccount) ? string.Empty : HTMLEncode(item.RefundAccount.Replace("'", "‘").Replace("\"", "”")),
                    Amount = item.Amount.ToString("F2"),
                    ReturnQuantity = ((item.RefundMode == OrderRefundInfo.OrderRefundMode.OrderRefund)
                                    ? 0
                                    : (item.ShowReturnQuantity == 0 ? orderItem.ReturnQuantity : item.ShowReturnQuantity)),
                    Quantity = orderItem.Quantity,
                    SalePrice = item.EnabledRefundAmount.ToString("F2"),
                    ProductName = ((item.RefundMode == OrderRefundInfo.OrderRefundMode.OrderRefund)
                                    ? "预约单所有诊疗项目"
                                    : (orderItem.ProductName + spec)),
                    Reason = string.IsNullOrEmpty(item.Reason) ? string.Empty : HTMLEncode(item.Reason.Replace("'", "‘").Replace("\"", "”")),
                    ReasonDetail = string.IsNullOrEmpty(item.ReasonDetail) ? string.Empty : item.ReasonDetail.Replace("'", "‘").Replace("\"", "”"),
                    ExpressCompanyName = HTMLEncode(item.ExpressCompanyName),
                    ShipOrderNumber = item.ShipOrderNumber,
                    Payee = string.IsNullOrEmpty(item.Payee) ? string.Empty : HTMLEncode(item.Payee),
                    PayeeAccount = string.IsNullOrEmpty(item.PayeeAccount) ? string.Empty : HTMLEncode(item.PayeeAccount.Replace("'", "‘").Replace("\"", "”")),
                    RefundMode = (int)item.RefundMode,
                    SellerRemark = string.IsNullOrEmpty(item.SellerRemark) ? string.Empty : HTMLEncode(item.SellerRemark.Replace("'", "‘").Replace("\"", "”")),
                    ManagerRemark = string.IsNullOrEmpty(item.ManagerRemark) ? string.Empty : HTMLEncode(item.ManagerRemark.Replace("'", "‘").Replace("\"", "”")),
                    RefundStatus = ((item.SellerAuditStatus == OrderRefundInfo.OrderRefundAuditStatus.Audited)
                                    ? item.ManagerConfirmStatus.ToDescription()
                                    : ((order.DeliveryType == CommonModel.Enum.DeliveryType.SelfTake || (order.ShopBranchId.HasValue && order.ShopBranchId.Value > 0)) ? ((CommonModel.Enum.OrderRefundShopAuditStatus)item.SellerAuditStatus).ToDescription() : item.SellerAuditStatus.ToDescription())),
                    RefundPayType = item.RefundPayType == null ? "线下处理" : item.RefundPayType.ToDescription(),
                    ApplyNumber = (item.ApplyNumber.HasValue ? item.ApplyNumber.Value : 1),
                    nextSecond = GetNextSecond(item),
                    CertPic1 = Core.HimallIO.GetImagePath(item.CertPic1),
                    CertPic2 = Core.HimallIO.GetImagePath(item.CertPic2),
                    CertPic3 = Core.HimallIO.GetImagePath(item.CertPic3),
                    ShopBranchId = order.ShopBranchId.HasValue ? order.ShopBranchId.Value : 0,
                    ShopBranchName = shopBranchName
                });
            });

            var dataGrid = new DataGridModel <OrderRefundModel>()
            {
                rows  = refundModels,
                total = refunds.Total
            };

            return(Json(dataGrid));
        }
 public JsonResult Freeze(long shopBranchId)
 {
     ShopBranchApplication.Freeze(shopBranchId);
     return(Json(new { success = true, msg = "冻结成功!" }));
 }
        public object GetShopBranchs(long shopId, bool getParent, string skuIds, string counts, int page, int rows, long shippingAddressId, long regionId)
        {
            string[]            strArray            = skuIds.Split(',');
            int[]               _counts             = Enumerable.ToArray <int>(Enumerable.Select <string, int>((IEnumerable <string>)counts.Split(','), (Func <string, int>)(p => TypeHelper.ObjectToInt((object)p))));
            ShippingAddressInfo userShippingAddress = ShippingAddressApplication.GetUserShippingAddress(shippingAddressId);
            int             streetId        = 0;
            int             districtId      = 0;
            ShopBranchQuery shopBranchQuery = new ShopBranchQuery();

            shopBranchQuery.ShopId   = shopId;
            shopBranchQuery.PageNo   = page;
            shopBranchQuery.PageSize = rows;
            shopBranchQuery.Status   = new ShopBranchStatus?(ShopBranchStatus.Normal);
            ShopBranchQuery query = shopBranchQuery;

            if (userShippingAddress != null)
            {
                query.FromLatLng = string.Format("{0},{1}", (object)userShippingAddress.Latitude, (object)userShippingAddress.Longitude);
                streetId         = userShippingAddress.RegionId;
                Region region = RegionApplication.GetRegion((long)userShippingAddress.RegionId, Region.RegionLevel.Town);
                if (region != null && region.ParentId > 0)
                {
                    districtId = region.ParentId;
                }
                else
                {
                    districtId = streetId;
                    streetId   = 0;
                }
            }
            bool hasLatLng = false;

            if (!string.IsNullOrWhiteSpace(query.FromLatLng))
            {
                hasLatLng = (query.FromLatLng.Split(',').Length == 2 ? 1 : 0) != 0;
            }
            Region region1 = RegionApplication.GetRegion(regionId, getParent ? Region.RegionLevel.City : Region.RegionLevel.County);

            if (region1 != null)
            {
                query.AddressPath = region1.GetIdPath(",");
            }
            List <SKU> skuInfos = ProductManagerApplication.GetSKUs((IEnumerable <string>)strArray);

            query.ProductIds = Enumerable.ToArray <long>(Enumerable.Select <SKU, long>((IEnumerable <SKU>)skuInfos, (Func <SKU, long>)(p => p.ProductId)));
            QueryPageModel <ShopBranch> shopBranchsAll = ShopBranchApplication.GetShopBranchsAll(query);
            List <ShopBranchSkusInfo>   shopBranchSkus = ShopBranchApplication.GetSkus(shopId, Enumerable.Select <ShopBranch, long>((IEnumerable <ShopBranch>)shopBranchsAll.Models, (Func <ShopBranch, long>)(p => p.Id)));

            shopBranchsAll.Models.ForEach((Action <ShopBranch>)(p => p.Enabled = Enumerable.All <SKU>((IEnumerable <SKU>)skuInfos, (Func <SKU, bool>)(skuInfo => Enumerable.Any <ShopBranchSkusInfo>((IEnumerable <ShopBranchSkusInfo>)shopBranchSkus, (Func <ShopBranchSkusInfo, bool>)(sbSku => sbSku.ShopBranchId == p.Id && sbSku.Stock >= _counts[skuInfos.IndexOf(skuInfo)] && sbSku.SkuId == skuInfo.Id))))));
            List <ShopBranch> list1      = new List <ShopBranch>();
            List <long>       fillterIds = new List <long>();
            List <ShopBranch> list2      = Enumerable.ToList <ShopBranch>((IEnumerable <ShopBranch>)Enumerable.OrderBy <ShopBranch, double>(Enumerable.Where <ShopBranch>((IEnumerable <ShopBranch>)shopBranchsAll.Models, (Func <ShopBranch, bool>)(p => hasLatLng && p.Enabled && ((double)p.Latitude > 0.0 && (double)p.Longitude > 0.0))), (Func <ShopBranch, double>)(p => p.Distance)));

            if (list2 != null && Enumerable.Count <ShopBranch>((IEnumerable <ShopBranch>)list2) > 0)
            {
                fillterIds.AddRange(Enumerable.Select <ShopBranch, long>((IEnumerable <ShopBranch>)list2, (Func <ShopBranch, long>)(p => p.Id)));
                list1.AddRange((IEnumerable <ShopBranch>)list2);
            }
            List <ShopBranch> list3 = Enumerable.ToList <ShopBranch>(Enumerable.Where <ShopBranch>((IEnumerable <ShopBranch>)shopBranchsAll.Models, (Func <ShopBranch, bool>)(p => !fillterIds.Contains(p.Id) && p.Enabled && p.AddressPath.Contains("," + (object)streetId + ","))));

            if (list3 != null && Enumerable.Count <ShopBranch>((IEnumerable <ShopBranch>)list3) > 0)
            {
                fillterIds.AddRange(Enumerable.Select <ShopBranch, long>((IEnumerable <ShopBranch>)list3, (Func <ShopBranch, long>)(p => p.Id)));
                list1.AddRange((IEnumerable <ShopBranch>)list3);
            }
            List <ShopBranch> list4 = Enumerable.ToList <ShopBranch>(Enumerable.Where <ShopBranch>((IEnumerable <ShopBranch>)shopBranchsAll.Models, (Func <ShopBranch, bool>)(p => !fillterIds.Contains(p.Id) && p.Enabled && p.AddressPath.Contains("," + (object)districtId + ","))));

            if (list4 != null && Enumerable.Count <ShopBranch>((IEnumerable <ShopBranch>)list4) > 0)
            {
                fillterIds.AddRange(Enumerable.Select <ShopBranch, long>((IEnumerable <ShopBranch>)list4, (Func <ShopBranch, long>)(p => p.Id)));
                list1.AddRange((IEnumerable <ShopBranch>)list4);
            }
            List <ShopBranch> list5 = Enumerable.ToList <ShopBranch>(Enumerable.Where <ShopBranch>((IEnumerable <ShopBranch>)shopBranchsAll.Models, (Func <ShopBranch, bool>)(p => !fillterIds.Contains(p.Id) && p.Enabled)));

            if (list5 != null && Enumerable.Count <ShopBranch>((IEnumerable <ShopBranch>)list5) > 0)
            {
                fillterIds.AddRange(Enumerable.Select <ShopBranch, long>((IEnumerable <ShopBranch>)list5, (Func <ShopBranch, long>)(p => p.Id)));
                list1.AddRange((IEnumerable <ShopBranch>)list5);
            }
            List <ShopBranch> list6 = Enumerable.ToList <ShopBranch>(Enumerable.Where <ShopBranch>((IEnumerable <ShopBranch>)shopBranchsAll.Models, (Func <ShopBranch, bool>)(p => !fillterIds.Contains(p.Id))));

            if (list6 != null && Enumerable.Count <ShopBranch>((IEnumerable <ShopBranch>)list6) > 0)
            {
                list1.AddRange((IEnumerable <ShopBranch>)list6);
            }
            if (Enumerable.Count <ShopBranch>((IEnumerable <ShopBranch>)list1) != Enumerable.Count <ShopBranch>((IEnumerable <ShopBranch>)shopBranchsAll.Models))
            {
                return((object)this.Json(new
                {
                    Success = false
                }));
            }
            var content = new
            {
                Success   = true,
                StoreList = Enumerable.Select((IEnumerable <ShopBranch>)list1, sb =>
                {
                    var fAnonymousType37 = new
                    {
                        ContactUser    = sb.ContactUser,
                        ContactPhone   = sb.ContactPhone,
                        AddressDetail  = sb.AddressDetail,
                        ShopBranchName = sb.ShopBranchName,
                        Id             = sb.Id,
                        Enabled        = sb.Enabled
                    };
                    return(fAnonymousType37);
                })
            };

            return((object)this.Json(content));
        }
 public JsonResult DeleteTag(long Id)
 {
     ShopBranchApplication.DeleteShopBranchTagInfo(Id);
     return(Json(new { success = true }));
 }
Beispiel #24
0
        public JsonResult GetShopBranchs(long shopId, long regionId, bool getParent, string[] skuIds, int[] counts, int page, int rows, long shippingAddressId)
        {
            ShippingAddressInfo userShippingAddress = ShippingAddressApplication.GetUserShippingAddress(shippingAddressId);
            int             streetId   = 0;
            int             districtId = 0;
            ShopBranchQuery query      = new ShopBranchQuery
            {
                ShopId   = shopId,
                PageNo   = page,
                PageSize = rows,
                Status   = 0
            };

            if (userShippingAddress != null)
            {
                query.FromLatLng = string.Format("{0},{1}", userShippingAddress.Latitude, userShippingAddress.Longitude);
                streetId         = userShippingAddress.RegionId;
                Region region = RegionApplication.GetRegion((long)userShippingAddress.RegionId, Region.RegionLevel.Town);
                if ((region != null) && (region.ParentId > 0))
                {
                    districtId = region.ParentId;
                }
                else
                {
                    districtId = streetId;
                    streetId   = 0;
                }
            }
            bool hasLatLng = false;

            if (!string.IsNullOrWhiteSpace(query.FromLatLng))
            {
                hasLatLng = query.FromLatLng.Split(new char[] { ',' }).Length == 2;
            }
            Region region2 = RegionApplication.GetRegion(regionId, getParent ? Region.RegionLevel.City : Region.RegionLevel.County);

            if (region2 != null)
            {
                query.AddressPath = region2.GetIdPath(",");
            }
            List <SKU> skuInfos = ProductManagerApplication.GetSKUs(skuIds);

            query.ProductIds = (from p in skuInfos select p.ProductId).ToArray <long>();
            QueryPageModel <ShopBranch> shopBranchsAll = ShopBranchApplication.GetShopBranchsAll(query);
            List <ShopBranchSkusInfo>   shopBranchSkus = ShopBranchApplication.GetSkus(shopId, from p in shopBranchsAll.Models select p.Id);

            shopBranchsAll.Models.ForEach(delegate(ShopBranch p)
            {
                p.Enabled = skuInfos.All <SKU>(skuInfo => shopBranchSkus.Any <ShopBranchSkusInfo>(sbSku => ((sbSku.ShopBranchId == p.Id) && (sbSku.Stock >= counts[skuInfos.IndexOf(skuInfo)])) && (sbSku.SkuId == skuInfo.Id)));
            });
            List <ShopBranch> source     = new List <ShopBranch>();
            List <long>       fillterIds = new List <long>();
            List <ShopBranch> list2      = (from p in shopBranchsAll.Models
                                            where (hasLatLng && p.Enabled) && ((p.Latitude > 0f) && (p.Longitude > 0f))
                                            orderby p.Distance
                                            select p).ToList <ShopBranch>();

            if ((list2 != null) && (list2.Count <ShopBranch>() > 0))
            {
                fillterIds.AddRange(from p in list2 select p.Id);
                source.AddRange(list2);
            }
            List <ShopBranch> list3 = (from p in shopBranchsAll.Models
                                       where (!fillterIds.Contains(p.Id) && p.Enabled) && p.AddressPath.Contains("," + streetId + ",")
                                       select p).ToList <ShopBranch>();

            if ((list3 != null) && (list3.Count <ShopBranch>() > 0))
            {
                fillterIds.AddRange(from p in list3 select p.Id);
                source.AddRange(list3);
            }
            List <ShopBranch> list4 = (from p in shopBranchsAll.Models
                                       where (!fillterIds.Contains(p.Id) && p.Enabled) && p.AddressPath.Contains("," + districtId + ",")
                                       select p).ToList <ShopBranch>();

            if ((list4 != null) && (list4.Count <ShopBranch>() > 0))
            {
                fillterIds.AddRange(from p in list4 select p.Id);
                source.AddRange(list4);
            }
            List <ShopBranch> list5 = (from p in shopBranchsAll.Models
                                       where !fillterIds.Contains(p.Id) && p.Enabled
                                       select p).ToList <ShopBranch>();

            if ((list5 != null) && (list5.Count <ShopBranch>() > 0))
            {
                fillterIds.AddRange(from p in list5 select p.Id);
                source.AddRange(list5);
            }
            List <ShopBranch> list6 = (from p in shopBranchsAll.Models
                                       where !fillterIds.Contains(p.Id)
                                       select p).ToList <ShopBranch>();

            if ((list6 != null) && (list6.Count <ShopBranch>() > 0))
            {
                source.AddRange(list6);
            }
            if (source.Count <ShopBranch>() != shopBranchsAll.Models.Count <ShopBranch>())
            {
                return(base.Json(new { Rows = "" }, true));
            }
            var data = new
            {
                Rows  = (from sb in source select new { ContactUser = sb.ContactUser, ContactPhone = sb.ContactPhone, AddressDetail = sb.AddressDetail, ShopBranchName = sb.ShopBranchName, Id = sb.Id, Enabled = sb.Enabled }).ToArray(),
                Total = source.Count
            };

            return(base.Json(data, true));
        }
Beispiel #25
0
        /// <summary>
        /// 门店首页获取诊疗项目列表
        /// </summary>
        /// <param name="pageSize"></param>
        /// <param name="pageNo"></param>
        /// <param name="shopCategoryId">诊所一级分类</param>
        /// <param name="shopId">诊所ID</param>
        /// <param name="shopBranchId">门店ID</param>
        /// <returns></returns>
        public object GetProductList(int pageSize, int pageNo, string shopCategoryId, string shopId, string shopBranchId)
        {
            ShopBranchProductQuery query = new ShopBranchProductQuery();

            query.PageSize = pageSize;
            query.PageNo   = pageNo;
            //query.ShopCategoryId = TypeHelper.ObjectToInt(shopCategoryId, 0);
            query.ShopId                  = TypeHelper.ObjectToInt(shopId, 0);
            query.shopBranchId            = TypeHelper.ObjectToInt(shopBranchId, 0);
            query.ShopBranchProductStatus = ShopBranchSkuStatus.Normal;

            if (query.ShopId <= 0)
            {
                return(Json(new { Success = false, Message = "无法定位到诊所!" }));
            }

            //if (query.ShopCategoryId <= 0)
            //    return Json(new { Success = false, Message = "无法定位到诊所分类!" });
            if (TypeHelper.ObjectToInt(shopCategoryId, 0) > 0)
            {
                query.ShopCategoryId = TypeHelper.ObjectToInt(shopCategoryId);
            }

            if (query.shopBranchId <= 0)
            {
                return(Json(new { Success = false, Message = "无法定位到门店!" }));
            }

            var pageModel = ShopBranchApplication.GetShopBranchProducts(query);

            if (pageModel.Models != null && pageModel.Models.Count > 0)
            {
                #region 处理诊疗项目 官方自营店会员折扣价,各活动价等。
                var flashSalePriceList      = LimitTimeApplication.GetPriceByProducrIds(pageModel.Models.Select(p => p.Id).ToList());
                var fightGroupSalePriceList = FightGroupApplication.GetActiveByProductIds(pageModel.Models.Select(p => p.Id).ToArray());
                if (CurrentUser != null)
                {
                    var shopInfo = ShopApplication.GetShop(query.ShopId.Value);
                    if (shopInfo != null && shopInfo.IsSelf)//当前诊所是否是官方自营店
                    {
                        decimal discount = 1M;
                        discount = CurrentUser.MemberDiscount;
                        foreach (var item in pageModel.Models)
                        {
                            item.MinSalePrice = Math.Round(item.MinSalePrice * discount, 2);
                        }
                    }
                }
                foreach (var item in pageModel.Models)
                {
                    var flashSale      = flashSalePriceList.Any(p => p.ProductId == item.Id);
                    var fightGroupSale = fightGroupSalePriceList.Any(p => p.ProductId == item.Id);

                    if (flashSale && !fightGroupSale)
                    {
                        item.MinSalePrice = TypeHelper.ObjectToDecimal(flashSalePriceList.FirstOrDefault(p => p.ProductId == item.Id).MinPrice.ToString("f2"));
                    }
                    else if (!flashSale && fightGroupSale)
                    {
                        item.MinSalePrice = TypeHelper.ObjectToDecimal(fightGroupSalePriceList.FirstOrDefault(p => p.ProductId == item.Id).MiniGroupPrice.ToString("f2"));
                    }
                }
                #endregion
            }

            var productlist = pageModel.Models.ToList().Select(item =>
            {
                return(new
                {
                    Id = item.Id,
                    ProductName = item.ProductName,
                    MeasureUnit = item.MeasureUnit,
                    MinSalePrice = item.MinSalePrice.ToString("f2"),
                    SaleCounts = item.SaleCounts,                                                                                             //销量统计没有考虑预约单支付完成。
                    RelativePath = Core.HimallIO.GetRomoteProductSizeImage(item.RelativePath, 1, (int)Himall.CommonModel.ImageSize.Size_350), //150-350
                });
            });
            var result = new
            {
                Success     = true,
                ProductList = productlist,
                total       = pageModel.Total
            };

            return(Json(result));
        }
Beispiel #26
0
        private List <CartProductModel> PackageCartProducts(Mall.Entities.ShoppingCartInfo cart, decimal prodPrice, decimal discount, IProductService productService, IShopService shopService, IShopBranchService shopBranchService, IVShopService vshopService, ITypeService typeservice, bool isBranch = false)
        {
            List <CartProductModel> products = new List <CartProductModel>();
            var limitProducts = LimitTimeApplication.GetPriceByProducrIds(cart.Items.Select(e => e.ProductId).ToList());//限时购价格
            var groupCart     = cart.Items.Where(item => item.ShopBranchId == 0).Select(c =>
            {
                var cItem   = new Mall.Entities.ShoppingCartItem();
                var skuInfo = productService.GetSku(c.SkuId);
                if (skuInfo != null)
                {
                    cItem = c;
                }
                return(cItem);
            }).GroupBy(i => i.ProductId).ToList();

            foreach (var item in cart.Items)
            {
                var                        product       = ProductManagerApplication.GetProduct(item.ProductId);
                var                        shop          = shopService.GetShop(product.ShopId);
                DTO.ShopBranch             shopbranch    = null;
                Entities.ShopBranchSkuInfo shopbranchsku = null;
                if (item.ShopBranchId > 0)
                {
                    shopbranch    = ShopBranchApplication.GetShopBranchById(item.ShopBranchId);
                    shopbranchsku = shopBranchService.GetSkusByIds(item.ShopBranchId, new List <string> {
                        item.SkuId
                    }).FirstOrDefault();
                }

                if (null != shop)
                {
                    var vshop = vshopService.GetVShopByShopId(shop.Id);
                    var sku   = ProductManagerApplication.GetSKU(item.SkuId);
                    if (sku == null)
                    {
                        continue;
                    }
                    //处理限时购、会员折扣价格
                    var prod = limitProducts.FirstOrDefault(e => e.ProductId == item.ProductId);
                    prodPrice = sku.SalePrice;
                    if (prod != null && !isBranch)
                    {
                        prodPrice = prod.MinPrice;
                    }
                    else
                    {
                        if (shop.IsSelf)
                        {//官方自营店才计算会员折扣
                            prodPrice = sku.SalePrice * discount;
                        }
                    }
                    #region 阶梯价--张宇枫
                    //阶梯价
                    if (product.IsOpenLadder)
                    {
                        var quantity = groupCart.Where(i => i.Key == item.ProductId).ToList().Sum(cartitem => cartitem.Sum(i => i.Quantity));
                        prodPrice = ProductManagerApplication.GetProductLadderPrice(item.ProductId, quantity);
                        if (shop.IsSelf)
                        {
                            prodPrice = prodPrice * discount;
                        }
                    }
                    #endregion
                    Entities.TypeInfo typeInfo     = typeservice.GetType(product.TypeId);
                    string            colorAlias   = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
                    string            sizeAlias    = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
                    string            versionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
                    if (product != null)
                    {
                        colorAlias   = !string.IsNullOrWhiteSpace(product.ColorAlias) ? product.ColorAlias : colorAlias;
                        sizeAlias    = !string.IsNullOrWhiteSpace(product.SizeAlias) ? product.SizeAlias : sizeAlias;
                        versionAlias = !string.IsNullOrWhiteSpace(product.VersionAlias) ? product.VersionAlias : versionAlias;
                    }
                    if (sku != null)
                    {
                        #region 正在参加限时抢购商品在购物车失效 TDO:ZYF
                        var isLimit = false;
                        //门店商品,在参加限时购,也可以正常购买
                        var limit = LimitTimeApplication.GetLimitTimeMarketItemByProductId(item.ProductId);
                        if (limit != null && !isBranch)
                        {
                            isLimit = limit.Status == Entities.FlashSaleInfo.FlashSaleStatus.Ongoing;
                        }
                        #endregion
                        var _tmp = new CartProductModel
                        {
                            CartItemId     = item.Id.ToString(),
                            SkuId          = item.SkuId,
                            Id             = product.Id.ToString(),
                            ImgUrl         = Core.MallIO.GetRomoteProductSizeImage(product.RelativePath, 1, (int)Mall.CommonModel.ImageSize.Size_150),
                            Name           = product.ProductName,
                            Price          = prodPrice.ToString("F2"),
                            Count          = item.Quantity.ToString(),
                            ShopId         = shop.Id.ToString(),
                            Size           = sku.Size,
                            Color          = sku.Color,
                            Version        = sku.Version,
                            VShopId        = vshop == null ? "0" : vshop.Id.ToString(),
                            ShopName       = shop.ShopName,
                            ShopLogo       = vshop == null ? "" : Core.MallIO.GetRomoteImagePath(vshop.StrLogo),
                            Url            = Core.MallIO.GetRomoteImagePath("/m-IOS/product/detail/") + item.ProductId,
                            ProductStatus  = isLimit ? 0 : (sku.Stock <= 0 ? ProductInfo.ProductSaleStatus.InStock.GetHashCode() : product.SaleStatus.GetHashCode()),
                            Status         = isLimit ? 1 : ProductManagerApplication.GetProductShowStatus(product, sku, shopbranch == null ? 1 : item.Quantity, shopbranch, shopbranchsku),// 0:正常;1:已失效;2:库存不足;3:已下架;
                            ColorAlias     = colorAlias,
                            SizeAlias      = sizeAlias,
                            VersionAlias   = versionAlias,
                            AddTime        = item.AddTime,
                            ShopBranchId   = item.ShopBranchId,
                            ShopBranchName = null == shopbranch ? "" : shopbranch.ShopBranchName,
                            ShopBranchLogo = null == shopbranch ? "" : Core.MallIO.GetRomoteImagePath(shopbranch.ShopImages)
                        };
                        products.Add(_tmp);
                    }
                }
            }
            return(products);
        }
Beispiel #27
0
 public JsonResult UnFreeze(long shopBranchId)
 {
     ShopBranchApplication.UnFreeze(shopBranchId);
     return(base.Json(new { success = true, msg = "解冻成功!" }));
 }
Beispiel #28
0
        public void AddToCart(string skuId, int count, long memberId, long shopBranchId)
        {
            CheckSkuIdIsValid(skuId, shopBranchId);
            //判断库存
            var sku = ProductManagerApplication.GetSKU(skuId);

            if (sku == null)
            {
                throw new HimallException("错误的SKU");
            }
            if (count > sku.Stock)
            {
                throw new HimallException("库存不足");
            }
            var shopBranch = ShopBranchApplication.GetShopBranchById(shopBranchId);

            if (shopBranch == null)
            {
                throw new HimallException("错误的门店id");
            }
            var shopBranchSkuList = ShopBranchApplication.GetSkusByIds(shopBranchId, new List <string> {
                skuId
            });

            if (shopBranchSkuList == null || shopBranchSkuList.Count == 0)
            {
                throw new HimallException("门店没有该商品");
            }
            if (shopBranchSkuList[0].Status == ShopBranchSkuStatus.InStock)
            {
                throw new HimallException("此商品已下架");
            }

            if (memberId > 0)
            {
                CartApplication.AddToShopBranchCart(skuId, count, memberId, shopBranchId);
            }
            else
            {
                string cartInfo = WebHelper.GetCookie(CookieKeysCollection.HIMALL_CART_BRANCH);
                if (!string.IsNullOrWhiteSpace(cartInfo))
                {
                    string[] cartItems   = cartInfo.Split(',');
                    string   newCartInfo = string.Empty;
                    bool     exist       = false;
                    foreach (string cartItem in cartItems)
                    {
                        var cartItemParts = cartItem.Split(':');
                        if (cartItemParts[0] == skuId && cartItemParts[2] == shopBranchId.ToString())
                        {
                            newCartInfo += "," + skuId + ":" + (int.Parse(cartItemParts[1]) + count) + ":" + shopBranchId;
                            exist        = true;
                        }
                        else
                        {
                            newCartInfo += "," + cartItem;
                        }
                    }
                    if (!exist)
                    {
                        newCartInfo += "," + skuId + ":" + count + ":" + shopBranchId;
                    }

                    if (!string.IsNullOrWhiteSpace(newCartInfo))
                    {
                        newCartInfo = newCartInfo.Substring(1);
                    }
                    WebHelper.SetCookie(CookieKeysCollection.HIMALL_CART_BRANCH, newCartInfo);
                }
                else
                {
                    WebHelper.SetCookie(CookieKeysCollection.HIMALL_CART_BRANCH, string.Format("{0}:{1}:{2}", skuId, count, shopBranchId));
                }
            }
        }
        private List <OrderRefundApiModel> FullModel(List <OrderRefund> refunds)
        {
            var orders     = Application.OrderApplication.GetOrders(refunds.Select(p => p.OrderId));
            var orderItems = Application.OrderApplication.GetOrderItemsByOrderId(refunds.Select(p => p.OrderId));
            var members    = Application.MemberApplication.GetMembers(orders.Select(p => p.UserId).ToList());

            AutoMapper.Mapper.CreateMap <OrderRefund, OrderRefundApiModel>();
            var result = refunds.Select(item =>
            {
                var orditems = new List <DTO.OrderItem>();
                var order    = orders.FirstOrDefault(o => o.Id == item.OrderId);

                if (item.RefundMode == OrderRefundInfo.OrderRefundMode.OrderRefund)
                {
                    orditems = orderItems.Where(d => d.OrderId == item.OrderId).ToList();
                }
                else
                {
                    orditems.Add(orderItems.FirstOrDefault(oi => oi.Id == item.OrderItemId));
                }
                foreach (var orderItem in orditems)
                {
                    orderItem.ThumbnailsUrl    = HimallIO.GetRomoteProductSizeImage(orderItem.ThumbnailsUrl, 1, (int)Himall.CommonModel.ImageSize.Size_100);
                    Entities.TypeInfo typeInfo = ServiceProvider.Instance <ITypeService> .Create.GetTypeByProductId(orderItem.ProductId);
                    orderItem.ColorAlias       = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
                    orderItem.SizeAlias        = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
                    orderItem.VersionAlias     = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
                    orderItem.ShipTo           = order.ShipTo;
                    orderItem.CellPhone        = order.CellPhone;
                    orderItem.RegionFullName   = order.RegionFullName;
                    orderItem.Address          = order.Address;
                    var productInfo            = ProductManagerApplication.GetProduct(orderItem.ProductId);
                    if (productInfo != null)
                    {
                        orderItem.ColorAlias   = !string.IsNullOrWhiteSpace(productInfo.ColorAlias) ? productInfo.ColorAlias : orderItem.ColorAlias;
                        orderItem.SizeAlias    = !string.IsNullOrWhiteSpace(productInfo.SizeAlias) ? productInfo.SizeAlias : orderItem.SizeAlias;
                        orderItem.VersionAlias = !string.IsNullOrWhiteSpace(productInfo.VersionAlias) ? productInfo.VersionAlias : orderItem.VersionAlias;
                    }
                }
                var member = members.FirstOrDefault(m => m.Id == order.UserId);

                var model    = item.Map <OrderRefundApiModel>();
                model.Status = item.SellerAuditStatus == OrderRefundInfo.OrderRefundAuditStatus.Audited ? (int)item.ManagerConfirmStatus : (int)item.SellerAuditStatus;
                //model.StatusDescription = item.SellerAuditStatus == OrderRefundInfo.OrderRefundAuditStatus.Audited ? item.ManagerConfirmStatus.ToDescription() : ((CommonModel.Enum.OrderRefundShopAuditStatus)item.SellerAuditStatus).ToDescription();
                model.StatusDescription = item.SellerAuditStatus == OrderRefundInfo.OrderRefundAuditStatus.Audited ? item.ManagerConfirmStatus.ToDescription() : (order.ShopBranchId > 0 ?
                                                                                                                                                                  ((CommonModel.Enum.OrderRefundShopAuditStatus)item.SellerAuditStatus).ToDescription() : item.SellerAuditStatus.ToDescription());
                //model.UserName = member == null ? "" : member.RealName;
                //model.UserCellPhone = member == null ? "" : member.CellPhone;
                model.IsShopBranchOrder = item.IsShopBranchOrder;
                if (item.IsShopBranchOrder)
                {
                    model.StatusDescription = model.StatusDescription.Replace("商家", "门店");
                    model.RefundStatus      = model.RefundStatus.Replace("商家", "门店");
                }
                model.UserName        = item.ContactPerson;
                model.UserCellPhone   = item.ContactCellPhone;
                model.OrderItem       = orditems;
                model.CertPics        = new string[3];
                model.CertPics[0]     = HimallIO.GetRomoteImagePath(model.CertPic1);
                model.CertPics[1]     = HimallIO.GetRomoteImagePath(model.CertPic2);
                model.CertPics[2]     = HimallIO.GetRomoteImagePath(model.CertPic3);
                string shopBranchName = order.ShopName;
                if (order.ShopBranchId > 0)
                {
                    var shopBranchInfo = ShopBranchApplication.GetShopBranchById(order.ShopBranchId);
                    if (shopBranchInfo != null)
                    {
                        shopBranchName = shopBranchInfo.ShopBranchName;
                    }
                }
                model.ShopName         = shopBranchName;
                model.ReasonDetail     = item.ReasonDetail;
                model.OrderTotalAmount = order.OrderTotalAmount;

                return(model);
            });

            return(result.ToList());
        }
        private string SendDaDaExpress(long orderId, long shopid, long sbid, bool isQueryOrder)
        {
            //Log.Error("达达发货ShopBranchOrder-01:orderId:" + orderId);
            var order = OrderApplication.GetOrder(orderId);

            if (order == null || order.ShopBranchId != sbid || order.OrderStatus != Entities.OrderInfo.OrderOperateStatus.WaitDelivery)
            {
                throw new HimallApiException("错误的订单编号");
            }
            var dadaconfig = CityExpressConfigApplication.GetDaDaCityExpressConfig(shopid);

            if (!dadaconfig.IsEnable)
            {
                throw new HimallApiException("未开启同城合作物流");
            }
            //Log.Error("达达发货ShopBranchOrder-02:OrderStatus:" + order.OrderStatus + "--RegionId:" + order.RegionId);
            if (order.ReceiveLatitude <= 0 || order.ReceiveLongitude <= 0)
            {
                throw new HimallApiException("未获取到客户收货地址坐标信息,无法使用该配送方式");
            }
            var sbdata = ShopBranchApplication.GetShopBranchById(sbid);

            if (sbdata == null || string.IsNullOrWhiteSpace(sbdata.DaDaShopId))
            {
                throw new HimallApiException("门店未在达达注册,或所在城市达达不支持配送,无法发单,请商家在后台进行设置");
            }
            //Log.Error("达达发货ShopBranchOrder-03:Latitude:" + sbdata.DaDaShopId);
            string cityCode  = "";
            var    _adregion = RegionApplication.GetRegion(order.RegionId);
            var    _city     = GetCity(_adregion);

            try
            {
                string cityJson = ExpressDaDaHelper.cityCodeList(shopid);
                var    cityObj  = JsonConvert.DeserializeObject(cityJson) as JObject;
                JArray citylist = (JArray)cityObj["result"];
                foreach (JToken item in citylist)
                {
                    if (_city.ShortName == item["cityName"].ToString())
                    {
                        cityCode = item["cityCode"].ToString();
                        break;
                    }
                }
            }
            catch
            {
            }
            //达达不支持的城市
            if (cityCode == "")
            {
                throw new HimallApiException("配送范围超区,无法配送");
            }
            string callback     = CurrentUrlHelper.CurrentUrl() + "/pay/dadaOrderNotify/";
            bool   isreaddorder = (order.DadaStatus == DadaStatus.Cancel.GetHashCode());

            if (isQueryOrder)
            {
                isreaddorder = false;
            }

            //Log.Error(DateTime.Now + "ShopBranchOrder-0:callback:" + callback + "|shopid:" + shopid + "|DaDaShopId:" + sbdata.DaDaShopId + "|orderId:" + order.Id + "|cityCode:" + cityCode + "|isreaddorder:" + isreaddorder);
            string json = ExpressDaDaHelper.addOrder(shopid, sbdata.DaDaShopId, order.Id.ToString()
                                                     , cityCode, (double)order.TotalAmount, 0, ExpressDaDaHelper.DateTimeToUnixTimestamp(DateTime.Now.AddMinutes(15))
                                                     , order.ShipTo, order.Address, order.ReceiveLatitude, order.ReceiveLongitude
                                                     , callback, order.CellPhone, order.CellPhone, isQueryDeliverFee: isQueryOrder
                                                     , isReAddOrder: isreaddorder);

            //Log.Error(DateTime.Now + "达达发货ShopBranchOrder-1:json:" + json);
            return(json);
        }