CatController.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. /**
  3. * 咨询分类
  4. * @author system
  5. * @version 1.0
  6. * @date 2018-05-21 16:17:09
  7. *
  8. */
  9. namespace App\Http\Controllers\Admin\Album\Info;
  10. use App\Http\Controllers\Admin\Controller;
  11. use App\Models\AlbumInfoCatModel;
  12. use Illuminate\Http\Request;
  13. use App\Repositories\Base\Criteria\OrderBy;
  14. use App\Repositories\Album\Info\Criteria\MultiWhere;
  15. use App\Repositories\Album\Info\CatRepository;
  16. class CatController extends Controller
  17. {
  18. private $repository;
  19. public function __construct(CatRepository $repository) {
  20. if(!$this->repository) $this->repository = $repository;
  21. }
  22. function index(Request $request) {
  23. $search['keyword'] = $request->input('keyword');
  24. $query = $this->repository->pushCriteria(new MultiWhere($search,$this->getStoreId()));
  25. if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
  26. $query = $query->pushCriteria(new OrderBy($request['sort_field'],$request['sort_field_by']));
  27. }else{
  28. $query = $query->pushCriteria(new OrderBy('id','DESC'));
  29. }
  30. $list = $query->paginate();
  31. return view('admin.album.info.cat.index',compact('list'));
  32. }
  33. function check(Request $request) {
  34. $request = $request->all();
  35. $search['keyword'] = $request->input('keyword');
  36. $orderby = array();
  37. if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
  38. $orderby[$request['sort_field']] = $request['sort_field_by'];
  39. }
  40. $list = $this->repository->search($search,$orderby);
  41. return view('admin.album.info.cat.check',compact('list'));
  42. }
  43. /**
  44. * 添加
  45. *
  46. */
  47. public function create(Request $request)
  48. {
  49. if($request->method() == 'POST') {
  50. return $this->_createSave();
  51. }
  52. return view('admin.album.info.cat.edit');
  53. }
  54. /**
  55. * 保存修改
  56. */
  57. private function _createSave(){
  58. $data = (array) request('data');
  59. $data['store_id'] = $this->getStoreId();
  60. $id = $this->repository->create($data);
  61. if($id) {
  62. $url[] = array('url'=>U( 'Album/Info/Cat/index'),'title'=>'返回列表');
  63. $url[] = array('url'=>U( 'Album/Info/Cat/create'),'title'=>'继续添加');
  64. $this->showMessage('添加成功',$url);
  65. }else{
  66. $url[] = array('url'=>U( 'Album/Info/Cat/index'),'title'=>'返回列表');
  67. return $this->showWarning('添加失败',$url);
  68. }
  69. }
  70. /**
  71. *
  72. * 修改
  73. *
  74. *
  75. */
  76. public function update(Request $request) {
  77. if($request->method() == 'POST') {
  78. return $this->_updateSave();
  79. }
  80. $data = $this->repository->find($request->get('id'));
  81. return view('admin.album.info.cat.edit',compact('data'));
  82. }
  83. /**
  84. * 保存修改
  85. */
  86. private function _updateSave() {
  87. $data = (array) request('data');
  88. $ok = $this->repository->update(request('id'),$data);
  89. if($ok) {
  90. $url[] = array('url'=>U( 'Album/Info/Cat/index'),'title'=>'返回列表');
  91. return $this->showMessage('操作成功',urldecode(request('_referer')));
  92. }else{
  93. $url[] = array('url'=>U( 'Album/Info/Cat/index'),'title'=>'返回列表');
  94. return $this->showWarning('操作失败',$url);
  95. }
  96. }
  97. public function view(Request $request) {
  98. $data = $this->repository->find(request('id'));
  99. return view('admin.album.info.cat.view',compact('data'));
  100. }
  101. /**
  102. *
  103. * 状态改变
  104. *
  105. */
  106. public function status(Request $request) {
  107. $ok = $this->repository->updateStatus(request('id'),request('status'));
  108. if($ok) {
  109. return $this->showMessage('操作成功');
  110. }else{
  111. return $this->showWarning('操作失败');
  112. }
  113. }
  114. /**
  115. * 删除
  116. */
  117. public function destroy(Request $request) {
  118. $cat = AlbumInfoCatModel::find($request->get('id'));
  119. $ok = $cat->delete();
  120. if($ok) {
  121. return $this->showMessage('操作成功');
  122. }else{
  123. return $this->showWarning("操作失败");
  124. }
  125. }
  126. }