/** * 查找特定的专题信息 * @param $topicId * @return ShopTopic * @throws DeepInException */ public function find($topicId) { $topic = ShopTopic::find($topicId); if (!$topic instanceof ShopTopic) { throw new DeepInException("找不到id为" . $topicId . "的数据~!"); } return $topic; }
/** * 封面图 * @param DeepInUpload $upload */ protected function topicImgView(DeepInUpload $upload) { $topicList = ShopTopic::all(); foreach ($topicList as $item) { if (!$item instanceof ShopTopic) { continue; } $imgView = $item->imgView(); if (empty($imgView)) { continue; } $response = $upload->getUpYunUrl($imgView); $responseValue = $response->getResponseValue(); if ($responseValue instanceof UpYunResponseValue) { $this->addToMap($imgView, $responseValue->getLocation()); } } }
/** * @param ShopSlider $slider * @param string $local * @throws DeepInException */ protected function checkLocal($slider, $local) { if ($slider->itemType() == 1) { //应用 if ($this->appHasLocal($slider->itemId(), $local) == false) { throw new DeepInException("专题地区与应用专题对应不上~!"); } } else { //专题 $topic = ShopTopic::find($slider->itemId()); if (!$topic instanceof ShopTopic) { throw new DeepInException("选择的专题不存在"); } if (strcmp($topic->local(), $local) !== 0) { throw new DeepInException("专题地区与slider地区无法对应"); } } }
/** * 获取列表所属的专题/栏目 * @param $type * @param $id * @return null * @throws DeepInHtmlException */ protected function getApplistParent($type, $id) { //列表集合类型(1栏目下的应用集合 2专题下的应用集合) if ($type == 1) { $column = ShopColumn::find($id); if (!$column instanceof ShopColumn) { return null; } return $column; } elseif ($type == 2) { $topic = ShopTopic::find($id); if (!$topic instanceof ShopTopic) { return null; } return $topic; } else { throw new DeepInHtmlException("未知的type" . $type); } }
/** * 选择应用 * @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())); }
/** * 保存数据 * @throws DeepInException * @throws DeepInHtmlException */ public function save() { $topicName = \Input::get("topicname"); $enTopicName = \Input::get("entopicname"); $local = \Input::get("local"); $description = \Input::get("description"); $enDescription = \Input::get("endescription"); $categoryId = \Input::get("categoryid"); $categoryId = intval($categoryId); $bgColor = \Input::get("bgcolor", null); //默认背景颜色 $pos = intval(\Input::get("pos")); //位置(顺序)升序 if (empty($bgColor)) { throw new DeepInHtmlException("默认背景颜色不能为空~!"); } $appNameColor = \Input::get("appnamecolor", null); $categoryNameColor = \Input::get("categorynamecolor", null); if (empty($appNameColor)) { throw new DeepInHtmlException("应用名称颜色不能为空"); } if (empty($categoryNameColor)) { throw new DeepInHtmlException("分类名称颜色不能为空~!"); } if (empty($enTopicName) || empty($topicName) || empty($local) || empty($description) || $categoryId < 1) { throw new DeepInHtmlException("参数不完整~!"); } $uploadInfo = DeepInUtil::upload(array("imgview")); if (!isset($uploadInfo["imgview"])) { throw new DeepInHtmlException("请选择封面图片~!"); } $topic = new ShopTopic(); $topic->topicName($topicName); $topic->enTopicName($enTopicName); $topic->local($local); $topic->description($description); $topic->enDescription($enDescription); // $topic->bgImage($uploadInfo["bgimage"]); $topic->imgView($uploadInfo["imgview"]); $topic->categoryId($categoryId); $topic->pos($pos); // $topic->bgColor($bgColor); if ($topic->save() == false) { throw new DeepInHtmlException("数据保存失败~!"); } $uploadInfo = DeepInUtil::upload(array("banner")); if (!isset($uploadInfo["banner"])) { throw new DeepInHtmlException("请选择默认背景图片~!"); } $banner = new ShopTopicBanner(); $banner->topicId($topic->topicId()); $banner->banner($uploadInfo['banner']); $banner->bgColor($bgColor); $banner->lang($local); //默认使用地区的代码 $banner->appNameColor($appNameColor); $banner->categoryNameColor($categoryNameColor); $to = "/admin/topic/edit/" . $topic->topicId(); if ($banner->save() == false) { throw new DeepInHtmlException("专题新增成功,但是默认背景图片信息保存失败~!", $to); } return $this->success("保存成功~!", $to); }
/** * 保存修改 * @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 $appId * @param $local * @throws DeepInException */ protected function checkAppsListReferred($appId, $local) { $appListItem = ShopAppsList::whereRaw("appid=:appid", array(":appid" => $appId))->get(); $data = array(); foreach ($appListItem as $v) { if ($v instanceof ShopAppsList) { if (isset($data[$v->listType()])) { $data[$v->listType()] = array(); } $data[$v->listType()][] = $v->itemId(); } } $locals = array(); if (isset($data[1])) { //栏目 $colnumList = ShopColumn::whereRaw("columnid in (:columnid)", array(":columnid" => implode(",", $data[1])))->get(); foreach ($colnumList as $v) { if ($v instanceof ShopColumn) { $locals[] = $v->local(); } } } if (in_array($local, $locals)) { throw new DeepInException("无法取消,在栏目里面引用到该应用了。"); } if (isset($data[2])) { //专题 $topicList = ShopTopic::whereRaw("topicid=:topicid", array(":topicid" => implode(",", $data[2])))->get(); foreach ($topicList as $v) { if ($v instanceof ShopTopic) { $locals[] = $v->local(); } } } if (in_array($local, $locals)) { throw new DeepInException("无法取消,在专题里面引用到该应用了。"); } }