// +---------------------------------------------------------------------- namespace App\Services\Common; use App\Models\DriverLevelModel; use App\Services\BaseService; /** * 司机等级管理-服务类 * @author laravel开发员 * @since 2020/11/11 * @package App\Services\Common */ class DriverLevelService extends BaseService { // 静态对象 protected static $instance = null; /** * 构造函数 * @author laravel开发员 * @since 2020/11/11 * CarCategoryService constructor. */ public function __construct() { $this->model = new DriverLevelModel(); } /** * 静态入口 * @return MemberService|static|null */ public static function make() { if (!self::$instance) { self::$instance = new static(); } return self::$instance; } /** * 列表 * @param $params * @param int $pageSize * @return array */ public function getDataList($params, $pageSize = 10) { $where = ['a.mark' => 1]; $list = $this->model->from('driver_level as a') ->where($where) ->where(function ($query) use($params){ $keyword = isset($params['keyword'])? $params['keyword'] : ''; if($keyword){ $query->where('a.name','like',"%{$keyword}%"); } }) ->where(function ($query) use($params){ $status = isset($params['status'])? $params['status'] : 0; if($status>0 && is_array($status)){ $query->whereIn('a.status', $status); }else if($status){ $query->where('a.status', $status); } }) ->select(['a.*']) ->orderBy('a.create_time','desc') ->orderBy('a.id','desc') ->paginate($pageSize > 0 ? $pageSize : 9999999); $list = $list? $list->toArray() :[]; if($list){ foreach($list['data'] as &$item){ $item['create_time'] = $item['create_time']? datetime($item['create_time'],'Y-m-d H.i.s') : ''; } } return [ 'pageSize'=> $pageSize, 'total'=>isset($list['total'])? $list['total'] : 0, 'list'=> isset($list['data'])? $list['data'] : [] ]; } /** * 车型选项 * @param int $num * @return array|mixed */ public function getOptions($num = 99,$field=[]) { $field = $field? $field : ['id','name','status']; $datas = $this->model->where(['status'=>1,'mark'=>1]) ->select($field) ->limit($num) ->orderBy('sort','asc') ->orderBy('id','asc') ->get(); $datas = $datas? $datas->toArray() : []; return $datas; } }