AttrRepository.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * 产品属性
  4. * @author system
  5. * @version 1.0
  6. * @date 2018-07-03 16:51:48
  7. *
  8. */
  9. namespace App\Repositories\Album\Product;
  10. use App\Repositories\Base\Repository;
  11. class AttrRepository extends Repository {
  12. public function model() {
  13. return \App\Models\AlbumProductAttrModel::class;
  14. }
  15. public function searchAttr(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('id' , 'like', $keywords)
  22. ->orwhere('name', 'like', $keywords);
  23. });
  24. }
  25. $currentQuery = $currentQuery->where(function ($query) use ($search) {
  26. $query->where('store_id',$search['storeid']);
  27. });
  28. if($orderby && is_array($orderby)){
  29. foreach ($orderby AS $field => $value){
  30. $currentQuery = $currentQuery -> orderBy($field, $value);
  31. }
  32. }
  33. $currentQuery = $currentQuery->paginate($pagesize);
  34. return $currentQuery;
  35. }
  36. }