Files
2026-04-04 08:52:59 +08:00

71 lines
2.0 KiB
PHP
Executable File

<?php
namespace app\model;
/**
* 相册模型
* @property integer $id 主键(ID)
* @property integer $user_id 用户ID
* @property integer $group_id 群组ID
* @property integer $userID 用户ID
* @property integer $groupID 群组ID
* @property string $title 标题
* @property int $image 封面图片ID
* @property int $weigh 排序权重,越小越靠前
* @property integer $created_at 创建时间
* @property integer $updated_at 更新时间
* @property integer $status 状态(0:隐藏 1:正常)
*/
class Album extends Base
{
protected $name = 'album';
protected function getOptions(): array
{
return array_merge(parent::getOptions(), [
'insert' => [
'status' => 1,
],
'append'=>[
'userID',
'groupID'
]
]);
}
public static function onAfterInsert($row){
$changeData = $row->getChangedData();
if(isset($changeData['image'])) {
Files::where('path',$changeData['image'])->inc('use_count');
};
}
public static function onAfterUpdate($row){
$OrgData = $row->getOrigin();
$changeData = $row->getChangedData();
if(isset($OrgData['image']) && $OrgData['image']) {
\support\Log::info('OrgData string');
Files::where('path',$OrgData['image'])->dec('use_count');
};
if(isset($changeData['image']) && $changeData['image']) {
\support\Log::info('changeData string');
Files::where('path',$changeData['image'])->inc('use_count');
};
}
public static function onBeforeDelete($row){
if($row->total>0){
return false;
}
}
public static function onAfterDelete($row){
Files::where('path',$row->image)->dec('use_count');
}
function getGroupIDAttr($v,$row){
return $v?:$row['group_id'];
}
function getUserIDAttr($v,$row){
return $v?:$row['user_id'];
}
}