/// <summary>
        /// 新增商户
        /// </summary>
        /// <returns></returns>
        public ActionResult AddShop(int id = 0)
        {
            var r = new UpdateShopModel();
            if (id != 0)
            {
                var req = YunClient.Instance.Execute(new GetShopRequest {ShopId = id}).Shop;
                if (req == null)
                {
                    Error500Message = "商户不存在";
                    return RedirectToAction("Error500", "Home");
                }

                ViewData["uname"] = req.ShopKeeper;

                r.AreaId = ((req.Areas != null && req.Areas.Any()) ? req.Areas.Last().Key : 0).ToString();
                r.Address = req.Address;
                r.Bulletin = req.Bulletin;
                r.Category = ((req.CategoryId != null && req.CategoryId.Any()) ? req.CategoryId.Last().Key : 0).ToString();
                r.Description = req.Description;
                r.Hours = req.Hours;
                r.Image = req.Picture;
                r.Location = req.Location;
                r.Longlat = req.Location;
                r.Phone = req.Phone;
                r.Summary = req.Summary;
                r.HomePage = req.HomePage;
                r.Title = req.Title;
                r.UserName = req.ShopKeeper;
            }

            return View(r);
        }
        public ActionResult AddShop(UpdateShopModel model, int id = 0)
        {
            if (id <= 0)
            {
                if (!ModelState.IsValid)
                {
                    TempData["error"] = "添加失败,缺少必填项";
                    return View(model);
                }

                if (model.UserPassword.IsEmpty())
                {
                    TempData["error"] = "请输入商家管理员密码";
                    return View(model);
                }

                var req=  YunClient.Instance.Execute(new AddShopRequest
                {
                    AreaId = model.AreaId.TryTo(0),
                    AppSecret = YunClient.AppSecret,
                    Address = model.Address,
                    Bulletin = model.Bulletin,
                    CategoryId = Request.Form["categoryId"].TryTo(0),
                    CityId = 0,
                    CompanyId = CompanyId,
                    Coordinate = model.Longlat,
                    Description = model.Description,
                    DeliveryTime = 0,
                    Name = model.Title,
                    UserName = model.UserName,
                    Summary = model.Summary,
                    ShopkeeperPhone = model.Phone,
                    Hours = model.Hours,
                    Location = model.Location,
                    Email = "",
                    Ip = Request.UserHostAddress,
                    Image = FileManage.GetFirstFile(),
                    HomeUrl = model.HomePage,
                    Phone = model.Phone,
                    Password = model.UserPassword
                }, Token);

                if (req.Result > 0)
                {
                    //成功添加后,新建默认的包邮物流模板
                    var r = YunClient.Instance.Execute(new AddDeliveryTemplateRequest
                    {
                        Title = "默认包邮",
                        Farefree = -1,
                        FareFreeStrategy = null,
                        LogisticsPrice = null,
                        PriceType = 0,
                        ShopId = (int)req.Result
                    }, Token);

                    TempData["success"] = "您已成功添加“" + model.Title + "”商户";
                    return RedirectToAction("Index");
                }

                TempData["error"] = "添加失败,远程错误";
                return View(model);
            }

            var img = FileManage.UploadOneFile();

            var updateReq = YunClient.Instance.Execute(new UpdateShopRequest
            {
                AreaId = model.AreaId.TryTo(0),
                AppSecret = YunClient.AppSecret,
                Address = model.Address,
                Bulletin = model.Bulletin,
                CategoryId = Request.Form["categoryId"].TryTo(0),
                Coordinate = model.Longlat,
                Description = model.Description,
                Summary = model.Summary,
                Hours = model.Hours,
                Location = model.Location,
                Image = string.IsNullOrEmpty(img) ? model.Image : img,
                ShopId = id,
                Title = model.Title,
                HomeUrl = model.HomePage,
                Phone = model.Phone,
                Password = model.UserPassword
            }, Token);

            if (updateReq.Result)
            {
                TempData["success"] = "您已成功更新“" + model.Title + "”商户";
                return RedirectToAction("Index");
            }

            TempData["error"] = "更新失败,远程错误";
            return View(model);
        }