/**
  * 查找指定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("保存成功~!");
 }
 /**
  * 新增数据
  * @return \Illuminate\View\View
  * @throws DeepInHtmlException
  */
 public function save()
 {
     $categoryName = \Input::get("categoryname");
     $enCategoryName = \Input::get("encategoryname");
     $local = \Input::get("local");
     if (empty($local)) {
         throw new DeepInHtmlException("请选择区域~!");
     }
     if (empty($categoryName)) {
         throw new DeepInHtmlException("名称不能为空~!");
     }
     $category = new ShopRankCategory();
     $category->categoryName($categoryName);
     $category->enCategoryName($enCategoryName);
     $category->local($local);
     if ($category->save() == false) {
         throw new DeepInHtmlException("新增失败~!");
     }
     return $this->success("操作成功~!");
 }
Example #4
0
 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("排行榜里面提交引用到该应用~!");
     }
 }