35 lines
816 B
PHP
35 lines
816 B
PHP
<?php
|
|
/**
|
|
* Author: cfn <cfn@leapy.cn>
|
|
*/
|
|
|
|
namespace App\Utils;
|
|
|
|
use function Hyperf\Support\make;
|
|
|
|
trait Crud
|
|
{
|
|
public static function add(array $data)
|
|
{
|
|
$data['create_time'] = date("Y-m-d H:i:s");
|
|
return self::insertGetId($data);
|
|
}
|
|
|
|
public static function edit(array $data)
|
|
{
|
|
$model = make(static::class);
|
|
return $model->where($model->primaryKey, $data[$model->primaryKey])->update($data);
|
|
}
|
|
|
|
public static function del(string $ids): int
|
|
{
|
|
return self::destroy(explode(",", $ids));
|
|
}
|
|
|
|
public static function getById(int $id, array $field = ['*']): array
|
|
{
|
|
$model = make(static::class);
|
|
$info = $model->where($model->primaryKey, $id)->select($field)->first();
|
|
return $info ? $info->toArray() : [];
|
|
}
|
|
} |