InfoController.php 4.0 KB

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