UserController.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. /**
  3. * 用户管理
  4. * @author system
  5. * @version 1.0
  6. * @date 2018-05-14 13:25:12
  7. *
  8. */
  9. namespace App\Http\Controllers\Admin\Album;
  10. use App\Http\Controllers\Admin\Controller;
  11. use App\Models\AlbumAgentModel;
  12. use App\Models\AlbumUserModel;
  13. use App\Repositories\Album\Criteria\UserWhere;
  14. use Illuminate\Http\Request;
  15. use App\Repositories\Base\Criteria\OrderBy;
  16. use App\Repositories\Album\Criteria\MultiWhere;
  17. use App\Repositories\Album\UserRepository;
  18. class UserController extends Controller
  19. {
  20. private $repository;
  21. public function __construct(UserRepository $repository) {
  22. if(!$this->repository) $this->repository = $repository;
  23. }
  24. function index(Request $request) {
  25. $search['keyword'] = $request->input('keyword');
  26. $search['storeid'] = $this->getStoreId();
  27. $order = array();
  28. if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
  29. $order[$request['sort_field']] = $request['sort_field_by'];
  30. }else{
  31. $order['id']='DESC';
  32. }
  33. $list = $this->repository->searchUser($search,$order);
  34. //dd($list);
  35. // dump($list);die;
  36. return view('admin.album.user.index',compact('list'));
  37. }
  38. function check(Request $request) {
  39. $request = $request->all();
  40. $search['keyword'] = $request->input('keyword');
  41. $orderby = array();
  42. if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
  43. $orderby[$request['sort_field']] = $request['sort_field_by'];
  44. }
  45. $list = $this->repository->search($search,$orderby);
  46. return view('admin.album.user.check',compact('list'));
  47. }
  48. /**
  49. * 添加
  50. *
  51. */
  52. public function create(Request $request)
  53. {
  54. if($request->method() == 'POST') {
  55. return $this->_createSave();
  56. }
  57. return view('admin.album.user.edit');
  58. }
  59. /**
  60. * 保存修改
  61. */
  62. private function _createSave(){
  63. $data = (array) request('data');
  64. $id = $this->repository->create($data);
  65. if($id) {
  66. $url[] = array('url'=>U( 'Album/User/index'),'title'=>'返回列表');
  67. $url[] = array('url'=>U( 'Album/User/create'),'title'=>'继续添加');
  68. $this->showMessage('添加成功',$url);
  69. }else{
  70. $url[] = array('url'=>U( 'Album/User/index'),'title'=>'返回列表');
  71. return $this->showWarning('添加失败',$url);
  72. }
  73. }
  74. /**
  75. *
  76. * 修改
  77. *
  78. *
  79. */
  80. public function update(Request $request) {
  81. $data = $this->repository->find($request->get('id'));
  82. if($data->is_dealer == 1){
  83. return $this->showWarning('该用户已成为经销商');
  84. }
  85. $save['is_dealer'] = 1;
  86. $ok = $this->repository->update(request('id'),$save);
  87. if($ok){
  88. $add['store_id'] = $this->getStoreId();
  89. $add['user_id'] = $data->id;
  90. $add['name'] = $data->username;
  91. $add['status'] = 1;
  92. $res = AlbumAgentModel::create($add);
  93. if($res) {
  94. return $this->showMessage('操作成功');
  95. }else{
  96. return $this->showWarning('操作失败');
  97. }
  98. }
  99. return view('admin.album.user.edit',compact('data'));
  100. }
  101. /**
  102. * 保存修改
  103. */
  104. private function _updateSave() {
  105. $data = (array) request('data');
  106. $ok = $this->repository->update(request('id'),$data);
  107. if($ok) {
  108. $url[] = array('url'=>U( 'Album/User/index'),'title'=>'返回列表');
  109. return $this->showMessage('操作成功',urldecode(request('_referer')));
  110. }else{
  111. $url[] = array('url'=>U( 'Album/User/index'),'title'=>'返回列表');
  112. return $this->showWarning('操作失败',$url);
  113. }
  114. }
  115. public function view(Request $request) {
  116. $data = $this->repository->find(request('id'));
  117. return view('admin.album.user.view',compact('data'));
  118. }
  119. /**
  120. *
  121. * 状态改变
  122. *
  123. */
  124. public function status(Request $request) {
  125. $ok = $this->repository->updateStatus(request('id'),request('status'));
  126. if($ok) {
  127. return $this->showMessage('操作成功');
  128. }else{
  129. return $this->showWarning('操作失败');
  130. }
  131. }
  132. /**
  133. * 删除
  134. */
  135. public function destroy(Request $request) {
  136. $bool = $this->repository->destroy($request->get('id'));
  137. if($bool) {
  138. return $this->showMessage('操作成功');
  139. }else{
  140. return $this->showWarning("操作失败");
  141. }
  142. }
  143. public function role(Request $request){
  144. $id = request('id');
  145. $role = request('role');
  146. $user = AlbumUserModel::find($id);
  147. if ($role == 4) {
  148. $user->is_boss = 1;
  149. } else {
  150. $user->role = $role;
  151. }
  152. $ok = $user->save();
  153. if($ok) {
  154. return $this->showMessage('操作成功');
  155. }else{
  156. return $this->showWarning('操作失败');
  157. }
  158. }
  159. }