<?php
/**
 *   用户管理
 *  @author  system
 *  @version    1.0
 *  @date 2018-05-14 13:25:12
 *
 */
namespace App\Repositories\Album;

use App\Repositories\Base\Repository;


class UserRepository extends Repository {

    public function model() {
        return \App\Models\AlbumUserModel::class;
    }

    public function searchUser(array $search,array $orderby=['id'=>'desc'],$pagesize=10)
    {
        $currentQuery = $this->model;
        if(isset($search['keyword']) && ! empty($search['keyword'])) {
            $keywords = '%' . $search['keyword'] . '%';
            $currentQuery = $currentQuery->where(function ($query) use ($keywords) {
                $query->where('username'  , 'like', $keywords)
                    ->orwhere('phone', 'like', $keywords)
                    ->orwhere('wechat_open_id', 'like', $keywords);
            });
        }

        // dd($orderby);
        $currentQuery = $currentQuery->where(function ($query) use ($search) {
            $query->where('store_id',$search['storeid']);
        });

        if($orderby && is_array($orderby)){
            foreach ($orderby AS $field => $value){
                //dd($orderby);
                $currentQuery = $currentQuery -> orderBy($field, $value);
            }
        }
        $currentQuery = $currentQuery->paginate($pagesize);
        return $currentQuery;
    }
    
}
