示例#1
0
        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
            }));
        }
示例#2
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 ActionResult Add(ShopBranch shopBranch)
        {
            try
            {
                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 <= 0 || shopBranch.Longitude <= 0)
                {
                    throw new HimallException("请搜索地址地图定位!");
                }
                string   regionIDList   = Request.Form["txtRegionScop"];
                string   regionNameList = Request.Form["txtRegionScopName"];
                string[] regionIdArr    = regionIDList.Split(',');
                string[] regionNameArr  = regionNameList.Split(',');

                if (shopBranch.ServeRadius <= 0 && string.IsNullOrWhiteSpace(regionIDList.Trim()))
                {
                    throw new HimallException("配送半径和配送范围不能同时为空!");
                }
                shopBranch.ShopId     = CurrentSellerManager.ShopId;
                shopBranch.CreateDate = DateTime.Now;
                long shopBranchId;
                ShopBranchApplication.AddShopBranch(shopBranch, out shopBranchId);
                if (shopBranchId > 0)
                {
                    #region 添加门店配送范围
                    List <DeliveryScope> deliveryScopList = new List <DeliveryScope>();
                    List <int>           regionIdList     = new List <int>();
                    DeliveryScope        info             = null;
                    for (int i = 0; i < regionIdArr.Length; i++)
                    {
                        int tempRegionId = 0;
                        if (int.TryParse(regionIdArr[i], out tempRegionId) && regionNameArr.Length >= i)
                        {
                            regionIdList.Add(tempRegionId);
                            if (!ShopBranchApplication.ExistsShopDeliveryScope(new ShopDeliveryScopeQuery()
                            {
                                ShopBranchId = shopBranchId, RegionId = tempRegionId
                            }))
                            {
                                info                = new DeliveryScope();
                                info.RegionId       = tempRegionId;
                                info.RegionName     = regionNameArr[i];
                                info.FullRegionPath = RegionApplication.GetRegionPath(tempRegionId);
                                info.FullRegionPath = CommonConst.ADDRESS_PATH_SPLIT + info.FullRegionPath + CommonConst.ADDRESS_PATH_SPLIT;//默认在结尾增加分隔符
                                info.ShopBranchId   = shopBranchId;
                                deliveryScopList.Add(info);
                            }
                        }
                    }
                    if (deliveryScopList.Count > 0)
                    {
                        ShopBranchApplication.AddShopDeliveryScope(deliveryScopList);
                    }
                    if (regionIdList.Count > 0)
                    {
                        ShopBranchApplication.DeleteShopDeliveryScope(new ShopDeliveryScopeQuery()
                        {
                            RegionIdList = regionIdList, ShopBranchId = shopBranchId
                        });                                                                                                                                      //清除旧数据
                    }
                    #endregion
                }
            }
            catch (Exception ex)
            {
                return(Json(new Result()
                {
                    success = false, msg = ex.Message
                }));
            }
            return(Json(new Result()
            {
                success = true
            }));
        }