Пример #1
0
        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));
        }
Пример #2
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
            }));
        }
Пример #3
0
        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
            }));
        }