/**
  * Bind data to the view.
  *
  * @param  View $view
  * @return void
  */
 public function compose(View $view)
 {
     $view->with('count', array("counter" => array("aaa")))->with("appid", intval($this->app->appId()));
 }
 /**
  * 选择应用
  * @return \Illuminate\Http\JsonResponse
  * @throws DeepInException
  * @throws DeepInHtmlException
  */
 public function select()
 {
     $listType = intval(\Input::get("listtype", 0));
     //类型
     $itemId = intval(\Input::get("itemid", 0));
     //类型下面对应的id
     $appId = intval(\Input::get("appid", 0));
     //选在的appid
     if ($listType < 1 || $itemId < 0) {
         throw new DeepInException("参数错误~!");
     }
     if ($appId < 1) {
         throw new DeepInException("请选择应用~!");
     }
     //判断应用是否存在
     $app = ShopApps::find($appId);
     if (!$app instanceof ShopApps) {
         throw new DeepInException("选择的应用不存在~!");
     }
     $appLocals = $app->localList()->getResults();
     if ($listType == 1) {
         //栏目
         $colunmn = ShopColumn::find($itemId);
         if (!$colunmn instanceof ShopColumn) {
             throw new DeepInException("专题不存在");
         }
         $local = $colunmn->local();
     } else {
         $topic = ShopTopic::find($itemId);
         if (!$topic instanceof ShopTopic) {
             throw new DeepInException("专题不存在~!");
         }
         $local = $topic->local();
     }
     $isFindLocal = false;
     foreach ($appLocals as $item) {
         if ($item instanceof ShopAppsLocal) {
             if (strcmp($local, $item->local()) === 0) {
                 $isFindLocal = true;
             }
         }
     }
     if ($isFindLocal == false) {
         throw new DeepInException("区域不对~!");
     }
     //        print_r($appLocals);
     //        exit;
     //判断listtype和itemid是否正确
     if ($this->checkAppList($listType, $itemId) == false) {
         throw new DeepInException("listType和itemId参数非法~!");
     }
     $parent = $this->getApplistParent($listType, $itemId);
     if ($parent == null) {
         throw new DeepInException("找不到对应的数据~!");
     }
     $canLocal = $parent->local();
     //只查询该地区下面的应用列表
     if ($this->appHasLocal($appId, $canLocal) == false) {
         throw new DeepInException("应用" . $app->appName() . "不属于" . $canLocal . "地区");
     }
     //创建一行数据加入到数据库中
     $appList = new ShopAppsList();
     $appList->listType($listType);
     $appList->itemId($itemId);
     $appList->appId($appId);
     $appList->pos(0);
     if ($appList->save() == false) {
         throw new DeepInException("新增数据错误~!");
     }
     $appList->pos($appList->id());
     $appList->save();
     //保存位置信息,如果知道不报错。
     return $this->successJSON(array("id" => $appList->id()));
 }
 /**
  * 选择应用
  * @return \Illuminate\View\View
  * @throws DeepInException
  */
 public function select()
 {
     $id = \Input::get("packageid");
     if (!$id) {
         throw new DeepInException("参数不完整");
     }
     //判断用户是否在应用里面
     $app = ShopApps::whereRaw("packageid=:packageid", array(":packageid" => $id))->first();
     if (!$app instanceof ShopApps) {
         //不存在在应用商店里面,属于新增一行数据到应用商店里面
         //拉取仓库里面的数据,部分数据是需要冗余的
         $responseValue = OpenApi::metadataInfo($id);
         if ($responseValue->getStatusCode() != 0) {
             throw new DeepInException("拉取仓库数据失败~!", $responseValue->getStatusMessage());
         }
         $data = $responseValue->getData();
         $app = new ShopApps();
         $app->packageId($id);
         $app->appName($id);
         //$data["name"]
         if ($app->save() == false) {
             throw new DeepInException("数据移进商店失败~!");
         }
         $appId = $app->appId();
         //创建两行宣传语的数据[默认新增两行]
         $inserted = ShopAppsTranslation::insert(array(array("appid" => $appId, "lang" => "zh_CN"), array("appid" => $appId, "lang" => "en_US")));
         if ($inserted == false) {
             throw new DeepInException("翻译数据新增失败~!");
         }
         return $this->successJSON();
     }
 }
 /**
  * 应用图片
  * @param DeepInUpload $upload
  */
 protected function app(DeepInUpload $upload)
 {
     $appList = ShopApps::all();
     foreach ($appList as $item) {
         if ($item instanceof ShopApps) {
             $imgView = $item->imgView();
             if (empty($imgView)) {
                 continue;
             }
             $response = $upload->getUpYunUrl($imgView);
             $responseValue = $response->getResponseValue();
             if ($responseValue instanceof UpYunResponseValue) {
                 $this->addToMap($imgView, $responseValue->getLocation());
             }
         }
     }
 }
 /**
  * 保存数据
  * @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\Http\JsonResponse
  * @throws DeepInException
  * @throws \Exception
  */
 public function select()
 {
     $id = \Input::get("packageid");
     if (!$id) {
         throw new DeepInException("参数不完整");
     }
     //判断用户是否在应用里面
     $app = ShopApps::whereRaw("packageid=:packageid", array(":packageid" => $id))->first();
     if (!$app instanceof ShopApps) {
         //不存在在应用商店里面,属于新增一行数据到应用商店里面
         //拉取仓库里面的数据,部分数据是需要冗余的
         $responseValue = OpenApi::metadataInfo($id);
         if ($responseValue->getStatusCode() != 0) {
             throw new DeepInException("拉取仓库数据失败~!", $responseValue->getStatusMessage());
         }
         $data = $responseValue->getData();
         $app = new ShopApps();
         $app->packageId($id);
         $app->appName($id);
         //$data["name"]
         if ($app->save() == false) {
             throw new DeepInException("数据移进商店失败~!");
         }
         $appId = $app->appId();
         //创建两行宣传语的数据[默认新增两行]
         $inserted = ShopAppsTranslation::insert(array(array("appid" => $appId, "lang" => "zh_CN"), array("appid" => $appId, "lang" => "en_US")));
         if ($inserted == false) {
             throw new DeepInException("翻译数据新增失败~!");
         }
     }
     return $this->successJSON();
     //        else {
     //            //应用在商店里面,需要判断该应用是否被栏目或者专题选用,如果被选用,则无法从商店里面remove掉该应用
     //
     //
     ////            $this->checkAppReferred($app->appId());
     ////            if ($app->inuse() == 1) {
     ////                throw new DeepInException("数据属于上架状态,无法移除商店~!");
     ////            }
     //            $applocalList = ShopAppsLocal::whereRaw("appid=:appid", array(":appid" => $appId))->get();
     //            if (count($applocalList) > 0) {
     //                throw new DeepInException("数据属于上架状态,无法移除商店~!");
     //            }
     //
     //            //删掉shop-app里面的数据
     //            if ($app->delete() == false) {
     //                throw new DeepInException("移除数据错误~!");
     //            }
     //
     //            //宣传语的翻译也要删掉
     //
     //            //对应的区域数据也要删掉
     //
     //
     //            return $this->successJSON();
     //        }
 }
 /**
  * 保存修改
  * @throws DeepInException
  * @throws DeepInHtmlException
  */
 public function save()
 {
     $id = intval(\Input::get("sliderid"));
     $pos = intval(\Input::get("pos"));
     $slider = null;
     //新增或者编辑的对象
     if ($id > 0) {
         //编辑
         $slider = $this->find($id);
         if (!$slider instanceof ShopSlider) {
             throw new DeepInHtmlException("当前编辑的数据可能已经被删除~!");
         }
         try {
             $uploadInfo = DeepInUtil::upload(array("sliderpic"));
             //上传信息
             if (isset($uploadInfo["sliderpic"])) {
                 $url = $uploadInfo["sliderpic"];
                 // TODO 删除之前的老图片
                 $oldPic = $slider->sliderPic();
                 //之前的老图片
                 $slider->sliderPic($url);
             }
         } catch (DeepInException $e) {
             //没有上传图片
             throw new DeepInHtmlException($e->getMessage());
         }
         $category = $slider->sliderCategory();
         $itemId = $slider->itemId();
         $itemType = $slider->itemType();
         $local = $slider->local();
         $pos = $slider->pos();
     } else {
         $category = \Input::get("slidercategory");
         //slider类别
         $category = intval($category);
         $itemType = intval(\Input::get("itemtype"));
         //连接的类型
         $itemId = intval(\Input::get("itemid"));
         //连接到对应的id
         $local = \Input::get("local");
         //地区
         if ($category < 1 || $itemId < 1 || $itemType < 1) {
             throw new DeepInHtmlException("参数不完整~!" . $category . "#" . $itemId . "#" . $itemType);
         }
         //新增
         $slider = new ShopSlider();
         try {
             $uploadInfo = DeepInUtil::upload(array("sliderpic"));
             //上传信息
             if (isset($uploadInfo['sliderpic']) == false) {
                 throw new DeepInHtmlException("请选择要上传的背景图片");
             }
             $url = $uploadInfo["sliderpic"];
             $slider->sliderPic($url);
         } catch (\Exception $e) {
             throw new DeepInHtmlException($e->getMessage());
         }
     }
     if ($category == 1) {
         //app
         $app = ShopApps::find($itemId);
         if (!$app instanceof ShopApps) {
             throw new DeepInHtmlException("找不到应用");
         }
         //            if ($app->inuse() != 1) {
         //                throw new DeepInHtmlException("该应用属于下线的状态,无法选择~!");
         //            }
         if ($this->appHasLocal($itemId, $local) == false) {
             throw new DeepInHtmlException("slider所在的地区与应用地区对应不上~!");
         }
     } elseif ($category == 2) {
         //专题
         $topic = ShopTopic::find($itemId);
         if (!$topic instanceof ShopTopic) {
             throw new DeepInHtmlException("找不到id为{$itemId}的专题~!");
         }
         if ($topic->inuse() != 1) {
             throw new DeepInHtmlException("你选择的专题已经下线,无法选择~!");
         }
         if (strcmp($topic->local(), $local) !== 0) {
             throw new DeepInHtmlException("slider所在的地区与专题地区对应不上~!");
         }
     } else {
         throw new DeepInHtmlException("错误的category" . $category . "~!");
     }
     //检查是否选择了地区对应不上的应用
     $slider->sliderCategory($category);
     $slider->itemType($itemType);
     $slider->itemId($itemId);
     $slider->local($local);
     $slider->pos($pos);
     if ($slider->save() == false) {
         throw new DeepInHtmlException("保存失败~!");
     }
     return $this->success("操作成功~!", "/admin/slider");
 }
 /**
  * 验证应用数据的完整性,防止信息不完整的信息被上架
  * @param ShopApps $app
  * @throws DeepInException
  */
 protected function checkAppIntegrity(ShopApps $app)
 {
     $validation = array(array($app->packageId(), "包不能为空,该数据无法使用"), array($app->imgView(), "应用的封面图片不能为空"));
     foreach ($validation as $item) {
         if (empty($item[0])) {
             throw new DeepInException($item[1]);
         }
     }
 }