BannerController.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /**
  3. * 轮播图管理
  4. * @author system
  5. * @version 1.0
  6. * @date 2018-05-14 10:41:53
  7. *
  8. */
  9. namespace App\Http\Controllers\Admin\Album;
  10. use App\Http\Controllers\Admin\Controller;
  11. use App\Repositories\Album\Criteria\BannerWhere;
  12. use Illuminate\Http\Request;
  13. use App\Repositories\Base\Criteria\OrderBy;
  14. use App\Repositories\Album\Banner\Criteria\MultiWhere;
  15. use App\Repositories\Album\BannerRepository;
  16. class BannerController extends Controller
  17. {
  18. private $repository;
  19. public function __construct(BannerRepository $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 BannerWhere($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.banner.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.banner.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.banner.edit');
  53. }
  54. /**
  55. * 保存修改
  56. */
  57. private function _createSave(){
  58. $data = (array) request('data');
  59. $data['store_id'] = $this->getStoreId();
  60. if(!empty($data['pic_url']))
  61. $data['pic_url'] = $this->formatImgUrl($data['pic_url']);
  62. $id = $this->repository->create($data);
  63. if($id) {
  64. $url[] = array('url'=>U( 'Album/Banner/index'),'title'=>'返回列表');
  65. $url[] = array('url'=>U( 'Album/Banner/create'),'title'=>'继续添加');
  66. $this->showMessage('添加成功',$url);
  67. }else{
  68. $url[] = array('url'=>U( 'Album/Banner/index'),'title'=>'返回列表');
  69. return $this->showWarning('添加失败',$url);
  70. }
  71. }
  72. /**
  73. *
  74. * 修改
  75. *
  76. *
  77. */
  78. public function update(Request $request) {
  79. if($request->method() == 'POST') {
  80. return $this->_updateSave();
  81. }
  82. $data = $this->repository->find($request->get('id'));
  83. return view('admin.album.banner.edit',compact('data'));
  84. }
  85. /**
  86. * 保存修改
  87. */
  88. private function _updateSave() {
  89. $data = (array) request('data');
  90. if(!empty($data['pic_url']))
  91. $data['pic_url'] = $this->formatImgUrl($data['pic_url']);
  92. $ok = $this->repository->update(request('id'),$data);
  93. if($ok) {
  94. $url[] = array('url'=>U( 'Album/Banner/index'),'title'=>'返回列表');
  95. return $this->showMessage('操作成功',urldecode(request('_referer')));
  96. }else{
  97. $url[] = array('url'=>U( 'Album/Banner/index'),'title'=>'返回列表');
  98. return $this->showWarning('操作失败',$url);
  99. }
  100. }
  101. public function view(Request $request) {
  102. $data = $this->repository->find(request('id'));
  103. return view('admin.album.banner.view',compact('data'));
  104. }
  105. /**
  106. *
  107. * 状态改变
  108. *
  109. */
  110. public function status(Request $request) {
  111. $ok = $this->repository->updateStatus(request('id'),request('status'));
  112. if($ok) {
  113. return $this->showMessage('操作成功');
  114. }else{
  115. return $this->showWarning('操作失败');
  116. }
  117. }
  118. /**
  119. * 删除
  120. */
  121. public function destroy(Request $request) {
  122. $bool = $this->repository->destroy($request->get('id'));
  123. if($bool) {
  124. return $this->showMessage('操作成功');
  125. }else{
  126. return $this->showWarning("操作失败");
  127. }
  128. }
  129. }