/** * 查找指定id的榜单分类 * @param $id * @return ShopRankCategory * @throws DeepInException */ public function find($id) { $category = ShopRankCategory::find($id); if ($category instanceof ShopRankCategory) { return $category; } throw new DeepInException("找不到id为" . $id . "的数据~!"); }
/** * 保存数据 * @return \Illuminate\View\View * @throws DeepInHtmlException */ public function save() { $rankId = intval(\Input::get("rankid")); $rank = null; if ($rankId > 0) { try { $rank = $this->find($rankId); } catch (DeepInException $e) { } } if (!$rank instanceof ShopRank) { $rank = new ShopRank(); } //判断选在的应用的合法性 $appId = intval(\Input::get("appid")); if ($appId < 1) { throw new DeepInHtmlException("请选在应用~!"); } //判断榜单类别的合法性 $categoryId = intval(\Input::get("categoryid")); if ($categoryId < 1) { throw new DeepInHtmlException("请选择榜单的类型~!"); } $ranking = intval(\Input::get("ranking")); if ($ranking < 1) { throw new DeepInHtmlException("名次必须是正整数~!"); } $app = ShopApps::find($appId); if (!$app instanceof ShopApps) { throw new DeepInHtmlException("选择的应用不存在~!"); } if ($app->inuse() != 1) { throw new DeepInHtmlException("选择的应用属于下架状态~!"); } $rankCategory = ShopRankCategory::find($categoryId); if (!$rankCategory instanceof ShopRankCategory) { throw new DeepInHtmlException("选择的榜单类型不存在~!"); } $rank->appId($appId); $rank->appName($app->appName()); $rank->categoryId($categoryId); $rank->ranking($ranking); if ($rank->save() == false) { throw new DeepInHtmlException("保存失败,请检查名次是否重复~!"); } return $this->success("保存成功~!"); }