InfoController.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. 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.user.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.user.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.user.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( 'User/Info/index'),'title'=>'返回列表');
  59. $url[] = array('url'=>U( 'User/Info/create'),'title'=>'继续添加');
  60. $this->showMessage('添加成功',$url);
  61. }else{
  62. $url[] = array('url'=>U( 'User/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.user.info.edit',compact('data'));
  78. }
  79. /**
  80. * 保存修改
  81. */
  82. private function _updateSave() {
  83. $data = (array) request('data');
  84. dd($data);
  85. $ok = $this->repository->update(request('id'),$data);
  86. if($ok) {
  87. $url[] = array('url'=>U( 'User/Info/index'),'title'=>'返回列表');
  88. return $this->showMessage('操作成功',urldecode(request('_referer')));
  89. }else{
  90. $url[] = array('url'=>U( 'User/Info/index'),'title'=>'返回列表');
  91. return $this->showWarning('操作失败',$url);
  92. }
  93. }
  94. public function view(Request $reqeust) {
  95. $data = $this->repository->find(request('id'));
  96. return view('admin.user.info.view',compact('data'));
  97. }
  98. /**
  99. *
  100. * 状态改变
  101. *
  102. */
  103. public function status(Request $reqeust) {
  104. $ok = $this->repository->updateStatus(request('id'),request('status'));
  105. if($ok) {
  106. return $this->showMessage('操作成功');
  107. }else{
  108. return $this->showWarning('操作失败');
  109. }
  110. }
  111. /**
  112. * 删除
  113. */
  114. public function destroy(Request $reqeust) {
  115. $bool = $this->repository->destroy($reqeust->get('id'));
  116. if($bool) {
  117. return $this->showMessage('操作成功');
  118. }else{
  119. return $this->showWarning("操作失败");
  120. }
  121. }
  122. }