InfoController.php 3.9 KB

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