| xqd
@@ -20,19 +20,26 @@ class CatController extends Controller
|
|
|
{
|
|
|
private $repository;
|
|
|
|
|
|
- public function __construct(CatRepository $repository) {
|
|
|
- if(!$this->repository) $this->repository = $repository;
|
|
|
+ public function __construct(CatRepository $repository)
|
|
|
+ {
|
|
|
+ if (!$this->repository) {
|
|
|
+ $this->repository = $repository;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- function index(Request $request) {
|
|
|
- //AlbumCatModel::where()->get();
|
|
|
+ /**
|
|
|
+ * @param Request $request
|
|
|
+ * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
|
+ */
|
|
|
+ function index(Request $request)
|
|
|
+ {
|
|
|
$search['keyword'] = $request->input('keyword');
|
|
|
- $query = $this->repository->pushCriteria(new CatWhere($search,0,$this->getStoreId()));
|
|
|
+ $query = $this->repository->pushCriteria(new CatWhere($search, 0, $this->getStoreId()));
|
|
|
|
|
|
- if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
|
|
|
- $query = $query->pushCriteria(new OrderBy($request['sort_field'],$request['sort_field_by']));
|
|
|
- }else{
|
|
|
- $query = $query->pushCriteria(new OrderBy('id','DESC'));
|
|
|
+ if (isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
|
|
|
+ $query = $query->pushCriteria(new OrderBy($request['sort_field'], $request['sort_field_by']));
|
|
|
+ } else {
|
|
|
+ $query = $query->pushCriteria(new OrderBy('id', 'DESC'));
|
|
|
}
|
|
|
$list = $query->paginate();
|
|
|
foreach ($list as $key => $item) {
|
| xqd
@@ -40,19 +47,23 @@ class CatController extends Controller
|
|
|
$item->sonlist = AlbumCatModel::where([['parent_id',$item->id],['store_id',$this->getStoreId()]])->get();
|
|
|
}
|
|
|
// dump($list);
|
|
|
- return view('admin.album.cat.index',compact('list'));
|
|
|
+ return view('admin.album.cat.index', compact('list'));
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- function check(Request $request) {
|
|
|
+ /**
|
|
|
+ * @param Request $request
|
|
|
+ * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
|
+ */
|
|
|
+ function check(Request $request)
|
|
|
+ {
|
|
|
$request = $request->all();
|
|
|
$search['keyword'] = $request->input('keyword');
|
|
|
$orderby = array();
|
|
|
- if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
|
|
|
+ if (isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
|
|
|
$orderby[$request['sort_field']] = $request['sort_field_by'];
|
|
|
}
|
|
|
- $list = $this->repository->search($search,$orderby);
|
|
|
- return view('admin.album.cat.check',compact('list'));
|
|
|
+ $list = $this->repository->search($search, $orderby);
|
|
|
+ return view('admin.album.cat.check', compact('list'));
|
|
|
}
|
|
|
|
|
|
|
| xqd
@@ -62,12 +73,12 @@ class CatController extends Controller
|
|
|
*/
|
|
|
public function create(Request $request)
|
|
|
{
|
|
|
- if($request->method() == 'POST') {
|
|
|
+ if ($request->method() == 'POST') {
|
|
|
return $this->_createSave();
|
|
|
}
|
|
|
- $cat = AlbumCatModel::where('parent_id',0)->get();
|
|
|
+ $cat = AlbumCatModel::where([['parent_id', 0],['store_id',$this->getStoreId()]])->get();
|
|
|
$data['parent_id'] = null;
|
|
|
- return view('admin.album.cat.edit',compact('data','cat'));
|
|
|
+ return view('admin.album.cat.edit', compact('data', 'cat'));
|
|
|
}
|
|
|
|
|
|
/**
|
| xqd
@@ -76,17 +87,18 @@ class CatController extends Controller
|
|
|
private function _createSave(){
|
|
|
$data = (array) request('data');
|
|
|
$data['store_id'] = $this->getStoreId();
|
|
|
- if(!empty($data['pic_url']))
|
|
|
- $data['pic_url'] = $this->formatImgUrl($data['pic_url']);
|
|
|
+ if (!empty($data['pic_url'])) {
|
|
|
+ $data['pic_url'] = $this->formatImgUrl($data['pic_url']);
|
|
|
+ }
|
|
|
|
|
|
$id = $this->repository->create($data);
|
|
|
- if($id) {
|
|
|
- $url[] = array('url'=>U( 'Album/Cat/index'),'title'=>'返回列表');
|
|
|
- $url[] = array('url'=>U( 'Album/Cat/create'),'title'=>'继续添加');
|
|
|
- $this->showMessage('添加成功',$url);
|
|
|
- }else{
|
|
|
- $url[] = array('url'=>U( 'Album/Cat/index'),'title'=>'返回列表');
|
|
|
- return $this->showWarning('添加失败',$url);
|
|
|
+ if ($id) {
|
|
|
+ $url[] = array('url' => U('Album/Cat/index'), 'title' => '返回列表');
|
|
|
+ $url[] = array('url' => U('Album/Cat/create'), 'title' => '继续添加');
|
|
|
+ $this->showMessage('添加成功', $url);
|
|
|
+ } else {
|
|
|
+ $url[] = array('url' => U('Album/Cat/index'), 'title' => '返回列表');
|
|
|
+ return $this->showWarning('添加失败', $url);
|
|
|
}
|
|
|
}
|
|
|
|
| xqd
@@ -96,36 +108,41 @@ class CatController extends Controller
|
|
|
*
|
|
|
*
|
|
|
*/
|
|
|
- public function update(Request $request) {
|
|
|
- if($request->method() == 'POST') {
|
|
|
+ public function update(Request $request)
|
|
|
+ {
|
|
|
+ if ($request->method() == 'POST') {
|
|
|
return $this->_updateSave();
|
|
|
}
|
|
|
$data = $this->repository->find($request->get('id'));
|
|
|
- $cat = AlbumCatModel::where('parent_id',0)->get();
|
|
|
+ $cat = AlbumCatModel::where([['parent_id',0],['store_id',$this->getStoreId()]])->get();
|
|
|
|
|
|
- return view('admin.album.cat.edit',compact('data','cat'));
|
|
|
+ return view('admin.album.cat.edit', compact('data', 'cat'));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 保存修改
|
|
|
*/
|
|
|
- private function _updateSave() {
|
|
|
+ private function _updateSave()
|
|
|
+ {
|
|
|
$data = (array) request('data');
|
|
|
- if(!empty($data['pic_url']))
|
|
|
- $data['pic_url'] = $this->formatImgUrl($data['pic_url']);
|
|
|
- $ok = $this->repository->update(request('id'),$data);
|
|
|
- if($ok) {
|
|
|
- $url[] = array('url'=>U( 'Album/Cat/index'),'title'=>'返回列表');
|
|
|
- return $this->showMessage('操作成功',urldecode(request('_referer')));
|
|
|
- }else{
|
|
|
- $url[] = array('url'=>U( 'Album/Cat/index'),'title'=>'返回列表');
|
|
|
- return $this->showWarning('操作失败',$url);
|
|
|
+ if (!empty($data['pic_url'])) {
|
|
|
+ $data['pic_url'] = $this->formatImgUrl($data['pic_url']);
|
|
|
+ }
|
|
|
+
|
|
|
+ $ok = $this->repository->update(request('id'), $data);
|
|
|
+ if ($ok) {
|
|
|
+ $url[] = array('url' => U('Album/Cat/index'), 'title' => '返回列表');
|
|
|
+ return $this->showMessage('操作成功', urldecode(request('_referer')));
|
|
|
+ } else {
|
|
|
+ $url[] = array('url' => U('Album/Cat/index'), 'title' => '返回列表');
|
|
|
+ return $this->showWarning('操作失败', $url);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public function view(Request $request) {
|
|
|
+ public function view(Request $request)
|
|
|
+ {
|
|
|
$data = $this->repository->find(request('id'));
|
|
|
- return view('admin.album.cat.view',compact('data'));
|
|
|
+ return view('admin.album.cat.view', compact('data'));
|
|
|
}
|
|
|
|
|
|
|
| xqd
@@ -134,12 +151,12 @@ class CatController extends Controller
|
|
|
* 状态改变
|
|
|
*
|
|
|
*/
|
|
|
- public function status(Request $request) {
|
|
|
-
|
|
|
- $ok = $this->repository->updateStatus(request('id'),request('status'));
|
|
|
- if($ok) {
|
|
|
+ public function status(Request $request)
|
|
|
+ {
|
|
|
+ $ok = $this->repository->updateStatus(request('id'), request('status'));
|
|
|
+ if ($ok) {
|
|
|
return $this->showMessage('操作成功');
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
return $this->showWarning('操作失败');
|
|
|
}
|
|
|
}
|
| xqd
@@ -147,17 +164,17 @@ class CatController extends Controller
|
|
|
/**
|
|
|
* 删除
|
|
|
*/
|
|
|
- public function destroy(Request $request) {
|
|
|
- //$bool = $this->repository->destroy($request->get('id'));
|
|
|
+ public function destroy(Request $request)
|
|
|
+ {
|
|
|
$cat = AlbumCatModel::find($request->get('id'));
|
|
|
- $son_cat = AlbumCatModel::where('parent_id',$cat->id)->delete();
|
|
|
- if($son_cat){
|
|
|
- //$son_cat->delete();
|
|
|
+ $son_cat = AlbumCatModel::where('parent_id', $cat->id)->delete();
|
|
|
+ if ($son_cat) {
|
|
|
+ $son_cat->delete();
|
|
|
}
|
|
|
$ok = $cat->delete();
|
|
|
- if($ok) {
|
|
|
+ if ($ok) {
|
|
|
return $this->showMessage('操作成功');
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
return $this->showWarning("操作失败");
|
|
|
}
|
|
|
}
|