UserRepository.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * 用户管理
  4. * @author system
  5. * @version 1.0
  6. * @date 2018-05-14 13:25:12
  7. *
  8. */
  9. namespace App\Repositories\Album;
  10. use App\Repositories\Base\Repository;
  11. class UserRepository extends Repository {
  12. public function model() {
  13. return \App\Models\AlbumUserModel::class;
  14. }
  15. public function searchUser(array $search,array $orderby=['id'=>'desc'],$pagesize=10)
  16. {
  17. $currentQuery = $this->model;
  18. if(isset($search['keyword']) && ! empty($search['keyword'])) {
  19. $keywords = '%' . $search['keyword'] . '%';
  20. $currentQuery = $currentQuery->where(function ($query) use ($keywords) {
  21. $query->where('username' , 'like', $keywords)
  22. ->orwhere('phone', 'like', $keywords)
  23. ->orwhere('open_id', 'like', $keywords);
  24. });
  25. }
  26. if (isset($search['role']) && ! empty($search['role']) && $search['role'] != -1) {
  27. $role = $search['role'];
  28. $currentQuery = $currentQuery->where(function ($query) use ($role) {
  29. $query->where('role', $role);
  30. });
  31. }
  32. if (isset($search['is_boss']) && ! empty($search['is_boss']) && $search['is_boss'] != -1) {
  33. $is_boss = $search['is_boss'];
  34. $currentQuery = $currentQuery->where(function ($query) use ($is_boss) {
  35. $query->where('is_boss', $is_boss);
  36. });
  37. }
  38. // dd($orderby);
  39. $currentQuery = $currentQuery->where(function ($query) use ($search) {
  40. $query->where('store_id',$search['storeid']);
  41. });
  42. if($orderby && is_array($orderby)){
  43. foreach ($orderby AS $field => $value){
  44. //dd($orderby);
  45. $currentQuery = $currentQuery -> orderBy($field, $value);
  46. }
  47. }
  48. $currentQuery = $currentQuery->paginate($pagesize);
  49. return $currentQuery;
  50. }
  51. }