<?php namespace app\service; use think\facade\Filesystem; use think\facade\Request; use think\Collection; /** * @method array|null detailById($id, ?array $field = []) 获取一条数据 * @method mixed deleteById($id) 删除 * @method mixed updateOne($where, $data) 更新 * @method int insertOne($data) 新增一条记录 * @method array|null getInfoByWhere($where) 查询记录 * @method array|Collection|null getLists($where = [], $field = [], $order = []) 查询列表 * */ class BaseService { static $page; protected $model; /** * @param $param * @return array */ public static function getPageInfo($param = []): array { return [ 'list_rows' => Request::param("pageSize", 10), 'var_page' => 'page', 'page' => Request::param("page", 1), ]; } public static function orderBy() { return Request::param("orderBy", 'id desc'); } public static function upload($data) { $file = $data['file']; $basePath = config('filesystem.disks.public.root'); validate(['file' => ['fileExt:jpg,png,jpeg,bmp,xlsx,xls,webp|fileSize:20*1024*1024']])->check($data); $path = '/images/'.date('Y').'/'.date('m').'/'.date('d'); $fullPath = $basePath.$path; if(!file_exists($fullPath)) { mkdir($fullPath,0777,true); } $imagePath = Filesystem::putFile($path,$file,'md5'); $imagePath = str_replace('\\','/',$imagePath); return ['image_path' =>config('filesystem.disks.public.url').$imagePath ]; } public function __call($name, $arguments) { //找不到方法,自动调用模型中基类方法 return call_user_func_array([$this->model, $name], $arguments); } }