UserController.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 furnitureIndex(Request $request) {
  25. $search['keyword'] = $request->input('keyword');
  26. $search['storeid'] = $this->getStoreId();
  27. $search['role'] = $request->input('role') ?? -1;
  28. $order = array();
  29. if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
  30. $order[$request['sort_field']] = $request['sort_field_by'];
  31. }else{
  32. $order['id']='DESC';
  33. }
  34. $list = $this->repository->searchUser($search,$order);
  35. //dd($list);
  36. // dump($list);die;
  37. return view('admin.album.user.furniture-index',compact('list'));
  38. }
  39. function albumIndex(Request $request) {
  40. $search['keyword'] = $request->input('keyword');
  41. $search['storeid'] = $this->getStoreId();
  42. $search['is_boss'] = $request->input('is_boss') ?? -1;
  43. $order = array();
  44. if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
  45. $order[$request['sort_field']] = $request['sort_field_by'];
  46. }else{
  47. $order['id']='DESC';
  48. }
  49. $list = $this->repository->searchUser($search,$order);
  50. //dd($list);
  51. // dump($list);die;
  52. return view('admin.album.user.album-index',compact('list'));
  53. }
  54. public function view(Request $request) {
  55. $data = $this->repository->find(request('id'));
  56. return view('admin.album.user.view',compact('data'));
  57. }
  58. /**
  59. *
  60. * 状态改变
  61. *
  62. */
  63. public function status(Request $request) {
  64. $ok = $this->repository->updateStatus(request('id'),request('status'));
  65. if($ok) {
  66. return $this->showMessage('操作成功');
  67. }else{
  68. return $this->showWarning('操作失败');
  69. }
  70. }
  71. /**
  72. *
  73. * 修改
  74. *
  75. *
  76. */
  77. public function update(Request $request) {
  78. $data = $this->repository->find($request->get('id'));
  79. if($data->is_dealer == 1){
  80. return $this->showWarning('该用户已成为经销商');
  81. }
  82. $save['is_dealer'] = 1;
  83. $ok = $this->repository->update(request('id'),$save);
  84. if($ok){
  85. $add['store_id'] = $this->getStoreId();
  86. $add['user_id'] = $data->id;
  87. $add['name'] = $data->username;
  88. $add['status'] = 1;
  89. $res = AlbumAgentModel::create($add);
  90. if($res) {
  91. return $this->showMessage('操作成功');
  92. }else{
  93. return $this->showWarning('操作失败');
  94. }
  95. }
  96. }
  97. /**
  98. * 保存修改
  99. */
  100. private function _updateSave() {
  101. $data = (array) request('data');
  102. $ok = $this->repository->update(request('id'),$data);
  103. if($ok) {
  104. $url[] = array('url'=>U( 'Album/User/index'),'title'=>'返回列表');
  105. return $this->showMessage('操作成功',urldecode(request('_referer')));
  106. }else{
  107. $url[] = array('url'=>U( 'Album/User/index'),'title'=>'返回列表');
  108. return $this->showWarning('操作失败',$url);
  109. }
  110. }
  111. /**
  112. * 删除
  113. */
  114. public function destroy(Request $request) {
  115. $bool = $this->repository->destroy($request->get('id'));
  116. if($bool) {
  117. return $this->showMessage('操作成功');
  118. }else{
  119. return $this->showWarning("操作失败");
  120. }
  121. }
  122. public function role(Request $request){
  123. $id = request('id');
  124. $role = request('role');
  125. $user = AlbumUserModel::find($id);
  126. if ($role == 4) {
  127. $user->is_boss = 1;
  128. } else if ($role == 5) {
  129. $user->is_boss = 0;
  130. } else {
  131. $user->role = $role;
  132. }
  133. $ok = $user->save();
  134. if($ok) {
  135. return $this->showMessage('操作成功');
  136. }else{
  137. return $this->showWarning('操作失败');
  138. }
  139. }
  140. }