BanksController.php 4.4 KB

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