public JsonResult DaDaConfig(ShopBranchDaDaConfigModel model) { long shopId = CurrentShop.Id; Result result = new Result { success = false, msg = "未知错误" }; if (ModelState.IsValid) { if (model.IsEnable) { if (string.IsNullOrWhiteSpace(model.app_key) || string.IsNullOrWhiteSpace(model.app_secret) || string.IsNullOrWhiteSpace(model.source_id)) { result.success = false; result.msg = "数据错误,请填写必填信息"; return(Json(result)); } } var data = CityExpressConfigApplication.GetDaDaCityExpressConfig(shopId); data.IsEnable = model.IsEnable; data.app_key = model.app_key; data.app_secret = model.app_secret; data.source_id = model.source_id; CityExpressConfigApplication.Update(CurrentShop.Id, data); result.msg = ""; //同步开通达达门店 var sblist = ShopBranchApplication.GetShopBranchByShopId(shopId).Where(d => string.IsNullOrWhiteSpace(d.DaDaShopId)); foreach (var item in sblist) { var dada_shop_id = GetNewDadaStoreId(CurrentShop.Id, item.Id); var _area = RegionApplication.GetRegion(item.AddressId); var _city = GetCity(_area); var json = ExpressDaDaHelper.shopAdd(shopId, item.ShopBranchName, 5, _city.ShortName, _area.Parent.Name, item.AddressDetail, item.Longitude, item.Latitude, item.ContactUser, item.ContactPhone, dada_shop_id); var resultObj = JsonConvert.DeserializeObject(json) as JObject; string status = resultObj["status"].ToString(); int code = int.Parse(resultObj["code"].ToString()); if (status == "fail" && code != 7718) { result.msg = "但部份同步门店失败,可能所在城市达达不支持"; } if (string.IsNullOrWhiteSpace(item.DaDaShopId) && (status == "success" || code == 7718)) { item.DaDaShopId = dada_shop_id; ShopBranchApplication.UpdateShopBranch(item); } } result.success = true; } else { result.success = false; result.msg = "数据错误,请填写必填信息"; } return(Json(result)); }
/// <summary> /// 获取市级的所有子区域 /// </summary> /// <param name="regionId"></param> /// <returns></returns> public JsonResult GetCitySubRegions(int regionId) { var region = RegionApplication.GetRegion(regionId, CommonModel.Region.RegionLevel.County); var subRegion = RegionApplication.GetSubRegion(region.ParentId); return(Json(new { regions = subRegion, selectId = region.Id }, true)); }
public JsonResult GetRegionTree(int id) { var region = RegionApplication.GetRegion(id); if (region == null) { var rid = RegionApplication.GetDefaultRegionId(); region = RegionApplication.GetRegion(rid); } Dictionary <string, object> map = new Dictionary <string, object>(); //[ //{ level:1,list:[{id,name,shortname}]}, //{ level:2,list:[{id,name,shortname}]}, //{ level:3,list:[{id,name,shortname}]}, //] //添加子集 if (region.Sub != null) { map.Add( ((int)region.Level + 1).ToString(), region.Sub.Select(p => new { Id = p.Id, Name = p.Name, ShortName = p.ShortName, option = "", }).ToList()); } var parent = 0; do { parent = region.ParentId; //上级节点 var cur = region.Id; //当前节点 var level = (int)region.Level; var regions = RegionApplication.GetSubRegion(parent); var list = regions.Select(p => new { Id = p.Id, Name = p.Name, ShortName = p.ShortName, option = p.Id == cur ? "true" : "" }).ToList(); map.Add(level.ToString(), list); region = region.Parent; } while (parent > 0); return(Json(map, JsonRequestBehavior.AllowGet)); }
public object GetExistShopBranch(long shopId, long regionId, string productIds) { var query = new ShopBranchQuery(); query.Status = ShopBranchStatus.Normal; query.ShopId = shopId; var region = RegionApplication.GetRegion(regionId, CommonModel.Region.RegionLevel.City); query.AddressPath = region.GetIdPath(); query.ProductIds = productIds.Split(',').Select(p => long.Parse(p)).ToArray(); query.ShopBranchProductStatus = ShopBranchSkuStatus.Normal; var existShopBranch = ShopBranchApplication.Exists(query); return new { success = true, ExistShopBranch = existShopBranch ? 1 : 0 }; }
public JsonResult ExistShopBranch(int shopId, int regionId, long[] productIds) { ShopBranchQuery query = new ShopBranchQuery { Status = 0, ShopId = shopId }; query.AddressPath = RegionApplication.GetRegion((long)regionId, Region.RegionLevel.City).GetIdPath(","); query.ProductIds = productIds; bool data = ShopBranchApplication.Exists(query); return(base.Json(data, JsonRequestBehavior.AllowGet)); }
public JsonResult ExistShopBranch(int shopId, int regionId, long[] productIds) { var query = new ShopBranchQuery(); query.Status = ShopBranchStatus.Normal; query.ShopId = shopId; var region = RegionApplication.GetRegion(regionId, Region.RegionLevel.City); query.AddressPath = region.GetIdPath(); query.ProductIds = productIds; var existShopBranch = ShopBranchApplication.Exists(query); return(SuccessResult <dynamic>(data: existShopBranch)); }
public JsonResult ExistShopBranch(int shopId, int regionId, long[] productIds) { var query = new CommonModel.ShopBranchQuery(); query.Status = CommonModel.ShopBranchStatus.Normal; query.ShopId = shopId; var region = RegionApplication.GetRegion(regionId, CommonModel.Region.RegionLevel.City); query.AddressPath = region.GetIdPath(); query.ProductIds = productIds; var existShopBranch = ShopBranchApplication.Exists(query); return(Json(existShopBranch, JsonRequestBehavior.AllowGet)); }
public object GetExistShopBranch(long shopId, long regionId, string productIds) { ShopBranchQuery query = new ShopBranchQuery(); query.Status = new ShopBranchStatus?(ShopBranchStatus.Normal); query.ShopId = shopId; Region region = RegionApplication.GetRegion(regionId, Region.RegionLevel.City); query.AddressPath = region.GetIdPath(","); query.ProductIds = Enumerable.ToArray <long>(Enumerable.Select <string, long>((IEnumerable <string>)productIds.Split(','), (Func <string, long>)(p => long.Parse(p)))); return((object)this.Json(new { Success = true, ExistShopBranch = ShopBranchApplication.Exists(query) ? 1 : 0 })); }
public JsonResult ShopList(int page, int rows, string titleKeyword, string tagsId, string addressId, bool?isRecommend) { ShopBranchQuery query = new ShopBranchQuery(); query.PageNo = page; query.PageSize = rows; if (!string.IsNullOrEmpty(titleKeyword)) { query.ShopBranchName = titleKeyword; } if (!string.IsNullOrEmpty(addressId)) { var regionid = Convert.ToInt32(addressId); var region = RegionApplication.GetRegion(regionid); switch (region.Level) { case Region.RegionLevel.Province: query.ProvinceId = regionid; break; case Region.RegionLevel.City: query.CityId = regionid; break; } } if (!string.IsNullOrEmpty(tagsId)) { query.ShopBranchTagId = Convert.ToInt64(tagsId); } if (isRecommend.HasValue) { query.IsRecommend = isRecommend; } var shopBranchs = ShopBranchApplication.GetShopBranchs(query); var curUrl = CurrentUrlHelper.CurrentUrlNoPort(); var list = new { rows = shopBranchs.Models.Select(item => new { id = item.Id, name = item.ShopBranchName, imgUrl = item.ShopImages, url = "/" + item.Id, tags = string.IsNullOrWhiteSpace(item.ShopBranchInTagNames) ? "" : item.ShopBranchInTagNames.Replace(",", " ") }), total = shopBranchs.Total }; return(Json(list)); }
private void InitOrderSubmitModel(MobileOrderDetailConfirmModel model) { if (model.Address != null) { ShopBranchQuery query = new ShopBranchQuery { Status = 0 }; query.AddressPath = RegionApplication.GetRegion((long)model.Address.RegionId, Region.RegionLevel.City).GetIdPath(","); foreach (MobileShopCartItemModel model2 in model.products) { query.ShopId = model2.shopId; query.ProductIds = (from p in model2.CartItemModels select p.id).ToArray <long>(); model2.ExistShopBranch = ShopBranchApplication.Exists(query); } } }
private void InitOrderSubmitModel(DTO.OrderSubmitModel model) { if (model.address != null) { var query = new CommonModel.ShopBranchQuery(); query.Status = CommonModel.ShopBranchStatus.Normal; var region = RegionApplication.GetRegion(model.address.RegionId, CommonModel.Region.RegionLevel.City); query.AddressPath = region.GetIdPath(); foreach (var item in model.products) { query.ShopId = item.shopId; query.ProductIds = item.freightProductGroup.Select(p => p.ProductId).ToArray(); item.ExistShopBranch = ShopBranchApplication.Exists(query); } } }
public JsonResult ShopList(int page, int rows, string titleKeyword, string tagsId, string addressId, bool?isRecommend) { ShopBranchQuery query = new ShopBranchQuery { PageNo = page, PageSize = rows }; if (!string.IsNullOrEmpty(titleKeyword)) { query.ShopBranchName = titleKeyword; } if (!string.IsNullOrEmpty(addressId)) { int num = Convert.ToInt32(addressId); switch (RegionApplication.GetRegion((long)num).Level) { case Region.RegionLevel.Province: query.ProvinceId = num; break; case Region.RegionLevel.City: query.CityId = num; break; } } if (!string.IsNullOrEmpty(tagsId)) { query.ShopBranchTagId = new long?(Convert.ToInt64(tagsId)); } if (isRecommend.HasValue) { query.IsRecommend = isRecommend; } QueryPageModel <ShopBranch> shopBranchs = ShopBranchApplication.GetShopBranchs(query); string str = CurrentUrlHelper.CurrentUrlNoPort(); var data = new { rows = from item in shopBranchs.Models select new { id = item.Id, name = item.ShopBranchName, imgUrl = item.ShopImages, url = "/" + item.Id, tags = string.IsNullOrWhiteSpace(item.ShopBranchInTagNames) ? "" : item.ShopBranchInTagNames.Replace(",", " ") }, total = shopBranchs.Total }; return(base.Json(data)); }
private void InitOrderSubmitModel(MobileOrderDetailConfirmModel model) { if (model.Address != null) { var query = new ShopBranchQuery(); query.Status = ShopBranchStatus.Normal; var region = RegionApplication.GetRegion(model.Address.RegionId, Region.RegionLevel.City); query.AddressPath = region.GetIdPath(); foreach (var item in model.products) { query.ShopId = item.shopId; query.ProductIds = item.CartItemModels.Select(p => p.id).ToArray(); query.ShopBranchProductStatus = ShopBranchSkuStatus.Normal; item.ExistShopBranch = ShopBranchApplication.Exists(query); } } }
public object GetSub(long parentId) { var region = RegionApplication.GetRegion(parentId); if (region == null) { return(Json(ErrorResult <dynamic>(msg: "错误的参数:parentId"))); } var models = region.Sub.Select(p => new { id = p.Id, name = p.Name, }).ToList(); return(Json(new { Depth = region.Level.GetHashCode(), Regions = models })); }
public ActionResult WXGroupMessage() { var pageModel = _iMemberLabelService.GetMemberLabelList(new LabelQuery() { }); ViewBag.LabelInfos = pageModel.Models.ToList(); //var topregion = _iMemberService.GetAllTopRegion().Select(e => new SelectListItem //{ // Text = _iRegionService.GetRegion(e).Name, // Value = e.ToString() //}).Where(e => !string.IsNullOrWhiteSpace(e.Text)).ToList(); //topregion.Insert(0, new SelectListItem { Value = "-1", Text = "全部" }); var topregion = MemberApplication.GetAllTopRegion().Select(e => { var region = RegionApplication.GetRegion(e); string shortName = ""; if (region != null && region.Level == Region.RegionLevel.Province) { shortName = region.ShortName; } return(new SelectListItem { Text = shortName, Value = e.ToString() }); }).Where(e => !string.IsNullOrWhiteSpace(e.Text)).ToList(); topregion.Insert(0, new SelectListItem { Value = "-1", Text = "全部" }); ViewBag.Regions = topregion; return(View()); }
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)); }
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)); }
public ActionResult Add(ShopBranch shopBranch) { try { if (!string.Equals(shopBranch.PasswordOne, shopBranch.PasswordTwo)) { throw new MallException("两次密码输入不一致!"); } if (string.IsNullOrWhiteSpace(shopBranch.PasswordOne) || string.IsNullOrWhiteSpace(shopBranch.PasswordTwo)) { throw new MallException("密码不能为空!"); } if (shopBranch.ShopBranchName.Length > 15) { throw new MallException("门店名称不能超过15个字!"); } if (shopBranch.AddressDetail.Length > 50) { throw new MallException("详细地址不能超过50个字!"); } if (shopBranch.Latitude <= 0 || shopBranch.Longitude <= 0) { throw new MallException("请搜索地址地图定位!"); } if (!shopBranch.IsAboveSelf && !shopBranch.IsStoreDelive) { throw new MallException("至少需要选择一种配送方式!"); } if (shopBranch.IsStoreDelive && shopBranch.IsFreeMail && shopBranch.FreeMailFee <= 0) { throw new MallException("满额包邮金额必须大于0!"); } if (!shopBranch.IsStoreDelive) { shopBranch.IsFreeMail = false; } if (!shopBranch.IsFreeMail) { shopBranch.FreeMailFee = 0; } shopBranch.ShopId = CurrentSellerManager.ShopId; shopBranch.CreateDate = DateTime.Now; long shopBranchId; ShopBranchApplication.AddShopBranch(shopBranch, out shopBranchId); if (!string.IsNullOrWhiteSpace(shopBranch.ShopBranchTagId)) { var tags = shopBranch.ShopBranchTagId.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(p => long.Parse(p)).ToList(); ShopBranchApplication.SetShopBrandTagInfos(new List <long> { shopBranch.Id }, tags); } //门店标签 var shopBranchTagInfos = ShopBranchApplication.GetAllShopBranchTagInfos(); List <SelectListItem> tagList = new List <SelectListItem>(); foreach (var item in shopBranchTagInfos) { tagList.Add(new SelectListItem { Selected = (shopBranch.ShopBranchTagId == null ? false : shopBranch.ShopBranchTagId.Split(',').Contains(item.Id.ToString()) ? true : false), Value = item.Id.ToString(), Text = item.Title }); } ViewBag.ShopBranchTags = tagList; if (CityExpressConfigApplication.GetDaDaCityExpressConfig(CurrentShop.Id).IsEnable) { var dada_shop_id = GetNewDadaStoreId(CurrentShop.Id, shopBranch.Id); var _area = RegionApplication.GetRegion(shopBranch.AddressId); var _city = GetCity(_area); var json = ExpressDaDaHelper.shopAdd(CurrentShop.Id, shopBranch.ShopBranchName, 5, _city.ShortName, _area.Parent.Name, shopBranch.AddressDetail, shopBranch.Longitude, shopBranch.Latitude, shopBranch.ContactUser, shopBranch.ContactPhone, dada_shop_id); var resultObj = JsonConvert.DeserializeObject(json) as JObject; string status = resultObj["status"].ToString(); int code = int.Parse(resultObj["code"].ToString()); if (status == "fail" && code != 7718) { return(Json(new Result() { success = true, msg = "但同步门店至达达物流失败,可能所在城市达达不支持" })); } if (string.IsNullOrWhiteSpace(shopBranch.DaDaShopId) && (status == "success" || code == 7718)) { shopBranch.DaDaShopId = dada_shop_id; ShopBranchApplication.UpdateShopBranch(shopBranch); } } } catch (Exception ex) { return(Json(new Result() { success = false, msg = ex.Message })); } return(Json(new Result() { success = true })); }
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); }
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 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 ActionResult Edit(ShopBranch shopBranch) { try { if (!string.Equals(shopBranch.PasswordOne, shopBranch.PasswordTwo)) { throw new MallException("两次密码输入不一致!"); } if (shopBranch.ShopBranchName.Length > 15) { throw new MallException("门店名称不能超过15个字!"); } if (shopBranch.AddressDetail.Length > 50) { throw new MallException("详细地址不能超过50个字!"); } if (shopBranch.Latitude <= 0 || shopBranch.Longitude <= 0) { throw new MallException("请搜索地址地图定位!"); } if (!shopBranch.IsAboveSelf && !shopBranch.IsStoreDelive) { throw new MallException("至少需要选择一种配送方式!"); } if (shopBranch.IsStoreDelive && shopBranch.IsFreeMail && shopBranch.FreeMailFee <= 0) { throw new MallException("满额包邮金额必须大于0!"); } if (!shopBranch.IsStoreDelive) { shopBranch.IsFreeMail = false; } if (!shopBranch.IsFreeMail) { shopBranch.FreeMailFee = 0; } //判断是否编辑自己的门店 shopBranch.ShopId = CurrentSellerManager.ShopId;//当前登录商家 //门店所属商家 var oldBranch = ShopBranchApplication.GetShopBranchById(shopBranch.Id); if (oldBranch != null && oldBranch.ShopId != shopBranch.ShopId) { throw new MallException("不能修改其他商家的门店!"); } if (!shopBranch.IsFreeMail) { shopBranch.FreeMailFee = 0; } if (!string.IsNullOrWhiteSpace(shopBranch.ShopBranchTagId)) { var tags = shopBranch.ShopBranchTagId.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(p => long.Parse(p)).ToList(); ShopBranchApplication.SetShopBrandTagInfos(new List <long> { shopBranch.Id }, tags); } ShopBranchApplication.UpdateShopBranch(shopBranch); if (CityExpressConfigApplication.GetDaDaCityExpressConfig(CurrentShop.Id).IsEnable) { var _area = RegionApplication.GetRegion(shopBranch.AddressId); var _city = GetCity(_area); string json = ""; var dada_shop_id = GetNewDadaStoreId(CurrentShop.Id, shopBranch.Id); if (string.IsNullOrWhiteSpace(shopBranch.DaDaShopId)) { json = ExpressDaDaHelper.shopAdd(CurrentShop.Id, shopBranch.ShopBranchName, 5, _city.ShortName, _area.Parent.Name, shopBranch.AddressDetail, shopBranch.Longitude, shopBranch.Latitude, shopBranch.ContactUser, shopBranch.ContactPhone, dada_shop_id); } else { json = ExpressDaDaHelper.shopUpdate(CurrentShop.Id, shopBranch.DaDaShopId, shopBranch.ShopBranchName, 5, _city.ShortName, _area.Parent.Name, shopBranch.AddressDetail, shopBranch.Longitude, shopBranch.Latitude, shopBranch.ContactUser, shopBranch.ContactPhone); } var resultObj = JsonConvert.DeserializeObject(json) as JObject; string status = resultObj["status"].ToString(); int code = int.Parse(resultObj["code"].ToString()); if (status == "fail" && code != 7718) { return(Json(new Result() { success = true, msg = "但同步门店至达达物流失败,可能所在城市达达不支持" })); } if (string.IsNullOrWhiteSpace(shopBranch.DaDaShopId) && (status == "success" || code == 7718)) { shopBranch.DaDaShopId = dada_shop_id; ShopBranchApplication.UpdateShopBranch(shopBranch); } } } catch (Exception ex) { return(Json(new Result() { success = false, msg = ex.Message })); } return(Json(new Result() { success = true })); }