public function getArticle($id = null) { try { if (empty($id)) { throw new Exception("Error request [10]"); } $articles = \BeautyNews::where('status', '=', '1')->where('id', '=', $id)->get(); if ($articles == null) { throw new Exception("Error request [11]"); } return \View::make('aesthetics.beautyNews.view_index', array('articles' => &$articles, 'bodyId' => 'beautyNews')); } catch (Exception $e) { return \Response::route('frontend.beautynes.list'); } }
public function postUpdateSort() { try { if (!isset($_POST) || !isset($_POST['id']) || !isset($_POST['sort'])) { throw new Exception('Error request [10]'); } $id = (int) Arr::get($_POST, 'id'); $sort = (int) Arr::get($_POST, 'sort'); $isUpdatedTime = Arr::get($_POST, 'isUpdatedTime', false); $lastUpdatedId = Arr::get($_POST, 'lastUpdatedId', false); $model = BeautyNews::find($id); if (empty($model)) { throw new Exception("Error request [11]"); } $model->sort = $sort; if (!$model->save()) { throw new Exception("更新排序失敗,請通知工程師"); } if ($isUpdatedTime) { $cmd = BeautyNews::where('id', '<>', $id)->where('sort', '=', $sort)->where('id', '>=', $lastUpdatedId)->orderBy('sort', 'desc')->orderBy('updated_at', 'desc'); $items = $cmd->get(); if (sizeof($items) > 0) { $t = time(); foreach ($items as $key => $item) { $t = $t + $key; $item->updated_at = $t; $item->save(); } } } return Response::json(array('status' => 'ok', 'message' => '更新排序完成')); } catch (Exception $e) { return Response::json(array('status' => 'error', 'message' => $e->getMessage())); } }