Files
cycle_api/app/Models/Post/PostHistoryModel.php
2024-02-26 00:41:25 +08:00

49 lines
1.2 KiB
PHP

<?php
namespace App\Models\Post;
use App\Exceptions\ModelException;
use App\Models\Base\BaseModel;
class PostHistoryModel extends BaseModel
{
protected $table = 'customer_post_history';
protected $primaryKey = 'id';
protected $fillable = [
'id',
'method',
'oid',
'uuid',
'mid',
'uid',
'media',
'content',
'created_at',
];
const METHOD_ADD = 1;
const METHOD_DEL = 2;
const METHOD_EDIT = 4;
const METHOD = [
self::METHOD_ADD => '新增',
self::METHOD_DEL => '删除',
self::METHOD_EDIT => '编辑',
];
/**
* @throws ModelException
*/
function addPostHistory($method, $aItem): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|array|null
{
if(!in_array($method,self::METHOD)) throw new ModelException('addPostHistory method error');
if(!isset($aItem['uuid'])) throw new ModelException('addPostHistory params error');
$aItem['oid'] = $aItem['id'];
unset($aItem['id']);
$sDateTime = date('Y-m-d H:i:s');
$aItem['created_at'] = $sDateTime;
$aItem['method'] = $method;
return $this->addItem($aItem);
}
}