<?php

namespace app\extra\service\system;

use app\extra\basic\Service;
use app\model\system\SystemUser;

class UserService extends Service
{

    /**
     * 列表
     * @param array $param
     */
    public function getList(array $param = [])
    {
        $this->mode = new SystemUser();
        return $this->searchVal($param,$this->searchFilter($param))->with(['account' => function ($query) {
            $query->field("shop_id,shop_name");
        }])->paginate([
            "list_rows" => $param['pageSize'],
            "page"      => $param['page']
        ]);
    }



    protected function searchFilter(array $param = []): array
    {
        $filter = [];
        !empty($param['agent']) && $filter[] = ["agent_id", '=', $param['agent']];
        !empty($param['store']) && $filter[] = ["store_id", '=', $param['store']];
        !empty($param['factory']) && $filter[] = ["factory_id", '=', $param['factory']];
        !empty($param['status']) && $filter[] = ["status", '=', ($param['status']-1)];
        !empty($param['mobile']) && $filter[] = ["mobile", 'like', "%{$param['mobile']}%"];
        !empty($param['username']) && $filter[] = ["username", 'like', "%{$param['username']}%"];
        !empty($param['name']) && $filter[] = ["username", 'like', "%{$param['name']}%"];
        !empty($param['type']) && $filter[] = ["type", '=', $param['type']];
        return $filter;
    }

}