cmbYouku_Api/app/service/BaseService.php

72 lines
2.0 KiB
PHP
Raw Normal View History

2024-07-01 15:57:07 +08:00
<?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);
2024-07-08 15:26:18 +08:00
$path = '/images/' . date('Y') . '/' . date('m') . '/' . date('d');
$fullPath = $basePath . $path;
if (!file_exists($fullPath)) {
mkdir($fullPath, 0777, true);
2024-07-01 15:57:07 +08:00
}
2024-07-08 15:26:18 +08:00
$imagePath = Filesystem::putFile($path, $file, 'md5');
$imagePath = str_replace('\\', '/', $imagePath);
return ['image_path' => config('filesystem.disks.public.url') . $imagePath];
2024-07-01 15:57:07 +08:00
}
public function __call($name, $arguments)
{
//找不到方法,自动调用模型中基类方法
return call_user_func_array([$this->model, $name], $arguments);
}
2024-07-08 15:26:18 +08:00
public static function isLastDayOfMonth()
{
$date = date('Y-m-d');
// 获取该月的最后一天
$lastDayOfMonth = date('Y-m-t', strtotime($date));
// 比较给定日期和该月的最后一天
return $date === $lastDayOfMonth;
}
2024-07-01 15:57:07 +08:00
}