/** * 查找指定id的排行数据 * @param $id * @return ShopRank * @throws DeepInException */ public function find($id) { $rank = ShopRank::find($id); if ($rank instanceof ShopRank) { return $rank; } 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("保存成功~!"); }
protected function checkRankReferred($appId, $local) { $rankList = ShopRank::whereRaw("appid=:appid", array(":appid" => $appId))->get(); $rankCategory = array(); foreach ($rankList as $v) { if ($v instanceof ShopRank) { $rankCategory[] = $v->categoryId(); } } $categoryList = ShopRankCategory::whereRaw("categoryid in (:categoryid)", array(":categoryid" => implode(",", $rankCategory)))->get(); $locals = array(); foreach ($categoryList as $v) { if ($v instanceof ShopRankCategory) { $locals[] = $v->local(); } } if (in_array($local, $locals)) { throw new DeepInException("排行榜里面提交引用到该应用~!"); } }